1 |
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Le5le=t():e.Le5le=t()}(self,(()=>(()=>{var e={176:(e,t,i)=>{var n=i(52);e.exports=function(e){if(!n(e))throw TypeError(String(e)+" is not an object");return e}},540:(e,t,i)=>{var n=i(905),r=i(237),o=i(357),s=function(e){return function(t,i,s){var a,c=n(t),l=r(c.length),h=o(s,l);if(e&&i!=i){for(;l>h;)if((a=c[h++])!=a)return!0}else for(;l>h;h++)if((e||h in c)&&c[h]===i)return e||h||0;return!e&&-1}};e.exports={includes:s(!0),indexOf:s(!1)}},79:e=>{var t={}.toString;e.exports=function(e){return t.call(e).slice(8,-1)}},81:(e,t,i)=>{var n=i(816),r=i(826),o=i(933),s=i(787);e.exports=function(e,t){for(var i=r(t),a=s.f,c=o.f,l=0;l<i.length;l++){var h=i[l];n(e,h)||a(e,h,c(t,h))}}},762:(e,t,i)=>{var n=i(400),r=i(787),o=i(358);e.exports=n?function(e,t,i){return r.f(e,t,o(1,i))}:function(e,t,i){return e[t]=i,e}},358:e=>{e.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},400:(e,t,i)=>{var n=i(229);e.exports=!n((function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a}))},635:(e,t,i)=>{var n=i(859),r=i(52),o=n.document,s=r(o)&&r(o.createElement);e.exports=function(e){return s?o.createElement(e):{}}},837:e=>{e.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},103:(e,t,i)=>{var n=i(859),r=i(933).f,o=i(762),s=i(487),a=i(333),c=i(81),l=i(541);e.exports=function(e,t){var i,h,u,d,f,p=e.target,v=e.global,x=e.stat;if(i=v?n:x?n[p]||a(p,{}):(n[p]||{}).prototype)for(h in t){if(d=t[h],u=e.noTargetGet?(f=r(i,h))&&f.value:i[h],!l(v?h:p+(x?".":"#")+h,e.forced)&&void 0!==u){if(typeof d==typeof u)continue;c(d,u)}(e.sham||u&&u.sham)&&o(d,"sham",!0),s(i,h,d,e)}}},229:e=>{e.exports=function(e){try{return!!e()}catch(e){return!0}}},379:(e,t,i)=>{var n=i(36);e.exports=n("native-function-to-string",Function.toString)},230:(e,t,i)=>{var n=i(276),r=i(859),o=function(e){return"function"==typeof e?e:void 0};e.exports=function(e,t){return arguments.length<2?o(n[e])||o(r[e]):n[e]&&n[e][t]||r[e]&&r[e][t]}},859:(e,t,i)=>{var n=function(e){return e&&e.Math==Math&&e};e.exports=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof i.g&&i.g)||Function("return this")()},816:e=>{var t={}.hasOwnProperty;e.exports=function(e,i){return t.call(e,i)}},977:e=>{e.exports={}},394:(e,t,i)=>{var n=i(400),r=i(229),o=i(635);e.exports=!n&&!r((function(){return 7!=Object.defineProperty(o("div"),"a",{get:function(){return 7}}).a}))},337:(e,t,i)=>{var n=i(229),r=i(79),o="".split;e.exports=n((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==r(e)?o.call(e,""):Object(e)}:Object},407:(e,t,i)=>{var n,r,o,s=i(694),a=i(859),c=i(52),l=i(762),h=i(816),u=i(399),d=i(977),f=a.WeakMap;if(s){var p=new f,v=p.get,x=p.has,g=p.set;n=function(e,t){return g.call(p,e,t),t},r=function(e){return v.call(p,e)||{}},o=function(e){return x.call(p,e)}}else{var y=u("state");d[y]=!0,n=function(e,t){return l(e,y,t),t},r=function(e){return h(e,y)?e[y]:{}},o=function(e){return h(e,y)}}e.exports={set:n,get:r,has:o,enforce:function(e){return o(e)?r(e):n(e,{})},getterFor:function(e){return function(t){var i;if(!c(t)||(i=r(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return i}}}},541:(e,t,i)=>{var n=i(229),r=/#|\.prototype\./,o=function(e,t){var i=a[s(e)];return i==l||i!=c&&("function"==typeof t?n(t):!!t)},s=o.normalize=function(e){return String(e).replace(r,".").toLowerCase()},a=o.data={},c=o.NATIVE="N",l=o.POLYFILL="P";e.exports=o},52:e=>{e.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},231:e=>{e.exports=!1},694:(e,t,i)=>{var n=i(859),r=i(379),o=n.WeakMap;e.exports="function"==typeof o&&/native code/.test(r.call(o))},787:(e,t,i)=>{var n=i(400),r=i(394),o=i(176),s=i(66),a=Object.defineProperty;t.f=n?a:function(e,t,i){if(o(e),t=s(t,!0),o(i),r)try{return a(e,t,i)}catch(e){}if("get"in i||"set"in i)throw TypeError("Accessors not supported");return"value"in i&&(e[t]=i.value),e}},933:(e,t,i)=>{var n=i(400),r=i(195),o=i(358),s=i(905),a=i(66),c=i(816),l=i(394),h=Object.getOwnPropertyDescriptor;t.f=n?h:function(e,t){if(e=s(e),t=a(t,!0),l)try{return h(e,t)}catch(e){}if(c(e,t))return o(!r.f.call(e,t),e[t])}},151:(e,t,i)=>{var n=i(140),r=i(837).concat("length","prototype");t.f=Object.getOwnPropertyNames||function(e){return n(e,r)}},894:(e,t)=>{t.f=Object.getOwnPropertySymbols},140:(e,t,i)=>{var n=i(816),r=i(905),o=i(540).indexOf,s=i(977);e.exports=function(e,t){var i,a=r(e),c=0,l=[];for(i in a)!n(s,i)&&n(a,i)&&l.push(i);for(;t.length>c;)n(a,i=t[c++])&&(~o(l,i)||l.push(i));return l}},195:(e,t)=>{"use strict";var i={}.propertyIsEnumerable,n=Object.getOwnPropertyDescriptor,r=n&&!i.call({1:2},1);t.f=r?function(e){var t=n(this,e);return!!t&&t.enumerable}:i},826:(e,t,i)=>{var n=i(230),r=i(151),o=i(894),s=i(176);e.exports=n("Reflect","ownKeys")||function(e){var t=r.f(s(e)),i=o.f;return i?t.concat(i(e)):t}},276:(e,t,i)=>{e.exports=i(859)},487:(e,t,i)=>{var n=i(859),r=i(36),o=i(762),s=i(816),a=i(333),c=i(379),l=i(407),h=l.get,u=l.enforce,d=String(c).split("toString");r("inspectSource",(function(e){return c.call(e)})),(e.exports=function(e,t,i,r){var c=!!r&&!!r.unsafe,l=!!r&&!!r.enumerable,h=!!r&&!!r.noTargetGet;"function"==typeof i&&("string"!=typeof t||s(i,"name")||o(i,"name",t),u(i).source=d.join("string"==typeof t?t:"")),e!==n?(c?!h&&e[t]&&(l=!0):delete e[t],l?e[t]=i:o(e,t,i)):l?e[t]=i:a(t,i)})(Function.prototype,"toString",(function(){return"function"==typeof this&&h(this).source||c.call(this)}))},885:e=>{e.exports=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e}},333:(e,t,i)=>{var n=i(859),r=i(762);e.exports=function(e,t){try{r(n,e,t)}catch(i){n[e]=t}return t}},399:(e,t,i)=>{var n=i(36),r=i(441),o=n("keys");e.exports=function(e){return o[e]||(o[e]=r(e))}},353:(e,t,i)=>{var n=i(859),r=i(333),o="__core-js_shared__",s=n[o]||r(o,{});e.exports=s},36:(e,t,i)=>{var n=i(231),r=i(353);(e.exports=function(e,t){return r[e]||(r[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.3.5",mode:n?"pure":"global",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})},357:(e,t,i)=>{var n=i(51),r=Math.max,o=Math.min;e.exports=function(e,t){var i=n(e);return i<0?r(i+t,0):o(i,t)}},905:(e,t,i)=>{var n=i(337),r=i(885);e.exports=function(e){return n(r(e))}},51:e=>{var t=Math.ceil,i=Math.floor;e.exports=function(e){return isNaN(e=+e)?0:(e>0?i:t)(e)}},237:(e,t,i)=>{var n=i(51),r=Math.min;e.exports=function(e){return e>0?r(n(e),9007199254740991):0}},66:(e,t,i)=>{var n=i(52);e.exports=function(e,t){if(!n(e))return e;var i,r;if(t&&"function"==typeof(i=e.toString)&&!n(r=i.call(e)))return r;if("function"==typeof(i=e.valueOf)&&!n(r=i.call(e)))return r;if(!t&&"function"==typeof(i=e.toString)&&!n(r=i.call(e)))return r;throw TypeError("Can't convert object to primitive value")}},441:e=>{var t=0,i=Math.random();e.exports=function(e){return"Symbol("+String(void 0===e?"":e)+")_"+(++t+i).toString(36)}},173:(e,t,i)=>{i(103)({global:!0},{globalThis:i(859)})},421:(e,t,i)=>{e.exports=function e(t,i,n){function r(s,a){if(!i[s]){if(!t[s]){if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=i[s]={exports:{}};t[s][0].call(l.exports,(function(e){return r(t[s][1][e]||e)}),l,l.exports,e,t,i,n)}return i[s].exports}for(var o=void 0,s=0;s<n.length;s++)r(n[s]);return r}({1:[function(e,t,n){(function(i,n){(function(){"use strict";const r=e("events").EventEmitter,o=e("./store"),s=e("./topic-alias-recv"),a=e("./topic-alias-send"),c=e("mqtt-packet"),l=e("./default-message-id-provider"),h=e("readable-stream").Writable,u=e("inherits"),d=e("reinterval"),f=e("rfdc/default"),p=e("./validations"),v=e("xtend"),x=e("debug")("mqttjs:client"),g=i?i.nextTick:function(e){setTimeout(e,0)},y=n.setImmediate||function(e){g(e)},m={keepalive:60,reschedulePings:!0,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:1e3,connectTimeout:3e4,clean:!0,resubscribe:!0},b=["ECONNREFUSED","EADDRINUSE","ECONNRESET","ENOTFOUND"],w={0:"",1:"Unacceptable protocol version",2:"Identifier rejected",3:"Server unavailable",4:"Bad username or password",5:"Not authorized",16:"No matching subscribers",17:"No subscription existed",128:"Unspecified error",129:"Malformed Packet",130:"Protocol Error",131:"Implementation specific error",132:"Unsupported Protocol Version",133:"Client Identifier not valid",134:"Bad User Name or Password",135:"Not authorized",136:"Server unavailable",137:"Server busy",138:"Banned",139:"Server shutting down",140:"Bad authentication method",141:"Keep Alive timeout",142:"Session taken over",143:"Topic Filter invalid",144:"Topic Name invalid",145:"Packet identifier in use",146:"Packet Identifier not found",147:"Receive Maximum exceeded",148:"Topic Alias invalid",149:"Packet too large",150:"Message rate too high",151:"Quota exceeded",152:"Administrative action",153:"Payload format invalid",154:"Retain not supported",155:"QoS not supported",156:"Use another server",157:"Server moved",158:"Shared Subscriptions not supported",159:"Connection rate exceeded",160:"Maximum connect time",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"};function _(e,t){let i;t.properties&&(i=t.properties.topicAlias);let n=t.topic.toString();if(0===n.length){if(void 0===i)return new Error("Unregistered Topic Alias");if(void 0===(n=e.topicAliasSend.getTopicByAlias(i)))return new Error("Unregistered Topic Alias");t.topic=n}i&&delete t.properties.topicAlias}function k(e,t,i){x("sendPacket :: packet: %O",t),x("sendPacket :: emitting `packetsend`"),e.emit("packetsend",t),x("sendPacket :: writing to stream");const n=c.writeToStream(t,e.stream,e.options);x("sendPacket :: writeToStream result %s",n),!n&&i&&i!==A?(x("sendPacket :: handle events on `drain` once through callback."),e.stream.once("drain",i)):i&&(x("sendPacket :: invoking cb"),i())}function T(e,t,i,n){x("storeAndSend :: store packet with cmd %s to outgoingStore",t.cmd);let r,o=t;if("publish"===o.cmd&&(o=f(t),r=_(e,o)))return i&&i(r);e.outgoingStore.put(o,(function(r){if(r)return i&&i(r);n(),k(e,t,i)}))}function A(e){x("nop ::",e)}function S(e,t){let i;const n=this;if(!(this instanceof S))return new S(e,t);for(i in this.options=t||{},m)void 0===this.options[i]?this.options[i]=m[i]:this.options[i]=t[i];x("MqttClient :: options.protocol",t.protocol),x("MqttClient :: options.protocolVersion",t.protocolVersion),x("MqttClient :: options.username",t.username),x("MqttClient :: options.keepalive",t.keepalive),x("MqttClient :: options.reconnectPeriod",t.reconnectPeriod),x("MqttClient :: options.rejectUnauthorized",t.rejectUnauthorized),x("MqttClient :: options.topicAliasMaximum",t.topicAliasMaximum),this.options.clientId="string"==typeof t.clientId?t.clientId:"mqttjs_"+Math.random().toString(16).substr(2,8),x("MqttClient :: clientId",this.options.clientId),this.options.customHandleAcks=5===t.protocolVersion&&t.customHandleAcks?t.customHandleAcks:function(){arguments[3](0)},this.streamBuilder=e,this.messageIdProvider=void 0===this.options.messageIdProvider?new l:this.options.messageIdProvider,this.outgoingStore=t.outgoingStore||new o,this.incomingStore=t.incomingStore||new o,this.queueQoSZero=void 0===t.queueQoSZero||t.queueQoSZero,this._resubscribeTopics={},this.messageIdToTopic={},this.pingTimer=null,this.connected=!1,this.disconnecting=!1,this.queue=[],this.connackTimer=null,this.reconnectTimer=null,this._storeProcessing=!1,this._packetIdsDuringStoreProcessing={},this._storeProcessingQueue=[],this.outgoing={},this._firstConnection=!0,t.topicAliasMaximum>0&&(t.topicAliasMaximum>65535?x("MqttClient :: options.topicAliasMaximum is out of range"):this.topicAliasRecv=new s(t.topicAliasMaximum)),this.on("connect",(function(){const e=this.queue;x("connect :: sending queued packets"),function t(){const i=e.shift();x("deliver :: entry %o",i);let r=null;if(!i)return void n._resubscribe();r=i.packet,x("deliver :: call _sendPacket for %o",r);let o=!0;r.messageId&&0!==r.messageId&&(n.messageIdProvider.register(r.messageId)||(o=!1)),o?n._sendPacket(r,(function(e){i.cb&&i.cb(e),t()})):(x("messageId: %d has already used. The message is skipped and removed.",r.messageId),t())}()})),this.on("close",(function(){x("close :: connected set to `false`"),this.connected=!1,x("close :: clearing connackTimer"),clearTimeout(this.connackTimer),x("close :: clearing ping timer"),null!==n.pingTimer&&(n.pingTimer.clear(),n.pingTimer=null),this.topicAliasRecv&&this.topicAliasRecv.clear(),x("close :: calling _setupReconnect"),this._setupReconnect()})),r.call(this),x("MqttClient :: setting up stream"),this._setupStream()}u(S,r),S.prototype._setupStream=function(){const e=this,t=new h,i=c.parser(this.options);let n=null;const r=[];function o(){if(r.length)g(s);else{const e=n;n=null,e()}}function s(){x("work :: getting next packet in queue");const t=r.shift();if(t)x("work :: packet pulled from queue"),e._handlePacket(t,o);else{x("work :: no packets in queue");const e=n;n=null,x("work :: done flag is %s",!!e),e&&e()}}x("_setupStream :: calling method to clear reconnect"),this._clearReconnect(),x("_setupStream :: using streamBuilder provided to client to create stream"),this.stream=this.streamBuilder(this),i.on("packet",(function(e){x("parser :: on packet push to packets array."),r.push(e)})),t._write=function(e,t,r){n=r,x("writable stream :: parsing buffer"),i.parse(e),s()},x("_setupStream :: pipe stream to writable stream"),this.stream.pipe(t),this.stream.on("error",(function(t){x("streamErrorHandler :: error",t.message),b.includes(t.code)?(x("streamErrorHandler :: emitting error"),e.emit("error",t)):A(t)})),this.stream.on("close",(function(){var t;x("(%s)stream :: on close",e.options.clientId),(t=e.outgoing)&&(x("flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"),Object.keys(t).forEach((function(e){t[e].volatile&&"function"==typeof t[e].cb&&(t[e].cb(new Error("Connection closed")),delete t[e])}))),x("stream: emit close to MqttClient"),e.emit("close")})),x("_setupStream: sending packet `connect`");const a=Object.create(this.options);if(a.cmd="connect",this.topicAliasRecv&&(a.properties||(a.properties={}),this.topicAliasRecv&&(a.properties.topicAliasMaximum=this.topicAliasRecv.max)),k(this,a),i.on("error",this.emit.bind(this,"error")),this.options.properties){if(!this.options.properties.authenticationMethod&&this.options.properties.authenticationData)return e.end((()=>this.emit("error",new Error("Packet has no Authentication Method")))),this;this.options.properties.authenticationMethod&&this.options.authPacket&&"object"==typeof this.options.authPacket&&k(this,v({cmd:"auth",reasonCode:0},this.options.authPacket))}this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout((function(){x("!!connectTimeout hit!! Calling _cleanUp with force `true`"),e._cleanUp(!0)}),this.options.connectTimeout)},S.prototype._handlePacket=function(e,t){const i=this.options;if(5===i.protocolVersion&&i.properties&&i.properties.maximumPacketSize&&i.properties.maximumPacketSize<e.length)return this.emit("error",new Error("exceeding packets size "+e.cmd)),this.end({reasonCode:149,properties:{reasonString:"Maximum packet size was exceeded"}}),this;switch(x("_handlePacket :: emitting packetreceive"),this.emit("packetreceive",e),e.cmd){case"publish":this._handlePublish(e,t);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":this._handleAck(e),t();break;case"pubrel":this._handlePubrel(e,t);break;case"connack":this._handleConnack(e),t();break;case"auth":this._handleAuth(e),t();break;case"pingresp":this._handlePingresp(e),t();break;case"disconnect":this._handleDisconnect(e),t()}},S.prototype._checkDisconnecting=function(e){return this.disconnecting&&(e&&e!==A?e(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting},S.prototype.publish=function(e,t,i,n){x("publish :: message `%s` to topic `%s`",t,e);const r=this.options;if("function"==typeof i&&(n=i,i=null),i=v({qos:0,retain:!1,dup:!1},i),this._checkDisconnecting(n))return this;const o=this,s=function(){let s=0;if((1===i.qos||2===i.qos)&&null===(s=o._nextId()))return x("No messageId left"),!1;const a={cmd:"publish",topic:e,payload:t,qos:i.qos,retain:i.retain,messageId:s,dup:i.dup};switch(5===r.protocolVersion&&(a.properties=i.properties),x("publish :: qos",i.qos),i.qos){case 1:case 2:o.outgoing[a.messageId]={volatile:!1,cb:n||A},x("MqttClient:publish: packet cmd: %s",a.cmd),o._sendPacket(a,void 0,i.cbStorePut);break;default:x("MqttClient:publish: packet cmd: %s",a.cmd),o._sendPacket(a,n,i.cbStorePut)}return!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!s())&&this._storeProcessingQueue.push({invoke:s,cbStorePut:i.cbStorePut,callback:n}),this},S.prototype.subscribe=function(){const e=this,t=new Array(arguments.length);for(let e=0;e<arguments.length;e++)t[e]=arguments[e];const i=[];let n=t.shift();const r=n.resubscribe;let o=t.pop()||A,s=t.pop();const a=this.options.protocolVersion;delete n.resubscribe,"string"==typeof n&&(n=[n]),"function"!=typeof o&&(s=o,o=A);const c=p.validateTopics(n);if(null!==c)return y(o,new Error("Invalid topic "+c)),this;if(this._checkDisconnecting(o))return x("subscribe: discconecting true"),this;const l={qos:0};if(5===a&&(l.nl=!1,l.rap=!1,l.rh=0),s=v(l,s),Array.isArray(n)?n.forEach((function(t){if(x("subscribe: array topic %s",t),!Object.prototype.hasOwnProperty.call(e._resubscribeTopics,t)||e._resubscribeTopics[t].qos<s.qos||r){const e={topic:t,qos:s.qos};5===a&&(e.nl=s.nl,e.rap=s.rap,e.rh=s.rh,e.properties=s.properties),x("subscribe: pushing topic `%s` and qos `%s` to subs list",e.topic,e.qos),i.push(e)}})):Object.keys(n).forEach((function(t){if(x("subscribe: object topic %s",t),!Object.prototype.hasOwnProperty.call(e._resubscribeTopics,t)||e._resubscribeTopics[t].qos<n[t].qos||r){const e={topic:t,qos:n[t].qos};5===a&&(e.nl=n[t].nl,e.rap=n[t].rap,e.rh=n[t].rh,e.properties=s.properties),x("subscribe: pushing `%s` to subs list",e),i.push(e)}})),!i.length)return o(null,[]),this;const h=function(){const t=e._nextId();if(null===t)return x("No messageId left"),!1;const n={cmd:"subscribe",subscriptions:i,qos:1,retain:!1,dup:!1,messageId:t};if(s.properties&&(n.properties=s.properties),e.options.resubscribe){x("subscribe :: resubscribe true");const t=[];i.forEach((function(i){if(e.options.reconnectPeriod>0){const n={qos:i.qos};5===a&&(n.nl=i.nl||!1,n.rap=i.rap||!1,n.rh=i.rh||0,n.properties=i.properties),e._resubscribeTopics[i.topic]=n,t.push(i.topic)}})),e.messageIdToTopic[n.messageId]=t}return e.outgoing[n.messageId]={volatile:!0,cb:function(e,t){if(!e){const e=t.granted;for(let t=0;t<e.length;t+=1)i[t].qos=e[t]}o(e,i)}},x("subscribe :: call _sendPacket"),e._sendPacket(n),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!h())&&this._storeProcessingQueue.push({invoke:h,callback:o}),this},S.prototype.unsubscribe=function(){const e=this,t=new Array(arguments.length);for(let e=0;e<arguments.length;e++)t[e]=arguments[e];let i=t.shift(),n=t.pop()||A,r=t.pop();"string"==typeof i&&(i=[i]),"function"!=typeof n&&(r=n,n=A);const o=p.validateTopics(i);if(null!==o)return y(n,new Error("Invalid topic "+o)),this;if(e._checkDisconnecting(n))return this;const s=function(){const t=e._nextId();if(null===t)return x("No messageId left"),!1;const o={cmd:"unsubscribe",qos:1,messageId:t};return"string"==typeof i?o.unsubscriptions=[i]:Array.isArray(i)&&(o.unsubscriptions=i),e.options.resubscribe&&o.unsubscriptions.forEach((function(t){delete e._resubscribeTopics[t]})),"object"==typeof r&&r.properties&&(o.properties=r.properties),e.outgoing[o.messageId]={volatile:!0,cb:n},x("unsubscribe: call _sendPacket"),e._sendPacket(o),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!s())&&this._storeProcessingQueue.push({invoke:s,callback:n}),this},S.prototype.end=function(e,t,i){const n=this;function r(){x("end :: (%s) :: finish :: calling _cleanUp with force %s",n.options.clientId,e),n._cleanUp(e,(()=>{x("end :: finish :: calling process.nextTick on closeStores"),g(function(){x("end :: closeStores: closing incoming and outgoing stores"),n.disconnected=!0,n.incomingStore.close((function(e){n.outgoingStore.close((function(t){if(x("end :: closeStores: emitting end"),n.emit("end"),i){const n=e||t;x("end :: closeStores: invoking callback with args"),i(n)}}))})),n._deferredReconnect&&n._deferredReconnect()}.bind(n))}),t)}return x("end :: (%s)",this.options.clientId),null!=e&&"boolean"==typeof e||(i=t||A,t=e,e=!1,"object"!=typeof t&&(i=t,t=null,"function"!=typeof i&&(i=A))),"object"!=typeof t&&(i=t,t=null),x("end :: cb? %s",!!i),i=i||A,this.disconnecting?(i(),this):(this._clearReconnect(),this.disconnecting=!0,!e&&Object.keys(this.outgoing).length>0?(x("end :: (%s) :: calling finish in 10ms once outgoing is empty",n.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,r,10))):(x("end :: (%s) :: immediately calling finish",n.options.clientId),r()),this)},S.prototype.removeOutgoingMessage=function(e){const t=this.outgoing[e]?this.outgoing[e].cb:null;return delete this.outgoing[e],this.outgoingStore.del({messageId:e},(function(){t(new Error("Message removed"))})),this},S.prototype.reconnect=function(e){x("client reconnect");const t=this,i=function(){e?(t.options.incomingStore=e.incomingStore,t.options.outgoingStore=e.outgoingStore):(t.options.incomingStore=null,t.options.outgoingStore=null),t.incomingStore=t.options.incomingStore||new o,t.outgoingStore=t.options.outgoingStore||new o,t.disconnecting=!1,t.disconnected=!1,t._deferredReconnect=null,t._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=i:i(),this},S.prototype._reconnect=function(){x("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end((()=>{this._setupStream()})),x("client already connected. disconnecting first.")):(x("_reconnect: calling _setupStream"),this._setupStream())},S.prototype._setupReconnect=function(){const e=this;!e.disconnecting&&!e.reconnectTimer&&e.options.reconnectPeriod>0?(this.reconnecting||(x("_setupReconnect :: emit `offline` state"),this.emit("offline"),x("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),x("_setupReconnect :: setting reconnectTimer for %d ms",e.options.reconnectPeriod),e.reconnectTimer=setInterval((function(){x("reconnectTimer :: reconnect triggered!"),e._reconnect()}),e.options.reconnectPeriod)):x("_setupReconnect :: doing nothing...")},S.prototype._clearReconnect=function(){x("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},S.prototype._cleanUp=function(e,t){const i=arguments[2];if(t&&(x("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",t)),x("_cleanUp :: forced? %s",e),e)0===this.options.reconnectPeriod&&this.options.clean&&(n=this.outgoing)&&(x("flush: queue exists? %b",!!n),Object.keys(n).forEach((function(e){"function"==typeof n[e].cb&&(n[e].cb(new Error("Connection closed")),delete n[e])}))),x("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{const e=v({cmd:"disconnect"},i);x("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(e,y.bind(null,this.stream.end.bind(this.stream)))}var n;this.disconnecting||(x("_cleanUp :: client not disconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),null!==this.pingTimer&&(x("_cleanUp :: clearing pingTimer"),this.pingTimer.clear(),this.pingTimer=null),t&&!this.connected&&(x("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",t),t())},S.prototype._sendPacket=function(e,t,i){x("_sendPacket :: (%s) :: start",this.options.clientId),i=i||A,t=t||A;const n=function(e,t){if(5===e.options.protocolVersion&&"publish"===t.cmd){let i;t.properties&&(i=t.properties.topicAlias);const n=t.topic.toString();if(e.topicAliasSend)if(i){if(0!==n.length&&(x("applyTopicAlias :: register topic: %s - alias: %d",n,i),!e.topicAliasSend.put(n,i)))return x("applyTopicAlias :: error out of range. topic: %s - alias: %d",n,i),new Error("Sending Topic Alias out of range")}else 0!==n.length&&(e.options.autoAssignTopicAlias?(i=e.topicAliasSend.getAliasByTopic(n))?(t.topic="",t.properties={...t.properties,topicAlias:i},x("applyTopicAlias :: auto assign(use) topic: %s - alias: %d",n,i)):(i=e.topicAliasSend.getLruAlias(),e.topicAliasSend.put(n,i),t.properties={...t.properties,topicAlias:i},x("applyTopicAlias :: auto assign topic: %s - alias: %d",n,i)):e.options.autoUseTopicAlias&&(i=e.topicAliasSend.getAliasByTopic(n))&&(t.topic="",t.properties={...t.properties,topicAlias:i},x("applyTopicAlias :: auto use topic: %s - alias: %d",n,i)));else if(i)return x("applyTopicAlias :: error out of range. topic: %s - alias: %d",n,i),new Error("Sending Topic Alias out of range")}}(this,e);if(n)t(n);else{if(!this.connected)return"auth"===e.cmd?(this._shiftPingInterval(),void k(this,e,t)):(x("_sendPacket :: client not connected. Storing packet offline."),void this._storePacket(e,t,i));switch(this._shiftPingInterval(),e.cmd){case"publish":break;case"pubrel":return void T(this,e,t,i);default:return void k(this,e,t)}switch(e.qos){case 2:case 1:T(this,e,t,i);break;default:k(this,e,t)}x("_sendPacket :: (%s) :: end",this.options.clientId)}},S.prototype._storePacket=function(e,t,i){x("_storePacket :: packet: %o",e),x("_storePacket :: cb? %s",!!t),i=i||A;let n=e;if("publish"===n.cmd){const i=_(this,n=f(e));if(i)return t&&t(i)}0===(n.qos||0)&&this.queueQoSZero||"publish"!==n.cmd?this.queue.push({packet:n,cb:t}):n.qos>0?(t=this.outgoing[n.messageId]?this.outgoing[n.messageId].cb:null,this.outgoingStore.put(n,(function(e){if(e)return t&&t(e);i()}))):t&&t(new Error("No connection to broker"))},S.prototype._setupPingTimer=function(){x("_setupPingTimer :: keepalive %d (seconds)",this.options.keepalive);const e=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=d((function(){e._checkPing()}),1e3*this.options.keepalive))},S.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},S.prototype._checkPing=function(){x("_checkPing :: checking ping..."),this.pingResp?(x("_checkPing :: ping response received. Clearing flag and sending `pingreq`"),this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):(x("_checkPing :: calling _cleanUp with force true"),this._cleanUp(!0))},S.prototype._handlePingresp=function(){this.pingResp=!0},S.prototype._handleConnack=function(e){x("_handleConnack");const t=this.options,i=5===t.protocolVersion?e.reasonCode:e.returnCode;if(clearTimeout(this.connackTimer),delete this.topicAliasSend,e.properties){if(e.properties.topicAliasMaximum){if(e.properties.topicAliasMaximum>65535)return void this.emit("error",new Error("topicAliasMaximum from broker is out of range"));e.properties.topicAliasMaximum>0&&(this.topicAliasSend=new a(e.properties.topicAliasMaximum))}e.properties.serverKeepAlive&&t.keepalive&&(t.keepalive=e.properties.serverKeepAlive,this._shiftPingInterval()),e.properties.maximumPacketSize&&(t.properties||(t.properties={}),t.properties.maximumPacketSize=e.properties.maximumPacketSize)}if(0===i)this.reconnecting=!1,this._onConnect(e);else if(i>0){const e=new Error("Connection refused: "+w[i]);e.code=i,this.emit("error",e)}},S.prototype._handleAuth=function(e){const t=this.options.protocolVersion,i=5===t?e.reasonCode:e.returnCode;if(5!==t){const e=new Error("Protocol error: Auth packets are only supported in MQTT 5. Your version:"+t);return e.code=i,void this.emit("error",e)}const n=this;this.handleAuth(e,(function(e,t){if(e)n.emit("error",e);else if(24===i)n.reconnecting=!1,n._sendPacket(t);else{const t=new Error("Connection refused: "+w[i]);e.code=i,n.emit("error",t)}}))},S.prototype.handleAuth=function(e,t){t()},S.prototype._handlePublish=function(e,t){x("_handlePublish: packet %o",e),t=void 0!==t?t:A;let i=e.topic.toString();const n=e.payload,r=e.qos,o=e.messageId,s=this,a=this.options,c=[0,16,128,131,135,144,145,151,153];if(5===this.options.protocolVersion){let t;if(e.properties&&(t=e.properties.topicAlias),void 0!==t)if(0===i.length){if(!(t>0&&t<=65535))return x("_handlePublish :: topic alias out of range. alias: %d",t),void this.emit("error",new Error("Received Topic Alias is out of range"));{const e=this.topicAliasRecv.getTopicByAlias(t);if(!e)return x("_handlePublish :: unregistered topic alias. alias: %d",t),void this.emit("error",new Error("Received unregistered Topic Alias"));x("_handlePublish :: topic complemented by alias. topic: %s - alias: %d",i=e,t)}}else{if(!this.topicAliasRecv.put(i,t))return x("_handlePublish :: topic alias out of range. alias: %d",t),void this.emit("error",new Error("Received Topic Alias is out of range"));x("_handlePublish :: registered topic: %s - alias: %d",i,t)}}switch(x("_handlePublish: qos %d",r),r){case 2:a.customHandleAcks(i,n,e,(function(i,n){return i instanceof Error||(n=i,i=null),i?s.emit("error",i):-1===c.indexOf(n)?s.emit("error",new Error("Wrong reason code for pubrec")):void(n?s._sendPacket({cmd:"pubrec",messageId:o,reasonCode:n},t):s.incomingStore.put(e,(function(){s._sendPacket({cmd:"pubrec",messageId:o},t)})))}));break;case 1:a.customHandleAcks(i,n,e,(function(r,a){return r instanceof Error||(a=r,r=null),r?s.emit("error",r):-1===c.indexOf(a)?s.emit("error",new Error("Wrong reason code for puback")):(a||s.emit("message",i,n,e),void s.handleMessage(e,(function(e){if(e)return t&&t(e);s._sendPacket({cmd:"puback",messageId:o,reasonCode:a},t)})))}));break;case 0:this.emit("message",i,n,e),this.handleMessage(e,t);break;default:x("_handlePublish: unknown QoS. Doing nothing.")}},S.prototype.handleMessage=function(e,t){t()},S.prototype._handleAck=function(e){const t=e.messageId,i=e.cmd;let n=null;const r=this.outgoing[t]?this.outgoing[t].cb:null,o=this;let s;if(r){switch(x("_handleAck :: packet type",i),i){case"pubcomp":case"puback":{const i=e.reasonCode;i&&i>0&&16!==i&&((s=new Error("Publish error: "+w[i])).code=i,r(s,e)),delete this.outgoing[t],this.outgoingStore.del(e,r),this.messageIdProvider.deallocate(t),this._invokeStoreProcessingQueue();break}case"pubrec":{n={cmd:"pubrel",qos:2,messageId:t};const i=e.reasonCode;i&&i>0&&16!==i?((s=new Error("Publish error: "+w[i])).code=i,r(s,e)):this._sendPacket(n);break}case"suback":delete this.outgoing[t],this.messageIdProvider.deallocate(t);for(let i=0;i<e.granted.length;i++)if(0!=(128&e.granted[i])){const e=this.messageIdToTopic[t];e&&e.forEach((function(e){delete o._resubscribeTopics[e]}))}this._invokeStoreProcessingQueue(),r(null,e);break;case"unsuback":delete this.outgoing[t],this.messageIdProvider.deallocate(t),this._invokeStoreProcessingQueue(),r(null);break;default:o.emit("error",new Error("unrecognized packet type"))}this.disconnecting&&0===Object.keys(this.outgoing).length&&this.emit("outgoingEmpty")}else x("_handleAck :: Server sent an ack in error. Ignoring.")},S.prototype._handlePubrel=function(e,t){x("handling pubrel packet"),t=void 0!==t?t:A;const i=this,n={cmd:"pubcomp",messageId:e.messageId};i.incomingStore.get(e,(function(e,r){e?i._sendPacket(n,t):(i.emit("message",r.topic,r.payload,r),i.handleMessage(r,(function(e){if(e)return t(e);i.incomingStore.del(r,A),i._sendPacket(n,t)})))}))},S.prototype._handleDisconnect=function(e){this.emit("disconnect",e)},S.prototype._nextId=function(){return this.messageIdProvider.allocate()},S.prototype.getLastMessageId=function(){return this.messageIdProvider.getLastAllocated()},S.prototype._resubscribe=function(){x("_resubscribe");const e=Object.keys(this._resubscribeTopics);if(!this._firstConnection&&(this.options.clean||5===this.options.protocolVersion&&!this.connackPacket.sessionPresent)&&e.length>0)if(this.options.resubscribe)if(5===this.options.protocolVersion){x("_resubscribe: protocolVersion 5");for(let t=0;t<e.length;t++){const i={};i[e[t]]=this._resubscribeTopics[e[t]],i.resubscribe=!0,this.subscribe(i,{properties:i[e[t]].properties})}}else this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics);else this._resubscribeTopics={};this._firstConnection=!1},S.prototype._onConnect=function(e){if(this.disconnected)return void this.emit("connect",e);const t=this;this.connackPacket=e,this.messageIdProvider.clear(),this._setupPingTimer(),this.connected=!0,function i(){let n=t.outgoingStore.createStream();function r(){t._storeProcessing=!1,t._packetIdsDuringStoreProcessing={}}function o(){n.destroy(),n=null,t._flushStoreProcessingQueue(),r()}t.once("close",o),n.on("error",(function(e){r(),t._flushStoreProcessingQueue(),t.removeListener("close",o),t.emit("error",e)})),n.on("end",(function(){let n=!0;for(const e in t._packetIdsDuringStoreProcessing)if(!t._packetIdsDuringStoreProcessing[e]){n=!1;break}n?(r(),t.removeListener("close",o),t._invokeAllStoreProcessingQueue(),t.emit("connect",e)):i()})),function e(){if(!n)return;t._storeProcessing=!0;const i=n.read(1);let r;i?t._packetIdsDuringStoreProcessing[i.messageId]?e():t.disconnecting||t.reconnectTimer?n.destroy&&n.destroy():(r=t.outgoing[i.messageId]?t.outgoing[i.messageId].cb:null,t.outgoing[i.messageId]={volatile:!1,cb:function(t,i){r&&r(t,i),e()}},t._packetIdsDuringStoreProcessing[i.messageId]=!0,t.messageIdProvider.register(i.messageId)?t._sendPacket(i):x("messageId: %d has already used.",i.messageId)):n.once("readable",e)}()}()},S.prototype._invokeStoreProcessingQueue=function(){if(this._storeProcessingQueue.length>0){const e=this._storeProcessingQueue[0];if(e&&e.invoke())return this._storeProcessingQueue.shift(),!0}return!1},S.prototype._invokeAllStoreProcessingQueue=function(){for(;this._invokeStoreProcessingQueue(););},S.prototype._flushStoreProcessingQueue=function(){for(const e of this._storeProcessingQueue)e.cbStorePut&&e.cbStorePut(new Error("Connection closed")),e.callback&&e.callback(new Error("Connection closed"));this._storeProcessingQueue.splice(0)},t.exports=S}).call(this)}).call(this,e("_process"),void 0!==i.g?i.g:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./default-message-id-provider":7,"./store":8,"./topic-alias-recv":9,"./topic-alias-send":10,"./validations":11,_process:50,debug:18,events:22,inherits:24,"mqtt-packet":40,"readable-stream":69,reinterval:70,"rfdc/default":71,xtend:81}],2:[function(e,t,i){"use strict";const{Buffer:n}=e("buffer"),r=e("readable-stream").Transform,o=e("duplexify");let s,a,c,l=!1;t.exports=function(e,t){if(t.hostname=t.hostname||t.host,!t.hostname)throw new Error("Could not determine host. Specify host manually.");const i="MQIsdp"===t.protocolId&&3===t.protocolVersion?"mqttv3.1":"mqtt";!function(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}(t);const h=function(e,t){const i="alis"===e.protocol?"wss":"ws";let n=i+"://"+e.hostname+e.path;return e.port&&80!==e.port&&443!==e.port&&(n=i+"://"+e.hostname+":"+e.port+e.path),"function"==typeof e.transformWsUrl&&(n=e.transformWsUrl(n,e,t)),n}(t,e);return(s=t.my).connectSocket({url:h,protocols:i}),a=function(){const e=new r;return e._write=function(e,t,i){s.sendSocketMessage({data:e.buffer,success:function(){i()},fail:function(){i(new Error)}})},e._flush=function(e){s.closeSocket({success:function(){e()}})},e}(),c=o.obj(),l||(l=!0,s.onSocketOpen((function(){c.setReadable(a),c.setWritable(a),c.emit("connect")})),s.onSocketMessage((function(e){if("string"==typeof e.data){const t=n.from(e.data,"base64");a.push(t)}else{const t=new FileReader;t.addEventListener("load",(function(){let e=t.result;e=e instanceof ArrayBuffer?n.from(e):n.from(e,"utf8"),a.push(e)})),t.readAsArrayBuffer(e.data)}})),s.onSocketClose((function(){c.end(),c.destroy()})),s.onSocketError((function(e){c.destroy(e)}))),c}},{buffer:17,duplexify:20,"readable-stream":69}],3:[function(e,t,i){"use strict";const n=e("net"),r=e("debug")("mqttjs:tcp");t.exports=function(e,t){t.port=t.port||1883,t.hostname=t.hostname||t.host||"localhost";const i=t.port,o=t.hostname;return r("port %d and host %s",i,o),n.createConnection(i,o)}},{debug:18,net:16}],4:[function(e,t,i){"use strict";const n=e("tls"),r=e("net"),o=e("debug")("mqttjs:tls");t.exports=function(e,t){t.port=t.port||8883,t.host=t.hostname||t.host||"localhost",0===r.isIP(t.host)&&(t.servername=t.host),t.rejectUnauthorized=!1!==t.rejectUnauthorized,delete t.path,o("port %d host %s rejectUnauthorized %b",t.port,t.host,t.rejectUnauthorized);const i=n.connect(t);function s(n){t.rejectUnauthorized&&e.emit("error",n),i.end()}return i.on("secureConnect",(function(){t.rejectUnauthorized&&!i.authorized?i.emit("error",new Error("TLS not authorized")):i.removeListener("error",s)})),i.on("error",s),i}},{debug:18,net:16,tls:16}],5:[function(e,t,n){(function(n){(function(){"use strict";const{Buffer:r}=e("buffer"),o=e("ws"),s=e("debug")("mqttjs:ws"),a=e("duplexify"),c=e("readable-stream").Transform,l=["rejectUnauthorized","ca","cert","key","pfx","passphrase"],h=void 0!==n&&"browser"===n.title||"function"==typeof i;function u(e,t){let i=e.protocol+"://"+e.hostname+":"+e.port+e.path;return"function"==typeof e.transformWsUrl&&(i=e.transformWsUrl(i,e,t)),i}function d(e){const t=e;return e.hostname||(t.hostname="localhost"),e.port||("wss"===e.protocol?t.port=443:t.port=80),e.path||(t.path="/"),e.wsOptions||(t.wsOptions={}),h||"wss"!==e.protocol||l.forEach((function(i){Object.prototype.hasOwnProperty.call(e,i)&&!Object.prototype.hasOwnProperty.call(e.wsOptions,i)&&(t.wsOptions[i]=e[i])})),t}t.exports=h?function(e,t){let i;s("browserStreamBuilder");const n=function(e){const t=d(e);if(t.hostname||(t.hostname=t.host),!t.hostname){if("undefined"==typeof document)throw new Error("Could not determine host. Specify host manually.");const e=new URL(document.URL);t.hostname=e.hostname,t.port||(t.port=e.port)}return void 0===t.objectMode&&(t.objectMode=!(!0===t.binary||void 0===t.binary)),t}(t).browserBufferSize||524288,o=t.browserBufferTimeout||1e3,l=!t.objectMode,h=function(e,t){const i="MQIsdp"===t.protocolId&&3===t.protocolVersion?"mqttv3.1":"mqtt",n=u(t,e),r=new WebSocket(n,[i]);return r.binaryType="arraybuffer",r}(e,t),f=function(e,t,i){const n=new c({objectModeMode:e.objectMode});return n._write=t,n._flush=function(e){h.close(),e()},n}(t,(function e(t,i,s){h.bufferedAmount>n&&setTimeout(e,o,t,i,s),l&&"string"==typeof t&&(t=r.from(t,"utf8"));try{h.send(t)}catch(e){return s(e)}s()}));t.objectMode||(f._writev=m),f.on("close",(()=>{h.close()}));const p=void 0!==h.addEventListener;function v(){i.setReadable(f),i.setWritable(f),i.emit("connect")}function x(){i.end(),i.destroy()}function g(e){i.destroy(e)}function y(e){let t=e.data;t=t instanceof ArrayBuffer?r.from(t):r.from(t,"utf8"),f.push(t)}function m(e,t){const i=new Array(e.length);for(let t=0;t<e.length;t++)"string"==typeof e[t].chunk?i[t]=r.from(e[t],"utf8"):i[t]=e[t].chunk;this._write(r.concat(i),"binary",t)}return h.readyState===h.OPEN?i=f:(i=i=a(void 0,void 0,t),t.objectMode||(i._writev=m),p?h.addEventListener("open",v):h.onopen=v),i.socket=h,p?(h.addEventListener("close",x),h.addEventListener("error",g),h.addEventListener("message",y)):(h.onclose=x,h.onerror=g,h.onmessage=y),i}:function(e,t){s("streamBuilder");const i=d(t),n=u(i,e),r=function(e,t,i){s("createWebSocket"),s("protocol: "+i.protocolId+" "+i.protocolVersion);const n="MQIsdp"===i.protocolId&&3===i.protocolVersion?"mqttv3.1":"mqtt";return s("creating new Websocket for url: "+t+" and protocol: "+n),new o(t,[n],i.wsOptions)}(0,n,i),a=o.createWebSocketStream(r,i.wsOptions);return a.url=n,r.on("close",(()=>{a.destroy()})),a}}).call(this)}).call(this,e("_process"))},{_process:50,buffer:17,debug:18,duplexify:20,"readable-stream":69,ws:80}],6:[function(e,t,i){"use strict";const{Buffer:n}=e("buffer"),r=e("readable-stream").Transform,o=e("duplexify");let s,a,c;t.exports=function(e,t){if(t.hostname=t.hostname||t.host,!t.hostname)throw new Error("Could not determine host. Specify host manually.");const i="MQIsdp"===t.protocolId&&3===t.protocolVersion?"mqttv3.1":"mqtt";!function(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}(t);const l=function(e,t){const i="wxs"===e.protocol?"wss":"ws";let n=i+"://"+e.hostname+e.path;return e.port&&80!==e.port&&443!==e.port&&(n=i+"://"+e.hostname+":"+e.port+e.path),"function"==typeof e.transformWsUrl&&(n=e.transformWsUrl(n,e,t)),n}(t,e);s=wx.connectSocket({url:l,protocols:[i]}),a=function(){const e=new r;return e._write=function(e,t,i){s.send({data:e.buffer,success:function(){i()},fail:function(e){i(new Error(e))}})},e._flush=function(e){s.close({success:function(){e()}})},e}(),(c=o.obj())._destroy=function(e,t){s.close({success:function(){t&&t(e)}})};const h=c.destroy;return c.destroy=function(){c.destroy=h;const e=this;setTimeout((function(){s.close({fail:function(){e._destroy(new Error)}})}),0)}.bind(c),s.onOpen((function(){c.setReadable(a),c.setWritable(a),c.emit("connect")})),s.onMessage((function(e){let t=e.data;t=t instanceof ArrayBuffer?n.from(t):n.from(t,"utf8"),a.push(t)})),s.onClose((function(){c.end(),c.destroy()})),s.onError((function(e){c.destroy(new Error(e.errMsg))})),c}},{buffer:17,duplexify:20,"readable-stream":69}],7:[function(e,t,i){"use strict";function n(){if(!(this instanceof n))return new n;this.nextId=Math.max(1,Math.floor(65535*Math.random()))}n.prototype.allocate=function(){const e=this.nextId++;return 65536===this.nextId&&(this.nextId=1),e},n.prototype.getLastAllocated=function(){return 1===this.nextId?65535:this.nextId-1},n.prototype.register=function(e){return!0},n.prototype.deallocate=function(e){},n.prototype.clear=function(){},t.exports=n},{}],8:[function(e,t,i){"use strict";const n=e("xtend"),r=e("readable-stream").Readable,o={objectMode:!0},s={clean:!0};function a(e){if(!(this instanceof a))return new a(e);this.options=e||{},this.options=n(s,e),this._inflights=new Map}a.prototype.put=function(e,t){return this._inflights.set(e.messageId,e),t&&t(),this},a.prototype.createStream=function(){const e=new r(o),t=[];let i=!1,n=0;return this._inflights.forEach((function(e,i){t.push(e)})),e._read=function(){!i&&n<t.length?this.push(t[n++]):this.push(null)},e.destroy=function(){if(i)return;const e=this;i=!0,setTimeout((function(){e.emit("close")}),0)},e},a.prototype.del=function(e,t){return(e=this._inflights.get(e.messageId))?(this._inflights.delete(e.messageId),t(null,e)):t&&t(new Error("missing packet")),this},a.prototype.get=function(e,t){return(e=this._inflights.get(e.messageId))?t(null,e):t&&t(new Error("missing packet")),this},a.prototype.close=function(e){this.options.clean&&(this._inflights=null),e&&e()},t.exports=a},{"readable-stream":69,xtend:81}],9:[function(e,t,i){"use strict";function n(e){if(!(this instanceof n))return new n(e);this.aliasToTopic={},this.max=e}n.prototype.put=function(e,t){return!(0===t||t>this.max||(this.aliasToTopic[t]=e,this.length=Object.keys(this.aliasToTopic).length,0))},n.prototype.getTopicByAlias=function(e){return this.aliasToTopic[e]},n.prototype.clear=function(){this.aliasToTopic={}},t.exports=n},{}],10:[function(e,t,i){"use strict";const n=e("lru-cache"),r=e("number-allocator").NumberAllocator;function o(e){if(!(this instanceof o))return new o(e);e>0&&(this.aliasToTopic=new n({max:e}),this.topicToAlias={},this.numberAllocator=new r(1,e),this.max=e,this.length=0)}o.prototype.put=function(e,t){if(0===t||t>this.max)return!1;const i=this.aliasToTopic.get(t);return i&&delete this.topicToAlias[i],this.aliasToTopic.set(t,e),this.topicToAlias[e]=t,this.numberAllocator.use(t),this.length=this.aliasToTopic.length,!0},o.prototype.getTopicByAlias=function(e){return this.aliasToTopic.get(e)},o.prototype.getAliasByTopic=function(e){const t=this.topicToAlias[e];return void 0!==t&&this.aliasToTopic.get(t),t},o.prototype.clear=function(){this.aliasToTopic.reset(),this.topicToAlias={},this.numberAllocator.clear(),this.length=0},o.prototype.getLruAlias=function(){return this.numberAllocator.firstVacant()||this.aliasToTopic.keys()[this.aliasToTopic.length-1]},t.exports=o},{"lru-cache":37,"number-allocator":46}],11:[function(e,t,i){"use strict";function n(e){const t=e.split("/");for(let e=0;e<t.length;e++)if("+"!==t[e]){if("#"===t[e])return e===t.length-1;if(-1!==t[e].indexOf("+")||-1!==t[e].indexOf("#"))return!1}return!0}t.exports={validateTopics:function(e){if(0===e.length)return"empty_topic_list";for(let t=0;t<e.length;t++)if(!n(e[t]))return e[t];return null}}},{}],12:[function(e,t,n){(function(n){(function(){"use strict";const r=e("../client"),o=e("../store"),s=e("url"),a=e("xtend"),c=e("debug")("mqttjs"),l={};function h(e,t){if(c("connecting to an MQTT broker..."),"object"!=typeof e||t||(t=e,e=null),t=t||{},e){const i=s.parse(e,!0);if(null!=i.port&&(i.port=Number(i.port)),null===(t=a(i,t)).protocol)throw new Error("Missing protocol");t.protocol=t.protocol.replace(/:$/,"")}if(function(e){let t;e.auth&&((t=e.auth.match(/^(.+):(.+)$/))?(e.username=t[1],e.password=t[2]):e.username=e.auth)}(t),t.query&&"string"==typeof t.query.clientId&&(t.clientId=t.query.clientId),t.cert&&t.key){if(!t.protocol)throw new Error("Missing secure protocol key");if(-1===["mqtts","wss","wxs","alis"].indexOf(t.protocol))switch(t.protocol){case"mqtt":t.protocol="mqtts";break;case"ws":t.protocol="wss";break;case"wx":t.protocol="wxs";break;case"ali":t.protocol="alis";break;default:throw new Error('Unknown protocol for secure connection: "'+t.protocol+'"!')}}if(!l[t.protocol]){const e=-1!==["mqtts","wss"].indexOf(t.protocol);t.protocol=["mqtt","mqtts","ws","wss","wx","wxs","ali","alis"].filter((function(t,i){return(!e||i%2!=0)&&"function"==typeof l[t]}))[0]}if(!1===t.clean&&!t.clientId)throw new Error("Missing clientId for unclean clients");t.protocol&&(t.defaultProtocol=t.protocol);const i=new r((function(e){return t.servers&&(e._reconnectCount&&e._reconnectCount!==t.servers.length||(e._reconnectCount=0),t.host=t.servers[e._reconnectCount].host,t.port=t.servers[e._reconnectCount].port,t.protocol=t.servers[e._reconnectCount].protocol?t.servers[e._reconnectCount].protocol:t.defaultProtocol,t.hostname=t.host,e._reconnectCount++),c("calling streambuilder for",t.protocol),l[t.protocol](e,t)}),t);return i.on("error",(function(){})),i}void 0!==n&&"browser"!==n.title||"function"!=typeof i?(l.mqtt=e("./tcp"),l.tcp=e("./tcp"),l.ssl=e("./tls"),l.tls=e("./tls"),l.mqtts=e("./tls")):(l.wx=e("./wx"),l.wxs=e("./wx"),l.ali=e("./ali"),l.alis=e("./ali")),l.ws=e("./ws"),l.wss=e("./ws"),t.exports=h,t.exports.connect=h,t.exports.MqttClient=r,t.exports.Store=o}).call(this)}).call(this,e("_process"))},{"../client":1,"../store":8,"./ali":2,"./tcp":3,"./tls":4,"./ws":5,"./wx":6,_process:50,debug:18,url:76,xtend:81}],13:[function(e,t,i){"use strict";i.byteLength=function(e){var t=l(e),i=t[0],n=t[1];return 3*(i+n)/4-n},i.toByteArray=function(e){var t,i,n=l(e),s=n[0],a=n[1],c=new o(function(e,t,i){return 3*(t+i)/4-i}(0,s,a)),h=0,u=a>0?s-4:s;for(i=0;i<u;i+=4)t=r[e.charCodeAt(i)]<<18|r[e.charCodeAt(i+1)]<<12|r[e.charCodeAt(i+2)]<<6|r[e.charCodeAt(i+3)],c[h++]=t>>16&255,c[h++]=t>>8&255,c[h++]=255&t;return 2===a&&(t=r[e.charCodeAt(i)]<<2|r[e.charCodeAt(i+1)]>>4,c[h++]=255&t),1===a&&(t=r[e.charCodeAt(i)]<<10|r[e.charCodeAt(i+1)]<<4|r[e.charCodeAt(i+2)]>>2,c[h++]=t>>8&255,c[h++]=255&t),c},i.fromByteArray=function(e){for(var t,i=e.length,r=i%3,o=[],s=0,a=i-r;s<a;s+=16383)o.push(h(e,s,s+16383>a?a:s+16383));return 1===r?(t=e[i-1],o.push(n[t>>2]+n[t<<4&63]+"==")):2===r&&(t=(e[i-2]<<8)+e[i-1],o.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"=")),o.join("")};for(var n=[],r=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=s.length;a<c;++a)n[a]=s[a],r[s.charCodeAt(a)]=a;function l(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var i=e.indexOf("=");return-1===i&&(i=t),[i,i===t?0:4-i%4]}function h(e,t,i){for(var r,o,s=[],a=t;a<i;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),s.push(n[(o=r)>>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return s.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},{}],14:[function(e,t,i){"use strict";const{Buffer:n}=e("buffer"),r=Symbol.for("BufferList");function o(e){if(!(this instanceof o))return new o(e);o._init.call(this,e)}o._init=function(e){Object.defineProperty(this,r,{value:!0}),this._bufs=[],this.length=0,e&&this.append(e)},o.prototype._new=function(e){return new o(e)},o.prototype._offset=function(e){if(0===e)return[0,0];let t=0;for(let i=0;i<this._bufs.length;i++){const n=t+this._bufs[i].length;if(e<n||i===this._bufs.length-1)return[i,e-t];t=n}},o.prototype._reverseOffset=function(e){const t=e[0];let i=e[1];for(let e=0;e<t;e++)i+=this._bufs[e].length;return i},o.prototype.get=function(e){if(e>this.length||e<0)return;const t=this._offset(e);return this._bufs[t[0]][t[1]]},o.prototype.slice=function(e,t){return"number"==typeof e&&e<0&&(e+=this.length),"number"==typeof t&&t<0&&(t+=this.length),this.copy(null,0,e,t)},o.prototype.copy=function(e,t,i,r){if(("number"!=typeof i||i<0)&&(i=0),("number"!=typeof r||r>this.length)&&(r=this.length),i>=this.length)return e||n.alloc(0);if(r<=0)return e||n.alloc(0);const o=!!e,s=this._offset(i),a=r-i;let c=a,l=o&&t||0,h=s[1];if(0===i&&r===this.length){if(!o)return 1===this._bufs.length?this._bufs[0]:n.concat(this._bufs,this.length);for(let t=0;t<this._bufs.length;t++)this._bufs[t].copy(e,l),l+=this._bufs[t].length;return e}if(c<=this._bufs[s[0]].length-h)return o?this._bufs[s[0]].copy(e,t,h,h+c):this._bufs[s[0]].slice(h,h+c);o||(e=n.allocUnsafe(a));for(let t=s[0];t<this._bufs.length;t++){const i=this._bufs[t].length-h;if(!(c>i)){this._bufs[t].copy(e,l,h,h+c),l+=i;break}this._bufs[t].copy(e,l,h),l+=i,c-=i,h&&(h=0)}return e.length>l?e.slice(0,l):e},o.prototype.shallowSlice=function(e,t){if(e=e||0,t="number"!=typeof t?this.length:t,e<0&&(e+=this.length),t<0&&(t+=this.length),e===t)return this._new();const i=this._offset(e),n=this._offset(t),r=this._bufs.slice(i[0],n[0]+1);return 0===n[1]?r.pop():r[r.length-1]=r[r.length-1].slice(0,n[1]),0!==i[1]&&(r[0]=r[0].slice(i[1])),this._new(r)},o.prototype.toString=function(e,t,i){return this.slice(t,i).toString(e)},o.prototype.consume=function(e){if(e=Math.trunc(e),Number.isNaN(e)||e<=0)return this;for(;this._bufs.length;){if(!(e>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(e),this.length-=e;break}e-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},o.prototype.duplicate=function(){const e=this._new();for(let t=0;t<this._bufs.length;t++)e.append(this._bufs[t]);return e},o.prototype.append=function(e){if(null==e)return this;if(e.buffer)this._appendBuffer(n.from(e.buffer,e.byteOffset,e.byteLength));else if(Array.isArray(e))for(let t=0;t<e.length;t++)this.append(e[t]);else if(this._isBufferList(e))for(let t=0;t<e._bufs.length;t++)this.append(e._bufs[t]);else"number"==typeof e&&(e=e.toString()),this._appendBuffer(n.from(e));return this},o.prototype._appendBuffer=function(e){this._bufs.push(e),this.length+=e.length},o.prototype.indexOf=function(e,t,i){if(void 0===i&&"string"==typeof t&&(i=t,t=void 0),"function"==typeof e||Array.isArray(e))throw new TypeError('The "value" argument must be one of type string, Buffer, BufferList, or Uint8Array.');if("number"==typeof e?e=n.from([e]):"string"==typeof e?e=n.from(e,i):this._isBufferList(e)?e=e.slice():Array.isArray(e.buffer)?e=n.from(e.buffer,e.byteOffset,e.byteLength):n.isBuffer(e)||(e=n.from(e)),t=Number(t||0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),0===e.length)return t>this.length?this.length:t;const r=this._offset(t);let o=r[0],s=r[1];for(;o<this._bufs.length;o++){const t=this._bufs[o];for(;s<t.length;)if(t.length-s>=e.length){const i=t.indexOf(e,s);if(-1!==i)return this._reverseOffset([o,i]);s=t.length-e.length+1}else{const t=this._reverseOffset([o,s]);if(this._match(t,e))return t;s++}s=0}return-1},o.prototype._match=function(e,t){if(this.length-e<t.length)return!1;for(let i=0;i<t.length;i++)if(this.get(e+i)!==t[i])return!1;return!0},function(){const e={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1,readIntBE:null,readIntLE:null,readUIntBE:null,readUIntLE:null};for(const t in e)!function(t){o.prototype[t]=null===e[t]?function(e,i){return this.slice(e,e+i)[t](0,i)}:function(i=0){return this.slice(i,i+e[t])[t](0)}}(t)}(),o.prototype._isBufferList=function(e){return e instanceof o||o.isBufferList(e)},o.isBufferList=function(e){return null!=e&&e[r]},t.exports=o},{buffer:17}],15:[function(e,t,i){"use strict";const n=e("readable-stream").Duplex,r=e("inherits"),o=e("./BufferList");function s(e){if(!(this instanceof s))return new s(e);if("function"==typeof e){this._callback=e;const t=function(e){this._callback&&(this._callback(e),this._callback=null)}.bind(this);this.on("pipe",(function(e){e.on("error",t)})),this.on("unpipe",(function(e){e.removeListener("error",t)})),e=null}o._init.call(this,e),n.call(this)}r(s,n),Object.assign(s.prototype,o.prototype),s.prototype._new=function(e){return new s(e)},s.prototype._write=function(e,t,i){this._appendBuffer(e),"function"==typeof i&&i()},s.prototype._read=function(e){if(!this.length)return this.push(null);e=Math.min(e,this.length),this.push(this.slice(0,e)),this.consume(e)},s.prototype.end=function(e){n.prototype.end.call(this,e),this._callback&&(this._callback(null,this.slice()),this._callback=null)},s.prototype._destroy=function(e,t){this._bufs.length=0,this.length=0,t(e)},s.prototype._isBufferList=function(e){return e instanceof s||e instanceof o||s.isBufferList(e)},s.isBufferList=o.isBufferList,t.exports=s,t.exports.BufferListStream=s,t.exports.BufferList=o},{"./BufferList":14,inherits:24,"readable-stream":69}],16:[function(e,t,i){},{}],17:[function(e,t,i){(function(t){(function(){"use strict";var t=e("base64-js"),n=e("ieee754");i.Buffer=s,i.SlowBuffer=function(e){return+e!=e&&(e=0),s.alloc(+e)},i.INSPECT_MAX_BYTES=50;var r=2147483647;function o(e){if(e>r)throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return t.__proto__=s.prototype,t}function s(e,t,i){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return l(e)}return a(e,t,i)}function a(e,t,i){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!s.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var i=0|d(e,t),n=o(i),r=n.write(e,t);return r!==i&&(n=n.slice(0,r)),n}(e,t);if(ArrayBuffer.isView(e))return h(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(z(e,ArrayBuffer)||e&&z(e.buffer,ArrayBuffer))return function(e,t,i){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(i||0))throw new RangeError('"length" is outside of buffer bounds');var n;return(n=void 0===t&&void 0===i?new Uint8Array(e):void 0===i?new Uint8Array(e,t):new Uint8Array(e,t,i)).__proto__=s.prototype,n}(e,t,i);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return s.from(n,t,i);var r=function(e){if(s.isBuffer(e)){var t=0|u(e.length),i=o(t);return 0===i.length||e.copy(i,0,0,t),i}return void 0!==e.length?"number"!=typeof e.length||j(e.length)?o(0):h(e):"Buffer"===e.type&&Array.isArray(e.data)?h(e.data):void 0}(e);if(r)return r;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return s.from(e[Symbol.toPrimitive]("string"),t,i);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function c(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function l(e){return c(e),o(e<0?0:0|u(e))}function h(e){for(var t=e.length<0?0:0|u(e.length),i=o(t),n=0;n<t;n+=1)i[n]=255&e[n];return i}function u(e){if(e>=r)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r.toString(16)+" bytes");return 0|e}function d(e,t){if(s.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||z(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var i=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===i)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":return O(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return B(e).length;default:if(r)return n?-1:O(e).length;t=(""+t).toLowerCase(),r=!0}}function f(e,t,i){var n=e[t];e[t]=e[i],e[i]=n}function p(e,t,i,n,r){if(0===e.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),j(i=+i)&&(i=r?0:e.length-1),i<0&&(i=e.length+i),i>=e.length){if(r)return-1;i=e.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof t&&(t=s.from(t,n)),s.isBuffer(t))return 0===t.length?-1:v(e,t,i,n,r);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(e,t,i):Uint8Array.prototype.lastIndexOf.call(e,t,i):v(e,[t],i,n,r);throw new TypeError("val must be string, number or Buffer")}function v(e,t,i,n,r){var o,s=1,a=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,c/=2,i/=2}function l(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(r){var h=-1;for(o=i;o<a;o++)if(l(e,o)===l(t,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===c)return h*s}else-1!==h&&(o-=o-h),h=-1}else for(i+c>a&&(i=a-c),o=i;o>=0;o--){for(var u=!0,d=0;d<c;d++)if(l(e,o+d)!==l(t,d)){u=!1;break}if(u)return o}return-1}function x(e,t,i,n){i=Number(i)||0;var r=e.length-i;n?(n=Number(n))>r&&(n=r):n=r;var o=t.length;n>o/2&&(n=o/2);for(var s=0;s<n;++s){var a=parseInt(t.substr(2*s,2),16);if(j(a))return s;e[i+s]=a}return s}function g(e,t,i,n){return F(O(t,e.length-i),e,i,n)}function y(e,t,i,n){return F(function(e){for(var t=[],i=0;i<e.length;++i)t.push(255&e.charCodeAt(i));return t}(t),e,i,n)}function m(e,t,i,n){return y(e,t,i,n)}function b(e,t,i,n){return F(B(t),e,i,n)}function w(e,t,i,n){return F(function(e,t){for(var i,n,r,o=[],s=0;s<e.length&&!((t-=2)<0);++s)n=(i=e.charCodeAt(s))>>8,r=i%256,o.push(r),o.push(n);return o}(t,e.length-i),e,i,n)}function _(e,i,n){return 0===i&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(i,n))}function k(e,t,i){i=Math.min(e.length,i);for(var n=[],r=t;r<i;){var o,s,a,c,l=e[r],h=null,u=l>239?4:l>223?3:l>191?2:1;if(r+u<=i)switch(u){case 1:l<128&&(h=l);break;case 2:128==(192&(o=e[r+1]))&&(c=(31&l)<<6|63&o)>127&&(h=c);break;case 3:o=e[r+1],s=e[r+2],128==(192&o)&&128==(192&s)&&(c=(15&l)<<12|(63&o)<<6|63&s)>2047&&(c<55296||c>57343)&&(h=c);break;case 4:o=e[r+1],s=e[r+2],a=e[r+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(c=(15&l)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&c<1114112&&(h=c)}null===h?(h=65533,u=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),r+=u}return function(e){var t=e.length;if(t<=T)return String.fromCharCode.apply(String,e);for(var i="",n=0;n<t;)i+=String.fromCharCode.apply(String,e.slice(n,n+=T));return i}(n)}i.kMaxLength=r,s.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(e){return!1}}(),s.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&s[Symbol.species]===s&&Object.defineProperty(s,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),s.poolSize=8192,s.from=function(e,t,i){return a(e,t,i)},s.prototype.__proto__=Uint8Array.prototype,s.__proto__=Uint8Array,s.alloc=function(e,t,i){return function(e,t,i){return c(e),e<=0?o(e):void 0!==t?"string"==typeof i?o(e).fill(t,i):o(e).fill(t):o(e)}(e,t,i)},s.allocUnsafe=function(e){return l(e)},s.allocUnsafeSlow=function(e){return l(e)},s.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==s.prototype},s.compare=function(e,t){if(z(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),z(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(e)||!s.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;for(var i=e.length,n=t.length,r=0,o=Math.min(i,n);r<o;++r)if(e[r]!==t[r]){i=e[r],n=t[r];break}return i<n?-1:n<i?1:0},s.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return s.alloc(0);var i;if(void 0===t)for(t=0,i=0;i<e.length;++i)t+=e[i].length;var n=s.allocUnsafe(t),r=0;for(i=0;i<e.length;++i){var o=e[i];if(z(o,Uint8Array)&&(o=s.from(o)),!s.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,r),r+=o.length}return n},s.byteLength=d,s.prototype._isBuffer=!0,s.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)f(this,t,t+1);return this},s.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)f(this,t,t+3),f(this,t+1,t+2);return this},s.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)f(this,t,t+7),f(this,t+1,t+6),f(this,t+2,t+5),f(this,t+3,t+4);return this},s.prototype.toString=function(){var e=this.length;return 0===e?"":0===arguments.length?k(this,0,e):function(e,t,i){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return P(this,t,i);case"utf8":case"utf-8":return k(this,t,i);case"ascii":return A(this,t,i);case"latin1":case"binary":return S(this,t,i);case"base64":return _(this,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,t,i);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(e){if(!s.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===s.compare(this,e)},s.prototype.inspect=function(){var e="",t=i.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},s.prototype.compare=function(e,t,i,n,r){if(z(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===i&&(i=e?e.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),t<0||i>e.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&t>=i)return 0;if(n>=r)return-1;if(t>=i)return 1;if(this===e)return 0;for(var o=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(t>>>=0),c=Math.min(o,a),l=this.slice(n,r),h=e.slice(t,i),u=0;u<c;++u)if(l[u]!==h[u]){o=l[u],a=h[u];break}return o<a?-1:a<o?1:0},s.prototype.includes=function(e,t,i){return-1!==this.indexOf(e,t,i)},s.prototype.indexOf=function(e,t,i){return p(this,e,t,i,!0)},s.prototype.lastIndexOf=function(e,t,i){return p(this,e,t,i,!1)},s.prototype.write=function(e,t,i,n){if(void 0===t)n="utf8",i=this.length,t=0;else if(void 0===i&&"string"==typeof t)n=t,i=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(i)?(i>>>=0,void 0===n&&(n="utf8")):(n=i,i=void 0)}var r=this.length-t;if((void 0===i||i>r)&&(i=r),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return x(this,e,t,i);case"utf8":case"utf-8":return g(this,e,t,i);case"ascii":return y(this,e,t,i);case"latin1":case"binary":return m(this,e,t,i);case"base64":return b(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return w(this,e,t,i);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var T=4096;function A(e,t,i){var n="";i=Math.min(e.length,i);for(var r=t;r<i;++r)n+=String.fromCharCode(127&e[r]);return n}function S(e,t,i){var n="";i=Math.min(e.length,i);for(var r=t;r<i;++r)n+=String.fromCharCode(e[r]);return n}function P(e,t,i){var n=e.length;(!t||t<0)&&(t=0),(!i||i<0||i>n)&&(i=n);for(var r="",o=t;o<i;++o)r+=N(e[o]);return r}function C(e,t,i){for(var n=e.slice(t,i),r="",o=0;o<n.length;o+=2)r+=String.fromCharCode(n[o]+256*n[o+1]);return r}function E(e,t,i){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>i)throw new RangeError("Trying to access beyond buffer length")}function R(e,t,i,n,r,o){if(!s.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>r||t<o)throw new RangeError('"value" argument is out of bounds');if(i+n>e.length)throw new RangeError("Index out of range")}function I(e,t,i,n,r,o){if(i+n>e.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function L(e,t,i,r,o){return t=+t,i>>>=0,o||I(e,0,i,4),n.write(e,t,i,r,23,4),i+4}function M(e,t,i,r,o){return t=+t,i>>>=0,o||I(e,0,i,8),n.write(e,t,i,r,52,8),i+8}s.prototype.slice=function(e,t){var i=this.length;(e=~~e)<0?(e+=i)<0&&(e=0):e>i&&(e=i),(t=void 0===t?i:~~t)<0?(t+=i)<0&&(t=0):t>i&&(t=i),t<e&&(t=e);var n=this.subarray(e,t);return n.__proto__=s.prototype,n},s.prototype.readUIntLE=function(e,t,i){e>>>=0,t>>>=0,i||E(e,t,this.length);for(var n=this[e],r=1,o=0;++o<t&&(r*=256);)n+=this[e+o]*r;return n},s.prototype.readUIntBE=function(e,t,i){e>>>=0,t>>>=0,i||E(e,t,this.length);for(var n=this[e+--t],r=1;t>0&&(r*=256);)n+=this[e+--t]*r;return n},s.prototype.readUInt8=function(e,t){return e>>>=0,t||E(e,1,this.length),this[e]},s.prototype.readUInt16LE=function(e,t){return e>>>=0,t||E(e,2,this.length),this[e]|this[e+1]<<8},s.prototype.readUInt16BE=function(e,t){return e>>>=0,t||E(e,2,this.length),this[e]<<8|this[e+1]},s.prototype.readUInt32LE=function(e,t){return e>>>=0,t||E(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},s.prototype.readUInt32BE=function(e,t){return e>>>=0,t||E(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},s.prototype.readIntLE=function(e,t,i){e>>>=0,t>>>=0,i||E(e,t,this.length);for(var n=this[e],r=1,o=0;++o<t&&(r*=256);)n+=this[e+o]*r;return n>=(r*=128)&&(n-=Math.pow(2,8*t)),n},s.prototype.readIntBE=function(e,t,i){e>>>=0,t>>>=0,i||E(e,t,this.length);for(var n=t,r=1,o=this[e+--n];n>0&&(r*=256);)o+=this[e+--n]*r;return o>=(r*=128)&&(o-=Math.pow(2,8*t)),o},s.prototype.readInt8=function(e,t){return e>>>=0,t||E(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},s.prototype.readInt16LE=function(e,t){e>>>=0,t||E(e,2,this.length);var i=this[e]|this[e+1]<<8;return 32768&i?4294901760|i:i},s.prototype.readInt16BE=function(e,t){e>>>=0,t||E(e,2,this.length);var i=this[e+1]|this[e]<<8;return 32768&i?4294901760|i:i},s.prototype.readInt32LE=function(e,t){return e>>>=0,t||E(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},s.prototype.readInt32BE=function(e,t){return e>>>=0,t||E(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},s.prototype.readFloatLE=function(e,t){return e>>>=0,t||E(e,4,this.length),n.read(this,e,!0,23,4)},s.prototype.readFloatBE=function(e,t){return e>>>=0,t||E(e,4,this.length),n.read(this,e,!1,23,4)},s.prototype.readDoubleLE=function(e,t){return e>>>=0,t||E(e,8,this.length),n.read(this,e,!0,52,8)},s.prototype.readDoubleBE=function(e,t){return e>>>=0,t||E(e,8,this.length),n.read(this,e,!1,52,8)},s.prototype.writeUIntLE=function(e,t,i,n){e=+e,t>>>=0,i>>>=0,n||R(this,e,t,i,Math.pow(2,8*i)-1,0);var r=1,o=0;for(this[t]=255&e;++o<i&&(r*=256);)this[t+o]=e/r&255;return t+i},s.prototype.writeUIntBE=function(e,t,i,n){e=+e,t>>>=0,i>>>=0,n||R(this,e,t,i,Math.pow(2,8*i)-1,0);var r=i-1,o=1;for(this[t+r]=255&e;--r>=0&&(o*=256);)this[t+r]=e/o&255;return t+i},s.prototype.writeUInt8=function(e,t,i){return e=+e,t>>>=0,i||R(this,e,t,1,255,0),this[t]=255&e,t+1},s.prototype.writeUInt16LE=function(e,t,i){return e=+e,t>>>=0,i||R(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},s.prototype.writeUInt16BE=function(e,t,i){return e=+e,t>>>=0,i||R(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},s.prototype.writeUInt32LE=function(e,t,i){return e=+e,t>>>=0,i||R(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},s.prototype.writeUInt32BE=function(e,t,i){return e=+e,t>>>=0,i||R(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},s.prototype.writeIntLE=function(e,t,i,n){if(e=+e,t>>>=0,!n){var r=Math.pow(2,8*i-1);R(this,e,t,i,r-1,-r)}var o=0,s=1,a=0;for(this[t]=255&e;++o<i&&(s*=256);)e<0&&0===a&&0!==this[t+o-1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+i},s.prototype.writeIntBE=function(e,t,i,n){if(e=+e,t>>>=0,!n){var r=Math.pow(2,8*i-1);R(this,e,t,i,r-1,-r)}var o=i-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+i},s.prototype.writeInt8=function(e,t,i){return e=+e,t>>>=0,i||R(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},s.prototype.writeInt16LE=function(e,t,i){return e=+e,t>>>=0,i||R(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},s.prototype.writeInt16BE=function(e,t,i){return e=+e,t>>>=0,i||R(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},s.prototype.writeInt32LE=function(e,t,i){return e=+e,t>>>=0,i||R(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},s.prototype.writeInt32BE=function(e,t,i){return e=+e,t>>>=0,i||R(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},s.prototype.writeFloatLE=function(e,t,i){return L(this,e,t,!0,i)},s.prototype.writeFloatBE=function(e,t,i){return L(this,e,t,!1,i)},s.prototype.writeDoubleLE=function(e,t,i){return M(this,e,t,!0,i)},s.prototype.writeDoubleBE=function(e,t,i){return M(this,e,t,!1,i)},s.prototype.copy=function(e,t,i,n){if(!s.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<i&&(n=i),n===i)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-i&&(n=e.length-t+i);var r=n-i;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(t,i,n);else if(this===e&&i<t&&t<n)for(var o=r-1;o>=0;--o)e[o+t]=this[o+i];else Uint8Array.prototype.set.call(e,this.subarray(i,n),t);return r},s.prototype.fill=function(e,t,i,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,i=this.length):"string"==typeof i&&(n=i,i=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){var r=e.charCodeAt(0);("utf8"===n&&r<128||"latin1"===n)&&(e=r)}}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;var o;if(t>>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(o=t;o<i;++o)this[o]=e;else{var a=s.isBuffer(e)?e:s.from(e,n),c=a.length;if(0===c)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<i-t;++o)this[o+t]=a[o%c]}return this};var D=/[^+/0-9A-Za-z-_]/g;function N(e){return e<16?"0"+e.toString(16):e.toString(16)}function O(e,t){var i;t=t||1/0;for(var n=e.length,r=null,o=[],s=0;s<n;++s){if((i=e.charCodeAt(s))>55295&&i<57344){if(!r){if(i>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}r=i;continue}if(i<56320){(t-=3)>-1&&o.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(t-=3)>-1&&o.push(239,191,189);if(r=null,i<128){if((t-=1)<0)break;o.push(i)}else if(i<2048){if((t-=2)<0)break;o.push(i>>6|192,63&i|128)}else if(i<65536){if((t-=3)<0)break;o.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return o}function B(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(D,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function F(e,t,i,n){for(var r=0;r<n&&!(r+i>=t.length||r>=e.length);++r)t[r+i]=e[r];return r}function z(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function j(e){return e!=e}}).call(this)}).call(this,e("buffer").Buffer)},{"base64-js":13,buffer:17,ieee754:23}],18:[function(e,t,i){(function(n){(function(){i.formatArgs=function(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+t.exports.humanize(this.diff),!this.useColors)return;const i="color: "+this.color;e.splice(1,0,i,"color: inherit");let n=0,r=0;e[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&"%c"===e&&(r=++n)})),e.splice(r,0,i)},i.save=function(e){try{e?i.storage.setItem("debug",e):i.storage.removeItem("debug")}catch(e){}},i.load=function(){let e;try{e=i.storage.getItem("debug")}catch(e){}return!e&&void 0!==n&&"env"in n&&(e=n.env.DEBUG),e},i.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type&&!window.process.__nwjs)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},i.storage=function(){try{return localStorage}catch(e){}}(),i.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),i.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],i.log=console.debug||console.log||(()=>{}),t.exports=e("./common")(i);const{formatters:r}=t.exports;r.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}).call(this)}).call(this,e("_process"))},{"./common":19,_process:50}],19:[function(e,t,i){t.exports=function(t){function i(e){let t,r,o,s=null;function a(...e){if(!a.enabled)return;const n=a,r=Number(new Date),o=r-(t||r);n.diff=o,n.prev=t,n.curr=r,t=r,e[0]=i.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((t,r)=>{if("%%"===t)return"%";s++;const o=i.formatters[r];if("function"==typeof o){const i=e[s];t=o.call(n,i),e.splice(s,1),s--}return t})),i.formatArgs.call(n,e),(n.log||i.log).apply(n,e)}return a.namespace=e,a.useColors=i.useColors(),a.color=i.selectColor(e),a.extend=n,a.destroy=i.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==s?s:(r!==i.namespaces&&(r=i.namespaces,o=i.enabled(e)),o),set:e=>{s=e}}),"function"==typeof i.init&&i.init(a),a}function n(e,t){const n=i(this.namespace+(void 0===t?":":t)+e);return n.log=this.log,n}function r(e){return e.toString().substring(2,e.toString().length-2).replace(/\.\*\?$/,"*")}return i.debug=i,i.default=i,i.coerce=function(e){return e instanceof Error?e.stack||e.message:e},i.disable=function(){const e=[...i.names.map(r),...i.skips.map(r).map((e=>"-"+e))].join(",");return i.enable(""),e},i.enable=function(e){let t;i.save(e),i.namespaces=e,i.names=[],i.skips=[];const n=("string"==typeof e?e:"").split(/[\s,]+/),r=n.length;for(t=0;t<r;t++)n[t]&&("-"===(e=n[t].replace(/\*/g,".*?"))[0]?i.skips.push(new RegExp("^"+e.substr(1)+"$")):i.names.push(new RegExp("^"+e+"$")))},i.enabled=function(e){if("*"===e[e.length-1])return!0;let t,n;for(t=0,n=i.skips.length;t<n;t++)if(i.skips[t].test(e))return!1;for(t=0,n=i.names.length;t<n;t++)if(i.names[t].test(e))return!0;return!1},i.humanize=e("ms"),i.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(t).forEach((e=>{i[e]=t[e]})),i.names=[],i.skips=[],i.formatters={},i.selectColor=function(e){let t=0;for(let i=0;i<e.length;i++)t=(t<<5)-t+e.charCodeAt(i),t|=0;return i.colors[Math.abs(t)%i.colors.length]},i.enable(i.load()),i}},{ms:45}],20:[function(e,t,i){(function(i,n){(function(){var r=e("readable-stream"),o=e("end-of-stream"),s=e("inherits"),a=e("stream-shift"),c=n.from&&n.from!==Uint8Array.from?n.from([0]):new n([0]),l=function(e,t){e._corked?e.once("uncork",t):t()},h=function(e,t){return function(i){i?function(e,t){e._autoDestroy&&e.destroy(t)}(e,"premature close"===i.message?null:i):t&&!e._ended&&e.end()}},u=function(){},d=function(e,t,i){if(!(this instanceof d))return new d(e,t,i);r.Duplex.call(this,i),this._writable=null,this._readable=null,this._readable2=null,this._autoDestroy=!i||!1!==i.autoDestroy,this._forwardDestroy=!i||!1!==i.destroy,this._forwardEnd=!i||!1!==i.end,this._corked=1,this._ondrain=null,this._drained=!1,this._forwarding=!1,this._unwrite=null,this._unread=null,this._ended=!1,this.destroyed=!1,e&&this.setWritable(e),t&&this.setReadable(t)};s(d,r.Duplex),d.obj=function(e,t,i){return i||(i={}),i.objectMode=!0,i.highWaterMark=16,new d(e,t,i)},d.prototype.cork=function(){1==++this._corked&&this.emit("cork")},d.prototype.uncork=function(){this._corked&&0==--this._corked&&this.emit("uncork")},d.prototype.setWritable=function(e){if(this._unwrite&&this._unwrite(),this.destroyed)e&&e.destroy&&e.destroy();else if(null!==e&&!1!==e){var t=this,n=o(e,{writable:!0,readable:!1},h(this,this._forwardEnd)),r=function(){var e=t._ondrain;t._ondrain=null,e&&e()};this._unwrite&&i.nextTick(r),this._writable=e,this._writable.on("drain",r),this._unwrite=function(){t._writable.removeListener("drain",r),n()},this.uncork()}else this.end()},d.prototype.setReadable=function(e){if(this._unread&&this._unread(),this.destroyed)e&&e.destroy&&e.destroy();else{if(null===e||!1===e)return this.push(null),void this.resume();var t,i=this,n=o(e,{writable:!1,readable:!0},h(this)),s=function(){i._forward()},a=function(){i.push(null)};this._drained=!0,this._readable=e,this._readable2=e._readableState?e:(t=e,new r.Readable({objectMode:!0,highWaterMark:16}).wrap(t)),this._readable2.on("readable",s),this._readable2.on("end",a),this._unread=function(){i._readable2.removeListener("readable",s),i._readable2.removeListener("end",a),n()},this._forward()}},d.prototype._read=function(){this._drained=!0,this._forward()},d.prototype._forward=function(){if(!this._forwarding&&this._readable2&&this._drained){var e;for(this._forwarding=!0;this._drained&&null!==(e=a(this._readable2));)this.destroyed||(this._drained=this.push(e));this._forwarding=!1}},d.prototype.destroy=function(e,t){if(t||(t=u),this.destroyed)return t(null);this.destroyed=!0;var n=this;i.nextTick((function(){n._destroy(e),t(null)}))},d.prototype._destroy=function(e){if(e){var t=this._ondrain;this._ondrain=null,t?t(e):this.emit("error",e)}this._forwardDestroy&&(this._readable&&this._readable.destroy&&this._readable.destroy(),this._writable&&this._writable.destroy&&this._writable.destroy()),this.emit("close")},d.prototype._write=function(e,t,i){if(!this.destroyed)return this._corked?l(this,this._write.bind(this,e,t,i)):e===c?this._finish(i):this._writable?void(!1===this._writable.write(e)?this._ondrain=i:this.destroyed||i()):i()},d.prototype._finish=function(e){var t=this;this.emit("preend"),l(this,(function(){var i,n;n=function(){!1===t._writableState.prefinished&&(t._writableState.prefinished=!0),t.emit("prefinish"),l(t,e)},(i=t._forwardEnd&&t._writable)?i._writableState&&i._writableState.finished?n():i._writableState?i.end(n):(i.end(),n()):n()}))},d.prototype.end=function(e,t,i){return"function"==typeof e?this.end(null,null,e):"function"==typeof t?this.end(e,null,t):(this._ended=!0,e&&this.write(e),this._writableState.ending||this._writableState.destroyed||this.write(c),r.Writable.prototype.end.call(this,i))},t.exports=d}).call(this)}).call(this,e("_process"),e("buffer").Buffer)},{_process:50,buffer:17,"end-of-stream":21,inherits:24,"readable-stream":69,"stream-shift":74}],21:[function(e,t,i){(function(i){(function(){var n=e("once"),r=function(){},o=function(e,t,s){if("function"==typeof t)return o(e,null,t);t||(t={}),s=n(s||r);var a=e._writableState,c=e._readableState,l=t.readable||!1!==t.readable&&e.readable,h=t.writable||!1!==t.writable&&e.writable,u=!1,d=function(){e.writable||f()},f=function(){h=!1,l||s.call(e)},p=function(){l=!1,h||s.call(e)},v=function(t){s.call(e,t?new Error("exited with error code: "+t):null)},x=function(t){s.call(e,t)},g=function(){i.nextTick(y)},y=function(){if(!u)return(!l||c&&c.ended&&!c.destroyed)&&(!h||a&&a.ended&&!a.destroyed)?void 0:s.call(e,new Error("premature close"))},m=function(){e.req.on("finish",f)};return function(e){return e.setHeader&&"function"==typeof e.abort}(e)?(e.on("complete",f),e.on("abort",g),e.req?m():e.on("request",m)):h&&!a&&(e.on("end",d),e.on("close",d)),function(e){return e.stdio&&Array.isArray(e.stdio)&&3===e.stdio.length}(e)&&e.on("exit",v),e.on("end",p),e.on("finish",f),!1!==t.error&&e.on("error",x),e.on("close",g),function(){u=!0,e.removeListener("complete",f),e.removeListener("abort",g),e.removeListener("request",m),e.req&&e.req.removeListener("finish",f),e.removeListener("end",d),e.removeListener("close",d),e.removeListener("finish",f),e.removeListener("exit",v),e.removeListener("end",p),e.removeListener("error",x),e.removeListener("close",g)}};t.exports=o}).call(this)}).call(this,e("_process"))},{_process:50,once:48}],22:[function(e,t,i){var n=Object.create||function(e){var t=function(){};return t.prototype=e,new t},r=Object.keys||function(e){var t=[];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.push(i);return i},o=Function.prototype.bind||function(e){var t=this;return function(){return t.apply(e,arguments)}};function s(){this._events&&Object.prototype.hasOwnProperty.call(this,"_events")||(this._events=n(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0}t.exports=s,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._maxListeners=void 0;var a,c=10;try{var l={};Object.defineProperty&&Object.defineProperty(l,"x",{value:0}),a=0===l.x}catch(e){a=!1}function h(e){return void 0===e._maxListeners?s.defaultMaxListeners:e._maxListeners}function u(e,t,i,r){var o,s,a;if("function"!=typeof i)throw new TypeError('"listener" argument must be a function');if((s=e._events)?(s.newListener&&(e.emit("newListener",t,i.listener?i.listener:i),s=e._events),a=s[t]):(s=e._events=n(null),e._eventsCount=0),a){if("function"==typeof a?a=s[t]=r?[i,a]:[a,i]:r?a.unshift(i):a.push(i),!a.warned&&(o=h(e))&&o>0&&a.length>o){a.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+a.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=a.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",c.name,c.message)}}else a=s[t]=i,++e._eventsCount;return e}function d(){if(!this.fired)switch(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:for(var e=new Array(arguments.length),t=0;t<e.length;++t)e[t]=arguments[t];this.listener.apply(this.target,e)}}function f(e,t,i){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:i},r=o.call(d,n);return r.listener=i,n.wrapFn=r,r}function p(e,t,i){var n=e._events;if(!n)return[];var r=n[t];return r?"function"==typeof r?i?[r.listener||r]:[r]:i?function(e){for(var t=new Array(e.length),i=0;i<t.length;++i)t[i]=e[i].listener||e[i];return t}(r):x(r,r.length):[]}function v(e){var t=this._events;if(t){var i=t[e];if("function"==typeof i)return 1;if(i)return i.length}return 0}function x(e,t){for(var i=new Array(t),n=0;n<t;++n)i[n]=e[n];return i}a?Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(e){if("number"!=typeof e||e<0||e!=e)throw new TypeError('"defaultMaxListeners" must be a positive number');c=e}}):s.defaultMaxListeners=c,s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},s.prototype.getMaxListeners=function(){return h(this)},s.prototype.emit=function(e){var t,i,n,r,o,s,a="error"===e;if(s=this._events)a=a&&null==s.error;else if(!a)return!1;if(a){if(arguments.length>1&&(t=arguments[1]),t instanceof Error)throw t;var c=new Error('Unhandled "error" event. ('+t+")");throw c.context=t,c}if(!(i=s[e]))return!1;var l="function"==typeof i;switch(n=arguments.length){case 1:!function(e,t,i){if(t)e.call(i);else for(var n=e.length,r=x(e,n),o=0;o<n;++o)r[o].call(i)}(i,l,this);break;case 2:!function(e,t,i,n){if(t)e.call(i,n);else for(var r=e.length,o=x(e,r),s=0;s<r;++s)o[s].call(i,n)}(i,l,this,arguments[1]);break;case 3:!function(e,t,i,n,r){if(t)e.call(i,n,r);else for(var o=e.length,s=x(e,o),a=0;a<o;++a)s[a].call(i,n,r)}(i,l,this,arguments[1],arguments[2]);break;case 4:!function(e,t,i,n,r,o){if(t)e.call(i,n,r,o);else for(var s=e.length,a=x(e,s),c=0;c<s;++c)a[c].call(i,n,r,o)}(i,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(r=new Array(n-1),o=1;o<n;o++)r[o-1]=arguments[o];!function(e,t,i,n){if(t)e.apply(i,n);else for(var r=e.length,o=x(e,r),s=0;s<r;++s)o[s].apply(i,n)}(i,l,this,r)}return!0},s.prototype.addListener=function(e,t){return u(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return u(this,e,t,!0)},s.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,f(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,f(this,e,t)),this},s.prototype.removeListener=function(e,t){var i,r,o,s,a;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(i=r[e]))return this;if(i===t||i.listener===t)0==--this._eventsCount?this._events=n(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,i.listener||t));else if("function"!=typeof i){for(o=-1,s=i.length-1;s>=0;s--)if(i[s]===t||i[s].listener===t){a=i[s].listener,o=s;break}if(o<0)return this;0===o?i.shift():function(e,t){for(var i=t,n=i+1,r=e.length;n<r;i+=1,n+=1)e[i]=e[n];e.pop()}(i,o),1===i.length&&(r[e]=i[0]),r.removeListener&&this.emit("removeListener",e,a||t)}return this},s.prototype.removeAllListeners=function(e){var t,i,o;if(!(i=this._events))return this;if(!i.removeListener)return 0===arguments.length?(this._events=n(null),this._eventsCount=0):i[e]&&(0==--this._eventsCount?this._events=n(null):delete i[e]),this;if(0===arguments.length){var s,a=r(i);for(o=0;o<a.length;++o)"removeListener"!==(s=a[o])&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=n(null),this._eventsCount=0,this}if("function"==typeof(t=i[e]))this.removeListener(e,t);else if(t)for(o=t.length-1;o>=0;o--)this.removeListener(e,t[o]);return this},s.prototype.listeners=function(e){return p(this,e,!0)},s.prototype.rawListeners=function(e){return p(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):v.call(e,t)},s.prototype.listenerCount=v,s.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],23:[function(e,t,i){i.read=function(e,t,i,n,r){var o,s,a=8*r-n-1,c=(1<<a)-1,l=c>>1,h=-7,u=i?r-1:0,d=i?-1:1,f=e[t+u];for(u+=d,o=f&(1<<-h)-1,f>>=-h,h+=a;h>0;o=256*o+e[t+u],u+=d,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+e[t+u],u+=d,h-=8);if(0===o)o=1-l;else{if(o===c)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,n),o-=l}return(f?-1:1)*s*Math.pow(2,o-n)},i.write=function(e,t,i,n,r,o){var s,a,c,l=8*o-r-1,h=(1<<l)-1,u=h>>1,d=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:o-1,p=n?1:-1,v=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=h):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+u>=1?d/c:d*Math.pow(2,1-u))*c>=2&&(s++,c/=2),s+u>=h?(a=0,s=h):s+u>=1?(a=(t*c-1)*Math.pow(2,r),s+=u):(a=t*Math.pow(2,u-1)*Math.pow(2,r),s=0));r>=8;e[i+f]=255&a,f+=p,a/=256,r-=8);for(s=s<<r|a,l+=r;l>0;e[i+f]=255&s,f+=p,s/=256,l-=8);e[i+f-p]|=128*v}},{}],24:[function(e,t,i){"function"==typeof Object.create?t.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:t.exports=function(e,t){if(t){e.super_=t;var i=function(){};i.prototype=t.prototype,e.prototype=new i,e.prototype.constructor=e}}},{}],25:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});var n=function(){function e(e,t){this.color=!0,this.key=void 0,this.value=void 0,this.parent=void 0,this.brother=void 0,this.leftChild=void 0,this.rightChild=void 0,this.key=e,this.value=t}return e.prototype.rotateLeft=function(){var e=this.parent,t=this.brother,i=this.leftChild,n=this.rightChild;if(!n)throw new Error("unknown error");var r=n.leftChild,o=n.rightChild;return e&&(e.leftChild===this?e.leftChild=n:e.rightChild===this&&(e.rightChild=n)),n.parent=e,n.brother=t,n.leftChild=this,n.rightChild=o,t&&(t.brother=n),this.parent=n,this.brother=o,this.leftChild=i,this.rightChild=r,o&&(o.parent=n,o.brother=this),i&&(i.parent=this,i.brother=r),r&&(r.parent=this,r.brother=i),n},e.prototype.rotateRight=function(){var e=this.parent,t=this.brother,i=this.leftChild;if(!i)throw new Error("unknown error");var n=this.rightChild,r=i.leftChild,o=i.rightChild;return e&&(e.leftChild===this?e.leftChild=i:e.rightChild===this&&(e.rightChild=i)),i.parent=e,i.brother=t,i.leftChild=r,i.rightChild=this,t&&(t.brother=i),r&&(r.parent=i,r.brother=this),this.parent=i,this.brother=r,this.leftChild=o,this.rightChild=n,o&&(o.parent=this,o.brother=n),n&&(n.parent=this,n.brother=o),i},e.prototype.remove=function(){if(this.leftChild||this.rightChild)throw new Error("can only remove leaf node");this.parent&&(this===this.parent.leftChild?this.parent.leftChild=void 0:this===this.parent.rightChild&&(this.parent.rightChild=void 0)),this.brother&&(this.brother.brother=void 0),this.key=void 0,this.value=void 0,this.parent=void 0,this.brother=void 0},e.TreeNodeColorType={red:!0,black:!1},e}();Object.freeze(n),i.default=n},{}],26:[function(e,t,i){"use strict";var n=this&&this.__generator||function(e,t){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}};function r(e){var t=this;void 0===e&&(e=[]);var i=[],o=0,s=0,a=0,c=0,l=0,h=0;this.size=function(){return h},this.empty=function(){return 0===h},this.clear=function(){o=a=s=c=l=h=0,d.call(this,r.bucketSize),h=0},this.front=function(){return i[o][s]},this.back=function(){return i[a][c]},this.forEach=function(e){if(!this.empty()){var t=0;if(o!==a){for(l=s;l<r.bucketSize;++l)e(i[o][l],t++);for(l=o+1;l<a;++l)for(var n=0;n<r.bucketSize;++n)e(i[l][n],t++);for(l=0;l<=c;++l)e(i[a][l],t++)}else for(var l=s;l<=c;++l)e(i[o][l],t++)}};var u=function(e){var t=o*r.bucketSize+s,i=t+e,n=a*r.bucketSize+c;if(i<t||i>n)throw new Error("pos should more than 0 and less than queue's size");return{curNodeBucketIndex:Math.floor(i/r.bucketSize),curNodePointerIndex:i%r.bucketSize}};this.getElementByPos=function(e){var t=u(e),n=t.curNodeBucketIndex,r=t.curNodePointerIndex;return i[n][r]},this.eraseElementByPos=function(e){var t=this;if(e<0||e>h)throw new Error("pos should more than 0 and less than queue's size");if(0===e)this.popFront();else if(e===this.size())this.popBack();else{for(var i=[],n=e+1;n<h;++n)i.push(this.getElementByPos(n));this.cut(e),this.popBack(),i.forEach((function(e){return t.pushBack(e)}))}},this.eraseElementByValue=function(e){if(!this.empty()){var t=[];this.forEach((function(i){i!==e&&t.push(i)}));for(var i=t.length,n=0;n<i;++n)this.setElementByPos(n,t[n]);this.cut(i-1)}};var d=function(e){for(var t=[],n=e*r.sigma,u=Math.max(Math.ceil(n/r.bucketSize),2),d=0;d<u;++d)t.push(new Array(r.bucketSize));var f=Math.ceil(e/r.bucketSize),p=Math.floor(u/2)-Math.floor(f/2),v=p,x=0;if(this.size())for(d=0;d<f;++d){for(var g=0;g<r.bucketSize;++g)if(t[p+d][g]=this.front(),this.popFront(),this.empty()){v=p+d,x=g;break}if(this.empty())break}i=t,o=p,s=0,a=v,c=x,l=u,h=e};this.pushBack=function(e){this.empty()||(a===l-1&&c===r.bucketSize-1&&d.call(this,this.size()),c<r.bucketSize-1?++c:a<l-1&&(++a,c=0)),++h,i[a][c]=e},this.popBack=function(){this.empty()||(1!==this.size()&&(c>0?--c:o<a&&(--a,c=r.bucketSize-1)),h>0&&--h)},this.setElementByPos=function(e,t){var n=u(e),r=n.curNodeBucketIndex,o=n.curNodePointerIndex;i[r][o]=t},this.insert=function(e,t,i){var n=this;if(void 0===i&&(i=1),0===e)for(;i--;)this.pushFront(t);else if(e===this.size())for(;i--;)this.pushBack(t);else{for(var r=[],o=e;o<h;++o)r.push(this.getElementByPos(o));for(this.cut(e-1),o=0;o<i;++o)this.pushBack(t);r.forEach((function(e){return n.pushBack(e)}))}},this.find=function(e){if(o===a){for(var t=s;t<=c;++t)if(i[o][t]===e)return!0;return!1}for(t=s;t<r.bucketSize;++t)if(i[o][t]===e)return!0;for(t=o+1;t<a;++t)for(var n=0;n<r.bucketSize;++n)if(i[t][n]===e)return!0;for(t=0;t<=c;++t)if(i[a][t]===e)return!0;return!1},this.reverse=function(){for(var e=0,t=h-1;e<t;){var i=this.getElementByPos(e);this.setElementByPos(e,this.getElementByPos(t)),this.setElementByPos(t,i),++e,--t}},this.unique=function(){if(!this.empty()){var e=[],t=this.front();this.forEach((function(i,n){0!==n&&i===t||(e.push(i),t=i)}));for(var i=0;i<h;++i)this.setElementByPos(i,e[i]);this.cut(e.length-1)}},this.sort=function(e){var t=[];this.forEach((function(e){t.push(e)})),t.sort(e);for(var i=0;i<h;++i)this.setElementByPos(i,t[i])},this.pushFront=function(e){this.empty()||(0===o&&0===s&&d.call(this,this.size()),s>0?--s:o>0&&(--o,s=r.bucketSize-1)),++h,i[o][s]=e},this.popFront=function(){this.empty()||(1!==this.size()&&(s<r.bucketSize-1?++s:o<a&&(++o,s=0)),h>0&&--h)},this.shrinkToFit=function(){var e=this,t=[];this.forEach((function(e){t.push(e)}));var n=t.length;i=[];for(var o=Math.ceil(n/r.bucketSize),s=0;s<o;++s)i.push(new Array(r.bucketSize));this.clear(),t.forEach((function(t){return e.pushBack(t)}))},this.cut=function(e){if(e<0)this.clear();else{var t=u(e),i=t.curNodeBucketIndex,n=t.curNodePointerIndex;a=i,c=n,h=e+1}},this[Symbol.iterator]=function(){return function(){var e,t;return n(this,(function(n){switch(n.label){case 0:if(0===h)return[2];if(o!==a)return[3,5];t=s,n.label=1;case 1:return t<=c?[4,i[o][t]]:[3,4];case 2:n.sent(),n.label=3;case 3:return++t,[3,1];case 4:return[2];case 5:t=s,n.label=6;case 6:return t<r.bucketSize?[4,i[o][t]]:[3,9];case 7:n.sent(),n.label=8;case 8:return++t,[3,6];case 9:t=o+1,n.label=10;case 10:if(!(t<a))return[3,15];e=0,n.label=11;case 11:return e<r.bucketSize?[4,i[t][e]]:[3,14];case 12:n.sent(),n.label=13;case 13:return++e,[3,11];case 14:return++t,[3,10];case 15:t=0,n.label=16;case 16:return t<=c?[4,i[a][t]]:[3,19];case 17:n.sent(),n.label=18;case 18:return++t,[3,16];case 19:return[2]}}))}()},function(){var n=r.bucketSize;e.size?n=e.size():e.length&&(n=e.length);var s=n*r.sigma;l=Math.ceil(s/r.bucketSize),l=Math.max(l,3);for(var c=0;c<l;++c)i.push(new Array(r.bucketSize));var h=Math.ceil(n/r.bucketSize);o=Math.floor(l/2)-Math.floor(h/2),a=o,e.forEach((function(e){return t.pushBack(e)}))}(),Object.freeze(this)}Object.defineProperty(i,"__esModule",{value:!0}),r.sigma=3,r.bucketSize=5e3,Object.freeze(r),i.default=r},{}],27:[function(e,t,i){"use strict";var n=this&&this.__generator||function(e,t){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},r=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,i=t&&e[t],n=0;if(i)return i.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(i,"__esModule",{value:!0});var o=e("../LinkList/LinkList"),s=e("../Map/Map");function a(e,t,i){var c=this;if(void 0===e&&(e=[]),void 0===t&&(t=a.initSize),i=i||function(e){var t,i,n=0,o="";if("number"==typeof e)n=((n=Math.floor(e))<<5)-n,n&=n;else{o="string"!=typeof e?JSON.stringify(e):e;try{for(var s=r(o),a=s.next();!a.done;a=s.next())n=(n<<5)-n+a.value.charCodeAt(0),n&=n}catch(e){t={error:e}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(t)throw t.error}}}return n^n>>>16},0!=(t&t-1))throw new Error("initBucketNum must be 2 to the power of n");var l=0,h=[],u=Math.max(a.initSize,Math.min(a.maxSize,t));this.size=function(){return l},this.empty=function(){return 0===l},this.clear=function(){l=0,u=t,h=[]},this.forEach=function(e){var t=0;h.forEach((function(i){i.forEach((function(i){e(i,t++)}))}))},this.setElement=function(e,t){var n,c;if(null==e)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(null!=t){var d=i(e)&u-1;if(h[d]){var f=h[d].size();if(h[d]instanceof o.default){try{for(var p=r(h[d]),v=p.next();!v.done;v=p.next()){var x=v.value;if(x.key===e)return void(x.value=t)}}catch(e){n={error:e}}finally{try{v&&!v.done&&(c=p.return)&&c.call(p)}finally{if(n)throw n.error}}h[d].pushBack({key:e,value:t}),h[d].size()>=a.treeifyThreshold&&(h[d]=new s.default(h[d]))}else h[d].setElement(e,t);var g=h[d].size();l+=g-f}else++l,h[d]=new o.default([{key:e,value:t}]);l>u*a.sigma&&function(e){if(!(e>=a.maxSize)){u=2*e;var t=[];h.forEach((function(n,r){if(!n.empty()){if(n instanceof o.default&&1===n.size()){var c=n.front(),l=c.key,d=c.value;t[i(l)&u-1]=new o.default([{key:l,value:d}])}else if(n instanceof s.default){var f=new o.default,p=new o.default;n.forEach((function(t){0==(i(t.key)&e)?f.pushBack(t):p.pushBack(t)})),f.size()>a.untreeifyThreshold?t[r]=new s.default(f):f.size()&&(t[r]=f),p.size()>a.untreeifyThreshold?t[r+e]=new s.default(p):p.size()&&(t[r+e]=p)}else{var v=new o.default,x=new o.default;n.forEach((function(t){0==(i(t.key)&e)?v.pushBack(t):x.pushBack(t)})),v.size()&&(t[r]=v),x.size()&&(t[r+e]=x)}h[r].clear()}})),h=t}}.call(this,u)}else this.eraseElementByKey(e)},this.getElementByKey=function(e){var t,n,o=i(e)&u-1;if(h[o]){if(h[o]instanceof s.default)return h[o].getElementByKey(e);try{for(var a=r(h[o]),c=a.next();!c.done;c=a.next()){var l=c.value;if(l.key===e)return l.value}}catch(e){t={error:e}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(t)throw t.error}}}},this.eraseElementByKey=function(e){var t,n,c=i(e)&u-1;if(h[c]){var d=h[c].size();if(h[c]instanceof s.default)h[c].eraseElementByKey(e),h[c].size()<=a.untreeifyThreshold&&(h[c]=new o.default(h[c]));else{var f=-1;try{for(var p=r(h[c]),v=p.next();!v.done;v=p.next())if(++f,v.value.key===e){h[c].eraseElementByPos(f);break}}catch(e){t={error:e}}finally{try{v&&!v.done&&(n=p.return)&&n.call(p)}finally{if(t)throw t.error}}}var x=h[c].size();l+=x-d}},this.find=function(e){var t,n,o=i(e)&u-1;if(!h[o])return!1;if(h[o]instanceof s.default)return h[o].find(e);try{for(var a=r(h[o]),c=a.next();!c.done;c=a.next())if(c.value.key===e)return!0}catch(e){t={error:e}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(t)throw t.error}}return!1},this[Symbol.iterator]=function(){return function(){var e,t,i,o,s,a;return n(this,(function(n){switch(n.label){case 0:e=0,n.label=1;case 1:if(!(e<u))return[3,10];for(;e<u&&!h[e];)++e;if(e>=u)return[3,10];n.label=2;case 2:n.trys.push([2,7,8,9]),s=void 0,t=r(h[e]),i=t.next(),n.label=3;case 3:return i.done?[3,6]:[4,i.value];case 4:n.sent(),n.label=5;case 5:return i=t.next(),[3,3];case 6:return[3,9];case 7:return o=n.sent(),s={error:o},[3,9];case 8:try{i&&!i.done&&(a=t.return)&&a.call(t)}finally{if(s)throw s.error}return[7];case 9:return++e,[3,1];case 10:return[2]}}))}()},e.forEach((function(e){var t=e.key,i=e.value;return c.setElement(t,i)})),Object.freeze(this)}a.initSize=16,a.maxSize=1<<30,a.sigma=.75,a.treeifyThreshold=8,a.untreeifyThreshold=6,a.minTreeifySize=64,Object.freeze(a),i.default=a},{"../LinkList/LinkList":29,"../Map/Map":30}],28:[function(e,t,i){"use strict";var n=this&&this.__generator||function(e,t){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},r=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,i=t&&e[t],n=0;if(i)return i.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(i,"__esModule",{value:!0});var o=e("../Set/Set"),s=e("../LinkList/LinkList");function a(e,t,i){var c=this;if(void 0===e&&(e=[]),void 0===t&&(t=a.initSize),i=i||function(e){var t=0,i="";if("number"==typeof e)t=((t=Math.floor(e))<<5)-t,t&=t;else{i="string"!=typeof e?JSON.stringify(e):e;for(var n=0;n<i.length;n++)t=(t<<5)-t+i.charCodeAt(n),t&=t}return t^t>>>16},0!=(t&t-1))throw new Error("initBucketNum must be 2 to the power of n");var l=0,h=[],u=Math.max(a.initSize,Math.min(a.maxSize,t));this.size=function(){return l},this.empty=function(){return 0===l},this.clear=function(){l=0,u=t,h=[]},this.forEach=function(e){var t=0;h.forEach((function(i){i.forEach((function(i){e(i,t++)}))}))},this.insert=function(e){if(null==e)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");var t=i(e)&u-1;if(h[t]){var n=h[t].size();if(h[t]instanceof s.default){if(h[t].find(e))return;h[t].pushBack(e),h[t].size()>=a.treeifyThreshold&&(h[t]=new o.default(h[t]))}else h[t].insert(e);var r=h[t].size();l+=r-n}else h[t]=new s.default([e]),++l;l>u*a.sigma&&function(e){if(!(e>=a.maxSize)){u=2*e;var t=[];h.forEach((function(n,r){if(!n.empty()){if(n instanceof s.default&&1===n.size()){var c=n.front();if(void 0===c)throw new Error("unknown error");t[i(c)&u-1]=new s.default([c])}else if(n instanceof o.default){var l=new s.default,d=new s.default;n.forEach((function(t){0==(i(t)&e)?l.pushBack(t):d.pushBack(t)})),l.size()>a.untreeifyThreshold?t[r]=new o.default(l):l.size()&&(t[r]=l),d.size()>a.untreeifyThreshold?t[r+e]=new o.default(d):d.size()&&(t[r+e]=d)}else{var f=new s.default,p=new s.default;n.forEach((function(t){0==(i(t)&e)?f.pushBack(t):p.pushBack(t)})),f.size()&&(t[r]=f),p.size()&&(t[r+e]=p)}h[r].clear()}})),h=t}}.call(this,u)},this.eraseElementByValue=function(e){var t=i(e)&u-1;if(h[t]){var n=h[t].size();h[t].eraseElementByValue(e),h[t]instanceof o.default&&h[t].size()<=a.untreeifyThreshold&&(h[t]=new s.default(h[t]));var r=h[t].size();l+=r-n}},this.find=function(e){var t=i(e)&u-1;return!!h[t]&&h[t].find(e)},this[Symbol.iterator]=function(){return function(){var e,t,i,o,s,a;return n(this,(function(n){switch(n.label){case 0:e=0,n.label=1;case 1:if(!(e<u))return[3,10];for(;e<u&&!h[e];)++e;if(e>=u)return[3,10];n.label=2;case 2:n.trys.push([2,7,8,9]),s=void 0,t=r(h[e]),i=t.next(),n.label=3;case 3:return i.done?[3,6]:[4,i.value];case 4:n.sent(),n.label=5;case 5:return i=t.next(),[3,3];case 6:return[3,9];case 7:return o=n.sent(),s={error:o},[3,9];case 8:try{i&&!i.done&&(a=t.return)&&a.call(t)}finally{if(s)throw s.error}return[7];case 9:return++e,[3,1];case 10:return[2]}}))}()},e.forEach((function(e){return c.insert(e)})),Object.freeze(this)}a.initSize=16,a.maxSize=1<<30,a.sigma=.75,a.treeifyThreshold=8,a.untreeifyThreshold=6,a.minTreeifySize=64,Object.freeze(a),i.default=a},{"../LinkList/LinkList":29,"../Set/Set":33}],29:[function(e,t,i){"use strict";var n=this&&this.__generator||function(e,t){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}};Object.defineProperty(i,"__esModule",{value:!0});var r=function(e){this.value=void 0,this.pre=void 0,this.next=void 0,this.value=e};function o(e){var t=this;void 0===e&&(e=[]);var i=0,o=void 0,s=void 0;this.size=function(){return i},this.empty=function(){return 0===i},this.clear=function(){o=s=void 0,i=0},this.front=function(){return null==o?void 0:o.value},this.back=function(){return null==s?void 0:s.value},this.forEach=function(e){for(var t=o,i=0;t;){if(void 0===t.value)throw new Error("unknown error");e(t.value,i++),t=t.next}},this.getElementByPos=function(e){if(e<0||e>=i)throw new Error("pos must more then 0 and less then the list length");for(var t=o;e--&&t;)t=t.next;if(!t||void 0===t.value)throw new Error("unknown error");return t.value},this.eraseElementByPos=function(e){if(e<0||e>=i)throw new Error("erase pos must more then 0 and less then the list length");if(0===e)this.popFront();else if(e===i-1)this.popBack();else{for(var t=o;e--;){if(!(null==t?void 0:t.next))throw new Error("unknown error");t=t.next}if(!t||!t.pre||!t.next)throw new Error("unknown error");var n=t.pre,r=t.next;r.pre=n,n.next=r,i>0&&--i}},this.eraseElementByValue=function(e){for(;o&&o.value===e;)this.popFront();for(;s&&s.value===e;)this.popBack();if(o)for(var t=o;t;){if(t.value===e){var n=t.pre,r=t.next;r&&(r.pre=n),n&&(n.next=r),i>0&&--i}t=t.next}},this.pushBack=function(e){if(null==e)throw new Error("you can't push null or undefined here");++i;var t=new r(e);s?(s.next=t,t.pre=s,s=t):o=s=t},this.popBack=function(){s&&(i>0&&--i,s&&(o===s?o=s=void 0:(s=s.pre)&&(s.next=void 0)))},this.setElementByPos=function(e,t){if(null==t)throw new Error("you can't set null or undefined here");if(e<0||e>=i)throw new Error("pos must more then 0 and less then the list length");for(var n=o;e--;){if(!n)throw new Error("unknown error");n=n.next}n&&(n.value=t)},this.insert=function(e,t,n){if(void 0===n&&(n=1),null==t)throw new Error("you can't insert null or undefined here");if(e<0||e>i)throw new Error("insert pos must more then 0 and less then or equal to the list length");if(n<0)throw new Error("insert size must more than 0");if(0===e)for(;n--;)this.pushFront(t);else if(e===i)for(;n--;)this.pushBack(t);else{for(var s=o,a=1;a<e;++a){if(!(null==s?void 0:s.next))throw new Error("unknown error");s=null==s?void 0:s.next}if(!s)throw new Error("unknown error");var c=s.next;for(i+=n;n--;)s.next=new r(t),s.next.pre=s,s=s.next;s.next=c,c&&(c.pre=s)}},this.find=function(e){for(var t=o;t;){if(t.value===e)return!0;t=t.next}return!1},this.reverse=function(){for(var e=o,t=s,n=0;e&&t&&2*n<i;){var r=e.value;e.value=t.value,t.value=r,e=e.next,t=t.pre,++n}},this.unique=function(){for(var e=o;e;){for(var t=e;t&&t.next&&t.value===t.next.value;)t=t.next,i>0&&--i;e.next=t.next,e.next&&(e.next.pre=e),e=e.next}},this.sort=function(e){var t=[];this.forEach((function(e){t.push(e)})),t.sort(e);var i=o;t.forEach((function(e){i&&(i.value=e,i=i.next)}))},this.pushFront=function(e){if(null==e)throw new Error("you can't push null or undefined here");++i;var t=new r(e);o?(t.next=o,o.pre=t,o=t):o=s=t},this.popFront=function(){o&&(i>0&&--i,o&&(o===s?o=s=void 0:(o=o.next)&&(o.pre=void 0)))},this.merge=function(e){var t=this,n=o;e.forEach((function(e){for(;n&&void 0!==n.value&&n.value<=e;)n=n.next;if(void 0===n)t.pushBack(e),n=s;else if(n===o)t.pushFront(e),n=o;else{++i;var a=n.pre;a&&(a.next=new r(e),a.next.pre=a,a.next.next=n,n&&(n.pre=a.next))}}))},this[Symbol.iterator]=function(){return function(){var e;return n(this,(function(t){switch(t.label){case 0:e=o,t.label=1;case 1:if(void 0===e)return[3,3];if(!e.value)throw new Error("unknown error");return[4,e.value];case 2:return t.sent(),e=e.next,[3,1];case 3:return[2]}}))}()},e.forEach((function(e){return t.pushBack(e)})),Object.freeze(this)}Object.freeze(o),i.default=o},{}],30:[function(e,t,i){"use strict";var n=this&&this.__generator||function(e,t){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},r=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,i=t&&e[t],n=0;if(i)return i.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(i,"__esModule",{value:!0});var o=e("../Base/TreeNode");function s(e,t){var i=this;void 0===e&&(e=[]),t=t||function(e,t){return e<t?-1:e>t?1:0};var s=0,a=new o.default;a.color=o.default.TreeNodeColorType.black,this.size=function(){return s},this.empty=function(){return 0===s},this.clear=function(){s=0,a.key=a.value=void 0,a.leftChild=a.rightChild=a.brother=void 0};var c=function(e){if(!e||void 0===e.key)throw new Error("unknown error");return e.leftChild?c(e.leftChild):e},l=function(e){if(!e||void 0===e.key)throw new Error("unknown error");return e.rightChild?l(e.rightChild):e};this.front=function(){if(!this.empty()){var e=c(a);if(void 0===e.key||void 0===e.value)throw new Error("unknown error");return{key:e.key,value:e.value}}},this.back=function(){if(!this.empty()){var e=l(a);if(void 0===e.key||void 0===e.value)throw new Error("unknown error");return{key:e.key,value:e.value}}},this.forEach=function(e){var t,i,n=0;try{for(var o=r(this),s=o.next();!s.done;s=o.next())e(s.value,n++)}catch(e){t={error:e}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}},this.getElementByPos=function(e){var t,i;if(e<0||e>=this.size())throw new Error("pos must more than 0 and less than set's size");var n=0;try{for(var o=r(this),s=o.next();!s.done;s=o.next()){var a=s.value;if(n===e)return a;++n}}catch(e){t={error:e}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}throw new Error("unknown Error")};var h=function(e,i){if(e&&void 0!==e.key&&void 0!==e.value){var n=t(e.key,i);return 0===n?{key:e.key,value:e.value}:n<0?h(e.rightChild,i):h(e.leftChild,i)||{key:e.key,value:e.value}}};this.lowerBound=function(e){return h(a,e)};var u=function(e,i){if(e&&void 0!==e.key&&void 0!==e.value)return t(e.key,i)<=0?u(e.rightChild,i):u(e.leftChild,i)||{key:e.key,value:e.value}};this.upperBound=function(e){return u(a,e)};var d=function(e,i){if(e&&void 0!==e.key&&void 0!==e.value){var n=t(e.key,i);return 0===n?{key:e.key,value:e.value}:n>0?d(e.leftChild,i):d(e.rightChild,i)||{key:e.key,value:e.value}}};this.reverseLowerBound=function(e){return d(a,e)};var f=function(e,i){if(e&&void 0!==e.key&&void 0!==e.value)return t(e.key,i)>=0?f(e.leftChild,i):f(e.rightChild,i)||{key:e.key,value:e.value}};this.reverseUpperBound=function(e){return f(a,e)};var p=function(e){var t=e.parent;if(!t){if(e===a)return;throw new Error("unknown error")}if(e.color!==o.default.TreeNodeColorType.red){var i=e.brother;if(!i)throw new Error("unknown error");if(e===t.leftChild)if(i.color===o.default.TreeNodeColorType.red){i.color=o.default.TreeNodeColorType.black,t.color=o.default.TreeNodeColorType.red;var n=t.rotateLeft();a===t&&(a=n),p(e)}else i.color===o.default.TreeNodeColorType.black&&(i.rightChild&&i.rightChild.color===o.default.TreeNodeColorType.red?(i.color=t.color,t.color=o.default.TreeNodeColorType.black,i.rightChild&&(i.rightChild.color=o.default.TreeNodeColorType.black),n=t.rotateLeft(),a===t&&(a=n),e.color=o.default.TreeNodeColorType.black):i.rightChild&&i.rightChild.color!==o.default.TreeNodeColorType.black||!i.leftChild||i.leftChild.color!==o.default.TreeNodeColorType.red?i.leftChild&&i.leftChild.color!==o.default.TreeNodeColorType.black||i.rightChild&&i.rightChild.color!==o.default.TreeNodeColorType.black||(i.color=o.default.TreeNodeColorType.red,p(t)):(i.color=o.default.TreeNodeColorType.red,i.leftChild&&(i.leftChild.color=o.default.TreeNodeColorType.black),n=i.rotateRight(),a===i&&(a=n),p(e)));else e===t.rightChild&&(i.color===o.default.TreeNodeColorType.red?(i.color=o.default.TreeNodeColorType.black,t.color=o.default.TreeNodeColorType.red,n=t.rotateRight(),a===t&&(a=n),p(e)):i.color===o.default.TreeNodeColorType.black&&(i.leftChild&&i.leftChild.color===o.default.TreeNodeColorType.red?(i.color=t.color,t.color=o.default.TreeNodeColorType.black,i.leftChild&&(i.leftChild.color=o.default.TreeNodeColorType.black),n=t.rotateRight(),a===t&&(a=n),e.color=o.default.TreeNodeColorType.black):i.leftChild&&i.leftChild.color!==o.default.TreeNodeColorType.black||!i.rightChild||i.rightChild.color!==o.default.TreeNodeColorType.red?i.leftChild&&i.leftChild.color!==o.default.TreeNodeColorType.black||i.rightChild&&i.rightChild.color!==o.default.TreeNodeColorType.black||(i.color=o.default.TreeNodeColorType.red,p(t)):(i.color=o.default.TreeNodeColorType.red,i.rightChild&&(i.rightChild.color=o.default.TreeNodeColorType.black),n=i.rotateLeft(),a===i&&(a=n),p(e))))}else e.color=o.default.TreeNodeColorType.black},v=function(e){for(var t=e;t.leftChild||t.rightChild;){if(t.rightChild){t=c(t.rightChild);var i=e.key;e.key=t.key,t.key=i;var n=e.value;e.value=t.value,t.value=n,e=t}t.leftChild&&(t=l(t.leftChild),i=e.key,e.key=t.key,t.key=i,n=e.value,e.value=t.value,t.value=n,e=t)}p(t),t&&t.remove(),--s,a.color=o.default.TreeNodeColorType.black},x=function(e,t){return!(!e||void 0===e.key)&&(!!x(e.leftChild,t)||!!t(e)||x(e.rightChild,t))};this.eraseElementByPos=function(e){if(e<0||e>=s)throw new Error("pos must more than 0 and less than set's size");var t=0;x(a,(function(i){return e===t?(v(i),!0):(++t,!1)}))},this.eraseElementByKey=function(e){if(!this.empty()){var i=m(a,e);void 0!==i&&void 0!==i.key&&0===t(i.key,e)&&v(i)}};var g=function(e,i){if(!e||void 0===e.key)throw new Error("unknown error");var n=t(i,e.key);return n<0?e.leftChild?g(e.leftChild,i):(e.leftChild=new o.default,e.leftChild.parent=e,e.leftChild.brother=e.rightChild,e.rightChild&&(e.rightChild.brother=e.leftChild),e.leftChild):n>0?e.rightChild?g(e.rightChild,i):(e.rightChild=new o.default,e.rightChild.parent=e,e.rightChild.brother=e.leftChild,e.leftChild&&(e.leftChild.brother=e.rightChild),e.rightChild):e},y=function(e){var t=e.parent;if(!t){if(e===a)return;throw new Error("unknown error")}if(t.color!==o.default.TreeNodeColorType.black&&t.color===o.default.TreeNodeColorType.red){var i=t.brother,n=t.parent;if(!n)throw new Error("unknown error");if(i&&i.color===o.default.TreeNodeColorType.red)i.color=t.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red,y(n);else if(!i||i.color===o.default.TreeNodeColorType.black)if(t===n.leftChild)if(e===t.leftChild){t.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red;var r=n.rotateRight();n===a&&(a=r)}else e===t.rightChild&&(r=t.rotateLeft(),n===a&&(a=r),y(t));else t===n.rightChild&&(e===t.leftChild?(r=t.rotateRight(),n===a&&(a=r),y(t)):e===t.rightChild&&(t.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red,r=n.rotateLeft(),n===a&&(a=r)))}};this.setElement=function(e,i){if(null==e)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(null!=i){if(this.empty())return++s,a.key=e,a.value=i,void(a.color=o.default.TreeNodeColorType.black);var n=g(a,e);void 0===n.key||0!==t(n.key,e)?(++s,n.key=e,n.value=i,y(n),a.color=o.default.TreeNodeColorType.black):n.value=i}else this.eraseElementByKey(e)};var m=function(e,i){if(e&&void 0!==e.key){var n=t(i,e.key);return n<0?m(e.leftChild,i):n>0?m(e.rightChild,i):e}};this.find=function(e){return!!m(a,e)},this.getElementByKey=function(e){var t=m(a,e);if(void 0===(null==t?void 0:t.key)||void 0===(null==t?void 0:t.value))throw new Error("unknown error");return t.value},this.union=function(e){var t=this;e.forEach((function(e){var i=e.key,n=e.value;return t.setElement(i,n)}))},this.getHeight=function(){if(this.empty())return 0;var e=function(t){return t?Math.max(e(t.leftChild),e(t.rightChild))+1:1};return e(a)};var b=function(e){return n(this,(function(t){switch(t.label){case 0:return e&&void 0!==e.key&&void 0!==e.value?[5,r(b(e.leftChild))]:[2];case 1:return t.sent(),[4,{key:e.key,value:e.value}];case 2:return t.sent(),[5,r(b(e.rightChild))];case 3:return t.sent(),[2]}}))};this[Symbol.iterator]=function(){return b(a)},e.forEach((function(e){var t=e.key,n=e.value;return i.setElement(t,n)})),Object.freeze(this)}Object.freeze(s),i.default=s},{"../Base/TreeNode":25}],31:[function(e,t,i){"use strict";function n(e,t){void 0===e&&(e=[]),t=t||function(e,t){return e>t?-1:e<t?1:0};var i=[];e.forEach((function(e){return i.push(e)}));var n=i.length,r=function(e,t){if(e<0||e>=n)throw new Error("unknown error");if(t<0||t>=n)throw new Error("unknown error");var r=i[e];i[e]=i[t],i[t]=r},o=function(e){if(e<0||e>=n)throw new Error("unknown error");var o=2*e+1,s=2*e+2;o<n&&t(i[e],i[o])>0&&r(e,o),s<n&&t(i[e],i[s])>0&&r(e,s)};!function(){for(var e=Math.floor((n-1)/2);e>=0;--e)for(var o=e,s=2*o+1;s<n;){var a=s+1,c=s;if(a<n&&t(i[s],i[a])>0&&(c=a),t(i[o],i[c])<=0)break;r(o,c),s=2*(o=c)+1}}(),this.size=function(){return n},this.empty=function(){return 0===n},this.clear=function(){n=0,i.length=0},this.push=function(e){if(i.push(e),1!=++n)for(var r=n-1;r>0;){var s=Math.floor((r-1)/2);if(t(i[s],e)<=0)break;o(s),r=s}},this.pop=function(){if(!this.empty())if(1!==this.size()){var e=i[n-1];--n;for(var r=0;r<this.size();){var o=2*r+1,s=2*r+2;if(o>=this.size())break;var a=o;if(s<this.size()&&t(i[o],i[s])>0&&(a=s),t(i[a],e)>=0)break;i[r]=i[a],r=a}i[r]=e}else--n},this.top=function(){return i[0]},Object.freeze(this)}Object.defineProperty(i,"__esModule",{value:!0}),Object.freeze(n),i.default=n},{}],32:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});var n=e("../LinkList/LinkList");function r(e){void 0===e&&(e=[]);var t=new n.default(e);this.size=function(){return t.size()},this.empty=function(){return t.empty()},this.clear=function(){t.clear()},this.push=function(e){t.pushBack(e)},this.pop=function(){t.popFront()},this.front=function(){return t.front()},Object.freeze(this)}Object.freeze(r),i.default=r},{"../LinkList/LinkList":29}],33:[function(e,t,i){"use strict";var n=this&&this.__generator||function(e,t){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},r=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,i=t&&e[t],n=0;if(i)return i.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(i,"__esModule",{value:!0});var o=e("../Base/TreeNode");function s(e,t){var i=this;void 0===e&&(e=[]),t=t||function(e,t){return e<t?-1:e>t?1:0};var s=0,a=new o.default;a.color=o.default.TreeNodeColorType.black,this.size=function(){return s},this.empty=function(){return 0===s},this.clear=function(){s=0,a.key=void 0,a.leftChild=a.rightChild=a.brother=a.parent=void 0,a.color=o.default.TreeNodeColorType.black};var c=function(e){if(!e||void 0===e.key)throw new Error("unknown error");return e.leftChild?c(e.leftChild):e},l=function(e){if(!e||void 0===e.key)throw new Error("unknown error");return e.rightChild?l(e.rightChild):e};this.front=function(){if(!this.empty())return c(a).key},this.back=function(){if(!this.empty())return l(a).key},this.forEach=function(e){var t,i,n=0;try{for(var o=r(this),s=o.next();!s.done;s=o.next())e(s.value,n++)}catch(e){t={error:e}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}},this.getElementByPos=function(e){var t,i;if(e<0||e>=this.size())throw new Error("pos must more than 0 and less than set's size");var n=0;try{for(var o=r(this),s=o.next();!s.done;s=o.next()){var a=s.value;if(n===e)return a;++n}}catch(e){t={error:e}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}throw new Error("unknown error")};var h=function(e){var t=e.parent;if(!t){if(e===a)return;throw new Error("unknown error")}if(e.color!==o.default.TreeNodeColorType.red){var i=e.brother;if(!i)throw new Error("unknown error");if(e===t.leftChild)if(i.color===o.default.TreeNodeColorType.red){i.color=o.default.TreeNodeColorType.black,t.color=o.default.TreeNodeColorType.red;var n=t.rotateLeft();a===t&&(a=n),h(e)}else i.color===o.default.TreeNodeColorType.black&&(i.rightChild&&i.rightChild.color===o.default.TreeNodeColorType.red?(i.color=t.color,t.color=o.default.TreeNodeColorType.black,i.rightChild&&(i.rightChild.color=o.default.TreeNodeColorType.black),n=t.rotateLeft(),a===t&&(a=n),e.color=o.default.TreeNodeColorType.black):i.rightChild&&i.rightChild.color!==o.default.TreeNodeColorType.black||!i.leftChild||i.leftChild.color!==o.default.TreeNodeColorType.red?i.leftChild&&i.leftChild.color!==o.default.TreeNodeColorType.black||i.rightChild&&i.rightChild.color!==o.default.TreeNodeColorType.black||(i.color=o.default.TreeNodeColorType.red,h(t)):(i.color=o.default.TreeNodeColorType.red,i.leftChild&&(i.leftChild.color=o.default.TreeNodeColorType.black),n=i.rotateRight(),a===i&&(a=n),h(e)));else e===t.rightChild&&(i.color===o.default.TreeNodeColorType.red?(i.color=o.default.TreeNodeColorType.black,t.color=o.default.TreeNodeColorType.red,n=t.rotateRight(),a===t&&(a=n),h(e)):i.color===o.default.TreeNodeColorType.black&&(i.leftChild&&i.leftChild.color===o.default.TreeNodeColorType.red?(i.color=t.color,t.color=o.default.TreeNodeColorType.black,i.leftChild&&(i.leftChild.color=o.default.TreeNodeColorType.black),n=t.rotateRight(),a===t&&(a=n),e.color=o.default.TreeNodeColorType.black):i.leftChild&&i.leftChild.color!==o.default.TreeNodeColorType.black||!i.rightChild||i.rightChild.color!==o.default.TreeNodeColorType.red?i.leftChild&&i.leftChild.color!==o.default.TreeNodeColorType.black||i.rightChild&&i.rightChild.color!==o.default.TreeNodeColorType.black||(i.color=o.default.TreeNodeColorType.red,h(t)):(i.color=o.default.TreeNodeColorType.red,i.rightChild&&(i.rightChild.color=o.default.TreeNodeColorType.black),n=i.rotateLeft(),a===i&&(a=n),h(e))))}else e.color=o.default.TreeNodeColorType.black},u=function(e){for(var t=e;t.leftChild||t.rightChild;){if(t.rightChild){t=c(t.rightChild);var i=e.key;e.key=t.key,t.key=i,e=t}t.leftChild&&(t=l(t.leftChild),i=e.key,e.key=t.key,t.key=i,e=t)}h(t),t&&t.remove(),--s,a.color=o.default.TreeNodeColorType.black},d=function(e,t){return!(!e||void 0===e.key)&&(!!d(e.leftChild,t)||!!t(e)||d(e.rightChild,t))};this.eraseElementByPos=function(e){if(e<0||e>=s)throw new Error("pos must more than 0 and less than set's size");var t=0;d(a,(function(i){return e===t?(u(i),!0):(++t,!1)}))},this.eraseElementByValue=function(e){if(!this.empty()){var i=v(a,e);void 0!==i&&void 0!==i.key&&0===t(i.key,e)&&u(i)}};var f=function(e,i){if(!e||void 0===e.key)throw new Error("unknown error");var n=t(i,e.key);return n<0?e.leftChild?f(e.leftChild,i):(e.leftChild=new o.default,e.leftChild.parent=e,e.leftChild.brother=e.rightChild,e.rightChild&&(e.rightChild.brother=e.leftChild),e.leftChild):n>0?e.rightChild?f(e.rightChild,i):(e.rightChild=new o.default,e.rightChild.parent=e,e.rightChild.brother=e.leftChild,e.leftChild&&(e.leftChild.brother=e.rightChild),e.rightChild):e},p=function(e){var t=e.parent;if(!t){if(e===a)return;throw new Error("unknown error")}if(t.color!==o.default.TreeNodeColorType.black&&t.color===o.default.TreeNodeColorType.red){var i=t.brother,n=t.parent;if(!n)throw new Error("unknown error");if(i&&i.color===o.default.TreeNodeColorType.red)i.color=t.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red,p(n);else if(!i||i.color===o.default.TreeNodeColorType.black)if(t===n.leftChild)if(e===t.leftChild){t.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red;var r=n.rotateRight();n===a&&(a=r)}else e===t.rightChild&&(r=t.rotateLeft(),n===a&&(a=r),p(t));else t===n.rightChild&&(e===t.leftChild?(r=t.rotateRight(),n===a&&(a=r),p(t)):e===t.rightChild&&(t.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red,r=n.rotateLeft(),n===a&&(a=r)))}};this.insert=function(e){if(null==e)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(this.empty())return++s,a.key=e,void(a.color=o.default.TreeNodeColorType.black);var i=f(a,e);void 0!==i.key&&0===t(i.key,e)||(++s,i.key=e,p(i),a.color=o.default.TreeNodeColorType.black)};var v=function(e,i){if(e&&void 0!==e.key){var n=t(i,e.key);return n<0?v(e.leftChild,i):n>0?v(e.rightChild,i):e}};this.find=function(e){var i=v(a,e);return void 0!==i&&void 0!==i.key&&0===t(i.key,e)};var x=function(e,i){if(e&&void 0!==e.key){var n=t(e.key,i);if(0===n)return e.key;if(n<0)return x(e.rightChild,i);var r=x(e.leftChild,i);return void 0!==r?r:e.key}};this.lowerBound=function(e){return x(a,e)};var g=function(e,i){if(e&&void 0!==e.key){if(t(e.key,i)<=0)return g(e.rightChild,i);var n=g(e.leftChild,i);return void 0!==n?n:e.key}};this.upperBound=function(e){return g(a,e)};var y=function(e,i){if(e&&void 0!==e.key){var n=t(e.key,i);if(0===n)return e.key;if(n>0)return y(e.leftChild,i);var r=y(e.rightChild,i);return void 0!==r?r:e.key}};this.reverseLowerBound=function(e){return y(a,e)};var m=function(e,i){if(e&&void 0!==e.key){if(t(e.key,i)>=0)return m(e.leftChild,i);var n=m(e.rightChild,i);return void 0!==n?n:e.key}};this.reverseUpperBound=function(e){return m(a,e)},this.union=function(e){var t=this;e.forEach((function(e){return t.insert(e)}))},this.getHeight=function(){if(this.empty())return 0;var e=function(t){return t?Math.max(e(t.leftChild),e(t.rightChild))+1:1};return e(a)};var b=function(e){return n(this,(function(t){switch(t.label){case 0:return e&&void 0!==e.key?[5,r(b(e.leftChild))]:[2];case 1:return t.sent(),[4,e.key];case 2:return t.sent(),[5,r(b(e.rightChild))];case 3:return t.sent(),[2]}}))};this[Symbol.iterator]=function(){return b(a)},e.forEach((function(e){return i.insert(e)})),Object.freeze(this)}Object.freeze(s),i.default=s},{"../Base/TreeNode":25}],34:[function(e,t,i){"use strict";function n(e){var t=this;void 0===e&&(e=[]);var i=0,n=[];this.size=function(){return i},this.empty=function(){return 0===i},this.clear=function(){i=0,n.length=0},this.push=function(e){n.push(e),++i},this.pop=function(){n.pop(),i>0&&--i},this.top=function(){return n[i-1]},e.forEach((function(e){return t.push(e)})),Object.freeze(this)}Object.defineProperty(i,"__esModule",{value:!0}),Object.freeze(n),i.default=n},{}],35:[function(e,t,i){"use strict";var n=this&&this.__generator||function(e,t){var i,n,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,n&&(r=2&o[0]?n.return:o[0]?n.throw||((r=n.return)&&r.call(n),0):n.next)&&!(r=r.call(n,o[1])).done)return r;switch(n=0,r&&(o=[2&o[0],r.value]),o[0]){case 0:case 1:r=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},r=this&&this.__read||function(e,t){var i="function"==typeof Symbol&&e[Symbol.iterator];if(!i)return e;var n,r,o=i.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return s},o=this&&this.__spreadArray||function(e,t,i){if(i||2===arguments.length)for(var n,r=0,o=t.length;r<o;r++)!n&&r in t||(n||(n=Array.prototype.slice.call(t,0,r)),n[r]=t[r]);return e.concat(n||Array.prototype.slice.call(t))},s=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,i=t&&e[t],n=0;if(i)return i.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};function a(e){var t=this;void 0===e&&(e=[]);var i=0,a=[];this.size=function(){return i},this.empty=function(){return 0===i},this.clear=function(){i=0,a.length=0},this.front=function(){if(!this.empty())return a[0]},this.back=function(){if(!this.empty())return a[i-1]},this.forEach=function(e){a.forEach(e)},this.getElementByPos=function(e){if(e<0||e>=i)throw new Error("pos must more than 0 and less than vector's size");return a[e]},this.eraseElementByPos=function(e){if(e<0||e>=i)throw new Error("pos must more than 0 and less than vector's size");for(var t=e;t<i-1;++t)a[t]=a[t+1];this.popBack()},this.eraseElementByValue=function(e){var t=[];this.forEach((function(i){i!==e&&t.push(i)})),t.forEach((function(e,t){a[t]=e}));for(var n=t.length;i>n;)this.popBack()},this.pushBack=function(e){a.push(e),++i},this.popBack=function(){a.pop(),i>0&&--i},this.setElementByPos=function(e,t){if(e<0||e>=i)throw new Error("pos must more than 0 and less than vector's size");a[e]=t},this.insert=function(e,t,n){if(void 0===n&&(n=1),e<0||e>i)throw new Error("pos must more than 0 and less than or equal to vector's size");a.splice.apply(a,o([e,0],r(new Array(n).fill(t)),!1)),i+=n},this.find=function(e){return a.includes(e)},this.reverse=function(){a.reverse()},this.unique=function(){var e,t=[];this.forEach((function(i,n){0!==n&&i===e||(t.push(i),e=i)})),t.forEach((function(e,t){a[t]=e}));for(var n=t.length;i>n;)this.popBack()},this.sort=function(e){a.sort(e)},this[Symbol.iterator]=function(){return function(){return n(this,(function(e){switch(e.label){case 0:return[5,s(a)];case 1:return[2,e.sent()]}}))}()},e.forEach((function(e){return t.pushBack(e)})),Object.freeze(this)}Object.defineProperty(i,"__esModule",{value:!0}),Object.freeze(a),i.default=a},{}],36:[function(e,t,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0}),i.HashMap=i.HashSet=i.Map=i.Set=i.PriorityQueue=i.Deque=i.LinkList=i.Queue=i.Stack=i.Vector=void 0;var n=e("./Vector/Vector");i.Vector=n.default;var r=e("./Stack/Stack");i.Stack=r.default;var o=e("./Queue/Queue");i.Queue=o.default;var s=e("./LinkList/LinkList");i.LinkList=s.default;var a=e("./Deque/Deque");i.Deque=a.default;var c=e("./PriorityQueue/PriorityQueue");i.PriorityQueue=c.default;var l=e("./Set/Set");i.Set=l.default;var h=e("./Map/Map");i.Map=h.default;var u=e("./HashSet/HashSet");i.HashSet=u.default;var d=e("./HashMap/HashMap");i.HashMap=d.default},{"./Deque/Deque":26,"./HashMap/HashMap":27,"./HashSet/HashSet":28,"./LinkList/LinkList":29,"./Map/Map":30,"./PriorityQueue/PriorityQueue":31,"./Queue/Queue":32,"./Set/Set":33,"./Stack/Stack":34,"./Vector/Vector":35}],37:[function(e,t,i){"use strict";const n=e("yallist"),r=Symbol("max"),o=Symbol("length"),s=Symbol("lengthCalculator"),a=Symbol("allowStale"),c=Symbol("maxAge"),l=Symbol("dispose"),h=Symbol("noDisposeOnSet"),u=Symbol("lruList"),d=Symbol("cache"),f=Symbol("updateAgeOnGet"),p=()=>1,v=(e,t,i)=>{const n=e[d].get(t);if(n){const t=n.value;if(x(e,t)){if(y(e,n),!e[a])return}else i&&(e[f]&&(n.value.now=Date.now()),e[u].unshiftNode(n));return t.value}},x=(e,t)=>{if(!t||!t.maxAge&&!e[c])return!1;const i=Date.now()-t.now;return t.maxAge?i>t.maxAge:e[c]&&i>e[c]},g=e=>{if(e[o]>e[r])for(let t=e[u].tail;e[o]>e[r]&&null!==t;){const i=t.prev;y(e,t),t=i}},y=(e,t)=>{if(t){const i=t.value;e[l]&&e[l](i.key,i.value),e[o]-=i.length,e[d].delete(i.key),e[u].removeNode(t)}};class m{constructor(e,t,i,n,r){this.key=e,this.value=t,this.length=i,this.now=n,this.maxAge=r||0}}const b=(e,t,i,n)=>{let r=i.value;x(e,r)&&(y(e,i),e[a]||(r=void 0)),r&&t.call(n,r.value,r.key,e)};t.exports=class{constructor(e){if("number"==typeof e&&(e={max:e}),e||(e={}),e.max&&("number"!=typeof e.max||e.max<0))throw new TypeError("max must be a non-negative number");this[r]=e.max||1/0;const t=e.length||p;if(this[s]="function"!=typeof t?p:t,this[a]=e.stale||!1,e.maxAge&&"number"!=typeof e.maxAge)throw new TypeError("maxAge must be a number");this[c]=e.maxAge||0,this[l]=e.dispose,this[h]=e.noDisposeOnSet||!1,this[f]=e.updateAgeOnGet||!1,this.reset()}set max(e){if("number"!=typeof e||e<0)throw new TypeError("max must be a non-negative number");this[r]=e||1/0,g(this)}get max(){return this[r]}set allowStale(e){this[a]=!!e}get allowStale(){return this[a]}set maxAge(e){if("number"!=typeof e)throw new TypeError("maxAge must be a non-negative number");this[c]=e,g(this)}get maxAge(){return this[c]}set lengthCalculator(e){"function"!=typeof e&&(e=p),e!==this[s]&&(this[s]=e,this[o]=0,this[u].forEach((e=>{e.length=this[s](e.value,e.key),this[o]+=e.length}))),g(this)}get lengthCalculator(){return this[s]}get length(){return this[o]}get itemCount(){return this[u].length}rforEach(e,t){t=t||this;for(let i=this[u].tail;null!==i;){const n=i.prev;b(this,e,i,t),i=n}}forEach(e,t){t=t||this;for(let i=this[u].head;null!==i;){const n=i.next;b(this,e,i,t),i=n}}keys(){return this[u].toArray().map((e=>e.key))}values(){return this[u].toArray().map((e=>e.value))}reset(){this[l]&&this[u]&&this[u].length&&this[u].forEach((e=>this[l](e.key,e.value))),this[d]=new Map,this[u]=new n,this[o]=0}dump(){return this[u].map((e=>!x(this,e)&&{k:e.key,v:e.value,e:e.now+(e.maxAge||0)})).toArray().filter((e=>e))}dumpLru(){return this[u]}set(e,t,i){if((i=i||this[c])&&"number"!=typeof i)throw new TypeError("maxAge must be a number");const n=i?Date.now():0,a=this[s](t,e);if(this[d].has(e)){if(a>this[r])return y(this,this[d].get(e)),!1;const s=this[d].get(e).value;return this[l]&&(this[h]||this[l](e,s.value)),s.now=n,s.maxAge=i,s.value=t,this[o]+=a-s.length,s.length=a,this.get(e),g(this),!0}const f=new m(e,t,a,n,i);return f.length>this[r]?(this[l]&&this[l](e,t),!1):(this[o]+=f.length,this[u].unshift(f),this[d].set(e,this[u].head),g(this),!0)}has(e){if(!this[d].has(e))return!1;const t=this[d].get(e).value;return!x(this,t)}get(e){return v(this,e,!0)}peek(e){return v(this,e,!1)}pop(){const e=this[u].tail;return e?(y(this,e),e.value):null}del(e){y(this,this[d].get(e))}load(e){this.reset();const t=Date.now();for(let i=e.length-1;i>=0;i--){const n=e[i],r=n.e||0;if(0===r)this.set(n.k,n.v);else{const e=r-t;e>0&&this.set(n.k,n.v,e)}}}prune(){this[d].forEach(((e,t)=>v(this,t,!1)))}}},{yallist:83}],38:[function(e,t,i){(function(e){(function(){const i=t.exports;i.types={0:"reserved",1:"connect",2:"connack",3:"publish",4:"puback",5:"pubrec",6:"pubrel",7:"pubcomp",8:"subscribe",9:"suback",10:"unsubscribe",11:"unsuback",12:"pingreq",13:"pingresp",14:"disconnect",15:"auth"},i.codes={};for(const e in i.types){const t=i.types[e];i.codes[t]=e}i.CMD_SHIFT=4,i.CMD_MASK=240,i.DUP_MASK=8,i.QOS_MASK=3,i.QOS_SHIFT=1,i.RETAIN_MASK=1,i.VARBYTEINT_MASK=127,i.VARBYTEINT_FIN_MASK=128,i.VARBYTEINT_MAX=268435455,i.SESSIONPRESENT_MASK=1,i.SESSIONPRESENT_HEADER=e.from([i.SESSIONPRESENT_MASK]),i.CONNACK_HEADER=e.from([i.codes.connack<<i.CMD_SHIFT]),i.USERNAME_MASK=128,i.PASSWORD_MASK=64,i.WILL_RETAIN_MASK=32,i.WILL_QOS_MASK=24,i.WILL_QOS_SHIFT=3,i.WILL_FLAG_MASK=4,i.CLEAN_SESSION_MASK=2,i.CONNECT_HEADER=e.from([i.codes.connect<<i.CMD_SHIFT]),i.properties={sessionExpiryInterval:17,willDelayInterval:24,receiveMaximum:33,maximumPacketSize:39,topicAliasMaximum:34,requestResponseInformation:25,requestProblemInformation:23,userProperties:38,authenticationMethod:21,authenticationData:22,payloadFormatIndicator:1,messageExpiryInterval:2,contentType:3,responseTopic:8,correlationData:9,maximumQoS:36,retainAvailable:37,assignedClientIdentifier:18,reasonString:31,wildcardSubscriptionAvailable:40,subscriptionIdentifiersAvailable:41,sharedSubscriptionAvailable:42,serverKeepAlive:19,responseInformation:26,serverReference:28,topicAlias:35,subscriptionIdentifier:11},i.propertiesCodes={};for(const e in i.properties){const t=i.properties[e];i.propertiesCodes[t]=e}function n(t){return[0,1,2].map((n=>[0,1].map((r=>[0,1].map((o=>{const s=e.alloc(1);return s.writeUInt8(i.codes[t]<<i.CMD_SHIFT|(r?i.DUP_MASK:0)|n<<i.QOS_SHIFT|o,0,!0),s}))))))}i.propertiesTypes={sessionExpiryInterval:"int32",willDelayInterval:"int32",receiveMaximum:"int16",maximumPacketSize:"int32",topicAliasMaximum:"int16",requestResponseInformation:"byte",requestProblemInformation:"byte",userProperties:"pair",authenticationMethod:"string",authenticationData:"binary",payloadFormatIndicator:"byte",messageExpiryInterval:"int32",contentType:"string",responseTopic:"string",correlationData:"binary",maximumQoS:"int8",retainAvailable:"byte",assignedClientIdentifier:"string",reasonString:"string",wildcardSubscriptionAvailable:"byte",subscriptionIdentifiersAvailable:"byte",sharedSubscriptionAvailable:"byte",serverKeepAlive:"int16",responseInformation:"string",serverReference:"string",topicAlias:"int16",subscriptionIdentifier:"var"},i.PUBLISH_HEADER=n("publish"),i.SUBSCRIBE_HEADER=n("subscribe"),i.SUBSCRIBE_OPTIONS_QOS_MASK=3,i.SUBSCRIBE_OPTIONS_NL_MASK=1,i.SUBSCRIBE_OPTIONS_NL_SHIFT=2,i.SUBSCRIBE_OPTIONS_RAP_MASK=1,i.SUBSCRIBE_OPTIONS_RAP_SHIFT=3,i.SUBSCRIBE_OPTIONS_RH_MASK=3,i.SUBSCRIBE_OPTIONS_RH_SHIFT=4,i.SUBSCRIBE_OPTIONS_RH=[0,16,32],i.SUBSCRIBE_OPTIONS_NL=4,i.SUBSCRIBE_OPTIONS_RAP=8,i.SUBSCRIBE_OPTIONS_QOS=[0,1,2],i.UNSUBSCRIBE_HEADER=n("unsubscribe"),i.ACKS={unsuback:n("unsuback"),puback:n("puback"),pubcomp:n("pubcomp"),pubrel:n("pubrel"),pubrec:n("pubrec")},i.SUBACK_HEADER=e.from([i.codes.suback<<i.CMD_SHIFT]),i.VERSION3=e.from([3]),i.VERSION4=e.from([4]),i.VERSION5=e.from([5]),i.VERSION131=e.from([131]),i.VERSION132=e.from([132]),i.QOS=[0,1,2].map((t=>e.from([t]))),i.EMPTY={pingreq:e.from([i.codes.pingreq<<4,0]),pingresp:e.from([i.codes.pingresp<<4,0]),disconnect:e.from([i.codes.disconnect<<4,0])}}).call(this)}).call(this,e("buffer").Buffer)},{buffer:17}],39:[function(e,t,i){(function(i){(function(){const n=e("./writeToStream"),r=e("events");class o extends r{constructor(){super(),this._array=new Array(20),this._i=0}write(e){return this._array[this._i++]=e,!0}concat(){let e=0;const t=new Array(this._array.length),n=this._array;let r,o=0;for(r=0;r<n.length&&void 0!==n[r];r++)"string"!=typeof n[r]?t[r]=n[r].length:t[r]=i.byteLength(n[r]),e+=t[r];const s=i.allocUnsafe(e);for(r=0;r<n.length&&void 0!==n[r];r++)"string"!=typeof n[r]?(n[r].copy(s,o),o+=t[r]):(s.write(n[r],o),o+=t[r]);return s}}t.exports=function(e,t){const i=new o;return n(e,i,t),i.concat()}}).call(this)}).call(this,e("buffer").Buffer)},{"./writeToStream":44,buffer:17,events:22}],40:[function(e,t,i){i.parser=e("./parser").parser,i.generate=e("./generate"),i.writeToStream=e("./writeToStream")},{"./generate":39,"./parser":43,"./writeToStream":44}],41:[function(e,t,i){(function(e){(function(){const i={},n=e.isBuffer(e.from([1,2]).subarray(0,1));function r(t){const i=e.allocUnsafe(2);return i.writeUInt8(t>>8,0),i.writeUInt8(255&t,1),i}t.exports={cache:i,generateCache:function(){for(let e=0;e<65536;e++)i[e]=r(e)},generateNumber:r,genBufVariableByteInt:function(t){let i=0,r=0;const o=e.allocUnsafe(4);do{i=t%128|0,(t=t/128|0)>0&&(i|=128),o.writeUInt8(i,r++)}while(t>0&&r<4);return t>0&&(r=0),n?o.subarray(0,r):o.slice(0,r)},generate4ByteBuffer:function(t){const i=e.allocUnsafe(4);return i.writeUInt32BE(t,0),i}}}).call(this)}).call(this,e("buffer").Buffer)},{buffer:17}],42:[function(e,t,i){t.exports=class{constructor(){this.cmd=null,this.retain=!1,this.qos=0,this.dup=!1,this.length=-1,this.topic=null,this.payload=null}}},{}],43:[function(e,t,i){const n=e("bl"),r=e("events"),o=e("./packet"),s=e("./constants"),a=e("debug")("mqtt-packet:parser");class c extends r{constructor(){super(),this.parser=this.constructor.parser}static parser(e){return this instanceof c?(this.settings=e||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):(new c).parser(e)}_resetState(){a("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new o,this.error=null,this._list=n(),this._stateCounter=0}parse(e){for(this.error&&this._resetState(),this._list.append(e),a("parse: current state: %s",this._states[this._stateCounter]);(-1!==this.packet.length||this._list.length>0)&&this[this._states[this._stateCounter]]()&&!this.error;)this._stateCounter++,a("parse: state complete. _stateCounter is now: %d",this._stateCounter),a("parse: packet.length: %d, buffer list length: %d",this.packet.length,this._list.length),this._stateCounter>=this._states.length&&(this._stateCounter=0);return a("parse: exited while loop. packet: %d, buffer list length: %d",this.packet.length,this._list.length),this._list.length}_parseHeader(){const e=this._list.readUInt8(0);return this.packet.cmd=s.types[e>>s.CMD_SHIFT],this.packet.retain=0!=(e&s.RETAIN_MASK),this.packet.qos=e>>s.QOS_SHIFT&s.QOS_MASK,this.packet.dup=0!=(e&s.DUP_MASK),a("_parseHeader: packet: %o",this.packet),this._list.consume(1),!0}_parseLength(){const e=this._parseVarByteNum(!0);return e&&(this.packet.length=e.value,this._list.consume(e.bytes)),a("_parseLength %d",e.value),!!e}_parsePayload(){a("_parsePayload: payload %O",this._list);let e=!1;if(0===this.packet.length||this._list.length>=this.packet.length){switch(this._pos=0,this.packet.cmd){case"connect":this._parseConnect();break;case"connack":this._parseConnack();break;case"publish":this._parsePublish();break;case"puback":case"pubrec":case"pubrel":case"pubcomp":this._parseConfirmation();break;case"subscribe":this._parseSubscribe();break;case"suback":this._parseSuback();break;case"unsubscribe":this._parseUnsubscribe();break;case"unsuback":this._parseUnsuback();break;case"pingreq":case"pingresp":break;case"disconnect":this._parseDisconnect();break;case"auth":this._parseAuth();break;default:this._emitError(new Error("Not supported"))}e=!0}return a("_parsePayload complete result: %s",e),e}_parseConnect(){let e,t,i,n;a("_parseConnect");const r={},o=this.packet,c=this._parseString();if(null===c)return this._emitError(new Error("Cannot parse protocolId"));if("MQTT"!==c&&"MQIsdp"!==c)return this._emitError(new Error("Invalid protocolId"));if(o.protocolId=c,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(o.protocolVersion=this._list.readUInt8(this._pos),o.protocolVersion>=128&&(o.bridgeMode=!0,o.protocolVersion=o.protocolVersion-128),3!==o.protocolVersion&&4!==o.protocolVersion&&5!==o.protocolVersion)return this._emitError(new Error("Invalid protocol version"));if(this._pos++,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(r.username=this._list.readUInt8(this._pos)&s.USERNAME_MASK,r.password=this._list.readUInt8(this._pos)&s.PASSWORD_MASK,r.will=this._list.readUInt8(this._pos)&s.WILL_FLAG_MASK,r.will&&(o.will={},o.will.retain=0!=(this._list.readUInt8(this._pos)&s.WILL_RETAIN_MASK),o.will.qos=(this._list.readUInt8(this._pos)&s.WILL_QOS_MASK)>>s.WILL_QOS_SHIFT),o.clean=0!=(this._list.readUInt8(this._pos)&s.CLEAN_SESSION_MASK),this._pos++,o.keepalive=this._parseNum(),-1===o.keepalive)return this._emitError(new Error("Packet too short"));if(5===o.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(o.properties=e)}const l=this._parseString();if(null===l)return this._emitError(new Error("Packet too short"));if(o.clientId=l,a("_parseConnect: packet.clientId: %s",o.clientId),r.will){if(5===o.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(o.will.properties=e)}if(null===(e=this._parseString()))return this._emitError(new Error("Cannot parse will topic"));if(o.will.topic=e,a("_parseConnect: packet.will.topic: %s",o.will.topic),null===(t=this._parseBuffer()))return this._emitError(new Error("Cannot parse will payload"));o.will.payload=t,a("_parseConnect: packet.will.paylaod: %s",o.will.payload)}if(r.username){if(null===(n=this._parseString()))return this._emitError(new Error("Cannot parse username"));o.username=n,a("_parseConnect: packet.username: %s",o.username)}if(r.password){if(null===(i=this._parseBuffer()))return this._emitError(new Error("Cannot parse password"));o.password=i}return this.settings=o,a("_parseConnect: complete"),o}_parseConnack(){a("_parseConnack");const e=this.packet;if(this._list.length<1)return null;if(e.sessionPresent=!!(this._list.readUInt8(this._pos++)&s.SESSIONPRESENT_MASK),5===this.settings.protocolVersion)this._list.length>=2?e.reasonCode=this._list.readUInt8(this._pos++):e.reasonCode=0;else{if(this._list.length<2)return null;e.returnCode=this._list.readUInt8(this._pos++)}if(-1===e.returnCode||-1===e.reasonCode)return this._emitError(new Error("Cannot parse return code"));if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}a("_parseConnack: complete")}_parsePublish(){a("_parsePublish");const e=this.packet;if(e.topic=this._parseString(),null===e.topic)return this._emitError(new Error("Cannot parse topic"));if(!(e.qos>0)||this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}e.payload=this._list.slice(this._pos,e.length),a("_parsePublish: payload from buffer list: %o",e.payload)}}_parseSubscribe(){a("_parseSubscribe");const e=this.packet;let t,i,n,r,o,c,l;if(1!==e.qos)return this._emitError(new Error("Wrong subscribe header"));if(e.subscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<e.length;){if(null===(t=this._parseString()))return this._emitError(new Error("Cannot parse topic"));if(this._pos>=e.length)return this._emitError(new Error("Malformed Subscribe Payload"));n=(i=this._parseByte())&s.SUBSCRIBE_OPTIONS_QOS_MASK,c=0!=(i>>s.SUBSCRIBE_OPTIONS_NL_SHIFT&s.SUBSCRIBE_OPTIONS_NL_MASK),o=0!=(i>>s.SUBSCRIBE_OPTIONS_RAP_SHIFT&s.SUBSCRIBE_OPTIONS_RAP_MASK),r=i>>s.SUBSCRIBE_OPTIONS_RH_SHIFT&s.SUBSCRIBE_OPTIONS_RH_MASK,l={topic:t,qos:n},5===this.settings.protocolVersion?(l.nl=c,l.rap=o,l.rh=r):this.settings.bridgeMode&&(l.rh=0,l.rap=!0,l.nl=!0),a("_parseSubscribe: push subscription `%s` to subscription",l),e.subscriptions.push(l)}}}_parseSuback(){a("_parseSuback");const e=this.packet;if(this.packet.granted=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseUnsubscribe(){a("_parseUnsubscribe");const e=this.packet;if(e.unsubscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}for(;this._pos<e.length;){const t=this._parseString();if(null===t)return this._emitError(new Error("Cannot parse topic"));a("_parseUnsubscribe: push topic `%s` to unsubscriptions",t),e.unsubscriptions.push(t)}}}_parseUnsuback(){a("_parseUnsuback");const e=this.packet;if(!this._parseMessageId())return this._emitError(new Error("Cannot parse messageId"));if(5===this.settings.protocolVersion){const t=this._parseProperties();for(Object.getOwnPropertyNames(t).length&&(e.properties=t),e.granted=[];this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseConfirmation(){a("_parseConfirmation: packet.cmd: `%s`",this.packet.cmd);const e=this.packet;if(this._parseMessageId(),5===this.settings.protocolVersion&&(e.length>2?(e.reasonCode=this._parseByte(),a("_parseConfirmation: packet.reasonCode `%d`",e.reasonCode)):e.reasonCode=0,e.length>3)){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}return!0}_parseDisconnect(){const e=this.packet;if(a("_parseDisconnect"),5===this.settings.protocolVersion){this._list.length>0?e.reasonCode=this._parseByte():e.reasonCode=0;const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}return a("_parseDisconnect result: true"),!0}_parseAuth(){a("_parseAuth");const e=this.packet;if(5!==this.settings.protocolVersion)return this._emitError(new Error("Not supported auth packet for this version MQTT"));e.reasonCode=this._parseByte();const t=this._parseProperties();return Object.getOwnPropertyNames(t).length&&(e.properties=t),a("_parseAuth: result: true"),!0}_parseMessageId(){const e=this.packet;return e.messageId=this._parseNum(),null===e.messageId?(this._emitError(new Error("Cannot parse messageId")),!1):(a("_parseMessageId: packet.messageId %d",e.messageId),!0)}_parseString(e){const t=this._parseNum(),i=t+this._pos;if(-1===t||i>this._list.length||i>this.packet.length)return null;const n=this._list.toString("utf8",this._pos,i);return this._pos+=t,a("_parseString: result: %s",n),n}_parseStringPair(){return a("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){const e=this._parseNum(),t=e+this._pos;if(-1===e||t>this._list.length||t>this.packet.length)return null;const i=this._list.slice(this._pos,t);return this._pos+=e,a("_parseBuffer: result: %o",i),i}_parseNum(){if(this._list.length-this._pos<2)return-1;const e=this._list.readUInt16BE(this._pos);return this._pos+=2,a("_parseNum: result: %s",e),e}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;const e=this._list.readUInt32BE(this._pos);return this._pos+=4,a("_parse4ByteNum: result: %s",e),e}_parseVarByteNum(e){a("_parseVarByteNum");let t,i=0,n=1,r=0,o=!1;const c=this._pos?this._pos:0;for(;i<4&&c+i<this._list.length;){if(r+=n*((t=this._list.readUInt8(c+i++))&s.VARBYTEINT_MASK),n*=128,0==(t&s.VARBYTEINT_FIN_MASK)){o=!0;break}if(this._list.length<=i)break}return!o&&4===i&&this._list.length>=i&&this._emitError(new Error("Invalid variable byte integer")),c&&(this._pos+=i),a("_parseVarByteNum: result: %o",o=!!o&&(e?{bytes:i,value:r}:r)),o}_parseByte(){let e;return this._pos<this._list.length&&(e=this._list.readUInt8(this._pos),this._pos++),a("_parseByte: result: %o",e),e}_parseByType(e){switch(a("_parseByType: type: %s",e),e){case"byte":return 0!==this._parseByte();case"int8":return this._parseByte();case"int16":return this._parseNum();case"int32":return this._parse4ByteNum();case"var":return this._parseVarByteNum();case"string":return this._parseString();case"pair":return this._parseStringPair();case"binary":return this._parseBuffer()}}_parseProperties(){a("_parseProperties");const e=this._parseVarByteNum(),t=this._pos+e,i={};for(;this._pos<t;){const e=this._parseByte();if(!e)return this._emitError(new Error("Cannot parse property code type")),!1;const t=s.propertiesCodes[e];if(!t)return this._emitError(new Error("Unknown property")),!1;if("userProperties"!==t)i[t]?(Array.isArray(i[t])||(i[t]=[i[t]]),i[t].push(this._parseByType(s.propertiesTypes[t]))):i[t]=this._parseByType(s.propertiesTypes[t]);else{i[t]||(i[t]=Object.create(null));const e=this._parseByType(s.propertiesTypes[t]);if(i[t][e.name])if(Array.isArray(i[t][e.name]))i[t][e.name].push(e.value);else{const n=i[t][e.name];i[t][e.name]=[n],i[t][e.name].push(e.value)}else i[t][e.name]=e.value}}return i}_newPacket(){return a("_newPacket"),this.packet&&(this._list.consume(this.packet.length),a("_newPacket: parser emit packet: packet.cmd: %s, packet.payload: %s, packet.length: %d",this.packet.cmd,this.packet.payload,this.packet.length),this.emit("packet",this.packet)),a("_newPacket: new packet"),this.packet=new o,this._pos=0,!0}_emitError(e){a("_emitError"),this.error=e,this.emit("error",e)}}t.exports=c},{"./constants":38,"./packet":42,bl:15,debug:18,events:22}],44:[function(e,t,i){(function(i){(function(){const n=e("./constants"),r=i.allocUnsafe(0),o=i.from([0]),s=e("./numbers"),a=e("process-nextick-args").nextTick,c=e("debug")("mqtt-packet:writeToStream"),l=s.cache,h=s.generateNumber,u=s.generateCache,d=s.genBufVariableByteInt,f=s.generate4ByteBuffer;let p=_,v=!0;function x(e,t,s){switch(c("generate called"),t.cork&&(t.cork(),a(g,t)),v&&(v=!1,u()),c("generate: packet.cmd: %s",e.cmd),e.cmd){case"connect":return function(e,t,r){const o=e||{},s=o.protocolId||"MQTT";let a=o.protocolVersion||4;const c=o.will;let l=o.clean;const h=o.keepalive||0,u=o.clientId||"",d=o.username,f=o.password,v=o.properties;void 0===l&&(l=!0);let x=0;if(!s||"string"!=typeof s&&!i.isBuffer(s))return t.emit("error",new Error("Invalid protocolId")),!1;if(x+=s.length+2,3!==a&&4!==a&&5!==a)return t.emit("error",new Error("Invalid protocol version")),!1;if(x+=1,("string"==typeof u||i.isBuffer(u))&&(u||a>=4)&&(u||l))x+=i.byteLength(u)+2;else{if(a<4)return t.emit("error",new Error("clientId must be supplied before 3.1.1")),!1;if(1*l==0)return t.emit("error",new Error("clientId must be given if cleanSession set to 0")),!1}if("number"!=typeof h||h<0||h>65535||h%1!=0)return t.emit("error",new Error("Invalid keepalive")),!1;if(x+=2,x+=1,5===a){var g=A(t,v);if(!g)return!1;x+=g.length}if(c){if("object"!=typeof c)return t.emit("error",new Error("Invalid will")),!1;if(!c.topic||"string"!=typeof c.topic)return t.emit("error",new Error("Invalid will topic")),!1;if(x+=i.byteLength(c.topic)+2,x+=2,c.payload){if(!(c.payload.length>=0))return t.emit("error",new Error("Invalid will payload")),!1;"string"==typeof c.payload?x+=i.byteLength(c.payload):x+=c.payload.length}var y={};if(5===a){if(!(y=A(t,c.properties)))return!1;x+=y.length}}let w=!1;if(null!=d){if(!R(d))return t.emit("error",new Error("Invalid username")),!1;w=!0,x+=i.byteLength(d)+2}if(null!=f){if(!w)return t.emit("error",new Error("Username is required to use password")),!1;if(!R(f))return t.emit("error",new Error("Invalid password")),!1;x+=E(f)+2}t.write(n.CONNECT_HEADER),m(t,x),T(t,s),o.bridgeMode&&(a+=128),t.write(131===a?n.VERSION131:132===a?n.VERSION132:4===a?n.VERSION4:5===a?n.VERSION5:n.VERSION3);let _=0;return _|=null!=d?n.USERNAME_MASK:0,_|=null!=f?n.PASSWORD_MASK:0,_|=c&&c.retain?n.WILL_RETAIN_MASK:0,_|=c&&c.qos?c.qos<<n.WILL_QOS_SHIFT:0,_|=c?n.WILL_FLAG_MASK:0,_|=l?n.CLEAN_SESSION_MASK:0,t.write(i.from([_])),p(t,h),5===a&&g.write(),T(t,u),c&&(5===a&&y.write(),b(t,c.topic),T(t,c.payload)),null!=d&&T(t,d),null!=f&&T(t,f),!0}(e,t);case"connack":return function(e,t,r){const s=r?r.protocolVersion:4,a=e||{},c=5===s?a.reasonCode:a.returnCode,l=a.properties;let h=2;if("number"!=typeof c)return t.emit("error",new Error("Invalid return code")),!1;let u=null;if(5===s){if(!(u=A(t,l)))return!1;h+=u.length}return t.write(n.CONNACK_HEADER),m(t,h),t.write(a.sessionPresent?n.SESSIONPRESENT_HEADER:o),t.write(i.from([c])),null!=u&&u.write(),!0}(e,t,s);case"publish":return function(e,t,o){c("publish: packet: %o",e);const s=o?o.protocolVersion:4,a=e||{},l=a.qos||0,h=a.retain?n.RETAIN_MASK:0,u=a.topic,d=a.payload||r,f=a.messageId,v=a.properties;let x=0;if("string"==typeof u)x+=i.byteLength(u)+2;else{if(!i.isBuffer(u))return t.emit("error",new Error("Invalid topic")),!1;x+=u.length+2}if(i.isBuffer(d)?x+=d.length:x+=i.byteLength(d),l&&"number"!=typeof f)return t.emit("error",new Error("Invalid messageId")),!1;l&&(x+=2);let g=null;if(5===s){if(!(g=A(t,v)))return!1;x+=g.length}return t.write(n.PUBLISH_HEADER[l][a.dup?1:0][h?1:0]),m(t,x),p(t,E(u)),t.write(u),l>0&&p(t,f),null!=g&&g.write(),c("publish: payload: %o",d),t.write(d)}(e,t,s);case"puback":case"pubrec":case"pubrel":case"pubcomp":return function(e,t,r){const o=r?r.protocolVersion:4,s=e||{},a=s.cmd||"puback",c=s.messageId,l=s.dup&&"pubrel"===a?n.DUP_MASK:0;let h=0;const u=s.reasonCode,d=s.properties;let f=5===o?3:2;if("pubrel"===a&&(h=1),"number"!=typeof c)return t.emit("error",new Error("Invalid messageId")),!1;let v=null;if(5===o&&"object"==typeof d){if(!(v=S(t,d,r,f)))return!1;f+=v.length}return t.write(n.ACKS[a][h][l][0]),m(t,f),p(t,c),5===o&&t.write(i.from([u])),null!==v&&v.write(),!0}(e,t,s);case"subscribe":return function(e,t,r){c("subscribe: packet: ");const o=r?r.protocolVersion:4,s=e||{},a=s.dup?n.DUP_MASK:0,l=s.messageId,h=s.subscriptions,u=s.properties;let d=0;if("number"!=typeof l)return t.emit("error",new Error("Invalid messageId")),!1;d+=2;let f=null;if(5===o){if(!(f=A(t,u)))return!1;d+=f.length}if("object"!=typeof h||!h.length)return t.emit("error",new Error("Invalid subscriptions")),!1;for(let e=0;e<h.length;e+=1){const n=h[e].topic,r=h[e].qos;if("string"!=typeof n)return t.emit("error",new Error("Invalid subscriptions - invalid topic")),!1;if("number"!=typeof r)return t.emit("error",new Error("Invalid subscriptions - invalid qos")),!1;if(5===o){if("boolean"!=typeof(h[e].nl||!1))return t.emit("error",new Error("Invalid subscriptions - invalid No Local")),!1;if("boolean"!=typeof(h[e].rap||!1))return t.emit("error",new Error("Invalid subscriptions - invalid Retain as Published")),!1;const i=h[e].rh||0;if("number"!=typeof i||i>2)return t.emit("error",new Error("Invalid subscriptions - invalid Retain Handling")),!1}d+=i.byteLength(n)+2+1}c("subscribe: writing to stream: %o",n.SUBSCRIBE_HEADER),t.write(n.SUBSCRIBE_HEADER[1][a?1:0][0]),m(t,d),p(t,l),null!==f&&f.write();let v=!0;for(const e of h){const r=e.topic,s=e.qos,a=+e.nl,c=+e.rap,l=e.rh;let h;b(t,r),h=n.SUBSCRIBE_OPTIONS_QOS[s],5===o&&(h|=a?n.SUBSCRIBE_OPTIONS_NL:0,h|=c?n.SUBSCRIBE_OPTIONS_RAP:0,h|=l?n.SUBSCRIBE_OPTIONS_RH[l]:0),v=t.write(i.from([h]))}return v}(e,t,s);case"suback":return function(e,t,r){const o=r?r.protocolVersion:4,s=e||{},a=s.messageId,c=s.granted,l=s.properties;let h=0;if("number"!=typeof a)return t.emit("error",new Error("Invalid messageId")),!1;if(h+=2,"object"!=typeof c||!c.length)return t.emit("error",new Error("Invalid qos vector")),!1;for(let e=0;e<c.length;e+=1){if("number"!=typeof c[e])return t.emit("error",new Error("Invalid qos vector")),!1;h+=1}let u=null;if(5===o){if(!(u=S(t,l,r,h)))return!1;h+=u.length}return t.write(n.SUBACK_HEADER),m(t,h),p(t,a),null!==u&&u.write(),t.write(i.from(c))}(e,t,s);case"unsubscribe":return function(e,t,r){const o=r?r.protocolVersion:4,s=e||{},a=s.messageId,c=s.dup?n.DUP_MASK:0,l=s.unsubscriptions,h=s.properties;let u=0;if("number"!=typeof a)return t.emit("error",new Error("Invalid messageId")),!1;if(u+=2,"object"!=typeof l||!l.length)return t.emit("error",new Error("Invalid unsubscriptions")),!1;for(let e=0;e<l.length;e+=1){if("string"!=typeof l[e])return t.emit("error",new Error("Invalid unsubscriptions")),!1;u+=i.byteLength(l[e])+2}let d=null;if(5===o){if(!(d=A(t,h)))return!1;u+=d.length}t.write(n.UNSUBSCRIBE_HEADER[1][c?1:0][0]),m(t,u),p(t,a),null!==d&&d.write();let f=!0;for(let e=0;e<l.length;e++)f=b(t,l[e]);return f}(e,t,s);case"unsuback":return function(e,t,r){const o=r?r.protocolVersion:4,s=e||{},a=s.messageId,c=s.dup?n.DUP_MASK:0,l=s.granted,h=s.properties,u=s.cmd;let d=2;if("number"!=typeof a)return t.emit("error",new Error("Invalid messageId")),!1;if(5===o){if("object"!=typeof l||!l.length)return t.emit("error",new Error("Invalid qos vector")),!1;for(let e=0;e<l.length;e+=1){if("number"!=typeof l[e])return t.emit("error",new Error("Invalid qos vector")),!1;d+=1}}let f=null;if(5===o){if(!(f=S(t,h,r,d)))return!1;d+=f.length}return t.write(n.ACKS[u][0][c][0]),m(t,d),p(t,a),null!==f&&f.write(),5===o&&t.write(i.from(l)),!0}(e,t,s);case"pingreq":case"pingresp":return function(e,t,i){return t.write(n.EMPTY[e.cmd])}(e,t);case"disconnect":return function(e,t,r){const o=r?r.protocolVersion:4,s=e||{},a=s.reasonCode,c=s.properties;let l=5===o?1:0,h=null;if(5===o){if(!(h=S(t,c,r,l)))return!1;l+=h.length}return t.write(i.from([n.codes.disconnect<<4])),m(t,l),5===o&&t.write(i.from([a])),null!==h&&h.write(),!0}(e,t,s);case"auth":return function(e,t,r){const o=r?r.protocolVersion:4,s=e||{},a=s.reasonCode,c=s.properties;let l=5===o?1:0;5!==o&&t.emit("error",new Error("Invalid mqtt version for auth packet"));const h=S(t,c,r,l);return!!h&&(l+=h.length,t.write(i.from([n.codes.auth<<4])),m(t,l),t.write(i.from([a])),null!==h&&h.write(),!0)}(e,t,s);default:return t.emit("error",new Error("Unknown command")),!1}}function g(e){e.uncork()}Object.defineProperty(x,"cacheNumbers",{get:()=>p===_,set(e){e?(l&&0!==Object.keys(l).length||(v=!0),p=_):(v=!1,p=k)}});const y={};function m(e,t){if(t>n.VARBYTEINT_MAX)return e.emit("error",new Error(`Invalid variable byte integer: ${t}`)),!1;let i=y[t];return i||(i=d(t),t<16384&&(y[t]=i)),c("writeVarByteInt: writing to stream: %o",i),e.write(i)}function b(e,t){const n=i.byteLength(t);return p(e,n),c("writeString: %s",t),e.write(t,"utf8")}function w(e,t,i){b(e,t),b(e,i)}function _(e,t){return c("writeNumberCached: number: %d",t),c("writeNumberCached: %o",l[t]),e.write(l[t])}function k(e,t){const i=h(t);return c("writeNumberGenerated: %o",i),e.write(i)}function T(e,t){"string"==typeof t?b(e,t):t?(p(e,t.length),e.write(t)):p(e,0)}function A(e,t){if("object"!=typeof t||null!=t.length)return{length:1,write(){C(e,{},0)}};let r=0;function o(t,r){let o=0;switch(n.propertiesTypes[t]){case"byte":if("boolean"!=typeof r)return e.emit("error",new Error(`Invalid ${t}: ${r}`)),!1;o+=2;break;case"int8":if("number"!=typeof r||r<0||r>255)return e.emit("error",new Error(`Invalid ${t}: ${r}`)),!1;o+=2;break;case"binary":if(r&&null===r)return e.emit("error",new Error(`Invalid ${t}: ${r}`)),!1;o+=1+i.byteLength(r)+2;break;case"int16":if("number"!=typeof r||r<0||r>65535)return e.emit("error",new Error(`Invalid ${t}: ${r}`)),!1;o+=3;break;case"int32":if("number"!=typeof r||r<0||r>4294967295)return e.emit("error",new Error(`Invalid ${t}: ${r}`)),!1;o+=5;break;case"var":if("number"!=typeof r||r<0||r>268435455)return e.emit("error",new Error(`Invalid ${t}: ${r}`)),!1;o+=1+i.byteLength(d(r));break;case"string":if("string"!=typeof r)return e.emit("error",new Error(`Invalid ${t}: ${r}`)),!1;o+=3+i.byteLength(r.toString());break;case"pair":if("object"!=typeof r)return e.emit("error",new Error(`Invalid ${t}: ${r}`)),!1;o+=Object.getOwnPropertyNames(r).reduce(((e,t)=>{const n=r[t];return Array.isArray(n)?e+=n.reduce(((e,n)=>e+(3+i.byteLength(t.toString())+2+i.byteLength(n.toString()))),0):e+=3+i.byteLength(t.toString())+2+i.byteLength(r[t].toString()),e}),0);break;default:return e.emit("error",new Error(`Invalid property ${t}: ${r}`)),!1}return o}if(t)for(const e in t){let i=0,n=0;const s=t[e];if(Array.isArray(s))for(let t=0;t<s.length;t++){if(!(n=o(e,s[t])))return!1;i+=n}else{if(!(n=o(e,s)))return!1;i=n}if(!i)return!1;r+=i}return{length:i.byteLength(d(r))+r,write(){C(e,t,r)}}}function S(e,t,i,n){const r=["reasonString","userProperties"],o=i&&i.properties&&i.properties.maximumPacketSize?i.properties.maximumPacketSize:0;let s=A(e,t);if(o)for(;n+s.length>o;){const i=r.shift();if(!i||!t[i])return!1;delete t[i],s=A(e,t)}return s}function P(e,t,r){switch(n.propertiesTypes[t]){case"byte":e.write(i.from([n.properties[t]])),e.write(i.from([+r]));break;case"int8":e.write(i.from([n.properties[t]])),e.write(i.from([r]));break;case"binary":e.write(i.from([n.properties[t]])),T(e,r);break;case"int16":e.write(i.from([n.properties[t]])),p(e,r);break;case"int32":e.write(i.from([n.properties[t]])),function(e,t){const i=f(t);c("write4ByteNumber: %o",i),e.write(i)}(e,r);break;case"var":e.write(i.from([n.properties[t]])),m(e,r);break;case"string":e.write(i.from([n.properties[t]])),b(e,r);break;case"pair":Object.getOwnPropertyNames(r).forEach((o=>{const s=r[o];Array.isArray(s)?s.forEach((r=>{e.write(i.from([n.properties[t]])),w(e,o.toString(),r.toString())})):(e.write(i.from([n.properties[t]])),w(e,o.toString(),s.toString()))}));break;default:return e.emit("error",new Error(`Invalid property ${t} value: ${r}`)),!1}}function C(e,t,i){m(e,i);for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)&&null!==t[i]){const n=t[i];if(Array.isArray(n))for(let t=0;t<n.length;t++)P(e,i,n[t]);else P(e,i,n)}}function E(e){return e?e instanceof i?e.length:i.byteLength(e):0}function R(e){return"string"==typeof e||e instanceof i}t.exports=x}).call(this)}).call(this,e("buffer").Buffer)},{"./constants":38,"./numbers":41,buffer:17,debug:18,"process-nextick-args":49}],45:[function(e,t,i){var n=1e3,r=60*n,o=60*r,s=24*o;function a(e,t,i,n){var r=t>=1.5*i;return Math.round(e/i)+" "+n+(r?"s":"")}t.exports=function(e,t){t=t||{};var i=typeof e;if("string"===i&&e.length>0)return function(e){if(!((e=String(e)).length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var i=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*i;case"weeks":case"week":case"w":return 6048e5*i;case"days":case"day":case"d":return i*s;case"hours":case"hour":case"hrs":case"hr":case"h":return i*o;case"minutes":case"minute":case"mins":case"min":case"m":return i*r;case"seconds":case"second":case"secs":case"sec":case"s":return i*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:return}}}}(e);if("number"===i&&isFinite(e))return t.long?function(e){var t=Math.abs(e);return t>=s?a(e,t,s,"day"):t>=o?a(e,t,o,"hour"):t>=r?a(e,t,r,"minute"):t>=n?a(e,t,n,"second"):e+" ms"}(e):function(e){var t=Math.abs(e);return t>=s?Math.round(e/s)+"d":t>=o?Math.round(e/o)+"h":t>=r?Math.round(e/r)+"m":t>=n?Math.round(e/n)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},{}],46:[function(e,t,i){const n=e("./lib/number-allocator.js");t.exports.NumberAllocator=n},{"./lib/number-allocator.js":47}],47:[function(e,t,i){"use strict";const n=e("js-sdsl").Set,r=e("debug")("number-allocator:trace"),o=e("debug")("number-allocator:error");function s(e,t){this.low=e,this.high=t}function a(e,t){if(!(this instanceof a))return new a(e,t);this.min=e,this.max=t,this.ss=new n([],((e,t)=>e.compare(t))),r("Create"),this.clear()}s.prototype.equals=function(e){return this.low===e.low&&this.high===e.high},s.prototype.compare=function(e){return this.low<e.low&&this.high<e.low?-1:e.low<this.low&&e.high<this.low?1:0},a.prototype.firstVacant=function(){return 0===this.ss.size()?null:this.ss.front().low},a.prototype.alloc=function(){if(0===this.ss.size())return r("alloc():empty"),null;const e=this.ss.front(),t=e.low;return t+1<=e.high?++e.low:this.ss.eraseElementByPos(0),r("alloc():"+t),t},a.prototype.use=function(e){const t=new s(e,e),i=this.ss.lowerBound(t);if(i){if(i.equals(t))return this.ss.eraseElementByValue(i),r("use():"+e),!0;if(i.low>e)return!1;if(i.low===e)return++i.low,r("use():"+e),!0;if(i.high===e)return--i.high,r("use():"+e),!0;const n=i.low;return i.low=e+1,this.ss.insert(new s(n,e-1)),r("use():"+e),!0}return r("use():failed"),!1},a.prototype.free=function(e){if(e<this.min||e>this.max)return void o("free():"+e+" is out of range");const t=new s(e,e),i=this.ss.lowerBound(t);if(i){if(i.low<=e&&e<=i.high)return void o("free():"+e+" has already been vacant");if(i===this.ss.front())e+1===i.low?--i.low:this.ss.insert(t);else{const n=this.ss.reverseLowerBound(t);n.high+1===e?e+1===i.low?(this.ss.eraseElementByValue(n),i.low=n.low):n.high=e:e+1===i.low?i.low=e:this.ss.insert(t)}}else{if(i===this.ss.front())return void this.ss.insert(t);const n=this.ss.reverseLowerBound(t);n.high+1===e?n.high=e:this.ss.insert(t)}r("free():"+e)},a.prototype.clear=function(){r("clear()"),this.ss.clear(),this.ss.insert(new s(this.min,this.max))},a.prototype.intervalCount=function(){return this.ss.size()},a.prototype.dump=function(){console.log("length:"+this.ss.size());for(const e of this.ss)console.log(e)},t.exports=a},{debug:18,"js-sdsl":36}],48:[function(e,t,i){var n=e("wrappy");function r(e){var t=function(){return t.called?t.value:(t.called=!0,t.value=e.apply(this,arguments))};return t.called=!1,t}function o(e){var t=function(){if(t.called)throw new Error(t.onceError);return t.called=!0,t.value=e.apply(this,arguments)},i=e.name||"Function wrapped with `once`";return t.onceError=i+" shouldn't be called more than once",t.called=!1,t}t.exports=n(r),t.exports.strict=n(o),r.proto=r((function(){Object.defineProperty(Function.prototype,"once",{value:function(){return r(this)},configurable:!0}),Object.defineProperty(Function.prototype,"onceStrict",{value:function(){return o(this)},configurable:!0})}))},{wrappy:79}],49:[function(e,t,i){(function(e){(function(){"use strict";void 0===e||!e.version||0===e.version.indexOf("v0.")||0===e.version.indexOf("v1.")&&0!==e.version.indexOf("v1.8.")?t.exports={nextTick:function(t,i,n,r){if("function"!=typeof t)throw new TypeError('"callback" argument must be a function');var o,s,a=arguments.length;switch(a){case 0:case 1:return e.nextTick(t);case 2:return e.nextTick((function(){t.call(null,i)}));case 3:return e.nextTick((function(){t.call(null,i,n)}));case 4:return e.nextTick((function(){t.call(null,i,n,r)}));default:for(o=new Array(a-1),s=0;s<o.length;)o[s++]=arguments[s];return e.nextTick((function(){t.apply(null,o)}))}}}:t.exports=e}).call(this)}).call(this,e("_process"))},{_process:50}],50:[function(e,t,i){var n,r,o=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function c(e){if(n===setTimeout)return setTimeout(e,0);if((n===s||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:s}catch(e){n=s}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(e){r=a}}();var l,h=[],u=!1,d=-1;function f(){u&&l&&(u=!1,l.length?h=l.concat(h):d=-1,h.length&&p())}function p(){if(!u){var e=c(f);u=!0;for(var t=h.length;t;){for(l=h,h=[];++d<t;)l&&l[d].run();d=-1,t=h.length}l=null,u=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===a||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function v(e,t){this.fun=e,this.array=t}function x(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var i=1;i<arguments.length;i++)t[i-1]=arguments[i];h.push(new v(e,t)),1!==h.length||u||c(p)},v.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=x,o.addListener=x,o.once=x,o.off=x,o.removeListener=x,o.removeAllListeners=x,o.emit=x,o.prependListener=x,o.prependOnceListener=x,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},{}],51:[function(e,t,n){(function(e){(function(){!function(i){var r="object"==typeof n&&n&&!n.nodeType&&n,o="object"==typeof t&&t&&!t.nodeType&&t,s="object"==typeof e&&e;s.global!==s&&s.window!==s&&s.self!==s||(i=s);var a,c,l=2147483647,h=36,u=26,d=38,f=700,p=/^xn--/,v=/[^\x20-\x7E]/,x=/[\x2E\u3002\uFF0E\uFF61]/g,g={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},y=h-1,m=Math.floor,b=String.fromCharCode;function w(e){throw new RangeError(g[e])}function _(e,t){for(var i=e.length,n=[];i--;)n[i]=t(e[i]);return n}function k(e,t){var i=e.split("@"),n="";return i.length>1&&(n=i[0]+"@",e=i[1]),n+_((e=e.replace(x,".")).split("."),t).join(".")}function T(e){for(var t,i,n=[],r=0,o=e.length;r<o;)(t=e.charCodeAt(r++))>=55296&&t<=56319&&r<o?56320==(64512&(i=e.charCodeAt(r++)))?n.push(((1023&t)<<10)+(1023&i)+65536):(n.push(t),r--):n.push(t);return n}function A(e){return _(e,(function(e){var t="";return e>65535&&(t+=b((e-=65536)>>>10&1023|55296),e=56320|1023&e),t+b(e)})).join("")}function S(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function P(e,t,i){var n=0;for(e=i?m(e/f):e>>1,e+=m(e/t);e>y*u>>1;n+=h)e=m(e/y);return m(n+(y+1)*e/(e+d))}function C(e){var t,i,n,r,o,s,a,c,d,f,p,v=[],x=e.length,g=0,y=128,b=72;for((i=e.lastIndexOf("-"))<0&&(i=0),n=0;n<i;++n)e.charCodeAt(n)>=128&&w("not-basic"),v.push(e.charCodeAt(n));for(r=i>0?i+1:0;r<x;){for(o=g,s=1,a=h;r>=x&&w("invalid-input"),((c=(p=e.charCodeAt(r++))-48<10?p-22:p-65<26?p-65:p-97<26?p-97:h)>=h||c>m((l-g)/s))&&w("overflow"),g+=c*s,!(c<(d=a<=b?1:a>=b+u?u:a-b));a+=h)s>m(l/(f=h-d))&&w("overflow"),s*=f;b=P(g-o,t=v.length+1,0==o),m(g/t)>l-y&&w("overflow"),y+=m(g/t),g%=t,v.splice(g++,0,y)}return A(v)}function E(e){var t,i,n,r,o,s,a,c,d,f,p,v,x,g,y,_=[];for(v=(e=T(e)).length,t=128,i=0,o=72,s=0;s<v;++s)(p=e[s])<128&&_.push(b(p));for(n=r=_.length,r&&_.push("-");n<v;){for(a=l,s=0;s<v;++s)(p=e[s])>=t&&p<a&&(a=p);for(a-t>m((l-i)/(x=n+1))&&w("overflow"),i+=(a-t)*x,t=a,s=0;s<v;++s)if((p=e[s])<t&&++i>l&&w("overflow"),p==t){for(c=i,d=h;!(c<(f=d<=o?1:d>=o+u?u:d-o));d+=h)y=c-f,g=h-f,_.push(b(S(f+y%g,0))),c=m(y/g);_.push(b(S(c,0))),o=P(i,x,n==r),i=0,++n}++i,++t}return _.join("")}if(a={version:"1.4.1",ucs2:{decode:T,encode:A},decode:C,encode:E,toASCII:function(e){return k(e,(function(e){return v.test(e)?"xn--"+E(e):e}))},toUnicode:function(e){return k(e,(function(e){return p.test(e)?C(e.slice(4).toLowerCase()):e}))}},r&&o)if(t.exports==r)o.exports=a;else for(c in a)a.hasOwnProperty(c)&&(r[c]=a[c]);else i.punycode=a}(this)}).call(this)}).call(this,void 0!==i.g?i.g:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],52:[function(e,t,i){"use strict";function n(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.exports=function(e,t,i,o){t=t||"&",i=i||"=";var s={};if("string"!=typeof e||0===e.length)return s;var a=/\+/g;e=e.split(t);var c=1e3;o&&"number"==typeof o.maxKeys&&(c=o.maxKeys);var l=e.length;c>0&&l>c&&(l=c);for(var h=0;h<l;++h){var u,d,f,p,v=e[h].replace(a,"%20"),x=v.indexOf(i);x>=0?(u=v.substr(0,x),d=v.substr(x+1)):(u=v,d=""),f=decodeURIComponent(u),p=decodeURIComponent(d),n(s,f)?r(s[f])?s[f].push(p):s[f]=[s[f],p]:s[f]=p}return s};var r=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)}},{}],53:[function(e,t,i){"use strict";var n=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}};t.exports=function(e,t,i,a){return t=t||"&",i=i||"=",null===e&&(e=void 0),"object"==typeof e?o(s(e),(function(s){var a=encodeURIComponent(n(s))+i;return r(e[s])?o(e[s],(function(e){return a+encodeURIComponent(n(e))})).join(t):a+encodeURIComponent(n(e[s]))})).join(t):a?encodeURIComponent(n(a))+i+encodeURIComponent(n(e)):""};var r=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function o(e,t){if(e.map)return e.map(t);for(var i=[],n=0;n<e.length;n++)i.push(t(e[n],n));return i}var s=Object.keys||function(e){var t=[];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.push(i);return t}},{}],54:[function(e,t,i){"use strict";i.decode=i.parse=e("./decode"),i.encode=i.stringify=e("./encode")},{"./decode":52,"./encode":53}],55:[function(e,t,i){"use strict";var n={};function r(e,t,i){i||(i=Error);var r=function(e){var i,n;function r(i,n,r){return e.call(this,function(e,i,n){return"string"==typeof t?t:t(e,i,n)}(i,n,r))||this}return n=e,(i=r).prototype=Object.create(n.prototype),i.prototype.constructor=i,i.__proto__=n,r}(i);r.prototype.name=i.name,r.prototype.code=e,n[e]=r}function o(e,t){if(Array.isArray(e)){var i=e.length;return e=e.map((function(e){return String(e)})),i>2?"one of ".concat(t," ").concat(e.slice(0,i-1).join(", "),", or ")+e[i-1]:2===i?"one of ".concat(t," ").concat(e[0]," or ").concat(e[1]):"of ".concat(t," ").concat(e[0])}return"of ".concat(t," ").concat(String(e))}r("ERR_INVALID_OPT_VALUE",(function(e,t){return'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),r("ERR_INVALID_ARG_TYPE",(function(e,t,i){var n,r,s;if("string"==typeof t&&(r="not ",t.substr(0,r.length)===r)?(n="must not be",t=t.replace(/^not /,"")):n="must be",function(e,t,i){return(void 0===i||i>e.length)&&(i=e.length),e.substring(i-t.length,i)===t}(e," argument"))s="The ".concat(e," ").concat(n," ").concat(o(t,"type"));else{var a=function(e,t,i){return"number"!=typeof i&&(i=0),!(i+".".length>e.length)&&-1!==e.indexOf(".",i)}(e)?"property":"argument";s='The "'.concat(e,'" ').concat(a," ").concat(n," ").concat(o(t,"type"))}return s+". Received type ".concat(typeof i)}),TypeError),r("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),r("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return"The "+e+" method is not implemented"})),r("ERR_STREAM_PREMATURE_CLOSE","Premature close"),r("ERR_STREAM_DESTROYED",(function(e){return"Cannot call "+e+" after a stream was destroyed"})),r("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),r("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),r("ERR_STREAM_WRITE_AFTER_END","write after end"),r("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),r("ERR_UNKNOWN_ENCODING",(function(e){return"Unknown encoding: "+e}),TypeError),r("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),t.exports.codes=n},{}],56:[function(e,t,i){(function(i){(function(){"use strict";var n=Object.keys||function(e){var t=[];for(var i in e)t.push(i);return t};t.exports=l;var r=e("./_stream_readable"),o=e("./_stream_writable");e("inherits")(l,r);for(var s=n(o.prototype),a=0;a<s.length;a++){var c=s[a];l.prototype[c]||(l.prototype[c]=o.prototype[c])}function l(e){if(!(this instanceof l))return new l(e);r.call(this,e),o.call(this,e),this.allowHalfOpen=!0,e&&(!1===e.readable&&(this.readable=!1),!1===e.writable&&(this.writable=!1),!1===e.allowHalfOpen&&(this.allowHalfOpen=!1,this.once("end",h)))}function h(){this._writableState.ended||i.nextTick(u,this)}function u(e){e.end()}Object.defineProperty(l.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(l.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(l.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(l.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&this._readableState.destroyed&&this._writableState.destroyed},set:function(e){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}})}).call(this)}).call(this,e("_process"))},{"./_stream_readable":58,"./_stream_writable":60,_process:50,inherits:24}],57:[function(e,t,i){"use strict";t.exports=r;var n=e("./_stream_transform");function r(e){if(!(this instanceof r))return new r(e);n.call(this,e)}e("inherits")(r,n),r.prototype._transform=function(e,t,i){i(null,e)}},{"./_stream_transform":59,inherits:24}],58:[function(e,t,n){(function(i,n){(function(){"use strict";var r;t.exports=A,A.ReadableState=T,e("events").EventEmitter;var o,s=function(e,t){return e.listeners(t).length},a=e("./internal/streams/stream"),c=e("buffer").Buffer,l=n.Uint8Array||function(){},h=e("util");o=h&&h.debuglog?h.debuglog("stream"):function(){};var u,d,f,p=e("./internal/streams/buffer_list"),v=e("./internal/streams/destroy"),x=e("./internal/streams/state").getHighWaterMark,g=e("../errors").codes,y=g.ERR_INVALID_ARG_TYPE,m=g.ERR_STREAM_PUSH_AFTER_EOF,b=g.ERR_METHOD_NOT_IMPLEMENTED,w=g.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;e("inherits")(A,a);var _=v.errorOrDestroy,k=["error","close","destroy","pause","resume"];function T(t,i,n){r=r||e("./_stream_duplex"),t=t||{},"boolean"!=typeof n&&(n=i instanceof r),this.objectMode=!!t.objectMode,n&&(this.objectMode=this.objectMode||!!t.readableObjectMode),this.highWaterMark=x(this,t,"readableHighWaterMark",n),this.buffer=new p,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=!1!==t.emitClose,this.autoDestroy=!!t.autoDestroy,this.destroyed=!1,this.defaultEncoding=t.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,t.encoding&&(u||(u=e("string_decoder/").StringDecoder),this.decoder=new u(t.encoding),this.encoding=t.encoding)}function A(t){if(r=r||e("./_stream_duplex"),!(this instanceof A))return new A(t);var i=this instanceof r;this._readableState=new T(t,this,i),this.readable=!0,t&&("function"==typeof t.read&&(this._read=t.read),"function"==typeof t.destroy&&(this._destroy=t.destroy)),a.call(this)}function S(e,t,i,n,r){o("readableAddChunk",t);var s,a=e._readableState;if(null===t)a.reading=!1,function(e,t){if(o("onEofChunk"),!t.ended){if(t.decoder){var i=t.decoder.end();i&&i.length&&(t.buffer.push(i),t.length+=t.objectMode?1:i.length)}t.ended=!0,t.sync?R(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,I(e)))}}(e,a);else if(r||(s=function(e,t){var i,n;return n=t,c.isBuffer(n)||n instanceof l||"string"==typeof t||void 0===t||e.objectMode||(i=new y("chunk",["string","Buffer","Uint8Array"],t)),i}(a,t)),s)_(e,s);else if(a.objectMode||t&&t.length>0)if("string"==typeof t||a.objectMode||Object.getPrototypeOf(t)===c.prototype||(t=function(e){return c.from(e)}(t)),n)a.endEmitted?_(e,new w):P(e,a,t,!0);else if(a.ended)_(e,new m);else{if(a.destroyed)return!1;a.reading=!1,a.decoder&&!i?(t=a.decoder.write(t),a.objectMode||0!==t.length?P(e,a,t,!1):L(e,a)):P(e,a,t,!1)}else n||(a.reading=!1,L(e,a));return!a.ended&&(a.length<a.highWaterMark||0===a.length)}function P(e,t,i,n){t.flowing&&0===t.length&&!t.sync?(t.awaitDrain=0,e.emit("data",i)):(t.length+=t.objectMode?1:i.length,n?t.buffer.unshift(i):t.buffer.push(i),t.needReadable&&R(e)),L(e,t)}Object.defineProperty(A.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),A.prototype.destroy=v.destroy,A.prototype._undestroy=v.undestroy,A.prototype._destroy=function(e,t){t(e)},A.prototype.push=function(e,t){var i,n=this._readableState;return n.objectMode?i=!0:"string"==typeof e&&((t=t||n.defaultEncoding)!==n.encoding&&(e=c.from(e,t),t=""),i=!0),S(this,e,t,!1,i)},A.prototype.unshift=function(e){return S(this,e,null,!0,!1)},A.prototype.isPaused=function(){return!1===this._readableState.flowing},A.prototype.setEncoding=function(t){u||(u=e("string_decoder/").StringDecoder);var i=new u(t);this._readableState.decoder=i,this._readableState.encoding=this._readableState.decoder.encoding;for(var n=this._readableState.buffer.head,r="";null!==n;)r+=i.write(n.data),n=n.next;return this._readableState.buffer.clear(),""!==r&&this._readableState.buffer.push(r),this._readableState.length=r.length,this};var C=1073741824;function E(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!=e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=function(e){return e>=C?e=C:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function R(e){var t=e._readableState;o("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(o("emitReadable",t.flowing),t.emittedReadable=!0,i.nextTick(I,e))}function I(e){var t=e._readableState;o("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,B(e)}function L(e,t){t.readingMore||(t.readingMore=!0,i.nextTick(M,e,t))}function M(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&0===t.length);){var i=t.length;if(o("maybeReadMore read 0"),e.read(0),i===t.length)break}t.readingMore=!1}function D(e){var t=e._readableState;t.readableListening=e.listenerCount("readable")>0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume()}function N(e){o("readable nexttick read 0"),e.read(0)}function O(e,t){o("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),B(e),t.flowing&&!t.reading&&e.read(0)}function B(e){var t=e._readableState;for(o("flow",t.flowing);t.flowing&&null!==e.read(););}function F(e,t){return 0===t.length?null:(t.objectMode?i=t.buffer.shift():!e||e>=t.length?(i=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):i=t.buffer.consume(e,t.decoder),i);var i}function z(e){var t=e._readableState;o("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,i.nextTick(j,t,e))}function j(e,t){if(o("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var i=t._writableState;(!i||i.autoDestroy&&i.finished)&&t.destroy()}}function H(e,t){for(var i=0,n=e.length;i<n;i++)if(e[i]===t)return i;return-1}A.prototype.read=function(e){o("read",e),e=parseInt(e,10);var t=this._readableState,i=e;if(0!==e&&(t.emittedReadable=!1),0===e&&t.needReadable&&((0!==t.highWaterMark?t.length>=t.highWaterMark:t.length>0)||t.ended))return o("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?z(this):R(this),null;if(0===(e=E(e,t))&&t.ended)return 0===t.length&&z(this),null;var n,r=t.needReadable;return o("need readable",r),(0===t.length||t.length-e<t.highWaterMark)&&o("length less than watermark",r=!0),t.ended||t.reading?o("reading or ended",r=!1):r&&(o("do read"),t.reading=!0,t.sync=!0,0===t.length&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=E(i,t))),null===(n=e>0?F(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),i!==e&&t.ended&&z(this)),null!==n&&this.emit("data",n),n},A.prototype._read=function(e){_(this,new b("_read()"))},A.prototype.pipe=function(e,t){var n=this,r=this._readableState;switch(r.pipesCount){case 0:r.pipes=e;break;case 1:r.pipes=[r.pipes,e];break;default:r.pipes.push(e)}r.pipesCount+=1,o("pipe count=%d opts=%j",r.pipesCount,t);var a=t&&!1===t.end||e===i.stdout||e===i.stderr?v:c;function c(){o("onend"),e.end()}r.endEmitted?i.nextTick(a):n.once("end",a),e.on("unpipe",(function t(i,s){o("onunpipe"),i===n&&s&&!1===s.hasUnpiped&&(s.hasUnpiped=!0,o("cleanup"),e.removeListener("close",f),e.removeListener("finish",p),e.removeListener("drain",l),e.removeListener("error",d),e.removeListener("unpipe",t),n.removeListener("end",c),n.removeListener("end",v),n.removeListener("data",u),h=!0,!r.awaitDrain||e._writableState&&!e._writableState.needDrain||l())}));var l=function(e){return function(){var t=e._readableState;o("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&s(e,"data")&&(t.flowing=!0,B(e))}}(n);e.on("drain",l);var h=!1;function u(t){o("ondata");var i=e.write(t);o("dest.write",i),!1===i&&((1===r.pipesCount&&r.pipes===e||r.pipesCount>1&&-1!==H(r.pipes,e))&&!h&&(o("false write response, pause",r.awaitDrain),r.awaitDrain++),n.pause())}function d(t){o("onerror",t),v(),e.removeListener("error",d),0===s(e,"error")&&_(e,t)}function f(){e.removeListener("finish",p),v()}function p(){o("onfinish"),e.removeListener("close",f),v()}function v(){o("unpipe"),n.unpipe(e)}return n.on("data",u),function(e,t,i){if("function"==typeof e.prependListener)return e.prependListener(t,i);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(i):e._events[t]=[i,e._events[t]]:e.on(t,i)}(e,"error",d),e.once("close",f),e.once("finish",p),e.emit("pipe",n),r.flowing||(o("pipe resume"),n.resume()),e},A.prototype.unpipe=function(e){var t=this._readableState,i={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,i)),this;if(!e){var n=t.pipes,r=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o<r;o++)n[o].emit("unpipe",this,{hasUnpiped:!1});return this}var s=H(t.pipes,e);return-1===s||(t.pipes.splice(s,1),t.pipesCount-=1,1===t.pipesCount&&(t.pipes=t.pipes[0]),e.emit("unpipe",this,i)),this},A.prototype.on=function(e,t){var n=a.prototype.on.call(this,e,t),r=this._readableState;return"data"===e?(r.readableListening=this.listenerCount("readable")>0,!1!==r.flowing&&this.resume()):"readable"===e&&(r.endEmitted||r.readableListening||(r.readableListening=r.needReadable=!0,r.flowing=!1,r.emittedReadable=!1,o("on readable",r.length,r.reading),r.length?R(this):r.reading||i.nextTick(N,this))),n},A.prototype.addListener=A.prototype.on,A.prototype.removeListener=function(e,t){var n=a.prototype.removeListener.call(this,e,t);return"readable"===e&&i.nextTick(D,this),n},A.prototype.removeAllListeners=function(e){var t=a.prototype.removeAllListeners.apply(this,arguments);return"readable"!==e&&void 0!==e||i.nextTick(D,this),t},A.prototype.resume=function(){var e=this._readableState;return e.flowing||(o("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,i.nextTick(O,e,t))}(this,e)),e.paused=!1,this},A.prototype.pause=function(){return o("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(o("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},A.prototype.wrap=function(e){var t=this,i=this._readableState,n=!1;for(var r in e.on("end",(function(){if(o("wrapped end"),i.decoder&&!i.ended){var e=i.decoder.end();e&&e.length&&t.push(e)}t.push(null)})),e.on("data",(function(r){o("wrapped data"),i.decoder&&(r=i.decoder.write(r)),(!i.objectMode||null!=r)&&(i.objectMode||r&&r.length)&&(t.push(r)||(n=!0,e.pause()))})),e)void 0===this[r]&&"function"==typeof e[r]&&(this[r]=function(t){return function(){return e[t].apply(e,arguments)}}(r));for(var s=0;s<k.length;s++)e.on(k[s],this.emit.bind(this,k[s]));return this._read=function(t){o("wrapped _read",t),n&&(n=!1,e.resume())},this},"function"==typeof Symbol&&(A.prototype[Symbol.asyncIterator]=function(){return void 0===d&&(d=e("./internal/streams/async_iterator")),d(this)}),Object.defineProperty(A.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(A.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(A.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),A._fromList=F,Object.defineProperty(A.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(A.from=function(t,i){return void 0===f&&(f=e("./internal/streams/from")),f(A,t,i)})}).call(this)}).call(this,e("_process"),void 0!==i.g?i.g:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../errors":55,"./_stream_duplex":56,"./internal/streams/async_iterator":61,"./internal/streams/buffer_list":62,"./internal/streams/destroy":63,"./internal/streams/from":65,"./internal/streams/state":67,"./internal/streams/stream":68,_process:50,buffer:17,events:22,inherits:24,"string_decoder/":75,util:16}],59:[function(e,t,i){"use strict";t.exports=l;var n=e("../errors").codes,r=n.ERR_METHOD_NOT_IMPLEMENTED,o=n.ERR_MULTIPLE_CALLBACK,s=n.ERR_TRANSFORM_ALREADY_TRANSFORMING,a=n.ERR_TRANSFORM_WITH_LENGTH_0,c=e("./_stream_duplex");function l(e){if(!(this instanceof l))return new l(e);c.call(this,e),this._transformState={afterTransform:function(e,t){var i=this._transformState;i.transforming=!1;var n=i.writecb;if(null===n)return this.emit("error",new o);i.writechunk=null,i.writecb=null,null!=t&&this.push(t),n(e);var r=this._readableState;r.reading=!1,(r.needReadable||r.length<r.highWaterMark)&&this._read(r.highWaterMark)}.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,e&&("function"==typeof e.transform&&(this._transform=e.transform),"function"==typeof e.flush&&(this._flush=e.flush)),this.on("prefinish",h)}function h(){var e=this;"function"!=typeof this._flush||this._readableState.destroyed?u(this,null,null):this._flush((function(t,i){u(e,t,i)}))}function u(e,t,i){if(t)return e.emit("error",t);if(null!=i&&e.push(i),e._writableState.length)throw new a;if(e._transformState.transforming)throw new s;return e.push(null)}e("inherits")(l,c),l.prototype.push=function(e,t){return this._transformState.needTransform=!1,c.prototype.push.call(this,e,t)},l.prototype._transform=function(e,t,i){i(new r("_transform()"))},l.prototype._write=function(e,t,i){var n=this._transformState;if(n.writecb=i,n.writechunk=e,n.writeencoding=t,!n.transforming){var r=this._readableState;(n.needTransform||r.needReadable||r.length<r.highWaterMark)&&this._read(r.highWaterMark)}},l.prototype._read=function(e){var t=this._transformState;null===t.writechunk||t.transforming?t.needTransform=!0:(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform))},l.prototype._destroy=function(e,t){c.prototype._destroy.call(this,e,(function(e){t(e)}))}},{"../errors":55,"./_stream_duplex":56,inherits:24}],60:[function(e,t,n){(function(i,n){(function(){"use strict";function r(e){var t=this;this.next=null,this.entry=null,this.finish=function(){!function(e,t,i){var n=e.entry;for(e.entry=null;n;){var r=n.callback;t.pendingcb--,r(undefined),n=n.next}t.corkedRequestsFree.next=e}(t,e)}}var o;t.exports=A,A.WritableState=T;var s,a={deprecate:e("util-deprecate")},c=e("./internal/streams/stream"),l=e("buffer").Buffer,h=n.Uint8Array||function(){},u=e("./internal/streams/destroy"),d=e("./internal/streams/state").getHighWaterMark,f=e("../errors").codes,p=f.ERR_INVALID_ARG_TYPE,v=f.ERR_METHOD_NOT_IMPLEMENTED,x=f.ERR_MULTIPLE_CALLBACK,g=f.ERR_STREAM_CANNOT_PIPE,y=f.ERR_STREAM_DESTROYED,m=f.ERR_STREAM_NULL_VALUES,b=f.ERR_STREAM_WRITE_AFTER_END,w=f.ERR_UNKNOWN_ENCODING,_=u.errorOrDestroy;function k(){}function T(t,n,s){o=o||e("./_stream_duplex"),t=t||{},"boolean"!=typeof s&&(s=n instanceof o),this.objectMode=!!t.objectMode,s&&(this.objectMode=this.objectMode||!!t.writableObjectMode),this.highWaterMark=d(this,t,"writableHighWaterMark",s),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var a=!1===t.decodeStrings;this.decodeStrings=!a,this.defaultEncoding=t.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){!function(e,t){var n=e._writableState,r=n.sync,o=n.writecb;if("function"!=typeof o)throw new x;if(function(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}(n),t)!function(e,t,n,r,o){--t.pendingcb,n?(i.nextTick(o,r),i.nextTick(I,e,t),e._writableState.errorEmitted=!0,_(e,r)):(o(r),e._writableState.errorEmitted=!0,_(e,r),I(e,t))}(e,n,r,t,o);else{var s=E(n)||e.destroyed;s||n.corked||n.bufferProcessing||!n.bufferedRequest||C(e,n),r?i.nextTick(P,e,n,s,o):P(e,n,s,o)}}(n,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==t.emitClose,this.autoDestroy=!!t.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new r(this)}function A(t){var i=this instanceof(o=o||e("./_stream_duplex"));if(!i&&!s.call(A,this))return new A(t);this._writableState=new T(t,this,i),this.writable=!0,t&&("function"==typeof t.write&&(this._write=t.write),"function"==typeof t.writev&&(this._writev=t.writev),"function"==typeof t.destroy&&(this._destroy=t.destroy),"function"==typeof t.final&&(this._final=t.final)),c.call(this)}function S(e,t,i,n,r,o,s){t.writelen=n,t.writecb=s,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new y("write")):i?e._writev(r,t.onwrite):e._write(r,o,t.onwrite),t.sync=!1}function P(e,t,i,n){i||function(e,t){0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}(e,t),t.pendingcb--,n(),I(e,t)}function C(e,t){t.bufferProcessing=!0;var i=t.bufferedRequest;if(e._writev&&i&&i.next){var n=t.bufferedRequestCount,o=new Array(n),s=t.corkedRequestsFree;s.entry=i;for(var a=0,c=!0;i;)o[a]=i,i.isBuf||(c=!1),i=i.next,a+=1;o.allBuffers=c,S(e,t,!0,t.length,o,"",s.finish),t.pendingcb++,t.lastBufferedRequest=null,s.next?(t.corkedRequestsFree=s.next,s.next=null):t.corkedRequestsFree=new r(t),t.bufferedRequestCount=0}else{for(;i;){var l=i.chunk,h=i.encoding,u=i.callback;if(S(e,t,!1,t.objectMode?1:l.length,l,h,u),i=i.next,t.bufferedRequestCount--,t.writing)break}null===i&&(t.lastBufferedRequest=null)}t.bufferedRequest=i,t.bufferProcessing=!1}function E(e){return e.ending&&0===e.length&&null===e.bufferedRequest&&!e.finished&&!e.writing}function R(e,t){e._final((function(i){t.pendingcb--,i&&_(e,i),t.prefinished=!0,e.emit("prefinish"),I(e,t)}))}function I(e,t){var n=E(t);if(n&&(function(e,t){t.prefinished||t.finalCalled||("function"!=typeof e._final||t.destroyed?(t.prefinished=!0,e.emit("prefinish")):(t.pendingcb++,t.finalCalled=!0,i.nextTick(R,e,t)))}(e,t),0===t.pendingcb&&(t.finished=!0,e.emit("finish"),t.autoDestroy))){var r=e._readableState;(!r||r.autoDestroy&&r.endEmitted)&&e.destroy()}return n}e("inherits")(A,c),T.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(T.prototype,"buffer",{get:a.deprecate((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(s=Function.prototype[Symbol.hasInstance],Object.defineProperty(A,Symbol.hasInstance,{value:function(e){return!!s.call(this,e)||this===A&&e&&e._writableState instanceof T}})):s=function(e){return e instanceof this},A.prototype.pipe=function(){_(this,new g)},A.prototype.write=function(e,t,n){var r,o=this._writableState,s=!1,a=!o.objectMode&&(r=e,l.isBuffer(r)||r instanceof h);return a&&!l.isBuffer(e)&&(e=function(e){return l.from(e)}(e)),"function"==typeof t&&(n=t,t=null),a?t="buffer":t||(t=o.defaultEncoding),"function"!=typeof n&&(n=k),o.ending?function(e,t){var n=new b;_(e,n),i.nextTick(t,n)}(this,n):(a||function(e,t,n,r){var o;return null===n?o=new m:"string"==typeof n||t.objectMode||(o=new p("chunk",["string","Buffer"],n)),!o||(_(e,o),i.nextTick(r,o),!1)}(this,o,e,n))&&(o.pendingcb++,s=function(e,t,i,n,r,o){if(!i){var s=function(e,t,i){return e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=l.from(t,i)),t}(t,n,r);n!==s&&(i=!0,r="buffer",n=s)}var a=t.objectMode?1:n.length;t.length+=a;var c=t.length<t.highWaterMark;if(c||(t.needDrain=!0),t.writing||t.corked){var h=t.lastBufferedRequest;t.lastBufferedRequest={chunk:n,encoding:r,isBuf:i,callback:o,next:null},h?h.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else S(e,t,!1,a,n,r,o);return c}(this,o,a,e,t,n)),s},A.prototype.cork=function(){this._writableState.corked++},A.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.bufferProcessing||!e.bufferedRequest||C(this,e))},A.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new w(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(A.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(A.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),A.prototype._write=function(e,t,i){i(new v("_write()"))},A.prototype._writev=null,A.prototype.end=function(e,t,n){var r=this._writableState;return"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||function(e,t,n){t.ending=!0,I(e,t),n&&(t.finished?i.nextTick(n):e.once("finish",n)),t.ended=!0,e.writable=!1}(this,r,n),this},Object.defineProperty(A.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(A.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),A.prototype.destroy=u.destroy,A.prototype._undestroy=u.undestroy,A.prototype._destroy=function(e,t){t(e)}}).call(this)}).call(this,e("_process"),void 0!==i.g?i.g:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../errors":55,"./_stream_duplex":56,"./internal/streams/destroy":63,"./internal/streams/state":67,"./internal/streams/stream":68,_process:50,buffer:17,inherits:24,"util-deprecate":78}],61:[function(e,t,i){(function(i){(function(){"use strict";var n;function r(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var o=e("./end-of-stream"),s=Symbol("lastResolve"),a=Symbol("lastReject"),c=Symbol("error"),l=Symbol("ended"),h=Symbol("lastPromise"),u=Symbol("handlePromise"),d=Symbol("stream");function f(e,t){return{value:e,done:t}}function p(e){var t=e[s];if(null!==t){var i=e[d].read();null!==i&&(e[h]=null,e[s]=null,e[a]=null,t(f(i,!1)))}}var v=Object.getPrototypeOf((function(){})),x=Object.setPrototypeOf((r(n={get stream(){return this[d]},next:function(){var e=this,t=this[c];if(null!==t)return Promise.reject(t);if(this[l])return Promise.resolve(f(void 0,!0));if(this[d].destroyed)return new Promise((function(t,n){i.nextTick((function(){e[c]?n(e[c]):t(f(void 0,!0))}))}));var n,r=this[h];if(r)n=new Promise(function(e,t){return function(i,n){e.then((function(){t[l]?i(f(void 0,!0)):t[u](i,n)}),n)}}(r,this));else{var o=this[d].read();if(null!==o)return Promise.resolve(f(o,!1));n=new Promise(this[u])}return this[h]=n,n}},Symbol.asyncIterator,(function(){return this})),r(n,"return",(function(){var e=this;return new Promise((function(t,i){e[d].destroy(null,(function(e){e?i(e):t(f(void 0,!0))}))}))})),n),v);t.exports=function(e){var t,n=Object.create(x,(r(t={},d,{value:e,writable:!0}),r(t,s,{value:null,writable:!0}),r(t,a,{value:null,writable:!0}),r(t,c,{value:null,writable:!0}),r(t,l,{value:e._readableState.endEmitted,writable:!0}),r(t,u,{value:function(e,t){var i=n[d].read();i?(n[h]=null,n[s]=null,n[a]=null,e(f(i,!1))):(n[s]=e,n[a]=t)},writable:!0}),t));return n[h]=null,o(e,(function(e){if(e&&"ERR_STREAM_PREMATURE_CLOSE"!==e.code){var t=n[a];return null!==t&&(n[h]=null,n[s]=null,n[a]=null,t(e)),void(n[c]=e)}var i=n[s];null!==i&&(n[h]=null,n[s]=null,n[a]=null,i(f(void 0,!0))),n[l]=!0})),e.on("readable",function(e){i.nextTick(p,e)}.bind(null,n)),n}}).call(this)}).call(this,e("_process"))},{"./end-of-stream":64,_process:50}],62:[function(e,t,i){"use strict";function n(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function r(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function o(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var s=e("buffer").Buffer,a=e("util").inspect,c=a&&a.custom||"inspect";t.exports=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.head=null,this.tail=null,this.length=0}var t,i;return t=e,(i=[{key:"push",value:function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(e){if(0===this.length)return"";for(var t=this.head,i=""+t.data;t=t.next;)i+=e+t.data;return i}},{key:"concat",value:function(e){if(0===this.length)return s.alloc(0);for(var t,i,n,r=s.allocUnsafe(e>>>0),o=this.head,a=0;o;)t=o.data,i=r,n=a,s.prototype.copy.call(t,i,n),a+=o.data.length,o=o.next;return r}},{key:"consume",value:function(e,t){var i;return e<this.head.data.length?(i=this.head.data.slice(0,e),this.head.data=this.head.data.slice(e)):i=e===this.head.data.length?this.shift():t?this._getString(e):this._getBuffer(e),i}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(e){var t=this.head,i=1,n=t.data;for(e-=n.length;t=t.next;){var r=t.data,o=e>r.length?r.length:e;if(o===r.length?n+=r:n+=r.slice(0,e),0==(e-=o)){o===r.length?(++i,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=r.slice(o));break}++i}return this.length-=i,n}},{key:"_getBuffer",value:function(e){var t=s.allocUnsafe(e),i=this.head,n=1;for(i.data.copy(t),e-=i.data.length;i=i.next;){var r=i.data,o=e>r.length?r.length:e;if(r.copy(t,t.length-e,0,o),0==(e-=o)){o===r.length?(++n,i.next?this.head=i.next:this.head=this.tail=null):(this.head=i,i.data=r.slice(o));break}++n}return this.length-=n,t}},{key:c,value:function(e,t){return a(this,function(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?n(Object(i),!0).forEach((function(t){r(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):n(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}({},t,{depth:0,customInspect:!1}))}}])&&o(t.prototype,i),e}()},{buffer:17,util:16}],63:[function(e,t,i){(function(e){(function(){"use strict";function i(e,t){r(e,t),n(e)}function n(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit("close")}function r(e,t){e.emit("error",t)}t.exports={destroy:function(t,o){var s=this,a=this._readableState&&this._readableState.destroyed,c=this._writableState&&this._writableState.destroyed;return a||c?(o?o(t):t&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,e.nextTick(r,this,t)):e.nextTick(r,this,t)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(t||null,(function(t){!o&&t?s._writableState?s._writableState.errorEmitted?e.nextTick(n,s):(s._writableState.errorEmitted=!0,e.nextTick(i,s,t)):e.nextTick(i,s,t):o?(e.nextTick(n,s),o(t)):e.nextTick(n,s)})),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)},errorOrDestroy:function(e,t){var i=e._readableState,n=e._writableState;i&&i.autoDestroy||n&&n.autoDestroy?e.destroy(t):e.emit("error",t)}}}).call(this)}).call(this,e("_process"))},{_process:50}],64:[function(e,t,i){"use strict";var n=e("../../../errors").codes.ERR_STREAM_PREMATURE_CLOSE;function r(){}t.exports=function e(t,i,o){if("function"==typeof i)return e(t,null,i);i||(i={}),o=function(e){var t=!1;return function(){if(!t){t=!0;for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];e.apply(this,n)}}}(o||r);var s=i.readable||!1!==i.readable&&t.readable,a=i.writable||!1!==i.writable&&t.writable,c=function(){t.writable||h()},l=t._writableState&&t._writableState.finished,h=function(){a=!1,l=!0,s||o.call(t)},u=t._readableState&&t._readableState.endEmitted,d=function(){s=!1,u=!0,a||o.call(t)},f=function(e){o.call(t,e)},p=function(){var e;return s&&!u?(t._readableState&&t._readableState.ended||(e=new n),o.call(t,e)):a&&!l?(t._writableState&&t._writableState.ended||(e=new n),o.call(t,e)):void 0},v=function(){t.req.on("finish",h)};return function(e){return e.setHeader&&"function"==typeof e.abort}(t)?(t.on("complete",h),t.on("abort",p),t.req?v():t.on("request",v)):a&&!t._writableState&&(t.on("end",c),t.on("close",c)),t.on("end",d),t.on("finish",h),!1!==i.error&&t.on("error",f),t.on("close",p),function(){t.removeListener("complete",h),t.removeListener("abort",p),t.removeListener("request",v),t.req&&t.req.removeListener("finish",h),t.removeListener("end",c),t.removeListener("close",c),t.removeListener("finish",h),t.removeListener("end",d),t.removeListener("error",f),t.removeListener("close",p)}}},{"../../../errors":55}],65:[function(e,t,i){t.exports=function(){throw new Error("Readable.from is not available in the browser")}},{}],66:[function(e,t,i){"use strict";var n,r=e("../../../errors").codes,o=r.ERR_MISSING_ARGS,s=r.ERR_STREAM_DESTROYED;function a(e){if(e)throw e}function c(e){e()}function l(e,t){return e.pipe(t)}t.exports=function(){for(var t=arguments.length,i=new Array(t),r=0;r<t;r++)i[r]=arguments[r];var h,u=function(e){return e.length?"function"!=typeof e[e.length-1]?a:e.pop():a}(i);if(Array.isArray(i[0])&&(i=i[0]),i.length<2)throw new o("streams");var d=i.map((function(t,r){var o=r<i.length-1;return function(t,i,r,o){o=function(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}(o);var a=!1;t.on("close",(function(){a=!0})),void 0===n&&(n=e("./end-of-stream")),n(t,{readable:i,writable:r},(function(e){if(e)return o(e);a=!0,o()}));var c=!1;return function(e){if(!a&&!c)return c=!0,function(e){return e.setHeader&&"function"==typeof e.abort}(t)?t.abort():"function"==typeof t.destroy?t.destroy():void o(e||new s("pipe"))}}(t,o,r>0,(function(e){h||(h=e),e&&d.forEach(c),o||(d.forEach(c),u(h))}))}));return i.reduce(l)}},{"../../../errors":55,"./end-of-stream":64}],67:[function(e,t,i){"use strict";var n=e("../../../errors").codes.ERR_INVALID_OPT_VALUE;t.exports={getHighWaterMark:function(e,t,i,r){var o=function(e,t,i){return null!=e.highWaterMark?e.highWaterMark:t?e[i]:null}(t,r,i);if(null!=o){if(!isFinite(o)||Math.floor(o)!==o||o<0)throw new n(r?i:"highWaterMark",o);return Math.floor(o)}return e.objectMode?16:16384}}},{"../../../errors":55}],68:[function(e,t,i){t.exports=e("events").EventEmitter},{events:22}],69:[function(e,t,i){(i=t.exports=e("./lib/_stream_readable.js")).Stream=i,i.Readable=i,i.Writable=e("./lib/_stream_writable.js"),i.Duplex=e("./lib/_stream_duplex.js"),i.Transform=e("./lib/_stream_transform.js"),i.PassThrough=e("./lib/_stream_passthrough.js"),i.finished=e("./lib/internal/streams/end-of-stream.js"),i.pipeline=e("./lib/internal/streams/pipeline.js")},{"./lib/_stream_duplex.js":56,"./lib/_stream_passthrough.js":57,"./lib/_stream_readable.js":58,"./lib/_stream_transform.js":59,"./lib/_stream_writable.js":60,"./lib/internal/streams/end-of-stream.js":64,"./lib/internal/streams/pipeline.js":66}],70:[function(e,t,i){"use strict";t.exports=function(){if("function"!=typeof arguments[0])throw new Error("callback needed");if("number"!=typeof arguments[1])throw new Error("interval needed");var e;if(arguments.length>0){e=new Array(arguments.length-2);for(var t=0;t<e.length;t++)e[t]=arguments[t+2]}return new function(e,t,i){var n=this;this._callback=e,this._args=i,this._interval=setInterval(e,t,this._args),this.reschedule=function(e){e||(e=n._interval),n._interval&&clearInterval(n._interval),n._interval=setInterval(n._callback,e,n._args)},this.clear=function(){n._interval&&(clearInterval(n._interval),n._interval=void 0)},this.destroy=function(){n._interval&&clearInterval(n._interval),n._callback=void 0,n._interval=void 0,n._args=void 0}}(arguments[0],arguments[1],e)}},{}],71:[function(e,t,i){"use strict";t.exports=e("./index.js")()},{"./index.js":72}],72:[function(e,t,i){(function(e){(function(){"use strict";function i(t){return t instanceof e?e.from(t):new t.constructor(t.buffer.slice(),t.byteOffset,t.length)}t.exports=function(e){return(e=e||{}).circles?function(e){var t=[],n=[];return e.proto?function e(o){if("object"!=typeof o||null===o)return o;if(o instanceof Date)return new Date(o);if(Array.isArray(o))return r(o,e);if(o instanceof Map)return new Map(r(Array.from(o),e));if(o instanceof Set)return new Set(r(Array.from(o),e));var s={};for(var a in t.push(o),n.push(s),o){var c=o[a];if("object"!=typeof c||null===c)s[a]=c;else if(c instanceof Date)s[a]=new Date(c);else if(c instanceof Map)s[a]=new Map(r(Array.from(c),e));else if(c instanceof Set)s[a]=new Set(r(Array.from(c),e));else if(ArrayBuffer.isView(c))s[a]=i(c);else{var l=t.indexOf(c);s[a]=-1!==l?n[l]:e(c)}}return t.pop(),n.pop(),s}:function e(o){if("object"!=typeof o||null===o)return o;if(o instanceof Date)return new Date(o);if(Array.isArray(o))return r(o,e);if(o instanceof Map)return new Map(r(Array.from(o),e));if(o instanceof Set)return new Set(r(Array.from(o),e));var s={};for(var a in t.push(o),n.push(s),o)if(!1!==Object.hasOwnProperty.call(o,a)){var c=o[a];if("object"!=typeof c||null===c)s[a]=c;else if(c instanceof Date)s[a]=new Date(c);else if(c instanceof Map)s[a]=new Map(r(Array.from(c),e));else if(c instanceof Set)s[a]=new Set(r(Array.from(c),e));else if(ArrayBuffer.isView(c))s[a]=i(c);else{var l=t.indexOf(c);s[a]=-1!==l?n[l]:e(c)}}return t.pop(),n.pop(),s};function r(e,r){for(var o=Object.keys(e),s=new Array(o.length),a=0;a<o.length;a++){var c=o[a],l=e[c];if("object"!=typeof l||null===l)s[c]=l;else if(l instanceof Date)s[c]=new Date(l);else if(ArrayBuffer.isView(l))s[c]=i(l);else{var h=t.indexOf(l);s[c]=-1!==h?n[h]:r(l)}}return s}}(e):e.proto?function e(n){if("object"!=typeof n||null===n)return n;if(n instanceof Date)return new Date(n);if(Array.isArray(n))return t(n,e);if(n instanceof Map)return new Map(t(Array.from(n),e));if(n instanceof Set)return new Set(t(Array.from(n),e));var r={};for(var o in n){var s=n[o];"object"!=typeof s||null===s?r[o]=s:s instanceof Date?r[o]=new Date(s):s instanceof Map?r[o]=new Map(t(Array.from(s),e)):s instanceof Set?r[o]=new Set(t(Array.from(s),e)):ArrayBuffer.isView(s)?r[o]=i(s):r[o]=e(s)}return r}:function e(n){if("object"!=typeof n||null===n)return n;if(n instanceof Date)return new Date(n);if(Array.isArray(n))return t(n,e);if(n instanceof Map)return new Map(t(Array.from(n),e));if(n instanceof Set)return new Set(t(Array.from(n),e));var r={};for(var o in n)if(!1!==Object.hasOwnProperty.call(n,o)){var s=n[o];"object"!=typeof s||null===s?r[o]=s:s instanceof Date?r[o]=new Date(s):s instanceof Map?r[o]=new Map(t(Array.from(s),e)):s instanceof Set?r[o]=new Set(t(Array.from(s),e)):ArrayBuffer.isView(s)?r[o]=i(s):r[o]=e(s)}return r};function t(e,t){for(var n=Object.keys(e),r=new Array(n.length),o=0;o<n.length;o++){var s=n[o],a=e[s];"object"!=typeof a||null===a?r[s]=a:a instanceof Date?r[s]=new Date(a):ArrayBuffer.isView(a)?r[s]=i(a):r[s]=t(a)}return r}}}).call(this)}).call(this,e("buffer").Buffer)},{buffer:17}],73:[function(e,t,i){var n=e("buffer"),r=n.Buffer;function o(e,t){for(var i in e)t[i]=e[i]}function s(e,t,i){return r(e,t,i)}r.from&&r.alloc&&r.allocUnsafe&&r.allocUnsafeSlow?t.exports=n:(o(n,i),i.Buffer=s),s.prototype=Object.create(r.prototype),o(r,s),s.from=function(e,t,i){if("number"==typeof e)throw new TypeError("Argument must not be a number");return r(e,t,i)},s.alloc=function(e,t,i){if("number"!=typeof e)throw new TypeError("Argument must be a number");var n=r(e);return void 0!==t?"string"==typeof i?n.fill(t,i):n.fill(t):n.fill(0),n},s.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r(e)},s.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n.SlowBuffer(e)}},{buffer:17}],74:[function(e,t,i){t.exports=function(e){var t,i=e._readableState;return i?i.objectMode||"number"==typeof e._duplexState?e.read():e.read((t=i).buffer.length?t.buffer.head?t.buffer.head.data.length:t.buffer[0].length:t.length):null}},{}],75:[function(e,t,i){"use strict";var n=e("safe-buffer").Buffer,r=n.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function o(e){var t;switch(this.encoding=function(e){var t=function(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(e);if("string"!=typeof t&&(n.isEncoding===r||!r(e)))throw new Error("Unknown encoding: "+e);return t||e}(e),this.encoding){case"utf16le":this.text=c,this.end=l,t=4;break;case"utf8":this.fillLast=a,t=4;break;case"base64":this.text=h,this.end=u,t=3;break;default:return this.write=d,void(this.end=f)}this.lastNeed=0,this.lastTotal=0,this.lastChar=n.allocUnsafe(t)}function s(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function a(e){var t=this.lastTotal-this.lastNeed,i=function(e,t,i){if(128!=(192&t[0]))return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�"}}(this,e);return void 0!==i?i:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function c(e,t){if((e.length-t)%2==0){var i=e.toString("utf16le",t);if(i){var n=i.charCodeAt(i.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],i.slice(0,-1)}return i}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function l(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var i=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,i)}return t}function h(e,t){var i=(e.length-t)%3;return 0===i?e.toString("base64",t):(this.lastNeed=3-i,this.lastTotal=3,1===i?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-i))}function u(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function d(e){return e.toString(this.encoding)}function f(e){return e&&e.length?this.write(e):""}i.StringDecoder=o,o.prototype.write=function(e){if(0===e.length)return"";var t,i;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";i=this.lastNeed,this.lastNeed=0}else i=0;return i<e.length?t?t+this.text(e,i):this.text(e,i):t||""},o.prototype.end=function(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t},o.prototype.text=function(e,t){var i=function(e,t,i){var n=t.length-1;if(n<i)return 0;var r=s(t[n]);return r>=0?(r>0&&(e.lastNeed=r-1),r):--n<i||-2===r?0:(r=s(t[n]))>=0?(r>0&&(e.lastNeed=r-2),r):--n<i||-2===r?0:(r=s(t[n]))>=0?(r>0&&(2===r?r=0:e.lastNeed=r-3),r):0}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=i;var n=e.length-(i-this.lastNeed);return e.copy(this.lastChar,0,n),e.toString("utf8",t,n)},o.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length}},{"safe-buffer":73}],76:[function(e,t,i){"use strict";var n=e("punycode"),r=e("./util");function o(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}i.parse=m,i.resolve=function(e,t){return m(e,!1,!0).resolve(t)},i.resolveObject=function(e,t){return e?m(e,!1,!0).resolveObject(t):t},i.format=function(e){return r.isString(e)&&(e=m(e)),e instanceof o?e.format():o.prototype.format.call(e)},i.Url=o;var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,c=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,l=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),h=["'"].concat(l),u=["%","/","?",";","#"].concat(h),d=["/","?","#"],f=/^[+a-z0-9A-Z_-]{0,63}$/,p=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,v={javascript:!0,"javascript:":!0},x={javascript:!0,"javascript:":!0},g={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},y=e("querystring");function m(e,t,i){if(e&&r.isObject(e)&&e instanceof o)return e;var n=new o;return n.parse(e,t,i),n}o.prototype.parse=function(e,t,i){if(!r.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var o=e.indexOf("?"),a=-1!==o&&o<e.indexOf("#")?"?":"#",l=e.split(a);l[0]=l[0].replace(/\\/g,"/");var m=e=l.join(a);if(m=m.trim(),!i&&1===e.split("#").length){var b=c.exec(m);if(b)return this.path=m,this.href=m,this.pathname=b[1],b[2]?(this.search=b[2],this.query=t?y.parse(this.search.substr(1)):this.search.substr(1)):t&&(this.search="",this.query={}),this}var w=s.exec(m);if(w){var _=(w=w[0]).toLowerCase();this.protocol=_,m=m.substr(w.length)}if(i||w||m.match(/^\/\/[^@\/]+@[^@\/]+/)){var k="//"===m.substr(0,2);!k||w&&x[w]||(m=m.substr(2),this.slashes=!0)}if(!x[w]&&(k||w&&!g[w])){for(var T,A,S=-1,P=0;P<d.length;P++)-1!==(C=m.indexOf(d[P]))&&(-1===S||C<S)&&(S=C);for(-1!==(A=-1===S?m.lastIndexOf("@"):m.lastIndexOf("@",S))&&(T=m.slice(0,A),m=m.slice(A+1),this.auth=decodeURIComponent(T)),S=-1,P=0;P<u.length;P++){var C;-1!==(C=m.indexOf(u[P]))&&(-1===S||C<S)&&(S=C)}-1===S&&(S=m.length),this.host=m.slice(0,S),m=m.slice(S),this.parseHost(),this.hostname=this.hostname||"";var E="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!E)for(var R=this.hostname.split(/\./),I=(P=0,R.length);P<I;P++){var L=R[P];if(L&&!L.match(f)){for(var M="",D=0,N=L.length;D<N;D++)L.charCodeAt(D)>127?M+="x":M+=L[D];if(!M.match(f)){var O=R.slice(0,P),B=R.slice(P+1),F=L.match(p);F&&(O.push(F[1]),B.unshift(F[2])),B.length&&(m="/"+B.join(".")+m),this.hostname=O.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),E||(this.hostname=n.toASCII(this.hostname));var z=this.port?":"+this.port:"",j=this.hostname||"";this.host=j+z,this.href+=this.host,E&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==m[0]&&(m="/"+m))}if(!v[_])for(P=0,I=h.length;P<I;P++){var H=h[P];if(-1!==m.indexOf(H)){var U=encodeURIComponent(H);U===H&&(U=escape(H)),m=m.split(H).join(U)}}var W=m.indexOf("#");-1!==W&&(this.hash=m.substr(W),m=m.slice(0,W));var V=m.indexOf("?");if(-1!==V?(this.search=m.substr(V),this.query=m.substr(V+1),t&&(this.query=y.parse(this.query)),m=m.slice(0,V)):t&&(this.search="",this.query={}),m&&(this.pathname=m),g[_]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){z=this.pathname||"";var q=this.search||"";this.path=z+q}return this.href=this.format(),this},o.prototype.format=function(){var e=this.auth||"";e&&(e=(e=encodeURIComponent(e)).replace(/%3A/i,":"),e+="@");var t=this.protocol||"",i=this.pathname||"",n=this.hash||"",o=!1,s="";this.host?o=e+this.host:this.hostname&&(o=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(o+=":"+this.port)),this.query&&r.isObject(this.query)&&Object.keys(this.query).length&&(s=y.stringify(this.query));var a=this.search||s&&"?"+s||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||g[t])&&!1!==o?(o="//"+(o||""),i&&"/"!==i.charAt(0)&&(i="/"+i)):o||(o=""),n&&"#"!==n.charAt(0)&&(n="#"+n),a&&"?"!==a.charAt(0)&&(a="?"+a),t+o+(i=i.replace(/[?#]/g,(function(e){return encodeURIComponent(e)})))+(a=a.replace("#","%23"))+n},o.prototype.resolve=function(e){return this.resolveObject(m(e,!1,!0)).format()},o.prototype.resolveObject=function(e){if(r.isString(e)){var t=new o;t.parse(e,!1,!0),e=t}for(var i=new o,n=Object.keys(this),s=0;s<n.length;s++){var a=n[s];i[a]=this[a]}if(i.hash=e.hash,""===e.href)return i.href=i.format(),i;if(e.slashes&&!e.protocol){for(var c=Object.keys(e),l=0;l<c.length;l++){var h=c[l];"protocol"!==h&&(i[h]=e[h])}return g[i.protocol]&&i.hostname&&!i.pathname&&(i.path=i.pathname="/"),i.href=i.format(),i}if(e.protocol&&e.protocol!==i.protocol){if(!g[e.protocol]){for(var u=Object.keys(e),d=0;d<u.length;d++){var f=u[d];i[f]=e[f]}return i.href=i.format(),i}if(i.protocol=e.protocol,e.host||x[e.protocol])i.pathname=e.pathname;else{for(var p=(e.pathname||"").split("/");p.length&&!(e.host=p.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==p[0]&&p.unshift(""),p.length<2&&p.unshift(""),i.pathname=p.join("/")}if(i.search=e.search,i.query=e.query,i.host=e.host||"",i.auth=e.auth,i.hostname=e.hostname||e.host,i.port=e.port,i.pathname||i.search){var v=i.pathname||"",y=i.search||"";i.path=v+y}return i.slashes=i.slashes||e.slashes,i.href=i.format(),i}var m=i.pathname&&"/"===i.pathname.charAt(0),b=e.host||e.pathname&&"/"===e.pathname.charAt(0),w=b||m||i.host&&e.pathname,_=w,k=i.pathname&&i.pathname.split("/")||[],T=(p=e.pathname&&e.pathname.split("/")||[],i.protocol&&!g[i.protocol]);if(T&&(i.hostname="",i.port=null,i.host&&(""===k[0]?k[0]=i.host:k.unshift(i.host)),i.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===p[0]?p[0]=e.host:p.unshift(e.host)),e.host=null),w=w&&(""===p[0]||""===k[0])),b)i.host=e.host||""===e.host?e.host:i.host,i.hostname=e.hostname||""===e.hostname?e.hostname:i.hostname,i.search=e.search,i.query=e.query,k=p;else if(p.length)k||(k=[]),k.pop(),k=k.concat(p),i.search=e.search,i.query=e.query;else if(!r.isNullOrUndefined(e.search))return T&&(i.hostname=i.host=k.shift(),(E=!!(i.host&&i.host.indexOf("@")>0)&&i.host.split("@"))&&(i.auth=E.shift(),i.host=i.hostname=E.shift())),i.search=e.search,i.query=e.query,r.isNull(i.pathname)&&r.isNull(i.search)||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.href=i.format(),i;if(!k.length)return i.pathname=null,i.search?i.path="/"+i.search:i.path=null,i.href=i.format(),i;for(var A=k.slice(-1)[0],S=(i.host||e.host||k.length>1)&&("."===A||".."===A)||""===A,P=0,C=k.length;C>=0;C--)"."===(A=k[C])?k.splice(C,1):".."===A?(k.splice(C,1),P++):P&&(k.splice(C,1),P--);if(!w&&!_)for(;P--;P)k.unshift("..");!w||""===k[0]||k[0]&&"/"===k[0].charAt(0)||k.unshift(""),S&&"/"!==k.join("/").substr(-1)&&k.push("");var E,R=""===k[0]||k[0]&&"/"===k[0].charAt(0);return T&&(i.hostname=i.host=R?"":k.length?k.shift():"",(E=!!(i.host&&i.host.indexOf("@")>0)&&i.host.split("@"))&&(i.auth=E.shift(),i.host=i.hostname=E.shift())),(w=w||i.host&&k.length)&&!R&&k.unshift(""),k.length?i.pathname=k.join("/"):(i.pathname=null,i.path=null),r.isNull(i.pathname)&&r.isNull(i.search)||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.auth=e.auth||i.auth,i.slashes=i.slashes||e.slashes,i.href=i.format(),i},o.prototype.parseHost=function(){var e=this.host,t=a.exec(e);t&&(":"!==(t=t[0])&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)}},{"./util":77,punycode:51,querystring:54}],77:[function(e,t,i){"use strict";t.exports={isString:function(e){return"string"==typeof e},isObject:function(e){return"object"==typeof e&&null!==e},isNull:function(e){return null===e},isNullOrUndefined:function(e){return null==e}}},{}],78:[function(e,t,n){(function(e){(function(){function i(t){try{if(!e.localStorage)return!1}catch(e){return!1}var i=e.localStorage[t];return null!=i&&"true"===String(i).toLowerCase()}t.exports=function(e,t){if(i("noDeprecation"))return e;var n=!1;return function(){if(!n){if(i("throwDeprecation"))throw new Error(t);i("traceDeprecation")?console.trace(t):console.warn(t),n=!0}return e.apply(this,arguments)}}}).call(this)}).call(this,void 0!==i.g?i.g:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],79:[function(e,t,i){t.exports=function e(t,i){if(t&&i)return e(t)(i);if("function"!=typeof t)throw new TypeError("need wrapper function");return Object.keys(t).forEach((function(e){n[e]=t[e]})),n;function n(){for(var e=new Array(arguments.length),i=0;i<e.length;i++)e[i]=arguments[i];var n=t.apply(this,e),r=e[e.length-1];return"function"==typeof n&&n!==r&&Object.keys(r).forEach((function(e){n[e]=r[e]})),n}}},{}],80:[function(e,t,i){"use strict";t.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},{}],81:[function(e,t,i){t.exports=function(){for(var e={},t=0;t<arguments.length;t++){var i=arguments[t];for(var r in i)n.call(i,r)&&(e[r]=i[r])}return e};var n=Object.prototype.hasOwnProperty},{}],82:[function(e,t,i){"use strict";t.exports=function(e){e.prototype[Symbol.iterator]=function*(){for(let e=this.head;e;e=e.next)yield e.value}}},{}],83:[function(e,t,i){"use strict";function n(e){var t=this;if(t instanceof n||(t=new n),t.tail=null,t.head=null,t.length=0,e&&"function"==typeof e.forEach)e.forEach((function(e){t.push(e)}));else if(arguments.length>0)for(var i=0,r=arguments.length;i<r;i++)t.push(arguments[i]);return t}function r(e,t,i){var n=t===e.head?new a(i,null,t,e):new a(i,t,t.next,e);return null===n.next&&(e.tail=n),null===n.prev&&(e.head=n),e.length++,n}function o(e,t){e.tail=new a(t,e.tail,null,e),e.head||(e.head=e.tail),e.length++}function s(e,t){e.head=new a(t,null,e.head,e),e.tail||(e.tail=e.head),e.length++}function a(e,t,i,n){if(!(this instanceof a))return new a(e,t,i,n);this.list=n,this.value=e,t?(t.next=this,this.prev=t):this.prev=null,i?(i.prev=this,this.next=i):this.next=null}t.exports=n,n.Node=a,n.create=n,n.prototype.removeNode=function(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");var t=e.next,i=e.prev;return t&&(t.prev=i),i&&(i.next=t),e===this.head&&(this.head=t),e===this.tail&&(this.tail=i),e.list.length--,e.next=null,e.prev=null,e.list=null,t},n.prototype.unshiftNode=function(e){if(e!==this.head){e.list&&e.list.removeNode(e);var t=this.head;e.list=this,e.next=t,t&&(t.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}},n.prototype.pushNode=function(e){if(e!==this.tail){e.list&&e.list.removeNode(e);var t=this.tail;e.list=this,e.prev=t,t&&(t.next=e),this.tail=e,this.head||(this.head=e),this.length++}},n.prototype.push=function(){for(var e=0,t=arguments.length;e<t;e++)o(this,arguments[e]);return this.length},n.prototype.unshift=function(){for(var e=0,t=arguments.length;e<t;e++)s(this,arguments[e]);return this.length},n.prototype.pop=function(){if(this.tail){var e=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,e}},n.prototype.shift=function(){if(this.head){var e=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,e}},n.prototype.forEach=function(e,t){t=t||this;for(var i=this.head,n=0;null!==i;n++)e.call(t,i.value,n,this),i=i.next},n.prototype.forEachReverse=function(e,t){t=t||this;for(var i=this.tail,n=this.length-1;null!==i;n--)e.call(t,i.value,n,this),i=i.prev},n.prototype.get=function(e){for(var t=0,i=this.head;null!==i&&t<e;t++)i=i.next;if(t===e&&null!==i)return i.value},n.prototype.getReverse=function(e){for(var t=0,i=this.tail;null!==i&&t<e;t++)i=i.prev;if(t===e&&null!==i)return i.value},n.prototype.map=function(e,t){t=t||this;for(var i=new n,r=this.head;null!==r;)i.push(e.call(t,r.value,this)),r=r.next;return i},n.prototype.mapReverse=function(e,t){t=t||this;for(var i=new n,r=this.tail;null!==r;)i.push(e.call(t,r.value,this)),r=r.prev;return i},n.prototype.reduce=function(e,t){var i,n=this.head;if(arguments.length>1)i=t;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");n=this.head.next,i=this.head.value}for(var r=0;null!==n;r++)i=e(i,n.value,r),n=n.next;return i},n.prototype.reduceReverse=function(e,t){var i,n=this.tail;if(arguments.length>1)i=t;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");n=this.tail.prev,i=this.tail.value}for(var r=this.length-1;null!==n;r--)i=e(i,n.value,r),n=n.prev;return i},n.prototype.toArray=function(){for(var e=new Array(this.length),t=0,i=this.head;null!==i;t++)e[t]=i.value,i=i.next;return e},n.prototype.toArrayReverse=function(){for(var e=new Array(this.length),t=0,i=this.tail;null!==i;t++)e[t]=i.value,i=i.prev;return e},n.prototype.slice=function(e,t){(t=t||this.length)<0&&(t+=this.length),(e=e||0)<0&&(e+=this.length);var i=new n;if(t<e||t<0)return i;e<0&&(e=0),t>this.length&&(t=this.length);for(var r=0,o=this.head;null!==o&&r<e;r++)o=o.next;for(;null!==o&&r<t;r++,o=o.next)i.push(o.value);return i},n.prototype.sliceReverse=function(e,t){(t=t||this.length)<0&&(t+=this.length),(e=e||0)<0&&(e+=this.length);var i=new n;if(t<e||t<0)return i;e<0&&(e=0),t>this.length&&(t=this.length);for(var r=this.length,o=this.tail;null!==o&&r>t;r--)o=o.prev;for(;null!==o&&r>e;r--,o=o.prev)i.push(o.value);return i},n.prototype.splice=function(e,t,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);for(var n=0,o=this.head;null!==o&&n<e;n++)o=o.next;var s=[];for(n=0;o&&n<t;n++)s.push(o.value),o=this.removeNode(o);for(null===o&&(o=this.tail),o!==this.head&&o!==this.tail&&(o=o.prev),n=0;n<i.length;n++)o=r(this,o,i[n]);return s},n.prototype.reverse=function(){for(var e=this.head,t=this.tail,i=e;null!==i;i=i.prev){var n=i.prev;i.prev=i.next,i.next=n}return this.head=t,this.tail=e,this};try{e("./iterator.js")(n)}catch(e){}},{"./iterator.js":82}]},{},[12])(12)}},t={};function i(n){var r=t[n];if(void 0!==r)return r.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,i),o.exports}i.d=(e,t)=>{for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{"use strict";function e(e,t){const i=t||new Path2D;let n=e.calculative.borderRadius||0,r=n;const{x:o,y:s,width:a,height:c,ex:l,ey:h}=e.calculative.worldRect;n<1&&(n*=a,r*=c);let u=n<r?n:r;if(a<2*u&&(u=a/2),c<2*u&&(u=c/2),i.moveTo(o+u,s),i.arcTo(l,s,l,h,u),i.arcTo(l,h,o,h,u),i.arcTo(o,h,o,s,u),i.arcTo(o,s,l,s,u),i instanceof Path2D)return i}i.r(n),i.d(n,{Meta2d:()=>Sn,activityDiagram:()=>Hn,activityDiagramByCtx:()=>Un,chartsPens:()=>hs,classPens:()=>Mn,flowAnchors:()=>or,flowPens:()=>rr,formPens:()=>So,ftaAnchors:()=>$o,ftaPens:()=>Ko,ftaPensbyCtx:()=>Yo,registerEcharts:()=>Rr,registerHighcharts:()=>Ir,registerLightningChart:()=>Lr,sequencePens:()=>On,sequencePensbyCtx:()=>Bn}),i(173);const t=e;var r,o,s,a;!function(e){e[e.Node=0]="Node",e[e.Line=1]="Line"}(r||(r={})),function(e){e[e.None=0]="None",e[e.DisableEdit=1]="DisableEdit",e[e.DisableMove=2]="DisableMove",e[e.DisableScale=3]="DisableScale",e[e.DisableMoveScale=4]="DisableMoveScale",e[e.Disable=10]="Disable"}(o||(o={})),function(e){e[e.Default=0]="Default",e[e.In=1]="In",e[e.Out=2]="Out"}(s||(s={})),function(e){e[e.None=0]="None",e[e.Linear=1]="Linear",e[e.Radial=2]="Radial"}(a||(a={}));const c=["text","textWidth","textHeight","textLeft","textTop","fontFamily","fontSize","lineHeight","fontStyle","fontWeight","textAlign","textBaseline","whiteSpace","ellipsis","keepDecimal"],l=["x","y","width","height","flipX","flipY"],h=["paddingTop","paddingRight","paddingBottom","paddingLeft","flipX","flipY","visible","showChild"],u=["iconLeft","iconTop","iconRotate"];var d;!function(e){e[e.Normal=0]="Normal",e[e.Beads=1]="Beads",e[e.Dot=2]="Dot"}(d||(d={}));const f=["gif","iframe","video","echarts","highcharts","lightningCharts"],p=new Set(["borderRadius","rotate","paddingLeft","paddingRight","paddingTop","paddingBottom","progress","progressColor","verticalProgress","flipX","flipY","input","lineDash","lineCap","lineJoin","strokeType","lineGradientFromColor","lineGradientToColor","lineGradientAngle","color","hoverColor","activeColor","lineWidth","bkType","gradientFromColor","gradientToColor","gradientAngle","gradientRadius","hoverBackground","activeBackground","globalAlpha","anchorColor","anchorRadius","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","textHasShadow","fontFamily","fontSize","textColor","hoverTextColor","activeTextColor","textBackground","fontStyle","fontWeight","textAlign","textBaseline","lineHeight","whiteSpace","textWidth","textHeight","textLeft","textTop","ellipsis","hiddenText","keepDecimal","borderWidth","borderColor","animateLineWidth","lineAnimateType","frames","animateColor","animateType","animateReverse","background","gradientColors","lineGradientColors","animateLineWidth","gradientSmooth"]);var v,x,g,y;!function(e){e[e.None=0]="None",e[e.LineAnchor=1]="LineAnchor",e[e.NodeAnchor=2]="NodeAnchor",e[e.Line=3]="Line",e[e.Node=4]="Node",e[e.Resize=5]="Resize",e[e.Rotate=6]="Rotate",e[e.LineAnchorPrev=7]="LineAnchorPrev",e[e.LineAnchorNext=8]="LineAnchorNext"}(v||(v={})),function(e){e[e.None=0]="None",e[e.Translate=1]="Translate",e[e.Select=2]="Select",e[e.Resize=3]="Resize",e[e.AddAnchor=4]="AddAnchor"}(x||(x={})),function(e){e[e.None=0]="None",e[e.Down=1]="Down",e[e.Translate=2]="Translate"}(g||(g={})),function(e){e[e.None=-1]="None",e[e.Up=0]="Up",e[e.Right=1]="Right",e[e.Bottom=2]="Bottom",e[e.Left=3]="Left"}(y||(y={}));const m=["nw-resize","ne-resize","se-resize","sw-resize"],b=["n-resize","e-resize","s-resize","w-resize"],w=["curve","polyline","line"],_=["dash","lineWidth","lineCap","lineJoin","strokeType","color","lineGradientFromColor","lineGradientToColor","lineGradientAngle","globalAlpha","bkType","background","gradientFromColor","gradientToColor","gradientAngle","gradientRadius","fontFamily","fontSize","textColor","hoverTextColor","activeTextColor","textBackground","fontStyle","fontWeight","textAlign","textBaseline","lineHeight","whiteSpace","textLeft","textTop","flipX","flipY","lineDash"];var k,T,A;function S(e,t,i){if(!t||t%360==0)return;const n=t*Math.PI/180,r=(e.x-i.x)*Math.cos(n)-(e.y-i.y)*Math.sin(n)+i.x,o=(e.x-i.x)*Math.sin(n)+(e.y-i.y)*Math.cos(n)+i.y;e.x=r,e.y=o,e.prev&&S(e.prev,t,i),e.next&&S(e.next,t,i)}function P(e,t,i=5,n){if(t.type===A.Line){let r=n.rotate;n.flipX&&(r*=-1),n.flipY&&(r*=-1);let o=t.rotate+r;return n.flipX&&(o*=-1),n.flipY&&(o*=-1),_t(e,{x:t.x-t.length*n.calculative.canvas.store.data.scale/2,y:t.y-i,width:t.length*n.calculative.canvas.store.data.scale,height:2*i,rotate:o})}return e.x>t.x-i&&e.x<t.x+i&&e.y>t.y-i&&e.y<t.y+i}function C(e,t,i){e.x=i.x-(i.x-e.x)*t,e.y=i.y-(i.y-e.y)*t}function E(e,t){if(e.x===t.x)return e.y<=t.y?0:180;if(e.y===t.y)return e.x<t.x?270:90;const i=e.x-t.x,n=e.y-t.y;let r=Math.atan(Math.abs(i/n))/(2*Math.PI)*360;return i>0&&n>0?r=180-r:i<0&&n>0?r+=180:i<0&&n<0&&(r=360-r),r}function R(e,t){const i=e.x-t.x,n=e.y-t.y;return Math.sqrt(i*i+n*n)}function I(e,t,i){e&&(e.x+=t,e.y+=i,e.next&&(e.next.x+=t,e.next.y+=i),e.prev&&(e.prev.x+=t,e.prev.y+=i))}function L(e,t){return e.anchorId===t.anchorId&&e.connectTo===t.connectTo}function M(e,t,i){let n=Math.sqrt((e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y))/i.data.scale;0===t.rotate?e.x<t.x?i.pens[t.penId].flipX||(n*=-1):i.pens[t.penId].flipX&&(n*=-1):e.y<t.y?i.pens[t.penId].flipY||(n*=-1):i.pens[t.penId].flipY&&(n*=-1),e.distance=n}!function(e){e[e.Mirror=0]="Mirror",e[e.Bilateral=1]="Bilateral",e[e.Free=2]="Free"}(k||(k={})),function(e){e[e.Default=0]="Default",e[e.In=1]="In",e[e.Out=2]="Out",e[e.DisableConnected=3]="DisableConnected",e[e.DisableConnectTo=4]="DisableConnectTo",e[e.Disable=10]="Disable"}(T||(T={})),function(e){e[e.Default=0]="Default",e[e.Line=1]="Line"}(A||(A={}));const D="1.0.23",N={version:D,path2dDraws:{},canvasDraws:{},anchors:{},htmlElements:{}};function O(e){Object.assign(N.path2dDraws,e)}function B(e){Object.assign(N.canvasDraws,e)}function F(e){Object.assign(N.anchors,e)}var z;!function(e){e[e.None=-1]="None",e[e.Document=0]="Document",e[e.Canvas=1]="Canvas"}(z||(z={}));const j={fontFamily:'"Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial',fontSize:12,lineHeight:1.5,textAlign:"center",textBaseline:"middle",color:"#222222",activeColor:"#278df8",hoverColor:"rgba(39,141,248,0.50)",anchorColor:"#278DF8",hoverAnchorColor:"#FF4101",anchorRadius:4,anchorBackground:"#fff",dockColor:"rgba(39,141,248,0.50)",dockPenColor:"#1890FF",dragColor:"#1890ff",rotateCursor:"rotate.cur",hoverCursor:"pointer",minScale:.1,maxScale:10,keydown:z.Document,gridSize:20,gridColor:"#e2e2e2",ruleColor:"#888888",drawingLineName:"curve",interval:30,animateInterval:30,autoPolyline:!0,autoAnchor:!0,animateColor:"#ff4d4f",ruleLineColor:"#FF4101",defaultAnchors:[{x:.5,y:0},{x:1,y:.5},{x:.5,y:1},{x:0,y:.5}],measureTextWidth:!0,moveConnectedLine:!0,mouseRightActive:!0,disableClipboard:!1,drawingLineLength:0,disableTouchPadScale:!1,cdn:"",polylineSpace:10,domShapes:[],textFlip:!0,textRotate:!0,unavailableKeys:[]};var H;!function(e){e[e.Add=0]="Add",e[e.Update=1]="Update",e[e.Delete=2]="Delete"}(H||(H={}));function U(e){const{paddingTop:t,paddingBottom:i,paddingLeft:n,paddingRight:r,worldRect:o,canvas:s}=e.calculative;let{textLeft:a,textTop:c,textWidth:l,textHeight:h}=e.calculative,u=n,d=t;a&&Math.abs(a)<1&&(a*=o.width),c&&Math.abs(c)<1&&(c*=o.height);const f=o.width-n-r-(("right"===e.textAlign?-a:a)||0),p=o.height-t-i-(("bottom"===e.textBaseline?-c:c)||0);l&&l<1&&(l*=o.width),h&&h<1&&(h*=o.height),l<e.calculative.fontSize&&(l=e.calculative.fontSize),u+=(a||0)+o.x,d+=(c||0)+o.y;const v=e.textAlign||s.store.options.textAlign,x=e.textBaseline||s.store.options.textBaseline;switch(v){case"center":u+=(f-(l||f))/2;break;case"right":u+=f-(l||f)}switch(x){case"middle":d+=(p-(h||p))/2;break;case"bottom":d+=p-(h||p)}const g={x:u,y:d,width:l||f,height:h||p};At(g),e.calculative.worldTextRect=g,V(e),e.calculative.textDrawRect=void 0}function W(e,t){const i=t.calculative.fontSize*t.calculative.lineHeight,n=t.calculative.textLines.length*i,r=function(e,t){let i=0;return t.calculative.textLineWidths=[],t.calculative.textLines.forEach((n=>{const r=e.measureText(n).width;t.calculative.textLineWidths.push(r),i<r&&(i=r)})),i}(e,t),o=t.calculative.worldTextRect;let s=o.x+(o.width-r)/2,a=o.y+(o.height-n)/2;const c=t.calculative.canvas.store.options;switch(t.textAlign||c.textAlign){case"left":s=o.x;break;case"right":s=o.x+o.width-r}switch(t.textBaseline||c.textBaseline){case"top":a=o.y;break;case"bottom":a=o.ey-n}t.calculative.textDrawRect={x:s,y:a,width:r,height:n},At(t.calculative.textDrawRect)}function V(e,t=e.calculative.text){if(null==t)return void(e.calculative.textLines=[]);t=t.toString();let i=[];const n=e.calculative.fontSize*e.calculative.lineHeight,r=e.calculative.worldTextRect.height,o=Math.floor(r/n),s=o>1?o:1;switch(e.whiteSpace){case"nowrap":if(!1!==e.ellipsis){const n=K(t.split(""),e);n[0]&&(i.push(n[0]),n.length>1&&Y(i))}else i.push(t);break;case"pre-line":i=t.split(/[\n]/g),!1!==e.ellipsis&&i.length>s&&(i=i.slice(0,s),Y(i));break;default:const n=t.split(/[\n]/g);let r=0;e:for(const t of n){let n=K("break-all"===e.whiteSpace?t.split(""):q(t),e);if(0===n.length&&(n=[""]),0!=e.ellipsis)for(const e of n){if(r++,r>s){Y(i);break e}i.push(e)}else i.push(...n)}}const a=e.calculative.keepDecimal;return null!=a&&i.forEach(((e,t)=>{const n=Number(e);isNaN(n)||(i[t]=n.toFixed(a))})),e.calculative.textLines=i,i}function q(e=""){const t=[];let i="";for(let n=0;n<e.length;++n){const r=e.charCodeAt(n);r<33||r>126?(i&&(t.push(i),i=""),t.push(e[n])):i+=e[n]}return i&&t.push(i),t}function K(e,t){const i=t.calculative.canvas,n=i.offscreen.getContext("2d"),{fontStyle:r,fontWeight:o,fontSize:s,fontFamily:a,lineHeight:c}=t.calculative;n.save();const l=[];let h=e[0]||"";for(let u=1;u<e.length;++u){const d=e[u]||"",f=h+d;let p=0;if(i.store.options.measureTextWidth)n.font=Ae({fontStyle:r,fontWeight:o,fontFamily:a||i.store.options.fontFamily,fontSize:s,lineHeight:c}),p=n.measureText(f).width;else{const e=f.match(/[^\x00-\xff]/g)||"",t=e.length*s,i=f.match(/\s/g)||"";p=t+i.length*s*.3+(f.length-e.length-i.length)*s*.6}p<=t.calculative.worldTextRect.width?h+=d:(h.length&&l.push(h),h=d)}return h.length&&l.push(h),n.restore(),l}function Y(e){e[e.length-1]=e[e.length-1].slice(0,-3)+"..."}function $(e,t=!1){if(Array.isArray(e)){const i=[];return e.forEach((e=>{i.push($(e,t))})),i}if("object"==typeof e){if(null===e)return null;if(e.constructor===RegExp)return e;const i={};for(const n in e)["canvas","lastFrame"].includes(n)||e[n]instanceof HTMLImageElement||e[n]instanceof HTMLMediaElement||("calculative"!==n||t)&&(i[n]="singleton"!==n?$(e[n],t):t?{}:e[n]);return i}return e}function X(e,t,i){if(Array.isArray(e)){const n=[];return e.forEach((e=>{n.push(X(e,t,i))})),n}if("object"==typeof e){if(null===e)return null;for(const n in e)e[n]=n===t?Number(e[n])*i:X(e[n],t,i);return e}return e}const G={};function Q(e,t,i){if(!G[t.fromArrow])return;const n=$e(t),{x:r,y:o}=n,s={x:r,y:o};if(s.step=(t.fromArrowSize||10)*i.data.scale,n.next)s.rotate=E(n.next,n)+90;else{const e=t.calculative.worldAnchors[1];if(!e)return;e.prev?s.rotate=E(e.prev,n)+90:s.rotate=E(e,n)+90}e.save(),e.beginPath();const a=t.fromArrowColor||t.calculative.color;a&&(e.strokeStyle=a),G[t.fromArrow](e,t,i,s),e.restore()}function J(e,t,i){if(!G[t.toArrow]||t.calculative.worldAnchors.length<2)return;e.save();const n=Xe(t),{x:r,y:o}=n,s={x:r,y:o};if(s.step=(t.toArrowSize||10)*i.data.scale,n.prev)s.rotate=E(n.prev,n)+90;else{const e=t.calculative.worldAnchors[t.calculative.worldAnchors.length-2];e.next?s.rotate=E(e.next,n)+90:s.rotate=E(e,n)+90}e.beginPath();const a=t.toArrowColor||t.calculative.color;a&&(e.strokeStyle=a),G[t.toArrow](e,t,i,s),e.restore()}function Z(e){const t=parseInt,i=Math.round;let n=e.length,r={};if(n>9){const[i,o,s,a]=e=e.split(",");if(n=e.length,n<3||n>4)return null;r.r=t("a"==i[3]?i.slice(5):i.slice(4)),r.g=t(o),r.b=t(s),r.a=a?parseFloat(a):-1}else{if(8==n||6==n||n<4)return null;n<6&&(e="#"+e[1]+e[1]+e[2]+e[2]+e[3]+e[3]+(n>4?e[4]+e[4]:"")),e=t(e.slice(1),16),9==n||5==n?(r.r=e>>24&255,r.g=e>>16&255,r.b=e>>8&255,r.a=i((255&e)/.255)/1e3):(r.r=e>>16,r.g=e>>8&255,r.b=255&e,r.a=-1)}return r}function ee(e,t){const i=Z(e)||{r:0,g:0,b:0};return i.a<0?`rgba(${i.r},${i.g},${i.b},${t})`:`rgba(${i.r},${i.g},${i.b},${t+i.a})`}function te(e,t){if(isNaN(e))return void console.warn("realValue not number");if("string"!=typeof t)return void console.warn("collection must be string");const[i,n]=[t[0],t[t.length-1]];if(!["[","("].includes(i))return void console.warn('collection must start with "[" or "("');if(!["]",")"].includes(n))return void console.warn('collection must end with "]" or ")"');const r=t.substring(1,t.length-1).split(",");if(2!==r.length)return void console.warn("collection must have 2 numbers");const[o,s]=[+r[0],+r[1]];if(!(o>=s))return(e>o||"["===i&&e===o)&&(e<s||"]"===n&&e===s);console.warn("startNum must less than endNum")}function ie(e,t){if(isNaN(e))return void console.warn("realValue not number");if("string"!=typeof t)return void console.warn("collection must be string");const[i,n]=[t[0],t[t.length-1]];if("["!==i||"]"!==n)return void console.warn('collection must start with "[" and end with "]"');const r=t.substring(1,t.length-1).split(",");for(const t of r)if(t.includes("..")){const[i,n]=t.split(".."),[r,o]=[+i,+n];if(r>=o)return void console.warn("startNum must less than endNum");if(e>=r&&e<=o)return!0}else if(e===+t)return!0;return!1}function ne(){return(4294967296*(1+Math.random())|0).toString(16).substring(1)}G.triangleSolid=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step;e.moveTo(r,n.y-n.step/4),e.lineTo(n.x,n.y),e.lineTo(r,n.y+n.step/4),e.closePath(),e.stroke(),e.fillStyle=e.strokeStyle,e.fill(),e.restore()},G.triangle=(e,t,i,n)=>{e.save(),e.lineWidth<2&&(e.lineWidth=2),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step;e.moveTo(r,n.y-n.step/4),e.lineTo(n.x,n.y),e.lineTo(r,n.y+n.step/4),e.closePath(),e.stroke(),e.fillStyle=i.data.background||"#ffffff",e.fill(),e.restore()},G.circleSolid=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.step/2;e.arc(n.x-r,n.y,r,0,2*Math.PI),e.stroke(),e.fillStyle=e.strokeStyle,e.fill(),e.restore()},G.circle=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.step/2;e.arc(n.x-r,n.y,r,0,2*Math.PI),e.stroke(),e.fillStyle=i.data.background||"#ffffff",e.fill(),e.restore()},G.diamondSolid=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step,o=n.step/2;e.moveTo(r,n.y),e.lineTo(r+o,n.y-o/2),e.lineTo(n.x,n.y),e.lineTo(r+o,n.y+o/2),e.closePath(),e.stroke(),e.fillStyle=e.strokeStyle,e.fill(),e.restore()},G.diamond=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step,o=n.step/2;e.moveTo(r,n.y),e.lineTo(r+o,n.y-o/2),e.lineTo(n.x,n.y),e.lineTo(r+o,n.y+o/2),e.closePath(),e.stroke(),e.fillStyle=i.data.background||"#ffffff",e.fill(),e.restore()},G.line=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step;e.moveTo(r,n.y-n.step/3),e.lineTo(n.x,n.y),e.lineTo(r,n.y+n.step/3),e.stroke(),e.restore()},G.lineUp=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step;e.moveTo(r,n.y-n.step/3),e.lineTo(n.x,n.y),e.stroke(),e.restore()},G.lineDown=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step;e.moveTo(r,n.y+n.step/3),e.lineTo(n.x,n.y),e.stroke(),e.restore()},globalThis.pSBC=function(e,t,i,n){let r,o,s,a,c,l,h,u=Math.round,d="string"==typeof i;return"number"!=typeof e||e<-1||e>1||"string"!=typeof t||"r"!=t[0]&&"#"!=t[0]||i&&!d?null:(h=t.length>9,h=d?i.length>9||"c"==i&&!h:h,c=Z(t),a=e<0,l=i&&"c"!=i?Z(i):a?{r:0,g:0,b:0,a:-1}:{r:255,g:255,b:255,a:-1},a=1-(e=a?-1*e:e),c&&l?(n?(r=u(a*c.r+e*l.r),o=u(a*c.g+e*l.g),s=u(a*c.b+e*l.b)):(r=u((a*c.r**2+e*l.r**2)**.5),o=u((a*c.g**2+e*l.g**2)**.5),s=u((a*c.b**2+e*l.b**2)**.5)),d=c.a,l=l.a,c=d>=0||l>=0,d=c?d<0?l:l<0?d:d*a+l*e:0,h?"rgb"+(c?"a(":"(")+r+","+o+","+s+(c?","+u(1e3*d)/1e3:"")+")":"#"+(4294967296+16777216*r+65536*o+256*s+(c?u(255*d):0)).toString(16).slice(1,c?void 0:-2)):null)};const re=e=>{let t=0,i=0,n=0,r=0;return"number"==typeof e?t=i=n=r=e:"string"==typeof e?t=i=n=r=parseInt(e,10):Array.isArray(e)&&(t=e[0],n=oe(e[1])?e[0]:e[1],r=oe(e[2])?e[0]:e[2],i=oe(e[3])?n:e[3]),[t,n,r,i]};function oe(e){return null==e}function se(e,t){if(!e||!e.parentId||!e.calculative)return;const i=e.calculative.canvas.store.pens[e.parentId];return t&&se(i,t)||i}function ae(e,t){if(!e||!e.children)return[];const i=[];return e.children.forEach((e=>{const n=t.pens[e];n&&(i.push(n),i.push(...ae(n,t)))})),i}function ce(e,t,i){const n=Math.atan(i/t)/Math.PI*180;let r=(e-90)%360,o=0;return r>n&&r<180-n||r>180+n&&r<360-n||r<0?(r>270?r=360-r:r>180?r-=180:r>90&&(r=180-r),o=Math.abs(i/Math.sin(r/180*Math.PI)/2)):(r>270?r=360-r:r>180?r-=180:r>90&&(r=180-r),o=Math.abs(t/Math.cos(r/180*Math.PI)/2)),o}function le(e){if("string"==typeof e&&e.startsWith("linear-gradient")){let t=e.slice(16,-2).split("deg,");if(t.length>1){let e=t[1].split("%,");const i=[];return e.forEach((e=>{if(/rgba?/.test(e)){let t=e.split(") ");i.push({color:he(t[0]+")"),i:parseFloat(t[1])/100})}else{let t=e.split(" ");t.length>2?i.push({color:t[1],i:parseFloat(t[2])/100}):i.push({color:t[0],i:parseFloat(t[1])/100})}})),{angle:parseFloat(t[0]),colors:i}}return{angle:parseFloat(t[0]),colors:[]}}return{angle:0,colors:[]}}function he(e){if(/rgba?/.test(e)){let t=e.split(",");if(t.length<3)return"";e="#";for(let i,n=0;i=t[n++];)n<4?(i=parseInt(i.replace(/[^\d]/gi,""),10).toString(16),e+=1==i.length?"0"+i:i):(i=i.replace(")",""),e+=parseInt(255*i+"").toString(16));e=e.toUpperCase()}return e}function ue(e,t,i,n){let r=function(e,t,i,n,r){let o=0;o=Math.PI/2-Math.atan2(n-t,i-e);const s=(e+i)/2,a=(t+n)/2;return[s+r*Math.sin(90*Math.PI/180-o),a+r*-Math.cos(90*Math.PI/180-o),s+r*Math.sin(270*Math.PI/180-o),a+r*-Math.cos(270*Math.PI/180-o)]}(t[0].x,t[0].y,t[1].x,t[1].y,n),o=e.createLinearGradient(r[0],r[1],r[2],r[3]);return i.forEach((e=>{o.addColorStop(e.i,e.color)})),o}function de(e,t,i){let n=[];t.calculative.gradientColorStop?n=t.calculative.gradientColorStop:(n=le(t.calculative.lineGradientColors).colors,t.calculative.gradientColorStop=n),e.strokeStyle=ue(e,i,n,t.calculative.lineWidth/2),e.beginPath(),e.moveTo(i[0].x,i[0].y),e.lineTo(i[1].x,i[1].y),e.stroke()}function fe(e,t,i){let n=Math.sqrt((i.x-t.x)*(i.x-t.x)+(i.y-t.y)*(i.y-t.y));return 0===n?{x:t.x,y:t.y}:e<n?{x:t.x+(i.x-t.x)*e/n,y:t.y+(i.y-t.y)*e/n}:{x:t.x+(i.x-t.x)/n/2,y:t.y+(i.y-t.y)/n/2}}function pe(e,t,i,n,r,o){let s=fe(i,r,n),a=fe(i,r,o),c=function(e=100,t,i,n,r){let o=null;const s=[];n||r?n&&!r?o=ge:n&&r&&(o=ye):o=xe;for(let a=0;a<e;a++)s.push(o(a/e,t,i,n,r));return r?s.push(r):n&&s.push(n),s}(100,s,{x:r.x,y:r.y},a);for(let i=0;i<c.length-1;i++)de(e,t,[{x:c[i].x,y:c[i].y},{x:c[i+1].x,y:c[i+1].y}])}function ve(e,t,i,n){let r=fe(t,i,n),o={x:i.x,y:i.y};e.quadraticCurveTo(o.x,o.y,r.x,r.y)}function xe(e,t,i){const{x:n,y:r}=t,{x:o,y:s}=i;return{x:n+(o-n)*e,y:r+(s-r)*e}}function ge(e,t,i,n){const{x:r,y:o}=t,{x:s,y:a}=i,{x:c,y:l}=n;return{x:(1-e)*(1-e)*r+2*e*(1-e)*s+e*e*c,y:(1-e)*(1-e)*o+2*e*(1-e)*a+e*e*l}}function ye(e,t,i,n,r){const{x:o,y:s}=t,{x:a,y:c}=r,{x:l,y:h}=i,{x:u,y:d}=n;return{x:o*(1-e)*(1-e)*(1-e)+3*l*e*(1-e)*(1-e)+3*u*e*e*(1-e)+a*e*e*e,y:s*(1-e)*(1-e)*(1-e)+3*h*e*(1-e)*(1-e)+3*d*e*e*(1-e)+c*e*e*e}}function me(e,t,i,n,r){if(!i||!n)return;const{x:o,y:s,center:a,ex:c,ey:l}=t,h={x:o,y:a.y},u={x:c,y:a.y};r%90==0&&r%180?(h.x=a.x,u.x=a.x,r%270?(h.y=s,u.y=l):(h.y=l,u.y=s)):r&&(S(h,r,t.center),S(u,r,t.center));const d=e.createLinearGradient(h.x,h.y,u.x,u.y);return d.addColorStop(0,i),d.addColorStop(1,n),d}function be(e,t){const{x:i,y:n,width:r,height:o}=function(e){const{worldIconRect:t,iconWidth:i,iconHeight:n,imgNaturalWidth:r,imgNaturalHeight:o}=e.calculative;let{x:s,y:a,width:c,height:l}=t;if(i&&(c=i),n&&(l=n),r&&o&&e.imageRatio){const e=t.width/r,s=t.height/o,a=Math.min(e,s),h=r/o;i?l=i/h:n?c=n*h:(c=a*r,l=a*o)}switch(s+=(t.width-c)/2,a+=(t.height-l)/2,e.iconAlign){case"top":a=t.y;break;case"bottom":a=t.ey-l;break;case"left":s=t.x;break;case"right":s=t.ex-c;break;case"left-top":s=t.x,a=t.y;break;case"right-top":s=t.ex-c,a=t.y;break;case"left-bottom":s=t.x,a=t.ey-l;break;case"right-bottom":s=t.ex-c,a=t.ey-l}return{x:s,y:a,width:c,height:l}}(t),{worldIconRect:s,iconRotate:a,img:c}=t.calculative;if(a){const{x:t,y:i}=s.center;e.translate(t,i),e.rotate(a*Math.PI/180),e.translate(-t,-i)}if(t.imageRadius){e.save();let s=t.calculative.imageRadius||0,a=s;const{x:l,y:h,width:u,height:d,ex:f,ey:p}=t.calculative.worldRect;s<1&&(s*=u,a*=d);let v=s<a?s:a;u<2*v&&(v=u/2),d<2*v&&(v=d/2),e.beginPath(),e.moveTo(l+v,h),e.arcTo(f,h,f,p,v),e.arcTo(f,p,l,p,v),e.arcTo(l,p,l,h,v),e.arcTo(l,h,f,h,v),e.clip(),e.drawImage(c,i,n,r,o),e.restore()}else e.drawImage(c,i,n,r,o)}function we(e,t){const{textColor:i,color:n}=e.calculative,{data:r,options:o}=t;return i||n||r.textColor||r.color||o.textColor||o.color}function _e(e,t){const{fontStyle:i,fontWeight:n,fontSize:r,fontFamily:o,lineHeight:s,text:a,hiddenText:c,canvas:l,textHasShadow:h,textBackground:u}=t.calculative;if(null==a||c)return;const d=l.store;let f;e.save(),h||(e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0),t.calculative.hover?f=t.hoverTextColor||t.hoverColor||d.options.hoverColor:t.calculative.active&&(f=t.activeTextColor||t.activeColor||d.options.activeColor),e.fillStyle=f||we(t,d),e.font=Ae({fontStyle:i,fontWeight:n,fontFamily:o||d.options.fontFamily,fontSize:r,lineHeight:s}),!t.calculative.textDrawRect&&W(e,t);const{x:p,y:v,width:x,height:g}=t.calculative.textDrawRect;u&&(e.save(),e.fillStyle=u,e.fillRect(p,v,x,g),e.restore());const y=t.textAlign||d.options.textAlign,m=r*s;t.calculative.textLines.forEach(((i,n)=>{const r=t.calculative.textLineWidths[n];let o=0;"center"===y?o=(x-r)/2:"right"===y&&(o=x-r),e.fillText(i,p+o,v+(n+.55)*m)})),e.restore()}function ke(e,t,i){if(null==i)return;const{fontStyle:n,fontWeight:r,fontSize:o,fontFamily:s,lineHeight:a,canvas:c}=t.calculative,l=c.store;let h;e.save(),t.calculative.hover?h=t.hoverTextColor||t.hoverColor||l.options.hoverColor:t.calculative.active&&(h=t.activeTextColor||t.activeColor||l.options.activeColor),e.fillStyle=h||we(t,l),e.font=Ae({fontStyle:n,fontWeight:r,fontFamily:s||l.options.fontFamily,fontSize:o,lineHeight:a});const u=e.measureText(i).width;let d,f;for(const n of t.calculative.worldAnchors){if(!f){f=n;continue}const t=R(f,n),r=Math.floor(t/u);d="";for(let e=0;e<r;e++)d+=i;const o=E(f,n)-270;if(e.save(),o%360!=0){const{x:t,y:i}=f;e.translate(t,i);let n=o*Math.PI/180;e.rotate(n),e.translate(-t,-i)}e.fillText(d,f.x,f.y+a/2),e.restore(),f=n}e.restore()}function Te(e,t){const i=t.calculative.canvas.store;e.save(),e.shadowColor="",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0,e.textAlign="center",e.textBaseline="middle";const n=t.calculative.worldIconRect;let r=n.x+n.width/2,o=n.y+n.height/2;switch(t.iconAlign){case"top":o=n.y,e.textBaseline="top";break;case"bottom":o=n.ey,e.textBaseline="bottom";break;case"left":r=n.x,e.textAlign="left";break;case"right":r=n.ex,e.textAlign="right";break;case"left-top":r=n.x,o=n.y,e.textAlign="left",e.textBaseline="top";break;case"right-top":r=n.ex,o=n.y,e.textAlign="right",e.textBaseline="top";break;case"left-bottom":r=n.x,o=n.ey,e.textAlign="left",e.textBaseline="bottom";break;case"right-bottom":r=n.ex,o=n.ey,e.textAlign="right",e.textBaseline="bottom"}const s=t.calculative.iconWeight;let a;const c=t.calculative.iconFamily;a=t.calculative.iconSize>0?t.calculative.iconSize:n.width>n.height?n.height:n.width,e.font=Ae({fontSize:a,fontWeight:s,fontFamily:c}),e.fillStyle=t.calculative.iconColor||we(t,i),t.calculative.iconRotate&&(e.translate(n.center.x,n.center.y),e.rotate(t.calculative.iconRotate*Math.PI/180),e.translate(-n.center.x,-n.center.y)),e.beginPath(),e.fillText(t.calculative.icon,r,o),e.restore()}function Ae({fontStyle:e="normal",textDecoration:t="normal",fontWeight:i="normal",fontSize:n=12,fontFamily:r="Arial",lineHeight:o=1}={}){return`${e} ${t} ${i} ${n}px/${o} ${r}`}function Se(e,t){const{x:i,ex:n,y:r,ey:o}=t.calculative.worldRect||{};t.calculative.flipX&&(e.translate(i+n+.5,.5),e.scale(-1,1)),t.calculative.flipY&&(e.translate(.5,r+o+.5),e.scale(1,-1))}function Pe(e,t,i=!1){const{x:n,y:r}=t.calculative.worldRect.center;e.translate(n,r);let o=t.calculative.rotate*Math.PI/180;i||(t.calculative.flipX&&(o*=-1),t.calculative.flipY&&(o*=-1)),e.rotate(o),e.translate(-n,-r)}function Ce(e,t){e.save(),e.translate(.5,.5),e.beginPath();const i=t.calculative.canvas.store,n=t.textFlip||i.options.textFlip,o=t.textRotate||i.options.textRotate;let s;n&&o||e.save(),Se(e,t),t.calculative.rotate&&"line"!==t.name&&Pe(e,t),t.calculative.lineWidth>1&&(e.lineWidth=t.calculative.lineWidth),function(e,t,i){if(t.fillWorldTextRect){e.save(),e.fillStyle="#c3deb7";const{x:t,y:n,width:r,height:o}=i.calculative.worldTextRect;e.fillRect(t,n,r,o),e.restore()}}(e,i,t);let c,l=!1;t.calculative.hover?(c=t.hoverColor||i.options.hoverColor,s=t.hoverBackground||i.options.hoverBackground):t.calculative.active?(c=t.activeColor||i.options.activeColor,s=t.activeBackground||i.options.activeBackground):t.calculative.isDock&&(t.type===r.Line?c=i.options.dockPenColor:s=ee(i.options.dockPenColor,.2));const h=t.calculative.strokeImg;if(t.calculative.strokeImage&&h)e.strokeStyle=c||e.createPattern(h,"repeat");else{let n;t.calculative.strokeType?t.calculative.lineGradientColors?"line"===t.name?l=!0:t.calculative.lineGradient?n=t.calculative.lineGradient:(n=function(e,t){const{x:i,y:n,ex:r,width:o,height:s,center:a}=t.calculative.worldRect;let c=[{x:r,y:n+s/2},{x:i,y:n+s/2}];const{angle:l,colors:h}=le(t.calculative.lineGradientColors);let u=ce(l,o,s);return c.forEach((e=>{S(e,l,a)})),ue(e,c,h,u)}(e,t),t.calculative.lineGradient=n):n=function(e,t){const{worldRect:i,lineGradientFromColor:n,lineGradientToColor:r,lineGradientAngle:o}=t.calculative;return me(e,i,n,r,o)}(e,t):n=t.calculative.color||De(i),e.strokeStyle=c||n}const u=t.calculative.backgroundImg;if(t.calculative.backgroundImage&&u)e.fillStyle=s||e.createPattern(u,"repeat"),s=!0;else{let n;t.calculative.bkType===a.Linear?t.calculative.gradientColors?"line"!==t.name&&(t.calculative.gradient?n=t.calculative.gradient:(n=function(e,t){const{x:i,y:n,ex:r,width:o,height:s,center:a}=t.calculative.worldRect;let c=[{x:r,y:n+s/2},{x:i,y:n+s/2}];const{angle:l,colors:h}=le(t.calculative.gradientColors);let u=ce(l,o,s);return c.forEach((e=>{S(e,l,a)})),ue(e,c,h,u)}(e,t),t.calculative.gradient=n)):n=function(e,t){const{worldRect:i,gradientFromColor:n,gradientToColor:r,gradientAngle:o}=t.calculative;return me(e,i,n,r,o)}(e,t):t.calculative.bkType===a.Radial?t.calculative.gradientColors?t.calculative.radialGradient?n=t.calculative.radialGradient:(n=function(e,t){const{worldRect:i,gradientColors:n,gradientRadius:r}=t.calculative;if(!n)return;const{width:o,height:s,center:a}=i,{x:c,y:l}=a;let h=o;h<s&&(h=s),h*=.5;const{colors:u}=le(n),d=e.createRadialGradient(c,l,h*(r||0),c,l,h);return u.forEach((e=>{d.addColorStop(e.i,e.color)})),d}(e,t),t.calculative.radialGradient=n):n=function(e,t){const{worldRect:i,gradientFromColor:n,gradientToColor:r,gradientRadius:o}=t.calculative;if(!n||!r)return;const{width:s,height:a,center:c}=i,{x:l,y:h}=c;let u=s;u<a&&(u=a),u*=.5;const d=e.createRadialGradient(l,h,u*(o||0),l,h,u);return d.addColorStop(0,n),d.addColorStop(1,r),d}(e,t):n=t.calculative.background||i.data.penBackground,e.fillStyle=s||n,s=!!n}if(Ee(e,t),Re(e,t),ut(e,t),t.calculative.lineDash&&e.setLineDash(t.calculative.lineDash),t.calculative.lineDashOffset&&(e.lineDashOffset=t.calculative.lineDashOffset),t.calculative.shadowColor&&(e.shadowColor=t.calculative.shadowColor,e.shadowOffsetX=t.calculative.shadowOffsetX,e.shadowOffsetY=t.calculative.shadowOffsetY,e.shadowBlur=t.calculative.shadowBlur),l?(function(e,t){const i=t.calculative.worldAnchors;let n=t.calculative.lineWidth*(t.calculative.gradientSmooth||0);for(let r=0;r<i.length-1;r++)if("curve"!==t.lineName&&"mind"!==t.lineName||!i[r].curvePoints){let o=i[r],s=i[r+1];if(r>0&&r<i.length-1){let o=i[r-1].curvePoints;pe(e,t,n,o?o[o.length-1]:i[r-1],i[r],i[r+1])}r>0&&r<i.length-1&&(o=fe(n,i[r],i[r+1])),r<i.length-2&&(s=fe(n,i[r+1],i[r])),de(e,t,[o,s])}else{if(r>0){let o=i[r-1].curvePoints;pe(e,t,n,o?o[o.length-1]:i[r-1],i[r],i[r].curvePoints[0]),de(e,t,[fe(n,i[r],i[r].curvePoints[0]),i[r].curvePoints[1]])}else de(e,t,[i[r],i[r].curvePoints[0]]),de(e,t,[i[r].curvePoints[0],i[r].curvePoints[1]]);let o=i[r].curvePoints.length-1;for(let n=1;n<o;n++)de(e,t,[i[r].curvePoints[n],i[r].curvePoints[n+1]]);let s=fe(n,i[r+1],i[r].curvePoints[o]);de(e,t,[i[r].curvePoints[o],s])}}(e,t),function(e=!0,t,i,n){const r=e?n.path2dMap.get(i):N.path2dDraws[i.name];r&&i.type&&(i.calculative.animatePos&&(t.save(),Me(t,i,n),t.beginPath(),r instanceof Path2D?!i.calculative.gradientSmooth||"polyline"!==i.lineName&&"line"!==i.lineName?t.stroke(r):(i.calculative.gradientAnimatePath||(i.calculative.gradientAnimatePath=function(e){const t=e.calculative.worldAnchors;let i=e.calculative.lineWidth*(e.calculative.gradientSmooth||0);const n=new Path2D;for(let e=0;e<t.length-1;e++){let r=t[e],o=t[e+1];0==e&&n.moveTo(t[e].x,t[e].y),e>0&&e<t.length-1&&(t[e-1].curvePoints,ve(n,i,t[e],t[e+1])),e>0&&e<t.length-1&&(r=fe(i,t[e],t[e+1])),e<t.length-2&&(o=fe(i,t[e+1],t[e])),n.lineTo(o.x,o.y)}return n}(i)),i.calculative.gradientAnimatePath instanceof Path2D&&t.stroke(i.calculative.gradientAnimatePath)):(r(i,t),t.stroke()),t.restore()),i.fromArrow&&Q(t,i,n),i.toArrow&&J(t,i,n),i.calculative.active&&!i.calculative.pencil&&Ne(t,i))}(!0,e,t,i)):(Le(!0,e,t,i,s),dt(e,t)),t.image&&t.calculative.img||!t.calculative.icon||Te(e,t),n&&o||e.restore(),n&&!o&&Se(e,t),!n&&o&&t.calculative.rotate&&"line"!==t.name&&Pe(e,t,!0),_e(e,t),t.type===r.Line&&t.fillTexts)for(const i of t.fillTexts)ke(e,t,i);e.restore()}function Ee(e,t){const i=t.lineCap||(t.type?"round":"square");i?e.lineCap=i:t.type&&(e.lineCap="round")}function Re(e,t){const i=t.lineJoin;i?e.lineJoin=i:t.type&&(e.lineJoin="round")}function Ie(e,t,i){e.save(),i&&e.translate(-i.x,-i.y),e.setAttrs?.(t);const n=t.calculative.canvas.store,o=t.textFlip||n.options.textFlip,s=t.textRotate||n.options.textRotate;let a;if(e.beginPath(),o&&s||e.save(),t.calculative.flipX&&(e.translate(t.calculative.worldRect.x+t.calculative.worldRect.ex,0),e.scale(-1,1)),t.calculative.flipY&&(e.translate(0,t.calculative.worldRect.y+t.calculative.worldRect.ey),e.scale(1,-1)),t.calculative.rotate&&"line"!==t.name&&Pe(e,t),t.calculative.lineWidth>1&&(e.lineWidth=t.calculative.lineWidth),t.calculative.hover?(e.strokeStyle=t.hoverColor||n.options.hoverColor,e.fillStyle=t.hoverBackground||n.options.hoverBackground,a=t.hoverBackground||n.options.hoverBackground):t.calculative.active?(e.strokeStyle=t.activeColor||n.options.activeColor,e.fillStyle=t.activeBackground||n.options.activeBackground,a=t.activeBackground||n.options.activeBackground):(t.strokeImage?t.calculative.strokeImg&&(e.strokeStyle=e.createPattern(t.calculative.strokeImg,"repeat"),a=!0):e.strokeStyle=t.calculative.color||De(n),t.backgroundImage?t.calculative.backgroundImg&&(e.fillStyle=e.createPattern(t.calculative.backgroundImg,"repeat"),a=!0):(e.fillStyle=t.background,a=!!t.background)),Ee(e,t),Re(e,t),ut(e,t),t.calculative.lineDash&&e.setLineDash(t.calculative.lineDash),t.calculative.lineDashOffset&&(e.lineDashOffset=t.calculative.lineDashOffset),t.calculative.shadowColor&&(e.shadowColor=t.calculative.shadowColor,e.shadowOffsetX=t.calculative.shadowOffsetX,e.shadowOffsetY=t.calculative.shadowOffsetY,e.shadowBlur=t.calculative.shadowBlur),Le(!1,e,t,n,a),dt(e,t),t.calculative.img?(e.save(),e.shadowColor="",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0,be(e,t),e.restore()):t.calculative.icon&&Te(e,t),o&&s||e.restore(),o&&!s&&(t.calculative.flipX&&(e.translate(t.calculative.worldRect.x+t.calculative.worldRect.ex,0),e.scale(-1,1)),t.calculative.flipY&&(e.translate(0,t.calculative.worldRect.y+t.calculative.worldRect.ey),e.scale(1,-1))),!o&&s&&t.calculative.rotate&&"line"!==t.name&&Pe(e,t,!0),_e(e,t),t.type===r.Line&&t.fillTexts)for(const i of t.fillTexts)ke(e,t,i);e.restore()}function Le(e=!0,t,i,n,o){const s=e?n.path2dMap.get(i):N.path2dDraws[i.name];if(s){if(i.type===r.Line&&i.borderWidth){t.save(),t.beginPath();const e=i.calculative.lineWidth+i.calculative.borderWidth;t.lineWidth=e,t.strokeStyle=i.borderColor,s instanceof Path2D?(o&&t.fill(s),e&&t.stroke(s)):(s(i,t),o&&t.fill(),e&&t.stroke()),t.restore()}s instanceof Path2D?o&&t.fill(s):(t.save(),s(i,t),o&&t.fill(),t.restore());const e=i.calculative.progress;if(null!=e){t.save();const{x:r,y:o,width:a,height:c,ey:l}=i.calculative.worldRect,h=i.verticalProgress?t.createLinearGradient(r,l,r,o+c*(1-e)):t.createLinearGradient(r,o,r+a*e,o),u=i.calculative.progressColor||i.calculative.color||n.options.activeColor;h.addColorStop(0,u),h.addColorStop(1,u),h.addColorStop(1,"transparent"),t.fillStyle=h,s instanceof Path2D?t.fill(s):(s(i,t),t.fill()),t.restore()}i.calculative.lineWidth&&(s instanceof Path2D?t.stroke(s):(s(i,t),t.stroke())),i.type&&(i.calculative.animatePos&&(t.save(),Me(t,i,n),s instanceof Path2D?t.stroke(s):(s(i,t),t.stroke()),t.restore()),i.fromArrow&&Q(t,i,n),i.toArrow&&J(t,i,n),i.calculative.active&&!i.calculative.pencil&&Ne(t,i))}}function Me(e,t,i){e.strokeStyle=t.animateColor||i.options.animateColor,t.calculative.animateLineWidth&&(e.lineWidth=t.calculative.animateLineWidth*i.data.scale);let n=0;switch(t.lineAnimateType){case d.Beads:t.animateReverse?e.lineDashOffset=t.calculative.animatePos:e.lineDashOffset=t.length-t.calculative.animatePos,n=t.calculative.lineWidth||5,n<5&&(n=5);const r=t.animateLineDash&&t.animateLineDash.map((e=>e*n/5));e.setLineDash(r||[n,2*n]);break;case d.Dot:t.animateReverse?e.lineDashOffset=t.calculative.animatePos:e.lineDashOffset=t.length-t.calculative.animatePos,n=t.calculative.animateDotSize||2*t.calculative.lineWidth||6,n<6&&(n=6),e.lineWidth=(t.calculative.animateLineWidth||n)*i.data.scale,e.setLineDash([.1,t.length]);break;default:t.animateReverse?e.setLineDash([0,t.length-t.calculative.animatePos+1,t.calculative.animatePos]):e.setLineDash([t.calculative.animatePos,t.length-t.calculative.animatePos])}}function De(e){const{data:t,options:i}=e;return t.color||i.color}function Ne(e,t){const i=t.calculative.canvas.store;e.save(),e.lineWidth=1,e.fillStyle=t.activeColor||i.options.activeColor,t.calculative.worldAnchors.forEach((i=>{!i.hidden&&!i.isTemp&&function(e,t,i){if(!t)return;const n=i.calculative.canvas.store.activeAnchor===i.calculative.activeAnchor&&i.calculative.activeAnchor===t;let r=3;i.calculative.lineWidth>3&&(r=i.calculative.lineWidth),i.anchorRadius&&(r=i.anchorRadius),t.radius&&(r=t.radius),n?(t.prev&&(e.save(),e.strokeStyle="#4dffff",e.beginPath(),e.moveTo(t.prev.x,t.prev.y),e.lineTo(t.x,t.y),e.stroke(),e.restore(),e.save(),e.fillStyle="#ffffff",e.beginPath(),e.arc(t.prev.x,t.prev.y,r,0,2*Math.PI),e.fill(),e.stroke(),e.restore()),t.next&&(e.save(),e.strokeStyle="#4dffff",e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(t.next.x,t.next.y),e.stroke(),e.restore(),e.save(),e.fillStyle="#ffffff",e.beginPath(),e.arc(t.next.x,t.next.y,r,0,2*Math.PI),e.fill(),e.stroke(),e.restore(),e.beginPath(),e.arc(t.x,t.y,r,0,2*Math.PI),e.fill(),e.stroke()),e.beginPath(),e.arc(t.x,t.y,r,0,2*Math.PI),e.fill(),e.stroke()):(e.save(),e.fillStyle="#ffffff",e.beginPath(),e.arc(t.x,t.y,r,0,2*Math.PI),e.fill(),e.stroke(),e.restore())}(e,i,t)})),e.restore()}function Oe(e){const t=e.calculative.canvas.store;let i={x:e.x,y:e.y};if(!e.parentId||e.parentId&&!t.pens[e.parentId])e.parentId=void 0,i.width=e.width,i.height=e.height,i.rotate=e.rotate,At(i),Tt(i);else{const n=t.pens[e.parentId];let r=n.calculative.worldRect;r||(r=Oe(n)),i.x=r.x+r.width*e.x,i.y=r.y+r.height*e.y,i.width=r.width*e.width,i.height=r.height*e.height,n.flipX&&(i.x=r.width-(i.x-r.x+i.width)+r.x),n.flipY&&(i.y=r.height-(i.y-r.y+i.height)+r.y),At(i),i.rotate=r.rotate+e.rotate,Tt(i)}return e.calculative.worldRect=i,Be(e,i),i}function Be(e,t){!e.paddingTop&&(e.calculative.paddingTop=0),!e.paddingBottom&&(e.calculative.paddingBottom=0),!e.paddingLeft&&(e.calculative.paddingLeft=0),!e.paddingRight&&(e.calculative.paddingRight=0),e.calculative.paddingTop<1&&(e.calculative.paddingTop*=t.height),e.calculative.paddingBottom<1&&(e.calculative.paddingBottom*=t.height),e.calculative.paddingLeft<1&&(e.calculative.paddingLeft*=t.width),e.calculative.paddingRight<1&&(e.calculative.paddingRight*=t.width)}function Fe(e){const t=e.calculative.worldRect;if(!e.parentId)return void Object.assign(e,t);const i=e.calculative.canvas.store.pens[e.parentId].calculative.worldRect;Object.assign(e,Dt(t,i))}function ze(e){const t=e.calculative.canvas.store;let i=[];if(e.anchors){let t=$(e.anchors);e.flipX&&t.forEach((e=>{e.x=.5-(e.x-.5)})),e.flipY&&t.forEach((e=>{e.y=.5-(e.y-.5)})),t.forEach((t=>{i.push(function(e,t){const i={...t},{x:n,y:r,width:o,height:s}=e.calculative.worldRect;return i.x=n+o*t.x,i.y=r+s*t.y,t.prev&&(i.prev={penId:e.id,connectTo:t.prev.connectTo,x:n+o*t.prev.x,y:r+s*t.prev.y}),t.next&&(i.next={penId:e.id,connectTo:t.next.connectTo,x:n+o*t.next.x,y:r+s*t.next.y}),i}(e,t))}))}if(!i.length&&!e.type&&!e.calculative.canvas.parent.isCombine(e)){const{x:n,y:r,width:o,height:s}=e.calculative.worldRect;i=t.options.defaultAnchors.map(((t,i)=>({id:`${i}`,penId:e.id,x:n+o*t.x,y:r+s*t.y})))}e.calculative.rotate&&i.forEach((t=>{S(t,e.calculative.rotate,e.calculative.worldRect.center)})),e.type&&!e.anchors||(e.calculative.worldAnchors=i),e.calculative.activeAnchor&&i.length&&(e.calculative.activeAnchor=i.find((t=>{t.id,e.calculative.activeAnchor.id}))),e.calculative.gradientAnimatePath=void 0}function je(e,t){const{paddingTop:i,paddingBottom:n,paddingLeft:r,paddingRight:o}=t.calculative;let s=r,a=i,c=t.calculative.worldRect.width-r-o,l=t.calculative.worldRect.height-i-n,h=t.calculative.iconLeft,u=t.calculative.iconTop;h&&Math.abs(h)<1&&(h=t.calculative.worldRect.width*h),u&&Math.abs(u)<1&&(u=t.calculative.worldRect.height*u),s+=h||0,a+=u||0,c-=h||0,l-=u||0;let d=t.calculative.iconRotate||0;if(t.parentId){const i=e[t.parentId].calculative;i&&(d+=i.rotate,d%=360)}s=t.calculative.worldRect.x+s,a=t.calculative.worldRect.y+a,t.calculative.worldIconRect={x:s,y:a,width:c,height:l,rotate:d},At(t.calculative.worldIconRect),Tt(t.calculative.worldIconRect)}function He(e,t,i){Mt(e.calculative.worldRect,t,i),e.calculative.initRect&&Mt(e.calculative.initRect,t,i),e.calculative.x&&C(e.calculative,t,i),e.type&&ze(e)}function Ue(e,t){if(!t||!t.calculative||!t.calculative.worldRect.center)return y.None;if(e.anchorId){let i=t.anchors.filter((t=>t.id===e.anchorId));if(i.length&&i[0].direction>-1)return i[0].direction}return function(e,t){let i=y.None;if(!t)return i;const n=e.x-t.x,r=e.y-t.y;return i=Math.abs(n)>Math.abs(r)?n>0?y.Right:y.Left:r>0?y.Bottom:y.Up,i}(e,t.calculative.worldRect.center)}function We(e,t){let i,n=1/0;return e.calculative.worldAnchors.forEach((e=>{const r=R(t,e);n>r&&(n=r,i=e)})),i}function Ve(e){if(e&&e.calculative&&e.calculative.worldAnchors.length){let t=Xe(e);if(e.anchors&&e.anchors.length)t===e.calculative.activeAnchor?e.calculative.worldAnchors=[e.calculative.worldAnchors[0]]:e.calculative.worldAnchors[0]===e.calculative.activeAnchor&&(e.calculative.worldAnchors=[e.calculative.worldAnchors[e.calculative.worldAnchors.length-1]]);else for(;e.calculative.worldAnchors.length&&t!==e.calculative.activeAnchor;)e.calculative.worldAnchors.pop(),t=Xe(e)}}function qe(e,t,i,n){if(e&&t&&i&&n&&t.twoWay!==T.DisableConnected&&t.twoWay!==T.Disable&&n.twoWay!==T.DisableConnectTo&&n.twoWay!==T.Disable){if(t.twoWay===T.In){if(1===i.calculative.worldAnchors.length)return;const e=Xe(i);if(n.id!==e.id)return}if(t.twoWay===T.Out){const e=$e(i);if(n.id!==e.id)return}if(n.connectTo!==e.id||n.anchorId!==t.id){if(n.connectTo){const t=e.calculative.canvas.store.pens[n.connectTo];Ke(t,Ye(t,n.anchorId),i,n)}return e.connectedLines||(e.connectedLines=[]),e.connectedLines.findIndex((e=>e.lineId===i.id&&e.lineAnchor===n.id&&e.anchor===t.id))<0&&e.connectedLines.push({lineId:i.id,lineAnchor:n.id,anchor:t.id}),n.connectTo=e.id,n.anchorId=t.id,e.type&&qe(i,n,e,t),e.calculative.canvas.store.emitter.emit("connectLine",{line:i,lineAnchor:n,pen:e,anchor:t}),!0}}}function Ke(e,t,i,n){if(e&&t&&i&&n&&e.connectedLines&&e.connectedLines.length)return e.connectedLines.forEach(((e,r,o)=>{e.lineId!==i.id&&e.lineId!==i.id||e.lineAnchor!==n.id||e.anchor!==t.id||o.splice(r,1)})),n.connectTo=void 0,n.anchorId=void 0,e.type&&t.connectTo===i.id&&t.anchorId===n.id&&Ke(i,n,e,t),e.calculative.canvas.store.emitter.emit("disconnectLine",{line:i,lineAnchor:n,pen:e,anchor:t}),!0}function Ye(e,t){if(e&&t)return e.calculative.worldAnchors?.find((e=>e.id===t))}function $e(e){if(e&&e.calculative.worldAnchors)return e.calculative.worldAnchors[0]}function Xe(e){if(e&&e.calculative.worldAnchors)return e.calculative.worldAnchors[e.calculative.worldAnchors.length-1]}function Ge(e,t){if(0===e.calculative.start||!e.frames||!e.frames.length)return e.calculative.start=void 0,0;if(!e.calculative.duration){e.calculative.duration=0;for(const t of e.frames){e.calculative.duration+=t.duration;for(const i in t)"duration"===i||e[i]||"scale"===i&&(e[i]=1)}}if(e.animateCycle||(e.animateCycle=1/0),e.calculative.start){let i=0;const n=Math.ceil((t-e.calculative.start)/e.calculative.duration);if(n>e.animateCycle)return e.currentAnimation=void 0,e.calculative.start=void 0,Je(e,1),0;const r=(t-e.calculative.start)%e.calculative.duration;let o=0;for(const t of e.frames){if(o+=t.duration,!(r>o))break;++i}if(!e.frames[i])return!0;e.calculative.frameDuration=e.frames[i].duration,e.calculative.frameStart=e.calculative.start+e.calculative.duration*(n-1),e.calculative.frameEnd=e.calculative.frameStart+e.calculative.frameDuration;const s=i!==e.calculative.frameIndex,a=n>e.calculative.cycleIndex;if(s&&(e.calculative.frameIndex=i),a&&(e.calculative.cycleIndex=n),s||a)if(e.calculative.x=e.calculative.initRect.x,e.calculative.y=e.calculative.initRect.y,e.calculative.rotate=e.calculative.initRect.rotate||0,i>0){e.prevFrame={};const t=e.frames[i-1];for(const i in t)e.prevFrame[i]=t[i];Object.assign(e.prevFrame,{rotate:t.rotate||0,x:t.x||0,y:t.y||0,scale:t.scale||1})}else Qe(e)}else e.calculative.start=t,e.calculative.frameIndex=0,e.calculative.frameStart=e.calculative.start,e.calculative.frameDuration=e.frames[0].duration,e.calculative.frameEnd=e.calculative.frameStart+e.calculative.frameDuration,e.calculative.cycleIndex=1,e.calculative.x=e.calculative.worldRect.x,e.calculative.y=e.calculative.worldRect.y,e.calculative.initRect=$(e.calculative.worldRect),e.calculative.initRect.rotate=e.calculative.rotate||0,Qe(e);return Je(e,(t-e.calculative.frameStart)/e.calculative.frameDuration%1),!0}function Qe(e){e.prevFrame={};for(const t in e)"object"==typeof e[t]&&"lineDash"!==t||(e.prevFrame[t]=e[t]);e.prevFrame.rotate=0,e.prevFrame.x=0,e.prevFrame.y=0,e.prevFrame.scale=1}function Je(e,t){if(t<0)return;t>1&&(t=1);const i=e.frames[e.calculative.frameIndex];for(const n in i)if("duration"!==n){if("scale"===n){e.calculative.worldRect=$(e.calculative.initRect),Mt(e.calculative.worldRect,e.prevFrame.scale,e.calculative.worldRect.center);const r=e.prevFrame.scale+(i[n]-e.prevFrame.scale)*t;Mt(e.calculative.worldRect,r/e.prevFrame.scale,e.calculative.worldRect.center),e.calculative.patchFlags=!0}else if("x"===n){const r=ct(e,n,e.calculative.frameIndex);e.calculative.worldRect.x=e.calculative.initRect.x+r,e.calculative.worldRect.ex=e.calculative.initRect.ex+r,Rt(e.calculative.worldRect,i[n]*t*e.calculative.canvas.store.data.scale,0),e.calculative.patchFlags=!0}else if("y"===n){const r=ct(e,n,e.calculative.frameIndex);e.calculative.worldRect.y=e.calculative.initRect.y+r,e.calculative.worldRect.ey=e.calculative.initRect.ey+r,Rt(e.calculative.worldRect,0,i[n]*t*e.calculative.canvas.store.data.scale),e.calculative.patchFlags=!0}else if("rotate"===n){e.prevFrame[n]>=360&&(e.prevFrame[n]%=360);const r=ct(e,n,e.calculative.frameIndex),o=(e.calculative.initRect.rotate+r+i[n]*t)%360-e.calculative.rotate;e.children?.length?e.calculative.canvas.rotatePen(e,o,e.calculative.initRect):e.calculative.rotate=(e.calculative.initRect.rotate+r+i[n]*t)%360,e.calculative.patchFlags=!0}else if("image"===n)e.image=i.image,e.calculative.image=void 0,e.calculative.canvas.loadImage(e),e.isBottom?e.calculative.canvas.canvasImageBottom.init():e.calculative.canvas.canvasImage.init();else if(Ze(i[n],n,e)){null==e.prevFrame[n]&&(e.prevFrame[n]="globalAlpha"===n?1:0);const r=e.prevFrame[n]+(i[n]-e.prevFrame[n])*t;e.calculative[n]=Math.round(100*r)/100}else{"visible"===n&&e.calculative.image&&(e.isBottom?e.calculative.canvas.canvasImageBottom.init():e.calculative.canvas.canvasImage.init()),e.calculative[n]=i[n];const t={};t[n]=i[n],ft(e,t)}"text"===n&&V(e)}}function Ze(e,t,i){return"number"==typeof e&&!1!==i.linear&&!["strokeType","bkType","showChild"].includes(t)}function et(e,t){if(0===e.calculative.start)return e.calculative.start=void 0,0;if(e.animateCycle||(e.animateCycle=1/0),e.animateSpan||(e.animateSpan=1),e.calculative.animatePos+=e.animateSpan*(e.calculative.canvas.store.data.scale||1),e.calculative.start){if(e.calculative.animatePos>e.length){if(++e.calculative.cycleIndex,e.calculative.cycleIndex>e.animateCycle)return e.currentAnimation=void 0,e.calculative.start=void 0,0;e.calculative.animatePos=e.animateSpan}}else e.calculative.start=Date.now(),e.calculative.animatePos=e.animateSpan*(e.calculative.canvas.store.data.scale||1),e.calculative.cycleIndex=1;return!0}function tt(e,t=!0){if(!e.children)return;const i=e.calculative.canvas.store;e.children.forEach((e=>{const n=i.pens[e];n&&(n.calculative.active=t,tt(n,t))}))}function it(e,t=!0){if(!e)return;const i=e.calculative.canvas.store;e.calculative.hover=t,e.children&&e.children.forEach((e=>{null==i.pens[e]?.hoverColor&&null==i.pens[e]?.hoverBackground&&it(i.pens[e],t)}))}function nt(e,t){if(!t)return;const i=e.calculative.canvas.store,n=e.calculative.worldRect;t.style.opacity=e.globalAlpha+"",t.style.position="absolute",t.style.outline="none",t.style.left=n.x+i.data.x+"px",t.style.top=n.y+i.data.y+"px",t.style.width=n.width+"px",t.style.height=n.height+"px",t.style.display=0!=e.calculative.inView?e.calculative.cssDisplay||"inline":"none",!e.calculative.rotate&&(e.calculative.rotate=0),t.style.transform=`rotate(${e.calculative.rotate}deg)`,e.calculative.rotate||(e.calculative.flipX&&(t.style.transform="rotateY(180deg)"),e.calculative.flipY&&(t.style.transform="rotateX(180deg)"),e.calculative.flipX&&e.calculative.flipY&&(t.style.transform="rotateZ(180deg)")),t.style.zIndex=void 0!==e.calculative.zIndex?e.calculative.zIndex+"":"4",e.calculative.zIndex>e.calculative.canvas.maxZindex&&(e.calculative.canvas.maxZindex=e.calculative.zIndex),e.locked===o.DisableEdit||e.locked===o.DisableMove||i.data.locked?(t.style.userSelect="initial",t.style.pointerEvents="initial","gif"===e.name&&(t.style.userSelect="none",t.style.pointerEvents="none")):(t.style.userSelect="none",t.style.pointerEvents="none")}function rt(e){return e.every((e=>e.locked))}function ot(e){return e.every((e=>e.disableRotate))}function st(e,t,i){e.type?(e.calculative.worldAnchors.forEach((e=>{S(e,t,i.center)})),function(e){if(!e.calculative.worldAnchors?.length)return;if(!isFinite(e.x)||!isFinite(e.x))return;if(null==e.x||null==e.y)return;const t=ti(e);e.parentId||Object.assign(e,t);const{fontSize:i,lineHeight:n}=e.calculative.canvas.store.options;e.fontSize||(e.fontSize=i,e.calculative.fontSize=e.fontSize*e.calculative.canvas.store.data.scale),e.lineHeight||(e.lineHeight=n,e.calculative.lineHeight=e.lineHeight),Tt(t),e.calculative.worldRect=t,Be(e,t),U(e),e.calculative.worldAnchors&&(e.anchors=e.calculative.worldAnchors.map((t=>Nt(t,e.calculative.worldRect))))}(e),Fe(e)):(e.calculative.rotate?e.calculative.rotate+=t:e.calculative.rotate=t,S(e.calculative.worldRect.center,t,i.center),e.parentId&&(e.calculative.worldRect.x=e.calculative.worldRect.center.x-e.calculative.worldRect.width/2,e.calculative.worldRect.y=e.calculative.worldRect.center.y-e.calculative.worldRect.height/2,e.x=(e.calculative.worldRect.x-i.x)/i.width,e.y=(e.calculative.worldRect.y-i.y)/i.height)),e.children?.forEach((n=>{st(e.calculative.canvas.store.pens[n],t,i)}))}function at(e){return e.every((e=>e.disableSize))}function ct(e,t,i){if(!e.frames||!t)return 0;let n=0;for(let r=0;r<i;r++)e.frames[r]&&(n+=e.frames[r][t]||0);return n}function lt(e,t){let i=e;for(;i&&i.parentId;){const e=i;i=t.pens[i.parentId];const n=i?.calculative?.showChild;if(null!=n&&i.children[n]!==e.id)return!1}return!0}function ht(e,t=!1){const{store:i,canvasRect:n}=e.calculative.canvas;if(t&&e.children?.forEach((e=>{const t=i.pens[e];t&&ht(t,!0)})),e.calculative.inView=!0,lt(e,i)&&0!=e.visible&&0!=e.calculative.visible){const{x:t,y:r,width:o,height:s,rotate:a}=e.calculative.worldRect,c={x:t+i.data.x,y:r+i.data.y,width:o,height:s,rotate:a};At(c),Et(c,n)||(e.calculative.inView=!1)}else e.calculative.inView=!1;e.onMove?.(e)}function ut(e,t){const i=t.calculative.globalAlpha;(i<1||""!==i)&&(e.globalAlpha=i)}function dt(e,t){const i=N.canvasDraws[t.name];i&&(e.save(),i(e,t),e.restore())}function ft(e,t){for(const i in t)_.includes(i)&&(e[i]=t[i],"fontSize"===i?(e.calculative[i]=t[i]*e.calculative.canvas.store.data.scale,U(e)):e.calculative[i]=t[i]);if(e.calculative.canvas.parent.isCombine(e)&&void 0===e.showChild){const i=e.children;i?.forEach((i=>{const n=e.calculative.canvas.store.pens[i];n&&ft(n,t)}))}}function pt(e,t,i){let n,r,o=1/0,s=1/0;for(const a of e.data.pens)!1!==a.calculative.inView&&xt(a).forEach((e=>{if(e===t||e===i)return;let c=(a.calculative.worldRect.center.x-t.x)*(a.calculative.worldRect.center.x-t.x)+(a.calculative.worldRect.center.y-t.y)*(a.calculative.worldRect.center.y-t.y);const l=Math.abs(e.x-t.x);l>0&&l<8&&c<o&&(n={x:Math.round(e.x)+.5,y:Math.round(e.y)+.5,prev:{x:Math.round(t.x)+.5,y:Math.round(t.y)+.5},step:e.x-t.x},o=c);const h=Math.abs(e.y-t.y);h>0&&h<8&&c<s&&(r={x:Math.round(e.x)+.5,y:Math.round(e.y)+.5,prev:{x:Math.round(t.x)+.5,y:Math.round(t.y)+.5},step:e.y-t.y},s=c)}));return{xDock:n,yDock:r}}function vt(e,t,i,n){let r=[];return 1===i.length?(r=$(xt(i[0])),r.forEach((e=>{e.x+=n.x,e.y+=n.y}))):(Tt(t),r=[t.center,...Pt(t)]),yt(e,r,t,!0)}function xt(e){if(!e.type){const t=Pt(e.calculative.worldRect);return Tt(e.calculative.worldRect),[...e.calculative.worldAnchors,...t,e.calculative.worldRect.center]}if(e.type===r.Line)return e.calculative.worldAnchors}function gt(e,t,i,n){return yt(e,Pt(t),t)}function yt(e,t,i,n=!1){let r,o,s=1/0,a=1/0;const c=function(e,t){const i=re(10),n={x:e.x-i[3],y:e.y-i[0],width:e.width+i[1]+i[3],height:e.height+i[0]+i[2]};return At(n),n}(i);return e.data.pens.forEach((l=>{const{inView:h,worldRect:u,active:d}=l.calculative;if(!1===h||!n&&d||(f=c,((p=u).x>f.ex||p.ex<f.x)&&(p.y>f.ey||p.ey<f.y))||l.type&&e.active.some((t=>mt(e,t,l))))return;var f,p;const v=xt(l);if(v)for(const e of v)for(const n of t){const t=e.x-n.x,c=e.y-n.y,h=Math.abs(t),u=Math.abs(c);i.center||(i.center={x:i.x+i.width/2,y:i.y+i.height/2}),h<10&&h<s&&(r={x:Math.round(e.x)+.5,y:Math.round(e.y)+.5,step:t,prev:{x:Math.round(n.x)+.5,y:Math.round(n.y)+.5},penId:l.id,anchorId:n.id,dockAnchorId:e.id},s=h),u<10&&u<a&&(o={x:Math.round(e.x)+.5,y:Math.round(e.y)+.5,step:c,prev:{x:Math.round(n.x)+.5,y:Math.round(n.y)+.5},penId:l.id,anchorId:n.id,dockAnchorId:e.id},a=u)}})),{xDock:r,yDock:o}}function mt(e,t,i){if(!i.type)return!1;if(Array.isArray(t?.connectedLines))for(const e of t?.connectedLines)if(e.lineId===i.id)return!0;if(Array.isArray(t?.children))for(const n of t.children)if(mt(e,e.pens[n],i))return!0;return!1}function bt(e,t){return e.toFixed(12)==t}function wt(e){if(e.id=ne(),Array.isArray(e.anchors))for(const t of e.anchors)e.type&&(t.id=ne()),t.penId=e.id,t.prev&&(e.type&&(t.prev.id=ne()),t.prev.penId=e.id),t.next&&(e.type&&(t.next.id=ne()),t.next.penId=e.id)}function _t(e,t){if(!t)return;if(null==t.ex&&At(t),!t.rotate||t.rotate%360==0)return e.x>t.x&&e.x<t.ex&&e.y>t.y&&e.y<t.ey;t.center||Tt(t);const i=[{x:t.x,y:t.y},{x:t.ex,y:t.y},{x:t.ex,y:t.ey},{x:t.x,y:t.ey}];return i.forEach((e=>{S(e,t.rotate,t.center)})),function(e,t){if(t.length<3)return!1;let i=!1,n=t[t.length-1];for(const r of t)n.y>e.y!=r.y>e.y&&r.x+(e.y-r.y)*(n.x-r.x)/(n.y-r.y)>e.x&&(i=!i),n=r;return i}(e,i)}function kt(e,t,i=0){const{x:n,y:r,ex:o,ey:s}=t;return e.x>=n-i&&e.x<=o+i&&e.y>=r-i&&e.y<=s+i}function Tt(e){e.center||(e.center={}),e.center.x=e.x+e.width/2,e.center.y=e.y+e.height/2}function At(e){e.ex=e.x+e.width,e.ey=e.y+e.height}function St(e){const t=[];e.forEach((e=>{if(e.isRuleLine)return;const i=e.calculative.worldRect;if(i){const e=Pt(i);t.push(...e)}}));const i=Ct(t);return Tt(i),i}function Pt(e){const t=[{x:e.x,y:e.y},{x:e.ex,y:e.y},{x:e.ex,y:e.ey},{x:e.x,y:e.ey}];return e.rotate&&(e.center||Tt(e),t.forEach((t=>{S(t,e.rotate,e.center)}))),t}function Ct(e){let t=1/0,i=1/0,n=-1/0,r=-1/0;return e?.forEach((e=>{isFinite(e.x)&&isFinite(e.y)&&(t=Math.min(t,e.x),i=Math.min(i,e.y),n=Math.max(n,e.x),r=Math.max(r,e.y))})),{x:t,y:i,ex:n,ey:r,width:n-t,height:r-i}}function Et(e,t,i){return e.rotate&&(e=Ct(Pt(e))),i?e.x>t.x&&e.ex<t.ex&&e.y>t.y&&e.ey<t.ey:!(e.x>t.ex||e.ex<t.x||e.ey<t.y||e.y>t.ey)}function Rt(e,t,i){e.x+=t,e.y+=i,e.ex+=t,e.ey+=i,e.center&&(e.center.x+=t,e.center.y+=i)}function It(e,t){if(bt(e.k,0))return{x:t.point.x,y:e.point.y};if(bt(t.k,0))return{x:e.point.x,y:t.point.y};const i=e.point.y-e.k*e.point.x,n=(t.point.y-t.k*t.point.x-i)/(e.k-t.k);return{x:n,y:e.k*n+i}}function Lt(e,t,i,n){if(e.rotate&&e.rotate%360){const r=Pt(e),o=(r[0].y-r[1].y)/(r[0].x-r[1].x),s=(r[1].y-r[2].y)/(r[1].x-r[2].x);if(n<4){r[n].x+=t,r[n].y+=i;const e=r[(n+2)%4];r[(n+1)%4]=It({k:n%2?s:o,point:r[n]},{k:n%2?o:s,point:e}),r[(n+4-1)%4]=It({k:n%2?o:s,point:r[n]},{k:n%2?s:o,point:e})}else{const e=[4,6].includes(n)?s:o;bt(e,0)?(r[n%4].x+=t,r[(n+1)%4].x+=t):(r[n%4].y+=i,r[n%4].x+=i/e,r[(n+1)%4].y+=i,r[(n+1)%4].x+=i/e)}if((r[0].x-r[1].x)**2+(r[0].y-r[1].y)**2<25||(r[1].x-r[2].x)**2+(r[1].y-r[2].y)**2<25)return;const a=function(e,t){const i=function(e,t){const i=(e.to.y-e.from.y)/(e.to.x-e.from.x),n=(t.to.y-t.from.y)/(t.to.x-t.from.x);return It({k:i,point:e.from},{k:n,point:t.from})}({from:e[0],to:e[2]},{from:e[1],to:e[3]});for(const n of e)S(n,-t,i);return Ct(e)}(r,e.rotate);return Tt(a),void Object.assign(e,a)}switch(n){case 0:if(e.width-t<5||e.height-i<5)break;e.x+=t,e.y+=i,e.width-=t,e.height-=i;break;case 1:if(e.width+t<5||e.height-i<5)break;e.ex+=t,e.y+=i,e.width+=t,e.height-=i;break;case 2:if(e.width+t<5||e.height+i<5)break;e.ex+=t,e.ey+=i,e.width+=t,e.height+=i;break;case 3:if(e.width-t<5||e.height+i<5)break;e.x+=t,e.ey+=i,e.width-=t,e.height+=i;break;case 4:if(e.height-i<5)break;e.y+=i,e.height-=i;break;case 5:if(e.width+t<5)break;e.ex+=t,e.width+=t;break;case 6:if(e.height+i<5)break;e.ey+=i,e.height+=i;break;case 7:if(e.width-t<5)break;e.x+=t,e.width-=t}}function Mt(e,t,i){e&&(e.width*=t,e.height*=t,C(e,t,i),At(e),Tt(e))}function Dt(e,t){const i={x:(e.x-t.x)/t.width,y:(e.y-t.y)/t.height,width:e.width/t.width,height:e.height/t.height};return At(i),i}function Nt(e,t){const{x:i,y:n,width:r,height:o}=t,{penId:s,connectTo:a}=e,c=Object.assign({},e,{x:r?(e.x-i)/r:0,y:o?(e.y-n)/o:0});return e.prev&&(c.prev={penId:s,connectTo:a,x:r?(e.prev.x-i)/r:0,y:o?(e.prev.y-n)/o:0}),e.next&&(c.next={penId:s,connectTo:a,x:r?(e.next.x-i)/r:0,y:o?(e.next.y-n)/o:0}),c}const Ot=/^[\t\n\f\r ]*([MLHVZCSQTAmlhvzcsqta])[\t\n\f\r ]*/,Bt=/^[01]/,Ft=/^[+-]?(([0-9]*\.[0-9]+)|([0-9]+\.)|([0-9]+))([eE][+-]?[0-9]+)?/,zt=/^(([\t\n\f\r ]+,?[\t\n\f\r ]*)|(,[\t\n\f\r ]*))/,jt={M:[Ft,Ft],L:[Ft,Ft],H:[Ft],V:[Ft],Z:[],C:[Ft,Ft,Ft,Ft,Ft,Ft],S:[Ft,Ft,Ft,Ft],Q:[Ft,Ft,Ft,Ft],T:[Ft,Ft],A:[Ft,Ft,Ft,Bt,Bt,Ft,Ft]};function Ht(e){let t=1/0,i=1/0,n=-1/0,r=-1/0;return function(e){let t,i=0,n=0;e.commands.forEach((e=>{switch(e.key){case"Z":case"z":e.worldPoints=[i,n];break;case"H":e.worldPoints=[e.values[0],t.worldPoints[t.worldPoints.length-1]];break;case"h":e.worldPoints=[e.values[0]+t.worldPoints[t.worldPoints.length-2],t.worldPoints[t.worldPoints.length-1]];break;case"V":e.worldPoints=[t.worldPoints[t.worldPoints.length-2],e.values[0]];break;case"v":case"A":e.worldPoints=[t.worldPoints[t.worldPoints.length-2],e.values[0]+t.worldPoints[t.worldPoints.length-1]];break;default:!function(e,t){const i=[];let n=e.relative&&t?{x:t.worldPoints[t.worldPoints.length-2],y:t.worldPoints[t.worldPoints.length-1]}:{x:0,y:0};for(let t=0;t<e.values.length-1;t+=2)i.push(n.x+e.values[t]),i.push(n.y+e.values[t+1]);e.worldPoints=i}(e,t)}"M"!==e.key&&"m"!==e.key&&"Z"!==e.key&&"z"!==e.key||(i=e.worldPoints[e.worldPoints.length-2],n=e.worldPoints[e.worldPoints.length-1]),t=e}))}(e),e.commands.forEach((e=>{e.worldPoints.forEach(((e,o)=>{o%2==0?(e<t&&(t=e),e>n&&(n=e)):(e<i&&(i=e),e>r&&(r=e))}))})),--t,--i,{x:t,y:i,ex:n,ey:r,width:n-t+1,height:r-i+1}}function Ut(e,t,i){const n=jt[e.toUpperCase()],r=[];for(;i<=t.length;){const o={key:e,values:[]};for(const e of n){const n=t.slice(i).match(e);if(null===n){if(0===o.values.length)return{cursor:i,commands:r};throw new Error("malformed path (first error at "+i+")")}{o.values.push(+n[0]),i+=n[0].length;const e=t.slice(i).match(zt);null!==e&&(i+=e[0].length)}}if(o.relative=o.key.toUpperCase()!==o.key,r.push(o),0===n.length)return{cursor:i,commands:r};"m"===e&&(e="l"),"M"===e&&(e="L")}throw new Error("malformed path (first error at "+i+")")}function Wt(e,t){const i=e.calculative.canvas.store.data.paths[e.pathId];if(!i)return new Path2D;const n=function(e){let t=0;const i=[];for(;t<e.length;){const n=e.slice(t).match(Ot);if(null===n)throw new Error("malformed path (first error at "+t+")");{const r=n[1];t+=n[0].length;const o=Ut(r,e,t);t=o.cursor,i.push(...o.commands)}}return{commands:i}}(i);e.calculative.svgRect=Ht(n),Tt(e.calculative.svgRect),e.calculative.svgRect.width===e.calculative.worldRect.width&&e.calculative.svgRect.height===e.calculative.worldRect.height||function(e,t,i){null==i&&(i=t),e.commands.forEach((e=>{switch(e.key){case"A":case"a":const n=e.values[0],r=e.values[1],o=Math.PI*e.values[2]/180,s=Math.cos(o),a=Math.sin(o),c=r*r*i*i*s*s+n*n*i*i*a*a,l=2*t*i*s*a*(r*r-n*n),h=n*n*t*t*s*s+r*r*t*t*a*a,u=-n*n*r*r*t*t*i*i,d=l*l-4*c*h,f=Math.sqrt((c-h)*(c-h)+l*l);e.values[2]=0!==l?180*Math.atan((h-c-f)/l)/Math.PI:c<h?0:90,e.values[0]=-Math.sqrt(2*d*u*(c+h+f))/d,e.values[1]=-Math.sqrt(2*d*u*(c+h-f))/d,e.values[5]*=t,e.values[6]*=i,e.values[4]=t*i>=0?e.values[4]:1-e.values[4];break;case"V":case"v":e.values[0]*=i;break;default:e.values.forEach(((n,r)=>{e.values[r]=n*(r%2==0?t:i)}))}}))}(n,e.calculative.worldRect.width/e.calculative.svgRect.width,e.calculative.worldRect.height/e.calculative.svgRect.height);const r=Ht(n);Tt(r),function(e,t,i){null==i&&(i=t),e.commands.forEach(((e,n)=>{if(!e.relative||!n)switch(e.key){case"A":case"a":e.values[5]+=t,e.values[6]+=i;break;case"V":case"v":e.values[0]+=i;break;default:e.values.forEach(((n,r)=>{e.values[r]=n+(r%2==0?t:i)}))}}))}(n,e.calculative.worldRect.x-r.x,e.calculative.worldRect.y-r.y);const o=function(e){let t="";return e.commands.forEach((e=>{t+=e.key+" ",e.values.forEach((e=>{t+=e+" "}))})),t}(n);if(!t)return new Path2D(o);t.svgPath?.(o)}function Vt(e,t){const{x:i,y:n,width:r,ex:o,ey:s}=t.calculative.worldRect;let a=.25*r;const c=t.z;c>1?a=c:c>0&&(a=r*c);const l={x:i,y:n+a},h={x:o-a,y:n+a},u={x:o-a,y:s};qt(e,[l,h,u,{x:i,y:s}],t.backgroundFront||t.background,t.color),qt(e,[l,{x:i+a,y:n},{x:o,y:n},h],t.backgroundUp||t.background,t.color),qt(e,[h,{x:o,y:n},{x:o,y:s-a},u],t.backgroundRight||t.background,t.color)}function qt(e,t,i="",n=""){e.save(),i&&(e.fillStyle=i),n&&(e.strokeStyle=n),e.beginPath();for(let i=0;i<t.length;++i)i?e.lineTo(t[i].x,t[i].y):e.moveTo(t[i].x,t[i].y);e.closePath(),i&&e.fill(),e.stroke(),e.restore()}function Kt(e,t,i){if(t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),i)t.calculative.activeAnchor&&(t.calculative.activeAnchor.next={penId:t.id,x:i.x,y:i.y},R(t.calculative.activeAnchor.next,t.calculative.activeAnchor)<5?t.calculative.activeAnchor.next=void 0:(t.calculative.activeAnchor.prev={...t.calculative.activeAnchor.next},S(t.calculative.activeAnchor.prev,180,t.calculative.activeAnchor)));else{const i=t.calculative.worldAnchors[0];i.next||(Yt(i,Ue(i,e.pens[i.connectTo]),50),i.prev=void 0);const n=t.calculative.worldAnchors[t.calculative.worldAnchors.length-1];n&&n!==i&&!n.prev&&(Yt(n,Ue(n,e.pens[n.connectTo]),-50),n.next=void 0)}}function Yt(e,t,i){switch(t){case y.Up:e.prev={penId:e.penId,x:e.x,y:e.y+i},e.next={penId:e.penId,x:e.x,y:e.y-i};break;case y.Right:e.prev={penId:e.penId,x:e.x-i,y:e.y},e.next={penId:e.penId,x:e.x+i,y:e.y};break;case y.Bottom:e.prev={penId:e.penId,x:e.x,y:e.y-i},e.next={penId:e.penId,x:e.x,y:e.y+i};break;case y.Left:e.prev={penId:e.penId,x:e.x+i,y:e.y},e.next={penId:e.penId,x:e.x-i,y:e.y}}}function $t(e,t,i,n){const r=1-e;return{x:r*r*t.x+2*r*e*i.x+e*e*n.x,y:r*r*t.y+2*r*e*i.y+e*e*n.y,step:e}}function Xt(e,t,i,n,r){const{x:o,y:s}=t,{x:a,y:c}=r,{x:l,y:h}=i,{x:u,y:d}=n,f=1-e;return{x:o*f*f*f+3*l*e*f*f+3*u*e*e*f+a*e*e*e,y:s*f*f*f+3*h*e*f*f+3*d*e*e*f+c*e*e*e,step:e}}function Gt(e,t,i){return{x:e.x+i*(t.x-e.x),y:e.y+i*(t.y-e.y)}}function Qt(e,t,i){if(t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),t.calculative.worldAnchors.length<2)return;let n=t.calculative.activeAnchor,r=i||Xe(t);if(!n||!r)return;let o=Ue(n,e.pens[n.connectTo]);switch(o===y.None&&(o=r.x>n.x?y.Right:y.Left),n.next={id:ne(),penId:t.id,x:n.x,y:n.y,prevNextType:2},r.prev={id:ne(),penId:t.id,x:r.x,y:r.y,prevNextType:2},o){case y.Up:n.next.y-=20,r.prev.y=n.y;break;case y.Bottom:n.next.y+=20,r.prev.y=n.y;break;case y.Left:n.next.x-=20,r.prev.x=n.x;break;default:n.next.x+=20,r.prev.x=n.x}}function Jt(e,t){const i=t||new Path2D,n=e.calculative.worldAnchors;if(n.length>1){let t;n.forEach((e=>{t?ei(i,t,e):e.start=!0,t=e})),e.close&&ei(i,t,n[0])}if(i instanceof Path2D)return i}function Zt(e,t,i){if(t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),t.calculative.worldAnchors.length<2||t.anchors?.length>1)return;const n=$e(t),r=Xe(t);n&&r&&r.id&&n!==r&&(n.next=void 0,Ve(t),r.prev=void 0,t.calculative.worldAnchors.push(r))}function ei(e,t,i){i&&!i.isTemp&&(t.start&&e.moveTo(t.x,t.y),t.next?i.prev?e.bezierCurveTo(t.next.x,t.next.y,i.prev.x,i.prev.y,i.x,i.y):e.quadraticCurveTo(t.next.x,t.next.y,i.x,i.y):i.prev?e.quadraticCurveTo(i.prev.x,i.prev.y,i.x,i.y):e.lineTo(i.x,i.y))}function ti(e){return ai(e),Ct(function(e){const t=[];let i;return e.calculative.worldAnchors.forEach((n=>{t.push(n),i&&t.push(...ni(i,n,e)),i=n})),e.close&&e.calculative.worldAnchors.length>1&&t.push(...ni(i,e.calculative.worldAnchors[0],e)),t}(e))}function ii(e){return e?.lineWidth?e.lineWidth/2+4:4}function ni(e,t,i){const n=[];if(!t)return n;let r=.02;if(e.lineLength&&(r=ii(i)/e.lineLength),e.next)if(t.prev)for(let i=r;i<1;i+=r)n.push(Xt(i,e,e.next,t.prev,t));else for(let i=r;i<1;i+=r)n.push($t(i,e,e.next,t));else if(t.prev)for(let i=r;i<1;i+=r)n.push($t(i,e,t.prev,t));else n.push({x:t.x,y:t.y});return n.length>1&&(e.curvePoints=n),n}function ri(e,t){const i=ii(t);let n,r,o=0;for(const s of t.calculative.worldAnchors){if(n){if(r=oi(e,n,s,i),r)return{i:o,point:r};++o}n=s}if(t.close&&t.calculative.worldAnchors.length>1&&(r=oi(e,n,t.calculative.worldAnchors[0],i)))return{i:o,point:r}}function oi(e,t,i,n=4){if(!t.next&&!i.prev){const{x:r,y:o}=t,{x:s,y:a}=i,c=Math.min(r,s),l=Math.max(r,s),h=Math.min(o,a),u=Math.max(o,a);if(!(e.x>=c-n&&e.x<=l+n&&e.y>=h-n&&e.y<=u+n))return;return function(e,t,i,n=4){if(t.x===i.x){if(Math.abs(e.x-t.x)<=n)return{x:t.x,y:e.y}}else{const r=(t.y-i.y)/(t.x-i.x),o=t.y-r*t.x;if(Math.abs((r*e.x+o-e.y)/Math.sqrt(r*r+1))<=n){const t=(e.x+r*e.y-r*o)/(r*r+1);return{x:t,y:r*t+o}}}}(e,t,i,n)}if(t.curvePoints)for(const i of t.curvePoints)if(P(e,i,n))return i}function si(e,t,i,n){if(!t&&!i)return Math.sqrt(Math.pow(Math.abs(e.x-n.x),2)+Math.pow(Math.abs(e.y-n.y),2))||0;const r=document.createElementNS("http://www.w3.org/2000/svg","path");return t&&i?r.setAttribute("d",`M${e.x} ${e.y} C${t.x} ${t.y} ${i.x} ${i.y} ${n.x} ${n.y}`):t?r.setAttribute("d",`M${e.x} ${e.y} Q${t.x} ${t.y} ${n.x} ${n.y}`):r.setAttribute("d",`M${e.x} ${e.y} Q${i.x} ${i.y} ${n.x} ${n.y}`),r.getTotalLength()||0}function ai(e){if(e.calculative.worldAnchors.length<2)return 0;let t,i=0;if(e.calculative.worldAnchors.forEach((e=>{t&&(t.lineLength=si(t,t.next,e.prev,e),i+=t.lineLength),t=e})),e.close){const n=$e(e);t.lineLength=si(t,t.next,n.prev,n),i+=t.lineLength}return e.length=i,i}function ci(e,t,i){if(kt(e,i)||kt(t,i))return!0;const n=e.x,r=e.y,o=t.x,s=t.y;let a=i.x,c=i.y,l=i.ex,h=i.ey;const u=r-s,d=o-n,f=n*s-o*r;if(u*a+d*c+f>=0&&u*l+d*h+f<=0||u*a+d*c+f<=0&&u*l+d*h+f>=0||u*a+d*h+f>=0&&u*l+d*c+f<=0||u*a+d*h+f<=0&&u*l+d*c+f>=0){if(a>l){const e=a;a=l,l=e}if(c<h){const e=c;c=h,h=e}return!(n<a&&o<a||n>l&&o>l||r>c&&s>c||r<h&&s<h)}return!1}function li(e,t,i){const n=.02;if(!e.next&&!t.prev)return ci(e,t,i);if(e.next&&t.prev){for(let r=n;r<1;r+=n)if(kt(Xt(r,e,e.next,t.prev,t),i))return!0}else if(e.next||t.prev)for(let r=n;r<1;r+=n)if(kt($t(r,e,e.next||t.prev,t),i))return!0;return!1}let hi=10;function ui(e,t,i){if(t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),hi=e.options.polylineSpace||10,t.calculative.worldAnchors.length<2)return;let n,r=$e(t),o=Xe(t);if(!r||!o)return;if(t.anchors?.length&&r===t.calculative.activeAnchor?(n=!0,r=o,o=$e(t)):t.anchors&&t.anchors.length||r===t.calculative.activeAnchor||(r=t.calculative.activeAnchor),!r||!o)return;r.next=void 0,o.prev=void 0;const s=o.connectTo;Ve(t);const a=[],c=e.pens[r.connectTo],l=e.pens[o.connectTo],h=Ue(r,c),u=Ue(o,l);let d=di(r,h,hi);d&&(r=d,a.push(d)),d=di(o,u,hi);const f=o;switch(d&&(o=d),h){case y.Up:a.push(...function(e,t,i){if(e.x===t.x||e.y===t.y)return[];const n=[];let r,o;switch(i){case y.Up:e.y<t.y?(r=t.x,o=e.y):(r=e.x,o=t.y),n.push({x:r,y:o});break;case y.Bottom:if(r=t.x,o=e.y,t.y>e.y)r=e.x+(t.x-e.x)/2,n.push({x:r,y:e.y},{x:r,y:t.y});else{const i=(e.y+t.y)/2;n.push({x:e.x,y:i},{x:t.x,y:i})}break;case y.Right:r=t.x,o=e.y,t.x<e.x&&t.y<e.y&&(r=e.x,o=t.y),n.push({x:r,y:o});break;case y.Left:r=t.x,o=e.y,t.x>e.x&&t.y<e.y&&(r=e.x,o=t.y),n.push({x:r,y:o});break;default:if(t.y>e.y-hi)r=e.x+(t.x-e.x)/2,n.push({x:r,y:e.y},{x:r,y:t.y});else{const i=(e.y+t.y+hi)/2;n.push({x:e.x,y:i},{x:t.x,y:i})}}return n}(r,o,u));break;case y.Right:a.push(...function(e,t,i){if(e.x===t.x||e.y===t.y)return[];const n=[];let r,o;switch(i){case y.Up:r=e.x,o=t.y,t.x>e.x&&t.y>e.y&&(r=t.x,o=e.y),n.push({x:r,y:o});break;case y.Bottom:r=e.x,o=t.y,t.x>e.x&&t.y<e.y&&(r=t.x,o=e.y),n.push({x:r,y:o});break;case y.Left:if(r=t.x,o=e.y,t.x<e.x)o=e.y+(t.y-e.y)/2,n.push({x:e.x,y:o},{x:t.x,y:o});else{const i=(e.x+t.x)/2;n.push({x:i,y:o},{x:i,y:t.y})}break;case y.Right:t.x<e.x?n.push({x:e.x,y:t.y}):n.push({x:t.x,y:e.y});break;default:if(r=t.x,o=t.y,t.x<e.x+hi)n.push({x:e.x,y:o});else{const i=(e.x+t.x-hi)/2;n.push({x:i,y:e.y},{x:i,y:o})}}return n}(r,o,u));break;case y.Bottom:a.push(...function(e,t,i){if(e.x===t.x||e.y===t.y)return[];const n=[];let r,o;switch(i){case y.Up:if(r=e.x,o=t.y,t.y<e.y)r=e.x+(t.x-e.x)/2,n.push({x:r,y:e.y},{x:r,y:t.y});else{const i=(e.y+t.y)/2;n.push({x:r,y:i},{x:t.x,y:i})}break;case y.Right:r=t.x,o=e.y,t.x<e.x&&t.y>e.y&&(r=e.x,o=t.y),n.push({x:r,y:o});break;case y.Bottom:e.y>t.y?(r=t.x,o=e.y):(r=e.x,o=t.y),n.push({x:r,y:o});break;case y.Left:r=t.x,o=e.y,t.x>e.x&&t.y>e.y&&(r=e.x,o=t.y),n.push({x:r,y:o});break;default:if(r=e.x,t.y<e.y+hi)r=e.x+(t.x-e.x)/2,n.push({x:r,y:e.y},{x:r,y:t.y});else{const i=(e.y+t.y-hi)/2;n.push({x:r,y:i},{x:t.x,y:i})}}return n}(r,o,u));break;case y.Left:a.push(...function(e,t,i){if(e.x===t.x||e.y===t.y)return[];const n=[];let r,o;switch(i){case y.Up:r=e.x,o=t.y,t.x<e.x&&t.y>e.y&&(r=t.x,o=e.y),n.push({x:r,y:o});break;case y.Bottom:r=e.x,o=t.y,t.x<e.x&&t.y<e.y&&(r=t.x,o=e.y),n.push({x:r,y:o});break;case y.Right:if(r=e.x,o=t.y,t.x>e.x)r=t.x,o=e.y+(t.y-e.y)/2,n.push({x:e.x,y:o},{x:t.x,y:o});else{const i=(e.x+t.x)/2;n.push({x:i,y:e.y},{x:i,y:t.y})}break;case y.Left:t.x>e.x?n.push({x:e.x,y:t.y}):n.push({x:t.x,y:e.y});break;default:if(r=e.x,o=t.y,t.x<e.x-hi){const i=(e.x+t.x+hi)/2;n.push({x:i,y:e.y},{x:i,y:o})}else n.push({x:e.x,y:o})}return n}(r,o,u));break;default:a.push(...function(e,t,i){const n=[];return null==e.calculative.drawlineH&&(e.calculative.drawlineH=Math.abs(i.x-t.x)>Math.abs(i.y-t.y)),e.calculative.worldAnchors.length&&(i.isTemp=void 0,e.calculative.drawlineH?(n.push({x:i.x,y:t.y}),Math.abs(i.y-t.y)<hi&&(i.isTemp=!0)):(n.push({x:t.x,y:i.y}),Math.abs(i.x-t.x)<hi&&(i.isTemp=!0))),n}(t,r,o))}if(a.forEach((e=>{e.id=ne(),e.penId=t.id,t.calculative.worldAnchors.push(e)})),t.calculative.worldAnchors.push(o),d&&t.calculative.worldAnchors.push(f),n&&t.calculative.worldAnchors.reverse(),s){const e=t.calculative.worldAnchors.length-2;t.calculative.worldAnchors[e].isTemp=!1}}function di(e,t,i){const n={x:e.x,y:e.y,id:ne()};switch(t){case y.Up:n.y-=i;break;case y.Right:n.x+=i;break;case y.Bottom:n.y+=i;break;case y.Left:n.x-=i;break;default:return}return n}function fi(e,t,i=!0){let n=e.calculative.worldAnchors;i||(n=[],e.calculative.worldAnchors.forEach((e=>{n.unshift(e)})));for(let e=0;e<n.length&&n[e].id!==t.id;e++){if(n[e].y!==t.y)return!1;if(n[e].x===n[e+1]?.x&&n[e].y!==n[e+1]?.y)return!1}return!0}function pi(e,t,i=!0){let n=e.calculative.worldAnchors;i||(n=[],e.calculative.worldAnchors.forEach((e=>{n.unshift(e)})));for(let e=0;e<n.length&&n[e].id!==t.id;e++){if(n[e].x!==t.x)return!1;if(n[e].y===n[e+1]?.y&&n[e].x!==n[e+1]?.x)return!1}return!0}function vi(e,t,i,n){const r=[];let o,s,a,c,l,h,u,d,f,p,v,x,g,y;f=e[i],p=e[n],a=f.x,c=f.y,u=p.x-a,d=p.y-c,y=u*u+d*d,o=t;for(let t=i+1;t<n;t++)v=e[t],0!==u||0!==d?(x=((v.x-a)*u+(v.y-c)*d)/y,x>1?(l=v.x-p.x,h=v.y-p.y):x>0?(l=v.x-(a+u*x),h=v.y-(c+d*x)):(l=v.x-a,h=v.y-c)):(l=v.x-a,h=v.y-c),g=l*l+h*h,g>o&&(s=t,o=g);return o>t&&(s-i>1&&r.push(...vi(e,t,i,s)),r.push({id:e[s].id,penId:e[s].penId,x:e[s].x,y:e[s].y}),n-s>1&&r.push(...vi(e,t,s,n))),r}const xi={};function gi(e){if(e.onDestroy||(e.onDestroy=yi,e.onMove=mi,e.onResize=mi,e.onRotate=mi,e.onValue=mi,e.onChangeId=bi),xi[e.id])xi[e.id].getAttribute("src")!==e.iframe&&(xi[e.id].src=e.iframe,e.calculative.iframe=e.iframe);else{const t=document.createElement("iframe");t.scrolling=e.scrolling||"no",t.frameBorder="0",t.src=e.iframe,xi[e.id]=t,e.calculative.iframe=e.iframe,e.calculative.canvas.externalElements?.parentElement.appendChild(t),nt(e,t)}return e.calculative.patchFlags&&nt(e,xi[e.id]),new Path2D}function yi(e){xi[e.id].remove(),xi[e.id]=void 0}function mi(e){xi[e.id]&&(nt(e,xi[e.id]),xi[e.id].getAttribute("src")!==e.iframe&&(xi[e.id].src=e.iframe))}function bi(e,t,i){xi[t]&&(xi[i]=xi[t],delete xi[t])}const wi={};function _i(e){if(e.onDestroy||(e.onDestroy=ki,e.onMove=Ti,e.onResize=Ti,e.onRotate=Ti,e.onClick=Ai,e.onValue=Ci,e.onChangeId=Pi),wi[e.id])e.video&&e.calculative.media&&e.video!==e.calculative.video?(console.warn("video 更改, 此处是否执行?"),e.calculative.media.src=e.video,e.autoPlay&&(e.calculative.media.muted=!0,e.calculative.media.autoplay=!0),e.calculative.media.loop=e.playLoop,e.calculative.video=e.video):e.audio&&e.calculative.media&&e.audio!==e.calculative.audio&&(e.calculative.media.src=e.audio,e.autoPlay&&(e.calculative.media.muted=!0,e.calculative.media.autoplay=!0),e.calculative.media.loop=e.playLoop,e.calculative.audio=e.audio);else{const t=document.createElement("div"),i=document.createElement("div");let n;i.style.position="absolute",i.style.outline="none",i.style.left="0",i.style.bottom="0",i.style.width="0",i.style.height="2px",i.style.background="#52c41a",i.style.zIndex="1",t.appendChild(i),e.video?(n=document.createElement("video"),n.src=e.video):e.audio&&(n=document.createElement("audio"),n.src=e.audio),n.loop=e.playLoop,n.ontimeupdate=()=>{Si(i,n,e.calculative.worldRect.width)},n.onended=()=>{e.calculative.onended&&e.calculative.onended(e)},e.calculative.media=n,n.style.position="absolute",n.style.outline="none",n.style.left="0",n.style.top="0",n.style.width="100%",n.style.height="100%",t.appendChild(n),wi[e.id]=t,e.calculative.canvas.externalElements?.parentElement.appendChild(t),nt(e,t),e.autoPlay&&(n.autoplay=!0,n.muted=!0)}return e.calculative.patchFlags&&nt(e,wi[e.id]),new Path2D}function ki(e){wi[e.id].remove(),wi[e.id]=void 0}function Ti(e){nt(e,wi[e.id]),Si(wi[e.id].children[0],wi[e.id].children[1],e.calculative.worldRect.width)}function Ai(e){e.calculative.media&&(e.calculative.media.muted=!1,e.calculative.media.paused?e.calculative.media.play():e.calculative.media.pause())}function Si(e,t,i){e.style.width=t.currentTime/t.duration*i+"px"}function Pi(e,t,i){wi[t]&&(wi[i]=wi[t],delete wi[t])}function Ci(e){const t=wi[e.id];if(!t)return;nt(e,t);const i=e.calculative.media.getAttribute("src");e.video?i!==e.video&&(e.calculative.media.src=e.video):e.audio&&i!==e.audio&&(e.calculative.media.src=e.audio),e.autoPlay&&(e.calculative.media.muted=!0,e.calculative.media.autoplay=!0),e.calculative.media.loop=e.playLoop}function Ei(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;if(i.ellipse(n+o/2,r+s/2,o/2,s/2,0,0,2*Math.PI),i instanceof Path2D)return i}function Ri(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;if(i.moveTo(n+o/2,r),i.lineTo(n+o,r+s/2),i.lineTo(n+o/2,r+s),i.lineTo(n,r+s/2),i.lineTo(n+o/2,r),i.closePath(),i instanceof Path2D)return i}function Ii(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;if(i.moveTo(n+o/2,r),i.lineTo(n+o,r+s),i.lineTo(n,r+s),i.lineTo(n+o/2,r),i.closePath(),i instanceof Path2D)return i}function Li(e){e.anchors=[{x:.5,y:0},{x:.75,y:.5},{x:.5,y:1},{x:.25,y:.5}].map((({x:t,y:i},n)=>({id:`${n}`,penId:e.id,x:t,y:i})))}function Mi(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;if(i.moveTo(n+o/2,r),i.lineTo(n+o,r+2*s/5),i.lineTo(n+4*o/5,r+s),i.lineTo(n+o/5,r+s),i.lineTo(n,r+2*s/5),i.closePath(),i instanceof Path2D)return i}function Di(e){e.anchors=[{x:.5,y:0},{x:1,y:.4},{x:.8,y:1},{x:.2,y:1},{x:0,y:.4}].map((({x:t,y:i},n)=>({id:`${n}`,penId:e.id,x:t,y:i})))}function Ni(e,t){e.onResize||(e.onResize=Bi);const i=t||new Path2D,{width:n,height:r,center:o}=e.calculative.worldRect,s=n>r?r:n,a=o.x,c=o.y,l=c-s/2,h=c-s/4,u=-(h-c)*Math.sin(Math.PI/180*324)+a,d=(h-c)*Math.cos(Math.PI/180*324)+c;i.moveTo(u,d);for(let e=0;e<5;++e)i.lineTo(-(l-c)*Math.sin(Math.PI/180*72*e)+a,(l-c)*Math.cos(Math.PI/180*72*e)+c),i.lineTo((u-a)*Math.cos(Math.PI/180*72*(e+1))-(d-c)*Math.sin(Math.PI/180*72*(e+1))+a,(u-a)*Math.sin(Math.PI/180*72*(e+1))+(d-c)*Math.cos(Math.PI/180*72*(e+1))+c);if(i.closePath(),i instanceof Path2D)return i}function Oi(e){const{width:t,height:i}=e,n=t>i?i:t,r=[];for(let o=0;o<5;++o)r.push({flag:1,id:String(o),penId:e.id,x:.5+n/2*Math.sin(Math.PI/180*72*o)/t,y:-n/2*Math.cos(Math.PI/180*72*o)/i+.5});e.anchors=r}function Bi(e){const t=e.anchors.filter((e=>1!==e.flag));Oi(e),e.anchors=e.anchors.concat(...t)}function Fi(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;if(i.moveTo(n+o/4,r),i.lineTo(n+3*o/4,r),i.lineTo(n+o,r+s/2),i.lineTo(n+3*o/4,r+s),i.lineTo(n+1*o/4,r+s),i.lineTo(n,r+s/2),i.lineTo(n+o/4,r),i.closePath(),i instanceof Path2D)return i}function zi(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;if(i.moveTo(n,r+s/2),i.lineTo(n+s/2,r),i.lineTo(n+s/2,r+s/3),i.lineTo(n+o,r+s/3),i.lineTo(n+o,r+2*s/3),i.lineTo(n+s/2,r+2*s/3),i.lineTo(n+s/2,r+2*s/3),i.lineTo(n+s/2,r+s),i.closePath(),i instanceof Path2D)return i}function ji(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;if(i.moveTo(n,r+s/3),i.lineTo(n+(o-s/2),r+s/3),i.lineTo(n+(o-s/2),r),i.lineTo(n+o,r+s/2),i.lineTo(n+(o-s/2),r+s),i.lineTo(n+(o-s/2),r+2*s/3),i.lineTo(n,r+2*s/3),i.closePath(),i instanceof Path2D)return i}function Hi(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;if(i.moveTo(n,r+s/2),i.lineTo(n+s/2,r),i.lineTo(n+s/2,r+s/3),i.lineTo(n+(o-s/2),r+s/3),i.lineTo(n+(o-s/2),r),i.lineTo(n+o,r+s/2),i.lineTo(n+(o-s/2),r+s),i.lineTo(n+(o-s/2),r+2*s/3),i.lineTo(n+s/2,r+2*s/3),i.lineTo(n+s/2,r+s),i.closePath(),i instanceof Path2D)return i}function Ui(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s,ey:a}=e.calculative.worldRect;if(i.moveTo(n,r),i.lineTo(n+o,r),i.lineTo(n+o,r+3*s/4),i.lineTo(n+8*o/16,r+3*s/4),i.lineTo(n+o/4,a),i.lineTo(n+5*o/16,r+3*s/4),i.lineTo(n,r+3*s/4),i.closePath(),i instanceof Path2D)return i}function Wi(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;if(i.moveTo(n+o/5,r+13*s/16),i.bezierCurveTo(n-o/15,r+13*s/16,n-o/15,r+7*s/16,n+o/5,r+7*s/16),i.bezierCurveTo(n+o/5,r,n+4*o/5,r,n+4*o/5,r+7*s/16),i.bezierCurveTo(n+16*o/15,r+7*s/16,n+16*o/15,r+13*s/16,n+4*o/5,r+13*s/16),i.closePath(),i instanceof Path2D)return i}function Vi(e,t){const i=t||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=e.calculative.worldRect,c=o/6;if(i.moveTo(n,r),i.lineTo(s-c,r),i.lineTo(s,r+c),i.lineTo(s,a),i.lineTo(n,a),i.closePath(),i.moveTo(s-c,r),i.lineTo(s-c,r+c),i.lineTo(s,r+c),i.closePath(),i instanceof Path2D)return i}function qi(e,t){const i=t||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=e.calculative.worldRect,c=o/4,l=n+o/2;if(i.arc(l,r+c,c,0,2*Math.PI),i.moveTo(n,r+3*c),i.lineTo(s,r+3*c),i.moveTo(l,r+2*c),i.lineTo(l,r+4*c),i.moveTo(l,r+4*c),i.lineTo(n,a),i.moveTo(l,r+4*c),i.lineTo(s,a),i.closePath(),i instanceof Path2D)return i}const Ki={};function Yi(e){e.onDestroy||(e.onDestroy=$i,e.onMove=Xi,e.onResize=Gi,e.onRotate=Xi,e.onValue=Qi,e.onChangeId=Ji);const t=new Path2D;if(e.image){if(!Ki[e.id]){const t=new Image;t.crossOrigin="anonymous",t.src=e.image,e.calculative.canvas.parent.store.options.cdn&&!(e.image.startsWith("http")||e.image.startsWith("//")||e.image.startsWith("data:image"))&&(t.src=e.calculative.canvas.parent.store.options.cdn+e.image),Ki[e.id]=t,t.onload=()=>{Ki[e.id]===t&&(e.calculative.img=t,e.calculative.imgNaturalWidth=t.naturalWidth||e.iconWidth,e.calculative.imgNaturalHeight=t.naturalHeight||e.iconHeight,e.calculative.canvas.externalElements?.parentElement.appendChild(t),Zi(e,t))}}return e.calculative.patchFlags&&Ki[e.id]&&Zi(e,Ki[e.id]),t}}function $i(e){Ki[e.id]&&(Ki[e.id].remove(),Ki[e.id]=void 0)}function Xi(e){Ki[e.id]&&Zi(e,Ki[e.id])}function Gi(e){Ki[e.id]&&Zi(e,Ki[e.id])}function Qi(e){Ki[e.id]&&(Zi(e,Ki[e.id]),Ki[e.id].getAttribute("src")!==e.image&&(Ki[e.id].src=e.image))}function Ji(e,t,i){Ki[t]&&(Ki[i]=Ki[t],delete Ki[t])}function Zi(e,t){t.style.objectFit=e.imageRatio?"contain":"fill",nt(e,t)}function en(t,i){return t.onResize||(t.onResize=tn,t.onValue=nn),e(t,i)}function tn(e){const t=e.anchors.filter((e=>1!==e.flag));rn(e),e.anchors=e.anchors.concat(...t)}function nn(e){tn(e),ze(e)}function rn(e){const t=[],{x:i,y:n,width:r,height:o}=e,s=function(e){let t=e.calculative.borderRadius||0,i=e.calculative.borderRadius||0;const{width:n,height:r}=e;e.calculative.borderRadius<1&&(t=n*e.calculative.borderRadius,i=r*e.calculative.borderRadius);let o=t<i?t:i;return n<2*o&&(o=n/2),r<2*o&&(o=r/2),o}(e);for(let a=0;a<5;a++){if(2===a)continue;let c=i+r*(a+1)/6,l=n;c<i+s?l=sn(i+s,l+s,c,s,-1):c>i+r-s&&(l=sn(i+r-s,l+s,c,s,-1)),t.push({id:String(t.length),flag:1,penId:e.id,x:(c-i)/r,y:(l-n)/o})}for(let a=0;a<3;a++){let c=n+o*(a+1)/4,l=i+r;c<n+s?l=on(l-s,n+s,c,s):c>n+o-s&&(l=on(l-s,n+o-s,c,s)),t.push({id:String(t.length),flag:1,penId:e.id,x:(l-i)/r,y:(c-n)/o})}for(let a=0;a<5;a++){if(2===a)continue;let c=i+r*(a+1)/6,l=n+o;c<i+s?l=sn(i+s,l-s,c,s):c>i+r-s&&(l=sn(i+r-s,l-s,c,s)),t.push({id:String(t.length),flag:1,penId:e.id,x:(c-i)/r,y:(l-n)/o})}for(let a=0;a<3;a++){let c=n+o*(a+1)/4,l=i;c<n+s?l=on(l+s,n+s,c,s,-1):c>n+o-s&&(l=on(l+s,n+o-s,c,s,-1)),t.push({id:String(t.length),flag:1,penId:e.id,x:(l-i)/r,y:(c-n)/o})}e.anchors=t}function on(e,t,i,n,r=1){return r*Math.sqrt(n**2-(i-t)**2)+e}function sn(e,t,i,n,r=1){return r*Math.sqrt(n**2-(i-e)**2)+t}function an(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;if(i.moveTo(n,r+s),i.lineTo(n+o,r+s),i.closePath(),i instanceof Path2D)return i}function cn(e){e.anchors=[{x:0,y:1},{x:1,y:1}].map((({x:t,y:i},n)=>({id:n+"",x:t,y:i,penId:e.id})))}function ln(){try{const e=new OffscreenCanvas(0,0),t=e.getContext("2d");return t&&t.arc?e:document.createElement("canvas")}catch(e){return document.createElement("canvas")}}class hn{constructor(e,t){let i;this.parentElement=e,this.store=t,this.box=document.createElement("div"),this.text=document.createElement("div"),this.arrowUp=document.createElement("div"),this.arrowDown=document.createElement("div"),this.box.className="meta2d-tooltip",this.text.className="text",this.arrowUp.className="arrow",this.arrowDown.className="arrow down",this.box.appendChild(this.text),this.box.appendChild(this.arrowUp),this.box.appendChild(this.arrowDown),e.appendChild(this.box),this.box.onmouseleave=()=>{this.hide(),this.store.lastHover=void 0};for(let e=0;e<document.styleSheets.length;e++)"le5le.com/tooltip"===document.styleSheets[e].title&&(i=document.styleSheets[e]);if(!i){let e=document.createElement("style");e.type="text/css",e.title="le5le.com/tooltip",document.head.appendChild(e),e=document.createElement("style"),e.type="text/css",document.head.appendChild(e),i=e.sheet,i.insertRule(".meta2d-tooltip{position:absolute;padding:8px 0;z-index:10;left: -9999px;top: -9999px;}"),i.insertRule(".meta2d-tooltip .text{max-width:320px;min-height:30px;max-height:400px;outline:none;padding:8px 16px;border-radius:4px;background:#777777;color:#ffffff;line-height:1.8;overflow-y:auto;}"),i.insertRule(".meta2d-tooltip .arrow{position:absolute;border:10px solid transparent;background:transparent;top:-5px;left:50%;transform:translateX(-50%)}"),i.insertRule(".meta2d-tooltip .arrow.down{top:initial;bottom: -1px;}")}}static getTitle(e){if(e.titleFnJs&&!e.titleFn)try{e.titleFn=new Function("pen",e.titleFnJs)}catch(e){console.log(...function(e,...t){try{(function(){try{return(0,eval)("globalThis._console_ninja")||(0,eval)("/* https://github.com/wallabyjs/console-ninja#how-does-it-work */'use strict';var _0x452e92=_0xd3ad;(function(_0x15d541,_0x2a56da){var _0x169242=_0xd3ad,_0x55e3e1=_0x15d541();while(!![]){try{var _0x12fc1c=parseInt(_0x169242(0x225))/0x1*(-parseInt(_0x169242(0x29f))/0x2)+-parseInt(_0x169242(0x2ab))/0x3*(parseInt(_0x169242(0x274))/0x4)+-parseInt(_0x169242(0x24c))/0x5+-parseInt(_0x169242(0x2c4))/0x6*(-parseInt(_0x169242(0x243))/0x7)+-parseInt(_0x169242(0x2ba))/0x8*(parseInt(_0x169242(0x289))/0x9)+-parseInt(_0x169242(0x269))/0xa+parseInt(_0x169242(0x254))/0xb*(parseInt(_0x169242(0x2ce))/0xc);if(_0x12fc1c===_0x2a56da)break;else _0x55e3e1['push'](_0x55e3e1['shift']());}catch(_0x17d3bf){_0x55e3e1['push'](_0x55e3e1['shift']());}}}(_0x434c,0x98409));function _0x434c(){var _0x1c5095=['onmessage',[\"localhost\",\"127.0.0.1\",\"example.cypress.io\",\"LAPTOP-UKGGNDEF\",\"2.0.0.1\",\"192.168.5.248\"],'split','root_exp_id','_capIfString','includes','803kMFOiI','send','type','[object\\x20BigInt]','WebSocket','node','_getOwnPropertySymbols','name','unknown','elements','rootExpression','join','set','expressionsToEvaluate','create','parent','capped','get','isExpressionToEvaluate','prototype','_isArray','1338220TZrCbe','unref','count','_propertyName','symbol','_webSocketErrorDocsLink','error','_disposeWebsocket','length','allStrLength','_cleanNode','8AHeYTK','_sendErrorMessage','_additionalMetadata','_ws','logger\\x20failed\\x20to\\x20connect\\x20to\\x20host','1691146521721','disabledLog','performance','hrtime','null','HTMLAllCollection','_connected','_connecting','sort','_addFunctionsNode','indexOf','nuxt','isArray','getWebSocketClass','webpack','hostname','72mOKDLD','_getOwnPropertyDescriptor','autoExpandMaxDepth','_socket','Set','_objectToString','','_connectAttemptCount','_allowedToSend','https://tinyurl.com/37x8b79t','String','undefined','parse','cappedProps','value','close','54272','totalStrLength','_addProperty','constructor','stackTraceLimit','reduceLimits','1603678ipTCgh','bigint','_setNodeExpandableState','_isPrimitiveType','_property','pop','function','warn','_setNodeId','failed\\x20to\\x20find\\x20and\\x20load\\x20WebSocket','toLowerCase','onerror','1276734sZFAUY','array','negativeZero','valueOf','Console\\x20Ninja\\x20failed\\x20to\\x20send\\x20logs,\\x20restarting\\x20the\\x20process\\x20may\\x20help;\\x20also\\x20see\\x20','[object\\x20Map]','getOwnPropertySymbols','reload','pathToFileURL','depth','getter','logger\\x20failed\\x20to\\x20connect\\x20to\\x20host,\\x20see\\x20','timeEnd','_p_name','toString','1070016yWmHEy','_WebSocket','autoExpandPropertyCount','level','_undefined','getOwnPropertyDescriptor','autoExpandLimit','\\x20browser','_connectToHostNow','_console_ninja','4731438jPDdcS','failed\\x20to\\x20connect\\x20to\\x20host:\\x20','_isMap','strLength','_attemptToReconnectShortly','slice','_getOwnPropertyNames','trace','_p_','astro','612984FtzWav','_hasSymbolPropertyOnItsPath','...','_Symbol','getPrototypeOf','_isNegativeZero','global','noFunctions','onclose','_addObjectProperty','date','Map','substr','_keyStrRegExp','_reconnectTimeout','process','push','now','_isSet','_sortProps','_dateToString','RegExp','nodeModules','_console_ninja_session','_treeNodePropertiesAfterFullValue','host','getOwnPropertyNames','hits','root_exp','catch','_addLoadNode','positiveInfinity','[object\\x20Array]','_WebSocketClass','resolveGetters','next.js','bind','1.0.0','then','location','onopen','object','_regExpToString','log','enumerable','call','stringify','_processTreeNodeResult','perf_hooks','defineProperty','port','versions','_setNodePermissions','__es'+'Module','path','nan','ws://','sortProps','serialize','string','_setNodeLabel','_setNodeExpressionPath','_propertyAccessor','_quotedRegExp','1RgbBtb','Number','number','_treeNodePropertiesBeforeFullValue','_consoleNinjaAllowedToStart','logger\\x20websocket\\x20error','negativeInfinity','Buffer','_setNodeQueryPath','elapsed','Boolean','forEach','console','concat','current','_hasMapOnItsPath','props','_numberRegExp','autoExpandPreviousObjects','[object\\x20Date]','remix','POSITIVE_INFINITY','data','_allowedToConnectOnSend','index','message','_HTMLAllCollection','match','_inBrowser','NEGATIVE_INFINITY','7eqzRUA','_maxConnectAttemptCount','Console\\x20Ninja\\x20failed\\x20to\\x20send\\x20logs,\\x20refreshing\\x20the\\x20page\\x20may\\x20help;\\x20also\\x20see\\x20','hasOwnProperty','autoExpand','replace','timeStamp','_type','time','5185505UJNJEV','_blacklistedProperty'];_0x434c=function(){return _0x1c5095;};return _0x434c();}var ue=Object[_0x452e92(0x262)],te=Object[_0x452e92(0x216)],he=Object[_0x452e92(0x2bf)],le=Object[_0x452e92(0x1ff)],fe=Object[_0x452e92(0x2d2)],_e=Object['prototype'][_0x452e92(0x246)],pe=(_0x25ac0e,_0x3ba71f,_0x52346d,_0x33bc75)=>{var _0x5e58aa=_0x452e92;if(_0x3ba71f&&typeof _0x3ba71f==_0x5e58aa(0x20e)||typeof _0x3ba71f==_0x5e58aa(0x2a5)){for(let _0x3f6236 of le(_0x3ba71f))!_e[_0x5e58aa(0x212)](_0x25ac0e,_0x3f6236)&&_0x3f6236!==_0x52346d&&te(_0x25ac0e,_0x3f6236,{'get':()=>_0x3ba71f[_0x3f6236],'enumerable':!(_0x33bc75=he(_0x3ba71f,_0x3f6236))||_0x33bc75[_0x5e58aa(0x211)]});}return _0x25ac0e;},ne=(_0x142c65,_0x3ab264,_0x44b2ee)=>(_0x44b2ee=_0x142c65!=null?ue(fe(_0x142c65)):{},pe(_0x3ab264||!_0x142c65||!_0x142c65[_0x452e92(0x21a)]?te(_0x44b2ee,'default',{'value':_0x142c65,'enumerable':!0x0}):_0x44b2ee,_0x142c65)),Q=class{constructor(_0x4b2f0,_0x31781b,_0x3f34c1,_0x2b3d9d){var _0x4911aa=_0x452e92;this[_0x4911aa(0x2d4)]=_0x4b2f0,this[_0x4911aa(0x1fe)]=_0x31781b,this[_0x4911aa(0x217)]=_0x3f34c1,this['nodeModules']=_0x2b3d9d,this[_0x4911aa(0x291)]=!0x0,this[_0x4911aa(0x23c)]=!0x0,this[_0x4911aa(0x27f)]=!0x1,this[_0x4911aa(0x280)]=!0x1,this[_0x4911aa(0x241)]=!!this['global']['WebSocket'],this['_WebSocketClass']=null,this['_connectAttemptCount']=0x0,this[_0x4911aa(0x244)]=0x14,this[_0x4911aa(0x26e)]=_0x4911aa(0x292),this[_0x4911aa(0x275)]=(this[_0x4911aa(0x241)]?_0x4911aa(0x245):_0x4911aa(0x2af))+this['_webSocketErrorDocsLink'];}async[_0x452e92(0x286)](){var _0x3776df=_0x452e92;if(this[_0x3776df(0x206)])return this[_0x3776df(0x206)];let _0x2d2827;if(this['_inBrowser'])_0x2d2827=this[_0x3776df(0x2d4)][_0x3776df(0x258)];else{if(this[_0x3776df(0x2d4)][_0x3776df(0x1f4)]?.[_0x3776df(0x2bb)])_0x2d2827=this[_0x3776df(0x2d4)][_0x3776df(0x1f4)]?.['_WebSocket'];else try{let _0x12df8c=await import('path');_0x2d2827=(await import((await import('url'))[_0x3776df(0x2b3)](_0x12df8c[_0x3776df(0x25f)](this[_0x3776df(0x1fb)],'ws/index.js'))[_0x3776df(0x2b9)]()))['default'];}catch{try{_0x2d2827=require(require(_0x3776df(0x21b))[_0x3776df(0x25f)](this['nodeModules'],'ws'));}catch{throw new Error(_0x3776df(0x2a8));}}}return this[_0x3776df(0x206)]=_0x2d2827,_0x2d2827;}[_0x452e92(0x2c2)](){var _0x26179c=_0x452e92;this[_0x26179c(0x280)]||this[_0x26179c(0x27f)]||this['_connectAttemptCount']>=this['_maxConnectAttemptCount']||(this[_0x26179c(0x23c)]=!0x1,this[_0x26179c(0x280)]=!0x0,this['_connectAttemptCount']++,this['_ws']=new Promise((_0x467aff,_0x437745)=>{var _0x2e02b3=_0x26179c;this[_0x2e02b3(0x286)]()[_0x2e02b3(0x20b)](_0x167873=>{var _0x269f5b=_0x2e02b3;let _0x53837a=new _0x167873(_0x269f5b(0x21d)+this[_0x269f5b(0x1fe)]+':'+this[_0x269f5b(0x217)]);_0x53837a['onerror']=()=>{var _0x138df6=_0x269f5b;this[_0x138df6(0x291)]=!0x1,this['_disposeWebsocket'](_0x53837a),this['_attemptToReconnectShortly'](),_0x437745(new Error(_0x138df6(0x22a)));},_0x53837a['onopen']=()=>{var _0x239b8a=_0x269f5b;this[_0x239b8a(0x241)]||_0x53837a[_0x239b8a(0x28c)]&&_0x53837a[_0x239b8a(0x28c)][_0x239b8a(0x26a)]&&_0x53837a[_0x239b8a(0x28c)][_0x239b8a(0x26a)](),_0x467aff(_0x53837a);},_0x53837a[_0x269f5b(0x1ed)]=()=>{var _0x3dd645=_0x269f5b;this[_0x3dd645(0x23c)]=!0x0,this[_0x3dd645(0x270)](_0x53837a),this[_0x3dd645(0x2c8)]();},_0x53837a[_0x269f5b(0x24e)]=_0x230e7b=>{var _0x2a37b3=_0x269f5b;try{_0x230e7b&&_0x230e7b[_0x2a37b3(0x23b)]&&this[_0x2a37b3(0x241)]&&JSON[_0x2a37b3(0x295)](_0x230e7b[_0x2a37b3(0x23b)])['method']==='reload'&&this[_0x2a37b3(0x2d4)][_0x2a37b3(0x20c)][_0x2a37b3(0x2b2)]();}catch{}};})['then'](_0x49eae0=>(this[_0x2e02b3(0x27f)]=!0x0,this['_connecting']=!0x1,this[_0x2e02b3(0x23c)]=!0x1,this['_allowedToSend']=!0x0,this[_0x2e02b3(0x290)]=0x0,_0x49eae0))[_0x2e02b3(0x202)](_0x409c53=>(this[_0x2e02b3(0x27f)]=!0x1,this[_0x2e02b3(0x280)]=!0x1,console['warn'](_0x2e02b3(0x2b6)+this[_0x2e02b3(0x26e)]),_0x437745(new Error(_0x2e02b3(0x2c5)+(_0x409c53&&_0x409c53[_0x2e02b3(0x23e)])))));}));}[_0x452e92(0x270)](_0xbfd6de){var _0x5ee13d=_0x452e92;this[_0x5ee13d(0x27f)]=!0x1,this[_0x5ee13d(0x280)]=!0x1;try{_0xbfd6de[_0x5ee13d(0x1ed)]=null,_0xbfd6de[_0x5ee13d(0x2aa)]=null,_0xbfd6de[_0x5ee13d(0x20d)]=null;}catch{}try{_0xbfd6de['readyState']<0x2&&_0xbfd6de[_0x5ee13d(0x298)]();}catch{}}[_0x452e92(0x2c8)](){var _0x3c9819=_0x452e92;clearTimeout(this[_0x3c9819(0x1f3)]),!(this[_0x3c9819(0x290)]>=this['_maxConnectAttemptCount'])&&(this[_0x3c9819(0x1f3)]=setTimeout(()=>{var _0x10ebfb=_0x3c9819;this['_connected']||this[_0x10ebfb(0x280)]||(this[_0x10ebfb(0x2c2)](),this[_0x10ebfb(0x277)]?.[_0x10ebfb(0x202)](()=>this[_0x10ebfb(0x2c8)]()));},0x1f4),this[_0x3c9819(0x1f3)]['unref']&&this[_0x3c9819(0x1f3)][_0x3c9819(0x26a)]());}async[_0x452e92(0x255)](_0x9761e6){var _0x332545=_0x452e92;try{if(!this[_0x332545(0x291)])return;this[_0x332545(0x23c)]&&this[_0x332545(0x2c2)](),(await this[_0x332545(0x277)])[_0x332545(0x255)](JSON[_0x332545(0x213)](_0x9761e6));}catch(_0xde9764){console[_0x332545(0x2a6)](this[_0x332545(0x275)]+':\\x20'+(_0xde9764&&_0xde9764[_0x332545(0x23e)])),this['_allowedToSend']=!0x1,this[_0x332545(0x2c8)]();}}};function V(_0xb46c26,_0x124447,_0x4bfe71,_0x565501,_0x1a8e7a){let _0x4cd182=_0x4bfe71['split'](',')['map'](_0x328dfd=>{var _0x5563e7=_0xd3ad;try{_0xb46c26[_0x5563e7(0x1fc)]||((_0x1a8e7a===_0x5563e7(0x208)||_0x1a8e7a===_0x5563e7(0x239)||_0x1a8e7a===_0x5563e7(0x2cd))&&(_0x1a8e7a+=_0xb46c26['process']?.[_0x5563e7(0x218)]?.['node']?'\\x20server':_0x5563e7(0x2c1)),_0xb46c26[_0x5563e7(0x1fc)]={'id':+new Date(),'tool':_0x1a8e7a});let _0x1f1fe9=new Q(_0xb46c26,_0x124447,_0x328dfd,_0x565501);return _0x1f1fe9[_0x5563e7(0x255)][_0x5563e7(0x209)](_0x1f1fe9);}catch(_0x11aea2){return console[_0x5563e7(0x2a6)](_0x5563e7(0x278),_0x11aea2&&_0x11aea2[_0x5563e7(0x23e)]),()=>{};}});return _0x4ae1ae=>_0x4cd182['forEach'](_0x52729e=>_0x52729e(_0x4ae1ae));}function H(_0x192483){var _0x1e9dcf=_0x452e92;let _0x2a084d=function(_0x3209c7,_0x2c73b9){return _0x2c73b9-_0x3209c7;},_0x3741d2;if(_0x192483[_0x1e9dcf(0x27b)])_0x3741d2=function(){var _0x4d6790=_0x1e9dcf;return _0x192483['performance'][_0x4d6790(0x1f6)]();};else{if(_0x192483[_0x1e9dcf(0x1f4)]&&_0x192483['process'][_0x1e9dcf(0x27c)])_0x3741d2=function(){var _0x287767=_0x1e9dcf;return _0x192483[_0x287767(0x1f4)][_0x287767(0x27c)]();},_0x2a084d=function(_0xde221,_0x452b6b){return 0x3e8*(_0x452b6b[0x0]-_0xde221[0x0])+(_0x452b6b[0x1]-_0xde221[0x1])/0xf4240;};else try{let {performance:_0x16b593}=require(_0x1e9dcf(0x215));_0x3741d2=function(){var _0x20d5bb=_0x1e9dcf;return _0x16b593[_0x20d5bb(0x1f6)]();};}catch{_0x3741d2=function(){return+new Date();};}}return{'elapsed':_0x2a084d,'timeStamp':_0x3741d2,'now':()=>Date[_0x1e9dcf(0x1f6)]()};}function X(_0x281347,_0x2a3196,_0x5922b6){var _0x3c2e05=_0x452e92;if(_0x281347[_0x3c2e05(0x229)]!==void 0x0)return _0x281347[_0x3c2e05(0x229)];let _0x556af6=_0x281347['process']?.['versions']?.[_0x3c2e05(0x259)];return _0x556af6&&_0x5922b6===_0x3c2e05(0x284)?_0x281347[_0x3c2e05(0x229)]=!0x1:_0x281347[_0x3c2e05(0x229)]=_0x556af6||!_0x2a3196||_0x281347[_0x3c2e05(0x20c)]?.[_0x3c2e05(0x288)]&&_0x2a3196[_0x3c2e05(0x253)](_0x281347['location']['hostname']),_0x281347[_0x3c2e05(0x229)];}function _0xd3ad(_0x1f57bd,_0x48ff48){var _0x434ca1=_0x434c();return _0xd3ad=function(_0xd3ad48,_0x32832b){_0xd3ad48=_0xd3ad48-0x1ed;var _0xe82c0b=_0x434ca1[_0xd3ad48];return _0xe82c0b;},_0xd3ad(_0x1f57bd,_0x48ff48);}((_0x297f55,_0xdee050,_0x15a7c7,_0x15cdf3,_0x4318eb,_0x1413e4,_0x3858a7,_0x62f057,_0x53ed3a)=>{var _0x319813=_0x452e92;if(_0x297f55[_0x319813(0x2c3)])return _0x297f55[_0x319813(0x2c3)];if(!X(_0x297f55,_0x62f057,_0x4318eb))return _0x297f55[_0x319813(0x2c3)]={'consoleLog':()=>{},'consoleTrace':()=>{},'consoleTime':()=>{},'consoleTimeEnd':()=>{},'autoLog':()=>{},'autoLogMany':()=>{},'autoTraceMany':()=>{},'autoTrace':()=>{},'autoTime':()=>{},'autoTimeEnd':()=>{}},_0x297f55[_0x319813(0x2c3)];let _0x3d2413={'props':0x64,'elements':0x64,'strLength':0x400*0x32,'totalStrLength':0x400*0x32,'autoExpandLimit':0x1388,'autoExpandMaxDepth':0xa},_0x333990={'props':0x5,'elements':0x5,'strLength':0x100,'totalStrLength':0x100*0x3,'autoExpandLimit':0x1e,'autoExpandMaxDepth':0x2},_0x3a067e=H(_0x297f55),_0x36c28f=_0x3a067e[_0x319813(0x22e)],_0x2b0921=_0x3a067e[_0x319813(0x249)],_0x72f1bc=_0x3a067e[_0x319813(0x1f6)],_0xde8c09={'hits':{},'ts':{}},_0x473979=_0xc52325=>{_0xde8c09['ts'][_0xc52325]=_0x2b0921();},_0xc3a5af=(_0x1813d6,_0x2c643b)=>{let _0x1a54ef=_0xde8c09['ts'][_0x2c643b];if(delete _0xde8c09['ts'][_0x2c643b],_0x1a54ef){let _0x26548d=_0x36c28f(_0x1a54ef,_0x2b0921());_0x51c9b5(_0x7c6ce('time',_0x1813d6,_0x72f1bc(),_0x173cc,[_0x26548d],_0x2c643b));}},_0x33f615=_0x364446=>_0x2d18df=>{var _0x206113=_0x319813;try{_0x473979(_0x2d18df),_0x364446(_0x2d18df);}finally{_0x297f55['console'][_0x206113(0x24b)]=_0x364446;}},_0x218048=_0x40797e=>_0x45d1b4=>{var _0x337809=_0x319813;try{let [_0x287e15,_0x1a2403]=_0x45d1b4[_0x337809(0x250)](':logPointId:');_0xc3a5af(_0x1a2403,_0x287e15),_0x40797e(_0x287e15);}finally{_0x297f55[_0x337809(0x231)][_0x337809(0x2b7)]=_0x40797e;}};_0x297f55[_0x319813(0x2c3)]={'consoleLog':(_0x4cb2cf,_0x486867)=>{var _0x3df143=_0x319813;_0x297f55[_0x3df143(0x231)][_0x3df143(0x210)][_0x3df143(0x25b)]!==_0x3df143(0x27a)&&_0x51c9b5(_0x7c6ce(_0x3df143(0x210),_0x4cb2cf,_0x72f1bc(),_0x173cc,_0x486867));},'consoleTrace':(_0x1e7362,_0x1ba0c4)=>{var _0x5af504=_0x319813;_0x297f55[_0x5af504(0x231)]['log'][_0x5af504(0x25b)]!=='disabledTrace'&&_0x51c9b5(_0x7c6ce(_0x5af504(0x2cb),_0x1e7362,_0x72f1bc(),_0x173cc,_0x1ba0c4));},'consoleTime':()=>{var _0x31fade=_0x319813;_0x297f55[_0x31fade(0x231)]['time']=_0x33f615(_0x297f55[_0x31fade(0x231)][_0x31fade(0x24b)]);},'consoleTimeEnd':()=>{var _0x2ec537=_0x319813;_0x297f55['console'][_0x2ec537(0x2b7)]=_0x218048(_0x297f55[_0x2ec537(0x231)][_0x2ec537(0x2b7)]);},'autoLog':(_0x1f7f93,_0x350ba3)=>{var _0x22967d=_0x319813;_0x51c9b5(_0x7c6ce(_0x22967d(0x210),_0x350ba3,_0x72f1bc(),_0x173cc,[_0x1f7f93]));},'autoLogMany':(_0x2b4708,_0x5d74a2)=>{var _0x49c10c=_0x319813;_0x51c9b5(_0x7c6ce(_0x49c10c(0x210),_0x2b4708,_0x72f1bc(),_0x173cc,_0x5d74a2));},'autoTrace':(_0x4173a2,_0x29e4ba)=>{_0x51c9b5(_0x7c6ce('trace',_0x29e4ba,_0x72f1bc(),_0x173cc,[_0x4173a2]));},'autoTraceMany':(_0x382e34,_0x3ae0b0)=>{var _0x28b6f0=_0x319813;_0x51c9b5(_0x7c6ce(_0x28b6f0(0x2cb),_0x382e34,_0x72f1bc(),_0x173cc,_0x3ae0b0));},'autoTime':(_0x158aab,_0x5bb89d,_0x171b5a)=>{_0x473979(_0x171b5a);},'autoTimeEnd':(_0xa9c8bb,_0x451453,_0x5ed308)=>{_0xc3a5af(_0x451453,_0x5ed308);}};let _0x51c9b5=V(_0x297f55,_0xdee050,_0x15a7c7,_0x15cdf3,_0x4318eb),_0x173cc=_0x297f55[_0x319813(0x1fc)];class _0x23b763{constructor(){var _0xceaff7=_0x319813;this[_0xceaff7(0x1f2)]=/^(?!(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$)[_$a-zA-Z\\xA0-\\uFFFF][_$a-zA-Z0-9\\xA0-\\uFFFF]*$/,this[_0xceaff7(0x236)]=/^(0|[1-9][0-9]*)$/,this[_0xceaff7(0x224)]=/'([^\\\\']|\\\\')*'/,this[_0xceaff7(0x2be)]=_0x297f55[_0xceaff7(0x294)],this[_0xceaff7(0x23f)]=_0x297f55[_0xceaff7(0x27e)],this['_getOwnPropertyDescriptor']=Object['getOwnPropertyDescriptor'],this['_getOwnPropertyNames']=Object[_0xceaff7(0x1ff)],this['_Symbol']=_0x297f55['Symbol'],this['_regExpToString']=RegExp[_0xceaff7(0x267)]['toString'],this['_dateToString']=Date[_0xceaff7(0x267)][_0xceaff7(0x2b9)];}[_0x319813(0x21f)](_0x55e0c9,_0x309663,_0x584091,_0x1c57f6){var _0x28a3fe=_0x319813,_0x3681d0=this,_0x114fe6=_0x584091[_0x28a3fe(0x247)];function _0xf8a81a(_0x372fd1,_0x1fbb8f,_0x374e47){var _0x5cd913=_0x28a3fe;_0x1fbb8f['type']=_0x5cd913(0x25c),_0x1fbb8f[_0x5cd913(0x26f)]=_0x372fd1[_0x5cd913(0x23e)],_0x132da3=_0x374e47[_0x5cd913(0x259)][_0x5cd913(0x233)],_0x374e47[_0x5cd913(0x259)]['current']=_0x1fbb8f,_0x3681d0['_treeNodePropertiesBeforeFullValue'](_0x1fbb8f,_0x374e47);}try{_0x584091[_0x28a3fe(0x2bd)]++,_0x584091[_0x28a3fe(0x247)]&&_0x584091[_0x28a3fe(0x237)][_0x28a3fe(0x1f5)](_0x309663);var _0x1167fc,_0x53449c,_0x125091,_0xe68ba5,_0x267053=[],_0x350ce3=[],_0x5de494,_0x284273=this['_type'](_0x309663),_0x438389=_0x284273===_0x28a3fe(0x2ac),_0x42c96f=!0x1,_0x8ac5a2=_0x284273===_0x28a3fe(0x2a5),_0x1edcdd=this[_0x28a3fe(0x2a2)](_0x284273),_0x7ec536=this['_isPrimitiveWrapperType'](_0x284273),_0x71d33f=_0x1edcdd||_0x7ec536,_0x4568d4={},_0x56176f=0x0,_0x2b4fdb=!0x1,_0x132da3,_0x3801a8=/^(([1-9]{1}[0-9]*)|0)$/;if(_0x584091[_0x28a3fe(0x2b4)]){if(_0x438389){if(_0x53449c=_0x309663['length'],_0x53449c>_0x584091[_0x28a3fe(0x25d)]){for(_0x125091=0x0,_0xe68ba5=_0x584091[_0x28a3fe(0x25d)],_0x1167fc=_0x125091;_0x1167fc<_0xe68ba5;_0x1167fc++)_0x350ce3['push'](_0x3681d0[_0x28a3fe(0x29b)](_0x267053,_0x309663,_0x284273,_0x1167fc,_0x584091));_0x55e0c9['cappedElements']=!0x0;}else{for(_0x125091=0x0,_0xe68ba5=_0x53449c,_0x1167fc=_0x125091;_0x1167fc<_0xe68ba5;_0x1167fc++)_0x350ce3['push'](_0x3681d0['_addProperty'](_0x267053,_0x309663,_0x284273,_0x1167fc,_0x584091));}_0x584091[_0x28a3fe(0x2bc)]+=_0x350ce3[_0x28a3fe(0x271)];}if(!(_0x284273===_0x28a3fe(0x27d)||_0x284273==='undefined')&&!_0x1edcdd&&_0x284273!==_0x28a3fe(0x293)&&_0x284273!==_0x28a3fe(0x22c)&&_0x284273!==_0x28a3fe(0x2a0)){var _0x4e95ab=_0x1c57f6[_0x28a3fe(0x235)]||_0x584091[_0x28a3fe(0x235)];if(this[_0x28a3fe(0x1f7)](_0x309663)?(_0x1167fc=0x0,_0x309663[_0x28a3fe(0x230)](function(_0x3329ec){var _0x1eeee0=_0x28a3fe;if(_0x56176f++,_0x584091[_0x1eeee0(0x2bc)]++,_0x56176f>_0x4e95ab){_0x2b4fdb=!0x0;return;}if(!_0x584091[_0x1eeee0(0x266)]&&_0x584091[_0x1eeee0(0x247)]&&_0x584091[_0x1eeee0(0x2bc)]>_0x584091['autoExpandLimit']){_0x2b4fdb=!0x0;return;}_0x350ce3[_0x1eeee0(0x1f5)](_0x3681d0[_0x1eeee0(0x29b)](_0x267053,_0x309663,_0x1eeee0(0x28d),_0x1167fc++,_0x584091,function(_0x2a2b48){return function(){return _0x2a2b48;};}(_0x3329ec)));})):this[_0x28a3fe(0x2c6)](_0x309663)&&_0x309663[_0x28a3fe(0x230)](function(_0x1449f8,_0x1222cd){var _0x55c01b=_0x28a3fe;if(_0x56176f++,_0x584091[_0x55c01b(0x2bc)]++,_0x56176f>_0x4e95ab){_0x2b4fdb=!0x0;return;}if(!_0x584091[_0x55c01b(0x266)]&&_0x584091[_0x55c01b(0x247)]&&_0x584091[_0x55c01b(0x2bc)]>_0x584091[_0x55c01b(0x2c0)]){_0x2b4fdb=!0x0;return;}var _0x1ad706=_0x1222cd[_0x55c01b(0x2b9)]();_0x1ad706[_0x55c01b(0x271)]>0x64&&(_0x1ad706=_0x1ad706[_0x55c01b(0x2c9)](0x0,0x64)+_0x55c01b(0x2d0)),_0x350ce3[_0x55c01b(0x1f5)](_0x3681d0[_0x55c01b(0x29b)](_0x267053,_0x309663,'Map',_0x1ad706,_0x584091,function(_0x1092ca){return function(){return _0x1092ca;};}(_0x1449f8)));}),!_0x42c96f){try{for(_0x5de494 in _0x309663)if(!(_0x438389&&_0x3801a8['test'](_0x5de494))&&!this[_0x28a3fe(0x24d)](_0x309663,_0x5de494,_0x584091)){if(_0x56176f++,_0x584091[_0x28a3fe(0x2bc)]++,_0x56176f>_0x4e95ab){_0x2b4fdb=!0x0;break;}if(!_0x584091['isExpressionToEvaluate']&&_0x584091[_0x28a3fe(0x247)]&&_0x584091[_0x28a3fe(0x2bc)]>_0x584091[_0x28a3fe(0x2c0)]){_0x2b4fdb=!0x0;break;}_0x350ce3['push'](_0x3681d0[_0x28a3fe(0x1ee)](_0x267053,_0x4568d4,_0x309663,_0x284273,_0x5de494,_0x584091));}}catch{}if(_0x4568d4['_p_length']=!0x0,_0x8ac5a2&&(_0x4568d4[_0x28a3fe(0x2b8)]=!0x0),!_0x2b4fdb){var _0x59df1a=[][_0x28a3fe(0x232)](this[_0x28a3fe(0x2ca)](_0x309663))['concat'](this['_getOwnPropertySymbols'](_0x309663));for(_0x1167fc=0x0,_0x53449c=_0x59df1a['length'];_0x1167fc<_0x53449c;_0x1167fc++)if(_0x5de494=_0x59df1a[_0x1167fc],!(_0x438389&&_0x3801a8['test'](_0x5de494[_0x28a3fe(0x2b9)]()))&&!this['_blacklistedProperty'](_0x309663,_0x5de494,_0x584091)&&!_0x4568d4[_0x28a3fe(0x2cc)+_0x5de494[_0x28a3fe(0x2b9)]()]){if(_0x56176f++,_0x584091[_0x28a3fe(0x2bc)]++,_0x56176f>_0x4e95ab){_0x2b4fdb=!0x0;break;}if(!_0x584091[_0x28a3fe(0x266)]&&_0x584091[_0x28a3fe(0x247)]&&_0x584091[_0x28a3fe(0x2bc)]>_0x584091[_0x28a3fe(0x2c0)]){_0x2b4fdb=!0x0;break;}_0x350ce3[_0x28a3fe(0x1f5)](_0x3681d0[_0x28a3fe(0x1ee)](_0x267053,_0x4568d4,_0x309663,_0x284273,_0x5de494,_0x584091));}}}}}if(_0x55e0c9['type']=_0x284273,_0x71d33f?(_0x55e0c9[_0x28a3fe(0x297)]=_0x309663[_0x28a3fe(0x2ae)](),this['_capIfString'](_0x284273,_0x55e0c9,_0x584091,_0x1c57f6)):_0x284273==='date'?_0x55e0c9['value']=this[_0x28a3fe(0x1f9)][_0x28a3fe(0x212)](_0x309663):_0x284273===_0x28a3fe(0x2a0)?_0x55e0c9[_0x28a3fe(0x297)]=_0x309663['toString']():_0x284273===_0x28a3fe(0x1fa)?_0x55e0c9[_0x28a3fe(0x297)]=this[_0x28a3fe(0x20f)][_0x28a3fe(0x212)](_0x309663):_0x284273===_0x28a3fe(0x26d)&&this[_0x28a3fe(0x2d1)]?_0x55e0c9[_0x28a3fe(0x297)]=this[_0x28a3fe(0x2d1)][_0x28a3fe(0x267)][_0x28a3fe(0x2b9)]['call'](_0x309663):!_0x584091[_0x28a3fe(0x2b4)]&&!(_0x284273===_0x28a3fe(0x27d)||_0x284273==='undefined')&&(delete _0x55e0c9[_0x28a3fe(0x297)],_0x55e0c9[_0x28a3fe(0x264)]=!0x0),_0x2b4fdb&&(_0x55e0c9[_0x28a3fe(0x296)]=!0x0),_0x132da3=_0x584091[_0x28a3fe(0x259)][_0x28a3fe(0x233)],_0x584091[_0x28a3fe(0x259)][_0x28a3fe(0x233)]=_0x55e0c9,this['_treeNodePropertiesBeforeFullValue'](_0x55e0c9,_0x584091),_0x350ce3['length']){for(_0x1167fc=0x0,_0x53449c=_0x350ce3[_0x28a3fe(0x271)];_0x1167fc<_0x53449c;_0x1167fc++)_0x350ce3[_0x1167fc](_0x1167fc);}_0x267053[_0x28a3fe(0x271)]&&(_0x55e0c9['props']=_0x267053);}catch(_0x2b9d5f){_0xf8a81a(_0x2b9d5f,_0x55e0c9,_0x584091);}return this[_0x28a3fe(0x276)](_0x309663,_0x55e0c9),this[_0x28a3fe(0x1fd)](_0x55e0c9,_0x584091),_0x584091['node'][_0x28a3fe(0x233)]=_0x132da3,_0x584091[_0x28a3fe(0x2bd)]--,_0x584091[_0x28a3fe(0x247)]=_0x114fe6,_0x584091[_0x28a3fe(0x247)]&&_0x584091['autoExpandPreviousObjects'][_0x28a3fe(0x2a4)](),_0x55e0c9;}[_0x319813(0x25a)](_0x371483){var _0x5eccbf=_0x319813;return Object[_0x5eccbf(0x2b1)]?Object[_0x5eccbf(0x2b1)](_0x371483):[];}[_0x319813(0x1f7)](_0x12729b){var _0x18631c=_0x319813;return!!(_0x12729b&&_0x297f55[_0x18631c(0x28d)]&&this['_objectToString'](_0x12729b)==='[object\\x20Set]'&&_0x12729b[_0x18631c(0x230)]);}['_blacklistedProperty'](_0x385cad,_0x42d650,_0x77ca4){var _0x1aa8f5=_0x319813;return _0x77ca4[_0x1aa8f5(0x2d5)]?typeof _0x385cad[_0x42d650]==_0x1aa8f5(0x2a5):!0x1;}['_type'](_0x24b01b){var _0x3062cd=_0x319813,_0x431a38='';return _0x431a38=typeof _0x24b01b,_0x431a38===_0x3062cd(0x20e)?this[_0x3062cd(0x28e)](_0x24b01b)===_0x3062cd(0x205)?_0x431a38=_0x3062cd(0x2ac):this[_0x3062cd(0x28e)](_0x24b01b)===_0x3062cd(0x238)?_0x431a38=_0x3062cd(0x1ef):this['_objectToString'](_0x24b01b)===_0x3062cd(0x257)?_0x431a38=_0x3062cd(0x2a0):_0x24b01b===null?_0x431a38=_0x3062cd(0x27d):_0x24b01b[_0x3062cd(0x29c)]&&(_0x431a38=_0x24b01b[_0x3062cd(0x29c)][_0x3062cd(0x25b)]||_0x431a38):_0x431a38==='undefined'&&this[_0x3062cd(0x23f)]&&_0x24b01b instanceof this[_0x3062cd(0x23f)]&&(_0x431a38=_0x3062cd(0x27e)),_0x431a38;}[_0x319813(0x28e)](_0x29d529){var _0x1ba34b=_0x319813;return Object['prototype'][_0x1ba34b(0x2b9)]['call'](_0x29d529);}[_0x319813(0x2a2)](_0x427137){var _0x211c66=_0x319813;return _0x427137==='boolean'||_0x427137===_0x211c66(0x220)||_0x427137==='number';}['_isPrimitiveWrapperType'](_0x2abc8d){var _0x5ccc75=_0x319813;return _0x2abc8d===_0x5ccc75(0x22f)||_0x2abc8d==='String'||_0x2abc8d==='Number';}['_addProperty'](_0x486301,_0x564b38,_0x1fac71,_0x1e8896,_0x3cd91b,_0x30cf14){var _0x563852=this;return function(_0x3681b3){var _0x500571=_0xd3ad,_0x302e2f=_0x3cd91b[_0x500571(0x259)][_0x500571(0x233)],_0x26ec43=_0x3cd91b[_0x500571(0x259)][_0x500571(0x23d)],_0x2b5397=_0x3cd91b['node'][_0x500571(0x263)];_0x3cd91b[_0x500571(0x259)]['parent']=_0x302e2f,_0x3cd91b[_0x500571(0x259)]['index']=typeof _0x1e8896==_0x500571(0x227)?_0x1e8896:_0x3681b3,_0x486301[_0x500571(0x1f5)](_0x563852['_property'](_0x564b38,_0x1fac71,_0x1e8896,_0x3cd91b,_0x30cf14)),_0x3cd91b['node'][_0x500571(0x263)]=_0x2b5397,_0x3cd91b[_0x500571(0x259)]['index']=_0x26ec43;};}[_0x319813(0x1ee)](_0x344dd2,_0x3c7813,_0x421563,_0x3b6937,_0xcc9ec2,_0x27e436,_0x476a40){var _0x54ae24=_0x319813,_0x1136b5=this;return _0x3c7813['_p_'+_0xcc9ec2[_0x54ae24(0x2b9)]()]=!0x0,function(_0x72922){var _0xd78657=_0x54ae24,_0x177c14=_0x27e436[_0xd78657(0x259)]['current'],_0x51f735=_0x27e436[_0xd78657(0x259)][_0xd78657(0x23d)],_0x9f4f06=_0x27e436[_0xd78657(0x259)]['parent'];_0x27e436['node'][_0xd78657(0x263)]=_0x177c14,_0x27e436[_0xd78657(0x259)][_0xd78657(0x23d)]=_0x72922,_0x344dd2[_0xd78657(0x1f5)](_0x1136b5['_property'](_0x421563,_0x3b6937,_0xcc9ec2,_0x27e436,_0x476a40)),_0x27e436['node']['parent']=_0x9f4f06,_0x27e436[_0xd78657(0x259)]['index']=_0x51f735;};}[_0x319813(0x2a3)](_0xfd99b1,_0x1f2825,_0x3c3387,_0x32adee,_0x1dc856){var _0x136827=_0x319813,_0x3eb493=this;_0x1dc856||(_0x1dc856=function(_0x3a936d,_0x41fc20){return _0x3a936d[_0x41fc20];});var _0x46d2fc=_0x3c3387[_0x136827(0x2b9)](),_0x122dfb=_0x32adee['expressionsToEvaluate']||{},_0x24103f=_0x32adee[_0x136827(0x2b4)],_0x75f095=_0x32adee[_0x136827(0x266)];try{var _0x49c4e2=this[_0x136827(0x2c6)](_0xfd99b1),_0x569cb0=_0x46d2fc;_0x49c4e2&&_0x569cb0[0x0]==='\\x27'&&(_0x569cb0=_0x569cb0[_0x136827(0x1f1)](0x1,_0x569cb0[_0x136827(0x271)]-0x2));var _0x1d9e58=_0x32adee[_0x136827(0x261)]=_0x122dfb[_0x136827(0x2cc)+_0x569cb0];_0x1d9e58&&(_0x32adee[_0x136827(0x2b4)]=_0x32adee[_0x136827(0x2b4)]+0x1),_0x32adee[_0x136827(0x266)]=!!_0x1d9e58;var _0x41616c=typeof _0x3c3387=='symbol',_0x2f294e={'name':_0x41616c||_0x49c4e2?_0x46d2fc:this[_0x136827(0x26c)](_0x46d2fc)};if(_0x41616c&&(_0x2f294e[_0x136827(0x26d)]=!0x0),!(_0x1f2825===_0x136827(0x2ac)||_0x1f2825==='Error')){var _0x3e68f0=this[_0x136827(0x28a)](_0xfd99b1,_0x3c3387);if(_0x3e68f0&&(_0x3e68f0[_0x136827(0x260)]&&(_0x2f294e['setter']=!0x0),_0x3e68f0[_0x136827(0x265)]&&!_0x1d9e58&&!_0x32adee['resolveGetters']))return _0x2f294e[_0x136827(0x2b5)]=!0x0,this[_0x136827(0x214)](_0x2f294e,_0x32adee),_0x2f294e;}var _0x5bb4fc;try{_0x5bb4fc=_0x1dc856(_0xfd99b1,_0x3c3387);}catch(_0x597000){return _0x2f294e={'name':_0x46d2fc,'type':_0x136827(0x25c),'error':_0x597000[_0x136827(0x23e)]},this[_0x136827(0x214)](_0x2f294e,_0x32adee),_0x2f294e;}var _0x327880=this[_0x136827(0x24a)](_0x5bb4fc),_0x1349b9=this[_0x136827(0x2a2)](_0x327880);if(_0x2f294e[_0x136827(0x256)]=_0x327880,_0x1349b9)this[_0x136827(0x214)](_0x2f294e,_0x32adee,_0x5bb4fc,function(){var _0x53b7c4=_0x136827;_0x2f294e[_0x53b7c4(0x297)]=_0x5bb4fc[_0x53b7c4(0x2ae)](),!_0x1d9e58&&_0x3eb493[_0x53b7c4(0x252)](_0x327880,_0x2f294e,_0x32adee,{});});else{var _0x3c88c2=_0x32adee[_0x136827(0x247)]&&_0x32adee[_0x136827(0x2bd)]<_0x32adee['autoExpandMaxDepth']&&_0x32adee[_0x136827(0x237)][_0x136827(0x283)](_0x5bb4fc)<0x0&&_0x327880!==_0x136827(0x2a5)&&_0x32adee[_0x136827(0x2bc)]<_0x32adee[_0x136827(0x2c0)];_0x3c88c2||_0x32adee[_0x136827(0x2bd)]<_0x24103f||_0x1d9e58?(this['serialize'](_0x2f294e,_0x5bb4fc,_0x32adee,_0x1d9e58||{}),this[_0x136827(0x276)](_0x5bb4fc,_0x2f294e)):this['_processTreeNodeResult'](_0x2f294e,_0x32adee,_0x5bb4fc,function(){var _0x456308=_0x136827;_0x327880==='null'||_0x327880===_0x456308(0x294)||(delete _0x2f294e[_0x456308(0x297)],_0x2f294e[_0x456308(0x264)]=!0x0);});}return _0x2f294e;}finally{_0x32adee[_0x136827(0x261)]=_0x122dfb,_0x32adee[_0x136827(0x2b4)]=_0x24103f,_0x32adee[_0x136827(0x266)]=_0x75f095;}}[_0x319813(0x252)](_0x3faf7b,_0x37b5f1,_0x4b5e7c,_0x3e6180){var _0xa69532=_0x319813,_0x3fa0b1=_0x3e6180['strLength']||_0x4b5e7c['strLength'];if((_0x3faf7b==='string'||_0x3faf7b==='String')&&_0x37b5f1[_0xa69532(0x297)]){let _0x451782=_0x37b5f1[_0xa69532(0x297)]['length'];_0x4b5e7c[_0xa69532(0x272)]+=_0x451782,_0x4b5e7c[_0xa69532(0x272)]>_0x4b5e7c[_0xa69532(0x29a)]?(_0x37b5f1['capped']='',delete _0x37b5f1[_0xa69532(0x297)]):_0x451782>_0x3fa0b1&&(_0x37b5f1[_0xa69532(0x264)]=_0x37b5f1[_0xa69532(0x297)][_0xa69532(0x1f1)](0x0,_0x3fa0b1),delete _0x37b5f1[_0xa69532(0x297)]);}}[_0x319813(0x2c6)](_0x2917cd){var _0x470a2c=_0x319813;return!!(_0x2917cd&&_0x297f55[_0x470a2c(0x1f0)]&&this[_0x470a2c(0x28e)](_0x2917cd)===_0x470a2c(0x2b0)&&_0x2917cd[_0x470a2c(0x230)]);}[_0x319813(0x26c)](_0x1d16e4){var _0x36fa02=_0x319813;if(_0x1d16e4['match'](/^\\d+$/))return _0x1d16e4;var _0x294dc9;try{_0x294dc9=JSON[_0x36fa02(0x213)](''+_0x1d16e4);}catch{_0x294dc9='\\x22'+this['_objectToString'](_0x1d16e4)+'\\x22';}return _0x294dc9[_0x36fa02(0x240)](/^\"([a-zA-Z_][a-zA-Z_0-9]*)\"$/)?_0x294dc9=_0x294dc9[_0x36fa02(0x1f1)](0x1,_0x294dc9[_0x36fa02(0x271)]-0x2):_0x294dc9=_0x294dc9[_0x36fa02(0x248)](/'/g,'\\x5c\\x27')['replace'](/\\\\\"/g,'\\x22')[_0x36fa02(0x248)](/(^\"|\"$)/g,'\\x27'),_0x294dc9;}[_0x319813(0x214)](_0x2cef8c,_0x150fd6,_0x2d62a3,_0x1fd291){var _0x171c5e=_0x319813;this[_0x171c5e(0x228)](_0x2cef8c,_0x150fd6),_0x1fd291&&_0x1fd291(),this[_0x171c5e(0x276)](_0x2d62a3,_0x2cef8c),this[_0x171c5e(0x1fd)](_0x2cef8c,_0x150fd6);}[_0x319813(0x228)](_0x2c9336,_0x38e496){var _0x4287c0=_0x319813;this['_setNodeId'](_0x2c9336,_0x38e496),this[_0x4287c0(0x22d)](_0x2c9336,_0x38e496),this[_0x4287c0(0x222)](_0x2c9336,_0x38e496),this[_0x4287c0(0x219)](_0x2c9336,_0x38e496);}['_setNodeId'](_0x4b382d,_0x44d613){}[_0x319813(0x22d)](_0x1f04c3,_0x3fa6b7){}[_0x319813(0x221)](_0x1bb531,_0x352bc1){}['_isUndefined'](_0xc61b5c){var _0x5a596f=_0x319813;return _0xc61b5c===this[_0x5a596f(0x2be)];}['_treeNodePropertiesAfterFullValue'](_0x34a13a,_0x4d6d34){var _0x25fb13=_0x319813;this[_0x25fb13(0x221)](_0x34a13a,_0x4d6d34),this[_0x25fb13(0x2a1)](_0x34a13a),_0x4d6d34[_0x25fb13(0x21e)]&&this[_0x25fb13(0x1f8)](_0x34a13a),this[_0x25fb13(0x282)](_0x34a13a,_0x4d6d34),this[_0x25fb13(0x203)](_0x34a13a,_0x4d6d34),this[_0x25fb13(0x273)](_0x34a13a);}[_0x319813(0x276)](_0x549a40,_0x1ff069){var _0x2e04f6=_0x319813;let _0x291640;try{_0x297f55[_0x2e04f6(0x231)]&&(_0x291640=_0x297f55[_0x2e04f6(0x231)][_0x2e04f6(0x26f)],_0x297f55[_0x2e04f6(0x231)][_0x2e04f6(0x26f)]=function(){}),_0x549a40&&typeof _0x549a40[_0x2e04f6(0x271)]==_0x2e04f6(0x227)&&(_0x1ff069['length']=_0x549a40[_0x2e04f6(0x271)]);}catch{}finally{_0x291640&&(_0x297f55['console']['error']=_0x291640);}if(_0x1ff069[_0x2e04f6(0x256)]===_0x2e04f6(0x227)||_0x1ff069['type']===_0x2e04f6(0x226)){if(isNaN(_0x1ff069[_0x2e04f6(0x297)]))_0x1ff069[_0x2e04f6(0x21c)]=!0x0,delete _0x1ff069[_0x2e04f6(0x297)];else switch(_0x1ff069[_0x2e04f6(0x297)]){case Number[_0x2e04f6(0x23a)]:_0x1ff069[_0x2e04f6(0x204)]=!0x0,delete _0x1ff069[_0x2e04f6(0x297)];break;case Number['NEGATIVE_INFINITY']:_0x1ff069[_0x2e04f6(0x22b)]=!0x0,delete _0x1ff069['value'];break;case 0x0:this[_0x2e04f6(0x2d3)](_0x1ff069[_0x2e04f6(0x297)])&&(_0x1ff069[_0x2e04f6(0x2ad)]=!0x0);break;}}else _0x1ff069[_0x2e04f6(0x256)]==='function'&&typeof _0x549a40[_0x2e04f6(0x25b)]==_0x2e04f6(0x220)&&_0x549a40[_0x2e04f6(0x25b)]&&_0x1ff069[_0x2e04f6(0x25b)]&&_0x549a40[_0x2e04f6(0x25b)]!==_0x1ff069['name']&&(_0x1ff069['funcName']=_0x549a40[_0x2e04f6(0x25b)]);}[_0x319813(0x2d3)](_0x26fcc8){var _0x1a1495=_0x319813;return 0x1/_0x26fcc8===Number[_0x1a1495(0x242)];}['_sortProps'](_0x274db2){var _0x49d911=_0x319813;!_0x274db2['props']||!_0x274db2[_0x49d911(0x235)][_0x49d911(0x271)]||_0x274db2['type']===_0x49d911(0x2ac)||_0x274db2['type']===_0x49d911(0x1f0)||_0x274db2[_0x49d911(0x256)]===_0x49d911(0x28d)||_0x274db2[_0x49d911(0x235)][_0x49d911(0x281)](function(_0x3e5e62,_0x6750a3){var _0x389f92=_0x49d911,_0x33411e=_0x3e5e62[_0x389f92(0x25b)][_0x389f92(0x2a9)](),_0x58afcd=_0x6750a3[_0x389f92(0x25b)][_0x389f92(0x2a9)]();return _0x33411e<_0x58afcd?-0x1:_0x33411e>_0x58afcd?0x1:0x0;});}[_0x319813(0x282)](_0x1d2b63,_0x329f22){var _0x3862c6=_0x319813;if(!(_0x329f22[_0x3862c6(0x2d5)]||!_0x1d2b63['props']||!_0x1d2b63['props'][_0x3862c6(0x271)])){for(var _0x2f4240=[],_0x2ede99=[],_0x60eec=0x0,_0x49e04d=_0x1d2b63['props'][_0x3862c6(0x271)];_0x60eec<_0x49e04d;_0x60eec++){var _0x2a32cd=_0x1d2b63[_0x3862c6(0x235)][_0x60eec];_0x2a32cd[_0x3862c6(0x256)]==='function'?_0x2f4240[_0x3862c6(0x1f5)](_0x2a32cd):_0x2ede99['push'](_0x2a32cd);}if(!(!_0x2ede99[_0x3862c6(0x271)]||_0x2f4240['length']<=0x1)){_0x1d2b63[_0x3862c6(0x235)]=_0x2ede99;var _0x3bc5d4={'functionsNode':!0x0,'props':_0x2f4240};this[_0x3862c6(0x2a7)](_0x3bc5d4,_0x329f22),this[_0x3862c6(0x221)](_0x3bc5d4,_0x329f22),this[_0x3862c6(0x2a1)](_0x3bc5d4),this[_0x3862c6(0x219)](_0x3bc5d4,_0x329f22),_0x3bc5d4['id']+='\\x20f',_0x1d2b63['props']['unshift'](_0x3bc5d4);}}}[_0x319813(0x203)](_0x4d6091,_0x168232){}[_0x319813(0x2a1)](_0x4c7f9c){}[_0x319813(0x268)](_0x59357a){var _0x1f40f0=_0x319813;return Array[_0x1f40f0(0x285)](_0x59357a)||typeof _0x59357a=='object'&&this[_0x1f40f0(0x28e)](_0x59357a)===_0x1f40f0(0x205);}['_setNodePermissions'](_0x302590,_0x5c62d7){}[_0x319813(0x273)](_0xa9389f){var _0x4289ad=_0x319813;delete _0xa9389f[_0x4289ad(0x2cf)],delete _0xa9389f['_hasSetOnItsPath'],delete _0xa9389f[_0x4289ad(0x234)];}['_setNodeExpressionPath'](_0x5029da,_0x3e1815){}[_0x319813(0x223)](_0x6b4382){var _0x21e7f5=_0x319813;return _0x6b4382?_0x6b4382[_0x21e7f5(0x240)](this[_0x21e7f5(0x236)])?'['+_0x6b4382+']':_0x6b4382[_0x21e7f5(0x240)](this[_0x21e7f5(0x1f2)])?'.'+_0x6b4382:_0x6b4382['match'](this[_0x21e7f5(0x224)])?'['+_0x6b4382+']':'[\\x27'+_0x6b4382+'\\x27]':'';}}let _0x42634f=new _0x23b763();function _0x7c6ce(_0x5bba14,_0x15eed6,_0x2e974a,_0x55999a,_0x43cf7a,_0x67ff5){var _0x1779d9=_0x319813;let _0x26fd64,_0x2d3028;try{_0x2d3028=_0x2b0921(),_0x26fd64=_0xde8c09[_0x15eed6],!_0x26fd64||_0x2d3028-_0x26fd64['ts']>0x1f4&&_0x26fd64[_0x1779d9(0x26b)]&&_0x26fd64[_0x1779d9(0x24b)]/_0x26fd64[_0x1779d9(0x26b)]<0x64?(_0xde8c09[_0x15eed6]=_0x26fd64={'count':0x0,'time':0x0,'ts':_0x2d3028},_0xde8c09[_0x1779d9(0x200)]={}):_0x2d3028-_0xde8c09[_0x1779d9(0x200)]['ts']>0x32&&_0xde8c09[_0x1779d9(0x200)]['count']&&_0xde8c09[_0x1779d9(0x200)][_0x1779d9(0x24b)]/_0xde8c09[_0x1779d9(0x200)]['count']<0x64&&(_0xde8c09[_0x1779d9(0x200)]={});let _0x3aafb9=[],_0x37c417=_0x26fd64[_0x1779d9(0x29e)]||_0xde8c09[_0x1779d9(0x200)]['reduceLimits']?_0x333990:_0x3d2413,_0x167e45=_0x31be77=>{var _0x58c659=_0x1779d9;let _0x1781f0={};return _0x1781f0['props']=_0x31be77[_0x58c659(0x235)],_0x1781f0['elements']=_0x31be77[_0x58c659(0x25d)],_0x1781f0['strLength']=_0x31be77[_0x58c659(0x2c7)],_0x1781f0['totalStrLength']=_0x31be77[_0x58c659(0x29a)],_0x1781f0[_0x58c659(0x2c0)]=_0x31be77[_0x58c659(0x2c0)],_0x1781f0[_0x58c659(0x28b)]=_0x31be77[_0x58c659(0x28b)],_0x1781f0[_0x58c659(0x21e)]=!0x1,_0x1781f0['noFunctions']=!_0x53ed3a,_0x1781f0[_0x58c659(0x2b4)]=0x1,_0x1781f0['level']=0x0,_0x1781f0['expId']=_0x58c659(0x251),_0x1781f0[_0x58c659(0x25e)]=_0x58c659(0x201),_0x1781f0['autoExpand']=!0x0,_0x1781f0[_0x58c659(0x237)]=[],_0x1781f0[_0x58c659(0x2bc)]=0x0,_0x1781f0[_0x58c659(0x207)]=!0x0,_0x1781f0['allStrLength']=0x0,_0x1781f0[_0x58c659(0x259)]={'current':void 0x0,'parent':void 0x0,'index':0x0},_0x1781f0;};for(var _0xd5a763=0x0;_0xd5a763<_0x43cf7a['length'];_0xd5a763++)_0x3aafb9['push'](_0x42634f[_0x1779d9(0x21f)]({'timeNode':_0x5bba14==='time'||void 0x0},_0x43cf7a[_0xd5a763],_0x167e45(_0x37c417),{}));if(_0x5bba14===_0x1779d9(0x2cb)){let _0x2ea77a=Error[_0x1779d9(0x29d)];try{Error[_0x1779d9(0x29d)]=0x1/0x0,_0x3aafb9['push'](_0x42634f[_0x1779d9(0x21f)]({'stackNode':!0x0},new Error()['stack'],_0x167e45(_0x37c417),{'strLength':0x1/0x0}));}finally{Error[_0x1779d9(0x29d)]=_0x2ea77a;}}return{'method':_0x1779d9(0x210),'version':_0x1413e4,'args':[{'ts':_0x2e974a,'session':_0x55999a,'args':_0x3aafb9,'id':_0x15eed6,'context':_0x67ff5}]};}catch(_0xffc067){return{'method':_0x1779d9(0x210),'version':_0x1413e4,'args':[{'ts':_0x2e974a,'session':_0x55999a,'args':[{'type':'unknown','error':_0xffc067&&_0xffc067[_0x1779d9(0x23e)]}],'id':_0x15eed6,'context':_0x67ff5}]};}finally{try{if(_0x26fd64&&_0x2d3028){let _0x4e863f=_0x2b0921();_0x26fd64[_0x1779d9(0x26b)]++,_0x26fd64[_0x1779d9(0x24b)]+=_0x36c28f(_0x2d3028,_0x4e863f),_0x26fd64['ts']=_0x4e863f,_0xde8c09[_0x1779d9(0x200)][_0x1779d9(0x26b)]++,_0xde8c09[_0x1779d9(0x200)][_0x1779d9(0x24b)]+=_0x36c28f(_0x2d3028,_0x4e863f),_0xde8c09['hits']['ts']=_0x4e863f,(_0x26fd64[_0x1779d9(0x26b)]>0x32||_0x26fd64[_0x1779d9(0x24b)]>0x64)&&(_0x26fd64[_0x1779d9(0x29e)]=!0x0),(_0xde8c09[_0x1779d9(0x200)]['count']>0x3e8||_0xde8c09[_0x1779d9(0x200)][_0x1779d9(0x24b)]>0x12c)&&(_0xde8c09[_0x1779d9(0x200)][_0x1779d9(0x29e)]=!0x0);}}catch{}}}return _0x297f55['_console_ninja'];})(globalThis,'127.0.0.1',_0x452e92(0x299),\"c:\\\\Users\\\\Administrator\\\\.vscode\\\\extensions\\\\wallabyjs.console-ninja-0.0.191\\\\node_modules\",_0x452e92(0x287),_0x452e92(0x20a),_0x452e92(0x279),_0x452e92(0x24f),_0x452e92(0x28f));")}catch(e){}})().consoleLog(e,t)}catch(e){}return t}("163540c6_0","titleFnJs",e))}return e.titleFn?e.titleFn(e):String(e.title)}setText(e){const t=this.box.getBoundingClientRect();let i=globalThis.marked;const n=hn.getTitle(e);if(i){this.text.innerHTML=i(n);const e=this.text.getElementsByTagName("A");for(let t=0;t<e.length;++t)e[t].setAttribute("target","_blank")}else this.text.innerHTML=n;return t}updateText(e){if(this.currentPen?.id!==e.id)return;if(hn.titleEmpty(e))return;const t=this.setText(e),i=this.box.getBoundingClientRect();this.changePositionByText(t,i)}changePositionByText(e,t){this.x-=(t.width-e.width)/2,this.y-=t.height-e.height,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px"}static titleEmpty(e){return!e.title&&!e.titleFn&&!e.titleFnJs}show(e,t){if(this.currentPen=e,hn.titleEmpty(e)){let i=se(e,!0);return void(i&&this.show(i,t))}this.setText(e);const i=this.box.getBoundingClientRect(),n=e.calculative.worldRect;let r=e.calculative.canvas.store.data.x+t.x-i.width/2,o=e.calculative.canvas.store.data.y+t.y-i.height;e.type||(r=e.calculative.canvas.store.data.x+n.x-(i.width-n.width)/2,o=e.calculative.canvas.store.data.y+n.ey-i.height-n.height),o>0?(this.arrowUp.style.borderBottomColor="transparent",this.arrowDown.style.borderTopColor="#777777"):(o+=i.height+n.height+5,this.arrowUp.style.borderBottomColor="#777777",this.arrowDown.style.borderTopColor="transparent"),this.x=r,this.y=o,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px"}hide(){this.currentPen=null,this.x=-9999,this.box.style.left="-9999px"}translate(e,t){this.x<-1e3||(this.x+=e,this.y+=t,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px")}destroy(){this.box.onmouseleave=null}}class un{constructor(e){let t;this.parent=e,this.onMouseDownH=e=>{e.preventDefault(),e.stopPropagation(),this.isDownH=e.x,this.x=this.parent.store.data.x||0,this.lastScrollX=this.scrollX},this.onMouseDownV=e=>{e.preventDefault(),e.stopPropagation(),this.isDownV=e.y,this.y=this.parent.store.data.y||0,this.lastScrollY=this.scrollY},this.onMouseMove=e=>{if(this.isDownH){const t=e.x-this.isDownH;this.scrollX=this.lastScrollX+t,this.h.style.left=`${this.scrollX}px`,this.parent.store.data.x=this.x-t*this.rect.width/this.parent.parentElement.clientWidth}if(this.isDownV){const t=e.y-this.isDownV;if(this.pageMode&&this.canMouseMove(t))return;this.scrollY=this.lastScrollY+t,this.v.style.top=`${this.scrollY}px`,this.parent.store.data.y=this.y-t*this.rect.height/this.parent.parentElement.clientHeight}(this.isDownH||this.isDownV)&&(this.parent.onMovePens(),this.parent.canvasImage.init(),this.parent.canvasImageBottom.init(),this.parent.render())},this.onMouseUp=e=>{(this.isDownH||this.isDownV)&&(this.isDownH=void 0,this.isDownV=void 0,this.scrollX<20?(this.scrollX=20,this.h.style.left=`${this.scrollX}px`):this.scrollX>this.parent.parentElement.clientWidth-this.hSize-20&&(this.scrollX=this.parent.parentElement.clientWidth-this.hSize-20,this.h.style.left=`${this.scrollX}px`),this.scrollY<20?(this.scrollY=20,this.v.style.top=`${this.scrollY}px`):this.scrollY>this.parent.parentElement.clientHeight-this.vSize-20&&(this.scrollY=this.parent.parentElement.clientHeight-this.vSize-20,this.v.style.top=`${this.scrollY}px`),this.resize())},this.h=document.createElement("div"),this.v=document.createElement("div"),this.parent.externalElements.appendChild(this.h),this.parent.externalElements.appendChild(this.v),this.h.className="meta2d-scroll h",this.h.onmousedown=this.onMouseDownH,this.v.className="meta2d-scroll v",this.v.onmousedown=this.onMouseDownV,document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp);for(let e=0;e<document.styleSheets.length;e++)"le5le/scroll"===document.styleSheets[e].title&&(t=document.styleSheets[e]);if(!t){let e=document.createElement("style");e.type="text/css",e.title="le5le.com/scroll",document.head.appendChild(e),e=document.createElement("style"),e.type="text/css",document.head.appendChild(e),t=e.sheet,t.insertRule(".meta2d-scroll{position:absolute;width:8px;height:200px;background:#dddddd;border-radius:10px;z-index:20;cursor:default;}"),t.insertRule(".meta2d-scroll:hover{background:#cccccc;cursor:pointer}"),t.insertRule(".meta2d-scroll.v{right:0;top:calc(50% - 100px);}"),t.insertRule(".meta2d-scroll.h{bottom:2px;left:calc(50% - 100px);width:200px;height:8px;}")}this.init()}init(){this.isShow=!0,this.resize(),this.initPos()}canMouseMove(e){const t=this.parent.parent.getRect();return e<0&&t.y+this.parent.store.data.y>=0||e>0&&t.ey-this.parent.height+this.parent.store.data.y<=0}changeMode(){this.pageMode=!0,this.h.style.display="none",this.parent.parent.getRect().height<this.parent.height&&(this.v.style.display="none")}initPos(){this.scrollX=(this.parent.parentElement.clientWidth-this.hSize)/2,this.scrollY=(this.parent.parentElement.clientHeight-this.vSize)/2,this.h.style.left=`${this.scrollX}px`,this.v.style.top=`${this.scrollY}px`}resize(){this.rect=St(this.parent.store.data.pens),this.rect.width<1400&&(this.rect.width=1400),this.rect.height<900&&(this.rect.height=900),this.parent.store.data.x>0?this.rect.width+=this.parent.store.data.x+(this.rect.x>0?0:this.rect.x):this.rect.width-=this.parent.store.data.x+(this.rect.x>0?0:this.rect.x),this.parent.store.data.y>0?this.rect.height+=this.parent.store.data.y+(this.rect.y>0?0:this.rect.y):this.rect.height-=this.parent.store.data.y+(this.rect.y>0?0:this.rect.y),this.rect.width<1400&&(this.rect.width=1400),this.rect.height<900&&(this.rect.height=900),this.hSize=1e3*this.parent.parentElement.clientWidth/this.rect.width/3,this.vSize=1e3*this.parent.parentElement.clientHeight/this.rect.height/3,this.h.style.width=this.hSize+"px",this.v.style.height=this.vSize+"px"}show(){this.isShow=!0,this.h.style.display="block",this.v.style.display="block",document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp)}hide(){this.isShow=!1,this.h.style.display="none",this.v.style.display="none",this.destroy()}translate(e,t){e&&(this.scrollX-=e*this.parent.parentElement.clientWidth/this.rect.width,this.h.style.left=`${this.scrollX}px`),t&&(this.scrollY-=t*this.parent.parentElement.clientHeight/this.rect.height,this.v.style.top=`${this.scrollY}px`)}wheel(e){let t=10;e&&(t=-10),this.pageMode&&this.canMouseMove(t)||(this.scrollY+=t,this.v.style.top=`${this.scrollY}px`,this.parent.store.data.y-=t*this.rect.height/this.parent.parentElement.clientHeight,this.parent.onMovePens(),this.parent.canvasImage.init(),this.parent.canvasImageBottom.init(),this.parent.render())}destroy(){document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp)}}class dn{constructor(e,t,i){this.parentElement=e,this.store=t,this.isBottom=i,this.canvas=document.createElement("canvas"),this.otherOffsreen=ln(),this.offscreen=ln(),this.animateOffsScreen=ln(),e.appendChild(this.canvas),this.canvas.style.backgroundRepeat="no-repeat",this.canvas.style.backgroundSize="100% 100%",this.canvas.style.position="absolute",this.canvas.style.top="0",this.canvas.style.left="0"}resize(e,t){this.canvas.style.width=e+"px",this.canvas.style.height=t+"px",e=e*this.store.dpiRatio|0,t=t*this.store.dpiRatio|0,this.canvas.width=e,this.canvas.height=t,this.otherOffsreen.width=e,this.otherOffsreen.height=t,this.offscreen.width=e,this.offscreen.height=t,this.animateOffsScreen.width=e,this.animateOffsScreen.height=t,this.otherOffsreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.otherOffsreen.getContext("2d").textBaseline="middle",this.offscreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.offscreen.getContext("2d").textBaseline="middle",this.animateOffsScreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.animateOffsScreen.getContext("2d").textBaseline="middle",this.init()}init(){this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.animateOffsScreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height);for(const e of this.store.data.pens)this.hasImage(e)&&(e.calculative.imageDrawed=!1);this.store.patchFlagsBackground=!0,this.store.patchFlagsTop=!0}clear(){this.otherOffsreen.getContext("2d").clearRect(0,0,this.otherOffsreen.width,this.otherOffsreen.height),this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.animateOffsScreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.canvas.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height)}hasImage(e){return e.calculative.hasImage=e.calculative&&e.calculative.inView&&!e.isBottom==!this.isBottom&&e.image&&e.calculative.img&&"gif"!==e.name,e.calculative.hasImage}render(){let e=!1,t=!1;for(const i of this.store.data.pens)this.hasImage(i)&&(this.store.animates.has(i)?t=!0:i.calculative.imageDrawed||(e=!0),i.parentId&&this.store.animates.has(se(i,!0))&&(t=!0));const i=this.store.patchFlagsBackground;if(i&&this.isBottom){const e=this.otherOffsreen.getContext("2d");e.clearRect(0,0,this.canvas.width,this.canvas.height);const t=this.store.data.width||this.store.options.width,i=this.store.data.height||this.store.options.height;t&&i&&this.store.bkImg&&(e.save(),e.drawImage(this.store.bkImg,this.store.data.origin.x+this.store.data.x,this.store.data.origin.y+this.store.data.y,this.store.data.width*this.store.data.scale,this.store.data.height*this.store.data.scale),e.restore());const n=this.store.data.background||this.store.options.background;if(n){e.save(),e.fillStyle=n;const t=this.store.data.width||this.store.options.width,i=this.store.data.height||this.store.options.height;if(t&&i){const n=this.store.data.x||this.store.options.x,r=this.store.data.y||this.store.options.y;e.fillRect(this.store.data.origin.x+n,this.store.data.origin.y+r,t*this.store.data.scale,i*this.store.data.scale)}else e.fillRect(0,0,this.canvas.width,this.canvas.height);e.restore()}this.renderGrid(e)}const n=this.store.patchFlagsTop;if(n&&!this.isBottom){const e=this.otherOffsreen.getContext("2d");e.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderRule(e)}if(this.store.patchFlagsLast&&this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),e){const e=this.offscreen.getContext("2d");e.save(),e.clearRect(0,0,this.canvas.width,this.canvas.height),e.translate(this.store.data.x,this.store.data.y);for(const t of this.store.data.pens)!t.calculative.hasImage||this.store.animates.has(t)||this.store.animates.has(se(t,!0))||(t.calculative.imageDrawed=!0,e.save(),Se(e,t),t.calculative.rotate&&Pe(e,t),ut(e,t),be(e,t),e.restore());e.restore()}if(t){const e=this.animateOffsScreen.getContext("2d");e.save(),e.clearRect(0,0,this.canvas.width,this.canvas.height),e.translate(this.store.data.x,this.store.data.y);for(const t of this.store.animates)t.calculative.hasImage&&(t.calculative.imageDrawed=!0,e.save(),Se(e,t),t.calculative.rotate&&Pe(e,t),ut(e,t),be(e,t),e.restore());for(const t of this.store.data.pens)t.calculative.hasImage&&t.parentId&&this.store.animates.has(se(t,!0))&&(t.calculative.imageDrawed=!0,e.save(),Se(e,t),t.calculative.rotate&&Pe(e,t),ut(e,t),be(e,t),e.restore());e.restore()}if(e||t||i&&this.isBottom||n&&!this.isBottom){const e=this.canvas.getContext("2d");e.clearRect(0,0,this.canvas.width,this.canvas.height),this.isBottom&&(e.drawImage(this.otherOffsreen,0,0,this.canvas.width,this.canvas.height),this.store.patchFlagsBackground=!1),e.drawImage(this.offscreen,0,0,this.canvas.width,this.canvas.height),e.drawImage(this.animateOffsScreen,0,0,this.canvas.width,this.canvas.height),this.isBottom||(e.drawImage(this.otherOffsreen,0,0,this.canvas.width,this.canvas.height),this.store.patchFlagsTop=!1)}}renderGrid(e){const{data:t,options:i}=this.store,{grid:n,gridRotate:r,gridColor:o,gridSize:s,scale:a}=t;if(!(n??i.grid))return;e.save();const{width:c,height:l}=this.canvas;r&&(e.translate(c/2,l/2),e.rotate(r*Math.PI/180),e.translate(-c/2,-l/2)),e.lineWidth=1,e.strokeStyle=o||i.gridColor,e.beginPath();const h=(s||i.gridSize)*a,u=Math.max(c,l),d=Math.ceil(u/h);for(let t=-h*d;t<2*u;t+=h)e.moveTo(t,-u),e.lineTo(t,2*u);for(let t=-h*d;t<2*u;t+=h)e.moveTo(-u,t),e.lineTo(2*u,t);e.stroke(),e.restore()}renderRule(e){const{data:t,options:i}=this.store,{rule:n,ruleColor:r,scale:o,origin:s}=t;if(!(n??i.rule))return;const a=10*o;e.save();const c=r||i.ruleColor;e.strokeStyle=ee(c,.7);const l=s.x+t.x,h=s.y+t.y,{width:u,height:d}=this.canvas;e.beginPath(),e.lineWidth=12,e.lineDashOffset=-l%a,e.setLineDash([1,a-1]),e.moveTo(0,0),e.lineTo(u,0),e.stroke(),e.beginPath(),e.lineDashOffset=-h%a,e.moveTo(0,0),e.lineTo(0,d),e.stroke(),e.strokeStyle=c,e.beginPath(),e.lineWidth=24,e.lineDashOffset=-l%(10*a),e.setLineDash([1,10*a-1]),e.moveTo(0,0),e.lineTo(u,0),e.stroke(),e.beginPath(),e.lineDashOffset=-h%(10*a),e.moveTo(0,0),e.lineTo(0,d),e.stroke(),e.beginPath(),e.fillStyle=e.strokeStyle;let f=0-100*Math.floor(l/a/10);l<0&&(f-=100);for(let t=l%(10*a);t<u;t+=10*a,f+=100)a<3&&f%500||e.fillText(f.toString(),t+4,16);f=0-100*Math.floor(h/a/10),h<0&&(f-=100);for(let t=h%(10*a);t<d;t+=10*a,f+=100)a<3&&f%500||(e.save(),e.beginPath(),e.translate(16,t-4),e.rotate(270*Math.PI/180),e.fillText(f.toString(),0,0),e.restore());e.restore()}}class fn{constructor(e,t,i){this.parentCanvas=e,this.parentElement=t,this.store=i,this.canvas=document.createElement("canvas"),this.magnifierScreen=ln(),this.offscreen=ln(),this.magnifierSize=300,t.appendChild(this.canvas),this.canvas.style.backgroundRepeat="no-repeat",this.canvas.style.backgroundSize="100% 100%",this.canvas.style.position="absolute",this.canvas.style.top="0",this.canvas.style.left="0"}resize(e,t){this.canvas.style.width=e+"px",this.canvas.style.height=t+"px",e=e*this.store.dpiRatio|0,t=t*this.store.dpiRatio|0,this.canvas.width=e,this.canvas.height=t,this.offscreen.width=e,this.offscreen.height=t,this.offscreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.offscreen.getContext("2d").textBaseline="middle",this.magnifierScreen.width=this.magnifierSize+5,this.magnifierScreen.height=this.magnifierSize+5}renderMagnifier(){if(!this.magnifier)return;const e=this.magnifierSize/2,t=this.magnifierSize+5,i=this.magnifierScreen.getContext("2d");i.clearRect(0,0,t,t),i.lineWidth=5,i.save(),i.translate(2.5,2.5),i.save(),i.arc(e,e,e,0,2*Math.PI,!1),i.clip(),i.fillStyle=this.store.data.background||this.store.options.background||"#f4f4f4",i.fillRect(0,0,t,t),i.translate(-e,-e),i.scale(2,2);const n=(this.parentCanvas.mousePos.x+this.store.data.x)*this.store.dpiRatio,r=(this.parentCanvas.mousePos.y+this.store.data.y)*this.store.dpiRatio;[this.parentCanvas.canvasImageBottom.offscreen,this.parentCanvas.canvasImageBottom.animateOffsScreen,this.parentCanvas.offscreen,this.parentCanvas.canvasImage.offscreen,this.parentCanvas.canvasImage.animateOffsScreen].forEach((t=>{i.drawImage(t,n-e,r-e,this.magnifierSize,this.magnifierSize,0,0,this.magnifierSize,this.magnifierSize)})),i.restore(),i.beginPath();const o=i.createRadialGradient(e,e,e-5,e,e,e);o.addColorStop(0,"rgba(0,0,0,0.2)"),o.addColorStop(.8,"rgb(200,200,200)"),o.addColorStop(.9,"rgb(200,200,200)"),o.addColorStop(1,"rgba(200,200,200,0.9)"),i.strokeStyle=o,i.arc(e,e,e,0,2*Math.PI,!1),i.stroke(),i.restore(),this.offscreen.getContext("2d").drawImage(this.magnifierScreen,0,0,this.magnifierSize+5,this.magnifierSize+5,(n-e-2.5)/this.store.dpiRatio,(r-e-2.5)/this.store.dpiRatio,(this.magnifierSize+5)/this.store.dpiRatio,(this.magnifierSize+5)/this.store.dpiRatio)}render(){this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.renderMagnifier();const e=this.canvas.getContext("2d");e.clearRect(0,0,this.canvas.width,this.canvas.height),e.drawImage(this.offscreen,0,0,this.canvas.width,this.canvas.height)}}function pn(e){if(e.data.locked)throw new Error("canvas is locked")}class vn{constructor(e){this.parentElement=e,this.box=document.createElement("div"),this.dialog=document.createElement("div");let t=document.createElement("div");this.title=document.createElement("div"),this.close=document.createElement("span"),this.close.innerHTML='\n <svg fill="none" viewBox="0 0 16 16" width="1em" height="1em">\n <path\n fill="currentColor"\n d="M8 8.92L11.08 12l.92-.92L8.92 8 12 4.92 11.08 4 8 7.08 4.92 4 4 4.92 7.08 8 4 11.08l.92.92L8 8.92z"\n fill-opacity="0.9"\n ></path>\n </svg>';let i,n=document.createElement("div");this.iframe=document.createElement("iframe"),this.iframe.setAttribute("frameborder","0"),this.box.className="meta2d-dialog_mask",this.dialog.className="meta2d-dialog",n.className="meta2d-dialog_body",t.className="meta2d-dialog_header",this.title.className="meta2d-dialog-content",this.close.className="meta2d-dialog-close",t.appendChild(this.title),t.appendChild(this.close),n.appendChild(this.iframe),this.dialog.appendChild(t),this.dialog.appendChild(n),this.box.appendChild(this.dialog),e.appendChild(this.box),this.dialog.onclick=e=>{e.stopPropagation()},this.box.onclick=()=>{this.hide()},this.close.onclick=()=>{this.hide()};for(let e=0;e<document.styleSheets.length;e++)"le5le.com/dialog"===document.styleSheets[e].title&&(i=document.styleSheets[e]);if(!i){let e=document.createElement("style");e.type="text/css",e.title="le5le.com/dialog",document.head.appendChild(e),e=document.createElement("style"),e.type="text/css",document.head.appendChild(e),i=e.sheet,i.insertRule(".meta2d-dialog_mask {\n display: none;\n position: absolute;\n top: 0%;\n left: 0%;\n width: 100%;\n height: 100%;\n background-color: #0000006f;\n z-index: 9999;"),i.insertRule(".meta2d-dialog_mask .meta2d-dialog {\n position: absolute;\n top: 15vh;\n left: 10%;\n width: 80%;\n padding: 16px 20px;\n border-radius: 9px;\n background-color: #1e2430;\n z-index: 19999;\n overflow: auto;\n }"),i.insertRule(".meta2d-dialog_header {\n display: flex;\n }"),i.insertRule(".meta2d-dialog-content {\n width: calc(100% - 20px);\n font-weight: 600;\n font-size: 14px;\n color: #bdc7db;\n }"),i.insertRule(".meta2d-dialog-close {\n width: 20px;\n height: 20px;\n line-height: 20px;\n text-align: center;\n color: #617b91;\n }"),i.insertRule(".meta2d-dialog-close :hover{\n cursor: pointer;\n }"),i.insertRule(".meta2d-dialog_body{\n margin-top: 4px;\n } "),i.insertRule(".meta2d-dialog_body iframe{\n width: 100%;\n height: 400px;\n }")}}show(e,t){this.box.style.display="block",t&&this.iframe.setAttribute("src",t),e&&(this.title.innerText=e)}hide(){this.box.style.display="none"}destroy(){this.dialog.onclick=void 0,this.box.onclick=void 0,this.close.onclick=void 0}}function xn(e,t){if(null==t)return e;const i=t.split(".");for(;i.length&&(e=e[i.shift()]););return e}function gn(e,t,i){null!=t&&t.split(".").reduce(((e,n,r)=>e[n]=t.split(".").length===++r?i:e[n]||{}),e)}class yn{constructor(e){let t;this.parentElement=e,this.box=document.createElement("div"),this.box.className="meta2d-title",e.appendChild(this.box),this.box.onmouseleave=()=>{this.hide()};for(let e=0;e<document.styleSheets.length;e++)"le5le.com/title"===document.styleSheets[e].title&&(t=document.styleSheets[e]);if(!t){let e=document.createElement("style");e.type="text/css",e.title="le5le.com/title",document.head.appendChild(e),e=document.createElement("style"),e.type="text/css",document.head.appendChild(e),t=e.sheet,t.insertRule(".meta2d-title{position:absolute;padding:0;z-index:10;left: -9999px;top: -9999px;width:8px;height:8px;cursor: crosshair;}")}}static getTitle(e){}setText(e){this.box.title=e.title}updateText(e){this.currentAnchor?.id===e.id&&(yn.titleEmpty(e)||(this.setText(e),this.changePositionByAnchor(e)))}changePositionByAnchor(e){this.box.style.left=e.x-4+"px",this.box.style.top=e.y-4+"px"}static titleEmpty(e){return!e.title}show(e,t){if(yn.titleEmpty(e))return;this.currentAnchor=e,this.setText(e);let i={x:t.calculative.canvas.store.data.x+e.x,y:t.calculative.canvas.store.data.y+e.y};this.changePositionByAnchor(i)}hide(){this.box.style.left="-9999px",this.box.title="",this.currentAnchor=null}destroy(){this.box.onmouseleave=null}}const mn="-moving";class bn{constructor(e,t,i){this.parent=e,this.parentElement=t,this.store=i,this.canvas=document.createElement("canvas"),this.offscreen=ln(),this.externalElements=document.createElement("div"),this.lastRotate=0,this.hoverType=v.None,this.resizeIndex=0,this.lastOffsetX=0,this.lastOffsetY=0,this.drawLineFns=[...w],this.patchFlagsLines=new Set,this.lastMouseTime=0,this.hoverTimer=0,this.patchFlags=!1,this.lastRender=0,this.touchStart=0,this.lastAnimateRender=0,this.animateRendering=!1,this.pointSize=8,this.pasteOffset=!0,this.opening=!1,this.maxZindex=4,this.canMoveLine=!1,this.inputParent=document.createElement("div"),this.inputDiv=document.createElement("div"),this.inputRight=document.createElement("div"),this.dropdown=document.createElement("ul"),this.mousePos={x:0,y:0},this.autoPolylineFlag=!1,this.stopPropagation=e=>{e.stopPropagation()},this.curve=Kt,this.polyline=ui,this.mind=Qt,this.line=Zt,this.onCopy=e=>{this.store.options.disableClipboard||e.target!==this.externalElements&&e.target!==document.body&&e.target.offsetParent!==this.externalElements||this.copy()},this.onCut=e=>{this.store.options.disableClipboard||e.target!==this.externalElements&&e.target!==document.body&&e.target.offsetParent!==this.externalElements||this.cut()},this.onPaste=e=>{if(this.store.options.disableClipboard)return;if(e.target!==this.externalElements&&e.target!==document.body&&e.target.offsetParent!==this.externalElements)return;let t;if(navigator.clipboard&&e.clipboardData){const i=e.clipboardData.items;if(i)for(let e=0;e<i.length;e++)if(-1!==i[e].type.indexOf("image")&&i[e].getAsFile()){t=!0;break}}if(t){const t=e.clipboardData.items;if(t)for(let e=0;e<t.length;e++)if(-1!==t[e].type.indexOf("image")&&t[e].getAsFile()){const{x:i,y:n}=this.mousePos,r=t[e].getAsFile();let o="gif"===t[e].type.slice(6)?"gif":"image";if(null!==r){let e;const t=new FileReader;t.onload=t=>{e=t.target.result;const r=new Image;r.src=e,r.onload=()=>{const{width:t,height:s}=r,a={name:o,x:i-25,y:n-s/t*50,externElement:"gif"===o,width:100,height:s/t*100,image:e};this.addPens([a]),this.active([a]),this.copy([a])}},t.readAsDataURL(r)}}}else this.paste()},this.onwheel=e=>{if("true"===this.inputDiv.contentEditable)return;if(this.drawingLine)return;if(this.pencil)return;if(this.store.options.disableScale)return;if(e.preventDefault(),e.stopPropagation(),this.mouseDown&&(this.hoverType===v.Node||this.hoverType===v.Line))return;if(this.store.data.locked===o.Disable)return;if(this.store.data.locked===o.DisableScale)return;if(this.store.data.locked===o.DisableMoveScale)return;if(!e.ctrlKey&&Math.abs(e.wheelDelta)<100)return this.store.options.scroll&&!e.metaKey&&this.scroll?void this.scroll.wheel(e.deltaY<0):void this.translate(-e.deltaX,-e.deltaY);if(this.store.options.disableTouchPadScale)return;let t=.015;/mac os /i.test(navigator.userAgent)?e.ctrlKey?e.deltaY>0&&(t*=-1):t*=e.wheelDeltaY/240:t=e.deltaY>0?-.2:.2;const{offsetX:i,offsetY:n}=e;this.scale(this.store.data.scale+t,{x:i,y:n}),this.externalElements.focus()},this.onkeydown=e=>{if(this.store.data.locked>=o.DisableEdit&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&this.store.active.forEach((t=>{t.onKeyDown?.(t,e.key)})),this.store.data.locked>=o.DisableEdit||"INPUT"===e.target.tagName||"TEXTAREA"===e.target.tagName)return;if(this.store.options.unavailableKeys.includes(e.key))return;let t=10,i=10;switch(e.key){case" ":this.hotkeyType=x.Translate;break;case"Control":this.drawingLine?this.drawingLine.calculative.drawlineH=!this.drawingLine.calculative.drawlineH:this.hotkeyType||(this.patchFlags=!0,this.hotkeyType=x.Select);break;case"Meta":break;case"Shift":1===this.store.active.length&&this.store.active[0].type&&this.store.activeAnchor?this.toggleAnchorHand():this.hotkeyType||(this.patchFlags=!0,this.hotkeyType=x.Resize);break;case"Alt":if(!e.ctrlKey&&!e.shiftKey&&this.drawingLine){const e=Xe(this.drawingLine);e!==this.drawingLine.calculative.activeAnchor?(Ve(this.drawingLine),this.drawingLine.calculative.worldAnchors.push(e)):this.drawingLine.calculative.worldAnchors.push({x:e.x,y:e.y});const t=this.drawLineFns.indexOf(this.drawingLineName);this.drawingLineName=this.drawLineFns[(t+1)%this.drawLineFns.length],this.drawingLine.lineName=this.drawingLineName,this.drawline(),this.patchFlags=!0}e.preventDefault();break;case"a":case"A":e.ctrlKey||e.metaKey?(this.active(this.store.data.pens.filter((e=>!e.parentId&&e.locked!==o.Disable))),e.preventDefault()):this.toggleAnchorMode();break;case"Delete":case"Backspace":!this.store.data.locked&&this.delete();break;case"ArrowLeft":if(this.movingAnchor){this.translateAnchor(-1,0);break}t=-10,e.shiftKey&&(t=-5),(e.ctrlKey||e.metaKey)&&(t=-1),this.translatePens(this.store.active,t,0);break;case"ArrowUp":if(this.movingAnchor){this.translateAnchor(0,-1);break}i=-10,e.shiftKey&&(i=-5),(e.ctrlKey||e.metaKey)&&(i=-1),this.translatePens(this.store.active,0,i);break;case"ArrowRight":if(this.movingAnchor){this.translateAnchor(1,0);break}e.shiftKey&&(t=5),(e.ctrlKey||e.metaKey)&&(t=1),this.translatePens(this.store.active,t,0);break;case"ArrowDown":if(this.movingAnchor){this.translateAnchor(0,1);break}e.shiftKey&&(i=5),(e.ctrlKey||e.metaKey)&&(i=1),this.translatePens(this.store.active,0,i);break;case"d":case"D":this.store.active[0]?.locked||this.removeAnchorHand();break;case"h":case"H":this.store.active[0]?.locked||this.addAnchorHand();break;case"m":case"M":this.toggleMagnifier();break;case"g":case"G":this.hoverType===v.NodeAnchor&&(this.movingAnchor=this.store.hoverAnchor,this.externalElements.style.cursor="move");break;case"s":case"S":this.store.data.locked||this.hoverType!==v.LineAnchor||this.store.hover!==this.store.active[0]||this.splitLine(this.store.active[0],this.store.hoverAnchor),(e.ctrlKey||e.metaKey)&&this.store.emitter.emit("save",{event:e});break;case"c":case"C":(e.ctrlKey||e.metaKey)&&this.store.options.disableClipboard&&this.copy();break;case"x":case"X":(e.ctrlKey||e.metaKey)&&this.store.options.disableClipboard&&this.cut();break;case"v":case"V":e.ctrlKey||e.metaKey||(this.drawingLineName?(this.finishDrawline(),this.drawingLineName=""):this.drawingLineName=this.store.options.drawingLineName),(e.ctrlKey||e.metaKey)&&this.store.options.disableClipboard&&this.paste();break;case"b":case"B":this.drawingPencil();break;case"y":case"Y":(e.ctrlKey||e.metaKey)&&this.redo();break;case"z":case"Z":e.ctrlKey||e.metaKey?this.undo():e.shiftKey&&this.redo();break;case"Enter":this.drawingLineName&&(this.finishDrawline(!0),this.store.active[0].anchors[0].connectTo?this.drawingLineName="":this.drawingLineName=this.store.options.drawingLineName),this.store.active&&(this.store.active.forEach((e=>{e.type&&(e.close=!e.close,this.store.path2dMap.set(e,N.path2dDraws.line(e)),ai(e))})),this.render());break;case"Escape":this.drawingLineName&&this.finishDrawline(),this.drawingLineName=void 0,this.stopPencil(),this.movingPens&&(this.getAllByPens(this.movingPens).forEach((e=>{this.store.pens[e.id]=void 0})),this.movingPens=void 0,this.mouseDown=void 0,this.clearDock(),this.store.active?.forEach((e=>{this.updateLines(e)})),this.calcActiveRect(),this.patchFlags=!0),this.hotkeyType=x.None,this.movingAnchor=void 0,this.magnifierCanvas.magnifier&&(this.magnifierCanvas.magnifier=!1,this.patchFlags=!0);break;case"E":case"e":this.store.options.disableAnchor=!this.store.options.disableAnchor,this.store.emitter.emit("disableAnchor",this.store.options.disableAnchor);break;case"=":(e.ctrlKey||e.metaKey)&&(this.scale(this.store.data.scale+.1),e.preventDefault(),e.stopPropagation());break;case"-":(e.ctrlKey||e.metaKey)&&(this.scale(this.store.data.scale-.1),e.preventDefault(),e.stopPropagation());break;case"l":case"L":this.canMoveLine=!0}this.render(!1)},this.onkeyup=e=>{switch(e.key){case"l":case"L":this.canMoveLine=!1}this.hotkeyType&&this.render(),this.hotkeyType<x.AddAnchor&&(this.hotkeyType=x.None)},this.ondrop=async e=>{if(this.store.data.locked)return void console.warn("canvas is locked, can not drop");e.preventDefault(),e.stopPropagation();const t=e.dataTransfer.getData("Meta2d")||e.dataTransfer.getData("Text");let i=null;try{t&&(i=JSON.parse(t))}catch(e){}if(!i){const{files:t}=e.dataTransfer;if(t.length&&t[0].type.match("image.*")){const e="image/gif"===t[0].type;i=await this.fileToPen(t[0],e)}else{if(!this.addCaches||!this.addCaches.length)return void this.store.emitter.emit("drop",void 0);i=this.addCaches,this.addCaches=[]}}if(i&&!1!==i.draggable){i=Array.isArray(i)?i:[i];const t={x:e.offsetX,y:e.offsetY};this.calibrateMouse(t),this.dropPens(i,t),this.addCaches=[]}this.store.emitter.emit("drop",i||t)},this.ontouchstart=e=>{this.store.data.locked!==o.Disable&&(this.touchStartTimer&&clearTimeout(this.touchStartTimer),this.touchStartTimer=setTimeout((()=>{this.touchStart=performance.now();const t=e.touches[0].pageX-this.clientRect.x,i=e.touches[0].pageY-this.clientRect.y,n={x:t,y:i};if(this.calibrateMouse(n),this.getHover(n),this.onMouseDown({x:t,y:i,clientX:e.touches[0].clientX,clientY:e.touches[0].clientY,pageX:e.touches[0].pageX,pageY:e.touches[0].pageY,ctrlKey:e.ctrlKey||e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,buttons:1}),2===e.touches.length)return this.initTouchDis=Math.hypot(e.touches[0].pageX-e.touches[1].pageX,e.touches[0].pageY-e.touches[1].pageY),this.initScale=this.store.data.scale,this.startTouches=e.touches,void(this.touchCenter={x:e.touches[0].pageX+(e.touches[1].pageX-e.touches[0].pageX)/2-this.clientRect.x,y:e.touches[0].pageY+(e.touches[1].pageY-e.touches[0].pageY)/2-this.clientRect.y});3===e.touches.length&&(this.store.emitter.emit("contextmenu",{e:{x:t,y:i,clientX:e.touches[0].clientX,clientY:e.touches[0].clientY,pageX:e.touches[0].pageX,pageY:e.touches[0].pageY},clientRect:this.clientRect}),e.preventDefault(),e.stopPropagation()),this.touchStartTimer=void 0}),50))},this.ontouchmove=e=>{if(this.store.data.locked===o.Disable)return;e.stopPropagation(),e.preventDefault();const t=performance.now();if(t-this.touchStart<50)return;this.touchStart=t;const i=e.touches,n=i.length,r=e.touches[0].pageX-this.clientRect.x,s=e.touches[0].pageY-this.clientRect.y;if(1===n)this.onMouseMove({x:r,y:s,clientX:e.changedTouches[0].clientX,clientY:e.changedTouches[0].clientY,pageX:e.changedTouches[0].pageX,pageY:e.changedTouches[0].pageY,ctrlKey:e.ctrlKey||e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,buttons:1});else if(2===n&&2===this.startTouches?.length){if(!this.touchMoving&&!this.touchScaling){const e=this.startTouches[0].pageX-i[0].pageX,t=this.startTouches[1].pageX-i[1].pageX,n=this.startTouches[0].pageY-i[0].pageY,r=this.startTouches[1].pageY-i[1].pageY;(e>=0&&t<0||e<=0&&t>0)&&(n>=0&&r<0||n<=0&&r>0)?this.touchScaling=!0:this.touchMoving=!0}if(this.touchScaling){if(this.store.options.disableScale)return;const e=Math.hypot(i[0].pageX-i[1].pageX,i[0].pageY-i[1].pageY)/this.initTouchDis;this.scale(this.initScale*e,$(this.touchCenter))}if(this.touchMoving){if(this.store.data.locked>=o.DisableMove&&this.store.data.locked!==o.DisableScale||this.store.options.disableScale)return;if(this.lastOffsetX){const{scale:e}=this.store.data;this.translate((r-this.lastOffsetX)/e,(s-this.lastOffsetY)/e)}this.lastOffsetX=r,this.lastOffsetY=s}}},this.ontouchend=e=>{if(this.store.data.locked===o.Disable)return;this.touchCenter=void 0,this.touchScaling=void 0,this.touchMoving=void 0,this.startTouches=void 0,this.lastOffsetX=0,this.lastOffsetY=0;const t=e.changedTouches[0].pageX-this.clientRect.x,i=e.changedTouches[0].pageY-this.clientRect.y;this.onMouseUp({x:t,y:i,clientX:e.changedTouches[0].clientX,clientY:e.changedTouches[0].clientY,pageX:e.changedTouches[0].pageX,pageY:e.changedTouches[0].pageY,ctrlKey:e.ctrlKey||e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,buttons:1}),setTimeout((()=>{this.render()}),20)},this.onGesturestart=e=>{e.preventDefault()},this.onMouseDown=e=>{if(2!==e.buttons||this.drawingLine||(this.mouseRight=g.Down),this.hideInput(),this.store.data.locked===o.Disable||1!==e.buttons&&2!==e.buttons)this.hoverType=v.None;else if(!this.magnifierCanvas.magnifier)if(this.calibrateMouse(e),this.mousePos.x=e.x,this.mousePos.y=e.y,this.mouseDown=e,this.lastMouseTime=performance.now(),this.hotkeyType!==x.AddAnchor){if(!this.store.options.autoAnchor&&!this.drawingLine&&e.shiftKey&&e.ctrlKey&&e.altKey){this.setAnchor(this.store.pointAt),this.drawingLineName=this.store.options.drawingLineName;const e=this.store.activeAnchor;if(!e)return;const t={id:ne(),x:e.x,y:e.y};this.drawingLine=this.createDrawingLine(t);let i=$e(this.drawingLine);return this.drawingLine.calculative.activeAnchor=i,qe(this.store.hover,e,this.drawingLine,t),void this.drawline()}if(this.hotkeyType!==x.Translate&&(this.mouseRight!==g.Down||this.store.options.mouseRightActive)){if(this.drawingLine){if(this.store.hoverAnchor){const e=Xe(this.drawingLine);return this.store.hoverAnchor.type===A.Line?M(e,this.store.hoverAnchor,this.store):(e.x=this.store.hoverAnchor.x,e.y=this.store.hoverAnchor.y),qe(this.store.hover,this.store.hoverAnchor,this.drawingLine,e),this.drawline(),void this.finishDrawline(!0)}if(!this.store.options.autoAnchor&&e.shiftKey&&e.altKey&&e.ctrlKey){this.setAnchor(this.store.pointAt);const e=Xe(this.drawingLine),t=this.store.activeAnchor;if(!t)return;return e.x=t.x,e.y=t.y,qe(this.store.hover,t,this.drawingLine,e),this.drawline(),void this.finishDrawline(!0)}if(2===e.buttons||"mind"===this.drawingLineName&&this.drawingLine?.calculative.worldAnchors.length>1||this.store.options.drawingLineLength&&this.drawingLine?.calculative.worldAnchors.length>this.store.options.drawingLineLength)return this.finishDrawline(!0),void(this.store.active[0]?.anchors[0].connectTo?this.drawingLineName="":this.drawingLineName=this.store.options.drawingLineName);if(this.store.options.autoAnchor&&this.hoverType===v.Node){const t=Xe(this.drawingLine),i=We(this.store.hover,e);return t.x=i.x,t.y=i.y,this.drawingLine.autoTo=!0,qe(this.store.hover,i,this.drawingLine,t),this.drawline(),void this.finishDrawline(!0)}const t=Xe(this.drawingLine);t.isTemp?(this.drawingLine.calculative.activeAnchor=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2],t.isTemp=void 0):(this.drawingLine.calculative.activeAnchor=t,this.drawingLine.calculative.worldAnchors.push({x:t.x,y:t.y,penId:t.penId})),this.drawingLine.calculative.drawlineH=void 0,"polyline"!==this.drawingLineName&&this.drawline()}if(this.drawingLineName){if(this.hoverType===v.Node)if(this.store.options.autoAnchor){this.inactive(!0);const t=We(this.store.hover,e);this.store.hoverAnchor=t;const i={id:ne(),x:t.x,y:t.y};this.drawingLine=this.createDrawingLine(i),this.drawingLine.autoFrom=!0,qe(this.store.hover,t,this.drawingLine,i)}else this.inactive(),this.hoverType=v.None;else if(this.hoverType===v.NodeAnchor){this.drawingLineName=this.store.options.drawingLineName;const e={id:ne(),x:this.store.hoverAnchor.x,y:this.store.hoverAnchor.y};this.drawingLine=this.createDrawingLine(e),this.drawingLine.calculative.activeAnchor=e,qe(this.store.hover,this.store.hoverAnchor,this.drawingLine,e)}else if(!this.drawingLine&&"curve"!==this.drawingLineName){this.inactive(!0);const t={id:ne(),x:e.x,y:e.y};this.drawingLine=this.createDrawingLine(t),this.drawingLine.calculative.activeAnchor=t}}else if(this.pencil){this.inactive(!0);const t=ne(),i={x:e.x,y:e.y,id:ne(),penId:t};this.pencilLine=this.getInitPencilLine(i)}else{switch(this.hoverType){case v.None:this.store.data.rule&&!this.store.options.disableRuleLine&&this.addRuleLine(e),this.inactive();break;case v.Node:case v.Line:if(this.store.hover){const t=se(this.store.hover,!0)||this.store.hover;e.ctrlKey&&!e.shiftKey?(t.calculative.active?this.willInactivePen=t:(t.calculative.active=!0,tt(t),this.store.active.push(t),this.store.emitter.emit("active",this.store.active)),this.patchFlags=!0):e.ctrlKey&&e.shiftKey&&this.store.hover.parentId?this.active([this.store.hover]):t.calculative.active||this.active([t]),this.calcActiveRect()}break;case v.LineAnchor:this.store.activeAnchor=this.store.hoverAnchor,this.store.hover.calculative.activeAnchor=this.store.hoverAnchor,this.active([this.store.hover]);break;case v.LineAnchorPrev:case v.LineAnchorNext:this.store.activeAnchor&&(this.prevAnchor={...this.store.activeAnchor.prev},this.nextAnchor={...this.store.activeAnchor.next});break;case v.Resize:this.activeInitPos=[],this.store.active.forEach((e=>{this.activeInitPos.push({x:(e.calculative.worldRect.x-this.activeRect.x)/this.activeRect.width,y:(e.calculative.worldRect.y-this.activeRect.y)/this.activeRect.height})}))}this.store.emitter.emit("mousedown",{x:e.x,y:e.y,pen:this.store.hover})}this.render()}}else this.setAnchor(this.store.pointAt)},this.onMouseMove=e=>{if(this.store.data.locked===o.Disable)return void(this.hoverType=v.None);if(this.mouseDown&&!this.mouseDown.restore&&1!==e.buttons&&2!==e.buttons)return void this.onMouseUp(e);if(this.lastMouseTime){if(performance.now()-this.lastMouseTime<50)return void(this.lastMouseTime=0);this.lastMouseTime=0}if(this.calibrateMouse(e),this.mousePos.x=e.x,this.mousePos.y=e.y,this.magnifierCanvas.magnifier)return void this.render();if(this.mouseDown&&!this.store.options.disableTranslate){if(this.mouseRight===g.Down&&(this.mouseRight=g.Translate),this.store.data.locked===o.DisableEdit||this.store.data.locked===o.DisableScale||this.hotkeyType===x.Translate||this.mouseRight===g.Translate){const{scale:t}=this.store.data;let i=(e.x-this.mouseDown.x)/t,n=(e.y-this.mouseDown.y)/t;return e.shiftKey&&!e.ctrlKey&&(n=0),e.ctrlKey&&(i=0),void this.translate(i,n)}if(this.store.data.locked)return;if(this.drawingLine||this.pencil){if(this.pencil){const t={...e};t.id=ne(),t.penId=this.pencilLine.id,this.pencilLine.calculative.worldAnchors.push(t),this.store.path2dMap.set(this.pencilLine,N.path2dDraws[this.pencilLine.name](this.pencilLine)),this.patchFlags=!0}}else{if(this.drawingLineName||this.movingAnchor){if(this.drawingLineName&&this.hoverType===v.None){const t={id:ne(),x:e.x,y:e.y};return this.drawingLine=this.createDrawingLine(t),this.drawingLine.calculative.activeAnchor=t,void this.drawline()}}else if(this.hoverType===v.NodeAnchor){this.drawingLineName=this.store.options.drawingLineName;const e={id:ne(),x:this.store.hoverAnchor.x,y:this.store.hoverAnchor.y};return this.drawingLine=this.createDrawingLine(e),this.drawingLine.calculative.activeAnchor=e,qe(this.store.hover,this.store.hoverAnchor,this.drawingLine,e),void this.drawline()}if(1===e.buttons&&!this.hoverType&&!this.hotkeyType)return this.dragRect={x:Math.min(this.mouseDown.x,e.x),y:Math.min(this.mouseDown.y,e.y),ex:Math.max(this.mouseDown.x,e.x),ey:Math.max(this.mouseDown.y,e.y),width:Math.abs(e.x-this.mouseDown.x),height:Math.abs(e.y-this.mouseDown.y)},void this.render();if(this.movingAnchor){const t=e.x-this.movingAnchor.x,i=e.y-this.movingAnchor.y;return this.translateAnchor(t,i),void this.render()}if(!this.store.active[0]?.locked){const t={x:e.x,y:e.y};if(this.hoverType===v.LineAnchor)return!this.dockInAnchor(e)||this.store.options.disableDock||this.store.options.disableLineDock||(this.clearDock(),this.dock=pt(this.store,t,this.store.activeAnchor),this.dock?.xDock&&(t.x+=this.dock.xDock.step),this.dock?.yDock&&(t.y+=this.dock.yDock.step)),void this.moveLineAnchor(t,e);if(this.hoverType===v.LineAnchorPrev)return void this.moveLineAnchorPrev(e);if(this.hoverType===v.LineAnchorNext)return void this.moveLineAnchorNext(e)}if(this.hoverType===v.Rotate)return void this.rotatePens({x:e.x,y:e.y});if(this.hoverType===v.Resize)return void this.resizePens(e);if(this.hoverType===v.Node||this.hoverType===v.Line){const t=e.x-this.mouseDown.x,i=e.y-this.mouseDown.y,n=20;if(e.ctrlKey&&!e.shiftKey&&(Math.abs(t)>=n||Math.abs(i)>=n)&&(this.willInactivePen=void 0),1===this.store.active.length){const e=this.store.active[0];e.locked<o.DisableMove&&e?.onMouseMove?.(e,this.mousePos)}return void this.movePens(e)}}}if(this.drawingLine){const t={...e};if(t.id=ne(),t.penId=this.drawingLine.id,this.store.options.disableDock||this.store.options.disableLineDock||(this.clearDock(),this.dock=pt(this.store,t),this.dock?.xDock&&(t.x+=this.dock.xDock.step),this.dock?.yDock&&(t.y+=this.dock.yDock.step)),this.mouseDown&&"curve"===this.drawingLineName&&!this.drawingLine.calculative.worldAnchors[0].connectTo)this.drawline(t);else{let i;if(this.drawingLine.calculative.worldAnchors.length>1&&(i=Xe(this.drawingLine)),i?(i.prev=void 0,i.next=void 0,i.id||(i.id=ne()),i.x=t.x,i.y=t.y,i.connectTo=void 0):(i={...t},this.drawingLine.calculative.worldAnchors.push(i)),this.hoverType!==v.NodeAnchor&&this.hoverType!==v.LineAnchor||(this.store.hoverAnchor.type!==A.Line&&(i.x=this.store.hoverAnchor.x,i.y=this.store.hoverAnchor.y),i.connectTo=this.store.hoverAnchor.penId,"polyline"===this.drawingLineName&&(i.isTemp=!1)),"line"===this.drawingLineName)if(e.ctrlKey&&!e.shiftKey)i.x=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].x;else if(e.shiftKey&&!e.ctrlKey)i.y=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].y;else if(e.shiftKey&&e.ctrlKey){let e=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2];this.getSpecialAngle(i,e)}this.drawline()}}globalThis.debug&&console.time("hover");const t=performance.now();t-this.hoverTimer>50&&(this.hoverTimer=t,this.getHover(e)),globalThis.debug&&console.timeEnd("hover"),this.hotkeyType===x.AddAnchor&&(this.patchFlags=!0),this.render(!1)},this.onMouseUp=e=>{if(this.store.data.locked!==o.Disable){if(this.mouseDown){if(this.mouseRight===g.Down&&this.store.emitter.emit("contextmenu",{e,clientRect:this.clientRect}),this.mouseRight=g.None,this.calibrateMouse(e),this.mousePos.x=e.x,this.mousePos.y=e.y,this.pencil&&this.finishPencil(),this.drawingLine){if(this.store.hoverAnchor){const e=Xe(this.drawingLine);return this.store.hoverAnchor.type===A.Line?M(e,this.store.hoverAnchor,this.store):(e.x=this.store.hoverAnchor.x,e.y=this.store.hoverAnchor.y),qe(this.store.hover,this.store.hoverAnchor,this.drawingLine,e),this.drawline(),void this.finishDrawline(!0)}if(this.store.options.autoAnchor&&this.hoverType===v.Node){const t=Xe(this.drawingLine),i=We(this.store.hover,e);return t.x=i.x,t.y=i.y,this.drawingLine.autoTo=!0,qe(this.store.hover,i,this.drawingLine,t),this.drawline(),void this.finishDrawline(!0)}}if(this.hoverType===v.LineAnchor&&this.store.hover&&this.store.active[0]&&"line"===this.store.active[0].name&&this.store.active[0]!==this.store.hover){const t=this.store.active[0],i=$e(t),n=Xe(t);if(this.store.hoverAnchor){const o=this.store.hover,s=$e(o)===this.store.hoverAnchor,a=Xe(o)===this.store.hoverAnchor,c=i===this.store.activeAnchor,l=n===this.store.activeAnchor;if((e.ctrlKey||e.altKey)&&o.type===r.Line&&(s||a)&&(c||l)){const e=o.calculative.worldAnchors.map((e=>({...e,penId:t.id})));s?e.shift():a&&e.pop(),(s&&c||a&&l)&&e.reverse(),c?(t.calculative.worldAnchors[0].connectTo=void 0,t.calculative.worldAnchors.unshift(...e)):l&&(t.calculative.worldAnchors[t.calculative.worldAnchors.length-1].connectTo=void 0,t.calculative.worldAnchors.push(...e)),this.delete([o]),this.render()}else this.store.activeAnchor&&(this.store.hoverAnchor.type===A.Line?M(this.store.activeAnchor,this.store.hoverAnchor,this.store):(this.store.activeAnchor.x=this.store.hoverAnchor.x,this.store.activeAnchor.y=this.store.hoverAnchor.y),qe(this.store.hover,this.store.hoverAnchor,t,this.store.activeAnchor));this[t.lineName]&&"polyline"!==t.lineName&&this[t.lineName](this.store,t),this.store.path2dMap.set(t,N.path2dDraws.line(t)),this.initLineRect(t)}else i===this.store.activeAnchor&&t.autoFrom?this.calcAutoAnchor(t,i,this.store.hover):n===this.store.activeAnchor&&t.autoTo&&this.calcAutoAnchor(t,n,this.store.hover)}if(this.addCaches&&this.addCaches.length&&(this.store.data.locked||this.dropPens(this.addCaches,e),this.addCaches=void 0),this.hoverType===v.Rotate&&(this.getSizeCPs(),this.store.active.forEach((e=>{e.rotate=e.calculative.rotate}))),this.patchFlagsLines.forEach((e=>{e.type&&this.initLineRect(e)})),this.patchFlagsLines.clear(),this.dragRect){const e=this.store.data.pens.filter((e=>!(!1===e.visible||e.locked>=o.DisableMove||e.parentId)&&(Et(e.calculative.worldRect,this.dragRect,this.store.options.dragAllIn)?!(e.type===r.Line&&!this.store.options.dragAllIn)||function(e,t){const i=e.calculative.worldAnchors;for(let e=0;e<i.length-1;e++){const n=i[e],r=i[e+1];if(n.next||r.prev){if(li(n,r,t))return!0}else if(ci(n,r,t))return!0}return!1}(e,this.dragRect):void 0)));this.active(e)}2!==e.button&&(R(this.mouseDown,e)<2&&(this.store.hover&&this.store.hover.input&&this.showInput(this.store.hover),this.store.emitter.emit("click",{x:e.x,y:e.y,pen:this.store.hover})),this.store.emitter.emit("mouseup",{x:e.x,y:e.y,pen:this.store.hover})),this.willInactivePen&&(this.willInactivePen.calculative.active=void 0,tt(this.willInactivePen,!1),this.store.active.splice(this.store.active.findIndex((e=>e===this.willInactivePen)),1),this.calcActiveRect(),this.willInactivePen=void 0,this.store.emitter.emit("inactive",[this.willInactivePen]),this.render()),this.movingPens&&(e.altKey&&!e.shiftKey?this.copyMovedPens():this.movedActivePens(e.ctrlKey&&e.shiftKey),this.getAllByPens(this.movingPens).forEach((e=>{this.store.pens[e.id]=void 0})),this.movingPens=void 0),this.store.active&&this.store.active[0]&&(this.store.active[0].calculative.h=void 0),this.mouseDown=void 0,this.lastOffsetX=0,this.lastOffsetY=0,this.clearDock(),this.dragRect=void 0,this.initActiveRect=void 0,this.render()}}else this.hoverType=v.None},this.clearDock=()=>{const e=this.dock?.xDock?.penId,t=this.dock?.yDock?.penId,i=this.store.pens[e];i&&(i.calculative.isDock=!1);const n=this.store.pens[t];n&&(n.calculative.isDock=!1),this.dock=void 0},this.onResize=()=>{this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.resize(),this.timer=void 0}),100)},this.onScroll=()=>{this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.clientRect=this.canvas.getBoundingClientRect(),this.timer=void 0}),100)},this.calibrateMouse=e=>(e.x-=this.store.data.x,e.y-=this.store.data.y,e),this.getHover=e=>{if(this.dragRect)return;let t=v.None;this.store.hover=void 0,this.store.hoverAnchor=void 0,this.store.pointAt=void 0,this.store.pointAtIndex=void 0;const i=1===this.store.active.length&&this.store.active[0].type;if(!this.drawingLineName&&this.hotkeyType!==x.AddAnchor&&this.activeRect&&!i&&!this.store.data.locked){const i=rt(this.store.active),n=ot(this.store.active)||this.store.options.disableRotate,r=at(this.store.active)||this.store.options.disableSize;if(!i&&!n){const i={x:this.activeRect.center.x,y:this.activeRect.y-30};this.activeRect.rotate&&S(i,this.activeRect.rotate,this.activeRect.center),!this.hotkeyType&&P(e,i,this.pointSize)&&(t=v.Rotate,this.externalElements.style.cursor=`url("${this.store.options.rotateCursor}"), auto`)}if(!i&&!r)for(let i=0;i<8;i++){const n=i<4;if((this.hotkeyType===x.Resize||n&&!this.hotkeyType)&&P(e,this.sizeCPs[i],this.pointSize)){let e=n?m:b,r=0;Math.abs(this.activeRect.rotate%90-45)<25?(e=n?b:m,r=Math.round((this.activeRect.rotate-45)/90)+(n?0:1)):r=Math.round(this.activeRect.rotate/90),t=v.Resize,this.resizeIndex=i,this.externalElements.style.cursor=e[(i+r)%4];break}}}t===v.None&&(t=this.inPens(e,this.store.data.pens)),t||i||!_t(e,this.activeRect)||(t=v.Node,this.externalElements.style.cursor="move"),this.hoverType=t,t===v.None&&(this.drawingLineName||this.pencil?this.externalElements.style.cursor="crosshair":this.mouseDown||(this.externalElements.style.cursor="default"),this.store.hover=void 0),this.store.lastHover!==this.store.hover&&(this.patchFlags=!0,this.store.lastHover&&(this.store.lastHover.calculative.hover=!1,it(se(this.store.lastHover,!0)||this.store.lastHover,!1),this.store.emitter.emit("leave",this.store.lastHover),this.tooltip.hide()),this.store.hover&&(this.store.hover.calculative.hover=!0,it(se(this.store.hover,!0)||this.store.hover),this.store.emitter.emit("enter",this.store.hover),this.tooltip.show(this.store.hover,e)),this.store.lastHover=this.store.hover),this.store.hover?.onMouseMove?.(this.store.hover,this.mousePos)},this.inPens=(e,t)=>{let i=v.None;e:for(let n=t.length-1;n>=0;--n){const r=t[n];if(0==r.visible||0==r.calculative.inView||r.locked===o.Disable)continue;const s=ii(r);if(r.calculative.active||kt(e,r.calculative.worldRect,s)||_t(e,r.calculative.worldRect)){if(this.store.data.locked&&r.calculative.worldAnchors)for(const t of r.calculative.worldAnchors)if(P(e,t,this.pointSize,t.penId?this.store.pens[t.penId]:void 0)&&(this.title.show(t,r),t.title))break e;if(!this.store.data.locked&&this.hotkeyType!==x.Resize&&r.calculative.worldAnchors)for(const t of r.calculative.worldAnchors)if(i=this.inAnchor(e,r,t),i)break e;if(r.type){const t=ri(e,r);if(t){this.store.data.locked||r.locked?this.externalElements.style.cursor=this.store.options.hoverCursor:this.hotkeyType===x.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move",this.store.hover=r,this.store.pointAt=t.point,this.store.pointAtIndex=t.i,i=v.Line;break}}else{if(r.children){const t=[];if(r.children.forEach((e=>{this.store.pens[e]&&t.push(this.store.pens[e])})),i=this.inPens(e,t),i)break}let t=!1;if(t="line"===r.name?kt(e,r.calculative.worldRect,r.lineWidth):_t(e,r.calculative.worldRect),t){if(this.store.data.locked||r.locked?this.externalElements.style.cursor=this.store.options.hoverCursor:this.hotkeyType===x.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move",this.store.hover=r,i=v.Node,this.store.pointAt=e,!e.ctrlKey){let{x:t,y:i,ex:n,ey:r,rotate:o,center:s}=this.store.hover.calculative.worldRect;if(o){const a=[{x:t,y:i},{x:n,y:i},{x:n,y:r},{x:t,y:r}];a.forEach((e=>{S(e,o,s)}));let c=a[a.length-1];for(const t of a){if(c.y>e.y!=t.y>e.y){const i=t.x+(e.y-t.y)*(c.x-t.x)/(c.y-t.y);Math.abs(i-this.store.pointAt.x)<10&&(this.store.pointAt.x=i)}c=t}}else this.store.pointAt.x-10<t?this.store.pointAt.x=t:this.store.pointAt.x+10>n&&(this.store.pointAt.x=n),this.store.pointAt.y-10<i?this.store.pointAt.y=i:this.store.pointAt.y+10>r&&(this.store.pointAt.y=r)}break}}}}return i},this.dockInAnchor=e=>{this.store.hover=void 0;for(let t=this.store.data.pens.length-1;t>=0;--t){const i=this.store.data.pens[t];if(0==i.visible||i.locked===o.Disable||i===this.store.active[0])continue;let n=ii(i);if(n+=2*this.store.options.anchorRadius,kt(e,i.calculative.worldRect,n)&&(this.store.hover=i,this.hotkeyType!==x.Resize&&i.calculative.worldAnchors))for(const t of i.calculative.worldAnchors){if(t.twoWay===T.In){const e=Xe(this.store.active[0]);if(this.store.activeAnchor.id!==e.id)continue}if(t.twoWay===T.Out){const e=$e(this.store.active[0]);if(this.store.activeAnchor.id!==e.id)continue}if(t.twoWay!==T.DisableConnected&&t.twoWay!==T.Disable&&this.store.activeAnchor?.twoWay!==T.DisableConnectTo&&this.store.activeAnchor?.twoWay!==T.Disable&&this.inAnchor(e,i,t))return!0}}},this.render=e=>{if(e&&(this.opening=!1),this.opening)return;let t;if(null==e||!0===e||e===1/0?(t=performance.now(),this.patchFlags=!0):t=e>1?e:performance.now(),!this.patchFlags)return;if(t-this.lastRender<this.store.options.interval)return this.renderTimer&&cancelAnimationFrame(this.renderTimer),void(this.renderTimer=requestAnimationFrame(this.render));this.renderTimer=void 0,this.lastRender=t;const i=this.offscreen.getContext("2d");i.clearRect(0,0,this.offscreen.width,this.offscreen.height),i.save(),i.translate(this.store.data.x,this.store.data.y),globalThis.debugRender&&console.time("renderPens"),this.renderPens(),globalThis.debugRender&&console.timeEnd("renderPens"),this.renderBorder(),this.renderHoverPoint(),i.restore(),this.magnifierCanvas.render();const n=this.canvas.getContext("2d");n.clearRect(0,0,this.canvas.width,this.canvas.height),n.drawImage(this.offscreen,0,0,this.width,this.height),this.canvasImageBottom.render(),this.canvasImage.render(),this.patchFlags=!1},this.renderPens=()=>{const e=this.offscreen.getContext("2d");e.strokeStyle=De(this.store);for(const t of this.store.data.pens)isFinite(t.x)&&t.calculative.inView&&Ce(e,t);this.drawingLine&&Ce(e,this.drawingLine),this.pencilLine&&Ce(e,this.pencilLine),this.movingPens&&this.movingPens.forEach((t=>{this.renderPenContainChild(e,t)}))},this.renderPenContainChild=(e,t)=>{t.calculative.inView&&Ce(e,t),t.children?.forEach((t=>{const i=this.store.pens[t];i&&this.renderPenContainChild(e,i)}))},this.renderBorder=()=>{if(!this.store.data.locked&&this.activeRect&&(1!==this.store.active.length||!this.store.active[0].type)&&!this.movingPens){const e=this.offscreen.getContext("2d");if(e.save(),e.translate(.5,.5),this.activeRect.rotate&&(e.translate(this.activeRect.center.x,this.activeRect.center.y),e.rotate(this.activeRect.rotate*Math.PI/180),e.translate(-this.activeRect.center.x,-this.activeRect.center.y)),e.strokeStyle=this.store.options.activeColor,e.globalAlpha=.3,e.beginPath(),e.strokeRect(this.activeRect.x,this.activeRect.y,this.activeRect.width,this.activeRect.height),e.globalAlpha=1,rt(this.store.active)||ot(this.store.active)||this.store.options.disableRotate)return void e.restore();e.beginPath(),e.moveTo(this.activeRect.center.x,this.activeRect.y),e.lineTo(this.activeRect.center.x,this.activeRect.y-30),e.stroke(),e.beginPath(),e.strokeStyle=this.store.options.activeColor,e.fillStyle="#ffffff",e.arc(this.activeRect.center.x,this.activeRect.y-30,5,0,2*Math.PI),e.fill(),e.stroke(),e.restore()}},this.renderHoverPoint=()=>{if(this.store.data.locked)return;const e=this.offscreen.getContext("2d");if(e.save(),e.translate(.5,.5),!this.store.options.disableAnchor&&this.store.hover&&!this.store.hover.disableAnchor&&(this.hotkeyType!==x.Resize||1!==this.store.active.length||this.store.active[0]!==this.store.hover)){const t=[...this.store.hover.calculative.worldAnchors];this.store.pointAt&&this.hotkeyType===x.AddAnchor&&t.push(this.store.pointAt),t&&(e.strokeStyle=this.store.hover.anchorColor||this.store.options.anchorColor,e.fillStyle=this.store.hover.anchorBackground||this.store.options.anchorBackground,t.forEach((t=>{if(t.hidden&&t.locked>o.DisableEdit)return;if(t===this.store.hoverAnchor){e.save();const t=this.store.hover.hoverAnchorColor||this.store.options.hoverAnchorColor;e.strokeStyle=t,e.fillStyle=t}e.beginPath();let i=t.radius||this.store.hover.anchorRadius||this.store.options.anchorRadius;if(!this.store.hover.type||t.radius||this.store.hover.anchorRadius||(i=3,this.store.hover.calculative.lineWidth>3&&(i=this.store.hover.calculative.lineWidth)),t.type===A.Line){let n=this.store.pens[t.penId].rotate;this.store.pens[t.penId].calculative.flipX&&(n*=-1),this.store.pens[t.penId].calculative.flipY&&(n*=-1);let r=t.rotate+n;this.store.pens[t.penId].calculative.flipX&&(r*=-1),this.store.pens[t.penId].calculative.flipY&&(r*=-1),e.save(),e.translate(t.x,t.y),e.rotate(r*Math.PI/180),e.translate(-t.x,-t.y),e.rect(t.x-t.length*this.store.data.scale/2,t.y-i,t.length*this.store.data.scale,2*i),e.restore()}else e.arc(t.x,t.y,i,0,2*Math.PI);if(this.store.hover.type&&this.store.hoverAnchor===t?(e.save(),e.strokeStyle=this.store.hover.activeColor||this.store.options.activeColor,e.fillStyle=e.strokeStyle):(t.color||t.background)&&(e.save(),e.strokeStyle=t.color,e.fillStyle=t.background),e.fill(),e.stroke(),t===this.store.hoverAnchor&&e.restore(),(this.store.hover.type&&this.store.hoverAnchor===t||t.color||t.background)&&e.restore(),!this.store.hover.parentId&&this.store.hover.children&&this.store.hover.children.length>0&&t===this.store.hoverAnchor){e.save(),e.beginPath(),e.lineWidth=3;const n=this.store.hover.hoverAnchorColor||this.store.options.hoverAnchorColor;globalThis.pSBC&&(e.strokeStyle=globalThis.pSBC(.5,n)),e.arc(t.x,t.y,i+1.5,0,2*Math.PI),e.stroke(),e.restore()}})))}this.hotkeyType===x.AddAnchor||this.movingPens||!this.activeRect||1===this.store.active.length&&this.store.active[0].type||rt(this.store.active)||at(this.store.active)||this.store.options.disableSize||(e.strokeStyle=this.store.options.activeColor,e.fillStyle="#ffffff",this.sizeCPs.forEach(((t,i)=>{this.activeRect.rotate&&(e.save(),e.translate(t.x,t.y),e.rotate(this.activeRect.rotate*Math.PI/180),e.translate(-t.x,-t.y)),(i<4||this.hotkeyType===x.Resize)&&(e.beginPath(),e.fillRect(t.x-4.5,t.y-4.5,8,8),e.strokeRect(t.x-5.5,t.y-5.5,10,10)),this.activeRect.rotate&&e.restore()}))),!this.store.data.locked&&this.dragRect&&(e.save(),e.fillStyle=ee(this.store.options.dragColor,.2),e.strokeStyle=this.store.options.dragColor,e.beginPath(),e.strokeRect(this.dragRect.x,this.dragRect.y,this.dragRect.width,this.dragRect.height),e.fillRect(this.dragRect.x,this.dragRect.y,this.dragRect.width,this.dragRect.height),e.restore()),this.dock&&(e.strokeStyle=this.store.options.dockColor,this.dock.xDock&&(e.beginPath(),e.moveTo(this.dock.xDock.x,this.dock.xDock.y),e.lineTo(this.dock.xDock.x,this.dock.xDock.prev.y),e.stroke()),this.dock.yDock&&(e.beginPath(),e.moveTo(this.dock.yDock.x,this.dock.yDock.y),e.lineTo(this.dock.yDock.prev.x,this.dock.yDock.y),e.stroke())),e.restore()},this.pastePen=(e,t)=>{const i=e.id;if(wt(e),e.parentId=t,e.type===r.Line?this.changeNodeConnectedLine(i,e,this.store.clipboard.pens):this.changeLineAnchors(i,e,this.store.clipboard.pens),!e.parentId){const t=this.getPenRect(e,this.store.clipboard.origin,this.store.clipboard.scale),i=this.getPenRect(this.store.clipboard.initRect,this.store.clipboard.origin,this.store.clipboard.scale),{origin:n,scale:r}=this.store.data;e.x=n.x+t.x*r,e.y=n.y+t.y*r,e.width=t.width*r,e.height=t.height*r,i.x=n.x+i.x*r,i.y=n.y+i.y*r,Tt(i),this.store.clipboard.pos&&(e.x-=i.center.x-this.store.clipboard.pos.x,e.y-=i.center.y-this.store.clipboard.pos.y),e.x+=this.store.clipboard.offset*this.store.data.scale,e.y+=this.store.clipboard.offset*this.store.data.scale}this.makePen(e);const n=[];if(Array.isArray(e.children))for(const t of e.children){const i=this.store.clipboard.pens.find((e=>e.id===t));i&&n.push(this.pastePen(i,e.id).id)}return e.children=n,e},this.ondblclick=e=>{!this.store.hover||this.store.data.locked&&!this.store.hover.dbInput||this.store.options.disableInput||(this.store.hover.onShowInput?this.store.hover.onShowInput(this.store.hover,e):this.showInput(this.store.hover)),this.store.emitter.emit("dblclick",{x:e.x,y:e.y,pen:this.store.hover})},this.showInput=(e,t,i="transparent")=>{if(!window||!this.store.hover||this.store.hover.locked||this.store.hover.externElement||this.store.hover.disableInput)return;if(this.inputDiv.dataset.penId===e.id){this.inputDiv.dataset.isInput="true",this.inputDiv.contentEditable="true",this.inputDiv.focus();const e=window.getSelection();return e.selectAllChildren(this.inputDiv),e.collapseToEnd(),this.inputDiv.scrollTop=this.inputDiv.scrollHeight,void(this.inputDiv.scrollLeft=this.inputDiv.scrollWidth)}t||e.dbInput?(this.inputDiv.style.width="100%",this.inputDiv.style.height="100%"):this.setInputStyle(e);const n=t||e.calculative.worldTextRect,r=`${(e.calculative.tempText||e.text+""||"").replace(/\x20/g," ").split(/[\s\n]/).join("</div><div>")}</div>`.replace("</div>","").replace(/\<div\>\<\/div\>/g,"<div><br></div>");this.inputDiv.innerHTML=r,this.inputParent.style.left=n.x+this.store.data.x-(e.textLeft||0)+"px",this.inputParent.style.top=n.y+this.store.data.y-(e.textTop||0)+"px";let o=n.width+(e.textLeft||0);this.inputParent.style.width=(o<0?12:o)+"px",this.inputParent.style.height=n.height+(e.textTop||0)+"px",this.inputParent.style.zIndex="9999",this.inputParent.style.background=i,e.rotate%360?this.inputParent.style.transform=`rotate(${e.rotate}deg)`:this.inputParent.style.transform=null,this.inputParent.style.display="flex",this.inputDiv.dataset.penId=e.id,this.inputDiv.contentEditable=null==e.disableInput?"true":e.disableInput.toString(),e.dropdownList&&"block"!==this.dropdown.style.display?(this.store.data.locked||(this.inputRight.style.display="none"),this.setDropdownList()):this.inputRight.style.display="none",this.inputDiv.contentEditable="true",this.inputDiv.focus();const s=window.getSelection();s.selectAllChildren(this.inputDiv),s.collapseToEnd(),this.inputDiv.scrollTop=this.inputDiv.scrollHeight,this.inputDiv.scrollLeft=this.inputDiv.scrollWidth,e.calculative.text=void 0,this.render()},this.setInputStyle=e=>{let t;e.text||(e.text="");for(let e=0;e<document.styleSheets.length;e++)"le5le.com"===document.styleSheets[e].title&&(t=document.styleSheets[e]);let i="overflow: scroll;",n="",r=1;const{scale:o}=this.store.data;if(e.fontSize<12&&(r=12/e.fontSize),e.textAlign?i+=`text-align: ${e.textAlign};`:i+="text-align: center;",e.textAlign&&"pre-line"===e.whiteSpace&&(i+=`align-items: ${{left:"start",center:"center",right:"end"}[e.textAlign]};`),e.textBaseline?i+=`justify-content: ${{top:"start",middle:"center",bottom:"end"}[e.textBaseline]};`:i+="justify-content: center;",e.fontFamily&&(i+=`font-family: ${e.fontFamily};`),e.fontSize&&(e.fontSize*o<12?(i+=`font-size:${e.fontSize}px;`,i+=`zoom:${e.fontSize/12*o};`):i+=`font-size:${e.fontSize*o}px;`),i+=`color:${we(e,this.store)};`,e.fontStyle&&(i+=`font-style: ${e.fontStyle};`),e.fontWeight&&(i+=`font-weight: ${e.fontWeight};`),e.textLeft&&(i+=`margin-left:${o>1?e.textLeft*r:e.textLeft*r/o}px;`),e.textTop&&(i+=`margin-top:${o>1?e.textTop*r:e.textTop*r/o}px;`),e.lineHeight&&(i+=`line-height:${o>1?e.fontSize*e.lineHeight*o:e.fontSize*e.lineHeight*r}px;`),e.textHeight)i+=`height:${o>1?e.textHeight*r*o:e.textHeight*r}px;`;else{let t=e.calculative.worldRect.height/o-(e.textTop||0);t<0&&(t=0),i+=`height:${e.fontSize*o<12?t*r:t*o*r}px;`}let s=null;if(e.textWidth)s=e.textWidth<1&&e.textWidth>-1?e.textWidth*e.calculative.worldRect.width:e.textWidth,"pre-line"!==e.whiteSpace&&(s<e.fontSize?i+=`width:${1.2*e.fontSize*r}px;`:i+=`width:${o>1?s*r*o:s*r}px;`);else if(void 0===e.whiteSpace||"break-all"===e.whiteSpace){let t=(e.calculative.worldTextRect.width||12)/o;t<0&&(t=0),i+=`width:${e.fontSize*o<12?t*r:t*o}px;`}e.whiteSpace&&("pre-line"===e.whiteSpace?i+="white-space:pre;":(i+=`white-space:${e.whiteSpace};`,"nowrap"===e.whiteSpace&&(n+="display:contents;"))),"nowrap"!==e.whiteSpace&&1.2*e.fontSize*e.text.length>(s||e.calculative.worldRect.width/o)*Math.floor(e.calculative.worldRect.height/o/(e.lineHeight*e.fontSize))&&(i+="justify-content: start;"),t.deleteRule(0),t.deleteRule(0),t.insertRule(`.meta2d-input\n .input-div{\n resize:none;border:none;outline:none;background:transparent;position:absolute;flex-grow:1;height:100%;width: 100%;position:absolute;left:0;top:0;display:flex;flex-direction: column;cursor: text;${i}}`),t.insertRule(`.input-div div{${n}}`)},this.hideInput=()=>{if("flex"===this.inputParent.style.display){this.inputParent.style.display="none";const e=this.store.pens[this.inputDiv.dataset.penId];if(!e)return;if(e.calculative.text=e.text,this.inputDiv.dataset.value=this.inputDiv.innerHTML.replace(/\<div\>/g,"\n").replace(/\<\/div\>/g,"").replace(/\<br\>/g,"").replace(/ /g," ").replace(/(<([^>]+)>)/gi,""),this.inputDiv.dataset.value=this.convertSpecialCharacter(this.inputDiv.dataset.value),e.onInput)e.onInput(e,this.inputDiv.dataset.value);else if(e.text!==this.inputDiv.dataset.value){const t=[$(e,!0)];e.text=this.inputDiv.dataset.value,e.calculative.text=e.text,this.inputDiv.dataset.penId=void 0,"text"===e.name&&e.textAutoAdjust&&function(e){let t=e.text.split("\n");const i=e.calculative.canvas,n=i.offscreen.getContext("2d"),{fontStyle:r,fontWeight:o,fontSize:s,fontFamily:a,lineHeight:c}=e.calculative;let l=0,h=0;n.save();for(let e=0;e<t.length;e++){if(i.store.options.measureTextWidth)n.font=Ae({fontStyle:r,fontWeight:o,fontFamily:a||i.store.options.fontFamily,fontSize:s,lineHeight:c}),h=n.measureText(t[e]).width;else{const i=t[e].match(/[^\x00-\xff]/g)||"",n=i.length*s,r=t[e].match(/\s/g)||"";h=n+r.length*s*.3+(t[e].length-i.length-r.length)*s*.6}h>l&&(l=h)}n.restore();let u=t.length*s*c;e.height=u,e.x=e.x-(l-e.width)/2,e.width=l,e.calculative.canvas.updatePenRect(e),e.calculative.canvas.calcActiveRect()}(e),U(e),this.patchFlags=!0,this.pushHistory({type:H.Update,pens:[$(e,!0)],initPens:t}),this.store.emitter.emit("valueUpdate",e)}}this.inputDiv.dataset.penId=void 0,this.dropdown.style.display="none",this.inputDiv.dataset.isInput="false",this.inputDiv.contentEditable="false",this.render()},this.setDropdownList=e=>{if(this.clearDropdownList(),!this.store.data.locked)return;this.dropdown.style.display="block",this.inputRight.style.display="block",setTimeout((()=>{this.inputRight.style.transform="rotate(315deg)",this.inputRight.style.zoom=this.store.data.scale}));const t=this.store.pens[this.inputDiv.dataset.penId];if(!t||!t.dropdownList)return this.dropdown.style.display="none",this.inputRight.style.display="none",void(this.inputRight.style.transform="rotate(135deg)");if(!t.dropdownList.length){const e=document.createElement("div");return e.innerText="None",e.style.padding="5px 12px",e.style.color="#ddd",void this.dropdown.appendChild(e)}const i=this.inputDiv.innerHTML.replace(/\<div\>/g,"\n").replace(/\<\/div\>/g,"").replace(/\<br\>/g,"");let n=0;for(const r of t.dropdownList){const t="string"==typeof r?r:r.text;e&&i?t.includes(i)&&this.dropdownAppendOption(t,n):this.dropdownAppendOption(t,n),++n}if(!this.dropdown.hasChildNodes()){const e=document.createElement("div");e.innerText="None",e.style.padding="5px 12px",e.style.color="#ddd",this.dropdown.appendChild(e)}},this.selectDropdown=e=>{const t=e.target,i=this.store.pens[this.inputDiv.dataset.penId];if(!t||!i||!i.dropdownList)return;const n=+t.dataset.i,r=i.dropdownList[n];if(!r)return;const o=[$(i,!0)];"object"==typeof r?(this.updateValue(i,{...r}),i.calculative.text=void 0,this.calcActiveRect()):i.text=r+"",this.inputDiv.innerText=i.text,this.hideInput(),this.pushHistory({type:H.Update,pens:[$(i,!0)],initPens:o}),this.render(),this.store.emitter.emit("valueUpdate",i)},this.canvasImageBottom=new dn(t,i,!0),this.canvasImageBottom.canvas.style.zIndex="1",t.appendChild(this.canvas),this.canvas.style.position="absolute",this.canvas.style.backgroundRepeat="no-repeat",this.canvas.style.backgroundSize="100% 100%",this.canvas.style.zIndex="2",this.canvasImage=new dn(t,i),this.canvasImage.canvas.style.zIndex="3",this.magnifierCanvas=new fn(this,t,i),this.magnifierCanvas.canvas.style.zIndex="4",this.externalElements.style.position="absolute",this.externalElements.style.left="0",this.externalElements.style.top="0",this.externalElements.style.outline="none",this.externalElements.style.background="transparent",this.externalElements.style.zIndex="4",t.style.position="relative",t.appendChild(this.externalElements),this.createInput(),this.tooltip=new hn(t,i),this.tooltip.box.onmouseleave=e=>{this.patchFlags=!0,this.store.lastHover&&(this.store.lastHover.calculative.hover=!1),it(this.store.data.pens.find((e=>!0===e.calculative.hover)),!1)},this.dialog=new vn(t),this.title=new yn(t),this.store.options.scroll&&(this.scroll=new un(this)),this.store.dpiRatio=globalThis.devicePixelRatio||1,this.store.dpiRatio<1?this.store.dpiRatio=1:this.store.dpiRatio>1&&this.store.dpiRatio<1.5&&(this.store.dpiRatio=1.5),this.clientRect=this.externalElements.getBoundingClientRect(),this.listen(),window?.addEventListener("resize",this.onResize),window?.addEventListener("scroll",this.onScroll)}listen(){switch(this.externalElements.addEventListener("gesturestart",this.onGesturestart),this.externalElements.ondragover=e=>e.preventDefault(),this.externalElements.ondrop=this.ondrop,this.externalElements.oncontextmenu=e=>e.preventDefault(),this.store.options.interval=50,this.externalElements.ontouchstart=this.ontouchstart,this.externalElements.ontouchmove=this.ontouchmove,this.externalElements.ontouchend=this.ontouchend,this.externalElements.onmousedown=e=>{this.onMouseDown({x:e.offsetX,y:e.offsetY,clientX:e.clientX,clientY:e.clientY,pageX:e.pageX,pageY:e.pageY,ctrlKey:e.ctrlKey||e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,buttons:e.buttons})},this.externalElements.onmousemove=e=>{e.target===this.externalElements&&this.onMouseMove({x:e.offsetX,y:e.offsetY,clientX:e.clientX,clientY:e.clientY,pageX:e.pageX,pageY:e.pageY,ctrlKey:e.ctrlKey||e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,buttons:e.buttons})},this.externalElements.onmouseup=e=>{this.onMouseUp({x:e.offsetX,y:e.offsetY,clientX:e.clientX,clientY:e.clientY,pageX:e.pageX,pageY:e.pageY,ctrlKey:e.ctrlKey||e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,buttons:e.buttons,button:e.button})},this.externalElements.onmouseleave=e=>{e.toElement!==this.tooltip.box&&(this.tooltip.hide(),this.store.lastHover=void 0)},this.externalElements.ondblclick=this.ondblclick,this.externalElements.tabIndex=0,this.externalElements.onblur=()=>{this.mouseDown=void 0},this.externalElements.onwheel=this.onwheel,document.addEventListener("copy",this.onCopy),document.addEventListener("cut",this.onCut),document.addEventListener("paste",this.onPaste),this.store.options.keydown){case z.Document:document.addEventListener("keydown",this.onkeydown),document.addEventListener("keyup",this.onkeyup);break;case z.Canvas:this.externalElements.addEventListener("keydown",this.onkeydown),this.externalElements.addEventListener("keyup",this.onkeyup)}}splitLine(e,t){const i=e.calculative.worldAnchors,n=i.findIndex((e=>e===t));if([-1,0,i.length-1].includes(n))return;const r=$(e,!0),o=$(e,!0),s=ne();o.id=s,o.calculative.canvas=this,o.calculative.active=!1,o.calculative.hover=!1;const a=$(i.slice(0,n+1)),c=$(i.slice(n)).map((e=>(e.penId=s,e)));e.calculative.worldAnchors=a,o.calculative.worldAnchors=c,this.initLineRect(e),this.initLineRect(o),this.store.data.pens.push(o),this.store.pens[s]=o,this.pushHistory({type:H.Add,pens:[$(o,!0)],step:2}),this.pushHistory({type:H.Update,initPens:[r],pens:[$(e,!0)],step:2})}translateAnchor(e,t){this.movingAnchor.x+=e,this.movingAnchor.y+=t;const i=this.movingAnchor.penId;if(i){const e=this.store.pens[i],t=e.calculative.worldRect;this.movingAnchor.x<t.x?this.movingAnchor.x=t.x:this.movingAnchor.x>t.ex&&(this.movingAnchor.x=t.ex),this.movingAnchor.y<t.y?this.movingAnchor.y=t.y:this.movingAnchor.y>t.ey&&(this.movingAnchor.y=t.ey);const n=Nt(this.movingAnchor,t),r=e.anchors.findIndex((e=>e.id===this.movingAnchor.id));e.anchors[r]=n,this.patchFlags=!0}}async fileToPen(e,t){let i="";return i=this.store.options.uploadFn?await this.store.options.uploadFn(e):this.store.options.uploadUrl?await async function(e,t,i,n){const r=new FormData;if(r.append("file",e),i)for(const e in i)i.hasOwnProperty(e)&&r.append(e,i[e]);const o=await fetch(t,{method:"POST",headers:n,body:r});return(await o.json()).url}(e,this.store.options.uploadUrl,this.store.options.uploadParams,this.store.options.uploadHeaders):await async function(e){return new Promise(((t,i)=>{const n=new FileReader;n.onload=e=>{t(e.target.result)},n.onerror=e=>{i(e)},n.readAsDataURL(e)}))}(e),new Promise(((e,n)=>{const r=new Image;r.onload=()=>{N.htmlElements[i]=r,e({width:r.width,height:r.height,name:t?"gif":"image",image:i})},r.onerror=e=>{n(e)},r.crossOrigin="anonymous",r.src=i}))}async dropPens(e,t){for(const t of e)!t.parentId&&this.randomCombineId(t,e);for(const t of e)t.id||(t.id=ne()),!t.calculative&&(t.calculative={canvas:this}),this.store.pens[t.id]=t;for(const i of e)i.parentId||(i.width*=this.store.data.scale,i.height*=this.store.data.scale,i.x=t.x-i.width/2,i.y=t.y-i.height/2,i.tags&&i.tags.includes("meta3d")&&(i.x=this.store.data.origin.x,i.y=this.store.data.origin.y));const i=this.store.data.width||this.store.options.width,n=this.store.data.height||this.store.options.height;if(i&&n){let t={x:this.store.data.origin.x,y:this.store.data.origin.y,width:i*this.store.data.scale,height:n*this.store.data.scale},r=!0;for(const i of e)if(!i.parentId){let e=[{x:i.x,y:i.y},{x:i.x+i.width,y:i.y},{x:i.x,y:i.y+i.height},{x:i.x+i.width,y:i.y+i.height}];if(i.x===t.x&&i.y===t.y&&i.width===t.width&&i.height===t.height||e.some((e=>_t(e,t)))){r=!1;break}}if(r)return void console.info("画笔在大屏范围外")}await this.addPens(e,!0),this.active(e.filter((e=>!e.parentId))),this.render(),this.externalElements.focus()}randomCombineId(e,t,i){wt(e),e.parentId=i;const n=[];if(Array.isArray(e.children))for(const i of e.children){const r=t.find((e=>e.id===i));r&&n.push(this.randomCombineId(r,t,e.id).id)}return e.children=n,e}async addPens(e,t){if(this.beforeAddPens&&1!=await this.beforeAddPens(e))return[];const i=[];for(const t of e)this.beforeAddPen&&1!=this.beforeAddPen(t)||(this.makePen(t),i.push(t));return this.render(),this.store.emitter.emit("add",i),t&&this.pushHistory({type:H.Add,pens:$(i,!0)}),i}getInitPencilLine(e){const{data:t,options:i}=this.store,n=t.scale,o=t.lineWidth||1;return{id:e.penId,name:"line",x:e.x,y:e.y,type:r.Line,calculative:{canvas:this,pencil:!0,active:!0,worldAnchors:[e],lineWidth:o*n},fromArrow:t.fromArrow||i.fromArrow,toArrow:t.toArrow||i.toArrow,lineWidth:o}}createDrawingLine(e){this.inactive();const{data:t,options:i}=this.store,n=t.scale,o=t.lineWidth||1;return e.penId=ne(),{id:e.penId,name:"line",lineName:this.drawingLineName,x:e.x,y:e.y,type:r.Line,calculative:{canvas:this,active:!0,worldAnchors:[e],lineWidth:o*n},fromArrow:t.fromArrow||i.fromArrow,toArrow:t.toArrow||i.toArrow,lineWidth:o}}addRuleLine(e){const{x:t,y:i}=this.store.data,n=e.x+t,o=e.y+i;let s=e.x,a=e.y,c=0,l=0,h=0,u=0;if(n<=o&&n<20)s=-t,c=this.width,h=1;else{if(!(o<n&&o<20))return;a=-i,l=this.height,u=1}this.addPen({isRuleLine:!0,type:r.Line,name:"line",lineName:"line",x:s,y:a,width:c,height:l,color:this.store.options.ruleLineColor,anchors:[{x:0,y:0},{x:h,y:u}]})}movedActivePens(e){const t=$(this.store.active,!0);if(this.store.active.forEach(((e,t)=>{const{x:i,y:n}=this.movingPens[t];Object.assign(e,{x:i,y:n}),e.onMove?.(e),this.updatePenRect(e),this.updateLines(e),this.store.emitter.emit("updateLines",e),this.patchFlagsLines.forEach((e=>{e.type&&this.initLineRect(e)})),this.patchFlagsLines.clear(),e.calculative.x=e.x,e.calculative.y=e.y,e.calculative.initRect&&(e.calculative.initRect.x=e.calculative.x,e.calculative.initRect.y=e.calculative.y,e.calculative.initRect.ex=e.calculative.x+e.calculative.width,e.calculative.initRect.ey=e.calculative.y+e.calculative.height)})),this.initImageCanvas(this.store.active),!this.dock)return;const{xDock:i,yDock:n}=this.dock;let r;i&&(r=this.store.pens[i.penId]),!r&&n&&(r=this.store.pens[n.penId]);const o=$(this.store.active,!0);if(e&&1===this.store.active.length&&1===r?.type&&(i?.anchorId||n?.anchorId)){const e=$e(r),s=Xe(r);if(i?.anchorId){const n=this.store.pens[this.store.active[0].id+mn].calculative.worldAnchors.find((e=>e.id===i.anchorId));n.x===e.x&&n.y===e.y?(t.push($(r,!0)),qe(this.store.active[0],n,r,e),o.push($(r,!0))):n.x===s.x&&n.y===s.y&&(t.push($(r,!0)),qe(this.store.active[0],n,r,s),o.push($(r,!0)))}else if(n?.anchorId){const i=this.store.pens[this.store.active[0].id+mn].calculative.worldAnchors.find((e=>e.id===n.anchorId));i.x===e.x&&i.y===e.y?(t.push($(r,!0)),qe(this.store.active[0],i,r,e),o.push($(r,!0))):i.x===s.x&&i.y===s.y&&(t.push($(r,!0)),qe(this.store.active[0],i,r,s),o.push($(r,!0)))}}this.pushHistory({type:H.Update,pens:o,initPens:t}),this.store.emitter.emit("translatePens",o)}copyMovedPens(){this.copy(this.store.active.map(((e,t)=>{const{x:i,y:n}=this.movingPens[t];return this.updateLines(e),{...e,x:i,y:n}}))),this.pasteOffset=!1,this.paste()}initImageCanvas(e){e.some((e=>this.hasImage(e,!1)))&&this.canvasImage.init(),e.some((e=>this.hasImage(e,!0)))&&this.canvasImageBottom.init()}hasImage(e,t){return!(!e.image||"gif"===e.name||!e.isBottom!=!t)||e.children?.some((e=>{const i=this.store.pens[e];return i&&this.hasImage(i,t)}))}inactive(e){this.store.active.length&&(this.store.active.forEach((e=>{e.calculative.active=void 0,e.calculative.activeAnchor=void 0,e.calculative.hover=!1,tt(e,!1)})),!e&&this.store.emitter.emit("inactive",this.store.active),this.store.active=[],this.activeRect=void 0,this.sizeCPs=void 0,this.store.activeAnchor=void 0,this.patchFlags=!0)}active(e,t=!0){if(this.store.active){t&&this.store.emitter.emit("inactive",this.store.active);for(const e of this.store.active)e.calculative.active=void 0,e.calculative.hover=!1,tt(e,!1)}this.store.active=[],e.forEach((e=>{e.calculative.active=!0,tt(e)})),this.store.active.push(...e),this.activeRect=void 0,this.calcActiveRect(),this.patchFlags=!0,t&&this.store.emitter.emit("active",this.store.active)}getSizeCPs(){this.sizeCPs=Pt(this.activeRect);const{x:e,y:t,width:i,height:n,rotate:r,center:o}=this.activeRect;[{x:.5,y:0},{x:1,y:.5},{x:.5,y:1},{x:0,y:.5}].forEach((s=>{const a={x:s.x*i+e,y:s.y*n+t};S(a,r,o),this.sizeCPs.push(a)}))}getSpecialAngle(e,t){let i=0,n=[0,30,45,60,90,120,150,135,180];e.x-t.x!=0?(i=180*Math.atan((t.y-e.y)/(e.x-t.x))/Math.PI,e.x<t.x&&(i>0?i-=180:i+=180)):t.y>e.y?i=90:t.y<e.y&&(i=-90);let r=999,o=-1;for(let e=0;e<n.length;e++)i<0?Math.abs(i+n[e])<r&&(o=e,r=Math.abs(i+n[e])):Math.abs(i-n[e])<r&&(o=e,r=Math.abs(i-n[e]));i=i<0?-n[o]:n[o];let s=Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y));e.x=t.x+Math.cos(i/180*Math.PI)*s,e.y=t.y-Math.sin(i/180*Math.PI)*s}clearHover(){this.hoverType=v.None,this.store.hover=null,this.store.hoverAnchor=null}inAnchor(e,t,i){if(this.store.hoverAnchor=void 0,this.movingAnchor=void 0,!i||i.locked>o.DisableEdit)return v.None;if((!t.type||!t.calculative.active)&&this.store.options.disableAnchor||t.disableAnchor)return v.None;if((this.mouseDown||this.drawingLine)&&"line"===t.name&&i.connectTo){const e=this.findOne(i.connectTo);if(e?.calculative&&!e?.calculative.active){t=e;const n=e.calculative.worldAnchors.find((e=>e.id===i.anchorId));n&&(i=n)}}if(i.twoWay===T.Disable&&"line"!==t.name)return v.None;if("line"===t.name&&i.connectTo){let e=this.findOne(i.connectTo)?.anchors.find((e=>e.id===i.anchorId));if(e&&e.twoWay)return v.None}if(this.drawingLine){if(i.twoWay===T.Out)return v.None}else if(this.mouseDown&&this.hoverType===v.LineAnchor);else if(i.twoWay===T.In)return v.None;if(P(e,i,this.pointSize,i.penId?this.store.pens[i.penId]:void 0))return i!==this.store.hoverAnchor&&(this.patchFlags=!0),this.store.hoverAnchor=i,this.store.hover=t,t.type?i.connectTo&&!t.calculative.active&&(this.store.hover=this.store.pens[i.connectTo],this.store.hover)?(this.store.hoverAnchor=this.store.hover.calculative.worldAnchors.find((e=>e.id===i.anchorId)),this.externalElements.style.cursor="crosshair",v.NodeAnchor):(this.hotkeyType===x.AddAnchor?this.externalElements.style.cursor="vertical-text":this.externalElements.style.cursor="pointer",v.LineAnchor):(this.hotkeyType===x.AddAnchor?this.externalElements.style.cursor="vertical-text":this.externalElements.style.cursor="crosshair",v.NodeAnchor);if(!this.mouseDown&&t.type){if(t.calculative.active&&i.prev&&P(e,i.prev,this.pointSize))return this.store.hoverAnchor=i,this.store.hover=t,this.externalElements.style.cursor="pointer",v.LineAnchorPrev;if(t.calculative.active&&i.next&&P(e,i.next,this.pointSize))return this.store.hoverAnchor=i,this.store.hover=t,this.externalElements.style.cursor="pointer",v.LineAnchorNext}return v.None}resize(e,t){e=e||this.parentElement.clientWidth,t=t||this.parentElement.clientHeight,this.width=e,this.height=t,this.canvasRect={x:0,y:0,width:e,height:t},At(this.canvasRect),this.canvas.style.width=e+"px",this.canvas.style.height=t+"px",this.externalElements.style.width=e+"px",this.externalElements.style.height=t+"px",this.canvasImage.resize(e,t),this.canvasImageBottom.resize(e,t),this.magnifierCanvas.resize(e,t),e=e*this.store.dpiRatio|0,t=t*this.store.dpiRatio|0,this.canvas.width=e,this.canvas.height=t,this.offscreen.width=e,this.offscreen.height=t,this.clientRect=this.externalElements.getBoundingClientRect(),this.canvas.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.offscreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.offscreen.getContext("2d").textBaseline="middle",this.render();for(const e of this.store.data.pens)ht(e)}clearCanvas(){this.activeRect=void 0,this.sizeCPs=void 0,this.canvas.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.offscreen.getContext("2d").clearRect(0,0,this.offscreen.width,this.offscreen.height),this.canvasImage.clear(),this.canvasImageBottom.clear()}async addPen(e,t,i){if(!(this.beforeAddPens&&1!=await this.beforeAddPens([e])||this.beforeAddPen&&1!=this.beforeAddPen(e)))return this.makePen(e),this.active([e]),this.render(),i&&this.store.emitter.emit("add",[e]),t&&this.pushHistory({type:H.Add,pens:[e]}),e}pushHistory(e){if(this.store.data.locked)return;const{origin:t,scale:i}=this.store.data;e.origin=$(t),e.scale=i,e.type!==H.Update&&e.pens&&e.pens.forEach((e=>{e.calculative&&(e.calculative.layer=this.store.data.pens.findIndex((t=>t.id===e.id)))})),this.store.historyIndex<this.store.histories.length-1&&this.store.histories.splice(this.store.historyIndex+1,this.store.histories.length-this.store.historyIndex-1),e.pens?.forEach((t=>{let i;if(e.initPens)for(const n of e.initPens)n.id===t.id&&(i=n);if(i)for(const e in t)null==i[e]&&(i[e]=void 0)})),this.store.histories.push(e),this.store.historyIndex=this.store.histories.length-1,this.store.emitter.emit("update",{previous:e.initPens,current:e.pens})}undo(){if(this.store.data.locked||null==this.store.historyIndex||this.store.historyIndex<0)return;const e=this.store.histories[this.store.historyIndex--];this.doEditAction(e,!0);let t=e.step;for(;t>1;){const e=this.store.histories[this.store.historyIndex--];this.doEditAction(e,!0),t--}e.type!=H.Add&&e.type!=H.Delete||this.activeHistory()}redo(){if(this.store.data.locked||null==this.store.historyIndex||this.store.historyIndex>this.store.histories.length-2)return;const e=this.store.histories[++this.store.historyIndex];this.doEditAction(e,!1);let t=e.step;for(;t>1;){const e=this.store.histories[++this.store.historyIndex];this.doEditAction(e,!1),t--}e.type!=H.Add&&e.type!=H.Delete||this.activeHistory()}activeHistory(){let e=this.store.histories[this.store.historyIndex];if(e&&e.type===H.Add){const t=[];e.pens.forEach((e=>{t.push(this.store.pens[e.id])})),this.active(t)}}doEditAction(e,t){switch(this.inactive(),this.store.hoverAnchor=void 0,this.store.hover=void 0,e.type){case H.Add:e.pens.forEach((e=>{const t=$(e,!0),i=this.store.data.pens.findIndex((e=>e.id===t.id));i>-1&&(t.onDestroy?.(this.store.pens[t.id]),this.store.data.pens.splice(i,1),this.store.pens[t.id]=void 0,t.calculative||(t.calculative={}),t.calculative.canvas=this,this.store.animates.delete(t),this.store.animateMap.delete(t))})),e.type=H.Delete;break;case H.Update:const i=t?e.initPens:e.pens,n=t?e.pens:e.initPens;i.forEach((t=>{const i=$(t,!0),r=this.store.data.pens.findIndex((e=>e.id===i.id));if(r>-1){i.calculative=this.store.data.pens[r].calculative,this.store.data.pens[r]=i,this.store.pens[i.id]=i;for(const e in i)"object"==typeof i[e]&&"lineDash"!==e||(i.calculative[e]=i[e]);i.calculative.image=void 0;const t=this.getPenRect(i,e.origin,e.scale);if(this.setPenRect(i,t,!1),this.updateLines(i,!0),i.calculative.canvas.parent.isCombine(i)){let e=n.find((e=>e.id===i.id));_.forEach((t=>{i[t]!==e[t]&&this.parent.setValue({id:i.id,[t]:i[t]},{render:!0,doEvent:!1})}))}}}));break;case H.Delete:e.pens.forEach((e=>{const t=$(e,!0);t.calculative||(t.calculative={}),this.store.data.pens.splice(t.calculative?.layer,0,t),this.store.pens[t.id]=t,t.calculative.canvas=this})),e.pens.forEach((t=>{const i=this.store.pens[t.id],n=this.getPenRect(i,e.origin,e.scale);this.setPenRect(i,n,!1),i.calculative.image=void 0,i.calculative.backgroundImage=void 0,i.calculative.strokeImage=void 0,this.loadImage(i)})),e.type=H.Add}e.type===H.Update?this.initImageCanvas([...e.pens,...e.initPens]):this.initImageCanvas(e.pens),this.parent.onSizeUpdate(),this.render(),this.store.emitter.emit(t?"undo":"redo",e)}makePen(e){if(e.id||(e.id=ne()),this.store.data.pens.push(e),this.store.pens[e.id]=e,e.path){!e.pathId&&(e.pathId=ne());const t=this.store.data.paths;!t[e.pathId]&&(t[e.pathId]=e.path),e.path=void 0}null==e.lineWidth&&(e.lineWidth=1);const{fontSize:t,lineHeight:i}=this.store.options;e.fontSize||(e.fontSize=t),e.lineHeight||(e.lineHeight=i),e.calculative={canvas:this,singleton:e.calculative?.singleton},(e.video||e.audio)&&(e.calculative.onended=e=>{this.nextAnimate(e)});for(const t in e)"object"==typeof e[t]&&"lineDash"!==t||(e.calculative[t]=e[t]);e.calculative.image=void 0,e.calculative.backgroundImage=void 0,e.calculative.strokeImage=void 0,!e.anchors&&N.anchors[e.name]&&(e.anchors||(e.anchors=[]),N.anchors[e.name](e)),this.updatePenRect(e),!e.anchors&&e.calculative.worldAnchors&&(e.anchors=e.calculative.worldAnchors.map((t=>Nt(t,e.calculative.worldRect)))),!e.rotate&&(e.rotate=0),this.loadImage(e)}drawline(e){this.drawingLine&&(this[this.drawingLineName]?.(this.store,this.drawingLine,e),this.store.path2dMap.set(this.drawingLine,N.path2dDraws.line(this.drawingLine)),this.patchFlags=!0)}initLineRect(e){if(!e)return;if(!e.calculative.worldAnchors?.length)return void this._del([e]);if(!isFinite(e.x)||!isFinite(e.x))return;if(null==e.x||null==e.y)return;const t=ti(e);e.parentId||Object.assign(e,t);const{fontSize:i,lineHeight:n}=this.store.options;e.fontSize||(e.fontSize=i,e.calculative.fontSize=e.fontSize*this.store.data.scale),e.lineHeight||(e.lineHeight=n,e.calculative.lineHeight=e.lineHeight),Tt(t),e.calculative.worldRect=t,Be(e,t),U(e),ht(e),this.store.path2dMap.set(e,N.path2dDraws[e.name](e)),e.calculative.worldAnchors&&(e.anchors=e.calculative.worldAnchors.map((t=>Nt(t,e.calculative.worldRect))))}drawingPencil(){pn(this.store),this.pencil=!0,this.externalElements.style.cursor="crosshair"}stopPencil(){this.pencil=!1,this.pencilLine=void 0,this.externalElements.style.cursor="default"}async finishDrawline(e){if(!this.drawingLine)return;const t=$e(this.drawingLine);let i=Xe(this.drawingLine);if(i.isTemp&&(this.drawingLine.calculative.worldAnchors.pop(),i=Xe(this.drawingLine)),!e&&(!i.connectTo&&this.drawingLine.calculative.worldAnchors.pop(),$e(this.drawingLine)===this.drawingLine.calculative.activeAnchor))return this.drawingLine=void 0,void this.render();if(t.connectTo&&i.connectTo){if(this.store.options.disableRepeatLine&&this.store.data.pens.find((e=>{if(e.type){const n=$e(e),r=Xe(e);return L(n,t)&&L(r,i)}})))return this.drawingLine=void 0,void this.render()}else if(this.store.options.disableEmptyLine)return this.drawingLine=void 0,void this.render();const n=ti(this.drawingLine);Object.assign(this.drawingLine,n),this.drawingLine.calculative.worldRect=n,this.drawingLine.calculative.activeAnchor=Xe(this.drawingLine),this.store.activeAnchor=this.drawingLine.calculative.activeAnchor,(!this.beforeAddPens||await this.beforeAddPens([this.drawingLine]))&&(!this.beforeAddPen||this.beforeAddPen(this.drawingLine))&&(this.initLineRect(this.drawingLine),this.store.data.pens.push(this.drawingLine),this.store.pens[this.drawingLine.id]=this.drawingLine,this.store.emitter.emit("add",[this.drawingLine]),this.active([this.drawingLine]),this.pushHistory({type:H.Add,pens:$([this.drawingLine],!0)})),this.store.path2dMap.set(this.drawingLine,N.path2dDraws[this.drawingLine.name](this.drawingLine)),this.drawingLine=void 0,this.drawingLineName=void 0,this.render()}async finishPencil(){if(this.pencilLine){const e=vi(this.pencilLine.calculative.worldAnchors,10,0,this.pencilLine.calculative.worldAnchors.length-1);let t=$e(this.pencilLine);e.unshift({id:t.id,penId:t.penId,x:t.x,y:t.y}),t=Xe(this.pencilLine),e.push({id:t.id,penId:t.penId,x:t.x,y:t.y}),this.pencilLine.calculative.worldAnchors=function(e,t=.8,i=!1){if(e.length<3)return e;let n,r,o,s,a,c,l,h,u,d,f,p,v,x,g,y;const m=(e,t,i,n)=>(s=Math.sqrt(e*e+t*t),s>0?(v=e/s,g=t/s):(v=1,g=0),a=Math.sqrt(i*i+n*n),a>0?(x=i/a,y=n/a):(x=1,y=0),Math.acos(v*x+g*y));f=[],p=e.length,n=e[0],h=e[p-1],f.push({...e[0]});for(let h=0;h<p-1;h++){if(r=e[h],o=e[h+1],d=Math.abs(m(r.x-n.x,r.y-n.y,o.x-r.x,o.y-r.y)),s)if(d<3.14*t)if(i&&(s=Math.min(s,a),a=s),c=(v+x)/2,l=(g+y)/2,u=Math.sqrt(c*c+l*l),0===u)f.push({...r});else{c/=u,l/=u;const e={...r};e.prevNextType=k.Bilateral,e.prev={penId:e.penId,x:r.x-c*s*.25,y:r.y-l*s*.25},e.next={penId:e.penId,x:r.x+c*a*.25,y:r.y+l*a*.25},f.push(e)}else f.push({...r});n=r}return f.push({...e[e.length-1]}),f}(e),this.pencilLine.calculative.worldAnchors.length>1&&(this.pencilLine.calculative.pencil=!1,this.store.path2dMap.set(this.pencilLine,N.path2dDraws[this.pencilLine.name](this.pencilLine)),(!this.beforeAddPens||await this.beforeAddPens([this.pencilLine]))&&(!this.beforeAddPen||this.beforeAddPen(this.pencilLine))&&(this.initLineRect(this.pencilLine),this.store.data.pens.push(this.pencilLine),this.store.pens[this.pencilLine.id]=this.pencilLine,this.store.emitter.emit("add",[this.pencilLine]),this.active([this.pencilLine]),this.pushHistory({type:H.Add,pens:$([this.pencilLine],!0)}))),this.pencilLine=void 0,this.render()}}firefoxLoadSvg(e){const t=new Image,i=new XMLHttpRequest;i.open("GET",e.image,!0),i.onload=()=>{const n=(new DOMParser).parseFromString(i.responseText,"text/xml").getElementsByTagName("svg")[0],{width:r,height:o}=e.calculative.worldRect;n.setAttribute("width",`${r}px`),n.setAttribute("height",`${o}px`);const s="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent((new XMLSerializer).serializeToString(n))));t.src=s,t.onload=()=>{e.calculative.img=t,e.calculative.imgNaturalWidth=t.naturalWidth||e.iconWidth,e.calculative.imgNaturalHeight=t.naturalHeight||e.iconHeight,N.htmlElements[e.image]=t,this.imageLoaded()}},i.send()}loadImage(e){if(e.image!==e.calculative.image||!e.calculative.img){if(e.calculative.img=void 0,e.image)if(N.htmlElements[e.image]){const t=N.htmlElements[e.image];e.calculative.img=t,e.calculative.imgNaturalWidth=t.naturalWidth||e.iconWidth,e.calculative.imgNaturalHeight=t.naturalHeight||e.iconHeight,this.imageLoaded()}else if(navigator.userAgent.includes("Firefox")&&e.image.endsWith(".svg"))this.firefoxLoadSvg(e);else{const t=new Image;t.crossOrigin="undefined"===e.crossOrigin?void 0:e.crossOrigin||"anonymous",t.src=e.image,this.store.options.cdn&&!(e.image.startsWith("http")||e.image.startsWith("//")||e.image.startsWith("data:image"))&&(t.src=this.store.options.cdn+e.image),t.onload=()=>{e.calculative.img=t,e.calculative.imgNaturalWidth=t.naturalWidth||e.iconWidth,e.calculative.imgNaturalHeight=t.naturalHeight||e.iconHeight,N.htmlElements[e.image]=t,this.imageLoaded()}}e.calculative.image=e.image}if(e.backgroundImage!==e.calculative.backgroundImage){if(e.calculative.backgroundImg=void 0,e.backgroundImage)if(N.htmlElements[e.backgroundImage]){const t=N.htmlElements[e.backgroundImage];e.calculative.backgroundImg=t}else{const t=new Image;t.crossOrigin="anonymous",t.src=e.backgroundImage,this.store.options.cdn&&!(e.backgroundImage.startsWith("http")||e.backgroundImage.startsWith("//")||e.backgroundImage.startsWith("data:image"))&&(t.src=this.store.options.cdn+e.backgroundImage),t.onload=()=>{e.calculative.backgroundImg=t,N.htmlElements[e.backgroundImage]=t,this.imageLoaded()}}e.calculative.backgroundImage=e.backgroundImage}if(e.strokeImage!==e.calculative.strokeImage){if(e.calculative.strokeImg=void 0,e.strokeImage)if(N.htmlElements[e.strokeImage]){const t=N.htmlElements[e.strokeImage];e.calculative.strokeImg=t}else{const t=new Image;t.crossOrigin="anonymous",t.src=e.strokeImage,this.store.options.cdn&&!(e.strokeImage.startsWith("http")||e.strokeImage.startsWith("//")||e.strokeImage.startsWith("data:image"))&&(t.src=this.store.options.cdn+e.strokeImage),t.onload=()=>{e.calculative.strokeImg=t,N.htmlElements[e.strokeImage]=t,this.imageLoaded()}}e.calculative.strokeImage=e.strokeImage}}imageLoaded(){this.imageTimer&&clearTimeout(this.imageTimer),this.imageTimer=setTimeout((()=>{this.canvasImage.init(),this.canvasImageBottom.init(),this.render()}),100)}setCalculativeByScale(e){const t=this.store.data.scale;e.calculative.lineWidth=e.lineWidth*t,e.calculative.fontSize=e.fontSize*t,e.fontSize<1&&(e.calculative.fontSize=e.fontSize*e.calculative.worldRect.height),e.calculative.iconSize=e.iconSize*t,e.calculative.iconWidth=e.iconWidth*t,e.calculative.iconHeight=e.iconHeight*t,e.calculative.iconLeft=e.iconLeft<1&&e.iconLeft>-1?e.iconLeft:e.iconLeft*t,e.calculative.iconTop=e.iconTop<1&&e.iconTop>-1?e.iconTop:e.iconTop*t,e.calculative.textWidth=e.textWidth<1&&e.textWidth>-1?e.textWidth:e.textWidth*t,e.calculative.textHeight=e.textHeight<1&&e.textHeight>-1?e.textHeight:e.textHeight*t,e.calculative.textLeft=e.textLeft<1&&e.textLeft>-1?e.textLeft:e.textLeft*t,e.calculative.textTop=e.textTop<1&&e.textTop>-1?e.textTop:e.textTop*t,e.type===r.Line&&e.borderWidth&&(e.calculative.borderWidth=e.borderWidth*t)}updatePenRect(e,{worldRectIsReady:t,playingAnimate:i}={}){t?Fe(e):Oe(e),i||this.setCalculativeByScale(e),ze(e),je(this.store.pens,e),U(e),ht(e),N.path2dDraws[e.name]&&this.store.path2dMap.set(e,N.path2dDraws[e.name](e)),e.calculative.patchFlags=!0,this.patchFlags=!0,e.children&&e.children.forEach((e=>{const t=this.store.pens[e];t&&this.updatePenRect(t,{worldRectIsReady:!1})})),e.type&&this.initLineRect(e),e.calculative.gradientTimer&&clearTimeout(e.calculative.gradientTimer),e.calculative.gradientTimer=setTimeout((()=>{e.calculative.lineGradient&&(e.calculative.lineGradient=null),e.calculative.gradient&&(e.calculative.gradient=null),e.calculative.radialGradient&&(e.calculative.radialGradient=null),this.patchFlags=!0,e.calculative.gradientTimer=void 0}),50)}translate(e=0,t=0){this.store.data.x+=e*this.store.data.scale,this.store.data.y+=t*this.store.data.scale,this.store.data.x=Math.round(this.store.data.x),this.store.data.y=Math.round(this.store.data.y),setTimeout((()=>{this.canvasImage.init(),this.canvasImageBottom.init(),this.render()})),this.store.emitter.emit("translate",{x:this.store.data.x,y:this.store.data.y}),this.tooltip.translate(e,t),this.scroll&&this.scroll.isShow&&this.scroll.translate(e,t),this.onMovePens()}onMovePens(){const e=this.parent.map;e&&e.isShow&&e.setView();for(const e of this.store.data.pens)ht(e),e.onMove?.(e),e.isRuleLine&&(e.width?e.height||(e.x=-this.store.data.x):e.y=-this.store.data.y,this.updatePenRect(e))}scale(e,t={x:0,y:0}){const{minScale:i,maxScale:n}=this.store.options;if(!(e>=i&&e<=n))return;this.calibrateMouse(t);const r=e/this.store.data.scale;this.store.data.scale=e,this.store.data.center=t,this.store.clipboard?.pos&&C(this.store.clipboard.pos,r,t),C(this.store.data.origin,r,t),this.store.data.pens.forEach((e=>{if(!e.parentId){if(He(e,r,t),e.onScale&&e.onScale(e),e.isRuleLine){const t=r>1?1:1/r/r,i=e.calculative.worldRect.center;e.width&&e.height||He(e,t,i)}this.updatePenRect(e,{worldRectIsReady:!0}),this.execPenResize(e)}})),this.calcActiveRect(),setTimeout((()=>{this.canvasImage.init(),this.canvasImageBottom.init();const e=this.parent.map;e&&e.isShow&&e.setView(),this.render(),this.store.emitter.emit("scale",this.store.data.scale)}))}rotatePens(e){this.initPens||(this.initPens=$(this.getAllByPens(this.store.active))),this.activeRect.rotate=E(e,this.activeRect.center),this.activeRect.rotate%90<10&&(this.activeRect.rotate-=this.activeRect.rotate%90),this.activeRect.rotate%90>80&&(this.activeRect.rotate+=90-this.activeRect.rotate%90),1===this.store.active.length&&(this.lastRotate=this.store.active[0].rotate||0);const t=this.activeRect.rotate-this.lastRotate;for(const e of this.store.active){if(e.parentId)return;this.rotatePen(e,t,this.activeRect),e.onRotate&&e.onRotate(e),this.updateLines(e)}this.lastRotate=this.activeRect.rotate,this.getSizeCPs(),this.initImageCanvas(this.store.active),this.render(),this.store.emitter.emit("rotatePens",this.store.active),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0,this.pushHistory({type:H.Update,pens:$(this.getAllByPens(this.store.active)),initPens:this.initPens}),this.initPens=void 0}),200)}resizePens(e){if(this.initPens||(this.initPens=$(this.store.active,!0)),!this.initActiveRect)return void(this.initActiveRect=$(this.activeRect));const t=this.mouseDown.x,i=this.mouseDown.y;let n=e.x-t,r=e.y-i;const o=$(this.initActiveRect);if(Lt(o,n,r,this.resizeIndex),Tt(o),!this.store.options.disableDock){this.clearDock();const e=this.customResizeDock||gt;this.dock=e(this.store,o,this.store.active,this.resizeIndex);const{xDock:t,yDock:i}=this.dock;t&&(n+=t.step,this.store.pens[t.penId].calculative.isDock=!0),i&&(r+=i.step,this.store.pens[i.penId].calculative.isDock=!0)}const s=this.activeRect.width,a=this.activeRect.height;let c=n-this.lastOffsetX,l=r-this.lastOffsetY;this.lastOffsetX=n,this.lastOffsetY=r,(e.ctrlKey||1===this.initPens.length&&this.initPens[0].ratio)&&(l=([1,3].includes(this.resizeIndex)?-1:1)*(c*a)/s),Lt(this.activeRect,c,l,this.resizeIndex),Tt(this.activeRect);const h=this.activeRect.width/s,u=this.activeRect.height/a;this.store.active.forEach(((e,t)=>{e.calculative.worldRect.x=this.activeInitPos[t].x*this.activeRect.width+this.activeRect.x,e.calculative.worldRect.y=this.activeInitPos[t].y*this.activeRect.height+this.activeRect.y,e.calculative.worldRect.width*=h,e.calculative.iconWidth&&(e.calculative.iconWidth*=h),e.calculative.worldRect.height*=u,e.calculative.iconHeight&&(e.calculative.iconHeight*=u),At(e.calculative.worldRect),Tt(e.calculative.worldRect),this.updatePenRect(e,{worldRectIsReady:!0}),this.execPenResize(e),this.updateLines(e)})),this.getSizeCPs(),this.initImageCanvas(this.store.active),this.render(),this.store.emitter.emit("resizePens",this.store.active),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0,this.pushHistory({type:H.Update,pens:$(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0}),200)}movePens(e){if(!this.activeRect||this.store.data.locked)return;if(!this.initActiveRect)return void(this.initActiveRect=$(this.activeRect));if(!this.store.options.moveConnectedLine&&!this.canMoveLine&&1===this.store.active.length&&(this.store.active[0].anchors[0]?.connectTo||this.store.active[0].anchors[this.store.active[0].anchors.length-1]?.connectTo))return;if(this.movingPens||(this.initMovingPens(),this.store.active.forEach((e=>{it(e,!1)})),this.store.hover=void 0),!this.mouseDown)return;let t=e.x-this.mouseDown.x,i=e.y-this.mouseDown.y;e.shiftKey&&!e.ctrlKey&&(i=0),e.ctrlKey&&(t=0);const n=$(this.initActiveRect);Rt(n,t,i);const r={x:n.x-this.activeRect.x,y:n.y-this.activeRect.y};if(!this.store.options.disableDock){this.clearDock();const e=this.customMoveDock||vt;this.dock=e(this.store,n,this.movingPens,r);const{xDock:t,yDock:i}=this.dock;let o;t&&(r.x+=t.step,o=this.store.pens[t.penId],o.calculative.isDock=!0),i&&(r.y+=i.step,o=this.store.pens[i.penId],o.calculative.isDock=!0)}this.translatePens(this.movingPens,r.x,r.y,!0)}changeIdsByMoving(e,t){e.id+=mn,e.parentId&&t.find((t=>t.id===e.parentId))&&(e.parentId+=mn),e.children&&(e.children=e.children.map((e=>e+mn))),e.connectedLines&&(e.connectedLines=e.connectedLines.map((e=>(t.find((t=>t.id===e.lineId))&&(e.lineId+=mn),e)))),e.type&&e.calculative.worldAnchors&&(e.calculative.worldAnchors=e.calculative.worldAnchors.map((e=>(e.connectTo&&t.find((t=>t.id===e.connectTo))&&(e.connectTo+=mn),e))))}initMovingPens(){if(!this.store.options.moveConnectedLine&&!this.canMoveLine)for(let e=0;e<this.store.active.length;e++){const t=this.store.active[e];(t.anchors[0]?.connectTo||t.anchors[t.anchors.length-1]?.connectTo)&&(this.store.active.splice(e,1),t.calculative.active=void 0,--e)}this.movingPens=$(this.store.active,!0);const e=this.getAllByPens(this.movingPens),t=$(e,!0);e.forEach((e=>{this.changeIdsByMoving(e,t),this.store.pens[e.id]=e,e.calculative.canvas=this;const i={globalAlpha:.5};0===e.lineWidth&&(i.lineWidth=1),(e.name.endsWith("Dom")||f.includes(e.name)||this.store.options.domShapes.includes(e.name)||e.image)&&(i.name="rectangle",i.onDestroy=void 0),this.updateValue(e,i),e.calculative.image=void 0}))}moveLineAnchor(e,t){if(!this.activeRect||this.store.data.locked)return;if(this.initPens||(this.initPens=$(this.store.active,!0)),this.store.activeAnchor?.connectTo){const e=this.store.pens[this.store.activeAnchor.connectTo];Ke(e,Ye(e,this.store.activeAnchor.anchorId),this.store.pens[this.store.activeAnchor.penId],this.store.activeAnchor)}let i=this.store.activeAnchor.id,n=this.store.pens[this.store.activeAnchor.penId]?.connectedLines?.filter((e=>e.anchor===i));n&&n.length>0&&n.forEach((e=>{const t=this.store.pens[e.lineId];Ke(this.store.pens[this.store.activeAnchor.penId],this.store.activeAnchor,t,Ye(t,e.lineAnchor))}));const r=this.store.active[0],o=($e(r),Xe(r));if("polyline"!==r.lineName||t.shiftKey){let i=0,n=0;if("line"===r.lineName&&r.calculative.worldAnchors[r.calculative.worldAnchors.length-1]===this.store.activeAnchor)if(t.ctrlKey&&t.shiftKey){let t=$(e);this.getSpecialAngle(t,r.calculative.worldAnchors[r.calculative.worldAnchors.length-2]),i=t.x-this.store.activeAnchor.x,n=t.y-this.store.activeAnchor.y}else if(!t.ctrlKey&&t.shiftKey){let t={x:e.x,y:r.calculative.worldAnchors[r.calculative.worldAnchors.length-2].y};i=t.x-this.store.activeAnchor.x,n=t.y-this.store.activeAnchor.y}else if(t.ctrlKey&&!t.shiftKey){let t={x:r.calculative.worldAnchors[r.calculative.worldAnchors.length-2].x,y:e.y};i=t.x-this.store.activeAnchor.x,n=t.y-this.store.activeAnchor.y}else i=e.x-this.store.activeAnchor.x,n=e.y-this.store.activeAnchor.y;else i=e.x-this.store.activeAnchor.x,n=e.y-this.store.activeAnchor.y;I(this.store.activeAnchor,i,n),this.store.hover&&this.store.hoverAnchor&&this.store.hoverAnchor.penId!==this.store.activeAnchor.penId&&(this.store.hoverAnchor.type===A.Line?(i=e.x-this.store.activeAnchor.x,n=e.y-this.store.activeAnchor.y,M(this.store.activeAnchor,this.store.hoverAnchor,this.store)):(i=this.store.hoverAnchor.x-this.store.activeAnchor.x,n=this.store.hoverAnchor.y-this.store.activeAnchor.y),I(this.store.activeAnchor,i,n),o.prev=void 0,"polyline"!==r.lineName&&this[r.lineName]?.(this.store,r))}else!function(e,t,i){if(!e.calculative.worldAnchors)return;const n=e.calculative.worldAnchors.findIndex((e=>e.id===t.id)),r=$e(e),o=Xe(e);let s=e.calculative.worldAnchors[n-1],a=e.calculative.worldAnchors[n+1];if(null==e.calculative.h&&(r.connectTo&&(fi(e,t,!0)?e.calculative.h=!0:pi(e,t,!0)&&(e.calculative.h=!1)),null==e.calculative.h&&o.connectTo&&(fi(e,t,!1)?e.calculative.h=!0:pi(e,t,!1)&&(e.calculative.h=!1)),null==e.calculative.h&&(s?e.calculative.h=s.y===t.y:a&&(e.calculative.h=a.y===t.y))),e.calculative.h){if(t.x=i.x,r.connectTo&&fi(e,t,!0))return void(a&&a.y!==t.y&&(a.x=t.x));if(o.connectTo&&fi(e,t,!1))return void(s&&s.y!==t.y&&(s.x=t.x));const c=e.anchors[n];let l;for(let t=n-1;t>-1;t--)if(s=e.anchors[t],null==l&&(l=s.y===c.y),!0===l){if(s.y!==c.y)break;e.calculative.worldAnchors[t].y=i.y}else{if(s.x!==c.x)break;e.calculative.worldAnchors[t].x=i.x}l=void 0;for(let t=n+1;t<e.calculative.worldAnchors.length&&(a=e.anchors[t],a);t++)if(null==l&&(l=a.y===c.y),!0===l){if(a.y!==c.y)break;e.calculative.worldAnchors[t].y=i.y}else{if(a.x!==c.x)break;e.calculative.worldAnchors[t].x=i.x}t.y=i.y}else{if(t.y=i.y,r.connectTo&&pi(e,t,!0))return void(a&&a.x!==t.x&&(a.y=t.y));if(o.connectTo&&pi(e,t,!1))return void(s&&s.x!==t.x&&(s.y=t.y));const c=e.anchors[n];let l;for(let t=n-1;t>-1;t--)if(s=e.anchors[t],null==l&&(l=s.x===c.x),!0===l){if(s.x!==c.x)break;e.calculative.worldAnchors[t].x=i.x}else{if(s.y!==c.y)break;e.calculative.worldAnchors[t].y=i.y}l=void 0;for(let t=n+1;t<e.calculative.worldAnchors.length&&(a=e.anchors[t],a);t++)if(null==l&&(l=a.x===c.x),!0===l){if(a.x!==c.x)break;e.calculative.worldAnchors[t].x=i.x}else{if(a.y!==c.y)break;e.calculative.worldAnchors[t].y=i.y}t.x=i.x}}(r,this.store.activeAnchor,e);this.patchFlagsLines.add(r),this.store.path2dMap.set(r,N.path2dDraws[r.name](r)),this.render(),this.store.active[0].calculative&&(this.store.active[0].calculative.gradientAnimatePath=void 0),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0,this.pushHistory({type:H.Update,pens:$(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0}),500)}moveLineAnchorPrev(e){if(!this.activeRect||this.store.data.locked||!this.store.activeAnchor)return;if(this.initPens||(this.initPens=$(this.store.active,!0)),this.store.activeAnchor.prev.x=e.x,this.store.activeAnchor.prev.y=e.y,this.store.activeAnchor.next)if(this.store.activeAnchor.prevNextType){if(this.store.activeAnchor.prevNextType===k.Bilateral&&this.prevAnchor){const t=E(e,this.store.activeAnchor),i=E(this.prevAnchor,this.store.activeAnchor);this.store.activeAnchor.next.x=this.nextAnchor.x,this.store.activeAnchor.next.y=this.nextAnchor.y,S(this.store.activeAnchor.next,t-i,this.store.activeAnchor)}}else this.store.activeAnchor.next.x=e.x,this.store.activeAnchor.next.y=e.y,S(this.store.activeAnchor.next,180,this.store.activeAnchor);const t=this.store.active[0];this.patchFlagsLines.add(t),this.store.path2dMap.set(t,N.path2dDraws[t.name](t)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0,this.pushHistory({type:H.Update,pens:$(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0}),200)}moveLineAnchorNext(e){if(!this.activeRect||this.store.data.locked||!this.store.activeAnchor)return;if(this.initPens||(this.initPens=$(this.store.active,!0)),this.store.activeAnchor.next.x=e.x,this.store.activeAnchor.next.y=e.y,this.store.activeAnchor.prev)if(this.store.activeAnchor.prevNextType){if(this.store.activeAnchor.prevNextType===k.Bilateral&&this.nextAnchor){const t=E(e,this.store.activeAnchor),i=E(this.nextAnchor,this.store.activeAnchor);this.store.activeAnchor.prev.x=this.prevAnchor.x,this.store.activeAnchor.prev.y=this.prevAnchor.y,S(this.store.activeAnchor.prev,t-i,this.store.activeAnchor)}}else this.store.activeAnchor.prev.x=e.x,this.store.activeAnchor.prev.y=e.y,S(this.store.activeAnchor.prev,180,this.store.activeAnchor);const t=this.store.active[0];this.patchFlagsLines.add(t),this.store.path2dMap.set(t,N.path2dDraws[t.name](t)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0,this.pushHistory({type:H.Update,pens:$(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0}),200)}async setAnchor(e){const t=[$(this.store.hover,!0)],i=this.store.hover;if(this.store.hoverAnchor){if(this.beforeRemoveAnchor&&!await this.beforeRemoveAnchor(i,this.store.hoverAnchor))return;i.type===r.Line&&i.calculative.worldAnchors?.length<=2?this.delete([i]):(function(e,t){if(!e||!e.calculative.worldAnchors)return;let i=e.calculative.worldAnchors.findIndex((e=>e.id===t.id));i>-1&&e.calculative.worldAnchors.splice(i,1),i=e.anchors.findIndex((e=>e.id===t.id)),i>-1&&e.anchors.splice(i,1)}(i,this.store.hoverAnchor),i.type===r.Line&&this.initLineRect(i)),this.store.hoverAnchor=void 0,this.store.activeAnchor=void 0,this.externalElements.style.cursor="default"}else if(i){if(this.beforeAddAnchor&&!await this.beforeAddAnchor(i,this.store.pointAt))return;if(i.type===r.Line){this.store.activeAnchor=function(e,t,i){e.anchors||(e.anchors=[]),e.calculative.worldAnchors||(e.calculative.worldAnchors=[]);const n=function(e,t,i){let n=e.calculative.worldAnchors[i],r=e.calculative.worldAnchors[i+1];const o=t.step;let s;if(n.next&&r.prev){const t=n,i=n.next,a=r.prev,c=r,l=Gt(t,i,o),h=Gt(i,a,o),u=Gt(a,c,o),d=Gt(l,h,o),f=Gt(h,u,o);s=Gt(d,f,o),d.penId=e.id,s.prev=d,f.penId=e.id,s.next=f,n.next.x=l.x,n.next.y=l.y,r.prev.x=u.x,r.prev.y=u.y}else if(n.next||r.prev){const i=n,a=n.next||r.prev,c=r,l=Gt(i,a,o),h=Gt(a,c,o);s=t,l.penId=e.id,h.penId=e.id,s.prev=l,s.next=h,n.next=void 0,r.prev=void 0}else s=t;return s.penId=e.id,s.id=ne(),s.prevNextType=k.Bilateral,s}(e,t,i);return e.calculative.worldAnchors.splice(i+1,0,n),e.anchors.splice(i+1,0,Nt(n,e.calculative.worldRect)),e.calculative.activeAnchor=n,n}(i,this.store.pointAt,this.store.pointAtIndex),this.initLineRect(i);const t={x:e.x,y:e.y};this.getHover(t)}else{const t={id:ne(),x:e.x,y:e.y};this.store.activeAnchor=function(e,t){e.anchors||(e.anchors=[]),e.calculative.worldAnchors||(e.calculative.worldAnchors=[]);const i={id:t.id,penId:e.id,x:t.x,y:t.y};if(e.calculative.worldAnchors.push(i),e.calculative.worldRect){e.rotate%360&&S(t,-e.rotate,e.calculative.worldRect.center);const i={id:t.id,penId:e.id,x:(t.x-e.calculative.worldRect.x)/e.calculative.worldRect.width,y:(t.y-e.calculative.worldRect.y)/e.calculative.worldRect.height};e.anchors.push(i)}return i}(i,t)}}this.hotkeyType=x.None,this.render(),i&&this.pushHistory({type:H.Update,pens:[$(i,!0)],initPens:t})}checkDisconnect(e,t){if(e.id.indexOf(mn)>0){const t=e.id;e=this.store.pens[t.replace(mn,"")]}e.anchors.forEach((i=>{if(i.connectTo&&!t.find((e=>e.id===i.connectTo||e.id===i.connectTo+mn))){const t=this.store.pens[i.connectTo];if(!t||t.type)return;Ke(t,Ye(t,i.anchorId),e,i)}}))}translatePens(e=this.store.active,t,i,n){if(!e||!e.length)return;if(e.some((e=>{if(e.locked>=o.DisableMove)return!0})))return;const s=!n&&$(e,!0);this.activeRect&&Rt(this.activeRect,t,i);const a=this.getAllByPens(e);e.forEach((e=>{if(!(e.locked>=o.DisableMove)){if(e.type===r.Line){if(!this.store.options.moveConnectedLine&&!this.canMoveLine)return;!function(e,t,i){e.x+=t,e.y+=i,e.anchors&&e.anchors.forEach((e=>{I(e,t,i)})),e.calculative.worldAnchors&&e.calculative.worldAnchors.forEach((e=>{I(e,t,i)}))}(e,t,i),this.checkDisconnect(e,a),this.store.path2dMap.set(e,N.path2dDraws[e.name](e)),n||(this.initLineRect(e),e.connectedLines?.forEach((e=>{const t=this.store.pens[e.lineId];this.initLineRect(t)})))}else Rt(e.calculative.worldRect,t,i),this.updatePenRect(e,{worldRectIsReady:!0}),e.calculative.x=e.x,e.calculative.y=e.y,e.calculative.initRect&&(e.calculative.initRect.x=e.calculative.x,e.calculative.initRect.y=e.calculative.y,e.calculative.initRect.ex=e.calculative.x+e.calculative.width,e.calculative.initRect.ey=e.calculative.y+e.calculative.height);this.updateLines(e),e.onMove?.(e)}})),this.activeRect&&this.getSizeCPs(),this.render(),this.tooltip.translate(t,i),n||(this.pushHistory({type:H.Update,pens:$(e,!0),initPens:s}),this.initImageCanvas(e),this.store.emitter.emit("translatePens",e)),this.store.emitter.emit("translatingPens",e)}calcAutoAnchor(e,t,i,n){const r=$e(e),o=Xe(e),s=We(i,t===r?o:r);t.x=s.x,t.y=s.y,t.prev=void 0,t.next=void 0,n?n.anchor=s.id:qe(i,s,e,t),this[e.lineName]&&this[e.lineName](this.store,e),this.store.path2dMap.set(e,N.path2dDraws.line(e)),this.initLineRect(e)}restoreNodeAnimate(e){if(e.calculative.initRect){if(e.keepAnimateState)for(const t in e)void 0!==e.calculative[t]&&("x"===t||"y"===t||"width"===t||"height"===t||"initRect"===t||"object"==typeof e[t]&&"lineDash"!==t||(e[t]="fontSize"===t||"lineWidth"===t?e.calculative[t]/e.calculative.canvas.store.data.scale:e.calculative[t]));else{const t=e.calculative.initRect.rotate-e.calculative.rotate;for(const t in e)"x"===t||"y"===t||"width"===t||"height"===t||"initRect"===t||"rotate"===t||"object"==typeof e[t]&&"lineDash"!==t||(e.calculative[t]=e[t]);e.children?.length?t&&st(e,t,e.calculative.worldRect):e.calculative.rotate=e.rotate;const i=$(this.store.animateMap.get(e));i&&(i.id=e.id,this.parent.setValue(i,{doEvent:!1,render:!0,history:!1})),e.calculative.worldRect=e.calculative.initRect}this.updatePenRect(e,{worldRectIsReady:!0}),e.calculative.text!==e.text&&(e.calculative.text=e.text,V(e)),e.calculative.initRect=void 0}}updateLines(e,t){e.children?.forEach((e=>{const i=this.store.pens[e];i&&this.updateLines(i,t)})),e.connectedLines&&e.connectedLines.forEach((i=>{const n=this.store.pens[i.lineId];if(!n||n.calculative.active)return;const r=Ye(n,i.lineAnchor);if(!r)return;if(n.autoFrom){const t=$e(n);t.id===r.id&&this.calcAutoAnchor(n,t,e,i)}if(n.autoTo){const t=Xe(n);t.id===r.id&&this.calcAutoAnchor(n,t,e,i)}const o=Ye(e,i.anchor);if(!o)return;let s=e.rotate;e.flipX&&(s*=-1),e.flipY&&(s*=-1);let a=r.distance*this.store.data.scale*Math.cos((s+o.rotate)/180*Math.PI)||0,c=r.distance*this.store.data.scale*Math.sin((s+o.rotate)/180*Math.PI)||0;if(e.flipX&&(a=-a),e.flipY&&(c=-c),I(r,o.x-r.x+a,o.y-r.y+c),this.store.options.autoPolyline&&!this.autoPolylineFlag&&!1!==n.autoPolyline&&"polyline"===n.lineName){let e=$e(n),t=Xe(n),i=!1;e.id===r.id?(e=r,i=!0):t.id===r.id&&(t=r,i=!0),i&&(n.calculative.worldAnchors=[e,t],n.calculative.activeAnchor=e,this.polyline(this.store,n,t),this.initLineRect(n))}this.store.path2dMap.set(n,N.path2dDraws[n.name](n)),this.patchFlagsLines.add(n),t&&ai(n)}))}calcActiveRect(){const e=this.store.active.filter((e=>(!e.locked||e.locked<o.DisableMove)&&0!=e.visible));e.length&&(1===e.length?(this.activeRect=$(e[0].calculative.worldRect),this.activeRect.rotate=e[0].calculative.rotate||0,Tt(this.activeRect)):(this.activeRect=St(e),this.activeRect.rotate=0),this.lastRotate=0,this.getSizeCPs())}rotatePen(e,t,i){e.type?(e.calculative.worldAnchors.forEach((e=>{S(e,t,i.center)})),this.initLineRect(e),Fe(e)):(e.calculative.rotate?e.calculative.rotate+=t:e.calculative.rotate=t,S(e.calculative.worldRect.center,t,i.center),e.parentId?(e.calculative.worldRect.x=e.calculative.worldRect.center.x-e.calculative.worldRect.width/2,e.calculative.worldRect.y=e.calculative.worldRect.center.y-e.calculative.worldRect.height/2,e.x=(e.calculative.worldRect.x-i.x)/i.width,e.y=(e.calculative.worldRect.y-i.y)/i.height):(e.x=e.calculative.worldRect.center.x-e.width/2,e.y=e.calculative.worldRect.center.y-e.height/2),e.rotate=e.calculative.rotate,this.updatePenRect(e),e.children&&e.children.forEach((i=>{const n=this.store.pens[i];this.rotatePen(n,t,e.calculative.worldRect)})))}nextAnimate(e){if(!e)return;let t;this.store.emitter.emit("animateEnd",e),e.nextAnimate&&(t=this.store.data.pens.filter((t=>t.id===e.nextAnimate||t.tags&&t.tags.indexOf(e.nextAnimate)>-1))),t&&(t.forEach((e=>{if(e.calculative.pause){const t=Date.now()-e.calculative.pause;e.calculative.pause=void 0,e.calculative.frameStart+=t,e.calculative.frameEnd+=t}else"video"===e.name?(e.calculative.media.currentTime=0,e.calculative.media?.play(),e.onStartVideo?.(e)):(e.type||e.frames?.length)&&(e.type||this.store.animateMap.set(e,this.getFrameProps(e)),this.store.animates.add(e))})),this.animate())}getFrameProps(e){let t={};return e.frames&&e.frames.forEach((i=>{for(let n in i)["duration","x","y","width","height","rotate"].includes(n)||t[n]||(t[n]=e[n])})),t}animate(){this.animateRendering||requestAnimationFrame((()=>{const e=Date.now();if(e-this.lastAnimateRender<this.store.options.animateInterval)return void(this.store.animates.size>0&&this.animate());this.lastAnimateRender=e,this.animateRendering=!0;const t=[];let i=!1;for(const n of this.store.animates)if(!n.calculative.pause){if(!n.calculative.active||n.type||this.movingPens||(i=!0),n.type){if(!et(n)){if(n.keepAnimateState){for(const e in n)void 0!==n.calculative[e]&&("object"==typeof n[e]&&"lineDash"!==e||(n[e]="lineWidth"===e?n.calculative[e]/n.calculative.canvas.store.data.scale:n.calculative[e]));Fe(n)}else for(const e in n)"object"==typeof n[e]&&"lineDash"!==e||(n.calculative[e]="lineWidth"===e?n[e]*n.calculative.canvas.store.data.scale:n[e]);t.push(n),this.nextAnimate(n)}}else Ge(n,e)?n.calculative.patchFlags&&(Tt(n.calculative.worldRect),this.updatePenRect(n,{worldRectIsReady:!0,playingAnimate:!0})):(requestAnimationFrame((()=>{this.restoreNodeAnimate(n)})),t.push(n),this.nextAnimate(n)),this.updateLines(n,!0);this.patchFlags=!0}i&&this.calcActiveRect(),t.forEach((e=>{this.store.animates.delete(e)})),this.render(!1),this.animateRendering=!1,this.animate()}))}get clipboardName(){return"meta2d-clipboard"}async copy(e,t=!0){const i=ne(),{origin:n,scale:r}=this.store.data;this.store.clipboard=void 0,localStorage.removeItem(this.clipboardName),sessionStorage.setItem("page",i);let o=this.getAllByPens($(e||this.store.active,!0));o.forEach((e=>{e.copyIndex=this.store.data.pens.findIndex((t=>t.id===e.id))})),o.sort(((e,t)=>e.copyIndex-t.copyIndex)),o.forEach((e=>{delete e.copyIndex}));const s={meta2d:!0,pens:o,origin:$(n),scale:r,page:i,initRect:$(this.activeRect),offset:10};if(!navigator.clipboard||this.store.options.disableClipboard||navigator.userAgent.includes("Firefox"))localStorage.setItem(this.clipboardName,JSON.stringify(s));else try{await navigator.clipboard.writeText(JSON.stringify(s))}catch{localStorage.setItem(this.clipboardName,JSON.stringify(s))}t&&this.store.emitter.emit("copy",s.pens)}cut(e){this.copy(e,!1),this.delete(e),this.store.emitter.emit("cut",e)}async paste(){let e,t,i,n;if(!navigator.clipboard||this.store.options.disableClipboard||navigator.userAgent.includes("Firefox"))e=localStorage.getItem(this.clipboardName);else try{e=await(navigator.clipboard?.readText())}catch{e=localStorage.getItem(this.clipboardName)}if(!e)return;try{t=JSON.parse(e)}catch(e){return void console.warn("剪切板数据不是json",e.message)}if(!t||!t.meta2d)return;if(this.beforeAddPens&&1!=await this.beforeAddPens(t.pens))return;this.store.clipboard&&(i=this.store.clipboard.offset+10,n=this.store.clipboard.pos),this.store.clipboard=$(t),sessionStorage.getItem("page")!==t.page?(this.store.clipboard.pos={x:this.mousePos.x,y:this.mousePos.y},this.store.clipboard.offset=0):this.pasteOffset?(i&&(this.store.clipboard.offset=i),n&&(this.store.clipboard.pos=n)):(this.store.clipboard.offset=0,this.pasteOffset=!0);const r=this.store.clipboard.pens.filter((e=>!e.parentId));for(const e of r)this.pastePen(e,void 0);sessionStorage.setItem("page",t.page),this.active(r),this.pushHistory({type:H.Add,pens:this.store.clipboard.pens}),this.render(),this.store.emitter.emit("add",this.store.clipboard.pens),this.store.emitter.emit("paste",this.store.clipboard.pens)}getAllByPens(e){const t=[];for(const i of e)t.push(...$(ae(i,this.store),!0));return t.concat(e)}changeLineAnchors(e,t,i){if(Array.isArray(t.connectedLines))for(let n=0;n<t.connectedLines.length;n++){const{lineId:r}=t.connectedLines[n],o=i.find((e=>e.id===r));if(o){const i=o.anchors[0],n=o.anchors[o.anchors.length-1];i.connectTo===e&&(i.connectTo=t.id),n.connectTo===e&&(n.connectTo=t.id)}else t.connectedLines.splice(n,1),n--}}changeNodeConnectedLine(e,t,i){const n=[t.anchors[0],t.anchors[t.anchors.length-1]];for(const r of n){const n=r.connectTo;if(n){const o=i.find((e=>e.id===n));o?o.connectedLines?.forEach((i=>{i.lineId===e&&(i.lineId=t.id,i.lineAnchor=r.id)})):(r.connectTo=void 0,r.prev&&(r.prev.connectTo=void 0),r.next&&(r.next.connectTo=void 0))}}}async delete(e=this.store.active,t=!1,i=!0){if(!e||!e.length)return;if(this.beforeRemovePens&&1!=await this.beforeRemovePens(e))return;if(t||(e=e.filter((e=>!e.locked))),!e||!e.length)return;const n=[];this._del(e,n),this.initImageCanvas(n),this.inactive(),this.clearHover(),this.render(),i&&this.pushHistory({type:H.Delete,pens:n}),this.store.emitter.emit("delete",e)}_del(e,t){e&&e.forEach((e=>{if(e.parentId){if(this.getLockedParent(e))return void console.warn("父节点锁定");{const i=se(e),n=i.children.indexOf(e.id);i.children.splice(n,1),t&&this.getDelPens(e,t),this.delForce(e)}}else{if(e.locked)return;t&&this.getDelPens(e,t),this.delForce(e)}}))}getDelPens(e,t){if(e){if(this.store.data.pens.findIndex((t=>t.id===e.id))>-1){const i=this.store.pens[e.id];i.calculative.active=void 0,t.push(i)}e.children&&e.children.forEach((e=>{this.getDelPens(this.store.pens[e],t)}))}}getLockedParent(e){if(!e.parentId)return!1;const t=se(e);if(t.locked)return t;this.getLockedParent(t)}delForce(e){if(!e)return;const t=this.store.data.pens.findIndex((t=>t.id===e.id));t>-1&&(this.delConnectedLines(this.store.data.pens[t]),this.store.data.pens.splice(t,1),this.store.pens[e.id]=void 0,delete this.store.pens[e.id]),this.store.animates.delete(e),this.store.animateMap.delete(e),e.children&&e.children.forEach((e=>{this.delForce(this.store.pens[e])})),e.onDestroy?.(e)}delConnectedLines(e){if(e.connectedLines)for(let t=0;t<e.connectedLines.length;t++){const{lineId:i,lineAnchor:n}=e.connectedLines[t],r=this.store.pens[i];if(r){let t=r.anchors.find((e=>e.id===n));t?.connectTo===e.id&&(t.connectTo=void 0,t.anchorId=void 0,t.prev&&(t.prev.connectTo=void 0),t.next&&(t.next.connectTo=void 0)),t=Ye(r,n),t&&(t.connectTo=void 0,t.anchorId=void 0,t.prev&&(t.prev.connectTo=void 0),t.next&&(t.next.connectTo=void 0))}}e.type&&e.calculative.worldAnchors?.forEach(((t,i)=>{if(!t.connectTo)return;const n=this.store.pens[t.connectTo];n&&n.calculative.worldAnchors?.forEach((i=>{Ke(n,i,e,t)}))}))}convertSpecialCharacter(e){var t={lt:"<",gt:">",nbsp:" ",amp:"&",quot:'"'};return e.replace(/&(lt|gt|nbsp|amp|quot);/gi,(function(e,i){return t[i]}))}createInput(){let e;this.inputParent.classList.add("meta2d-input"),this.inputRight.classList.add("right"),this.inputDiv.classList.add("input-div"),this.inputParent.appendChild(this.inputDiv),this.inputParent.appendChild(this.inputRight),this.dropdown.onmouseleave=()=>{this.store.hover=null},this.inputParent.appendChild(this.dropdown),this.externalElements.appendChild(this.inputParent),this.inputParent.onmousedown=this.stopPropagation,this.inputDiv.onmousedown=this.stopPropagation,this.inputDiv.contentEditable="false",this.inputRight.onmousedown=this.stopPropagation,this.dropdown.onmousedown=this.stopPropagation,this.inputRight.style.transform="rotate(135deg)";for(let t=0;t<document.styleSheets.length;t++)"le5le.com"===document.styleSheets[t].title&&(e=document.styleSheets[t]);if(!e){const t=document.createElement("style");t.title="le5le.com",document.head.appendChild(t),e=t.sheet,e.insertRule(".meta2d-input{display:none;position:absolute;outline:none;align-items: center;}"),e.insertRule(".meta2d-input textarea{resize:none;border:none;outline:none;background:transparent;flex-grow:1;height:100%;left:0;top:0}"),e.insertRule(".meta2d-input .right{width:10px;height:10px;flex-shrink:0;border-top: 1px solid;border-right: 1px solid;margin-right: 5px;transition: all .3s cubic-bezier(.645,.045,.355,1);position:absolute;right:1px;}"),e.insertRule(".meta2d-input ul{position:absolute;top:100%;left:-5px;width:calc(100% + 10px);min-height:30px;border-radius: 2px;box-shadow: 0 2px 8px #00000026;list-style-type: none;background-color: #fff;padding: 4px 0;max-height: 105px;overflow-y: auto;}"),e.insertRule(".meta2d-input ul li{padding: 5px 12px;line-height: 22px;white-space: nowrap;cursor: pointer;}"),e.insertRule(".meta2d-input ul li:hover{background: #eeeeee;}"),e.insertRule(".input-div::-webkit-scrollbar {display:none}"),e.insertRule(".meta2d-input .input-div{resize:none;border:none;outline:none;background:transparent;flex-grow:1;height:100%;width: 100%;left:0;top:0;display:flex;text-align: center;justify-content: center;flex-direction: column;}"),e.insertRule(".input-div div{}")}this.inputDiv.onclick=e=>{e.stopPropagation();const t=this.store.pens[this.inputDiv.dataset.penId];"block"===this.dropdown.style.display?(this.dropdown.style.display="none",this.inputRight.style.transform="rotate(135deg)"):t?.dropdownList&&this.store.data.locked&&(this.dropdown.style.display="block",this.inputRight.style.transform="rotate(315deg)"),this.store.emitter.emit("clickInput",t)},this.inputDiv.onkeyup=e=>{this.setDropdownList(!0);const t=this.store.pens[this.inputDiv.dataset.penId];this.store.emitter.emit("input",{pen:t,text:e.key}),e.stopPropagation()},this.inputDiv.onkeydown=e=>{e.stopPropagation()},this.inputDiv.onmousedown=this.stopPropagation,this.inputDiv.onwheel=e=>{e.stopPropagation()},this.inputDiv.onpaste=e=>{e.preventDefault();let t="";e.clipboardData&&e.clipboardData.getData&&(t=e.clipboardData.getData("text/plain")),document.execCommand("insertHTML",!1,t)}}clearDropdownList(){if(this.dropdown.hasChildNodes())for(let e=0;e<this.dropdown.childNodes.length;e++)this.dropdown.childNodes[e].remove(),--e}dropdownAppendOption(e,t){const i=document.createElement("li");i.onwheel=this.stopPropagation,i.innerText=e,i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.title=e,i.style.zoom=this.store.data.scale,i.onmousedown=this.stopPropagation,i.dataset.i=t+"",i.onclick=this.selectDropdown,this.dropdown.appendChild(i)}find(e){return this.store.data.pens.filter((t=>t.id==e||t.tags&&t.tags.indexOf(e)>-1))}findOne(e){return this.store.data.pens.find((t=>t.id==e||t.tags&&t.tags.indexOf(e)>-1))}changePenId(e,t){if(e===t)return;const i=this.store.pens[e];if(i&&!this.store.pens[t]){if(i.id=t,this.store.pens[t]=this.store.pens[e],i.onChangeId?.(i,e,t),delete this.store.pens[e],i.parentId){const n=this.store.pens[i.parentId],r=n.children?.findIndex((t=>t===e));-1!==r&&n.children?.splice(r,1,t)}i.children?.forEach((e=>{this.store.pens[e].parentId=t})),i.type===r.Line?this.changeNodeConnectedLine(e,i,this.store.data.pens):(this.changeLineAnchors(e,i,this.store.data.pens),i.connectedLines?.forEach((({lineId:e})=>{ze(this.store.pens[e])})))}}updateValue(e,t){const i=this.getPenRect(e),n=e.name;Object.assign(e,t);const r=n!==e.name;t.newId&&this.changePenId(e.id,t.newId);let o,s=!1,a=!1,d=!1,f=!1,p=!1,v=!1,x=!1;for(const i in t)"rotate"===i&&(o=e.calculative.rotate||0),"object"==typeof e[i]&&"lineDash"!==i||(e.calculative[i]=t[i]),c.includes(i)&&(a=!0),["name","borderRadius"].includes(i)&&(s=!0),l.includes(i)&&(p=!0),h.includes(i)&&(d=!0),u.includes(i)&&(f=!0),"isBottom"===i&&(v=!0),"image"===i&&(x=!0),-1!==i.indexOf(".")&&(delete e[i],gn(e,i,t[i]));if(this.setCalculativeByScale(e),r&&(e.onDestroy?.(e),function(e){e.onAdd=void 0,e.onValue=void 0,e.onBeforeValue=void 0,e.onDestroy=void 0,e.onMove=void 0,e.onResize=void 0,e.onRotate=void 0,e.onClick=void 0,e.onMouseEnter=void 0,e.onMouseLeave=void 0,e.onMouseDown=void 0,e.onMouseMove=void 0,e.onMouseUp=void 0,e.onShowInput=void 0,e.onInput=void 0,e.onChangeId=void 0,e.onBinds=void 0,e.onStartVideo=void 0,e.onPauseVideo=void 0,e.onStopVideo=void 0,e.onRenderPenRaw=void 0,e.onKeyDown=void 0}(e)),p){const n={x:t.x??i.x,y:t.y??i.y,width:t.width??i.width,height:t.height??i.height};this.setPenRect(e,n,!1),this.updateLines(e,!0)}else d?this.updatePenRect(e):(a&&U(e),f&&je(this.store.pens,e),s&&N.path2dDraws[e.name]&&this.store.path2dMap.set(e,N.path2dDraws[e.name](e)));if(void 0!==o){const t=e.calculative.rotate;e.calculative.rotate=o,this.rotatePen(e,t-o,e.calculative.worldRect)}(t.image||t.backgroundImage||t.strokeImage)&&(e.calculative.image=void 0,e.calculative.backgroundImage=void 0,e.calculative.strokeImage=void 0,this.loadImage(e)),t.lineGradientColors&&(e.calculative.lineGradient=void 0,e.calculative.gradientColorStop=void 0),t.gradientColors&&(e.calculative.gradient=void 0,e.calculative.radialGradient=void 0),t.gradientRadius&&(e.calculative.gradient=void 0,e.calculative.radialGradient=void 0),t.animateLineWidth&&(e.calculative.gradientAnimatePath=void 0),t.gradientSmooth&&(e.calculative.gradientAnimatePath=void 0),v?(this.canvasImage.init(),this.canvasImageBottom.init()):x?e.isBottom?this.canvasImageBottom.init():this.canvasImage.init():this.initImageCanvas([e])}execPenResize(e){e.onResize?.(e),e.children?.forEach((e=>{const t=this.store.pens[e];t&&this.execPenResize(t)}))}setPenRect(e,t,i=!0){if(e.parentId)Object.assign(e,t);else{const{origin:i,scale:n}=this.store.data;e.x=i.x+t.x*n,e.y=i.y+t.y*n,e.width=t.width*n,e.height=t.height*n}this.updatePenRect(e),this.execPenResize(e),i&&this.render()}getPenRect(e,t=this.store.data.origin,i=this.store.data.scale){if(e)return e.parentId?{x:e.x,y:e.y,width:e.width,height:e.height}:{x:(e.x-t.x)/i,y:(e.y-t.y)/i,width:e.width/i,height:e.height/i}}toPng(e=2,t,i=!1){const n=St(this.store.data.pens);if(!isFinite(n.width))throw new Error("can not to png, because width is not finite");const r=$(n),o=this.store.data,s=i&&!o.background&&this.store.bkImg;let a=!1,c=!1;if(s){if(n.x+=o.x,n.y+=o.y,At(n),Et(n,this.canvasRect,!0))Object.assign(n,this.canvasRect);else{const e=Ct([...Pt(n),...Pt(this.canvasRect)]);Object.assign(n,e)}a=0===n.x,c=0===n.y}const l=re(e);n.x-=l[3],n.y-=l[0],n.width+=l[3]+l[1],n.height+=l[0]+l[2],At(n);const h=document.createElement("canvas");if(h.width=n.width,h.height=n.height,h.width>32767||h.height>32767||!navigator.userAgent.includes("Firefox")&&h.height*h.width>268435456||navigator.userAgent.includes("Firefox")&&h.height*h.width>472907776)throw new Error("can not to png, because the size exceeds the browser limit");const u=h.getContext("2d");if(u.textBaseline="middle",s){const e=n.x<0?-n.x:0,t=n.y<0?-n.y:0;u.drawImage(this.store.bkImg,e,t,this.canvasRect.width,this.canvasRect.height)}const d=this.store.data.background||this.store.options.background;d&&(u.save(),u.fillStyle=d,u.fillRect(0,0,h.width,h.height),u.restore()),s?u.translate(a?o.x:-r.x,c?o.y:-r.y):u.translate(-n.x,-n.y);for(const e of this.store.data.pens){if(!lt(e,this.store)||0==e.visible)continue;const{active:t}=e.calculative;e.calculative.active=!1,e.calculative.img?Ie(u,e):Ce(u,e),e.calculative.active=t}if(!t)return h.toDataURL();h.toBlob(t)}toggleAnchorMode(){if(this.hotkeyType)this.hotkeyType===x.AddAnchor&&(this.hotkeyType=x.None,this.store.hoverAnchor?this.externalElements.style.cursor="vertical-text":this.store.hover&&(this.externalElements.style.cursor="move"));else{if(this.store.options.disableAnchor||this.store.hover?.disableAnchor)return;this.hotkeyType=x.AddAnchor,this.store.hover&&(this.externalElements.style.cursor="pointer")}this.patchFlags=!0}addAnchorHand(){if(this.store.activeAnchor&&this.store.active&&1===this.store.active.length&&this.store.active[0].type){const e=[$(this.store.active[0],!0)];this.store.activeAnchor.prev?this.store.activeAnchor.next||(this.store.activeAnchor.next={...this.store.activeAnchor.prev},S(this.store.activeAnchor.next,180,this.store.activeAnchor),this.initLineRect(this.store.active[0]),this.patchFlags=!0):(this.store.activeAnchor.next||(this.store.activeAnchor.next={penId:this.store.activeAnchor.penId,x:this.store.activeAnchor.x+50,y:this.store.activeAnchor.y}),this.store.activeAnchor.prev={...this.store.activeAnchor.next},S(this.store.activeAnchor.prev,180,this.store.activeAnchor),this.initLineRect(this.store.active[0]),this.patchFlags=!0),this.pushHistory({type:H.Update,pens:[$(this.store.active[0],!0)],initPens:e})}}removeAnchorHand(){if(this.store.activeAnchor&&this.store.active&&1===this.store.active.length&&this.store.active[0].type){const e=[$(this.store.active[0],!0)];this.hoverType===v.LineAnchorPrev?(this.store.activeAnchor.prev=void 0,this.initLineRect(this.store.active[0]),this.patchFlags=!0):this.hoverType===v.LineAnchorNext?(this.store.activeAnchor.next=void 0,this.initLineRect(this.store.active[0]),this.patchFlags=!0):(this.store.activeAnchor.prev=void 0,this.store.activeAnchor.next=void 0,this.initLineRect(this.store.active[0]),this.patchFlags=!0),this.pushHistory({type:H.Update,pens:[$(this.store.active[0])],initPens:e})}}toggleAnchorHand(){1===this.store.active.length&&this.store.active[0].type&&this.store.activeAnchor&&(this.store.activeAnchor.prevNextType||(this.store.activeAnchor.prevNextType=k.Mirror),this.store.activeAnchor.prevNextType=(this.store.activeAnchor.prevNextType+1)%3)}gotoView(e,t){const i=St(this.store.data.pens);if(!isFinite(i.width))throw new Error("can not move view, because width is not finite");this.store.data.x=this.canvas.clientWidth/2-e*i.width-i.x,this.store.data.y=this.canvas.clientHeight/2-t*i.height-i.y,this.onMovePens(),this.canvasImage.init(),this.canvasImageBottom.init(),this.render()}showMagnifier(){this.magnifierCanvas.magnifier=!0,this.externalElements.style.cursor="default",this.render()}hideMagnifier(){this.magnifierCanvas.magnifier=!1,this.externalElements.style.cursor="default",this.render()}toggleMagnifier(){this.magnifierCanvas.magnifier=!this.magnifierCanvas.magnifier,this.magnifierCanvas.magnifier&&(this.externalElements.style.cursor="default"),this.render()}destroy(){switch(this.scroll&&this.scroll.destroy(),this.tooltip?.destroy(),this.dialog?.destroy(),this.title?.destroy(),this.externalElements.removeEventListener("gesturestart",this.onGesturestart),this.externalElements.ondragover=e=>e.preventDefault(),this.externalElements.ondrop=void 0,this.externalElements.ontouchstart=void 0,this.externalElements.ontouchmove=void 0,this.externalElements.ontouchend=void 0,this.externalElements.onmousedown=void 0,this.externalElements.onmousemove=void 0,this.externalElements.onmouseup=void 0,this.externalElements.onmouseleave=void 0,this.externalElements.ondblclick=void 0,this.store.options.keydown){case z.Document:document.removeEventListener("keydown",this.onkeydown),document.removeEventListener("keyup",this.onkeyup);break;case z.Canvas:this.externalElements.removeEventListener("keydown",this.onkeydown),this.externalElements.removeEventListener("keyup",this.onkeyup)}document.removeEventListener("copy",this.onCopy),document.removeEventListener("cut",this.onCut),document.removeEventListener("paste",this.onPaste),window&&window.removeEventListener("resize",this.onResize),window&&window.removeEventListener("scroll",this.onScroll)}}var wn;!function(e){e[e.Link=0]="Link",e[e.SetProps=1]="SetProps",e[e.StartAnimate=2]="StartAnimate",e[e.PauseAnimate=3]="PauseAnimate",e[e.StopAnimate=4]="StopAnimate",e[e.JS=5]="JS",e[e.GlobalFn=6]="GlobalFn",e[e.Emit=7]="Emit",e[e.StartVideo=8]="StartVideo",e[e.PauseVideo=9]="PauseVideo",e[e.StopVideo=10]="StopVideo",e[e.SendPropData=11]="SendPropData",e[e.SendVarData=12]="SendVarData",e[e.Navigator=13]="Navigator",e[e.Dialog=14]="Dialog",e[e.SendData=15]="SendData"}(wn||(wn={}));class _n{constructor(e){let t;this.parent=e,this.boxWidth=320,this.boxHeight=180,this.ratio=this.boxWidth/this.boxHeight,this.padding=5,this.onMouseDown=e=>{e.preventDefault(),e.stopPropagation(),this.isDown=!0},this.onMouseMove=e=>{if(e.preventDefault(),e.stopPropagation(),this.isDown)try{this.parent.gotoView(e.offsetX/this.box.clientWidth,e.offsetY/this.box.clientHeight)}catch(e){console.warn(e.message),this.isDown=!1}},this.onMouseUp=e=>{e.preventDefault(),e.stopPropagation();try{this.parent.gotoView(e.offsetX/this.box.clientWidth,e.offsetY/this.box.clientHeight)}catch(e){console.warn(e.message)}finally{this.isDown=!1}},this.box=document.createElement("div"),this.img=new Image,this.view=document.createElement("div"),this.box.appendChild(this.img),this.box.appendChild(this.view),this.parent.externalElements.appendChild(this.box),this.box.className="meta2d-map",this.box.onmousedown=this.onMouseDown,this.box.onmousemove=this.onMouseMove,this.box.onmouseup=this.onMouseUp;for(let e=0;e<document.styleSheets.length;e++)"le5le/map"===document.styleSheets[e].title&&(t=document.styleSheets[e]);if(!t){let e=document.createElement("style");e.type="text/css",e.title="le5le.com/map",document.head.appendChild(e),e=document.createElement("style"),e.type="text/css",document.head.appendChild(e),t=e.sheet,t.insertRule(`.meta2d-map{display:flex;width:${this.boxWidth+2*this.padding}px;height:${this.boxHeight+2*this.padding}px;padding:${this.padding}px;background:#f4f4f4;border:1px solid #ffffff;box-shadow: 0px 0px 14px 0px rgba(0,10,38,0.30);border-radius:8px;position:absolute;z-index:9999;right:0;bottom:0;justify-content:center;align-items:center;cursor:default;user-select:none;overflow: hidden;}`),t.insertRule(".meta2d-map img{max-width:100%;max-height:100%;pointer-events: none;}"),t.insertRule(".meta2d-map div{pointer-events: none;border:1px solid #1890ff;position:absolute}")}}show(){this.box.style.display="flex",this.parent.store.data.pens.length?(this.img.style.display="block",this.img.src=this.parent.toPng(),this.setView()):this.img.style.display="none",this.isShow=!0}hide(){this.box.style.display="none",this.isShow=!1}setView(){const e=this.parent.store.data;if(e.pens.length){const t=St(e.pens);if(Rt(t,e.x,e.y),t.width/t.height>this.ratio){const e=t.width/this.ratio;t.y-=(e-t.height)/2,t.height=e,At(t)}else{const e=t.height*this.ratio;t.x-=(e-t.width)/2,t.width=e,At(t)}const i=this.parent.canvasRect;let n=0,r=0;if(t.x<0)n=-t.x/t.width;else if(t.x+t.width>i.width){let e=0;i.width>t.width&&(e=i.width-t.width),n=(-t.x+e)/t.width}if(t.y<0)r=-t.y/t.height;else if(t.y+t.height>i.height){let e=0;i.height>t.height&&(e=i.height-t.height),r=(-t.y+e)/t.height}const o=i.width>t.width?1:i.width/t.width,s=i.height>t.height?1:i.height/t.height;this.view.style.left=this.padding+n*this.boxWidth+"px",this.view.style.width=o*this.boxWidth+"px",this.view.style.top=this.padding+r*this.boxHeight+"px",this.view.style.height=s*this.boxHeight+"px"}}}var kn,Tn,An=i(421);class Sn{constructor(i,n={}){this.events={},this.facePen=Ue,this.getWords=q,this.calcTextLines=V,this.calcTextRect=U,this.calcTextDrawRect=W,this.register=O,this.registerCanvasDraw=B,this.registerAnchors=F,this.httpTimerList=[],this.onEvent=(e,t)=>{switch(e){case"add":t.forEach((e=>{e.onAdd?.(e)})),this.onSizeUpdate();break;case"enter":t&&t.onMouseEnter&&t.onMouseEnter(t,this.canvas.mousePos),this.store.data.locked&&this.doEvent(t,e);break;case"leave":t&&t.onMouseLeave&&t.onMouseLeave(t,this.canvas.mousePos),this.store.data.locked&&this.doEvent(t,e);break;case"active":case"inactive":this.store.data.locked&&t.forEach((t=>{this.doEvent(t,e)}));break;case"click":t.pen&&t.pen.onClick&&t.pen.onClick(t.pen,this.canvas.mousePos),this.store.data.locked&&t.pen&&this.doEvent(t.pen,e);break;case"mousedown":t.pen&&t.pen.onMouseDown&&t.pen.onMouseDown(t.pen,this.canvas.mousePos),this.store.data.locked&&t.pen&&this.doEvent(t.pen,e);break;case"mouseup":t.pen&&t.pen.onMouseUp&&t.pen.onMouseUp(t.pen,this.canvas.mousePos),this.store.data.locked&&t.pen&&this.doEvent(t.pen,e);break;case"dblclick":this.store.data.locked&&t.pen&&this.doEvent(t.pen,e);break;case"valueUpdate":this.store.data.locked&&this.doEvent(t,e),this.canvas.tooltip.updateText(t);break;case"update":case"delete":case"translatePens":case"rotatePens":case"resizePens":this.onSizeUpdate()}},this.doEvent=(e,t)=>{e&&(e.events?.forEach((i=>{if(i.actions&&i.actions.length)i.actions.forEach((n=>{this.events[n.action]&&i.name===t&&this.events[n.action](e,n)}));else if(this.events[i.action]&&i.name===t){let t=!i.where?.type;if(i.where){const{fn:n,fnJs:r,comparison:o,key:s,value:a}=i.where;if(n)t=n(e,{meta2d:this});else if(r){try{i.where.fn=new Function("pen","context",r)}catch(e){console.error("Error: make function:",e)}i.where.fn&&(t=i.where.fn(e,{meta2d:this}))}else switch(o){case">":t=e[s]>+a;break;case">=":t=e[s]>=+a;break;case"<":t=e[s]<+a;break;case"<=":t=e[s]<=+a;break;case"=":case"==":t=e[s]==a;break;case"!=":t=e[s]!=a;break;case"[)":t=te(+e[s],a);break;case"![)":t=!te(+e[s],a);break;case"[]":t=ie(+e[s],a);break;case"![]":t=!ie(+e[s],a)}}t&&this.events[i.action](e,i)}})),e.realTimes?.forEach((t=>{t.triggers?.forEach((i=>{let n=!1;"and"===i.conditionType?n=i.conditions.every((i=>this.judgeCondition(e,t.key,i))):"or"===i.conditionType&&(n=i.conditions.some((i=>this.judgeCondition(e,t.key,i)))),n&&i.actions?.forEach((t=>{this.events[t.action](e,t)}))}))})),this.doEvent(this.store.pens[e.parentId],t))},this.renderPenRaw=Ie,this.setElemPosition=nt,this.store=((e="default")=>{var t;return N[e]||(N[e]={data:{x:0,y:0,scale:1,pens:[],origin:{x:0,y:0},center:{x:0,y:0},paths:{}},histories:[],pens:{},path2dMap:new WeakMap,animateMap:new WeakMap,active:[],animates:new Set,options:{...j},emitter:{all:t=t||new Map,on:function(e,i){var n=t.get(e);n&&n.push(i)||t.set(e,[i])},off:function(e,i){var n=t.get(e);n&&n.splice(n.indexOf(i)>>>0,1)},emit:function(e,i){(t.get(e)||[]).slice().map((function(e){e(i)})),(t.get("*")||[]).slice().map((function(t){t(e,i)}))}},bindDatas:{},bind:{},cacheDatas:[]},N[e].id=e),N[e]})(ne()),this.setOptions(n),this.setDatabyOptions(n),this.init(i),this.register({rectangle:e,square:t,circle:Ei,svgPath:Wt,diamond:Ri,triangle:Ii,pentagon:Mi,pentagram:Ni,hexagon:Fi,leftArrow:zi,rightArrow:ji,twowayArrow:Hi,message:Ui,cloud:Wi,file:Vi,people:qi,line:Jt,iframe:gi,video:_i,gif:Yi,mindNode:en,mindLine:an}),this.registerCanvasDraw({cube:Vt}),this.registerAnchors({triangle:Li,pentagon:Di,pentagram:Oi,mindNode:rn,mindLine:cn}),globalThis.meta2d=this,this.initEventFns(),this.store.emitter.on("*",this.onEvent)}get beforeAddPen(){return this.canvas.beforeAddPen}set beforeAddPen(e){this.canvas.beforeAddPen=e}get beforeAddPens(){return this.canvas.beforeAddPens}set beforeAddPens(e){this.canvas.beforeAddPens=e}get beforeAddAnchor(){return this.canvas.beforeAddAnchor}set beforeAddAnchor(e){this.canvas.beforeAddAnchor=e}get beforeRemovePens(){return this.canvas.beforeRemovePens}set beforeRemovePens(e){this.canvas.beforeRemovePens=e}get beforeRemoveAnchor(){return this.canvas.beforeRemoveAnchor}set beforeRemoveAnchor(e){this.canvas.beforeRemoveAnchor=e}setOptions(e={}){this.store.options=Object.assign(this.store.options,e),this.canvas&&void 0!==e.scroll&&(e.scroll?(!this.canvas.scroll&&(this.canvas.scroll=new un(this.canvas)),this.canvas.scroll.show()):this.canvas.scroll&&this.canvas.scroll.hide())}getOptions(){return this.store.options}setDatabyOptions(e={}){const{color:t,activeColor:i,activeBackground:n,grid:r,gridColor:o,gridSize:s,fromArrow:a,toArrow:c,rule:l,ruleColor:h,textColor:u}=e;this.setRule({rule:l,ruleColor:h}),this.setGrid({grid:r,gridColor:o,gridSize:s}),this.store.data=Object.assign(this.store.data,{textColor:u,color:t,activeColor:i,activeBackground:n,fromArrow:a,toArrow:c})}init(e){this.canvas=new bn(this,"string"==typeof e?document.getElementById(e):e,this.store),this.resize(),this.canvas.listen()}initEventFns(){this.events[wn.Link]=(e,t)=>{window&&t.value&&"string"==typeof t.value?window.open(t.value,t.params??"_blank"):console.warn("[meta2d] Link param is not a string")},this.events[wn.SetProps]=(e,t)=>{const i=t.value;if(i&&"object"==typeof i)return(t.params?this.find(t.params):[e]).forEach((e=>{i.hasOwnProperty("visible")&&this.setVisible(e,i.visible),this.setValue({id:e.id,...i},{render:!1,doEvent:!1})})),void this.render();console.warn("[meta2d] SetProps value is not an object")},this.events[wn.StartAnimate]=(e,t)=>{t.targetType&&t.params?this.startAnimate(t.value||[e],t.params):t.value&&"string"!=typeof t.value?console.warn("[meta2d] StartAnimate value is not a string"):this.startAnimate(t.value||[e])},this.events[wn.PauseAnimate]=(e,t)=>{t.value&&"string"!=typeof t.value?console.warn("[meta2d] PauseAnimate value is not a string"):this.pauseAnimate(t.value||[e])},this.events[wn.StopAnimate]=(e,t)=>{t.value&&"string"!=typeof t.value?console.warn("[meta2d] StopAnimate event value is not a string"):this.stopAnimate(t.value||[e])},this.events[wn.StartVideo]=(e,t)=>{t.value&&"string"!=typeof t.value?console.warn("[meta2d] StartVideo value is not a string"):this.startVideo(t.value||[e])},this.events[wn.PauseVideo]=(e,t)=>{t.value&&"string"!=typeof t.value?console.warn("[meta2d] PauseVideo value is not a string"):this.pauseVideo(t.value||[e])},this.events[wn.StopVideo]=(e,t)=>{t.value&&"string"!=typeof t.value?console.warn("[meta2d] StopVideo event value is not a string"):this.stopVideo(t.value||[e])},this.events[wn.JS]=(e,t)=>{if(t.value&&!t.fn)try{if("string"!=typeof t.value)throw new Error("[meta2d] Function value must be string");const e=t.value;t.fn=new Function("pen","params","context",e)}catch(e){console.error("[meta2d]: Error on make a function:",e)}t.fn?.(e,t.params,{meta2d:this,eventName:t.name})},this.events[wn.GlobalFn]=(e,t)=>{"string"==typeof t.value?globalThis[t.value]&&globalThis[t.value](e,t.params):console.warn("[meta2d] GlobalFn value must be a string")},this.events[wn.Emit]=(e,t)=>{"string"==typeof t.value?this.store.emitter.emit(t.value,{pen:e,params:t.params,eventName:t.name}):console.warn("[meta2d] Emit value must be a string")},this.events[wn.SendPropData]=(e,t)=>{const i=$(t.value);if(i&&"object"==typeof i){const n=t.params?this.findOne(t.params):e;for(let e in i)i[e]||(i[e]=n[e]);return i.id=n.id,void this.doSendDataEvent(i,t.extend)}console.warn("[meta2d] SendPropData value is not an object")},this.events[wn.SendVarData]=(e,t)=>{const i=$(t.value);if(i&&"object"==typeof i){const n=t.params?this.findOne(t.params):e;let r=[];for(let e in i){let t={dataId:e,value:i[e]};if(!t.value){let e=n.form.find((e=>e.dataIds&&e.dataIds.dataId===t.dataId));e&&(t.value=n[e.key])}r.push(t)}this.doSendDataEvent(r,t.extend)}else console.warn("[meta2d] SendVarData value is not an object")},this.events[wn.Navigator]=(e,t)=>{t.value&&"string"==typeof t.value&&this.navigatorTo(t.value)},this.events[wn.Dialog]=(e,t)=>{t.params&&"string"==typeof t.params&&t.value&&"string"==typeof t.value&&this.canvas.dialog.show(t.value,t.params)},this.events[wn.SendData]=(e,t)=>{const i=$(t.value);if(i&&"object"==typeof i&&"action"===t.targetType){const n=t.params?this.findOne(t.params):e;for(let e in i)i[e]||(i[e]=n[e]);return i.id=n.id,void this.sendDataToNetWork(i,t.network)}}}navigatorTo(e){if(!e)return;let t=window.location.href.split("id=");if(t.length>1){let i=t[1].indexOf("&");window.location.href=-1===i?t[0]+"id="+e:t[0]+"id="+e+t[1].slice(i+1)}}doSendDataEvent(e,t){let i=JSON.stringify(e);this.mqttClient&&this.mqttClient.connected&&(t?t.split(",").forEach((e=>{this.mqttClient.publish(e,i)})):this.store.data.mqttTopics&&this.store.data.mqttTopics.split(",").forEach((e=>{this.mqttClient.publish(e,i)}))),this.websocket&&1===this.websocket.readyState&&this.websocket.send(i),(this.store.data.https||this.store.data.http)&&this.sendDatabyHttp(i),this.store.emitter.emit("sendData",i)}async sendDataToNetWork(e,t){if(t.url)if("http"===t.type)(await fetch(t.url,{headers:t.headers,method:t.method,body:e})).ok&&console.info("http消息发送成功");else if("mqtt"===t.type){const i=this.mqttClients.filter((e=>e.options.href===t.url));if(i&&i.length)i[0].connected&&t.topics.split(",").forEach((t=>{i[0].publish(t,e)}));else{let i=An.connect(t.url,t.options);i.on("connect",(()=>{console.info("mqtt连接成功"),t.topics.split(",").forEach((t=>{i.publish(t,e),i?.end()}))}))}}else if("websocket"===t.type){const i=this.websockets.filter((e=>e.url===t.url));if(i&&i.length)1===i[0].readyState&&i[0].send(e);else{let i=new WebSocket(t.url,t.protocols);i.onopen=function(){console.info("websocket连接成功"),i.send(e),setTimeout((()=>{i.close()}),100)}}}}resize(e,t){this.canvas.resize(e,t),this.render(),this.store.emitter.emit("resize",{width:e,height:t}),this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.init()}async addPen(e,t,i=!0){return await this.canvas.addPen(e,t,i)}async addPens(e,t){return await this.canvas.addPens(e,t)}render(e){this.canvas.render(e)}async setBackgroundImage(e){let t=this;this.store.data.bkImage=e;const i=this.store.data.width||this.store.options.width,n=this.store.data.height||this.store.options.height;if(this.canvas.canvasImageBottom.canvas.style.backgroundImage=i&&n?null:e?`url('${e}')`:"",e){const i=await async function(e){return new Promise((i=>{const n=new Image;n.src=e,t.store.options.cdn&&!(e.startsWith("http")||e.startsWith("//")||e.startsWith("data:image"))&&(n.src=t.store.options.cdn+e),n.crossOrigin="anonymous",n.onload=()=>{i(n)}}))}(e);this.store.bkImg=i}else this.store.bkImg=null}setBackgroundColor(e=this.store.data.background){this.store.data.background=e,this.store.patchFlagsBackground=!0}setGrid({grid:e=this.store.data.grid,gridColor:t=this.store.data.gridColor,gridSize:i=this.store.data.gridSize,gridRotate:n=this.store.data.gridRotate}={}){this.store.data.grid=e,this.store.data.gridColor=t,this.store.data.gridSize=i,this.store.data.gridRotate=n,this.store.patchFlagsBackground=!0}setRule({rule:e=this.store.data.rule,ruleColor:t=this.store.data.ruleColor}={}){this.store.data.rule=e,this.store.data.ruleColor=t,this.store.patchFlagsTop=!0}open(e,t=!0){if(this.clear(!1),this.canvas.autoPolylineFlag=!0,e){this.setBackgroundImage(e.bkImage),Object.assign(this.store.data,e),this.store.data.pens=[];for(const t of e.pens)t.id||(t.id=ne()),!t.calculative&&(t.calculative={canvas:this.canvas}),this.store.pens[t.id]=t;for(const t of e.pens)this.canvas.makePen(t);for(const t of e.pens)this.canvas.updateLines(t)}if(this.canvas.patchFlagsLines.forEach((e=>{e.type&&this.canvas.initLineRect(e)})),t||(this.canvas.opening=!0),this.initBindDatas(),this.initBinds(),this.render(),this.listenSocket(),this.connectSocket(),this.connectNetwork(),this.startAnimate(),this.startVideo(),this.doInitJS(),this.store.data.iconUrls)for(const e of this.store.data.iconUrls)i=e,n=()=>{this.render()},void 0,r=void 0,(r=document.createElement("link")).href=i,r.rel="stylesheet",n&&(r.onload=n),document.head.appendChild(r);var i,n,r;this.canvas.autoPolylineFlag=!1,this.store.emitter.emit("opened"),this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.init()}cacheData(e){if(e&&this.store.options.cacheLength){let t=this.store.cacheDatas.findIndex((t=>t.data&&t.data._id===e));if(-1===t)this.store.cacheDatas.push({data:$(this.store.data,!0)}),this.store.cacheDatas.length>this.store.options.cacheLength&&this.store.cacheDatas.shift();else{let e=this.store.cacheDatas.splice(t,1)[0];this.store.cacheDatas.push(e)}}}loadCacheData(e){let t=this.store.cacheDatas.findIndex((t=>t.data&&t.data._id===e));-1!==t&&(this.store.data=this.store.cacheDatas[t].data,this.setBackgroundImage(this.store.data.bkImage),this.store.pens={},this.store.data.pens.forEach((e=>{e.calculative.canvas=this.canvas,this.store.pens[e.id]=e,N.path2dDraws[e.name]&&this.store.path2dMap.set(e,N.path2dDraws[e.name](e)),e.type&&this.store.path2dMap.set(e,N.path2dDraws[e.name](e)),e.image&&(e.calculative.imageDrawed=!1,this.canvas.loadImage(e))})),this.render())}initBindDatas(){this.store.bindDatas={},this.store.data.pens.forEach((e=>{e.form?.forEach((t=>{let i;t.dataIds&&(i=Array.isArray(t.dataIds)?t.dataIds:[t.dataIds]),i?.forEach((i=>{this.store.bindDatas[i.dataId]||(this.store.bindDatas[i.dataId]=[]),this.store.bindDatas[i.dataId].push({id:e.id,formItem:t})}))}))}))}initBinds(){this.store.bind={},this.store.data.pens.forEach((e=>{e.realTimes?.forEach((t=>{t.bind&&t.bind.id&&(this.store.bind[t.bind.id]||(this.store.bind[t.bind.id]=[]),this.store.bind[t.bind.id].push({id:e.id,key:t.key}))}))}))}connectSocket(){this.connectWebsocket(),this.connectMqtt(),this.connectHttp()}doInitJS(){const e=this.store.data.initJs;if(e&&e.trim())try{new Function("context",e)({meta2d:this})}catch(e){console.warn("initJs error",e)}}drawLine(e){e&&pn(this.store),this.canvas.drawingLineName=e}drawingPencil(){this.canvas.drawingPencil()}stopPencil(){this.canvas.stopPencil()}lock(e){this.store.data.locked=e,this.finishDrawLine(!0),this.canvas.drawingLineName="",this.stopPencil(),this.store.data.pens.forEach((e=>{!0===e.externElement&&e.onMove&&e.onMove(e)}))}async finishDrawLine(e){await this.canvas.finishDrawline(e)}async finishPencil(){await this.canvas.finishPencil()}updateLineType(e,t){if(!e||"line"!=e.name||!t||!this.canvas[t])return;e.lineName=t;const i=$e(e),n=Xe(e);i.prev=void 0,i.next=void 0,n.prev=void 0,n.next=void 0,e.calculative.worldAnchors=[i,n],e.calculative.activeAnchor=i,this.canvas[t](this.store,e,n),"curve"===e.lineName&&(i.prev={penId:i.penId,x:i.x-50,y:i.y},i.next={penId:i.penId,x:i.x+50,y:i.y},n.prev={penId:n.penId,x:n.x-50,y:n.y},n.next={penId:n.penId,x:n.x+50,y:n.y}),e.calculative.activeAnchor=void 0,this.canvas.initLineRect(e),this.render()}addDrawLineFn(e,t){this.canvas[e]=t,this.canvas.drawLineFns.push(e)}removeDrawLineFn(e){const t=this.canvas.drawLineFns.indexOf(e);t>-1&&this.canvas.drawLineFns.splice(t,1)}showMagnifier(){this.canvas.showMagnifier()}hideMagnifier(){this.canvas.hideMagnifier()}toggleMagnifier(){this.canvas.toggleMagnifier()}clear(e=!0){for(const e of this.store.data.pens)e.onDestroy?.(e);var t;(t=this.store).data={x:0,y:0,scale:1,pens:[],origin:{x:0,y:0},center:{x:0,y:0},paths:{}},t.pens={},t.histories=[],t.historyIndex=null,t.path2dMap=new WeakMap,t.animateMap=new WeakMap,t.bindDatas={},t.bind={},t.active=[],t.hover=void 0,t.lastHover=void 0,t.animates.clear(),this.hideInput(),this.canvas.tooltip.hide(),this.canvas.clearCanvas(),sessionStorage.removeItem("page"),this.store.clipboard=void 0,this.store.patchFlagsBackground=!0,this.store.patchFlagsTop=!0,this.setBackgroundImage(void 0),e&&this.render()}emit(e,t){this.store.emitter.emit(e,t)}on(e,t){return this.store.emitter.on(e,t),this}off(e,t){return this.store.emitter.off(e,t),this}registerMoveDock(e){this.canvas.customMoveDock=e}registerResizeDock(e){this.canvas.customResizeDock=e}find(e){return this.canvas.find(e)}findOne(e){return this.canvas.findOne(e)}getPenRect(e){return this.canvas.getPenRect(e)}setPenRect(e,t,i=!0){this.canvas.setPenRect(e,t,i)}startAnimate(e,t){let i;this.stopAnimate(e),i=e?"string"==typeof e?this.find(e):e:this.store.data.pens.filter((e=>(e.type||e.frames)&&e.autoPlay)),i.forEach((e=>{if(e.calculative.pause){const t=Date.now()-e.calculative.pause;e.calculative.pause=void 0,e.calculative.frameStart+=t,e.calculative.frameEnd+=t}else{if(void 0!==t&&e.animations){let i=-1;if("string"==typeof t){if(i=e.animations.findIndex((e=>e.name===t)),-1===i)return}else if("number"==typeof t){if(!(e.animations.length>t))return;i=t}const n=$(e.animations[i]);delete n.name,n.currentAnimation=i,!e.type&&n.frames&&(n.showDuration=this.calcAnimateDuration(n)),this.setValue({id:e.id,...n},{doEvent:!1,history:!1})}this.store.animates.add(e),e.type||this.store.animateMap.set(e,e.calculative.canvas.getFrameProps(e))}})),this.canvas.canvasImage.init(),this.canvas.canvasImageBottom.init(),this.canvas.animate()}pauseAnimate(e){let t=[];e?t="string"==typeof e?this.find(e):e:this.store.animates.forEach((e=>{t.push(e)})),t.forEach((e=>{e.calculative.pause||(e.calculative.pause=Date.now())}))}stopAnimate(e){let t=[];e?t="string"==typeof e?this.find(e):e:this.store.animates.forEach((e=>{t.push(e)})),t.forEach((e=>{e.currentAnimation=void 0,e.calculative.pause=void 0,e.calculative.start=void 0,e.calculative.duration=void 0,e.calculative.animatePos=0,this.store.animates.delete(e),this.canvas.restoreNodeAnimate(e),this.canvas.updateLines(e),this.store.animateMap.delete(e)})),this.initImageCanvas(t),setTimeout((()=>{this.canvas.calcActiveRect(),this.render()}),20)}startVideo(e){let t;t=e?"string"==typeof e?this.find(e):e:this.store.data.pens.filter((e=>(e.video||e.audio)&&e.autoPlay)),t.forEach((e=>{e.calculative.media?.play(),e.onStartVideo?.(e)}))}pauseVideo(e){let t=[];t=e?"string"==typeof e?this.find(e):e:this.store.data.pens.filter((e=>(e.video||e.audio)&&e.autoPlay)),t.forEach((e=>{e.calculative.media?.pause(),e.onPauseVideo?.(e)}))}stopVideo(e){let t=[];t=e?"string"==typeof e?this.find(e):e:this.store.data.pens.filter((e=>(e.video||e.audio)&&e.autoPlay)),t.forEach((e=>{e.calculative.media&&(e.calculative.media.currentTime=0,e.calculative.media.pause()),e.onStopVideo?.(e)}))}calcAnimateDuration(e){return e.frames.reduce(((e,t)=>e+t.duration),0)}combine(e=this.store.active,t){if(!e||!e.length)return;const i=$(e);if(1===e.length&&e[0].type)return e[0].type=r.Node,this.canvas.active(e),this.pushHistory({type:H.Update,initPens:i,pens:$(e,!0)}),void this.render();const n=St(e);let s={id:ne(),name:"combine",...n,children:[],showChild:t};this.canvas.makePen(s);const a=$(s);let c=1/0;e.forEach((e=>{const t=this.store.data.pens.findIndex((t=>t.id===e.id));if(t<c&&(c=t),e===s||e.parentId===s.id)return;s.children.push(e.id),e.parentId=s.id;const i=Dt(e.calculative.worldRect,n);Object.assign(e,i),e.locked=e.lockedOnCombine??o.DisableMove})),this.store.data.pens.splice(c,0,s),this.store.data.pens.pop(),this.canvas.active([s]),this.pushHistory({type:H.Add,pens:[a],step:3}),this.pushHistory({type:H.Update,initPens:[a],pens:[s],step:3}),this.pushHistory({type:H.Update,initPens:i,pens:e,step:3}),null!=t&&(e.forEach((e=>{ht(e,!0)})),this.initImageCanvas([s])),this.store.emitter.emit("combine",[s]),this.render()}uncombine(e){if(!e&&this.store.active&&(e=this.store.active[0]),!e||!e.children)return;const t=e.children.map((e=>this.store.pens[e]));let i=$(t);t.forEach((e=>{e.parentId=void 0,e.x=e.calculative.worldRect.x,e.y=e.calculative.worldRect.y,e.width=e.calculative.worldRect.width,e.height=e.calculative.worldRect.height,e.locked=o.None,e.calculative.active=void 0,e.calculative.hover=!1,this.setVisible(e,!0)}));const n=this.isCombine(e)?3:2;this.pushHistory({type:H.Update,initPens:i,pens:t,step:n}),i=[$(e)],e.children=void 0,this.pushHistory({type:H.Update,initPens:i,pens:[e],step:n}),this.isCombine(e)&&(this.delete([e]),this.store.histories[this.store.histories.length-1].step=n),this.inactive()}isCombine(e){return"combine"===e.name||!!(e.children&&e.children.length>0)}active(e,t=!0){this.canvas.active(e,t)}inactive(){this.canvas.inactive()}activeAll(){this.canvas.active(this.store.data.pens.filter((e=>!e.parentId&&e.locked!==o.Disable))),this.render()}delete(e,t=!1,i=!0){this.canvas.delete(e,t,i)}scale(e,t={x:0,y:0}){this.canvas.scale(e,t)}translate(e,t){this.canvas.translate(e,t)}translatePens(e,t,i){this.canvas.translatePens(e,t,i)}getParent(e,t){return se(e,t)}data(){const e=$(this.store.data),{pens:t,paths:i}=this.store.data;e.version=D,e.paths={};for(const n in i)Object.prototype.hasOwnProperty.call(i,n)&&t.find((e=>e.pathId===n))&&(e.paths[n]=i[n]);return e}copy(e){this.canvas.copy(e)}cut(e){this.canvas.cut(e)}paste(){this.canvas.paste()}undo(){this.canvas.undo()}redo(){this.canvas.redo()}listenSocket(){try{let e;const t=this.store.data.socketCbJs;if(t&&(e=new Function("e","context",t)),!e)return!1;this.socketFn=e}catch(e){return console.error("Create the function for socket:",e),!1}return!0}connectWebsocket(e){this.closeWebsocket(),e&&(this.store.data.websocket=e),this.store.data.websocket&&(this.websocket=new WebSocket(this.store.data.websocket,this.store.data.websocketProtocols),this.websocket.onmessage=e=>{this.socketCallback(e.data,{type:"websocket",url:this.store.data.websocket})},this.websocket.onclose=()=>{console.info("Canvas websocket closed and reconneting..."),this.connectWebsocket()})}closeWebsocket(){this.websocket&&(this.websocket.onclose=void 0,this.websocket.close(),this.websocket=void 0)}connectMqtt(e){this.closeMqtt(),e&&(this.store.data.mqtt=e.mqtt,this.store.data.mqttTopics=e.mqttTopics,this.store.data.mqttOptions=e.mqttOptions),this.store.data.mqtt&&(this.store.data.mqttOptions.clientId&&!this.store.data.mqttOptions.customClientId&&(this.store.data.mqttOptions.clientId=ne()),this.mqttClient=An.connect(this.store.data.mqtt,this.store.data.mqttOptions),this.mqttClient.on("message",((e,t)=>{this.socketCallback(t.toString(),{topic:e,type:"mqtt",url:this.store.data.mqtt})})),this.store.data.mqttTopics&&this.mqttClient.subscribe(this.store.data.mqttTopics.split(",")))}closeMqtt(){this.mqttClient?.end()}connectHttp(){this.closeHttp();const{https:e}=this.store.data;if(e)e.forEach(((e,t)=>{e.http&&(this.httpTimerList[t]=setInterval((async()=>{const t=await fetch(e.http,{headers:e.httpHeaders});if(t.ok){const i=await t.text();this.socketCallback(i,{type:"http",url:e.http})}}),e.httpTimeInterval||1e3))}));else{const{http:e,httpTimeInterval:t,httpHeaders:i}=this.store.data;e&&(this.httpTimer=setInterval((async()=>{const t=await fetch(e,{headers:i});if(t.ok){const i=await t.text();this.socketCallback(i,{type:"http",url:e})}}),t||1e3))}}async sendDatabyHttp(e){const{https:t}=this.store.data;if(t)t.forEach((async t=>{t.http&&(await fetch(t.http,{method:"post",body:e,headers:t.httpHeaders})).ok&&console.info("http消息发送成功")}));else{const{http:t,httpHeaders:i}=this.store.data;t&&(await fetch(t,{method:"post",body:e,headers:i})).ok&&console.info("http消息发送成功")}}closeHttp(){clearInterval(this.httpTimer),this.httpTimer=void 0,this.httpTimerList&&this.httpTimerList.forEach((e=>{clearInterval(e),e=void 0}))}connectNetwork(){this.closeNetwork();const{networks:e}=this.store.data,t=[];if(e){let i=0;this.mqttClients=[];let n=0;this.websockets=[],e.forEach((e=>{"subscribe"===e.type&&("mqtt"===e.protocol?(e.options.clientId&&!e.options.customClientId&&(e.options.clientId=ne()),this.mqttClients[i]=An.connect(e.url,e.options),this.mqttClients[i].on("message",((t,i)=>{this.socketCallback(i.toString(),{topic:t,type:"mqtt",url:e.url})})),e.topics&&this.mqttClients[i].subscribe(e.topics.split(",")),i+=1):"websocket"===e.protocol?(this.websockets[n]=new WebSocket(e.url,e.protocols),this.websockets[n].onmessage=t=>{this.socketCallback(t.data,{type:"websocket",url:e.url})},n+=1):"http"===e.protocol&&t.push({url:e.url,headers:e.headers||void 0,method:e.method,body:e.body}))}))}this.onNetworkConnect(t)}randomString(e){e=e||32;let t="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",i=t.length,n="";for(let r=0;r<e;r++)n+=t.charAt(Math.floor(Math.random()*i));return n}penMock(e){if(e.realTimes){let t={};if(e.realTimes.forEach((e=>{if(e.enableMock&&void 0!==e.mock)if("float"===e.type)if(e.mock&&-1!==e.mock.indexOf(",")){let i=e.mock.split(","),n=Math.floor(Math.random()*i.length);t[e.key]=parseFloat(i[n])}else if(e.mock&&-1!==e.mock.indexOf("-")){let i,n,r,o=e.mock.split("-");if("-"===e.mock.charAt(0)?4===o.length?(i=-parseFloat(o[3]),n=-parseFloat(o[1]),r=o[3]):(i=parseFloat(o[2]),n=-parseFloat(o[1]),r=o[2]):(i=parseFloat(o[1]),n=parseFloat(o[0]),r=o[1]),-1!==(r+"").indexOf(".")){let o=(r+"").split(".")[1].length;t[e.key]=(Math.random()*(i-n)+n).toFixed(o)}else t[e.key]=Math.random()*(i-n)+n}else t[e.key]=parseFloat(e.mock);else if("integer"===e.type)if(e.mock&&-1!==e.mock.indexOf(",")){let i=e.mock.split(","),n=Math.floor(Math.random()*i.length);t[e.key]=parseInt(i[n])}else if(e.mock&&-1!==e.mock.indexOf("-")){let i,n,r=e.mock.split("-");"-"===e.mock.charAt(0)?4===r.length?(i=-parseFloat(r[3]),n=-parseFloat(r[1])):(i=parseFloat(r[2]),n=-parseFloat(r[1])):(i=parseInt(r[1]),n=parseInt(r[0])),t[e.key]=parseInt(Math.random()*(i-n)+n+"")}else t[e.key]=parseInt(e.mock);else if("bool"===e.type)"boolean"==typeof e.mock?t[e.key]=e.mock:"true"===e.mock?t[e.key]=!0:"false"===e.mock?t[e.key]=!1:t[e.key]=Math.random()<.5;else if("object"===e.type||"array"===e.type)e.mock;else if(e.mock&&e.mock.startsWith("{")&&e.mock.endsWith("}")){let i=e.mock.substring(1,e.mock.length-1).split(","),n=Math.floor(Math.random()*i.length);t[e.key]=i[n]}else if(e.mock&&e.mock.startsWith("[")&&e.mock.endsWith("]")){let i=parseInt(e.mock.substring(1,e.mock.length-1));t[e.key]=this.randomString(i)}else t[e.key]=e.mock})),Object.keys(t).length){let i=e.onBeforeValue?e.onBeforeValue(e,t):t;this.canvas.updateValue(e,i),this.store.emitter.emit("valueUpdate",e),e.onValue?.(e)}}}onNetworkConnect(e){let t=this.store.data.enableMock;(e&&e.length||t)&&(this.updateTimer=setInterval((()=>{t&&this.store.data.pens.forEach((e=>{this.penMock(e)})),e.forEach((async e=>{if(e.url){const t=await fetch(e.url,{headers:e.headers,method:e.method,body:"GET"===e.method?void 0:e.body});if(t.ok){const i=await t.text();this.socketCallback(i,{type:"http",url:e.url})}}})),this.render()}),this.store.data.networkInterval||1e3))}closeNetwork(){this.mqttClients&&this.mqttClients.forEach((e=>{e.end()})),this.websockets&&this.websockets.forEach((e=>{e.close()})),this.mqttClients=void 0,this.websockets=void 0,clearInterval(this.updateTimer),this.updateTimer=void 0}socketCallback(e,t){if(this.store.emitter.emit("socket",{message:e,context:t}),this.socketFn&&!this.socketFn(e,{meta2d:this,type:t.type,topic:t.topic,url:t.url}))return;let i;if(e.constructor===Object||e.constructor===Array)i=e;else{if("string"!=typeof e)return;try{i=JSON.parse(e)}catch(e){console.warn("Invalid socket data:",i,e)}}i&&(Array.isArray(i)||(i=[i]),i.length&&(i[0].dataId?this.setDatas(i):i.forEach((e=>{this.setValue(e)}))))}setDatas(e,{render:t=!0,doEvent:i=!0,history:n}={}){const r=new Map;let o,s;e.forEach((t=>{this.store.bindDatas[t.dataId]?.forEach((i=>{const n=this.store.pens[i.id];if(!n)return;let o=r.get(n);if("function"!=typeof n.onBinds)o?o[i.formItem.key]=t.value:(o={id:i.id,[i.formItem.key]:t.value},r.set(n,o));else{if(o)return;r.set(n,n.onBinds(n,e,i.formItem))}})),this.store.bind[t.id]?.forEach((e=>{const i=this.store.pens[e.id];if(!i)return;let n=r.get(i);n?n[e.key]=t.value:(n={id:e.id,[e.key]:t.value},r.set(i,n))}))})),n&&(o=[]),r.forEach(((e,t)=>{this.setValue(e,{render:!1,doEvent:i,history:!1}),n&&(o.push($(t,!0)),s.push(t))})),t&&this.render(),n&&this.pushHistory({type:H.Update,initPens:o,pens:s})}setValue(e,{render:t=!0,doEvent:i=!0,history:n}={}){let r,o=[];if(e.id){if(e.id===this.store.data.id)return this.setDatabyOptions(e),e.bkImage&&this.setBackgroundImage(e.bkImage),e.background&&this.setBackgroundColor(e.background),void this.render();const r=this.store.pens[e.id];if(r)o=[r];else{let r=this.store.bind[e.id];if(r&&r.length)return o=[],void this.setDatas([e],{render:t,doEvent:i,history:n})}}else{if(e.dataId)return o=[],void this.setDatas([e],{render:t,doEvent:i,history:n});if(!e.tag)return;o=this.find(e.tag)}(n=n&&!this.store.data.locked)&&(r=$(o)),o.forEach((t=>{const i=t.onBeforeValue?t.onBeforeValue(t,e):e;e.frames&&(this.stopAnimate([t]),e.showDuration||(e.showDuration=e.frames.reduce(((e,t)=>e+t.duration),0))),ft(t,i),this.canvas.updateValue(t,i),t.onValue?.(t)})),this.store.data.locked||!this.store.active.length||this.canvas.movingPens||this.canvas.calcActiveRect(),n&&this.pushHistory({type:H.Update,initPens:r,pens:o}),i&&o.forEach((e=>{this.store.emitter.emit("valueUpdate",e)})),t&&this.render()}_setValue(e,t=!1){this.setValue(e,{history:t,render:!1,doEvent:!1})}pushHistory(e){this.canvas.pushHistory(e)}showInput(e,t){this.canvas.showInput(e,t)}hideInput(){this.canvas.hideInput()}clearDropdownList(){this.canvas.clearDropdownList()}judgeCondition(e,t,i){const{type:n,target:r,fnJs:o,fn:s,operator:a,valueType:c}=i;let l=!1;if("fn"===n){if(s)l=s(e,{meta2d:this});else if(o){try{i.fn=new Function("pen","context",o)}catch(e){console.error("Error: make function:",e)}i.fn&&(l=i.fn(e,{meta2d:this}))}}else{let n=i.value;"prop"===c&&(n=this.store.pens[r][i.value]);let o=xn(e,t);switch(a){case">":l=o>+n;break;case">=":l=o>=+n;break;case"<":l=o<+n;break;case"<=":l=o<=+n;break;case"=":case"==":l=o==n;break;case"!=":l=o!=n;break;case"[)":l=te(+o,n);break;case"![)":l=!te(+o,n);break;case"[]":l=ie(+o,n);break;case"![]":l=!ie(+o,n)}}return l}pushChildren(e,t){const i=[$(e,!0)],n=[];e.children||(e.children=[]);const r=[];t.forEach((t=>{let s=$(t,!0);if(t.id&&this.store.pens[t.id]||(this.canvas.makePen(t),s=null),t.parentId){const e=this.store.pens[t.parentId],n=e.children.findIndex((e=>e===t.id));i.push($(e,!0)),e.children.splice(n,1),r.push($(e,!0))}e.children.push(t.id),t.parentId=e.id;const a=Dt(t.calculative.worldRect,e.calculative.worldRect);Object.assign(t,a),t.locked=t.lockedOnCombine??o.DisableMove,s?(i.push(s),r.push($(t,!0))):n.push($(t,!0))})),r.push($(e,!0));let s=1;n.length&&(s=2,this.pushHistory({type:H.Add,pens:n,step:s})),this.pushHistory({type:H.Update,initPens:i,pens:r,step:s})}toPng(e,t,i=!1){return this.canvas.toPng(e,t,i)}downloadPng(e,t){for(const e of this.store.data.pens)e.calculative.img&&e.onRenderPenRaw?.(e);setTimeout((()=>{const i=document.createElement("a");i.setAttribute("download",(e||this.store.data.name||"le5le.meta2d")+".png"),i.setAttribute("href",this.toPng(t,void 0,!0));const n=document.createEvent("MouseEvents");n.initEvent("click",!0,!0),i.dispatchEvent(n)}))}getRect(e=this.store.data.pens){return St(e)}fitView(e=!0,t=10){if(!this.hasView())return;const{canvas:i}=this.canvas,{offsetWidth:n,offsetHeight:r}=i;this.resize(n,r);const o=re(t),s=this.getRect(),a=(n-o[1]-o[3])/s.width,c=(r-o[0]-o[2])/s.height;let l=a;l=e?a>c?c:a:a>c?a:c,this.scale(l*this.store.data.scale),this.centerView()}fitSizeView(e=!0,t=10){const{canvas:i}=this.canvas,{offsetWidth:n,offsetHeight:r}=i;this.resize(n,r);const o=re(t),s=(this.store.data.width||this.store.options.width)*this.store.data.scale,a=(this.store.data.height||this.store.options.height)*this.store.data.scale,c=(n-o[1]-o[3])/s,l=(r-o[0]-o[2])/a;let h=c;h=e?c>l?l:c:c>l?c:l,this.scale(h*this.store.data.scale),this.centerSizeView()}centerSizeView(){const e=this.getViewCenter(),t={x:0,y:0,width:this.store.data.width||this.store.options.width,height:this.store.data.height||this.store.options.height};Tt(t);const{center:i}=t,{scale:n,origin:r,x:o,y:s}=this.store.data;this.translate((e.x-r.x)/n-i.x-o/n,(e.y-r.y)/n-i.y-s/n);const{canvas:a}=this.canvas,c=(a.scrollWidth-a.offsetWidth)/2,l=(a.scrollHeight-a.offsetHeight)/2;a.scrollTo(c,l)}scrollView(e=10,t=!1){if(!this.hasView())return;if(!this.canvas.scroll)return;const{canvas:i}=this.canvas,{offsetWidth:n,offsetHeight:r}=i;this.resize(n,r);const o=re(e),s=this.getRect(),a=(n-o[1]-o[3])/s.width;this.scale(a*this.store.data.scale),this.topView(o[0]),t&&this.canvas.scroll.changeMode()}screenView(e=10,t=!0){if(!this.hasView())return;const{canvas:i}=this.canvas,{offsetWidth:n,offsetHeight:r}=i;this.resize(n,r);const o=re(e),s=this.getRect();let a=(n-o[1]-o[3])/s.width;t||(a=(r-o[0]-o[2])/s.height),this.scale(a*this.store.data.scale),this.topView(o[0])}topView(e=10){if(!this.hasView())return;const t=this.getRect(),i=this.getViewCenter(),n=this.getPenRect(t);Tt(n);const{center:r}=n,{scale:o,origin:s,x:a,y:c}=this.store.data;this.translate((i.x-s.x)/o-r.x-a/o,(e-s.y)/o-n.y-c/o);const{canvas:l}=this.canvas,h=(l.scrollWidth-l.offsetWidth)/2,u=(l.scrollHeight-l.offsetHeight)/2;l.scrollTo(h,u)}centerView(){if(!this.hasView())return;const e=this.getRect(),t=this.getViewCenter(),i=this.getPenRect(e);Tt(i);const{center:n}=i,{scale:r,origin:o,x:s,y:a}=this.store.data;this.translate((t.x-o.x)/r-n.x-s/r,(t.y-o.y)/r-n.y-a/r);const{canvas:c}=this.canvas,l=(c.scrollWidth-c.offsetWidth)/2,h=(c.scrollHeight-c.offsetHeight)/2;c.scrollTo(l,h)}hasView(){return!!this.store.data.pens.filter((e=>!e.isRuleLine)).length}getViewCenter(){const{width:e,height:t}=this.canvas;return{x:e/2,y:t/2}}beSameByFirst(e=this.store.data.pens,t){const i=$(e),n=e[0],{width:r,height:o}=this.getPenRect(n);for(let i=1;i<e.length;i++){const n=e[i];"width"===t?this.setValue({id:n.id,width:r},{render:!1,doEvent:!1}):"height"===t?this.setValue({id:n.id,height:o},{render:!1,doEvent:!1}):this.setValue({id:n.id,width:r,height:o},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:H.Update,initPens:i,pens:e})}beSameByLast(e=this.store.data.pens,t){const i=$(e),n=e[e.length-1],{width:r,height:o}=this.getPenRect(n);for(let i=0;i<e.length-1;i++){const n=e[i];"width"===t?this.setValue({id:n.id,width:r},{render:!1,doEvent:!1}):"height"===t?this.setValue({id:n.id,height:o},{render:!1,doEvent:!1}):this.setValue({id:n.id,width:r,height:o},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:H.Update,initPens:i,pens:e})}formatPainterByFirst(e=this.store.data.pens){const t=$(e),i=e[0],n={};p.forEach((e=>{n[e]=i[e]}));for(let t=1;t<e.length;t++){const i=e[t];this.setValue({id:i.id,...n},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:H.Update,initPens:t,pens:e})}setFormatPainter(){const e=this.store.active,t={};if(e.length>0){const i=e[0];p.forEach((e=>{t[e]=i[e]||this.store.options.defaultFormat[e]||this.store.options[e]}))}else{const e={};p.forEach((t=>{e[t]=this.store.options.defaultFormat[t]||this.store.options[t]||void 0}))}localStorage.setItem("meta2d-formatPainter",JSON.stringify(t))}formatPainter(){const e=this.store.active,t=$(e),i=JSON.parse(localStorage.getItem("meta2d-formatPainter"));for(let t=0;t<e.length;t++){const n=e[t];this.setValue({id:n.id,...i},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:H.Update,initPens:t,pens:e})}clearFormatPainter(){const e={};p.forEach((t=>{e[t]=this.store.options.defaultFormat[t]||this.store.options[t]||void 0})),localStorage.setItem("meta2d-formatPainter",JSON.stringify(e)),this.formatPainter()}alignNodes(e,t=this.store.data.pens,i){!i&&(i=this.getPenRect(this.getRect(t)));const n=$(t);for(const n of t)this.alignPen(e,n,i);this.render(),this.pushHistory({type:H.Update,initPens:n,pens:t})}alignNodesByFirst(e,t=this.store.data.pens){const i=$(t),n=t[0],r=this.getPenRect(n);for(let i=1;i<t.length;i++){const n=t[i];this.alignPen(e,n,r)}this.render(),this.pushHistory({type:H.Update,initPens:i,pens:t})}alignNodesByLast(e,t=this.store.data.pens){const i=$(t),n=t[t.length-1],r=this.getPenRect(n);for(let i=0;i<t.length-1;i++){const n=t[i];this.alignPen(e,n,r)}this.render(),this.pushHistory({type:H.Update,initPens:i,pens:t})}alignPen(e,t,i){const n=this.getPenRect(t);switch(e){case"left":n.x=i.x;break;case"right":n.x=i.x+i.width-n.width;break;case"top":n.y=i.y;break;case"bottom":n.y=i.y+i.height-n.height;break;case"center":n.x=i.x+i.width/2-n.width/2;break;case"middle":n.y=i.y+i.height/2-n.height/2}this.setValue({id:t.id,...n},{render:!1,doEvent:!1})}spaceBetweenByDirection(e,t=this.store.data.pens,i){if(!i&&(i=this.getPenRect(this.getRect(t))[e]),(t=t.filter((e=>!e.parentId))).length<=2)return;const n=$(t),r=t.reduce(((t,i)=>t+this.getPenRect(i)[e]),0),o=(i-r)/(t.length-1);t=t.sort(((t,i)=>"width"===e?t.x-i.x:t.y-i.y));const s=this.getPenRect(t[0]);let a="width"===e?s.x:s.y;for(const i of t){const t=this.getPenRect(i);"width"===e?t.x=a:t.y=a,a+=t[e]+o,this.setValue({id:i.id,...t},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:H.Update,initPens:n,pens:t})}spaceBetween(e,t){this.spaceBetweenByDirection("width",e,t)}spaceBetweenColumn(e,t){this.spaceBetweenByDirection("height",e,t)}layout(e=this.store.data.pens,t,i=30){const n=this.getPenRect(St(e));!t&&(t=n.width);const r=$(e=e.filter((e=>!e.type&&!e.parentId)));let o=0;e.forEach((e=>{const t=this.getPenRect(e);t.height>o&&(o=t.height)}));let s=n.x,a=n.y;e.forEach(((r,c)=>{const l=this.getPenRect(r);if(l.x=s,l.y=a+o/2-l.height/2,this.setValue({id:r.id,...l},{render:!1,doEvent:!1}),c===e.length-1)return;const h=s+l.width-n.x,u=this.getPenRect(e[c+1]);Math.round(t-h)>=Math.round(u.width+i)?s+=l.width+i:(s=n.x,a+=o+i)})),this.render(),this.pushHistory({type:H.Update,initPens:r,pens:e})}gotoView(e){const t=this.getViewCenter(),i=t.x-e.calculative.worldRect.x-e.calculative.worldRect.width/2,n=t.y-e.calculative.worldRect.y-e.calculative.worldRect.height/2;this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.translate(i-this.store.data.x,n-this.store.data.y),this.store.data.x=i,this.store.data.y=n,this.canvas.canvasImage.init(),this.canvas.canvasImageBottom.init(),this.render()}showMap(){this.map||(this.map=new _n(this.canvas)),this.map.show()}hideMap(){this.map.hide()}onSizeUpdate(){this.mapTimer&&(clearTimeout(this.mapTimer),this.mapTimer=void 0),this.mapTimer=setTimeout((()=>{this.map&&this.map.isShow&&this.map.show(),this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.resize()}),500)}toggleAnchorMode(){this.canvas.toggleAnchorMode()}addAnchorHand(){this.canvas.addAnchorHand()}removeAnchorHand(){this.canvas.removeAnchorHand()}toggleAnchorHand(){this.canvas.toggleAnchorHand()}top(e){e||(e=this.store.active),Array.isArray(e)||(e=[e]);for(const t of e){const e=this.store.data.pens,i=[...ae(t,this.store),t].map((e=>e.id));e.filter((e=>i.includes(e.id))).forEach((t=>{const i=e.findIndex((e=>e.id===t.id));i>-1&&(e.push(e[i]),e.splice(i,1),this.initImageCanvas([t])),this.specificLayerMove(t,"top")}))}}initImageCanvas(e){this.canvas.initImageCanvas(e)}bottom(e){e||(e=this.store.active),Array.isArray(e)||(e=[e]);for(const t of e){const e=this.store.data.pens,i=[...ae(t,this.store),t].map((e=>e.id)),n=e.filter((e=>i.includes(e.id)));for(let t=n.length-1;t>=0;t--){const i=n[t],r=e.findIndex((e=>e.id===i.id));r>-1&&(e.unshift(e[r]),e.splice(r+1,1),this.initImageCanvas([i])),this.specificLayerMove(i,"bottom")}}}upByArea(e){if(-1===this.store.data.pens.findIndex((t=>t.id===e.id)))return void console.warn("upByArea: pen not in canvas");const t=[e,...ae(e,this.store)];let i=t.map((e=>this.store.data.pens.findIndex((t=>t.id===e.id))));i.includes(-1)&&(console.warn("upByArea: pen children not in canvas"),i=i.filter((e=>-1!==e)));const n=Math.min(...i),r=e.calculative.worldRect,o=this.store.data.pens.findIndex(((t,i)=>{if(i<=n)return!1;if(t.id===e.id||function(e,t){if(!e||!t)return!1;let i=se(e);for(;i;){if(i.id===t.id)return!0;i=se(i)}return!1}(t,e))return!1;const o=t.calculative.worldRect;return Et(r,o)}));if(-1!==o){this.store.data.pens.splice(o+1,0,...t);for(const e of t){const t=this.store.data.pens.findIndex((t=>t.id===e.id));t>-1&&this.store.data.pens.splice(t,1)}this.initImageCanvas([e])}else this.up(e)}specificLayerMove(e,t){if(e.image&&"gif"!==e.name){let i=!1;"bottom"!==t&&"down"!==t||(i=!0),this.setValue({id:e.id,isBottom:i},{render:!1,doEvent:!1,history:!1})}if(e.externElement||"gif"===e.name){let i=0;"top"===t?(e.calculative.canvas.maxZindex+=1,i=e.calculative.canvas.maxZindex):"up"===t?i=void 0===e.calculative.zIndex?5:e.calculative.zIndex+1:"down"===t&&(i=void 0===e.calculative.zIndex?3:e.calculative.zIndex-1,i<0&&(i=0)),this.setValue({id:e.id,zIndex:i},{render:!1,doEvent:!1,history:!1})}}up(e){e||(e=this.store.active),Array.isArray(e)||(e=[e]);for(const t of e){const e=this.store.data.pens;if(t.children&&t.children.length){const i=[...ae(t,this.store),t],n=[];for(let t=0;t<e.length;t++){const r=e[t];-1!==i.findIndex((e=>e.id===r.id))&&(r.temIndex=t,n.push(r))}let r=-1,o=0;n.forEach((t=>{t.temIndex-=o,e.splice(t.temIndex,1),o+=1,r=t.temIndex,delete t.temIndex,this.specificLayerMove(t,"up")})),e.splice(r+1,0,...n),this.initImageCanvas(n)}else{const i=e.findIndex((e=>e.id===t.id));i>-1&&i!==e.length-1&&(e.splice(i+2,0,e[i]),e.splice(i,1),this.initImageCanvas([t])),this.specificLayerMove(t,"up")}}}down(e){e||(e=this.store.active),Array.isArray(e)||(e=[e]);for(const t of e){const e=this.store.data.pens;if(t.children&&t.children.length){const i=[...ae(t,this.store),t],n=[];for(let t=0;t<e.length;t++){const r=e[t];-1!==i.findIndex((e=>e.id===r.id))&&(r.temIndex=t,n.push(r))}let r=-1,o=0;n.forEach(((t,i)=>{t.temIndex-=o,e.splice(t.temIndex,1),o+=1,0===i&&(r=t.temIndex),delete t.temIndex,this.specificLayerMove(t,"down")})),e.splice(r-1,0,...n),this.initImageCanvas(n)}else{const i=e.findIndex((e=>e.id===t.id));i>-1&&0!==i&&(e.splice(i-1,0,e[i]),e.splice(i+1,1),this.initImageCanvas([t])),this.specificLayerMove(t,"down")}}}setLayer(e,t,i=this.store.data.pens){const n=i.findIndex((t=>t.id===e.id));n>-1&&(n>t?(i.splice(t,0,i[n]),i.splice(n+1,1)):n<t&&(i.splice(t,0,i[n]),i.splice(n,1)))}changePenId(e,t){this.canvas.changePenId(e,t)}getLines(e,t="all"){if(e.type===r.Line)return[];const i=[];return e.connectedLines?.forEach((({lineId:n})=>{const r=this.store.pens[n];if(r)switch(t){case"all":i.push(r);break;case"in":Xe(r).connectTo===e.id&&i.push(r);break;case"out":$e(r).connectTo===e.id&&i.push(r)}else console.warn(e,"node contain a error connectedLine")})),i}nextNode(e){if(e.type===r.Line){const t=this.store.pens[Xe(e).connectTo];return t?[t]:[]}{const t=this.getLines(e,"out"),i=[];return t.forEach((e=>{const t=this.nextNode(e);for(const e of t)!i.find((t=>t.id===e.id))&&i.push(e)})),i}}previousNode(e){if(e.type===r.Line){const t=this.store.pens[$e(e).connectTo];return t?[t]:[]}{const t=this.getLines(e,"in"),i=[];return t.forEach((e=>{const t=this.previousNode(e);for(const e of t)!i.find((t=>t.id===e.id))&&i.push(e)})),i}}getNext(e){if(e.type===r.Line)return void console.warn("非连线节点");const t=[];return e.connectedLines?.forEach((({lineId:i,anchor:n})=>{const r=e.anchors?.filter((e=>e.id===n))[0],o=this.findOne(i);if(o.anchors[0].connectTo==e.id){const i=o.anchors[o.anchors.length-1].connectTo;if(i){const n=this.findOne(i),s=n.connectedLines?.filter((e=>e.lineId===o.id))[0],a=n.anchors.filter((e=>e.id===s.anchor))[0];t.push({from:e,fromAnchor:r,line:o,to:n,toAnchor:a})}}})),t}addAnchor(e,t,i){if(!e)return;if(e.anchors||(e.anchors=[]),e.calculative.worldAnchors||(e.calculative.worldAnchors=[]),e.type===r.Line&&(i<0&&(i=e.anchors.length+1+i),i>e.anchors.length&&(i=e.anchors.length),i<0&&(i=0),0==i&&e.anchors[0].connectTo||i==e.anchors.length&&e.anchors[i-1].connectTo))return void console.warn("端点存在连接关系");let n=null,o=null;t.x<=1&&t.x>=0&&t.y<=1&&t.y>=0?(o={id:t.id||ne(),penId:e.id,x:e.calculative.worldRect.x+e.calculative.worldRect.width*t.x,y:e.calculative.worldRect.y+e.calculative.worldRect.height*t.y},e.calculative.worldRect&&e.rotate%360&&S(o,e.rotate,e.calculative.worldRect.center),n={id:o.id,penId:e.id,x:t.x,y:t.y}):(o={id:t.id||ne(),penId:e.id,x:t.x,y:t.y},e.calculative.worldRect&&(e.rotate%360&&S(t,-e.rotate,e.calculative.worldRect.center),n={id:o.id,penId:e.id,x:(t.x-e.calculative.worldRect.x)/e.calculative.worldRect.width,y:(t.y-e.calculative.worldRect.y)/e.calculative.worldRect.height})),e.type===r.Line?(e.calculative.worldAnchors.splice(i,0,o),e.anchors.splice(i,0,n),this.canvas.updateLines(e),this.canvas.initLineRect(e),this.render()):(e.calculative.worldAnchors.push(o),e.anchors.push(n))}connectLine(e,t,i,n,r=!0){if(!i){const n=t.calculative.worldRect;i=We(e,{x:n.x+n.width/2,y:n.y+n.height/2})}if(!n){const i=e.calculative.worldRect;n=We(t,{x:i.x+i.width/2,y:i.y+i.height/2})}const o=Math.abs(i.x-n.x),s={height:Math.abs(i.y-n.y),lineName:"line",lineWidth:1,name:"line",type:1,width:o,x:Math.min(i.x,n.x),y:Math.min(i.y,n.y),anchors:[{x:i.x>n.x?1:0,y:i.y>n.y?1:0,id:ne()},{x:i.x>n.x?0:1,y:i.x>n.x?0:1,id:ne()}]};return this.addPens([s]),qe(e,i,s,s.calculative.worldAnchors[0]),qe(t,n,s,s.calculative.worldAnchors[1]),s.calculative.active=!1,this.canvas.updateLines(s),this.canvas.updateLines(e),this.canvas.updateLines(t),this.canvas.initLineRect(s),r&&this.render(),s}toComponent(e=this.store.data.pens,t,i){if(1===e.length){const t=$(e[0]);return t.type=r.Node,t.id=void 0,[t]}const n=$(e,!0),s=St(n);let a={id:ne(),name:"combine",...s,children:[],showChild:t};i&&(a.anchors=[{id:"0",penId:a.id,x:.5,y:0},{id:"1",penId:a.id,x:1,y:.5},{id:"2",penId:a.id,x:.5,y:1},{id:"3",penId:a.id,x:0,y:.5}]);const c=n.find((e=>e.width===s.width&&e.height===s.height)),l=c&&void 0===t;return l&&(c.children||(c.children=[]),a=c),n.forEach((e=>{if(e===a||e.parentId===a.id)return;if(e.parentId)return;a.children.push(e.id),e.parentId=a.id;const t=Dt(e.calculative.worldRect,s);Object.assign(e,t),e.locked=e.lockedOnCombine??o.DisableMove})),$(l?n:[a,...n])}setVisible(e,t,i=!0){if(this.onSizeUpdate(),this.setValue({id:e.id,visible:t},{render:!1,doEvent:!1}),e.children)for(const i of e.children){const e=this.store.pens[i];e&&this.setVisible(e,t,!1)}i&&this.render()}clearHover(){this.canvas.clearHover()}closeSocket(){this.closeWebsocket(),this.closeMqtt(),this.closeHttp()}destroy(e){if(this.clear(!1),this.closeSocket(),this.closeNetwork(),this.store.emitter.all.clear(),this.canvas.destroy(),this.canvas=void 0,N[this.store.id]=void 0,!e){for(const e in N)delete N[e];N.path2dDraws={},N.canvasDraws={},N.anchors={},N.htmlElements={}}}}function Pn(e,t){e.onDestroy||(e.onDestroy=En,e.onAdd=Cn);const i=t||new Path2D,{x:n,y:r,width:o,height:s,ex:a}=e.calculative.worldRect;let c=e.calculative.borderRadius||0,l=c;c<1&&(c*=o,l*=s);let h=c<l?c:l;o<2*h&&(h=o/2),s<2*h&&(h=s/2),i.moveTo(n+h,r),i.arcTo(n+o,r,n+o,r+s,h),i.arcTo(n+o,r+s,n,r+s,h),i.arcTo(n,r+s,n,r,h),i.arcTo(n,r,n+o,r,h);const u=.2*s;i.moveTo(n,r+u),i.lineTo(a,r+u);const d=r+u+(s-u)/2;if(i.moveTo(n,d),i.lineTo(a,d),i.closePath(),i instanceof Path2D)return i}function Cn(e){const{x:t,y:i,width:n,height:r}=e.calculative.worldRect,o=e.list,s={name:"text",x:t,y:i+.2*r,width:n,height:.4*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10},a={name:"text",x:t,y:i+.6*r,width:n,height:.4*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10};Object.assign(s,o[0]),Object.assign(a,o[1]),e.calculative.canvas.makePen(s),e.calculative.canvas.makePen(a),e.calculative.canvas.parent.pushChildren(e,[s]),e.calculative.canvas.parent.pushChildren(e,[a])}function En(e){const t=e.calculative.canvas.store;e.children.forEach((e=>{const i=t.data.pens.findIndex((t=>t.id===e));i>-1&&(t.data.pens.splice(i,1),t.pens[e]=void 0)})),e.children=void 0}function Rn(e,t){e.onDestroy||(e.onDestroy=Ln,e.onAdd=In);const i=t||new Path2D,{x:n,y:r,width:o,height:s,ex:a}=e.calculative.worldRect;let c=e.calculative.borderRadius||0,l=c;c<1&&(c*=o,l*=s);let h=c<l?c:l;o<2*h&&(h=o/2),s<2*h&&(h=s/2),i.moveTo(n+h,r),i.arcTo(n+o,r,n+o,r+s,h),i.lineTo(n+o,r+s-h),i.arcTo(n+o,r+s,n,r+s,h),i.arcTo(n,r+s,n,r,h),i.arcTo(n,r,n+o,r,h);const u=.2*s;if(i.moveTo(n,r+u),i.lineTo(a,r+u),i.closePath(),i instanceof Path2D)return i}function In(e){const{x:t,y:i,width:n,height:r}=e.calculative.worldRect,o=e.list;let s={name:"text",x:t,y:i+.2*r,width:n,height:.8*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10};Object.assign(s,o[0]),e.calculative.canvas.makePen(s),e.calculative.canvas.parent.pushChildren(e,[s])}function Ln(e){const t=e.calculative.canvas.store;e.children.forEach((e=>{const i=t.data.pens.findIndex((t=>t.id===e));i>-1&&(t.data.pens.splice(i,1),t.pens[e]=void 0)})),e.children=[]}function Mn(){return{interfaceClass:Pn,simpleClass:Rn}}function Dn(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;if(i.rect(n,r,o,s),i.closePath(),i instanceof Path2D)return i}function Nn(e,t){const i=t.headHeight??50,{x:n,y:r,width:o,height:s,ey:a}=t.calculative.worldRect;let c=t.calculative.borderRadius||0,l=c;t.calculative.borderRadius<1&&(c*=o,l*=s);let h=c<l?c:l;o<2*h&&(h=o/2),i<2*h&&(h=i/2),e.beginPath(),e.moveTo(n+h,r),e.arcTo(n+o,r,n+o,r+i,h),e.arcTo(n+o,r+i,n,r+i,h),e.arcTo(n,r+i,n,r,h),e.arcTo(n,r,n+o,r,h),e.closePath(),e.stroke(),e.save(),e.beginPath(),e.lineWidth=1,e.setLineDash([7,7]);const u=n+o/2;e.moveTo(u,r+i+1),e.lineTo(u,a),e.stroke(),e.restore()}function On(){return{sequenceFocus:Dn}}function Bn(){return{lifeline:Nn}}function Fn(e,t){const{x:i,y:n,width:r,height:o}=t.calculative.worldRect;e.beginPath(),e.ellipse(i+r/2,n+o/2,r/2,o/2,0,0,2*Math.PI),e.stroke(),e.beginPath(),e.fillStyle=e.strokeStyle,e.ellipse(i+r/2,n+o/2,r/4,o/4,0,0,2*Math.PI),e.fill()}function zn(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s,ey:a}=e.calculative.worldRect,c=e.calculative.lineLeft||.08;let l=e.calculative.borderRadius||0,h=l;l<1&&(l*=o,h=s*l);let u=l<h?l:h;if(o<2*u&&(u=o/2),s<2*u&&(u=s/2),i.moveTo(n+u,r),i.arcTo(n+o,r,n+o,r+s,u),i.arcTo(n+o,r+s,n,r+s,u),i.arcTo(n,r+s,n,r,u),i.arcTo(n,r,n+o,r,u),i.closePath(),i.moveTo(n+c*o,r),i.lineTo(n+c*o,a),i instanceof Path2D)return i}function jn(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s,ex:a}=e.calculative.worldRect,c=e.calculative.lineTop||.08;let l=e.calculative.borderRadius||0,h=l;l<1&&(l*=o,h*=s);let u=l<h?l:h;if(o<2*u&&(u=o/2),s<2*u&&(u=s/2),i.moveTo(n+u,r),i.arcTo(n+o,r,n+o,r+s,u),i.arcTo(n+o,r+s,n,r+s,u),i.arcTo(n,r+s,n,r,u),i.arcTo(n,r,n+o,r,u),i.closePath(),i.moveTo(n,r+c*s),i.lineTo(a,r+c*s),i instanceof Path2D)return i}function Hn(){return{forkV:e,forkH:e,swimlaneH:zn,swimlaneV:jn}}function Un(){return{activityFinal:Fn}}function Wn(e,t){const i=t||new Path2D,{x:n,y:r,width:o,ey:s}=e.calculative.worldRect,a=o/4;if(i.moveTo(n+a,r),i.lineTo(n,r),i.lineTo(n,s),i.lineTo(n+a,s),i instanceof Path2D)return i}function Vn(e){e.anchors=[{x:.25,y:0},{x:.25,y:1},{x:0,y:.5}].map((({x:t,y:i},n)=>({id:n+"",x:t,y:i,penId:e.id})))}function qn(e,t){const i=t||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=e.calculative.worldRect,c=e.offsetX;let l=o/7;if(c>1?l=c:c>0&&(l=o*c),i.moveTo(n+l,r),i.lineTo(s,r),i.lineTo(n+o-l,a),i.lineTo(n,a),i.closePath(),i instanceof Path2D)return i}function Kn(e,t){const i=t||new Path2D,{x:n,y:r,height:o,ex:s,ey:a}=e.calculative.worldRect,c=o/7;if(i.moveTo(n,r+c),i.bezierCurveTo(n,r-c/2|0,s,r-c/2|0,s,r+c),i.lineTo(s,a-c),i.bezierCurveTo(s,a+c/2|0,n,a+c/2|0,n,a-c),i.closePath(),i.moveTo(n,a-c),i.bezierCurveTo(n,a-2*c|0,s,a-2*c|0,s,a-c),i instanceof Path2D)return i}function Yn(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s,ex:a,ey:c}=e.calculative.worldRect,l=o/8;if(i.moveTo(n+l,r),i.lineTo(a-l,r),i.bezierCurveTo(a+l/3,r,a+l/3,c,a-l,c),i.lineTo(n+l,c),i.lineTo(n,r+s/2),i.closePath(),i instanceof Path2D)return i}function $n(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s,ex:a,center:c}=e.calculative.worldRect,l=c.x,h=r+6*s/7,u=s/6;if(i.moveTo(n,r),i.lineTo(a,r),i.lineTo(a,h),i.bezierCurveTo(a-20,h-u,l+o/5,h-u,l,h),i.bezierCurveTo(l-o/5,h+u,n,h+u,n,h),i.closePath(),i instanceof Path2D)return i}function Xn(e){e.anchors=[{x:.5,y:0},{x:1,y:.5},{x:.5,y:6/7},{x:0,y:.5}].map((({x:t,y:i},n)=>({id:`${n}`,penId:e.id,x:t,y:i})))}function Gn(e,t){const i=t||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=e.calculative.worldRect,c=o/10;if(i.moveTo(n+2*c,r),i.bezierCurveTo(n-2*c/3,r,n-2*c/3,a,n+2*c,a),i.lineTo(s,a),i.bezierCurveTo(s-c,a,s-c,r,s,r),i.closePath(),i instanceof Path2D)return i}function Qn(e,t){const i=t||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=e.calculative.worldRect;i.moveTo(n,r),i.lineTo(s,r),i.lineTo(s,a),i.lineTo(n,a),i.closePath();const c=o/7;if(i.moveTo(n,r+c),i.lineTo(s,r+c),i.moveTo(n+c,r),i.lineTo(n+c,a),i instanceof Path2D)return i}function Jn(e,t){const i=t||new Path2D,{x:n,y:r,height:o,ex:s,ey:a}=e.calculative.worldRect,c=o/4;if(i.moveTo(n,r+c),i.lineTo(s,r),i.lineTo(s,a),i.lineTo(n,a),i.closePath(),i instanceof Path2D)return i}function Zn(e){e.anchors=[{x:.5,y:.125},{x:1,y:.5},{x:.5,y:1},{x:0,y:.5}].map((({x:t,y:i},n)=>({id:`${n}`,penId:e.id,x:t,y:i})))}function er(e,t){const i=t||new Path2D,{x:n,y:r,ex:o,ey:s}=e.calculative.worldRect;if(i.moveTo(n,r),i.lineTo(o,r),i.moveTo(n,s),i.lineTo(o,s),i instanceof Path2D)return i}function tr(e){e.anchors=[{x:.5,y:0},{x:.5,y:1}].map((({x:t,y:i},n)=>({id:n+"",x:t,y:i,penId:e.id})))}function ir(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s,ex:a,ey:c}=e.calculative.worldRect;if(i.ellipse(n+o/2,r+s/2,o/2,s/2,0,0,2*Math.PI),i.moveTo(n+o/2,c),i.lineTo(a,c),i.closePath(),i instanceof Path2D)return i}function nr(e,t){const i=t||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=e.calculative.worldRect,c=o/7;if(i.moveTo(n,r),i.lineTo(s,r),i.lineTo(s,a),i.lineTo(n,a),i.closePath(),i.moveTo(n+c,r),i.lineTo(n+c,a),i.moveTo(s-c,r),i.lineTo(s-c,a),i instanceof Path2D)return i}function rr(){return{flowComment:Wn,flowData:qn,flowDb:Kn,flowDisplay:Yn,flowDocument:$n,flowExternStorage:Gn,flowInternalStorage:Qn,flowManually:Jn,flowParallel:er,flowQueue:ir,flowSubprocess:nr}}function or(){return{flowDocument:Xn,flowManually:Zn,flowParallel:tr,flowComment:Vn}}function sr(e){const t=new Date,i=t.getFullYear(),n=t.getMonth()+1,r=t.getDate(),o=t.getDay(),s=t.getHours(),a=t.getMinutes(),c=t.getSeconds();return new Function("year","month","day","week","hours","minutes","seconds",e?`return ${e}`:"return `${year}:${month}:${day} ${hours}:${minutes}:${seconds} 星期${week}`")(i,n,r,["天","一","二","三","四","五","六"][o],s,a,c)}function ar(e){let t=globalThis.echarts;if(!e.echarts||!t)return;if("string"==typeof e.echarts)try{e.echarts=JSON.parse(e.echarts)}catch(e){}if(!e.echarts)return;e.onDestroy||(e.onDestroy=lr,e.onMove=hr,e.onResize=ur,e.onRotate=hr,e.onValue=dr,e.onBeforeValue=fr,e.onBinds=pr,e.onMouseEnter=hr,e.onAdd=cr,e.onRenderPenRaw=vr),e.calculative.singleton||(e.calculative.singleton={});const i=new Path2D,n=e.calculative.worldRect;if(!e.calculative.singleton.div){const i=document.createElement("div");i.style.position="absolute",i.style.outline="none",i.style.left="-9999px",i.style.top="-9999px",i.style.width=n.width+"px",i.style.height=n.height+"px",document.body.appendChild(i),e.calculative.canvas.externalElements?.parentElement.appendChild(i),nt(e,i),e.calculative.singleton.div=i,e.calculative.singleton.echart=t.init(i,e.echarts.theme),e.calculative.singleton.echartsReady=!0,e.echarts.geoName&&!t.getMap(e.echarts.geoName)&&(e.echarts.geoJson?t.registerMap(e.echarts.geoName,e.echarts.geoJson):e.echarts.geoUrl&&(e.calculative.singleton.echartsReady=!1,fetch(e.echarts.geoUrl).then((i=>{i.text().then((i=>{if("string"==typeof i)try{i=JSON.parse(i)}catch{}i.constructor===Object||i.constructor===Array?(t.registerMap(e.echarts.geoName,i),e.calculative.singleton.echartsReady=!0,e.calculative.singleton.echart.setOption(e.echarts.option,!0),setTimeout((()=>{vr(e)}),300)):console.warn("Invalid data:",i)}))})))),e.calculative.singleton.echartsReady&&setTimeout((()=>{e.calculative.singleton.echart.setOption(e.echarts.option,!0),setTimeout((()=>vr(e)),300)}))}return i}function cr(e){e.beforeScale=e.calculative.canvas.store.data.scale}function lr(e){if(e.calculative.singleton&&e.calculative.singleton.div){e.calculative.singleton.div.remove();let t=globalThis.echarts;t&&t.dispose(e.calculative.singleton.echart),delete e.calculative.singleton.div,delete e.calculative.singleton.echart}}function hr(e){e.calculative.singleton.div&&nt(e,e.calculative.singleton.div)}function ur(e){if(!e.calculative.singleton.echart)return;nt(e,e.calculative.singleton.div);let t=e.echarts.option;e.beforeScale||(e.beforeScale=e.calculative.canvas.store.data.scale);let i=e.calculative.canvas.store.data.scale/e.beforeScale;if(t.grid){let e=["top","bottom","left","right"];for(let n=0;n<e.length;n++)Array.isArray(t.grid)?t.grid.forEach((t=>{isNaN(t[e[n]])||(t[e[n]]*=i)})):isNaN(t.grid[e[n]])||(t.grid[e[n]]*=i)}if(t.dataZoom){let e=["right","top","width","height","left","bottom"];for(let n=0;n<e.length;n++)t.dataZoom.forEach((t=>{isNaN(t[e[n]])||(t[e[n]]*=i)}))}X(t,"fontSize",i),e.calculative.singleton.echart.setOption(t,!0),e.beforeScale=e.calculative.canvas.store.data.scale,e.calculative.singleton.echart.resize()}function dr(e){e.calculative.singleton.echart&&(nt(e,e.calculative.singleton.div),e.calculative.singleton.echartsReady&&e.calculative.singleton.echart.setOption(e.echarts.option,!0))}function fr(e,t){if(t.echarts)return t;if(e.realTimes&&e.realTimes.length){const{xAxis:i,yAxis:n}=e.echarts.option,{max:r,replaceMode:o,timeFormat:s}=e.echarts;for(let n in t)if(n.includes("echarts.option")){let a=xn(e,n);if(Array.isArray(a)&&o===kn.Add){a.push(t[n]),r&&a.splice(0,a.length-r),t[n]=a;let o="echarts.option.xAxis.data";Array.isArray(i)&&i.length&&(o="echarts.option.xAxis.0.data");let c=xn(e,o),l=sr(s||"`${hours}:${minutes}:${seconds}`");c.push(l),r&&c.splice(0,c.length-r),t[o]=c}}return t}if(!t.dataX&&!t.dataY)return t;const i=e.echarts,{max:n,replaceMode:r}=i;let o=t.dataX,s=t.dataY;const a=i.option.series,c=a.length,{xAxis:l,yAxis:h}=i.option;Array.isArray(l)&&l.length>1&&console.warn("echarts 只支持单 x 轴,多 x 轴将被忽略");const u=Array.isArray(l)?l[0]:l,d=Array.isArray(h)?h[0]:h;if(r)if(r===kn.Replace)if(u||d){if(("category"===u.type||"category"===d.type)&&o&&s){const e="category"===u.type?u.data:d.data;!Array.isArray(o)&&(o=[o]),!Array.isArray(s)&&(s=[s]),1===c?s.forEach(((t,i)=>{const n=e.indexOf(o[i]);a[0].data[n]=t})):a.forEach(((t,i)=>{s[i].forEach(((i,n)=>{const r=e.indexOf(o[n]);t.data[r]=i}))}))}}else s&&(1===c?(!Array.isArray(s)&&(s=[s]),s.forEach(((e,t)=>{const i=a[0].data.find((t=>t.name===e.name));i&&(i.value=e.value)}))):a.forEach(((e,t)=>{Array.isArray(s[t])||(s[t]=[s[t]]),s[t].forEach(((t,i)=>{const n=e.data.find((e=>e.name===t.name));n&&(n.value=t.value)}))})));else r===kn.ReplaceAll&&(o&&(u.data=o,u.data.splice(0,u.data.length-n)),s&&(1===c?(a[0].data=s,a[0].data.splice(0,a[0].data.length-n)):a.forEach(((e,t)=>{e.data=s[t],e.data.splice(0,e.data.length-n)}))));else{if(o){!Array.isArray(o)&&(o=[o]);const e=u.data;e.push(...o),e.splice(0,e.length-n)}if(s)if(1===c){!Array.isArray(s)&&(s=[s]);const e=a[0].data;e.push(...s),e.splice(0,e.length-n)}else a.forEach(((e,t)=>{Array.isArray(s[t])||(s[t]=[s[t]]);const i=e.data;i.push(...s[t]),i.splice(0,i.length-n)}))}return delete t.dataX,delete t.dataY,Object.assign(t,{echarts:i})}function pr(e,t,i){if("dataY"!==i.key)return;const n=e.echarts,{xAxis:r,yAxis:o}=n.option;Array.isArray(r)&&r.length>1&&console.warn("echarts 只支持单 x 轴,多 x 轴将被忽略");const s=Array.isArray(r)?r[0]:r,a=Array.isArray(o)?o[0]:o,c=n.option.series;if(s||a){if("category"===s.type||"category"===a.type){const n=[],r=[],o="category"===s.type?s.data:a.data;return o?.forEach((e=>{const{dataId:o}=i.dataIds.find((t=>t.name===e));if(o){const i=t.find((e=>e.dataId===o));i&&(r.push(e),n.push(i.value))}})),{id:e.id,dataY:n,dataX:r}}if("time"===s.type){const n=[],r=+new Date;let o=!1;if(c.forEach(((e,s)=>{const a=[],{dataId:c}=i.dataIds.find((t=>t.name===e.name));if(c){const e=t.find((e=>e.dataId===c));e&&(a.push([r,e.value]),o=!0)}n[s]=a})),!o)return;return n.forEach(((e,t)=>{if(!e||0===e.length){const e=c[t].data[c[t].data.length-1];n[t]=[[r,e[1]]]}})),{id:e.id,dataY:1===n.length?n[0]:n}}}else{const n=[];if(Array.isArray(c)&&1===c.length)return c[0].data.forEach((e=>{const{dataId:r}=i.dataIds.find((t=>t.name===e.name));if(r){const i=t.find((e=>e.dataId===r));i&&n.push({name:e.name,value:i.value})}})),{id:e.id,dataY:n}}}function vr(e){const t=new Image;t.src=e.calculative.singleton?.echart?.getDataURL({pixelRatio:2}),e.calculative.img=t}function xr(e){const t=globalThis.Highcharts;if(!t)return;if("string"==typeof e.highcharts)try{e.highcharts=JSON.parse(e.highcharts.option)}catch(e){}if(!e.highcharts)return;e.onDestroy||(e.onDestroy=gr,e.onMove=yr,e.onResize=mr,e.onRotate=yr,e.onValue=br,e.onBeforeValue=wr,e.onRenderPenRaw=_r),e.calculative.singleton||(e.calculative.singleton={});const i=new Path2D,n=e.calculative.worldRect;if(!e.calculative.singleton.div){const i=document.createElement("div");i.style.position="absolute",i.style.outline="none",i.style.left="-9999px",i.style.top="-9999px",i.style.width=n.width+"px",i.style.height=n.height+"px",i.style.minWidth="100px",i.style.minHeight="100px",i.id=e.id,document.body.appendChild(i),e.calculative.singleton.div=i,setTimeout((()=>{e.calculative.singleton.highchart=t.chart(e.id,e.highcharts.option);const i=e.calculative.singleton.highchart.getSVG(),n=new Image;n.src="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(i))),e.calculative.img=n})),e.calculative.canvas.externalElements?.parentElement.appendChild(i),nt(e,i)}return e.calculative.patchFlags&&e.calculative.singleton.div&&nt(e,e.calculative.singleton.div),i}function gr(e){e.calculative.singleton&&e.calculative.singleton.div&&(e.calculative.singleton.div.remove(),e.calculative.singleton.highchart.destroy(),delete e.calculative.singleton.div,delete e.calculative.singleton.highchart)}function yr(e){e.calculative.singleton.div&&nt(e,e.calculative.singleton.div)}function mr(e){e.calculative.singleton.div&&(nt(e,e.calculative.singleton.div),setTimeout((()=>{e.calculative.singleton.highchart.reflow()}),100))}function br(e){e.calculative.singleton.div&&nt(e,e.calculative.singleton.div)}function wr(e,t){if(t.highcharts)return e.calculative.singleton.highchart.update(t.highcharts.option),t;if(!t.dataX&&!t.dataY)return t;const i=e.highcharts,n=i.max;let r=t.dataX,o=t.dataY;const s=i.option.series.length;if(t.overwrite)r&&(i.option.xAxis.categories=r,i.option.xAxis.categories.splice(0,i.option.xAxis.categories.length-n)),o&&(1===s?(i.option.series[0].data=o,i.option.series[0].data.splice(0,i.option.series[0].data.length-n)):i.option.series.forEach(((e,t)=>{e.data=o[t],e.data.splice(0,e.data.length-n)}))),e.calculative.singleton.highchart.update(i.option);else{let t=[],a=null,c=!1;if(r){Array.isArray(r)||(r=[r]);const e=i.option.xAxis,o=Array.isArray(e)?e[0].categories:e.categories;o&&(o.push(...r),o.splice(0,o.length-n),c=!0),t=[...r]}o&&(1===s?(Array.isArray(o)||(o=[o]),a=[o]):(a=[],i.option.series.forEach(((e,t)=>{Array.isArray(o[t])||(o[t]=[o[t]]),a.push(o[t])})))),a&&e.calculative.singleton.highchart.series.forEach(((e,i)=>{a[i].forEach(((i,r)=>{let o=!1;n&&e.data.length>=n&&(o=!0);const s=c||null==t[r]?i:[t[r],i];e.addPoint(s,!0,o)}))}))}return delete t.dataX,delete t.dataY,delete t.overwrite,Object.assign(t,{highcharts:i})}function _r(e){if(!e.calculative?.singleton)return;const t=e.calculative.singleton.highchart.getSVG(),i=new Image;i.src="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(t))),e.calculative.img=i}function kr(e){let t=globalThis.lcjs;if(!e.lightningCharts||!t)return;if("string"==typeof e.lightningCharts)try{e.lightningCharts=JSON.parse(e.lightningCharts)}catch(e){}if(!e.lightningCharts)return;e.onDestroy||(e.onDestroy=Ar,e.onMove=Sr,e.onResize=Pr,e.onRotate=Sr,e.onValue=Cr,e.onRenderPenRaw=Er);const i=new Path2D,n=e.calculative.worldRect;if(e.calculative.singleton||(e.calculative.singleton={}),!e.calculative.singleton.div){const t=document.createElement("div");t.style.position="absolute",t.style.outline="none",t.style.left="-9999px",t.style.top="-9999px",t.style.width=n.width+"px",t.style.height=n.height+"px",t.id=e.id,document.body.appendChild(t),e.calculative.singleton.div=t,setTimeout((()=>{Tr(e)}),100),setTimeout((()=>{e.calculative.canvas.externalElements&&e.calculative.canvas.externalElements.parentElement.appendChild(t),nt(e,t);const i=new Image;i.src=e.calculative.singleton.div.children[0].toDataURL(),e.calculative.img=i}),400)}return e.calculative.patchFlags&&e.calculative.singleton.div&&nt(e,e.calculative.singleton.div),i}function Tr(e){const{lightningChart:t,PieChartTypes:i,LegendBoxBuilders:n,SliceLabelFormatters:r,Themes:o,GaugeChartTypes:s,SolidLine:a,SolidFill:c,ColorRGBA:l,UIOrigins:h,emptyLine:u,AutoCursorModes:d,AxisScrollStrategies:f,AxisTickStrategies:p,UIElementBuilders:v}=lcjs,x=e.lightningCharts.option.data,g=e.lightningCharts.option.title||"Title",y=o[e.lightningCharts.option.theme||"lightNew"];switch(e.calculative.singleton.lightningChart=t(),e.lightningCharts.option.type){case"line":const t=e.calculative.singleton.lightningChart.ChartXY({container:e.id}).setTitle(g);x.forEach((e=>{t.addLineSeries().setName(e.name).add(e.data)}));break;case"bar":const i=e.calculative.singleton.lightningChart;let o;o=t=>{const r=[],o=[],s=i.ChartXY(t).setTitle(g).setAutoCursorMode(d.onHover).setMouseInteractions(!1).setPadding({bottom:30}),a=s.getDefaultAxisX().setMouseInteractions(!1).setScrollStrategy(void 0).setTickStrategy(p.Empty);s.getDefaultAxisY().setMouseInteractions(!1).setTitle(e.lightningCharts.option.yTitle).setInterval(0,70).setScrollStrategy(f.fitting),s.setAutoCursor((e=>e.disposePointMarker().disposeTickMarkerX().disposeTickMarkerY().setGridStrokeXStyle(u).setGridStrokeYStyle(u).setResultTable((e=>{e.setOrigin(h.CenterBottom)}))));const c=s.addLegendBox(n.VerticalLegendBox).setAutoDispose({type:"max-width",maxWidth:.2});return{addCategory:e=>{const t=(e=>{const t=s.addRectangleSeries();return t.setCursorResultTableFormatter(((t,i,n)=>{let r={name:e.name,value:e.data[e.figures.indexOf(n)]};return t.addRow("Department:",r.name).addRow("# of employees:",String(r.value))})),t})(e).setName(e.name);e.figures=e.data.map((e=>t.add({x:0,y:0,width:0,height:0}))),c.add(t),o.push(e),(()=>{let e=0;for(let t=0;t<r.length;t++){const i=r[t],n=e;for(const i of o){const n=i.data[t];void 0!==n&&(i.figures[t].setDimensions({x:e,y:0,width:10,height:n}),e+=12.5)}i.tick.setValue((n+e-2.5)/2),e+=7.5}a.setInterval(-10,e)})()},addGroups:e=>{for(const t of e)r.push({name:t,tick:a.addCustomTick(v.AxisTick).setGridStrokeLength(0).setTextFormatter((e=>t))})}}};const s=o({theme:y,container:e.id});s.addGroups(e.lightningCharts.option.groups);const a=e.lightningCharts.option.categories;x.forEach(((e,t)=>s.addCategory({name:a[t],data:e})));break;case"pie":const m=e.calculative.singleton.lightningChart.Pie({theme:y,container:e.id}).setTitle(g).setAnimationsEnabled(!0).setMultipleSliceExplosion(!0);x.map((e=>m.addSlice(e.name,e.value))),m.setInnerRadius(e.lightningCharts.option.innerRadius||0).setLabelFormatter(r.NamePlusRelativeValue),m.addLegendBox(n.VerticalLegendBox).setAutoDispose({type:"max-width",maxWidth:.3}).add(m);break;case"gauge":const b=e.calculative.singleton.lightningChart.Gauge({theme:y,container:e.id}).setTitle(g).setThickness(20).setAngleInterval(e.lightningCharts.option.startAngle||225,e.lightningCharts.option.endAngle||-45);let w=function(e){let t=e.toLowerCase();if(t&&/^#([0-9|a-f]{3}|[0-9|a-f]{6})$/.test(t)){4==t.length&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]);for(var i=[],n=1;n<7;n+=2)i.push(parseInt("0x"+t.slice(n,n+2)));return i}return t&&/rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/.test(t)?t.match(/\(([^)]*)\)/)[1].split(",").map((e=>parseInt(e))):t}(e.lightningCharts.option.background);b.getDefaultSlice().setInterval(e.lightningCharts.option.min||0,e.lightningCharts.option.max||100).setValue(x).setFillStyle(new c({color:l(w[0],w[1],w[2])}))}}function Ar(e){e.calculative.singleton&&e.calculative.singleton.div&&(e.calculative.singleton.div.remove(),delete e.calculative.singleton.div,delete e.calculative.singleton.lightningChart)}function Sr(e){e.calculative.singleton.div&&nt(e,e.calculative.singleton.div)}function Pr(e){e.calculative.singleton.div&&nt(e,e.calculative.singleton.div)}function Cr(e){e.calculative.singleton.div&&(Tr(e),nt(e,e.calculative.singleton.div))}function Er(e){if(!e.calculative?.singleton)return;const t=new Image;t.src=e.calculative.singleton.div.children[0].toDataURL(),e.calculative.img=t}function Rr(e){e&&(globalThis.echarts=e),O({echarts:ar})}function Ir(e){e&&(globalThis.Highcharts=e),O({highcharts:xr})}function Lr(e){e&&(globalThis.lcjs=e),O({lightningCharts:kr})}function Mr(e,t){t.onAdd||(t.onAdd=Dr,t.onMouseMove=Br,t.onMouseLeave=Fr,t.onMouseDown=zr,t.onShowInput=Nr,t.onInput=Or,t.onValue=qr,t.onBeforeValue=Kr);const i=t.calculative.canvas.store.data,n=t.calculative.canvas.store.options;t.color=t.color||i.color||n.color,t.activeColor=t.activeColor||n.activeColor,t.hoverColor=t.hoverColor||n.hoverColor,t.activeBackground=t.activeBackground||n.activeBackground,t.hoverBackground=t.hoverBackground||n.hoverBackground,function(e,t){if(!t.colPos)return;const i=t.calculative.worldRect;e.save(),e.strokeStyle=t.color,e.beginPath(),e.rect(i.x,i.y,i.width,i.height),t.background&&(e.fillStyle=t.background,e.fill()),e.stroke();let n=t.rowPos[t.rowPos.length-1];for(const i of t.rowPos){if(i===n)continue;const r=i*t.calculative.worldRect.height/t.tableHeight;e.beginPath(),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y+r),e.lineTo(t.calculative.worldRect.ex,t.calculative.worldRect.y+r),e.stroke()}n=t.colPos[t.colPos.length-1],t.colPos.forEach(((i,r)=>{if(i===n)return;const o=i*t.calculative.worldRect.width/t.tableWidth;e.beginPath(),e.moveTo(t.calculative.worldRect.x+o,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+o,t.calculative.worldRect.ey),e.stroke()})),e.restore()}(e,t),function(e,t){if(!t.colPos)return;t.calculative.texts||(t.calculative.texts=[]);for(let i=0;i<t.rowPos.length;i++)for(let n=0;n<t.colPos.length;n++){let r,o=Hr(t,i,n),s=o.color||t.color,a=o.background;t.calculative.activeCell?.row===i&&t.calculative.activeCell?.col===n&&(s=t.activeColor,a=t.activeBackground,r=s),t.calculative.hoverCell?.row===i&&t.calculative.hoverCell?.col===n&&(s=t.hoverColor,a=t.hoverBackground,r=s);const c=Wr(t,i,n);a&&(e.save(),e.fillStyle=a,e.fillRect(c.x,c.y,c.width,c.height),e.restore()),r&&(e.save(),e.strokeStyle=r,e.strokeRect(c.x,c.y,c.width,c.height),e.restore()),t.calculative.worldTextRect=c;let l=t.calculative.texts[i];if(t.calculative.texts[i]||(l=[],t.calculative.texts.push(l)),null==l[n]){if(Array.isArray(o)){l[n]="",o[0].id||(Vr(t,c,o),t.calculative.canvas.parent.pushChildren(t,o));continue}if(l[n]=o.text||o+"",!l[n])continue;l[n]=V(t,l[n])}if(l[n]){if(e.save(),e.fillStyle=s,e.textAlign="center",e.textBaseline="middle",e.font=(t.calculative.fontStyle||"")+" normal "+(t.calculative.fontWeight||"")+" "+1*(t.calculative.fontSize||12)+"px "+t.calculative.fontFamily,1===l[n].length)e.fillText(l[n][0],c.x+c.width/2,c.y+c.height/2);else{const i=.55,r=t.calculative.fontSize*t.calculative.lineHeight*1,o=l[n].length*r;let s=(c.height-o)/2;l[n].forEach(((t,n)=>{e.fillText(t,c.x+c.width/2,c.y+s+(n+i)*r)}))}e.restore()}}}(e,t)}function Dr(e){!function(e){const t=[],i=[];e.table.rowHeight||(e.table.rowHeight=40),e.table.colWidth||(e.table.colWidth=150);let n=0;for(const i of e.table.header.data)n+=i.width||e.table.colWidth,t.push(n);let r=0;0!=e.table.header.show&&(r+=e.table.header.height||e.table.rowHeight,i.push(r));for(const t of e.table.data)r+=t.height||e.table.rowHeight,i.push(r);e.colPos=t,e.rowPos=i,e.tableWidth=n,e.tableHeight=r,e.width||(e.width=n,e.height=r,e.calculative.width=n,e.calculative.height=r,e.calculative.worldRect={x:e.x,y:e.y,height:e.height,width:e.width},At(e.calculative.worldRect))}(e)}function Nr(e,t){if(!e.calculative.hoverCell)return;const i=Hr(e,e.calculative.hoverCell.row,e.calculative.hoverCell.col);if(Array.isArray(i))return;e.calculative.inputCell=e.calculative.hoverCell;const n=Wr(e,e.calculative.hoverCell.row,e.calculative.hoverCell.col);e.calculative.tempText=i.text||i+"",e.calculative.canvas.showInput(e,n,"#ffffff")}function Or(e,t){e.calculative.inputCell&&(Ur(e,e.calculative.inputCell.row,e.calculative.inputCell.col,t),e.calculative.canvas.render())}function Br(e,t){e.calculative.hoverCell=jr(e,t),e.calculative.canvas.render()}function Fr(e,t){e.calculative.hoverCell=void 0,e.calculative.canvas.render()}function zr(e,t){e.calculative.activeCell=jr(e,t),e.calculative.canvas.render()}function jr(e,t){const i=e.calculative.worldRect.width/e.tableWidth,n=e.calculative.worldRect.height/e.tableHeight,r={row:0,col:0};for(let n=0;n<e.colPos.length;n++)t.x>e.calculative.worldRect.x+e.colPos[n]*i&&(r.col=n+1);for(let i=0;i<e.rowPos.length;i++)t.y>e.calculative.worldRect.y+e.rowPos[i]*n&&(r.row=i+1);return r}function Hr(e,t,i){if(!e.table.data||!Array.isArray(e.table.data))return;if(0==e.table.header.show){const n=e.table.data[t];if(Array.isArray(n))return n[i];if(!n.data||!Array.isArray(n.data))return;return n.data[i]}if(0===t){const t=e.table.header.data[i];return t.fontWeight=e.table.header.fontWeight,t}const n=e.table.data[t-1];if(n){if(Array.isArray(n))return n[i];if(n.data&&Array.isArray(n.data))return n.data[i]}}function Ur(e,t,i,n){if(!e.table.data||!Array.isArray(e.table.data))return;let r;e.calculative.texts=void 0,0==e.table.header.show?(r=e.table.data[t],Array.isArray(r)||r.data&&Array.isArray(r.data)&&(r=r.data)):0===t?r=e.table.header.data:(r=e.table.data[t-1],Array.isArray(r)||r.data&&Array.isArray(r.data)&&(r=r.data)),r&&(r[i]instanceof Object?r[i].text=n:r[i]=n,e.calculative.canvas.store.emitter.emit("valueUpdate",e))}function Wr(e,t,i){const n=e.calculative.worldRect.width/e.tableWidth,r=e.calculative.worldRect.height/e.tableHeight;let o=0,s=e.colPos[i]*n;i>0&&(o=e.colPos[i-1]*n);let a=0,c=e.rowPos[t]*r;return t>0&&(a=e.rowPos[t-1]*r),{x:e.calculative.worldRect.x+o,y:e.calculative.worldRect.y+a,ex:e.calculative.worldRect.x+s,ey:e.calculative.worldRect.y+c,width:s-o,height:c-a}}function Vr(e,t,i){const n=e.calculative.worldRect.width/e.tableWidth,r=e.calculative.worldRect.height/e.tableHeight;let o=0,s=0,a=0;for(const e of i)s+e.width*n+20*n<t.width?(e.x=t.x+s+10*n,e.y=t.y+a+10*r,s+=(e.width+10)*n,o=Math.max(o,a+(e.height+10)*r)):(s=0,a=o,e.x=t.x+s+10*n,e.y=t.y+a+10*r,o+=(e.height+10)*r);if(o+20*r<t.height){const e=(t.height-o-10*r)/2;for(const t of i)t.y+=e}}function qr(e){e.calculative.texts=void 0}function Kr(e,t){return t.table||null==t.col&&null==t.row||(Ur(e,t.row,t.col,t.value),e.calculative.canvas.render(),delete t.col,delete t.row),t}function Yr(e,t){const i=14*t.calculative.worldRect.height/16,n=(e.match(/[\u4e00-\u9fa5]/g)||"").length;return(e.length-n)*i*.6+n*i}function $r(e){if("horizontal"==e.direction){const t=[];let i=0;const n=e.height;e.checkboxHeight=n,e.options.forEach(((r,o)=>{t.push(o*(40+n)+i),i+=Yr(r.text,e)})),e.optionPos=t;const r=t.length*(40+n)+i;e.checkboxWidth=r,e.width=r,e.calculative.width=r,e.calculative.worldRect={x:e.x,y:e.y,height:e.height,width:e.width,center:{x:e.x+e.width/2,y:e.y+e.height/2}},At(e.calculative.worldRect)}else if("vertical"==e.direction){null==e.optionInterval&&(e.optionInterval=20),e.optionHeight||(e.optionHeight=20);const t=[];e.options.forEach(((i,n)=>{t.push(n*(e.optionInterval+e.optionHeight))})),e.optionPos=t;const i=t[t.length-1]+e.optionHeight;e.checkboxHeight=i,e.width||(e.height=i,e.calculative.height=i,e.calculative.worldRect={x:e.x,y:e.y,height:e.height,width:e.width,center:{x:e.x+e.width/2,y:e.y+e.height/2}},At(e.calculative.worldRect))}}function Xr(e,t){t.onAdd||(t.onAdd=Gr,t.rowPos&&t.colPos||t.onAdd(t),t.onMouseMove=Zr,t.onMouseLeave=eo,t.onMouseDown=to,t.onShowInput=Qr,t.onInput=Jr,t.onValue=co,t.onBeforeValue=lo);const i=t.calculative.canvas.store.data,n=t.calculative.canvas.store.options;t.color=t.color||i.color||n.color,t.textColor=t.textColor||t.color||i.textColor||n.textColor,t.activeColor=t.activeColor||n.activeColor,t.hoverColor=t.hoverColor||n.hoverColor,t.activeBackground=t.activeBackground||n.activeBackground,t.hoverBackground=t.hoverBackground||n.hoverBackground,function(e,t){if(!t.colPos)return;const{x:i,y:n,width:r,height:o,ex:s,ey:a}=t.calculative.worldRect;e.save(),e.strokeStyle=t.color,e.beginPath();let c=t.calculative.borderRadius||0,l=c;c<1&&(c*=r,l*=o);let h=c<l?c:l;if(r<2*h&&(h=r/2),o<2*h&&(h=o/2),e.moveTo(i+h,n),e.arcTo(s,n,s,a,h),e.arcTo(s,a,i,a,h),e.arcTo(i,a,i,n,h),e.arcTo(i,n,s,n,h),t.background&&(e.fillStyle=t.background,e.fill()),!1!==t.bordered&&e.stroke(),!1!==t.hLine){let i=t.rowPos[t.rowPos.length-1];for(const n of t.rowPos){if(n===i)continue;const r=n*t.calculative.worldRect.height/t.tableHeight;e.beginPath(),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y+r),e.lineTo(t.calculative.worldRect.ex,t.calculative.worldRect.y+r),e.stroke()}}if(!1!==t.vLine){let i=t.colPos[t.colPos.length-1];t.colPos.forEach(((n,r)=>{if(n===i)return;const o=n*t.calculative.worldRect.width/t.tableWidth;e.beginPath(),e.moveTo(t.calculative.worldRect.x+o,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+o,t.calculative.worldRect.ey),e.stroke()}))}e.restore()}(e,t),function(e,t){if(!t.colPos)return;t.calculative.texts||(t.calculative.texts=[]);for(let i=0;i<t.rowPos.length;i++){let{style:n}=ro(t,i);for(let r=0;r<t.colPos.length;r++){let{value:o,style:s}=no(t,i,r),a=!0;s.wheres&&Array.isArray(s.wheres)&&(a=!1,a=s.wheres.every((function(e){return new Function("attr",`return attr ${e.comparison} ${e.value}`)(o)})));let c,l=t.color,h=t.textColor||t.color,u=null,d=null,f=null,p=null;a&&(l=s.color||n.color||t.color,h=s.textColor||n.textColor||t.textColor,u=s.background||n.background,d=(s.fontSize||n.fontSize||0)*t.calculative.canvas.store.data.scale,f=s.fontWeight||n.fontWeight,p=s.fontStyle||n.fontStyle),t.stripe&&(!1!==t.hasHeader?i%2==1&&(u=u||t.stripeColor||"#407FFF1F"):i%2==0&&(u=u||t.stripeColor||"#407FFF1F")),t.calculative.active&&t.calculative.activeCell?.row===i&&t.calculative.activeCell?.col===r&&(l=t.activeColor,u=t.activeBackground,c=l,h=t.activeTextColor||t.activeColor),t.calculative.hoverCell?.row===i&&t.calculative.hoverCell?.col===r&&(l=t.hoverColor,u=t.hoverBackground,h=t.hoverTextColor||t.hoverColor,c=l);const v=so(t,i,r);u&&(e.save(),e.fillStyle=u,e.fillRect(v.x,v.y,v.width+.25*t.calculative.canvas.store.data.scale,v.height),e.restore()),c&&(e.save(),e.strokeStyle=c,e.strokeRect(v.x,v.y,v.width,v.height),e.restore()),t.calculative.worldTextRect=v;let x=t.calculative.texts[i];if(t.calculative.texts[i]||(x=[],t.calculative.texts.push(x)),null==x[r]){if("object"==typeof o){const e=t.styles&&t.styles.filter((e=>e.col===r&&void 0===e.row&&e.pens));if(e.length>0){if(x[r]="",t.isFirstTime){let n=JSON.parse(JSON.stringify(e[0].pens));n.forEach((e=>{Object.assign(e,{row:i,col:r},o),e.activeBackground=e.background,e.hoverBackground=e.background,e.activeColor=e.color,e.hoverColor=e.color,e.activeTextColor=e.textColor,e.hoverTextColor=e.textColor,e.height*=t.calculative.canvas.store.data.scale,e.width*=t.calculative.canvas.store.data.scale})),ao(t,v,n),t.calculative.canvas.parent.pushChildren(t,n)}continue}}else x[r]=void 0===o?"":o.text||o+"";if(!x[r])continue;x[r]=V(t,x[r])}if(x[r]){if(e.save(),e.fillStyle=h,e.textAlign="center",e.textBaseline="middle",e.font=(p||t.calculative.fontStyle||"")+" normal "+(f||t.calculative.fontWeight||"")+" "+1*(d||t.calculative.fontSize||12)+"px "+t.calculative.fontFamily,1===x[r].length)e.fillText(x[r][0],v.x+v.width/2,v.y+v.height/2);else{const i=.55,n=(d||t.calculative.fontSize)*t.calculative.lineHeight*1,o=x[r].length*n;let s=(v.height-o)/2;x[r].forEach(((t,r)=>{e.fillText(t,v.x+v.width/2,v.y+s+(r+i)*n)}))}e.restore()}}}}(e,t),function(e,t){if(!t.calculative.hover)return;if(!t.calculative.hoverCell)return;if(t.calculative.isInput)return;if(!t.calculative.isHover)return;let i=t.calculative.worldRect,n=t.calculative.canvas.mousePos;if(!(n.x>i.x&&n.x<i.x+i.width&&n.y>i.y&&n.y<i.y+i.height))return t.calculative.hover=!1,t.calculative.isHover=!1,void(t.calculative.hoverCell=void 0);const{row:r,col:o}=t.calculative.hoverCell,{x:s,y:a}=t.calculative.canvas.mousePos;if(!t.data[r])return;let c=t.data[r][o];if("object"==typeof c||!c)return;e.save(),e.textAlign="start",e.textBaseline="middle",e.font=e.font=(t.calculative.fontStyle||"")+" normal "+(t.calculative.fontWeight||"")+" "+(t.calculative.fontSize||12)+"px "+t.calculative.fontFamily;const l=e.measureText(c).width;e.beginPath(),e.fillStyle="#fff",e.strokeStyle="#000",e.moveTo(s,a),e.rect(s-10,a,l+20,20),e.fill(),e.stroke(),e.beginPath(),e.fillStyle="#000",e.fillText(c,s,a+10),e.restore()}(e,t),t.isFirstTime=!1}function Gr(e){e.isFirstTime=!0,function(e){const t=[],i=[];e.rowHeight||(e.rowHeight=40),e.colWidth||(e.colWidth=150);let n=0;const r=e.styles&&e.styles.filter((e=>void 0!==e.col&&void 0===e.row&&e.width));let o={};r&&r.forEach((e=>{o[e.col]=e.width}));for(let i=0;i<e.data[0].length;i++)n+=(o[i]||e.colWidth)*e.calculative.canvas.store.data.scale,t.push(n);let s=0;const a=e.styles&&e.styles.filter((e=>void 0===e.col&&void 0!==e.row&&e.height));let c={};a&&a.forEach((e=>{c[e.row]=e.height}));for(let t=0;t<e.data.length;t++)s+=(c[t]||e.rowHeight)*e.calculative.canvas.store.data.scale,i.push(s);e.colPos=t,e.rowPos=i,e.tableWidth=n,e.tableHeight=s,e.width=n,e.height=s,e.calculative.width=n,e.calculative.height=s,e.calculative.worldRect={x:e.x,y:e.y,height:e.height,width:e.width,center:{x:e.x+e.width/2,y:e.y+e.height/2}},At(e.calculative.worldRect)}(e)}function Qr(e,t){if(!e.calculative.hoverCell)return;const{value:i}=no(e,e.calculative.hoverCell.row,e.calculative.hoverCell.col);if("object"==typeof i)return;e.calculative.isHover=!1,e.calculative.isInput=!0,e.calculative.canvas.render(),e.calculative.inputCell=e.calculative.hoverCell;const n=so(e,e.calculative.hoverCell.row,e.calculative.hoverCell.col);e.calculative.tempText=i.text||i+"",e.calculative.canvas.showInput(e,n,"#ffffff")}function Jr(e,t){e.calculative.inputCell&&(oo(e,e.calculative.inputCell.row,e.calculative.inputCell.col,t),e.calculative.isInput=!1,e.calculative.isHover=!0,e.calculative.canvas.render())}function Zr(e,t){e.timer&&(e.calculative.isHover=!1,clearTimeout(e.timer)),e.timer=setTimeout((()=>{e.calculative.isHover=!0,e.calculative.canvas.render()}),500),e.calculative.hoverCell=io(e,t),e.calculative.canvas.render()}function eo(e,t){e.calculative.hoverCell=void 0,e.calculative.canvas.render()}function to(e,t){e.calculative.activeCell=io(e,t),e.calculative.canvas.render()}function io(e,t){const i=e.calculative.worldRect.width/e.tableWidth,n=e.calculative.worldRect.height/e.tableHeight,r={row:0,col:0};for(let n=0;n<e.colPos.length;n++)t.x>e.calculative.worldRect.x+e.colPos[n]*i&&(r.col=n+1);for(let i=0;i<e.rowPos.length;i++)t.y>e.calculative.worldRect.y+e.rowPos[i]*n&&(r.row=i+1);return r}function no(e,t,i){if(!e.data||!Array.isArray(e.data))return;const n=e.data[t],r=e.styles&&e.styles.filter((e=>e.row===t&&e.col===i));if(Array.isArray(n))return{value:n[i],style:r?.length>0?r[0]:{}};n.data&&Array.isArray(n.data)}function ro(e,t){if(!e.data||!Array.isArray(e.data))return;const i=e.data[t],n=e.styles&&e.styles.filter((e=>e.row===t&&!e.col));if(Array.isArray(i))return{value:i,style:n?.length>0?n[0]:{}};i.data&&Array.isArray(i.data)}function oo(e,t,i,n){if(!e.data||!Array.isArray(e.data))return;e.isFirstTime=!1,e.calculative.texts=void 0;let r=e.data[t];r&&(r[i]instanceof Object||(r[i]=n),e.calculative.canvas.store.emitter.emit("valueUpdate",e))}function so(e,t,i){const n=e.calculative.worldRect.width/e.tableWidth,r=e.calculative.worldRect.height/e.tableHeight;let o=0,s=e.colPos[i]*n;i>0&&(o=e.colPos[i-1]*n);let a=0,c=e.rowPos[t]*r;return t>0&&(a=e.rowPos[t-1]*r),{x:e.calculative.worldRect.x+o,y:e.calculative.worldRect.y+a,ex:e.calculative.worldRect.x+s,ey:e.calculative.worldRect.y+c,width:s-o,height:c-a}}function ao(e,t,i){const n=e.calculative.worldRect.width/e.tableWidth,r=e.calculative.worldRect.height/e.tableHeight;let o=0,s=0,a=0;const c=e.calculative.canvas.store.data.scale;if(i.length>1){for(const e of i)s+e.width*n+20*c*n<t.width?(e.x=t.x+s+10*c*n,e.y=t.y+a+10*c*r,s+=(e.width+10*c)*n,o=Math.max(o,a+(e.height+10*c)*r)):(s=0,a=o,e.x=t.x+s+10*c*n,e.y=t.y+a+10*c*r,o+=(e.height+10*c)*r);if(o+20*c*r<t.height){const e=(t.height-o-10*c*r)/2;for(const t of i)t.y+=e}}else i[0].x=t.x+(t.width-i[0].width)/2,i[0].y=t.y+(t.height-i[0].height)/2}function co(e){if(e.calculative.isUpdateData){Gr(e),delete e.calculative.isUpdateData;let t=e.children;e.children=[],t&&t.forEach((t=>{e.calculative.canvas.delForce(e.calculative.canvas.findOne(t))})),e.calculative.texts=void 0}}function lo(e,t){if(e.calculative.isUpdateData=!1,t.table||null==t.col&&null==t.row){if(t.dataY){const i=e.replaceMode;let n=[];return i?i===Tn.Replace?(n=e.data,t.dataX&&t.dataX.forEach(((e,i)=>{n[e]=t.dataY[i]}))):i===Tn.ReplaceAll&&(t.dataX?n[0]=t.dataX:n[0]=e.data[0],n=n.concat(t.dataY)):n=e.data.concat(t.dataY),delete t.dataX,delete t.dataY,e.calculative.isUpdateData=!0,Object.assign(t,{data:n})}return(t.data||e.styles)&&(e.calculative.isUpdateData=!0),t}let i=e.data[t.row];return i?(i[t.col]instanceof Object||(i[t.col]=t.value),oo(e,t.row,t.col,t.value),e.calculative.canvas.render(),delete t.col,delete t.row,t):t}function ho(e,t){t.onAdd||(t.onAdd=uo,t.onResize=uo,t.onMove=uo,t.onMouseMove=vo,t.onMouseDown=po,t.onValue=xo,t.onBeforeValue=go),t.calculative.barRect||uo(t),t.calculative.canvas.store.data;const i=t.calculative.canvas.store.options;e.fillStyle=t.background,e.beginPath();let n=t.calculative.worldRect.x+t.calculative.barRect.x,r=t.calculative.worldRect.y+t.calculative.barRect.y,o=t.calculative.barRect.width,s=t.calculative.barRect.height,a=s/2;e.moveTo(n+a,r),e.arcTo(n+o,r,n+o,r+s,a),e.arcTo(n+o,r+s,n,r+s,a),e.arcTo(n,r+s,t.x,t.y,a),e.arcTo(n,r,n+o,r,a),e.fill(),e.fillStyle=t.activeColor||i.activeColor,e.beginPath(),o=t.calculative.ballRect.x,e.moveTo(n+a,r),e.arcTo(n+o,r,n+o,r+s,a),e.arcTo(n+o,r+s,n,r+s,a),e.arcTo(n,r+s,t.x,t.y,a),e.arcTo(n,r,n+o,r,a),e.fill(),e.fillStyle="#ffffff",e.beginPath(),n=t.calculative.worldRect.x+t.calculative.ballRect.x,r=t.calculative.worldRect.y+t.calculative.ballRect.y+t.calculative.ballRect.height/2,e.lineWidth=t.calculative.ballRect.width/10,e.arc(n,r,t.calculative.ballRect.width/2,0,2*Math.PI),e.fill(),e.stroke()}function uo(e){if(e._textWidth||(e._textWidth=e.textWidth||50,e._fontSize=e.fontSize||12),e.textWidth=e.calculative.worldRect.width,e.calculative.textWidth=e.textWidth,e.unit||(e.unit="%"),e.sliderWidth||(e.sliderWidth=e.width),e.sliderHeight||(e.sliderHeight=e.height),!e.calculative.worldRect)return;const t=e.calculative.worldRect.width/e.sliderWidth,i=e.calculative.worldRect.height/e.sliderHeight,n=Math.min(t,i);e.fontSize=e._fontSize*n;const r=e.calculative.worldRect.width-e._textWidth*n;e.textLeft=r+10*n,e.calculative.textLeft=e.textLeft,e.calculative.barRect={x:0,y:(e.calculative.worldRect.height-e.barHeight*i)/2,width:r,height:e.barHeight*i},At(e.calculative.barRect),fo(e)}function fo(e){const t=3.5*e.calculative.barRect.height,i=e.calculative.barRect.width*e.value/100;e.calculative.ballRect={x:i,y:(e.calculative.worldRect.height-t)/2,width:t,height:t},At(e.calculative.ballRect),e.calculative.text=e.value+e.unit,U(e)}function po(e,t){const i=t.x-e.calculative.worldRect.x;if(i>e.calculative.barRect.width)return;let n=Math.round(i/e.calculative.barRect.width*100);n<e.min||n>e.max||n<0||n>100||(e.value=n,fo(e),e.calculative.text=e.value+e.unit,U(e),e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render())}function vo(e,t){e.calculative.canvas.mouseDown&&po(e,t)}function xo(e){e.calculative.isUpdateData&&(delete e.calculative.isUpdateData,uo(e)),fo(e)}function go(e,t){return e.calculative.isUpdateData=!1,(t.textWidth||t.barHeight)&&(t.textWidth&&(e._textWidth=0),e.calculative.isUpdateData=!0),t}function yo(e,t){t.onClick||(t.onClick=mo);let i=t.calculative.worldRect.x,n=t.calculative.worldRect.y,r=t.calculative.worldRect.width,o=t.calculative.worldRect.height;r<1.5*o&&(r=1.5*o),e.beginPath(),e.arc(i+o/2,n+o/2,o/2,Math.PI/2,3*Math.PI/2),e.lineTo(i+r-o/2,n),e.arc(i+r-o/2,n+o/2,o/2,-Math.PI/2,Math.PI/2),e.lineTo(i+o/2,n+o),t.checked?(e.fillStyle=t.onColor,t.disable&&(e.fillStyle=t.disableOnColor),e.fill(),e.closePath(),e.beginPath(),e.fillStyle="#ffffff",e.moveTo(i+2*o,n+o/2),e.arc(i+r-o/2,n+o/2,o/2>2?o/2-2:1,0,2*Math.PI),e.fill()):(e.fillStyle=t.offColor,t.disable&&(e.fillStyle=t.disableOffColor),e.fill(),e.closePath(),e.beginPath(),e.fillStyle="#ffffff",e.moveTo(i+o,n+o/2),e.arc(i+o/2,n+o/2,o/2>2?o/2-2:1,0,2*Math.PI),e.fill()),e.closePath()}function mo(e){e.disable||(e.checked=!e.checked,e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render())}function bo(e,t){t.onMouseDown||(t.onMouseDown=wo);let i=t.calculative.worldRect.x,n=t.calculative.worldRect.y,r=t.calculative.worldRect.height;t.calculative.worldRect.width;const{fontStyle:o,fontWeight:s,fontSize:a,fontFamily:c,lineHeight:l}=t.calculative;e.beginPath(),e.moveTo(i,n),e.arcTo(i+r,n,i+r,n+r,2),e.arcTo(i+r,n+r,i,n+r,2),e.arcTo(i,n+r,i,n,2),e.arcTo(i,n,i+r,n,2),e.strokeStyle="#d9d9d9",e.fillStyle="#ffffff00",t.checked&&(e.fillStyle=t.background||"#1890ff",e.strokeStyle=t.background||"#1890ff"),t.isForbidden&&(e.fillStyle="#ebebeb",e.strokeStyle="#d9d9d9"),e.closePath(),e.fill(),e.stroke(),e.save(),t.checked&&(e.beginPath(),e.lineWidth=r/10,e.strokeStyle="#ffffff",e.moveTo(i+102/506*r,n+r/2),e.lineTo(i+220/506*r,n+346/460*r),e.lineTo(i+404/506*r,n+142/460*r),e.stroke()),e.restore(),e.save(),e.fillStyle=t.isForbidden?"#00000040":we(t,t.calculative.canvas.parent.store)||"#000000d9",e.textAlign="start",e.textBaseline="middle",e.font=Ae({fontStyle:o,fontWeight:s,fontFamily:c||t.calculative.canvas.parent.store.options.fontFamily,fontSize:a,lineHeight:l}),e.fillText(t.value+"",i+r+10,n+r/2),e.restore()}function wo(e,t){e.isForbidden||(e.checked=!e.checked,e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render())}function _o(e,t){t.onAdd||(t.onAdd=ko,t.optionPos||(t.onAdd(t),t.calculative.canvas.parent.active([t])),t.onMouseDown=To,t.onValue=Ao);let i=t.calculative.worldRect.x,n=t.calculative.worldRect.y,r=t.calculative.worldRect.height,o=t.calculative.worldRect.width;if(!t.optionPos)return;const{fontStyle:s,fontWeight:a,fontSize:c,fontFamily:l,lineHeight:h}=t.calculative;if("horizontal"==t.direction)for(let c=0;c<t.optionPos.length;c++){const u=t.optionPos[c]*o/t.checkboxWidth,d=t.options[c].isForbidden;e.beginPath(),e.arc(i+u+r/2,n+r/2,r/2,0,2*Math.PI),e.strokeStyle="#d9d9d9",e.fillStyle="#ffffff00",t.options[c].text===t.checked&&(e.strokeStyle=t.options[c].background||t.background||"#1890ff"),d&&(e.fillStyle="#ebebeb",e.strokeStyle="#d9d9d9"),e.closePath(),e.fill(),e.stroke(),e.save(),d||t.options[c].text!==t.checked||(e.beginPath(),e.strokeStyle=t.options[c].background?t.options[c].background+"20":t.background||"#1890ff20",e.arc(i+r/2+u,n+r/2,r/2+1.5,0,2*Math.PI),e.stroke(),e.closePath(),e.beginPath(),e.fillStyle=t.options[c].background||t.background||"#1890ff",e.arc(i+r/2+u,n+r/2,r/4,0,2*Math.PI),e.fill(),e.closePath()),e.restore(),e.save(),e.fillStyle=d?"#00000040":we(t,t.calculative.canvas.parent.store)||"#000000d9";const f=14*t.calculative.worldRect.height/16;e.textAlign="start",e.textBaseline="middle",e.font=Ae({fontStyle:s,fontWeight:a,fontFamily:l||t.calculative.canvas.parent.store.options.fontFamily,fontSize:f,lineHeight:h}),e.fillText(t.options[c].text,i+r+u+10/t.checkboxWidth*o,n+r/2),e.restore()}else if("vertical"==t.direction){const o=t.optionHeight*r/t.checkboxHeight;for(let c=0;c<t.optionPos.length;c++){const u=t.optionPos[c]*r/t.checkboxHeight,d=t.options[c].isForbidden;e.beginPath(),e.arc(i+o/2,n+o/2+u,o/2,0,2*Math.PI),e.strokeStyle="#d9d9d9",e.fillStyle="#ffffff00",t.options[c].text===t.checked&&(e.strokeStyle=t.options[c].background||"#1890ff"),d&&(e.fillStyle="#ebebeb",e.strokeStyle="#d9d9d9"),e.closePath(),e.fill(),e.stroke(),e.save(),d||t.options[c].text!==t.checked||(e.beginPath(),e.strokeStyle=t.options[c].background?t.options[c].background+"20":"#1890ff20",e.arc(i+o/2,n+o/2+u,o/2+1.5,0,2*Math.PI),e.stroke(),e.closePath(),e.beginPath(),e.fillStyle=t.options[c].background||"#1890ff",e.arc(i+o/2,n+o/2+u,o/4,0,2*Math.PI),e.fill(),e.closePath()),e.restore(),e.save(),e.fillStyle=d?"#00000040":we(t,t.calculative.canvas.parent.store)||"#000000d9";const f=14*t.calculative.worldRect.height/t.checkboxHeight;e.textAlign="start",e.textBaseline="middle",e.font=Ae({fontStyle:s,fontWeight:a,fontFamily:l||t.calculative.canvas.parent.store.options.fontFamily,fontSize:f,lineHeight:h}),e.fillText(t.options[c].text,i+o+10,n+o/2+u),e.restore()}}}function ko(e){$r(e)}function To(e,t){if("horizontal"==e.direction)for(let i=0;i<e.optionPos.length;i++)!e.options[i].isForbidden&&t.x>e.calculative.worldRect.x+e.optionPos[i]*e.calculative.worldRect.width/e.checkboxWidth&&t.x<e.calculative.worldRect.x+(e.optionPos[i]+e.height)/e.checkboxWidth*e.calculative.worldRect.width+Yr(e.options[i].text,e)+10/e.checkboxWidth*e.calculative.worldRect.width&&(e.checked=e.options[i].text,e.calculative.canvas.store.emitter.emit("valueUpdate",e));else if("vertical"==e.direction){const i=e.calculative.worldRect.height/e.checkboxHeight;for(let n=0;n<e.optionPos.length;n++)!e.options[n].isForbidden&&t.y>e.calculative.worldRect.y+e.optionPos[n]*i&&t.y<e.calculative.worldRect.y+(e.optionPos[n]+e.optionHeight)*i&&(e.checked=e.options[n].text,e.calculative.canvas.store.emitter.emit("valueUpdate",e))}e.calculative.canvas.render()}function Ao(e){$r(e)}function So(){return{radio:_o,switch:yo,slider:ho,checkbox:bo,table:Mr,table2:Xr}}function Po(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect,a=s/6,c=o/4;if(i.moveTo(n+2*c,r+0),i.lineTo(n+2*c,r+a),i.moveTo(n,r+a+2*c),i.arc(n+2*c,r+a+2*c,2*c,1*Math.PI,2*Math.PI,!1),i.lineTo(n+4*c,r+5*a),i.lineTo(n,r+5*a),i.lineTo(n,r+a+2*c),i.moveTo(n+c,r+5*a),i.lineTo(n+c,r+6*a),i.moveTo(n+2*c,r+5*a),i.lineTo(n+2*c,r+6*a),i.moveTo(n+3*c,r+5*a),i.lineTo(n+3*c,r+6*a),i.closePath(),i instanceof Path2D)return i}function Co(e){e.anchors=[{x:.5,y:0},{x:.25,y:1},{x:.5,y:1},{x:.75,y:1}].map((({x:t,y:i},n)=>({id:`${n}`,penId:e.id,x:t,y:i})))}function Eo(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect,a=s-o,c=.5*o;if(i.moveTo(n+o/2,r),i.lineTo(n+o/2,r+a),i.moveTo(n+o,r+c+a),i.arc(n+o/2,r+c+a,c,0,2*Math.PI,!1),i.closePath(),i instanceof Path2D)return i}function Ro(e){e.anchors=[{x:.5,y:0},{x:.5,y:1}].map((({x:t,y:i},n)=>({id:`${n}`,penId:e.id,x:t,y:i})))}function Io(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect,a=s/2,c=o/5;if(i.moveTo(n,r+a),i.lineTo(n+c,r+a),i.moveTo(n+5*c,r+a),i.ellipse(n+3*c,r+a,2*c,a,0,0,2*Math.PI),i.closePath(),i instanceof Path2D)return i}function Lo(e){e.anchors=[{x:.6,y:0},{x:1,y:.5},{x:.6,y:1},{x:0,y:.5}].map((({x:t,y:i},n)=>({id:`${n}`,penId:e.id,x:t,y:i})))}function Mo(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect,a=s/4,c=.5*o;if(i.moveTo(n+c,r),i.lineTo(n+c,r+a),i.moveTo(n,r+a),i.rect(n,r+a,2*c,2*a),i.moveTo(n+c,r+3*a),i.lineTo(n+c,r+4*a),i.closePath(),i instanceof Path2D)return i}function Do(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect,a=s/8,c=.25*o;if(i.moveTo(n+2*c,r),i.lineTo(n+2*c,r+2*a),i.lineTo(n+3*c,r+3*a),i.lineTo(n+3*c,r+5*a),i.lineTo(n+2*c,r+6*a),i.lineTo(n+1*c,r+5*a),i.lineTo(n+1*c,r+3*a),i.lineTo(n+2*c,r+2*a),i.moveTo(n+3*c,r+4*a),i.lineTo(n+4*c,r+4*a),i.moveTo(n+2*c,r+6*a),i.lineTo(n+2*c,r+8*a),i.closePath(),i instanceof Path2D)return i}function No(e){e.anchors=[{x:.5,y:0},{x:1,y:.5},{x:.5,y:1}].map((({x:t,y:i},n)=>({id:`${n}`,penId:e.id,x:t,y:i})))}function Oo(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect,a=o/2,c=s/10;if(i.moveTo(n+a,r),i.lineTo(n+a,r+c),i.moveTo(n+a,r+c),i.quadraticCurveTo(n+2*a,r+c,n+2*a,r+9*c),i.moveTo(n+a,r+c),i.quadraticCurveTo(n,r+c,n,r+9*c),i.quadraticCurveTo(n+a,r+6*c,n+2*a,r+9*c),i.moveTo(n+a,r+3*s/4),i.lineTo(n+a,r+s),i.moveTo(n+2*a/5,r+201*s/250),i.lineTo(n+2*a/5,r+s),i.moveTo(n+8*a/5,r+201*s/250),i.lineTo(n+8*a/5,r+s),i.closePath(),i instanceof Path2D)return i}function Bo(e){e.anchors=[{x:.5,y:0},{x:.2,y:1},{x:.5,y:1},{x:.8,y:1}].map((({x:t,y:i},n)=>({id:`${n}`,penId:e.id,x:t,y:i})))}function Fo(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect,a=s/6,c=o/4;if(i.moveTo(n+2*c,r+0),i.lineTo(n+2*c,r+a),i.moveTo(n,r+a+2*c),i.arc(n+2*c,r+a+2*c,2*c,1*Math.PI,2*Math.PI,!1),i.lineTo(n+4*c,r+5*a),i.lineTo(n,r+5*a),i.lineTo(n,r+a+2*c),i.moveTo(n,r+5*a-a/3),i.lineTo(n+4*c,r+5*a-a/3),i.moveTo(n+c,r+5*a),i.lineTo(n+c,r+6*a),i.moveTo(n+2*c,r+5*a),i.lineTo(n+2*c,r+6*a),i.moveTo(n+3*c,r+5*a),i.lineTo(n+3*c,r+6*a),i.closePath(),i instanceof Path2D)return i}function zo(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect,a=s/4,c=.5*o;if(i.moveTo(n+c,r),i.lineTo(n+c,r+a),i.lineTo(n+2*c,r+2*a),i.lineTo(n+2*c,r+4*a),i.lineTo(n,r+4*a),i.lineTo(n,r+2*a),i.lineTo(n+c,r+a),i.closePath(),i instanceof Path2D)return i}function jo(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect,a=s/4,c=o/2;if(i.moveTo(n+c,r),i.lineTo(n+c,r+a),i.lineTo(n+2*c,r+4*a),i.lineTo(n,r+4*a),i.lineTo(n+c,r+a),i.closePath(),i instanceof Path2D)return i}function Ho(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect,a=s/3,c=.5*o;if(i.moveTo(n+c,r),i.lineTo(n+c,r+a),i.lineTo(n+o,r+2*a),i.lineTo(n+c,r+s),i.lineTo(n,r+2*a),i.lineTo(n+c,r+a),i.closePath(),i instanceof Path2D)return i}function Uo(e){e.anchors=[{x:.5,y:0},{x:1,y:2/3},{x:.5,y:1},{x:0,y:2/3}].map((({x:t,y:i},n)=>({id:`${n}`,penId:e.id,x:t,y:i})))}function Wo(e,t){const{x:i,y:n,width:r,height:o}=t.calculative.worldRect,s=r/2,a=o/10;e.beginPath(),e.moveTo(i+s,n),e.lineTo(i+s,n+a),e.moveTo(i+s,n+a),e.quadraticCurveTo(i+2*s,n+a,i+2*s,n+9*a),e.moveTo(i+s,n+a),e.quadraticCurveTo(i,n+a,i,n+9*a),e.quadraticCurveTo(i+s,n+6*a,i+2*s,n+9*a),e.moveTo(i+s,n+3*o/4),e.lineTo(i+s,n+9*o/10),e.moveTo(i+2*s/5,n+201*o/250),e.lineTo(i+2*s/5,n+9*o/10),e.moveTo(i+8*s/5,n+201*o/250),e.lineTo(i+8*s/5,n+9*o/10),e.stroke(),e.closePath(),e.beginPath();const c=2*s>10*a?a:s/5;e.fillStyle="#333333",e.font=c+"px Arial",e.textBaseline="bottom",e.textAlign="center",e.fillText("o",i+s,n+o),e.fillText("m",i+2*s/5,n+o),e.fillText("o",i+8*s/5,n+o),e.closePath()}function Vo(e,t){const i=t||new Path2D,{x:n,y:r,width:o,height:s}=e.calculative.worldRect;let a=o/2,c=s/10;if(i.moveTo(n+a,r),i.lineTo(n+a,r+c),i.moveTo(n+a,r+c),i.quadraticCurveTo(n+2*a,r+c,n+2*a,r+9*c),i.moveTo(n+a,r+c),i.quadraticCurveTo(n,r+c,n,r+9*c),i.quadraticCurveTo(n+a,r+6*c,n+2*a,r+9*c),i.moveTo(n,r+10*c),i.quadraticCurveTo(n+a,r+7*c,n+2*a,r+10*c),i.moveTo(n+2*a/5,r+201*s/250+c),i.lineTo(n+2*a/5,r+s),i.moveTo(n+8*a/5,r+201*s/250+c),i.lineTo(n+8*a/5,r+s),i.closePath(),i instanceof Path2D)return i}function qo(e){e.anchors=[{x:.5,y:0},{x:.2,y:1},{x:.8,y:1}].map((({x:t,y:i},n)=>({id:`${n}`,penId:e.id,x:t,y:i})))}function Ko(){return{andGate:Po,basicEvent:Eo,conditionalEvent:Io,event:Mo,forbiddenGate:Do,orGate:Oo,priorityAndGate:Fo,switchEvent:zo,transferSymbol:jo,unexpandedEvent:Ho,xorGate:Vo}}function Yo(){return{votingGate:Wo}}function $o(){return{andGate:Co,orGate:Bo,priorityAndGate:Co,votingGate:Bo,xorGate:qo,forbiddenGate:No,basicEvent:Ro,unexpandedEvent:Uo,conditionalEvent:Lo,transferSymbol:Ro}}!function(e){e[e.Add=0]="Add",e[e.Replace=1]="Replace",e[e.ReplaceAll=2]="ReplaceAll"}(kn||(kn={})),function(e){e[e.Add=0]="Add",e[e.Replace=1]="Replace",e[e.ReplaceAll=2]="ReplaceAll"}(Tn||(Tn={}));const Xo=15;function Go(e,t=Xo){let i=""+e;return i.indexOf(".")>=0&&(i=Number.parseFloat(i).toFixed(t)),Number.parseFloat(i)}function Qo(e){return"number"==typeof e&&Number.isFinite(e)}function Jo(e,t){const i=t.calculative.worldRect.x,n=t.calculative.worldRect.y,r=t.calculative.worldRect.width,o=t.calculative.worldRect.height;let s=[];if(t.echarts)for(let e=0;e<t.echarts.option.series.length;e++)s.push(t.echarts.option.series[e].data);else s=t.data;let a=[];for(let e=0;e<s.length;e++)a=a.concat(s[e]);let c=function(e){e={max:null,min:null,splitNumber:4,symmetrical:!1,deviation:!1,preferZero:!1,...e};const t=[10,15,20,25,30,40,50,60,70,80,90,100,150];let{max:i,min:n,splitNumber:r,symmetrical:o,deviation:s,preferZero:a}=e;if(!Qo(i)||!Qo(n)||i<n)return{splitNumber:r};if(i===n&&0===i)return{max:Go(t[0]*r),min:n,interval:t[0],splitNumber:r};i===n&&(a=!0),(!Qo(r)||r<=0)&&(r=4),a&&i*n>0&&(i<0?i=0:n=0);const c=(i-n)/r;let l=Math.floor(Math.log10(c)-1);l=Math.pow(10,l);const h=c/l;let u,d=t[0]*l,f=-1;for(u=0;u<t.length;u++)if(t[u]>h){d=t[u]*l;break}let p=i,v=n;function x(e){if(p=parseInt(""+(i/e+1))*e,v=parseInt(""+(n/e-1))*e,0===i&&(p=0),0===n&&(v=0),o&&p*v<0){const e=Math.max(Math.abs(p),Math.abs(v));p=e,v=-e}}if(x(d),s)return{max:Go(p),min:Go(v),interval:Go(d),splitNumber:Math.round((p-v)/d)};if(!o||p*v>0){let e;e:do{if(e=Math.round((p-v)/d),(u-f)*(e-r)<0)for(;e<r;)if(v-n<=p-i&&0!==v||0===p?v-=d:p+=d,e++,e===r)break e;if(u>=t.length-1||u<=0||e===r)break;f=u,d=e>r?t[++u]*l:t[--u]*l,x(d)}while(e!==r)}p=Go(p),v=Go(v);const g=Go((p-v)/r);return{max:p,min:v,interval:g,splitNumber:r}}({max:Math.max.apply(null,a),min:Math.min.apply(null,a),splitNumber:5}),l=t.echarts?t.echarts.option.xAxis.data.length:t.xAxisData.length;e.beginPath(),e.strokeStyle="#BFBFBF",e.lineWidth=6,e.lineCap="butt";let h=(r-1*(l+1))/l;e.setLineDash([1,h]),e.moveTo(i,n+o+3),e.lineTo(i+r,n+o+3),e.stroke(),e.closePath(),e.beginPath(),e.lineWidth=1,e.setLineDash([]),e.moveTo(i,n+o),e.lineTo(i+r,n+o),e.stroke(),e.closePath(),e.beginPath(),e.fillStyle="#BFBFBF",e.strokeStyle="#E9E9E9",e.setLineDash([2,2]);for(let t=0;t<c.splitNumber+1;t++){let s=t*o/c.splitNumber;e.textAlign="right",e.textBaseline="middle",e.fillText(c.max-t*c.interval+"",i-10,n+s),e.fill(),t<c.splitNumber&&(e.moveTo(i,n+s),e.lineTo(i+r,n+s),e.stroke())}e.closePath(),e.beginPath(),e.strokeStyle="#BFBFBF";let u=t.echarts?t.echarts.option.xAxis.data:t.xAxisData,d=0;for(let t=0;t<u.length;t++)d=i+(1+h/2)+(h+1)*t,e.textAlign="center",e.textBaseline="top",e.fillText(u[t],d,n+o+10),e.fill();return e.closePath(),e.setLineDash([]),{dash:h,normalizedOption:c}}function Zo(e,t){if(!isNaN(e))return-1===t?e:Math.round(1e3*Number(e))/1e3}var es;function ts(e,t){t.onBeforeValue||(t.onBeforeValue=is);const i=t.calculative.worldRect.x,n=t.calculative.worldRect.y,r=(t.calculative.worldRect.width,t.calculative.worldRect.height);let o=[];t.echarts&&!t.echarts.option.color&&(t.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]);let s=Jo(e,t),a=s.dash,c=s.normalizedOption;const l=!!(t.echarts?t.echarts.option.series[0].smooth:t.smooth);let h=[];if(t.echarts)for(let e=0;e<t.echarts.option.series.length;e++)o.push(t.echarts.option.series[e].data);else o=t.data;for(let s=0;s<o.length;s++){e.beginPath();let u=o[s];e.strokeStyle=t.echarts?t.echarts.option.color[s]:t.chartsColor[s],e.fillStyle=t.echarts?t.echarts.option.color[s]:t.chartsColor[s];let d=i+(1+a/2),f=n+r-(u[0]-c.min)/(c.max-c.min)*r;if(e.moveTo(d,f),h.push({x:d,y:f}),l)if(u.length<=2)for(let t=1;t<u.length;t++)d=i+(1+a/2)+(a+1)*t,f=n+r-(u[t]-c.min)/(c.max-c.min)*r,e.lineTo(d,f),h.push({x:d,y:f});else{let t,o,s,l;u.forEach(((p,v)=>{d=i+(1+a/2)+(a+1)*v,f=n+r-(u[v]-c.min)/(c.max-c.min)*r;let x=i+(1+a/2)+(a+1)*(v+1),g=n+r-(u[v+1]-c.min)/(c.max-c.min)*r,y=i+(1+a/2)+(a+1)*(v-1),m=n+r-(u[v-1]-c.min)/(c.max-c.min)*r,b=i+(1+a/2)+(a+1)*(v+2),w=n+r-(u[v+2]-c.min)/(c.max-c.min)*r;0===v?(y=i+(1+a/2)+(a+1)*v,m=n+r-(u[v]-c.min)/(c.max-c.min)*r):v===u.length-2&&(b=i+(1+a/2)+(a+1)*(v+1),w=n+r-(u[v+1]-c.min)/(c.max-c.min)*r),h.push({x:d,y:f}),t=d+(x-y)/4,o=f+(g-m)/4,s=x-(b-d)/4,l=g-(w-f)/4,e.bezierCurveTo(t,o,s,l,x,g)}))}else for(let t=1;t<u.length;t++)d=i+(1+a/2)+(a+1)*t,f=n+r-(u[t]-c.min)/(c.max-c.min)*r,e.lineTo(d,f),h.push({x:d,y:f});e.stroke(),e.closePath(),e.save(),h.forEach(((t,i)=>{e.beginPath(),e.strokeStyle="#fff",e.lineWidth=2,e.arc(t.x,t.y,4,0,2*Math.PI),e.stroke(),e.fill(),e.closePath()})),e.restore(),h=[]}}function is(e,t){if(t.xAxisData||t.data||!t.dataX&&!t.dataY)return t;const i=e.xAxisData,n=e.data,r=e.replaceMode;let o=[],s=[];return r?r===es.Replace?(t.dataX.forEach(((e,r)=>{let o=i.indexOf(e);n.forEach(((e,i)=>{e[o]=t.dataY[i][r]}))})),o=i,s=n):r===es.ReplaceAll&&(o=t.dataX,s=t.dataY):(o=[...i,...t.dataX],n.forEach(((e,i)=>{let n=[...e,...t.dataY[i]];s.push(n)}))),delete t.dataX,delete t.dataY,Object.assign(t,{xAxisData:o,data:s})}function ns(e,t){t.onBeforeValue||(t.onBeforeValue=rs);const i=t.calculative.worldRect.x,n=t.calculative.worldRect.y,r=t.calculative.worldRect.width,o=t.calculative.worldRect.height,s=!!t.echarts;t.echarts?(t.echarts.option.color||(t.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]),t.chartsColor=t.echarts.option.color):t.chartsColor||(t.chartsColor=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]);const a=s?t.echarts.option.series:t.data;let c=0;for(let l=0;l<a.length;l++){let h=a[l],u=r/2;o<r&&(u=o/2);const d=i+r/2,f=n+o/2;let p=0;p=s?h.data.reduce(((e,t)=>e+t.value),0):h.reduce(((e,t)=>e+t.value),0);const v=u*parseFloat(s?h.radius[0]:t.chartsRadius[l][0])/100,x=u*parseFloat(s?h.radius[1]:t.chartsRadius[l][1])/100;if(v>x)return;let g=0,y=0;e.strokeStyle=s&&h.itemStyle?.borderColor||"#fff",e.lineWidth=s&&h.itemStyle?.borderWidth||2;const m=s?h.data:h;m.forEach(((i,n)=>{y+=2*Math.PI*i.value/p,e.beginPath();let r=c+n;r>=t.chartsColor.length&&(r%=t.chartsColor.length),e.fillStyle=s?t.echarts.option.color[r]:t.chartsColor[r],e.moveTo(d+v*Math.sin(y),f-v*Math.cos(y)),e.arc(d,f,v,-Math.PI/2+y,-Math.PI/2+g,!0),e.lineTo(d+x*Math.sin(g),f-x*Math.cos(g)),e.arc(d,f,x,-Math.PI/2+g,-Math.PI/2+y),e.lineTo(d+v*Math.sin(y),f-v*Math.cos(y)),e.stroke(),e.fill(),e.closePath();let o=(g+y)/2,a=d+(x+5)*Math.sin(o),l=f-(x+5)*Math.cos(o),m=e.fillStyle;h.label||(h.label={position:"outside",show:!0}),s&&["inner","inside"].includes(h.label.position)?(e.fillStyle="#ffffff",a=d+(x-v)/2*Math.sin(o),l=f-(x-v)/2*Math.cos(o)):s&&h.label.position,h.labelLine||(h.labelLine={show:!0}),(s&&!1!==h.labelLine.show||!s)&&(e.beginPath(),e.strokeStyle=s?t.echarts.option.color[c+n]:t.chartsColor[c+n],e.moveTo(d+x*Math.sin(o),f-x*Math.cos(o)),e.lineTo(a,l)),e.font=u/10+"px AlibabaPuHuiTi-Regular, Alibaba PuHuiTi",e.textBaseline="middle",e.textAlign="center",o>Math.PI?((s&&"outside"===h.label.position||!s)&&(e.textAlign="end"),(s&&!1!==h.labelLine.show||!s)&&e.lineTo(a-5,l),(s&&!1!==h.label.show||!s)&&e.fillText(i.name,a-5,l)):((s&&"outside"===h.label.position||!s)&&(e.textAlign="start"),(s&&!1!==h.labelLine.show||!s)&&e.lineTo(a+5,l),(s&&!1!==h.label.show||!s)&&e.fillText(i.name,a+5,l)),e.stroke(),e.closePath(),e.fillStyle=m,e.strokeStyle=s&&h.itemStyle?.borderColor||"#fff",g=y})),c+=m.length}}function rs(e,t){if(t.data||!t.dataX&&!t.dataY)return t;const i=e.data,n=e.replaceMode;let r=[];return n?n===es.Replace?(t.dataY.forEach(((e,t)=>{e.forEach(((e,n)=>{let r=i[t].filter((t=>t.name===e.name));r.length>0&&(r[0].value=e.value)}))})),r=i):n===es.ReplaceAll&&(r=t.dataY):i.forEach(((e,i)=>{let n=[...e,...t.dataY[i]];r.push(n)})),delete t.dataX,delete t.dataY,Object.assign(t,{data:r})}function os(e,t){t.onBeforeValue||(t.onBeforeValue=is);const i=t.calculative.worldRect.x,n=t.calculative.worldRect.y,r=(t.calculative.worldRect.width,t.calculative.worldRect.height);let o=[];if(t.echarts&&!t.echarts.option.color&&(t.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]),t.echarts)for(let e=0;e<t.echarts.option.series.length;e++)o.push(t.echarts.option.series[e].data);else o=t.data;let s=Jo(e,t),a=s.dash,c=s.normalizedOption,l=4*a/5/o.length;for(let s=0;s<o.length;s++){e.beginPath();let h=o[s];e.fillStyle=t.echarts?t.echarts.option.color[s]:t.chartsColor[s],e.strokeStyle="#ffffff";let u=0,d=0,f=0;for(let t=0;t<h.length;t++)u=i+(1+.1*a)+(a+1)*t+l*s,f=(h[t]-c.min)/(c.max-c.min)*r,d=n+r-f,e.rect(u,d,l-1,f-1),e.stroke(),e.fill();e.closePath()}}function ss(e,t){t.onAdd||(t.onAdd=as,t.onDestroy=cs,t.onClick=ls,t.clockInterval&&(t.onDestroy(t),t.onAdd(t)));const i=t.calculative.worldRect.x,n=t.calculative.worldRect.y,r=t.calculative.worldRect.width,o=t.calculative.worldRect.height;let s={startAngle:225,endAngle:-45,min:0,max:100,splitNumber:10};if(t.echarts&&t.echarts.option){let e=t.echarts.option.series[0];t.startAngle=e.startAngle||s.startAngle,t.endAngle=e.endAngle||s.endAngle,t.min=e.min||s.min,t.max=e.max||s.max,t.axisLine=e.axisLine.lineStyle.color,t.unit=e.detail.formatter.replace("{value}",""),t.value=e.data[0].value,t.splitNumber=e.splitNumber||s.splitNumber}let a,c=r>o?o/2*9/10:r/2*9/10,l=i+r/2,h=n+o/2,u=(t={...s,...t}).echarts?t.echarts.option.series[0].data[0].value:t.value,d=t.startAngle-t.endAngle,f=t.background||"#E6EBF8";e.strokeStyle=f;let p=c/10;e.lineWidth=p,e.beginPath(),e.lineCap="round",e.arc(l,h,c,-t.startAngle/180*Math.PI,-t.endAngle/180*Math.PI),e.stroke(),e.closePath();let v=0;if(t.axisLine&&!t.isClock)for(let i=t.axisLine.length-1;i>=0;i--)t.axisLine[i][0]*(t.max-t.min)<u?v=t.axisLine[i][0]:(v=(u-t.min)/(t.max-t.min),a=t.axisLine[i][1]),e.beginPath(),e.strokeStyle=t.axisLine[i][1],e.arc(l,h,c,-t.startAngle/180*Math.PI,(-t.startAngle+v*d)/180*Math.PI),e.stroke(),e.closePath();e.lineCap="butt";let x=c-p;x<0&&(x=0);let g=d/180*Math.PI*x,y=(g-2*t.splitNumber)/t.splitNumber,m=d/180*Math.PI*2/2/g;e.beginPath(),e.strokeStyle=t.color||"#999999",e.lineWidth=c/20,e.setLineDash([2,y]),e.arc(l,h,x,-t.startAngle/180*Math.PI-m,-t.endAngle/180*Math.PI+m),e.stroke(),e.closePath();let b=c-p;b<0&&(b=0);let w=d/180*Math.PI*b,_=(w-5*t.splitNumber)/5/t.splitNumber,k=d/180*Math.PI*1/2/w;e.beginPath(),e.strokeStyle=t.color||"#999999",e.lineWidth=c/40,e.setLineDash([1,_]),e.arc(l,h,b,-t.startAngle/180*Math.PI-k,-t.endAngle/180*Math.PI+k),e.stroke(),e.closePath(),e.beginPath();let T=t.max-t.min,A=T/t.splitNumber;e.font=(t.calculative.fontStyle||"")+" normal "+(t.calculative.fontWeight||"")+" "+c/10+"px "+t.calculative.fontFamily;let S=c-p-c/20;for(let i=0;i<=t.splitNumber;i++){if(Math.abs(t.startAngle)+Math.abs(t.endAngle)===360&&0==i)continue;let n=t.startAngle-A*i/T*d,r=Math.cos(n/180*Math.PI),o=Math.sin(n/180*Math.PI);e.fillStyle="#999999",e.textAlign=r>.02?"end":r<-.02?"start":"center",e.textBaseline=o>.02?"top":o<-.02?"bottom":"middle",e.fillText(Zo(A*i+t.min,1),l+S*r,h-S*o),e.fill()}e.closePath();let P=1,C=["value"];if(t.isClock&&(P=3,C=["hourvalue","minutevalue","secondvalue"]),t.isClock)for(let i=0;i<P;i++){let n=(t.startAngle-(t[C[i]]-t.min)/(t.max-t.min)*d)/180*Math.PI;i>0&&(n=(t.startAngle-(t[C[i]]-t.min)/(5*t.max-t.min)*d)/180*Math.PI);let r=.8*c;"hourvalue"===C[i]&&(r=.6*c),"minutevalue"===C[i]&&(r=.7*c);let o=1*c/40;e.beginPath(),e.setLineDash([]),e.lineWidth=c/(i+1)/20,e.strokeStyle=t.color||"#999999",e.moveTo(l-3*o*Math.cos(n),h+3*o*Math.sin(n)),e.lineTo(l+r*Math.cos(n),h-r*Math.sin(n)),e.stroke()}else{let i=(t.startAngle-(u-t.min)/(t.max-t.min)*d)/180*Math.PI,n=.8*c,r=1*c/40;e.beginPath(),e.setLineDash([]),e.lineWidth=2,e.fillStyle=a,e.moveTo(l-3*r*Math.cos(i),h+3*r*Math.sin(i)),e.lineTo(l+r*Math.cos(i-Math.PI/2),h-r*Math.sin(i-Math.PI/2)),e.lineTo(l+n*Math.cos(i),h-n*Math.sin(i)),e.lineTo(l+r*Math.cos(i+Math.PI/2),h-r*Math.sin(i+Math.PI/2)),e.lineTo(l-3*r*Math.cos(i),h+3*r*Math.sin(i)),e.fill()}e.beginPath(),e.textAlign="center",e.textBaseline="middle",e.font=(t.calculative.fontStyle||"")+" normal "+(t.calculative.fontWeight||"")+" "+c/5+"px "+t.calculative.fontFamily,e.fillStyle=a,t.isClock?e.fillText(("0"+parseInt(t.hourvalue)).slice(-2)+":"+("0"+parseInt(t.minutevalue)).slice(-2)+":"+("0"+parseInt(t.secondvalue)).slice(-2),l,h+c/2):e.fillText(u+" "+(t.unit||""),l,h+c/2),e.fill(),t.isClock&&(e.beginPath(),e.fillStyle=t.color||"#999999",e.strokeStyle="#ffffff",e.arc(l,h,c/20,0,2*Math.PI),e.stroke(),e.fill(),e.closePath())}function as(e){if(e.isClock)e.clockInterval=setInterval((()=>{var t=new Date,i=t.getSeconds(),n=t.getMinutes()+i/60,r=t.getHours()%12+n/60;e.calculative.canvas.parent.setValue({id:e.id,hourvalue:r,minutevalue:n,secondvalue:i},{render:!0,doEvent:!1})}),1e3);else{const t=e.value;e.value=0,e.frames=[{duration:2e3,value:t}],e.calculative.canvas.parent.startAnimate(e.id),setTimeout((()=>{e.value=t}),1e3)}}function cs(e){e.clockInterval&&(clearInterval(e.clockInterval),e.clockInterval=void 0)}function ls(e){e.isClock&&(e.onDestroy(e),e.onAdd(e))}function hs(){return{lineChart:ts,histogram:os,pieChart:ns,gauge:ss}}!function(e){e[e.Add=0]="Add",e[e.Replace=1]="Replace",e[e.ReplaceAll=2]="ReplaceAll"}(es||(es={})),globalThis.Meta2d=Sn,globalThis.registerCommonDiagram=function(){var e=globalThis.meta2d;e&&(Rr(),Ir(),Lr(),e.register(rr()),e.registerAnchors(or()),e.register(Hn()),e.registerCanvasDraw(Un()),e.register(Mn()),e.register(On()),e.registerCanvasDraw(Bn()),e.registerCanvasDraw(So()),e.registerCanvasDraw(hs()),e.register(Ko()),e.registerCanvasDraw(Yo()),e.registerAnchors($o()))}})(),n})()));
|