meta2d.js 529 KB

1
  1. !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<i.length;l++){var h=i[l];n(t,h)||a(t,h,c(e,h))}}},762:(t,e,i)=>{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;s<n.length;s++)r(n[s]);return r}({1:[function(t,e,n){(function(i,n){(function(){"use strict";const r=t("events").EventEmitter,o=t("./store"),s=t("./topic-alias-recv"),a=t("./topic-alias-send"),c=t("mqtt-packet"),l=t("./default-message-id-provider"),h=t("readable-stream").Writable,u=t("inherits"),d=t("reinterval"),f=t("rfdc/default"),p=t("./validations"),v=t("xtend"),g=t("debug")("mqttjs:client"),y=i?i.nextTick:function(t){setTimeout(t,0)},m=n.setImmediate||function(t){y(t)},w={keepalive:60,reschedulePings:!0,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:1e3,connectTimeout:3e4,clean:!0,resubscribe:!0},b=["ECONNREFUSED","EADDRINUSE","ECONNRESET","ENOTFOUND"],x={0:"",1:"Unacceptable protocol version",2:"Identifier rejected",3:"Server unavailable",4:"Bad username or password",5:"Not authorized",16:"No matching subscribers",17:"No subscription existed",128:"Unspecified error",129:"Malformed Packet",130:"Protocol Error",131:"Implementation specific error",132:"Unsupported Protocol Version",133:"Client Identifier not valid",134:"Bad User Name or Password",135:"Not authorized",136:"Server unavailable",137:"Server busy",138:"Banned",139:"Server shutting down",140:"Bad authentication method",141:"Keep Alive timeout",142:"Session taken over",143:"Topic Filter invalid",144:"Topic Name invalid",145:"Packet identifier in use",146:"Packet Identifier not found",147:"Receive Maximum exceeded",148:"Topic Alias invalid",149:"Packet too large",150:"Message rate too high",151:"Quota exceeded",152:"Administrative action",153:"Payload format invalid",154:"Retain not supported",155:"QoS not supported",156:"Use another server",157:"Server moved",158:"Shared Subscriptions not supported",159:"Connection rate exceeded",160:"Maximum connect time",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"};function k(t,e){let i;e.properties&&(i=e.properties.topicAlias);let n=e.topic.toString();if(0===n.length){if(void 0===i)return new Error("Unregistered Topic Alias");if(void 0===(n=t.topicAliasSend.getTopicByAlias(i)))return new Error("Unregistered Topic Alias");e.topic=n}i&&delete e.properties.topicAlias}function T(t,e,i){g("sendPacket :: packet: %O",e),g("sendPacket :: emitting `packetsend`"),t.emit("packetsend",e),g("sendPacket :: writing to stream");const n=c.writeToStream(e,t.stream,t.options);g("sendPacket :: writeToStream result %s",n),!n&&i&&i!==S?(g("sendPacket :: handle events on `drain` once through callback."),t.stream.once("drain",i)):i&&(g("sendPacket :: invoking cb"),i())}function A(t,e,i,n){g("storeAndSend :: store packet with cmd %s to outgoingStore",e.cmd);let r,o=e;if("publish"===o.cmd&&(o=f(e),r=k(t,o)))return i&&i(r);t.outgoingStore.put(o,(function(r){if(r)return i&&i(r);n(),T(t,e,i)}))}function S(t){g("nop ::",t)}function P(t,e){let i;const n=this;if(!(this instanceof P))return new P(t,e);for(i in this.options=e||{},w)void 0===this.options[i]?this.options[i]=w[i]:this.options[i]=e[i];g("MqttClient :: options.protocol",e.protocol),g("MqttClient :: options.protocolVersion",e.protocolVersion),g("MqttClient :: options.username",e.username),g("MqttClient :: options.keepalive",e.keepalive),g("MqttClient :: options.reconnectPeriod",e.reconnectPeriod),g("MqttClient :: options.rejectUnauthorized",e.rejectUnauthorized),g("MqttClient :: options.topicAliasMaximum",e.topicAliasMaximum),this.options.clientId="string"==typeof e.clientId?e.clientId:"mqttjs_"+Math.random().toString(16).substr(2,8),g("MqttClient :: clientId",this.options.clientId),this.options.customHandleAcks=5===e.protocolVersion&&e.customHandleAcks?e.customHandleAcks:function(){arguments[3](0)},this.streamBuilder=t,this.messageIdProvider=void 0===this.options.messageIdProvider?new l:this.options.messageIdProvider,this.outgoingStore=e.outgoingStore||new o,this.incomingStore=e.incomingStore||new o,this.queueQoSZero=void 0===e.queueQoSZero||e.queueQoSZero,this._resubscribeTopics={},this.messageIdToTopic={},this.pingTimer=null,this.connected=!1,this.disconnecting=!1,this.queue=[],this.connackTimer=null,this.reconnectTimer=null,this._storeProcessing=!1,this._packetIdsDuringStoreProcessing={},this._storeProcessingQueue=[],this.outgoing={},this._firstConnection=!0,e.topicAliasMaximum>0&&(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.maximumPacketSize<t.length)return this.emit("error",new Error("exceeding packets size "+t.cmd)),this.end({reasonCode:149,properties:{reasonString:"Maximum packet size was exceeded"}}),this;switch(g("_handlePacket :: emitting packetreceive"),this.emit("packetreceive",t),t.cmd){case"publish":this._handlePublish(t,e);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":this._handleAck(t),e();break;case"pubrel":this._handlePubrel(t,e);break;case"connack":this._handleConnack(t),e();break;case"auth":this._handleAuth(t),e();break;case"pingresp":this._handlePingresp(t),e();break;case"disconnect":this._handleDisconnect(t),e()}},P.prototype._checkDisconnecting=function(t){return this.disconnecting&&(t&&t!==S?t(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting},P.prototype.publish=function(t,e,i,n){g("publish :: message `%s` to topic `%s`",e,t);const r=this.options;if("function"==typeof i&&(n=i,i=null),i=v({qos:0,retain:!1,dup:!1},i),this._checkDisconnecting(n))return this;const o=this,s=function(){let s=0;if((1===i.qos||2===i.qos)&&null===(s=o._nextId()))return g("No messageId left"),!1;const a={cmd:"publish",topic:t,payload:e,qos:i.qos,retain:i.retain,messageId:s,dup:i.dup};switch(5===r.protocolVersion&&(a.properties=i.properties),g("publish :: qos",i.qos),i.qos){case 1:case 2:o.outgoing[a.messageId]={volatile:!1,cb:n||S},g("MqttClient:publish: packet cmd: %s",a.cmd),o._sendPacket(a,void 0,i.cbStorePut);break;default:g("MqttClient:publish: packet cmd: %s",a.cmd),o._sendPacket(a,n,i.cbStorePut)}return!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!s())&&this._storeProcessingQueue.push({invoke:s,cbStorePut:i.cbStorePut,callback:n}),this},P.prototype.subscribe=function(){const t=this,e=new Array(arguments.length);for(let t=0;t<arguments.length;t++)e[t]=arguments[t];const i=[];let n=e.shift();const r=n.resubscribe;let o=e.pop()||S,s=e.pop();const a=this.options.protocolVersion;delete n.resubscribe,"string"==typeof n&&(n=[n]),"function"!=typeof o&&(s=o,o=S);const c=p.validateTopics(n);if(null!==c)return m(o,new Error("Invalid topic "+c)),this;if(this._checkDisconnecting(o))return g("subscribe: discconecting true"),this;const l={qos:0};if(5===a&&(l.nl=!1,l.rap=!1,l.rh=0),s=v(l,s),Array.isArray(n)?n.forEach((function(e){if(g("subscribe: array topic %s",e),!Object.prototype.hasOwnProperty.call(t._resubscribeTopics,e)||t._resubscribeTopics[e].qos<s.qos||r){const t={topic:e,qos:s.qos};5===a&&(t.nl=s.nl,t.rap=s.rap,t.rh=s.rh,t.properties=s.properties),g("subscribe: pushing topic `%s` and qos `%s` to subs list",t.topic,t.qos),i.push(t)}})):Object.keys(n).forEach((function(e){if(g("subscribe: object topic %s",e),!Object.prototype.hasOwnProperty.call(t._resubscribeTopics,e)||t._resubscribeTopics[e].qos<n[e].qos||r){const t={topic:e,qos:n[e].qos};5===a&&(t.nl=n[e].nl,t.rap=n[e].rap,t.rh=n[e].rh,t.properties=s.properties),g("subscribe: pushing `%s` to subs list",t),i.push(t)}})),!i.length)return o(null,[]),this;const h=function(){const e=t._nextId();if(null===e)return g("No messageId left"),!1;const n={cmd:"subscribe",subscriptions:i,qos:1,retain:!1,dup:!1,messageId:e};if(s.properties&&(n.properties=s.properties),t.options.resubscribe){g("subscribe :: resubscribe true");const e=[];i.forEach((function(i){if(t.options.reconnectPeriod>0){const n={qos:i.qos};5===a&&(n.nl=i.nl||!1,n.rap=i.rap||!1,n.rh=i.rh||0,n.properties=i.properties),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;e<t.length;e+=1)i[e].qos=t[e]}o(t,i)}},g("subscribe :: call _sendPacket"),t._sendPacket(n),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!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;t<arguments.length;t++)e[t]=arguments[t];let i=e.shift(),n=e.pop()||S,r=e.pop();"string"==typeof i&&(i=[i]),"function"!=typeof n&&(r=n,n=S);const o=p.validateTopics(i);if(null!==o)return m(n,new Error("Invalid topic "+o)),this;if(t._checkDisconnecting(n))return this;const s=function(){const e=t._nextId();if(null===e)return g("No messageId left"),!1;const o={cmd:"unsubscribe",qos:1,messageId:e};return"string"==typeof i?o.unsubscriptions=[i]:Array.isArray(i)&&(o.unsubscriptions=i),t.options.resubscribe&&o.unsubscriptions.forEach((function(e){delete t._resubscribeTopics[e]})),"object"==typeof r&&r.properties&&(o.properties=r.properties),t.outgoing[o.messageId]={volatile:!0,cb:n},g("unsubscribe: call _sendPacket"),t._sendPacket(o),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!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;i<t.granted.length;i++)if(0!=(128&t.granted[i])){const t=this.messageIdToTopic[e];t&&t.forEach((function(t){delete o._resubscribeTopics[t]}))}this._invokeStoreProcessingQueue(),r(null,t);break;case"unsuback":delete this.outgoing[e],this.messageIdProvider.deallocate(e),this._invokeStoreProcessingQueue(),r(null);break;default:o.emit("error",new Error("unrecognized packet type"))}this.disconnecting&&0===Object.keys(this.outgoing).length&&this.emit("outgoingEmpty")}else g("_handleAck :: Server sent an ack in error. Ignoring.")},P.prototype._handlePubrel=function(t,e){g("handling pubrel packet"),e=void 0!==e?e:S;const i=this,n={cmd:"pubcomp",messageId:t.messageId};i.incomingStore.get(t,(function(t,r){t?i._sendPacket(n,e):(i.emit("message",r.topic,r.payload,r),i.handleMessage(r,(function(t){if(t)return e(t);i.incomingStore.del(r,S),i._sendPacket(n,e)})))}))},P.prototype._handleDisconnect=function(t){this.emit("disconnect",t)},P.prototype._nextId=function(){return this.messageIdProvider.allocate()},P.prototype.getLastMessageId=function(){return this.messageIdProvider.getLastAllocated()},P.prototype._resubscribe=function(){g("_resubscribe");const t=Object.keys(this._resubscribeTopics);if(!this._firstConnection&&(this.options.clean||5===this.options.protocolVersion&&!this.connackPacket.sessionPresent)&&t.length>0)if(this.options.resubscribe)if(5===this.options.protocolVersion){g("_resubscribe: protocolVersion 5");for(let e=0;e<t.length;e++){const i={};i[t[e]]=this._resubscribeTopics[t[e]],i.resubscribe=!0,this.subscribe(i,{properties:i[t[e]].properties})}}else this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics);else this._resubscribeTopics={};this._firstConnection=!1},P.prototype._onConnect=function(t){if(this.disconnected)return void this.emit("connect",t);const e=this;this.connackPacket=t,this.messageIdProvider.clear(),this._setupPingTimer(),this.connected=!0,function i(){let n=e.outgoingStore.createStream();function r(){e._storeProcessing=!1,e._packetIdsDuringStoreProcessing={}}function o(){n.destroy(),n=null,e._flushStoreProcessingQueue(),r()}e.once("close",o),n.on("error",(function(t){r(),e._flushStoreProcessingQueue(),e.removeListener("close",o),e.emit("error",t)})),n.on("end",(function(){let n=!0;for(const t in e._packetIdsDuringStoreProcessing)if(!e._packetIdsDuringStoreProcessing[t]){n=!1;break}n?(r(),e.removeListener("close",o),e._invokeAllStoreProcessingQueue(),e.emit("connect",t)):i()})),function t(){if(!n)return;e._storeProcessing=!0;const i=n.read(1);let r;i?e._packetIdsDuringStoreProcessing[i.messageId]?t():e.disconnecting||e.reconnectTimer?n.destroy&&n.destroy():(r=e.outgoing[i.messageId]?e.outgoing[i.messageId].cb:null,e.outgoing[i.messageId]={volatile:!1,cb:function(e,i){r&&r(e,i),t()}},e._packetIdsDuringStoreProcessing[i.messageId]=!0,e.messageIdProvider.register(i.messageId)?e._sendPacket(i):g("messageId: %d has already used.",i.messageId)):n.once("readable",t)}()}()},P.prototype._invokeStoreProcessingQueue=function(){if(this._storeProcessingQueue.length>0){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<t.length;e++)"string"==typeof t[e].chunk?i[e]=r.from(t[e],"utf8"):i[e]=t[e].chunk;this._write(r.concat(i),"binary",e)}return h.readyState===h.OPEN?i=f:(i=i=a(void 0,void 0,e),e.objectMode||(i._writev=w),p?h.addEventListener("open",v):h.onopen=v),i.socket=h,p?(h.addEventListener("close",g),h.addEventListener("error",y),h.addEventListener("message",m)):(h.onclose=g,h.onerror=y,h.onmessage=m),i}:function(t,e){s("streamBuilder");const i=d(e),n=u(i,t),r=function(t,e,i){s("createWebSocket"),s("protocol: "+i.protocolId+" "+i.protocolVersion);const n="MQIsdp"===i.protocolId&&3===i.protocolVersion?"mqttv3.1":"mqtt";return s("creating new Websocket for url: "+e+" and protocol: "+n),new o(e,[n],i.wsOptions)}(0,n,i),a=o.createWebSocketStream(r,i.wsOptions);return a.url=n,r.on("close",(()=>{a.destroy()})),a}}).call(this)}).call(this,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&&n<e.length?this.push(e[n++]):this.push(null)},t.destroy=function(){if(i)return;const t=this;i=!0,setTimeout((function(){t.emit("close")}),0)},t},a.prototype.del=function(t,e){return(t=this._inflights.get(t.messageId))?(this._inflights.delete(t.messageId),e(null,t)):e&&e(new Error("missing packet")),this},a.prototype.get=function(t,e){return(t=this._inflights.get(t.messageId))?e(null,t):e&&e(new Error("missing packet")),this},a.prototype.close=function(t){this.options.clean&&(this._inflights=null),t&&t()},e.exports=a},{"readable-stream":69,xtend:81}],9:[function(t,e,i){"use strict";function n(t){if(!(this instanceof n))return new n(t);this.aliasToTopic={},this.max=t}n.prototype.put=function(t,e){return!(0===e||e>this.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;t<e.length;t++)if("+"!==e[t]){if("#"===e[t])return t===e.length-1;if(-1!==e[t].indexOf("+")||-1!==e[t].indexOf("#"))return!1}return!0}e.exports={validateTopics:function(t){if(0===t.length)return"empty_topic_list";for(let e=0;e<t.length;e++)if(!n(t[e]))return t[e];return null}}},{}],12:[function(t,e,n){(function(n){(function(){"use strict";const r=t("../client"),o=t("../store"),s=t("url"),a=t("xtend"),c=t("debug")("mqttjs"),l={};function h(t,e){if(c("connecting to an MQTT broker..."),"object"!=typeof t||e||(e=t,t=null),e=e||{},t){const i=s.parse(t,!0);if(null!=i.port&&(i.port=Number(i.port)),null===(e=a(i,e)).protocol)throw new Error("Missing protocol");e.protocol=e.protocol.replace(/:$/,"")}if(function(t){let e;t.auth&&((e=t.auth.match(/^(.+):(.+)$/))?(t.username=e[1],t.password=e[2]):t.username=t.auth)}(e),e.query&&"string"==typeof e.query.clientId&&(e.clientId=e.query.clientId),e.cert&&e.key){if(!e.protocol)throw new Error("Missing secure protocol key");if(-1===["mqtts","wss","wxs","alis"].indexOf(e.protocol))switch(e.protocol){case"mqtt":e.protocol="mqtts";break;case"ws":e.protocol="wss";break;case"wx":e.protocol="wxs";break;case"ali":e.protocol="alis";break;default:throw new Error('Unknown protocol for secure connection: "'+e.protocol+'"!')}}if(!l[e.protocol]){const t=-1!==["mqtts","wss"].indexOf(e.protocol);e.protocol=["mqtt","mqtts","ws","wss","wx","wxs","ali","alis"].filter((function(e,i){return(!t||i%2!=0)&&"function"==typeof l[e]}))[0]}if(!1===e.clean&&!e.clientId)throw new Error("Missing clientId for unclean clients");e.protocol&&(e.defaultProtocol=e.protocol);const i=new r((function(t){return e.servers&&(t._reconnectCount&&t._reconnectCount!==e.servers.length||(t._reconnectCount=0),e.host=e.servers[t._reconnectCount].host,e.port=e.servers[t._reconnectCount].port,e.protocol=e.servers[t._reconnectCount].protocol?e.servers[t._reconnectCount].protocol:e.defaultProtocol,e.hostname=e.host,t._reconnectCount++),c("calling streambuilder for",e.protocol),l[e.protocol](t,e)}),e);return i.on("error",(function(){})),i}void 0!==n&&"browser"!==n.title||"function"!=typeof i?(l.mqtt=t("./tcp"),l.tcp=t("./tcp"),l.ssl=t("./tls"),l.tls=t("./tls"),l.mqtts=t("./tls")):(l.wx=t("./wx"),l.wxs=t("./wx"),l.ali=t("./ali"),l.alis=t("./ali")),l.ws=t("./ws"),l.wss=t("./ws"),e.exports=h,e.exports.connect=h,e.exports.MqttClient=r,e.exports.Store=o}).call(this)}).call(this,t("_process"))},{"../client":1,"../store":8,"./ali":2,"./tcp":3,"./tls":4,"./ws":5,"./wx":6,_process:50,debug:18,url:76,xtend:81}],13:[function(t,e,i){"use strict";i.byteLength=function(t){var e=l(t),i=e[0],n=e[1];return 3*(i+n)/4-n},i.toByteArray=function(t){var e,i,n=l(t),s=n[0],a=n[1],c=new o(function(t,e,i){return 3*(e+i)/4-i}(0,s,a)),h=0,u=a>0?s-4:s;for(i=0;i<u;i+=4)e=r[t.charCodeAt(i)]<<18|r[t.charCodeAt(i+1)]<<12|r[t.charCodeAt(i+2)]<<6|r[t.charCodeAt(i+3)],c[h++]=e>>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;s<a;s+=16383)o.push(h(t,s,s+16383>a?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;a<c;++a)n[a]=s[a],r[s.charCodeAt(a)]=a;function l(t){var e=t.length;if(e%4>0)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<i;a+=3)r=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),s.push(n[(o=r)>>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return s.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},{}],14:[function(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;i<this._bufs.length;i++){const n=e+this._bufs[i].length;if(t<n||i===this._bufs.length-1)return[i,t-e];e=n}},o.prototype._reverseOffset=function(t){const e=t[0];let i=t[1];for(let t=0;t<e;t++)i+=this._bufs[t].length;return i},o.prototype.get=function(t){if(t>this.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;e<this._bufs.length;e++)this._bufs[e].copy(t,l),l+=this._bufs[e].length;return t}if(c<=this._bufs[s[0]].length-h)return o?this._bufs[s[0]].copy(t,e,h,h+c):this._bufs[s[0]].slice(h,h+c);o||(t=n.allocUnsafe(a));for(let e=s[0];e<this._bufs.length;e++){const i=this._bufs[e].length-h;if(!(c>i)){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;e<this._bufs.length;e++)t.append(this._bufs[e]);return t},o.prototype.append=function(t){if(null==t)return this;if(t.buffer)this._appendBuffer(n.from(t.buffer,t.byteOffset,t.byteLength));else if(Array.isArray(t))for(let e=0;e<t.length;e++)this.append(t[e]);else if(this._isBufferList(t))for(let e=0;e<t._bufs.length;e++)this.append(t._bufs[e]);else"number"==typeof t&&(t=t.toString()),this._appendBuffer(n.from(t));return this},o.prototype._appendBuffer=function(t){this._bufs.push(t),this.length+=t.length},o.prototype.indexOf=function(t,e,i){if(void 0===i&&"string"==typeof e&&(i=e,e=void 0),"function"==typeof t||Array.isArray(t))throw new TypeError('The "value" argument must be one of type string, Buffer, BufferList, or Uint8Array.');if("number"==typeof t?t=n.from([t]):"string"==typeof t?t=n.from(t,i):this._isBufferList(t)?t=t.slice():Array.isArray(t.buffer)?t=n.from(t.buffer,t.byteOffset,t.byteLength):n.isBuffer(t)||(t=n.from(t)),e=Number(e||0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),0===t.length)return e>this.length?this.length:e;const r=this._offset(e);let o=r[0],s=r[1];for(;o<this._bufs.length;o++){const e=this._bufs[o];for(;s<e.length;)if(e.length-s>=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-t<e.length)return!1;for(let i=0;i<e.length;i++)if(this.get(t+i)!==e[i])return!1;return!0},function(){const t={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1,readIntBE:null,readIntLE:null,readUIntBE:null,readUIntLE:null};for(const e in t)!function(e){o.prototype[e]=null===t[e]?function(t,i){return this.slice(t,t+i)[e](0,i)}:function(i=0){return this.slice(i,i+t[e])[e](0)}}(e)}(),o.prototype._isBufferList=function(t){return t instanceof o||o.isBufferList(t)},o.isBufferList=function(t){return null!=t&&t[r]},e.exports=o},{buffer:17}],15:[function(t,e,i){"use strict";const n=t("readable-stream").Duplex,r=t("inherits"),o=t("./BufferList");function s(t){if(!(this instanceof s))return new s(t);if("function"==typeof t){this._callback=t;const e=function(t){this._callback&&(this._callback(t),this._callback=null)}.bind(this);this.on("pipe",(function(t){t.on("error",e)})),this.on("unpipe",(function(t){t.removeListener("error",e)})),t=null}o._init.call(this,t),n.call(this)}r(s,n),Object.assign(s.prototype,o.prototype),s.prototype._new=function(t){return new s(t)},s.prototype._write=function(t,e,i){this._appendBuffer(t),"function"==typeof i&&i()},s.prototype._read=function(t){if(!this.length)return this.push(null);t=Math.min(t,this.length),this.push(this.slice(0,t)),this.consume(t)},s.prototype.end=function(t){n.prototype.end.call(this,t),this._callback&&(this._callback(null,this.slice()),this._callback=null)},s.prototype._destroy=function(t,e){this._bufs.length=0,this.length=0,e(t)},s.prototype._isBufferList=function(t){return t instanceof s||t instanceof o||s.isBufferList(t)},s.isBufferList=o.isBufferList,e.exports=s,e.exports.BufferListStream=s,e.exports.BufferList=o},{"./BufferList":14,inherits:24,"readable-stream":69}],16:[function(t,e,i){},{}],17:[function(t,e,i){(function(e){(function(){"use strict";var e=t("base64-js"),n=t("ieee754");i.Buffer=s,i.SlowBuffer=function(t){return+t!=t&&(t=0),s.alloc(+t)},i.INSPECT_MAX_BYTES=50;var r=2147483647;function o(t){if(t>r)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<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(i||0))throw new RangeError('"length" is outside of buffer bounds');var n;return(n=void 0===e&&void 0===i?new Uint8Array(t):void 0===i?new Uint8Array(t,e):new Uint8Array(t,e,i)).__proto__=s.prototype,n}(t,e,i);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return s.from(n,e,i);var r=function(t){if(s.isBuffer(t)){var e=0|u(t.length),i=o(e);return 0===i.length||t.copy(i,0,0,e),i}return void 0!==t.length?"number"!=typeof t.length||j(t.length)?o(0):h(t):"Buffer"===t.type&&Array.isArray(t.data)?h(t.data):void 0}(t);if(r)return r;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return s.from(t[Symbol.toPrimitive]("string"),e,i);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function c(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function l(t){return c(t),o(t<0?0:0|u(t))}function h(t){for(var e=t.length<0?0:0|u(t.length),i=o(e),n=0;n<e;n+=1)i[n]=255&t[n];return i}function u(t){if(t>=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;o<a;o++)if(l(t,o)===l(e,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===c)return h*s}else-1!==h&&(o-=o-h),h=-1}else for(i+c>a&&(i=a-c),o=i;o>=0;o--){for(var u=!0,d=0;d<c;d++)if(l(t,o+d)!==l(e,d)){u=!1;break}if(u)return o}return-1}function g(t,e,i,n){i=Number(i)||0;var r=t.length-i;n?(n=Number(n))>r&&(n=r):n=r;var o=e.length;n>o/2&&(n=o/2);for(var s=0;s<n;++s){var a=parseInt(e.substr(2*s,2),16);if(j(a))return s;t[i+s]=a}return s}function y(t,e,i,n){return z(N(e,t.length-i),t,i,n)}function m(t,e,i,n){return z(function(t){for(var e=[],i=0;i<t.length;++i)e.push(255&t.charCodeAt(i));return e}(e),t,i,n)}function w(t,e,i,n){return m(t,e,i,n)}function b(t,e,i,n){return z(O(e),t,i,n)}function x(t,e,i,n){return z(function(t,e){for(var i,n,r,o=[],s=0;s<t.length&&!((e-=2)<0);++s)n=(i=t.charCodeAt(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;r<i;){var o,s,a,c,l=t[r],h=null,u=l>239?4:l>223?3:l>191?2:1;if(r+u<=i)switch(u){case 1:l<128&&(h=l);break;case 2:128==(192&(o=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;n<e;)i+=String.fromCharCode.apply(String,t.slice(n,n+=A));return i}(n)}i.kMaxLength=r,s.TYPED_ARRAY_SUPPORT=function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()}catch(t){return!1}}(),s.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&s[Symbol.species]===s&&Object.defineProperty(s,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),s.poolSize=8192,s.from=function(t,e,i){return a(t,e,i)},s.prototype.__proto__=Uint8Array.prototype,s.__proto__=Uint8Array,s.alloc=function(t,e,i){return function(t,e,i){return c(t),t<=0?o(t):void 0!==e?"string"==typeof i?o(t).fill(e,i):o(t).fill(e):o(t)}(t,e,i)},s.allocUnsafe=function(t){return l(t)},s.allocUnsafeSlow=function(t){return l(t)},s.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==s.prototype},s.compare=function(t,e){if(F(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),F(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;for(var i=t.length,n=e.length,r=0,o=Math.min(i,n);r<o;++r)if(t[r]!==e[r]){i=t[r],n=e[r];break}return i<n?-1:n<i?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);var i;if(void 0===e)for(e=0,i=0;i<t.length;++i)e+=t[i].length;var n=s.allocUnsafe(e),r=0;for(i=0;i<t.length;++i){var o=t[i];if(F(o,Uint8Array)&&(o=s.from(o)),!s.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,r),r+=o.length}return n},s.byteLength=d,s.prototype._isBuffer=!0,s.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)f(this,e,e+1);return this},s.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)f(this,e,e+3),f(this,e+1,e+2);return this},s.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)f(this,e,e+7),f(this,e+1,e+6),f(this,e+2,e+5),f(this,e+3,e+4);return this},s.prototype.toString=function(){var t=this.length;return 0===t?"":0===arguments.length?T(this,0,t):function(t,e,i){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.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+=" ... "),"<Buffer "+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<c;++u)if(l[u]!==h[u]){o=l[u],a=h[u];break}return o<a?-1:a<o?1:0},s.prototype.includes=function(t,e,i){return-1!==this.indexOf(t,e,i)},s.prototype.indexOf=function(t,e,i){return p(this,t,e,i,!0)},s.prototype.lastIndexOf=function(t,e,i){return p(this,t,e,i,!1)},s.prototype.write=function(t,e,i,n){if(void 0===e)n="utf8",i=this.length,e=0;else if(void 0===i&&"string"==typeof e)n=e,i=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=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;r<i;++r)n+=String.fromCharCode(127&t[r]);return n}function P(t,e,i){var n="";i=Math.min(t.length,i);for(var r=e;r<i;++r)n+=String.fromCharCode(t[r]);return n}function C(t,e,i){var n=t.length;(!e||e<0)&&(e=0),(!i||i<0||i>n)&&(i=n);for(var r="",o=e;o<i;++o)r+=B(t[o]);return r}function R(t,e,i){for(var n=t.slice(e,i),r="",o=0;o<n.length;o+=2)r+=String.fromCharCode(n[o]+256*n[o+1]);return r}function _(t,e,i){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>i)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||e<o)throw new RangeError('"value" argument is out of bounds');if(i+n>t.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<t&&(e=t);var n=this.subarray(t,e);return n.__proto__=s.prototype,n},s.prototype.readUIntLE=function(t,e,i){t>>>=0,e>>>=0,i||_(t,e,this.length);for(var n=this[t],r=1,o=0;++o<e&&(r*=256);)n+=this[t+o]*r;return n},s.prototype.readUIntBE=function(t,e,i){t>>>=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<e&&(r*=256);)n+=this[t+o]*r;return n>=(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<i&&(r*=256);)this[e+o]=t/r&255;return e+i},s.prototype.writeUIntBE=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=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<i&&(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.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<i&&(n=i),n===i)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-i&&(n=t.length-e+i);var r=n-i;if(this===t&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(e,i,n);else if(this===t&&i<e&&e<n)for(var o=r-1;o>=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<e||this.length<i)throw new RangeError("Out of range index");if(i<=e)return this;var o;if(e>>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(o=e;o<i;++o)this[o]=t;else{var a=s.isBuffer(t)?t:s.from(t,n),c=a.length;if(0===c)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<i-e;++o)this[o+e]=a[o%c]}return this};var D=/[^+/0-9A-Za-z-_]/g;function B(t){return t<16?"0"+t.toString(16):t.toString(16)}function N(t,e){var i;e=e||1/0;for(var n=t.length,r=null,o=[],s=0;s<n;++s){if((i=t.charCodeAt(s))>55295&&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<n&&!(r+i>=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<r;e++)n[e]&&("-"===(t=n[e].replace(/\*/g,".*?"))[0]?i.skips.push(new RegExp("^"+t.substr(1)+"$")):i.names.push(new RegExp("^"+t+"$")))},i.enabled=function(t){if("*"===t[t.length-1])return!0;let e,n;for(e=0,n=i.skips.length;e<n;e++)if(i.skips[e].test(t))return!1;for(e=0,n=i.names.length;e<n;e++)if(i.names[e].test(t))return!0;return!1},i.humanize=t("ms"),i.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach((t=>{i[t]=e[t]})),i.names=[],i.skips=[],i.formatters={},i.selectColor=function(t){let e=0;for(let i=0;i<t.length;i++)e=(e<<5)-e+t.charCodeAt(i),e|=0;return i.colors[Math.abs(e)%i.colors.length]},i.enable(i.load()),i}},{ms:45}],20:[function(t,e,i){(function(i,n){(function(){var r=t("readable-stream"),o=t("end-of-stream"),s=t("inherits"),a=t("stream-shift"),c=n.from&&n.from!==Uint8Array.from?n.from([0]):new n([0]),l=function(t,e){t._corked?t.once("uncork",e):e()},h=function(t,e){return function(i){i?function(t,e){t._autoDestroy&&t.destroy(e)}(t,"premature close"===i.message?null:i):e&&!t._ended&&t.end()}},u=function(){},d=function(t,e,i){if(!(this instanceof d))return new d(t,e,i);r.Duplex.call(this,i),this._writable=null,this._readable=null,this._readable2=null,this._autoDestroy=!i||!1!==i.autoDestroy,this._forwardDestroy=!i||!1!==i.destroy,this._forwardEnd=!i||!1!==i.end,this._corked=1,this._ondrain=null,this._drained=!1,this._forwarding=!1,this._unwrite=null,this._unread=null,this._ended=!1,this.destroyed=!1,t&&this.setWritable(t),e&&this.setReadable(e)};s(d,r.Duplex),d.obj=function(t,e,i){return i||(i={}),i.objectMode=!0,i.highWaterMark=16,new d(t,e,i)},d.prototype.cork=function(){1==++this._corked&&this.emit("cork")},d.prototype.uncork=function(){this._corked&&0==--this._corked&&this.emit("uncork")},d.prototype.setWritable=function(t){if(this._unwrite&&this._unwrite(),this.destroyed)t&&t.destroy&&t.destroy();else if(null!==t&&!1!==t){var e=this,n=o(t,{writable:!0,readable:!1},h(this,this._forwardEnd)),r=function(){var t=e._ondrain;e._ondrain=null,t&&t()};this._unwrite&&i.nextTick(r),this._writable=t,this._writable.on("drain",r),this._unwrite=function(){e._writable.removeListener("drain",r),n()},this.uncork()}else this.end()},d.prototype.setReadable=function(t){if(this._unread&&this._unread(),this.destroyed)t&&t.destroy&&t.destroy();else{if(null===t||!1===t)return this.push(null),void this.resume();var e,i=this,n=o(t,{writable:!1,readable:!0},h(this)),s=function(){i._forward()},a=function(){i.push(null)};this._drained=!0,this._readable=t,this._readable2=t._readableState?t:(e=t,new r.Readable({objectMode:!0,highWaterMark:16}).wrap(e)),this._readable2.on("readable",s),this._readable2.on("end",a),this._unread=function(){i._readable2.removeListener("readable",s),i._readable2.removeListener("end",a),n()},this._forward()}},d.prototype._read=function(){this._drained=!0,this._forward()},d.prototype._forward=function(){if(!this._forwarding&&this._readable2&&this._drained){var t;for(this._forwarding=!0;this._drained&&null!==(t=a(this._readable2));)this.destroyed||(this._drained=this.push(t));this._forwarding=!1}},d.prototype.destroy=function(t,e){if(e||(e=u),this.destroyed)return e(null);this.destroyed=!0;var n=this;i.nextTick((function(){n._destroy(t),e(null)}))},d.prototype._destroy=function(t){if(t){var e=this._ondrain;this._ondrain=null,e?e(t):this.emit("error",t)}this._forwardDestroy&&(this._readable&&this._readable.destroy&&this._readable.destroy(),this._writable&&this._writable.destroy&&this._writable.destroy()),this.emit("close")},d.prototype._write=function(t,e,i){if(!this.destroyed)return this._corked?l(this,this._write.bind(this,t,e,i)):t===c?this._finish(i):this._writable?void(!1===this._writable.write(t)?this._ondrain=i:this.destroyed||i()):i()},d.prototype._finish=function(t){var e=this;this.emit("preend"),l(this,(function(){var i,n;n=function(){!1===e._writableState.prefinished&&(e._writableState.prefinished=!0),e.emit("prefinish"),l(e,t)},(i=e._forwardEnd&&e._writable)?i._writableState&&i._writableState.finished?n():i._writableState?i.end(n):(i.end(),n()):n()}))},d.prototype.end=function(t,e,i){return"function"==typeof t?this.end(null,null,t):"function"==typeof e?this.end(t,null,e):(this._ended=!0,t&&this.write(t),this._writableState.ending||this._writableState.destroyed||this.write(c),r.Writable.prototype.end.call(this,i))},e.exports=d}).call(this)}).call(this,t("_process"),t("buffer").Buffer)},{_process:50,buffer:17,"end-of-stream":21,inherits:24,"readable-stream":69,"stream-shift":74}],21:[function(t,e,i){(function(i){(function(){var n=t("once"),r=function(){},o=function(t,e,s){if("function"==typeof e)return o(t,null,e);e||(e={}),s=n(s||r);var a=t._writableState,c=t._readableState,l=e.readable||!1!==e.readable&&t.readable,h=e.writable||!1!==e.writable&&t.writable,u=!1,d=function(){t.writable||f()},f=function(){h=!1,l||s.call(t)},p=function(){l=!1,h||s.call(t)},v=function(e){s.call(t,e?new Error("exited with error code: "+e):null)},g=function(e){s.call(t,e)},y=function(){i.nextTick(m)},m=function(){if(!u)return(!l||c&&c.ended&&!c.destroyed)&&(!h||a&&a.ended&&!a.destroyed)?void 0:s.call(t,new Error("premature close"))},w=function(){t.req.on("finish",f)};return function(t){return t.setHeader&&"function"==typeof t.abort}(t)?(t.on("complete",f),t.on("abort",y),t.req?w():t.on("request",w)):h&&!a&&(t.on("end",d),t.on("close",d)),function(t){return t.stdio&&Array.isArray(t.stdio)&&3===t.stdio.length}(t)&&t.on("exit",v),t.on("end",p),t.on("finish",f),!1!==e.error&&t.on("error",g),t.on("close",y),function(){u=!0,t.removeListener("complete",f),t.removeListener("abort",y),t.removeListener("request",w),t.req&&t.req.removeListener("finish",f),t.removeListener("end",d),t.removeListener("close",d),t.removeListener("finish",f),t.removeListener("exit",v),t.removeListener("end",p),t.removeListener("error",g),t.removeListener("close",y)}};e.exports=o}).call(this)}).call(this,t("_process"))},{_process:50,once:48}],22:[function(t,e,i){var n=Object.create||function(t){var e=function(){};return e.prototype=t,new e},r=Object.keys||function(t){var e=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.push(i);return i},o=Function.prototype.bind||function(t){var e=this;return function(){return e.apply(t,arguments)}};function s(){this._events&&Object.prototype.hasOwnProperty.call(this,"_events")||(this._events=n(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0}e.exports=s,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._maxListeners=void 0;var a,c=10;try{var l={};Object.defineProperty&&Object.defineProperty(l,"x",{value:0}),a=0===l.x}catch(t){a=!1}function h(t){return void 0===t._maxListeners?s.defaultMaxListeners:t._maxListeners}function u(t,e,i,r){var o,s,a;if("function"!=typeof i)throw new TypeError('"listener" argument must be a function');if((s=t._events)?(s.newListener&&(t.emit("newListener",e,i.listener?i.listener:i),s=t._events),a=s[e]):(s=t._events=n(null),t._eventsCount=0),a){if("function"==typeof a?a=s[e]=r?[i,a]:[a,i]:r?a.unshift(i):a.push(i),!a.warned&&(o=h(t))&&o>0&&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;e<t.length;++e)t[e]=arguments[e];this.listener.apply(this.target,t)}}function f(t,e,i){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:i},r=o.call(d,n);return r.listener=i,n.wrapFn=r,r}function p(t,e,i){var n=t._events;if(!n)return[];var r=n[e];return r?"function"==typeof r?i?[r.listener||r]:[r]:i?function(t){for(var e=new Array(t.length),i=0;i<e.length;++i)e[i]=t[i].listener||t[i];return e}(r):g(r,r.length):[]}function v(t){var e=this._events;if(e){var i=e[t];if("function"==typeof i)return 1;if(i)return i.length}return 0}function g(t,e){for(var i=new Array(e),n=0;n<e;++n)i[n]=t[n];return i}a?Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(t){if("number"!=typeof t||t<0||t!=t)throw new TypeError('"defaultMaxListeners" must be a positive number');c=t}}):s.defaultMaxListeners=c,s.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||isNaN(t))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=t,this},s.prototype.getMaxListeners=function(){return h(this)},s.prototype.emit=function(t){var e,i,n,r,o,s,a="error"===t;if(s=this._events)a=a&&null==s.error;else if(!a)return!1;if(a){if(arguments.length>1&&(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<n;++o)r[o].call(i)}(i,l,this);break;case 2:!function(t,e,i,n){if(e)t.call(i,n);else for(var r=t.length,o=g(t,r),s=0;s<r;++s)o[s].call(i,n)}(i,l,this,arguments[1]);break;case 3:!function(t,e,i,n,r){if(e)t.call(i,n,r);else for(var o=t.length,s=g(t,o),a=0;a<o;++a)s[a].call(i,n,r)}(i,l,this,arguments[1],arguments[2]);break;case 4:!function(t,e,i,n,r,o){if(e)t.call(i,n,r,o);else for(var s=t.length,a=g(t,s),c=0;c<s;++c)a[c].call(i,n,r,o)}(i,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(r=new Array(n-1),o=1;o<n;o++)r[o-1]=arguments[o];!function(t,e,i,n){if(e)t.apply(i,n);else for(var r=t.length,o=g(t,r),s=0;s<r;++s)o[s].apply(i,n)}(i,l,this,r)}return!0},s.prototype.addListener=function(t,e){return u(this,t,e,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(t,e){return u(this,t,e,!0)},s.prototype.once=function(t,e){if("function"!=typeof e)throw new TypeError('"listener" argument must be a function');return this.on(t,f(this,t,e)),this},s.prototype.prependOnceListener=function(t,e){if("function"!=typeof e)throw new TypeError('"listener" argument must be a function');return this.prependListener(t,f(this,t,e)),this},s.prototype.removeListener=function(t,e){var i,r,o,s,a;if("function"!=typeof e)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(i=r[t]))return this;if(i===e||i.listener===e)0==--this._eventsCount?this._events=n(null):(delete r[t],r.removeListener&&this.emit("removeListener",t,i.listener||e));else if("function"!=typeof i){for(o=-1,s=i.length-1;s>=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<r;i+=1,n+=1)t[i]=t[n];t.pop()}(i,o),1===i.length&&(r[t]=i[0]),r.removeListener&&this.emit("removeListener",t,a||e)}return this},s.prototype.removeAllListeners=function(t){var e,i,o;if(!(i=this._events))return this;if(!i.removeListener)return 0===arguments.length?(this._events=n(null),this._eventsCount=0):i[t]&&(0==--this._eventsCount?this._events=n(null):delete i[t]),this;if(0===arguments.length){var s,a=r(i);for(o=0;o<a.length;++o)"removeListener"!==(s=a[o])&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=n(null),this._eventsCount=0,this}if("function"==typeof(e=i[t]))this.removeListener(t,e);else if(e)for(o=e.length-1;o>=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<<a)-1,l=c>>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<<l)-1,u=h>>1,d=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:o-1,p=n?1:-1,v=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<<r|a,l+=r;l>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]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}};function r(t){var e=this;void 0===t&&(t=[]);var i=[],o=0,s=0,a=0,c=0,l=0,h=0;this.size=function(){return h},this.empty=function(){return 0===h},this.clear=function(){o=a=s=c=l=h=0,d.call(this,r.bucketSize),h=0},this.front=function(){return i[o][s]},this.back=function(){return i[a][c]},this.forEach=function(t){if(!this.empty()){var e=0;if(o!==a){for(l=s;l<r.bucketSize;++l)t(i[o][l],e++);for(l=o+1;l<a;++l)for(var n=0;n<r.bucketSize;++n)t(i[l][n],e++);for(l=0;l<=c;++l)t(i[a][l],e++)}else for(var l=s;l<=c;++l)t(i[o][l],e++)}};var u=function(t){var e=o*r.bucketSize+s,i=e+t,n=a*r.bucketSize+c;if(i<e||i>n)throw new Error("pos should more than 0 and less than queue's size");return{curNodeBucketIndex:Math.floor(i/r.bucketSize),curNodePointerIndex:i%r.bucketSize}};this.getElementByPos=function(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;n<h;++n)i.push(this.getElementByPos(n));this.cut(t),this.popBack(),i.forEach((function(t){return e.pushBack(t)}))}},this.eraseElementByValue=function(t){if(!this.empty()){var e=[];this.forEach((function(i){i!==t&&e.push(i)}));for(var i=e.length,n=0;n<i;++n)this.setElementByPos(n,e[n]);this.cut(i-1)}};var d=function(t){for(var e=[],n=t*r.sigma,u=Math.max(Math.ceil(n/r.bucketSize),2),d=0;d<u;++d)e.push(new Array(r.bucketSize));var f=Math.ceil(t/r.bucketSize),p=Math.floor(u/2)-Math.floor(f/2),v=p,g=0;if(this.size())for(d=0;d<f;++d){for(var y=0;y<r.bucketSize;++y)if(e[p+d][y]=this.front(),this.popFront(),this.empty()){v=p+d,g=y;break}if(this.empty())break}i=e,o=p,s=0,a=v,c=g,l=u,h=t};this.pushBack=function(t){this.empty()||(a===l-1&&c===r.bucketSize-1&&d.call(this,this.size()),c<r.bucketSize-1?++c:a<l-1&&(++a,c=0)),++h,i[a][c]=t},this.popBack=function(){this.empty()||(1!==this.size()&&(c>0?--c:o<a&&(--a,c=r.bucketSize-1)),h>0&&--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;o<h;++o)r.push(this.getElementByPos(o));for(this.cut(t-1),o=0;o<i;++o)this.pushBack(e);r.forEach((function(t){return n.pushBack(t)}))}},this.find=function(t){if(o===a){for(var e=s;e<=c;++e)if(i[o][e]===t)return!0;return!1}for(e=s;e<r.bucketSize;++e)if(i[o][e]===t)return!0;for(e=o+1;e<a;++e)for(var n=0;n<r.bucketSize;++n)if(i[e][n]===t)return!0;for(e=0;e<=c;++e)if(i[a][e]===t)return!0;return!1},this.reverse=function(){for(var t=0,e=h-1;t<e;){var i=this.getElementByPos(t);this.setElementByPos(t,this.getElementByPos(e)),this.setElementByPos(e,i),++t,--e}},this.unique=function(){if(!this.empty()){var t=[],e=this.front();this.forEach((function(i,n){0!==n&&i===e||(t.push(i),e=i)}));for(var i=0;i<h;++i)this.setElementByPos(i,t[i]);this.cut(t.length-1)}},this.sort=function(t){var e=[];this.forEach((function(t){e.push(t)})),e.sort(t);for(var i=0;i<h;++i)this.setElementByPos(i,e[i])},this.pushFront=function(t){this.empty()||(0===o&&0===s&&d.call(this,this.size()),s>0?--s:o>0&&(--o,s=r.bucketSize-1)),++h,i[o][s]=t},this.popFront=function(){this.empty()||(1!==this.size()&&(s<r.bucketSize-1?++s:o<a&&(++o,s=0)),h>0&&--h)},this.shrinkToFit=function(){var 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;s<o;++s)i.push(new Array(r.bucketSize));this.clear(),e.forEach((function(e){return t.pushBack(e)}))},this.cut=function(t){if(t<0)this.clear();else{var e=u(t),i=e.curNodeBucketIndex,n=e.curNodePointerIndex;a=i,c=n,h=t+1}},this[Symbol.iterator]=function(){return function(){var t,e;return n(this,(function(n){switch(n.label){case 0:if(0===h)return[2];if(o!==a)return[3,5];e=s,n.label=1;case 1:return e<=c?[4,i[o][e]]:[3,4];case 2:n.sent(),n.label=3;case 3:return++e,[3,1];case 4:return[2];case 5:e=s,n.label=6;case 6:return e<r.bucketSize?[4,i[o][e]]:[3,9];case 7:n.sent(),n.label=8;case 8:return++e,[3,6];case 9:e=o+1,n.label=10;case 10:if(!(e<a))return[3,15];t=0,n.label=11;case 11:return t<r.bucketSize?[4,i[e][t]]:[3,14];case 12:n.sent(),n.label=13;case 13:return++t,[3,11];case 14:return++e,[3,10];case 15:e=0,n.label=16;case 16:return e<=c?[4,i[a][e]]:[3,19];case 17:n.sent(),n.label=18;case 18:return++e,[3,16];case 19:return[2]}}))}()},function(){var n=r.bucketSize;t.size?n=t.size():t.length&&(n=t.length);var s=n*r.sigma;l=Math.ceil(s/r.bucketSize),l=Math.max(l,3);for(var c=0;c<l;++c)i.push(new Array(r.bucketSize));var h=Math.ceil(n/r.bucketSize);o=Math.floor(l/2)-Math.floor(h/2),a=o,t.forEach((function(t){return e.pushBack(t)}))}(),Object.freeze(this)}Object.defineProperty(i,"__esModule",{value:!0}),r.sigma=3,r.bucketSize=5e3,Object.freeze(r),i.default=r},{}],27:[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]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},r=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],n=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=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];for(;t<u&&!h[t];)++t;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]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},r=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],n=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=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<i.length;n++)e=(e<<5)-e+i.charCodeAt(n),e&=e}return e^e>>>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];for(;t<u&&!h[t];)++t;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]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}};Object.defineProperty(i,"__esModule",{value:!0});var r=function(t){this.value=void 0,this.pre=void 0,this.next=void 0,this.value=t};function o(t){var e=this;void 0===t&&(t=[]);var i=0,o=void 0,s=void 0;this.size=function(){return i},this.empty=function(){return 0===i},this.clear=function(){o=s=void 0,i=0},this.front=function(){return null==o?void 0:o.value},this.back=function(){return null==s?void 0:s.value},this.forEach=function(t){for(var e=o,i=0;e;){if(void 0===e.value)throw new Error("unknown error");t(e.value,i++),e=e.next}},this.getElementByPos=function(t){if(t<0||t>=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;a<t;++a){if(!(null==s?void 0:s.next))throw new Error("unknown error");s=null==s?void 0:s.next}if(!s)throw new Error("unknown error");var c=s.next;for(i+=n;n--;)s.next=new r(e),s.next.pre=s,s=s.next;s.next=c,c&&(c.pre=s)}},this.find=function(t){for(var e=o;e;){if(e.value===t)return!0;e=e.next}return!1},this.reverse=function(){for(var t=o,e=s,n=0;t&&e&&2*n<i;){var r=t.value;t.value=e.value,e.value=r,t=t.next,e=e.pre,++n}},this.unique=function(){for(var t=o;t;){for(var e=t;e&&e.next&&e.value===e.next.value;)e=e.next,i>0&&--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]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},r=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],n=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=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 t<e?-1:t>e?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<e?1:0};var i=[];t.forEach((function(t){return i.push(t)}));var n=i.length,r=function(t,e){if(t<0||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;o<n&&e(i[t],i[o])>0&&r(t,o),s<n&&e(i[t],i[s])>0&&r(t,s)};!function(){for(var t=Math.floor((n-1)/2);t>=0;--t)for(var o=t,s=2*o+1;s<n;){var a=s+1,c=s;if(a<n&&e(i[s],i[a])>0&&(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();){var o=2*r+1,s=2*r+2;if(o>=this.size())break;var a=o;if(s<this.size()&&e(i[o],i[s])>0&&(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]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},r=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],n=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=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 t<e?-1:t>e?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]<r[3])){s.label=o[1];break}if(6===o[0]&&s.label<r[1]){s.label=r[1],r=o;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(o);break}r[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],n=0}finally{i=r=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},r=this&&this.__read||function(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var n,r,o=i.call(t),s=[];try{for(;(void 0===e||e-- >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<o;r++)!n&&r in e||(n||(n=Array.prototype.slice.call(e,0,r)),n[r]=e[r]);return t.concat(n||Array.prototype.slice.call(e))},s=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],n=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=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;e<i-1;++e)a[e]=a[e+1];this.popBack()},this.eraseElementByValue=function(t){var e=[];this.forEach((function(i){i!==t&&e.push(i)})),e.forEach((function(t,e){a[e]=t}));for(var n=e.length;i>n;)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<<i.CMD_SHIFT]),i.USERNAME_MASK=128,i.PASSWORD_MASK=64,i.WILL_RETAIN_MASK=32,i.WILL_QOS_MASK=24,i.WILL_QOS_SHIFT=3,i.WILL_FLAG_MASK=4,i.CLEAN_SESSION_MASK=2,i.CONNECT_HEADER=t.from([i.codes.connect<<i.CMD_SHIFT]),i.properties={sessionExpiryInterval:17,willDelayInterval:24,receiveMaximum:33,maximumPacketSize:39,topicAliasMaximum:34,requestResponseInformation:25,requestProblemInformation:23,userProperties:38,authenticationMethod:21,authenticationData:22,payloadFormatIndicator:1,messageExpiryInterval:2,contentType:3,responseTopic:8,correlationData:9,maximumQoS:36,retainAvailable:37,assignedClientIdentifier:18,reasonString:31,wildcardSubscriptionAvailable:40,subscriptionIdentifiersAvailable:41,sharedSubscriptionAvailable:42,serverKeepAlive:19,responseInformation:26,serverReference:28,topicAlias:35,subscriptionIdentifier:11},i.propertiesCodes={};for(const t in i.properties){const e=i.properties[t];i.propertiesCodes[e]=t}function n(e){return[0,1,2].map((n=>[0,1].map((r=>[0,1].map((o=>{const s=t.alloc(1);return s.writeUInt8(i.codes[e]<<i.CMD_SHIFT|(r?i.DUP_MASK:0)|n<<i.QOS_SHIFT|o,0,!0),s}))))))}i.propertiesTypes={sessionExpiryInterval:"int32",willDelayInterval:"int32",receiveMaximum:"int16",maximumPacketSize:"int32",topicAliasMaximum:"int16",requestResponseInformation:"byte",requestProblemInformation:"byte",userProperties:"pair",authenticationMethod:"string",authenticationData:"binary",payloadFormatIndicator:"byte",messageExpiryInterval:"int32",contentType:"string",responseTopic:"string",correlationData:"binary",maximumQoS:"int8",retainAvailable:"byte",assignedClientIdentifier:"string",reasonString:"string",wildcardSubscriptionAvailable:"byte",subscriptionIdentifiersAvailable:"byte",sharedSubscriptionAvailable:"byte",serverKeepAlive:"int16",responseInformation:"string",serverReference:"string",topicAlias:"int16",subscriptionIdentifier:"var"},i.PUBLISH_HEADER=n("publish"),i.SUBSCRIBE_HEADER=n("subscribe"),i.SUBSCRIBE_OPTIONS_QOS_MASK=3,i.SUBSCRIBE_OPTIONS_NL_MASK=1,i.SUBSCRIBE_OPTIONS_NL_SHIFT=2,i.SUBSCRIBE_OPTIONS_RAP_MASK=1,i.SUBSCRIBE_OPTIONS_RAP_SHIFT=3,i.SUBSCRIBE_OPTIONS_RH_MASK=3,i.SUBSCRIBE_OPTIONS_RH_SHIFT=4,i.SUBSCRIBE_OPTIONS_RH=[0,16,32],i.SUBSCRIBE_OPTIONS_NL=4,i.SUBSCRIBE_OPTIONS_RAP=8,i.SUBSCRIBE_OPTIONS_QOS=[0,1,2],i.UNSUBSCRIBE_HEADER=n("unsubscribe"),i.ACKS={unsuback:n("unsuback"),puback:n("puback"),pubcomp:n("pubcomp"),pubrel:n("pubrel"),pubrec:n("pubrec")},i.SUBACK_HEADER=t.from([i.codes.suback<<i.CMD_SHIFT]),i.VERSION3=t.from([3]),i.VERSION4=t.from([4]),i.VERSION5=t.from([5]),i.VERSION131=t.from([131]),i.VERSION132=t.from([132]),i.QOS=[0,1,2].map((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<n.length&&void 0!==n[r];r++)"string"!=typeof n[r]?e[r]=n[r].length:e[r]=i.byteLength(n[r]),t+=e[r];const s=i.allocUnsafe(t);for(r=0;r<n.length&&void 0!==n[r];r++)"string"!=typeof n[r]?(n[r].copy(s,o),o+=e[r]):(s.write(n[r],o),o+=e[r]);return s}}e.exports=function(t,e){const i=new o;return n(t,i,e),i.concat()}}).call(this)}).call(this,t("buffer").Buffer)},{"./writeToStream":44,buffer:17,events:22}],40:[function(t,e,i){i.parser=t("./parser").parser,i.generate=t("./generate"),i.writeToStream=t("./writeToStream")},{"./generate":39,"./parser":43,"./writeToStream":44}],41:[function(t,e,i){(function(t){(function(){const i={},n=t.isBuffer(t.from([1,2]).subarray(0,1));function r(e){const i=t.allocUnsafe(2);return i.writeUInt8(e>>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;){if(null===(e=this._parseString()))return this._emitError(new Error("Cannot parse topic"));if(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._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseUnsubscribe(){a("_parseUnsubscribe");const t=this.packet;if(t.unsubscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}for(;this._pos<t.length;){const e=this._parseString();if(null===e)return this._emitError(new Error("Cannot parse topic"));a("_parseUnsubscribe: push topic `%s` to unsubscriptions",e),t.unsubscriptions.push(e)}}}_parseUnsuback(){a("_parseUnsuback");const t=this.packet;if(!this._parseMessageId())return this._emitError(new Error("Cannot parse messageId"));if(5===this.settings.protocolVersion){const e=this._parseProperties();for(Object.getOwnPropertyNames(e).length&&(t.properties=e),t.granted=[];this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseConfirmation(){a("_parseConfirmation: packet.cmd: `%s`",this.packet.cmd);const t=this.packet;if(this._parseMessageId(),5===this.settings.protocolVersion&&(t.length>2?(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<this._list.length;){if(r+=n*((e=this._list.readUInt8(c+i++))&s.VARBYTEINT_MASK),n*=128,0==(e&s.VARBYTEINT_FIN_MASK)){o=!0;break}if(this._list.length<=i)break}return!o&&4===i&&this._list.length>=i&&this._emitError(new Error("Invalid variable byte integer")),c&&(this._pos+=i),a("_parseVarByteNum: result: %o",o=!!o&&(t?{bytes:i,value:r}:r)),o}_parseByte(){let t;return this._pos<this._list.length&&(t=this._list.readUInt8(this._pos),this._pos++),a("_parseByte: result: %o",t),t}_parseByType(t){switch(a("_parseByType: type: %s",t),t){case"byte":return 0!==this._parseByte();case"int8":return this._parseByte();case"int16":return this._parseNum();case"int32":return this._parse4ByteNum();case"var":return this._parseVarByteNum();case"string":return this._parseString();case"pair":return this._parseStringPair();case"binary":return this._parseBuffer()}}_parseProperties(){a("_parseProperties");const t=this._parseVarByteNum(),e=this._pos+t,i={};for(;this._pos<e;){const t=this._parseByte();if(!t)return this._emitError(new Error("Cannot parse property code type")),!1;const e=s.propertiesCodes[t];if(!e)return this._emitError(new Error("Unknown property")),!1;if("userProperties"!==e)i[e]?(Array.isArray(i[e])||(i[e]=[i[e]]),i[e].push(this._parseByType(s.propertiesTypes[e]))):i[e]=this._parseByType(s.propertiesTypes[e]);else{i[e]||(i[e]=Object.create(null));const t=this._parseByType(s.propertiesTypes[e]);if(i[e][t.name])if(Array.isArray(i[e][t.name]))i[e][t.name].push(t.value);else{const n=i[e][t.name];i[e][t.name]=[n],i[e][t.name].push(t.value)}else i[e][t.name]=t.value}}return i}_newPacket(){return a("_newPacket"),this.packet&&(this._list.consume(this.packet.length),a("_newPacket: parser emit packet: packet.cmd: %s, packet.payload: %s, packet.length: %d",this.packet.cmd,this.packet.payload,this.packet.length),this.emit("packet",this.packet)),a("_newPacket: new packet"),this.packet=new o,this._pos=0,!0}_emitError(t){a("_emitError"),this.error=t,this.emit("error",t)}}e.exports=c},{"./constants":38,"./packet":42,bl:15,debug:18,events:22}],44:[function(t,e,i){(function(i){(function(){const n=t("./constants"),r=i.allocUnsafe(0),o=i.from([0]),s=t("./numbers"),a=t("process-nextick-args").nextTick,c=t("debug")("mqtt-packet:writeToStream"),l=s.cache,h=s.generateNumber,u=s.generateCache,d=s.genBufVariableByteInt,f=s.generate4ByteBuffer;let p=k,v=!0;function g(t,e,s){switch(c("generate called"),e.cork&&(e.cork(),a(y,e)),v&&(v=!1,u()),c("generate: packet.cmd: %s",t.cmd),t.cmd){case"connect":return function(t,e,r){const o=t||{},s=o.protocolId||"MQTT";let a=o.protocolVersion||4;const c=o.will;let l=o.clean;const h=o.keepalive||0,u=o.clientId||"",d=o.username,f=o.password,v=o.properties;void 0===l&&(l=!0);let g=0;if(!s||"string"!=typeof s&&!i.isBuffer(s))return e.emit("error",new Error("Invalid protocolId")),!1;if(g+=s.length+2,3!==a&&4!==a&&5!==a)return e.emit("error",new Error("Invalid protocol version")),!1;if(g+=1,("string"==typeof u||i.isBuffer(u))&&(u||a>=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<<n.WILL_QOS_SHIFT:0,k|=c?n.WILL_FLAG_MASK:0,k|=l?n.CLEAN_SESSION_MASK:0,e.write(i.from([k])),p(e,h),5===a&&y.write(),A(e,u),c&&(5===a&&m.write(),b(e,c.topic),A(e,c.payload)),null!=d&&A(e,d),null!=f&&A(e,f),!0}(t,e);case"connack":return function(t,e,r){const s=r?r.protocolVersion:4,a=t||{},c=5===s?a.reasonCode:a.returnCode,l=a.properties;let h=2;if("number"!=typeof c)return e.emit("error",new Error("Invalid return code")),!1;let u=null;if(5===s){if(!(u=S(e,l)))return!1;h+=u.length}return e.write(n.CONNACK_HEADER),w(e,h),e.write(a.sessionPresent?n.SESSIONPRESENT_HEADER:o),e.write(i.from([c])),null!=u&&u.write(),!0}(t,e,s);case"publish":return function(t,e,o){c("publish: packet: %o",t);const s=o?o.protocolVersion:4,a=t||{},l=a.qos||0,h=a.retain?n.RETAIN_MASK:0,u=a.topic,d=a.payload||r,f=a.messageId,v=a.properties;let g=0;if("string"==typeof u)g+=i.byteLength(u)+2;else{if(!i.isBuffer(u))return e.emit("error",new Error("Invalid topic")),!1;g+=u.length+2}if(i.isBuffer(d)?g+=d.length:g+=i.byteLength(d),l&&"number"!=typeof f)return e.emit("error",new Error("Invalid messageId")),!1;l&&(g+=2);let y=null;if(5===s){if(!(y=S(e,v)))return!1;g+=y.length}return e.write(n.PUBLISH_HEADER[l][a.dup?1:0][h?1:0]),w(e,g),p(e,_(u)),e.write(u),l>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;t<h.length;t+=1){const n=h[t].topic,r=h[t].qos;if("string"!=typeof n)return e.emit("error",new Error("Invalid subscriptions - invalid topic")),!1;if("number"!=typeof r)return e.emit("error",new Error("Invalid subscriptions - invalid qos")),!1;if(5===o){if("boolean"!=typeof(h[t].nl||!1))return e.emit("error",new Error("Invalid subscriptions - invalid No Local")),!1;if("boolean"!=typeof(h[t].rap||!1))return e.emit("error",new Error("Invalid subscriptions - invalid Retain as Published")),!1;const i=h[t].rh||0;if("number"!=typeof i||i>2)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;t<c.length;t+=1){if("number"!=typeof c[t])return e.emit("error",new Error("Invalid qos vector")),!1;h+=1}let u=null;if(5===o){if(!(u=P(e,l,r,h)))return!1;h+=u.length}return e.write(n.SUBACK_HEADER),w(e,h),p(e,a),null!==u&&u.write(),e.write(i.from(c))}(t,e,s);case"unsubscribe":return function(t,e,r){const o=r?r.protocolVersion:4,s=t||{},a=s.messageId,c=s.dup?n.DUP_MASK:0,l=s.unsubscriptions,h=s.properties;let u=0;if("number"!=typeof a)return e.emit("error",new Error("Invalid messageId")),!1;if(u+=2,"object"!=typeof l||!l.length)return e.emit("error",new Error("Invalid unsubscriptions")),!1;for(let t=0;t<l.length;t+=1){if("string"!=typeof l[t])return e.emit("error",new Error("Invalid unsubscriptions")),!1;u+=i.byteLength(l[t])+2}let d=null;if(5===o){if(!(d=S(e,h)))return!1;u+=d.length}e.write(n.UNSUBSCRIBE_HEADER[1][c?1:0][0]),w(e,u),p(e,a),null!==d&&d.write();let f=!0;for(let t=0;t<l.length;t++)f=b(e,l[t]);return f}(t,e,s);case"unsuback":return function(t,e,r){const o=r?r.protocolVersion:4,s=t||{},a=s.messageId,c=s.dup?n.DUP_MASK:0,l=s.granted,h=s.properties,u=s.cmd;let d=2;if("number"!=typeof a)return e.emit("error",new Error("Invalid messageId")),!1;if(5===o){if("object"!=typeof l||!l.length)return e.emit("error",new Error("Invalid qos vector")),!1;for(let t=0;t<l.length;t+=1){if("number"!=typeof l[t])return e.emit("error",new Error("Invalid qos vector")),!1;d+=1}}let f=null;if(5===o){if(!(f=P(e,h,r,d)))return!1;d+=f.length}return e.write(n.ACKS[u][0][c][0]),w(e,d),p(e,a),null!==f&&f.write(),5===o&&e.write(i.from(l)),!0}(t,e,s);case"pingreq":case"pingresp":return function(t,e,i){return e.write(n.EMPTY[t.cmd])}(t,e);case"disconnect":return function(t,e,r){const o=r?r.protocolVersion:4,s=t||{},a=s.reasonCode,c=s.properties;let l=5===o?1:0,h=null;if(5===o){if(!(h=P(e,c,r,l)))return!1;l+=h.length}return e.write(i.from([n.codes.disconnect<<4])),w(e,l),5===o&&e.write(i.from([a])),null!==h&&h.write(),!0}(t,e,s);case"auth":return function(t,e,r){const o=r?r.protocolVersion:4,s=t||{},a=s.reasonCode,c=s.properties;let l=5===o?1:0;5!==o&&e.emit("error",new Error("Invalid mqtt version for auth packet"));const h=P(e,c,r,l);return!!h&&(l+=h.length,e.write(i.from([n.codes.auth<<4])),w(e,l),e.write(i.from([a])),null!==h&&h.write(),!0)}(t,e,s);default:return e.emit("error",new Error("Unknown command")),!1}}function y(t){t.uncork()}Object.defineProperty(g,"cacheNumbers",{get:()=>p===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;e<s.length;e++){if(!(n=o(t,s[e])))return!1;i+=n}else{if(!(n=o(t,s)))return!1;i=n}if(!i)return!1;r+=i}return{length:i.byteLength(d(r))+r,write(){R(t,e,r)}}}function P(t,e,i,n){const r=["reasonString","userProperties"],o=i&&i.properties&&i.properties.maximumPacketSize?i.properties.maximumPacketSize:0;let s=S(t,e);if(o)for(;n+s.length>o;){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<n.length;e++)C(t,i,n[e]);else C(t,i,n)}}function _(t){return t?t instanceof i?t.length:i.byteLength(t):0}function E(t){return"string"==typeof t||t instanceof i}e.exports=g}).call(this)}).call(this,t("buffer").Buffer)},{"./constants":38,"./numbers":41,buffer:17,debug:18,"process-nextick-args":49}],45:[function(t,e,i){var n=1e3,r=60*n,o=60*r,s=24*o;function a(t,e,i,n){var r=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.low<t.low&&this.high<t.low?-1:t.low<this.low&&t.high<this.low?1:0},a.prototype.firstVacant=function(){return 0===this.ss.size()?null:this.ss.front().low},a.prototype.alloc=function(){if(0===this.ss.size())return r("alloc():empty"),null;const t=this.ss.front(),e=t.low;return e+1<=t.high?++t.low:this.ss.eraseElementByPos(0),r("alloc():"+e),e},a.prototype.use=function(t){const e=new s(t,t),i=this.ss.lowerBound(e);if(i){if(i.equals(e))return this.ss.eraseElementByValue(i),r("use():"+t),!0;if(i.low>t)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(t<this.min||t>this.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;s<o.length;)o[s++]=arguments[s];return t.nextTick((function(){e.apply(null,o)}))}}}:e.exports=t}).call(this)}).call(this,t("_process"))},{_process:50}],50:[function(t,e,i){var n,r,o=e.exports={};function s(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function c(t){if(n===setTimeout)return setTimeout(t,0);if((n===s||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:s}catch(t){n=s}try{r="function"==typeof clearTimeout?clearTimeout:a}catch(t){r=a}}();var l,h=[],u=!1,d=-1;function f(){u&&l&&(u=!1,l.length?h=l.concat(h):d=-1,h.length&&p())}function p(){if(!u){var t=c(f);u=!0;for(var e=h.length;e;){for(l=h,h=[];++d<e;)l&&l[d].run();d=-1,e=h.length}l=null,u=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===a||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.call(this,t)}}}(t)}}function v(t,e){this.fun=t,this.array=e}function g(){}o.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var i=1;i<arguments.length;i++)e[i-1]=arguments[i];h.push(new v(t,e)),1!==h.length||u||c(p)},v.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=g,o.addListener=g,o.once=g,o.off=g,o.removeListener=g,o.removeAllListeners=g,o.emit=g,o.prependListener=g,o.prependOnceListener=g,o.listeners=function(t){return[]},o.binding=function(t){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(t){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},{}],51:[function(t,e,n){(function(t){(function(){!function(i){var r="object"==typeof n&&n&&!n.nodeType&&n,o="object"==typeof e&&e&&!e.nodeType&&e,s="object"==typeof t&&t;s.global!==s&&s.window!==s&&s.self!==s||(i=s);var a,c,l=2147483647,h=36,u=26,d=38,f=700,p=/^xn--/,v=/[^\x20-\x7E]/,g=/[\x2E\u3002\uFF0E\uFF61]/g,y={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 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<o;)(e=t.charCodeAt(r++))>=55296&&e<=56319&&r<o?56320==(64512&(i=t.charCodeAt(r++)))?n.push(((1023&e)<<10)+(1023&i)+65536):(n.push(e),r--):n.push(e);return n}function S(t){return k(t,(function(t){var e="";return t>65535&&(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<i;++n)t.charCodeAt(n)>=128&&x("not-basic"),v.push(t.charCodeAt(n));for(r=i>0?i+1:0;r<g;){for(o=y,s=1,a=h;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<v;++s)(p=t[s])<128&&k.push(b(p));for(n=r=k.length,r&&k.push("-");n<v;){for(a=l,s=0;s<v;++s)(p=t[s])>=e&&p<a&&(a=p);for(a-e>w((l-i)/(g=n+1))&&x("overflow"),i+=(a-e)*g,e=a,s=0;s<v;++s)if((p=t[s])<e&&++i>l&&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<l;++h){var u,d,f,p,v=t[h].replace(a,"%20"),g=v.indexOf(i);g>=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;n<t.length;n++)i.push(e(t[n],n));return i}var s=Object.keys||function(t){var e=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.push(i);return e}},{}],54:[function(t,e,i){"use strict";i.decode=i.parse=t("./decode"),i.encode=i.stringify=t("./encode")},{"./decode":52,"./encode":53}],55:[function(t,e,i){"use strict";var n={};function r(t,e,i){i||(i=Error);var r=function(t){var i,n;function r(i,n,r){return t.call(this,function(t,i,n){return"string"==typeof e?e:e(t,i,n)}(i,n,r))||this}return n=t,(i=r).prototype=Object.create(n.prototype),i.prototype.constructor=i,i.__proto__=n,r}(i);r.prototype.name=i.name,r.prototype.code=t,n[t]=r}function o(t,e){if(Array.isArray(t)){var i=t.length;return t=t.map((function(t){return String(t)})),i>2?"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;a<s.length;a++){var c=s[a];l.prototype[c]||(l.prototype[c]=o.prototype[c])}function l(t){if(!(this instanceof l))return new l(t);r.call(this,t),o.call(this,t),this.allowHalfOpen=!0,t&&(!1===t.readable&&(this.readable=!1),!1===t.writable&&(this.writable=!1),!1===t.allowHalfOpen&&(this.allowHalfOpen=!1,this.once("end",h)))}function h(){this._writableState.ended||i.nextTick(u,this)}function u(t){t.end()}Object.defineProperty(l.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(l.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(l.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(l.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&void 0!==this._writableState&&this._readableState.destroyed&&this._writableState.destroyed},set:function(t){void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed=t,this._writableState.destroyed=t)}})}).call(this)}).call(this,t("_process"))},{"./_stream_readable":58,"./_stream_writable":60,_process:50,inherits:24}],57:[function(t,e,i){"use strict";e.exports=r;var n=t("./_stream_transform");function r(t){if(!(this instanceof r))return new r(t);n.call(this,t)}t("inherits")(r,n),r.prototype._transform=function(t,e,i){i(null,t)}},{"./_stream_transform":59,inherits:24}],58:[function(t,e,n){(function(i,n){(function(){"use strict";var r;e.exports=S,S.ReadableState=A,t("events").EventEmitter;var o,s=function(t,e){return t.listeners(e).length},a=t("./internal/streams/stream"),c=t("buffer").Buffer,l=n.Uint8Array||function(){},h=t("util");o=h&&h.debuglog?h.debuglog("stream"):function(){};var u,d,f,p=t("./internal/streams/buffer_list"),v=t("./internal/streams/destroy"),g=t("./internal/streams/state").getHighWaterMark,y=t("../errors").codes,m=y.ERR_INVALID_ARG_TYPE,w=y.ERR_STREAM_PUSH_AFTER_EOF,b=y.ERR_METHOD_NOT_IMPLEMENTED,x=y.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;t("inherits")(S,a);var k=v.errorOrDestroy,T=["error","close","destroy","pause","resume"];function A(e,i,n){r=r||t("./_stream_duplex"),e=e||{},"boolean"!=typeof n&&(n=i instanceof r),this.objectMode=!!e.objectMode,n&&(this.objectMode=this.objectMode||!!e.readableObjectMode),this.highWaterMark=g(this,e,"readableHighWaterMark",n),this.buffer=new p,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(u||(u=t("string_decoder/").StringDecoder),this.decoder=new u(e.encoding),this.encoding=e.encoding)}function S(e){if(r=r||t("./_stream_duplex"),!(this instanceof S))return new S(e);var i=this instanceof r;this._readableState=new A(e,this,i),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),a.call(this)}function P(t,e,i,n,r){o("readableAddChunk",e);var s,a=t._readableState;if(null===e)a.reading=!1,function(t,e){if(o("onEofChunk"),!e.ended){if(e.decoder){var i=e.decoder.end();i&&i.length&&(e.buffer.push(i),e.length+=e.objectMode?1:i.length)}e.ended=!0,e.sync?E(t):(e.needReadable=!1,e.emittedReadable||(e.emittedReadable=!0,I(t)))}}(t,a);else if(r||(s=function(t,e){var i,n;return n=e,c.isBuffer(n)||n instanceof l||"string"==typeof e||void 0===e||t.objectMode||(i=new m("chunk",["string","Buffer","Uint8Array"],e)),i}(a,e)),s)k(t,s);else if(a.objectMode||e&&e.length>0)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.length<a.highWaterMark||0===a.length)}function C(t,e,i,n){e.flowing&&0===e.length&&!e.sync?(e.awaitDrain=0,t.emit("data",i)):(e.length+=e.objectMode?1:i.length,n?e.buffer.unshift(i):e.buffer.push(i),e.needReadable&&E(t)),L(t,e)}Object.defineProperty(S.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._readableState&&this._readableState.destroyed},set:function(t){this._readableState&&(this._readableState.destroyed=t)}}),S.prototype.destroy=v.destroy,S.prototype._undestroy=v.undestroy,S.prototype._destroy=function(t,e){e(t)},S.prototype.push=function(t,e){var i,n=this._readableState;return n.objectMode?i=!0:"string"==typeof t&&((e=e||n.defaultEncoding)!==n.encoding&&(t=c.from(t,e),e=""),i=!0),P(this,t,e,!1,i)},S.prototype.unshift=function(t){return P(this,t,null,!0,!1)},S.prototype.isPaused=function(){return!1===this._readableState.flowing},S.prototype.setEncoding=function(e){u||(u=t("string_decoder/").StringDecoder);var i=new u(e);this._readableState.decoder=i,this._readableState.encoding=this._readableState.decoder.encoding;for(var n=this._readableState.buffer.head,r="";null!==n;)r+=i.write(n.data),n=n.next;return this._readableState.buffer.clear(),""!==r&&this._readableState.buffer.push(r),this._readableState.length=r.length,this};var R=1073741824;function _(t,e){return t<=0||0===e.length&&e.ended?0:e.objectMode?1:t!=t?e.flowing&&e.length?e.buffer.head.data.length:e.length:(t>e.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.length<e.highWaterMark||e.flowing&&0===e.length);){var i=e.length;if(o("maybeReadMore read 0"),t.read(0),i===e.length)break}e.readingMore=!1}function D(t){var e=t._readableState;e.readableListening=t.listenerCount("readable")>0,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<n;i++)if(t[i]===e)return i;return-1}S.prototype.read=function(t){o("read",t),t=parseInt(t,10);var e=this._readableState,i=t;if(0!==t&&(e.emittedReadable=!1),0===t&&e.needReadable&&((0!==e.highWaterMark?e.length>=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-t<e.highWaterMark)&&o("length less than watermark",r=!0),e.ended||e.reading?o("reading or ended",r=!1):r&&(o("do read"),e.reading=!0,e.sync=!0,0===e.length&&(e.needReadable=!0),this._read(e.highWaterMark),e.sync=!1,e.reading||(t=_(i,e))),null===(n=t>0?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;o<r;o++)n[o].emit("unpipe",this,{hasUnpiped:!1});return this}var s=H(e.pipes,t);return-1===s||(e.pipes.splice(s,1),e.pipesCount-=1,1===e.pipesCount&&(e.pipes=e.pipes[0]),t.emit("unpipe",this,i)),this},S.prototype.on=function(t,e){var n=a.prototype.on.call(this,t,e),r=this._readableState;return"data"===t?(r.readableListening=this.listenerCount("readable")>0,!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<T.length;s++)t.on(T[s],this.emit.bind(this,T[s]));return this._read=function(e){o("wrapped _read",e),n&&(n=!1,t.resume())},this},"function"==typeof Symbol&&(S.prototype[Symbol.asyncIterator]=function(){return void 0===d&&(d=t("./internal/streams/async_iterator")),d(this)}),Object.defineProperty(S.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(S.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(S.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(t){this._readableState&&(this._readableState.flowing=t)}}),S._fromList=z,Object.defineProperty(S.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(S.from=function(e,i){return void 0===f&&(f=t("./internal/streams/from")),f(S,e,i)})}).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/async_iterator":61,"./internal/streams/buffer_list":62,"./internal/streams/destroy":63,"./internal/streams/from":65,"./internal/streams/state":67,"./internal/streams/stream":68,_process:50,buffer:17,events:22,inherits:24,"string_decoder/":75,util:16}],59:[function(t,e,i){"use strict";e.exports=l;var n=t("../errors").codes,r=n.ERR_METHOD_NOT_IMPLEMENTED,o=n.ERR_MULTIPLE_CALLBACK,s=n.ERR_TRANSFORM_ALREADY_TRANSFORMING,a=n.ERR_TRANSFORM_WITH_LENGTH_0,c=t("./_stream_duplex");function l(t){if(!(this instanceof l))return new l(t);c.call(this,t),this._transformState={afterTransform:function(t,e){var i=this._transformState;i.transforming=!1;var n=i.writecb;if(null===n)return this.emit("error",new o);i.writechunk=null,i.writecb=null,null!=e&&this.push(e),n(t);var r=this._readableState;r.reading=!1,(r.needReadable||r.length<r.highWaterMark)&&this._read(r.highWaterMark)}.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,t&&("function"==typeof t.transform&&(this._transform=t.transform),"function"==typeof t.flush&&(this._flush=t.flush)),this.on("prefinish",h)}function h(){var t=this;"function"!=typeof this._flush||this._readableState.destroyed?u(this,null,null):this._flush((function(e,i){u(t,e,i)}))}function u(t,e,i){if(e)return t.emit("error",e);if(null!=i&&t.push(i),t._writableState.length)throw new a;if(t._transformState.transforming)throw new s;return t.push(null)}t("inherits")(l,c),l.prototype.push=function(t,e){return this._transformState.needTransform=!1,c.prototype.push.call(this,t,e)},l.prototype._transform=function(t,e,i){i(new r("_transform()"))},l.prototype._write=function(t,e,i){var n=this._transformState;if(n.writecb=i,n.writechunk=t,n.writeencoding=e,!n.transforming){var r=this._readableState;(n.needTransform||r.needReadable||r.length<r.highWaterMark)&&this._read(r.highWaterMark)}},l.prototype._read=function(t){var e=this._transformState;null===e.writechunk||e.transforming?e.needTransform=!0:(e.transforming=!0,this._transform(e.writechunk,e.writeencoding,e.afterTransform))},l.prototype._destroy=function(t,e){c.prototype._destroy.call(this,t,(function(t){e(t)}))}},{"../errors":55,"./_stream_duplex":56,inherits:24}],60:[function(t,e,n){(function(i,n){(function(){"use strict";function r(t){var e=this;this.next=null,this.entry=null,this.finish=function(){!function(t,e,i){var n=t.entry;for(t.entry=null;n;){var r=n.callback;e.pendingcb--,r(undefined),n=n.next}e.corkedRequestsFree.next=t}(e,t)}}var o;e.exports=S,S.WritableState=A;var s,a={deprecate:t("util-deprecate")},c=t("./internal/streams/stream"),l=t("buffer").Buffer,h=n.Uint8Array||function(){},u=t("./internal/streams/destroy"),d=t("./internal/streams/state").getHighWaterMark,f=t("../errors").codes,p=f.ERR_INVALID_ARG_TYPE,v=f.ERR_METHOD_NOT_IMPLEMENTED,g=f.ERR_MULTIPLE_CALLBACK,y=f.ERR_STREAM_CANNOT_PIPE,m=f.ERR_STREAM_DESTROYED,w=f.ERR_STREAM_NULL_VALUES,b=f.ERR_STREAM_WRITE_AFTER_END,x=f.ERR_UNKNOWN_ENCODING,k=u.errorOrDestroy;function T(){}function A(e,n,s){o=o||t("./_stream_duplex"),e=e||{},"boolean"!=typeof s&&(s=n instanceof o),this.objectMode=!!e.objectMode,s&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=d(this,e,"writableHighWaterMark",s),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var a=!1===e.decodeStrings;this.decodeStrings=!a,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(t){!function(t,e){var n=t._writableState,r=n.sync,o=n.writecb;if("function"!=typeof o)throw new g;if(function(t){t.writing=!1,t.writecb=null,t.length-=t.writelen,t.writelen=0}(n),e)!function(t,e,n,r,o){--e.pendingcb,n?(i.nextTick(o,r),i.nextTick(I,t,e),t._writableState.errorEmitted=!0,k(t,r)):(o(r),t._writableState.errorEmitted=!0,k(t,r),I(t,e))}(t,n,r,e,o);else{var s=_(n)||t.destroyed;s||n.corked||n.bufferProcessing||!n.bufferedRequest||R(t,n),r?i.nextTick(C,t,n,s,o):C(t,n,s,o)}}(n,t)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!1!==e.emitClose,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new r(this)}function S(e){var i=this instanceof(o=o||t("./_stream_duplex"));if(!i&&!s.call(S,this))return new S(e);this._writableState=new A(e,this,i),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),c.call(this)}function P(t,e,i,n,r,o,s){e.writelen=n,e.writecb=s,e.writing=!0,e.sync=!0,e.destroyed?e.onwrite(new m("write")):i?t._writev(r,e.onwrite):t._write(r,o,e.onwrite),e.sync=!1}function C(t,e,i,n){i||function(t,e){0===e.length&&e.needDrain&&(e.needDrain=!1,t.emit("drain"))}(t,e),e.pendingcb--,n(),I(t,e)}function R(t,e){e.bufferProcessing=!0;var i=e.bufferedRequest;if(t._writev&&i&&i.next){var n=e.bufferedRequestCount,o=new Array(n),s=e.corkedRequestsFree;s.entry=i;for(var a=0,c=!0;i;)o[a]=i,i.isBuf||(c=!1),i=i.next,a+=1;o.allBuffers=c,P(t,e,!0,e.length,o,"",s.finish),e.pendingcb++,e.lastBufferedRequest=null,s.next?(e.corkedRequestsFree=s.next,s.next=null):e.corkedRequestsFree=new r(e),e.bufferedRequestCount=0}else{for(;i;){var l=i.chunk,h=i.encoding,u=i.callback;if(P(t,e,!1,e.objectMode?1:l.length,l,h,u),i=i.next,e.bufferedRequestCount--,e.writing)break}null===i&&(e.lastBufferedRequest=null)}e.bufferedRequest=i,e.bufferProcessing=!1}function _(t){return t.ending&&0===t.length&&null===t.bufferedRequest&&!t.finished&&!t.writing}function E(t,e){t._final((function(i){e.pendingcb--,i&&k(t,i),e.prefinished=!0,t.emit("prefinish"),I(t,e)}))}function I(t,e){var n=_(e);if(n&&(function(t,e){e.prefinished||e.finalCalled||("function"!=typeof t._final||e.destroyed?(e.prefinished=!0,t.emit("prefinish")):(e.pendingcb++,e.finalCalled=!0,i.nextTick(E,t,e)))}(t,e),0===e.pendingcb&&(e.finished=!0,t.emit("finish"),e.autoDestroy))){var r=t._readableState;(!r||r.autoDestroy&&r.endEmitted)&&t.destroy()}return n}t("inherits")(S,c),A.prototype.getBuffer=function(){for(var t=this.bufferedRequest,e=[];t;)e.push(t),t=t.next;return e},function(){try{Object.defineProperty(A.prototype,"buffer",{get:a.deprecate((function(){return this.getBuffer()}),"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(t){}}(),"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(s=Function.prototype[Symbol.hasInstance],Object.defineProperty(S,Symbol.hasInstance,{value:function(t){return!!s.call(this,t)||this===S&&t&&t._writableState instanceof A}})):s=function(t){return t instanceof this},S.prototype.pipe=function(){k(this,new y)},S.prototype.write=function(t,e,n){var r,o=this._writableState,s=!1,a=!o.objectMode&&(r=t,l.isBuffer(r)||r instanceof h);return a&&!l.isBuffer(t)&&(t=function(t){return l.from(t)}(t)),"function"==typeof e&&(n=e,e=null),a?e="buffer":e||(e=o.defaultEncoding),"function"!=typeof n&&(n=T),o.ending?function(t,e){var n=new b;k(t,n),i.nextTick(e,n)}(this,n):(a||function(t,e,n,r){var o;return null===n?o=new w:"string"==typeof n||e.objectMode||(o=new p("chunk",["string","Buffer"],n)),!o||(k(t,o),i.nextTick(r,o),!1)}(this,o,t,n))&&(o.pendingcb++,s=function(t,e,i,n,r,o){if(!i){var s=function(t,e,i){return t.objectMode||!1===t.decodeStrings||"string"!=typeof e||(e=l.from(e,i)),e}(e,n,r);n!==s&&(i=!0,r="buffer",n=s)}var a=e.objectMode?1:n.length;e.length+=a;var c=e.length<e.highWaterMark;if(c||(e.needDrain=!0),e.writing||e.corked){var h=e.lastBufferedRequest;e.lastBufferedRequest={chunk:n,encoding:r,isBuf:i,callback:o,next:null},h?h.next=e.lastBufferedRequest:e.bufferedRequest=e.lastBufferedRequest,e.bufferedRequestCount+=1}else P(t,e,!1,a,n,r,o);return c}(this,o,a,t,e,n)),s},S.prototype.cork=function(){this._writableState.corked++},S.prototype.uncork=function(){var t=this._writableState;t.corked&&(t.corked--,t.writing||t.corked||t.bufferProcessing||!t.bufferedRequest||R(this,t))},S.prototype.setDefaultEncoding=function(t){if("string"==typeof t&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-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;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var s=t("buffer").Buffer,a=t("util").inspect,c=a&&a.custom||"inspect";e.exports=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.head=null,this.tail=null,this.length=0}var e,i;return e=t,(i=[{key:"push",value:function(t){var e={data:t,next:null};this.length>0?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 t<this.head.data.length?(i=this.head.data.slice(0,t),this.head.data=this.head.data.slice(t)):i=t===this.head.data.length?this.shift():e?this._getString(t):this._getBuffer(t),i}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(t){var e=this.head,i=1,n=e.data;for(t-=n.length;e=e.next;){var r=e.data,o=t>r.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;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?n(Object(i),!0).forEach((function(e){r(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):n(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}({},e,{depth:0,customInspect:!1}))}}])&&o(e.prototype,i),t}()},{buffer:17,util:16}],63:[function(t,e,i){(function(t){(function(){"use strict";function i(t,e){r(t,e),n(t)}function n(t){t._writableState&&!t._writableState.emitClose||t._readableState&&!t._readableState.emitClose||t.emit("close")}function r(t,e){t.emit("error",e)}e.exports={destroy:function(e,o){var s=this,a=this._readableState&&this._readableState.destroyed,c=this._writableState&&this._writableState.destroyed;return a||c?(o?o(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,t.nextTick(r,this,e)):t.nextTick(r,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,(function(e){!o&&e?s._writableState?s._writableState.errorEmitted?t.nextTick(n,s):(s._writableState.errorEmitted=!0,t.nextTick(i,s,e)):t.nextTick(i,s,e):o?(t.nextTick(n,s),o(e)):t.nextTick(n,s)})),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)},errorOrDestroy:function(t,e){var i=t._readableState,n=t._writableState;i&&i.autoDestroy||n&&n.autoDestroy?t.destroy(e):t.emit("error",e)}}}).call(this)}).call(this,t("_process"))},{_process:50}],64:[function(t,e,i){"use strict";var n=t("../../../errors").codes.ERR_STREAM_PREMATURE_CLOSE;function r(){}e.exports=function t(e,i,o){if("function"==typeof i)return t(e,null,i);i||(i={}),o=function(t){var e=!1;return function(){if(!e){e=!0;for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];t.apply(this,n)}}}(o||r);var s=i.readable||!1!==i.readable&&e.readable,a=i.writable||!1!==i.writable&&e.writable,c=function(){e.writable||h()},l=e._writableState&&e._writableState.finished,h=function(){a=!1,l=!0,s||o.call(e)},u=e._readableState&&e._readableState.endEmitted,d=function(){s=!1,u=!0,a||o.call(e)},f=function(t){o.call(e,t)},p=function(){var t;return s&&!u?(e._readableState&&e._readableState.ended||(t=new n),o.call(e,t)):a&&!l?(e._writableState&&e._writableState.ended||(t=new n),o.call(e,t)):void 0},v=function(){e.req.on("finish",h)};return function(t){return t.setHeader&&"function"==typeof t.abort}(e)?(e.on("complete",h),e.on("abort",p),e.req?v():e.on("request",v)):a&&!e._writableState&&(e.on("end",c),e.on("close",c)),e.on("end",d),e.on("finish",h),!1!==i.error&&e.on("error",f),e.on("close",p),function(){e.removeListener("complete",h),e.removeListener("abort",p),e.removeListener("request",v),e.req&&e.req.removeListener("finish",h),e.removeListener("end",c),e.removeListener("close",c),e.removeListener("finish",h),e.removeListener("end",d),e.removeListener("error",f),e.removeListener("close",p)}}},{"../../../errors":55}],65:[function(t,e,i){e.exports=function(){throw new Error("Readable.from is not available in the browser")}},{}],66:[function(t,e,i){"use strict";var n,r=t("../../../errors").codes,o=r.ERR_MISSING_ARGS,s=r.ERR_STREAM_DESTROYED;function a(t){if(t)throw t}function c(t){t()}function l(t,e){return t.pipe(e)}e.exports=function(){for(var e=arguments.length,i=new Array(e),r=0;r<e;r++)i[r]=arguments[r];var h,u=function(t){return t.length?"function"!=typeof t[t.length-1]?a:t.pop():a}(i);if(Array.isArray(i[0])&&(i=i[0]),i.length<2)throw new o("streams");var d=i.map((function(e,r){var o=r<i.length-1;return function(e,i,r,o){o=function(t){var e=!1;return function(){e||(e=!0,t.apply(void 0,arguments))}}(o);var a=!1;e.on("close",(function(){a=!0})),void 0===n&&(n=t("./end-of-stream")),n(e,{readable:i,writable:r},(function(t){if(t)return o(t);a=!0,o()}));var c=!1;return function(t){if(!a&&!c)return c=!0,function(t){return t.setHeader&&"function"==typeof t.abort}(e)?e.abort():"function"==typeof e.destroy?e.destroy():void o(t||new s("pipe"))}}(e,o,r>0,(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<t.length;e++)t[e]=arguments[e+2]}return new function(t,e,i){var n=this;this._callback=t,this._args=i,this._interval=setInterval(t,e,this._args),this.reschedule=function(t){t||(t=n._interval),n._interval&&clearInterval(n._interval),n._interval=setInterval(n._callback,t,n._args)},this.clear=function(){n._interval&&(clearInterval(n._interval),n._interval=void 0)},this.destroy=function(){n._interval&&clearInterval(n._interval),n._callback=void 0,n._interval=void 0,n._args=void 0}}(arguments[0],arguments[1],t)}},{}],71:[function(t,e,i){"use strict";e.exports=t("./index.js")()},{"./index.js":72}],72:[function(t,e,i){(function(t){(function(){"use strict";function i(e){return e instanceof t?t.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}e.exports=function(t){return(t=t||{}).circles?function(t){var e=[],n=[];return t.proto?function t(o){if("object"!=typeof o||null===o)return o;if(o instanceof Date)return new Date(o);if(Array.isArray(o))return r(o,t);if(o instanceof Map)return new Map(r(Array.from(o),t));if(o instanceof Set)return new Set(r(Array.from(o),t));var s={};for(var a in e.push(o),n.push(s),o){var c=o[a];if("object"!=typeof c||null===c)s[a]=c;else if(c instanceof Date)s[a]=new Date(c);else if(c instanceof Map)s[a]=new Map(r(Array.from(c),t));else if(c instanceof Set)s[a]=new Set(r(Array.from(c),t));else if(ArrayBuffer.isView(c))s[a]=i(c);else{var l=e.indexOf(c);s[a]=-1!==l?n[l]:t(c)}}return e.pop(),n.pop(),s}:function t(o){if("object"!=typeof o||null===o)return o;if(o instanceof Date)return new Date(o);if(Array.isArray(o))return r(o,t);if(o instanceof Map)return new Map(r(Array.from(o),t));if(o instanceof Set)return new Set(r(Array.from(o),t));var s={};for(var a in e.push(o),n.push(s),o)if(!1!==Object.hasOwnProperty.call(o,a)){var c=o[a];if("object"!=typeof c||null===c)s[a]=c;else if(c instanceof Date)s[a]=new Date(c);else if(c instanceof Map)s[a]=new Map(r(Array.from(c),t));else if(c instanceof Set)s[a]=new Set(r(Array.from(c),t));else if(ArrayBuffer.isView(c))s[a]=i(c);else{var l=e.indexOf(c);s[a]=-1!==l?n[l]:t(c)}}return e.pop(),n.pop(),s};function r(t,r){for(var o=Object.keys(t),s=new Array(o.length),a=0;a<o.length;a++){var c=o[a],l=t[c];if("object"!=typeof l||null===l)s[c]=l;else if(l instanceof Date)s[c]=new Date(l);else if(ArrayBuffer.isView(l))s[c]=i(l);else{var h=e.indexOf(l);s[c]=-1!==h?n[h]:r(l)}}return s}}(t):t.proto?function t(n){if("object"!=typeof n||null===n)return n;if(n instanceof Date)return new Date(n);if(Array.isArray(n))return e(n,t);if(n instanceof Map)return new Map(e(Array.from(n),t));if(n instanceof Set)return new Set(e(Array.from(n),t));var r={};for(var o in n){var s=n[o];"object"!=typeof s||null===s?r[o]=s:s instanceof Date?r[o]=new Date(s):s instanceof Map?r[o]=new Map(e(Array.from(s),t)):s instanceof Set?r[o]=new Set(e(Array.from(s),t)):ArrayBuffer.isView(s)?r[o]=i(s):r[o]=t(s)}return r}:function t(n){if("object"!=typeof n||null===n)return n;if(n instanceof Date)return new Date(n);if(Array.isArray(n))return e(n,t);if(n instanceof Map)return new Map(e(Array.from(n),t));if(n instanceof Set)return new Set(e(Array.from(n),t));var r={};for(var o in n)if(!1!==Object.hasOwnProperty.call(n,o)){var s=n[o];"object"!=typeof s||null===s?r[o]=s:s instanceof Date?r[o]=new Date(s):s instanceof Map?r[o]=new Map(e(Array.from(s),t)):s instanceof Set?r[o]=new Set(e(Array.from(s),t)):ArrayBuffer.isView(s)?r[o]=i(s):r[o]=t(s)}return r};function e(t,e){for(var n=Object.keys(t),r=new Array(n.length),o=0;o<n.length;o++){var s=n[o],a=t[s];"object"!=typeof a||null===a?r[s]=a:a instanceof Date?r[s]=new Date(a):ArrayBuffer.isView(a)?r[s]=i(a):r[s]=e(a)}return r}}}).call(this)}).call(this,t("buffer").Buffer)},{buffer:17}],73:[function(t,e,i){var n=t("buffer"),r=n.Buffer;function o(t,e){for(var i in t)e[i]=t[i]}function s(t,e,i){return r(t,e,i)}r.from&&r.alloc&&r.allocUnsafe&&r.allocUnsafeSlow?e.exports=n:(o(n,i),i.Buffer=s),s.prototype=Object.create(r.prototype),o(r,s),s.from=function(t,e,i){if("number"==typeof t)throw new TypeError("Argument must not be a number");return r(t,e,i)},s.alloc=function(t,e,i){if("number"!=typeof t)throw new TypeError("Argument must be a number");var n=r(t);return void 0!==e?"string"==typeof i?n.fill(e,i):n.fill(e):n.fill(0),n},s.allocUnsafe=function(t){if("number"!=typeof t)throw new TypeError("Argument must be a number");return r(t)},s.allocUnsafeSlow=function(t){if("number"!=typeof t)throw new TypeError("Argument must be a number");return n.SlowBuffer(t)}},{buffer:17}],74:[function(t,e,i){e.exports=function(t){var e,i=t._readableState;return i?i.objectMode||"number"==typeof t._duplexState?t.read():t.read((e=i).buffer.length?e.buffer.head?e.buffer.head.data.length:e.buffer[0].length:e.length):null}},{}],75:[function(t,e,i){"use strict";var n=t("safe-buffer").Buffer,r=n.isEncoding||function(t){switch((t=""+t)&&t.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function o(t){var e;switch(this.encoding=function(t){var e=function(t){if(!t)return"utf8";for(var e;;)switch(t){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return t;default:if(e)return;t=(""+t).toLowerCase(),e=!0}}(t);if("string"!=typeof e&&(n.isEncoding===r||!r(t)))throw new Error("Unknown encoding: "+t);return e||t}(t),this.encoding){case"utf16le":this.text=c,this.end=l,e=4;break;case"utf8":this.fillLast=a,e=4;break;case"base64":this.text=h,this.end=u,e=3;break;default:return this.write=d,void(this.end=f)}this.lastNeed=0,this.lastTotal=0,this.lastChar=n.allocUnsafe(e)}function s(t){return t<=127?0:t>>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<t.length?e?e+this.text(t,i):this.text(t,i):e||""},o.prototype.end=function(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+"�":e},o.prototype.text=function(t,e){var i=function(t,e,i){var n=e.length-1;if(n<i)return 0;var r=s(e[n]);return r>=0?(r>0&&(t.lastNeed=r-1),r):--n<i||-2===r?0:(r=s(e[n]))>=0?(r>0&&(t.lastNeed=r-2),r):--n<i||-2===r?0:(r=s(e[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&&o<t.indexOf("#")?"?":"#",l=t.split(a);l[0]=l[0].replace(/\\/g,"/");var w=t=l.join(a);if(w=w.trim(),!i&&1===t.split("#").length){var b=c.exec(w);if(b)return this.path=w,this.href=w,this.pathname=b[1],b[2]?(this.search=b[2],this.query=e?m.parse(this.search.substr(1)):this.search.substr(1)):e&&(this.search="",this.query={}),this}var x=s.exec(w);if(x){var k=(x=x[0]).toLowerCase();this.protocol=k,w=w.substr(x.length)}if(i||x||w.match(/^\/\/[^@\/]+@[^@\/]+/)){var T="//"===w.substr(0,2);!T||x&&g[x]||(w=w.substr(2),this.slashes=!0)}if(!g[x]&&(T||x&&!y[x])){for(var A,S,P=-1,C=0;C<d.length;C++)-1!==(R=w.indexOf(d[C]))&&(-1===P||R<P)&&(P=R);for(-1!==(S=-1===P?w.lastIndexOf("@"):w.lastIndexOf("@",P))&&(A=w.slice(0,S),w=w.slice(S+1),this.auth=decodeURIComponent(A)),P=-1,C=0;C<u.length;C++){var R;-1!==(R=w.indexOf(u[C]))&&(-1===P||R<P)&&(P=R)}-1===P&&(P=w.length),this.host=w.slice(0,P),w=w.slice(P),this.parseHost(),this.hostname=this.hostname||"";var _="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!_)for(var E=this.hostname.split(/\./),I=(C=0,E.length);C<I;C++){var L=E[C];if(L&&!L.match(f)){for(var M="",D=0,B=L.length;D<B;D++)L.charCodeAt(D)>127?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;C<I;C++){var H=h[C];if(-1!==w.indexOf(H)){var U=encodeURIComponent(H);U===H&&(U=escape(H)),w=w.split(H).join(U)}}var W=w.indexOf("#");-1!==W&&(this.hash=w.substr(W),w=w.slice(0,W));var q=w.indexOf("?");if(-1!==q?(this.search=w.substr(q),this.query=w.substr(q+1),e&&(this.query=m.parse(this.query)),w=w.slice(0,q)):e&&(this.search="",this.query={}),w&&(this.pathname=w),y[k]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){F=this.pathname||"";var V=this.search||"";this.path=F+V}return this.href=this.format(),this},o.prototype.format=function(){var t=this.auth||"";t&&(t=(t=encodeURIComponent(t)).replace(/%3A/i,":"),t+="@");var e=this.protocol||"",i=this.pathname||"",n=this.hash||"",o=!1,s="";this.host?o=t+this.host:this.hostname&&(o=t+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(o+=":"+this.port)),this.query&&r.isObject(this.query)&&Object.keys(this.query).length&&(s=m.stringify(this.query));var a=this.search||s&&"?"+s||"";return e&&":"!==e.substr(-1)&&(e+=":"),this.slashes||(!e||y[e])&&!1!==o?(o="//"+(o||""),i&&"/"!==i.charAt(0)&&(i="/"+i)):o||(o=""),n&&"#"!==n.charAt(0)&&(n="#"+n),a&&"?"!==a.charAt(0)&&(a="?"+a),e+o+(i=i.replace(/[?#]/g,(function(t){return encodeURIComponent(t)})))+(a=a.replace("#","%23"))+n},o.prototype.resolve=function(t){return this.resolveObject(w(t,!1,!0)).format()},o.prototype.resolveObject=function(t){if(r.isString(t)){var e=new o;e.parse(t,!1,!0),t=e}for(var i=new o,n=Object.keys(this),s=0;s<n.length;s++){var a=n[s];i[a]=this[a]}if(i.hash=t.hash,""===t.href)return i.href=i.format(),i;if(t.slashes&&!t.protocol){for(var c=Object.keys(t),l=0;l<c.length;l++){var h=c[l];"protocol"!==h&&(i[h]=t[h])}return y[i.protocol]&&i.hostname&&!i.pathname&&(i.path=i.pathname="/"),i.href=i.format(),i}if(t.protocol&&t.protocol!==i.protocol){if(!y[t.protocol]){for(var u=Object.keys(t),d=0;d<u.length;d++){var f=u[d];i[f]=t[f]}return i.href=i.format(),i}if(i.protocol=t.protocol,t.host||g[t.protocol])i.pathname=t.pathname;else{for(var p=(t.pathname||"").split("/");p.length&&!(t.host=p.shift()););t.host||(t.host=""),t.hostname||(t.hostname=""),""!==p[0]&&p.unshift(""),p.length<2&&p.unshift(""),i.pathname=p.join("/")}if(i.search=t.search,i.query=t.query,i.host=t.host||"",i.auth=t.auth,i.hostname=t.hostname||t.host,i.port=t.port,i.pathname||i.search){var v=i.pathname||"",m=i.search||"";i.path=v+m}return i.slashes=i.slashes||t.slashes,i.href=i.format(),i}var w=i.pathname&&"/"===i.pathname.charAt(0),b=t.host||t.pathname&&"/"===t.pathname.charAt(0),x=b||w||i.host&&t.pathname,k=x,T=i.pathname&&i.pathname.split("/")||[],A=(p=t.pathname&&t.pathname.split("/")||[],i.protocol&&!y[i.protocol]);if(A&&(i.hostname="",i.port=null,i.host&&(""===T[0]?T[0]=i.host:T.unshift(i.host)),i.host="",t.protocol&&(t.hostname=null,t.port=null,t.host&&(""===p[0]?p[0]=t.host:p.unshift(t.host)),t.host=null),x=x&&(""===p[0]||""===T[0])),b)i.host=t.host||""===t.host?t.host:i.host,i.hostname=t.hostname||""===t.hostname?t.hostname:i.hostname,i.search=t.search,i.query=t.query,T=p;else if(p.length)T||(T=[]),T.pop(),T=T.concat(p),i.search=t.search,i.query=t.query;else if(!r.isNullOrUndefined(t.search))return A&&(i.hostname=i.host=T.shift(),(_=!!(i.host&&i.host.indexOf("@")>0)&&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;i<t.length;i++)t[i]=arguments[i];var n=e.apply(this,t),r=t[t.length-1];return"function"==typeof n&&n!==r&&Object.keys(r).forEach((function(t){n[t]=r[t]})),n}}},{}],80:[function(t,e,i){"use strict";e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},{}],81:[function(t,e,i){e.exports=function(){for(var t={},e=0;e<arguments.length;e++){var i=arguments[e];for(var r in i)n.call(i,r)&&(t[r]=i[r])}return t};var n=Object.prototype.hasOwnProperty},{}],82:[function(t,e,i){"use strict";e.exports=function(t){t.prototype[Symbol.iterator]=function*(){for(let t=this.head;t;t=t.next)yield t.value}}},{}],83:[function(t,e,i){"use strict";function n(t){var e=this;if(e instanceof n||(e=new n),e.tail=null,e.head=null,e.length=0,t&&"function"==typeof t.forEach)t.forEach((function(t){e.push(t)}));else if(arguments.length>0)for(var i=0,r=arguments.length;i<r;i++)e.push(arguments[i]);return e}function r(t,e,i){var n=e===t.head?new a(i,null,e,t):new a(i,e,e.next,t);return null===n.next&&(t.tail=n),null===n.prev&&(t.head=n),t.length++,n}function o(t,e){t.tail=new a(e,t.tail,null,t),t.head||(t.head=t.tail),t.length++}function s(t,e){t.head=new a(e,null,t.head,t),t.tail||(t.tail=t.head),t.length++}function a(t,e,i,n){if(!(this instanceof a))return new a(t,e,i,n);this.list=n,this.value=t,e?(e.next=this,this.prev=e):this.prev=null,i?(i.prev=this,this.next=i):this.next=null}e.exports=n,n.Node=a,n.create=n,n.prototype.removeNode=function(t){if(t.list!==this)throw new Error("removing node which does not belong to this list");var e=t.next,i=t.prev;return e&&(e.prev=i),i&&(i.next=e),t===this.head&&(this.head=e),t===this.tail&&(this.tail=i),t.list.length--,t.next=null,t.prev=null,t.list=null,e},n.prototype.unshiftNode=function(t){if(t!==this.head){t.list&&t.list.removeNode(t);var e=this.head;t.list=this,t.next=e,e&&(e.prev=t),this.head=t,this.tail||(this.tail=t),this.length++}},n.prototype.pushNode=function(t){if(t!==this.tail){t.list&&t.list.removeNode(t);var e=this.tail;t.list=this,t.prev=e,e&&(e.next=t),this.tail=t,this.head||(this.head=t),this.length++}},n.prototype.push=function(){for(var t=0,e=arguments.length;t<e;t++)o(this,arguments[t]);return this.length},n.prototype.unshift=function(){for(var t=0,e=arguments.length;t<e;t++)s(this,arguments[t]);return this.length},n.prototype.pop=function(){if(this.tail){var t=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,t}},n.prototype.shift=function(){if(this.head){var t=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,t}},n.prototype.forEach=function(t,e){e=e||this;for(var i=this.head,n=0;null!==i;n++)t.call(e,i.value,n,this),i=i.next},n.prototype.forEachReverse=function(t,e){e=e||this;for(var i=this.tail,n=this.length-1;null!==i;n--)t.call(e,i.value,n,this),i=i.prev},n.prototype.get=function(t){for(var e=0,i=this.head;null!==i&&e<t;e++)i=i.next;if(e===t&&null!==i)return i.value},n.prototype.getReverse=function(t){for(var e=0,i=this.tail;null!==i&&e<t;e++)i=i.prev;if(e===t&&null!==i)return i.value},n.prototype.map=function(t,e){e=e||this;for(var i=new n,r=this.head;null!==r;)i.push(t.call(e,r.value,this)),r=r.next;return i},n.prototype.mapReverse=function(t,e){e=e||this;for(var i=new n,r=this.tail;null!==r;)i.push(t.call(e,r.value,this)),r=r.prev;return i},n.prototype.reduce=function(t,e){var i,n=this.head;if(arguments.length>1)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(e<t||e<0)return i;t<0&&(t=0),e>this.length&&(e=this.length);for(var r=0,o=this.head;null!==o&&r<t;r++)o=o.next;for(;null!==o&&r<e;r++,o=o.next)i.push(o.value);return i},n.prototype.sliceReverse=function(t,e){(e=e||this.length)<0&&(e+=this.length),(t=t||0)<0&&(t+=this.length);var i=new n;if(e<t||e<0)return i;t<0&&(t=0),e>this.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<t;n++)o=o.next;var s=[];for(n=0;o&&n<e;n++)s.push(o.value),o=this.removeNode(o);for(null===o&&(o=this.tail),o!==this.head&&o!==this.tail&&(o=o.prev),n=0;n<i.length;n++)o=r(this,o,i[n]);return s},n.prototype.reverse=function(){for(var t=this.head,e=this.tail,i=t;null!==i;i=i.prev){var n=i.prev;i.prev=i.next,i.next=n}return this.head=e,this.tail=t,this};try{t("./iterator.js")(n)}catch(t){}},{"./iterator.js":82}]},{},[12])(12)}},e={};function i(n){var r=e[n];if(void 0!==r)return r.exports;var o=e[n]={exports:{}};return t[n](o,o.exports,i),o.exports}i.d=(t,e)=>{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=n<r?n:r;if(a<2*u&&(u=a/2),c<2*u&&(u=c/2),i.moveTo(o+u,s),i.arcTo(l,s,l,h,u),i.arcTo(l,h,o,h,u),i.arcTo(o,h,o,s,u),i.arcTo(o,s,l,s,u),i instanceof Path2D)return i}i.r(n),i.d(n,{Meta2d:()=>xn,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.x<e.x+i&&t.y>e.y-i&&t.y<e.y+i}function C(t,e,i){t.x=i.x-(i.x-t.x)*e,t.y=i.y-(i.y-t.y)*e}function R(t,e){if(t.x===e.x)return t.y<=e.y?0:180;if(t.y===e.y)return t.x<e.x?270:90;const i=t.x-e.x,n=t.y-e.y;let r=Math.atan(Math.abs(i/n))/(2*Math.PI)*360;return i>0&&n>0?r=180-r:i<0&&n>0?r+=180:i<0&&n<0&&(r=360-r),r}function _(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<t.calculative.fontSize&&(l=t.calculative.fontSize),u+=(a||0)+o.x,d+=(c||0)+o.y;const v=t.textAlign||s.store.options.textAlign,g=t.textBaseline||s.store.options.textBaseline;switch(v){case"center":u+=(f-(l||f))/2;break;case"right":u+=f-(l||f)}switch(g){case"middle":d+=(p-(h||p))/2;break;case"bottom":d+=p-(h||p)}const y={x:u,y:d,width:l||f,height:h||p};Te(y),t.calculative.worldTextRect=y,U(t),t.calculative.textDrawRect=void 0}function H(t,e){const i=e.calculative.fontSize*e.calculative.lineHeight,n=e.calculative.textLines.length*i,r=function(t,e){let i=0;return e.calculative.textLineWidths=[],e.calculative.textLines.forEach((n=>{const r=t.measureText(n).width;e.calculative.textLineWidths.push(r),i<r&&(i=r)})),i}(t,e),o=e.calculative.worldTextRect;let s=o.x+(o.width-r)/2,a=o.y+(o.height-n)/2;const c=e.calculative.canvas.store.options;switch(e.textAlign||c.textAlign){case"left":s=o.x;break;case"right":s=o.x+o.width-r}switch(e.textBaseline||c.textBaseline){case"top":a=o.y;break;case"bottom":a=o.ey-n}e.calculative.textDrawRect={x:s,y:a,width:r,height:n},Te(e.calculative.textDrawRect)}function U(t,e=t.calculative.text){if(null==e)return void(t.calculative.textLines=[]);e=e.toString();let i=[];const n=t.calculative.fontSize*t.calculative.lineHeight,r=t.calculative.worldTextRect.height,o=Math.floor(r/n),s=o>1?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;n<t.length;++n){const r=t.charCodeAt(n);r<33||r>126?(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<t.length;++u){const d=t[u]||"",f=h+d;let p=0;if(i.store.options.measureTextWidth)n.font=Tt({fontStyle:r,fontWeight:o,fontFamily:a||i.store.options.fontFamily,fontSize:s,lineHeight:c}),p=n.measureText(f).width;else{const t=f.match(/[^\x00-\xff]/g)||"",e=t.length*s,i=f.match(/\s/g)||"";p=e+i.length*s*.3+(f.length-t.length-i.length)*s*.6}p<=e.calculative.worldTextRect.width?h+=d:(h.length&&l.push(h),h=d)}return h.length&&l.push(h),n.restore(),l}function V(t){t[t.length-1]=t[t.length-1].slice(0,-3)+"..."}function K(t,e=!1){if(Array.isArray(t)){const i=[];return t.forEach((t=>{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<s||"]"===n&&t===s);console.warn("startNum must less than endNum")}function tt(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("["!==i||"]"!==n)return void console.warn('collection must start with "[" and end with "]"');const r=e.substring(1,e.length-1).split(",");for(const e of r)if(e.includes("..")){const[i,n]=e.split(".."),[r,o]=[+i,+n];if(r>=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<n?{x:e.x+(i.x-e.x)*t/n,y:e.y+(i.y-e.y)*t/n}:{x:e.x+(i.x-e.x)/n/2,y:e.y+(i.y-e.y)/n/2}}function dt(t,e,i,n,r,o){let s=ut(i,r,n),a=ut(i,r,o),c=function(t=100,e,i,n,r){let o=null;const s=[];n||r?n&&!r?o=vt:n&&r&&(o=gt):o=pt;for(let a=0;a<t;a++)s.push(o(a/t,e,i,n,r));return r?s.push(r):n&&s.push(n),s}(100,s,{x:r.x,y:r.y},a);for(let i=0;i<c.length-1;i++)ht(t,e,[{x:c[i].x,y:c[i].y},{x:c[i+1].x,y:c[i+1].y}])}function ft(t,e,i,n){let r=ut(e,i,n),o={x:i.x,y:i.y};t.quadraticCurveTo(o.x,o.y,r.x,r.y)}function pt(t,e,i){const{x:n,y:r}=e,{x:o,y:s}=i;return{x:n+(o-n)*t,y:r+(s-r)*t}}function vt(t,e,i,n){const{x:r,y:o}=e,{x:s,y:a}=i,{x:c,y:l}=n;return{x:(1-t)*(1-t)*r+2*t*(1-t)*s+t*t*c,y:(1-t)*(1-t)*o+2*t*(1-t)*a+t*t*l}}function gt(t,e,i,n,r){const{x:o,y:s}=e,{x:a,y:c}=r,{x:l,y:h}=i,{x:u,y:d}=n;return{x:o*(1-t)*(1-t)*(1-t)+3*l*t*(1-t)*(1-t)+3*u*t*t*(1-t)+a*t*t*t,y:s*(1-t)*(1-t)*(1-t)+3*h*t*(1-t)*(1-t)+3*d*t*t*(1-t)+c*t*t*t}}function yt(t,e,i,n,r){if(!i||!n)return;const{x:o,y:s,center:a,ex:c,ey:l}=e,h={x:o,y:a.y},u={x:c,y:a.y};r%90==0&&r%180?(h.x=a.x,u.x=a.x,r%270?(h.y=s,u.y=l):(h.y=l,u.y=s)):r&&(S(h,r,e.center),S(u,r,e.center));const d=t.createLinearGradient(h.x,h.y,u.x,u.y);return d.addColorStop(0,i),d.addColorStop(1,n),d}function mt(t,e){const{x:i,y:n,width:r,height:o}=function(t){const{worldIconRect:e,iconWidth:i,iconHeight:n,imgNaturalWidth:r,imgNaturalHeight:o}=t.calculative;let{x:s,y:a,width:c,height:l}=e;if(i&&(c=i),n&&(l=n),r&&o&&t.imageRatio){const t=e.width/r,s=e.height/o,a=Math.min(t,s),h=r/o;i?l=i/h:n?c=n*h:(c=a*r,l=a*o)}switch(s+=(e.width-c)/2,a+=(e.height-l)/2,t.iconAlign){case"top":a=e.y;break;case"bottom":a=e.ey-l;break;case"left":s=e.x;break;case"right":s=e.ex-c;break;case"left-top":s=e.x,a=e.y;break;case"right-top":s=e.ex-c,a=e.y;break;case"left-bottom":s=e.x,a=e.ey-l;break;case"right-bottom":s=e.ex-c,a=e.ey-l}return{x:s,y:a,width:c,height:l}}(e),{worldIconRect:s,iconRotate:a,img:c}=e.calculative;if(a){const{x:e,y:i}=s.center;t.translate(e,i),t.rotate(a*Math.PI/180),t.translate(-e,-i)}t.drawImage(c,i,n,r,o)}function wt(t,e){const{textColor:i,color:n}=t.calculative,{data:r,options:o}=e;return i||n||r.color||o.textColor||o.color}function bt(t,e){const{fontStyle:i,fontWeight:n,fontSize:r,fontFamily:o,lineHeight:s,text:a,hiddenText:c,canvas:l,textHasShadow:h,textBackground:u}=e.calculative;if(null==a||c)return;const d=l.store;let f;t.save(),h||(t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),e.calculative.hover?f=e.hoverTextColor||e.hoverColor||d.options.hoverColor:e.calculative.active&&(f=e.activeTextColor||e.activeColor||d.options.activeColor),t.fillStyle=f||wt(e,d),t.font=Tt({fontStyle:i,fontWeight:n,fontFamily:o||d.options.fontFamily,fontSize:r,lineHeight:s}),!e.calculative.textDrawRect&&H(t,e);const{x:p,y:v,width:g,height:y}=e.calculative.textDrawRect;u&&(t.save(),t.fillStyle=u,t.fillRect(p,v,g,y),t.restore());const m=e.textAlign||d.options.textAlign,w=r*s;e.calculative.textLines.forEach(((i,n)=>{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;t<r;t++)d+=i;const o=R(f,n)-270;if(t.save(),o%360!=0){const{x:e,y:i}=f;t.translate(e,i);let n=o*Math.PI/180;t.rotate(n),t.translate(-e,-i)}t.fillText(d,f.x,f.y+a/2),t.restore(),f=n}t.restore()}function kt(t,e){const i=e.calculative.canvas.store;t.save(),t.shadowColor="",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0,t.textAlign="center",t.textBaseline="middle";const n=e.calculative.worldIconRect;let r=n.x+n.width/2,o=n.y+n.height/2;switch(e.iconAlign){case"top":o=n.y,t.textBaseline="top";break;case"bottom":o=n.ey,t.textBaseline="bottom";break;case"left":r=n.x,t.textAlign="left";break;case"right":r=n.ex,t.textAlign="right";break;case"left-top":r=n.x,o=n.y,t.textAlign="left",t.textBaseline="top";break;case"right-top":r=n.ex,o=n.y,t.textAlign="right",t.textBaseline="top";break;case"left-bottom":r=n.x,o=n.ey,t.textAlign="left",t.textBaseline="bottom";break;case"right-bottom":r=n.ex,o=n.ey,t.textAlign="right",t.textBaseline="bottom"}const s=e.calculative.iconWeight;let a;const c=e.calculative.iconFamily;a=e.calculative.iconSize>0?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<s&&(h=s),h*=.5;const{colors:u}=at(n),d=t.createRadialGradient(c,l,h*(r||0),c,l,h);return u.forEach((t=>{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;u<a&&(u=a),u*=.5;const d=t.createRadialGradient(l,h,u*(o||0),l,h,u);return d.addColorStop(0,n),d.addColorStop(1,r),d}(t,e):r=e.calculative.background||i.data.penBackground,t.fillStyle=r,n=!!r}}if(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),s?(function(t,e){const i=e.calculative.worldAnchors;let n=e.calculative.lineWidth*(e.calculative.gradientSmooth||0);for(let r=0;r<i.length-1;r++)if("curve"!==e.lineName&&"mind"!==e.lineName||!i[r].curvePoints){let o=i[r],s=i[r+1];if(r>0&&r<i.length-1){let o=i[r-1].curvePoints;dt(t,e,n,o?o[o.length-1]:i[r-1],i[r],i[r+1])}r>0&&r<i.length-1&&(o=ut(n,i[r],i[r+1])),r<i.length-2&&(s=ut(n,i[r+1],i[r])),ht(t,e,[o,s])}else{if(r>0){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;n<o;n++)ht(t,e,[i[r].curvePoints[n],i[r].curvePoints[n+1]]);let s=ut(n,i[r+1],i[r].curvePoints[o]);ht(t,e,[i[r].curvePoints[o],s])}}(t,e),function(t=!0,e,i,n){const r=t?n.path2dMap.get(i):M.path2dDraws[i.name];r&&i.type&&(i.calculative.animatePos&&(e.save(),It(e,i,n),e.beginPath(),r instanceof Path2D?!i.calculative.gradientSmooth||"polyline"!==i.lineName&&"line"!==i.lineName?e.stroke(r):(i.calculative.gradientAnimatePath||(i.calculative.gradientAnimatePath=function(t){const e=t.calculative.worldAnchors;let i=t.calculative.lineWidth*(t.calculative.gradientSmooth||0);const n=new Path2D;for(let t=0;t<e.length-1;t++){let r=e[t],o=e[t+1];0==t&&n.moveTo(e[t].x,e[t].y),t>0&&t<e.length-1&&(e[t-1].curvePoints,ft(n,i,e[t],e[t+1])),t>0&&t<e.length-1&&(r=ut(i,e[t],e[t+1])),t<e.length-2&&(o=ut(i,e[t+1],e[t])),n.lineTo(o.x,o.y)}return n}(i)),e.stroke(i.calculative.gradientAnimatePath)):(r(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))}(!0,t,e,i)):(Et(!0,t,e,i,n),he(t,e)),e.image&&e.calculative.img||!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 Ct(t,e){const i=e.lineCap||(e.type?"round":"square");i?t.lineCap=i:e.type&&(t.lineCap="round")}function Rt(t,e){const i=e.lineJoin;i?t.lineJoin=i:e.type&&(t.lineJoin="round")}function _t(t,e,i){t.save(),i&&t.translate(-i.x,-i.y),t.setAttrs?.(e),t.beginPath(),e.calculative.flipX&&(t.translate(e.calculative.worldRect.x+e.calculative.worldRect.ex,0),t.scale(-1,1)),e.calculative.flipY&&(t.translate(0,e.calculative.worldRect.y+e.calculative.worldRect.ey),t.scale(1,-1)),e.calculative.rotate&&"line"!==e.name&&St(t,e),e.calculative.lineWidth>1&&(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<i;r++)t.frames[r]&&(n+=t.frames[r][e]||0);return n}function ae(t,e){let i=t;for(;i&&i.parentId;){const t=i;i=e.pens[i.parentId];const n=i?.calculative?.showChild;if(null!=n&&i.children[n]!==t.id)return!1}return!0}function ce(t,e=!1){const{store:i,canvasRect:n}=t.calculative.canvas;if(e&&t.children?.forEach((t=>{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&&c<o&&(n={x:Math.round(t.x)+.5,y:Math.round(t.y)+.5,prev:{x:Math.round(e.x)+.5,y:Math.round(e.y)+.5},step:t.x-e.x},o=c);const h=Math.abs(t.y-e.y);h>0&&h<8&&c<s&&(r={x:Math.round(t.x)+.5,y:Math.round(t.y)+.5,prev:{x:Math.round(e.x)+.5,y:Math.round(e.y)+.5},step:t.y-e.y},s=c)}));return{xDock:n,yDock:r}}function fe(t,e,i,n){let r=[];return 1===i.length?(r=K(pe(i[0])),r.forEach((t=>{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.ex<f.x)&&(p.y>f.ey||p.ey<f.y))||l.type&&t.active.some((e=>ye(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&&h<s&&(r={x:Math.round(t.x)+.5,y:Math.round(t.y)+.5,step:e,prev:{x:Math.round(n.x)+.5,y:Math.round(n.y)+.5},penId:l.id,anchorId:n.id,dockAnchorId:t.id},s=h),u<10&&u<a&&(o={x:Math.round(t.x)+.5,y:Math.round(t.y)+.5,step:c,prev:{x:Math.round(n.x)+.5,y:Math.round(n.y)+.5},penId:l.id,anchorId:n.id,dockAnchorId:t.id},a=u)}})),{xDock:r,yDock:o}}function ye(t,e,i){if(!i.type)return!1;if(Array.isArray(e?.connectedLines))for(const t of e?.connectedLines)if(t.lineId===i.id)return!0;if(Array.isArray(e?.children))for(const n of e.children)if(ye(t,t.pens[n],i))return!0;return!1}function me(t,e){return t.toFixed(12)==e}function we(t){if(t.id=et(),Array.isArray(t.anchors))for(const e of t.anchors)t.type&&(e.id=et()),e.penId=t.id,e.prev&&(t.type&&(e.prev.id=et()),e.prev.penId=t.id),e.next&&(t.type&&(e.next.id=et()),e.next.penId=t.id)}function be(t,e){if(!e)return;if(null==e.ex&&Te(e),!e.rotate||e.rotate%360==0)return t.x>e.x&&t.x<e.ex&&t.y>e.y&&t.y<e.ey;e.center||ke(e);const i=[{x:e.x,y:e.y},{x:e.ex,y:e.y},{x:e.ex,y:e.ey},{x:e.x,y:e.ey}];return i.forEach((t=>{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.ex<e.ex&&t.y>e.y&&t.ey<e.ey:!(t.x>e.ex||t.ex<e.x||t.ey<e.y||t.y>e.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.values.length-1;e+=2)i.push(n.x+t.values[e]),i.push(n.y+t.values[e+1]);t.worldPoints=i}(t,e)}"M"!==t.key&&"m"!==t.key&&"Z"!==t.key&&"z"!==t.key||(i=t.worldPoints[t.worldPoints.length-2],n=t.worldPoints[t.worldPoints.length-1]),e=t}))}(t),t.commands.forEach((t=>{t.worldPoints.forEach(((t,o)=>{o%2==0?(t<e&&(e=t),t>n&&(n=t)):(t<i&&(i=t),t>r&&(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<t.length;){const n=t.slice(e).match(De);if(null===n)throw new Error("malformed path (first error at "+e+")");{const r=n[1];e+=n[0].length;const o=je(r,t,e);e=o.cursor,i.push(...o.commands)}}return{commands:i}}(i);t.calculative.svgRect=Fe(n),ke(t.calculative.svgRect),t.calculative.svgRect.width===t.calculative.worldRect.width&&t.calculative.svgRect.height===t.calculative.worldRect.height||function(t,e,i){null==i&&(i=e),t.commands.forEach((t=>{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<h?0:90,t.values[0]=-Math.sqrt(2*d*u*(c+h+f))/d,t.values[1]=-Math.sqrt(2*d*u*(c+h-f))/d,t.values[5]*=e,t.values[6]*=i,t.values[4]=e*i>=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;i<e.length;++i)i?t.lineTo(e[i].x,e[i].y):t.moveTo(e[i].x,e[i].y);t.closePath(),i&&t.fill(),t.stroke(),t.restore()}function qe(t,e,i){if(e.calculative.worldAnchors||(e.calculative.worldAnchors=[]),i)e.calculative.activeAnchor&&(e.calculative.activeAnchor.next={penId:e.id,x:i.x,y:i.y},_(e.calculative.activeAnchor.next,e.calculative.activeAnchor)<5?e.calculative.activeAnchor.next=void 0:(e.calculative.activeAnchor.prev={...e.calculative.activeAnchor.next},S(e.calculative.activeAnchor.prev,180,e.calculative.activeAnchor)));else{const i=e.calculative.worldAnchors[0];i.next||(Ve(i,jt(i,t.pens[i.connectTo]),50),i.prev=void 0);const n=e.calculative.worldAnchors[e.calculative.worldAnchors.length-1];n&&n!==i&&!n.prev&&(Ve(n,jt(n,t.pens[n.connectTo]),-50),n.next=void 0)}}function Ve(t,e,i){switch(e){case m.Up:t.prev={penId:t.penId,x:t.x,y:t.y+i},t.next={penId:t.penId,x:t.x,y:t.y-i};break;case m.Right:t.prev={penId:t.penId,x:t.x-i,y:t.y},t.next={penId:t.penId,x:t.x+i,y:t.y};break;case m.Bottom:t.prev={penId:t.penId,x:t.x,y:t.y-i},t.next={penId:t.penId,x:t.x,y:t.y+i};break;case m.Left:t.prev={penId:t.penId,x:t.x+i,y:t.y},t.next={penId:t.penId,x:t.x-i,y:t.y}}}function Ke(t,e,i,n){const r=1-t;return{x:r*r*e.x+2*r*t*i.x+t*t*n.x,y:r*r*e.y+2*r*t*i.y+t*t*n.y,step:t}}function Ye(t,e,i,n,r){const{x:o,y:s}=e,{x:a,y:c}=r,{x:l,y:h}=i,{x:u,y:d}=n,f=1-t;return{x:o*f*f*f+3*l*t*f*f+3*u*t*t*f+a*t*t*t,y:s*f*f*f+3*h*t*f*f+3*d*t*t*f+c*t*t*t,step:t}}function Xe(t,e,i){return{x:t.x+i*(e.x-t.x),y:t.y+i*(e.y-t.y)}}function $e(t,e,i){if(e.calculative.worldAnchors||(e.calculative.worldAnchors=[]),e.calculative.worldAnchors.length<2)return;let n=e.calculative.activeAnchor,r=i||Yt(e);if(!n||!r)return;let o=jt(n,t.pens[n.connectTo]);switch(o===m.None&&(o=r.x>n.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(c<h){const t=c;c=h,h=t}return!(n<a&&o<a||n>l&&o>l||r>c&&s>c||r<h&&s<h)}return!1}function ai(t,e,i){const n=.02;if(!t.next&&!e.prev)return si(t,e,i);if(t.next&&e.prev){for(let r=n;r<1;r+=n)if(xe(Ye(r,t,t.next,e.prev,e),i))return!0}else if(t.next||e.prev)for(let r=n;r<1;r+=n)if(xe(Ke(r,t,t.next||e.prev,e),i))return!0;return!1}const ci=30;function li(t,e,i){if(e.calculative.worldAnchors||(e.calculative.worldAnchors=[]),e.calculative.worldAnchors.length<2)return;let n,r=Kt(e),o=Yt(e);if(!r||!o)return;if(e.anchors?.length&&r===e.calculative.activeAnchor?(n=!0,r=o,o=Kt(e)):e.anchors&&e.anchors.length||r===e.calculative.activeAnchor||(r=e.calculative.activeAnchor),!r||!o)return;r.next=void 0,o.prev=void 0;const s=o.connectTo;Ut(e);const a=[],c=t.pens[r.connectTo],l=t.pens[o.connectTo],h=jt(r,c),u=jt(o,l);let d=hi(r,h,ci);d&&(r=d,a.push(d)),d=hi(o,u,ci);const f=o;switch(d&&(o=d),h){case m.Up: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: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.Bottom:if(r=e.x,o=t.y,e.y>t.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.x<t.x&&e.y<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(e.y>t.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.y<t.y&&(r=e.x,o=t.y),n.push({x:r,y:o});break;case m.Left:if(r=e.x,o=t.y,e.x<t.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:o},{x:i,y:e.y})}break;case m.Right:e.x<t.x?n.push({x:t.x,y:e.y}):n.push({x:e.x,y:t.y});break;default:if(r=e.x,o=e.y,e.x<t.x+ci)n.push({x:t.x,y:o});else{const i=(t.x+e.x-ci)/2;n.push({x:i,y:t.y},{x:i,y:o})}}return n}(r,o,u));break;case m.Bottom: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:if(r=t.x,o=e.y,e.y<t.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:r,y:i},{x:e.x,y:i})}break;case m.Right: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;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.y<t.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:r,y:i},{x:e.x,y:i})}}return n}(r,o,u));break;case m.Left: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.y<t.y&&(r=e.x,o=t.y),n.push({x:r,y:o});break;case m.Right:if(r=t.x,o=e.y,e.x>t.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.x<t.x-ci){const i=(t.x+e.x+ci)/2;n.push({x:i,y:t.y},{x:i,y:o})}else n.push({x:t.x,y:o})}return n}(r,o,u));break;default:a.push(...function(t,e,i){const n=[];return null==t.calculative.drawlineH&&(t.calculative.drawlineH=Math.abs(i.x-e.x)>Math.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)<ci&&(i.isTemp=!0)):(n.push({x:e.x,y:i.y}),Math.abs(i.x-e.x)<ci&&(i.isTemp=!0))),n}(e,r,o))}if(a.forEach((t=>{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.length&&n[t].id!==e.id;t++){if(n[t].y!==e.y)return!1;if(n[t].x===n[t+1]?.x&&n[t].y!==n[t+1]?.y)return!1}return!0}function di(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.length&&n[t].id!==e.id;t++){if(n[t].x!==e.x)return!1;if(n[t].y===n[t+1]?.y&&n[t].x!==n[t+1]?.x)return!1}return!0}function fi(t,e,i,n){const r=[];let o,s,a,c,l,h,u,d,f,p,v,g,y,m;f=t[i],p=t[n],a=f.x,c=f.y,u=p.x-a,d=p.y-c,m=u*u+d*d,o=e;for(let e=i+1;e<n;e++)v=t[e],0!==u||0!==d?(g=((v.x-a)*u+(v.y-c)*d)/m,g>1?(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=e<i?e:i;return n<2*o&&(o=n/2),r<2*o&&(o=r/2),o}(t);for(let a=0;a<5;a++){if(2===a)continue;let c=i+r*(a+1)/6,l=n;c<i+s?l=on(i+s,l+s,c,s,-1):c>i+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;c<n+s?l=rn(l-s,n+s,c,s):c>n+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;c<i+s?l=on(i+s,l-s,c,s):c>i+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;c<n+s?l=rn(l+s,n+s,c,s,-1):c>n+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;t<document.styleSheets.length;t++)"le5le.com/tooltip"===document.styleSheets[t].title&&(i=document.styleSheets[t]);if(!i){let t=document.createElement("style");t.type="text/css",t.title="le5le.com/tooltip",document.head.appendChild(t),t=document.createElement("style"),t.type="text/css",document.head.appendChild(t),i=t.sheet,i.insertRule(".meta2d-tooltip{position:absolute;padding:8px 0;z-index:10;left: -9999px;top: -9999px;}"),i.insertRule(".meta2d-tooltip .text{max-width:320px;min-height:30px;max-height:400px;outline:none;padding:8px 16px;border-radius:4px;background:#777777;color:#ffffff;line-height:1.8;overflow-y:auto;}"),i.insertRule(".meta2d-tooltip .arrow{position:absolute;border:6px solid transparent;background:transparent;top:-4px;left:50%;transform:translateX(-50%)}"),i.insertRule(".meta2d-tooltip .arrow.down{top:initial;bottom: 1.5px;}")}}static getTitle(t){if(t.titleFnJs&&!t.titleFn)try{t.titleFn=new Function("pen",t.titleFnJs)}catch(t){console.log("titleFnJs",t)}return t.titleFn?t.titleFn(t):String(t.title)}setText(t){const e=this.box.getBoundingClientRect();let i=globalThis.marked;const n=ln.getTitle(t);if(i){this.text.innerHTML=i(n);const t=this.text.getElementsByTagName("A");for(let e=0;e<t.length;++e)t[e].setAttribute("target","_blank")}else this.text.innerHTML=n;return e}updateText(t){if(this.currentPen?.id!==t.id)return;if(ln.titleEmpty(t))return;const e=this.setText(t),i=this.box.getBoundingClientRect();this.changePositionByText(e,i)}changePositionByText(t,e){this.x-=(e.width-t.width)/2,this.y-=e.height-t.height,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px"}static titleEmpty(t){return!t.title&&!t.titleFn&&!t.titleFnJs}show(t,e){if(this.currentPen=t,ln.titleEmpty(t)){let i=ot(t,!0);return void(i&&this.show(i,e))}this.setText(t);const i=this.box.getBoundingClientRect(),n=t.calculative.worldRect;let r=t.calculative.canvas.store.data.x+e.x-i.width/2,o=t.calculative.canvas.store.data.y+e.y-i.height;t.type||(r=t.calculative.canvas.store.data.x+n.x-(i.width-n.width)/2,o=t.calculative.canvas.store.data.y+n.ey-i.height-n.height),o>0?(this.arrowUp.style.borderBottomColor="transparent",this.arrowDown.style.borderTopColor="#777777"):(o+=i.height+n.height+5,this.arrowUp.style.borderBottomColor="#777777",this.arrowDown.style.borderTopColor="transparent"),this.x=r,this.y=o,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px"}hide(){this.currentPen=null,this.x=-9999,this.box.style.left="-9999px"}translate(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;t<document.styleSheets.length;t++)"le5le/scroll"===document.styleSheets[t].title&&(e=document.styleSheets[t]);if(!e){let t=document.createElement("style");t.type="text/css",t.title="le5le.com/scroll",document.head.appendChild(t),t=document.createElement("style"),t.type="text/css",document.head.appendChild(t),e=t.sheet,e.insertRule(".meta2d-scroll{position:absolute;width:8px;height:200px;background:#dddddd;border-radius:10px;z-index:20;cursor:default;}"),e.insertRule(".meta2d-scroll:hover{background:#cccccc;cursor:pointer}"),e.insertRule(".meta2d-scroll.v{right:0;top:calc(50% - 100px);}"),e.insertRule(".meta2d-scroll.h{bottom:2px;left:calc(50% - 100px);width:200px;height:8px;}")}this.init()}init(){this.isShow=!0,this.resize(),this.initPos()}initPos(){this.scrollX=(this.parent.parentElement.clientWidth-this.hSize)/2,this.scrollY=(this.parent.parentElement.clientHeight-this.vSize)/2,this.h.style.left=`${this.scrollX}px`,this.v.style.top=`${this.scrollY}px`}resize(){this.rect=Ae(this.parent.store.data.pens),this.rect.width<1400&&(this.rect.width=1400),this.rect.height<900&&(this.rect.height=900),this.parent.store.data.x>0?this.rect.width+=this.parent.store.data.x+(this.rect.x>0?0:this.rect.x):this.rect.width-=this.parent.store.data.x+(this.rect.x>0?0:this.rect.x),this.parent.store.data.y>0?this.rect.height+=this.parent.store.data.y+(this.rect.y>0?0:this.rect.y):this.rect.height-=this.parent.store.data.y+(this.rect.y>0?0:this.rect.y),this.rect.width<1400&&(this.rect.width=1400),this.rect.height<900&&(this.rect.height=900),this.hSize=1e3*this.parent.parentElement.clientWidth/this.rect.width/3,this.vSize=1e3*this.parent.parentElement.clientHeight/this.rect.height/3,this.h.style.width=this.hSize+"px",this.v.style.height=this.vSize+"px"}show(){this.isShow=!0,this.h.style.display="block",this.v.style.display="block",document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp)}hide(){this.isShow=!1,this.h.style.display="none",this.v.style.display="none",this.destroy()}translate(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<u;e+=10*a,f+=100)a<3&&f%500||t.fillText(f.toString(),e+4,16);f=0-100*Math.floor(h/a/10),h<0&&(f-=100);for(let e=h%(10*a);e<d;e+=10*a,f+=100)a<3&&f%500||(t.save(),t.beginPath(),t.translate(16,e-4),t.rotate(270*Math.PI/180),t.fillText(f.toString(),0,0),t.restore());t.restore()}}class dn{constructor(t,e,i){this.parentCanvas=t,this.parentElement=e,this.store=i,this.canvas=document.createElement("canvas"),this.magnifierScreen=cn(),this.offscreen=cn(),this.magnifierSize=300,e.appendChild(this.canvas),this.canvas.style.backgroundRepeat="no-repeat",this.canvas.style.backgroundSize="100% 100%",this.canvas.style.position="absolute",this.canvas.style.top="0",this.canvas.style.left="0"}resize(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.offscreen.width=t,this.offscreen.height=e,this.offscreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.offscreen.getContext("2d").textBaseline="middle",this.magnifierScreen.width=this.magnifierSize+5,this.magnifierScreen.height=this.magnifierSize+5}renderMagnifier(){if(!this.magnifier)return;const t=this.magnifierSize/2,e=this.magnifierSize+5,i=this.magnifierScreen.getContext("2d");i.clearRect(0,0,e,e),i.lineWidth=5,i.save(),i.translate(2.5,2.5),i.save(),i.arc(t,t,t,0,2*Math.PI,!1),i.clip(),i.fillStyle=this.store.data.background||this.store.options.background||"#f4f4f4",i.fillRect(0,0,e,e),i.translate(-t,-t),i.scale(2,2);const n=(this.parentCanvas.mousePos.x+this.store.data.x)*this.store.dpiRatio,r=(this.parentCanvas.mousePos.y+this.store.data.y)*this.store.dpiRatio;[this.parentCanvas.canvasImageBottom.offscreen,this.parentCanvas.canvasImageBottom.animateOffsScreen,this.parentCanvas.offscreen,this.parentCanvas.canvasImage.offscreen,this.parentCanvas.canvasImage.animateOffsScreen].forEach((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<i.length;t++)if(-1!==i[t].type.indexOf("image")&&i[t].getAsFile()){e=!0;break}}if(e){const e=t.clipboardData.items;if(e)for(let t=0;t<e.length;t++)if(-1!==e[t].type.indexOf("image")&&e[t].getAsFile()){const{x:i,y:n}=this.mousePos,r=e[t].getAsFile();let o="gif"===e[t].type.slice(6)?"gif":"image";if(null!==r){let t;const e=new FileReader;e.onload=e=>{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<g.AddAnchor&&(this.hotkeyType=g.None)},this.ondrop=async t=>{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.locked<o.DisableMove&&t?.onMouseMove?.(t,this.mousePos)}return void this.movePens(t)}}}if(this.drawingLine){const e={...t};if(e.id=et(),e.penId=this.drawingLine.id,this.store.options.disableDock||this.store.options.disableLineDock||(this.clearDock(),this.dock=de(this.store,e),this.dock?.xDock&&(e.x+=this.dock.xDock.step),this.dock?.yDock&&(e.y+=this.dock.yDock.step)),this.mouseDown&&"curve"===this.drawingLineName&&!this.drawingLine.calculative.worldAnchors[0].connectTo)this.drawline(e);else{let i;if(this.drawingLine.calculative.worldAnchors.length>1&&(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.x<t.x&&(e>0?e-=180:e+=180)):t.y>i.y?e=90:t.y<i.y&&(e=-90);let r=999,o=-1;for(let t=0;t<n.length;t++)e<0?Math.abs(e+n[t])<r&&(o=t,r=Math.abs(e+n[t])):Math.abs(e-n[t])<r&&(o=t,r=Math.abs(e-n[t]));e=e<0?-n[o]:n[o];let s=Math.sqrt((t.x-i.x)*(t.x-i.x)+(t.y-i.y)*(t.y-i.y));i.x=t.x+Math.cos(e/180*Math.PI)*s,i.y=t.y-Math.sin(e/180*Math.PI)*s}this.drawline()}}globalThis.debug&&console.time("hover");const e=performance.now();e-this.hoverTimer>50&&(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;t<i.length-1;t++){const n=i[t],r=i[t+1];if(n.next||r.prev){if(ai(n,r,e))return!0}else if(si(n,r,e))return!0}return!1}(t,this.dragRect):void 0)));this.active(t)}2!==t.button&&(_(this.mouseDown,t)<2&&(this.store.hover&&this.store.hover.input&&this.showInput(this.store.hover),this.store.emitter.emit("click",{x:t.x,y:t.y,pen:this.store.hover})),this.store.emitter.emit("mouseup",{x:t.x,y:t.y,pen:this.store.hover})),this.willInactivePen&&(this.willInactivePen.calculative.active=void 0,Zt(this.willInactivePen,!1),this.store.active.splice(this.store.active.findIndex((t=>t===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-10<e?this.store.pointAt.x=e:this.store.pointAt.x+10>n&&(this.store.pointAt.x=n),this.store.pointAt.y-10<i?this.store.pointAt.y=i:this.store.pointAt.y+10>r&&(this.store.pointAt.y=r)}break}}}}return i},this.dockInAnchor=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<this.store.options.interval)return this.renderTimer&&cancelAnimationFrame(this.renderTimer),void(this.renderTimer=requestAnimationFrame(this.render));this.renderTimer=void 0,this.lastRender=e;const i=this.offscreen.getContext("2d");i.clearRect(0,0,this.offscreen.width,this.offscreen.height),i.save(),i.translate(this.store.data.x,this.store.data.y),globalThis.debugRender&&console.time("renderPens"),this.renderPens(),globalThis.debugRender&&console.timeEnd("renderPens"),this.renderBorder(),this.renderHoverPoint(),i.restore(),this.magnifierCanvas.render();const n=this.canvas.getContext("2d");n.clearRect(0,0,this.canvas.width,this.canvas.height),n.drawImage(this.offscreen,0,0,this.width,this.height),this.canvasImageBottom.render(),this.canvasImage.render(),this.patchFlags=!1},this.renderPens=()=>{const 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,"&nbsp;").split(/[\s\n]/).join("</div><div>")}</div>`.replace("</div>","").replace(/\<div\>\<\/div\>/g,"<div><br></div>");this.inputDiv.innerHTML=r,this.inputParent.style.left=n.x+this.store.data.x-(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;t<document.styleSheets.length;t++)"le5le.com"===document.styleSheets[t].title&&(e=document.styleSheets[t]);let i="overflow: scroll;",n="",r=1;const{scale:o}=this.store.data;if(t.fontSize<12&&(r=12/t.fontSize),t.textAlign?i+=`text-align: ${t.textAlign};`:i+="text-align: center;",t.textAlign&&"pre-line"===t.whiteSpace&&(i+=`align-items: ${{left:"start",center:"center",right:"end"}[t.textAlign]};`),t.textBaseline?i+=`justify-content: ${{top:"start",middle:"center",bottom:"end"}[t.textBaseline]};`:i+="justify-content: center;",t.fontFamily&&(i+=`font-family: ${t.fontFamily};`),t.fontSize&&(t.fontSize*o<12?(i+=`font-size:${t.fontSize}px;`,i+=`zoom:${t.fontSize/12*o};`):i+=`font-size:${t.fontSize*o}px;`),i+=`color:${wt(t,this.store)};`,t.fontStyle&&(i+=`font-style: ${t.fontStyle};`),t.fontWeight&&(i+=`font-weight: ${t.fontWeight};`),t.textLeft&&(i+=`margin-left:${o>1?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&&(s<t.fontSize?i+=`width:${1.2*t.fontSize*r}px;`:i+=`width:${o>1?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(/\<div\>/g,"\n").replace(/\<\/div\>/g,"").replace(/\<br\>/g,"").replace(/&nbsp;/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(/\<div\>/g,"\n").replace(/\<\/div\>/g,"").replace(/\<br\>/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.x<e.x?this.movingAnchor.x=e.x:this.movingAnchor.x>e.ex&&(this.movingAnchor.x=e.ex),this.movingAnchor.y<e.y?this.movingAnchor.y=e.y:this.movingAnchor.y>e.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<n&&o<20))return;a=-i,l=this.height,u=1}this.addPen({isRuleLine:!0,type:r.Line,name:"line",lineName:"line",x:s,y:a,width:c,height:l,color:this.store.options.ruleLineColor,anchors:[{x:0,y:0},{x:h,y:u}]})}movedActivePens(t){const e=K(this.store.active,!0);this.store.active.forEach(((t,e)=>{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<this.store.histories.length-1&&this.store.histories.splice(this.store.historyIndex+1,this.store.histories.length-this.store.historyIndex-1),t.pens?.forEach((e=>{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;h<p-1;h++){if(r=t[h],o=t[h+1],d=Math.abs(w(r.x-n.x,r.y-n.y,o.x-r.x,o.y-r.y)),s)if(d<3.14*e)if(i&&(s=Math.min(s,a),a=s),c=(v+g)/2,l=(y+m)/2,u=Math.sqrt(c*c+l*l),0===u)f.push({...r});else{c/=u,l/=u;const t={...r};t.prevNextType=T.Bilateral,t.prev={penId:t.penId,x:r.x-c*s*.25,y:r.y-l*s*.25},t.next={penId:t.penId,x:r.x+c*a*.25,y:r.y+l*a*.25},f.push(t)}else f.push({...r});n=r}return f.push({...t[t.length-1]}),f}(t),this.pencilLine.calculative.worldAnchors.length>1&&(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.store.active.length;t++){const e=this.store.active[t];(e.anchors[0]?.connectTo||e.anchors[e.anchors.length-1]?.connectTo)&&(this.store.active.splice(t,1),e.calculative.active=void 0,--t)}this.movingPens=K(this.store.active,!0);const t=this.getAllByPens(this.movingPens),e=K(t,!0);t.forEach((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<t.calculative.worldAnchors.length&&(a=t.anchors[e],a);e++)if(null==l&&(l=a.y===c.y),!0===l){if(a.y!==c.y)break;t.calculative.worldAnchors[e].y=i.y}else{if(a.x!==c.x)break;t.calculative.worldAnchors[e].x=i.x}e.y=i.y}else{if(e.y=i.y,r.connectTo&&di(t,e,!0))return void(a&&a.x!==e.x&&(a.y=e.y));if(o.connectTo&&di(t,e,!1))return void(s&&s.x!==e.x&&(s.y=e.y));const c=t.anchors[n];let l;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<t.calculative.worldAnchors.length&&(a=t.anchors[e],a);e++)if(null==l&&(l=a.x===c.x),!0===l){if(a.x!==c.x)break;t.calculative.worldAnchors[e].x=i.x}else{if(a.y!==c.y)break;t.calculative.worldAnchors[e].y=i.y}e.x=i.x}}(r,this.store.activeAnchor,t);this.patchFlagsLines.add(r),this.store.path2dMap.set(r,M.path2dDraws[r.name](r)),this.render(),this.store.active[0].calculative&&(this.store.active[0].calculative.gradientAnimatePath=void 0),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0,this.pushHistory({type: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<o.DisableMove)&&0!=t.visible));t.length&&(1===t.length?(this.activeRect=K(t[0].calculative.worldRect),this.activeRect.rotate=t[0].calculative.rotate||0,ke(this.activeRect)):(this.activeRect=Ae(t),this.activeRect.rotate=0),this.lastRotate=0,this.getSizeCPs())}rotatePen(t,e,i){t.type?(t.calculative.worldAnchors.forEach((t=>{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.lastAnimateRender<this.store.options.animateInterval)return void(this.store.animates.size>0&&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;n<e.connectedLines.length;n++){const{lineId:r}=e.connectedLines[n],o=i.find((t=>t.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;e<t.connectedLines.length;e++){const{lineId:i,lineAnchor:n}=t.connectedLines[e],r=this.store.pens[i];if(r){let e=r.anchors.find((t=>t.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<document.styleSheets.length;e++)"le5le.com"===document.styleSheets[e].title&&(t=document.styleSheets[e]);if(!t){const e=document.createElement("style");e.title="le5le.com",document.head.appendChild(e),t=e.sheet,t.insertRule(".meta2d-input{display:none;position:absolute;outline:none;align-items: center;}"),t.insertRule(".meta2d-input textarea{resize:none;border:none;outline:none;background:transparent;flex-grow:1;height:100%;left:0;top:0}"),t.insertRule(".meta2d-input .right{width:10px;height:10px;flex-shrink:0;border-top: 1px solid;border-right: 1px solid;margin-right: 5px;transition: all .3s cubic-bezier(.645,.045,.355,1);position:absolute;right:1px;}"),t.insertRule(".meta2d-input ul{position:absolute;top:100%;left:-5px;width:calc(100% + 10px);min-height:30px;border-radius: 2px;box-shadow: 0 2px 8px #00000026;list-style-type: none;background-color: #fff;padding: 4px 0;max-height: 105px;overflow-y: auto;}"),t.insertRule(".meta2d-input ul li{padding: 5px 12px;line-height: 22px;white-space: nowrap;cursor: pointer;}"),t.insertRule(".meta2d-input ul li:hover{background: #eeeeee;}"),t.insertRule(".input-div::-webkit-scrollbar {display:none}"),t.insertRule(".meta2d-input .input-div{resize:none;border:none;outline:none;background:transparent;flex-grow:1;height:100%;width: 100%;left:0;top:0;display:flex;text-align: center;justify-content: center;flex-direction: column;}"),t.insertRule(".input-div div{}")}this.inputDiv.onclick=t=>{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;t<this.dropdown.childNodes.length;t++)this.dropdown.childNodes[t].remove(),--t}dropdownAppendOption(t,e){const i=document.createElement("li");i.onwheel=this.stopPropagation,i.innerText=t,i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.title=t,i.style.zoom=this.store.data.scale,i.onmousedown=this.stopPropagation,i.dataset.i=e+"",i.onclick=this.selectDropdown,this.dropdown.appendChild(i)}find(t){return this.store.data.pens.filter((e=>e.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;t<document.styleSheets.length;t++)"le5le/map"===document.styleSheets[t].title&&(e=document.styleSheets[t]);if(!e){let t=document.createElement("style");t.type="text/css",t.title="le5le.com/map",document.head.appendChild(t),t=document.createElement("style"),t.type="text/css",document.head.appendChild(t),e=t.sheet,e.insertRule(`.meta2d-map{display:flex;width:${this.boxWidth+2*this.padding}px;height:${this.boxHeight+2*this.padding}px;padding:${this.padding}px;background:#f4f4f4;border:1px solid #ffffff;box-shadow: 0px 0px 14px 0px rgba(0,10,38,0.30);border-radius:8px;position:absolute;z-index:9999;right:0;bottom:0;justify-content:center;align-items:center;cursor:default;user-select:none;overflow: hidden;}`),e.insertRule(".meta2d-map img{max-width:100%;max-height:100%;pointer-events: none;}"),e.insertRule(".meta2d-map div{pointer-events: none;border:1px solid #1890ff;position:absolute}")}}show(){this.box.style.display="flex",this.parent.store.data.pens.length?(this.img.style.display="block",this.img.src=this.parent.toPng(),this.setView()):this.img.style.display="none",this.isShow=!0}hide(){this.box.style.display="none",this.isShow=!1}setView(){const t=this.parent.store.data;if(t.pens.length){const e=Ae(t.pens);if(Re(e,t.x,t.y),e.width/e.height>this.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<t.length;i++){const n=t[i];"width"===e?this.setValue({id:n.id,width:r},{render:!1,doEvent:!1}):"height"===e?this.setValue({id:n.id,height:o},{render:!1,doEvent:!1}):this.setValue({id:n.id,width:r,height:o},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:F.Update,initPens:i,pens:t})}formatPainterByFirst(t=this.store.data.pens){const e=K(t),i=t[0],n={};p.forEach((t=>{n[t]=i[t]}));for(let e=1;e<t.length;e++){const i=t[e];this.setValue({id:i.id,...n},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:F.Update,initPens:e,pens:t})}alignNodes(t,e=this.store.data.pens,i){!i&&(i=this.getPenRect(this.getRect(e)));const n=K(e);for(const n of e)this.alignPen(t,n,i);this.render(),this.pushHistory({type:F.Update,initPens:n,pens:e})}alignNodesByFirst(t,e=this.store.data.pens){const i=K(e),n=e[0],r=this.getPenRect(n);for(let i=1;i<e.length;i++){const n=e[i];this.alignPen(t,n,r)}this.render(),this.pushHistory({type:F.Update,initPens:i,pens:e})}alignPen(t,e,i){const n=this.getPenRect(e);switch(t){case"left":n.x=i.x;break;case"right":n.x=i.x+i.width-n.width;break;case"top":n.y=i.y;break;case"bottom":n.y=i.y+i.height-n.height;break;case"center":n.x=i.x+i.width/2-n.width/2;break;case"middle":n.y=i.y+i.height/2-n.height/2}this.setValue({id:e.id,...n},{render:!1,doEvent:!1})}spaceBetweenByDirection(t,e=this.store.data.pens,i){if(!i&&(i=this.getPenRect(this.getRect(e))[t]),(e=e.filter((t=>!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<e&&(i.splice(e,0,i[n]),i.splice(n,1)))}changePenId(t,e){this.canvas.changePenId(t,e)}getLines(t,e="all"){if(t.type===r.Line)return[];const i=[];return t.connectedLines?.forEach((({lineId: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<l?c:l;o<2*h&&(h=o/2),s<2*h&&(h=s/2),i.moveTo(n+h,r),i.arcTo(n+o,r,n+o,r+s,h),i.arcTo(n+o,r+s,n,r+s,h),i.arcTo(n,r+s,n,r,h),i.arcTo(n,r,n+o,r,h);const u=.2*s;i.moveTo(n,r+u),i.lineTo(a,r+u);const d=r+u+(s-u)/2;if(i.moveTo(n,d),i.lineTo(a,d),i.closePath(),i instanceof Path2D)return i}function Tn(t){const{x:e,y:i,width:n,height:r}=t.calculative.worldRect,o=t.list,s={name:"text",x:e,y:i+.2*r,width:n,height:.4*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10},a={name:"text",x:e,y:i+.6*r,width:n,height:.4*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10};Object.assign(s,o[0]),Object.assign(a,o[1]),t.calculative.canvas.makePen(s),t.calculative.canvas.makePen(a),t.calculative.canvas.parent.pushChildren(t,[s]),t.calculative.canvas.parent.pushChildren(t,[a])}function An(t){const e=t.calculative.canvas.store;t.children.forEach((t=>{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<l?c:l;o<2*h&&(h=o/2),s<2*h&&(h=s/2),i.moveTo(n+h,r),i.arcTo(n+o,r,n+o,r+s,h),i.lineTo(n+o,r+s-h),i.arcTo(n+o,r+s,n,r+s,h),i.arcTo(n,r+s,n,r,h),i.arcTo(n,r,n+o,r,h);const u=.2*s;if(i.moveTo(n,r+u),i.lineTo(a,r+u),i.closePath(),i instanceof Path2D)return i}function Pn(t){const{x:e,y:i,width:n,height:r}=t.calculative.worldRect,o=t.list;let s={name:"text",x:e,y:i+.2*r,width:n,height:.8*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10};Object.assign(s,o[0]),t.calculative.canvas.makePen(s),t.calculative.canvas.parent.pushChildren(t,[s])}function Cn(t){const e=t.calculative.canvas.store;t.children.forEach((t=>{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<l?c:l;o<2*h&&(h=o/2),i<2*h&&(h=i/2),t.beginPath(),t.moveTo(n+h,r),t.arcTo(n+o,r,n+o,r+i,h),t.arcTo(n+o,r+i,n,r+i,h),t.arcTo(n,r+i,n,r,h),t.arcTo(n,r,n+o,r,h),t.closePath(),t.stroke(),t.save(),t.beginPath(),t.lineWidth=1,t.setLineDash([7,7]);const u=n+o/2;t.moveTo(u,r+i+1),t.lineTo(u,a),t.stroke(),t.restore()}function In(){return{sequenceFocus:_n}}function Ln(){return{lifeline:En}}function Mn(t,e){const{x:i,y:n,width:r,height:o}=e.calculative.worldRect;t.beginPath(),t.ellipse(i+r/2,n+o/2,r/2,o/2,0,0,2*Math.PI),t.stroke(),t.beginPath(),t.fillStyle=t.strokeStyle,t.ellipse(i+r/2,n+o/2,r/4,o/4,0,0,2*Math.PI),t.fill()}function Dn(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s,ey:a}=t.calculative.worldRect,c=t.calculative.lineLeft||.08;let l=t.calculative.borderRadius||0,h=l;l<1&&(l*=o,h=s*l);let u=l<h?l:h;if(o<2*u&&(u=o/2),s<2*u&&(u=s/2),i.moveTo(n+u,r),i.arcTo(n+o,r,n+o,r+s,u),i.arcTo(n+o,r+s,n,r+s,u),i.arcTo(n,r+s,n,r,u),i.arcTo(n,r,n+o,r,u),i.closePath(),i.moveTo(n+c*o,r),i.lineTo(n+c*o,a),i instanceof Path2D)return i}function Bn(t,e){const i=e||new Path2D,{x:n,y:r,width:o,height:s,ex:a}=t.calculative.worldRect,c=t.calculative.lineTop||.08;let l=t.calculative.borderRadius||0,h=l;l<1&&(l*=o,h*=s);let u=l<h?l:h;if(o<2*u&&(u=o/2),s<2*u&&(u=s/2),i.moveTo(n+u,r),i.arcTo(n+o,r,n+o,r+s,u),i.arcTo(n+o,r+s,n,r+s,u),i.arcTo(n,r+s,n,r,u),i.arcTo(n,r,n+o,r,u),i.closePath(),i.moveTo(n,r+c*s),i.lineTo(a,r+c*s),i instanceof Path2D)return i}function Nn(){return{forkV:t,forkH:t,swimlaneH:Dn,swimlaneV:Bn}}function On(){return{activityFinal:Mn}}function zn(t,e){const i=e||new Path2D,{x:n,y:r,width:o,ey:s}=t.calculative.worldRect,a=o/4;if(i.moveTo(n+a,r),i.lineTo(n,r),i.lineTo(n,s),i.lineTo(n+a,s),i instanceof Path2D)return i}function Fn(t){t.anchors=[{x:.25,y:0},{x:.25,y:1},{x:0,y:.5}].map((({x:e,y:i},n)=>({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<t.length;n++)Array.isArray(e.grid)?e.grid.forEach((e=>{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<t.length;n++)e.dataZoom.forEach((e=>{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<r.length;e++){const i=r[e],n=t;for(const i of o){const n=i.data[e];void 0!==n&&(i.figures[e].setDimensions({x:t,y:0,width:10,height:n}),t+=12.5)}i.tick.setValue((n+t-2.5)/2),t+=7.5}a.setInterval(-10,t)})()},addGroups:t=>{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<e.rowPos.length;i++)for(let n=0;n<e.colPos.length;n++){let r,o=Lr(e,i,n),s=o.color||e.color,a=o.background;e.calculative.activeCell?.row===i&&e.calculative.activeCell?.col===n&&(s=e.activeColor,a=e.activeBackground,r=s),e.calculative.hoverCell?.row===i&&e.calculative.hoverCell?.col===n&&(s=e.hoverColor,a=e.hoverBackground,r=s);const c=Dr(e,i,n);a&&(t.save(),t.fillStyle=a,t.fillRect(c.x,c.y,c.width,c.height),t.restore()),r&&(t.save(),t.strokeStyle=r,t.strokeRect(c.x,c.y,c.width,c.height),t.restore()),e.calculative.worldTextRect=c;let l=e.calculative.texts[i];if(e.calculative.texts[i]||(l=[],e.calculative.texts.push(l)),null==l[n]){if(Array.isArray(o)){l[n]="",o[0].id||(Br(e,c,o),e.calculative.canvas.parent.pushChildren(e,o));continue}if(l[n]=o.text||o+"",!l[n])continue;l[n]=U(e,l[n])}if(l[n]){if(t.save(),t.fillStyle=s,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===l[n].length)t.fillText(l[n][0],c.x+c.width/2,c.y+c.height/2);else{const i=.55,r=e.calculative.fontSize*e.calculative.lineHeight*1,o=l[n].length*r;let s=(c.height-o)/2;l[n].forEach(((e,n)=>{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;n<t.colPos.length;n++)e.x>t.calculative.worldRect.x+t.colPos[n]*i&&(r.col=n+1);for(let i=0;i<t.rowPos.length;i++)e.y>t.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.width?(t.x=e.x+s+10*n,t.y=e.y+a+10*r,s+=(t.width+10)*n,o=Math.max(o,a+(t.height+10)*r)):(s=0,a=o,t.x=e.x+s+10*n,t.y=e.y+a+10*r,o+=(t.height+10)*r);if(o+20*r<e.height){const t=(e.height-o-10*r)/2;for(const e of i)e.y+=t}}function Nr(t){t.calculative.texts=void 0}function Or(t,e){return e.table||null==e.col&&null==e.row||(Mr(t,e.row,e.col,e.value),t.calculative.canvas.render(),delete e.col,delete e.row),e}function zr(t,e){const i=14*e.calculative.worldRect.height/16,n=(t.match(/[\u4e00-\u9fa5]/g)||"").length;return(t.length-n)*i*.6+n*i}function Fr(t){if("horizontal"==t.direction){const e=[];let i=0;const n=t.height;t.checkboxHeight=n,t.options.forEach(((r,o)=>{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;i<e.rowPos.length;i++)for(let n=0;n<e.colPos.length;n++){let{value:r,style:o}=Xr(e,i,n),s=!1;o.wheres&&Array.isArray(o.wheres)&&(s=!1,s=o.wheres.every((function(t){return new Function("attr",`return attr ${t.comparison} ${t.value}`)(r)})));let a,c=e.textColor||e.color,l=null;s&&(c=o.color||e.color,l=o.background),e.calculative.activeCell?.row===i&&e.calculative.activeCell?.col===n&&(c=e.activeColor,l=e.activeBackground,a=c),e.calculative.hoverCell?.row===i&&e.calculative.hoverCell?.col===n&&(c=e.hoverColor,l=e.hoverBackground,a=c);const h=Gr(e,i,n);l&&(t.save(),t.fillStyle=l,t.fillRect(h.x,h.y,h.width,h.height),t.restore()),a&&(t.save(),t.strokeStyle=a,t.strokeRect(h.x,h.y,h.width,h.height),t.restore()),e.calculative.worldTextRect=h;let u=e.calculative.texts[i];if(e.calculative.texts[i]||(u=[],e.calculative.texts.push(u)),null==u[n]){if("object"==typeof r){const t=e.styles&&e.styles.filter((t=>t.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;i<t.data[0].length;i++)n+=(o[i]||t.colWidth)*t.calculative.canvas.store.data.scale,e.push(n);let s=0;const a=t.styles&&t.styles.filter((t=>void 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.data.length;e++)s+=(c[e]||t.rowHeight)*t.calculative.canvas.store.data.scale,i.push(s);t.colPos=e,t.rowPos=i,t.tableWidth=n,t.tableHeight=s,t.width=n,t.height=s,t.calculative.width=n,t.calculative.height=s,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)}(t)}function Ur(t,e){if(!t.calculative.hoverCell)return;const{value:i}=Xr(t,t.calculative.hoverCell.row,t.calculative.hoverCell.col);if("object"==typeof i)return;t.calculative.isHover=!1,t.calculative.isInput=!0,t.calculative.canvas.render(),t.calculative.inputCell=t.calculative.hoverCell;const n=Gr(t,t.calculative.hoverCell.row,t.calculative.hoverCell.col);t.calculative.tempText=i.text||i+"",t.calculative.canvas.showInput(t,n,"#ffffff")}function Wr(t,e){t.calculative.inputCell&&($r(t,t.calculative.inputCell.row,t.calculative.inputCell.col,e),t.calculative.isInput=!1,t.calculative.isHover=!0,t.calculative.canvas.render())}function qr(t,e){t.timer&&(t.calculative.isHover=!1,clearTimeout(t.timer)),t.timer=setTimeout((()=>{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;n<t.colPos.length;n++)e.x>t.calculative.worldRect.x+t.colPos[n]*i&&(r.col=n+1);for(let i=0;i<t.rowPos.length;i++)e.y>t.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<e.width?(t.x=e.x+s+10*c*n,t.y=e.y+a+10*c*r,s+=(t.width+10*c)*n,o=Math.max(o,a+(t.height+10*c)*r)):(s=0,a=o,t.x=e.x+s+10*c*n,t.y=e.y+a+10*c*r,o+=(t.height+10*c)*r);if(o+20*c*r<e.height){const t=(e.height-o-10*c*r)/2;for(const e of i)e.y+=t}}function Jr(t){if(t.calculative.isUpdateData){Hr(t),delete t.calculative.isUpdateData;let e=t.children;t.children=[],e&&e.forEach((e=>{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);n<t.min||n>t.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;s<e.optionPos.length;s++){const a=e.optionPos[s]*o/e.checkboxWidth,c=e.options[s].isForbidden;t.beginPath(),t.arc(i+a+r/2,n+r/2,r/2,0,2*Math.PI),t.strokeStyle="#d9d9d9",t.fillStyle="#ffffff00",e.options[s].text===e.checked&&(t.strokeStyle=e.options[s].background||e.background||"#1890ff"),c&&(t.fillStyle="#ebebeb",t.strokeStyle="#d9d9d9"),t.closePath(),t.fill(),t.stroke(),t.save(),c||e.options[s].text!==e.checked||(t.beginPath(),t.strokeStyle=e.options[s].background?e.options[s].background+"20":e.background||"#1890ff20",t.arc(i+r/2+a,n+r/2,r/2+1.5,0,2*Math.PI),t.stroke(),t.closePath(),t.beginPath(),t.fillStyle=e.options[s].background||e.background||"#1890ff",t.arc(i+r/2+a,n+r/2,r/4,0,2*Math.PI),t.fill(),t.closePath()),t.restore(),t.save(),t.fillStyle=c?"#00000040":e.textColor||e.color||"#000000d9";const l=14*e.calculative.worldRect.height/16;t.textAlign="start",t.textBaseline="middle",t.font=(e.calculative.fontStyle||"")+" normal "+(e.calculative.fontWeight||"")+" "+l+"px "+e.calculative.fontFamily,t.fillText(e.options[s].text,i+r+a+10/e.checkboxWidth*o,n+r/2),t.restore()}else if("vertical"==e.direction){const o=e.optionHeight*r/e.checkboxHeight;for(let s=0;s<e.optionPos.length;s++){const a=e.optionPos[s]*r/e.checkboxHeight,c=e.options[s].isForbidden;t.beginPath(),t.arc(i+o/2,n+o/2+a,o/2,0,2*Math.PI),t.strokeStyle="#d9d9d9",t.fillStyle="#ffffff00",e.options[s].text===e.checked&&(t.strokeStyle=e.options[s].background||"#1890ff"),c&&(t.fillStyle="#ebebeb",t.strokeStyle="#d9d9d9"),t.closePath(),t.fill(),t.stroke(),t.save(),c||e.options[s].text!==e.checked||(t.beginPath(),t.strokeStyle=e.options[s].background?e.options[s].background+"20":"#1890ff20",t.arc(i+o/2,n+o/2+a,o/2+1.5,0,2*Math.PI),t.stroke(),t.closePath(),t.beginPath(),t.fillStyle=e.options[s].background||"#1890ff",t.arc(i+o/2,n+o/2+a,o/4,0,2*Math.PI),t.fill(),t.closePath()),t.restore(),t.save(),t.fillStyle=c?"#00000040":"#000000d9";const l=14*e.calculative.worldRect.height/e.checkboxHeight;t.textAlign="start",t.textBaseline="middle",t.font=(e.calculative.fontStyle||"")+" normal "+(e.calculative.fontWeight||"")+" "+l+"px "+e.calculative.fontFamily,t.fillText(e.options[s].text,i+o+10,n+o/2+a),t.restore()}}}function fo(t){Fr(t)}function po(t,e){if("horizontal"==t.direction)for(let i=0;i<t.optionPos.length;i++)!t.options[i].isForbidden&&e.x>t.calculative.worldRect.x+t.optionPos[i]*t.calculative.worldRect.width/t.checkboxWidth&&e.x<t.calculative.worldRect.x+(t.optionPos[i]+t.height)/t.checkboxWidth*t.calculative.worldRect.width+zr(t.options[i].text,t)+10/t.checkboxWidth*t.calculative.worldRect.width&&(t.checked=t.options[i].text,t.calculative.canvas.store.emitter.emit("valueUpdate",t));else if("vertical"==t.direction){const i=t.calculative.worldRect.height/t.checkboxHeight;for(let n=0;n<t.optionPos.length;n++)!t.options[n].isForbidden&&e.y>t.calculative.worldRect.y+t.optionPos[n]*i&&e.y<t.calculative.worldRect.y+(t.optionPos[n]+t.optionHeight)*i&&(t.checked=t.options[n].text,t.calculative.canvas.store.emitter.emit("valueUpdate",t))}t.calculative.canvas.render()}function vo(t){Fr(t)}function go(){return{radio:uo,switch:ao,slider:to,checkbox:lo,table:Ar,table2:jr}}function yo(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+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 mo(t){t.anchors=[{x:.5,y:0},{x:.25,y:1},{x:.5,y:1},{x:.75,y:1}].map((({x:e,y:i},n)=>({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;t<e.echarts.option.series.length;t++)s.push(e.echarts.option.series[t].data);else s=e.data;let a=[];for(let t=0;t<s.length;t++)a=a.concat(s[t]);let c=function(t){t={max:null,min:null,splitNumber:4,symmetrical:!1,deviation:!1,preferZero:!1,...t};const e=[10,15,20,25,30,40,50,60,70,80,90,100,150];let{max:i,min:n,splitNumber:r,symmetrical:o,deviation:s,preferZero:a}=t;if(!Ho(i)||!Ho(n)||i<n)return{splitNumber:r};if(i===n&&0===i)return{max:jo(e[0]*r),min:n,interval:e[0],splitNumber:r};i===n&&(a=!0),(!Ho(r)||r<=0)&&(r=4),a&&i*n>0&&(i<0?i=0:n=0);const c=(i-n)/r;let l=Math.floor(Math.log10(c)-1);l=Math.pow(10,l);const h=c/l;let u,d=e[0]*l,f=-1;for(u=0;u<e.length;u++)if(e[u]>h){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<r;)if(v-n<=p-i&&0!==v||0===p?v-=d:p+=d,t++,t===r)break t;if(u>=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<c.splitNumber+1;e++){let s=e*o/c.splitNumber;t.textAlign="right",t.textBaseline="middle",t.fillText(c.max-e*c.interval+"",i-10,n+s),t.fill(),e<c.splitNumber&&(t.moveTo(i,n+s),t.lineTo(i+r,n+s),t.stroke())}t.closePath(),t.beginPath(),t.strokeStyle="#BFBFBF";let u=e.echarts?e.echarts.option.xAxis.data:e.xAxisData,d=0;for(let e=0;e<u.length;e++)d=i+(1+h/2)+(h+1)*e,t.textAlign="center",t.textBaseline="top",t.fillText(u[e],d,n+o+10),t.fill();return t.closePath(),t.setLineDash([]),{dash:h,normalizedOption:c}}function Wo(t,e){if(!isNaN(t))return-1===e?t:Math.round(1e3*Number(t))/1e3}var qo;function Vo(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=[];e.echarts&&!e.echarts.option.color&&(e.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]);let s=Uo(t,e),a=s.dash,c=s.normalizedOption;const l=!!(e.echarts?e.echarts.option.series[0].smooth:e.smooth);let h=[];if(e.echarts)for(let t=0;t<e.echarts.option.series.length;t++)o.push(e.echarts.option.series[t].data);else o=e.data;for(let s=0;s<o.length;s++){t.beginPath();let u=o[s];t.strokeStyle=e.echarts?e.echarts.option.color[s]:e.chartsColor[s],t.fillStyle=e.echarts?e.echarts.option.color[s]:e.chartsColor[s];let d=i+(1+a/2),f=n+r-(u[0]-c.min)/(c.max-c.min)*r;if(t.moveTo(d,f),h.push({x:d,y:f}),l)if(u.length<=2)for(let e=1;e<u.length;e++)d=i+(1+a/2)+(a+1)*e,f=n+r-(u[e]-c.min)/(c.max-c.min)*r,t.lineTo(d,f),h.push({x:d,y:f});else{let e,o,s,l;u.forEach(((p,v)=>{d=i+(1+a/2)+(a+1)*v,f=n+r-(u[v]-c.min)/(c.max-c.min)*r;let 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<u.length;e++)d=i+(1+a/2)+(a+1)*e,f=n+r-(u[e]-c.min)/(c.max-c.min)*r,t.lineTo(d,f),h.push({x:d,y:f});t.stroke(),t.closePath(),h.forEach(((e,i)=>{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;l<a.length;l++){let h=a[l],u=r/2;o<r&&(u=o/2);const d=i+r/2,f=n+o/2;let p=0;p=s?h.data.reduce(((t,e)=>t+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;t<e.echarts.option.series.length;t++)o.push(e.echarts.option.series[t].data);else o=e.data;let s=Uo(t,e),a=s.dash,c=s.normalizedOption,l=4*a/5/o.length;for(let s=0;s<o.length;s++){t.beginPath();let h=o[s];t.fillStyle=e.echarts?e.echarts.option.color[s]:e.chartsColor[s],t.strokeStyle="#ffffff";let u=0,d=0,f=0;for(let e=0;e<h.length;e++)u=i+(1+.1*a)+(a+1)*e+l*s,f=(h[e]-c.min)/(c.max-c.min)*r,d=n+r-f,t.rect(u,d,l-1,f-1),t.stroke(),t.fill();t.closePath()}}function Go(t,e){e.onAdd||(e.onAdd=Qo,e.onDestroy=Jo,e.onClick=Zo);const i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,r=e.calculative.worldRect.width,o=e.calculative.worldRect.height;let s={startAngle:225,endAngle:-45,min:0,max:100,splitNumber:10};if(e.echarts&&e.echarts.option){let t=e.echarts.option.series[0];e.startAngle=t.startAngle||s.startAngle,e.endAngle=t.endAngle||s.endAngle,e.min=t.min||s.min,e.max=t.max||s.max,e.axisLine=t.axisLine.lineStyle.color,e.unit=t.detail.formatter.replace("{value}",""),e.value=t.data[0].value,e.splitNumber=t.splitNumber||s.splitNumber}let a,c=r>o?o/2*9/10:r/2*9/10,l=i+r/2,h=n+o/2,u=(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)<u?v=e.axisLine[i][0]:(v=(u-e.min)/(e.max-e.min),a=e.axisLine[i][1]),t.beginPath(),t.strokeStyle=e.axisLine[i][1],t.arc(l,h,c,-e.startAngle/180*Math.PI,(-e.startAngle+v*d)/180*Math.PI),t.stroke(),t.closePath();t.lineCap="butt";let g=c-p;g<0&&(g=0);let y=d/180*Math.PI*g,m=(y-2*e.splitNumber)/e.splitNumber,w=d/180*Math.PI*2/2/y;t.beginPath(),t.strokeStyle=e.color||"#999999",t.lineWidth=c/20,t.setLineDash([2,m]),t.arc(l,h,g,-e.startAngle/180*Math.PI-w,-e.endAngle/180*Math.PI+w),t.stroke(),t.closePath();let b=c-p;b<0&&(b=0);let x=d/180*Math.PI*b,k=(x-5*e.splitNumber)/5/e.splitNumber,T=d/180*Math.PI*1/2/x;t.beginPath(),t.strokeStyle=e.color||"#999999",t.lineWidth=c/40,t.setLineDash([1,k]),t.arc(l,h,b,-e.startAngle/180*Math.PI-T,-e.endAngle/180*Math.PI+T),t.stroke(),t.closePath(),t.beginPath();let A=e.max-e.min,S=A/e.splitNumber;t.font=(e.calculative.fontStyle||"")+" normal "+(e.calculative.fontWeight||"")+" "+c/10+"px "+e.calculative.fontFamily;let P=c-p-c/20;for(let i=0;i<=e.splitNumber;i++){if(Math.abs(e.startAngle)+Math.abs(e.endAngle)===360&&0==i)continue;let n=e.startAngle-S*i/A*d,r=Math.cos(n/180*Math.PI),o=Math.sin(n/180*Math.PI);t.fillStyle="#999999",t.textAlign=r>.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;i<C;i++){let n=(e.startAngle-(e[R[i]]-e.min)/(e.max-e.min)*d)/180*Math.PI;i>0&&(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})()));