!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{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;s0&&(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.maximumPacketSize0||!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;e0){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;t0||!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;e0||!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;i0)if(this.options.resubscribe)if(5===this.options.protocolVersion){x("_resubscribe: protocolVersion 5");for(let t=0;t0){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{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&&nthis.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;e0?s-4:s;for(i=0;i>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;sa?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;a0)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>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;ithis.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;ti)){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;tthis.length?this.length:t;const r=this._offset(t);let o=r[0],s=r[1];for(;o=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-er)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=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;oa&&(i=a-c),o=i;o>=0;o--){for(var u=!0,d=0;dr&&(n=r):n=r;var o=t.length;n>o/2&&(n=o/2);for(var s=0;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;r239?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;nthis.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+=" ... "),""},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>>=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;rn)&&(i=n);for(var r="",o=t;oi)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||te.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>>=0,t>>>=0,i||E(e,t,this.length);for(var n=this[e],r=1,o=0;++o>>=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=(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>>=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>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=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=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>>=0,i=void 0===i?this.length:i>>>0,e||(e=0),"number"==typeof e)for(o=t;o55295&&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=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{i[e]=t[e]})),i.names=[],i.skips=[],i.formatters={},i.selectColor=function(e){let t=0;for(let i=0;i0&&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;t1&&(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=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=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<>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<>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<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]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;n0?--c:o0&&--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;o0?--s:o>0&&(--o,s=r.bucketSize-1)),++h,i[o][s]=e},this.popFront=function(){this.empty()||(1!==this.size()&&(s0&&--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;s0&&r[r.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!r||o[1]>r[0]&&o[1]=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];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]=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>>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];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]=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;a0&&--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]=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 et?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=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;o0&&r(e,o),s0&&r(e,s)};!function(){for(var e=Math.floor((n-1)/2);e>=0;--e)for(var o=e,s=2*o+1;s0&&(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())break;var a=o;if(s0&&(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]=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 et?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]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=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;tn;)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<[0,1].map((r=>[0,1].map((o=>{const s=e.alloc(1);return s.writeUInt8(i.codes[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>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)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._pos2?(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=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=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<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;e2)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;ep===_,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;to;){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=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.lowe)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(ethis.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;s1)for(var i=1;i= 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=55296&&t<=56319&&r65535&&(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=128&&w("not-basic"),v.push(e.charCodeAt(n));for(r=i>0?i+1:0;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=t&&pm((l-i)/(x=n+1))&&w("overflow"),i+=(a-t)*x,t=a,s=0;sl&&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=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;n2?"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;a0)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.lengtht.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.length0,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=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-e0?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;o0,!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-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;i0?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 er.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;t0,(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>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=0?(r>0&&(e.lastNeed=r-1),r):--n=0?(r>0&&(e.lastNeed=r-2),r):--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&&o127?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;P0)&&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;i0)for(var i=0,r=arguments.length;i1)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(tthis.length&&(t=this.length);for(var r=0,o=this.head;null!==o&&rthis.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{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=nSn,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.xt.y-i&&e.y0&&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{const r=e.measureText(n).width;t.calculative.textLineWidths.push(r),i1?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;n126?(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{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=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{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;e0?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{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;u0&&r0&&r0){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;n0&&e0&&e1&&(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{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&&c0&&h<8&&c{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.exf.ey||p.eymt(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&&ht.x&&e.xt.y&&e.y{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.ext.y&&e.eyt.ex||e.ext.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.worldPoints.forEach(((e,o)=>{o%2==0?(en&&(n=e)):(er&&(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{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=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;in.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(cl&&o>l||r>c&&s>c||re.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.xe.x&&t.ye.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.ye.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.ye.y&&(r=t.x,o=e.y),n.push({x:r,y:o});break;case y.Bottom:r=e.x,o=t.y,t.xe.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.xMath.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){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.unshift(e)})));for(let e=0;e1?(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=ti+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;cn+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;ci+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;cn+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{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;t0?(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=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().height0?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{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 \n \n ';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;ee[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{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{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{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.locked1&&(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;ee===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-10n&&(this.store.pointAt.x=n),this.store.pointAt.y-10r&&(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{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("
")}
`.replace("","").replace(/\\<\/div\>/g,"

");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;e1?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&&(s1?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(/\/g,"\n").replace(/\<\/div\>/g,"").replace(/\/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;el&&(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(/\/g,"\n").replace(/\<\/div\>/g,"").replace(/\/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.xt.ex&&(this.movingAnchor.x=t.ex),this.movingAnchor.yt.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{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.x0?i-=180:i+=180)):t.y>e.y?i=90:t.yo.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{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;h1&&(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.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-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{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{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.lastAnimateRender0&&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;ne.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;te.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{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;et.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;ethis.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{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{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{n[e]=i[e]}));for(let t=1;t0){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[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!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;te.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;te.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{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{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{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({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{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{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{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{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;ne.calculative.worldRect.x+e.colPos[n]*i&&(r.col=n+1);for(let i=0;ie.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.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{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;ie.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.xi.y&&n.yvoid 0!==e.col&&void 0===e.row&&e.width));let o={};r&&r.forEach((e=>{o[e.col]=e.width}));for(let i=0;ivoid 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.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;ne.calculative.worldRect.x+e.colPos[n]*i&&(r.col=n+1);for(let i=0;ie.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{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);ne.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;ce.calculative.worldRect.x+e.optionPos[i]*e.calculative.worldRect.width/e.checkboxWidth&&t.xe.calculative.worldRect.y+e.optionPos[n]*i&&t.y({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;e0&&(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;uh){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=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{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{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;le+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;eo?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).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;i0&&(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})()));