!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Le5le=e():t.Le5le=e()}(self,(()=>(()=>{var t={176:(t,e,i)=>{var n=i(52);t.exports=function(t){if(!n(t))throw TypeError(String(t)+" is not an object");return t}},540:(t,e,i)=>{var n=i(905),r=i(237),o=i(357),s=function(t){return function(e,i,s){var a,c=n(e),l=r(c.length),h=o(s,l);if(t&&i!=i){for(;l>h;)if((a=c[h++])!=a)return!0}else for(;l>h;h++)if((t||h in c)&&c[h]===i)return t||h||0;return!t&&-1}};t.exports={includes:s(!0),indexOf:s(!1)}},79:t=>{var e={}.toString;t.exports=function(t){return e.call(t).slice(8,-1)}},81:(t,e,i)=>{var n=i(816),r=i(826),o=i(933),s=i(787);t.exports=function(t,e){for(var i=r(e),a=s.f,c=o.f,l=0;l{var n=i(400),r=i(787),o=i(358);t.exports=n?function(t,e,i){return r.f(t,e,o(1,i))}:function(t,e,i){return t[e]=i,t}},358:t=>{t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},400:(t,e,i)=>{var n=i(229);t.exports=!n((function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a}))},635:(t,e,i)=>{var n=i(859),r=i(52),o=n.document,s=r(o)&&r(o.createElement);t.exports=function(t){return s?o.createElement(t):{}}},837:t=>{t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},103:(t,e,i)=>{var n=i(859),r=i(933).f,o=i(762),s=i(487),a=i(333),c=i(81),l=i(541);t.exports=function(t,e){var i,h,u,d,f,p=t.target,v=t.global,g=t.stat;if(i=v?n:g?n[p]||a(p,{}):(n[p]||{}).prototype)for(h in e){if(d=e[h],u=t.noTargetGet?(f=r(i,h))&&f.value:i[h],!l(v?h:p+(g?".":"#")+h,t.forced)&&void 0!==u){if(typeof d==typeof u)continue;c(d,u)}(t.sham||u&&u.sham)&&o(d,"sham",!0),s(i,h,d,t)}}},229:t=>{t.exports=function(t){try{return!!t()}catch(t){return!0}}},379:(t,e,i)=>{var n=i(36);t.exports=n("native-function-to-string",Function.toString)},230:(t,e,i)=>{var n=i(276),r=i(859),o=function(t){return"function"==typeof t?t:void 0};t.exports=function(t,e){return arguments.length<2?o(n[t])||o(r[t]):n[t]&&n[t][e]||r[t]&&r[t][e]}},859:(t,e,i)=>{var n=function(t){return t&&t.Math==Math&&t};t.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:t=>{var e={}.hasOwnProperty;t.exports=function(t,i){return e.call(t,i)}},977:t=>{t.exports={}},394:(t,e,i)=>{var n=i(400),r=i(229),o=i(635);t.exports=!n&&!r((function(){return 7!=Object.defineProperty(o("div"),"a",{get:function(){return 7}}).a}))},337:(t,e,i)=>{var n=i(229),r=i(79),o="".split;t.exports=n((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==r(t)?o.call(t,""):Object(t)}:Object},407:(t,e,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,g=p.has,y=p.set;n=function(t,e){return y.call(p,t,e),e},r=function(t){return v.call(p,t)||{}},o=function(t){return g.call(p,t)}}else{var m=u("state");d[m]=!0,n=function(t,e){return l(t,m,e),e},r=function(t){return h(t,m)?t[m]:{}},o=function(t){return h(t,m)}}t.exports={set:n,get:r,has:o,enforce:function(t){return o(t)?r(t):n(t,{})},getterFor:function(t){return function(e){var i;if(!c(e)||(i=r(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return i}}}},541:(t,e,i)=>{var n=i(229),r=/#|\.prototype\./,o=function(t,e){var i=a[s(t)];return i==l||i!=c&&("function"==typeof e?n(e):!!e)},s=o.normalize=function(t){return String(t).replace(r,".").toLowerCase()},a=o.data={},c=o.NATIVE="N",l=o.POLYFILL="P";t.exports=o},52:t=>{t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},231:t=>{t.exports=!1},694:(t,e,i)=>{var n=i(859),r=i(379),o=n.WeakMap;t.exports="function"==typeof o&&/native code/.test(r.call(o))},787:(t,e,i)=>{var n=i(400),r=i(394),o=i(176),s=i(66),a=Object.defineProperty;e.f=n?a:function(t,e,i){if(o(t),e=s(e,!0),o(i),r)try{return a(t,e,i)}catch(t){}if("get"in i||"set"in i)throw TypeError("Accessors not supported");return"value"in i&&(t[e]=i.value),t}},933:(t,e,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;e.f=n?h:function(t,e){if(t=s(t),e=a(e,!0),l)try{return h(t,e)}catch(t){}if(c(t,e))return o(!r.f.call(t,e),t[e])}},151:(t,e,i)=>{var n=i(140),r=i(837).concat("length","prototype");e.f=Object.getOwnPropertyNames||function(t){return n(t,r)}},894:(t,e)=>{e.f=Object.getOwnPropertySymbols},140:(t,e,i)=>{var n=i(816),r=i(905),o=i(540).indexOf,s=i(977);t.exports=function(t,e){var i,a=r(t),c=0,l=[];for(i in a)!n(s,i)&&n(a,i)&&l.push(i);for(;e.length>c;)n(a,i=e[c++])&&(~o(l,i)||l.push(i));return l}},195:(t,e)=>{"use strict";var i={}.propertyIsEnumerable,n=Object.getOwnPropertyDescriptor,r=n&&!i.call({1:2},1);e.f=r?function(t){var e=n(this,t);return!!e&&e.enumerable}:i},826:(t,e,i)=>{var n=i(230),r=i(151),o=i(894),s=i(176);t.exports=n("Reflect","ownKeys")||function(t){var e=r.f(s(t)),i=o.f;return i?e.concat(i(t)):e}},276:(t,e,i)=>{t.exports=i(859)},487:(t,e,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(t){return c.call(t)})),(t.exports=function(t,e,i,r){var c=!!r&&!!r.unsafe,l=!!r&&!!r.enumerable,h=!!r&&!!r.noTargetGet;"function"==typeof i&&("string"!=typeof e||s(i,"name")||o(i,"name",e),u(i).source=d.join("string"==typeof e?e:"")),t!==n?(c?!h&&t[e]&&(l=!0):delete t[e],l?t[e]=i:o(t,e,i)):l?t[e]=i:a(e,i)})(Function.prototype,"toString",(function(){return"function"==typeof this&&h(this).source||c.call(this)}))},885:t=>{t.exports=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t}},333:(t,e,i)=>{var n=i(859),r=i(762);t.exports=function(t,e){try{r(n,t,e)}catch(i){n[t]=e}return e}},399:(t,e,i)=>{var n=i(36),r=i(441),o=n("keys");t.exports=function(t){return o[t]||(o[t]=r(t))}},353:(t,e,i)=>{var n=i(859),r=i(333),o="__core-js_shared__",s=n[o]||r(o,{});t.exports=s},36:(t,e,i)=>{var n=i(231),r=i(353);(t.exports=function(t,e){return r[t]||(r[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.3.5",mode:n?"pure":"global",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})},357:(t,e,i)=>{var n=i(51),r=Math.max,o=Math.min;t.exports=function(t,e){var i=n(t);return i<0?r(i+e,0):o(i,e)}},905:(t,e,i)=>{var n=i(337),r=i(885);t.exports=function(t){return n(r(t))}},51:t=>{var e=Math.ceil,i=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?i:e)(t)}},237:(t,e,i)=>{var n=i(51),r=Math.min;t.exports=function(t){return t>0?r(n(t),9007199254740991):0}},66:(t,e,i)=>{var n=i(52);t.exports=function(t,e){if(!n(t))return t;var i,r;if(e&&"function"==typeof(i=t.toString)&&!n(r=i.call(t)))return r;if("function"==typeof(i=t.valueOf)&&!n(r=i.call(t)))return r;if(!e&&"function"==typeof(i=t.toString)&&!n(r=i.call(t)))return r;throw TypeError("Can't convert object to primitive value")}},441:t=>{var e=0,i=Math.random();t.exports=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++e+i).toString(36)}},173:(t,e,i)=>{i(103)({global:!0},{globalThis:i(859)})},421:(t,e,i)=>{t.exports=function t(e,i,n){function r(s,a){if(!i[s]){if(!e[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:{}};e[s][0].call(l.exports,(function(t){return r(e[s][1][t]||t)}),l,l.exports,t,e,i,n)}return i[s].exports}for(var o=void 0,s=0;s0&&(e.topicAliasMaximum>65535?g("MqttClient :: options.topicAliasMaximum is out of range"):this.topicAliasRecv=new s(e.topicAliasMaximum)),this.on("connect",(function(){const t=this.queue;g("connect :: sending queued packets"),function e(){const i=t.shift();g("deliver :: entry %o",i);let r=null;if(!i)return void n._resubscribe();r=i.packet,g("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(t){i.cb&&i.cb(t),e()})):(g("messageId: %d has already used. The message is skipped and removed.",r.messageId),e())}()})),this.on("close",(function(){g("close :: connected set to `false`"),this.connected=!1,g("close :: clearing connackTimer"),clearTimeout(this.connackTimer),g("close :: clearing ping timer"),null!==n.pingTimer&&(n.pingTimer.clear(),n.pingTimer=null),this.topicAliasRecv&&this.topicAliasRecv.clear(),g("close :: calling _setupReconnect"),this._setupReconnect()})),r.call(this),g("MqttClient :: setting up stream"),this._setupStream()}u(P,r),P.prototype._setupStream=function(){const t=this,e=new h,i=c.parser(this.options);let n=null;const r=[];function o(){if(r.length)y(s);else{const t=n;n=null,t()}}function s(){g("work :: getting next packet in queue");const e=r.shift();if(e)g("work :: packet pulled from queue"),t._handlePacket(e,o);else{g("work :: no packets in queue");const t=n;n=null,g("work :: done flag is %s",!!t),t&&t()}}g("_setupStream :: calling method to clear reconnect"),this._clearReconnect(),g("_setupStream :: using streamBuilder provided to client to create stream"),this.stream=this.streamBuilder(this),i.on("packet",(function(t){g("parser :: on packet push to packets array."),r.push(t)})),e._write=function(t,e,r){n=r,g("writable stream :: parsing buffer"),i.parse(t),s()},g("_setupStream :: pipe stream to writable stream"),this.stream.pipe(e),this.stream.on("error",(function(e){g("streamErrorHandler :: error",e.message),b.includes(e.code)?(g("streamErrorHandler :: emitting error"),t.emit("error",e)):S(e)})),this.stream.on("close",(function(){var e;g("(%s)stream :: on close",t.options.clientId),(e=t.outgoing)&&(g("flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"),Object.keys(e).forEach((function(t){e[t].volatile&&"function"==typeof e[t].cb&&(e[t].cb(new Error("Connection closed")),delete e[t])}))),g("stream: emit close to MqttClient"),t.emit("close")})),g("_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)),T(this,a),i.on("error",this.emit.bind(this,"error")),this.options.properties){if(!this.options.properties.authenticationMethod&&this.options.properties.authenticationData)return t.end((()=>this.emit("error",new Error("Packet has no Authentication Method")))),this;this.options.properties.authenticationMethod&&this.options.authPacket&&"object"==typeof this.options.authPacket&&T(this,v({cmd:"auth",reasonCode:0},this.options.authPacket))}this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout((function(){g("!!connectTimeout hit!! Calling _cleanUp with force `true`"),t._cleanUp(!0)}),this.options.connectTimeout)},P.prototype._handlePacket=function(t,e){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},P.prototype.subscribe=function(){const t=this,e=new Array(arguments.length);for(let t=0;t0){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),t._resubscribeTopics[i.topic]=n,e.push(i.topic)}})),t.messageIdToTopic[n.messageId]=e}return t.outgoing[n.messageId]={volatile:!0,cb:function(t,e){if(!t){const t=e.granted;for(let e=0;e0||!h())&&this._storeProcessingQueue.push({invoke:h,callback:o}),this},P.prototype.unsubscribe=function(){const t=this,e=new Array(arguments.length);for(let t=0;t0||!s())&&this._storeProcessingQueue.push({invoke:s,callback:n}),this},P.prototype.end=function(t,e,i){const n=this;function r(){g("end :: (%s) :: finish :: calling _cleanUp with force %s",n.options.clientId,t),n._cleanUp(t,(()=>{g("end :: finish :: calling process.nextTick on closeStores"),y(function(){g("end :: closeStores: closing incoming and outgoing stores"),n.disconnected=!0,n.incomingStore.close((function(t){n.outgoingStore.close((function(e){if(g("end :: closeStores: emitting end"),n.emit("end"),i){const n=t||e;g("end :: closeStores: invoking callback with args"),i(n)}}))})),n._deferredReconnect&&n._deferredReconnect()}.bind(n))}),e)}return g("end :: (%s)",this.options.clientId),null!=t&&"boolean"==typeof t||(i=e||S,e=t,t=!1,"object"!=typeof e&&(i=e,e=null,"function"!=typeof i&&(i=S))),"object"!=typeof e&&(i=e,e=null),g("end :: cb? %s",!!i),i=i||S,this.disconnecting?(i(),this):(this._clearReconnect(),this.disconnecting=!0,!t&&Object.keys(this.outgoing).length>0?(g("end :: (%s) :: calling finish in 10ms once outgoing is empty",n.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,r,10))):(g("end :: (%s) :: immediately calling finish",n.options.clientId),r()),this)},P.prototype.removeOutgoingMessage=function(t){const e=this.outgoing[t]?this.outgoing[t].cb:null;return delete this.outgoing[t],this.outgoingStore.del({messageId:t},(function(){e(new Error("Message removed"))})),this},P.prototype.reconnect=function(t){g("client reconnect");const e=this,i=function(){t?(e.options.incomingStore=t.incomingStore,e.options.outgoingStore=t.outgoingStore):(e.options.incomingStore=null,e.options.outgoingStore=null),e.incomingStore=e.options.incomingStore||new o,e.outgoingStore=e.options.outgoingStore||new o,e.disconnecting=!1,e.disconnected=!1,e._deferredReconnect=null,e._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=i:i(),this},P.prototype._reconnect=function(){g("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end((()=>{this._setupStream()})),g("client already connected. disconnecting first.")):(g("_reconnect: calling _setupStream"),this._setupStream())},P.prototype._setupReconnect=function(){const t=this;!t.disconnecting&&!t.reconnectTimer&&t.options.reconnectPeriod>0?(this.reconnecting||(g("_setupReconnect :: emit `offline` state"),this.emit("offline"),g("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),g("_setupReconnect :: setting reconnectTimer for %d ms",t.options.reconnectPeriod),t.reconnectTimer=setInterval((function(){g("reconnectTimer :: reconnect triggered!"),t._reconnect()}),t.options.reconnectPeriod)):g("_setupReconnect :: doing nothing...")},P.prototype._clearReconnect=function(){g("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},P.prototype._cleanUp=function(t,e){const i=arguments[2];if(e&&(g("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",e)),g("_cleanUp :: forced? %s",t),t)0===this.options.reconnectPeriod&&this.options.clean&&(n=this.outgoing)&&(g("flush: queue exists? %b",!!n),Object.keys(n).forEach((function(t){"function"==typeof n[t].cb&&(n[t].cb(new Error("Connection closed")),delete n[t])}))),g("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{const t=v({cmd:"disconnect"},i);g("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(t,m.bind(null,this.stream.end.bind(this.stream)))}var n;this.disconnecting||(g("_cleanUp :: client not disconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),null!==this.pingTimer&&(g("_cleanUp :: clearing pingTimer"),this.pingTimer.clear(),this.pingTimer=null),e&&!this.connected&&(g("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",e),e())},P.prototype._sendPacket=function(t,e,i){g("_sendPacket :: (%s) :: start",this.options.clientId),i=i||S,e=e||S;const n=function(t,e){if(5===t.options.protocolVersion&&"publish"===e.cmd){let i;e.properties&&(i=e.properties.topicAlias);const n=e.topic.toString();if(t.topicAliasSend)if(i){if(0!==n.length&&(g("applyTopicAlias :: register topic: %s - alias: %d",n,i),!t.topicAliasSend.put(n,i)))return g("applyTopicAlias :: error out of range. topic: %s - alias: %d",n,i),new Error("Sending Topic Alias out of range")}else 0!==n.length&&(t.options.autoAssignTopicAlias?(i=t.topicAliasSend.getAliasByTopic(n))?(e.topic="",e.properties={...e.properties,topicAlias:i},g("applyTopicAlias :: auto assign(use) topic: %s - alias: %d",n,i)):(i=t.topicAliasSend.getLruAlias(),t.topicAliasSend.put(n,i),e.properties={...e.properties,topicAlias:i},g("applyTopicAlias :: auto assign topic: %s - alias: %d",n,i)):t.options.autoUseTopicAlias&&(i=t.topicAliasSend.getAliasByTopic(n))&&(e.topic="",e.properties={...e.properties,topicAlias:i},g("applyTopicAlias :: auto use topic: %s - alias: %d",n,i)));else if(i)return g("applyTopicAlias :: error out of range. topic: %s - alias: %d",n,i),new Error("Sending Topic Alias out of range")}}(this,t);if(n)e(n);else{if(!this.connected)return"auth"===t.cmd?(this._shiftPingInterval(),void T(this,t,e)):(g("_sendPacket :: client not connected. Storing packet offline."),void this._storePacket(t,e,i));switch(this._shiftPingInterval(),t.cmd){case"publish":break;case"pubrel":return void A(this,t,e,i);default:return void T(this,t,e)}switch(t.qos){case 2:case 1:A(this,t,e,i);break;default:T(this,t,e)}g("_sendPacket :: (%s) :: end",this.options.clientId)}},P.prototype._storePacket=function(t,e,i){g("_storePacket :: packet: %o",t),g("_storePacket :: cb? %s",!!e),i=i||S;let n=t;if("publish"===n.cmd){const i=k(this,n=f(t));if(i)return e&&e(i)}0===(n.qos||0)&&this.queueQoSZero||"publish"!==n.cmd?this.queue.push({packet:n,cb:e}):n.qos>0?(e=this.outgoing[n.messageId]?this.outgoing[n.messageId].cb:null,this.outgoingStore.put(n,(function(t){if(t)return e&&e(t);i()}))):e&&e(new Error("No connection to broker"))},P.prototype._setupPingTimer=function(){g("_setupPingTimer :: keepalive %d (seconds)",this.options.keepalive);const t=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=d((function(){t._checkPing()}),1e3*this.options.keepalive))},P.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},P.prototype._checkPing=function(){g("_checkPing :: checking ping..."),this.pingResp?(g("_checkPing :: ping response received. Clearing flag and sending `pingreq`"),this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):(g("_checkPing :: calling _cleanUp with force true"),this._cleanUp(!0))},P.prototype._handlePingresp=function(){this.pingResp=!0},P.prototype._handleConnack=function(t){g("_handleConnack");const e=this.options,i=5===e.protocolVersion?t.reasonCode:t.returnCode;if(clearTimeout(this.connackTimer),delete this.topicAliasSend,t.properties){if(t.properties.topicAliasMaximum){if(t.properties.topicAliasMaximum>65535)return void this.emit("error",new Error("topicAliasMaximum from broker is out of range"));t.properties.topicAliasMaximum>0&&(this.topicAliasSend=new a(t.properties.topicAliasMaximum))}t.properties.serverKeepAlive&&e.keepalive&&(e.keepalive=t.properties.serverKeepAlive,this._shiftPingInterval()),t.properties.maximumPacketSize&&(e.properties||(e.properties={}),e.properties.maximumPacketSize=t.properties.maximumPacketSize)}if(0===i)this.reconnecting=!1,this._onConnect(t);else if(i>0){const t=new Error("Connection refused: "+x[i]);t.code=i,this.emit("error",t)}},P.prototype._handleAuth=function(t){const e=this.options.protocolVersion,i=5===e?t.reasonCode:t.returnCode;if(5!==e){const t=new Error("Protocol error: Auth packets are only supported in MQTT 5. Your version:"+e);return t.code=i,void this.emit("error",t)}const n=this;this.handleAuth(t,(function(t,e){if(t)n.emit("error",t);else if(24===i)n.reconnecting=!1,n._sendPacket(e);else{const e=new Error("Connection refused: "+x[i]);t.code=i,n.emit("error",e)}}))},P.prototype.handleAuth=function(t,e){e()},P.prototype._handlePublish=function(t,e){g("_handlePublish: packet %o",t),e=void 0!==e?e:S;let i=t.topic.toString();const n=t.payload,r=t.qos,o=t.messageId,s=this,a=this.options,c=[0,16,128,131,135,144,145,151,153];if(5===this.options.protocolVersion){let e;if(t.properties&&(e=t.properties.topicAlias),void 0!==e)if(0===i.length){if(!(e>0&&e<=65535))return g("_handlePublish :: topic alias out of range. alias: %d",e),void this.emit("error",new Error("Received Topic Alias is out of range"));{const t=this.topicAliasRecv.getTopicByAlias(e);if(!t)return g("_handlePublish :: unregistered topic alias. alias: %d",e),void this.emit("error",new Error("Received unregistered Topic Alias"));g("_handlePublish :: topic complemented by alias. topic: %s - alias: %d",i=t,e)}}else{if(!this.topicAliasRecv.put(i,e))return g("_handlePublish :: topic alias out of range. alias: %d",e),void this.emit("error",new Error("Received Topic Alias is out of range"));g("_handlePublish :: registered topic: %s - alias: %d",i,e)}}switch(g("_handlePublish: qos %d",r),r){case 2:a.customHandleAcks(i,n,t,(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},e):s.incomingStore.put(t,(function(){s._sendPacket({cmd:"pubrec",messageId:o},e)})))}));break;case 1:a.customHandleAcks(i,n,t,(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,t),void s.handleMessage(t,(function(t){if(t)return e&&e(t);s._sendPacket({cmd:"puback",messageId:o,reasonCode:a},e)})))}));break;case 0:this.emit("message",i,n,t),this.handleMessage(t,e);break;default:g("_handlePublish: unknown QoS. Doing nothing.")}},P.prototype.handleMessage=function(t,e){e()},P.prototype._handleAck=function(t){const e=t.messageId,i=t.cmd;let n=null;const r=this.outgoing[e]?this.outgoing[e].cb:null,o=this;let s;if(r){switch(g("_handleAck :: packet type",i),i){case"pubcomp":case"puback":{const i=t.reasonCode;i&&i>0&&16!==i&&((s=new Error("Publish error: "+x[i])).code=i,r(s,t)),delete this.outgoing[e],this.outgoingStore.del(t,r),this.messageIdProvider.deallocate(e),this._invokeStoreProcessingQueue();break}case"pubrec":{n={cmd:"pubrel",qos:2,messageId:e};const i=t.reasonCode;i&&i>0&&16!==i?((s=new Error("Publish error: "+x[i])).code=i,r(s,t)):this._sendPacket(n);break}case"suback":delete this.outgoing[e],this.messageIdProvider.deallocate(e);for(let i=0;i0)if(this.options.resubscribe)if(5===this.options.protocolVersion){g("_resubscribe: protocolVersion 5");for(let e=0;e0){const t=this._storeProcessingQueue[0];if(t&&t.invoke())return this._storeProcessingQueue.shift(),!0}return!1},P.prototype._invokeAllStoreProcessingQueue=function(){for(;this._invokeStoreProcessingQueue(););},P.prototype._flushStoreProcessingQueue=function(){for(const t of this._storeProcessingQueue)t.cbStorePut&&t.cbStorePut(new Error("Connection closed")),t.callback&&t.callback(new Error("Connection closed"));this._storeProcessingQueue.splice(0)},e.exports=P}).call(this)}).call(this,t("_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(t,e,i){"use strict";const{Buffer:n}=t("buffer"),r=t("readable-stream").Transform,o=t("duplexify");let s,a,c,l=!1;e.exports=function(t,e){if(e.hostname=e.hostname||e.host,!e.hostname)throw new Error("Could not determine host. Specify host manually.");const i="MQIsdp"===e.protocolId&&3===e.protocolVersion?"mqttv3.1":"mqtt";!function(t){t.hostname||(t.hostname="localhost"),t.path||(t.path="/"),t.wsOptions||(t.wsOptions={})}(e);const h=function(t,e){const i="alis"===t.protocol?"wss":"ws";let n=i+"://"+t.hostname+t.path;return t.port&&80!==t.port&&443!==t.port&&(n=i+"://"+t.hostname+":"+t.port+t.path),"function"==typeof t.transformWsUrl&&(n=t.transformWsUrl(n,t,e)),n}(e,t);return(s=e.my).connectSocket({url:h,protocols:i}),a=function(){const t=new r;return t._write=function(t,e,i){s.sendSocketMessage({data:t.buffer,success:function(){i()},fail:function(){i(new Error)}})},t._flush=function(t){s.closeSocket({success:function(){t()}})},t}(),c=o.obj(),l||(l=!0,s.onSocketOpen((function(){c.setReadable(a),c.setWritable(a),c.emit("connect")})),s.onSocketMessage((function(t){if("string"==typeof t.data){const e=n.from(t.data,"base64");a.push(e)}else{const e=new FileReader;e.addEventListener("load",(function(){let t=e.result;t=t instanceof ArrayBuffer?n.from(t):n.from(t,"utf8"),a.push(t)})),e.readAsArrayBuffer(t.data)}})),s.onSocketClose((function(){c.end(),c.destroy()})),s.onSocketError((function(t){c.destroy(t)}))),c}},{buffer:17,duplexify:20,"readable-stream":69}],3:[function(t,e,i){"use strict";const n=t("net"),r=t("debug")("mqttjs:tcp");e.exports=function(t,e){e.port=e.port||1883,e.hostname=e.hostname||e.host||"localhost";const i=e.port,o=e.hostname;return r("port %d and host %s",i,o),n.createConnection(i,o)}},{debug:18,net:16}],4:[function(t,e,i){"use strict";const n=t("tls"),r=t("net"),o=t("debug")("mqttjs:tls");e.exports=function(t,e){e.port=e.port||8883,e.host=e.hostname||e.host||"localhost",0===r.isIP(e.host)&&(e.servername=e.host),e.rejectUnauthorized=!1!==e.rejectUnauthorized,delete e.path,o("port %d host %s rejectUnauthorized %b",e.port,e.host,e.rejectUnauthorized);const i=n.connect(e);function s(n){e.rejectUnauthorized&&t.emit("error",n),i.end()}return i.on("secureConnect",(function(){e.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(t,e,n){(function(n){(function(){"use strict";const{Buffer:r}=t("buffer"),o=t("ws"),s=t("debug")("mqttjs:ws"),a=t("duplexify"),c=t("readable-stream").Transform,l=["rejectUnauthorized","ca","cert","key","pfx","passphrase"],h=void 0!==n&&"browser"===n.title||"function"==typeof i;function u(t,e){let i=t.protocol+"://"+t.hostname+":"+t.port+t.path;return"function"==typeof t.transformWsUrl&&(i=t.transformWsUrl(i,t,e)),i}function d(t){const e=t;return t.hostname||(e.hostname="localhost"),t.port||("wss"===t.protocol?e.port=443:e.port=80),t.path||(e.path="/"),t.wsOptions||(e.wsOptions={}),h||"wss"!==t.protocol||l.forEach((function(i){Object.prototype.hasOwnProperty.call(t,i)&&!Object.prototype.hasOwnProperty.call(t.wsOptions,i)&&(e.wsOptions[i]=t[i])})),e}e.exports=h?function(t,e){let i;s("browserStreamBuilder");const n=function(t){const e=d(t);if(e.hostname||(e.hostname=e.host),!e.hostname){if("undefined"==typeof document)throw new Error("Could not determine host. Specify host manually.");const t=new URL(document.URL);e.hostname=t.hostname,e.port||(e.port=t.port)}return void 0===e.objectMode&&(e.objectMode=!(!0===e.binary||void 0===e.binary)),e}(e).browserBufferSize||524288,o=e.browserBufferTimeout||1e3,l=!e.objectMode,h=function(t,e){const i="MQIsdp"===e.protocolId&&3===e.protocolVersion?"mqttv3.1":"mqtt",n=u(e,t),r=new WebSocket(n,[i]);return r.binaryType="arraybuffer",r}(t,e),f=function(t,e,i){const n=new c({objectModeMode:t.objectMode});return n._write=e,n._flush=function(t){h.close(),t()},n}(e,(function t(e,i,s){h.bufferedAmount>n&&setTimeout(t,o,e,i,s),l&&"string"==typeof e&&(e=r.from(e,"utf8"));try{h.send(e)}catch(t){return s(t)}s()}));e.objectMode||(f._writev=w),f.on("close",(()=>{h.close()}));const p=void 0!==h.addEventListener;function v(){i.setReadable(f),i.setWritable(f),i.emit("connect")}function g(){i.end(),i.destroy()}function y(t){i.destroy(t)}function m(t){let e=t.data;e=e instanceof ArrayBuffer?r.from(e):r.from(e,"utf8"),f.push(e)}function w(t,e){const i=new Array(t.length);for(let e=0;e{a.destroy()})),a}}).call(this)}).call(this,t("_process"))},{_process:50,buffer:17,debug:18,duplexify:20,"readable-stream":69,ws:80}],6:[function(t,e,i){"use strict";const{Buffer:n}=t("buffer"),r=t("readable-stream").Transform,o=t("duplexify");let s,a,c;e.exports=function(t,e){if(e.hostname=e.hostname||e.host,!e.hostname)throw new Error("Could not determine host. Specify host manually.");const i="MQIsdp"===e.protocolId&&3===e.protocolVersion?"mqttv3.1":"mqtt";!function(t){t.hostname||(t.hostname="localhost"),t.path||(t.path="/"),t.wsOptions||(t.wsOptions={})}(e);const l=function(t,e){const i="wxs"===t.protocol?"wss":"ws";let n=i+"://"+t.hostname+t.path;return t.port&&80!==t.port&&443!==t.port&&(n=i+"://"+t.hostname+":"+t.port+t.path),"function"==typeof t.transformWsUrl&&(n=t.transformWsUrl(n,t,e)),n}(e,t);s=wx.connectSocket({url:l,protocols:[i]}),a=function(){const t=new r;return t._write=function(t,e,i){s.send({data:t.buffer,success:function(){i()},fail:function(t){i(new Error(t))}})},t._flush=function(t){s.close({success:function(){t()}})},t}(),(c=o.obj())._destroy=function(t,e){s.close({success:function(){e&&e(t)}})};const h=c.destroy;return c.destroy=function(){c.destroy=h;const t=this;setTimeout((function(){s.close({fail:function(){t._destroy(new Error)}})}),0)}.bind(c),s.onOpen((function(){c.setReadable(a),c.setWritable(a),c.emit("connect")})),s.onMessage((function(t){let e=t.data;e=e instanceof ArrayBuffer?n.from(e):n.from(e,"utf8"),a.push(e)})),s.onClose((function(){c.end(),c.destroy()})),s.onError((function(t){c.destroy(new Error(t.errMsg))})),c}},{buffer:17,duplexify:20,"readable-stream":69}],7:[function(t,e,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 t=this.nextId++;return 65536===this.nextId&&(this.nextId=1),t},n.prototype.getLastAllocated=function(){return 1===this.nextId?65535:this.nextId-1},n.prototype.register=function(t){return!0},n.prototype.deallocate=function(t){},n.prototype.clear=function(){},e.exports=n},{}],8:[function(t,e,i){"use strict";const n=t("xtend"),r=t("readable-stream").Readable,o={objectMode:!0},s={clean:!0};function a(t){if(!(this instanceof a))return new a(t);this.options=t||{},this.options=n(s,t),this._inflights=new Map}a.prototype.put=function(t,e){return this._inflights.set(t.messageId,t),e&&e(),this},a.prototype.createStream=function(){const t=new r(o),e=[];let i=!1,n=0;return this._inflights.forEach((function(t,i){e.push(t)})),t._read=function(){!i&&nthis.max||(this.aliasToTopic[e]=t,this.length=Object.keys(this.aliasToTopic).length,0))},n.prototype.getTopicByAlias=function(t){return this.aliasToTopic[t]},n.prototype.clear=function(){this.aliasToTopic={}},e.exports=n},{}],10:[function(t,e,i){"use strict";const n=t("lru-cache"),r=t("number-allocator").NumberAllocator;function o(t){if(!(this instanceof o))return new o(t);t>0&&(this.aliasToTopic=new n({max:t}),this.topicToAlias={},this.numberAllocator=new r(1,t),this.max=t,this.length=0)}o.prototype.put=function(t,e){if(0===e||e>this.max)return!1;const i=this.aliasToTopic.get(e);return i&&delete this.topicToAlias[i],this.aliasToTopic.set(e,t),this.topicToAlias[t]=e,this.numberAllocator.use(e),this.length=this.aliasToTopic.length,!0},o.prototype.getTopicByAlias=function(t){return this.aliasToTopic.get(t)},o.prototype.getAliasByTopic=function(t){const e=this.topicToAlias[t];return void 0!==e&&this.aliasToTopic.get(e),e},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]},e.exports=o},{"lru-cache":37,"number-allocator":46}],11:[function(t,e,i){"use strict";function n(t){const e=t.split("/");for(let t=0;t0?s-4:s;for(i=0;i>16&255,c[h++]=e>>8&255,c[h++]=255&e;return 2===a&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,c[h++]=255&e),1===a&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,c[h++]=e>>8&255,c[h++]=255&e),c},i.fromByteArray=function(t){for(var e,i=t.length,r=i%3,o=[],s=0,a=i-r;sa?a:s+16383));return 1===r?(e=t[i-1],o.push(n[e>>2]+n[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],o.push(n[e>>10]+n[e>>4&63]+n[e<<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=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function h(t,e,i){for(var r,o,s=[],a=e;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(t,e,i){"use strict";const{Buffer:n}=t("buffer"),r=Symbol.for("BufferList");function o(t){if(!(this instanceof o))return new o(t);o._init.call(this,t)}o._init=function(t){Object.defineProperty(this,r,{value:!0}),this._bufs=[],this.length=0,t&&this.append(t)},o.prototype._new=function(t){return new o(t)},o.prototype._offset=function(t){if(0===t)return[0,0];let e=0;for(let i=0;ithis.length||t<0)return;const e=this._offset(t);return this._bufs[e[0]][e[1]]},o.prototype.slice=function(t,e){return"number"==typeof t&&t<0&&(t+=this.length),"number"==typeof e&&e<0&&(e+=this.length),this.copy(null,0,t,e)},o.prototype.copy=function(t,e,i,r){if(("number"!=typeof i||i<0)&&(i=0),("number"!=typeof r||r>this.length)&&(r=this.length),i>=this.length)return t||n.alloc(0);if(r<=0)return t||n.alloc(0);const o=!!t,s=this._offset(i),a=r-i;let c=a,l=o&&e||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 e=0;ei)){this._bufs[e].copy(t,l,h,h+c),l+=i;break}this._bufs[e].copy(t,l,h),l+=i,c-=i,h&&(h=0)}return t.length>l?t.slice(0,l):t},o.prototype.shallowSlice=function(t,e){if(t=t||0,e="number"!=typeof e?this.length:e,t<0&&(t+=this.length),e<0&&(e+=this.length),t===e)return this._new();const i=this._offset(t),n=this._offset(e),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(t,e,i){return this.slice(e,i).toString(t)},o.prototype.consume=function(t){if(t=Math.trunc(t),Number.isNaN(t)||t<=0)return this;for(;this._bufs.length;){if(!(t>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(t),this.length-=t;break}t-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},o.prototype.duplicate=function(){const t=this._new();for(let e=0;ethis.length?this.length:e;const r=this._offset(e);let o=r[0],s=r[1];for(;o=t.length){const i=e.indexOf(t,s);if(-1!==i)return this._reverseOffset([o,i]);s=e.length-t.length+1}else{const e=this._reverseOffset([o,s]);if(this._match(e,t))return e;s++}s=0}return-1},o.prototype._match=function(t,e){if(this.length-tr)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return e.__proto__=s.prototype,e}function s(t,e,i){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return l(t)}return a(t,e,i)}function a(t,e,i){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var i=0|d(t,e),n=o(i),r=n.write(t,e);return r!==i&&(n=n.slice(0,r)),n}(t,e);if(ArrayBuffer.isView(t))return h(t);if(null==t)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(F(t,ArrayBuffer)||t&&F(t.buffer,ArrayBuffer))return function(t,e,i){if(e<0||t.byteLength=r)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r.toString(16)+" bytes");return 0|t}function d(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||F(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var i=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===i)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":return N(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return O(t).length;default:if(r)return n?-1:N(t).length;e=(""+e).toLowerCase(),r=!0}}function f(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function p(t,e,i,n,r){if(0===t.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:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:v(t,e,i,n,r);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):v(t,[e],i,n,r);throw new TypeError("val must be string, number or Buffer")}function v(t,e,i,n,r){var o,s=1,a=t.length,c=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,c/=2,i/=2}function l(t,e){return 1===s?t[e]:t.readUInt16BE(e*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=e.length;n>o/2&&(n=o/2);for(var s=0;s>8,r=i%256,o.push(r),o.push(n);return o}(e,t.length-i),t,i,n)}function k(t,i,n){return 0===i&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(i,n))}function T(t,e,i){i=Math.min(t.length,i);for(var n=[],r=e;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=t[r+1]))&&(c=(31&l)<<6|63&o)>127&&(h=c);break;case 3:o=t[r+1],s=t[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=t[r+1],s=t[r+2],a=t[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(t){var e=t.length;if(e<=A)return String.fromCharCode.apply(String,t);for(var i="",n=0;nthis.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return C(this,e,i);case"utf8":case"utf-8":return T(this,e,i);case"ascii":return S(this,e,i);case"latin1":case"binary":return P(this,e,i);case"base64":return k(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){var t="",e=i.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),""},s.prototype.compare=function(t,e,i,n,r){if(F(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===n&&(n=0),void 0===r&&(r=this.length),e<0||i>t.length||n<0||r>this.length)throw new RangeError("out of range index");if(n>=r&&e>=i)return 0;if(n>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var o=(r>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),c=Math.min(o,a),l=this.slice(n,r),h=t.slice(e,i),u=0;u>>=0,isFinite(i)?(i>>>=0,void 0===n&&(n="utf8")):(n=i,i=void 0)}var r=this.length-e;if((void 0===i||i>r)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return g(this,t,e,i);case"utf8":case"utf-8":return y(this,t,e,i);case"ascii":return m(this,t,e,i);case"latin1":case"binary":return w(this,t,e,i);case"base64":return b(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,t,e,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 A=4096;function S(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;rn)&&(i=n);for(var r="",o=e;oi)throw new RangeError("Trying to access beyond buffer length")}function E(t,e,i,n,r,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||et.length)throw new RangeError("Index out of range")}function I(t,e,i,n,r,o){if(i+n>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function L(t,e,i,r,o){return e=+e,i>>>=0,o||I(t,0,i,4),n.write(t,e,i,r,23,4),i+4}function M(t,e,i,r,o){return e=+e,i>>>=0,o||I(t,0,i,8),n.write(t,e,i,r,52,8),i+8}s.prototype.slice=function(t,e){var i=this.length;(t=~~t)<0?(t+=i)<0&&(t=0):t>i&&(t=i),(e=void 0===e?i:~~e)<0?(e+=i)<0&&(e=0):e>i&&(e=i),e>>=0,e>>>=0,i||_(t,e,this.length);for(var n=this[t],r=1,o=0;++o>>=0,e>>>=0,i||_(t,e,this.length);for(var n=this[t+--e],r=1;e>0&&(r*=256);)n+=this[t+--e]*r;return n},s.prototype.readUInt8=function(t,e){return t>>>=0,e||_(t,1,this.length),this[t]},s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||_(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||_(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||_(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUInt32BE=function(t,e){return t>>>=0,e||_(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,i){t>>>=0,e>>>=0,i||_(t,e,this.length);for(var n=this[t],r=1,o=0;++o=(r*=128)&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,i){t>>>=0,e>>>=0,i||_(t,e,this.length);for(var n=e,r=1,o=this[t+--n];n>0&&(r*=256);)o+=this[t+--n]*r;return o>=(r*=128)&&(o-=Math.pow(2,8*e)),o},s.prototype.readInt8=function(t,e){return t>>>=0,e||_(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||_(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},s.prototype.readInt16BE=function(t,e){t>>>=0,e||_(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},s.prototype.readInt32LE=function(t,e){return t>>>=0,e||_(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return t>>>=0,e||_(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return t>>>=0,e||_(t,4,this.length),n.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||_(t,4,this.length),n.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||_(t,8,this.length),n.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||_(t,8,this.length),n.read(this,t,!1,52,8)},s.prototype.writeUIntLE=function(t,e,i,n){t=+t,e>>>=0,i>>>=0,n||E(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,o=0;for(this[e]=255&t;++o>>=0,i>>>=0,n||E(this,t,e,i,Math.pow(2,8*i)-1,0);var r=i-1,o=1;for(this[e+r]=255&t;--r>=0&&(o*=256);)this[e+r]=t/o&255;return e+i},s.prototype.writeUInt8=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,1,255,0),this[e]=255&t,e+1},s.prototype.writeUInt16LE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeUInt16BE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeUInt32LE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},s.prototype.writeUInt32BE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeIntLE=function(t,e,i,n){if(t=+t,e>>>=0,!n){var r=Math.pow(2,8*i-1);E(this,t,e,i,r-1,-r)}var o=0,s=1,a=0;for(this[e]=255&t;++o>0)-a&255;return e+i},s.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e>>>=0,!n){var r=Math.pow(2,8*i-1);E(this,t,e,i,r-1,-r)}var o=i-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+i},s.prototype.writeInt8=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeInt16BE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeInt32LE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},s.prototype.writeInt32BE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeFloatLE=function(t,e,i){return L(this,t,e,!0,i)},s.prototype.writeFloatBE=function(t,e,i){return L(this,t,e,!1,i)},s.prototype.writeDoubleLE=function(t,e,i){return M(this,t,e,!0,i)},s.prototype.writeDoubleBE=function(t,e,i){return M(this,t,e,!1,i)},s.prototype.copy=function(t,e,i,n){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=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),t.length-e=0;--o)t[o+e]=this[o+i];else Uint8Array.prototype.set.call(t,this.subarray(i,n),e);return r},s.prototype.fill=function(t,e,i,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=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===t.length){var r=t.charCodeAt(0);("utf8"===n&&r<128||"latin1"===n)&&(t=r)}}else"number"==typeof t&&(t&=255);if(e<0||this.length>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(o=e;o55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&o.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&o.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&o.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;o.push(i)}else if(i<2048){if((e-=2)<0)break;o.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=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((e-=4)<0)break;o.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return o}function O(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(D,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function z(t,e,i,n){for(var r=0;r=e.length||r>=t.length);++r)e[r+i]=t[r];return r}function F(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function j(t){return t!=t}}).call(this)}).call(this,t("buffer").Buffer)},{"base64-js":13,buffer:17,ieee754:23}],18:[function(t,e,i){(function(n){(function(){i.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const i="color: "+this.color;t.splice(1,0,i,"color: inherit");let n=0,r=0;t[0].replace(/%[a-zA-Z%]/g,(t=>{"%%"!==t&&"%c"===t&&(r=++n)})),t.splice(r,0,i)},i.save=function(t){try{t?i.storage.setItem("debug",t):i.storage.removeItem("debug")}catch(t){}},i.load=function(){let t;try{t=i.storage.getItem("debug")}catch(t){}return!t&&void 0!==n&&"env"in n&&(t=n.env.DEBUG),t},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(t){}}(),i.destroy=(()=>{let t=!1;return()=>{t||(t=!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||(()=>{}),e.exports=t("./common")(i);const{formatters:r}=e.exports;r.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}).call(this)}).call(this,t("_process"))},{"./common":19,_process:50}],19:[function(t,e,i){e.exports=function(e){function i(t){let e,r,o,s=null;function a(...t){if(!a.enabled)return;const n=a,r=Number(new Date),o=r-(e||r);n.diff=o,n.prev=e,n.curr=r,e=r,t[0]=i.coerce(t[0]),"string"!=typeof t[0]&&t.unshift("%O");let s=0;t[0]=t[0].replace(/%([a-zA-Z%])/g,((e,r)=>{if("%%"===e)return"%";s++;const o=i.formatters[r];if("function"==typeof o){const i=t[s];e=o.call(n,i),t.splice(s,1),s--}return e})),i.formatArgs.call(n,t),(n.log||i.log).apply(n,t)}return a.namespace=t,a.useColors=i.useColors(),a.color=i.selectColor(t),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(t)),o),set:t=>{s=t}}),"function"==typeof i.init&&i.init(a),a}function n(t,e){const n=i(this.namespace+(void 0===e?":":e)+t);return n.log=this.log,n}function r(t){return t.toString().substring(2,t.toString().length-2).replace(/\.\*\?$/,"*")}return i.debug=i,i.default=i,i.coerce=function(t){return t instanceof Error?t.stack||t.message:t},i.disable=function(){const t=[...i.names.map(r),...i.skips.map(r).map((t=>"-"+t))].join(",");return i.enable(""),t},i.enable=function(t){let e;i.save(t),i.namespaces=t,i.names=[],i.skips=[];const n=("string"==typeof t?t:"").split(/[\s,]+/),r=n.length;for(e=0;e{i[t]=e[t]})),i.names=[],i.skips=[],i.formatters={},i.selectColor=function(t){let e=0;for(let i=0;i0&&a.length>o){a.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+a.length+' "'+String(e)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=a.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",c.name,c.message)}}else a=s[e]=i,++t._eventsCount;return t}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 t=new Array(arguments.length),e=0;e1&&(e=arguments[1]),e instanceof Error)throw e;var c=new Error('Unhandled "error" event. ('+e+")");throw c.context=e,c}if(!(i=s[t]))return!1;var l="function"==typeof i;switch(n=arguments.length){case 1:!function(t,e,i){if(e)t.call(i);else for(var n=t.length,r=g(t,n),o=0;o=0;s--)if(i[s]===e||i[s].listener===e){a=i[s].listener,o=s;break}if(o<0)return this;0===o?i.shift():function(t,e){for(var i=e,n=i+1,r=t.length;n=0;o--)this.removeListener(t,e[o]);return this},s.prototype.listeners=function(t){return p(this,t,!0)},s.prototype.rawListeners=function(t){return p(this,t,!1)},s.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):v.call(t,e)},s.prototype.listenerCount=v,s.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],23:[function(t,e,i){i.read=function(t,e,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=t[e+u];for(u+=d,o=f&(1<<-h)-1,f>>=-h,h+=a;h>0;o=256*o+t[e+u],u+=d,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=n;h>0;s=256*s+t[e+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(t,e,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=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),(e+=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=(e*c-1)*Math.pow(2,r),s+=u):(a=e*Math.pow(2,u-1)*Math.pow(2,r),s=0));r>=8;t[i+f]=255&a,f+=p,a/=256,r-=8);for(s=s<0;t[i+f]=255&s,f+=p,s/=256,l-=8);t[i+f-p]|=128*v}},{}],24:[function(t,e,i){"function"==typeof Object.create?e.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:e.exports=function(t,e){if(e){t.super_=e;var i=function(){};i.prototype=e.prototype,t.prototype=new i,t.prototype.constructor=t}}},{}],25:[function(t,e,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});var n=function(){function t(t,e){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=t,this.value=e}return t.prototype.rotateLeft=function(){var t=this.parent,e=this.brother,i=this.leftChild,n=this.rightChild;if(!n)throw new Error("unknown error");var r=n.leftChild,o=n.rightChild;return t&&(t.leftChild===this?t.leftChild=n:t.rightChild===this&&(t.rightChild=n)),n.parent=t,n.brother=e,n.leftChild=this,n.rightChild=o,e&&(e.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},t.prototype.rotateRight=function(){var t=this.parent,e=this.brother,i=this.leftChild;if(!i)throw new Error("unknown error");var n=this.rightChild,r=i.leftChild,o=i.rightChild;return t&&(t.leftChild===this?t.leftChild=i:t.rightChild===this&&(t.rightChild=i)),i.parent=t,i.brother=e,i.leftChild=r,i.rightChild=this,e&&(e.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},t.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},t.TreeNodeColorType={red:!0,black:!1},t}();Object.freeze(n),i.default=n},{}],26:[function(t,e,i){"use strict";var n=this&&this.__generator||function(t,e){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(t){var e=u(t),n=e.curNodeBucketIndex,r=e.curNodePointerIndex;return i[n][r]},this.eraseElementByPos=function(t){var e=this;if(t<0||t>h)throw new Error("pos should more than 0 and less than queue's size");if(0===t)this.popFront();else if(t===this.size())this.popBack();else{for(var i=[],n=t+1;n0?--c:o0&&--h)},this.setElementByPos=function(t,e){var n=u(t),r=n.curNodeBucketIndex,o=n.curNodePointerIndex;i[r][o]=e},this.insert=function(t,e,i){var n=this;if(void 0===i&&(i=1),0===t)for(;i--;)this.pushFront(e);else if(t===this.size())for(;i--;)this.pushBack(e);else{for(var r=[],o=t;o0?--s:o>0&&(--o,s=r.bucketSize-1)),++h,i[o][s]=t},this.popFront=function(){this.empty()||(1!==this.size()&&(s0&&--h)},this.shrinkToFit=function(){var t=this,e=[];this.forEach((function(t){e.push(t)}));var n=e.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]=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(i,"__esModule",{value:!0});var o=t("../LinkList/LinkList"),s=t("../Map/Map");function a(t,e,i){var c=this;if(void 0===t&&(t=[]),void 0===e&&(e=a.initSize),i=i||function(t){var e,i,n=0,o="";if("number"==typeof t)n=((n=Math.floor(t))<<5)-n,n&=n;else{o="string"!=typeof t?JSON.stringify(t):t;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(t){e={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(e)throw e.error}}}return n^n>>>16},0!=(e&e-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,e));this.size=function(){return l},this.empty=function(){return 0===l},this.clear=function(){l=0,u=e,h=[]},this.forEach=function(t){var e=0;h.forEach((function(i){i.forEach((function(i){t(i,e++)}))}))},this.setElement=function(t,e){var n,c;if(null==t)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(null!=e){var d=i(t)&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 g=v.value;if(g.key===t)return void(g.value=e)}}catch(t){n={error:t}}finally{try{v&&!v.done&&(c=p.return)&&c.call(p)}finally{if(n)throw n.error}}h[d].pushBack({key:t,value:e}),h[d].size()>=a.treeifyThreshold&&(h[d]=new s.default(h[d]))}else h[d].setElement(t,e);var y=h[d].size();l+=y-f}else++l,h[d]=new o.default([{key:t,value:e}]);l>u*a.sigma&&function(t){if(!(t>=a.maxSize)){u=2*t;var e=[];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;e[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(e){0==(i(e.key)&t)?f.pushBack(e):p.pushBack(e)})),f.size()>a.untreeifyThreshold?e[r]=new s.default(f):f.size()&&(e[r]=f),p.size()>a.untreeifyThreshold?e[r+t]=new s.default(p):p.size()&&(e[r+t]=p)}else{var v=new o.default,g=new o.default;n.forEach((function(e){0==(i(e.key)&t)?v.pushBack(e):g.pushBack(e)})),v.size()&&(e[r]=v),g.size()&&(e[r+t]=g)}h[r].clear()}})),h=e}}.call(this,u)}else this.eraseElementByKey(t)},this.getElementByKey=function(t){var e,n,o=i(t)&u-1;if(h[o]){if(h[o]instanceof s.default)return h[o].getElementByKey(t);try{for(var a=r(h[o]),c=a.next();!c.done;c=a.next()){var l=c.value;if(l.key===t)return l.value}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}}},this.eraseElementByKey=function(t){var e,n,c=i(t)&u-1;if(h[c]){var d=h[c].size();if(h[c]instanceof s.default)h[c].eraseElementByKey(t),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===t){h[c].eraseElementByPos(f);break}}catch(t){e={error:t}}finally{try{v&&!v.done&&(n=p.return)&&n.call(p)}finally{if(e)throw e.error}}}var g=h[c].size();l+=g-d}},this.find=function(t){var e,n,o=i(t)&u-1;if(!h[o])return!1;if(h[o]instanceof s.default)return h[o].find(t);try{for(var a=r(h[o]),c=a.next();!c.done;c=a.next())if(c.value.key===t)return!0}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(e)throw e.error}}return!1},this[Symbol.iterator]=function(){return function(){var t,e,i,o,s,a;return n(this,(function(n){switch(n.label){case 0:t=0,n.label=1;case 1:if(!(t=u)return[3,10];n.label=2;case 2:n.trys.push([2,7,8,9]),s=void 0,e=r(h[t]),i=e.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=e.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=e.return)&&a.call(e)}finally{if(s)throw s.error}return[7];case 9:return++t,[3,1];case 10:return[2]}}))}()},t.forEach((function(t){var e=t.key,i=t.value;return c.setElement(e,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(t,e,i){"use strict";var n=this&&this.__generator||function(t,e){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]=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(i,"__esModule",{value:!0});var o=t("../Set/Set"),s=t("../LinkList/LinkList");function a(t,e,i){var c=this;if(void 0===t&&(t=[]),void 0===e&&(e=a.initSize),i=i||function(t){var e=0,i="";if("number"==typeof t)e=((e=Math.floor(t))<<5)-e,e&=e;else{i="string"!=typeof t?JSON.stringify(t):t;for(var n=0;n>>16},0!=(e&e-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,e));this.size=function(){return l},this.empty=function(){return 0===l},this.clear=function(){l=0,u=e,h=[]},this.forEach=function(t){var e=0;h.forEach((function(i){i.forEach((function(i){t(i,e++)}))}))},this.insert=function(t){if(null==t)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");var e=i(t)&u-1;if(h[e]){var n=h[e].size();if(h[e]instanceof s.default){if(h[e].find(t))return;h[e].pushBack(t),h[e].size()>=a.treeifyThreshold&&(h[e]=new o.default(h[e]))}else h[e].insert(t);var r=h[e].size();l+=r-n}else h[e]=new s.default([t]),++l;l>u*a.sigma&&function(t){if(!(t>=a.maxSize)){u=2*t;var e=[];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");e[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(e){0==(i(e)&t)?l.pushBack(e):d.pushBack(e)})),l.size()>a.untreeifyThreshold?e[r]=new o.default(l):l.size()&&(e[r]=l),d.size()>a.untreeifyThreshold?e[r+t]=new o.default(d):d.size()&&(e[r+t]=d)}else{var f=new s.default,p=new s.default;n.forEach((function(e){0==(i(e)&t)?f.pushBack(e):p.pushBack(e)})),f.size()&&(e[r]=f),p.size()&&(e[r+t]=p)}h[r].clear()}})),h=e}}.call(this,u)},this.eraseElementByValue=function(t){var e=i(t)&u-1;if(h[e]){var n=h[e].size();h[e].eraseElementByValue(t),h[e]instanceof o.default&&h[e].size()<=a.untreeifyThreshold&&(h[e]=new s.default(h[e]));var r=h[e].size();l+=r-n}},this.find=function(t){var e=i(t)&u-1;return!!h[e]&&h[e].find(t)},this[Symbol.iterator]=function(){return function(){var t,e,i,o,s,a;return n(this,(function(n){switch(n.label){case 0:t=0,n.label=1;case 1:if(!(t=u)return[3,10];n.label=2;case 2:n.trys.push([2,7,8,9]),s=void 0,e=r(h[t]),i=e.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=e.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=e.return)&&a.call(e)}finally{if(s)throw s.error}return[7];case 9:return++t,[3,1];case 10:return[2]}}))}()},t.forEach((function(t){return c.insert(t)})),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(t,e,i){"use strict";var n=this&&this.__generator||function(t,e){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 e=o;t--&&e;)e=e.next;if(!e||void 0===e.value)throw new Error("unknown error");return e.value},this.eraseElementByPos=function(t){if(t<0||t>=i)throw new Error("erase pos must more then 0 and less then the list length");if(0===t)this.popFront();else if(t===i-1)this.popBack();else{for(var e=o;t--;){if(!(null==e?void 0:e.next))throw new Error("unknown error");e=e.next}if(!e||!e.pre||!e.next)throw new Error("unknown error");var n=e.pre,r=e.next;r.pre=n,n.next=r,i>0&&--i}},this.eraseElementByValue=function(t){for(;o&&o.value===t;)this.popFront();for(;s&&s.value===t;)this.popBack();if(o)for(var e=o;e;){if(e.value===t){var n=e.pre,r=e.next;r&&(r.pre=n),n&&(n.next=r),i>0&&--i}e=e.next}},this.pushBack=function(t){if(null==t)throw new Error("you can't push null or undefined here");++i;var e=new r(t);s?(s.next=e,e.pre=s,s=e):o=s=e},this.popBack=function(){s&&(i>0&&--i,s&&(o===s?o=s=void 0:(s=s.pre)&&(s.next=void 0)))},this.setElementByPos=function(t,e){if(null==e)throw new Error("you can't set null or undefined here");if(t<0||t>=i)throw new Error("pos must more then 0 and less then the list length");for(var n=o;t--;){if(!n)throw new Error("unknown error");n=n.next}n&&(n.value=e)},this.insert=function(t,e,n){if(void 0===n&&(n=1),null==e)throw new Error("you can't insert null or undefined here");if(t<0||t>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===t)for(;n--;)this.pushFront(e);else if(t===i)for(;n--;)this.pushBack(e);else{for(var s=o,a=1;a0&&--i;t.next=e.next,t.next&&(t.next.pre=t),t=t.next}},this.sort=function(t){var e=[];this.forEach((function(t){e.push(t)})),e.sort(t);var i=o;e.forEach((function(t){i&&(i.value=t,i=i.next)}))},this.pushFront=function(t){if(null==t)throw new Error("you can't push null or undefined here");++i;var e=new r(t);o?(e.next=o,o.pre=e,o=e):o=s=e},this.popFront=function(){o&&(i>0&&--i,o&&(o===s?o=s=void 0:(o=o.next)&&(o.pre=void 0)))},this.merge=function(t){var e=this,n=o;t.forEach((function(t){for(;n&&void 0!==n.value&&n.value<=t;)n=n.next;if(void 0===n)e.pushBack(t),n=s;else if(n===o)e.pushFront(t),n=o;else{++i;var a=n.pre;a&&(a.next=new r(t),a.next.pre=a,a.next.next=n,n&&(n.pre=a.next))}}))},this[Symbol.iterator]=function(){return function(){var t;return n(this,(function(e){switch(e.label){case 0:t=o,e.label=1;case 1:if(void 0===t)return[3,3];if(!t.value)throw new Error("unknown error");return[4,t.value];case 2:return e.sent(),t=t.next,[3,1];case 3:return[2]}}))}()},t.forEach((function(t){return e.pushBack(t)})),Object.freeze(this)}Object.freeze(o),i.default=o},{}],30:[function(t,e,i){"use strict";var n=this&&this.__generator||function(t,e){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]=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(i,"__esModule",{value:!0});var o=t("../Base/TreeNode");function s(t,e){var i=this;void 0===t&&(t=[]),e=e||function(t,e){return te?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(t){if(!t||void 0===t.key)throw new Error("unknown error");return t.leftChild?c(t.leftChild):t},l=function(t){if(!t||void 0===t.key)throw new Error("unknown error");return t.rightChild?l(t.rightChild):t};this.front=function(){if(!this.empty()){var t=c(a);if(void 0===t.key||void 0===t.value)throw new Error("unknown error");return{key:t.key,value:t.value}}},this.back=function(){if(!this.empty()){var t=l(a);if(void 0===t.key||void 0===t.value)throw new Error("unknown error");return{key:t.key,value:t.value}}},this.forEach=function(t){var e,i,n=0;try{for(var o=r(this),s=o.next();!s.done;s=o.next())t(s.value,n++)}catch(t){e={error:t}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(e)throw e.error}}},this.getElementByPos=function(t){var e,i;if(t<0||t>=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===t)return a;++n}}catch(t){e={error:t}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(e)throw e.error}}throw new Error("unknown Error")};var h=function(t,i){if(t&&void 0!==t.key&&void 0!==t.value){var n=e(t.key,i);return 0===n?{key:t.key,value:t.value}:n<0?h(t.rightChild,i):h(t.leftChild,i)||{key:t.key,value:t.value}}};this.lowerBound=function(t){return h(a,t)};var u=function(t,i){if(t&&void 0!==t.key&&void 0!==t.value)return e(t.key,i)<=0?u(t.rightChild,i):u(t.leftChild,i)||{key:t.key,value:t.value}};this.upperBound=function(t){return u(a,t)};var d=function(t,i){if(t&&void 0!==t.key&&void 0!==t.value){var n=e(t.key,i);return 0===n?{key:t.key,value:t.value}:n>0?d(t.leftChild,i):d(t.rightChild,i)||{key:t.key,value:t.value}}};this.reverseLowerBound=function(t){return d(a,t)};var f=function(t,i){if(t&&void 0!==t.key&&void 0!==t.value)return e(t.key,i)>=0?f(t.leftChild,i):f(t.rightChild,i)||{key:t.key,value:t.value}};this.reverseUpperBound=function(t){return f(a,t)};var p=function(t){var e=t.parent;if(!e){if(t===a)return;throw new Error("unknown error")}if(t.color!==o.default.TreeNodeColorType.red){var i=t.brother;if(!i)throw new Error("unknown error");if(t===e.leftChild)if(i.color===o.default.TreeNodeColorType.red){i.color=o.default.TreeNodeColorType.black,e.color=o.default.TreeNodeColorType.red;var n=e.rotateLeft();a===e&&(a=n),p(t)}else i.color===o.default.TreeNodeColorType.black&&(i.rightChild&&i.rightChild.color===o.default.TreeNodeColorType.red?(i.color=e.color,e.color=o.default.TreeNodeColorType.black,i.rightChild&&(i.rightChild.color=o.default.TreeNodeColorType.black),n=e.rotateLeft(),a===e&&(a=n),t.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(e)):(i.color=o.default.TreeNodeColorType.red,i.leftChild&&(i.leftChild.color=o.default.TreeNodeColorType.black),n=i.rotateRight(),a===i&&(a=n),p(t)));else t===e.rightChild&&(i.color===o.default.TreeNodeColorType.red?(i.color=o.default.TreeNodeColorType.black,e.color=o.default.TreeNodeColorType.red,n=e.rotateRight(),a===e&&(a=n),p(t)):i.color===o.default.TreeNodeColorType.black&&(i.leftChild&&i.leftChild.color===o.default.TreeNodeColorType.red?(i.color=e.color,e.color=o.default.TreeNodeColorType.black,i.leftChild&&(i.leftChild.color=o.default.TreeNodeColorType.black),n=e.rotateRight(),a===e&&(a=n),t.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(e)):(i.color=o.default.TreeNodeColorType.red,i.rightChild&&(i.rightChild.color=o.default.TreeNodeColorType.black),n=i.rotateLeft(),a===i&&(a=n),p(t))))}else t.color=o.default.TreeNodeColorType.black},v=function(t){for(var e=t;e.leftChild||e.rightChild;){if(e.rightChild){e=c(e.rightChild);var i=t.key;t.key=e.key,e.key=i;var n=t.value;t.value=e.value,e.value=n,t=e}e.leftChild&&(e=l(e.leftChild),i=t.key,t.key=e.key,e.key=i,n=t.value,t.value=e.value,e.value=n,t=e)}p(e),e&&e.remove(),--s,a.color=o.default.TreeNodeColorType.black},g=function(t,e){return!(!t||void 0===t.key)&&(!!g(t.leftChild,e)||!!e(t)||g(t.rightChild,e))};this.eraseElementByPos=function(t){if(t<0||t>=s)throw new Error("pos must more than 0 and less than set's size");var e=0;g(a,(function(i){return t===e?(v(i),!0):(++e,!1)}))},this.eraseElementByKey=function(t){if(!this.empty()){var i=w(a,t);void 0!==i&&void 0!==i.key&&0===e(i.key,t)&&v(i)}};var y=function(t,i){if(!t||void 0===t.key)throw new Error("unknown error");var n=e(i,t.key);return n<0?t.leftChild?y(t.leftChild,i):(t.leftChild=new o.default,t.leftChild.parent=t,t.leftChild.brother=t.rightChild,t.rightChild&&(t.rightChild.brother=t.leftChild),t.leftChild):n>0?t.rightChild?y(t.rightChild,i):(t.rightChild=new o.default,t.rightChild.parent=t,t.rightChild.brother=t.leftChild,t.leftChild&&(t.leftChild.brother=t.rightChild),t.rightChild):t},m=function(t){var e=t.parent;if(!e){if(t===a)return;throw new Error("unknown error")}if(e.color!==o.default.TreeNodeColorType.black&&e.color===o.default.TreeNodeColorType.red){var i=e.brother,n=e.parent;if(!n)throw new Error("unknown error");if(i&&i.color===o.default.TreeNodeColorType.red)i.color=e.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red,m(n);else if(!i||i.color===o.default.TreeNodeColorType.black)if(e===n.leftChild)if(t===e.leftChild){e.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red;var r=n.rotateRight();n===a&&(a=r)}else t===e.rightChild&&(r=e.rotateLeft(),n===a&&(a=r),m(e));else e===n.rightChild&&(t===e.leftChild?(r=e.rotateRight(),n===a&&(a=r),m(e)):t===e.rightChild&&(e.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red,r=n.rotateLeft(),n===a&&(a=r)))}};this.setElement=function(t,i){if(null==t)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=t,a.value=i,void(a.color=o.default.TreeNodeColorType.black);var n=y(a,t);void 0===n.key||0!==e(n.key,t)?(++s,n.key=t,n.value=i,m(n),a.color=o.default.TreeNodeColorType.black):n.value=i}else this.eraseElementByKey(t)};var w=function(t,i){if(t&&void 0!==t.key){var n=e(i,t.key);return n<0?w(t.leftChild,i):n>0?w(t.rightChild,i):t}};this.find=function(t){return!!w(a,t)},this.getElementByKey=function(t){var e=w(a,t);if(void 0===(null==e?void 0:e.key)||void 0===(null==e?void 0:e.value))throw new Error("unknown error");return e.value},this.union=function(t){var e=this;t.forEach((function(t){var i=t.key,n=t.value;return e.setElement(i,n)}))},this.getHeight=function(){if(this.empty())return 0;var t=function(e){return e?Math.max(t(e.leftChild),t(e.rightChild))+1:1};return t(a)};var b=function(t){return n(this,(function(e){switch(e.label){case 0:return t&&void 0!==t.key&&void 0!==t.value?[5,r(b(t.leftChild))]:[2];case 1:return e.sent(),[4,{key:t.key,value:t.value}];case 2:return e.sent(),[5,r(b(t.rightChild))];case 3:return e.sent(),[2]}}))};this[Symbol.iterator]=function(){return b(a)},t.forEach((function(t){var e=t.key,n=t.value;return i.setElement(e,n)})),Object.freeze(this)}Object.freeze(s),i.default=s},{"../Base/TreeNode":25}],31:[function(t,e,i){"use strict";function n(t,e){void 0===t&&(t=[]),e=e||function(t,e){return t>e?-1:t=n)throw new Error("unknown error");if(e<0||e>=n)throw new Error("unknown error");var r=i[t];i[t]=i[e],i[e]=r},o=function(t){if(t<0||t>=n)throw new Error("unknown error");var o=2*t+1,s=2*t+2;o0&&r(t,o),s0&&r(t,s)};!function(){for(var t=Math.floor((n-1)/2);t>=0;--t)for(var o=t,s=2*o+1;s0&&(c=a),e(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(t){if(i.push(t),1!=++n)for(var r=n-1;r>0;){var s=Math.floor((r-1)/2);if(e(i[s],t)<=0)break;o(s),r=s}},this.pop=function(){if(!this.empty())if(1!==this.size()){var t=i[n-1];--n;for(var r=0;r=this.size())break;var a=o;if(s0&&(a=s),e(i[a],t)>=0)break;i[r]=i[a],r=a}i[r]=t}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(t,e,i){"use strict";Object.defineProperty(i,"__esModule",{value:!0});var n=t("../LinkList/LinkList");function r(t){void 0===t&&(t=[]);var e=new n.default(t);this.size=function(){return e.size()},this.empty=function(){return e.empty()},this.clear=function(){e.clear()},this.push=function(t){e.pushBack(t)},this.pop=function(){e.popFront()},this.front=function(){return e.front()},Object.freeze(this)}Object.freeze(r),i.default=r},{"../LinkList/LinkList":29}],33:[function(t,e,i){"use strict";var n=this&&this.__generator||function(t,e){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]=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(i,"__esModule",{value:!0});var o=t("../Base/TreeNode");function s(t,e){var i=this;void 0===t&&(t=[]),e=e||function(t,e){return te?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(t){if(!t||void 0===t.key)throw new Error("unknown error");return t.leftChild?c(t.leftChild):t},l=function(t){if(!t||void 0===t.key)throw new Error("unknown error");return t.rightChild?l(t.rightChild):t};this.front=function(){if(!this.empty())return c(a).key},this.back=function(){if(!this.empty())return l(a).key},this.forEach=function(t){var e,i,n=0;try{for(var o=r(this),s=o.next();!s.done;s=o.next())t(s.value,n++)}catch(t){e={error:t}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(e)throw e.error}}},this.getElementByPos=function(t){var e,i;if(t<0||t>=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===t)return a;++n}}catch(t){e={error:t}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(e)throw e.error}}throw new Error("unknown error")};var h=function(t){var e=t.parent;if(!e){if(t===a)return;throw new Error("unknown error")}if(t.color!==o.default.TreeNodeColorType.red){var i=t.brother;if(!i)throw new Error("unknown error");if(t===e.leftChild)if(i.color===o.default.TreeNodeColorType.red){i.color=o.default.TreeNodeColorType.black,e.color=o.default.TreeNodeColorType.red;var n=e.rotateLeft();a===e&&(a=n),h(t)}else i.color===o.default.TreeNodeColorType.black&&(i.rightChild&&i.rightChild.color===o.default.TreeNodeColorType.red?(i.color=e.color,e.color=o.default.TreeNodeColorType.black,i.rightChild&&(i.rightChild.color=o.default.TreeNodeColorType.black),n=e.rotateLeft(),a===e&&(a=n),t.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(e)):(i.color=o.default.TreeNodeColorType.red,i.leftChild&&(i.leftChild.color=o.default.TreeNodeColorType.black),n=i.rotateRight(),a===i&&(a=n),h(t)));else t===e.rightChild&&(i.color===o.default.TreeNodeColorType.red?(i.color=o.default.TreeNodeColorType.black,e.color=o.default.TreeNodeColorType.red,n=e.rotateRight(),a===e&&(a=n),h(t)):i.color===o.default.TreeNodeColorType.black&&(i.leftChild&&i.leftChild.color===o.default.TreeNodeColorType.red?(i.color=e.color,e.color=o.default.TreeNodeColorType.black,i.leftChild&&(i.leftChild.color=o.default.TreeNodeColorType.black),n=e.rotateRight(),a===e&&(a=n),t.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(e)):(i.color=o.default.TreeNodeColorType.red,i.rightChild&&(i.rightChild.color=o.default.TreeNodeColorType.black),n=i.rotateLeft(),a===i&&(a=n),h(t))))}else t.color=o.default.TreeNodeColorType.black},u=function(t){for(var e=t;e.leftChild||e.rightChild;){if(e.rightChild){e=c(e.rightChild);var i=t.key;t.key=e.key,e.key=i,t=e}e.leftChild&&(e=l(e.leftChild),i=t.key,t.key=e.key,e.key=i,t=e)}h(e),e&&e.remove(),--s,a.color=o.default.TreeNodeColorType.black},d=function(t,e){return!(!t||void 0===t.key)&&(!!d(t.leftChild,e)||!!e(t)||d(t.rightChild,e))};this.eraseElementByPos=function(t){if(t<0||t>=s)throw new Error("pos must more than 0 and less than set's size");var e=0;d(a,(function(i){return t===e?(u(i),!0):(++e,!1)}))},this.eraseElementByValue=function(t){if(!this.empty()){var i=v(a,t);void 0!==i&&void 0!==i.key&&0===e(i.key,t)&&u(i)}};var f=function(t,i){if(!t||void 0===t.key)throw new Error("unknown error");var n=e(i,t.key);return n<0?t.leftChild?f(t.leftChild,i):(t.leftChild=new o.default,t.leftChild.parent=t,t.leftChild.brother=t.rightChild,t.rightChild&&(t.rightChild.brother=t.leftChild),t.leftChild):n>0?t.rightChild?f(t.rightChild,i):(t.rightChild=new o.default,t.rightChild.parent=t,t.rightChild.brother=t.leftChild,t.leftChild&&(t.leftChild.brother=t.rightChild),t.rightChild):t},p=function(t){var e=t.parent;if(!e){if(t===a)return;throw new Error("unknown error")}if(e.color!==o.default.TreeNodeColorType.black&&e.color===o.default.TreeNodeColorType.red){var i=e.brother,n=e.parent;if(!n)throw new Error("unknown error");if(i&&i.color===o.default.TreeNodeColorType.red)i.color=e.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red,p(n);else if(!i||i.color===o.default.TreeNodeColorType.black)if(e===n.leftChild)if(t===e.leftChild){e.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red;var r=n.rotateRight();n===a&&(a=r)}else t===e.rightChild&&(r=e.rotateLeft(),n===a&&(a=r),p(e));else e===n.rightChild&&(t===e.leftChild?(r=e.rotateRight(),n===a&&(a=r),p(e)):t===e.rightChild&&(e.color=o.default.TreeNodeColorType.black,n.color=o.default.TreeNodeColorType.red,r=n.rotateLeft(),n===a&&(a=r)))}};this.insert=function(t){if(null==t)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=t,void(a.color=o.default.TreeNodeColorType.black);var i=f(a,t);void 0!==i.key&&0===e(i.key,t)||(++s,i.key=t,p(i),a.color=o.default.TreeNodeColorType.black)};var v=function(t,i){if(t&&void 0!==t.key){var n=e(i,t.key);return n<0?v(t.leftChild,i):n>0?v(t.rightChild,i):t}};this.find=function(t){var i=v(a,t);return void 0!==i&&void 0!==i.key&&0===e(i.key,t)};var g=function(t,i){if(t&&void 0!==t.key){var n=e(t.key,i);if(0===n)return t.key;if(n<0)return g(t.rightChild,i);var r=g(t.leftChild,i);return void 0!==r?r:t.key}};this.lowerBound=function(t){return g(a,t)};var y=function(t,i){if(t&&void 0!==t.key){if(e(t.key,i)<=0)return y(t.rightChild,i);var n=y(t.leftChild,i);return void 0!==n?n:t.key}};this.upperBound=function(t){return y(a,t)};var m=function(t,i){if(t&&void 0!==t.key){var n=e(t.key,i);if(0===n)return t.key;if(n>0)return m(t.leftChild,i);var r=m(t.rightChild,i);return void 0!==r?r:t.key}};this.reverseLowerBound=function(t){return m(a,t)};var w=function(t,i){if(t&&void 0!==t.key){if(e(t.key,i)>=0)return w(t.leftChild,i);var n=w(t.rightChild,i);return void 0!==n?n:t.key}};this.reverseUpperBound=function(t){return w(a,t)},this.union=function(t){var e=this;t.forEach((function(t){return e.insert(t)}))},this.getHeight=function(){if(this.empty())return 0;var t=function(e){return e?Math.max(t(e.leftChild),t(e.rightChild))+1:1};return t(a)};var b=function(t){return n(this,(function(e){switch(e.label){case 0:return t&&void 0!==t.key?[5,r(b(t.leftChild))]:[2];case 1:return e.sent(),[4,t.key];case 2:return e.sent(),[5,r(b(t.rightChild))];case 3:return e.sent(),[2]}}))};this[Symbol.iterator]=function(){return b(a)},t.forEach((function(t){return i.insert(t)})),Object.freeze(this)}Object.freeze(s),i.default=s},{"../Base/TreeNode":25}],34:[function(t,e,i){"use strict";function n(t){var e=this;void 0===t&&(t=[]);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(t){n.push(t),++i},this.pop=function(){n.pop(),i>0&&--i},this.top=function(){return n[i-1]},t.forEach((function(t){return e.push(t)})),Object.freeze(this)}Object.defineProperty(i,"__esModule",{value:!0}),Object.freeze(n),i.default=n},{}],35:[function(t,e,i){"use strict";var n=this&&this.__generator||function(t,e){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(t){r={error:t}}finally{try{n&&!n.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return s},o=this&&this.__spreadArray||function(t,e,i){if(i||2===arguments.length)for(var n,r=0,o=e.length;r=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};function a(t){var e=this;void 0===t&&(t=[]);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(t){a.forEach(t)},this.getElementByPos=function(t){if(t<0||t>=i)throw new Error("pos must more than 0 and less than vector's size");return a[t]},this.eraseElementByPos=function(t){if(t<0||t>=i)throw new Error("pos must more than 0 and less than vector's size");for(var e=t;en;)this.popBack()},this.pushBack=function(t){a.push(t),++i},this.popBack=function(){a.pop(),i>0&&--i},this.setElementByPos=function(t,e){if(t<0||t>=i)throw new Error("pos must more than 0 and less than vector's size");a[t]=e},this.insert=function(t,e,n){if(void 0===n&&(n=1),t<0||t>i)throw new Error("pos must more than 0 and less than or equal to vector's size");a.splice.apply(a,o([t,0],r(new Array(n).fill(e)),!1)),i+=n},this.find=function(t){return a.includes(t)},this.reverse=function(){a.reverse()},this.unique=function(){var t,e=[];this.forEach((function(i,n){0!==n&&i===t||(e.push(i),t=i)})),e.forEach((function(t,e){a[e]=t}));for(var n=e.length;i>n;)this.popBack()},this.sort=function(t){a.sort(t)},this[Symbol.iterator]=function(){return function(){return n(this,(function(t){switch(t.label){case 0:return[5,s(a)];case 1:return[2,t.sent()]}}))}()},t.forEach((function(t){return e.pushBack(t)})),Object.freeze(this)}Object.defineProperty(i,"__esModule",{value:!0}),Object.freeze(a),i.default=a},{}],36:[function(t,e,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=t("./Vector/Vector");i.Vector=n.default;var r=t("./Stack/Stack");i.Stack=r.default;var o=t("./Queue/Queue");i.Queue=o.default;var s=t("./LinkList/LinkList");i.LinkList=s.default;var a=t("./Deque/Deque");i.Deque=a.default;var c=t("./PriorityQueue/PriorityQueue");i.PriorityQueue=c.default;var l=t("./Set/Set");i.Set=l.default;var h=t("./Map/Map");i.Map=h.default;var u=t("./HashSet/HashSet");i.HashSet=u.default;var d=t("./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(t,e,i){"use strict";const n=t("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=(t,e,i)=>{const n=t[d].get(e);if(n){const e=n.value;if(g(t,e)){if(m(t,n),!t[a])return}else i&&(t[f]&&(n.value.now=Date.now()),t[u].unshiftNode(n));return e.value}},g=(t,e)=>{if(!e||!e.maxAge&&!t[c])return!1;const i=Date.now()-e.now;return e.maxAge?i>e.maxAge:t[c]&&i>t[c]},y=t=>{if(t[o]>t[r])for(let e=t[u].tail;t[o]>t[r]&&null!==e;){const i=e.prev;m(t,e),e=i}},m=(t,e)=>{if(e){const i=e.value;t[l]&&t[l](i.key,i.value),t[o]-=i.length,t[d].delete(i.key),t[u].removeNode(e)}};class w{constructor(t,e,i,n,r){this.key=t,this.value=e,this.length=i,this.now=n,this.maxAge=r||0}}const b=(t,e,i,n)=>{let r=i.value;g(t,r)&&(m(t,i),t[a]||(r=void 0)),r&&e.call(n,r.value,r.key,t)};e.exports=class{constructor(t){if("number"==typeof t&&(t={max:t}),t||(t={}),t.max&&("number"!=typeof t.max||t.max<0))throw new TypeError("max must be a non-negative number");this[r]=t.max||1/0;const e=t.length||p;if(this[s]="function"!=typeof e?p:e,this[a]=t.stale||!1,t.maxAge&&"number"!=typeof t.maxAge)throw new TypeError("maxAge must be a number");this[c]=t.maxAge||0,this[l]=t.dispose,this[h]=t.noDisposeOnSet||!1,this[f]=t.updateAgeOnGet||!1,this.reset()}set max(t){if("number"!=typeof t||t<0)throw new TypeError("max must be a non-negative number");this[r]=t||1/0,y(this)}get max(){return this[r]}set allowStale(t){this[a]=!!t}get allowStale(){return this[a]}set maxAge(t){if("number"!=typeof t)throw new TypeError("maxAge must be a non-negative number");this[c]=t,y(this)}get maxAge(){return this[c]}set lengthCalculator(t){"function"!=typeof t&&(t=p),t!==this[s]&&(this[s]=t,this[o]=0,this[u].forEach((t=>{t.length=this[s](t.value,t.key),this[o]+=t.length}))),y(this)}get lengthCalculator(){return this[s]}get length(){return this[o]}get itemCount(){return this[u].length}rforEach(t,e){e=e||this;for(let i=this[u].tail;null!==i;){const n=i.prev;b(this,t,i,e),i=n}}forEach(t,e){e=e||this;for(let i=this[u].head;null!==i;){const n=i.next;b(this,t,i,e),i=n}}keys(){return this[u].toArray().map((t=>t.key))}values(){return this[u].toArray().map((t=>t.value))}reset(){this[l]&&this[u]&&this[u].length&&this[u].forEach((t=>this[l](t.key,t.value))),this[d]=new Map,this[u]=new n,this[o]=0}dump(){return this[u].map((t=>!g(this,t)&&{k:t.key,v:t.value,e:t.now+(t.maxAge||0)})).toArray().filter((t=>t))}dumpLru(){return this[u]}set(t,e,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](e,t);if(this[d].has(t)){if(a>this[r])return m(this,this[d].get(t)),!1;const s=this[d].get(t).value;return this[l]&&(this[h]||this[l](t,s.value)),s.now=n,s.maxAge=i,s.value=e,this[o]+=a-s.length,s.length=a,this.get(t),y(this),!0}const f=new w(t,e,a,n,i);return f.length>this[r]?(this[l]&&this[l](t,e),!1):(this[o]+=f.length,this[u].unshift(f),this[d].set(t,this[u].head),y(this),!0)}has(t){if(!this[d].has(t))return!1;const e=this[d].get(t).value;return!g(this,e)}get(t){return v(this,t,!0)}peek(t){return v(this,t,!1)}pop(){const t=this[u].tail;return t?(m(this,t),t.value):null}del(t){m(this,this[d].get(t))}load(t){this.reset();const e=Date.now();for(let i=t.length-1;i>=0;i--){const n=t[i],r=n.e||0;if(0===r)this.set(n.k,n.v);else{const t=r-e;t>0&&this.set(n.k,n.v,t)}}}prune(){this[d].forEach(((t,e)=>v(this,e,!1)))}}},{yallist:83}],38:[function(t,e,i){(function(t){(function(){const i=e.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 t in i.types){const e=i.types[t];i.codes[e]=t}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=t.from([i.SESSIONPRESENT_MASK]),i.CONNACK_HEADER=t.from([i.codes.connack<[0,1].map((r=>[0,1].map((o=>{const s=t.alloc(1);return s.writeUInt8(i.codes[e]<t.from([e]))),i.EMPTY={pingreq:t.from([i.codes.pingreq<<4,0]),pingresp:t.from([i.codes.pingresp<<4,0]),disconnect:t.from([i.codes.disconnect<<4,0])}}).call(this)}).call(this,t("buffer").Buffer)},{buffer:17}],39:[function(t,e,i){(function(i){(function(){const n=t("./writeToStream"),r=t("events");class o extends r{constructor(){super(),this._array=new Array(20),this._i=0}write(t){return this._array[this._i++]=t,!0}concat(){let t=0;const e=new Array(this._array.length),n=this._array;let r,o=0;for(r=0;r>8,0),i.writeUInt8(255&e,1),i}e.exports={cache:i,generateCache:function(){for(let t=0;t<65536;t++)i[t]=r(t)},generateNumber:r,genBufVariableByteInt:function(e){let i=0,r=0;const o=t.allocUnsafe(4);do{i=e%128|0,(e=e/128|0)>0&&(i|=128),o.writeUInt8(i,r++)}while(e>0&&r<4);return e>0&&(r=0),n?o.subarray(0,r):o.slice(0,r)},generate4ByteBuffer:function(e){const i=t.allocUnsafe(4);return i.writeUInt32BE(e,0),i}}}).call(this)}).call(this,t("buffer").Buffer)},{buffer:17}],42:[function(t,e,i){e.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(t,e,i){const n=t("bl"),r=t("events"),o=t("./packet"),s=t("./constants"),a=t("debug")("mqtt-packet:parser");class c extends r{constructor(){super(),this.parser=this.constructor.parser}static parser(t){return this instanceof c?(this.settings=t||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):(new c).parser(t)}_resetState(){a("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new o,this.error=null,this._list=n(),this._stateCounter=0}parse(t){for(this.error&&this._resetState(),this._list.append(t),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 t=this._list.readUInt8(0);return this.packet.cmd=s.types[t>>s.CMD_SHIFT],this.packet.retain=0!=(t&s.RETAIN_MASK),this.packet.qos=t>>s.QOS_SHIFT&s.QOS_MASK,this.packet.dup=0!=(t&s.DUP_MASK),a("_parseHeader: packet: %o",this.packet),this._list.consume(1),!0}_parseLength(){const t=this._parseVarByteNum(!0);return t&&(this.packet.length=t.value,this._list.consume(t.bytes)),a("_parseLength %d",t.value),!!t}_parsePayload(){a("_parsePayload: payload %O",this._list);let t=!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"))}t=!0}return a("_parsePayload complete result: %s",t),t}_parseConnect(){let t,e,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 t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(o.properties=t)}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 t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(o.will.properties=t)}if(null===(t=this._parseString()))return this._emitError(new Error("Cannot parse will topic"));if(o.will.topic=t,a("_parseConnect: packet.will.topic: %s",o.will.topic),null===(e=this._parseBuffer()))return this._emitError(new Error("Cannot parse will payload"));o.will.payload=e,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 t=this.packet;if(this._list.length<1)return null;if(t.sessionPresent=!!(this._list.readUInt8(this._pos++)&s.SESSIONPRESENT_MASK),5===this.settings.protocolVersion)this._list.length>=2?t.reasonCode=this._list.readUInt8(this._pos++):t.reasonCode=0;else{if(this._list.length<2)return null;t.returnCode=this._list.readUInt8(this._pos++)}if(-1===t.returnCode||-1===t.reasonCode)return this._emitError(new Error("Cannot parse return code"));if(5===this.settings.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}a("_parseConnack: complete")}_parsePublish(){a("_parsePublish");const t=this.packet;if(t.topic=this._parseString(),null===t.topic)return this._emitError(new Error("Cannot parse topic"));if(!(t.qos>0)||this._parseMessageId()){if(5===this.settings.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}t.payload=this._list.slice(this._pos,t.length),a("_parsePublish: payload from buffer list: %o",t.payload)}}_parseSubscribe(){a("_parseSubscribe");const t=this.packet;let e,i,n,r,o,c,l;if(1!==t.qos)return this._emitError(new Error("Wrong subscribe header"));if(t.subscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}for(;this._pos=t.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:e,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),t.subscriptions.push(l)}}}_parseSuback(){a("_parseSuback");const t=this.packet;if(this.packet.granted=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}for(;this._pos2?(t.reasonCode=this._parseByte(),a("_parseConfirmation: packet.reasonCode `%d`",t.reasonCode)):t.reasonCode=0,t.length>3)){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}return!0}_parseDisconnect(){const t=this.packet;if(a("_parseDisconnect"),5===this.settings.protocolVersion){this._list.length>0?t.reasonCode=this._parseByte():t.reasonCode=0;const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}return a("_parseDisconnect result: true"),!0}_parseAuth(){a("_parseAuth");const t=this.packet;if(5!==this.settings.protocolVersion)return this._emitError(new Error("Not supported auth packet for this version MQTT"));t.reasonCode=this._parseByte();const e=this._parseProperties();return Object.getOwnPropertyNames(e).length&&(t.properties=e),a("_parseAuth: result: true"),!0}_parseMessageId(){const t=this.packet;return t.messageId=this._parseNum(),null===t.messageId?(this._emitError(new Error("Cannot parse messageId")),!1):(a("_parseMessageId: packet.messageId %d",t.messageId),!0)}_parseString(t){const e=this._parseNum(),i=e+this._pos;if(-1===e||i>this._list.length||i>this.packet.length)return null;const n=this._list.toString("utf8",this._pos,i);return this._pos+=e,a("_parseString: result: %s",n),n}_parseStringPair(){return a("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){const t=this._parseNum(),e=t+this._pos;if(-1===t||e>this._list.length||e>this.packet.length)return null;const i=this._list.slice(this._pos,e);return this._pos+=t,a("_parseBuffer: result: %o",i),i}_parseNum(){if(this._list.length-this._pos<2)return-1;const t=this._list.readUInt16BE(this._pos);return this._pos+=2,a("_parseNum: result: %s",t),t}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;const t=this._list.readUInt32BE(this._pos);return this._pos+=4,a("_parse4ByteNum: result: %s",t),t}_parseVarByteNum(t){a("_parseVarByteNum");let e,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&&(t?{bytes:i,value:r}:r)),o}_parseByte(){let t;return this._pos=4)&&(u||l))g+=i.byteLength(u)+2;else{if(a<4)return e.emit("error",new Error("clientId must be supplied before 3.1.1")),!1;if(1*l==0)return e.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 e.emit("error",new Error("Invalid keepalive")),!1;if(g+=2,g+=1,5===a){var y=S(e,v);if(!y)return!1;g+=y.length}if(c){if("object"!=typeof c)return e.emit("error",new Error("Invalid will")),!1;if(!c.topic||"string"!=typeof c.topic)return e.emit("error",new Error("Invalid will topic")),!1;if(g+=i.byteLength(c.topic)+2,g+=2,c.payload){if(!(c.payload.length>=0))return e.emit("error",new Error("Invalid will payload")),!1;"string"==typeof c.payload?g+=i.byteLength(c.payload):g+=c.payload.length}var m={};if(5===a){if(!(m=S(e,c.properties)))return!1;g+=m.length}}let x=!1;if(null!=d){if(!E(d))return e.emit("error",new Error("Invalid username")),!1;x=!0,g+=i.byteLength(d)+2}if(null!=f){if(!x)return e.emit("error",new Error("Username is required to use password")),!1;if(!E(f))return e.emit("error",new Error("Invalid password")),!1;g+=_(f)+2}e.write(n.CONNECT_HEADER),w(e,g),A(e,s),o.bridgeMode&&(a+=128),e.write(131===a?n.VERSION131:132===a?n.VERSION132:4===a?n.VERSION4:5===a?n.VERSION5:n.VERSION3);let k=0;return k|=null!=d?n.USERNAME_MASK:0,k|=null!=f?n.PASSWORD_MASK:0,k|=c&&c.retain?n.WILL_RETAIN_MASK:0,k|=c&&c.qos?c.qos<0&&p(e,f),null!=y&&y.write(),c("publish: payload: %o",d),e.write(d)}(t,e,s);case"puback":case"pubrec":case"pubrel":case"pubcomp":return function(t,e,r){const o=r?r.protocolVersion:4,s=t||{},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 e.emit("error",new Error("Invalid messageId")),!1;let v=null;if(5===o&&"object"==typeof d){if(!(v=P(e,d,r,f)))return!1;f+=v.length}return e.write(n.ACKS[a][h][l][0]),w(e,f),p(e,c),5===o&&e.write(i.from([u])),null!==v&&v.write(),!0}(t,e,s);case"subscribe":return function(t,e,r){c("subscribe: packet: ");const o=r?r.protocolVersion:4,s=t||{},a=s.dup?n.DUP_MASK:0,l=s.messageId,h=s.subscriptions,u=s.properties;let d=0;if("number"!=typeof l)return e.emit("error",new Error("Invalid messageId")),!1;d+=2;let f=null;if(5===o){if(!(f=S(e,u)))return!1;d+=f.length}if("object"!=typeof h||!h.length)return e.emit("error",new Error("Invalid subscriptions")),!1;for(let t=0;t2)return e.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),e.write(n.SUBSCRIBE_HEADER[1][a?1:0][0]),w(e,d),p(e,l),null!==f&&f.write();let v=!0;for(const t of h){const r=t.topic,s=t.qos,a=+t.nl,c=+t.rap,l=t.rh;let h;b(e,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=e.write(i.from([h]))}return v}(t,e,s);case"suback":return function(t,e,r){const o=r?r.protocolVersion:4,s=t||{},a=s.messageId,c=s.granted,l=s.properties;let h=0;if("number"!=typeof a)return e.emit("error",new Error("Invalid messageId")),!1;if(h+=2,"object"!=typeof c||!c.length)return e.emit("error",new Error("Invalid qos vector")),!1;for(let t=0;tp===k,set(t){t?(l&&0!==Object.keys(l).length||(v=!0),p=k):(v=!1,p=T)}});const m={};function w(t,e){if(e>n.VARBYTEINT_MAX)return t.emit("error",new Error(`Invalid variable byte integer: ${e}`)),!1;let i=m[e];return i||(i=d(e),e<16384&&(m[e]=i)),c("writeVarByteInt: writing to stream: %o",i),t.write(i)}function b(t,e){const n=i.byteLength(e);return p(t,n),c("writeString: %s",e),t.write(e,"utf8")}function x(t,e,i){b(t,e),b(t,i)}function k(t,e){return c("writeNumberCached: number: %d",e),c("writeNumberCached: %o",l[e]),t.write(l[e])}function T(t,e){const i=h(e);return c("writeNumberGenerated: %o",i),t.write(i)}function A(t,e){"string"==typeof e?b(t,e):e?(p(t,e.length),t.write(e)):p(t,0)}function S(t,e){if("object"!=typeof e||null!=e.length)return{length:1,write(){R(t,{},0)}};let r=0;function o(e,r){let o=0;switch(n.propertiesTypes[e]){case"byte":if("boolean"!=typeof r)return t.emit("error",new Error(`Invalid ${e}: ${r}`)),!1;o+=2;break;case"int8":if("number"!=typeof r||r<0||r>255)return t.emit("error",new Error(`Invalid ${e}: ${r}`)),!1;o+=2;break;case"binary":if(r&&null===r)return t.emit("error",new Error(`Invalid ${e}: ${r}`)),!1;o+=1+i.byteLength(r)+2;break;case"int16":if("number"!=typeof r||r<0||r>65535)return t.emit("error",new Error(`Invalid ${e}: ${r}`)),!1;o+=3;break;case"int32":if("number"!=typeof r||r<0||r>4294967295)return t.emit("error",new Error(`Invalid ${e}: ${r}`)),!1;o+=5;break;case"var":if("number"!=typeof r||r<0||r>268435455)return t.emit("error",new Error(`Invalid ${e}: ${r}`)),!1;o+=1+i.byteLength(d(r));break;case"string":if("string"!=typeof r)return t.emit("error",new Error(`Invalid ${e}: ${r}`)),!1;o+=3+i.byteLength(r.toString());break;case"pair":if("object"!=typeof r)return t.emit("error",new Error(`Invalid ${e}: ${r}`)),!1;o+=Object.getOwnPropertyNames(r).reduce(((t,e)=>{const n=r[e];return Array.isArray(n)?t+=n.reduce(((t,n)=>t+(3+i.byteLength(e.toString())+2+i.byteLength(n.toString()))),0):t+=3+i.byteLength(e.toString())+2+i.byteLength(r[e].toString()),t}),0);break;default:return t.emit("error",new Error(`Invalid property ${e}: ${r}`)),!1}return o}if(e)for(const t in e){let i=0,n=0;const s=e[t];if(Array.isArray(s))for(let e=0;eo;){const i=r.shift();if(!i||!e[i])return!1;delete e[i],s=S(t,e)}return s}function C(t,e,r){switch(n.propertiesTypes[e]){case"byte":t.write(i.from([n.properties[e]])),t.write(i.from([+r]));break;case"int8":t.write(i.from([n.properties[e]])),t.write(i.from([r]));break;case"binary":t.write(i.from([n.properties[e]])),A(t,r);break;case"int16":t.write(i.from([n.properties[e]])),p(t,r);break;case"int32":t.write(i.from([n.properties[e]])),function(t,e){const i=f(e);c("write4ByteNumber: %o",i),t.write(i)}(t,r);break;case"var":t.write(i.from([n.properties[e]])),w(t,r);break;case"string":t.write(i.from([n.properties[e]])),b(t,r);break;case"pair":Object.getOwnPropertyNames(r).forEach((o=>{const s=r[o];Array.isArray(s)?s.forEach((r=>{t.write(i.from([n.properties[e]])),x(t,o.toString(),r.toString())})):(t.write(i.from([n.properties[e]])),x(t,o.toString(),s.toString()))}));break;default:return t.emit("error",new Error(`Invalid property ${e} value: ${r}`)),!1}}function R(t,e,i){w(t,i);for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)&&null!==e[i]){const n=e[i];if(Array.isArray(n))for(let e=0;e=1.5*i;return Math.round(t/i)+" "+n+(r?"s":"")}e.exports=function(t,e){e=e||{};var i=typeof t;if("string"===i&&t.length>0)return function(t){if(!((t=String(t)).length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(e){var i=parseFloat(e[1]);switch((e[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}}}}(t);if("number"===i&&isFinite(t))return e.long?function(t){var e=Math.abs(t);return e>=s?a(t,e,s,"day"):e>=o?a(t,e,o,"hour"):e>=r?a(t,e,r,"minute"):e>=n?a(t,e,n,"second"):t+" ms"}(t):function(t){var e=Math.abs(t);return e>=s?Math.round(t/s)+"d":e>=o?Math.round(t/o)+"h":e>=r?Math.round(t/r)+"m":e>=n?Math.round(t/n)+"s":t+"ms"}(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))}},{}],46:[function(t,e,i){const n=t("./lib/number-allocator.js");e.exports.NumberAllocator=n},{"./lib/number-allocator.js":47}],47:[function(t,e,i){"use strict";const n=t("js-sdsl").Set,r=t("debug")("number-allocator:trace"),o=t("debug")("number-allocator:error");function s(t,e){this.low=t,this.high=e}function a(t,e){if(!(this instanceof a))return new a(t,e);this.min=t,this.max=e,this.ss=new n([],((t,e)=>t.compare(e))),r("Create"),this.clear()}s.prototype.equals=function(t){return this.low===t.low&&this.high===t.high},s.prototype.compare=function(t){return this.lowt)return!1;if(i.low===t)return++i.low,r("use():"+t),!0;if(i.high===t)return--i.high,r("use():"+t),!0;const n=i.low;return i.low=t+1,this.ss.insert(new s(n,t-1)),r("use():"+t),!0}return r("use():failed"),!1},a.prototype.free=function(t){if(tthis.max)return void o("free():"+t+" is out of range");const e=new s(t,t),i=this.ss.lowerBound(e);if(i){if(i.low<=t&&t<=i.high)return void o("free():"+t+" has already been vacant");if(i===this.ss.front())t+1===i.low?--i.low:this.ss.insert(e);else{const n=this.ss.reverseLowerBound(e);n.high+1===t?t+1===i.low?(this.ss.eraseElementByValue(n),i.low=n.low):n.high=t:t+1===i.low?i.low=t:this.ss.insert(e)}}else{if(i===this.ss.front())return void this.ss.insert(e);const n=this.ss.reverseLowerBound(e);n.high+1===t?n.high=t:this.ss.insert(e)}r("free():"+t)},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 t of this.ss)console.log(t)},e.exports=a},{debug:18,"js-sdsl":36}],48:[function(t,e,i){var n=t("wrappy");function r(t){var e=function(){return e.called?e.value:(e.called=!0,e.value=t.apply(this,arguments))};return e.called=!1,e}function o(t){var e=function(){if(e.called)throw new Error(e.onceError);return e.called=!0,e.value=t.apply(this,arguments)},i=t.name||"Function wrapped with `once`";return e.onceError=i+" shouldn't be called more than once",e.called=!1,e}e.exports=n(r),e.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(t,e,i){(function(t){(function(){"use strict";void 0===t||!t.version||0===t.version.indexOf("v0.")||0===t.version.indexOf("v1.")&&0!==t.version.indexOf("v1.8.")?e.exports={nextTick:function(e,i,n,r){if("function"!=typeof e)throw new TypeError('"callback" argument must be a function');var o,s,a=arguments.length;switch(a){case 0:case 1:return t.nextTick(e);case 2:return t.nextTick((function(){e.call(null,i)}));case 3:return t.nextTick((function(){e.call(null,i,n)}));case 4:return t.nextTick((function(){e.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"},m=h-1,w=Math.floor,b=String.fromCharCode;function x(t){throw new RangeError(y[t])}function k(t,e){for(var i=t.length,n=[];i--;)n[i]=e(t[i]);return n}function T(t,e){var i=t.split("@"),n="";return i.length>1&&(n=i[0]+"@",t=i[1]),n+k((t=t.replace(g,".")).split("."),e).join(".")}function A(t){for(var e,i,n=[],r=0,o=t.length;r=55296&&e<=56319&&r65535&&(e+=b((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+b(t)})).join("")}function P(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function C(t,e,i){var n=0;for(t=i?w(t/f):t>>1,t+=w(t/e);t>m*u>>1;n+=h)t=w(t/m);return w(n+(m+1)*t/(t+d))}function R(t){var e,i,n,r,o,s,a,c,d,f,p,v=[],g=t.length,y=0,m=128,b=72;for((i=t.lastIndexOf("-"))<0&&(i=0),n=0;n=128&&x("not-basic"),v.push(t.charCodeAt(n));for(r=i>0?i+1:0;r=g&&x("invalid-input"),((c=(p=t.charCodeAt(r++))-48<10?p-22:p-65<26?p-65:p-97<26?p-97:h)>=h||c>w((l-y)/s))&&x("overflow"),y+=c*s,!(c<(d=a<=b?1:a>=b+u?u:a-b));a+=h)s>w(l/(f=h-d))&&x("overflow"),s*=f;b=C(y-o,e=v.length+1,0==o),w(y/e)>l-m&&x("overflow"),m+=w(y/e),y%=e,v.splice(y++,0,m)}return S(v)}function _(t){var e,i,n,r,o,s,a,c,d,f,p,v,g,y,m,k=[];for(v=(t=A(t)).length,e=128,i=0,o=72,s=0;s=e&&pw((l-i)/(g=n+1))&&x("overflow"),i+=(a-e)*g,e=a,s=0;sl&&x("overflow"),p==e){for(c=i,d=h;!(c<(f=d<=o?1:d>=o+u?u:d-o));d+=h)m=c-f,y=h-f,k.push(b(P(f+m%y,0))),c=w(m/y);k.push(b(P(c,0))),o=C(i,g,n==r),i=0,++n}++i,++e}return k.join("")}if(a={version:"1.4.1",ucs2:{decode:A,encode:S},decode:R,encode:_,toASCII:function(t){return T(t,(function(t){return v.test(t)?"xn--"+_(t):t}))},toUnicode:function(t){return T(t,(function(t){return p.test(t)?R(t.slice(4).toLowerCase()):t}))}},r&&o)if(e.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(t,e,i){"use strict";function n(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.exports=function(t,e,i,o){e=e||"&",i=i||"=";var s={};if("string"!=typeof t||0===t.length)return s;var a=/\+/g;t=t.split(e);var c=1e3;o&&"number"==typeof o.maxKeys&&(c=o.maxKeys);var l=t.length;c>0&&l>c&&(l=c);for(var h=0;h=0?(u=v.substr(0,g),d=v.substr(g+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(t){return"[object Array]"===Object.prototype.toString.call(t)}},{}],53:[function(t,e,i){"use strict";var n=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};e.exports=function(t,e,i,a){return e=e||"&",i=i||"=",null===t&&(t=void 0),"object"==typeof t?o(s(t),(function(s){var a=encodeURIComponent(n(s))+i;return r(t[s])?o(t[s],(function(t){return a+encodeURIComponent(n(t))})).join(e):a+encodeURIComponent(n(t[s]))})).join(e):a?encodeURIComponent(n(a))+i+encodeURIComponent(n(t)):""};var r=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function o(t,e){if(t.map)return t.map(e);for(var i=[],n=0;n2?"one of ".concat(e," ").concat(t.slice(0,i-1).join(", "),", or ")+t[i-1]:2===i?"one of ".concat(e," ").concat(t[0]," or ").concat(t[1]):"of ".concat(e," ").concat(t[0])}return"of ".concat(e," ").concat(String(t))}r("ERR_INVALID_OPT_VALUE",(function(t,e){return'The value "'+e+'" is invalid for option "'+t+'"'}),TypeError),r("ERR_INVALID_ARG_TYPE",(function(t,e,i){var n,r,s;if("string"==typeof e&&(r="not ",e.substr(0,r.length)===r)?(n="must not be",e=e.replace(/^not /,"")):n="must be",function(t,e,i){return(void 0===i||i>t.length)&&(i=t.length),t.substring(i-e.length,i)===e}(t," argument"))s="The ".concat(t," ").concat(n," ").concat(o(e,"type"));else{var a=function(t,e,i){return"number"!=typeof i&&(i=0),!(i+".".length>t.length)&&-1!==t.indexOf(".",i)}(t)?"property":"argument";s='The "'.concat(t,'" ').concat(a," ").concat(n," ").concat(o(e,"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(t){return"The "+t+" method is not implemented"})),r("ERR_STREAM_PREMATURE_CLOSE","Premature close"),r("ERR_STREAM_DESTROYED",(function(t){return"Cannot call "+t+" 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(t){return"Unknown encoding: "+t}),TypeError),r("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),e.exports.codes=n},{}],56:[function(t,e,i){(function(i){(function(){"use strict";var n=Object.keys||function(t){var e=[];for(var i in t)e.push(i);return e};e.exports=l;var r=t("./_stream_readable"),o=t("./_stream_writable");t("inherits")(l,r);for(var s=n(o.prototype),a=0;a0)if("string"==typeof e||a.objectMode||Object.getPrototypeOf(e)===c.prototype||(e=function(t){return c.from(t)}(e)),n)a.endEmitted?k(t,new x):C(t,a,e,!0);else if(a.ended)k(t,new w);else{if(a.destroyed)return!1;a.reading=!1,a.decoder&&!i?(e=a.decoder.write(e),a.objectMode||0!==e.length?C(t,a,e,!1):L(t,a)):C(t,a,e,!1)}else n||(a.reading=!1,L(t,a));return!a.ended&&(a.lengthe.highWaterMark&&(e.highWaterMark=function(t){return t>=R?t=R:(t--,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t++),t}(t)),t<=e.length?t:e.ended?e.length:(e.needReadable=!0,0))}function E(t){var e=t._readableState;o("emitReadable",e.needReadable,e.emittedReadable),e.needReadable=!1,e.emittedReadable||(o("emitReadable",e.flowing),e.emittedReadable=!0,i.nextTick(I,t))}function I(t){var e=t._readableState;o("emitReadable_",e.destroyed,e.length,e.ended),e.destroyed||!e.length&&!e.ended||(t.emit("readable"),e.emittedReadable=!1),e.needReadable=!e.flowing&&!e.ended&&e.length<=e.highWaterMark,O(t)}function L(t,e){e.readingMore||(e.readingMore=!0,i.nextTick(M,t,e))}function M(t,e){for(;!e.reading&&!e.ended&&(e.length0,e.resumeScheduled&&!e.paused?e.flowing=!0:t.listenerCount("data")>0&&t.resume()}function B(t){o("readable nexttick read 0"),t.read(0)}function N(t,e){o("resume",e.reading),e.reading||t.read(0),e.resumeScheduled=!1,t.emit("resume"),O(t),e.flowing&&!e.reading&&t.read(0)}function O(t){var e=t._readableState;for(o("flow",e.flowing);e.flowing&&null!==t.read(););}function z(t,e){return 0===e.length?null:(e.objectMode?i=e.buffer.shift():!t||t>=e.length?(i=e.decoder?e.buffer.join(""):1===e.buffer.length?e.buffer.first():e.buffer.concat(e.length),e.buffer.clear()):i=e.buffer.consume(t,e.decoder),i);var i}function F(t){var e=t._readableState;o("endReadable",e.endEmitted),e.endEmitted||(e.ended=!0,i.nextTick(j,e,t))}function j(t,e){if(o("endReadableNT",t.endEmitted,t.length),!t.endEmitted&&0===t.length&&(t.endEmitted=!0,e.readable=!1,e.emit("end"),t.autoDestroy)){var i=e._writableState;(!i||i.autoDestroy&&i.finished)&&e.destroy()}}function H(t,e){for(var i=0,n=t.length;i=e.highWaterMark:e.length>0)||e.ended))return o("read: emitReadable",e.length,e.ended),0===e.length&&e.ended?F(this):E(this),null;if(0===(t=_(t,e))&&e.ended)return 0===e.length&&F(this),null;var n,r=e.needReadable;return o("need readable",r),(0===e.length||e.length-t0?z(t,e):null)?(e.needReadable=e.length<=e.highWaterMark,t=0):(e.length-=t,e.awaitDrain=0),0===e.length&&(e.ended||(e.needReadable=!0),i!==t&&e.ended&&F(this)),null!==n&&this.emit("data",n),n},S.prototype._read=function(t){k(this,new b("_read()"))},S.prototype.pipe=function(t,e){var n=this,r=this._readableState;switch(r.pipesCount){case 0:r.pipes=t;break;case 1:r.pipes=[r.pipes,t];break;default:r.pipes.push(t)}r.pipesCount+=1,o("pipe count=%d opts=%j",r.pipesCount,e);var a=e&&!1===e.end||t===i.stdout||t===i.stderr?v:c;function c(){o("onend"),t.end()}r.endEmitted?i.nextTick(a):n.once("end",a),t.on("unpipe",(function e(i,s){o("onunpipe"),i===n&&s&&!1===s.hasUnpiped&&(s.hasUnpiped=!0,o("cleanup"),t.removeListener("close",f),t.removeListener("finish",p),t.removeListener("drain",l),t.removeListener("error",d),t.removeListener("unpipe",e),n.removeListener("end",c),n.removeListener("end",v),n.removeListener("data",u),h=!0,!r.awaitDrain||t._writableState&&!t._writableState.needDrain||l())}));var l=function(t){return function(){var e=t._readableState;o("pipeOnDrain",e.awaitDrain),e.awaitDrain&&e.awaitDrain--,0===e.awaitDrain&&s(t,"data")&&(e.flowing=!0,O(t))}}(n);t.on("drain",l);var h=!1;function u(e){o("ondata");var i=t.write(e);o("dest.write",i),!1===i&&((1===r.pipesCount&&r.pipes===t||r.pipesCount>1&&-1!==H(r.pipes,t))&&!h&&(o("false write response, pause",r.awaitDrain),r.awaitDrain++),n.pause())}function d(e){o("onerror",e),v(),t.removeListener("error",d),0===s(t,"error")&&k(t,e)}function f(){t.removeListener("finish",p),v()}function p(){o("onfinish"),t.removeListener("close",f),v()}function v(){o("unpipe"),n.unpipe(t)}return n.on("data",u),function(t,e,i){if("function"==typeof t.prependListener)return t.prependListener(e,i);t._events&&t._events[e]?Array.isArray(t._events[e])?t._events[e].unshift(i):t._events[e]=[i,t._events[e]]:t.on(e,i)}(t,"error",d),t.once("close",f),t.once("finish",p),t.emit("pipe",n),r.flowing||(o("pipe resume"),n.resume()),t},S.prototype.unpipe=function(t){var e=this._readableState,i={hasUnpiped:!1};if(0===e.pipesCount)return this;if(1===e.pipesCount)return t&&t!==e.pipes||(t||(t=e.pipes),e.pipes=null,e.pipesCount=0,e.flowing=!1,t&&t.emit("unpipe",this,i)),this;if(!t){var n=e.pipes,r=e.pipesCount;e.pipes=null,e.pipesCount=0,e.flowing=!1;for(var o=0;o0,!1!==r.flowing&&this.resume()):"readable"===t&&(r.endEmitted||r.readableListening||(r.readableListening=r.needReadable=!0,r.flowing=!1,r.emittedReadable=!1,o("on readable",r.length,r.reading),r.length?E(this):r.reading||i.nextTick(B,this))),n},S.prototype.addListener=S.prototype.on,S.prototype.removeListener=function(t,e){var n=a.prototype.removeListener.call(this,t,e);return"readable"===t&&i.nextTick(D,this),n},S.prototype.removeAllListeners=function(t){var e=a.prototype.removeAllListeners.apply(this,arguments);return"readable"!==t&&void 0!==t||i.nextTick(D,this),e},S.prototype.resume=function(){var t=this._readableState;return t.flowing||(o("resume"),t.flowing=!t.readableListening,function(t,e){e.resumeScheduled||(e.resumeScheduled=!0,i.nextTick(N,t,e))}(this,t)),t.paused=!1,this},S.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},S.prototype.wrap=function(t){var e=this,i=this._readableState,n=!1;for(var r in t.on("end",(function(){if(o("wrapped end"),i.decoder&&!i.ended){var t=i.decoder.end();t&&t.length&&e.push(t)}e.push(null)})),t.on("data",(function(r){o("wrapped data"),i.decoder&&(r=i.decoder.write(r)),(!i.objectMode||null!=r)&&(i.objectMode||r&&r.length)&&(e.push(r)||(n=!0,t.pause()))})),t)void 0===this[r]&&"function"==typeof t[r]&&(this[r]=function(e){return function(){return t[e].apply(t,arguments)}}(r));for(var s=0;s-1))throw new x(t);return this._writableState.defaultEncoding=t,this},Object.defineProperty(S.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(S.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),S.prototype._write=function(t,e,i){i(new v("_write()"))},S.prototype._writev=null,S.prototype.end=function(t,e,n){var r=this._writableState;return"function"==typeof t?(n=t,t=null,e=null):"function"==typeof e&&(n=e,e=null),null!=t&&this.write(t,e),r.corked&&(r.corked=1,this.uncork()),r.ending||function(t,e,n){e.ending=!0,I(t,e),n&&(e.finished?i.nextTick(n):t.once("finish",n)),e.ended=!0,t.writable=!1}(this,r,n),this},Object.defineProperty(S.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(S.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(t){this._writableState&&(this._writableState.destroyed=t)}}),S.prototype.destroy=u.destroy,S.prototype._undestroy=u.undestroy,S.prototype._destroy=function(t,e){e(t)}}).call(this)}).call(this,t("_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(t,e,i){(function(i){(function(){"use strict";var n;function r(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}var o=t("./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(t,e){return{value:t,done:e}}function p(t){var e=t[s];if(null!==e){var i=t[d].read();null!==i&&(t[h]=null,t[s]=null,t[a]=null,e(f(i,!1)))}}var v=Object.getPrototypeOf((function(){})),g=Object.setPrototypeOf((r(n={get stream(){return this[d]},next:function(){var t=this,e=this[c];if(null!==e)return Promise.reject(e);if(this[l])return Promise.resolve(f(void 0,!0));if(this[d].destroyed)return new Promise((function(e,n){i.nextTick((function(){t[c]?n(t[c]):e(f(void 0,!0))}))}));var n,r=this[h];if(r)n=new Promise(function(t,e){return function(i,n){t.then((function(){e[l]?i(f(void 0,!0)):e[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 t=this;return new Promise((function(e,i){t[d].destroy(null,(function(t){t?i(t):e(f(void 0,!0))}))}))})),n),v);e.exports=function(t){var e,n=Object.create(g,(r(e={},d,{value:t,writable:!0}),r(e,s,{value:null,writable:!0}),r(e,a,{value:null,writable:!0}),r(e,c,{value:null,writable:!0}),r(e,l,{value:t._readableState.endEmitted,writable:!0}),r(e,u,{value:function(t,e){var i=n[d].read();i?(n[h]=null,n[s]=null,n[a]=null,t(f(i,!1))):(n[s]=t,n[a]=e)},writable:!0}),e));return n[h]=null,o(t,(function(t){if(t&&"ERR_STREAM_PREMATURE_CLOSE"!==t.code){var e=n[a];return null!==e&&(n[h]=null,n[s]=null,n[a]=null,e(t)),void(n[c]=t)}var i=n[s];null!==i&&(n[h]=null,n[s]=null,n[a]=null,i(f(void 0,!0))),n[l]=!0})),t.on("readable",function(t){i.nextTick(p,t)}.bind(null,n)),n}}).call(this)}).call(this,t("_process"))},{"./end-of-stream":64,_process:50}],62:[function(t,e,i){"use strict";function n(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function r(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function o(t,e){for(var i=0;i0?this.tail.next=e:this.head=e,this.tail=e,++this.length}},{key:"unshift",value:function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length}},{key:"shift",value:function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(t){if(0===this.length)return"";for(var e=this.head,i=""+e.data;e=e.next;)i+=t+e.data;return i}},{key:"concat",value:function(t){if(0===this.length)return s.alloc(0);for(var e,i,n,r=s.allocUnsafe(t>>>0),o=this.head,a=0;o;)e=o.data,i=r,n=a,s.prototype.copy.call(e,i,n),a+=o.data.length,o=o.next;return r}},{key:"consume",value:function(t,e){var i;return tr.length?r.length:t;if(o===r.length?n+=r:n+=r.slice(0,t),0==(t-=o)){o===r.length?(++i,e.next?this.head=e.next:this.head=this.tail=null):(this.head=e,e.data=r.slice(o));break}++i}return this.length-=i,n}},{key:"_getBuffer",value:function(t){var e=s.allocUnsafe(t),i=this.head,n=1;for(i.data.copy(e),t-=i.data.length;i=i.next;){var r=i.data,o=t>r.length?r.length:t;if(r.copy(e,e.length-t,0,o),0==(t-=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,e}},{key:c,value:function(t,e){return a(this,function(t){for(var e=1;e0,(function(t){h||(h=t),t&&d.forEach(c),o||(d.forEach(c),u(h))}))}));return i.reduce(l)}},{"../../../errors":55,"./end-of-stream":64}],67:[function(t,e,i){"use strict";var n=t("../../../errors").codes.ERR_INVALID_OPT_VALUE;e.exports={getHighWaterMark:function(t,e,i,r){var o=function(t,e,i){return null!=t.highWaterMark?t.highWaterMark:e?t[i]:null}(e,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 t.objectMode?16:16384}}},{"../../../errors":55}],68:[function(t,e,i){e.exports=t("events").EventEmitter},{events:22}],69:[function(t,e,i){(i=e.exports=t("./lib/_stream_readable.js")).Stream=i,i.Readable=i,i.Writable=t("./lib/_stream_writable.js"),i.Duplex=t("./lib/_stream_duplex.js"),i.Transform=t("./lib/_stream_transform.js"),i.PassThrough=t("./lib/_stream_passthrough.js"),i.finished=t("./lib/internal/streams/end-of-stream.js"),i.pipeline=t("./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(t,e,i){"use strict";e.exports=function(){if("function"!=typeof arguments[0])throw new Error("callback needed");if("number"!=typeof arguments[1])throw new Error("interval needed");var t;if(arguments.length>0){t=new Array(arguments.length-2);for(var e=0;e>5==6?2:t>>4==14?3:t>>3==30?4:t>>6==2?-1:-2}function a(t){var e=this.lastTotal-this.lastNeed,i=function(t,e,i){if(128!=(192&e[0]))return t.lastNeed=0,"�";if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"�";if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"�"}}(this,t);return void 0!==i?i:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),void(this.lastNeed-=t.length))}function c(t,e){if((t.length-e)%2==0){var i=t.toString("utf16le",e);if(i){var n=i.charCodeAt(i.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],i.slice(0,-1)}return i}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function l(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var i=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,i)}return e}function h(t,e){var i=(t.length-e)%3;return 0===i?t.toString("base64",e):(this.lastNeed=3-i,this.lastTotal=3,1===i?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-i))}function u(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function d(t){return t.toString(this.encoding)}function f(t){return t&&t.length?this.write(t):""}i.StringDecoder=o,o.prototype.write=function(t){if(0===t.length)return"";var e,i;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return"";i=this.lastNeed,this.lastNeed=0}else i=0;return i=0?(r>0&&(t.lastNeed=r-1),r):--n=0?(r>0&&(t.lastNeed=r-2),r):--n=0?(r>0&&(2===r?r=0:t.lastNeed=r-3),r):0}(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=i;var n=t.length-(i-this.lastNeed);return t.copy(this.lastChar,0,n),t.toString("utf8",e,n)},o.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length}},{"safe-buffer":73}],76:[function(t,e,i){"use strict";var n=t("punycode"),r=t("./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=w,i.resolve=function(t,e){return w(t,!1,!0).resolve(e)},i.resolveObject=function(t,e){return t?w(t,!1,!0).resolveObject(e):e},i.format=function(t){return r.isString(t)&&(t=w(t)),t instanceof o?t.format():o.prototype.format.call(t)},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},g={javascript:!0,"javascript:":!0},y={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},m=t("querystring");function w(t,e,i){if(t&&r.isObject(t)&&t instanceof o)return t;var n=new o;return n.parse(t,e,i),n}o.prototype.parse=function(t,e,i){if(!r.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var o=t.indexOf("?"),a=-1!==o&&o127?M+="x":M+=L[D];if(!M.match(f)){var N=E.slice(0,C),O=E.slice(C+1),z=L.match(p);z&&(N.push(z[1]),O.unshift(z[2])),O.length&&(w="/"+O.join(".")+w),this.hostname=N.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),_||(this.hostname=n.toASCII(this.hostname));var F=this.port?":"+this.port:"",j=this.hostname||"";this.host=j+F,this.href+=this.host,_&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==w[0]&&(w="/"+w))}if(!v[k])for(C=0,I=h.length;C0)&&i.host.split("@"))&&(i.auth=_.shift(),i.host=i.hostname=_.shift())),i.search=t.search,i.query=t.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(!T.length)return i.pathname=null,i.search?i.path="/"+i.search:i.path=null,i.href=i.format(),i;for(var S=T.slice(-1)[0],P=(i.host||t.host||T.length>1)&&("."===S||".."===S)||""===S,C=0,R=T.length;R>=0;R--)"."===(S=T[R])?T.splice(R,1):".."===S?(T.splice(R,1),C++):C&&(T.splice(R,1),C--);if(!x&&!k)for(;C--;C)T.unshift("..");!x||""===T[0]||T[0]&&"/"===T[0].charAt(0)||T.unshift(""),P&&"/"!==T.join("/").substr(-1)&&T.push("");var _,E=""===T[0]||T[0]&&"/"===T[0].charAt(0);return A&&(i.hostname=i.host=E?"":T.length?T.shift():"",(_=!!(i.host&&i.host.indexOf("@")>0)&&i.host.split("@"))&&(i.auth=_.shift(),i.host=i.hostname=_.shift())),(x=x||i.host&&T.length)&&!E&&T.unshift(""),T.length?i.pathname=T.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=t.auth||i.auth,i.slashes=i.slashes||t.slashes,i.href=i.format(),i},o.prototype.parseHost=function(){var t=this.host,e=a.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},{"./util":77,punycode:51,querystring:54}],77:[function(t,e,i){"use strict";e.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},{}],78:[function(t,e,n){(function(t){(function(){function i(e){try{if(!t.localStorage)return!1}catch(t){return!1}var i=t.localStorage[e];return null!=i&&"true"===String(i).toLowerCase()}e.exports=function(t,e){if(i("noDeprecation"))return t;var n=!1;return function(){if(!n){if(i("throwDeprecation"))throw new Error(e);i("traceDeprecation")?console.trace(e):console.warn(e),n=!0}return t.apply(this,arguments)}}}).call(this)}).call(this,void 0!==i.g?i.g:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],79:[function(t,e,i){e.exports=function t(e,i){if(e&&i)return t(e)(i);if("function"!=typeof e)throw new TypeError("need wrapper function");return Object.keys(e).forEach((function(t){n[t]=e[t]})),n;function n(){for(var t=new Array(arguments.length),i=0;i0)for(var i=0,r=arguments.length;i1)i=e;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=t(i,n.value,r),n=n.next;return i},n.prototype.reduceReverse=function(t,e){var i,n=this.tail;if(arguments.length>1)i=e;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=t(i,n.value,r),n=n.prev;return i},n.prototype.toArray=function(){for(var t=new Array(this.length),e=0,i=this.head;null!==i;e++)t[e]=i.value,i=i.next;return t},n.prototype.toArrayReverse=function(){for(var t=new Array(this.length),e=0,i=this.tail;null!==i;e++)t[e]=i.value,i=i.prev;return t},n.prototype.slice=function(t,e){(e=e||this.length)<0&&(e+=this.length),(t=t||0)<0&&(t+=this.length);var i=new n;if(ethis.length&&(e=this.length);for(var r=0,o=this.head;null!==o&&rthis.length&&(e=this.length);for(var r=this.length,o=this.tail;null!==o&&r>e;r--)o=o.prev;for(;null!==o&&r>t;r--,o=o.prev)i.push(o.value);return i},n.prototype.splice=function(t,e,...i){t>this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(var n=0,o=this.head;null!==o&&n{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{"use strict";function t(t,e){const i=e||new Path2D;let n=t.calculative.borderRadius||0,r=n;const{x:o,y:s,width:a,height:c,ex:l,ey:h}=t.calculative.worldRect;n<1&&(n*=a,r*=c);let u=nxn,activityDiagram:()=>Nn,activityDiagramByCtx:()=>On,chartsPens:()=>ts,classPens:()=>Rn,flowAnchors:()=>tr,flowPens:()=>Zn,formPens:()=>go,ftaAnchors:()=>zo,ftaPens:()=>No,ftaPensbyCtx:()=>Oo,registerEcharts:()=>xr,registerHighcharts:()=>kr,registerLightningChart:()=>Tr,sequencePens:()=>In,sequencePensbyCtx:()=>Ln}),i(173);const e=t;var r,o,s,a;!function(t){t[t.Node=0]="Node",t[t.Line=1]="Line"}(r||(r={})),function(t){t[t.None=0]="None",t[t.DisableEdit=1]="DisableEdit",t[t.DisableMove=2]="DisableMove",t[t.DisableScale=3]="DisableScale",t[t.DisableMoveScale=4]="DisableMoveScale",t[t.Disable=10]="Disable"}(o||(o={})),function(t){t[t.Default=0]="Default",t[t.In=1]="In",t[t.Out=2]="Out"}(s||(s={})),function(t){t[t.None=0]="None",t[t.Linear=1]="Linear",t[t.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"],h=["paddingTop","paddingRight","paddingBottom","paddingLeft","flipX","flipY","visible","showChild"],u=["iconLeft","iconTop","iconRotate"];var d;!function(t){t[t.Normal=0]="Normal",t[t.Beads=1]="Beads",t[t.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,g,y,m;!function(t){t[t.None=0]="None",t[t.LineAnchor=1]="LineAnchor",t[t.NodeAnchor=2]="NodeAnchor",t[t.Line=3]="Line",t[t.Node=4]="Node",t[t.Resize=5]="Resize",t[t.Rotate=6]="Rotate",t[t.LineAnchorPrev=7]="LineAnchorPrev",t[t.LineAnchorNext=8]="LineAnchorNext"}(v||(v={})),function(t){t[t.None=0]="None",t[t.Translate=1]="Translate",t[t.Select=2]="Select",t[t.Resize=3]="Resize",t[t.AddAnchor=4]="AddAnchor"}(g||(g={})),function(t){t[t.None=0]="None",t[t.Down=1]="Down",t[t.Translate=2]="Translate"}(y||(y={})),function(t){t[t.None=-1]="None",t[t.Up=0]="Up",t[t.Right=1]="Right",t[t.Bottom=2]="Bottom",t[t.Left=3]="Left"}(m||(m={}));const w=["nw-resize","ne-resize","se-resize","sw-resize"],b=["n-resize","e-resize","s-resize","w-resize"],x=["curve","polyline","line"],k=["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 T,A;function S(t,e,i){if(!e||e%360==0)return;const n=e*Math.PI/180,r=(t.x-i.x)*Math.cos(n)-(t.y-i.y)*Math.sin(n)+i.x,o=(t.x-i.x)*Math.sin(n)+(t.y-i.y)*Math.cos(n)+i.y;t.x=r,t.y=o,t.prev&&S(t.prev,e,i),t.next&&S(t.next,e,i)}function P(t,e,i=5){return t.x>e.x-i&&t.xe.y-i&&t.y0&&n>0?r=180-r:i<0&&n>0?r+=180:i<0&&n<0&&(r=360-r),r}function _(t,e){const i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)}function E(t,e,i){t&&(t.x+=e,t.y+=i,t.next&&(t.next.x+=e,t.next.y+=i),t.prev&&(t.prev.x+=e,t.prev.y+=i))}function I(t,e){return t.anchorId===e.anchorId&&t.connectTo===e.connectTo}!function(t){t[t.Mirror=0]="Mirror",t[t.Bilateral=1]="Bilateral",t[t.Free=2]="Free"}(T||(T={})),function(t){t[t.Default=0]="Default",t[t.In=1]="In",t[t.Out=2]="Out",t[t.DisableConnected=3]="DisableConnected",t[t.DisableConnectTo=4]="DisableConnectTo",t[t.Disable=10]="Disable"}(A||(A={}));const L="1.0.0",M={version:L,path2dDraws:{},canvasDraws:{},anchors:{},htmlElements:{}};function D(t){Object.assign(M.path2dDraws,t)}function B(t){Object.assign(M.canvasDraws,t)}function N(t){Object.assign(M.anchors,t)}var O;!function(t){t[t.None=-1]="None",t[t.Document=0]="Document",t[t.Canvas=1]="Canvas"}(O||(O={}));const z={fontFamily:'"Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial',fontSize:12,lineHeight:1.5,textAlign:"center",textBaseline:"middle",color:"#222222",activeColor:"#278df8",hoverColor:"rgba(39,141,248,0.50)",anchorColor:"#278DF8",hoverAnchorColor:"#FF4101",anchorRadius:4,anchorBackground:"#fff",dockColor:"rgba(39,141,248,0.50)",dockPenColor:"#1890FF",dragColor:"#1890ff",rotateCursor:"rotate.cur",hoverCursor:"pointer",minScale:.1,maxScale:10,keydown:O.Document,gridSize:20,gridColor:"#e2e2e2",ruleColor:"#888888",drawingLineName:"curve",interval:30,animateInterval:30,autoPolyline:!0,autoAnchor:!0,animateColor:"#ff4d4f",ruleLineColor:"#FF4101",defaultAnchors:[{x:.5,y:0},{x:1,y:.5},{x:.5,y:1},{x:0,y:.5}],measureTextWidth:!0,moveConnectedLine:!0,mouseRightActive:!0,disableClipboard:!1,drawingLineLength:0,disableTouchPadScale:!1};var F;!function(t){t[t.Add=0]="Add",t[t.Update=1]="Update",t[t.Delete=2]="Delete"}(F||(F={}));function j(t){const{paddingTop:e,paddingBottom:i,paddingLeft:n,paddingRight:r,worldRect:o,canvas:s}=t.calculative;let{textLeft:a,textTop:c,textWidth:l,textHeight:h}=t.calculative,u=n,d=e;a&&Math.abs(a)<1&&(a*=o.width),c&&Math.abs(c)<1&&(c*=o.height);const f=o.width-n-r-(("right"===t.textAlign?-a:a)||0),p=o.height-e-i-(("bottom"===t.textBaseline?-c:c)||0);l&&l<1&&(l*=o.width),h&&h<1&&(h*=o.height),l{const r=t.measureText(n).width;e.calculative.textLineWidths.push(r),i1?o:1;switch(t.whiteSpace){case"nowrap":if(!1!==t.ellipsis){const n=q(e.split(""),t);n[0]&&(i.push(n[0]),n.length>1&&V(i))}else i.push(e);break;case"pre-line":i=e.split(/[\n]/g),!1!==t.ellipsis&&i.length>s&&(i=i.slice(0,s),V(i));break;default:const n=e.split(/[\n]/g);let r=0;t:for(const e of n){let n=q("break-all"===t.whiteSpace?e.split(""):W(e),t);if(0===n.length&&(n=[""]),0!=t.ellipsis)for(const t of n){if(r++,r>s){V(i);break t}i.push(t)}else i.push(...n)}}const a=t.calculative.keepDecimal;return null!=a&&i.forEach(((t,e)=>{const n=Number(t);isNaN(n)||(i[e]=n.toFixed(a))})),t.calculative.textLines=i,i}function W(t=""){const e=[];let i="";for(let n=0;n126?(i&&(e.push(i),i=""),e.push(t[n])):i+=t[n]}return i&&e.push(i),e}function q(t,e){const i=e.calculative.canvas,n=i.offscreen.getContext("2d"),{fontStyle:r,fontWeight:o,fontSize:s,fontFamily:a,lineHeight:c}=e.calculative;n.save();const l=[];let h=t[0]||"";for(let u=1;u{i.push(K(t,e))})),i}if("object"==typeof t){if(null===t)return null;if(t.constructor===RegExp)return t;const i={};for(const n in t)["canvas","lastFrame"].includes(n)||t[n]instanceof HTMLImageElement||t[n]instanceof HTMLMediaElement||("calculative"!==n||e)&&(i[n]="singleton"!==n?K(t[n],e):e?{}:t[n]);return i}return t}function Y(t,e,i){if(Array.isArray(t)){const n=[];return t.forEach((t=>{n.push(Y(t,e,i))})),n}if("object"==typeof t){if(null===t)return null;for(const n in t)t[n]=n===e?Number(t[n])*i:Y(t[n],e,i);return t}return t}const X={};function $(t,e,i){if(!X[e.fromArrow])return;const n=Kt(e),{x:r,y:o}=n,s={x:r,y:o};if(s.step=(e.fromArrowSize||10)*i.data.scale,n.next)s.rotate=R(n.next,n)+90;else{const t=e.calculative.worldAnchors[1];if(!t)return;t.prev?s.rotate=R(t.prev,n)+90:s.rotate=R(t,n)+90}t.save(),t.beginPath();const a=e.fromArrowColor||e.calculative.color;a&&(t.strokeStyle=a),X[e.fromArrow](t,e,i,s),t.restore()}function G(t,e,i){if(!X[e.toArrow]||e.calculative.worldAnchors.length<2)return;t.save();const n=Yt(e),{x:r,y:o}=n,s={x:r,y:o};if(s.step=(e.toArrowSize||10)*i.data.scale,n.prev)s.rotate=R(n.prev,n)+90;else{const t=e.calculative.worldAnchors[e.calculative.worldAnchors.length-2];t.next?s.rotate=R(t.next,n)+90:s.rotate=R(t,n)+90}t.beginPath();const a=e.toArrowColor||e.calculative.color;a&&(t.strokeStyle=a),X[e.toArrow](t,e,i,s),t.restore()}function Q(t){const e=parseInt,i=Math.round;let n=t.length,r={};if(n>9){const[i,o,s,a]=t=t.split(",");if(n=t.length,n<3||n>4)return null;r.r=e("a"==i[3]?i.slice(5):i.slice(4)),r.g=e(o),r.b=e(s),r.a=a?parseFloat(a):-1}else{if(8==n||6==n||n<4)return null;n<6&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(n>4?t[4]+t[4]:"")),t=e(t.slice(1),16),9==n||5==n?(r.r=t>>24&255,r.g=t>>16&255,r.b=t>>8&255,r.a=i((255&t)/.255)/1e3):(r.r=t>>16,r.g=t>>8&255,r.b=255&t,r.a=-1)}return r}function J(t,e){const i=Q(t)||{r:0,g:0,b:0};return i.a<0?`rgba(${i.r},${i.g},${i.b},${e})`:`rgba(${i.r},${i.g},${i.b},${e+i.a})`}function Z(t,e){if(isNaN(t))return void console.warn("realValue not number");if("string"!=typeof e)return void console.warn("collection must be string");const[i,n]=[e[0],e[e.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=e.substring(1,e.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(t>o||"["===i&&t===o)&&(t=o)return void console.warn("startNum must less than endNum");if(t>=r&&t<=o)return!0}else if(t===+e)return!0;return!1}function et(){return(4294967296*(1+Math.random())|0).toString(16).substring(1)}function it(){return/Android|webOS|iPad|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)}X.triangleSolid=(t,e,i,n)=>{t.save(),t.translate(n.x,n.y),t.rotate(n.rotate*Math.PI/180),t.translate(-n.x,-n.y);const r=n.x-n.step;t.moveTo(r,n.y-n.step/4),t.lineTo(n.x,n.y),t.lineTo(r,n.y+n.step/4),t.closePath(),t.stroke(),t.fillStyle=t.strokeStyle,t.fill(),t.restore()},X.triangle=(t,e,i,n)=>{t.save(),t.lineWidth<2&&(t.lineWidth=2),t.translate(n.x,n.y),t.rotate(n.rotate*Math.PI/180),t.translate(-n.x,-n.y);const r=n.x-n.step;t.moveTo(r,n.y-n.step/4),t.lineTo(n.x,n.y),t.lineTo(r,n.y+n.step/4),t.closePath(),t.stroke(),t.fillStyle=i.data.background||"#ffffff",t.fill(),t.restore()},X.circleSolid=(t,e,i,n)=>{t.save(),t.translate(n.x,n.y),t.rotate(n.rotate*Math.PI/180),t.translate(-n.x,-n.y);const r=n.step/2;t.arc(n.x-r,n.y,r,0,2*Math.PI),t.stroke(),t.fillStyle=t.strokeStyle,t.fill(),t.restore()},X.circle=(t,e,i,n)=>{t.save(),t.translate(n.x,n.y),t.rotate(n.rotate*Math.PI/180),t.translate(-n.x,-n.y);const r=n.step/2;t.arc(n.x-r,n.y,r,0,2*Math.PI),t.stroke(),t.fillStyle=i.data.background||"#ffffff",t.fill(),t.restore()},X.diamondSolid=(t,e,i,n)=>{t.save(),t.translate(n.x,n.y),t.rotate(n.rotate*Math.PI/180),t.translate(-n.x,-n.y);const r=n.x-n.step,o=n.step/2;t.moveTo(r,n.y),t.lineTo(r+o,n.y-o/2),t.lineTo(n.x,n.y),t.lineTo(r+o,n.y+o/2),t.closePath(),t.stroke(),t.fillStyle=t.strokeStyle,t.fill(),t.restore()},X.diamond=(t,e,i,n)=>{t.save(),t.translate(n.x,n.y),t.rotate(n.rotate*Math.PI/180),t.translate(-n.x,-n.y);const r=n.x-n.step,o=n.step/2;t.moveTo(r,n.y),t.lineTo(r+o,n.y-o/2),t.lineTo(n.x,n.y),t.lineTo(r+o,n.y+o/2),t.closePath(),t.stroke(),t.fillStyle=i.data.background||"#ffffff",t.fill(),t.restore()},X.line=(t,e,i,n)=>{t.save(),t.translate(n.x,n.y),t.rotate(n.rotate*Math.PI/180),t.translate(-n.x,-n.y);const r=n.x-n.step;t.moveTo(r,n.y-n.step/3),t.lineTo(n.x,n.y),t.lineTo(r,n.y+n.step/3),t.stroke(),t.restore()},X.lineUp=(t,e,i,n)=>{t.save(),t.translate(n.x,n.y),t.rotate(n.rotate*Math.PI/180),t.translate(-n.x,-n.y);const r=n.x-n.step;t.moveTo(r,n.y-n.step/3),t.lineTo(n.x,n.y),t.stroke(),t.restore()},X.lineDown=(t,e,i,n)=>{t.save(),t.translate(n.x,n.y),t.rotate(n.rotate*Math.PI/180),t.translate(-n.x,-n.y);const r=n.x-n.step;t.moveTo(r,n.y+n.step/3),t.lineTo(n.x,n.y),t.stroke(),t.restore()},globalThis.pSBC=function(t,e,i,n){let r,o,s,a,c,l,h,u=Math.round,d="string"==typeof i;return"number"!=typeof t||t<-1||t>1||"string"!=typeof e||"r"!=e[0]&&"#"!=e[0]||i&&!d?null:(h=e.length>9,h=d?i.length>9||"c"==i&&!h:h,c=Q(e),a=t<0,l=i&&"c"!=i?Q(i):a?{r:0,g:0,b:0,a:-1}:{r:255,g:255,b:255,a:-1},a=1-(t=a?-1*t:t),c&&l?(n?(r=u(a*c.r+t*l.r),o=u(a*c.g+t*l.g),s=u(a*c.b+t*l.b)):(r=u((a*c.r**2+t*l.r**2)**.5),o=u((a*c.g**2+t*l.g**2)**.5),s=u((a*c.b**2+t*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*t: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 nt=t=>{let e=0,i=0,n=0,r=0;return"number"==typeof t?e=i=n=r=t:"string"==typeof t?e=i=n=r=parseInt(t,10):Array.isArray(t)&&(e=t[0],n=rt(t[1])?t[0]:t[1],r=rt(t[2])?t[0]:t[2],i=rt(t[3])?n:t[3]),[e,n,r,i]};function rt(t){return null==t}function ot(t,e){if(!t||!t.parentId||!t.calculative)return;const i=t.calculative.canvas.store.pens[t.parentId];return e&&ot(i,e)||i}function st(t,e){if(!t||!t.children)return[];const i=[];return t.children.forEach((t=>{const n=e.pens[t];n&&(i.push(n),i.push(...st(n,e)))})),i}function at(t){if("string"==typeof t&&t.startsWith("linear-gradient")){let e=t.slice(16,-2).split("deg,");if(e.length>1){let t=e[1].split("%,");const i=[];return t.forEach((t=>{if(/rgba?/.test(t)){let e=t.split(") ");i.push({color:ct(e[0]+")"),i:parseFloat(e[1])/100})}else{let e=t.split(" ");e.length>2?i.push({color:e[1],i:parseFloat(e[2])/100}):i.push({color:e[0],i:parseFloat(e[1])/100})}})),{angle:parseFloat(e[0]),colors:i}}return{angle:parseFloat(e[0]),colors:[]}}return{angle:0,colors:[]}}function ct(t){if(/rgba?/.test(t)){let e=t.split(",");if(e.length<3)return"";t="#";for(let i,n=0;i=e[n++];)n<4?(i=parseInt(i.replace(/[^\d]/gi,""),10).toString(16),t+=1==i.length?"0"+i:i):(i=i.replace(")",""),t+=parseInt(255*i+"").toString(16));t=t.toUpperCase()}return t}function lt(t,e,i,n){let r=function(t,e,i,n,r){let o=0;o=Math.PI/2-Math.atan2(n-e,i-t);const s=(t+i)/2,a=(e+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)]}(e[0].x,e[0].y,e[1].x,e[1].y,n),o=t.createLinearGradient(r[0],r[1],r[2],r[3]);return i.forEach((t=>{o.addColorStop(t.i,t.color)})),o}function ht(t,e,i){let n=[];e.calculative.gradientColorStop?n=e.calculative.gradientColorStop:(n=at(e.calculative.lineGradientColors).colors,e.calculative.gradientColorStop=n),t.strokeStyle=lt(t,i,n,e.calculative.lineWidth/2),t.beginPath(),t.moveTo(i[0].x,i[0].y),t.lineTo(i[1].x,i[1].y),t.stroke()}function ut(t,e,i){let n=Math.sqrt((i.x-e.x)*(i.x-e.x)+(i.y-e.y)*(i.y-e.y));return t{const r=e.calculative.textLineWidths[n];let o=0;"center"===m?o=(g-r)/2:"right"===m&&(o=g-r),t.fillText(i,p+o,v+(n+.55)*w)})),t.restore()}function xt(t,e,i){if(null==i)return;const{fontStyle:n,fontWeight:r,fontSize:o,fontFamily:s,lineHeight:a,canvas:c}=e.calculative,l=c.store;let h;t.save(),e.calculative.hover?h=e.hoverTextColor||e.hoverColor||l.options.hoverColor:e.calculative.active&&(h=e.activeTextColor||e.activeColor||l.options.activeColor),t.fillStyle=h||wt(e,l),t.font=Tt({fontStyle:n,fontWeight:r,fontFamily:s||l.options.fontFamily,fontSize:o,lineHeight:a});const u=t.measureText(i).width;let d,f;for(const n of e.calculative.worldAnchors){if(!f){f=n;continue}const e=_(f,n),r=Math.floor(e/u);d="";for(let t=0;t0?e.calculative.iconSize:n.width>n.height?n.height:n.width,t.font=Tt({fontSize:a,fontWeight:s,fontFamily:c}),t.fillStyle=e.calculative.iconColor||wt(e,i),e.calculative.iconRotate&&(t.translate(n.center.x,n.center.y),t.rotate(e.calculative.iconRotate*Math.PI/180),t.translate(-n.center.x,-n.center.y)),t.beginPath(),t.fillText(e.calculative.icon,r,o),t.restore()}function Tt({fontStyle:t="normal",textDecoration:e="normal",fontWeight:i="normal",fontSize:n=12,fontFamily:r="Arial",lineHeight:o=1}={}){return`${t} ${e} ${i} ${n}px/${o} ${r}`}function At(t,e){const{x:i,ex:n,y:r,ey:o}=e.calculative.worldRect||{};e.calculative.flipX&&(t.translate(i+n+.5,.5),t.scale(-1,1)),e.calculative.flipY&&(t.translate(.5,r+o+.5),t.scale(1,-1))}function St(t,e){const{x:i,y:n}=e.calculative.worldRect.center;t.translate(i,n);let r=e.calculative.rotate*Math.PI/180;(e.calculative.flipX||e.calculative.flipY)&&(r*=-1),t.rotate(r),t.translate(-i,-n)}function Pt(t,e){t.save(),t.translate(.5,.5),t.beginPath(),At(t,e),e.calculative.rotate&&"line"!==e.name&&St(t,e),e.calculative.lineWidth>1&&(t.lineWidth=e.calculative.lineWidth);const i=e.calculative.canvas.store;let n;!function(t,e,i){if(e.fillWorldTextRect){t.save(),t.fillStyle="#c3deb7";const{x:e,y:n,width:r,height:o}=i.calculative.worldTextRect;t.fillRect(e,n,r,o),t.restore()}}(t,i,e);let o=!0,s=!1;if(e.calculative.hover)t.strokeStyle=e.hoverColor||i.options.hoverColor,n=e.hoverBackground||i.options.hoverBackground,t.fillStyle=n,n&&(o=!1);else if(e.calculative.active)t.strokeStyle=e.activeColor||i.options.activeColor,n=e.activeBackground||i.options.activeBackground,t.fillStyle=n,n&&(o=!1);else if(e.calculative.isDock)e.type===r.Line?t.strokeStyle=i.options.dockPenColor:(n=J(i.options.dockPenColor,.2),t.fillStyle=n,n&&(o=!1));else{const r=e.calculative.strokeImg;if(e.calculative.strokeImage&&r)t.strokeStyle=t.createPattern(r,"repeat"),n=!0;else{let n;e.calculative.strokeType===a.Linear?e.calculative.lineGradientColors?"line"===e.name?s=!0:e.calculative.lineGradient?n=e.calculative.lineGradient:(n=function(t,e){const{x:i,y:n,ex:r,width:o,height:s,center:a}=e.calculative.worldRect;let c=[{x:r,y:n+s/2},{x:i,y:n+s/2}],l=o/2;o>s&&(l=s/2);const{angle:h,colors:u}=at(e.calculative.lineGradientColors);return c.forEach((t=>{S(t,h,a)})),lt(t,c,u,l)}(t,e),e.calculative.lineGradient=n):n=function(t,e){const{worldRect:i,lineGradientFromColor:n,lineGradientToColor:r,lineGradientAngle:o}=e.calculative;return yt(t,i,n,r,o)}(t,e):n=e.calculative.color||Lt(i),t.strokeStyle=n}}if(o){const r=e.calculative.backgroundImg;if(e.calculative.backgroundImage&&r)t.fillStyle=t.createPattern(r,"repeat"),n=!0;else{let r;e.calculative.bkType===a.Linear?e.calculative.gradientColors?"line"!==e.name&&(e.calculative.gradient?r=e.calculative.gradient:(r=function(t,e){const{x:i,y:n,ex:r,width:o,height:s,center:a}=e.calculative.worldRect;let c=[{x:r,y:n+s/2},{x:i,y:n+s/2}],l=o/2;o>s&&(l=s/2);const{angle:h,colors:u}=at(e.calculative.gradientColors);return c.forEach((t=>{S(t,h,a)})),lt(t,c,u,l)}(t,e),e.calculative.gradient=r)):r=function(t,e){const{worldRect:i,gradientFromColor:n,gradientToColor:r,gradientAngle:o}=e.calculative;return yt(t,i,n,r,o)}(t,e):e.calculative.bkType===a.Radial?e.calculative.gradientColors?e.calculative.radialGradient?r=e.calculative.radialGradient:(r=function(t,e){const{worldRect:i,gradientColors:n,gradientRadius:r}=e.calculative;if(!n)return;const{width:o,height:s,center:a}=i,{x:c,y:l}=a;let h=o;h{d.addColorStop(t.i,t.color)})),d}(t,e),e.calculative.radialGradient=r):r=function(t,e){const{worldRect:i,gradientFromColor:n,gradientToColor:r,gradientRadius:o}=e.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;dt(t,e,n,o?o[o.length-1]:i[r-1],i[r],i[r].curvePoints[0]),ht(t,e,[ut(n,i[r],i[r].curvePoints[0]),i[r].curvePoints[1]])}else ht(t,e,[i[r],i[r].curvePoints[0]]),ht(t,e,[i[r].curvePoints[0],i[r].curvePoints[1]]);let o=i[r].curvePoints.length-1;for(let n=1;n0&&t0&&t1&&(t.lineWidth=e.calculative.lineWidth);const n=e.calculative.canvas.store;let o;if(e.calculative.hover?(t.strokeStyle=e.hoverColor||n.options.hoverColor,t.fillStyle=e.hoverBackground||n.options.hoverBackground,o=e.hoverBackground||n.options.hoverBackground):e.calculative.active?(t.strokeStyle=e.activeColor||n.options.activeColor,t.fillStyle=e.activeBackground||n.options.activeBackground,o=e.activeBackground||n.options.activeBackground):(e.strokeImage?e.calculative.strokeImg&&(t.strokeStyle=t.createPattern(e.calculative.strokeImg,"repeat"),o=!0):t.strokeStyle=e.calculative.color||Lt(n),e.backgroundImage?e.calculative.backgroundImg&&(t.fillStyle=t.createPattern(e.calculative.backgroundImg,"repeat"),o=!0):(t.fillStyle=e.background,o=!!e.background)),Ct(t,e),Rt(t,e),le(t,e),e.calculative.lineDash&&t.setLineDash(e.calculative.lineDash),e.calculative.lineDashOffset&&(t.lineDashOffset=e.calculative.lineDashOffset),e.calculative.shadowColor&&(t.shadowColor=e.calculative.shadowColor,t.shadowOffsetX=e.calculative.shadowOffsetX,t.shadowOffsetY=e.calculative.shadowOffsetY,t.shadowBlur=e.calculative.shadowBlur),Et(!1,t,e,n,o),he(t,e),e.calculative.img?(t.save(),t.shadowColor="",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0,mt(t,e),t.restore()):e.calculative.icon&&kt(t,e),bt(t,e),e.type===r.Line&&e.fillTexts)for(const i of e.fillTexts)xt(t,e,i);t.restore()}function Et(t=!0,e,i,n,o){const s=t?n.path2dMap.get(i):M.path2dDraws[i.name];if(s){if(i.type===r.Line&&i.borderWidth){e.save(),e.beginPath();const t=i.calculative.lineWidth+i.calculative.borderWidth;e.lineWidth=t,e.strokeStyle=i.borderColor,s instanceof Path2D?(o&&e.fill(s),t&&e.stroke(s)):(s(i,e),o&&e.fill(),t&&e.stroke()),e.restore()}s instanceof Path2D?o&&e.fill(s):(e.save(),s(i,e),o&&e.fill(),e.restore());const t=i.calculative.progress;if(null!=t){e.save();const{x:r,y:o,width:a,height:c,ey:l}=i.calculative.worldRect,h=i.verticalProgress?e.createLinearGradient(r,l,r,o+c*(1-t)):e.createLinearGradient(r,o,r+a*t,o),u=i.calculative.progressColor||i.calculative.color||n.options.activeColor;h.addColorStop(0,u),h.addColorStop(1,u),h.addColorStop(1,"transparent"),e.fillStyle=h,s instanceof Path2D?e.fill(s):(s(i,e),e.fill()),e.restore()}i.calculative.lineWidth&&(s instanceof Path2D?e.stroke(s):(s(i,e),e.stroke())),i.type&&(i.calculative.animatePos&&(e.save(),It(e,i,n),s instanceof Path2D?e.stroke(s):(s(i,e),e.stroke()),e.restore()),i.fromArrow&&$(e,i,n),i.toArrow&&G(e,i,n),i.calculative.active&&!i.calculative.pencil&&Mt(e,i))}}function It(t,e,i){t.strokeStyle=e.animateColor||i.options.animateColor,e.calculative.animateLineWidth&&(t.lineWidth=e.calculative.animateLineWidth*i.data.scale);let n=0;switch(e.lineAnimateType){case d.Beads:e.animateReverse?t.lineDashOffset=e.calculative.animatePos:t.lineDashOffset=e.length-e.calculative.animatePos,n=e.calculative.lineWidth||5,n<5&&(n=5);const r=e.animateLineDash&&e.animateLineDash.map((t=>t*n/5));t.setLineDash(r||[n,2*n]);break;case d.Dot:e.animateReverse?t.lineDashOffset=e.calculative.animatePos:t.lineDashOffset=e.length-e.calculative.animatePos,n=e.calculative.animateDotSize||2*e.calculative.lineWidth||6,n<6&&(n=6),t.lineWidth=(e.calculative.animateLineWidth||n)*i.data.scale,t.setLineDash([.1,e.length]);break;default:e.animateReverse?t.setLineDash([0,e.length-e.calculative.animatePos+1,e.calculative.animatePos]):t.setLineDash([e.calculative.animatePos,e.length-e.calculative.animatePos])}}function Lt(t){const{data:e,options:i}=t;return e.color||i.color}function Mt(t,e){const i=e.calculative.canvas.store;t.save(),t.lineWidth=1,t.fillStyle=e.activeColor||i.options.activeColor,e.calculative.worldAnchors.forEach((i=>{!i.hidden&&!i.isTemp&&function(t,e,i){if(!e)return;const n=i.calculative.activeAnchor===e;let r=3;i.calculative.lineWidth>3&&(r=i.calculative.lineWidth),i.anchorRadius&&(r=i.anchorRadius),e.radius&&(r=e.radius),n?(e.prev&&(t.save(),t.strokeStyle="#4dffff",t.beginPath(),t.moveTo(e.prev.x,e.prev.y),t.lineTo(e.x,e.y),t.stroke(),t.restore(),t.save(),t.fillStyle="#ffffff",t.beginPath(),t.arc(e.prev.x,e.prev.y,r,0,2*Math.PI),t.fill(),t.stroke(),t.restore()),e.next&&(t.save(),t.strokeStyle="#4dffff",t.beginPath(),t.moveTo(e.x,e.y),t.lineTo(e.next.x,e.next.y),t.stroke(),t.restore(),t.save(),t.fillStyle="#ffffff",t.beginPath(),t.arc(e.next.x,e.next.y,r,0,2*Math.PI),t.fill(),t.stroke(),t.restore(),t.beginPath(),t.arc(e.x,e.y,r,0,2*Math.PI),t.fill(),t.stroke()),t.beginPath(),t.arc(e.x,e.y,r,0,2*Math.PI),t.fill(),t.stroke()):(t.save(),t.fillStyle="#ffffff",t.beginPath(),t.arc(e.x,e.y,r,0,2*Math.PI),t.fill(),t.stroke(),t.restore())}(t,i,e)})),t.restore()}function Dt(t){const e=t.calculative.canvas.store;let i={x:t.x,y:t.y};if(t.parentId){const n=e.pens[t.parentId];let r=n.calculative.worldRect;r||(r=Dt(n)),i.x=r.x+r.width*t.x,i.y=r.y+r.height*t.y,i.width=r.width*t.width,i.height=r.height*t.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),Te(i),i.rotate=r.rotate+t.rotate,ke(i)}else i.width=t.width,i.height=t.height,i.rotate=t.rotate,Te(i),ke(i);return t.calculative.worldRect=i,Bt(t,i),i}function Bt(t,e){!t.paddingTop&&(t.calculative.paddingTop=0),!t.paddingBottom&&(t.calculative.paddingBottom=0),!t.paddingLeft&&(t.calculative.paddingLeft=0),!t.paddingRight&&(t.calculative.paddingRight=0),t.calculative.paddingTop<1&&(t.calculative.paddingTop*=e.height),t.calculative.paddingBottom<1&&(t.calculative.paddingBottom*=e.height),t.calculative.paddingLeft<1&&(t.calculative.paddingLeft*=e.width),t.calculative.paddingRight<1&&(t.calculative.paddingRight*=e.width)}function Nt(t){const e=t.calculative.worldRect;if(!t.parentId)return void Object.assign(t,e);const i=t.calculative.canvas.store.pens[t.parentId].calculative.worldRect;Object.assign(t,Le(e,i))}function Ot(t){const e=t.calculative.canvas.store;let i=[];if(t.anchors&&t.anchors.forEach((e=>{i.push(function(t,e){const i={...e},{x:n,y:r,width:o,height:s}=t.calculative.worldRect;return i.x=n+o*e.x,i.y=r+s*e.y,e.prev&&(i.prev={penId:t.id,connectTo:e.prev.connectTo,x:n+o*e.prev.x,y:r+s*e.prev.y}),e.next&&(i.next={penId:t.id,connectTo:e.next.connectTo,x:n+o*e.next.x,y:r+s*e.next.y}),i}(t,e))})),!i.length&&!t.type&&!t.calculative.canvas.parent.isCombine(t)){const{x:n,y:r,width:o,height:s}=t.calculative.worldRect;i=e.options.defaultAnchors.map(((e,i)=>({id:`${i}`,penId:t.id,x:n+o*e.x,y:r+s*e.y})))}t.calculative.rotate&&i.forEach((e=>{S(e,t.calculative.rotate,t.calculative.worldRect.center)})),t.type&&!t.anchors||(t.calculative.worldAnchors=i),t.calculative.activeAnchor&&i.length&&(t.calculative.activeAnchor=i.find((e=>{e.id,t.calculative.activeAnchor.id}))),t.calculative.gradientAnimatePath=void 0}function zt(t,e){const{paddingTop:i,paddingBottom:n,paddingLeft:r,paddingRight:o}=e.calculative;let s=r,a=i,c=e.calculative.worldRect.width-r-o,l=e.calculative.worldRect.height-i-n,h=e.calculative.iconLeft,u=e.calculative.iconTop;h&&Math.abs(h)<1&&(h=e.calculative.worldRect.width*h),u&&Math.abs(u)<1&&(u=e.calculative.worldRect.height*u),s+=h||0,a+=u||0,c-=h||0,l-=u||0;let d=e.calculative.iconRotate||0;if(e.parentId){const i=t[e.parentId].calculative;i&&(d+=i.rotate,d%=360)}s=e.calculative.worldRect.x+s,a=e.calculative.worldRect.y+a,e.calculative.worldIconRect={x:s,y:a,width:c,height:l,rotate:d},Te(e.calculative.worldIconRect),ke(e.calculative.worldIconRect)}function Ft(t,e,i){Ie(t.calculative.worldRect,e,i),t.calculative.initRect&&Ie(t.calculative.initRect,e,i),t.calculative.x&&C(t.calculative,e,i),t.type&&Ot(t)}function jt(t,e){return e&&e.calculative&&e.calculative.worldRect.center?function(t,e){let i=m.None;if(!e)return i;const n=t.x-e.x,r=t.y-e.y;return i=Math.abs(n)>Math.abs(r)?n>0?m.Right:m.Left:r>0?m.Bottom:m.Up,i}(t,e.calculative.worldRect.center):m.None}function Ht(t,e){let i,n=1/0;return t.calculative.worldAnchors.forEach((t=>{const r=_(e,t);n>r&&(n=r,i=t)})),i}function Ut(t){if(t&&t.calculative&&t.calculative.worldAnchors.length){let e=Yt(t);if(t.anchors&&t.anchors.length)e===t.calculative.activeAnchor?t.calculative.worldAnchors=[t.calculative.worldAnchors[0]]:t.calculative.worldAnchors[0]===t.calculative.activeAnchor&&(t.calculative.worldAnchors=[t.calculative.worldAnchors[t.calculative.worldAnchors.length-1]]);else for(;t.calculative.worldAnchors.length&&e!==t.calculative.activeAnchor;)t.calculative.worldAnchors.pop(),e=Yt(t)}}function Wt(t,e,i,n){if(t&&e&&i&&n&&e.twoWay!==A.DisableConnected&&e.twoWay!==A.Disable&&n.twoWay!==A.DisableConnectTo&&n.twoWay!==A.Disable){if(e.twoWay===A.In){if(1===i.calculative.worldAnchors.length)return;const t=Yt(i);if(n.id!==t.id)return}if(e.twoWay===A.Out){const t=Kt(i);if(n.id!==t.id)return}if(n.connectTo!==t.id||n.anchorId!==e.id){if(n.connectTo){const e=t.calculative.canvas.store.pens[n.connectTo];qt(e,Vt(e,n.anchorId),i,n)}return t.connectedLines||(t.connectedLines=[]),t.connectedLines.findIndex((t=>t.lineId===i.id&&t.lineAnchor===n.id&&t.anchor===e.id))<0&&t.connectedLines.push({lineId:i.id,lineAnchor:n.id,anchor:e.id}),n.connectTo=t.id,n.anchorId=e.id,t.type&&Wt(i,n,t,e),t.calculative.canvas.store.emitter.emit("connectLine",{line:i,lineAnchor:n,pen:t,anchor:e}),!0}}}function qt(t,e,i,n){if(t&&e&&i&&n&&t.connectedLines&&t.connectedLines.length)return t.connectedLines.forEach(((t,r,o)=>{t.lineId!==i.id&&t.lineId!==i.id||t.lineAnchor!==n.id||t.anchor!==e.id||o.splice(r,1)})),n.connectTo=void 0,n.anchorId=void 0,t.type&&e.connectTo===i.id&&e.anchorId===n.id&&qt(i,n,t,e),t.calculative.canvas.store.emitter.emit("disconnectLine",{line:i,lineAnchor:n,pen:t,anchor:e}),!0}function Vt(t,e){if(t&&e)return t.calculative.worldAnchors?.find((t=>t.id===e))}function Kt(t){if(t&&t.calculative.worldAnchors)return t.calculative.worldAnchors[0]}function Yt(t){if(t&&t.calculative.worldAnchors)return t.calculative.worldAnchors[t.calculative.worldAnchors.length-1]}function Xt(t,e){if(0===t.calculative.start||!t.frames||!t.frames.length)return t.calculative.start=void 0,0;if(!t.calculative.duration){t.calculative.duration=0;for(const e of t.frames){t.calculative.duration+=e.duration;for(const i in e)"duration"===i||t[i]||"scale"===i&&(t[i]=1)}}if(t.animateCycle||(t.animateCycle=1/0),t.calculative.start){let i=0;const n=Math.ceil((e-t.calculative.start)/t.calculative.duration);if(n>t.animateCycle)return t.calculative.start=void 0,Gt(t,1),0;const r=(e-t.calculative.start)%t.calculative.duration;let o=0;for(const e of t.frames){if(o+=e.duration,!(r>o))break;++i}if(!t.frames[i])return!0;t.calculative.frameDuration=t.frames[i].duration,t.calculative.frameStart=t.calculative.start+t.calculative.duration*(n-1),t.calculative.frameEnd=t.calculative.frameStart+t.calculative.frameDuration;const s=i!==t.calculative.frameIndex,a=n>t.calculative.cycleIndex;if(s&&(t.calculative.frameIndex=i),a&&(t.calculative.cycleIndex=n),s||a)if(t.calculative.x=t.calculative.initRect.x,t.calculative.y=t.calculative.initRect.y,t.calculative.rotate=t.calculative.initRect.rotate||0,i>0){t.prevFrame={};const e=t.frames[i-1];for(const i in e)t.prevFrame[i]=e[i];Object.assign(t.prevFrame,{rotate:e.rotate||0,x:e.x||0,y:e.y||0,scale:e.scale||1})}else $t(t)}else t.calculative.start=e,t.calculative.frameIndex=0,t.calculative.frameStart=t.calculative.start,t.calculative.frameDuration=t.frames[0].duration,t.calculative.frameEnd=t.calculative.frameStart+t.calculative.frameDuration,t.calculative.cycleIndex=1,t.calculative.x=t.calculative.worldRect.x,t.calculative.y=t.calculative.worldRect.y,t.calculative.initRect=K(t.calculative.worldRect),t.calculative.initRect.rotate=t.calculative.rotate||0,$t(t);return Gt(t,(e-t.calculative.frameStart)/t.calculative.frameDuration%1),!0}function $t(t){t.prevFrame={};for(const e in t)"object"==typeof t[e]&&"lineDash"!==e||(t.prevFrame[e]=t[e]);t.prevFrame.rotate=0,t.prevFrame.x=0,t.prevFrame.y=0,t.prevFrame.scale=1}function Gt(t,e){if(e<0)return;e>1&&(e=1);const i=t.frames[t.calculative.frameIndex];for(const n in i)if("duration"!==n){if("scale"===n){t.calculative.worldRect=K(t.calculative.initRect),Ie(t.calculative.worldRect,t.prevFrame.scale,t.calculative.worldRect.center);const r=t.prevFrame.scale+(i[n]-t.prevFrame.scale)*e;Ie(t.calculative.worldRect,r/t.prevFrame.scale,t.calculative.worldRect.center),t.calculative.patchFlags=!0}else if("x"===n){const r=se(t,n,t.calculative.frameIndex);t.calculative.worldRect.x=t.calculative.initRect.x+r,t.calculative.worldRect.ex=t.calculative.initRect.ex+r,Re(t.calculative.worldRect,i[n]*e*t.calculative.canvas.store.data.scale,0),t.calculative.patchFlags=!0}else if("y"===n){const r=se(t,n,t.calculative.frameIndex);t.calculative.worldRect.y=t.calculative.initRect.y+r,t.calculative.worldRect.ey=t.calculative.initRect.ey+r,Re(t.calculative.worldRect,0,i[n]*e*t.calculative.canvas.store.data.scale),t.calculative.patchFlags=!0}else if("rotate"===n){t.prevFrame[n]>=360&&(t.prevFrame[n]%=360);const r=se(t,n,t.calculative.frameIndex),o=(t.calculative.initRect.rotate+r+i[n]*e)%360-t.calculative.rotate;t.children?.length?t.calculative.canvas.rotatePen(t,o,t.calculative.initRect):t.calculative.rotate=(t.calculative.initRect.rotate+r+i[n]*e)%360,t.calculative.patchFlags=!0}else if("image"===n)t.image=i.image,t.calculative.image=void 0,t.calculative.canvas.loadImage(t),t.isBottom?t.calculative.canvas.canvasImageBottom.init():t.calculative.canvas.canvasImage.init();else if(Qt(i[n],n,t)){null==t.prevFrame[n]&&(t.prevFrame[n]="globalAlpha"===n?1:0);const r=t.prevFrame[n]+(i[n]-t.prevFrame[n])*e;t.calculative[n]=Math.round(100*r)/100}else{"visible"===n&&t.calculative.image&&(t.isBottom?t.calculative.canvas.canvasImageBottom.init():t.calculative.canvas.canvasImage.init()),t.calculative[n]=i[n];const e={};e[n]=i[n],ue(t,e)}"text"===n&&U(t)}}function Qt(t,e,i){return"number"==typeof t&&!1!==i.linear&&!["strokeType","bkType","showChild"].includes(e)}function Jt(t,e){if(0===t.calculative.start)return t.calculative.start=void 0,0;if(t.animateCycle||(t.animateCycle=1/0),t.animateSpan||(t.animateSpan=1),t.calculative.animatePos+=t.animateSpan*(t.calculative.canvas.store.data.scale||1),t.calculative.start){if(t.calculative.animatePos>t.length){if(++t.calculative.cycleIndex,t.calculative.cycleIndex>t.animateCycle)return t.calculative.start=void 0,0;t.calculative.animatePos=t.animateSpan}}else t.calculative.start=Date.now(),t.calculative.animatePos=t.animateSpan*(t.calculative.canvas.store.data.scale||1),t.calculative.cycleIndex=1;return!0}function Zt(t,e=!0){if(!t.children)return;const i=t.calculative.canvas.store;t.children.forEach((t=>{const n=i.pens[t];n&&(n.calculative.active=e,Zt(n,e))}))}function te(t,e=!0){if(!t)return;const i=t.calculative.canvas.store;t.calculative.hover=e,t.children&&t.children.forEach((t=>{null==i.pens[t]?.hoverColor&&null==i.pens[t]?.hoverBackground&&te(i.pens[t],e)}))}function ee(t,e){if(!e)return;const i=t.calculative.canvas.store,n=t.calculative.worldRect;e.style.position="absolute",e.style.outline="none",e.style.left=n.x+i.data.x+"px",e.style.top=n.y+i.data.y+"px",e.style.width=n.width+"px",e.style.height=n.height+"px",e.style.display=0!=t.calculative.inView?"inline":"none",!t.calculative.rotate&&(t.calculative.rotate=0),e.style.transform=`rotate(${t.calculative.rotate}deg)`,t.calculative.rotate||(t.calculative.flipX&&(e.style.transform="rotateY(180deg)"),t.calculative.flipY&&(e.style.transform="rotateX(180deg)"),t.calculative.flipX&&t.calculative.flipY&&(e.style.transform="rotateZ(180deg)")),e.style.zIndex=t.calculative.zIndex+"",t.locked===o.DisableEdit||t.locked===o.DisableMove||i.data.locked?(e.style.userSelect="initial",e.style.pointerEvents="initial","gif"===t.name&&(e.style.userSelect="none",e.style.pointerEvents="none")):(e.style.userSelect="none",e.style.pointerEvents="none")}function ie(t){return t.every((t=>t.locked))}function ne(t){return t.every((t=>t.disableRotate))}function re(t,e,i){t.type?(t.calculative.worldAnchors.forEach((t=>{S(t,e,i.center)})),function(t){if(!t.calculative.worldAnchors?.length)return;if(!isFinite(t.x)||!isFinite(t.x))return;if(null==t.x||null==t.y)return;const e=Ze(t);t.parentId||Object.assign(t,e);const{fontSize:i,lineHeight:n}=t.calculative.canvas.store.options;t.fontSize||(t.fontSize=i,t.calculative.fontSize=t.fontSize*t.calculative.canvas.store.data.scale),t.lineHeight||(t.lineHeight=n,t.calculative.lineHeight=t.lineHeight),ke(e),t.calculative.worldRect=e,Bt(t,e),j(t),t.calculative.worldAnchors&&(t.anchors=t.calculative.worldAnchors.map((e=>Me(e,t.calculative.worldRect))))}(t),Nt(t)):(t.calculative.rotate?t.calculative.rotate+=e:t.calculative.rotate=e,S(t.calculative.worldRect.center,e,i.center),t.parentId&&(t.calculative.worldRect.x=t.calculative.worldRect.center.x-t.calculative.worldRect.width/2,t.calculative.worldRect.y=t.calculative.worldRect.center.y-t.calculative.worldRect.height/2,t.x=(t.calculative.worldRect.x-i.x)/i.width,t.y=(t.calculative.worldRect.y-i.y)/i.height)),t.children?.forEach((n=>{re(t.calculative.canvas.store.pens[n],e,i)}))}function oe(t){return t.every((t=>t.disableSize))}function se(t,e,i){if(!t.frames||!e)return 0;let n=0;for(let r=0;r{const e=i.pens[t];e&&ce(e,!0)})),t.calculative.inView=!0,ae(t,i)&&0!=t.visible&&0!=t.calculative.visible){const{x:e,y:r,width:o,height:s,rotate:a}=t.calculative.worldRect,c={x:e+i.data.x,y:r+i.data.y,width:o,height:s,rotate:a};Te(c),Ce(c,n)||(t.calculative.inView=!1)}else t.calculative.inView=!1;t.onMove?.(t)}function le(t,e){const i=e.calculative.globalAlpha;i<1&&(t.globalAlpha=i)}function he(t,e){const i=M.canvasDraws[e.name];i&&(t.save(),i(t,e),t.restore())}function ue(t,e){for(const i in e)if(k.includes(i)&&(t[i]=e[i],t.calculative[i]=e[i]),t.calculative.canvas.parent.isCombine(t)&&void 0===t.showChild){const i=t.children;i?.forEach((i=>{ue(t.calculative.canvas.store.pens[i],e)}))}}function de(t,e,i){let n,r,o=1/0,s=1/0;for(const a of t.data.pens)!1!==a.calculative.inView&&pe(a).forEach((t=>{if(t===e||t===i)return;let c=(a.calculative.worldRect.center.x-e.x)*(a.calculative.worldRect.center.x-e.x)+(a.calculative.worldRect.center.y-e.y)*(a.calculative.worldRect.center.y-e.y);const l=Math.abs(t.x-e.x);l>0&&l<8&&c0&&h<8&&c{t.x+=n.x,t.y+=n.y}))):(ke(e),r=[e.center,...Se(e)]),ge(t,r,e,!0)}function pe(t){if(!t.type){const e=Se(t.calculative.worldRect);return ke(t.calculative.worldRect),[...t.calculative.worldAnchors,...e,t.calculative.worldRect.center]}if(t.type===r.Line)return t.calculative.worldAnchors}function ve(t,e,i,n){return ge(t,Se(e),e)}function ge(t,e,i,n=!1){let r,o,s=1/0,a=1/0;const c=function(t,e){const i=nt(10),n={x:t.x-i[3],y:t.y-i[0],width:t.width+i[1]+i[3],height:t.height+i[0]+i[2]};return Te(n),n}(i);return t.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.eyye(t,e,l))))return;var f,p;const v=pe(l);if(v)for(const t of v)for(const n of e){const e=t.x-n.x,c=t.y-n.y,h=Math.abs(e),u=Math.abs(c);i.center||(i.center={x:i.x+i.width/2,y:i.y+i.height/2}),h<10&&he.x&&t.xe.y&&t.y{S(t,e.rotate,e.center)})),function(t,e){if(e.length<3)return!1;let i=!1,n=e[e.length-1];for(const r of e)n.y>t.y!=r.y>t.y&&r.x+(t.y-r.y)*(n.x-r.x)/(n.y-r.y)>t.x&&(i=!i),n=r;return i}(t,i)}function xe(t,e,i=0){const{x:n,y:r,ex:o,ey:s}=e;return t.x>=n-i&&t.x<=o+i&&t.y>=r-i&&t.y<=s+i}function ke(t){t.center||(t.center={}),t.center.x=t.x+t.width/2,t.center.y=t.y+t.height/2}function Te(t){t.ex=t.x+t.width,t.ey=t.y+t.height}function Ae(t){const e=[];t.forEach((t=>{if(t.isRuleLine)return;const i=t.calculative.worldRect;if(i){const t=Se(i);e.push(...t)}}));const i=Pe(e);return ke(i),i}function Se(t){const e=[{x:t.x,y:t.y},{x:t.ex,y:t.y},{x:t.ex,y:t.ey},{x:t.x,y:t.ey}];return t.rotate&&(t.center||ke(t),e.forEach((e=>{S(e,t.rotate,t.center)}))),e}function Pe(t){let e=1/0,i=1/0,n=-1/0,r=-1/0;return t?.forEach((t=>{isFinite(t.x)&&isFinite(t.y)&&(e=Math.min(e,t.x),i=Math.min(i,t.y),n=Math.max(n,t.x),r=Math.max(r,t.y))})),{x:e,y:i,ex:n,ey:r,width:n-e,height:r-i}}function Ce(t,e,i){return t.rotate&&(t=Pe(Se(t))),i?t.x>e.x&&t.exe.y&&t.eye.ex||t.exe.ey)}function Re(t,e,i){t.x+=e,t.y+=i,t.ex+=e,t.ey+=i,t.center&&(t.center.x+=e,t.center.y+=i)}function _e(t,e){if(me(t.k,0))return{x:e.point.x,y:t.point.y};if(me(e.k,0))return{x:t.point.x,y:e.point.y};const i=t.point.y-t.k*t.point.x,n=(e.point.y-e.k*e.point.x-i)/(t.k-e.k);return{x:n,y:t.k*n+i}}function Ee(t,e,i,n){if(t.rotate&&t.rotate%360){const r=Se(t),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+=e,r[n].y+=i;const t=r[(n+2)%4];r[(n+1)%4]=_e({k:n%2?s:o,point:r[n]},{k:n%2?o:s,point:t}),r[(n+4-1)%4]=_e({k:n%2?o:s,point:r[n]},{k:n%2?s:o,point:t})}else{const t=[4,6].includes(n)?s:o;me(t,0)?(r[n%4].x+=e,r[(n+1)%4].x+=e):(r[n%4].y+=i,r[n%4].x+=i/t,r[(n+1)%4].y+=i,r[(n+1)%4].x+=i/t)}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(t,e){const i=function(t,e){const i=(t.to.y-t.from.y)/(t.to.x-t.from.x),n=(e.to.y-e.from.y)/(e.to.x-e.from.x);return _e({k:i,point:t.from},{k:n,point:e.from})}({from:t[0],to:t[2]},{from:t[1],to:t[3]});for(const n of t)S(n,-e,i);return Pe(t)}(r,t.rotate);return ke(a),void Object.assign(t,a)}switch(n){case 0:if(t.width-e<5||t.height-i<5)break;t.x+=e,t.y+=i,t.width-=e,t.height-=i;break;case 1:if(t.width+e<5||t.height-i<5)break;t.ex+=e,t.y+=i,t.width+=e,t.height-=i;break;case 2:if(t.width+e<5||t.height+i<5)break;t.ex+=e,t.ey+=i,t.width+=e,t.height+=i;break;case 3:if(t.width-e<5||t.height+i<5)break;t.x+=e,t.ey+=i,t.width-=e,t.height+=i;break;case 4:if(t.height-i<5)break;t.y+=i,t.height-=i;break;case 5:if(t.width+e<5)break;t.ex+=e,t.width+=e;break;case 6:if(t.height+i<5)break;t.ey+=i,t.height+=i;break;case 7:if(t.width-e<5)break;t.x+=e,t.width-=e}}function Ie(t,e,i){t&&(t.width*=e,t.height*=e,C(t,e,i),Te(t),ke(t))}function Le(t,e){const i={x:(t.x-e.x)/e.width,y:(t.y-e.y)/e.height,width:t.width/e.width,height:t.height/e.height};return Te(i),i}function Me(t,e){const{x:i,y:n,width:r,height:o}=e,{penId:s,connectTo:a}=t,c=Object.assign({},t,{x:r?(t.x-i)/r:0,y:o?(t.y-n)/o:0});return t.prev&&(c.prev={penId:s,connectTo:a,x:r?(t.prev.x-i)/r:0,y:o?(t.prev.y-n)/o:0}),t.next&&(c.next={penId:s,connectTo:a,x:r?(t.next.x-i)/r:0,y:o?(t.next.y-n)/o:0}),c}const De=/^[\t\n\f\r ]*([MLHVZCSQTAmlhvzcsqta])[\t\n\f\r ]*/,Be=/^[01]/,Ne=/^[+-]?(([0-9]*\.[0-9]+)|([0-9]+\.)|([0-9]+))([eE][+-]?[0-9]+)?/,Oe=/^(([\t\n\f\r ]+,?[\t\n\f\r ]*)|(,[\t\n\f\r ]*))/,ze={M:[Ne,Ne],L:[Ne,Ne],H:[Ne],V:[Ne],Z:[],C:[Ne,Ne,Ne,Ne,Ne,Ne],S:[Ne,Ne,Ne,Ne],Q:[Ne,Ne,Ne,Ne],T:[Ne,Ne],A:[Ne,Ne,Ne,Be,Be,Ne,Ne]};function Fe(t){let e=1/0,i=1/0,n=-1/0,r=-1/0;return function(t){let e,i=0,n=0;t.commands.forEach((t=>{switch(t.key){case"Z":case"z":t.worldPoints=[i,n];break;case"H":t.worldPoints=[t.values[0],e.worldPoints[e.worldPoints.length-1]];break;case"h":t.worldPoints=[t.values[0]+e.worldPoints[e.worldPoints.length-2],e.worldPoints[e.worldPoints.length-1]];break;case"V":t.worldPoints=[e.worldPoints[e.worldPoints.length-2],t.values[0]];break;case"v":case"A":t.worldPoints=[e.worldPoints[e.worldPoints.length-2],t.values[0]+e.worldPoints[e.worldPoints.length-1]];break;default:!function(t,e){const i=[];let n=t.relative&&e?{x:e.worldPoints[e.worldPoints.length-2],y:e.worldPoints[e.worldPoints.length-1]}:{x:0,y:0};for(let e=0;e{t.worldPoints.forEach(((t,o)=>{o%2==0?(tn&&(n=t)):(tr&&(r=t))}))})),--e,--i,{x:e,y:i,ex:n,ey:r,width:n-e+1,height:r-i+1}}function je(t,e,i){const n=ze[t.toUpperCase()],r=[];for(;i<=e.length;){const o={key:t,values:[]};for(const t of n){const n=e.slice(i).match(t);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 t=e.slice(i).match(Oe);null!==t&&(i+=t[0].length)}}if(o.relative=o.key.toUpperCase()!==o.key,r.push(o),0===n.length)return{cursor:i,commands:r};"m"===t&&(t="l"),"M"===t&&(t="L")}throw new Error("malformed path (first error at "+i+")")}function He(t,e){const i=t.calculative.canvas.store.data.paths[t.pathId];if(!i)return new Path2D;const n=function(t){let e=0;const i=[];for(;e{switch(t.key){case"A":case"a":const n=t.values[0],r=t.values[1],o=Math.PI*t.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*e*i*s*a*(r*r-n*n),h=n*n*e*e*s*s+r*r*e*e*a*a,u=-n*n*r*r*e*e*i*i,d=l*l-4*c*h,f=Math.sqrt((c-h)*(c-h)+l*l);t.values[2]=0!==l?180*Math.atan((h-c-f)/l)/Math.PI:c=0?t.values[4]:1-t.values[4];break;case"V":case"v":t.values[0]*=i;break;default:t.values.forEach(((n,r)=>{t.values[r]=n*(r%2==0?e:i)}))}}))}(n,t.calculative.worldRect.width/t.calculative.svgRect.width,t.calculative.worldRect.height/t.calculative.svgRect.height);const r=Fe(n);ke(r),function(t,e,i){null==i&&(i=e),t.commands.forEach(((t,n)=>{if(!t.relative||!n)switch(t.key){case"A":case"a":t.values[5]+=e,t.values[6]+=i;break;case"V":case"v":t.values[0]+=i;break;default:t.values.forEach(((n,r)=>{t.values[r]=n+(r%2==0?e:i)}))}}))}(n,t.calculative.worldRect.x-r.x,t.calculative.worldRect.y-r.y);const o=function(t){let e="";return t.commands.forEach((t=>{e+=t.key+" ",t.values.forEach((t=>{e+=t+" "}))})),e}(n);if(!e)return new Path2D(o);e.svgPath?.(o)}function Ue(t,e){const{x:i,y:n,width:r,ex:o,ey:s}=e.calculative.worldRect;let a=.25*r;const c=e.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};We(t,[l,h,u,{x:i,y:s}],e.backgroundFront||e.background,e.color),We(t,[l,{x:i+a,y:n},{x:o,y:n},h],e.backgroundUp||e.background,e.color),We(t,[h,{x:o,y:n},{x:o,y:s-a},u],e.backgroundRight||e.background,e.color)}function We(t,e,i="",n=""){t.save(),i&&(t.fillStyle=i),n&&(t.strokeStyle=n),t.beginPath();for(let i=0;in.x?m.Right:m.Left),n.next={id:et(),penId:e.id,x:n.x,y:n.y,prevNextType:2},r.prev={id:et(),penId:e.id,x:r.x,y:r.y,prevNextType:2},o){case m.Up:n.next.y-=20,r.prev.y=n.y;break;case m.Bottom:n.next.y+=20,r.prev.y=n.y;break;case m.Left:n.next.x-=20,r.prev.x=n.x;break;default:n.next.x+=20,r.prev.x=n.x}}function Ge(t,e){const i=e||new Path2D,n=t.calculative.worldAnchors;if(n.length>1){let e;n.forEach((t=>{e?Je(i,e,t):t.start=!0,e=t})),t.close&&Je(i,e,n[0])}if(i instanceof Path2D)return i}function Qe(t,e,i){if(e.calculative.worldAnchors||(e.calculative.worldAnchors=[]),e.calculative.worldAnchors.length<2||e.anchors?.length>1)return;const n=Kt(e),r=Yt(e);n&&r&&r.id&&n!==r&&(n.next=void 0,Ut(e),r.prev=void 0,e.calculative.worldAnchors.push(r))}function Je(t,e,i){i&&!i.isTemp&&(e.start&&t.moveTo(e.x,e.y),e.next?i.prev?t.bezierCurveTo(e.next.x,e.next.y,i.prev.x,i.prev.y,i.x,i.y):t.quadraticCurveTo(e.next.x,e.next.y,i.x,i.y):i.prev?t.quadraticCurveTo(i.prev.x,i.prev.y,i.x,i.y):t.lineTo(i.x,i.y))}function Ze(t){return oi(t),Pe(function(t){const e=[];let i;return t.calculative.worldAnchors.forEach((n=>{e.push(n),i&&e.push(...ei(i,n,t)),i=n})),t.close&&t.calculative.worldAnchors.length>1&&e.push(...ei(i,t.calculative.worldAnchors[0],t)),e}(t))}function ti(t){return t?.lineWidth?t.lineWidth/2+4:4}function ei(t,e,i){const n=[];if(!e)return n;let r=.02;if(t.lineLength&&(r=ti(i)/t.lineLength),t.next)if(e.prev)for(let i=r;i<1;i+=r)n.push(Ye(i,t,t.next,e.prev,e));else for(let i=r;i<1;i+=r)n.push(Ke(i,t,t.next,e));else if(e.prev)for(let i=r;i<1;i+=r)n.push(Ke(i,t,e.prev,e));else n.push({x:e.x,y:e.y});return n.length>1&&(t.curvePoints=n),n}function ii(t,e){const i=ti(e);let n,r,o=0;for(const s of e.calculative.worldAnchors){if(n){if(r=ni(t,n,s,i),r)return{i:o,point:r};++o}n=s}if(e.close&&e.calculative.worldAnchors.length>1&&(r=ni(t,n,e.calculative.worldAnchors[0],i)))return{i:o,point:r}}function ni(t,e,i,n=4){if(!e.next&&!i.prev){const{x:r,y:o}=e,{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(!(t.x>=c-n&&t.x<=l+n&&t.y>=h-n&&t.y<=u+n))return;return function(t,e,i,n=4){if(e.x===i.x){if(Math.abs(t.x-e.x)<=n)return{x:e.x,y:t.y}}else{const r=(e.y-i.y)/(e.x-i.x),o=e.y-r*e.x;if(Math.abs((r*t.x+o-t.y)/Math.sqrt(r*r+1))<=n){const e=(t.x+r*t.y-r*o)/(r*r+1);return{x:e,y:r*e+o}}}}(t,e,i,n)}if(e.curvePoints)for(const i of e.curvePoints)if(P(t,i,n))return i}function ri(t,e,i,n){if(!e&&!i)return Math.sqrt(Math.pow(Math.abs(t.x-n.x),2)+Math.pow(Math.abs(t.y-n.y),2))||0;const r=document.createElementNS("http://www.w3.org/2000/svg","path");return e&&i?r.setAttribute("d",`M${t.x} ${t.y} C${e.x} ${e.y} ${i.x} ${i.y} ${n.x} ${n.y}`):e?r.setAttribute("d",`M${t.x} ${t.y} Q${e.x} ${e.y} ${n.x} ${n.y}`):r.setAttribute("d",`M${t.x} ${t.y} Q${i.x} ${i.y} ${n.x} ${n.y}`),r.getTotalLength()||0}function oi(t){if(t.calculative.worldAnchors.length<2)return 0;let e,i=0;if(t.calculative.worldAnchors.forEach((t=>{e&&(e.lineLength=ri(e,e.next,t.prev,t),i+=e.lineLength),e=t})),t.close){const n=Kt(t);e.lineLength=ri(e,e.next,n.prev,n),i+=e.lineLength}return t.length=i,i}function si(t,e,i){if(xe(t,i)||xe(e,i))return!0;const n=t.x,r=t.y,o=e.x,s=e.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 t=a;a=l,l=t}if(cl&&o>l||r>c&&s>c||rt.y)r=t.x+(e.x-t.x)/2,n.push({x:r,y:t.y},{x:r,y:e.y});else{const i=(t.y+e.y)/2;n.push({x:t.x,y:i},{x:e.x,y:i})}break;case m.Right:r=e.x,o=t.y,e.xt.x&&e.yt.y-ci)r=t.x+(e.x-t.x)/2,n.push({x:r,y:t.y},{x:r,y:e.y});else{const i=(t.y+e.y+ci)/2;n.push({x:t.x,y:i},{x:e.x,y:i})}}return n}(r,o,u));break;case m.Right:a.push(...function(t,e,i){if(t.x===e.x||t.y===e.y)return[];const n=[];let r,o;switch(i){case m.Up:r=t.x,o=e.y,e.x>t.x&&e.y>t.y&&(r=e.x,o=t.y),n.push({x:r,y:o});break;case m.Bottom:r=t.x,o=e.y,e.x>t.x&&e.yt.y&&(r=t.x,o=e.y),n.push({x:r,y:o});break;case m.Bottom:t.y>e.y?(r=e.x,o=t.y):(r=t.x,o=e.y),n.push({x:r,y:o});break;case m.Left:r=e.x,o=t.y,e.x>t.x&&e.y>t.y&&(r=t.x,o=e.y),n.push({x:r,y:o});break;default:if(r=t.x,e.yt.y&&(r=e.x,o=t.y),n.push({x:r,y:o});break;case m.Bottom:r=t.x,o=e.y,e.xt.x)r=e.x,o=t.y+(e.y-t.y)/2,n.push({x:t.x,y:o},{x:e.x,y:o});else{const i=(t.x+e.x)/2;n.push({x:i,y:t.y},{x:i,y:e.y})}break;case m.Left:e.x>t.x?n.push({x:t.x,y:e.y}):n.push({x:e.x,y:t.y});break;default:if(r=t.x,o=e.y,e.xMath.abs(i.y-e.y)),t.calculative.worldAnchors.length&&(i.isTemp=void 0,t.calculative.drawlineH?(n.push({x:i.x,y:e.y}),Math.abs(i.y-e.y){t.id=et(),t.penId=e.id,e.calculative.worldAnchors.push(t)})),e.calculative.worldAnchors.push(o),d&&e.calculative.worldAnchors.push(f),n&&e.calculative.worldAnchors.reverse(),s){const t=e.calculative.worldAnchors.length-2;e.calculative.worldAnchors[t].isTemp=!1}}function hi(t,e,i){const n={x:t.x,y:t.y,id:et()};switch(e){case m.Up:n.y-=i;break;case m.Right:n.x+=i;break;case m.Bottom:n.y+=i;break;case m.Left:n.x-=i;break;default:return}return n}function ui(t,e,i=!0){let n=t.calculative.worldAnchors;i||(n=[],t.calculative.worldAnchors.forEach((t=>{n.unshift(t)})));for(let t=0;t{n.unshift(t)})));for(let t=0;t1?(l=v.x-p.x,h=v.y-p.y):g>0?(l=v.x-(a+u*g),h=v.y-(c+d*g)):(l=v.x-a,h=v.y-c)):(l=v.x-a,h=v.y-c),y=l*l+h*h,y>o&&(s=e,o=y);return o>e&&(s-i>1&&r.push(...fi(t,e,i,s)),r.push({id:t[s].id,penId:t[s].penId,x:t[s].x,y:t[s].y}),n-s>1&&r.push(...fi(t,e,s,n))),r}const pi={};function vi(t){if(t.onDestroy||(t.onDestroy=gi,t.onMove=yi,t.onResize=yi,t.onRotate=yi,t.onValue=yi,t.onChangeId=mi),pi[t.id])pi[t.id].getAttribute("src")!==t.iframe&&(pi[t.id].src=t.iframe,t.calculative.iframe=t.iframe);else{const e=document.createElement("iframe");e.scrolling="no",e.frameBorder="0",e.src=t.iframe,pi[t.id]=e,t.calculative.iframe=t.iframe,t.calculative.canvas.externalElements?.appendChild(e),ee(t,e)}return t.calculative.patchFlags&&ee(t,pi[t.id]),new Path2D}function gi(t){pi[t.id].remove(),pi[t.id]=void 0}function yi(t){pi[t.id]&&(ee(t,pi[t.id]),pi[t.id].getAttribute("src")!==t.iframe&&(pi[t.id].src=t.iframe))}function mi(t,e,i){pi[e]&&(pi[i]=pi[e],delete pi[e])}const wi={};function bi(t){if(t.onDestroy||(t.onDestroy=xi,t.onMove=ki,t.onResize=ki,t.onRotate=ki,t.onClick=Ti,t.onValue=Pi,t.onChangeId=Si),wi[t.id])t.video&&t.calculative.media&&t.video!==t.calculative.video?(console.warn("video 更改, 此处是否执行?"),t.calculative.media.src=t.video,t.autoPlay&&(t.calculative.media.muted=!0,t.calculative.media.autoplay=!0),t.calculative.media.loop=t.playLoop,t.calculative.video=t.video):t.audio&&t.calculative.media&&t.audio!==t.calculative.audio&&(t.calculative.media.src=t.audio,t.autoPlay&&(t.calculative.media.muted=!0,t.calculative.media.autoplay=!0),t.calculative.media.loop=t.playLoop,t.calculative.audio=t.audio);else{const e=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",e.appendChild(i),t.video?(n=document.createElement("video"),n.src=t.video):t.audio&&(n=document.createElement("audio"),n.src=t.audio),n.loop=t.playLoop,n.ontimeupdate=()=>{Ai(i,n,t.calculative.worldRect.width)},n.onended=()=>{t.calculative.onended&&t.calculative.onended(t)},t.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%",e.appendChild(n),wi[t.id]=e,t.calculative.canvas.externalElements?.appendChild(e),ee(t,e),t.autoPlay&&(n.autoplay=!0,n.muted=!0)}return t.calculative.patchFlags&&ee(t,wi[t.id]),new Path2D}function xi(t){wi[t.id].remove(),wi[t.id]=void 0}function ki(t){ee(t,wi[t.id]),Ai(wi[t.id].children[0],wi[t.id].children[1],t.calculative.worldRect.width)}function Ti(t){t.calculative.media&&(t.calculative.media.muted=!1,t.calculative.media.paused?t.calculative.media.play():t.calculative.media.pause())}function Ai(t,e,i){t.style.width=e.currentTime/e.duration*i+"px"}function Si(t,e,i){wi[e]&&(wi[i]=wi[e],delete wi[e])}function Pi(t){const e=wi[t.id];if(!e)return;ee(t,e);const i=t.calculative.media.getAttribute("src");t.video?i!==t.video&&(t.calculative.media.src=t.video):t.audio&&i!==t.audio&&(t.calculative.media.src=t.audio),t.autoPlay&&(t.calculative.media.muted=!0,t.calculative.media.autoplay=!0),t.calculative.media.loop=t.playLoop}function Ci(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 _i(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 Ei(t){t.anchors=[{x:.5,y:0},{x:.75,y:.5},{x:.5,y:1},{x:.25,y:.5}].map((({x:e,y:i},n)=>({id:`${n}`,penId:t.id,x:e,y:i})))}function Ii(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 Li(t){t.anchors=[{x:.5,y:0},{x:1,y:.4},{x:.8,y:1},{x:.2,y:1},{x:0,y:.4}].map((({x:e,y:i},n)=>({id:`${n}`,penId:t.id,x:e,y:i})))}function Mi(t,e){t.onResize||(t.onResize=Bi);const i=e||new Path2D,{width:n,height:r,center:o}=t.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 t=0;t<5;++t)i.lineTo(-(l-c)*Math.sin(Math.PI/180*72*t)+a,(l-c)*Math.cos(Math.PI/180*72*t)+c),i.lineTo((u-a)*Math.cos(Math.PI/180*72*(t+1))-(d-c)*Math.sin(Math.PI/180*72*(t+1))+a,(u-a)*Math.sin(Math.PI/180*72*(t+1))+(d-c)*Math.cos(Math.PI/180*72*(t+1))+c);if(i.closePath(),i instanceof Path2D)return i}function Di(t){const{width:e,height:i}=t,n=e>i?i:e,r=[];for(let o=0;o<5;++o)r.push({flag:1,id:String(o),penId:t.id,x:.5+n/2*Math.sin(Math.PI/180*72*o)/e,y:-n/2*Math.cos(Math.PI/180*72*o)/i+.5});t.anchors=r}function Bi(t){const e=t.anchors.filter((t=>1!==t.flag));Di(t),t.anchors=t.anchors.concat(...e)}function Ni(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 Oi(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 zi(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 Fi(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 ji(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s,ey:a}=t.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 Hi(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 Ui(t,e){const i=e||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=t.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 Wi(t,e){const i=e||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=t.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 qi={};let Vi=0;function Ki(t){t.onDestroy||(t.onDestroy=Yi,t.onMove=Xi,t.onResize=$i,t.onRotate=Xi,t.onValue=Gi,t.onChangeId=Qi);const e=new Path2D;if(t.image){if(!qi[t.id]){const e=new Image;e.crossOrigin="anonymous",e.src=t.image,qi[t.id]=e,Vi++,t.calculative.zIndex=Vi,e.onload=()=>{t.calculative.img=e,t.calculative.imgNaturalWidth=e.naturalWidth||t.iconWidth,t.calculative.imgNaturalHeight=e.naturalHeight||t.iconHeight,t.calculative.canvas.externalElements?.appendChild(e),Ji(t,e)}}return t.calculative.patchFlags&&qi[t.id]&&Ji(t,qi[t.id]),e}}function Yi(t){qi[t.id].remove(),qi[t.id]=void 0}function Xi(t){qi[t.id]&&Ji(t,qi[t.id])}function $i(t){qi[t.id]&&Ji(t,qi[t.id])}function Gi(t){qi[t.id]&&(Ji(t,qi[t.id]),qi[t.id].getAttribute("src")!==t.image&&(qi[t.id].src=t.image))}function Qi(t,e,i){qi[e]&&(qi[i]=qi[e],delete qi[e])}function Ji(t,e){e.style.objectFit=t.imageRatio?"contain":"fill",ee(t,e)}function Zi(e,i){return e.onResize||(e.onResize=tn,e.onValue=en),t(e,i)}function tn(t){const e=t.anchors.filter((t=>1!==t.flag));nn(t),t.anchors=t.anchors.concat(...e)}function en(t){tn(t),Ot(t)}function nn(t){const e=[],{x:i,y:n,width:r,height:o}=t,s=function(t){let e=t.calculative.borderRadius||0,i=t.calculative.borderRadius||0;const{width:n,height:r}=t;t.calculative.borderRadius<1&&(e=n*t.calculative.borderRadius,i=r*t.calculative.borderRadius);let o=ei+r-s&&(l=on(i+r-s,l+s,c,s,-1)),e.push({id:String(e.length),flag:1,penId:t.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=rn(l-s,n+o-s,c,s)),e.push({id:String(e.length),flag:1,penId:t.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=on(i+r-s,l-s,c,s)),e.push({id:String(e.length),flag:1,penId:t.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=rn(l+s,n+o-s,c,s,-1)),e.push({id:String(e.length),flag:1,penId:t.id,x:(l-i)/r,y:(c-n)/o})}t.anchors=e}function rn(t,e,i,n,r=1){return r*Math.sqrt(n**2-(i-e)**2)+t}function on(t,e,i,n,r=1){return r*Math.sqrt(n**2-(i-t)**2)+e}function sn(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.calculative.worldRect;if(i.moveTo(n,r+s),i.lineTo(n+o,r+s),i.closePath(),i instanceof Path2D)return i}function an(t){t.anchors=[{x:0,y:1},{x:1,y:1}].map((({x:e,y:i},n)=>({id:n+"",x:e,y:i,penId:t.id})))}function cn(){try{const t=new OffscreenCanvas(0,0),e=t.getContext("2d");return e&&e.arc?t:document.createElement("canvas")}catch(t){return document.createElement("canvas")}}class ln{constructor(t,e){let i;this.parentElement=t,this.store=e,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),t.appendChild(this.box),this.box.onmouseleave=()=>{this.hide(),this.store.lastHover=void 0};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(t,e){this.x<-1e3||(this.x+=t,this.y+=e,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px")}destroy(){this.box.onmouseleave=null}}class hn{constructor(t){let e;this.parent=t,this.onMouseDownH=t=>{t.preventDefault(),t.stopPropagation(),this.isDownH=t.x,this.x=this.parent.store.data.x||0,this.lastScrollX=this.scrollX},this.onMouseDownV=t=>{t.preventDefault(),t.stopPropagation(),this.isDownV=t.y,this.y=this.parent.store.data.y||0,this.lastScrollY=this.scrollY},this.onMouseMove=t=>{if(this.isDownH){const e=t.x-this.isDownH;this.scrollX=this.lastScrollX+e,this.h.style.left=`${this.scrollX}px`,this.parent.store.data.x=this.x-e*this.rect.width/this.parent.parentElement.clientWidth}if(this.isDownV){const e=t.y-this.isDownV;this.scrollY=this.lastScrollY+e,this.v.style.top=`${this.scrollY}px`,this.parent.store.data.y=this.y-e*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=t=>{(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 t=0;t0?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(t,e){t&&(this.scrollX-=t*this.parent.parentElement.clientWidth/this.rect.width,this.h.style.left=`${this.scrollX}px`),e&&(this.scrollY-=e*this.parent.parentElement.clientHeight/this.rect.height,this.v.style.top=`${this.scrollY}px`)}wheel(t){let e=10;t&&(e=-10),this.scrollY+=e,this.v.style.top=`${this.scrollY}px`,this.parent.store.data.y-=e*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 un{constructor(t,e,i){this.parentElement=t,this.store=e,this.isBottom=i,this.canvas=document.createElement("canvas"),this.otherOffsreen=cn(),this.offscreen=cn(),this.animateOffsScreen=cn(),t.appendChild(this.canvas),this.canvas.style.backgroundRepeat="no-repeat",this.canvas.style.backgroundSize="100% 100%",this.canvas.style.position="absolute",this.canvas.style.top="0",this.canvas.style.left="0"}resize(t,e){this.canvas.style.width=t+"px",this.canvas.style.height=e+"px",t=t*this.store.dpiRatio|0,e=e*this.store.dpiRatio|0,this.canvas.width=t,this.canvas.height=e,this.otherOffsreen.width=t,this.otherOffsreen.height=e,this.offscreen.width=t,this.offscreen.height=e,this.animateOffsScreen.width=t,this.animateOffsScreen.height=e,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 t of this.store.data.pens)this.hasImage(t)&&(t.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(t){return t.calculative.hasImage=t.calculative&&t.calculative.inView&&!t.isBottom==!this.isBottom&&t.image&&t.calculative.img&&"gif"!==t.name,t.calculative.hasImage}render(){let t=!1,e=!1;for(const i of this.store.data.pens)this.hasImage(i)&&(this.store.animates.has(i)?e=!0:i.calculative.imageDrawed||(t=!0),i.parentId&&this.store.animates.has(ot(i,!0))&&(e=!0));const i=this.store.patchFlagsBackground;if(i&&this.isBottom){const t=this.otherOffsreen.getContext("2d");t.clearRect(0,0,this.canvas.width,this.canvas.height);const e=this.store.data.background||this.store.options.background;e&&(t.save(),t.fillStyle=e,t.fillRect(0,0,this.canvas.width,this.canvas.height),t.restore()),this.renderGrid(t)}const n=this.store.patchFlagsTop;if(n&&!this.isBottom){const t=this.otherOffsreen.getContext("2d");t.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderRule(t)}if(t){const t=this.offscreen.getContext("2d");t.save(),t.translate(this.store.data.x,this.store.data.y);for(const e of this.store.data.pens)!e.calculative.hasImage||e.calculative.imageDrawed||this.store.animates.has(e)||this.store.animates.has(ot(e,!0))||(e.calculative.imageDrawed=!0,t.save(),At(t,e),e.calculative.rotate&&St(t,e),le(t,e),mt(t,e),t.restore());t.restore()}if(e){const t=this.animateOffsScreen.getContext("2d");t.save(),t.clearRect(0,0,this.canvas.width,this.canvas.height),t.translate(this.store.data.x,this.store.data.y);for(const e of this.store.animates)e.calculative.hasImage&&(e.calculative.imageDrawed=!0,t.save(),At(t,e),e.calculative.rotate&&St(t,e),le(t,e),mt(t,e),t.restore());for(const e of this.store.data.pens)e.calculative.hasImage&&e.parentId&&this.store.animates.has(ot(e,!0))&&(e.calculative.imageDrawed=!0,t.save(),At(t,e),e.calculative.rotate&&St(t,e),le(t,e),mt(t,e),t.restore());t.restore()}if(t||e||i&&this.isBottom||n&&!this.isBottom){const t=this.canvas.getContext("2d");t.clearRect(0,0,this.canvas.width,this.canvas.height),this.isBottom&&(t.drawImage(this.otherOffsreen,0,0,this.canvas.width,this.canvas.height),this.store.patchFlagsBackground=!1),t.drawImage(this.offscreen,0,0,this.canvas.width,this.canvas.height),t.drawImage(this.animateOffsScreen,0,0,this.canvas.width,this.canvas.height),this.isBottom||(t.drawImage(this.otherOffsreen,0,0,this.canvas.width,this.canvas.height),this.store.patchFlagsTop=!1)}}renderGrid(t){const{data:e,options:i}=this.store,{grid:n,gridRotate:r,gridColor:o,gridSize:s,scale:a}=e;if(!(n??i.grid))return;t.save();const{width:c,height:l}=this.canvas;r&&(t.translate(c/2,l/2),t.rotate(r*Math.PI/180),t.translate(-c/2,-l/2)),t.lineWidth=1,t.strokeStyle=o||i.gridColor,t.beginPath();const h=(s||i.gridSize)*a,u=Math.max(c,l),d=Math.ceil(u/h);for(let e=-h*d;e<2*u;e+=h)t.moveTo(e,-u),t.lineTo(e,2*u);for(let e=-h*d;e<2*u;e+=h)t.moveTo(-u,e),t.lineTo(2*u,e);t.stroke(),t.restore()}renderRule(t){const{data:e,options:i}=this.store,{rule:n,ruleColor:r,scale:o,origin:s}=e;if(!(n??i.rule))return;const a=10*o;t.save();const c=r||i.ruleColor;t.strokeStyle=J(c,.7);const l=s.x+e.x,h=s.y+e.y,{width:u,height:d}=this.canvas;t.beginPath(),t.lineWidth=12,t.lineDashOffset=-l%a,t.setLineDash([1,a-1]),t.moveTo(0,0),t.lineTo(u,0),t.stroke(),t.beginPath(),t.lineDashOffset=-h%a,t.moveTo(0,0),t.lineTo(0,d),t.stroke(),t.strokeStyle=c,t.beginPath(),t.lineWidth=24,t.lineDashOffset=-l%(10*a),t.setLineDash([1,10*a-1]),t.moveTo(0,0),t.lineTo(u,0),t.stroke(),t.beginPath(),t.lineDashOffset=-h%(10*a),t.moveTo(0,0),t.lineTo(0,d),t.stroke(),t.beginPath(),t.fillStyle=t.strokeStyle;let f=0-100*Math.floor(l/a/10);l<0&&(f-=100);for(let e=l%(10*a);e{i.drawImage(e,n-t,r-t,this.magnifierSize,this.magnifierSize,0,0,this.magnifierSize,this.magnifierSize)})),i.restore(),i.beginPath();const o=i.createRadialGradient(t,t,t-5,t,t,t);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(t,t,t,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-t-2.5)/this.store.dpiRatio,(r-t-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 t=this.canvas.getContext("2d");t.clearRect(0,0,this.canvas.width,this.canvas.height),t.drawImage(this.offscreen,0,0,this.canvas.width,this.canvas.height)}}function fn(t){if(t.data.locked)throw new Error("canvas is locked")}const pn="-moving";class vn{constructor(t,e,i){this.parent=t,this.parentElement=e,this.store=i,this.canvas=document.createElement("canvas"),this.offscreen=cn(),this.externalElements=document.createElement("div"),this.lastRotate=0,this.hoverType=v.None,this.resizeIndex=0,this.lastOffsetX=0,this.lastOffsetY=0,this.drawLineFns=[...x],this.patchFlagsLines=new Set,this.lastMouseTime=0,this.hoverTimer=0,this.patchFlags=!1,this.lastRender=0,this.touchStart=0,this.lastAnimateRender=0,this.animateRendering=!1,this.pointSize=8,this.pasteOffset=10,this.inputParent=document.createElement("div"),this.inputDiv=document.createElement("div"),this.inputRight=document.createElement("div"),this.dropdown=document.createElement("ul"),this.mousePos={x:0,y:0},this.stopPropagation=t=>{t.stopPropagation()},this.curve=qe,this.polyline=li,this.mind=$e,this.line=Qe,this.onCopy=t=>{this.store.options.disableClipboard||t.target!==this.externalElements&&t.target!==document.body&&t.target.offsetParent!==this.externalElements||this.copy()},this.onCut=t=>{this.store.options.disableClipboard||t.target!==this.externalElements&&t.target!==document.body&&t.target.offsetParent!==this.externalElements||this.cut()},this.onPaste=t=>{if(this.store.options.disableClipboard)return;if(t.target!==this.externalElements&&t.target!==document.body&&t.target.offsetParent!==this.externalElements)return;let e;if(navigator.clipboard&&t.clipboardData){const i=t.clipboardData.items;if(i)for(let t=0;t{t=e.target.result;const r=new Image;r.src=t,r.onload=()=>{const{width:e,height:s}=r,a={name:o,x:i-25,y:n-s/e*50,externElement:"gif"===o,width:100,height:s/e*100,image:t};this.addPens([a]),this.active([a]),this.copy([a])}},e.readAsDataURL(r)}}}else this.paste()},this.onwheel=t=>{if("true"===this.inputDiv.contentEditable)return;if(this.drawingLine)return;if(this.pencil)return;if(t.preventDefault(),t.stopPropagation(),this.store.options.disableScale)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(this.store.options.disableTouchPadScale&&t.ctrlKey&&0!==t.deltaY)return;if(-1!==navigator.userAgent.indexOf("Win")&&!t.ctrlKey&&Math.abs(t.deltaY)<100)return void this.translate(-t.deltaX,-t.deltaY);if((/macintosh|mac os x/i.test(navigator.userAgent)||-1!==navigator.platform.indexOf("Mac"))&&!t.ctrlKey&&t.wheelDeltaY%240!=0)return void this.translate(-t.deltaX,-t.deltaY);if(this.store.options.scroll&&!t.ctrlKey&&!t.metaKey&&this.scroll)return void this.scroll.wheel(t.deltaY<0);const e=!(!t.deltaX&&t.deltaY),i=performance.now();let n=.1;if(i-this.touchStart<50)return;n=i-this.touchStart<100?.5:i-this.touchStart<200?.3:.1,this.touchStart=i;const{offsetX:r,offsetY:s}=t;e?this.translate(t.deltaX,t.deltaY):t.deltaY<0?this.scale(this.store.data.scale+n,{x:r,y:s}):this.scale(this.store.data.scale-n,{x:r,y:s}),this.externalElements.focus()},this.onkeydown=t=>{if(this.store.data.locked>=o.DisableEdit||"INPUT"===t.target.tagName||"TEXTAREA"===t.target.tagName)return;let e=10,i=10;switch(t.key){case" ":this.hotkeyType=g.Translate;break;case"Control":this.drawingLine?this.drawingLine.calculative.drawlineH=!this.drawingLine.calculative.drawlineH:this.hotkeyType||(this.patchFlags=!0,this.hotkeyType=g.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=g.Resize);break;case"Alt":if(!t.ctrlKey&&!t.shiftKey&&this.drawingLine){const t=Yt(this.drawingLine);t!==this.drawingLine.calculative.activeAnchor?(Ut(this.drawingLine),this.drawingLine.calculative.worldAnchors.push(t)):this.drawingLine.calculative.worldAnchors.push({x:t.x,y:t.y});const e=this.drawLineFns.indexOf(this.drawingLineName);this.drawingLineName=this.drawLineFns[(e+1)%this.drawLineFns.length],this.drawingLine.lineName=this.drawingLineName,this.drawline(),this.patchFlags=!0}t.preventDefault();break;case"a":case"A":t.ctrlKey||t.metaKey?(this.active(this.store.data.pens.filter((t=>!t.parentId&&t.locked!==o.Disable))),t.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}e=-10,t.shiftKey&&(e=-5),(t.ctrlKey||t.metaKey)&&(e=-1),this.translatePens(this.store.active,e,0);break;case"ArrowUp":if(this.movingAnchor){this.translateAnchor(0,-1);break}i=-10,t.shiftKey&&(i=-5),(t.ctrlKey||t.metaKey)&&(i=-1),this.translatePens(this.store.active,0,i);break;case"ArrowRight":if(this.movingAnchor){this.translateAnchor(1,0);break}t.shiftKey&&(e=5),(t.ctrlKey||t.metaKey)&&(e=1),this.translatePens(this.store.active,e,0);break;case"ArrowDown":if(this.movingAnchor){this.translateAnchor(0,1);break}t.shiftKey&&(i=5),(t.ctrlKey||t.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),(t.ctrlKey||t.metaKey)&&this.store.emitter.emit("save",{event:t});break;case"c":case"C":(t.ctrlKey||t.metaKey)&&this.store.options.disableClipboard&&this.copy();break;case"x":case"X":(t.ctrlKey||t.metaKey)&&this.store.options.disableClipboard&&this.cut();break;case"v":case"V":t.ctrlKey||t.metaKey||(this.drawingLineName?(this.finishDrawline(),this.drawingLineName=""):this.drawingLineName=this.store.options.drawingLineName),(t.ctrlKey||t.metaKey)&&this.store.options.disableClipboard&&this.paste();break;case"b":case"B":this.drawingPencil();break;case"y":case"Y":(t.ctrlKey||t.metaKey)&&this.redo();break;case"z":case"Z":t.ctrlKey||t.metaKey?this.undo():t.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((t=>{t.type&&(t.close=!t.close,this.store.path2dMap.set(t,M.path2dDraws.line(t)),oi(t))})),this.render());break;case"Escape":this.drawingLineName&&this.finishDrawline(),this.drawingLineName=void 0,this.stopPencil(),this.movingPens&&(this.getAllByPens(this.movingPens).forEach((t=>{this.store.pens[t.id]=void 0})),this.movingPens=void 0,this.mouseDown=void 0,this.clearDock(),this.store.active?.forEach((t=>{this.updateLines(t)})),this.calcActiveRect(),this.patchFlags=!0),this.hotkeyType=g.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"=":(t.ctrlKey||t.metaKey)&&(this.scale(this.store.data.scale+.1),t.preventDefault(),t.stopPropagation());break;case"-":(t.ctrlKey||t.metaKey)&&(this.scale(this.store.data.scale-.1),t.preventDefault(),t.stopPropagation())}this.render(!1)},this.onkeyup=t=>{this.hotkeyType&&this.render(),this.hotkeyType{if(this.store.data.locked)console.warn("canvas is locked, can not drop");else try{t.preventDefault(),t.stopPropagation();const e=t.dataTransfer.getData("Meta2d")||t.dataTransfer.getData("Text");let i=null;if(!e){const{files:e}=t.dataTransfer;if(e.length&&e[0].type.match("image.*")){const t="image/gif"===e[0].type;i=await this.fileToPen(e[0],t)}}!i&&(i=JSON.parse(e)),i=Array.isArray(i)?i:[i];const n={x:t.offsetX,y:t.offsetY};this.calibrateMouse(n),this.dropPens(i,n)}catch(t){}},this.ontouchstart=t=>{this.store.data.locked!==o.Disable&&(this.touchStartTimer&&clearTimeout(this.touchStartTimer),this.touchStartTimer=setTimeout((()=>{this.touchStart=performance.now();const e=t.touches[0].pageX-this.clientRect.x,i=t.touches[0].pageY-this.clientRect.y,n={x:e,y:i};if(this.calibrateMouse(n),this.getHover(n),this.onMouseDown({x:e,y:i,clientX:t.touches[0].clientX,clientY:t.touches[0].clientY,pageX:t.touches[0].pageX,pageY:t.touches[0].pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:1}),2===t.touches.length)return this.initTouchDis=Math.hypot(t.touches[0].pageX-t.touches[1].pageX,t.touches[0].pageY-t.touches[1].pageY),this.initScale=this.store.data.scale,this.startTouches=t.touches,void(this.touchCenter={x:t.touches[0].pageX+(t.touches[1].pageX-t.touches[0].pageX)/2-this.clientRect.x,y:t.touches[0].pageY+(t.touches[1].pageY-t.touches[0].pageY)/2-this.clientRect.y});3===t.touches.length&&(this.store.emitter.emit("contextmenu",{e:{x:e,y:i,clientX:t.touches[0].clientX,clientY:t.touches[0].clientY,pageX:t.touches[0].pageX,pageY:t.touches[0].pageY},clientRect:this.clientRect}),t.preventDefault(),t.stopPropagation()),this.touchStartTimer=void 0}),50))},this.ontouchmove=t=>{if(this.store.data.locked===o.Disable)return;t.stopPropagation(),t.preventDefault();const e=performance.now();if(e-this.touchStart<50)return;this.touchStart=e;const i=t.touches,n=i.length,r=t.touches[0].pageX-this.clientRect.x,s=t.touches[0].pageY-this.clientRect.y;if(1===n)this.onMouseMove({x:r,y:s,clientX:t.changedTouches[0].clientX,clientY:t.changedTouches[0].clientY,pageX:t.changedTouches[0].pageX,pageY:t.changedTouches[0].pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:1});else if(2===n&&2===this.startTouches?.length){if(!this.touchMoving&&!this.touchScaling){const t=this.startTouches[0].pageX-i[0].pageX,e=this.startTouches[1].pageX-i[1].pageX,n=this.startTouches[0].pageY-i[0].pageY,r=this.startTouches[1].pageY-i[1].pageY;(t>=0&&e<0||t<=0&&e>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 t=Math.hypot(i[0].pageX-i[1].pageX,i[0].pageY-i[1].pageY)/this.initTouchDis;this.scale(this.initScale*t,K(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:t}=this.store.data;this.translate((r-this.lastOffsetX)/t,(s-this.lastOffsetY)/t)}this.lastOffsetX=r,this.lastOffsetY=s}}},this.ontouchend=t=>{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 e=t.changedTouches[0].pageX-this.clientRect.x,i=t.changedTouches[0].pageY-this.clientRect.y;this.onMouseUp({x:e,y:i,clientX:t.changedTouches[0].clientX,clientY:t.changedTouches[0].clientY,pageX:t.changedTouches[0].pageX,pageY:t.changedTouches[0].pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:1}),this.render()},this.onGesturestart=t=>{t.preventDefault()},this.onMouseDown=t=>{if(2!==t.buttons||this.drawingLine||(this.mouseRight=y.Down),this.hideInput(),this.store.data.locked===o.Disable||1!==t.buttons&&2!==t.buttons)this.hoverType=v.None;else if(!this.magnifierCanvas.magnifier)if(this.calibrateMouse(t),this.mousePos.x=t.x,this.mousePos.y=t.y,this.mouseDown=t,this.lastMouseTime=performance.now(),this.hotkeyType!==g.AddAnchor){if(!this.store.options.autoAnchor&&!this.drawingLine&&t.shiftKey&&t.ctrlKey&&t.altKey){this.setAnchor(this.store.pointAt),this.drawingLineName=this.store.options.drawingLineName;const t=this.store.activeAnchor;if(!t)return;const e={id:et(),x:t.x,y:t.y};this.drawingLine=this.createDrawingLine(e);let i=Kt(this.drawingLine);return this.drawingLine.calculative.activeAnchor=i,Wt(this.store.hover,t,this.drawingLine,e),void this.drawline()}if(this.hotkeyType!==g.Translate&&(this.mouseRight!==y.Down||this.store.options.mouseRightActive)){if(this.drawingLine){if(this.store.hoverAnchor){const t=Yt(this.drawingLine);return t.x=this.store.hoverAnchor.x,t.y=this.store.hoverAnchor.y,Wt(this.store.hover,this.store.hoverAnchor,this.drawingLine,t),this.drawline(),void this.finishDrawline(!0)}if(!this.store.options.autoAnchor&&t.shiftKey&&t.altKey&&t.ctrlKey){this.setAnchor(this.store.pointAt);const t=Yt(this.drawingLine),e=this.store.activeAnchor;if(!e)return;return t.x=e.x,t.y=e.y,Wt(this.store.hover,e,this.drawingLine,t),this.drawline(),void this.finishDrawline(!0)}if(2===t.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 e=Yt(this.drawingLine),i=Ht(this.store.hover,t);return e.x=i.x,e.y=i.y,this.drawingLine.autoTo=!0,Wt(this.store.hover,i,this.drawingLine,e),this.drawline(),void this.finishDrawline(!0)}const e=Yt(this.drawingLine);e.isTemp?(this.drawingLine.calculative.activeAnchor=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2],e.isTemp=void 0):(this.drawingLine.calculative.activeAnchor=e,this.drawingLine.calculative.worldAnchors.push({x:e.x,y:e.y,penId:e.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 e=Ht(this.store.hover,t);this.store.hoverAnchor=e;const i={id:et(),x:e.x,y:e.y};this.drawingLine=this.createDrawingLine(i),this.drawingLine.autoFrom=!0,Wt(this.store.hover,e,this.drawingLine,i)}else this.inactive(),this.hoverType=v.None;else if(!this.drawingLine&&"curve"!==this.drawingLineName){this.inactive(!0);const e={id:et(),x:t.x,y:t.y};this.drawingLine=this.createDrawingLine(e),this.drawingLine.calculative.activeAnchor=e}}else if(this.pencil){this.inactive(!0);const e=et(),i={x:t.x,y:t.y,id:et(),penId:e};this.pencilLine=this.getInitPencilLine(i)}else{switch(this.hoverType){case v.None:this.store.data.rule&&!this.store.options.disableRuleLine&&this.addRuleLine(t),this.inactive();break;case v.Node:case v.Line:if(this.store.hover){const e=ot(this.store.hover,!0)||this.store.hover;t.ctrlKey&&!t.shiftKey?(e.calculative.active?this.willInactivePen=e:(e.calculative.active=!0,Zt(e),this.store.active.push(e),this.store.emitter.emit("active",this.store.active)),this.patchFlags=!0):t.ctrlKey&&t.shiftKey&&this.store.hover.parentId?this.active([this.store.hover]):e.calculative.active||this.active([e]),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((t=>{this.activeInitPos.push({x:(t.calculative.worldRect.x-this.activeRect.x)/this.activeRect.width,y:(t.calculative.worldRect.y-this.activeRect.y)/this.activeRect.height})}))}this.store.emitter.emit("mousedown",{x:t.x,y:t.y,pen:this.store.hover})}this.render()}}else this.setAnchor(this.store.pointAt)},this.onMouseMove=t=>{if(this.store.data.locked===o.Disable)return void(this.hoverType=v.None);if(this.mouseDown&&!this.mouseDown.restore&&1!==t.buttons&&2!==t.buttons)return void this.onMouseUp(t);if(this.lastMouseTime){if(performance.now()-this.lastMouseTime<50)return void(this.lastMouseTime=0);this.lastMouseTime=0}if(this.calibrateMouse(t),this.mousePos.x=t.x,this.mousePos.y=t.y,this.magnifierCanvas.magnifier)return void this.render();if(this.mouseDown&&!this.store.options.disableTranslate){if(this.mouseRight===y.Down&&(this.mouseRight=y.Translate),this.store.data.locked===o.DisableEdit||this.store.data.locked===o.DisableScale||this.hotkeyType===g.Translate||this.mouseRight===y.Translate){const{scale:e}=this.store.data;let i=(t.x-this.mouseDown.x)/e,n=(t.y-this.mouseDown.y)/e;return t.shiftKey&&!t.ctrlKey&&(n=0),t.ctrlKey&&(i=0),void this.translate(i,n)}if(this.store.data.locked)return;if(this.drawingLine||this.pencil){if(this.pencil){const e={...t};e.id=et(),e.penId=this.pencilLine.id,this.pencilLine.calculative.worldAnchors.push(e),this.store.path2dMap.set(this.pencilLine,M.path2dDraws[this.pencilLine.name](this.pencilLine)),this.patchFlags=!0}}else{if(this.drawingLineName||this.movingAnchor){if(this.drawingLineName&&this.hoverType===v.None){const e={id:et(),x:t.x,y:t.y};return this.drawingLine=this.createDrawingLine(e),this.drawingLine.calculative.activeAnchor=e,void this.drawline()}}else if(this.hoverType===v.NodeAnchor){this.drawingLineName=this.store.options.drawingLineName;const t={id:et(),x:this.store.hoverAnchor.x,y:this.store.hoverAnchor.y};return this.drawingLine=this.createDrawingLine(t),this.drawingLine.calculative.activeAnchor=t,Wt(this.store.hover,this.store.hoverAnchor,this.drawingLine,t),void this.drawline()}if(1===t.buttons&&!this.hoverType&&!this.hotkeyType)return this.dragRect={x:Math.min(this.mouseDown.x,t.x),y:Math.min(this.mouseDown.y,t.y),ex:Math.max(this.mouseDown.x,t.x),ey:Math.max(this.mouseDown.y,t.y),width:Math.abs(t.x-this.mouseDown.x),height:Math.abs(t.y-this.mouseDown.y)},void this.render();if(this.movingAnchor){const e=t.x-this.movingAnchor.x,i=t.y-this.movingAnchor.y;return this.translateAnchor(e,i),void this.render()}if(!this.store.active[0]?.locked){const e={x:t.x,y:t.y};if(this.hoverType===v.LineAnchor)return!this.dockInAnchor(t)||this.store.options.disableDock||this.store.options.disableLineDock||(this.clearDock(),this.dock=de(this.store,e,this.store.activeAnchor),this.dock?.xDock&&(e.x+=this.dock.xDock.step),this.dock?.yDock&&(e.y+=this.dock.yDock.step)),void this.moveLineAnchor(e,t);if(this.hoverType===v.LineAnchorPrev)return void this.moveLineAnchorPrev(t);if(this.hoverType===v.LineAnchorNext)return void this.moveLineAnchorNext(t)}if(this.hoverType===v.Rotate)return void this.rotatePens({x:t.x,y:t.y});if(this.hoverType===v.Resize)return void this.resizePens(t);if(this.hoverType===v.Node||this.hoverType===v.Line){const e=t.x-this.mouseDown.x,i=t.y-this.mouseDown.y,n=20;if(t.ctrlKey&&!t.shiftKey&&(Math.abs(e)>=n||Math.abs(i)>=n)&&(this.willInactivePen=void 0),1===this.store.active.length){const t=this.store.active[0];t.locked1&&(i=Yt(this.drawingLine)),i?(i.prev=void 0,i.next=void 0,i.id||(i.id=et()),i.x=e.x,i.y=e.y,i.connectTo=void 0):(i={...e},this.drawingLine.calculative.worldAnchors.push(i)),this.hoverType!==v.NodeAnchor&&this.hoverType!==v.LineAnchor||(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(t.ctrlKey&&!t.shiftKey)i.x=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].x;else if(t.shiftKey&&!t.ctrlKey)i.y=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].y;else if(t.shiftKey&&t.ctrlKey){let t=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2],e=0,n=[0,30,45,60,90,120,150,135,180];i.x-t.x!=0?(e=180*Math.atan((t.y-i.y)/(i.x-t.x))/Math.PI,i.x0?e-=180:e+=180)):t.y>i.y?e=90:t.y50&&(this.hoverTimer=e,this.getHover(t)),globalThis.debug&&console.timeEnd("hover"),this.hotkeyType===g.AddAnchor&&(this.patchFlags=!0),this.render(!1)},this.onMouseUp=t=>{if(this.store.data.locked!==o.Disable){if(this.mouseDown){if(this.mouseRight===y.Down&&this.store.emitter.emit("contextmenu",{e:t,clientRect:this.clientRect}),this.mouseRight=y.None,this.calibrateMouse(t),this.mousePos.x=t.x,this.mousePos.y=t.y,this.pencil&&this.finishPencil(),this.drawingLine){if(this.store.hoverAnchor){const t=Yt(this.drawingLine);return t.x=this.store.hoverAnchor.x,t.y=this.store.hoverAnchor.y,Wt(this.store.hover,this.store.hoverAnchor,this.drawingLine,t),this.drawline(),void this.finishDrawline(!0)}if(this.store.options.autoAnchor&&this.hoverType===v.Node){const e=Yt(this.drawingLine),i=Ht(this.store.hover,t);return e.x=i.x,e.y=i.y,this.drawingLine.autoTo=!0,Wt(this.store.hover,i,this.drawingLine,e),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 e=this.store.active[0],i=Kt(e),n=Yt(e);if(this.store.hoverAnchor){const o=this.store.hover,s=Kt(o)===this.store.hoverAnchor,a=Yt(o)===this.store.hoverAnchor,c=i===this.store.activeAnchor,l=n===this.store.activeAnchor;if((t.ctrlKey||t.altKey)&&o.type===r.Line&&(s||a)&&(c||l)){const t=o.calculative.worldAnchors.map((t=>({...t,penId:e.id})));s?t.shift():a&&t.pop(),(s&&c||a&&l)&&t.reverse(),c?(e.calculative.worldAnchors[0].connectTo=void 0,e.calculative.worldAnchors.unshift(...t)):l&&(e.calculative.worldAnchors[e.calculative.worldAnchors.length-1].connectTo=void 0,e.calculative.worldAnchors.push(...t)),this.delete([o]),this.render()}else this.store.activeAnchor&&(this.store.activeAnchor.x=this.store.hoverAnchor.x,this.store.activeAnchor.y=this.store.hoverAnchor.y,Wt(this.store.hover,this.store.hoverAnchor,e,this.store.activeAnchor));this[e.lineName]&&"polyline"!==e.lineName&&this[e.lineName](this.store,e),this.store.path2dMap.set(e,M.path2dDraws.line(e)),this.initLineRect(e)}else i===this.store.activeAnchor&&e.autoFrom?this.calcAutoAnchor(e,i,this.store.hover):n===this.store.activeAnchor&&e.autoTo&&this.calcAutoAnchor(e,n,this.store.hover)}if(this.addCaches&&(this.store.data.locked||this.dropPens(this.addCaches,t),this.addCaches=void 0),this.hoverType===v.Rotate&&(this.getSizeCPs(),this.store.active.forEach((t=>{t.rotate=t.calculative.rotate}))),this.patchFlagsLines.forEach((t=>{t.type&&this.initLineRect(t)})),this.patchFlagsLines.clear(),this.dragRect){const t=this.store.data.pens.filter((t=>!1!==t.visible&&t.locked!==o.Disable&&!t.parentId&&(Ce(t.calculative.worldRect,this.dragRect,this.store.options.dragAllIn)?!(t.type===r.Line&&!this.store.options.dragAllIn)||function(t,e){const i=t.calculative.worldAnchors;for(let t=0;tt===this.willInactivePen)),1),this.calcActiveRect(),this.willInactivePen=void 0,this.store.emitter.emit("inactive",[this.willInactivePen]),this.render()),this.movingPens&&(t.altKey&&!t.shiftKey?this.copyMovedPens():this.movedActivePens(t.ctrlKey&&t.shiftKey),this.getAllByPens(this.movingPens).forEach((t=>{this.store.pens[t.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}}else this.hoverType=v.None},this.clearDock=()=>{const t=this.dock?.xDock?.penId,e=this.dock?.yDock?.penId,i=this.store.pens[t];i&&(i.calculative.isDock=!1);const n=this.store.pens[e];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=t=>(t.x-=this.store.data.x,t.y-=this.store.data.y,t),this.getHover=t=>{if(this.dragRect)return;let e=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!==g.AddAnchor&&this.activeRect&&!i&&!this.store.data.locked){const i=ie(this.store.active),n=ne(this.store.active)||this.store.options.disableRotate,r=oe(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(t,i,this.pointSize)&&(e=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===g.Resize||n&&!this.hotkeyType)&&P(t,this.sizeCPs[i],this.pointSize)){let t=n?w:b,r=0;Math.abs(this.activeRect.rotate%90-45)<25?(t=n?b:w,r=Math.round((this.activeRect.rotate-45)/90)+(n?0:1)):r=Math.round(this.activeRect.rotate/90),e=v.Resize,this.resizeIndex=i,this.externalElements.style.cursor=t[(i+r)%4];break}}}e===v.None&&(e=this.inPens(t,this.store.data.pens)),e||i||!be(t,this.activeRect)||(e=v.Node,this.externalElements.style.cursor="move"),this.hoverType=e,e===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,te(ot(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,te(ot(this.store.hover,!0)||this.store.hover),this.store.emitter.emit("enter",this.store.hover),this.tooltip.show(this.store.hover,t)),this.store.lastHover=this.store.hover),this.store.hover?.onMouseMove?.(this.store.hover,this.mousePos)},this.inPens=(t,e)=>{let i=v.None;t:for(let n=e.length-1;n>=0;--n){const r=e[n];if(0==r.visible||0==r.calculative.inView||r.locked===o.Disable)continue;const s=ti(r);if(r.calculative.active||xe(t,r.calculative.worldRect,s)||be(t,r.calculative.worldRect)){if(!this.store.data.locked&&this.hotkeyType!==g.Resize&&r.calculative.worldAnchors)for(const e of r.calculative.worldAnchors)if(i=this.inAnchor(t,r,e),i)break t;if(r.type){const e=ii(t,r);if(e){this.store.data.locked||r.locked?this.externalElements.style.cursor=this.store.options.hoverCursor:this.hotkeyType===g.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move",this.store.hover=r,this.store.pointAt=e.point,this.store.pointAtIndex=e.i,i=v.Line;break}}else{if(r.children){const e=[];if(r.children.forEach((t=>{e.push(this.store.pens[t])})),i=this.inPens(t,e),i)break}let e=!1;if(e="line"===r.name?xe(t,r.calculative.worldRect,r.lineWidth):be(t,r.calculative.worldRect),e){if(this.store.data.locked||r.locked?this.externalElements.style.cursor=this.store.options.hoverCursor:this.hotkeyType===g.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move",this.store.hover=r,i=v.Node,this.store.pointAt=t,!t.ctrlKey){let{x:e,y:i,ex:n,ey:r,rotate:o,center:s}=this.store.hover.calculative.worldRect;if(o){const a=[{x:e,y:i},{x:n,y:i},{x:n,y:r},{x:e,y:r}];a.forEach((t=>{S(t,o,s)}));let c=a[a.length-1];for(const e of a){if(c.y>t.y!=e.y>t.y){const i=e.x+(t.y-e.y)*(c.x-e.x)/(c.y-e.y);Math.abs(i-this.store.pointAt.x)<10&&(this.store.pointAt.x=i)}c=e}}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=t=>{this.store.hover=void 0;for(let e=this.store.data.pens.length-1;e>=0;--e){const i=this.store.data.pens[e];if(0==i.visible||i.locked===o.Disable||i===this.store.active[0])continue;let n=ti(i);if(n+=2*this.store.options.anchorRadius,xe(t,i.calculative.worldRect,n)&&(this.store.hover=i,this.hotkeyType!==g.Resize&&i.calculative.worldAnchors))for(const e of i.calculative.worldAnchors){if(e.twoWay===A.In){const t=Yt(this.store.active[0]);if(this.store.activeAnchor.id!==t.id)continue}if(e.twoWay===A.Out){const t=Kt(this.store.active[0]);if(this.store.activeAnchor.id!==t.id)continue}if(e.twoWay!==A.DisableConnected&&e.twoWay!==A.Disable&&this.store.activeAnchor?.twoWay!==A.DisableConnectTo&&this.store.activeAnchor?.twoWay!==A.Disable&&this.inAnchor(t,i,e))return!0}}},this.render=t=>{let e;if(null==t||!0===t||t===1/0?(e=performance.now(),this.patchFlags=!0):e=t>1?t:performance.now(),!this.patchFlags)return;if(e-this.lastRender{const t=this.offscreen.getContext("2d");t.strokeStyle=Lt(this.store);for(const e of this.store.data.pens)isFinite(e.x)&&e.calculative.inView&&Pt(t,e);this.drawingLine&&Pt(t,this.drawingLine),this.pencilLine&&Pt(t,this.pencilLine),this.movingPens&&this.movingPens.forEach((e=>{this.renderPenContainChild(t,e)}))},this.renderPenContainChild=(t,e)=>{e.calculative.inView&&Pt(t,e),e.children?.forEach((e=>{const i=this.store.pens[e];i&&this.renderPenContainChild(t,i)}))},this.renderBorder=()=>{if(!this.store.data.locked&&this.activeRect&&(1!==this.store.active.length||!this.store.active[0].type)&&!this.movingPens){const t=this.offscreen.getContext("2d");if(t.save(),t.translate(.5,.5),this.activeRect.rotate&&(t.translate(this.activeRect.center.x,this.activeRect.center.y),t.rotate(this.activeRect.rotate*Math.PI/180),t.translate(-this.activeRect.center.x,-this.activeRect.center.y)),t.strokeStyle=this.store.options.activeColor,t.globalAlpha=.3,t.beginPath(),t.strokeRect(this.activeRect.x,this.activeRect.y,this.activeRect.width,this.activeRect.height),t.globalAlpha=1,ie(this.store.active)||ne(this.store.active)||this.store.options.disableRotate)return void t.restore();t.beginPath(),t.moveTo(this.activeRect.center.x,this.activeRect.y),t.lineTo(this.activeRect.center.x,this.activeRect.y-30),t.stroke(),t.beginPath(),t.strokeStyle=this.store.options.activeColor,t.fillStyle="#ffffff",t.arc(this.activeRect.center.x,this.activeRect.y-30,5,0,2*Math.PI),t.fill(),t.stroke(),t.restore()}},this.renderHoverPoint=()=>{if(this.store.data.locked)return;const t=this.offscreen.getContext("2d");if(t.save(),t.translate(.5,.5),!this.store.options.disableAnchor&&this.store.hover&&!this.store.hover.disableAnchor&&(this.hotkeyType!==g.Resize||1!==this.store.active.length||this.store.active[0]!==this.store.hover)){const e=[...this.store.hover.calculative.worldAnchors];this.store.pointAt&&this.hotkeyType===g.AddAnchor&&e.push(this.store.pointAt),e&&(t.strokeStyle=this.store.hover.anchorColor||this.store.options.anchorColor,t.fillStyle=this.store.hover.anchorBackground||this.store.options.anchorBackground,e.forEach((e=>{if(e.hidden&&e.locked>o.DisableEdit)return;if(e===this.store.hoverAnchor){t.save();const e=this.store.hover.hoverAnchorColor||this.store.options.hoverAnchorColor;t.strokeStyle=e,t.fillStyle=e}t.beginPath();let i=e.radius||this.store.hover.anchorRadius||this.store.options.anchorRadius;if(!this.store.hover.type||e.radius||this.store.hover.anchorRadius||(i=3,this.store.hover.calculative.lineWidth>3&&(i=this.store.hover.calculative.lineWidth)),t.arc(e.x,e.y,i,0,2*Math.PI),this.store.hover.type&&this.store.hoverAnchor===e?(t.save(),t.strokeStyle=this.store.hover.activeColor||this.store.options.activeColor,t.fillStyle=t.strokeStyle):(e.color||e.background)&&(t.save(),t.strokeStyle=e.color,t.fillStyle=e.background),t.fill(),t.stroke(),e===this.store.hoverAnchor&&t.restore(),(this.store.hover.type&&this.store.hoverAnchor===e||e.color||e.background)&&t.restore(),!this.store.hover.parentId&&this.store.hover.children&&this.store.hover.children.length>0&&e===this.store.hoverAnchor){t.save(),t.beginPath(),t.lineWidth=3;const n=this.store.hover.hoverAnchorColor||this.store.options.hoverAnchorColor;globalThis.pSBC&&(t.strokeStyle=globalThis.pSBC(.5,n)),t.arc(e.x,e.y,i+1.5,0,2*Math.PI),t.stroke(),t.restore()}})))}this.hotkeyType===g.AddAnchor||this.movingPens||!this.activeRect||1===this.store.active.length&&this.store.active[0].type||ie(this.store.active)||oe(this.store.active)||this.store.options.disableSize||(t.strokeStyle=this.store.options.activeColor,t.fillStyle="#ffffff",this.sizeCPs.forEach(((e,i)=>{this.activeRect.rotate&&(t.save(),t.translate(e.x,e.y),t.rotate(this.activeRect.rotate*Math.PI/180),t.translate(-e.x,-e.y)),(i<4||this.hotkeyType===g.Resize)&&(t.beginPath(),t.fillRect(e.x-4.5,e.y-4.5,8,8),t.strokeRect(e.x-5.5,e.y-5.5,10,10)),this.activeRect.rotate&&t.restore()}))),!this.store.data.locked&&this.dragRect&&(t.save(),t.fillStyle=J(this.store.options.dragColor,.2),t.strokeStyle=this.store.options.dragColor,t.beginPath(),t.strokeRect(this.dragRect.x,this.dragRect.y,this.dragRect.width,this.dragRect.height),t.fillRect(this.dragRect.x,this.dragRect.y,this.dragRect.width,this.dragRect.height),t.restore()),this.dock&&(t.strokeStyle=this.store.options.dockColor,this.dock.xDock&&(t.beginPath(),t.moveTo(this.dock.xDock.x,this.dock.xDock.y),t.lineTo(this.dock.xDock.x,this.dock.xDock.prev.y),t.stroke()),this.dock.yDock&&(t.beginPath(),t.moveTo(this.dock.yDock.x,this.dock.yDock.y),t.lineTo(this.dock.yDock.prev.x,this.dock.yDock.y),t.stroke())),t.restore()},this.pastePen=(t,e)=>{const i=t.id;if(we(t),t.parentId=e,t.type===r.Line?this.changeNodeConnectedLine(i,t,this.store.clipboard.pens):this.changeLineAnchors(i,t,this.store.clipboard.pens),!t.parentId){const e=this.getPenRect(t,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;t.x=n.x+e.x*r,t.y=n.y+e.y*r,t.width=e.width*r,t.height=e.height*r,i.x=n.x+i.x*r,i.y=n.y+i.y*r,ke(i),this.store.clipboard.pos&&(t.x-=i.center.x-this.store.clipboard.pos.x,t.y-=i.center.y-this.store.clipboard.pos.y),t.x+=this.store.clipboard.offset*this.store.data.scale,t.y+=this.store.clipboard.offset*this.store.data.scale}this.makePen(t);const n=[];if(Array.isArray(t.children))for(const e of t.children){const i=this.store.clipboard.pens.find((t=>t.id===e));i&&n.push(this.pastePen(i,t.id).id)}return t.children=n,t},this.ondblclick=t=>{!this.store.hover||this.store.data.locked||this.store.options.disableInput||(this.store.hover.onShowInput?this.store.hover.onShowInput(this.store.hover,t):this.showInput(this.store.hover)),this.store.emitter.emit("dblclick",{x:t.x,y:t.y,pen:this.store.hover})},this.showInput=(t,e,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===t.id){this.inputDiv.dataset.isInput="true",this.inputDiv.contentEditable="true",this.inputDiv.focus();const t=window.getSelection();return t.selectAllChildren(this.inputDiv),t.collapseToEnd(),this.inputDiv.scrollTop=this.inputDiv.scrollHeight,void(this.inputDiv.scrollLeft=this.inputDiv.scrollWidth)}e||this.setInputStyle(t);const n=e||t.calculative.worldTextRect,r=`${(t.calculative.tempText||t.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-(t.textLeft||0)+"px",this.inputParent.style.top=n.y+this.store.data.y-(t.textTop||0)+"px";let o=n.width+(t.textLeft||0);this.inputParent.style.width=(o<0?12:o)+"px",this.inputParent.style.height=n.height+(t.textTop||0)+"px",this.inputParent.style.zIndex="9999",this.inputParent.style.background=i,t.rotate%360?this.inputParent.style.transform=`rotate(${t.rotate}deg)`:this.inputParent.style.transform=null,this.inputParent.style.display="flex",this.inputDiv.dataset.penId=t.id,this.inputDiv.contentEditable=null==t.disableInput?"true":t.disableInput.toString(),t.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,t.calculative.text=void 0,this.render()},this.setInputStyle=t=>{let e;t.text||(t.text="");for(let t=0;t1?t.textLeft*r:t.textLeft*r/o}px;`),t.textTop&&(i+=`margin-top:${o>1?t.textTop*r:t.textTop*r/o}px;`),t.lineHeight&&(i+=`line-height:${o>1?t.fontSize*t.lineHeight*o:t.fontSize*t.lineHeight*r}px;`),t.textHeight)i+=`height:${o>1?t.textHeight*r*o:t.textHeight*r}px;`;else{let e=t.calculative.worldRect.height/o-(t.textTop||0);e<0&&(e=0),i+=`height:${t.fontSize*o<12?e*r:e*o*r}px;`}let s=null;if(t.textWidth)s=(t.textWidth<1&&t.textWidth)>-1?t.textWidth*t.calculative.worldRect.width:t.textWidth,"pre-line"!==t.whiteSpace&&(s1?s*r*o:s*r}px;`);else if(void 0===t.whiteSpace||"break-all"===t.whiteSpace){let e=(t.calculative.worldTextRect.width||12)/o;e<0&&(e=0),i+=`width:${t.fontSize*o<12?e*r:e*o}px;`}t.whiteSpace&&("pre-line"===t.whiteSpace?i+="white-space:pre;":(i+=`white-space:${t.whiteSpace};`,"nowrap"===t.whiteSpace&&(n+="display:contents;"))),"nowrap"!==t.whiteSpace&&1.2*t.fontSize*t.text.length>(s||t.calculative.worldRect.width/o)*Math.floor(t.calculative.worldRect.height/o/(t.lineHeight*t.fontSize))&&(i+="justify-content: start;"),e.deleteRule(0),e.deleteRule(0),e.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}}`),e.insertRule(`.input-div div{${n}}`)},this.hideInput=()=>{if("flex"===this.inputParent.style.display){this.inputParent.style.display="none";const t=this.store.pens[this.inputDiv.dataset.penId];if(!t)return;if(t.calculative.text=t.text,this.inputDiv.dataset.value=this.inputDiv.innerHTML.replace(/\/g,"\n").replace(/\<\/div\>/g,"").replace(/\/g,"").replace(/ /g," ").replace(/(<([^>]+)>)/gi,""),t.onInput)t.onInput(t,this.inputDiv.dataset.value);else if(t.text!==this.inputDiv.dataset.value){const e=[K(t,!0)];t.text=this.inputDiv.dataset.value,t.calculative.text=t.text,this.inputDiv.dataset.penId=void 0,j(t),this.patchFlags=!0,this.pushHistory({type:F.Update,pens:[K(t,!0)],initPens:e}),this.store.emitter.emit("valueUpdate",t)}}this.inputDiv.dataset.penId=void 0,this.dropdown.style.display="none",this.inputDiv.dataset.isInput="false",this.inputDiv.contentEditable="false",this.render()},this.setDropdownList=t=>{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 e=this.store.pens[this.inputDiv.dataset.penId];if(!e||!e.dropdownList)return this.dropdown.style.display="none",this.inputRight.style.display="none",void(this.inputRight.style.transform="rotate(135deg)");if(!e.dropdownList.length){const t=document.createElement("div");return t.innerText="None",t.style.padding="5px 12px",t.style.color="#ddd",void this.dropdown.appendChild(t)}const i=this.inputDiv.innerHTML.replace(/\/g,"\n").replace(/\<\/div\>/g,"").replace(/\/g,"");let n=0;for(const r of e.dropdownList){const e="string"==typeof r?r:r.text;t&&i?e.includes(i)&&this.dropdownAppendOption(e,n):this.dropdownAppendOption(e,n),++n}if(!this.dropdown.hasChildNodes()){const t=document.createElement("div");t.innerText="None",t.style.padding="5px 12px",t.style.color="#ddd",this.dropdown.appendChild(t)}},this.selectDropdown=t=>{const e=t.target,i=this.store.pens[this.inputDiv.dataset.penId];if(!e||!i||!i.dropdownList)return;const n=+e.dataset.i,r=i.dropdownList[n];if(!r)return;const o=[K(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:F.Update,pens:[K(i,!0)],initPens:o}),this.render(),this.store.emitter.emit("valueUpdate",i)},this.canvasImageBottom=new un(e,i,!0),e.appendChild(this.canvas),this.canvas.style.position="absolute",this.canvas.style.backgroundRepeat="no-repeat",this.canvas.style.backgroundSize="100% 100%",this.canvasImage=new un(e,i),this.magnifierCanvas=new dn(this,e,i),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",e.style.position="relative",e.appendChild(this.externalElements),this.createInput(),this.tooltip=new ln(e,i),this.tooltip.box.onmouseleave=t=>{this.patchFlags=!0,this.store.lastHover&&(this.store.lastHover.calculative.hover=!1),te(this.store.data.pens.find((t=>!0===t.calculative.hover)),!1)},this.store.options.scroll&&(this.scroll=new hn(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=t=>t.preventDefault(),this.externalElements.ondrop=this.ondrop,this.externalElements.oncontextmenu=t=>t.preventDefault(),it()?(this.store.options.interval=50,this.externalElements.ontouchstart=this.ontouchstart,this.externalElements.ontouchmove=this.ontouchmove,this.externalElements.ontouchend=this.ontouchend):(this.externalElements.onmousedown=t=>{this.onMouseDown({x:t.offsetX,y:t.offsetY,clientX:t.clientX,clientY:t.clientY,pageX:t.pageX,pageY:t.pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons})},this.externalElements.onmousemove=t=>{t.target===this.externalElements&&this.onMouseMove({x:t.offsetX,y:t.offsetY,clientX:t.clientX,clientY:t.clientY,pageX:t.pageX,pageY:t.pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons})},this.externalElements.onmouseup=t=>{this.onMouseUp({x:t.offsetX,y:t.offsetY,clientX:t.clientX,clientY:t.clientY,pageX:t.pageX,pageY:t.pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons,button:t.button})},this.externalElements.onmouseleave=t=>{t.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 O.Document:document.addEventListener("keydown",this.onkeydown),document.addEventListener("keyup",this.onkeyup);break;case O.Canvas:this.externalElements.addEventListener("keydown",this.onkeydown),this.externalElements.addEventListener("keyup",this.onkeyup)}}splitLine(t,e){const i=t.calculative.worldAnchors,n=i.findIndex((t=>t===e));if([-1,0,i.length-1].includes(n))return;const r=K(t,!0),o=K(t,!0),s=et();o.id=s,o.calculative.canvas=this,o.calculative.active=!1,o.calculative.hover=!1;const a=K(i.slice(0,n+1)),c=K(i.slice(n)).map((t=>(t.penId=s,t)));t.calculative.worldAnchors=a,o.calculative.worldAnchors=c,this.initLineRect(t),this.initLineRect(o),this.store.data.pens.push(o),this.store.pens[s]=o,this.pushHistory({type:F.Add,pens:[K(o,!0)],step:2}),this.pushHistory({type:F.Update,initPens:[r],pens:[K(t,!0)],step:2})}translateAnchor(t,e){this.movingAnchor.x+=t,this.movingAnchor.y+=e;const i=this.movingAnchor.penId;if(i){const t=this.store.pens[i],e=t.calculative.worldRect;this.movingAnchor.xe.ex&&(this.movingAnchor.x=e.ex),this.movingAnchor.ye.ey&&(this.movingAnchor.y=e.ey);const n=Me(this.movingAnchor,e),r=t.anchors.findIndex((t=>t.id===this.movingAnchor.id));t.anchors[r]=n,this.patchFlags=!0}}async fileToPen(t,e){let i="";return i=this.store.options.uploadFn?await this.store.options.uploadFn(t):this.store.options.uploadUrl?await async function(t,e,i,n){const r=new FormData;if(r.append("file",t),i)for(const t in i)i.hasOwnProperty(t)&&r.append(t,i[t]);const o=await fetch(e,{method:"POST",headers:n,body:r});return(await o.json()).url}(t,this.store.options.uploadUrl,this.store.options.uploadParams,this.store.options.uploadHeaders):await async function(t){return new Promise(((e,i)=>{const n=new FileReader;n.onload=t=>{e(t.target.result)},n.onerror=t=>{i(t)},n.readAsDataURL(t)}))}(t),new Promise(((t,n)=>{const r=new Image;r.onload=()=>{M.htmlElements[i]=r,t({width:r.width,height:r.height,name:e?"gif":"image",image:i})},r.onerror=t=>{n(t)},r.src=i}))}async dropPens(t,e){for(const e of t)!e.parentId&&this.randomCombineId(e,t);for(const e of t)e.id||(e.id=et()),!e.calculative&&(e.calculative={canvas:this}),this.store.pens[e.id]=e;for(const i of t)i.parentId||(i.width*=this.store.data.scale,i.height*=this.store.data.scale,i.x=e.x-i.width/2,i.y=e.y-i.height/2);await this.addPens(t,!0),this.active(t.filter((t=>!t.parentId))),this.render(),this.externalElements.focus()}randomCombineId(t,e,i){we(t),t.parentId=i;const n=[];if(Array.isArray(t.children))for(const i of t.children){const r=e.find((t=>t.id===i));r&&n.push(this.randomCombineId(r,e,t.id).id)}return t.children=n,t}async addPens(t,e){if(this.beforeAddPens&&1!=await this.beforeAddPens(t))return[];const i=[];for(const e of t)this.beforeAddPen&&1!=this.beforeAddPen(e)||(this.makePen(e),i.push(e));return this.render(),this.store.emitter.emit("add",i),e&&this.pushHistory({type:F.Add,pens:K(i,!0)}),i}getInitPencilLine(t){const{data:e,options:i}=this.store,n=e.scale,o=e.lineWidth||1;return{id:t.penId,name:"line",x:t.x,y:t.y,type:r.Line,calculative:{canvas:this,pencil:!0,active:!0,worldAnchors:[t],lineWidth:o*n},fromArrow:e.fromArrow||i.fromArrow,toArrow:e.toArrow||i.toArrow,lineWidth:o}}createDrawingLine(t){this.inactive();const{data:e,options:i}=this.store,n=e.scale,o=e.lineWidth||1;return t.penId=et(),{id:t.penId,name:"line",lineName:this.drawingLineName,x:t.x,y:t.y,type:r.Line,calculative:{canvas:this,active:!0,worldAnchors:[t],lineWidth:o*n},fromArrow:e.fromArrow||i.fromArrow,toArrow:e.toArrow||i.toArrow,lineWidth:o}}addRuleLine(t){const{x:e,y:i}=this.store.data,n=t.x+e,o=t.y+i;let s=t.x,a=t.y,c=0,l=0,h=0,u=0;if(n<=o&&n<20)s=-e,c=this.width,h=1;else{if(!(o{const{x:i,y:n}=this.movingPens[e];Object.assign(t,{x:i,y:n}),t.onMove?.(t),this.updatePenRect(t),this.updateLines(t),this.store.emitter.emit("updateLines",t),this.patchFlagsLines.forEach((t=>{t.type&&this.initLineRect(t)})),this.patchFlagsLines.clear(),t.calculative.x=t.x,t.calculative.y=t.y,t.calculative.initRect&&(t.calculative.initRect.x=t.calculative.x,t.calculative.initRect.y=t.calculative.y,t.calculative.initRect.ex=t.calculative.x+t.calculative.width,t.calculative.initRect.ey=t.calculative.y+t.calculative.height)})),this.initImageCanvas(this.store.active);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=K(this.store.active,!0);if(t&&1===this.store.active.length&&1===r?.type&&(i?.anchorId||n?.anchorId)){const t=Kt(r),s=Yt(r);if(i?.anchorId){const n=this.store.pens[this.store.active[0].id+pn].calculative.worldAnchors.find((t=>t.id===i.anchorId));n.x===t.x&&n.y===t.y?(e.push(K(r,!0)),Wt(this.store.active[0],n,r,t),o.push(K(r,!0))):n.x===s.x&&n.y===s.y&&(e.push(K(r,!0)),Wt(this.store.active[0],n,r,s),o.push(K(r,!0)))}else if(n?.anchorId){const i=this.store.pens[this.store.active[0].id+pn].calculative.worldAnchors.find((t=>t.id===n.anchorId));i.x===t.x&&i.y===t.y?(e.push(K(r,!0)),Wt(this.store.active[0],i,r,t),o.push(K(r,!0))):i.x===s.x&&i.y===s.y&&(e.push(K(r,!0)),Wt(this.store.active[0],i,r,s),o.push(K(r,!0)))}}this.pushHistory({type:F.Update,pens:o,initPens:e}),this.store.emitter.emit("translatePens",o)}copyMovedPens(){this.copy(this.store.active.map(((t,e)=>{const{x:i,y:n}=this.movingPens[e];return this.updateLines(t),{...t,x:i,y:n}}))),this.pasteOffset=0,this.paste()}initImageCanvas(t){t.some((t=>this.hasImage(t,!1)))&&this.canvasImage.init(),t.some((t=>this.hasImage(t,!0)))&&this.canvasImageBottom.init()}hasImage(t,e){return!(!t.image||"gif"===t.name||!t.isBottom!=!e)||t.children?.some((t=>{const i=this.store.pens[t];return i&&this.hasImage(i,e)}))}inactive(t){this.store.active.length&&(this.store.active.forEach((t=>{t.calculative.active=void 0,t.calculative.activeAnchor=void 0,Zt(t,!1)})),!t&&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(t,e=!0){if(this.store.active)for(const t of this.store.active)t.calculative.active=void 0,Zt(t,!1);this.store.active=[],t.forEach((t=>{t.calculative.active=!0,Zt(t)})),this.store.active.push(...t),this.calcActiveRect(),this.patchFlags=!0,e&&this.store.emitter.emit("active",this.store.active)}getSizeCPs(){this.sizeCPs=Se(this.activeRect);const{x:t,y:e,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+t,y:s.y*n+e};S(a,r,o),this.sizeCPs.push(a)}))}clearHover(){this.hoverType=v.None,this.store.hover=null,this.store.hoverAnchor=null}inAnchor(t,e,i){if(this.store.hoverAnchor=void 0,this.movingAnchor=void 0,!i||i.locked>o.DisableEdit)return v.None;if(this.store.options.disableAnchor||e.disableAnchor)return v.None;if((this.mouseDown||this.drawingLine)&&"line"===e.name&&i.connectTo){const t=this.findOne(i.connectTo);if(t?.calculative&&!t?.calculative.active){e=t;const n=t.calculative.worldAnchors.find((t=>t.id===i.anchorId));n&&(i=n)}}if(i.twoWay===A.Disable&&"line"!==e.name)return v.None;if("line"===e.name&&i.connectTo){let t=this.findOne(i.connectTo)?.anchors.find((t=>t.id===i.anchorId));if(t&&t.twoWay)return v.None}if(this.drawingLine){if(i.twoWay===A.Out)return v.None}else if(this.mouseDown&&this.hoverType===v.LineAnchor);else if(i.twoWay===A.In)return v.None;if(P(t,i,this.pointSize))return i!==this.store.hoverAnchor&&(this.patchFlags=!0),this.store.hoverAnchor=i,this.store.hover=e,e.type?i.connectTo&&!e.calculative.active&&(this.store.hover=this.store.pens[i.connectTo],this.store.hover)?(this.store.hoverAnchor=this.store.hover.calculative.worldAnchors.find((t=>t.id===i.anchorId)),this.externalElements.style.cursor="crosshair",v.NodeAnchor):(this.hotkeyType===g.AddAnchor?this.externalElements.style.cursor="vertical-text":this.externalElements.style.cursor="pointer",v.LineAnchor):(this.hotkeyType===g.AddAnchor?this.externalElements.style.cursor="vertical-text":this.externalElements.style.cursor="crosshair",v.NodeAnchor);if(!this.mouseDown&&e.type){if(e.calculative.active&&i.prev&&P(t,i.prev,this.pointSize))return this.store.hoverAnchor=i,this.store.hover=e,this.externalElements.style.cursor="pointer",v.LineAnchorPrev;if(e.calculative.active&&i.next&&P(t,i.next,this.pointSize))return this.store.hoverAnchor=i,this.store.hover=e,this.externalElements.style.cursor="pointer",v.LineAnchorNext}return v.None}resize(t,e){t=t||this.parentElement.clientWidth,e=e||this.parentElement.clientHeight,this.width=t,this.height=e,this.canvasRect={x:0,y:0,width:t,height:e},Te(this.canvasRect),this.canvas.style.width=t+"px",this.canvas.style.height=e+"px",this.externalElements.style.width=t+"px",this.externalElements.style.height=e+"px",this.canvasImage.resize(t,e),this.canvasImageBottom.resize(t,e),this.magnifierCanvas.resize(t,e),t=t*this.store.dpiRatio|0,e=e*this.store.dpiRatio|0,this.canvas.width=t,this.canvas.height=e,this.offscreen.width=t,this.offscreen.height=e,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 t of this.store.data.pens)ce(t)}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(t,e,i){if(!(this.beforeAddPens&&1!=await this.beforeAddPens([t])||this.beforeAddPen&&1!=this.beforeAddPen(t)))return this.makePen(t),this.active([t]),this.render(),i&&this.store.emitter.emit("add",[t]),e&&this.pushHistory({type:F.Add,pens:[t]}),t}pushHistory(t){if(this.store.data.locked)return;const{origin:e,scale:i}=this.store.data;t.origin=K(e),t.scale=i,t.type!==F.Update&&t.pens&&t.pens.forEach((t=>{t.calculative&&(t.calculative.layer=this.store.data.pens.findIndex((e=>e.id===t.id)))})),this.store.historyIndex{let i;if(t.initPens)for(const n of t.initPens)n.id===e.id&&(i=n);if(i)for(const t in e)null==i[t]&&(i[t]=void 0)})),this.store.histories.push(t),this.store.historyIndex=this.store.histories.length-1,this.store.emitter.emit("update",{previous:t.initPens,current:t.pens})}undo(){if(this.store.data.locked||null==this.store.historyIndex||this.store.historyIndex<0)return;const t=this.store.histories[this.store.historyIndex--];this.doEditAction(t,!0);let e=t.step;for(;e>1;){const t=this.store.histories[this.store.historyIndex--];this.doEditAction(t,!0),e--}t.type!=F.Add&&t.type!=F.Delete||this.activeHistory()}redo(){if(this.store.data.locked||null==this.store.historyIndex||this.store.historyIndex>this.store.histories.length-2)return;const t=this.store.histories[++this.store.historyIndex];this.doEditAction(t,!1);let e=t.step;for(;e>1;){const t=this.store.histories[++this.store.historyIndex];this.doEditAction(t,!1),e--}t.type!=F.Add&&t.type!=F.Delete||this.activeHistory()}activeHistory(){let t=this.store.histories[this.store.historyIndex];if(t&&t.type===F.Add){const e=[];t.pens.forEach((t=>{e.push(this.store.pens[t.id])})),this.active(e)}}doEditAction(t,e){switch(this.inactive(),this.store.hoverAnchor=void 0,this.store.hover=void 0,t.type){case F.Add:t.pens.forEach((t=>{const e=K(t,!0),i=this.store.data.pens.findIndex((t=>t.id===e.id));i>-1&&(this.store.data.pens.splice(i,1),this.store.pens[e.id]=void 0,e.calculative.canvas=this,this.store.animates.delete(e),this.store.animateMap.delete(e),e.onDestroy?.(e))})),t.type=F.Delete;break;case F.Update:const i=e?t.initPens:t.pens,n=e?t.pens:t.initPens;i.forEach((e=>{const i=K(e,!0),r=this.store.data.pens.findIndex((t=>t.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 t in i)"object"==typeof i[t]&&"lineDash"!==t||(i.calculative[t]=i[t]);i.calculative.image=void 0;const e=this.getPenRect(i,t.origin,t.scale);if(this.setPenRect(i,e,!1),this.updateLines(i,!0),i.calculative.canvas.parent.isCombine(i)){let t=n.find((t=>t.id===i.id));k.forEach((e=>{i[e]!==t[e]&&this.parent.setValue({id:i.id,[e]:i[e]},{render:!0,doEvent:!1})}))}}}));break;case F.Delete:t.pens.forEach((t=>{const e=K(t,!0);this.store.data.pens.splice(e.calculative.layer,0,e),this.store.pens[e.id]=e,e.calculative.canvas=this})),t.pens.forEach((e=>{const i=this.store.pens[e.id],n=this.getPenRect(i,t.origin,t.scale);this.setPenRect(i,n,!1),i.calculative.image=void 0,i.calculative.backgroundImage=void 0,i.calculative.strokeImage=void 0,this.loadImage(i)})),t.type=F.Add}t.type===F.Update?this.initImageCanvas([...t.pens,...t.initPens]):this.initImageCanvas(t.pens),this.render(),this.store.emitter.emit(e?"undo":"redo",t)}makePen(t){if(t.id||(t.id=et()),this.store.data.pens.push(t),this.store.pens[t.id]=t,t.path){!t.pathId&&(t.pathId=et());const e=this.store.data.paths;!e[t.pathId]&&(e[t.pathId]=t.path),t.path=void 0}null==t.lineWidth&&(t.lineWidth=1);const{fontSize:e,lineHeight:i}=this.store.options;t.fontSize||(t.fontSize=e),t.lineHeight||(t.lineHeight=i),t.calculative={canvas:this,singleton:t.calculative?.singleton},(t.video||t.audio)&&(t.calculative.onended=t=>{this.nextAnimate(t)});for(const e in t)"object"==typeof t[e]&&"lineDash"!==e||(t.calculative[e]=t[e]);t.calculative.image=void 0,t.calculative.backgroundImage=void 0,t.calculative.strokeImage=void 0,!t.anchors&&M.anchors[t.name]&&(t.anchors||(t.anchors=[]),M.anchors[t.name](t)),this.updatePenRect(t),!t.anchors&&t.calculative.worldAnchors&&(t.anchors=t.calculative.worldAnchors.map((e=>Me(e,t.calculative.worldRect)))),!t.rotate&&(t.rotate=0),this.loadImage(t)}drawline(t){this.drawingLine&&(this[this.drawingLineName]?.(this.store,this.drawingLine,t),this.store.path2dMap.set(this.drawingLine,M.path2dDraws.line(this.drawingLine)),this.patchFlags=!0)}initLineRect(t){if(!t)return;if(!t.calculative.worldAnchors?.length)return void this._del([t]);if(!isFinite(t.x)||!isFinite(t.x))return;if(null==t.x||null==t.y)return;const e=Ze(t);t.parentId||Object.assign(t,e);const{fontSize:i,lineHeight:n}=this.store.options;t.fontSize||(t.fontSize=i,t.calculative.fontSize=t.fontSize*this.store.data.scale),t.lineHeight||(t.lineHeight=n,t.calculative.lineHeight=t.lineHeight),ke(e),t.calculative.worldRect=e,Bt(t,e),j(t),ce(t),this.store.path2dMap.set(t,M.path2dDraws[t.name](t)),t.calculative.worldAnchors&&(t.anchors=t.calculative.worldAnchors.map((e=>Me(e,t.calculative.worldRect))))}drawingPencil(){fn(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(t){if(!this.drawingLine)return;const e=Kt(this.drawingLine);let i=Yt(this.drawingLine);if(i.isTemp&&(this.drawingLine.calculative.worldAnchors.pop(),i=Yt(this.drawingLine)),!t&&(!i.connectTo&&this.drawingLine.calculative.worldAnchors.pop(),Kt(this.drawingLine)===this.drawingLine.calculative.activeAnchor))return this.drawingLine=void 0,void this.render();if(e.connectTo&&i.connectTo){if(this.store.options.disableRepeatLine&&this.store.data.pens.find((t=>{if(t.type){const n=Kt(t),r=Yt(t);return I(n,e)&&I(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=Ze(this.drawingLine);Object.assign(this.drawingLine,n),this.drawingLine.calculative.worldRect=n,this.drawingLine.calculative.activeAnchor=Yt(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:F.Add,pens:K([this.drawingLine],!0)})),this.store.path2dMap.set(this.drawingLine,M.path2dDraws[this.drawingLine.name](this.drawingLine)),this.drawingLine=void 0,this.drawingLineName=void 0,this.render()}async finishPencil(){if(this.pencilLine){const t=fi(this.pencilLine.calculative.worldAnchors,10,0,this.pencilLine.calculative.worldAnchors.length-1);let e=Kt(this.pencilLine);t.unshift({id:e.id,penId:e.penId,x:e.x,y:e.y}),e=Yt(this.pencilLine),t.push({id:e.id,penId:e.penId,x:e.x,y:e.y}),this.pencilLine.calculative.worldAnchors=function(t,e=.8,i=!1){if(t.length<3)return t;let n,r,o,s,a,c,l,h,u,d,f,p,v,g,y,m;const w=(t,e,i,n)=>(s=Math.sqrt(t*t+e*e),s>0?(v=t/s,y=e/s):(v=1,y=0),a=Math.sqrt(i*i+n*n),a>0?(g=i/a,m=n/a):(g=1,m=0),Math.acos(v*g+y*m));f=[],p=t.length,n=t[0],h=t[p-1],f.push({...t[0]});for(let h=0;h1&&(this.pencilLine.calculative.pencil=!1,this.store.path2dMap.set(this.pencilLine,M.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:F.Add,pens:K([this.pencilLine],!0)}))),this.pencilLine=void 0,this.render()}}firefoxLoadSvg(t){const e=new Image,i=new XMLHttpRequest;i.open("GET",t.image,!0),i.onload=()=>{const n=(new DOMParser).parseFromString(i.responseText,"text/xml").getElementsByTagName("svg")[0],{width:r,height:o}=t.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))));e.src=s,e.onload=()=>{t.calculative.img=e,t.calculative.imgNaturalWidth=e.naturalWidth||t.iconWidth,t.calculative.imgNaturalHeight=e.naturalHeight||t.iconHeight,M.htmlElements[t.image]=e,this.imageLoaded()}},i.send()}loadImage(t){if(t.image!==t.calculative.image){if(t.calculative.img=void 0,t.image)if(M.htmlElements[t.image]){const e=M.htmlElements[t.image];t.calculative.img=e,t.calculative.imgNaturalWidth=e.naturalWidth||t.iconWidth,t.calculative.imgNaturalHeight=e.naturalHeight||t.iconHeight,this.imageLoaded()}else if(navigator.userAgent.includes("Firefox")&&t.image.endsWith(".svg"))this.firefoxLoadSvg(t);else{const e=new Image;e.crossOrigin="anonymous",e.src=t.image,e.onload=()=>{t.calculative.img=e,t.calculative.imgNaturalWidth=e.naturalWidth||t.iconWidth,t.calculative.imgNaturalHeight=e.naturalHeight||t.iconHeight,M.htmlElements[t.image]=e,this.imageLoaded()}}t.calculative.image=t.image}if(t.backgroundImage!==t.calculative.backgroundImage){if(t.calculative.backgroundImg=void 0,t.backgroundImage)if(M.htmlElements[t.backgroundImage]){const e=M.htmlElements[t.backgroundImage];t.calculative.backgroundImg=e}else{const e=new Image;e.crossOrigin="anonymous",e.src=t.backgroundImage,e.onload=()=>{t.calculative.backgroundImg=e,M.htmlElements[t.backgroundImage]=e,this.imageLoaded()}}t.calculative.backgroundImage=t.backgroundImage}if(t.strokeImage!==t.calculative.strokeImage){if(t.calculative.strokeImg=void 0,t.strokeImage)if(M.htmlElements[t.strokeImage]){const e=M.htmlElements[t.strokeImage];t.calculative.strokeImg=e}else{const e=new Image;e.crossOrigin="anonymous",e.src=t.strokeImage,e.onload=()=>{t.calculative.strokeImg=e,M.htmlElements[t.strokeImage]=e,this.imageLoaded()}}t.calculative.strokeImage=t.strokeImage}}imageLoaded(){this.imageTimer&&clearTimeout(this.imageTimer),this.imageTimer=setTimeout((()=>{this.canvasImage.init(),this.canvasImageBottom.init(),this.render()}),100)}setCalculativeByScale(t){const e=this.store.data.scale;t.calculative.lineWidth=t.lineWidth*e,t.calculative.fontSize=t.fontSize*e,t.fontSize<1&&(t.calculative.fontSize=t.fontSize*t.calculative.worldRect.height),t.calculative.iconSize=t.iconSize*e,t.calculative.iconWidth=t.iconWidth*e,t.calculative.iconHeight=t.iconHeight*e,t.calculative.iconLeft=t.iconLeft<1&&t.iconLeft>-1?t.iconLeft:t.iconLeft*e,t.calculative.iconTop=t.iconTop<1&&t.iconTop>-1?t.iconTop:t.iconTop*e,t.calculative.textWidth=t.textWidth<1&&t.textWidth>-1?t.textWidth:t.textWidth*e,t.calculative.textHeight=t.textHeight<1&&t.textHeight>-1?t.textHeight:t.textHeight*e,t.calculative.textLeft=t.textLeft<1&&t.textLeft>-1?t.textLeft:t.textLeft*e,t.calculative.textTop=t.textTop<1&&t.textTop>-1?t.textTop:t.textTop*e,t.type===r.Line&&t.borderWidth&&(t.calculative.borderWidth=t.borderWidth*e)}updatePenRect(t,{worldRectIsReady:e,playingAnimate:i}={}){e?Nt(t):Dt(t),i||this.setCalculativeByScale(t),Ot(t),zt(this.store.pens,t),j(t),ce(t),M.path2dDraws[t.name]&&this.store.path2dMap.set(t,M.path2dDraws[t.name](t)),t.calculative.patchFlags=!0,this.patchFlags=!0,t.children&&t.children.forEach((t=>{const e=this.store.pens[t];e&&this.updatePenRect(e,{worldRectIsReady:!1})})),t.type&&this.initLineRect(t),t.calculative.gradientTimer&&clearTimeout(t.calculative.gradientTimer),t.calculative.gradientTimer=setTimeout((()=>{t.calculative.lineGradient&&(t.calculative.lineGradient=null),t.calculative.gradient&&(t.calculative.gradient=null),t.calculative.radialGradient&&(t.calculative.radialGradient=null),this.patchFlags=!0,t.calculative.gradientTimer=void 0}),50)}translate(t=0,e=0){this.store.data.x+=t*this.store.data.scale,this.store.data.y+=e*this.store.data.scale,this.store.data.x=Math.round(this.store.data.x),this.store.data.y=Math.round(this.store.data.y),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(t,e),this.scroll&&this.scroll.isShow&&this.scroll.translate(t,e),this.onMovePens()}onMovePens(){const t=this.parent.map;t&&t.isShow&&t.setView();for(const t of this.store.data.pens)ce(t),t.onMove?.(t),t.isRuleLine&&(t.width?t.height||(t.x=-this.store.data.x):t.y=-this.store.data.y,this.updatePenRect(t))}scale(t,e={x:0,y:0}){const{minScale:i,maxScale:n}=this.store.options;if(!(t>=i&&t<=n))return;this.calibrateMouse(e);const r=t/this.store.data.scale;this.store.data.scale=t,this.store.data.center=e,this.store.clipboard?.pos&&C(this.store.clipboard.pos,r,e),C(this.store.data.origin,r,e),this.store.data.pens.forEach((t=>{if(!t.parentId){if(Ft(t,r,e),t.isRuleLine){const e=r>1?1:1/r/r,i=t.calculative.worldRect.center;t.width&&t.height||Ft(t,e,i)}this.updatePenRect(t,{worldRectIsReady:!0}),this.execPenResize(t)}})),this.calcActiveRect(),this.canvasImage.init(),this.canvasImageBottom.init();const o=this.parent.map;o&&o.isShow&&o.setView(),this.render(),this.store.emitter.emit("scale",this.store.data.scale)}rotatePens(t){this.initPens||(this.initPens=K(this.getAllByPens(this.store.active))),this.activeRect.rotate=R(t,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 e=this.activeRect.rotate-this.lastRotate;for(const t of this.store.active){if(t.parentId)return;this.rotatePen(t,e,this.activeRect),t.onRotate&&t.onRotate(t),this.updateLines(t)}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:F.Update,pens:K(this.getAllByPens(this.store.active)),initPens:this.initPens}),this.initPens=void 0}),200)}resizePens(t){if(this.initPens||(this.initPens=K(this.store.active,!0)),!this.initActiveRect)return void(this.initActiveRect=K(this.activeRect));const e=this.mouseDown.x,i=this.mouseDown.y;let n=t.x-e,r=t.y-i;const o=K(this.initActiveRect);if((t.shiftKey||1==this.initPens.length&&this.initPens[0].ratio)&&(n=o.width/o.height*r),Ee(o,n,r,this.resizeIndex),ke(o),!this.store.options.disableDock){this.clearDock();const t=this.customResizeDock||ve;this.dock=t(this.store,o,this.store.active,this.resizeIndex);const{xDock:e,yDock:i}=this.dock;e&&(n+=e.step,this.store.pens[e.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,t.ctrlKey&&(l=([1,3].includes(this.resizeIndex)?-1:1)*(c*a)/s),Ee(this.activeRect,c,l,this.resizeIndex),ke(this.activeRect);const h=this.activeRect.width/s,u=this.activeRect.height/a;this.store.active.forEach(((t,e)=>{t.calculative.worldRect.x=this.activeInitPos[e].x*this.activeRect.width+this.activeRect.x,t.calculative.worldRect.y=this.activeInitPos[e].y*this.activeRect.height+this.activeRect.y,t.calculative.worldRect.width*=h,t.calculative.iconWidth&&(t.calculative.iconWidth*=h),t.calculative.worldRect.height*=u,t.calculative.iconHeight&&(t.calculative.iconHeight*=u),Te(t.calculative.worldRect),ke(t.calculative.worldRect),this.updatePenRect(t,{worldRectIsReady:!0}),this.execPenResize(t),this.updateLines(t)})),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:F.Update,pens:K(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0}),200)}movePens(t){if(!this.activeRect||this.store.data.locked)return;if(!this.initActiveRect)return void(this.initActiveRect=K(this.activeRect));if(!this.store.options.moveConnectedLine&&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((t=>{te(t,!1)})),this.store.hover=void 0),!this.mouseDown)return;let e=t.x-this.mouseDown.x,i=t.y-this.mouseDown.y;t.shiftKey&&!t.ctrlKey&&(i=0),t.ctrlKey&&(e=0);const n=K(this.initActiveRect);Re(n,e,i);const r={x:n.x-this.activeRect.x,y:n.y-this.activeRect.y};if(!this.store.options.disableDock){this.clearDock();const t=this.customMoveDock||fe;this.dock=t(this.store,n,this.movingPens,r);const{xDock:e,yDock:i}=this.dock;let o;e&&(r.x+=e.step,o=this.store.pens[e.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(t,e){t.id+=pn,t.parentId&&e.find((e=>e.id===t.parentId))&&(t.parentId+=pn),t.children&&(t.children=t.children.map((t=>t+pn))),t.connectedLines&&(t.connectedLines=t.connectedLines.map((t=>(e.find((e=>e.id===t.lineId))&&(t.lineId+=pn),t)))),t.type&&t.calculative.worldAnchors&&(t.calculative.worldAnchors=t.calculative.worldAnchors.map((t=>(t.connectTo&&e.find((e=>e.id===t.connectTo))&&(t.connectTo+=pn),t))))}initMovingPens(){if(!this.store.options.moveConnectedLine)for(let t=0;t{this.changeIdsByMoving(t,e),this.store.pens[t.id]=t,t.calculative.canvas=this;const i={globalAlpha:.5};0===t.lineWidth&&(i.lineWidth=1),(f.includes(t.name)||t.image)&&(i.name="rectangle",i.onDestroy=void 0),this.updateValue(t,i),t.calculative.image=void 0}))}moveLineAnchor(t,e){if(!this.activeRect||this.store.data.locked)return;if(this.initPens||(this.initPens=K(this.store.active,!0)),this.store.activeAnchor?.connectTo){const t=this.store.pens[this.store.activeAnchor.connectTo];qt(t,Vt(t,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((t=>t.anchor===i));n&&n.length>0&&n.forEach((t=>{const e=this.store.pens[t.lineId];qt(this.store.pens[this.store.activeAnchor.penId],this.store.activeAnchor,e,Vt(e,t.lineAnchor))}));const r=this.store.active[0],o=(Kt(r),Yt(r));if("polyline"!==r.lineName||e.shiftKey){let e=t.x-this.store.activeAnchor.x,i=t.y-this.store.activeAnchor.y;E(this.store.activeAnchor,e,i),this.store.hover&&this.store.hoverAnchor&&this.store.hoverAnchor.penId!==this.store.activeAnchor.penId&&(e=this.store.hoverAnchor.x-this.store.activeAnchor.x,i=this.store.hoverAnchor.y-this.store.activeAnchor.y,E(this.store.activeAnchor,e,i),o.prev=void 0,"polyline"!==r.lineName&&this[r.lineName]?.(this.store,r))}else!function(t,e,i){if(!t.calculative.worldAnchors)return;const n=t.calculative.worldAnchors.findIndex((t=>t.id===e.id)),r=Kt(t),o=Yt(t);let s=t.calculative.worldAnchors[n-1],a=t.calculative.worldAnchors[n+1];if(null==t.calculative.h&&(r.connectTo&&(ui(t,e,!0)?t.calculative.h=!0:di(t,e,!0)&&(t.calculative.h=!1)),null==t.calculative.h&&o.connectTo&&(ui(t,e,!1)?t.calculative.h=!0:di(t,e,!1)&&(t.calculative.h=!1)),null==t.calculative.h&&(s?t.calculative.h=s.y===e.y:a&&(t.calculative.h=a.y===e.y))),t.calculative.h){if(e.x=i.x,r.connectTo&&ui(t,e,!0))return void(a&&a.y!==e.y&&(a.x=e.x));if(o.connectTo&&ui(t,e,!1))return void(s&&s.y!==e.y&&(s.x=e.x));const c=t.anchors[n];let l;for(let e=n-1;e>-1;e--)if(s=t.anchors[e],null==l&&(l=s.y===c.y),!0===l){if(s.y!==c.y)break;t.calculative.worldAnchors[e].y=i.y}else{if(s.x!==c.x)break;t.calculative.worldAnchors[e].x=i.x}l=void 0;for(let e=n+1;e-1;e--)if(s=t.anchors[e],null==l&&(l=s.x===c.x),!0===l){if(s.x!==c.x)break;t.calculative.worldAnchors[e].x=i.x}else{if(s.y!==c.y)break;t.calculative.worldAnchors[e].y=i.y}l=void 0;for(let e=n+1;e{this.timer=void 0,this.pushHistory({type:F.Update,pens:K(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0}),500)}moveLineAnchorPrev(t){if(!this.activeRect||this.store.data.locked||!this.store.activeAnchor)return;if(this.initPens||(this.initPens=K(this.store.active,!0)),this.store.activeAnchor.prev.x=t.x,this.store.activeAnchor.prev.y=t.y,this.store.activeAnchor.next)if(this.store.activeAnchor.prevNextType){if(this.store.activeAnchor.prevNextType===T.Bilateral&&this.prevAnchor){const e=R(t,this.store.activeAnchor),i=R(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,e-i,this.store.activeAnchor)}}else this.store.activeAnchor.next.x=t.x,this.store.activeAnchor.next.y=t.y,S(this.store.activeAnchor.next,180,this.store.activeAnchor);const e=this.store.active[0];this.patchFlagsLines.add(e),this.store.path2dMap.set(e,M.path2dDraws[e.name](e)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0,this.pushHistory({type:F.Update,pens:K(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0}),200)}moveLineAnchorNext(t){if(!this.activeRect||this.store.data.locked)return;if(this.initPens||(this.initPens=K(this.store.active,!0)),this.store.activeAnchor.next.x=t.x,this.store.activeAnchor.next.y=t.y,this.store.activeAnchor.prev)if(this.store.activeAnchor.prevNextType){if(this.store.activeAnchor.prevNextType===T.Bilateral&&this.nextAnchor){const e=R(t,this.store.activeAnchor),i=R(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,e-i,this.store.activeAnchor)}}else this.store.activeAnchor.prev.x=t.x,this.store.activeAnchor.prev.y=t.y,S(this.store.activeAnchor.prev,180,this.store.activeAnchor);const e=this.store.active[0];this.patchFlagsLines.add(e),this.store.path2dMap.set(e,M.path2dDraws[e.name](e)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0,this.pushHistory({type:F.Update,pens:K(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0}),200)}async setAnchor(t){const e=[K(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(t,e){if(!t||!t.calculative.worldAnchors)return;let i=t.calculative.worldAnchors.findIndex((t=>t.id===e.id));i>-1&&t.calculative.worldAnchors.splice(i,1),i=t.anchors.findIndex((t=>t.id===e.id)),i>-1&&t.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(t,e,i){t.anchors||(t.anchors=[]),t.calculative.worldAnchors||(t.calculative.worldAnchors=[]);const n=function(t,e,i){let n=t.calculative.worldAnchors[i],r=t.calculative.worldAnchors[i+1];const o=e.step;let s;if(n.next&&r.prev){const e=n,i=n.next,a=r.prev,c=r,l=Xe(e,i,o),h=Xe(i,a,o),u=Xe(a,c,o),d=Xe(l,h,o),f=Xe(h,u,o);s=Xe(d,f,o),d.penId=t.id,s.prev=d,f.penId=t.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=Xe(i,a,o),h=Xe(a,c,o);s=e,l.penId=t.id,h.penId=t.id,s.prev=l,s.next=h,n.next=void 0,r.prev=void 0}else s=e;return s.penId=t.id,s.id=et(),s.prevNextType=T.Bilateral,s}(t,e,i);return t.calculative.worldAnchors.splice(i+1,0,n),t.anchors.splice(i+1,0,Me(n,t.calculative.worldRect)),t.calculative.activeAnchor=n,n}(i,this.store.pointAt,this.store.pointAtIndex),this.initLineRect(i);const e={x:t.x,y:t.y};this.getHover(e)}else{const e={id:et(),x:t.x,y:t.y};this.store.activeAnchor=function(t,e){t.anchors||(t.anchors=[]),t.calculative.worldAnchors||(t.calculative.worldAnchors=[]);const i={id:e.id,penId:t.id,x:e.x,y:e.y};if(t.calculative.worldAnchors.push(i),t.calculative.worldRect){t.rotate%360&&S(e,-t.rotate,t.calculative.worldRect.center);const i={id:e.id,penId:t.id,x:(e.x-t.calculative.worldRect.x)/t.calculative.worldRect.width,y:(e.y-t.calculative.worldRect.y)/t.calculative.worldRect.height};t.anchors.push(i)}return i}(i,e)}}this.hotkeyType=g.None,this.render(),i&&this.pushHistory({type:F.Update,pens:[K(i,!0)],initPens:e})}checkDisconnect(t,e){if(t.id.indexOf(pn)>0){const e=t.id;t=this.store.pens[e.replace(pn,"")]}t.anchors.forEach((i=>{if(i.connectTo&&!e.find((t=>t.id===i.connectTo||t.id===i.connectTo+pn))){const e=this.store.pens[i.connectTo];if(!e||e.type)return;qt(e,Vt(e,i.anchorId),t,i)}}))}translatePens(t=this.store.active,e,i,n){if(!t||!t.length)return;if(t.some((t=>{if(t.locked>=o.DisableMove)return!0})))return;const s=!n&&K(t,!0);this.activeRect&&Re(this.activeRect,e,i);const a=this.getAllByPens(t);t.forEach((t=>{if(!(t.locked>=o.DisableMove)){if(t.type===r.Line){if(!this.store.options.moveConnectedLine)return;!function(t,e,i){t.x+=e,t.y+=i,t.anchors&&t.anchors.forEach((t=>{E(t,e,i)})),t.calculative.worldAnchors&&t.calculative.worldAnchors.forEach((t=>{E(t,e,i)}))}(t,e,i),this.checkDisconnect(t,a),this.store.path2dMap.set(t,M.path2dDraws[t.name](t)),n||(this.initLineRect(t),t.connectedLines?.forEach((t=>{const e=this.store.pens[t.lineId];this.initLineRect(e)})))}else Re(t.calculative.worldRect,e,i),this.updatePenRect(t,{worldRectIsReady:!0}),t.calculative.x=t.x,t.calculative.y=t.y,t.calculative.initRect&&(t.calculative.initRect.x=t.calculative.x,t.calculative.initRect.y=t.calculative.y,t.calculative.initRect.ex=t.calculative.x+t.calculative.width,t.calculative.initRect.ey=t.calculative.y+t.calculative.height);this.updateLines(t),t.onMove?.(t)}})),this.activeRect&&this.getSizeCPs(),this.render(),this.tooltip.translate(e,i),n||(this.pushHistory({type:F.Update,pens:K(t,!0),initPens:s}),this.initImageCanvas(t),this.store.emitter.emit("translatePens",t)),this.store.emitter.emit("translatingPens",t)}calcAutoAnchor(t,e,i,n){const r=Kt(t),o=Yt(t),s=Ht(i,e===r?o:r);e.x=s.x,e.y=s.y,e.prev=void 0,e.next=void 0,n?n.anchor=s.id:Wt(i,s,t,e),this[t.lineName]&&this[t.lineName](this.store,t),this.store.path2dMap.set(t,M.path2dDraws.line(t)),this.initLineRect(t)}restoreNodeAnimate(t){if(t.calculative.initRect){if(t.keepAnimateState)for(const e in t)void 0!==t.calculative[e]&&("x"===e||"y"===e||"width"===e||"height"===e||"initRect"===e||"object"==typeof t[e]&&"lineDash"!==e||(t[e]="fontSize"===e?t.calculative[e]/t.calculative.canvas.store.data.scale:t.calculative[e]));else{const e=t.calculative.initRect.rotate-t.calculative.rotate;for(const e in t)"x"===e||"y"===e||"width"===e||"height"===e||"initRect"===e||"rotate"===e||"object"==typeof t[e]&&"lineDash"!==e||(t.calculative[e]=t[e]);t.children?.length?e&&re(t,e,t.calculative.worldRect):t.calculative.rotate=t.rotate;const i=K(this.store.animateMap.get(t));i&&(i.id=t.id,this.parent.setValue(i,{doEvent:!1,render:!0,history:!1})),t.calculative.worldRect=t.calculative.initRect}this.updatePenRect(t,{worldRectIsReady:!0}),t.calculative.text!==t.text&&(t.calculative.text=t.text,U(t)),t.calculative.initRect=void 0}}updateLines(t,e){t.children?.forEach((t=>{const i=this.store.pens[t];i&&this.updateLines(i,e)})),t.connectedLines&&t.connectedLines.forEach((i=>{const n=this.store.pens[i.lineId];if(!n||n.calculative.active)return;const r=Vt(n,i.lineAnchor);if(!r)return;if(n.autoFrom){const e=Kt(n);e.id===r.id&&this.calcAutoAnchor(n,e,t,i)}if(n.autoTo){const e=Yt(n);e.id===r.id&&this.calcAutoAnchor(n,e,t,i)}const o=Vt(t,i.anchor);if(o){if(E(r,o.x-r.x,o.y-r.y),this.store.options.autoPolyline&&!1!==n.autoPolyline&&"polyline"===n.lineName){let t=Kt(n),e=Yt(n),i=!1;t.id===r.id?(t=r,i=!0):e.id===r.id&&(e=r,i=!0),i&&(n.calculative.worldAnchors=[t,e],n.calculative.activeAnchor=t,this.polyline(this.store,n,e),this.initLineRect(n))}this.store.path2dMap.set(n,M.path2dDraws[n.name](n)),this.patchFlagsLines.add(n),e&&oi(n)}}))}calcActiveRect(){const t=this.store.active.filter((t=>(!t.locked||t.locked{S(t,e,i.center)})),this.initLineRect(t),Nt(t)):(t.calculative.rotate?t.calculative.rotate+=e:t.calculative.rotate=e,S(t.calculative.worldRect.center,e,i.center),t.parentId?(t.calculative.worldRect.x=t.calculative.worldRect.center.x-t.calculative.worldRect.width/2,t.calculative.worldRect.y=t.calculative.worldRect.center.y-t.calculative.worldRect.height/2,t.x=(t.calculative.worldRect.x-i.x)/i.width,t.y=(t.calculative.worldRect.y-i.y)/i.height):(t.x=t.calculative.worldRect.center.x-t.width/2,t.y=t.calculative.worldRect.center.y-t.height/2),t.rotate=t.calculative.rotate,this.updatePenRect(t),t.children&&t.children.forEach((i=>{const n=this.store.pens[i];this.rotatePen(n,e,t.calculative.worldRect)})))}nextAnimate(t){if(!t)return;let e;this.store.emitter.emit("animateEnd",t),t.nextAnimate&&(e=this.store.data.pens.filter((e=>e.id===t.nextAnimate||e.tags&&e.tags.indexOf(t.nextAnimate)>-1))),e&&(e.forEach((t=>{if(t.calculative.pause){const e=Date.now()-t.calculative.pause;t.calculative.pause=void 0,t.calculative.frameStart+=e,t.calculative.frameEnd+=e}else"video"===t.name?(t.calculative.media.currentTime=0,t.calculative.media?.play(),t.onStartVideo?.(t)):(t.type||t.frames?.length)&&(t.type||this.store.animateMap.set(t,this.getFrameProps(t)),this.store.animates.add(t))})),this.animate())}getFrameProps(t){let e={};return t.frames&&t.frames.forEach((i=>{for(let n in i)["duration","x","y","width","height","rotate"].includes(n)||e[n]||(e[n]=t[n])})),e}animate(){this.animateRendering||requestAnimationFrame((()=>{const t=Date.now();if(t-this.lastAnimateRender0&&this.animate());this.lastAnimateRender=t,this.animateRendering=!0;const e=[];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(!Jt(n)){if(n.keepAnimateState){for(const t in n)void 0!==n.calculative[t]&&("object"==typeof n[t]&&"lineDash"!==t||(n[t]="lineWidth"===t?n.calculative[t]/n.calculative.canvas.store.data.scale:n.calculative[t]));Nt(n)}else for(const t in n)"object"==typeof n[t]&&"lineDash"!==t||(n.calculative[t]="lineWidth"===t?n[t]*n.calculative.canvas.store.data.scale:n[t]);e.push(n),this.nextAnimate(n)}}else Xt(n,t)?n.calculative.patchFlags&&(ke(n.calculative.worldRect),this.updatePenRect(n,{worldRectIsReady:!0,playingAnimate:!0})):(requestAnimationFrame((()=>{this.restoreNodeAnimate(n)})),e.push(n),this.nextAnimate(n)),this.updateLines(n,!0);this.patchFlags=!0}i&&this.calcActiveRect(),e.forEach((t=>{this.store.animates.delete(t)})),this.render(!1),this.animateRendering=!1,this.animate()}))}get clipboardName(){return"meta2d-clipboard"}async copy(t){const e=et(),{origin:i,scale:n}=this.store.data;this.store.clipboard=void 0,localStorage.removeItem(this.clipboardName),sessionStorage.setItem("page",e);const r={meta2d:!0,pens:this.getAllByPens(K(t||this.store.active,!0)),origin:K(i),scale:n,page:e,initRect:K(this.activeRect),offset:10};if(!navigator.clipboard||this.store.options.disableClipboard||navigator.userAgent.includes("Firefox"))localStorage.setItem(this.clipboardName,JSON.stringify(r));else try{await navigator.clipboard.writeText(JSON.stringify(r))}catch{localStorage.setItem(this.clipboardName,JSON.stringify(r))}}cut(t){this.copy(t),this.delete(t)}async paste(){let t,e,i,n;if(!navigator.clipboard||this.store.options.disableClipboard||navigator.userAgent.includes("Firefox"))t=localStorage.getItem(this.clipboardName);else try{t=await(navigator.clipboard?.readText())}catch{t=localStorage.getItem(this.clipboardName)}if(!t)return;try{e=JSON.parse(t)}catch(t){return void console.warn("剪切板数据不是json",t.message)}if(!e||!e.meta2d)return;if(this.beforeAddPens&&1!=await this.beforeAddPens(e.pens))return;this.store.clipboard&&(i=this.store.clipboard.offset+10,n=this.store.clipboard.pos),this.store.clipboard=K(e),sessionStorage.getItem("page")!==e.page?(this.store.clipboard.pos={x:this.mousePos.x,y:this.mousePos.y},this.store.clipboard.offset=0):(i&&(this.store.clipboard.offset=i),n&&(this.store.clipboard.pos=n));const r=this.store.clipboard.pens.filter((t=>!t.parentId));for(const t of r)this.pastePen(t,void 0);sessionStorage.setItem("page",e.page),this.active(r),this.pushHistory({type:F.Add,pens:this.store.clipboard.pens}),this.render(),this.store.emitter.emit("add",this.store.clipboard.pens)}getAllByPens(t){const e=[];for(const i of t)e.push(...K(st(i,this.store),!0));return e.concat(t)}changeLineAnchors(t,e,i){if(Array.isArray(e.connectedLines))for(let n=0;nt.id===r));if(o){const i=o.anchors[0],n=o.anchors[o.anchors.length-1];i.connectTo===t&&(i.connectTo=e.id),n.connectTo===t&&(n.connectTo=e.id)}else e.connectedLines.splice(n,1),n--}}changeNodeConnectedLine(t,e,i){const n=[e.anchors[0],e.anchors[e.anchors.length-1]];for(const r of n){const n=r.connectTo;if(n){const o=i.find((t=>t.id===n));o?o.connectedLines?.forEach((i=>{i.lineId===t&&(i.lineId=e.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(t=this.store.active,e=!1,i=!0){if(!t||!t.length)return;if(this.beforeRemovePens&&1!=await this.beforeRemovePens(t))return;if(e||(t=t.filter((t=>!t.locked))),!t||!t.length)return;const n=[];this._del(t,n),this.initImageCanvas(n),this.inactive(),this.clearHover(),this.render(),i&&this.pushHistory({type:F.Delete,pens:n}),this.store.emitter.emit("delete",t)}_del(t,e){t&&t.forEach((t=>{if(t.parentId){if(this.getLockedParent(t))return void console.warn("父节点锁定");{const i=ot(t),n=i.children.indexOf(t.id);i.children.splice(n,1),e&&this.getDelPens(t,e),this.delForce(t)}}else{if(t.locked)return;e&&this.getDelPens(t,e),this.delForce(t)}}))}getDelPens(t,e){if(t){if(this.store.data.pens.findIndex((e=>e.id===t.id))>-1){const i=this.store.pens[t.id];i.calculative.active=void 0,e.push(i)}t.children&&t.children.forEach((t=>{this.getDelPens(this.store.pens[t],e)}))}}getLockedParent(t){if(!t.parentId)return!1;const e=ot(t);if(e.locked)return e;this.getLockedParent(e)}delForce(t){if(!t)return;const e=this.store.data.pens.findIndex((e=>e.id===t.id));e>-1&&(this.delConnectedLines(this.store.data.pens[e]),this.store.data.pens.splice(e,1),this.store.pens[t.id]=void 0,delete this.store.pens[t.id]),this.store.animates.delete(t),this.store.animateMap.delete(t),t.children&&t.children.forEach((t=>{this.delForce(this.store.pens[t])})),t.onDestroy?.(t)}delConnectedLines(t){if(t.connectedLines)for(let e=0;et.id===n));e?.connectTo===t.id&&(e.connectTo=void 0,e.anchorId=void 0,e.prev&&(e.prev.connectTo=void 0),e.next&&(e.next.connectTo=void 0)),e=Vt(r,n),e&&(e.connectTo=void 0,e.anchorId=void 0,e.prev&&(e.prev.connectTo=void 0),e.next&&(e.next.connectTo=void 0))}}t.type&&t.calculative.worldAnchors?.forEach(((e,i)=>{if(!e.connectTo)return;const n=this.store.pens[e.connectTo];n&&n.calculative.worldAnchors?.forEach((i=>{qt(n,i,t,e)}))}))}createInput(){let t;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 e=0;e{t.stopPropagation();const e=this.store.pens[this.inputDiv.dataset.penId];"block"===this.dropdown.style.display?(this.dropdown.style.display="none",this.inputRight.style.transform="rotate(135deg)"):e?.dropdownList&&this.store.data.locked&&(this.dropdown.style.display="block",this.inputRight.style.transform="rotate(315deg)"),this.store.emitter.emit("clickInput",e)},this.inputDiv.onkeyup=t=>{this.setDropdownList(!0);const e=this.store.pens[this.inputDiv.dataset.penId];this.store.emitter.emit("input",{pen:e,text:t.key}),t.stopPropagation()},this.inputDiv.onkeydown=t=>{t.stopPropagation()},this.inputDiv.onmousedown=this.stopPropagation,this.inputDiv.onwheel=t=>{t.stopPropagation()},this.inputDiv.onpaste=t=>{t.preventDefault();let e="";t.clipboardData&&t.clipboardData.getData&&(e=t.clipboardData.getData("text/plain")),document.execCommand("insertHTML",!1,e)}}clearDropdownList(){if(this.dropdown.hasChildNodes())for(let t=0;te.id==t||e.tags&&e.tags.indexOf(t)>-1))}findOne(t){return this.store.data.pens.find((e=>e.id==t||e.tags&&e.tags.indexOf(t)>-1))}changePenId(t,e){if(t===e)return;const i=this.store.pens[t];if(i&&!this.store.pens[e]){if(i.id=e,this.store.pens[e]=this.store.pens[t],i.onChangeId?.(i,t,e),delete this.store.pens[t],i.parentId){const n=this.store.pens[i.parentId],r=n.children?.findIndex((e=>e===t));-1!==r&&n.children?.splice(r,1,e)}i.children?.forEach((t=>{this.store.pens[t].parentId=e})),i.type===r.Line?this.changeNodeConnectedLine(t,i,this.store.data.pens):(this.changeLineAnchors(t,i,this.store.data.pens),i.connectedLines?.forEach((({lineId:t})=>{Ot(this.store.pens[t])})))}}updateValue(t,e){const i=this.getPenRect(t),n=t.name;Object.assign(t,e);const r=n!==t.name;e.newId&&this.changePenId(t.id,e.newId);let o,s=!1,a=!1,d=!1,f=!1,p=!1,v=!1,g=!1;for(const i in e)"rotate"===i&&(o=t.calculative.rotate||0),"object"==typeof t[i]&&"lineDash"!==i||(t.calculative[i]=e[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&&(g=!0);if(this.setCalculativeByScale(t),r&&(t.onDestroy?.(t),function(t){t.onAdd=void 0,t.onValue=void 0,t.onBeforeValue=void 0,t.onDestroy=void 0,t.onMove=void 0,t.onResize=void 0,t.onRotate=void 0,t.onClick=void 0,t.onMouseEnter=void 0,t.onMouseLeave=void 0,t.onMouseDown=void 0,t.onMouseMove=void 0,t.onMouseUp=void 0,t.onShowInput=void 0,t.onInput=void 0,t.onChangeId=void 0,t.onBinds=void 0}(t)),p){const n={x:e.x??i.x,y:e.y??i.y,width:e.width??i.width,height:e.height??i.height};this.setPenRect(t,n,!1),this.updateLines(t,!0)}else d?this.updatePenRect(t):(a&&j(t),f&&zt(this.store.pens,t),s&&M.path2dDraws[t.name]&&this.store.path2dMap.set(t,M.path2dDraws[t.name](t)));if(void 0!==o){const e=t.calculative.rotate;t.calculative.rotate=o,this.rotatePen(t,e-o,t.calculative.worldRect)}(e.image||e.backgroundImage||e.strokeImage)&&(t.calculative.image=void 0,t.calculative.backgroundImage=void 0,t.calculative.strokeImage=void 0,this.loadImage(t)),e.lineGradientColors&&(t.calculative.lineGradient=void 0,t.calculative.gradientColorStop=void 0),e.gradientColors&&(t.calculative.gradient=void 0,t.calculative.radialGradient=void 0),e.animateLineWidth&&(t.calculative.gradientAnimatePath=void 0),e.gradientSmooth&&(t.calculative.gradientAnimatePath=void 0),v?(this.canvasImage.init(),this.canvasImageBottom.init()):g?t.isBottom?this.canvasImageBottom.init():this.canvasImage.init():this.initImageCanvas([t])}execPenResize(t){t.onResize?.(t),t.children?.forEach((t=>{const e=this.store.pens[t];e&&this.execPenResize(e)}))}setPenRect(t,e,i=!0){if(t.parentId)Object.assign(t,e);else{const{origin:i,scale:n}=this.store.data;t.x=i.x+e.x*n,t.y=i.y+e.y*n,t.width=e.width*n,t.height=e.height*n}this.updatePenRect(t),this.execPenResize(t),i&&this.render()}getPenRect(t,e=this.store.data.origin,i=this.store.data.scale){if(t)return t.parentId?{x:t.x,y:t.y,width:t.width,height:t.height}:{x:(t.x-e.x)/i,y:(t.y-e.y)/i,width:t.width/i,height:t.height/i}}toPng(t=2,e,i=!1){const n=Ae(this.store.data.pens);if(!isFinite(n.width))throw new Error("can not to png, because width is not finite");const r=K(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,Te(n),Ce(n,this.canvasRect,!0))Object.assign(n,this.canvasRect);else{const t=Pe([...Se(n),...Se(this.canvasRect)]);Object.assign(n,t)}a=0===n.x,c=0===n.y}const l=nt(t);n.x-=l[3],n.y-=l[0],n.width+=l[3]+l[1],n.height+=l[0]+l[2],Te(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 t=n.x<0?-n.x:0,e=n.y<0?-n.y:0;u.drawImage(this.store.bkImg,t,e,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 t of this.store.data.pens){if(!ae(t,this.store)||0==t.visible)continue;const{active:e}=t.calculative;t.calculative.active=!1,t.calculative.img?_t(u,t):Pt(u,t),t.calculative.active=e}if(!e)return h.toDataURL();h.toBlob(e)}toggleAnchorMode(){if(this.hotkeyType)this.hotkeyType===g.AddAnchor&&(this.hotkeyType=g.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=g.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 t=[K(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:F.Update,pens:[K(this.store.active[0],!0)],initPens:t})}}removeAnchorHand(){if(this.store.activeAnchor&&this.store.active&&1===this.store.active.length&&this.store.active[0].type){const t=[K(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:F.Update,pens:[K(this.store.active[0])],initPens:t})}}toggleAnchorHand(){1===this.store.active.length&&this.store.active[0].type&&this.store.activeAnchor&&(this.store.activeAnchor.prevNextType||(this.store.activeAnchor.prevNextType=T.Mirror),this.store.activeAnchor.prevNextType=(this.store.activeAnchor.prevNextType+1)%3)}gotoView(t,e){const i=Ae(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-t*i.width-i.x,this.store.data.y=this.canvas.clientHeight/2-e*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.externalElements.removeEventListener("gesturestart",this.onGesturestart),this.externalElements.ondragover=t=>t.preventDefault(),this.externalElements.ondrop=void 0,it()?(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 O.Document:document.removeEventListener("keydown",this.onkeydown),document.removeEventListener("keyup",this.onkeyup);break;case O.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 gn;!function(t){t[t.Link=0]="Link",t[t.SetProps=1]="SetProps",t[t.StartAnimate=2]="StartAnimate",t[t.PauseAnimate=3]="PauseAnimate",t[t.StopAnimate=4]="StopAnimate",t[t.JS=5]="JS",t[t.GlobalFn=6]="GlobalFn",t[t.Emit=7]="Emit",t[t.StartVideo=8]="StartVideo",t[t.PauseVideo=9]="PauseVideo",t[t.StopVideo=10]="StopVideo",t[t.SendPropData=11]="SendPropData",t[t.SendVarData=12]="SendVarData"}(gn||(gn={}));class yn{constructor(t){let e;this.parent=t,this.boxWidth=320,this.boxHeight=180,this.ratio=this.boxWidth/this.boxHeight,this.padding=5,this.onMouseDown=t=>{t.preventDefault(),t.stopPropagation(),this.isDown=!0},this.onMouseMove=t=>{if(t.preventDefault(),t.stopPropagation(),this.isDown)try{this.parent.gotoView(t.offsetX/this.box.clientWidth,t.offsetY/this.box.clientHeight)}catch(t){console.warn(t.message),this.isDown=!1}},this.onMouseUp=t=>{t.preventDefault(),t.stopPropagation();try{this.parent.gotoView(t.offsetX/this.box.clientWidth,t.offsetY/this.box.clientHeight)}catch(t){console.warn(t.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 t=0;tthis.ratio){const t=e.width/this.ratio;e.y-=(t-e.height)/2,e.height=t,Te(e)}else{const t=e.height*this.ratio;e.x-=(t-e.width)/2,e.width=t,Te(e)}const i=this.parent.canvasRect;let n=0,r=0;if(e.x<0)n=-e.x/e.width;else if(e.x+e.width>i.width){let t=0;i.width>e.width&&(t=i.width-e.width),n=(-e.x+t)/e.width}if(e.y<0)r=-e.y/e.height;else if(e.y+e.height>i.height){let t=0;i.height>e.height&&(t=i.height-e.height),r=(-e.y+t)/e.height}const o=i.width>e.width?1:i.width/e.width,s=i.height>e.height?1:i.height/e.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 mn,wn,bn=i(421);class xn{constructor(i,n={}){this.events={},this.facePen=jt,this.getWords=W,this.calcTextLines=U,this.calcTextRect=j,this.calcTextDrawRect=H,this.register=D,this.registerCanvasDraw=B,this.registerAnchors=N,this.httpTimerList=[],this.onEvent=(t,e)=>{switch(t){case"add":e.forEach((t=>{t.onAdd?.(t)})),this.onSizeUpdate();break;case"enter":e&&e.onMouseEnter&&e.onMouseEnter(e,this.canvas.mousePos),this.store.data.locked&&this.doEvent(e,t);break;case"leave":e&&e.onMouseLeave&&e.onMouseLeave(e,this.canvas.mousePos),this.store.data.locked&&this.doEvent(e,t);break;case"active":case"inactive":this.store.data.locked&&e.forEach((e=>{this.doEvent(e,t)}));break;case"click":e.pen&&e.pen.onClick&&e.pen.onClick(e.pen,this.canvas.mousePos),this.store.data.locked&&e.pen&&this.doEvent(e.pen,t);break;case"mousedown":e.pen&&e.pen.onMouseDown&&e.pen.onMouseDown(e.pen,this.canvas.mousePos),this.store.data.locked&&e.pen&&this.doEvent(e.pen,t);break;case"mouseup":e.pen&&e.pen.onMouseUp&&e.pen.onMouseUp(e.pen,this.canvas.mousePos),this.store.data.locked&&e.pen&&this.doEvent(e.pen,t);break;case"dblclick":this.store.data.locked&&e.pen&&this.doEvent(e.pen,t);break;case"valueUpdate":this.store.data.locked&&this.doEvent(e,t),this.canvas.tooltip.updateText(e);break;case"update":case"delete":case"translatePens":case"rotatePens":case"resizePens":this.onSizeUpdate()}},this.doEvent=(t,e)=>{t&&(t.events?.forEach((i=>{if(this.events[i.action]&&i.name===e){let e=!i.where?.type;if(i.where){const{fn:n,fnJs:r,comparison:o,key:s,value:a}=i.where;if(n)e=n(t);else if(r){try{i.where.fn=new Function("pen",r)}catch(t){console.error("Error: make function:",t)}i.where.fn&&(e=i.where.fn(t))}else switch(o){case">":e=t[s]>+a;break;case">=":e=t[s]>=+a;break;case"<":e=t[s]<+a;break;case"<=":e=t[s]<=+a;break;case"=":case"==":e=t[s]==a;break;case"!=":e=t[s]!=a;break;case"[)":e=Z(+t[s],a);break;case"![)":e=!Z(+t[s],a);break;case"[]":e=tt(+t[s],a);break;case"![]":e=!tt(+t[s],a)}}e&&this.events[i.action](t,i)}})),this.doEvent(this.store.pens[t.parentId],e))},this.renderPenRaw=_t,this.setElemPosition=ee,this.store=((t="default")=>{var e;return M[t]||(M[t]={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:{...z},emitter:{all:e=e||new Map,on:function(t,i){var n=e.get(t);n&&n.push(i)||e.set(t,[i])},off:function(t,i){var n=e.get(t);n&&n.splice(n.indexOf(i)>>>0,1)},emit:function(t,i){(e.get(t)||[]).slice().map((function(t){t(i)})),(e.get("*")||[]).slice().map((function(e){e(t,i)}))}},bindDatas:{}},M[t].id=t),M[t]})(et()),this.setOptions(n),this.setDatabyOptions(n),this.init(i),this.register({rectangle:t,square:e,circle:Ci,svgPath:He,diamond:Ri,triangle:_i,pentagon:Ii,pentagram:Mi,hexagon:Ni,leftArrow:Oi,rightArrow:zi,twowayArrow:Fi,message:ji,cloud:Hi,file:Ui,people:Wi,line:Ge,iframe:vi,video:bi,gif:Ki,mindNode:Zi,mindLine:sn}),this.registerCanvasDraw({cube:Ue}),this.registerAnchors({triangle:Ei,pentagon:Li,pentagram:Di,mindNode:nn,mindLine:an}),globalThis.meta2d=this,this.initEventFns(),this.store.emitter.on("*",this.onEvent)}get beforeAddPen(){return this.canvas.beforeAddPen}set beforeAddPen(t){this.canvas.beforeAddPen=t}get beforeAddPens(){return this.canvas.beforeAddPens}set beforeAddPens(t){this.canvas.beforeAddPens=t}get beforeAddAnchor(){return this.canvas.beforeAddAnchor}set beforeAddAnchor(t){this.canvas.beforeAddAnchor=t}get beforeRemovePens(){return this.canvas.beforeRemovePens}set beforeRemovePens(t){this.canvas.beforeRemovePens=t}get beforeRemoveAnchor(){return this.canvas.beforeRemoveAnchor}set beforeRemoveAnchor(t){this.canvas.beforeRemoveAnchor=t}setOptions(t={}){this.store.options=Object.assign(this.store.options,t)}getOptions(){return this.store.options}setDatabyOptions(t={}){const{color:e,activeColor:i,activeBackground:n,grid:r,gridColor:o,gridSize:s,fromArrow:a,toArrow:c,rule:l,ruleColor:h}=t;this.setRule({rule:l,ruleColor:h}),this.setGrid({grid:r,gridColor:o,gridSize:s}),this.store.data=Object.assign(this.store.data,{color:e,activeColor:i,activeBackground:n,fromArrow:a,toArrow:c})}init(t){this.canvas=new vn(this,"string"==typeof t?document.getElementById(t):t,this.store),this.resize(),this.canvas.listen()}initEventFns(){this.events[gn.Link]=(t,e)=>{window&&e.value&&"string"==typeof e.value?window.open(e.value,e.params??"_blank"):console.warn("[meta2d] Link param is not a string")},this.events[gn.SetProps]=(t,e)=>{const i=e.value;if(i&&"object"==typeof i)return(e.params?this.find(e.params):[t]).forEach((t=>{i.hasOwnProperty("visible")&&this.setVisible(t,i.visible),this.setValue({id:t.id,...i},{render:!1,doEvent:!1})})),void this.render();console.warn("[meta2d] SetProps value is not an object")},this.events[gn.StartAnimate]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[meta2d] StartAnimate value is not a string"):this.startAnimate(e.value||[t])},this.events[gn.PauseAnimate]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[meta2d] PauseAnimate value is not a string"):this.pauseAnimate(e.value||[t])},this.events[gn.StopAnimate]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[meta2d] StopAnimate event value is not a string"):this.stopAnimate(e.value||[t])},this.events[gn.StartVideo]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[meta2d] StartVideo value is not a string"):this.startVideo(e.value||[t])},this.events[gn.PauseVideo]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[meta2d] PauseVideo value is not a string"):this.pauseVideo(e.value||[t])},this.events[gn.StopVideo]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[meta2d] StopVideo event value is not a string"):this.stopVideo(e.value||[t])},this.events[gn.JS]=(t,e)=>{if(e.value&&!e.fn)try{if("string"!=typeof e.value)throw new Error("[meta2d] Function value must be string");const t=e.value;e.fn=new Function("pen","params",t)}catch(t){console.error("[meta2d]: Error on make a function:",t)}e.fn?.(t,e.params)},this.events[gn.GlobalFn]=(t,e)=>{"string"==typeof e.value?globalThis[e.value]&&globalThis[e.value](t,e.params):console.warn("[meta2d] GlobalFn value must be a string")},this.events[gn.Emit]=(t,e)=>{"string"==typeof e.value?this.store.emitter.emit(e.value,{pen:t,params:e.params}):console.warn("[meta2d] Emit value must be a string")},this.events[gn.SendPropData]=(t,e)=>{const i=K(e.value);if(i&&"object"==typeof i){const n=e.params?this.findOne(e.params):t;for(let t in i)i[t]||(i[t]=n[t]);return i.id=n.id,void this.doSendDataEvent(i,e.extend)}console.warn("[meta2d] SendPropData value is not an object")},this.events[gn.SendVarData]=(t,e)=>{const i=K(e.value);if(i&&"object"==typeof i){const n=e.params?this.findOne(e.params):t;let r=[];for(let t in i){let e={dataId:t,value:i[t]};if(!e.value){let t=n.form.find((t=>t.dataIds&&t.dataIds.dataId===e.dataId));t&&(e.value=n[t.key])}r.push(e)}this.doSendDataEvent(r,e.extend)}else console.warn("[meta2d] SendVarData value is not an object")}}doSendDataEvent(t,e){let i=JSON.stringify(t);this.mqttClient&&this.mqttClient.connected&&(e?e.split(",").forEach((t=>{this.mqttClient.publish(t,i)})):this.store.data.mqttTopics&&this.store.data.mqttTopics.split(",").forEach((t=>{this.mqttClient.publish(t,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)}resize(t,e){this.canvas.resize(t,e),this.render(),this.store.emitter.emit("resize",{width:t,height:e}),this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.init()}async addPen(t,e,i=!0){return await this.canvas.addPen(t,e,i)}async addPens(t,e){return await this.canvas.addPens(t,e)}render(t){this.canvas.render(t)}async setBackgroundImage(t){if(this.store.data.bkImage=t,this.canvas.canvasImageBottom.canvas.style.backgroundImage=t?`url(${t})`:"",t){const e=await async function(t){return new Promise((e=>{const i=new Image;i.src=t,i.crossOrigin="anonymous",i.onload=()=>{e(i)}}))}(t);this.store.bkImg=e}else this.store.bkImg=null}setBackgroundColor(t=this.store.data.background){this.store.data.background=t,this.store.patchFlagsBackground=!0}setGrid({grid:t=this.store.data.grid,gridColor:e=this.store.data.gridColor,gridSize:i=this.store.data.gridSize,gridRotate:n=this.store.data.gridRotate}={}){this.store.data.grid=t,this.store.data.gridColor=e,this.store.data.gridSize=i,this.store.data.gridRotate=n,this.store.patchFlagsBackground=!0}setRule({rule:t=this.store.data.rule,ruleColor:e=this.store.data.ruleColor}={}){this.store.data.rule=t,this.store.data.ruleColor=e,this.store.patchFlagsTop=!0}open(t){if(this.clear(!1),t){this.setBackgroundImage(t.bkImage),Object.assign(this.store.data,t),this.store.data.pens=[];for(const e of t.pens)e.id||(e.id=et()),!e.calculative&&(e.calculative={canvas:this.canvas}),this.store.pens[e.id]=e;for(const e of t.pens)this.canvas.makePen(e)}this.initBindDatas(),this.render(),this.listenSocket(),this.connectSocket(),this.startAnimate(),this.startVideo(),this.doInitJS(),this.store.emitter.emit("opened"),this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.init()}initBindDatas(){this.store.bindDatas={},this.store.data.pens.forEach((t=>{t.form?.forEach((e=>{let i;e.dataIds&&(i=Array.isArray(e.dataIds)?e.dataIds:[e.dataIds]),i?.forEach((i=>{this.store.bindDatas[i.dataId]||(this.store.bindDatas[i.dataId]=[]),this.store.bindDatas[i.dataId].push({id:t.id,formItem:e})}))}))}))}connectSocket(){this.connectWebsocket(),this.connectMqtt(),this.connectHttp()}doInitJS(){const t=this.store.data.initJs;if(t&&t.trim())try{new Function(t)()}catch(t){console.warn("initJs error",t)}}drawLine(t){t&&fn(this.store),this.canvas.drawingLineName=t}drawingPencil(){this.canvas.drawingPencil()}stopPencil(){this.canvas.stopPencil()}lock(t){this.store.data.locked=t,this.finishDrawLine(!0),this.canvas.drawingLineName="",this.stopPencil(),0===t&&this.store.data.pens.forEach((t=>{!0===t.externElement&&t.onMove&&t.onMove(t)}))}async finishDrawLine(t){await this.canvas.finishDrawline(t)}async finishPencil(){await this.canvas.finishPencil()}updateLineType(t,e){if(!t||"line"!=t.name||!e||!this.canvas[e])return;t.lineName=e;const i=Kt(t),n=Yt(t);i.prev=void 0,i.next=void 0,n.prev=void 0,n.next=void 0,t.calculative.worldAnchors=[i,n],t.calculative.activeAnchor=i,this.canvas[e](this.store,t,n),"curve"===t.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}),t.calculative.activeAnchor=void 0,this.canvas.initLineRect(t),this.render()}addDrawLineFn(t,e){this.canvas[t]=e,this.canvas.drawLineFns.push(t)}removeDrawLineFn(t){const e=this.canvas.drawLineFns.indexOf(t);e>-1&&this.canvas.drawLineFns.splice(e,1)}showMagnifier(){this.canvas.showMagnifier()}hideMagnifier(){this.canvas.hideMagnifier()}toggleMagnifier(){this.canvas.toggleMagnifier()}clear(t=!0){for(const t of this.store.data.pens)t.onDestroy?.(t);var e;(e=this.store).data={x:0,y:0,scale:1,pens:[],origin:{x:0,y:0},center:{x:0,y:0},paths:{}},e.pens={},e.histories=[],e.historyIndex=null,e.path2dMap=new WeakMap,e.animateMap=new WeakMap,e.bindDatas={},e.active=[],e.hover=void 0,e.lastHover=void 0,e.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),t&&this.render()}emit(t,e){this.store.emitter.emit(t,e)}on(t,e){return this.store.emitter.on(t,e),this}off(t,e){return this.store.emitter.off(t,e),this}registerMoveDock(t){this.canvas.customMoveDock=t}registerResizeDock(t){this.canvas.customResizeDock=t}find(t){return this.canvas.find(t)}findOne(t){return this.canvas.findOne(t)}getPenRect(t){return this.canvas.getPenRect(t)}setPenRect(t,e,i=!0){this.canvas.setPenRect(t,e,i)}startAnimate(t){let e;e=t?"string"==typeof t?this.find(t):t:this.store.data.pens.filter((t=>(t.type||t.frames)&&t.autoPlay)),e.forEach((t=>{if(t.calculative.pause){const e=Date.now()-t.calculative.pause;t.calculative.pause=void 0,t.calculative.frameStart+=e,t.calculative.frameEnd+=e}else this.store.animates.add(t),t.type||this.store.animateMap.set(t,t.calculative.canvas.getFrameProps(t))})),this.canvas.canvasImage.init(),this.canvas.canvasImageBottom.init(),this.canvas.animate()}pauseAnimate(t){let e=[];t?e="string"==typeof t?this.find(t):t:this.store.animates.forEach((t=>{e.push(t)})),e.forEach((t=>{t.calculative.pause||(t.calculative.pause=Date.now())}))}stopAnimate(t){let e=[];t?e="string"==typeof t?this.find(t):t:this.store.animates.forEach((t=>{e.push(t)})),e.forEach((t=>{t.calculative.pause=void 0,t.calculative.start=void 0,t.calculative.duration=void 0,t.calculative.animatePos=0,this.store.animates.delete(t),this.canvas.restoreNodeAnimate(t),this.canvas.updateLines(t),this.store.animateMap.delete(t)})),this.initImageCanvas(e),setTimeout((()=>{this.canvas.calcActiveRect(),this.render()}),20)}startVideo(t){let e;e=t?"string"==typeof t?this.find(t):t:this.store.data.pens.filter((t=>(t.video||t.audio)&&t.autoPlay)),e.forEach((t=>{t.calculative.media?.play(),t.onStartVideo?.(t)}))}pauseVideo(t){let e=[];e=t?"string"==typeof t?this.find(t):t:this.store.data.pens.filter((t=>(t.video||t.audio)&&t.autoPlay)),e.forEach((t=>{t.calculative.media?.pause(),t.onPauseVideo?.(t)}))}stopVideo(t){let e=[];e=t?"string"==typeof t?this.find(t):t:this.store.data.pens.filter((t=>(t.video||t.audio)&&t.autoPlay)),e.forEach((t=>{t.calculative.media&&(t.calculative.media.currentTime=0,t.calculative.media.pause()),t.onStopVideo?.(t)}))}calcAnimateDuration(t){return t.frames.reduce(((t,e)=>t+e.duration),0)}combine(t=this.store.active,e){if(!t||!t.length)return;const i=K(t);if(1===t.length&&t[0].type)return t[0].type=r.Node,this.canvas.active(t),this.pushHistory({type:F.Update,initPens:i,pens:K(t,!0)}),void this.render();const n=Ae(t);let s={id:et(),name:"combine",...n,children:[],showChild:e};this.canvas.makePen(s),t.forEach((t=>{if(t===s||t.parentId===s.id)return;s.children.push(t.id),t.parentId=s.id;const e=Le(t.calculative.worldRect,n);Object.assign(t,e),t.locked=t.lockedOnCombine??o.DisableMove})),this.canvas.active([s]),this.pushHistory({type:F.Update,initPens:i,pens:t,step:1}),null!=e&&(t.forEach((t=>{ce(t,!0)})),this.initImageCanvas([s])),this.store.emitter.emit("combine",[s]),this.render()}uncombine(t){if(!t&&this.store.active&&(t=this.store.active[0]),!t||!t.children)return;const e=t.children.map((t=>this.store.pens[t]));let i=K(e);e.forEach((t=>{t.parentId=void 0,t.x=t.calculative.worldRect.x,t.y=t.calculative.worldRect.y,t.width=t.calculative.worldRect.width,t.height=t.calculative.worldRect.height,t.locked=o.None,t.calculative.active=void 0,t.calculative.hover=!1,this.setVisible(t,!0)}));const n=this.isCombine(t)?3:2;this.pushHistory({type:F.Update,initPens:i,pens:e,step:n}),i=[K(t)],t.children=void 0,this.pushHistory({type:F.Update,initPens:i,pens:[t],step:n}),this.isCombine(t)&&(this.delete([t]),this.store.histories[this.store.histories.length-1].step=n),this.inactive()}isCombine(t){return"combine"===t.name||!!(t.children&&t.children.length>0)}active(t,e=!0){this.canvas.active(t,e)}inactive(){this.canvas.inactive()}delete(t,e=!1,i=!0){this.canvas.delete(t,e,i)}scale(t,e={x:0,y:0}){this.canvas.scale(t,e)}translate(t,e){this.canvas.translate(t,e)}translatePens(t,e,i){this.canvas.translatePens(t,e,i)}getParent(t,e){return ot(t,e)}data(){const t=K(this.store.data),{pens:e,paths:i}=this.store.data;t.version=L,t.paths={};for(const n in i)Object.prototype.hasOwnProperty.call(i,n)&&e.find((t=>t.pathId===n))&&(t.paths[n]=i[n]);return t}copy(t){this.canvas.copy(t)}cut(t){this.canvas.cut(t)}paste(){this.canvas.paste()}undo(){this.canvas.undo()}redo(){this.canvas.redo()}listenSocket(){try{let t;const e=this.store.data.socketCbJs;if(e&&(t=new Function("e","topic",e)),!t)return!1;this.socketFn=t}catch(t){return console.error("Create the function for socket:",t),!1}return!0}connectWebsocket(t){this.closeWebsocket(),t&&(this.store.data.websocket=t),this.store.data.websocket&&(this.websocket=new WebSocket(this.store.data.websocket),this.websocket.onmessage=t=>{this.socketCallback(t.data)},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(t){this.closeMqtt(),t&&(this.store.data.mqtt=t.mqtt,this.store.data.mqttTopics=t.mqttTopics,this.store.data.mqttOptions=t.mqttOptions),this.store.data.mqtt&&(this.store.data.mqttOptions.clientId&&!this.store.data.mqttOptions.customClientId&&(this.store.data.mqttOptions.clientId=et()),this.mqttClient=bn.connect(this.store.data.mqtt,this.store.data.mqttOptions),this.mqttClient.on("message",((t,e)=>{this.socketCallback(e.toString(),t)})),this.store.data.mqttTopics&&this.mqttClient.subscribe(this.store.data.mqttTopics.split(",")))}closeMqtt(){this.mqttClient?.end()}connectHttp(){this.closeHttp();const{https:t}=this.store.data;if(t)t.forEach(((t,e)=>{t.http&&(this.httpTimerList[e]=setInterval((async()=>{const e=await fetch(t.http,{headers:t.httpHeaders});if(e.ok){const t=await e.text();this.socketCallback(t)}}),t.httpTimeInterval||1e3))}));else{const{http:t,httpTimeInterval:e,httpHeaders:i}=this.store.data;t&&(this.httpTimer=setInterval((async()=>{const e=await fetch(t,{headers:i});if(e.ok){const t=await e.text();this.socketCallback(t)}}),e||1e3))}}async sendDatabyHttp(t){const{https:e}=this.store.data;if(e)e.forEach((async e=>{e.http&&(await fetch(e.http,{method:"post",body:t,headers:e.httpHeaders})).ok&&console.info("http消息发送成功")}));else{const{http:e,httpHeaders:i}=this.store.data;e&&(await fetch(e,{method:"post",body:t,headers:i})).ok&&console.info("http消息发送成功")}}closeHttp(){clearInterval(this.httpTimer),this.httpTimer=void 0,this.httpTimerList&&this.httpTimerList.forEach((t=>{clearInterval(t),t=void 0}))}socketCallback(t,e=""){if(this.store.emitter.emit("socket",{message:t,topic:e}),this.socketFn&&!this.socketFn(t,e))return;let i;if(t.constructor===Object||t.constructor===Array)i=t;else{if("string"!=typeof t)return;try{i=JSON.parse(t)}catch(t){console.warn("Invalid socket data:",i,t)}}i&&(Array.isArray(i)||(i=[i]),i[0].dataId?this.setDatas(i):i.forEach((t=>{this.setValue(t)})))}setDatas(t,{render:e=!0,doEvent:i=!0,history:n}={}){const r=new Map;let o,s;t.forEach((e=>{this.store.bindDatas[e.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]=e.value:(o={id:i.id,[i.formItem.key]:e.value},r.set(n,o));else{if(o)return;r.set(n,n.onBinds(n,t,i.formItem))}}))})),n&&(o=[]),r.forEach(((t,e)=>{this.setValue(t,{render:!1,doEvent:i,history:!1}),n&&(o.push(K(e,!0)),s.push(e))})),e&&this.render(),n&&this.pushHistory({type:F.Update,initPens:o,pens:s})}setValue(t,{render:e=!0,doEvent:i=!0,history:n}={}){let r,o=[];if(t.id){if(t.id===this.store.data.id)return this.setDatabyOptions(t),t.bkImage&&this.setBackgroundImage(t.bkImage),t.background&&this.setBackgroundColor(t.background),void this.render();const e=this.store.pens[t.id];e&&(o=[e])}else{if(t.dataId)return o=[],void this.setDatas([t],{render:e,doEvent:i,history:n});if(!t.tag)return;o=this.find(t.tag)}(n=n&&!this.store.data.locked)&&(r=K(o)),o.forEach((e=>{const i=e.onBeforeValue?e.onBeforeValue(e,t):t;t.frames&&(this.stopAnimate([e]),t.showDuration||(t.showDuration=t.frames.reduce(((t,e)=>t+e.duration),0))),ue(e,i),this.canvas.updateValue(e,i),e.onValue?.(e)})),this.store.data.locked||!this.store.active.length||this.canvas.movingPens||this.canvas.calcActiveRect(),n&&this.pushHistory({type:F.Update,initPens:r,pens:o}),i&&o.forEach((t=>{this.store.emitter.emit("valueUpdate",t)})),e&&this.render()}_setValue(t,e=!1){this.setValue(t,{history:e,render:!1,doEvent:!1})}pushHistory(t){this.canvas.pushHistory(t)}showInput(t,e){this.canvas.showInput(t,e)}hideInput(){this.canvas.hideInput()}clearDropdownList(){this.canvas.clearDropdownList()}pushChildren(t,e){const i=[K(t,!0)],n=[];t.children||(t.children=[]);const r=[];e.forEach((e=>{let s=K(e,!0);if(e.id&&this.store.pens[e.id]||(this.canvas.makePen(e),s=null),e.parentId){const t=this.store.pens[e.parentId],n=t.children.findIndex((t=>t===e.id));i.push(K(t,!0)),t.children.splice(n,1),r.push(K(t,!0))}t.children.push(e.id),e.parentId=t.id;const a=Le(e.calculative.worldRect,t.calculative.worldRect);Object.assign(e,a),e.locked=e.lockedOnCombine??o.DisableMove,s?(i.push(s),r.push(K(e,!0))):n.push(K(e,!0))})),r.push(K(t,!0));let s=1;n.length&&(s=2,this.pushHistory({type:F.Add,pens:n,step:s})),this.pushHistory({type:F.Update,initPens:i,pens:r,step:s})}toPng(t,e,i=!1){return this.canvas.toPng(t,e,i)}downloadPng(t,e){const i=document.createElement("a");i.setAttribute("download",t||"le5le.meta2d.png"),i.setAttribute("href",this.toPng(e,void 0,!0));const n=document.createEvent("MouseEvents");n.initEvent("click",!0,!0),i.dispatchEvent(n)}getRect(t=this.store.data.pens){return Ae(t)}fitView(t=!0,e=10){if(!this.hasView())return;const{canvas:i}=this.canvas,{offsetWidth:n,offsetHeight:r}=i;this.resize(n,r);const o=nt(e),s=this.getRect(),a=(n-o[1]-o[3])/s.width,c=(r-o[0]-o[2])/s.height;let l=a;l=t?a>c?c:a:a>c?a:c,this.scale(l*this.store.data.scale),this.centerView()}scrollView(t=10){if(!this.hasView())return;if(!this.canvas.scroll)return;const{canvas:e}=this.canvas,{offsetWidth:i,offsetHeight:n}=e;this.resize(i,n);const r=nt(t),o=this.getRect(),s=(i-r[1]-r[3])/o.width;this.scale(s*this.store.data.scale),this.topView(r[0])}topView(t=10){if(!this.hasView())return;const e=this.getRect(),i=this.getViewCenter(),n=this.getPenRect(e);ke(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,(t-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 t=this.getRect(),e=this.getViewCenter(),i=this.getPenRect(t);ke(i);const{center:n}=i,{scale:r,origin:o,x:s,y:a}=this.store.data;this.translate((e.x-o.x)/r-n.x-s/r,(e.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((t=>!t.isRuleLine)).length}getViewCenter(){const{width:t,height:e}=this.canvas;return{x:t/2,y:e/2}}beSameByFirst(t=this.store.data.pens,e){const i=K(t),n=t[0],{width:r,height:o}=this.getPenRect(n);for(let i=1;i{n[t]=i[t]}));for(let e=1;e!t.parentId))).length<=2)return;const n=K(e),r=e.reduce(((e,i)=>e+this.getPenRect(i)[t]),0),o=(i-r)/(e.length-1);e=e.sort(((e,i)=>"width"===t?e.x-i.x:e.y-i.y));const s=this.getPenRect(e[0]);let a="width"===t?s.x:s.y;for(const i of e){const e=this.getPenRect(i);"width"===t?e.x=a:e.y=a,a+=e[t]+o,this.setValue({id:i.id,...e},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:F.Update,initPens:n,pens:e})}spaceBetween(t,e){this.spaceBetweenByDirection("width",t,e)}spaceBetweenColumn(t,e){this.spaceBetweenByDirection("height",t,e)}layout(t=this.store.data.pens,e,i=30){const n=this.getPenRect(Ae(t));!e&&(e=n.width);const r=K(t=t.filter((t=>!t.type&&!t.parentId)));let o=0;t.forEach((t=>{const e=this.getPenRect(t);e.height>o&&(o=e.height)}));let s=n.x,a=n.y;t.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===t.length-1)return;const h=s+l.width-n.x,u=this.getPenRect(t[c+1]);Math.round(e-h)>=Math.round(u.width+i)?s+=l.width+i:(s=n.x,a+=o+i)})),this.render(),this.pushHistory({type:F.Update,initPens:r,pens:t})}gotoView(t){const e=this.getViewCenter(),i=e.x-t.calculative.worldRect.x-t.calculative.worldRect.width/2,n=e.y-t.calculative.worldRect.y-t.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 yn(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(t,e=this.store.data.pens){const i=[...st(t,this.store),t].map((t=>t.id));e.filter((t=>i.includes(t.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]))}))}initImageCanvas(t){this.canvas.initImageCanvas(t)}bottom(t,e=this.store.data.pens){const i=[...st(t,this.store),t].map((t=>t.id)),n=e.filter((t=>i.includes(t.id)));for(let t=n.length-1;t>=0;t--){const i=n[t],r=e.findIndex((t=>t.id===i.id));r>-1&&(e.unshift(e[r]),e.splice(r+1,1),this.initImageCanvas([i]))}}upByArea(t){if(-1===this.store.data.pens.findIndex((e=>e.id===t.id)))return void console.warn("upByArea: pen not in canvas");const e=[t,...st(t,this.store)];let i=e.map((t=>this.store.data.pens.findIndex((e=>e.id===t.id))));i.includes(-1)&&(console.warn("upByArea: pen children not in canvas"),i=i.filter((t=>-1!==t)));const n=Math.min(...i),r=t.calculative.worldRect,o=this.store.data.pens.findIndex(((e,i)=>{if(i<=n)return!1;if(e.id===t.id||function(t,e){if(!t||!e)return!1;let i=ot(t);for(;i;){if(i.id===e.id)return!0;i=ot(i)}return!1}(e,t))return!1;const o=e.calculative.worldRect;return Ce(r,o)}));if(-1!==o){this.store.data.pens.splice(o+1,0,...e);for(const t of e){const e=this.store.data.pens.findIndex((e=>e.id===t.id));e>-1&&this.store.data.pens.splice(e,1)}this.initImageCanvas([t])}else this.up(t)}up(t,e=this.store.data.pens){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]))}down(t,e=this.store.data.pens){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]))}setLayer(t,e,i=this.store.data.pens){const n=i.findIndex((e=>e.id===t.id));n>-1&&(n>e?(i.splice(e,0,i[n]),i.splice(n+1,1)):n{const r=this.store.pens[n];if(r)switch(e){case"all":i.push(r);break;case"in":Yt(r).connectTo===t.id&&i.push(r);break;case"out":Kt(r).connectTo===t.id&&i.push(r)}else console.warn(t,"node contain a error connectedLine")})),i}nextNode(t){if(t.type===r.Line){const e=this.store.pens[Yt(t).connectTo];return e?[e]:[]}{const e=this.getLines(t,"out"),i=[];return e.forEach((t=>{const e=this.nextNode(t);for(const t of e)!i.find((e=>e.id===t.id))&&i.push(t)})),i}}previousNode(t){if(t.type===r.Line){const e=this.store.pens[Kt(t).connectTo];return e?[e]:[]}{const e=this.getLines(t,"in"),i=[];return e.forEach((t=>{const e=this.previousNode(t);for(const t of e)!i.find((e=>e.id===t.id))&&i.push(t)})),i}}getNext(t){if(t.type===r.Line)return void console.warn("非连线节点");const e=[];return t.connectedLines?.forEach((({lineId:i,anchor:n})=>{const r=t.anchors?.filter((t=>t.id===n))[0],o=this.findOne(i);if(o.anchors[0].connectTo==t.id){const i=o.anchors[o.anchors.length-1].connectTo;if(i){const n=this.findOne(i),s=n.connectedLines?.filter((t=>t.lineId===o.id))[0],a=n.anchors.filter((t=>t.id===s.anchor))[0];e.push({from:t,fromAnchor:r,line:o,to:n,toAnchor:a})}}})),e}addAnchor(t,e,i){if(!t)return;if(t.anchors||(t.anchors=[]),t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),t.type===r.Line&&(i<0&&(i=t.anchors.length+1+i),i>t.anchors.length&&(i=t.anchors.length),i<0&&(i=0),0==i&&t.anchors[0].connectTo||i==t.anchors.length&&t.anchors[i-1].connectTo))return void console.warn("端点存在连接关系");let n=null,o=null;e.x<=1&&e.x>=0&&e.y<=1&&e.y>=0?(o={id:e.id||et(),penId:t.id,x:t.calculative.worldRect.x+t.calculative.worldRect.width*e.x,y:t.calculative.worldRect.y+t.calculative.worldRect.height*e.y},t.calculative.worldRect&&t.rotate%360&&S(o,t.rotate,t.calculative.worldRect.center),n={id:o.id,penId:t.id,x:e.x,y:e.y}):(o={id:e.id||et(),penId:t.id,x:e.x,y:e.y},t.calculative.worldRect&&(t.rotate%360&&S(e,-t.rotate,t.calculative.worldRect.center),n={id:o.id,penId:t.id,x:(e.x-t.calculative.worldRect.x)/t.calculative.worldRect.width,y:(e.y-t.calculative.worldRect.y)/t.calculative.worldRect.height})),t.type===r.Line?(t.calculative.worldAnchors.splice(i,0,o),t.anchors.splice(i,0,n),this.canvas.updateLines(t),this.canvas.initLineRect(t),this.render()):(t.calculative.worldAnchors.push(o),t.anchors.push(n))}connectLine(t,e,i,n,r=!0){if(!i){const n=e.calculative.worldRect;i=Ht(t,{x:n.x+n.width/2,y:n.y+n.height/2})}if(!n){const i=t.calculative.worldRect;n=Ht(e,{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:et()},{x:i.x>n.x?0:1,y:i.x>n.x?0:1,id:et()}]};return this.addPens([s]),Wt(t,i,s,s.calculative.worldAnchors[0]),Wt(e,n,s,s.calculative.worldAnchors[1]),s.calculative.active=!1,this.canvas.updateLines(s),this.canvas.updateLines(t),this.canvas.updateLines(e),this.canvas.initLineRect(s),r&&this.render(),s}toComponent(t=this.store.data.pens,e,i){if(1===t.length){const e=K(t[0]);return e.type=r.Node,e.id=void 0,[e]}const n=K(t,!0),s=Ae(n);let a={id:et(),name:"combine",...s,children:[],showChild:e};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((t=>t.width===s.width&&t.height===s.height)),l=c&&void 0===e;return l&&(c.children||(c.children=[]),a=c),n.forEach((t=>{if(t===a||t.parentId===a.id)return;if(t.parentId)return;a.children.push(t.id),t.parentId=a.id;const e=Le(t.calculative.worldRect,s);Object.assign(t,e),t.locked=t.lockedOnCombine??o.DisableMove})),K(l?n:[a,...n])}setVisible(t,e,i=!0){if(this.onSizeUpdate(),this.setValue({id:t.id,visible:e},{render:!1,doEvent:!1}),t.children)for(const i of t.children){const t=this.store.pens[i];t&&this.setVisible(t,e,!1)}i&&this.render()}clearHover(){this.canvas.clearHover()}closeSocket(){this.closeWebsocket(),this.closeMqtt(),this.closeHttp()}destroy(t){if(this.clear(!1),this.closeSocket(),this.store.emitter.all.clear(),this.canvas.destroy(),this.canvas=void 0,M[this.store.id]=void 0,!t){for(const t in M)delete M[t];M.path2dDraws={},M.canvasDraws={},M.anchors={},M.htmlElements={}}}}function kn(t,e){t.onDestroy||(t.onDestroy=An,t.onAdd=Tn);const i=e||new Path2D,{x:n,y:r,width:o,height:s,ex:a}=t.calculative.worldRect;let c=t.calculative.borderRadius||0,l=c;c<1&&(c*=o,l*=s);let h=c{const i=e.data.pens.findIndex((e=>e.id===t));i>-1&&(e.data.pens.splice(i,1),e.pens[t]=void 0)})),t.children=void 0}function Sn(t,e){t.onDestroy||(t.onDestroy=Cn,t.onAdd=Pn);const i=e||new Path2D,{x:n,y:r,width:o,height:s,ex:a}=t.calculative.worldRect;let c=t.calculative.borderRadius||0,l=c;c<1&&(c*=o,l*=s);let h=c{const i=e.data.pens.findIndex((e=>e.id===t));i>-1&&(e.data.pens.splice(i,1),e.pens[t]=void 0)})),t.children=void 0}function Rn(){return{interfaceClass:kn,simpleClass:Sn}}function _n(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.calculative.worldRect;if(i.rect(n,r,o,s),i.closePath(),i instanceof Path2D)return i}function En(t,e){const i=e.headHeight??50,{x:n,y:r,width:o,height:s,ey:a}=e.calculative.worldRect;let c=e.calculative.borderRadius||0,l=c;e.calculative.borderRadius<1&&(c*=o,l*=s);let h=c({id:n+"",x:e,y:i,penId:t.id})))}function jn(t,e){const i=e||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=t.calculative.worldRect,c=t.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 Hn(t,e){const i=e||new Path2D,{x:n,y:r,height:o,ex:s,ey:a}=t.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 Un(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s,ex:a,ey:c}=t.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 Wn(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s,ex:a,center:c}=t.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 qn(t){t.anchors=[{x:.5,y:0},{x:1,y:.5},{x:.5,y:6/7},{x:0,y:.5}].map((({x:e,y:i},n)=>({id:`${n}`,penId:t.id,x:e,y:i})))}function Vn(t,e){const i=e||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=t.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 Kn(t,e){const i=e||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=t.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 Yn(t,e){const i=e||new Path2D,{x:n,y:r,height:o,ex:s,ey:a}=t.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 Xn(t){t.anchors=[{x:.5,y:.125},{x:1,y:.5},{x:.5,y:1},{x:0,y:.5}].map((({x:e,y:i},n)=>({id:`${n}`,penId:t.id,x:e,y:i})))}function $n(t,e){const i=e||new Path2D,{x:n,y:r,ex:o,ey:s}=t.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 Gn(t){t.anchors=[{x:.5,y:0},{x:.5,y:1}].map((({x:e,y:i},n)=>({id:n+"",x:e,y:i,penId:t.id})))}function Qn(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s,ex:a,ey:c}=t.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 Jn(t,e){const i=e||new Path2D,{x:n,y:r,width:o,ex:s,ey:a}=t.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 Zn(){return{flowComment:zn,flowData:jn,flowDb:Hn,flowDisplay:Un,flowDocument:Wn,flowExternStorage:Vn,flowInternalStorage:Kn,flowManually:Yn,flowParallel:$n,flowQueue:Qn,flowSubprocess:Jn}}function tr(){return{flowDocument:qn,flowManually:Xn,flowParallel:Gn,flowComment:Fn}}function er(t){let e=globalThis.echarts;if(!t.echarts||!e)return;if("string"==typeof t.echarts)try{t.echarts=JSON.parse(t.echarts)}catch(t){}if(!t.echarts)return;t.onDestroy||(t.onDestroy=nr,t.onMove=rr,t.onResize=or,t.onRotate=rr,t.onValue=sr,t.onBeforeValue=ar,t.onBinds=cr,t.onMouseEnter=rr,t.onAdd=ir),t.calculative.singleton||(t.calculative.singleton={});const i=new Path2D,n=t.calculative.worldRect;if(t.calculative.singleton.div)i.rect(n.x,n.y,n.width,n.height),t.calculative.patchFlags&&t.calculative.singleton.div&&ee(t,t.calculative.singleton.div);else{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),t.calculative.singleton.div=i,t.calculative.singleton.echart=e.init(i,t.echarts.theme),setTimeout((()=>{t.calculative.singleton.echart.setOption(t.echarts.option,!0),t.calculative.singleton.echart.resize(),setTimeout((()=>{const e=new Image;e.src=t.calculative.singleton.echart.getDataURL({pixelRatio:2}),t.calculative.img=e}),100)})),t.calculative.canvas.externalElements?.appendChild(i),ee(t,i)}return i}function ir(t){t.beforeScale=t.calculative.canvas.store.data.scale}function nr(t){if(t.calculative.singleton&&t.calculative.singleton.div){t.calculative.singleton.div.remove();let e=globalThis.echarts;e&&e.dispose(t.calculative.singleton.echart),delete t.calculative.singleton.div,delete t.calculative.singleton.echart}}function rr(t){t.calculative.singleton.div&&ee(t,t.calculative.singleton.div)}function or(t){if(!t.calculative.singleton.echart)return;ee(t,t.calculative.singleton.div);let e=t.echarts.option;t.beforeScale||(t.beforeScale=t.calculative.canvas.store.data.scale);let i=t.calculative.canvas.store.data.scale/t.beforeScale;if(e.grid){let t=["top","bottom","left","right"];for(let n=0;n{isNaN(e[t[n]])||(e[t[n]]*=i)})):isNaN(e.grid[t[n]])||(e.grid[t[n]]*=i)}if(e.dataZoom){let t=["right","top","width","height","left","bottom"];for(let n=0;n{isNaN(e[t[n]])||(e[t[n]]*=i)}))}Y(e,"fontSize",i),t.calculative.singleton.echart.setOption(e,!0),t.beforeScale=t.calculative.canvas.store.data.scale,t.calculative.singleton.echart.resize()}function sr(t){t.calculative.singleton.echart&&(ee(t,t.calculative.singleton.div),t.calculative.singleton.echart.setOption(t.echarts.option,!0))}function ar(t,e){if(e.echarts||!e.dataX&&!e.dataY)return e;const i=t.echarts,{max:n,replaceMode:r}=i;let o=e.dataX,s=e.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===mn.Replace)if(u||d){if(("category"===u.type||"category"===d.type)&&o&&s){const t="category"===u.type?u.data:d.data;!Array.isArray(o)&&(o=[o]),!Array.isArray(s)&&(s=[s]),1===c?s.forEach(((e,i)=>{const n=t.indexOf(o[i]);a[0].data[n]=e})):a.forEach(((e,i)=>{s[i].forEach(((i,n)=>{const r=t.indexOf(o[n]);e.data[r]=i}))}))}}else s&&(1===c?(!Array.isArray(s)&&(s=[s]),s.forEach(((t,e)=>{const i=a[0].data.find((e=>e.name===t.name));i&&(i.value=t.value)}))):a.forEach(((t,e)=>{Array.isArray(s[e])||(s[e]=[s[e]]),s[e].forEach(((e,i)=>{const n=t.data.find((t=>t.name===e.name));n&&(n.value=e.value)}))})));else r===mn.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(((t,e)=>{t.data=s[e],t.data.splice(0,t.data.length-n)}))));else{if(o){!Array.isArray(o)&&(o=[o]);const t=u.data;t.push(...o),t.splice(0,t.length-n)}if(s)if(1===c){!Array.isArray(s)&&(s=[s]);const t=a[0].data;t.push(...s),t.splice(0,t.length-n)}else a.forEach(((t,e)=>{Array.isArray(s[e])||(s[e]=[s[e]]);const i=t.data;i.push(...s[e]),i.splice(0,i.length-n)}))}return delete e.dataX,delete e.dataY,Object.assign(e,{echarts:i})}function cr(t,e,i){if("dataY"!==i.key)return;const n=t.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((t=>{const{dataId:o}=i.dataIds.find((e=>e.name===t));if(o){const i=e.find((t=>t.dataId===o));i&&(r.push(t),n.push(i.value))}})),{id:t.id,dataY:n,dataX:r}}if("time"===s.type){const n=[],r=+new Date;let o=!1;if(c.forEach(((t,s)=>{const a=[],{dataId:c}=i.dataIds.find((e=>e.name===t.name));if(c){const t=e.find((t=>t.dataId===c));t&&(a.push([r,t.value]),o=!0)}n[s]=a})),!o)return;return n.forEach(((t,e)=>{if(!t||0===t.length){const t=c[e].data[c[e].data.length-1];n[e]=[[r,t[1]]]}})),{id:t.id,dataY:1===n.length?n[0]:n}}}else{const n=[];if(Array.isArray(c)&&1===c.length)return c[0].data.forEach((t=>{const{dataId:r}=i.dataIds.find((e=>e.name===t.name));if(r){const i=e.find((t=>t.dataId===r));i&&n.push({name:t.name,value:i.value})}})),{id:t.id,dataY:n}}}function lr(t){const e=globalThis.Highcharts;if(!e)return;if("string"==typeof t.highcharts)try{t.highcharts=JSON.parse(t.highcharts.option)}catch(t){}if(!t.highcharts)return;t.onDestroy||(t.onDestroy=hr,t.onMove=ur,t.onResize=dr,t.onRotate=ur,t.onValue=fr,t.onBeforeValue=pr),t.calculative.singleton||(t.calculative.singleton={});const i=new Path2D,n=t.calculative.worldRect;if(!t.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=t.id,document.body.appendChild(i),t.calculative.singleton.div=i,setTimeout((()=>{t.calculative.singleton.highchart=e.chart(t.id,t.highcharts.option);const i=t.calculative.singleton.highchart.getSVG(),n=new Image;n.src="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(i))),t.calculative.img=n})),t.calculative.canvas.externalElements?.appendChild(i),ee(t,i)}return i.rect(n.x,n.y,n.width,n.height),t.calculative.patchFlags&&t.calculative.singleton.div&&ee(t,t.calculative.singleton.div),i}function hr(t){t.calculative.singleton&&t.calculative.singleton.div&&(t.calculative.singleton.div.remove(),t.calculative.singleton.highchart.destroy(),delete t.calculative.singleton.div,delete t.calculative.singleton.highchart)}function ur(t){t.calculative.singleton.div&&ee(t,t.calculative.singleton.div)}function dr(t){t.calculative.singleton.div&&(ee(t,t.calculative.singleton.div),setTimeout((()=>{t.calculative.singleton.highchart.reflow()}),100))}function fr(t){t.calculative.singleton.div&&ee(t,t.calculative.singleton.div)}function pr(t,e){if(e.highcharts)return t.calculative.singleton.highchart.update(e.highcharts.option),e;if(!e.dataX&&!e.dataY)return e;const i=t.highcharts,n=i.max;let r=e.dataX,o=e.dataY;const s=i.option.series.length;if(e.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(((t,e)=>{t.data=o[e],t.data.splice(0,t.data.length-n)}))),t.calculative.singleton.highchart.update(i.option);else{let e=[],a=null,c=!1;if(r){Array.isArray(r)||(r=[r]);const t=i.option.xAxis,o=Array.isArray(t)?t[0].categories:t.categories;o&&(o.push(...r),o.splice(0,o.length-n),c=!0),e=[...r]}o&&(1===s?(Array.isArray(o)||(o=[o]),a=[o]):(a=[],i.option.series.forEach(((t,e)=>{Array.isArray(o[e])||(o[e]=[o[e]]),a.push(o[e])})))),a&&t.calculative.singleton.highchart.series.forEach(((t,i)=>{a[i].forEach(((i,r)=>{let o=!1;n&&t.data.length>=n&&(o=!0);const s=c||null==e[r]?i:[e[r],i];t.addPoint(s,!0,o)}))}))}return delete e.dataX,delete e.dataY,delete e.overwrite,Object.assign(e,{highcharts:i})}function vr(t){let e=globalThis.lcjs;if(!t.lightningCharts||!e)return;if("string"==typeof t.lightningCharts)try{t.lightningCharts=JSON.parse(t.lightningCharts)}catch(t){}if(!t.lightningCharts)return;t.onDestroy||(t.onDestroy=yr,t.onMove=mr,t.onResize=wr,t.onRotate=mr,t.onValue=br);const i=new Path2D,n=t.calculative.worldRect;if(t.calculative.singleton||(t.calculative.singleton={}),!t.calculative.singleton.div){const e=document.createElement("div");e.style.position="absolute",e.style.outline="none",e.style.left="-9999px",e.style.top="-9999px",e.style.width=n.width+"px",e.style.height=n.height+"px",e.id=t.id,document.body.appendChild(e),t.calculative.singleton.div=e,setTimeout((()=>{gr(t)}),100),setTimeout((()=>{t.calculative.canvas.externalElements&&t.calculative.canvas.externalElements.appendChild(e),ee(t,e);const i=new Image;i.src=t.calculative.singleton.div.children[0].toDataURL(),t.calculative.img=i}),400)}return i.rect(n.x,n.y,n.width,n.height),t.calculative.patchFlags&&t.calculative.singleton.div&&ee(t,t.calculative.singleton.div),i}function gr(t){const{lightningChart:e,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,g=t.lightningCharts.option.data,y=t.lightningCharts.option.title||"Title",m=o[t.lightningCharts.option.theme||"lightNew"];switch(t.calculative.singleton.lightningChart=e(),t.lightningCharts.option.type){case"line":const e=t.calculative.singleton.lightningChart.ChartXY({container:t.id}).setTitle(y);g.forEach((t=>{e.addLineSeries().setName(t.name).add(t.data)}));break;case"bar":const i=t.calculative.singleton.lightningChart;let o;o=e=>{const r=[],o=[],s=i.ChartXY(e).setTitle(y).setAutoCursorMode(d.onHover).setMouseInteractions(!1).setPadding({bottom:30}),a=s.getDefaultAxisX().setMouseInteractions(!1).setScrollStrategy(void 0).setTickStrategy(p.Empty);s.getDefaultAxisY().setMouseInteractions(!1).setTitle(t.lightningCharts.option.yTitle).setInterval(0,70).setScrollStrategy(f.fitting),s.setAutoCursor((t=>t.disposePointMarker().disposeTickMarkerX().disposeTickMarkerY().setGridStrokeXStyle(u).setGridStrokeYStyle(u).setResultTable((t=>{t.setOrigin(h.CenterBottom)}))));const c=s.addLegendBox(n.VerticalLegendBox).setAutoDispose({type:"max-width",maxWidth:.2});return{addCategory:t=>{const e=(t=>{const e=s.addRectangleSeries();return e.setCursorResultTableFormatter(((e,i,n)=>{let r={name:t.name,value:t.data[t.figures.indexOf(n)]};return e.addRow("Department:",r.name).addRow("# of employees:",String(r.value))})),e})(t).setName(t.name);t.figures=t.data.map((t=>e.add({x:0,y:0,width:0,height:0}))),c.add(e),o.push(t),(()=>{let t=0;for(let e=0;e{for(const e of t)r.push({name:e,tick:a.addCustomTick(v.AxisTick).setGridStrokeLength(0).setTextFormatter((t=>e))})}}};const s=o({theme:m,container:t.id});s.addGroups(t.lightningCharts.option.groups);const a=t.lightningCharts.option.categories;g.forEach(((t,e)=>s.addCategory({name:a[e],data:t})));break;case"pie":const w=t.calculative.singleton.lightningChart.Pie({theme:m,container:t.id}).setTitle(y).setAnimationsEnabled(!0).setMultipleSliceExplosion(!0);g.map((t=>w.addSlice(t.name,t.value))),w.setInnerRadius(t.lightningCharts.option.innerRadius||0).setLabelFormatter(r.NamePlusRelativeValue),w.addLegendBox(n.VerticalLegendBox).setAutoDispose({type:"max-width",maxWidth:.3}).add(w);break;case"gauge":const b=t.calculative.singleton.lightningChart.Gauge({theme:m,container:t.id}).setTitle(y).setThickness(20).setAngleInterval(t.lightningCharts.option.startAngle||225,t.lightningCharts.option.endAngle||-45);let x=function(t){let e=t.toLowerCase();if(e&&/^#([0-9|a-f]{3}|[0-9|a-f]{6})$/.test(e)){4==e.length&&(e="#"+e[1]+e[1]+e[2]+e[2]+e[3]+e[3]);for(var i=[],n=1;n<7;n+=2)i.push(parseInt("0x"+e.slice(n,n+2)));return i}return e&&/rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/.test(e)?e.match(/\(([^)]*)\)/)[1].split(",").map((t=>parseInt(t))):e}(t.lightningCharts.option.background);b.getDefaultSlice().setInterval(t.lightningCharts.option.min||0,t.lightningCharts.option.max||100).setValue(g).setFillStyle(new c({color:l(x[0],x[1],x[2])}))}}function yr(t){t.calculative.singleton&&t.calculative.singleton.div&&(t.calculative.singleton.div.remove(),delete t.calculative.singleton.div,delete t.calculative.singleton.lightningChart)}function mr(t){t.calculative.singleton.div&&ee(t,t.calculative.singleton.div)}function wr(t){t.calculative.singleton.div&&ee(t,t.calculative.singleton.div)}function br(t){t.calculative.singleton.div&&(gr(t),ee(t,t.calculative.singleton.div))}function xr(t){t&&(globalThis.echarts=t),D({echarts:er})}function kr(t){t&&(globalThis.Highcharts=t),D({highcharts:lr})}function Tr(t){t&&(globalThis.lcjs=t),D({lightningCharts:vr})}function Ar(t,e){e.onAdd||(e.onAdd=Sr,e.onMouseMove=Rr,e.onMouseLeave=_r,e.onMouseDown=Er,e.onShowInput=Pr,e.onInput=Cr,e.onValue=Nr,e.onBeforeValue=Or);const i=e.calculative.canvas.store.data,n=e.calculative.canvas.store.options;e.color=e.color||i.color||n.color,e.activeColor=e.activeColor||n.activeColor,e.hoverColor=e.hoverColor||n.hoverColor,e.activeBackground=e.activeBackground||n.activeBackground,e.hoverBackground=e.hoverBackground||n.hoverBackground,function(t,e){if(!e.colPos)return;const i=e.calculative.worldRect;t.save(),t.strokeStyle=e.color,t.beginPath(),t.rect(i.x,i.y,i.width,i.height),e.background&&(t.fillStyle=e.background,t.fill()),t.stroke();let n=e.rowPos[e.rowPos.length-1];for(const i of e.rowPos){if(i===n)continue;const r=i*e.calculative.worldRect.height/e.tableHeight;t.beginPath(),t.moveTo(e.calculative.worldRect.x,e.calculative.worldRect.y+r),t.lineTo(e.calculative.worldRect.ex,e.calculative.worldRect.y+r),t.stroke()}n=e.colPos[e.colPos.length-1],e.colPos.forEach(((i,r)=>{if(i===n)return;const o=i*e.calculative.worldRect.width/e.tableWidth;t.beginPath(),t.moveTo(e.calculative.worldRect.x+o,e.calculative.worldRect.y),t.lineTo(e.calculative.worldRect.x+o,e.calculative.worldRect.ey),t.stroke()})),t.restore()}(t,e),function(t,e){if(!e.colPos)return;e.calculative.texts||(e.calculative.texts=[]);for(let i=0;i{t.fillText(e,c.x+c.width/2,c.y+s+(n+i)*r)}))}t.restore()}}}(t,e)}function Sr(t){!function(t){const e=[],i=[];t.table.rowHeight||(t.table.rowHeight=40),t.table.colWidth||(t.table.colWidth=150);let n=0;for(const i of t.table.header.data)n+=i.width||t.table.colWidth,e.push(n);let r=0;0!=t.table.header.show&&(r+=t.table.header.height||t.table.rowHeight,i.push(r));for(const e of t.table.data)r+=e.height||t.table.rowHeight,i.push(r);t.colPos=e,t.rowPos=i,t.tableWidth=n,t.tableHeight=r,t.width||(t.width=n,t.height=r,t.calculative.width=n,t.calculative.height=r,t.calculative.worldRect={x:t.x,y:t.y,height:t.height,width:t.width},Te(t.calculative.worldRect))}(t)}function Pr(t,e){if(!t.calculative.hoverCell)return;const i=Lr(t,t.calculative.hoverCell.row,t.calculative.hoverCell.col);if(Array.isArray(i))return;t.calculative.inputCell=t.calculative.hoverCell;const n=Dr(t,t.calculative.hoverCell.row,t.calculative.hoverCell.col);t.calculative.tempText=i.text||i+"",t.calculative.canvas.showInput(t,n,"#ffffff")}function Cr(t,e){t.calculative.inputCell&&(Mr(t,t.calculative.inputCell.row,t.calculative.inputCell.col,e),t.calculative.canvas.render())}function Rr(t,e){t.calculative.hoverCell=Ir(t,e),t.calculative.canvas.render()}function _r(t,e){t.calculative.hoverCell=void 0,t.calculative.canvas.render()}function Er(t,e){t.calculative.activeCell=Ir(t,e),t.calculative.canvas.render()}function Ir(t,e){const i=t.calculative.worldRect.width/t.tableWidth,n=t.calculative.worldRect.height/t.tableHeight,r={row:0,col:0};for(let n=0;nt.calculative.worldRect.x+t.colPos[n]*i&&(r.col=n+1);for(let i=0;it.calculative.worldRect.y+t.rowPos[i]*n&&(r.row=i+1);return r}function Lr(t,e,i){if(!t.table.data||!Array.isArray(t.table.data))return;if(0==t.table.header.show){const n=t.table.data[e];if(Array.isArray(n))return n[i];if(!n.data||!Array.isArray(n.data))return;return n.data[i]}if(0===e){const e=t.table.header.data[i];return e.fontWeight=t.table.header.fontWeight,e}const n=t.table.data[e-1];if(n){if(Array.isArray(n))return n[i];if(n.data&&Array.isArray(n.data))return n.data[i]}}function Mr(t,e,i,n){if(!t.table.data||!Array.isArray(t.table.data))return;let r;t.calculative.texts=void 0,0==t.table.header.show?(r=t.table.data[e],Array.isArray(r)||r.data&&Array.isArray(r.data)&&(r=r.data)):0===e?r=t.table.header.data:(r=t.table.data[e-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,t.calculative.canvas.store.emitter.emit("valueUpdate",t))}function Dr(t,e,i){const n=t.calculative.worldRect.width/t.tableWidth,r=t.calculative.worldRect.height/t.tableHeight;let o=0,s=t.colPos[i]*n;i>0&&(o=t.colPos[i-1]*n);let a=0,c=t.rowPos[e]*r;return e>0&&(a=t.rowPos[e-1]*r),{x:t.calculative.worldRect.x+o,y:t.calculative.worldRect.y+a,ex:t.calculative.worldRect.x+s,ey:t.calculative.worldRect.y+c,width:s-o,height:c-a}}function Br(t,e,i){const n=t.calculative.worldRect.width/t.tableWidth,r=t.calculative.worldRect.height/t.tableHeight;let o=0,s=0,a=0;for(const t of i)s+t.width*n+20*n{e.push(o*(40+n)+i),i+=zr(r.text,t)})),t.optionPos=e;const r=e.length*(40+n)+i;t.checkboxWidth=r,t.width=r,t.calculative.width=r,t.calculative.worldRect={x:t.x,y:t.y,height:t.height,width:t.width,center:{x:t.x+t.width/2,y:t.y+t.height/2}},Te(t.calculative.worldRect)}else if("vertical"==t.direction){null==t.optionInterval&&(t.optionInterval=20),t.optionHeight||(t.optionHeight=20);const e=[];t.options.forEach(((i,n)=>{e.push(n*(t.optionInterval+t.optionHeight))})),t.optionPos=e;const i=e[e.length-1]+t.optionHeight;t.checkboxHeight=i,t.width||(t.height=i,t.calculative.height=i,t.calculative.worldRect={x:t.x,y:t.y,height:t.height,width:t.width,center:{x:t.x+t.width/2,y:t.y+t.height/2}},Te(t.calculative.worldRect))}}function jr(t,e){e.onAdd||(e.onAdd=Hr,e.rowPos&&e.colPos||(e.onAdd(e),e.calculative.canvas.parent.active([e])),e.onMouseMove=qr,e.onMouseLeave=Vr,e.onMouseDown=Kr,e.onShowInput=Ur,e.onInput=Wr,e.onValue=Jr,e.onBeforeValue=Zr);const i=e.calculative.canvas.store.data,n=e.calculative.canvas.store.options;e.color=e.color||i.color||n.color,e.activeColor=e.activeColor||n.activeColor,e.hoverColor=e.hoverColor||n.hoverColor,e.activeBackground=e.activeBackground||n.activeBackground,e.hoverBackground=e.hoverBackground||n.hoverBackground,function(t,e){if(!e.colPos)return;const i=e.calculative.worldRect;t.save(),t.strokeStyle=e.color,t.beginPath(),t.rect(i.x,i.y,i.width,i.height),e.background&&(t.fillStyle=e.background,t.fill()),t.stroke();let n=e.rowPos[e.rowPos.length-1];for(const i of e.rowPos){if(i===n)continue;const r=i*e.calculative.worldRect.height/e.tableHeight;t.beginPath(),t.moveTo(e.calculative.worldRect.x,e.calculative.worldRect.y+r),t.lineTo(e.calculative.worldRect.ex,e.calculative.worldRect.y+r),t.stroke()}n=e.colPos[e.colPos.length-1],e.colPos.forEach(((i,r)=>{if(i===n)return;const o=i*e.calculative.worldRect.width/e.tableWidth;t.beginPath(),t.moveTo(e.calculative.worldRect.x+o,e.calculative.worldRect.y),t.lineTo(e.calculative.worldRect.x+o,e.calculative.worldRect.ey),t.stroke()})),t.restore()}(t,e),function(t,e){if(!e.colPos)return;e.calculative.texts||(e.calculative.texts=[]);for(let i=0;it.col===n&&void 0===t.row&&t.pens));if(t.length>0){if(u[n]="",e.isFirstTime){let r=JSON.parse(JSON.stringify(t[0].pens));r.forEach((t=>{Object.assign(t,{row:i,col:n}),t.height*=e.calculative.canvas.store.data.scale,t.width*=e.calculative.canvas.store.data.scale})),Qr(e,h,r),e.calculative.canvas.parent.pushChildren(e,r)}continue}}else u[n]=void 0===r?"":r.text||r+"";if(!u[n])continue;u[n]=U(e,u[n])}if(u[n]){if(t.save(),t.fillStyle=c,t.textAlign="center",t.textBaseline="middle",t.font=(e.calculative.fontStyle||"")+" normal "+(e.calculative.fontWeight||"")+" "+1*(e.calculative.fontSize||12)+"px "+e.calculative.fontFamily,1===u[n].length)t.fillText(u[n][0],h.x+h.width/2,h.y+h.height/2);else{const i=.55,r=e.calculative.fontSize*e.calculative.lineHeight*1,o=u[n].length*r;let s=(h.height-o)/2;u[n].forEach(((e,n)=>{t.fillText(e,h.x+h.width/2,h.y+s+(n+i)*r)}))}t.restore()}}}(t,e),function(t,e){if(!e.calculative.hoverCell)return;if(e.calculative.isInput)return;if(!e.calculative.isHover)return;const{row:i,col:n}=e.calculative.hoverCell,{x:r,y:o}=e.calculative.canvas.mousePos;if(!e.data[i])return;let s=e.data[i][n];if("object"==typeof s||!s)return;t.save(),t.textAlign="start",t.textBaseline="middle",t.font=t.font=(e.calculative.fontStyle||"")+" normal "+(e.calculative.fontWeight||"")+" "+(e.calculative.fontSize||12)+"px "+e.calculative.fontFamily;const a=t.measureText(s).width;t.beginPath(),t.fillStyle="#fff",t.strokeStyle="#000",t.moveTo(r,o),t.rect(r-10,o,a+20,20),t.fill(),t.stroke(),t.beginPath(),t.fillStyle="#000",t.fillText(s,r,o+10),t.restore()}(t,e),e.isFirstTime=!1}function Hr(t){t.isFirstTime=!0,function(t){const e=[],i=[];t.rowHeight||(t.rowHeight=40),t.colWidth||(t.colWidth=150);let n=0;const r=t.styles&&t.styles.filter((t=>void 0!==t.col&&void 0===t.row&&t.width));let o={};r&&r.forEach((t=>{o[t.col]=t.width}));for(let i=0;ivoid 0===t.col&&void 0!==t.row&&t.height));let c={};a&&a.forEach((t=>{c[t.row]=t.height}));for(let e=0;e{t.calculative.isHover=!0,t.calculative.canvas.render()}),500),t.calculative.hoverCell=Yr(t,e),t.calculative.canvas.render()}function Vr(t,e){t.calculative.hoverCell=void 0,t.calculative.canvas.render()}function Kr(t,e){t.calculative.activeCell=Yr(t,e),t.calculative.canvas.render()}function Yr(t,e){const i=t.calculative.worldRect.width/t.tableWidth,n=t.calculative.worldRect.height/t.tableHeight,r={row:0,col:0};for(let n=0;nt.calculative.worldRect.x+t.colPos[n]*i&&(r.col=n+1);for(let i=0;it.calculative.worldRect.y+t.rowPos[i]*n&&(r.row=i+1);return r}function Xr(t,e,i){if(!t.data||!Array.isArray(t.data))return;const n=t.data[e],r=t.styles&&t.styles.filter((t=>t.row===e&&t.col===i));if(Array.isArray(n))return{value:n[i],style:r?.length>0?r[0]:{}};n.data&&Array.isArray(n.data)}function $r(t,e,i,n){if(!t.data||!Array.isArray(t.data))return;t.isFirstTime=!1,t.calculative.texts=void 0;let r=t.data[e];r&&(r[i]instanceof Object||(r[i]=n),t.calculative.canvas.store.emitter.emit("valueUpdate",t))}function Gr(t,e,i){const n=t.calculative.worldRect.width/t.tableWidth,r=t.calculative.worldRect.height/t.tableHeight;let o=0,s=t.colPos[i]*n;i>0&&(o=t.colPos[i-1]*n);let a=0,c=t.rowPos[e]*r;return e>0&&(a=t.rowPos[e-1]*r),{x:t.calculative.worldRect.x+o,y:t.calculative.worldRect.y+a,ex:t.calculative.worldRect.x+s,ey:t.calculative.worldRect.y+c,width:s-o,height:c-a}}function Qr(t,e,i){const n=t.calculative.worldRect.width/t.tableWidth,r=t.calculative.worldRect.height/t.tableHeight;let o=0,s=0,a=0;const c=t.calculative.canvas.store.data.scale;for(const t of i)s+t.width*n+20*c*n{t.calculative.canvas.delForce(t.calculative.canvas.findOne(e))})),t.calculative.texts=void 0,t.calculative.canvas.active([t])}}function Zr(t,e){if(t.calculative.isUpdateData=!1,e.table||null==e.col&&null==e.row){if(e.dataY){const i=t.replaceMode;let n=[];return i?i===wn.Replace?(n=t.data,e.dataX&&e.dataX.forEach(((t,i)=>{n[t]=e.dataY[i]}))):i===wn.ReplaceAll&&(e.dataX?n[0]=e.dataX:n[0]=t.data[0],n=n.concat(e.dataY)):n=t.data.concat(e.dataY),delete e.dataX,delete e.dataY,t.calculative.isUpdateData=!0,Object.assign(e,{data:n})}return(e.data||t.styles)&&(t.calculative.isUpdateData=!0),e}let i=t.data[e.row];return i?(i[e.col]instanceof Object||(i[e.col]=e.value),$r(t,e.row,e.col,e.value),t.calculative.canvas.render(),delete e.col,delete e.row,e):e}function to(t,e){e.onAdd||(e.onAdd=eo,e.onResize=eo,e.onMove=eo,e.onMouseMove=ro,e.onMouseDown=no,e.onValue=oo,e.onBeforeValue=so),e.calculative.barRect||eo(e),e.calculative.canvas.store.data;const i=e.calculative.canvas.store.options;t.fillStyle=e.background,t.beginPath();let n=e.calculative.worldRect.x+e.calculative.barRect.x,r=e.calculative.worldRect.y+e.calculative.barRect.y,o=e.calculative.barRect.width,s=e.calculative.barRect.height,a=s/2;t.moveTo(n+a,r),t.arcTo(n+o,r,n+o,r+s,a),t.arcTo(n+o,r+s,n,r+s,a),t.arcTo(n,r+s,e.x,e.y,a),t.arcTo(n,r,n+o,r,a),t.fill(),t.fillStyle=e.activeColor||i.activeColor,t.beginPath(),o=e.calculative.ballRect.x,t.moveTo(n+a,r),t.arcTo(n+o,r,n+o,r+s,a),t.arcTo(n+o,r+s,n,r+s,a),t.arcTo(n,r+s,e.x,e.y,a),t.arcTo(n,r,n+o,r,a),t.fill(),t.fillStyle="#ffffff",t.beginPath(),n=e.calculative.worldRect.x+e.calculative.ballRect.x,r=e.calculative.worldRect.y+e.calculative.ballRect.y+e.calculative.ballRect.height/2,t.lineWidth=e.calculative.ballRect.width/10,t.arc(n,r,e.calculative.ballRect.width/2,0,2*Math.PI),t.fill(),t.stroke()}function eo(t){if(t._textWidth||(t._textWidth=t.textWidth||50,t._fontSize=t.fontSize||12),t.textWidth=t.calculative.worldRect.width,t.calculative.textWidth=t.textWidth,t.unit||(t.unit="%"),t.sliderWidth||(t.sliderWidth=t.width),t.sliderHeight||(t.sliderHeight=t.height),!t.calculative.worldRect)return;const e=t.calculative.worldRect.width/t.sliderWidth,i=t.calculative.worldRect.height/t.sliderHeight,n=Math.min(e,i);t.fontSize=t._fontSize*n;const r=t.calculative.worldRect.width-t._textWidth*n;t.textLeft=r+10*n,t.calculative.textLeft=t.textLeft,t.calculative.barRect={x:0,y:(t.calculative.worldRect.height-t.barHeight*i)/2,width:r,height:t.barHeight*i},Te(t.calculative.barRect),io(t)}function io(t){const e=3.5*t.calculative.barRect.height,i=t.calculative.barRect.width*t.value/100;t.calculative.ballRect={x:i,y:(t.calculative.worldRect.height-e)/2,width:e,height:e},Te(t.calculative.ballRect),t.calculative.text=t.value+t.unit,j(t)}function no(t,e){const i=e.x-t.calculative.worldRect.x;if(i>t.calculative.barRect.width)return;let n=Math.round(i/t.calculative.barRect.width*100);nt.max||n<0||n>100||(t.value=n,io(t),t.calculative.text=t.value+t.unit,j(t),t.calculative.canvas.store.emitter.emit("valueUpdate",t),t.calculative.canvas.render())}function ro(t,e){t.calculative.canvas.mouseDown&&no(t,e)}function oo(t){t.calculative.isUpdateData&&(delete t.calculative.isUpdateData,eo(t)),io(t)}function so(t,e){return t.calculative.isUpdateData=!1,(e.textWidth||e.barHeight)&&(e.textWidth&&(t._textWidth=0),t.calculative.isUpdateData=!0),e}function ao(t,e){e.onClick||(e.onClick=co);let i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,r=e.calculative.worldRect.width,o=e.calculative.worldRect.height;r<1.5*o&&(r=1.5*o),t.beginPath(),t.arc(i+o/2,n+o/2,o/2,Math.PI/2,3*Math.PI/2),t.lineTo(i+r-o/2,n),t.arc(i+r-o/2,n+o/2,o/2,-Math.PI/2,Math.PI/2),t.lineTo(i+o/2,n+o),e.checked?(t.fillStyle=e.onColor,e.disable&&(t.fillStyle=e.disableOnColor),t.fill(),t.closePath(),t.beginPath(),t.fillStyle="#ffffff",t.moveTo(i+2*o,n+o/2),t.arc(i+r-o/2,n+o/2,o/2>2?o/2-2:1,0,2*Math.PI),t.fill()):(t.fillStyle=e.offColor,e.disable&&(t.fillStyle=e.disableOffColor),t.fill(),t.closePath(),t.beginPath(),t.fillStyle="#ffffff",t.moveTo(i+o,n+o/2),t.arc(i+o/2,n+o/2,o/2>2?o/2-2:1,0,2*Math.PI),t.fill()),t.closePath()}function co(t){t.disable||(t.checked=!t.checked,t.calculative.canvas.store.emitter.emit("valueUpdate",t),t.calculative.canvas.render())}function lo(t,e){e.onMouseDown||(e.onMouseDown=ho);let i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,r=e.calculative.worldRect.height;e.calculative.worldRect.width,t.beginPath(),t.moveTo(i,n),t.arcTo(i+r,n,i+r,n+r,2),t.arcTo(i+r,n+r,i,n+r,2),t.arcTo(i,n+r,i,n,2),t.arcTo(i,n,i+r,n,2),t.strokeStyle="#d9d9d9",t.fillStyle="#ffffff00",e.checked&&(t.fillStyle=e.background||"#1890ff",t.strokeStyle=e.background||"#1890ff"),e.isForbidden&&(t.fillStyle="#ebebeb",t.strokeStyle="#d9d9d9"),t.closePath(),t.fill(),t.stroke(),t.save(),e.checked&&(t.beginPath(),t.lineWidth=r/10,t.strokeStyle="#ffffff",t.moveTo(i+102/506*r,n+r/2),t.lineTo(i+220/506*r,n+346/460*r),t.lineTo(i+404/506*r,n+142/460*r),t.stroke()),t.restore(),t.save(),t.fillStyle=e.isForbidden?"#00000040":e.textColor||e.color||"#000000d9",t.textAlign="start",t.textBaseline="middle",t.font=(e.calculative.fontStyle||"")+" normal "+(e.calculative.fontWeight||"")+" "+e.fontSize+"px "+e.calculative.fontFamily,t.fillText(e.value+"",i+r+10,n+r/2),t.restore()}function ho(t,e){t.isForbidden||(t.checked=!t.checked,t.calculative.canvas.store.emitter.emit("valueUpdate",t),t.calculative.canvas.render())}function uo(t,e){e.onAdd||(e.onAdd=fo,e.optionPos||(e.onAdd(e),e.calculative.canvas.parent.active([e])),e.onMouseDown=po,e.onValue=vo);let i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,r=e.calculative.worldRect.height,o=e.calculative.worldRect.width;if(e.optionPos)if("horizontal"==e.direction)for(let s=0;st.calculative.worldRect.x+t.optionPos[i]*t.calculative.worldRect.width/t.checkboxWidth&&e.xt.calculative.worldRect.y+t.optionPos[n]*i&&e.y({id:`${n}`,penId:t.id,x:e,y:i})))}function wo(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 bo(t){t.anchors=[{x:.5,y:0},{x:.5,y:1}].map((({x:e,y:i},n)=>({id:`${n}`,penId:t.id,x:e,y:i})))}function xo(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 ko(t){t.anchors=[{x:.6,y:0},{x:1,y:.5},{x:.6,y:1},{x:0,y:.5}].map((({x:e,y:i},n)=>({id:`${n}`,penId:t.id,x:e,y:i})))}function To(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 Ao(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 So(t){t.anchors=[{x:.5,y:0},{x:1,y:.5},{x:.5,y:1}].map((({x:e,y:i},n)=>({id:`${n}`,penId:t.id,x:e,y:i})))}function Po(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 Co(t){t.anchors=[{x:.5,y:0},{x:.2,y:1},{x:.5,y:1},{x:.8,y:1}].map((({x:e,y:i},n)=>({id:`${n}`,penId:t.id,x:e,y:i})))}function Ro(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 _o(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 Eo(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 Io(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 Lo(t){t.anchors=[{x:.5,y:0},{x:1,y:2/3},{x:.5,y:1},{x:0,y:2/3}].map((({x:e,y:i},n)=>({id:`${n}`,penId:t.id,x:e,y:i})))}function Mo(t,e){const{x:i,y:n,width:r,height:o}=e.calculative.worldRect,s=r/2,a=o/10;t.beginPath(),t.moveTo(i+s,n),t.lineTo(i+s,n+a),t.moveTo(i+s,n+a),t.quadraticCurveTo(i+2*s,n+a,i+2*s,n+9*a),t.moveTo(i+s,n+a),t.quadraticCurveTo(i,n+a,i,n+9*a),t.quadraticCurveTo(i+s,n+6*a,i+2*s,n+9*a),t.moveTo(i+s,n+3*o/4),t.lineTo(i+s,n+9*o/10),t.moveTo(i+2*s/5,n+201*o/250),t.lineTo(i+2*s/5,n+9*o/10),t.moveTo(i+8*s/5,n+201*o/250),t.lineTo(i+8*s/5,n+9*o/10),t.stroke(),t.closePath(),t.beginPath();const c=2*s>10*a?a:s/5;t.fillStyle="#333333",t.font=c+"px Arial",t.textBaseline="bottom",t.textAlign="center",t.fillText("o",i+s,n+o),t.fillText("m",i+2*s/5,n+o),t.fillText("o",i+8*s/5,n+o),t.closePath()}function Do(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s}=t.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 Bo(t){t.anchors=[{x:.5,y:0},{x:.2,y:1},{x:.8,y:1}].map((({x:e,y:i},n)=>({id:`${n}`,penId:t.id,x:e,y:i})))}function No(){return{andGate:yo,basicEvent:wo,conditionalEvent:xo,event:To,forbiddenGate:Ao,orGate:Po,priorityAndGate:Ro,switchEvent:_o,transferSymbol:Eo,unexpandedEvent:Io,xorGate:Do}}function Oo(){return{votingGate:Mo}}function zo(){return{andGate:mo,orGate:Co,priorityAndGate:mo,votingGate:Co,xorGate:Bo,forbiddenGate:So,basicEvent:bo,unexpandedEvent:Lo,conditionalEvent:ko,transferSymbol:bo}}!function(t){t[t.Add=0]="Add",t[t.Replace=1]="Replace",t[t.ReplaceAll=2]="ReplaceAll"}(mn||(mn={})),function(t){t[t.Add=0]="Add",t[t.Replace=1]="Replace",t[t.ReplaceAll=2]="ReplaceAll"}(wn||(wn={}));const Fo=15;function jo(t,e=Fo){let i=""+t;return i.indexOf(".")>=0&&(i=Number.parseFloat(i).toFixed(e)),Number.parseFloat(i)}function Ho(t){return"number"==typeof t&&Number.isFinite(t)}function Uo(t,e){const i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,r=e.calculative.worldRect.width,o=e.calculative.worldRect.height;let s=[];if(e.echarts)for(let t=0;t0&&(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=e[0]*l,f=-1;for(u=0;uh){d=e[u]*l;break}let p=i,v=n;function g(t){if(p=parseInt(""+(i/t+1))*t,v=parseInt(""+(n/t-1))*t,0===i&&(p=0),0===n&&(v=0),o&&p*v<0){const t=Math.max(Math.abs(p),Math.abs(v));p=t,v=-t}}if(g(d),s)return{max:jo(p),min:jo(v),interval:jo(d),splitNumber:Math.round((p-v)/d)};if(!o||p*v>0){let t;t:do{if(t=Math.round((p-v)/d),(u-f)*(t-r)<0)for(;t=e.length-1||u<=0||t===r)break;f=u,d=t>r?e[++u]*l:e[--u]*l,g(d)}while(t!==r)}p=jo(p),v=jo(v);const y=jo((p-v)/r);return{max:p,min:v,interval:y,splitNumber:r}}({max:Math.max.apply(null,a),min:Math.min.apply(null,a),splitNumber:5}),l=e.echarts?e.echarts.option.xAxis.data.length:e.xAxisData.length;t.beginPath(),t.strokeStyle="#BFBFBF",t.lineWidth=6,t.lineCap="butt";let h=(r-1*(l+1))/l;t.setLineDash([1,h]),t.moveTo(i,n+o+3),t.lineTo(i+r,n+o+3),t.stroke(),t.closePath(),t.beginPath(),t.lineWidth=1,t.setLineDash([]),t.moveTo(i,n+o),t.lineTo(i+r,n+o),t.stroke(),t.closePath(),t.beginPath(),t.fillStyle="#BFBFBF",t.strokeStyle="#E9E9E9",t.setLineDash([2,2]);for(let e=0;e{d=i+(1+a/2)+(a+1)*v,f=n+r-(u[v]-c.min)/(c.max-c.min)*r;let g=i+(1+a/2)+(a+1)*(v+1),y=n+r-(u[v+1]-c.min)/(c.max-c.min)*r,m=i+(1+a/2)+(a+1)*(v-1),w=n+r-(u[v-1]-c.min)/(c.max-c.min)*r,b=i+(1+a/2)+(a+1)*(v+2),x=n+r-(u[v+2]-c.min)/(c.max-c.min)*r;0===v?(m=i+(1+a/2)+(a+1)*v,w=n+r-(u[v]-c.min)/(c.max-c.min)*r):v===u.length-2&&(b=i+(1+a/2)+(a+1)*(v+1),x=n+r-(u[v+1]-c.min)/(c.max-c.min)*r),h.push({x:d,y:f}),e=d+(g-m)/4,o=f+(y-w)/4,s=g-(b-d)/4,l=y-(x-f)/4,t.bezierCurveTo(e,o,s,l,g,y)}))}else for(let e=1;e{t.beginPath(),t.strokeStyle="#fff",t.lineWidth=2,t.arc(e.x,e.y,4,0,2*Math.PI),t.stroke(),t.fill(),t.closePath()})),h=[]}}function Ko(t,e){if(e.xAxisData||e.data||!e.dataX&&!e.dataY)return e;const i=t.xAxisData,n=t.data,r=t.replaceMode;let o=[],s=[];return r?r===qo.Replace?(e.dataX.forEach(((t,r)=>{let o=i.indexOf(t);n.forEach(((t,i)=>{t[o]=e.dataY[i][r]}))})),o=i,s=n):r===qo.ReplaceAll&&(o=e.dataX,s=e.dataY):(o=[...i,...e.dataX],n.forEach(((t,i)=>{let n=[...t,...e.dataY[i]];s.push(n)}))),delete e.dataX,delete e.dataY,Object.assign(e,{xAxisData:o,data:s})}function Yo(t,e){e.onBeforeValue||(e.onBeforeValue=Xo);const i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,r=e.calculative.worldRect.width,o=e.calculative.worldRect.height,s=!!e.echarts;e.echarts?(e.echarts.option.color||(e.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]),e.chartsColor=e.echarts.option.color):e.chartsColor||(e.chartsColor=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]);const a=s?e.echarts.option.series:e.data;let c=0;for(let l=0;lt+e.value),0):h.reduce(((t,e)=>t+e.value),0);const v=u*parseFloat(s?h.radius[0]:e.chartsRadius[l][0])/100,g=u*parseFloat(s?h.radius[1]:e.chartsRadius[l][1])/100;if(v>g)return;let y=0,m=0;t.strokeStyle=s&&h.itemStyle?.borderColor||"#fff",t.lineWidth=s&&h.itemStyle?.borderWidth||2;const w=s?h.data:h;w.forEach(((i,n)=>{m+=2*Math.PI*i.value/p,t.beginPath();let r=c+n;r>=e.chartsColor.length&&(r%=e.chartsColor.length),t.fillStyle=s?e.echarts.option.color[r]:e.chartsColor[r],t.moveTo(d+v*Math.sin(m),f-v*Math.cos(m)),t.arc(d,f,v,-Math.PI/2+m,-Math.PI/2+y,!0),t.lineTo(d+g*Math.sin(y),f-g*Math.cos(y)),t.arc(d,f,g,-Math.PI/2+y,-Math.PI/2+m),t.lineTo(d+v*Math.sin(m),f-v*Math.cos(m)),t.stroke(),t.fill(),t.closePath();let o=(y+m)/2,a=d+(g+5)*Math.sin(o),l=f-(g+5)*Math.cos(o),w=t.fillStyle;h.label||(h.label={position:"outside",show:!0}),s&&["inner","inside"].includes(h.label.position)?(t.fillStyle="#ffffff",a=d+(g-v)/2*Math.sin(o),l=f-(g-v)/2*Math.cos(o)):s&&h.label.position,h.labelLine||(h.labelLine={show:!0}),(s&&!1!==h.labelLine.show||!s)&&(t.beginPath(),t.strokeStyle=s?e.echarts.option.color[c+n]:e.chartsColor[c+n],t.moveTo(d+g*Math.sin(o),f-g*Math.cos(o)),t.lineTo(a,l)),t.font=u/10+"px AlibabaPuHuiTi-Regular, Alibaba PuHuiTi",t.textBaseline="middle",t.textAlign="center",o>Math.PI?((s&&"outside"===h.label.position||!s)&&(t.textAlign="end"),(s&&!1!==h.labelLine.show||!s)&&t.lineTo(a-5,l),(s&&!1!==h.label.show||!s)&&t.fillText(i.name,a-5,l)):((s&&"outside"===h.label.position||!s)&&(t.textAlign="start"),(s&&!1!==h.labelLine.show||!s)&&t.lineTo(a+5,l),(s&&!1!==h.label.show||!s)&&t.fillText(i.name,a+5,l)),t.stroke(),t.closePath(),t.fillStyle=w,t.strokeStyle=s&&h.itemStyle?.borderColor||"#fff",y=m})),c+=w.length}}function Xo(t,e){if(e.data||!e.dataX&&!e.dataY)return e;const i=t.data,n=t.replaceMode;let r=[];return n?n===qo.Replace?(e.dataY.forEach(((t,e)=>{t.forEach(((t,n)=>{let r=i[e].filter((e=>e.name===t.name));r.length>0&&(r[0].value=t.value)}))})),r=i):n===qo.ReplaceAll&&(r=e.dataY):i.forEach(((t,i)=>{let n=[...t,...e.dataY[i]];r.push(n)})),delete e.dataX,delete e.dataY,Object.assign(e,{data:r})}function $o(t,e){e.onBeforeValue||(e.onBeforeValue=Ko);const i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,r=(e.calculative.worldRect.width,e.calculative.worldRect.height);let o=[];if(e.echarts&&!e.echarts.option.color&&(e.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]),e.echarts)for(let t=0;to?o/2*9/10:r/2*9/10,l=i+r/2,h=n+o/2,u=(e={...s,...e}).echarts?e.echarts.option.series[0].data[0].value:e.value,d=e.startAngle-e.endAngle,f=e.background||"#E6EBF8";t.strokeStyle=f;let p=c/10;t.lineWidth=p,t.beginPath(),t.lineCap="round",t.arc(l,h,c,-e.startAngle/180*Math.PI,-e.endAngle/180*Math.PI),t.stroke(),t.closePath();let v=0;if(e.axisLine&&!e.isClock)for(let i=e.axisLine.length-1;i>=0;i--)e.axisLine[i][0]*(e.max-e.min).02?"end":r<-.02?"start":"center",t.textBaseline=o>.02?"top":o<-.02?"bottom":"middle",t.fillText(Wo(S*i+e.min,1),l+P*r,h-P*o),t.fill()}t.closePath();let C=1,R=["value"];if(e.isClock&&(C=3,R=["hourvalue","minutevalue","secondvalue"]),e.isClock)for(let i=0;i0&&(n=(e.startAngle-(e[R[i]]-e.min)/(5*e.max-e.min)*d)/180*Math.PI);let r=.8*c;"hourvalue"===R[i]&&(r=.6*c),"minutevalue"===R[i]&&(r=.7*c);let o=1*c/40;t.beginPath(),t.setLineDash([]),t.lineWidth=c/(i+1)/20,t.strokeStyle=e.color||"#999999",t.moveTo(l-3*o*Math.cos(n),h+3*o*Math.sin(n)),t.lineTo(l+r*Math.cos(n),h-r*Math.sin(n)),t.stroke()}else{let i=(e.startAngle-(u-e.min)/(e.max-e.min)*d)/180*Math.PI,n=.8*c,r=1*c/40;t.beginPath(),t.setLineDash([]),t.lineWidth=2,t.fillStyle=a,t.moveTo(l-3*r*Math.cos(i),h+3*r*Math.sin(i)),t.lineTo(l+r*Math.cos(i-Math.PI/2),h-r*Math.sin(i-Math.PI/2)),t.lineTo(l+n*Math.cos(i),h-n*Math.sin(i)),t.lineTo(l+r*Math.cos(i+Math.PI/2),h-r*Math.sin(i+Math.PI/2)),t.lineTo(l-3*r*Math.cos(i),h+3*r*Math.sin(i)),t.fill()}t.beginPath(),t.textAlign="center",t.textBaseline="middle",t.font=(e.calculative.fontStyle||"")+" normal "+(e.calculative.fontWeight||"")+" "+c/5+"px "+e.calculative.fontFamily,t.fillStyle=a,e.isClock?t.fillText(("0"+parseInt(e.hourvalue)).slice(-2)+":"+("0"+parseInt(e.minutevalue)).slice(-2)+":"+("0"+parseInt(e.secondvalue)).slice(-2),l,h+c/2):t.fillText(u+" "+(e.unit||""),l,h+c/2),t.fill(),e.isClock&&(t.beginPath(),t.fillStyle=e.color||"#999999",t.strokeStyle="#ffffff",t.arc(l,h,c/20,0,2*Math.PI),t.stroke(),t.fill(),t.closePath())}function Qo(t){if(t.isClock)t.clockInterval=setInterval((()=>{var e=new Date,i=e.getSeconds(),n=e.getMinutes()+i/60,r=e.getHours()%12+n/60;t.calculative.canvas.parent.setValue({id:t.id,hourvalue:r,minutevalue:n,secondvalue:i},{render:!0,doEvent:!1})}),1e3);else{const e=t.value;t.value=0,t.frames=[{duration:2e3,value:e}],t.calculative.canvas.parent.startAnimate(t.id),setTimeout((()=>{t.value=e}),1e3)}}function Jo(t){t.clockInterval&&(clearInterval(t.clockInterval),t.clockInterval=void 0)}function Zo(t){t.isClock&&(t.onDestroy(t),t.onAdd(t))}function ts(){return{lineChart:Vo,histogram:$o,pieChart:Yo,gauge:Go}}!function(t){t[t.Add=0]="Add",t[t.Replace=1]="Replace",t[t.ReplaceAll=2]="ReplaceAll"}(qo||(qo={})),globalThis.Meta2d=xn,globalThis.registerCommonDiagram=function(){var t=globalThis.meta2d;t&&(xr(),kr(),Tr(),t.register(Zn()),t.registerAnchors(tr()),t.register(Nn()),t.registerCanvasDraw(On()),t.register(Rn()),t.register(In()),t.registerCanvasDraw(Ln()),t.registerCanvasDraw(go()),t.registerCanvasDraw(ts()),t.register(No()),t.registerCanvasDraw(Oo()),t.registerAnchors(zo()))}})(),n})()));