diff --git a/src/BootstrapBlazor.Shared/Samples/Topologies.razor.cs b/src/BootstrapBlazor.Shared/Samples/Topologies.razor.cs index 949af6118c0c613045639ebeddefe2ca8015e3b5..503aa00bd77d0247eb1cf70ea3803e4ded8d4a1b 100644 --- a/src/BootstrapBlazor.Shared/Samples/Topologies.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/Topologies.razor.cs @@ -61,13 +61,6 @@ public partial class Topologies : IDisposable { Interop = new JSInterop(JSRuntime); await Interop.InvokeVoidAsync(this, null, "bb_topology_demo", nameof(ToggleFan)); - - // 推送数据 - var data = DataService.GetDatas(); - await TopologyElement.PushData(data); - - // 数据订阅 - DataService.OnDataChange = async datas => await TopologyElement.PushData(datas); } } @@ -97,6 +90,13 @@ public partial class Topologies : IDisposable private async Task OnBeforePushData() { await JSRuntime.InvokeVoidAsync("$.bb_topology_demo_setOptions"); + + // 推送数据 + var data = DataService.GetDatas(); + await TopologyElement.PushData(data); + + // 数据订阅 + DataService.OnDataChange = async datas => await TopologyElement.PushData(datas); } /// diff --git a/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs b/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs index cf335f0e666f784075a5e5a0d538fe7315d42220..4c8bf3f023927c244db50baa387ed6d46c4e3c19 100644 --- a/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs +++ b/src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs @@ -101,14 +101,11 @@ public abstract class BootstrapModuleComponentBase : IdComponentBase, IAsyncDisp /// protected virtual async ValueTask DisposeAsync(bool disposing) { - if (disposing) + if (Module != null && disposing) { - if (Module != null) - { - await Module.InvokeVoidAsync($"{ModuleName}.dispose", Id); - await Module.DisposeAsync(); - Module = null; - } + await Module.InvokeVoidAsync($"{ModuleName}.dispose", Id); + await Module.DisposeAsync(); + Module = null; } } diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/BootstrapBlazor.Topology.csproj b/src/Extensions/Components/BootstrapBlazor.Topology/BootstrapBlazor.Topology.csproj index ea014f0a1671c4f136836ae5ecd9ab8046d08e32..a278b97edab5d819999b3b1e9803d5923b812685 100644 --- a/src/Extensions/Components/BootstrapBlazor.Topology/BootstrapBlazor.Topology.csproj +++ b/src/Extensions/Components/BootstrapBlazor.Topology/BootstrapBlazor.Topology.csproj @@ -3,7 +3,7 @@ - 6.0.8 + 6.0.9 @@ -19,11 +19,7 @@ - - - - - + diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.js b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.js index 264a78c3d39b67e402415d80a78799edb61653c9..5e409667b51194ac449726c050ee3d29aa92c519 100644 --- a/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.js +++ b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.js @@ -1,25 +1,30 @@ -var topology = undefined; +import BlazorComponent from "../../../_content/BootstrapBlazor/modules/base/blazor-component.js" -export function init(id, data, method, obj) { - if (window.Topology) { - Topology.prototype.lock = function (status) { - this.store.data.locked = status; - this.finishDrawLine(!0); - this.canvas.drawingLineName = ""; - this.stopPencil(); - } +export class BlazorTopology extends BlazorComponent { + _init() { + if (window.Topology) { + Topology.prototype.lock = function (status) { + this.store.data.locked = status + this.finishDrawLine(!0) + this.canvas.drawingLineName = "" + this.stopPencil() + } + + const obj = this._config.arguments[0] + const data = this._config.arguments[1] + const method = this._config.arguments[2] - topology = new Topology(id); - topology.connectSocket = function () { - }; - topology.open(JSON.parse(data)); - topology.lock(1); - obj.invokeMethodAsync(method); + this._topology = new Topology(this._element.getAttribute('id')) + this._topology.connectSocket = function () { + } + this._topology.open(JSON.parse(data)) + this._topology.lock(1) + obj.invokeMethodAsync(method) + } } -} -export function push_data(id, data) { - if (topology !== undefined) { - topology.doSocket(JSON.stringify(data)); + _execute(args) { + const data = args[1]; + this._topology.doSocket(JSON.stringify(data)) } } diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.min.js b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.min.js index afc87d1fc44708fec52e0a4a61a2b86c767d4401..65245059472ed11944adcab3b3233cfc5c348aab 100644 --- a/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.min.js +++ b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.min.js @@ -1 +1 @@ -export function init(t,i,r,u){window.Topology&&(Topology.prototype.lock=function(n){this.store.data.locked=n;this.finishDrawLine(!0);this.canvas.drawingLineName="";this.stopPencil()},n=new Topology(t),n.connectSocket=function(){},n.open(JSON.parse(i)),n.lock(1),u.invokeMethodAsync(r))}export function push_data(t,i){n!==undefined&&n.doSocket(JSON.stringify(i))}var n=undefined; \ No newline at end of file +import BlazorComponent from"../../../_content/BootstrapBlazor/modules/base/blazor-component.js";export class BlazorTopology extends BlazorComponent{_init(){if(window.Topology){Topology.prototype.lock=function(n){this.store.data.locked=n;this.finishDrawLine(!0);this.canvas.drawingLineName="";this.stopPencil()};const n=this._config.arguments[0],t=this._config.arguments[1],i=this._config.arguments[2];this._topology=new Topology(this._element.getAttribute("id"));this._topology.connectSocket=function(){};this._topology.open(JSON.parse(t));this._topology.lock(1);n.invokeMethodAsync(i)}}_execute(n){const t=n[1];this._topology.doSocket(JSON.stringify(t))}} \ No newline at end of file diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor index 1988fae3b6210efdc065e1733c18200178af55b6..25bdc332e509f65778ad5c8e34d9de755081642e 100644 --- a/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor +++ b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor @@ -1,4 +1,4 @@ @namespace BootstrapBlazor.Components -@inherits IdComponentBase +@inherits BootstrapModuleComponentBase
diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor.cs b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor.cs index 3dc9a4027b84e9a53129554d443bb46fcba64441..2fbca586be514c44a7848fad8f9d8aa3a800182b 100644 --- a/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor.cs +++ b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor.cs @@ -3,14 +3,14 @@ // Website: https://www.blazor.zone or https://argozhang.github.io/ using Microsoft.AspNetCore.Components; -using Microsoft.JSInterop; namespace BootstrapBlazor.Components; /// /// Topology 组件类 /// -public partial class Topology : IDisposable +[JSModuleAutoLoader("./_content/BootstrapBlazor.Topology/js/bootstrap.blazor.topology.min.js", ModuleName = "BlazorTopology", Relative = false)] +public partial class Topology { /// /// 获得/设置 JSON 文件内容 @@ -40,32 +40,21 @@ public partial class Topology : IDisposable [Parameter] public Func? OnBeforePushData { get; set; } - [NotNull] - private JSModule? Module { get; set; } - private string? StyleString => CssBuilder.Default("width: 100%; height: 100%;") .AddStyleFromAttributes(AdditionalAttributes) .Build(); private CancellationTokenSource? CancelToken { get; set; } - private bool isInited { get; set; } - /// - /// OnAfterRenderAsync 方法 + /// /// - /// /// - protected override async Task OnAfterRenderAsync(bool firstRender) + protected override async Task ModuleInitAsync() { - if (!isInited) + if (Module != null) { - if (!string.IsNullOrEmpty(Content)) - { - isInited = true; - Module = await JSRuntime.LoadModule("./_content/BootstrapBlazor.Topology/js/bootstrap.blazor.topology.min.js", this, false); - await Module.InvokeVoidAsync("init", Id, Content, nameof(PushData)); - } + await Module.InvokeVoidAsync($"{ModuleName}.init", Id, Content, nameof(PushData)); } } @@ -76,7 +65,7 @@ public partial class Topology : IDisposable [JSInvokable] public async Task PushData() { - if (!disposing) + if (!_disposing) { if (OnBeforePushData != null) { @@ -114,39 +103,27 @@ public partial class Topology : IDisposable /// public async ValueTask PushData(IEnumerable items, CancellationToken token = default) { - if (Module != null) + if (Module != null && !_disposing) { - await Module.InvokeVoidAsync("push_data", token, Id, items); + await Module.InvokeVoidAsync($"{ModuleName}.execute", token, Id, items); } } - private bool disposing = false; + private bool _disposing; /// - /// Dispose 方法 + /// DisposeAsync 方法 /// /// - protected virtual void Dispose(bool disposing) + protected override async ValueTask DisposeAsync(bool disposing) { - if (disposing) + _disposing = true; + if (CancelToken != null && disposing) { - if (CancelToken != null) - { - CancelToken.Cancel(); - CancelToken.Dispose(); - CancelToken = null; - } + CancelToken.Cancel(); + CancelToken.Dispose(); + CancelToken = null; } - } - - /// - /// Dispose 方法 - /// - /// - public void Dispose() - { - disposing = true; - Dispose(true); - GC.SuppressFinalize(this); + await base.DisposeAsync(disposing); } } diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/wwwroot/js/bootstrap.blazor.topology.min.js b/src/Extensions/Components/BootstrapBlazor.Topology/wwwroot/js/bootstrap.blazor.topology.min.js index 3981d2c7d7aaaa2bb384ba90d1d47c2f4f8c13f5..903759c677ccb8e540fd33258b0562ef5094aeab 100644 --- a/src/Extensions/Components/BootstrapBlazor.Topology/wwwroot/js/bootstrap.blazor.topology.min.js +++ b/src/Extensions/Components/BootstrapBlazor.Topology/wwwroot/js/bootstrap.blazor.topology.min.js @@ -1,2 +1,2 @@ !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,(function(){return(()=>{var t={176:(t,e,i)=>{t.exports=function t(e,i,n){function o(s,a){if(!i[s]){if(!e[s]){if(r)return r(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 o(e[s][1][t]||t)}),l,l.exports,t,e,i,n)}return i[s].exports}for(var r=void 0,s=0;sthis.emit("error",new Error("Packet has no Authentication Method")))),this;this.options.properties.authenticationMethod&&this.options.authPacket&&"object"==typeof this.options.authPacket&&m(this,u({cmd:"auth",reasonCode:0},this.options.authPacket))}this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout((function(){d("!!connectTimeout hit!! Calling _cleanUp with force `true`"),e._cleanUp(!0)}),this.options.connectTimeout)},b.prototype._handlePacket=function(t,e){var i=this.options;if(5===i.protocolVersion&&i.properties&&i.properties.maximumPacketSize&&i.properties.maximumPacketSizer.properties.topicAliasMaximum||!r.properties.topicAliasMaximum&&i.properties.topicAlias))&&delete o.properties.topicAlias),d("publish :: qos",i.qos),i.qos){case 1:case 2:this.outgoing[o.messageId]={volatile:!1,cb:n||x},this._storeProcessing?(d("_storeProcessing enabled"),this._packetIdsDuringStoreProcessing[o.messageId]=!1,this._storePacket(o,void 0,i.cbStorePut)):(d("MqttClient:publish: packet cmd: %s",o.cmd),this._sendPacket(o,void 0,i.cbStorePut));break;default:this._storeProcessing?(d("_storeProcessing enabled"),this._storePacket(o,n,i.cbStorePut)):(d("MqttClient:publish: packet cmd: %s",o.cmd),this._sendPacket(o,n,i.cbStorePut))}return this},b.prototype.subscribe=function(){for(var t,e=new Array(arguments.length),i=0;i0){var e={qos:t.qos};5===f&&(e.nl=t.nl||!1,e.rap=t.rap||!1,e.rh=t.rh||0,e.properties=t.properties),l._resubscribeTopics[t.topic]=e,g.push(t.topic)}})),l.messageIdToTopic[t.messageId]=g}return this.outgoing[t.messageId]={volatile:!0,cb:function(t,e){if(!t)for(var i=e.granted,n=0;n{d("end :: finish :: calling process.nextTick on closeStores"),f(function(){d("end :: closeStores: closing incoming and outgoing stores"),n.disconnected=!0,n.incomingStore.close((function(t){n.outgoingStore.close((function(e){if(d("end :: closeStores: emitting end"),n.emit("end"),i){let n=t||e;d("end :: closeStores: invoking callback with args"),i(n)}}))})),n._deferredReconnect&&n._deferredReconnect()}.bind(n))}),e)}return d("end :: (%s)",this.options.clientId),null!=t&&"boolean"==typeof t||(i=e||x,e=t,t=!1,"object"!=typeof e&&(i=e,e=null,"function"!=typeof i&&(i=x))),"object"!=typeof e&&(i=e,e=null),d("end :: cb? %s",!!i),i=i||x,this.disconnecting?(i(),this):(this._clearReconnect(),this.disconnecting=!0,!t&&Object.keys(this.outgoing).length>0?(d("end :: (%s) :: calling finish in 10ms once outgoing is empty",n.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,o,10))):(d("end :: (%s) :: immediately calling finish",n.options.clientId),o()),this)},b.prototype.removeOutgoingMessage=function(t){var 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},b.prototype.reconnect=function(t){d("client reconnect");var 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 r,e.outgoingStore=e.options.outgoingStore||new r,e.disconnecting=!1,e.disconnected=!1,e._deferredReconnect=null,e._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=i:i(),this},b.prototype._reconnect=function(){d("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end((()=>{this._setupStream()})),d("client already connected. disconnecting first.")):(d("_reconnect: calling _setupStream"),this._setupStream())},b.prototype._setupReconnect=function(){var t=this;!t.disconnecting&&!t.reconnectTimer&&t.options.reconnectPeriod>0?(this.reconnecting||(d("_setupReconnect :: emit `offline` state"),this.emit("offline"),d("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),d("_setupReconnect :: setting reconnectTimer for %d ms",t.options.reconnectPeriod),t.reconnectTimer=setInterval((function(){d("reconnectTimer :: reconnect triggered!"),t._reconnect()}),t.options.reconnectPeriod)):d("_setupReconnect :: doing nothing...")},b.prototype._clearReconnect=function(){d("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},b.prototype._cleanUp=function(t,e){var i,n=arguments[2];if(e&&(d("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",e)),d("_cleanUp :: forced? %s",t),t)0===this.options.reconnectPeriod&&this.options.clean&&(i=this.outgoing)&&(d("flush: queue exists? %b",!!i),Object.keys(i).forEach((function(t){"function"==typeof i[t].cb&&(i[t].cb(new Error("Connection closed")),delete i[t])}))),d("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{var o=u({cmd:"disconnect"},n);d("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(o,p.bind(null,this.stream.end.bind(this.stream)))}this.disconnecting||(d("_cleanUp :: client not disconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),null!==this.pingTimer&&(d("_cleanUp :: clearing pingTimer"),this.pingTimer.clear(),this.pingTimer=null),e&&!this.connected&&(d("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",e),e())},b.prototype._sendPacket=function(t,e,i){if(d("_sendPacket :: (%s) :: start",this.options.clientId),i=i||x,!this.connected)return d("_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 w(this,t,e,i);default:return void m(this,t,e)}switch(t.qos){case 2:case 1:w(this,t,e,i);break;default:m(this,t,e)}d("_sendPacket :: (%s) :: end",this.options.clientId)},b.prototype._storePacket=function(t,e,i){d("_storePacket :: packet: %o",t),d("_storePacket :: cb? %s",!!e),i=i||x,0===(t.qos||0)&&this.queueQoSZero||"publish"!==t.cmd?this.queue.push({packet:t,cb:e}):t.qos>0?(e=this.outgoing[t.messageId]?this.outgoing[t.messageId].cb:null,this.outgoingStore.put(t,(function(t){if(t)return e&&e(t);i()}))):e&&e(new Error("No connection to broker"))},b.prototype._setupPingTimer=function(){d("_setupPingTimer :: keepalive %d (seconds)",this.options.keepalive);var t=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=l((function(){t._checkPing()}),1e3*this.options.keepalive))},b.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},b.prototype._checkPing=function(){d("_checkPing :: checking ping..."),this.pingResp?(d("_checkPing :: ping response received. Clearing flag and sending `pingreq`"),this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):(d("_checkPing :: calling _cleanUp with force true"),this._cleanUp(!0))},b.prototype._handlePingresp=function(){this.pingResp=!0},b.prototype._handleConnack=function(t){d("_handleConnack");var e=this.options,i=5===e.protocolVersion?t.reasonCode:t.returnCode;if(clearTimeout(this.connackTimer),t.properties&&(t.properties.topicAliasMaximum&&(e.properties||(e.properties={}),e.properties.topicAliasMaximum=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)),0===i)this.reconnecting=!1,this._onConnect(t);else if(i>0){var n=new Error("Connection refused: "+y[i]);n.code=i,this.emit("error",n)}},b.prototype._handlePublish=function(t,e){d("_handlePublish: packet %o",t),e=void 0!==e?e:x;var i=t.topic.toString(),n=t.payload,o=t.qos,r=t.messageId,s=this,a=this.options,c=[0,16,128,131,135,144,145,151,153];switch(d("_handlePublish: qos %d",o),o){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:r,reasonCode:n},e):s.incomingStore.put(t,(function(){s._sendPacket({cmd:"pubrec",messageId:r},e)})))}));break;case 1:a.customHandleAcks(i,n,t,(function(o,a){return o instanceof Error||(a=o,o=null),o?s.emit("error",o):-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:r,reasonCode:a},e)})))}));break;case 0:this.emit("message",i,n,t),this.handleMessage(t,e);break;default:d("_handlePublish: unknown QoS. Doing nothing.")}},b.prototype.handleMessage=function(t,e){e()},b.prototype._handleAck=function(t){var e,i=t.messageId,n=t.cmd,o=null,r=this.outgoing[i]?this.outgoing[i].cb:null,s=this;if(r){switch(d("_handleAck :: packet type",n),n){case"pubcomp":case"puback":var a=t.reasonCode;a&&a>0&&16!==a&&((e=new Error("Publish error: "+y[a])).code=a,r(e,t)),delete this.outgoing[i],this.outgoingStore.del(t,r);break;case"pubrec":o={cmd:"pubrel",qos:2,messageId:i};var c=t.reasonCode;c&&c>0&&16!==c?((e=new Error("Publish error: "+y[c])).code=c,r(e,t)):this._sendPacket(o);break;case"suback":delete this.outgoing[i];for(var l=0;l0)if(this.options.resubscribe)if(5===this.options.protocolVersion){d("_resubscribe: protocolVersion 5");for(var i=0;in&&setTimeout(t,r,e,i,s),l&&"string"==typeof e&&(e=o.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?o.from(e):o.from(e,"utf8"),f.push(e)}function w(t,e){const i=new Array(t.length);for(let e=0;e{a.destroy()})),a}}).call(this)}).call(this,t("_process"),t("buffer").Buffer)},{_process:32,buffer:14,debug:15,duplexify:17,"readable-stream":51,ws:60}],6:[function(t,e,i){(function(i){(function(){"use strict";var n,o,r,s=t("readable-stream").Transform,a=t("duplexify");e.exports=function(t,e){if(e.hostname=e.hostname||e.host,!e.hostname)throw new Error("Could not determine host. Specify host manually.");var c="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);var l=function(t,e){var i="wxs"===t.protocol?"wss":"ws",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);n=wx.connectSocket({url:l,protocols:[c]}),o=function(){var t=new s;return t._write=function(t,e,i){n.send({data:t.buffer,success:function(){i()},fail:function(t){i(new Error(t))}})},t._flush=function(t){n.close({success:function(){t()}})},t}(),(r=a.obj())._destroy=function(t,e){n.close({success:function(){e&&e(t)}})};var h=r.destroy;return r.destroy=function(){r.destroy=h;var t=this;setTimeout((function(){n.close({fail:function(){t._destroy(new Error)}})}),0)}.bind(r),n.onOpen((function(){r.setReadable(o),r.setWritable(o),r.emit("connect")})),n.onMessage((function(t){var e=t.data;e=e instanceof ArrayBuffer?i.from(e):i.from(e,"utf8"),o.push(e)})),n.onClose((function(){r.end(),r.destroy()})),n.onError((function(t){r.destroy(new Error(t.errMsg))})),r}}).call(this)}).call(this,t("buffer").Buffer)},{buffer:14,duplexify:17,"readable-stream":51}],7:[function(t,e,i){"use strict";var n=t("xtend"),o=t("readable-stream").Readable,r={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(){var t=new o(r),e=!1,i=[],n=0;return this._inflights.forEach((function(t,e){i.push(t)})),t._read=function(){!e&&n0?s-4:s;for(i=0;i>16&255,c[h++]=e>>8&255,c[h++]=255&e;return 2===a&&(e=o[t.charCodeAt(i)]<<2|o[t.charCodeAt(i+1)]>>4,c[h++]=255&e),1===a&&(e=o[t.charCodeAt(i)]<<10|o[t.charCodeAt(i+1)]<<4|o[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,o=i%3,r=[],s=0,a=i-o;sa?a:s+16383));return 1===o?(e=t[i-1],r.push(n[e>>2]+n[e<<4&63]+"==")):2===o&&(e=(t[i-2]<<8)+t[i-1],r.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"=")),r.join("")};for(var n=[],o=[],r="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=s.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function h(t,e,i){for(var o,r,s=[],a=e;a>18&63]+n[r>>12&63]+n[r>>6&63]+n[63&r]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},{}],11:[function(t,e,i){"use strict";const{Buffer:n}=t("buffer"),o=Symbol.for("BufferList");function r(t){if(!(this instanceof r))return new r(t);r._init.call(this,t)}r._init=function(t){Object.defineProperty(this,o,{value:!0}),this._bufs=[],this.length=0,t&&this.append(t)},r.prototype._new=function(t){return new r(t)},r.prototype._offset=function(t){if(0===t)return[0,0];let e=0;for(let i=0;ithis.length||t<0)return;const e=this._offset(t);return this._bufs[e[0]][e[1]]},r.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)},r.prototype.copy=function(t,e,i,o){if(("number"!=typeof i||i<0)&&(i=0),("number"!=typeof o||o>this.length)&&(o=this.length),i>=this.length)return t||n.alloc(0);if(o<=0)return t||n.alloc(0);const r=!!t,s=this._offset(i),a=o-i;let c=a,l=r&&e||0,h=s[1];if(0===i&&o===this.length){if(!r)return 1===this._bufs.length?this._bufs[0]:n.concat(this._bufs,this.length);for(let e=0;ei)){this._bufs[e].copy(t,l,h,h+c),l+=i;break}this._bufs[e].copy(t,l,h),l+=i,c-=i,h&&(h=0)}return t.length>l?t.slice(0,l):t},r.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),o=this._bufs.slice(i[0],n[0]+1);return 0===n[1]?o.pop():o[o.length-1]=o[o.length-1].slice(0,n[1]),0!==i[1]&&(o[0]=o[0].slice(i[1])),this._new(o)},r.prototype.toString=function(t,e,i){return this.slice(e,i).toString(t)},r.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},r.prototype.duplicate=function(){const t=this._new();for(let e=0;ethis.length?this.length:e;const o=this._offset(e);let r=o[0],s=o[1];for(;r=t.length){const i=e.indexOf(t,s);if(-1!==i)return this._reverseOffset([r,i]);s=e.length-t.length+1}else{const e=this._reverseOffset([r,s]);if(this._match(e,t))return e;s++}s=0}return-1},r.prototype._match=function(t,e){if(this.length-to)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=r(i),o=n.write(t,e);return o!==i&&(n=n.slice(0,o)),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=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.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 o=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":return O(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return N(t).length;default:if(o)return n?-1:O(t).length;e=(""+e).toLowerCase(),o=!0}}function f(t,e,i){var n=t[e];t[e]=t[i],t[i]=n}function p(t,e,i,n,o){if(0===t.length)return-1;if("string"==typeof i?(n=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),H(i=+i)&&(i=o?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(o)return-1;i=t.length-1}else if(i<0){if(!o)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,o);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):v(t,[e],i,n,o);throw new TypeError("val must be string, number or Buffer")}function v(t,e,i,n,o){var r,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(o){var h=-1;for(r=i;ra&&(i=a-c),r=i;r>=0;r--){for(var u=!0,d=0;do&&(n=o):n=o;var r=e.length;n>r/2&&(n=r/2);for(var s=0;s>8,o=i%256,r.push(o),r.push(n);return r}(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 A(t,e,i){i=Math.min(t.length,i);for(var n=[],o=e;o239?4:l>223?3:l>191?2:1;if(o+u<=i)switch(u){case 1:l<128&&(h=l);break;case 2:128==(192&(r=t[o+1]))&&(c=(31&l)<<6|63&r)>127&&(h=c);break;case 3:r=t[o+1],s=t[o+2],128==(192&r)&&128==(192&s)&&(c=(15&l)<<12|(63&r)<<6|63&s)>2047&&(c<55296||c>57343)&&(h=c);break;case 4:r=t[o+1],s=t[o+2],a=t[o+3],128==(192&r)&&128==(192&s)&&128==(192&a)&&(c=(15&l)<<18|(63&r)<<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),o+=u}return function(t){var e=t.length;if(e<=R)return String.fromCharCode.apply(String,t);for(var i="",n=0;nthis.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return S(this,e,i);case"utf8":case"utf-8":return A(this,e,i);case"ascii":return _(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 T(this,e,i);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){var t="",e=i.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),""},s.prototype.compare=function(t,e,i,n,o){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===o&&(o=this.length),e<0||i>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&e>=i)return 0;if(n>=o)return-1;if(e>=i)return 1;if(this===t)return 0;for(var r=(o>>>=0)-(n>>>=0),a=(i>>>=0)-(e>>>=0),c=Math.min(r,a),l=this.slice(n,o),h=t.slice(e,i),u=0;u>>=0,isFinite(i)?(i>>>=0,void 0===n&&(n="utf8")):(n=i,i=void 0)}var o=this.length-e;if((void 0===i||i>o)&&(i=o),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var r=!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 x(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,e,i);default:if(r)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),r=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var R=4096;function _(t,e,i){var n="";i=Math.min(t.length,i);for(var o=e;on)&&(i=n);for(var o="",r=e;ri)throw new RangeError("Trying to access beyond buffer length")}function E(t,e,i,n,o,r){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||et.length)throw new RangeError("Index out of range")}function C(t,e,i,n,o,r){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,o,r){return e=+e,i>>>=0,r||C(t,0,i,4),n.write(t,e,i,o,23,4),i+4}function M(t,e,i,o,r){return e=+e,i>>>=0,r||C(t,0,i,8),n.write(t,e,i,o,52,8),i+8}s.prototype.slice=function(t,e){var i=this.length;(t=~~t)<0?(t+=i)<0&&(t=0):t>i&&(t=i),(e=void 0===e?i:~~e)<0?(e+=i)<0&&(e=0):e>i&&(e=i),e>>=0,e>>>=0,i||I(t,e,this.length);for(var n=this[t],o=1,r=0;++r>>=0,e>>>=0,i||I(t,e,this.length);for(var n=this[t+--e],o=1;e>0&&(o*=256);)n+=this[t+--e]*o;return n},s.prototype.readUInt8=function(t,e){return t>>>=0,e||I(t,1,this.length),this[t]},s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||I(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||I(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||I(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||I(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||I(t,e,this.length);for(var n=this[t],o=1,r=0;++r=(o*=128)&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,i){t>>>=0,e>>>=0,i||I(t,e,this.length);for(var n=e,o=1,r=this[t+--n];n>0&&(o*=256);)r+=this[t+--n]*o;return r>=(o*=128)&&(r-=Math.pow(2,8*e)),r},s.prototype.readInt8=function(t,e){return t>>>=0,e||I(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||I(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||I(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||I(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||I(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||I(t,4,this.length),n.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||I(t,4,this.length),n.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||I(t,8,this.length),n.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||I(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 o=1,r=0;for(this[e]=255&t;++r>>=0,i>>>=0,n||E(this,t,e,i,Math.pow(2,8*i)-1,0);var o=i-1,r=1;for(this[e+o]=255&t;--o>=0&&(r*=256);)this[e+o]=t/r&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 o=Math.pow(2,8*i-1);E(this,t,e,i,o-1,-o)}var r=0,s=1,a=0;for(this[e]=255&t;++r>0)-a&255;return e+i},s.prototype.writeIntBE=function(t,e,i,n){if(t=+t,e>>>=0,!n){var o=Math.pow(2,8*i-1);E(this,t,e,i,o-1,-o)}var r=i-1,s=1,a=0;for(this[e+r]=255&t;--r>=0&&(s*=256);)t<0&&0===a&&0!==this[e+r+1]&&(a=1),this[e+r]=(t/s>>0)-a&255;return e+i},s.prototype.writeInt8=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeInt16BE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeInt32LE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},s.prototype.writeInt32BE=function(t,e,i){return t=+t,e>>>=0,i||E(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeFloatLE=function(t,e,i){return L(this,t,e,!0,i)},s.prototype.writeFloatBE=function(t,e,i){return L(this,t,e,!1,i)},s.prototype.writeDoubleLE=function(t,e,i){return M(this,t,e,!0,i)},s.prototype.writeDoubleBE=function(t,e,i){return M(this,t,e,!1,i)},s.prototype.copy=function(t,e,i,n){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(i||(i=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--r)t[r+e]=this[r+i];else Uint8Array.prototype.set.call(t,this.subarray(i,n),e);return o},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 o=t.charCodeAt(0);("utf8"===n&&o<128||"latin1"===n)&&(t=o)}}else"number"==typeof t&&(t&=255);if(e<0||this.length>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(r=e;r55295&&i<57344){if(!o){if(i>56319){(e-=3)>-1&&r.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&r.push(239,191,189);continue}o=i;continue}if(i<56320){(e-=3)>-1&&r.push(239,191,189),o=i;continue}i=65536+(o-55296<<10|i-56320)}else o&&(e-=3)>-1&&r.push(239,191,189);if(o=null,i<128){if((e-=1)<0)break;r.push(i)}else if(i<2048){if((e-=2)<0)break;r.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;r.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;r.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return r}function N(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 U(t,e,i,n){for(var o=0;o=e.length||o>=t.length);++o)e[o+i]=t[o];return o}function F(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function H(t){return t!=t}}).call(this)}).call(this,t("buffer").Buffer)},{"base64-js":10,buffer:14,ieee754:20}],15:[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,o=0;t[0].replace(/%[a-zA-Z%]/g,(t=>{"%%"!==t&&"%c"===t&&(o=++n)})),t.splice(o,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:o}=e.exports;o.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}}).call(this)}).call(this,t("_process"))},{"./common":16,_process:32}],16:[function(t,e,i){e.exports=function(e){function i(t){let e,o=null;function r(...t){if(!r.enabled)return;const n=r,o=Number(new Date),s=o-(e||o);n.diff=s,n.prev=e,n.curr=o,e=o,t[0]=i.coerce(t[0]),"string"!=typeof t[0]&&t.unshift("%O");let a=0;t[0]=t[0].replace(/%([a-zA-Z%])/g,((e,o)=>{if("%%"===e)return"%";a++;const r=i.formatters[o];if("function"==typeof r){const i=t[a];e=r.call(n,i),t.splice(a,1),a--}return e})),i.formatArgs.call(n,t),(n.log||i.log).apply(n,t)}return r.namespace=t,r.useColors=i.useColors(),r.color=i.selectColor(t),r.extend=n,r.destroy=i.destroy,Object.defineProperty(r,"enabled",{enumerable:!0,configurable:!1,get:()=>null===o?i.enabled(t):o,set:t=>{o=t}}),"function"==typeof i.init&&i.init(r),r}function n(t,e){const n=i(this.namespace+(void 0===e?":":e)+t);return n.log=this.log,n}function o(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(o),...i.skips.map(o).map((t=>"-"+t))].join(",");return i.enable(""),t},i.enable=function(t){let e;i.save(t),i.names=[],i.skips=[];const n=("string"==typeof t?t:"").split(/[\s,]+/),o=n.length;for(e=0;e{i[t]=e[t]})),i.names=[],i.skips=[],i.formatters={},i.selectColor=function(t){let e=0;for(let i=0;i0&&a.length>r){a.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+a.length+' "'+String(e)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=a.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",c.name,c.message)}}else a=s[e]=i,++t._eventsCount;return t}function d(){if(!this.fired)switch(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:for(var t=new Array(arguments.length),e=0;e1&&(e=arguments[1]),e instanceof Error)throw e;var c=new Error('Unhandled "error" event. ('+e+")");throw c.context=e,c}if(!(i=s[t]))return!1;var l="function"==typeof i;switch(n=arguments.length){case 1:!function(t,e,i){if(e)t.call(i);else for(var n=t.length,o=g(t,n),r=0;r=0;s--)if(i[s]===e||i[s].listener===e){a=i[s].listener,r=s;break}if(r<0)return this;0===r?i.shift():function(t,e){for(var i=e,n=i+1,o=t.length;n=0;r--)this.removeListener(t,e[r]);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):[]}},{}],20:[function(t,e,i){i.read=function(t,e,i,n,o){var r,s,a=8*o-n-1,c=(1<>1,h=-7,u=i?o-1:0,d=i?-1:1,f=t[e+u];for(u+=d,r=f&(1<<-h)-1,f>>=-h,h+=a;h>0;r=256*r+t[e+u],u+=d,h-=8);for(s=r&(1<<-h)-1,r>>=-h,h+=n;h>0;s=256*s+t[e+u],u+=d,h-=8);if(0===r)r=1-l;else{if(r===c)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,n),r-=l}return(f?-1:1)*s*Math.pow(2,r-n)},i.write=function(t,e,i,n,o,r){var s,a,c,l=8*r-o-1,h=(1<>1,d=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:r-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,o),s+=u):(a=e*Math.pow(2,u-1)*Math.pow(2,o),s=0));o>=8;t[i+f]=255&a,f+=p,a/=256,o-=8);for(s=s<0;t[i+f]=255&s,f+=p,s/=256,l-=8);t[i+f-p]|=128*v}},{}],21:[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}}},{}],22:[function(t,e,i){(function(t){(function(){const i=e.exports;i.types={0:"reserved",1:"connect",2:"connack",3:"publish",4:"puback",5:"pubrec",6:"pubrel",7:"pubcomp",8:"subscribe",9:"suback",10:"unsubscribe",11:"unsuback",12:"pingreq",13:"pingresp",14:"disconnect",15:"auth"},i.codes={};for(const t in i.types){const e=i.types[t];i.codes[e]=t}i.CMD_SHIFT=4,i.CMD_MASK=240,i.DUP_MASK=8,i.QOS_MASK=3,i.QOS_SHIFT=1,i.RETAIN_MASK=1,i.VARBYTEINT_MASK=127,i.VARBYTEINT_FIN_MASK=128,i.VARBYTEINT_MAX=268435455,i.SESSIONPRESENT_MASK=1,i.SESSIONPRESENT_HEADER=t.from([i.SESSIONPRESENT_MASK]),i.CONNACK_HEADER=t.from([i.codes.connack<[0,1].map((o=>[0,1].map((r=>{const s=t.alloc(1);return s.writeUInt8(i.codes[e]<t.from([e]))),i.EMPTY={pingreq:t.from([i.codes.pingreq<<4,0]),pingresp:t.from([i.codes.pingresp<<4,0]),disconnect:t.from([i.codes.disconnect<<4,0])}}).call(this)}).call(this,t("buffer").Buffer)},{buffer:14}],23:[function(t,e,i){(function(i){(function(){const n=t("./writeToStream"),o=t("events");class r extends o{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 o,r=0;for(o=0;o>8,0),i.writeUInt8(255&e,1),i}e.exports={cache:i,generateCache:function(){for(let t=0;t<65536;t++)i[t]=o(t)},generateNumber:o,genBufVariableByteInt:function(e){let i=0,o=0;const r=t.allocUnsafe(4);do{i=e%128|0,(e=e/128|0)>0&&(i|=128),r.writeUInt8(i,o++)}while(e>0&&o<4);return e>0&&(o=0),n?r.subarray(0,o):r.slice(0,o)},generate4ByteBuffer:function(e){const i=t.allocUnsafe(4);return i.writeUInt32BE(e,0),i}}}).call(this)}).call(this,t("buffer").Buffer)},{buffer:14}],26:[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}}},{}],27:[function(t,e,i){const n=t("bl"),o=t("events"),r=t("./packet"),s=t("./constants"),a=t("debug")("mqtt-packet:parser");class c extends o{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 r,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 o={},r=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(r.protocolId=c,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(r.protocolVersion=this._list.readUInt8(this._pos),r.protocolVersion>=128&&(r.bridgeMode=!0,r.protocolVersion=r.protocolVersion-128),3!==r.protocolVersion&&4!==r.protocolVersion&&5!==r.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(o.username=this._list.readUInt8(this._pos)&s.USERNAME_MASK,o.password=this._list.readUInt8(this._pos)&s.PASSWORD_MASK,o.will=this._list.readUInt8(this._pos)&s.WILL_FLAG_MASK,o.will&&(r.will={},r.will.retain=0!=(this._list.readUInt8(this._pos)&s.WILL_RETAIN_MASK),r.will.qos=(this._list.readUInt8(this._pos)&s.WILL_QOS_MASK)>>s.WILL_QOS_SHIFT),r.clean=0!=(this._list.readUInt8(this._pos)&s.CLEAN_SESSION_MASK),this._pos++,r.keepalive=this._parseNum(),-1===r.keepalive)return this._emitError(new Error("Packet too short"));if(5===r.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(r.properties=t)}const l=this._parseString();if(null===l)return this._emitError(new Error("Packet too short"));if(r.clientId=l,a("_parseConnect: packet.clientId: %s",r.clientId),o.will){if(5===r.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(r.will.properties=t)}if(null===(t=this._parseString()))return this._emitError(new Error("Cannot parse will topic"));if(r.will.topic=t,a("_parseConnect: packet.will.topic: %s",r.will.topic),null===(e=this._parseBuffer()))return this._emitError(new Error("Cannot parse will payload"));r.will.payload=e,a("_parseConnect: packet.will.paylaod: %s",r.will.payload)}if(o.username){if(null===(n=this._parseString()))return this._emitError(new Error("Cannot parse username"));r.username=n,a("_parseConnect: packet.username: %s",r.username)}if(o.password){if(null===(i=this._parseBuffer()))return this._emitError(new Error("Cannot parse password"));r.password=i}return this.settings=r,a("_parseConnect: complete"),r}_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,o,r,c,l;if(1!==t.qos)return this._emitError(new Error("Wrong subscribe header"));if(t.subscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}for(;this._pos=t.length)return this._emitError(new Error("Malformed Subscribe Payload"));n=(i=this._parseByte())&s.SUBSCRIBE_OPTIONS_QOS_MASK,c=0!=(i>>s.SUBSCRIBE_OPTIONS_NL_SHIFT&s.SUBSCRIBE_OPTIONS_NL_MASK),r=0!=(i>>s.SUBSCRIBE_OPTIONS_RAP_SHIFT&s.SUBSCRIBE_OPTIONS_RAP_MASK),o=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=r,l.rh=o):this.settings.bridgeMode&&(l.rh=0,l.rap=!0,l.nl=!0),a("_parseSubscribe: push subscription `%s` to subscription",l),t.subscriptions.push(l)}}}_parseSuback(){a("_parseSuback");const t=this.packet;if(this.packet.granted=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}for(;this._pos2?(t.reasonCode=this._parseByte(),a("_parseConfirmation: packet.reasonCode `%d`",t.reasonCode)):t.reasonCode=0,t.length>3)){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}return!0}_parseDisconnect(){const t=this.packet;if(a("_parseDisconnect"),5===this.settings.protocolVersion){this._list.length>0?t.reasonCode=this._parseByte():t.reasonCode=0;const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}return a("_parseDisconnect result: true"),!0}_parseAuth(){a("_parseAuth");const t=this.packet;if(5!==this.settings.protocolVersion)return this._emitError(new Error("Not supported auth packet for this version MQTT"));t.reasonCode=this._parseByte();const e=this._parseProperties();return Object.getOwnPropertyNames(e).length&&(t.properties=e),a("_parseAuth: result: true"),!0}_parseMessageId(){const t=this.packet;return t.messageId=this._parseNum(),null===t.messageId?(this._emitError(new Error("Cannot parse messageId")),!1):(a("_parseMessageId: packet.messageId %d",t.messageId),!0)}_parseString(t){const e=this._parseNum(),i=e+this._pos;if(-1===e||i>this._list.length||i>this.packet.length)return null;const n=this._list.toString("utf8",this._pos,i);return this._pos+=e,a("_parseString: result: %s",n),n}_parseStringPair(){return a("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){const t=this._parseNum(),e=t+this._pos;if(-1===t||e>this._list.length||e>this.packet.length)return null;const i=this._list.slice(this._pos,e);return this._pos+=t,a("_parseBuffer: result: %o",i),i}_parseNum(){if(this._list.length-this._pos<2)return-1;const t=this._list.readUInt16BE(this._pos);return this._pos+=2,a("_parseNum: result: %s",t),t}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;const t=this._list.readUInt32BE(this._pos);return this._pos+=4,a("_parse4ByteNum: result: %s",t),t}_parseVarByteNum(t){a("_parseVarByteNum");let e,i=0,n=1,o=0,r=!1;const c=this._pos?this._pos:0;for(;i<4&&c+i=i&&this._emitError(new Error("Invalid variable byte integer")),c&&(this._pos+=i),a("_parseVarByteNum: result: %o",r=!!r&&(t?{bytes:i,value:o}:o)),r}_parseByte(){let t;return this._pos=4)&&(u||l))g+=i.byteLength(u)+2;else{if(a<4)return e.emit("error",new Error("clientId must be supplied before 3.1.1")),!1;if(1*l==0)return e.emit("error",new Error("clientId must be given if cleanSession set to 0")),!1}if("number"!=typeof h||h<0||h>65535||h%1!=0)return e.emit("error",new Error("Invalid keepalive")),!1;if(g+=2,g+=1,5===a){var y=_(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=_(e,c.properties)))return!1;g+=m.length}}let b=!1;if(null!=d){if(!E(d))return e.emit("error",new Error("Invalid username")),!1;b=!0,g+=i.byteLength(d)+2}if(null!=f){if(!b)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+=I(f)+2}e.write(n.CONNECT_HEADER),w(e,g),R(e,s),r.bridgeMode&&(a+=128),e.write(131===a?n.VERSION131:132===a?n.VERSION132:4===a?n.VERSION4:5===a?n.VERSION5:n.VERSION3);let k=0;return k|=null!=d?n.USERNAME_MASK:0,k|=null!=f?n.PASSWORD_MASK:0,k|=c&&c.retain?n.WILL_RETAIN_MASK:0,k|=c&&c.qos?c.qos<0&&p(e,f),null!=y&&y.write(),c("publish: payload: %o",d),e.write(d)}(t,e,s);case"puback":case"pubrec":case"pubrel":case"pubcomp":return function(t,e,o){const r=o?o.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===r?3:2;if("pubrel"===a&&(h=1),"number"!=typeof c)return e.emit("error",new Error("Invalid messageId")),!1;let v=null;if(5===r&&"object"==typeof d){if(!(v=P(e,d,o,f)))return!1;f+=v.length}return e.write(n.ACKS[a][h][l][0]),w(e,f),p(e,c),5===r&&e.write(i.from([u])),null!==v&&v.write(),!0}(t,e,s);case"subscribe":return function(t,e,o){c("subscribe: packet: ");const r=o?o.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===r){if(!(f=_(e,u)))return!1;d+=f.length}if("object"!=typeof h||!h.length)return e.emit("error",new Error("Invalid subscriptions")),!1;for(let t=0;t2)return e.emit("error",new Error("Invalid subscriptions - invalid Retain Handling")),!1}d+=i.byteLength(n)+2+1}c("subscribe: writing to stream: %o",n.SUBSCRIBE_HEADER),e.write(n.SUBSCRIBE_HEADER[1][a?1:0][0]),w(e,d),p(e,l),null!==f&&f.write();let v=!0;for(const t of h){const o=t.topic,s=t.qos,a=+t.nl,c=+t.rap,l=t.rh;let h;x(e,o),h=n.SUBSCRIBE_OPTIONS_QOS[s],5===r&&(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,o){const r=o?o.protocolVersion:4,s=t||{},a=s.messageId,c=s.granted,l=s.properties;let h=0;if("number"!=typeof a)return e.emit("error",new Error("Invalid messageId")),!1;if(h+=2,"object"!=typeof c||!c.length)return e.emit("error",new Error("Invalid qos vector")),!1;for(let t=0;tp===k,set(t){t?(l&&0!==Object.keys(l).length||(v=!0),p=k):(v=!1,p=A)}});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 x(t,e){const n=i.byteLength(e);return p(t,n),c("writeString: %s",e),t.write(e,"utf8")}function b(t,e,i){x(t,e),x(t,i)}function k(t,e){return c("writeNumberCached: number: %d",e),c("writeNumberCached: %o",l[e]),t.write(l[e])}function A(t,e){const i=h(e);return c("writeNumberGenerated: %o",i),t.write(i)}function R(t,e){"string"==typeof e?x(t,e):e?(p(t,e.length),t.write(e)):p(t,0)}function _(t,e){if("object"!=typeof e||null!=e.length)return{length:1,write(){T(t,{},0)}};let o=0;function r(e,o){let r=0;switch(n.propertiesTypes[e]){case"byte":if("boolean"!=typeof o)return t.emit("error",new Error(`Invalid ${e}: ${o}`)),!1;r+=2;break;case"int8":if("number"!=typeof o||o<0||o>255)return t.emit("error",new Error(`Invalid ${e}: ${o}`)),!1;r+=2;break;case"binary":if(o&&null===o)return t.emit("error",new Error(`Invalid ${e}: ${o}`)),!1;r+=1+i.byteLength(o)+2;break;case"int16":if("number"!=typeof o||o<0||o>65535)return t.emit("error",new Error(`Invalid ${e}: ${o}`)),!1;r+=3;break;case"int32":if("number"!=typeof o||o<0||o>4294967295)return t.emit("error",new Error(`Invalid ${e}: ${o}`)),!1;r+=5;break;case"var":if("number"!=typeof o||o<0||o>268435455)return t.emit("error",new Error(`Invalid ${e}: ${o}`)),!1;r+=1+i.byteLength(d(o));break;case"string":if("string"!=typeof o)return t.emit("error",new Error(`Invalid ${e}: ${o}`)),!1;r+=3+i.byteLength(o.toString());break;case"pair":if("object"!=typeof o)return t.emit("error",new Error(`Invalid ${e}: ${o}`)),!1;r+=Object.getOwnPropertyNames(o).reduce(((t,e)=>{const n=o[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(o[e].toString()),t}),0);break;default:return t.emit("error",new Error(`Invalid property ${e}: ${o}`)),!1}return r}if(e)for(const t in e){let i=0,n=0;const s=e[t];if(Array.isArray(s))for(let e=0;er;){const i=o.shift();if(!i||!e[i])return!1;delete e[i],s=_(t,e)}return s}function S(t,e,o){switch(n.propertiesTypes[e]){case"byte":t.write(i.from([n.properties[e]])),t.write(i.from([+o]));break;case"int8":t.write(i.from([n.properties[e]])),t.write(i.from([o]));break;case"binary":t.write(i.from([n.properties[e]])),R(t,o);break;case"int16":t.write(i.from([n.properties[e]])),p(t,o);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,o);break;case"var":t.write(i.from([n.properties[e]])),w(t,o);break;case"string":t.write(i.from([n.properties[e]])),x(t,o);break;case"pair":Object.getOwnPropertyNames(o).forEach((r=>{const s=o[r];Array.isArray(s)?s.forEach((o=>{t.write(i.from([n.properties[e]])),b(t,r.toString(),o.toString())})):(t.write(i.from([n.properties[e]])),b(t,r.toString(),s.toString()))}));break;default:return t.emit("error",new Error(`Invalid property ${e} value: ${o}`)),!1}}function T(t,e,i){w(t,i);for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)&&null!==e[i]){const n=e[i];if(Array.isArray(n))for(let e=0;e=1.5*i;return Math.round(t/i)+" "+n+(o?"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*r;case"minutes":case"minute":case"mins":case"min":case"m":return i*o;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>=r?a(t,e,r,"hour"):e>=o?a(t,e,o,"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>=r?Math.round(t/r)+"h":e>=o?Math.round(t/o)+"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))}},{}],30:[function(t,e,i){var n=t("wrappy");function o(t){var e=function(){return e.called?e.value:(e.called=!0,e.value=t.apply(this,arguments))};return e.called=!1,e}function r(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(o),e.exports.strict=n(r),o.proto=o((function(){Object.defineProperty(Function.prototype,"once",{value:function(){return o(this)},configurable:!0}),Object.defineProperty(Function.prototype,"onceStrict",{value:function(){return r(this)},configurable:!0})}))},{wrappy:59}],31:[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,o){if("function"!=typeof e)throw new TypeError('"callback" argument must be a function');var r,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,o)}));default:for(r=new Array(a-1),s=0;s1)for(var i=1;i= 0x80 (not a basic code point)","invalid-input":"Invalid input"},v=Math.floor,g=String.fromCharCode;function y(t){throw new RangeError(p[t])}function m(t,e){for(var i=t.length,n=[];i--;)n[i]=e(t[i]);return n}function w(t,e){var i=t.split("@"),n="";return i.length>1&&(n=i[0]+"@",t=i[1]),n+m((t=t.replace(f,".")).split("."),e).join(".")}function x(t){for(var e,i,n=[],o=0,r=t.length;o=55296&&e<=56319&&o65535&&(e+=g((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+g(t)})).join("")}function k(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function A(t,e,i){var n=0;for(t=i?v(t/700):t>>1,t+=v(t/e);t>455;n+=h)t=v(t/35);return v(n+36*t/(t+38))}function R(t){var e,i,n,o,r,s,a,c,u,d,f,p=[],g=t.length,m=0,w=128,x=72;for((i=t.lastIndexOf("-"))<0&&(i=0),n=0;n=128&&y("not-basic"),p.push(t.charCodeAt(n));for(o=i>0?i+1:0;o=g&&y("invalid-input"),((c=(f=t.charCodeAt(o++))-48<10?f-22:f-65<26?f-65:f-97<26?f-97:h)>=h||c>v((l-m)/s))&&y("overflow"),m+=c*s,!(c<(u=a<=x?1:a>=x+26?26:a-x));a+=h)s>v(l/(d=h-u))&&y("overflow"),s*=d;x=A(m-r,e=p.length+1,0==r),v(m/e)>l-w&&y("overflow"),w+=v(m/e),m%=e,p.splice(m++,0,w)}return b(p)}function _(t){var e,i,n,o,r,s,a,c,u,d,f,p,m,w,b,R=[];for(p=(t=x(t)).length,e=128,i=0,r=72,s=0;s=e&&fv((l-i)/(m=n+1))&&y("overflow"),i+=(a-e)*m,e=a,s=0;sl&&y("overflow"),f==e){for(c=i,u=h;!(c<(d=u<=r?1:u>=r+26?26:u-r));u+=h)b=c-d,w=h-d,R.push(g(k(d+b%w,0))),c=v(b/w);R.push(g(k(c,0))),r=A(i,m,n==o),i=0,++n}++i,++e}return R.join("")}if(a={version:"1.4.1",ucs2:{decode:x,encode:b},decode:R,encode:_,toASCII:function(t){return w(t,(function(t){return d.test(t)?"xn--"+_(t):t}))},toUnicode:function(t){return w(t,(function(t){return u.test(t)?R(t.slice(4).toLowerCase()):t}))}},o&&r)if(e.exports==o)r.exports=a;else for(c in a)a.hasOwnProperty(c)&&(o[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:{})},{}],34:[function(t,e,i){"use strict";function n(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.exports=function(t,e,i,r){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;r&&"number"==typeof r.maxKeys&&(c=r.maxKeys);var l=t.length;c>0&&l>c&&(l=c);for(var h=0;h=0?(u=v.substr(0,g),d=v.substr(g+1)):(u=v,d=""),f=decodeURIComponent(u),p=decodeURIComponent(d),n(s,f)?o(s[f])?s[f].push(p):s[f]=[s[f],p]:s[f]=p}return s};var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},{}],35:[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?r(s(t),(function(s){var a=encodeURIComponent(n(s))+i;return o(t[s])?r(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 o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function r(t,e){if(t.map)return t.map(e);for(var i=[],n=0;n2?"one of ".concat(e," ").concat(t.slice(0,i-1).join(", "),", or ")+t[i-1]:2===i?"one of ".concat(e," ").concat(t[0]," or ").concat(t[1]):"of ".concat(e," ").concat(t[0])}return"of ".concat(e," ").concat(String(t))}o("ERR_INVALID_OPT_VALUE",(function(t,e){return'The value "'+e+'" is invalid for option "'+t+'"'}),TypeError),o("ERR_INVALID_ARG_TYPE",(function(t,e,i){var n,o,s;if("string"==typeof e&&(o="not ",e.substr(0,o.length)===o)?(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(r(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(r(e,"type"))}return s+". Received type ".concat(typeof i)}),TypeError),o("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),o("ERR_METHOD_NOT_IMPLEMENTED",(function(t){return"The "+t+" method is not implemented"})),o("ERR_STREAM_PREMATURE_CLOSE","Premature close"),o("ERR_STREAM_DESTROYED",(function(t){return"Cannot call "+t+" after a stream was destroyed"})),o("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),o("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),o("ERR_STREAM_WRITE_AFTER_END","write after end"),o("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),o("ERR_UNKNOWN_ENCODING",(function(t){return"Unknown encoding: "+t}),TypeError),o("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),e.exports.codes=n},{}],38:[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 o=t("./_stream_readable"),r=t("./_stream_writable");t("inherits")(l,o);for(var s=n(r.prototype),a=0;a0)if("string"==typeof e||a.objectMode||Object.getPrototypeOf(e)===c.prototype||(e=function(t){return c.from(t)}(e)),n)a.endEmitted?k(t,new b):S(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?S(t,a,e,!1):L(t,a)):S(t,a,e,!1)}else n||(a.reading=!1,L(t,a));return!a.ended&&(a.lengthe.highWaterMark&&(e.highWaterMark=function(t){return t>=T?t=T:(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;r("emitReadable",e.needReadable,e.emittedReadable),e.needReadable=!1,e.emittedReadable||(r("emitReadable",e.flowing),e.emittedReadable=!0,i.nextTick(C,t))}function C(t){var e=t._readableState;r("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,N(t)}function L(t,e){e.readingMore||(e.readingMore=!0,i.nextTick(M,t,e))}function M(t,e){for(;!e.reading&&!e.ended&&(e.length0,e.resumeScheduled&&!e.paused?e.flowing=!0:t.listenerCount("data")>0&&t.resume()}function B(t){r("readable nexttick read 0"),t.read(0)}function O(t,e){r("resume",e.reading),e.reading||t.read(0),e.resumeScheduled=!1,t.emit("resume"),N(t),e.flowing&&!e.reading&&t.read(0)}function N(t){var e=t._readableState;for(r("flow",e.flowing);e.flowing&&null!==t.read(););}function U(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;r("endReadable",e.endEmitted),e.endEmitted||(e.ended=!0,i.nextTick(H,e,t))}function H(t,e){if(r("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 j(t,e){for(var i=0,n=t.length;i=e.highWaterMark:e.length>0)||e.ended))return r("read: emitReadable",e.length,e.ended),0===e.length&&e.ended?F(this):E(this),null;if(0===(t=I(t,e))&&e.ended)return 0===e.length&&F(this),null;var n,o=e.needReadable;return r("need readable",o),(0===e.length||e.length-t0?U(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},_.prototype._read=function(t){k(this,new x("_read()"))},_.prototype.pipe=function(t,e){var n=this,o=this._readableState;switch(o.pipesCount){case 0:o.pipes=t;break;case 1:o.pipes=[o.pipes,t];break;default:o.pipes.push(t)}o.pipesCount+=1,r("pipe count=%d opts=%j",o.pipesCount,e);var a=e&&!1===e.end||t===i.stdout||t===i.stderr?v:c;function c(){r("onend"),t.end()}o.endEmitted?i.nextTick(a):n.once("end",a),t.on("unpipe",(function e(i,s){r("onunpipe"),i===n&&s&&!1===s.hasUnpiped&&(s.hasUnpiped=!0,r("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,!o.awaitDrain||t._writableState&&!t._writableState.needDrain||l())}));var l=function(t){return function(){var e=t._readableState;r("pipeOnDrain",e.awaitDrain),e.awaitDrain&&e.awaitDrain--,0===e.awaitDrain&&s(t,"data")&&(e.flowing=!0,N(t))}}(n);t.on("drain",l);var h=!1;function u(e){r("ondata");var i=t.write(e);r("dest.write",i),!1===i&&((1===o.pipesCount&&o.pipes===t||o.pipesCount>1&&-1!==j(o.pipes,t))&&!h&&(r("false write response, pause",o.awaitDrain),o.awaitDrain++),n.pause())}function d(e){r("onerror",e),v(),t.removeListener("error",d),0===s(t,"error")&&k(t,e)}function f(){t.removeListener("finish",p),v()}function p(){r("onfinish"),t.removeListener("close",f),v()}function v(){r("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),o.flowing||(r("pipe resume"),n.resume()),t},_.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,o=e.pipesCount;e.pipes=null,e.pipesCount=0,e.flowing=!1;for(var r=0;r0,!1!==o.flowing&&this.resume()):"readable"===t&&(o.endEmitted||o.readableListening||(o.readableListening=o.needReadable=!0,o.flowing=!1,o.emittedReadable=!1,r("on readable",o.length,o.reading),o.length?E(this):o.reading||i.nextTick(B,this))),n},_.prototype.addListener=_.prototype.on,_.prototype.removeListener=function(t,e){var n=a.prototype.removeListener.call(this,t,e);return"readable"===t&&i.nextTick(D,this),n},_.prototype.removeAllListeners=function(t){var e=a.prototype.removeAllListeners.apply(this,arguments);return"readable"!==t&&void 0!==t||i.nextTick(D,this),e},_.prototype.resume=function(){var t=this._readableState;return t.flowing||(r("resume"),t.flowing=!t.readableListening,function(t,e){e.resumeScheduled||(e.resumeScheduled=!0,i.nextTick(O,t,e))}(this,t)),t.paused=!1,this},_.prototype.pause=function(){return r("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(r("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},_.prototype.wrap=function(t){var e=this,i=this._readableState,n=!1;for(var o in t.on("end",(function(){if(r("wrapped end"),i.decoder&&!i.ended){var t=i.decoder.end();t&&t.length&&e.push(t)}e.push(null)})),t.on("data",(function(o){r("wrapped data"),i.decoder&&(o=i.decoder.write(o)),(!i.objectMode||null!=o)&&(i.objectMode||o&&o.length)&&(e.push(o)||(n=!0,t.pause()))})),t)void 0===this[o]&&"function"==typeof t[o]&&(this[o]=function(e){return function(){return t[e].apply(t,arguments)}}(o));for(var s=0;s-1))throw new b(t);return this._writableState.defaultEncoding=t,this},Object.defineProperty(_.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(_.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),_.prototype._write=function(t,e,i){i(new v("_write()"))},_.prototype._writev=null,_.prototype.end=function(t,e,n){var o=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),o.corked&&(o.corked=1,this.uncork()),o.ending||function(t,e,n){e.ending=!0,C(t,e),n&&(e.finished?i.nextTick(n):t.once("finish",n)),e.ended=!0,t.writable=!1}(this,o,n),this},Object.defineProperty(_.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(_.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(t){this._writableState&&(this._writableState.destroyed=t)}}),_.prototype.destroy=u.destroy,_.prototype._undestroy=u.undestroy,_.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":37,"./_stream_duplex":38,"./internal/streams/destroy":45,"./internal/streams/state":49,"./internal/streams/stream":50,_process:32,buffer:14,inherits:21,"util-deprecate":58}],43:[function(t,e,i){(function(i){(function(){"use strict";var n;function o(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}var r=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((o(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,o=this[h];if(o)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)}}(o,this));else{var r=this[d].read();if(null!==r)return Promise.resolve(f(r,!1));n=new Promise(this[u])}return this[h]=n,n}},Symbol.asyncIterator,(function(){return this})),o(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,(o(e={},d,{value:t,writable:!0}),o(e,s,{value:null,writable:!0}),o(e,a,{value:null,writable:!0}),o(e,c,{value:null,writable:!0}),o(e,l,{value:t._readableState.endEmitted,writable:!0}),o(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,r(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":46,_process:32}],44:[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 o(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function r(t,e){for(var i=0;i0?this.tail.next=e:this.head=e,this.tail=e,++this.length}},{key:"unshift",value:function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length}},{key:"shift",value:function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(t){if(0===this.length)return"";for(var e=this.head,i=""+e.data;e=e.next;)i+=t+e.data;return i}},{key:"concat",value:function(t){if(0===this.length)return s.alloc(0);for(var e,i,n,o=s.allocUnsafe(t>>>0),r=this.head,a=0;r;)e=r.data,i=o,n=a,s.prototype.copy.call(e,i,n),a+=r.data.length,r=r.next;return o}},{key:"consume",value:function(t,e){var i;return to.length?o.length:t;if(r===o.length?n+=o:n+=o.slice(0,t),0==(t-=r)){r===o.length?(++i,e.next?this.head=e.next:this.head=this.tail=null):(this.head=e,e.data=o.slice(r));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 o=i.data,r=t>o.length?o.length:t;if(o.copy(e,e.length-t,0,r),0==(t-=r)){r===o.length?(++n,i.next?this.head=i.next:this.head=this.tail=null):(this.head=i,i.data=o.slice(r));break}++n}return this.length-=n,e}},{key:c,value:function(t,e){return a(this,function(t){for(var e=1;e0,(function(t){h||(h=t),t&&d.forEach(c),r||(d.forEach(c),u(h))}))}));return i.reduce(l)}},{"../../../errors":37,"./end-of-stream":46}],49:[function(t,e,i){"use strict";var n=t("../../../errors").codes.ERR_INVALID_OPT_VALUE;e.exports={getHighWaterMark:function(t,e,i,o){var r=function(t,e,i){return null!=t.highWaterMark?t.highWaterMark:e?t[i]:null}(e,o,i);if(null!=r){if(!isFinite(r)||Math.floor(r)!==r||r<0)throw new n(o?i:"highWaterMark",r);return Math.floor(r)}return t.objectMode?16:16384}}},{"../../../errors":37}],50:[function(t,e,i){e.exports=t("events").EventEmitter},{events:19}],51:[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":38,"./lib/_stream_passthrough.js":39,"./lib/_stream_readable.js":40,"./lib/_stream_transform.js":41,"./lib/_stream_writable.js":42,"./lib/internal/streams/end-of-stream.js":46,"./lib/internal/streams/pipeline.js":48}],52:[function(t,e,i){"use strict";e.exports=function(){if("function"!=typeof arguments[0])throw new Error("callback needed");if("number"!=typeof arguments[1])throw new Error("interval needed");var t;if(arguments.length>0){t=new Array(arguments.length-2);for(var e=0;e>5==6?2:t>>4==14?3:t>>3==30?4:t>>6==2?-1:-2}function a(t){var e=this.lastTotal-this.lastNeed,i=function(t,e,i){if(128!=(192&e[0]))return t.lastNeed=0,"�";if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"�";if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"�"}}(this,t);return void 0!==i?i:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),void(this.lastNeed-=t.length))}function c(t,e){if((t.length-e)%2==0){var i=t.toString("utf16le",e);if(i){var n=i.charCodeAt(i.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],i.slice(0,-1)}return i}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function l(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var i=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,i)}return e}function h(t,e){var i=(t.length-e)%3;return 0===i?t.toString("base64",e):(this.lastNeed=3-i,this.lastTotal=3,1===i?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-i))}function u(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function d(t){return t.toString(this.encoding)}function f(t){return t&&t.length?this.write(t):""}i.StringDecoder=r,r.prototype.write=function(t){if(0===t.length)return"";var e,i;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return"";i=this.lastNeed,this.lastNeed=0}else i=0;return i=0?(o>0&&(t.lastNeed=o-1),o):--n=0?(o>0&&(t.lastNeed=o-2),o):--n=0?(o>0&&(2===o?o=0:t.lastNeed=o-3),o):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)},r.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":53}],56:[function(t,e,i){"use strict";var n=t("punycode"),o=t("./util");function r(){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 o.isString(t)&&(t=w(t)),t instanceof r?t.format():r.prototype.format.call(t)},i.Url=r;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&&o.isObject(t)&&t instanceof r)return t;var n=new r;return n.parse(t,e,i),n}r.prototype.parse=function(t,e,i){if(!o.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var r=t.indexOf("?"),a=-1!==r&&r127?M+="x":M+=L[D];if(!M.match(f)){var O=E.slice(0,S),N=E.slice(S+1),U=L.match(p);U&&(O.push(U[1]),N.unshift(U[2])),N.length&&(w="/"+N.join(".")+w),this.hostname=O.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),I||(this.hostname=n.toASCII(this.hostname));var F=this.port?":"+this.port:"",H=this.hostname||"";this.host=H+F,this.href+=this.host,I&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==w[0]&&(w="/"+w))}if(!v[k])for(S=0,C=h.length;S0)&&i.host.split("@"))&&(i.auth=I.shift(),i.host=i.hostname=I.shift())),i.search=t.search,i.query=t.query,o.isNull(i.pathname)&&o.isNull(i.search)||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.href=i.format(),i;if(!A.length)return i.pathname=null,i.search?i.path="/"+i.search:i.path=null,i.href=i.format(),i;for(var _=A.slice(-1)[0],P=(i.host||t.host||A.length>1)&&("."===_||".."===_)||""===_,S=0,T=A.length;T>=0;T--)"."===(_=A[T])?A.splice(T,1):".."===_?(A.splice(T,1),S++):S&&(A.splice(T,1),S--);if(!b&&!k)for(;S--;S)A.unshift("..");!b||""===A[0]||A[0]&&"/"===A[0].charAt(0)||A.unshift(""),P&&"/"!==A.join("/").substr(-1)&&A.push("");var I,E=""===A[0]||A[0]&&"/"===A[0].charAt(0);return R&&(i.hostname=i.host=E?"":A.length?A.shift():"",(I=!!(i.host&&i.host.indexOf("@")>0)&&i.host.split("@"))&&(i.auth=I.shift(),i.host=i.hostname=I.shift())),(b=b||i.host&&A.length)&&!E&&A.unshift(""),A.length?i.pathname=A.join("/"):(i.pathname=null,i.path=null),o.isNull(i.pathname)&&o.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},r.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":57,punycode:33,querystring:36}],57:[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}}},{}],58:[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:{})},{}],59:[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{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,o=n;const{x:r,y:s,width:a,height:c,ex:l,ey:h}=t.calculative.worldRect;n<1&&(n*=a,o*=c);let u=nJi,activityDiagram:()=>pn,activityDiagramByCtx:()=>vn,chartsPens:()=>Nr,classPens:()=>sn,flowAnchors:()=>Ln,flowPens:()=>Cn,formPens:()=>tr,ftaAnchors:()=>kr,ftaPens:()=>xr,ftaPensbyCtx:()=>br,registerEcharts:()=>oo,registerHighcharts:()=>ro,registerLightningChart:()=>so,sequencePens:()=>ln,sequencePensbyCtx:()=>hn});const e=t;var o,r,s,a;!function(t){t[t.Node=0]="Node",t[t.Line=1]="Line"}(o||(o={})),function(t){t[t.None=0]="None",t[t.DisableEdit=1]="DisableEdit",t[t.DisableMove=2]="DisableMove",t[t.Disable=10]="Disable"}(r||(r={})),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"]);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"],x=["n-resize","e-resize","s-resize","w-resize"],b=["curve","polyline","line"];var k,A;function R(t,e,i){if(!e||e%360==0)return;const n=e*Math.PI/180,o=(t.x-i.x)*Math.cos(n)-(t.y-i.y)*Math.sin(n)+i.x,r=(t.x-i.x)*Math.sin(n)+(t.y-i.y)*Math.cos(n)+i.y;t.x=o,t.y=r,t.prev&&R(t.prev,e,i),t.next&&R(t.next,e,i)}function _(t,e,i=5){return t.x>e.x-i&&t.xe.y-i&&t.y0&&n>0?o=180-o:i<0&&n>0?o+=180:i<0&&n<0&&(o=360-o),o}function T(t,e){const i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)}function I(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 E(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"}(k||(k={})),function(t){t[t.Default=0]="Default",t[t.In=1]="In",t[t.Out=2]="Out"}(A||(A={}));const C="1.1.0",L={version:C,path2dDraws:{},canvasDraws:{},anchors:{},htmlElements:{}};function M(t){Object.assign(L.path2dDraws,t)}function D(t){Object.assign(L.canvasDraws,t)}function B(t){Object.assign(L.anchors,t)}var O;!function(t){t[t.None=-1]="None",t[t.Document=0]="Document",t[t.Canvas=1]="Canvas"}(O||(O={}));const N={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};var U;!function(t){t[t.Add=0]="Add",t[t.Update=1]="Update",t[t.Delete=2]="Delete"}(U||(U={}));function F(t){const{paddingTop:e,paddingBottom:i,paddingLeft:n,paddingRight:o,worldRect:r,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*=r.width),c&&Math.abs(c)<1&&(c*=r.height);const f=r.width-n-o-(a||0),p=r.height-e-i-(c||0);l&&l<1&&(l*=r.width),h&&h<1&&(h*=r.height),l{const o=t.measureText(n).width;e.calculative.textLineWidths.push(o),i1?r:1;switch(t.whiteSpace){case"nowrap":if(!1!==t.ellipsis){const n=W(e.split(""),t);i.push(n[0]),n.length>1&&q(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),q(i));break;default:const n=e.split(/[\n]/g);let o=0;t:for(const e of n){let n=W("break-all"===t.whiteSpace?e.split(""):z(e),t);if(0===n.length&&(n=[""]),0!=t.ellipsis)for(const t of n){if(o++,o>s){q(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 z(t=""){const e=[];let i="";for(let n=0;n126?(i&&(e.push(i),i=""),e.push(t[n])):i+=t[n]}return i&&e.push(i),e}function W(t,e){const i=e.calculative.canvas,n=i.offscreen.getContext("2d"),{fontStyle:o,fontWeight:r,fontSize:s,fontFamily:a,lineHeight:c}=e.calculative;n.save();const l=[];let h=t[0]||"";for(let u=1;u{i.push(V(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]=V(t[n],e));return i}return t}const K={};function Y(t){const e=parseInt,i=Math.round;let n=t.length,o={};if(n>9){const[i,r,s,a]=t=t.split(",");if(n=t.length,n<3||n>4)return null;o.r=e("a"==i[3]?i.slice(5):i.slice(4)),o.g=e(r),o.b=e(s),o.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?(o.r=t>>24&255,o.g=t>>16&255,o.b=t>>8&255,o.a=i((255&t)/.255)/1e3):(o.r=t>>16,o.g=t>>8&255,o.b=255&t,o.a=-1)}return o}function $(t,e){const i=Y(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 X(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 o=e.substring(1,e.length-1).split(",");if(2!==o.length)return void console.warn("collection must have 2 numbers");const[r,s]=[+o[0],+o[1]];if(!(r>=s))return(t>r||"["===i&&t===r)&&(t=r)return void console.warn("startNum must less than endNum");if(t>=o&&t<=r)return!0}else if(t===+e)return!0;return!1}function Q(){return(4294967296*(1+Math.random())|0).toString(16).substring(1)}function J(){return/Android|webOS|iPad|iPhone|iPod|BlackBerry|X11|CrOS/i.test(navigator.userAgent)}K.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 o=n.x-n.step;t.moveTo(o,n.y-n.step/4),t.lineTo(n.x,n.y),t.lineTo(o,n.y+n.step/4),t.closePath(),t.stroke(),t.fillStyle=t.strokeStyle,t.fill(),t.restore()},K.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 o=n.x-n.step;t.moveTo(o,n.y-n.step/4),t.lineTo(n.x,n.y),t.lineTo(o,n.y+n.step/4),t.closePath(),t.stroke(),t.fillStyle=i.data.background||"#ffffff",t.fill(),t.restore()},K.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 o=n.step/2;t.arc(n.x-o,n.y,o,0,2*Math.PI),t.stroke(),t.fillStyle=t.strokeStyle,t.fill(),t.restore()},K.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 o=n.step/2;t.arc(n.x-o,n.y,o,0,2*Math.PI),t.stroke(),t.fillStyle=i.data.background||"#ffffff",t.fill(),t.restore()},K.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 o=n.x-n.step,r=n.step/2;t.moveTo(o,n.y),t.lineTo(o+r,n.y-r/2),t.lineTo(n.x,n.y),t.lineTo(o+r,n.y+r/2),t.closePath(),t.stroke(),t.fillStyle=t.strokeStyle,t.fill(),t.restore()},K.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 o=n.x-n.step,r=n.step/2;t.moveTo(o,n.y),t.lineTo(o+r,n.y-r/2),t.lineTo(n.x,n.y),t.lineTo(o+r,n.y+r/2),t.closePath(),t.stroke(),t.fillStyle=i.data.background||"#ffffff",t.fill(),t.restore()},K.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 o=n.x-n.step;t.moveTo(o,n.y-n.step/3),t.lineTo(n.x,n.y),t.lineTo(o,n.y+n.step/3),t.stroke(),t.restore()},K.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 o=n.x-n.step;t.moveTo(o,n.y-n.step/3),t.lineTo(n.x,n.y),t.stroke(),t.restore()},K.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 o=n.x-n.step;t.moveTo(o,n.y+n.step/3),t.lineTo(n.x,n.y),t.stroke(),t.restore()},window.pSBC=function(t,e,i,n){let o,r,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=Y(e),a=t<0,l=i&&"c"!=i?Y(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?(o=u(a*c.r+t*l.r),r=u(a*c.g+t*l.g),s=u(a*c.b+t*l.b)):(o=u((a*c.r**2+t*l.r**2)**.5),r=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(":"(")+o+","+r+","+s+(c?","+u(1e3*d)/1e3:"")+")":"#"+(4294967296+16777216*o+65536*r+256*s+(c?u(255*d):0)).toString(16).slice(1,c?void 0:-2)):null)};const Z=t=>{let e=0,i=0,n=0,o=0;return"number"==typeof t?e=i=n=o=t:"string"==typeof t?e=i=n=o=parseInt(t,10):Array.isArray(t)&&(e=t[0],n=tt(t[1])?t[0]:t[1],o=tt(t[2])?t[0]:t[2],i=tt(t[3])?n:t[3]),[e,n,o,i]};function tt(t){return null==t}function et(t,e){if(!t||!t.parentId||!t.calculative)return;const i=t.calculative.canvas.store.pens[t.parentId];return e&&et(i,e)||i}function it(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(...it(n,e)))})),i}function nt(t,e,i,n,o){if(!i||!n)return;const{x:r,y:s,center:a,ex:c,ey:l}=e,h={x:r,y:a.y},u={x:c,y:a.y};o%90==0&&o%180?(h.x=a.x,u.x=a.x,o%270?(h.y=s,u.y=l):(h.y=l,u.y=s)):o&&(R(h,o,e.center),R(u,o,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 ot(t,e){const{x:i,y:n,width:o,height:r}=function(t){const{worldIconRect:e,iconWidth:i,iconHeight:n,imgNaturalWidth:o,imgNaturalHeight:r}=t.calculative;let{x:s,y:a,width:c,height:l}=e;if(i&&(c=i),n&&(l=n),o&&r&&t.imageRatio){const t=e.width/o,s=e.height/r,a=Math.min(t,s),h=o/r;i?l=i/h:n?c=n*h:(c=a*o,l=a*r)}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,o,r)}function rt(t,e){const{textColor:i,color:n}=t.calculative,{data:o,options:r}=e;return i||n||o.color||r.textColor||r.color}function st(t,e){const{fontStyle:i,fontWeight:n,fontSize:o,fontFamily:r,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||rt(e,d),t.font=lt({fontStyle:i,fontWeight:n,fontFamily:r||d.options.fontFamily,fontSize:o,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=o*s;e.calculative.textLines.forEach(((i,n)=>{const o=e.calculative.textLineWidths[n];let r=0;"center"===m?r=(g-o)/2:"right"===m&&(r=g-o),t.fillText(i,p+r,v+(n+.55)*w)})),t.restore()}function at(t,e,i){if(null==i)return;const{fontStyle:n,fontWeight:o,fontSize:r,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||rt(e,l),t.font=lt({fontStyle:n,fontWeight:o,fontFamily:s||l.options.fontFamily,fontSize:r,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=T(f,n),o=Math.floor(e/u);d="";for(let t=0;t0?e.calculative.iconSize:n.width>n.height?n.height:n.width,t.font=lt({fontSize:a,fontWeight:s,fontFamily:c}),t.fillStyle=e.calculative.iconColor||rt(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,o,r),t.restore()}function lt({fontStyle:t="normal",textDecoration:e="normal",fontWeight:i="normal",fontSize:n=12,fontFamily:o="Arial",lineHeight:r=1}={}){return`${t} ${e} ${i} ${n}px/${r} ${o}`}function ht(t,e){const{x:i,ex:n,y:o,ey:r}=e.calculative.worldRect||{};e.calculative.flipX&&(t.translate(i+n+.5,.5),t.scale(-1,1)),e.calculative.flipY&&(t.translate(.5,o+r+.5),t.scale(1,-1))}function ut(t,e){const{x:i,y:n}=e.calculative.worldRect.center;t.translate(i,n);let o=e.calculative.rotate*Math.PI/180;(e.calculative.flipX||e.calculative.flipY)&&(o*=-1),t.rotate(o),t.translate(-i,-n)}function dt(t,e){t.save(),t.translate(.5,.5),t.beginPath(),ht(t,e),e.calculative.rotate&&"line"!==e.name&&ut(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:o,height:r}=i.calculative.worldTextRect;t.fillRect(e,n,o,r),t.restore()}}(t,i,e);let r=!0;if(e.calculative.hover)t.strokeStyle=e.hoverColor||i.options.hoverColor,n=e.hoverBackground||i.options.hoverBackground,t.fillStyle=n,n&&(r=!1);else if(e.calculative.active)t.strokeStyle=e.activeColor||i.options.activeColor,n=e.activeBackground||i.options.activeBackground,t.fillStyle=n,n&&(r=!1);else if(e.calculative.isDock)e.type===o.Line?t.strokeStyle=i.options.dockPenColor:(n=$(i.options.dockPenColor,.2),t.fillStyle=n,n&&(r=!1));else{const i=e.calculative.strokeImg;if(e.calculative.strokeImage&&i)t.strokeStyle=t.createPattern(i,"repeat"),n=!0;else{let i;i=e.calculative.strokeType===a.Linear?function(t,e){const{worldRect:i,lineGradientFromColor:n,lineGradientToColor:o,lineGradientAngle:r}=e.calculative;return nt(t,i,n,o,r)}(t,e):e.calculative.color,t.strokeStyle=i}}if(r){const o=e.calculative.backgroundImg;if(e.calculative.backgroundImage&&o)t.fillStyle=t.createPattern(o,"repeat"),n=!0;else{let o;o=e.calculative.bkType===a.Linear?function(t,e){const{worldRect:i,gradientFromColor:n,gradientToColor:o,gradientAngle:r}=e.calculative;return nt(t,i,n,o,r)}(t,e):e.calculative.bkType===a.Radial?function(t,e){const{worldRect:i,gradientFromColor:n,gradientToColor:o,gradientRadius:r}=e.calculative;if(!n||!o)return;const{width:s,height:a,center:c}=i,{x:l,y:h}=c;let u=s;u1&&(t.lineWidth=e.calculative.lineWidth);const n=e.calculative.canvas.store;let r;if(e.calculative.hover?(t.strokeStyle=e.hoverColor||n.options.hoverColor,t.fillStyle=e.hoverBackground||n.options.hoverBackground,r=e.hoverBackground||n.options.hoverBackground):e.calculative.active?(t.strokeStyle=e.activeColor||n.options.activeColor,t.fillStyle=e.activeBackground||n.options.activeBackground,r=e.activeBackground||n.options.activeBackground):(e.strokeImage?e.calculative.strokeImg&&(t.strokeStyle=t.createPattern(e.calculative.strokeImg,"repeat"),r=!0):t.strokeStyle=e.calculative.color||yt(n),e.backgroundImage?e.calculative.backgroundImg&&(t.fillStyle=t.createPattern(e.calculative.backgroundImg,"repeat"),r=!0):(t.fillStyle=e.background,r=!!e.background)),ft(t,e),pt(t,e),Kt(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),gt(!1,t,e,n,r),Yt(t,e),e.calculative.img?(t.save(),t.shadowColor="",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0,ot(t,e),t.restore()):e.calculative.icon&&ct(t,e),st(t,e),e.type===o.Line&&e.fillTexts)for(const i of e.fillTexts)at(t,e,i);t.restore()}function gt(t=!0,e,i,n,r){const s=t?n.path2dMap.get(i):L.path2dDraws[i.name];if(s){if(i.type===o.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?(r&&e.fill(s),t&&e.stroke(s)):(s(i,e),r&&e.fill(),t&&e.stroke()),e.restore()}s instanceof Path2D?r&&e.fill(s):(e.save(),s(i,e),r&&e.fill(),e.restore());const t=i.calculative.progress;if(null!=t){e.save();const{x:o,y:r,width:a,height:c,ey:l}=i.calculative.worldRect,h=i.verticalProgress?e.createLinearGradient(o,l,o,r+c*(1-t)):e.createLinearGradient(o,r,o+a*t,r),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(),function(t,e,i){t.strokeStyle=e.animateColor||i.options.animateColor;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 i=e.animateLineDash&&e.animateLineDash.map((t=>t*n/5));t.setLineDash(i||[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=n,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])}}(e,i,n),s instanceof Path2D?e.stroke(s):(s(i,e),e.stroke()),e.restore()),i.fromArrow&&function(t,e,i){if(!K[e.fromArrow])return;const n=Et(e),{x:o,y:r}=n,s={x:o,y:r};if(s.step=(e.fromArrowSize||10)*i.data.scale,n.next)s.rotate=S(n.next,n)+90;else{const t=e.calculative.worldAnchors[1];if(!t)return;t.prev?s.rotate=S(t.prev,n)+90:s.rotate=S(t,n)+90}t.save(),t.beginPath();const a=e.fromArrowColor||e.calculative.color;a&&(t.strokeStyle=a),K[e.fromArrow](t,e,i,s),t.restore()}(e,i,n),i.toArrow&&function(t,e,i){if(!K[e.toArrow]||e.calculative.worldAnchors.length<2)return;t.save();const n=Ct(e),{x:o,y:r}=n,s={x:o,y:r};if(s.step=(e.toArrowSize||10)*i.data.scale,n.prev)s.rotate=S(n.prev,n)+90;else{const t=e.calculative.worldAnchors[e.calculative.worldAnchors.length-2];t.next?s.rotate=S(t.next,n)+90:s.rotate=S(t,n)+90}t.beginPath();const a=e.toArrowColor||e.calculative.color;a&&(t.strokeStyle=a),K[e.toArrow](t,e,i,s),t.restore()}(e,i,n),i.calculative.active&&!i.calculative.pencil&&function(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 o=3;i.calculative.lineWidth>3&&(o=i.calculative.lineWidth),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,o,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,o,0,2*Math.PI),t.fill(),t.stroke(),t.restore(),t.beginPath(),t.arc(e.x,e.y,o,0,2*Math.PI),t.fill(),t.stroke()),t.beginPath(),t.arc(e.x,e.y,o,0,2*Math.PI),t.fill(),t.stroke()):(t.save(),t.fillStyle="#ffffff",t.beginPath(),t.arc(e.x,e.y,o,0,2*Math.PI),t.fill(),t.stroke(),t.restore())}(t,i,e)})),t.restore()}(e,i))}}function yt(t){const{data:e,options:i}=t;return e.color||i.color}function mt(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 o=n.calculative.worldRect;o||(o=mt(n)),i.x=o.x+o.width*t.x,i.y=o.y+o.height*t.y,i.width=o.width*t.width,i.height=o.height*t.height,n.flipX&&(i.x=o.width-(i.x-o.x+i.width)+o.x),n.flipY&&(i.y=o.height-(i.y-o.y+i.height)+o.y),re(i),i.rotate=o.rotate+t.rotate,oe(i)}else i.width=t.width,i.height=t.height,i.rotate=t.rotate,re(i),oe(i);return t.calculative.worldRect=i,wt(t,i),i}function wt(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 xt(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,pe(e,i))}function bt(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:o,width:r,height:s}=t.calculative.worldRect;return i.x=n+r*e.x,i.y=o+s*e.y,e.prev&&(i.prev={penId:t.id,connectTo:e.prev.connectTo,x:n+r*e.prev.x,y:o+s*e.prev.y}),e.next&&(i.next={penId:t.id,connectTo:e.next.connectTo,x:n+r*e.next.x,y:o+s*e.next.y}),i}(t,e))})),!i.length&&!t.type&&"combine"!==t.name){const{x:n,y:o,width:r,height:s}=t.calculative.worldRect;i=e.options.defaultAnchors.map(((e,i)=>({id:`${i}`,penId:t.id,x:n+r*e.x,y:o+s*e.y})))}t.calculative.rotate&&i.forEach((e=>{R(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})))}function kt(t,e){const{paddingTop:i,paddingBottom:n,paddingLeft:o,paddingRight:r}=e.calculative;let s=o,a=i,c=e.calculative.worldRect.width-o-r,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},re(e.calculative.worldIconRect),oe(e.calculative.worldIconRect)}function At(t,e,i){fe(t.calculative.worldRect,e,i),t.calculative.initRect&&fe(t.calculative.initRect,e,i),t.calculative.x&&P(t.calculative,e,i),t.type&&bt(t)}function Rt(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,o=t.y-e.y;return i=Math.abs(n)>Math.abs(o)?n>0?m.Right:m.Left:o>0?m.Bottom:m.Up,i}(t,e.calculative.worldRect.center):m.None}function _t(t,e){let i,n=1/0;return t.calculative.worldAnchors.forEach((t=>{const o=T(e,t);n>o&&(n=o,i=t)})),i}function Pt(t){if(t&&t.calculative&&t.calculative.worldAnchors.length){let e=Ct(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=Ct(t)}}function St(t,e,i,n){if(t&&e&&i&&n&&(n.connectTo!==t.id||n.anchorId!==e.id)){if(n.connectTo){const e=t.calculative.canvas.store.pens[n.connectTo];Tt(e,It(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&&St(i,n,t,e),!0}}function Tt(t,e,i,n){if(t&&e&&i&&n&&t.connectedLines&&t.connectedLines.length)return t.connectedLines.forEach(((t,o,r)=>{t.lineId!==i.id&&t.lineId!==i.id||t.lineAnchor!==n.id||t.anchor!==e.id||r.splice(o,1)})),n.connectTo=void 0,n.anchorId=void 0,t.type&&e.connectTo===i.id&&e.anchorId===n.id&&Tt(i,n,t,e),!0}function It(t,e){if(t&&e)return t.calculative.worldAnchors?.find((t=>t.id===e))}function Et(t){if(t&&t.calculative.worldAnchors)return t.calculative.worldAnchors[0]}function Ct(t){if(t&&t.calculative.worldAnchors)return t.calculative.worldAnchors[t.calculative.worldAnchors.length-1]}function Lt(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,Dt(t,1),0;const o=(e-t.calculative.start)%t.calculative.duration;let r=0;for(const e of t.frames){if(r+=e.duration,!(o>r))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 Mt(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=V(t.calculative.worldRect),t.calculative.initRect.rotate=t.calculative.rotate||0,Mt(t);return Dt(t,(e-t.calculative.frameStart)/t.calculative.frameDuration%1),!0}function Mt(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 Dt(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=V(t.calculative.initRect),fe(t.calculative.worldRect,t.prevFrame.scale,t.calculative.worldRect.center);const o=t.prevFrame.scale+(i[n]-t.prevFrame.scale)*e;fe(t.calculative.worldRect,o/t.prevFrame.scale,t.calculative.worldRect.center),t.calculative.dirty=!0}else if("x"===n){const o=Wt(t,n,t.calculative.frameIndex);t.calculative.worldRect.x=t.calculative.initRect.x+o,t.calculative.worldRect.ex=t.calculative.initRect.ex+o,he(t.calculative.worldRect,i[n]*e*t.calculative.canvas.store.data.scale,0),t.calculative.dirty=!0}else if("y"===n){const o=Wt(t,n,t.calculative.frameIndex);t.calculative.worldRect.y=t.calculative.initRect.y+o,t.calculative.worldRect.ey=t.calculative.initRect.ey+o,he(t.calculative.worldRect,0,i[n]*e*t.calculative.canvas.store.data.scale),t.calculative.dirty=!0}else if("rotate"===n){t.prevFrame[n]>=360&&(t.prevFrame[n]%=360);const o=Wt(t,n,t.calculative.frameIndex);t.calculative.rotate=(t.calculative.initRect.rotate+o+i[n]*e)%360,t.calculative.dirty=!0}else if(Bt(i[n],n,t)){null==t.prevFrame[n]&&(t.prevFrame[n]="globalAlpha"===n?1:0);const o=t.prevFrame[n]+(i[n]-t.prevFrame[n])*e;t.calculative[n]=Math.round(100*o)/100}else t.calculative[n]=i[n];"text"===n&&j(t)}}function Bt(t,e,i){return"number"==typeof t&&!1!==i.linear&&!["strokeType","bkType","showChild"].includes(e)}function Ot(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 Nt(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,Nt(n,e))}))}function Ut(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&&Ut(i.pens[t],e)}))}function Ft(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.locked===r.DisableEdit||t.locked===r.DisableMove||i.data.locked?(e.style.userSelect="initial",e.style.pointerEvents="initial"):(e.style.userSelect="none",e.style.pointerEvents="none")}function Ht(t){return t.every((t=>t.locked))}function jt(t){return t.every((t=>t.disableRotate))}function zt(t){return t.every((t=>t.disableSize))}function Wt(t,e,i){if(!t.frames||!e)return 0;let n=0;for(let o=0;o{const e=i.pens[t];e&&Vt(e,!0)})),t.calculative.inView=!0,qt(t,i)&&0!=t.visible&&0!=t.calculative.visible){const{x:e,y:o,width:r,height:s,rotate:a}=t.calculative.worldRect,c={x:e+i.data.x,y:o+i.data.y,width:r,height:s,rotate:a};re(c),le(c,n)||(t.calculative.inView=!1)}else t.calculative.inView=!1;t.onMove?.(t)}function Kt(t,e){const i=e.calculative.globalAlpha;i<1&&(t.globalAlpha=i)}function Yt(t,e){const i=L.canvasDraws[e.name];i&&(t.save(),i(t,e),t.restore())}function $t(t,e,i){let n,o,r=1/0,s=1/0;for(const a of t.data.pens)!1!==a.calculative.inView&&Gt(a).forEach((t=>{if(t===e||t===i)return;const a=Math.abs(t.x-e.x);a>0&&a<8&&a0&&c<8&&c{t.x+=n.x,t.y+=n.y}))):(oe(e),o=[e.center,...ae(e)]),Jt(t,o,e,!0)}function Gt(t){if(!t.type){const e=ae(t.calculative.worldRect);return oe(t.calculative.worldRect),[...e,...t.calculative.worldAnchors,t.calculative.worldRect.center]}if(t.type===o.Line)return t.calculative.worldAnchors}function Qt(t,e,i,n){return Jt(t,ae(e),e)}function Jt(t,e,i,n=!1){let o,r,s=1/0,a=1/0;const c=function(t,e){const i=Z(8),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 re(n),n}(i),l=t.data.pens.filter((e=>{const{inView:i,worldRect:o,active:r}=e.calculative;return!(!1===i||!n&&r||(s=c,a=o,(a.x>s.ex||a.exs.ey||a.eyZt(t,i,e))));var s,a}));for(const t of l){const i=Gt(t);for(const n of i)for(const i of e){const e=n.x-i.x,c=n.y-i.y,l=Math.abs(e),h=Math.abs(c);l<8&&le.x&&t.xe.y&&t.y{R(t,e.rotate,e.center)})),function(t,e){if(e.length<3)return!1;let i=!1,n=e[e.length-1];for(const o of e)n.y>t.y!=o.y>t.y&&o.x+(t.y-o.y)*(n.x-o.x)/(n.y-o.y)>t.x&&(i=!i),n=o;return i}(t,i)}function ne(t,e,i=0){const{x:n,y:o,ex:r,ey:s}=e;return t.x>=n-i&&t.x<=r+i&&t.y>=o-i&&t.y<=s+i}function oe(t){t.center||(t.center={}),t.center.x=t.x+t.width/2,t.center.y=t.y+t.height/2}function re(t){t.ex=t.x+t.width,t.ey=t.y+t.height}function se(t){const e=[];t.forEach((t=>{if(t.isRuleLine)return;const i=t.calculative.worldRect;if(i){const t=ae(i);e.push(...t)}}));const i=ce(e);return oe(i),i}function ae(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||oe(t),e.forEach((e=>{R(e,t.rotate,t.center)}))),e}function ce(t){let e=1/0,i=1/0,n=-1/0,o=-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),o=Math.max(o,t.y))})),isFinite(e)||console.error("getRectOfPoints 非法的 points",t),{x:e,y:i,ex:n,ey:o,width:n-e,height:o-i}}function le(t,e,i){return t.rotate&&(t=ce(ae(t))),i?t.x>e.x&&t.exe.y&&t.eye.ex||t.exe.ey)}function he(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 ue(t,e){if(te(t.k,0))return{x:e.point.x,y:t.point.y};if(te(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 de(t,e,i,n){if(t.rotate&&t.rotate%360){const o=ae(t),r=(o[0].y-o[1].y)/(o[0].x-o[1].x),s=(o[1].y-o[2].y)/(o[1].x-o[2].x);if(n<4){o[n].x+=e,o[n].y+=i;const t=o[(n+2)%4];o[(n+1)%4]=ue({k:n%2?s:r,point:o[n]},{k:n%2?r:s,point:t}),o[(n+4-1)%4]=ue({k:n%2?r:s,point:o[n]},{k:n%2?s:r,point:t})}else{const t=[4,6].includes(n)?s:r;te(t,0)?(o[n%4].x+=e,o[(n+1)%4].x+=e):(o[n%4].y+=i,o[n%4].x+=i/t,o[(n+1)%4].y+=i,o[(n+1)%4].x+=i/t)}if((o[0].x-o[1].x)**2+(o[0].y-o[1].y)**2<25||(o[1].x-o[2].x)**2+(o[1].y-o[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 ue({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)R(n,-e,i);return ce(t)}(o,t.rotate);return oe(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 fe(t,e,i){t&&(t.width*=e,t.height*=e,P(t,e,i),re(t),oe(t))}function pe(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 re(i),i}function ve(t,e){const{x:i,y:n,width:o,height:r}=e,{id:s,penId:a,connectTo:c,anchorId:l,prevNextType:h,hidden:u}=t,d={id:s,penId:a,connectTo:c,x:o?(t.x-i)/o:0,y:r?(t.y-n)/r:0,anchorId:l,prevNextType:h,hidden:u};return t.prev&&(d.prev={penId:a,connectTo:c,x:o?(t.prev.x-i)/o:0,y:r?(t.prev.y-n)/r:0}),t.next&&(d.next={penId:a,connectTo:c,x:o?(t.next.x-i)/o:0,y:r?(t.next.y-n)/r:0}),d}const ge=/^[\t\n\f\r ]*([MLHVZCSQTAmlhvzcsqta])[\t\n\f\r ]*/,ye=/^[01]/,me=/^[+-]?(([0-9]*\.[0-9]+)|([0-9]+\.)|([0-9]+))([eE][+-]?[0-9]+)?/,we=/^(([\t\n\f\r ]+,?[\t\n\f\r ]*)|(,[\t\n\f\r ]*))/,xe={M:[me,me],L:[me,me],H:[me],V:[me],Z:[],C:[me,me,me,me,me,me],S:[me,me,me,me],Q:[me,me,me,me],T:[me,me],A:[me,me,me,ye,ye,me,me]};function be(t){let e=1/0,i=1/0,n=-1/0,o=-1/0;return function(t){let e,i=0,n=0;t.commands.forEach((t=>{switch(t.key){case"Z":case"z":t.worldPoints=[i,n];break;case"H":t.worldPoints=[t.values[0],e.worldPoints[e.worldPoints.length-1]];break;case"h":t.worldPoints=[t.values[0]+e.worldPoints[e.worldPoints.length-2],e.worldPoints[e.worldPoints.length-1]];break;case"V":t.worldPoints=[e.worldPoints[e.worldPoints.length-2],t.values[0]];break;case"v":case"A":t.worldPoints=[e.worldPoints[e.worldPoints.length-2],t.values[0]+e.worldPoints[e.worldPoints.length-1]];break;default:!function(t,e){const i=[];let n=t.relative&&e?{x:e.worldPoints[e.worldPoints.length-2],y:e.worldPoints[e.worldPoints.length-1]}:{x:0,y:0};for(let e=0;e{t.worldPoints.forEach(((t,r)=>{r%2==0?(tn&&(n=t)):(to&&(o=t))}))})),--e,--i,{x:e,y:i,ex:n,ey:o,width:n-e+1,height:o-i+1}}function ke(t,e,i){const n=xe[t.toUpperCase()],o=[];for(;i<=e.length;){const r={key:t,values:[]};for(const t of n){const n=e.slice(i).match(t);if(null===n){if(0===r.values.length)return{cursor:i,commands:o};throw new Error("malformed path (first error at "+i+")")}{r.values.push(+n[0]),i+=n[0].length;const t=e.slice(i).match(we);null!==t&&(i+=t[0].length)}}if(r.relative=r.key.toUpperCase()!==r.key,o.push(r),0===n.length)return{cursor:i,commands:o};"m"===t&&(t="l"),"M"===t&&(t="L")}throw new Error("malformed path (first error at "+i+")")}function Ae(t,e){const i=t.calculative.canvas.store.data.paths[t.pathId];if(!i)return new Path2D;const n=function(t){let e=0;const i=[];for(;e{switch(t.key){case"A":case"a":const n=t.values[0],o=t.values[1],r=Math.PI*t.values[2]/180,s=Math.cos(r),a=Math.sin(r),c=o*o*i*i*s*s+n*n*i*i*a*a,l=2*e*i*s*a*(o*o-n*n),h=n*n*e*e*s*s+o*o*e*e*a*a,u=-n*n*o*o*e*e*i*i,d=l*l-4*c*h,f=Math.sqrt((c-h)*(c-h)+l*l);t.values[2]=0!==l?180*Math.atan((h-c-f)/l)/Math.PI:c=0?t.values[4]:1-t.values[4];break;case"V":case"v":t.values[0]*=i;break;default:t.values.forEach(((n,o)=>{t.values[o]=n*(o%2==0?e:i)}))}}))}(n,t.calculative.worldRect.width/t.calculative.svgRect.width,t.calculative.worldRect.height/t.calculative.svgRect.height);const o=be(n);oe(o),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,o)=>{t.values[o]=n+(o%2==0?e:i)}))}}))}(n,t.calculative.worldRect.x-o.x,t.calculative.worldRect.y-o.y);const r=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(r);e.svgPath?.(r)}function Re(t,e){const{x:i,y:n,width:o,ex:r,ey:s}=e.calculative.worldRect;let a=.25*o;const c=e.z;c>1?a=c:c>0&&(a=o*c);const l={x:i,y:n+a},h={x:r-a,y:n+a},u={x:r-a,y:s};_e(t,[l,h,u,{x:i,y:s}],e.backgroundFront||e.background,e.color),_e(t,[l,{x:i+a,y:n},{x:r,y:n},h],e.backgroundUp||e.background,e.color),_e(t,[h,{x:r,y:n},{x:r,y:s-a},u],e.backgroundRight||e.background,e.color)}function _e(t,e,i="",n=""){t.save(),i&&(t.fillStyle=i),n&&(t.strokeStyle=n),t.beginPath();for(let i=0;in.x?m.Right:m.Left),n.next={id:Q(),penId:e.id,x:n.x,y:n.y,prevNextType:2},o.prev={id:Q(),penId:e.id,x:o.x,y:o.y,prevNextType:2},r){case m.Up:n.next.y-=20,o.prev.y=n.y;break;case m.Bottom:n.next.y+=20,o.prev.y=n.y;break;case m.Left:n.next.x-=20,o.prev.x=n.x;break;default:n.next.x+=20,o.prev.x=n.x}}function Le(t,e){const i=e||new Path2D,n=t.calculative.worldAnchors;if(n.length>1){let e;n.forEach((t=>{e?De(i,e,t):t.start=!0,e=t})),t.close&&De(i,e,n[0])}if(i instanceof Path2D)return i}function Me(t,e,i){if(e.calculative.worldAnchors||(e.calculative.worldAnchors=[]),e.calculative.worldAnchors.length<2||e.anchors?.length>1)return;const n=Et(e),o=Ct(e);n&&o&&o.id&&n!==o&&(n.next=void 0,Pt(e),o.prev=void 0,e.calculative.worldAnchors.push(o))}function De(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 Be(t){return je(t),ce(function(t){const e=[];let i;return t.calculative.worldAnchors.forEach((n=>{e.push(n),i&&e.push(...Ne(i,n,t)),i=n})),t.close&&t.calculative.worldAnchors.length>1&&e.push(...Ne(i,t.calculative.worldAnchors[0],t)),e}(t))}function Oe(t){return t?.lineWidth?t.lineWidth/2+4:4}function Ne(t,e,i){const n=[];if(!e)return n;let o=.02;if(t.lineLength&&(o=Oe(i)/t.lineLength),t.next)if(e.prev)for(let i=o;i<1;i+=o)n.push(Ie(i,t,t.next,e.prev,e));else for(let i=o;i<1;i+=o)n.push(Te(i,t,t.next,e));else if(e.prev)for(let i=o;i<1;i+=o)n.push(Te(i,t,e.prev,e));else n.push({x:e.x,y:e.y});return n.length>1&&(t.curvePoints=n),n}function Ue(t,e){const i=Oe(e);let n,o,r=0;for(const s of e.calculative.worldAnchors){if(n){if(o=Fe(t,n,s,i),o)return{i:r,point:o};++r}n=s}if(e.close&&e.calculative.worldAnchors.length>1&&(o=Fe(t,n,e.calculative.worldAnchors[0],i)))return{i:r,point:o}}function Fe(t,e,i,n=4){if(!e.next&&!i.prev){const{x:o,y:r}=e,{x:s,y:a}=i,c=Math.min(o,s),l=Math.max(o,s),h=Math.min(r,a),u=Math.max(r,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 o=(e.y-i.y)/(e.x-i.x),r=e.y-o*e.x;if(Math.abs((o*t.x+r-t.y)/Math.sqrt(o*o+1))<=n){const e=(t.x+o*t.y-o*r)/(o*o+1);return{x:e,y:o*e+r}}}}(t,e,i,n)}if(e.curvePoints)for(const i of e.curvePoints)if(_(t,i,n))return i}function He(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 o=document.createElementNS("http://www.w3.org/2000/svg","path");return e&&i?o.setAttribute("d",`M${t.x} ${t.y} C${e.x} ${e.y} ${i.x} ${i.y} ${n.x} ${n.y}`):e?o.setAttribute("d",`M${t.x} ${t.y} Q${e.x} ${e.y} ${n.x} ${n.y}`):o.setAttribute("d",`M${t.x} ${t.y} Q${i.x} ${i.y} ${n.x} ${n.y}`),o.getTotalLength()||0}function je(t){if(t.calculative.worldAnchors.length<2)return 0;let e,i=0;if(t.calculative.worldAnchors.forEach((t=>{e&&(e.lineLength=He(e,e.next,t.prev,t),i+=e.lineLength),e=t})),t.close){const n=Et(t);e.lineLength=He(e,e.next,n.prev,n),i+=e.lineLength}return t.length=i,i}function ze(t,e,i){if(ne(t,i)||ne(e,i))return!0;const n=t.x,o=t.y,r=e.x,s=e.y;let a=i.x,c=i.y,l=i.ex,h=i.ey;const u=o-s,d=r-n,f=n*s-r*o;if(u*a+d*c+f>=0&&u*l+d*h+f<=0||u*a+d*c+f<=0&&u*l+d*h+f>=0||u*a+d*h+f>=0&&u*l+d*c+f<=0||u*a+d*h+f<=0&&u*l+d*c+f>=0){if(a>l){const t=a;a=l,l=t}if(cl&&r>l||o>c&&s>c||ot.y)o=t.x+(e.x-t.x)/2,n.push({x:o,y:t.y},{x:o,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:o=e.x,r=t.y,e.xt.x&&e.yt.y-qe)o=t.x+(e.x-t.x)/2,n.push({x:o,y:t.y},{x:o,y:e.y});else{const i=(t.y+e.y+qe)/2;n.push({x:t.x,y:i},{x:e.x,y:i})}}return n}(o,r,h));break;case m.Right:s.push(...function(t,e,i){if(t.x===e.x||t.y===e.y)return[];const n=[];let o,r;switch(i){case m.Up:o=t.x,r=e.y,e.x>t.x&&e.y>t.y&&(o=e.x,r=t.y),n.push({x:o,y:r});break;case m.Bottom:o=t.x,r=e.y,e.x>t.x&&e.yt.y&&(o=t.x,r=e.y),n.push({x:o,y:r});break;case m.Bottom:t.y>e.y?(o=e.x,r=t.y):(o=t.x,r=e.y),n.push({x:o,y:r});break;case m.Left:o=e.x,r=t.y,e.x>t.x&&e.y>t.y&&(o=t.x,r=e.y),n.push({x:o,y:r});break;default:if(o=t.x,e.yt.y&&(o=e.x,r=t.y),n.push({x:o,y:r});break;case m.Bottom:o=t.x,r=e.y,e.xt.x)o=e.x,r=t.y+(e.y-t.y)/2,n.push({x:t.x,y:r},{x:e.x,y:r});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(o=t.x,r=e.y,e.xMath.abs(i.y-e.y)),t.calculative.worldAnchors.length&&(i.isTemp=void 0,t.calculative.drawlineH?(n.push({x:i.x,y:e.y}),Math.abs(i.y-e.y){t.id=Q(),t.penId=e.id,e.calculative.worldAnchors.push(t)})),e.calculative.worldAnchors.push(r),u&&e.calculative.worldAnchors.push(d),n&&e.calculative.worldAnchors.reverse()}function Ke(t,e,i){const n={x:t.x,y:t.y,id:Q()};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 Ye(t,e,i,n){const o=[];let r,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,r=e;for(let e=i+1;e1?(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>r&&(s=e,r=y);return r>e&&(s-i>1&&o.push(...Ye(t,e,i,s)),o.push({id:t[s].id,penId:t[s].penId,x:t[s].x,y:t[s].y}),n-s>1&&o.push(...Ye(t,e,s,n))),o}const $e={};function Xe(t){if(t.onDestroy||(t.onDestroy=Ge,t.onMove=Qe,t.onResize=Qe,t.onRotate=Qe,t.onValue=Qe,t.onChangeId=Je),$e[t.id])$e[t.id].getAttribute("src")!==t.iframe&&($e[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,$e[t.id]=e,t.calculative.iframe=t.iframe,t.calculative.canvas.externalElements?.appendChild(e),Ft(t,e)}return t.calculative.dirty&&Ft(t,$e[t.id]),new Path2D}function Ge(t){$e[t.id].remove(),$e[t.id]=void 0}function Qe(t){$e[t.id]&&(Ft(t,$e[t.id]),$e[t.id].getAttribute("src")!==t.iframe&&($e[t.id].src=t.iframe))}function Je(t,e,i){$e[e]&&($e[i]=$e[e],delete $e[e])}const Ze={};function ti(t){if(t.onDestroy||(t.onDestroy=ei,t.onMove=ii,t.onResize=ii,t.onRotate=ii,t.onClick=ni,t.onValue=si,t.onChangeId=ri),Ze[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=()=>{oi(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),Ze[t.id]=e,t.calculative.canvas.externalElements?.appendChild(e),Ft(t,e),t.autoPlay&&(n.autoplay=!0,n.muted=!0)}return t.calculative.dirty&&Ft(t,Ze[t.id]),new Path2D}function ei(t){Ze[t.id].remove(),Ze[t.id]=void 0}function ii(t){Ft(t,Ze[t.id]),oi(Ze[t.id].children[0],Ze[t.id].children[1],t.calculative.worldRect.width)}function ni(t){t.calculative.media&&(t.calculative.media.muted=!1,t.calculative.media.paused?t.calculative.media.play():t.calculative.media.pause())}function oi(t,e,i){t.style.width=e.currentTime/e.duration*i+"px"}function ri(t,e,i){Ze[e]&&(Ze[i]=Ze[e],delete Ze[e])}function si(t){const e=Ze[t.id];if(!e)return;Ft(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 ai(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;if(i.ellipse(n+r/2,o+s/2,r/2,s/2,0,0,2*Math.PI),i instanceof Path2D)return i}function ci(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;if(i.moveTo(n+r/2,o),i.lineTo(n+r,o+s/2),i.lineTo(n+r/2,o+s),i.lineTo(n,o+s/2),i.lineTo(n+r/2,o),i.closePath(),i instanceof Path2D)return i}function li(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;if(i.moveTo(n+r/2,o),i.lineTo(n+r,o+s),i.lineTo(n,o+s),i.lineTo(n+r/2,o),i.closePath(),i instanceof Path2D)return i}function hi(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 ui(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;if(i.moveTo(n+r/2,o),i.lineTo(n+r,o+2*s/5),i.lineTo(n+4*r/5,o+s),i.lineTo(n+r/5,o+s),i.lineTo(n,o+2*s/5),i.closePath(),i instanceof Path2D)return i}function di(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 fi(t,e){t.onResize||(t.onResize=vi);const i=e||new Path2D,{width:n,height:o,center:r}=t.calculative.worldRect,s=n>o?o:n,a=r.x,c=r.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 pi(t){const{width:e,height:i}=t,n=e>i?i:e,o=[];for(let r=0;r<5;++r)o.push({flag:1,id:String(r),penId:t.id,x:.5+n/2*Math.sin(Math.PI/180*72*r)/e,y:-n/2*Math.cos(Math.PI/180*72*r)/i+.5});t.anchors=o}function vi(t){const e=t.anchors.filter((t=>1!==t.flag));pi(t),t.anchors=t.anchors.concat(...e)}function gi(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;if(i.moveTo(n+r/4,o),i.lineTo(n+3*r/4,o),i.lineTo(n+r,o+s/2),i.lineTo(n+3*r/4,o+s),i.lineTo(n+1*r/4,o+s),i.lineTo(n,o+s/2),i.lineTo(n+r/4,o),i.closePath(),i instanceof Path2D)return i}function yi(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;if(i.moveTo(n,o+s/2),i.lineTo(n+s/2,o),i.lineTo(n+s/2,o+s/3),i.lineTo(n+r,o+s/3),i.lineTo(n+r,o+2*s/3),i.lineTo(n+s/2,o+2*s/3),i.lineTo(n+s/2,o+2*s/3),i.lineTo(n+s/2,o+s),i.closePath(),i instanceof Path2D)return i}function mi(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;if(i.moveTo(n,o+s/3),i.lineTo(n+(r-s/2),o+s/3),i.lineTo(n+(r-s/2),o),i.lineTo(n+r,o+s/2),i.lineTo(n+(r-s/2),o+s),i.lineTo(n+(r-s/2),o+2*s/3),i.lineTo(n,o+2*s/3),i.closePath(),i instanceof Path2D)return i}function wi(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;if(i.moveTo(n,o+s/2),i.lineTo(n+s/2,o),i.lineTo(n+s/2,o+s/3),i.lineTo(n+(r-s/2),o+s/3),i.lineTo(n+(r-s/2),o),i.lineTo(n+r,o+s/2),i.lineTo(n+(r-s/2),o+s),i.lineTo(n+(r-s/2),o+2*s/3),i.lineTo(n+s/2,o+2*s/3),i.lineTo(n+s/2,o+s),i.closePath(),i instanceof Path2D)return i}function xi(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s,ey:a}=t.calculative.worldRect;if(i.moveTo(n,o),i.lineTo(n+r,o),i.lineTo(n+r,o+3*s/4),i.lineTo(n+8*r/16,o+3*s/4),i.lineTo(n+r/4,a),i.lineTo(n+5*r/16,o+3*s/4),i.lineTo(n,o+3*s/4),i.closePath(),i instanceof Path2D)return i}function bi(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;if(i.moveTo(n+r/5,o+13*s/16),i.bezierCurveTo(n-r/15,o+13*s/16,n-r/15,o+7*s/16,n+r/5,o+7*s/16),i.bezierCurveTo(n+r/5,o,n+4*r/5,o,n+4*r/5,o+7*s/16),i.bezierCurveTo(n+16*r/15,o+7*s/16,n+16*r/15,o+13*s/16,n+4*r/5,o+13*s/16),i.closePath(),i instanceof Path2D)return i}function ki(t,e){const i=e||new Path2D,{x:n,y:o,width:r,ex:s,ey:a}=t.calculative.worldRect,c=r/6;if(i.moveTo(n,o),i.lineTo(s-c,o),i.lineTo(s,o+c),i.lineTo(s,a),i.lineTo(n,a),i.closePath(),i.moveTo(s-c,o),i.lineTo(s-c,o+c),i.lineTo(s,o+c),i.closePath(),i instanceof Path2D)return i}function Ai(t,e){const i=e||new Path2D,{x:n,y:o,width:r,ex:s,ey:a}=t.calculative.worldRect,c=r/4,l=n+r/2;if(i.arc(l,o+c,c,0,2*Math.PI),i.moveTo(n,o+3*c),i.lineTo(s,o+3*c),i.moveTo(l,o+2*c),i.lineTo(l,o+4*c),i.moveTo(l,o+4*c),i.lineTo(n,a),i.moveTo(l,o+4*c),i.lineTo(s,a),i.closePath(),i instanceof Path2D)return i}const Ri={};function _i(t){t.onDestroy||(t.onDestroy=Pi,t.onMove=Si,t.onResize=Ti,t.onRotate=Si,t.onValue=Ii,t.onChangeId=Ei);const e=new Path2D;if(t.image){if(!Ri[t.id]){const e=new Image;e.crossOrigin="anonymous",e.src=t.image,Ri[t.id]=e,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),Ci(t,e)}}return t.calculative.dirty&&Ri[t.id]&&Ci(t,Ri[t.id]),e}}function Pi(t){Ri[t.id].remove(),Ri[t.id]=void 0}function Si(t){Ri[t.id]&&Ci(t,Ri[t.id])}function Ti(t){Ri[t.id]&&Ci(t,Ri[t.id])}function Ii(t){Ri[t.id]&&(Ci(t,Ri[t.id]),Ri[t.id].getAttribute("src")!==t.image&&(Ri[t.id].src=t.image))}function Ei(t,e,i){Ri[e]&&(Ri[i]=Ri[e],delete Ri[e])}function Ci(t,e){e.style.objectFit=t.imageRatio?"contain":"fill",Ft(t,e)}function Li(e,i){return e.onResize||(e.onResize=Mi,e.onValue=Di),t(e,i)}function Mi(t){const e=t.anchors.filter((t=>1!==t.flag));Bi(t),t.anchors=t.anchors.concat(...e)}function Di(t){Mi(t),bt(t)}function Bi(t){const e=[],{x:i,y:n,width:o,height:r}=t,s=function(t){let e=t.calculative.borderRadius||0,i=t.calculative.borderRadius||0;const{width:n,height:o}=t;t.calculative.borderRadius<1&&(e=n*t.calculative.borderRadius,i=o*t.calculative.borderRadius);let r=ei+o-s&&(l=Ni(i+o-s,l+s,c,s,-1)),e.push({id:String(e.length),flag:1,penId:t.id,x:(c-i)/o,y:(l-n)/r})}for(let a=0;a<3;a++){let c=n+r*(a+1)/4,l=i+o;cn+r-s&&(l=Oi(l-s,n+r-s,c,s)),e.push({id:String(e.length),flag:1,penId:t.id,x:(l-i)/o,y:(c-n)/r})}for(let a=0;a<5;a++){if(2===a)continue;let c=i+o*(a+1)/6,l=n+r;ci+o-s&&(l=Ni(i+o-s,l-s,c,s)),e.push({id:String(e.length),flag:1,penId:t.id,x:(c-i)/o,y:(l-n)/r})}for(let a=0;a<3;a++){let c=n+r*(a+1)/4,l=i;cn+r-s&&(l=Oi(l+s,n+r-s,c,s,-1)),e.push({id:String(e.length),flag:1,penId:t.id,x:(l-i)/o,y:(c-n)/r})}t.anchors=e}function Oi(t,e,i,n,o=1){return o*Math.sqrt(n**2-(i-e)**2)+t}function Ni(t,e,i,n,o=1){return o*Math.sqrt(n**2-(i-t)**2)+e}function Ui(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;if(i.moveTo(n,o+s),i.lineTo(n+r,o+s),i.closePath(),i instanceof Path2D)return i}function Fi(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 Hi(){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 ji{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="topology-tooltip",this.text.className="text",this.arrowUp.className="arrow",this.arrowDown.className="arrow down",this.box.appendChild(this.text),this.box.appendChild(this.arrowUp),this.box.appendChild(this.arrowDown),t.appendChild(this.box),this.box.onmouseleave=()=>{this.hide(),this.store.lastHover=void 0};for(let t=0;t0?(this.arrowUp.style.borderBottomColor="transparent",this.arrowDown.style.borderTopColor="#777777"):(r+=i.height+n.height+5,this.arrowUp.style.borderBottomColor="#777777",this.arrowDown.style.borderTopColor="transparent"),this.x=o,this.y=r,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 zi{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="topology-scroll h",this.h.onmousedown=this.onMouseDownH,this.v.className="topology-scroll v",this.v.onmousedown=this.onMouseDownV,document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp);for(let t=0;t0?this.rect.width+=this.parent.store.data.x+(this.rect.x>0?0:this.rect.x):this.rect.width-=this.parent.store.data.x+(this.rect.x>0?0:this.rect.x),this.parent.store.data.y>0?this.rect.height+=this.parent.store.data.y+(this.rect.y>0?0:this.rect.y):this.rect.height-=this.parent.store.data.y+(this.rect.y>0?0:this.rect.y),this.rect.width<1400&&(this.rect.width=1400),this.rect.height<900&&(this.rect.height=900),this.hSize=1e3*this.parent.parentElement.clientWidth/this.rect.width/3,this.vSize=1e3*this.parent.parentElement.clientHeight/this.rect.height/3,this.h.style.width=this.hSize+"px",this.v.style.height=this.vSize+"px"}show(){this.isShow=!0,this.h.style.display="block",this.v.style.display="block",document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp)}hide(){this.isShow=!1,this.h.style.display="none",this.v.style.display="none",this.destroy()}translate(t,e){t&&(this.scrollX-=t*this.parent.parentElement.clientWidth/this.rect.width,this.h.style.left=`${this.scrollX}px`),e&&(this.scrollY-=e*this.parent.parentElement.clientHeight/this.rect.height,this.v.style.top=`${this.scrollY}px`)}wheel(t){let e=10;t&&(e=-10),this.scrollY+=e,this.v.style.top=`${this.scrollY}px`,this.parent.store.data.y-=e*this.rect.height/this.parent.parentElement.clientHeight,this.parent.onMovePens(),this.parent.render()}destroy(){document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp)}}class Wi{constructor(t,e,i){this.parentElement=t,this.store=e,this.isBottom=i,this.canvas=document.createElement("canvas"),this.otherOffsreen=Hi(),this.offscreen=Hi(),this.animateOffsScreen=Hi(),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.dirtyBackground=!0,this.store.dirtyTop=!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));const i=this.store.dirtyBackground;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.dirtyTop;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)||(e.calculative.imageDrawed=!0,t.save(),ht(t,e),e.calculative.rotate&&ut(t,e),Kt(t,e),ot(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(),ht(t,e),e.calculative.rotate&&ut(t,e),Kt(t,e),ot(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.dirtyBackground=!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.dirtyTop=!1)}}renderGrid(t){const{data:e,options:i}=this.store,{grid:n,gridRotate:o,gridColor:r,gridSize:s,scale:a}=e;if(!(n??i.grid))return;t.save();const{width:c,height:l}=this.canvas;o&&(t.translate(c/2,l/2),t.rotate(o*Math.PI/180),t.translate(-c/2,-l/2)),t.lineWidth=1,t.strokeStyle=r||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:o,scale:r,origin:s}=e;if(!(n??i.rule))return;const a=10*r;t.save();const c=o||i.ruleColor;t.strokeStyle=$(c,.7);const l=s.x+e.x,h=s.y+e.y,{width:u,height:d}=this.canvas;t.beginPath(),t.lineWidth=12,t.lineDashOffset=-l%a,t.setLineDash([1,a-1]),t.moveTo(0,0),t.lineTo(u,0),t.stroke(),t.beginPath(),t.lineDashOffset=-h%a,t.moveTo(0,0),t.lineTo(0,d),t.stroke(),t.strokeStyle=c,t.beginPath(),t.lineWidth=24,t.lineDashOffset=-l%(10*a),t.setLineDash([1,10*a-1]),t.moveTo(0,0),t.lineTo(u,0),t.stroke(),t.beginPath(),t.lineDashOffset=-h%(10*a),t.moveTo(0,0),t.lineTo(0,d),t.stroke(),t.beginPath(),t.fillStyle=t.strokeStyle;let f=0-100*Math.floor(l/a/10);l<0&&(f-=100);for(let e=l%(10*a);e{i.drawImage(e,n-t,o-t,this.magnifierSize,this.magnifierSize,0,0,this.magnifierSize,this.magnifierSize)})),i.restore(),i.beginPath();const r=i.createRadialGradient(t,t,t-5,t,t,t);r.addColorStop(0,"rgba(0,0,0,0.2)"),r.addColorStop(.8,"rgb(200,200,200)"),r.addColorStop(.9,"rgb(200,200,200)"),r.addColorStop(1,"rgba(200,200,200,0.9)"),i.strokeStyle=r,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,(o-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 Vi(t){if(t.data.locked)throw new Error("canvas is locked")}const Ki="-moving";class Yi{constructor(t,e,i){this.parent=t,this.parentElement=e,this.store=i,this.canvas=document.createElement("canvas"),this.offscreen=Hi(),this.externalElements=document.createElement("div"),this.lastRotate=0,this.hoverType=v.None,this.resizeIndex=0,this.lastOffsetX=0,this.lastOffsetY=0,this.drawLineFns=[...b],this.dirtyLines=new Set,this.lastMouseTime=0,this.hoverTimer=0,this.dirty=!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.alreadyCopy=!1,this.stopPropagation=t=>{t.stopPropagation()},this.curve=Pe,this.polyline=Ve,this.mind=Ce,this.line=Me,this.onwheel=t=>{if("true"===this.inputDiv.contentEditable)return;if(t.preventDefault(),t.stopPropagation(),this.store.options.scroll&&!t.ctrlKey&&!t.metaKey&&this.scroll)return void this.scroll.wheel(t.deltaY<0);if(this.store.options.disableScale)return;if(this.store.data.locked===r.Disable)return;const e=!(!t.deltaX&&t.deltaY),i=performance.now();if(i-this.touchStart<50)return;this.touchStart=i;const{offsetX:n,offsetY:o}=t;e?this.translate(t.deltaX,t.deltaY):t.deltaY<0?this.scale(this.store.data.scale+.1,{x:n,y:o}):this.scale(this.store.data.scale-.1,{x:n,y:o}),this.externalElements.focus()},this.onkeydown=t=>{if(this.store.data.locked>=r.DisableMove||"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.dirty=!0,this.hotkeyType=g.Select);break;case"Meta":case"Alt":break;case"Shift":if(this.drawingLine){const t=Ct(this.drawingLine);t!==this.drawingLine.calculative.activeAnchor?(Pt(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.drawline(),this.dirty=!0}else 1===this.store.active.length&&this.store.active[0].type&&this.store.activeAnchor?this.toggleAnchorHand():this.hotkeyType||(this.dirty=!0,this.hotkeyType=g.Resize);break;case"a":case"A":t.ctrlKey||t.metaKey?(this.active(this.store.data.pens.filter((t=>!t.parentId))),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"x":case"X":(t.ctrlKey||t.metaKey)&&this.cut();break;case"c":case"C":(t.ctrlKey||t.metaKey)&&this.copy();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);break;case"v":case"V":t.ctrlKey||t.metaKey?this.paste():this.drawingLineName?(this.finishDrawline(),this.drawingLineName=""):this.drawingLineName=this.store.options.drawingLineName;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,L.path2dDraws.line(t)),je(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.dirty=!0),this.hotkeyType=g.None,this.movingAnchor=void 0,this.magnifierCanvas.magnifier&&(this.magnifierCanvas.magnifier=!1,this.dirty=!0)}this.render(!1)},this.onkeyup=t=>{"Alt"===t.key&&this.drawingLine&&(this.store.options.autoAnchor=!this.store.options.autoAnchor),this.hotkeyType&&this.render(),this.hotkeyType{if(this.store.data.locked)console.warn("canvas is locked, can not drop");else try{t.preventDefault(),t.stopPropagation();const e=t.dataTransfer.getData("Topology")||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!==r.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===r.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,o=t.touches[0].pageX-this.clientRect.x,s=t.touches[0].pageY-this.clientRect.y;if(1===n)this.onMouseMove({x:o,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){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,o=this.startTouches[1].pageY-i[1].pageY;(t>=0&&e<0||t<=0&&e>0)&&(n>=0&&o<0||n<=0&&o>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,V(this.touchCenter))}if(this.touchMoving){if(this.store.data.locked>=r.DisableMove||this.store.options.disableScale)return;if(this.lastOffsetX){const{scale:t}=this.store.data;this.translate((o-this.lastOffsetX)/t,(s-this.lastOffsetY)/t)}this.lastOffsetX=o,this.lastOffsetY=s}}},this.ontouchend=t=>{if(this.store.data.locked===r.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===r.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.hotkeyType!==g.Translate&&this.mouseRight!==y.Down){if(this.drawingLine){if(this.store.hoverAnchor){const t=Ct(this.drawingLine);return t.x=this.store.hoverAnchor.x,t.y=this.store.hoverAnchor.y,St(this.store.hover,this.store.hoverAnchor,this.drawingLine,t),this.drawline(),void this.finishDrawline(!0)}if(2===t.buttons||"mind"===this.drawingLineName&&this.drawingLine?.calculative.worldAnchors.length>1)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=Ct(this.drawingLine),i=_t(this.store.hover,t);return e.x=i.x,e.y=i.y,this.drawingLine.autoTo=!0,St(this.store.hover,i,this.drawingLine,e),this.drawline(),void this.finishDrawline(!0)}const e=Ct(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})),"polyline"===this.drawingLineName&&(this.drawingLine.autoPolyline=!1),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=_t(this.store.hover,t);this.store.hoverAnchor=e;const i={id:Q(),x:e.x,y:e.y};this.drawingLine=this.createDrawingLine(i),this.drawingLine.autoFrom=!0,St(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:Q(),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=Q(),i={x:t.x,y:t.y,id:Q(),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=et(this.store.hover,!0)||this.store.hover;t.ctrlKey&&!t.shiftKey?(e.calculative.active?this.willInactivePen=e:(e.calculative.active=!0,Nt(e),this.store.active.push(e),this.store.emitter.emit("active",this.store.active)),this.dirty=!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===r.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){if(this.mouseRight===y.Down&&(this.mouseRight=y.Translate),this.store.data.locked===r.DisableEdit||this.hotkeyType===g.Translate||this.mouseRight===y.Translate){const{scale:e}=this.store.data;return void this.translate((t.x-this.mouseDown.x)/e,(t.y-this.mouseDown.y)/e)}if(this.store.data.locked)return;if(this.drawingLine||this.pencil){if(this.pencil){const e={...t};e.id=Q(),e.penId=this.pencilLine.id,this.pencilLine.calculative.worldAnchors.push(e),this.store.path2dMap.set(this.pencilLine,L.path2dDraws[this.pencilLine.name](this.pencilLine)),this.dirty=!0}}else{if(this.drawingLineName||this.movingAnchor){if(this.drawingLineName&&this.hoverType===v.None){const e={id:Q(),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:Q(),x:this.store.hoverAnchor.x,y:this.store.hoverAnchor.y};return this.drawingLine=this.createDrawingLine(t),this.drawingLine.calculative.activeAnchor=t,St(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.disableDockLine||(this.clearDock(),this.dock=$t(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);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&&!this.alreadyCopy&&(Math.abs(e)>=n||Math.abs(i)>=n)&&(this.alreadyCopy=!0,this.willInactivePen=void 0),1===this.store.active.length){const t=this.store.active[0];t.locked1&&(i=Ct(this.drawingLine)),i?(i.prev=void 0,i.next=void 0,i.id||(i.id=Q()),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),"line"===this.drawingLineName&&(t.ctrlKey?i.y=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].y:t.altKey&&(i.x=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].x)),this.drawline()}}window&&window.debug&&console.time("hover");const e=performance.now();e-this.hoverTimer>50&&(this.hoverTimer=e,this.getHover(t)),window&&window.debug&&console.timeEnd("hover"),this.hotkeyType===g.AddAnchor&&(this.dirty=!0),this.render(!1)},this.onMouseUp=t=>{if(this.store.data.locked!==r.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=Ct(this.drawingLine);return t.x=this.store.hoverAnchor.x,t.y=this.store.hoverAnchor.y,St(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=Ct(this.drawingLine),i=_t(this.store.hover,t);return e.x=i.x,e.y=i.y,this.drawingLine.autoTo=!0,St(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]&&this.store.active[0]!==this.store.hover){const e=this.store.active[0],i=Et(e),n=Ct(e);if(this.store.hoverAnchor){const r=this.store.hover,s=Et(r)===this.store.hoverAnchor,a=Ct(r)===this.store.hoverAnchor,c=i===this.store.activeAnchor,l=n===this.store.activeAnchor;if((t.ctrlKey||t.altKey)&&r.type===o.Line&&(s||a)&&(c||l)){const t=r.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([r]),this.render()}else this.store.activeAnchor.x=this.store.hoverAnchor.x,this.store.activeAnchor.y=this.store.hoverAnchor.y,St(this.store.hover,this.store.hoverAnchor,e,this.store.activeAnchor);this[e.lineName]&&this[e.lineName](this.store,e),this.store.path2dMap.set(e,L.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.dirtyLines.forEach((t=>{t.type&&this.initLineRect(t)})),this.dirtyLines.clear(),this.dragRect){const t=this.store.data.pens.filter((t=>!1!==t.visible&&t.locked!==r.Disable&&!t.parentId&&(le(t.calculative.worldRect,this.dragRect,this.store.options.dragAllIn)?!(t.type===o.Line&&!this.store.options.dragAllIn)||function(t,e){const i=t.calculative.worldAnchors;for(let t=0;tt===this.willInactivePen)),1),this.calcActiveRect(),this.willInactivePen=void 0,this.store.emitter.emit("inactive",[this.willInactivePen]),this.render()),this.movingPens&&(this.alreadyCopy?this.copyMovedPens():this.movedActivePens(),this.getAllByPens(this.movingPens).forEach((t=>{this.store.pens[t.id]=void 0})),this.movingPens=void 0,this.translatePens(this.movingPens,0,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=Ht(this.store.active),n=jt(this.store.active)||this.store.options.disableRotate,o=zt(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&&R(i,this.activeRect.rotate,this.activeRect.center),!this.hotkeyType&&_(t,i,this.pointSize)&&(e=v.Rotate,this.externalElements.style.cursor=`url("${this.store.options.rotateCursor}"), auto`)}if(!i&&!o)for(let i=0;i<8;i++){const n=i<4;if((this.hotkeyType===g.Resize||n&&!this.hotkeyType)&&_(t,this.sizeCPs[i],this.pointSize)){let t=n?w:x,o=0;Math.abs(this.activeRect.rotate%90-45)<25?(t=n?x:w,o=Math.round((this.activeRect.rotate-45)/90)+(n?0:1)):o=Math.round(this.activeRect.rotate/90),e=v.Resize,this.resizeIndex=i,this.externalElements.style.cursor=t[(i+o)%4];break}}}e===v.None&&(e=this.inPens(t,this.store.data.pens)),e||i||!ie(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.dirty=!0,this.store.lastHover&&(this.store.lastHover.calculative.hover=!1,Ut(et(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,Ut(et(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 o=e[n];if(0==o.visible||0==o.calculative.inView||o.locked===r.Disable)continue;const s=Oe(o);if(o.calculative.active||ne(t,o.calculative.worldRect,s)||ie(t,o.calculative.worldRect)){if(!this.store.data.locked&&this.hotkeyType!==g.Resize&&o.calculative.worldAnchors)for(const e of o.calculative.worldAnchors)if(i=this.inAnchor(t,o,e),i)break t;if(o.type){const e=Ue(t,o);if(e){this.store.data.locked||o.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=o,this.store.pointAt=e.point,this.store.pointAtIndex=e.i,i=v.Line;break}}else{if(o.children){const e=[];if(o.children.forEach((t=>{e.push(this.store.pens[t])})),i=this.inPens(t,e),i)break}let e=!1;if(e="line"===o.name?ne(t,o.calculative.worldRect,o.lineWidth):ie(t,o.calculative.worldRect),e){if(this.store.data.locked||o.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=o,i=v.Node,this.store.pointAt=t,!t.ctrlKey){let{x:e,y:i,ex:n,ey:o,rotate:r,center:s}=this.store.hover.calculative.worldRect;if(r){const a=[{x:e,y:i},{x:n,y:i},{x:n,y:o},{x:e,y:o}];a.forEach((t=>{R(t,r,s)}));let c=a[a.length-1];for(const e of a){if(c.y>t.y!=e.y>t.y){const i=e.x+(t.y-e.y)*(c.x-e.x)/(c.y-e.y);Math.abs(i-this.store.pointAt.x)<10&&(this.store.pointAt.x=i)}c=e}}else this.store.pointAt.x-10n&&(this.store.pointAt.x=n),this.store.pointAt.y-10o&&(this.store.pointAt.y=o)}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===r.Disable||i===this.store.active[0])continue;let n=Oe(i);if(n+=2*this.store.options.anchorRadius,ne(t,i.calculative.worldRect,n)&&(this.store.hover=i,this.hotkeyType!==g.Resize&&i.calculative.worldAnchors))for(const e of i.calculative.worldAnchors)if(this.inAnchor(t,i,e))return!0}},this.render=t=>{let e;if(null==t||!0===t?(e=performance.now(),this.dirty=!0):e=t>1?t:performance.now(),!this.dirty)return;if(e-this.lastRender{const t=this.offscreen.getContext("2d");t.strokeStyle=yt(this.store);for(const e of this.store.data.pens)isFinite(e.x)||console.warn(e,"画笔的 x 不合法"),e.calculative.inView&&dt(t,e);this.drawingLine&&dt(t,this.drawingLine),this.pencilLine&&dt(t,this.pencilLine),this.movingPens&&this.movingPens.forEach((e=>{this.renderPenContainChild(t,e)}))},this.renderPenContainChild=(t,e)=>{e.calculative.inView&&dt(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,Ht(this.store.active)||jt(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===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;this.store.hover.type&&(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.hotkeyType===g.AddAnchor||this.movingPens||!this.activeRect||1===this.store.active.length&&this.store.active[0].type||Ht(this.store.active)||zt(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=$(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.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(!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,o=`${(t.calculative.tempText||t.text||"").split(/[\s\n]/).join("
")}
`.replace("","").replace(/\\<\/div\>/g,"

");this.inputDiv.innerHTML=o,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",this.inputParent.style.width=n.width+(t.textLeft||0)+"px",this.inputParent.style.height=n.height+(t.textTop||0)+"px",this.inputParent.style.zIndex="1000",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 r=window.getSelection();r.selectAllChildren(this.inputDiv),r.collapseToEnd(),this.inputDiv.scrollTop=this.inputDiv.scrollHeight,this.inputDiv.scrollLeft=this.inputDiv.scrollWidth,t.calculative.text=void 0,this.render()},this.setInputStyle=t=>{let e;t.text||(t.text="");for(let t=0;t1?t.textLeft*o:t.textLeft*o/r}px;`),t.textTop&&(i+=`margin-top:${r>1?t.textTop*o:t.textTop*o/r}px;`),t.lineHeight&&(i+=`line-height:${r>1?t.fontSize*t.lineHeight*r:t.fontSize*t.lineHeight*o}px;`),t.textHeight)i+=`height:${r>1?t.textHeight*o*r:t.textHeight*o}px;`;else{let e=t.height/r-(t.textTop||0);e<0&&(e=0),i+=`height:${t.fontSize*r<12?e*o:e*r*o}px;`}if(t.textWidth)"pre-line"!==t.whiteSpace&&(t.textWidth1?t.textWidth*o*r:t.textWidth*o}px;`);else if(void 0===t.whiteSpace||"break-all"===t.whiteSpace){let e=t.width/r-(t.textLeft||0);e<0&&(e=0),i+=`width:${t.fontSize*r<12?e*o:e*r}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>(t.textWidth||t.width/r)*Math.floor(t.height/r/(t.lineHeight*t.fontSize))&&(i+="justify-content: start;"),e.deleteRule(0),e.deleteRule(0),e.insertRule(`.topology-input \n .input-div{\n resize:none;border:none;outline:none;background:transparent;position:absolute;flex-grow:1;height:100%;width: 100%;position:absolute;left:0;top:0;display:flex;flex-direction: column;cursor: text;${i}}`),e.insertRule(`.input-div div{${n}}`)},this.hideInput=()=>{if("flex"===this.inputParent.style.display){this.inputParent.style.display="none";const t=this.store.pens[this.inputDiv.dataset.penId];if(!t)return;if(t.calculative.text=t.text,this.inputDiv.dataset.value=this.inputDiv.innerHTML.replace(/\/g,"\n").replace(/\<\/div\>/g,"").replace(/\/g,""),t.onInput)t.onInput(t,this.inputDiv.dataset.value);else if(t.text!==this.inputDiv.dataset.value){const e=[V(t,!0)];t.text=this.inputDiv.dataset.value,t.calculative.text=t.text,this.inputDiv.dataset.penId=void 0,F(t),this.dirty=!0,this.pushHistory({type:U.Update,pens:[V(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)"}));const e=this.store.pens[this.inputDiv.dataset.penId];if(!e||!e.dropdownList)return this.dropdown.style.display="none",this.inputRight.style.display="none",void(this.inputRight.style.transform="rotate(135deg)");if(!e.dropdownList.length){const t=document.createElement("div");return t.innerText="None",t.style.padding="5px 12px",t.style.color="#ddd",void this.dropdown.appendChild(t)}const i=this.inputDiv.innerHTML.replace(/\/g,"\n").replace(/\<\/div\>/g,"").replace(/\/g,"");let n=0;for(const o of e.dropdownList){const e="string"==typeof o?o:o.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,o=i.dropdownList[n];if(!o)return;const r=[V(i,!0)];"object"==typeof o?(this.updateValue(i,{...o}),i.calculative.text=void 0,this.calcActiveRect()):i.text=o+"",this.inputDiv.innerText=i.text,this.hideInput(),this.pushHistory({type:U.Update,pens:[V(i,!0)],initPens:r}),this.render(),this.store.emitter.emit("valueUpdate",i)},this.canvasImageBottom=new Wi(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 Wi(e,i),this.magnifierCanvas=new qi(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 ji(e,i),this.store.options.scroll&&(this.scroll=new zi(this)),this.store.dpiRatio=window?window.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&&window.addEventListener("resize",this.onResize),window&&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(),J()?(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=>{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,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 o=V(t,!0),r=V(t,!0),s=Q();r.id=s,r.calculative.canvas=this,r.calculative.active=!1,r.calculative.hover=!1;const a=V(i.slice(0,n+1)),c=V(i.slice(n)).map((t=>(t.penId=s,t)));t.calculative.worldAnchors=a,r.calculative.worldAnchors=c,this.initLineRect(t),this.initLineRect(r),this.store.data.pens.push(r),this.store.pens[s]=r,this.pushHistory({type:U.Add,pens:[V(r,!0)],step:2}),this.pushHistory({type:U.Update,initPens:[o],pens:[V(t,!0)],step:2})}translateAnchor(t,e){this.movingAnchor.x+=t,this.movingAnchor.y+=e;const i=this.movingAnchor.penId;if(i){const t=this.store.pens[i],e=t.calculative.worldRect;this.movingAnchor.xe.ex&&(this.movingAnchor.x=e.ex),this.movingAnchor.ye.ey&&(this.movingAnchor.y=e.ey);const n=ve(this.movingAnchor,e),o=t.anchors.findIndex((t=>t.id===this.movingAnchor.id));t.anchors[o]=n,this.dirty=!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 o=new FormData;if(o.append("file",t),i)for(const t in i)i.hasOwnProperty(t)&&o.append(t,i[t]);const r=await fetch(e,{method:"POST",headers:n,body:o});return(await r.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 o=new Image;o.onload=()=>{L.htmlElements[i]=o,t({width:o.width,height:o.height,name:e?"gif":"image",image:i})},o.onerror=t=>{n(t)},o.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=Q()),!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){ee(t),t.parentId=i;const n=[];if(Array.isArray(t.children))for(const i of t.children){const o=e.find((t=>t.id===i));o&&n.push(this.randomCombineId(o,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:U.Add,pens:V(i,!0)}),i}getInitPencilLine(t){const{data:e,options:i}=this.store,n=e.scale,r=e.lineWidth||1;return{id:t.penId,name:"line",x:t.x,y:t.y,type:o.Line,calculative:{canvas:this,pencil:!0,active:!0,worldAnchors:[t],lineWidth:r*n},fromArrow:e.fromArrow||i.fromArrow,toArrow:e.toArrow||i.toArrow,lineWidth:r}}createDrawingLine(t){const{data:e,options:i}=this.store,n=e.scale,r=e.lineWidth||1;return t.penId=Q(),{id:t.penId,name:"line",lineName:this.drawingLineName,x:t.x,y:t.y,type:o.Line,calculative:{canvas:this,active:!0,worldAnchors:[t],lineWidth:r*n},fromArrow:e.fromArrow||i.fromArrow,toArrow:e.toArrow||i.toArrow,lineWidth:r}}addRuleLine(t){const{x:e,y:i}=this.store.data,n=t.x+e,s=t.y+i;let a=t.x,c=t.y,l=0,h=0,u=0,d=0;if(n<=s&&n<20)a=-e,l=this.width,u=1;else{if(!(s{const{x:i,y:n}=this.movingPens[e];Object.assign(t,{x:i,y:n}),t.onMove?.(t),this.dirtyPenRect(t),this.updateLines(t),this.dirtyLines.forEach((t=>{t.type&&this.initLineRect(t)})),this.dirtyLines.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.store.emitter.emit("active",this.store.active),this.initImageCanvas(this.store.active),this.pushHistory({type:U.Update,pens:V(this.store.active,!0),initPens:t})}copyMovedPens(){this.copy(this.store.active.map(((t,e)=>{const{x:i,y:n}=this.movingPens[e];return{...t,x:i,y:n}}))),this.pasteOffset=0,this.paste(),this.alreadyCopy=!1}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,Nt(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.dirty=!0)}active(t,e=!0){if(this.store.active)for(const t of this.store.active)t.calculative.active=void 0,Nt(t,!1);this.store.active=[],t.forEach((t=>{t.calculative.active=!0,Nt(t)})),this.store.active.push(...t),this.calcActiveRect(),this.dirty=!0,e&&this.store.emitter.emit("active",this.store.active)}getSizeCPs(){this.sizeCPs=ae(this.activeRect);const{x:t,y:e,width:i,height:n,rotate:o,center:r}=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};R(a,o,r),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)return v.None;if(this.store.options.disableAnchor||e.disableAnchor)return v.None;if(_(t,i,this.pointSize))return i!==this.store.hoverAnchor&&(this.dirty=!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&&_(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&&_(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},re(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()}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){if(!(this.beforeAddPens&&1!=await this.beforeAddPens([t])||this.beforeAddPen&&1!=this.beforeAddPen(t)))return this.makePen(t),this.active([t]),this.render(),this.store.emitter.emit("add",[t]),e&&this.pushHistory({type:U.Add,pens:[t]}),t}pushHistory(t){if(this.store.data.locked)return;const{origin:e,scale:i}=this.store.data;t.origin=V(e),t.scale=i,t.type!==U.Update&&t.pens&&t.pens.forEach((t=>{t.calculative.layer=this.store.data.pens.findIndex((e=>e.id===t.id))})),this.store.historyIndex1;){const t=this.store.histories[this.store.historyIndex--];this.doEditAction(t,!0),e--}}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--}}doEditAction(t,e){switch(this.inactive(),this.store.hoverAnchor=void 0,this.store.hover=void 0,t.type){case U.Add:t.pens.forEach((t=>{const e=V(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),e.onDestroy?.(e))})),t.type=U.Delete;break;case U.Update:(e?t.initPens:t.pens).forEach((e=>{const i=V(e,!0),n=this.store.data.pens.findIndex((t=>t.id===i.id));if(n>-1){i.calculative=this.store.data.pens[n].calculative,this.store.data.pens[n]=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);this.setPenRect(i,e,!1),this.updateLines(i,!0)}}));break;case U.Delete:t.pens.forEach((t=>{const e=V(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=U.Add}t.type===U.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=Q()),this.store.data.pens.push(t),this.store.pens[t.id]=t,t.path){!t.pathId&&(t.pathId=Q());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},(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&&L.anchors[t.name]&&(t.anchors||(t.anchors=[]),L.anchors[t.name](t)),this.dirtyPenRect(t),t.type?this.initLineRect(t):t.anchors||(t.anchors=t.calculative.worldAnchors.map((e=>ve(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,L.path2dDraws.line(this.drawingLine)),this.dirty=!0)}initLineRect(t){const e=Be(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),oe(e),t.calculative.worldRect=e,wt(t,e),F(t),Vt(t),this.store.path2dMap.set(t,L.path2dDraws[t.name](t)),t.calculative.worldAnchors&&(t.anchors=t.calculative.worldAnchors.map((e=>ve(e,t.calculative.worldRect))))}drawingPencil(){Vi(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=Et(this.drawingLine);let i=Ct(this.drawingLine);if(i.isTemp&&(this.drawingLine.calculative.worldAnchors.pop(),i=Ct(this.drawingLine)),!t&&(!i.connectTo&&this.drawingLine.calculative.worldAnchors.pop(),Et(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=Et(t),o=Ct(t);return E(n,e)&&E(o,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=Be(this.drawingLine);Object.assign(this.drawingLine,n),this.drawingLine.calculative.worldRect=n,this.drawingLine.calculative.activeAnchor=Ct(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:U.Add,pens:V([this.drawingLine],!0)})),this.store.path2dMap.set(this.drawingLine,L.path2dDraws[this.drawingLine.name](this.drawingLine)),this.drawingLine=void 0,this.drawingLineName=void 0,this.render()}async finishPencil(){if(this.pencilLine){const t=Ye(this.pencilLine.calculative.worldAnchors,10,0,this.pencilLine.calculative.worldAnchors.length-1);let e=Et(this.pencilLine);t.unshift({id:e.id,penId:e.penId,x:e.x,y:e.y}),e=Ct(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,o,r,s,a,c,l,h,u,d,f,p,v,g,y,m;const w=(t,e,i,n)=>(s=Math.sqrt(t*t+e*e),s>0?(v=t/s,y=e/s):(v=1,y=0),a=Math.sqrt(i*i+n*n),a>0?(g=i/a,m=n/a):(g=1,m=0),Math.acos(v*g+y*m));f=[],p=t.length,n=t[0],h=t[p-1],f.push({...t[0]});for(let h=0;h1&&(this.pencilLine.calculative.pencil=!1,this.store.path2dMap.set(this.pencilLine,L.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:U.Add,pens:V([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:o,height:r}=t.calculative.worldRect;n.setAttribute("width",`${o}px`),n.setAttribute("height",`${r}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,L.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(L.htmlElements[t.image]){const e=L.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,L.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(L.htmlElements[t.backgroundImage]){const e=L.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,L.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(L.htmlElements[t.strokeImage]){const e=L.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,L.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*e,t.calculative.iconTop=t.iconTop*e,t.calculative.textWidth=t.textWidth*e,t.calculative.textHeight=t.textHeight*e,t.calculative.textLeft=t.textLeft*e,t.calculative.textTop=t.textTop*e,t.type===o.Line&&t.borderWidth&&(t.calculative.borderWidth=t.borderWidth*e)}dirtyPenRect(t,{worldRectIsReady:e,playingAnimate:i}={}){e?xt(t):mt(t),i||this.setCalculativeByScale(t),bt(t),kt(this.store.pens,t),F(t),Vt(t),L.path2dDraws[t.name]&&this.store.path2dMap.set(t,L.path2dDraws[t.name](t)),t.calculative.dirty=!0,this.dirty=!0,t.children&&t.children.forEach((t=>{const e=this.store.pens[t];e&&this.dirtyPenRect(e,{worldRectIsReady:!1})})),t.type&&this.initLineRect(t)}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)Vt(t),t.onMove?.(t),t.isRuleLine&&(t.width?t.height||(t.x=-this.store.data.x):t.y=-this.store.data.y,this.dirtyPenRect(t))}scale(t,e={x:0,y:0}){const{minScale:i,maxScale:n}=this.store.options;if(tn)return;this.calibrateMouse(e);const o=t/this.store.data.scale;this.store.data.scale=t,this.store.data.center=e,P(this.store.data.origin,o,e),this.store.data.pens.forEach((t=>{if(!t.parentId){if(At(t,o,e),t.isRuleLine){const e=o>1?1:1/o/o,i=t.calculative.worldRect.center;t.width&&t.height||At(t,e,i)}this.dirtyPenRect(t,{worldRectIsReady:!0}),this.execPenResize(t)}})),this.calcActiveRect(),this.canvasImage.init(),this.canvasImageBottom.init();const r=this.parent.map;r&&r.isShow&&r.setView(),this.render(),this.store.emitter.emit("scale",this.store.data.scale)}rotatePens(t){this.initPens||(this.initPens=V(this.getAllByPens(this.store.active))),this.activeRect.rotate=S(t,this.activeRect.center),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:U.Update,pens:V(this.getAllByPens(this.store.active)),initPens:this.initPens}),this.initPens=void 0}),200)}resizePens(t){if(this.initPens||(this.initPens=V(this.store.active,!0)),!this.initActiveRect)return void(this.initActiveRect=V(this.activeRect));const e=this.mouseDown.x,i=this.mouseDown.y;let n=t.x-e,o=t.y-i;const r=V(this.initActiveRect);if(de(r,n,o,this.resizeIndex),oe(r),!this.store.options.disableDockLine){this.clearDock();const t=this.customeResizeDock||Qt;this.dock=t(this.store,r,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&&(o+=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=o-this.lastOffsetY;this.lastOffsetX=n,this.lastOffsetY=o,t.ctrlKey&&(l=([1,3].includes(this.resizeIndex)?-1:1)*(c*a)/s),de(this.activeRect,c,l,this.resizeIndex),oe(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),re(t.calculative.worldRect),oe(t.calculative.worldRect),this.dirtyPenRect(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:U.Update,pens:V(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=V(this.activeRect));this.movingPens||(this.initMovingPens(),this.store.active.forEach((t=>{Ut(t,!1)})),this.store.hover=void 0);let e=t.x-this.mouseDown.x,i=t.y-this.mouseDown.y;t.shiftKey&&!t.ctrlKey&&(e=0),t.altKey&&(i=0);const n=V(this.initActiveRect);he(n,e,i);const o={x:n.x-this.activeRect.x,y:n.y-this.activeRect.y};if(!this.store.options.disableDockLine){this.clearDock();const t=this.customeMoveDock||Xt;this.dock=t(this.store,n,this.movingPens,o);const{xDock:e,yDock:i}=this.dock;e&&(o.x+=e.step,this.store.pens[e.penId].calculative.isDock=!0),i&&(o.y+=i.step,this.store.pens[i.penId].calculative.isDock=!0)}this.translatePens(this.movingPens,o.x,o.y,!0)}changeIdsByMoving(t,e){t.id+=Ki,t.parentId&&e.find((e=>e.id===t.parentId))&&(t.parentId+=Ki),t.children&&(t.children=t.children.map((t=>t+Ki))),t.connectedLines&&(t.connectedLines=t.connectedLines.map((t=>(e.find((e=>e.id===t.lineId))&&(t.lineId+=Ki),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+=Ki),t))))}initMovingPens(){this.movingPens=V(this.store.active,!0);const t=this.getAllByPens(this.movingPens),e=V(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){if(!this.activeRect||this.store.data.locked)return;if(this.initPens||(this.initPens=V(this.store.active,!0)),this.store.activeAnchor?.connectTo){const t=this.store.pens[this.store.activeAnchor.connectTo];Tt(t,It(t,this.store.activeAnchor.anchorId),this.store.pens[this.store.activeAnchor.penId],this.store.activeAnchor)}let e=t.x-this.store.activeAnchor.x,i=t.y-this.store.activeAnchor.y;I(this.store.activeAnchor,e,i);const n=this.store.active[0],o=Et(n),r=Ct(n);!1!==n.autoPolyline&&this.store.activeAnchor!==o&&this.store.activeAnchor!==r&&(n.autoPolyline=!1),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,I(this.store.activeAnchor,e,i),this.store.activeAnchor.connectTo=this.store.hover.id,r.prev=void 0,"polyline"!==n.lineName&&this[n.lineName]?.(this.store,n)),!1!==n.autoPolyline&&"polyline"===n.lineName&&this[n.lineName]?.(this.store,n),this.dirtyLines.add(n),this.store.path2dMap.set(n,L.path2dDraws[n.name](n)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0,this.pushHistory({type:U.Update,pens:V(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=V(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===k.Bilateral){const e=S(t,this.store.activeAnchor),i=S(this.prevAnchor,this.store.activeAnchor);this.store.activeAnchor.next.x=this.nextAnchor.x,this.store.activeAnchor.next.y=this.nextAnchor.y,R(this.store.activeAnchor.next,e-i,this.store.activeAnchor)}}else this.store.activeAnchor.next.x=t.x,this.store.activeAnchor.next.y=t.y,R(this.store.activeAnchor.next,180,this.store.activeAnchor);const e=this.store.active[0];this.dirtyLines.add(e),this.store.path2dMap.set(e,L.path2dDraws[e.name](e)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0,this.pushHistory({type:U.Update,pens:V(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=V(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===k.Bilateral){const e=S(t,this.store.activeAnchor),i=S(this.nextAnchor,this.store.activeAnchor);this.store.activeAnchor.prev.x=this.prevAnchor.x,this.store.activeAnchor.prev.y=this.prevAnchor.y,R(this.store.activeAnchor.prev,e-i,this.store.activeAnchor)}}else this.store.activeAnchor.prev.x=t.x,this.store.activeAnchor.prev.y=t.y,R(this.store.activeAnchor.prev,180,this.store.activeAnchor);const e=this.store.active[0];this.dirtyLines.add(e),this.store.path2dMap.set(e,L.path2dDraws[e.name](e)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0,this.pushHistory({type:U.Update,pens:V(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0}),200)}async setAnchor(t){const e=[V(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===o.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===o.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===o.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],o=t.calculative.worldAnchors[i+1];const r=e.step;let s;if(n.next&&o.prev){const e=n,i=n.next,a=o.prev,c=o,l=Ee(e,i,r),h=Ee(i,a,r),u=Ee(a,c,r),d=Ee(l,h,r),f=Ee(h,u,r);s=Ee(d,f,r),d.penId=t.id,s.prev=d,f.penId=t.id,s.next=f,n.next.x=l.x,n.next.y=l.y,o.prev.x=u.x,o.prev.y=u.y}else if(n.next||o.prev){const i=n,a=n.next||o.prev,c=o,l=Ee(i,a,r),h=Ee(a,c,r);s=e,l.penId=t.id,h.penId=t.id,s.prev=l,s.next=h,n.next=void 0,o.prev=void 0}else s=e;return s.penId=t.id,s.id=Q(),s.prevNextType=k.Bilateral,s}(t,e,i);return t.calculative.worldAnchors.splice(i+1,0,n),t.anchors.splice(i+1,0,ve(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:Q(),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&&R(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(),this.pushHistory({type:U.Update,pens:[V(i,!0)],initPens:e})}checkDisconnect(t,e){if(t.id.indexOf(Ki)>0){const e=t.id;t=this.store.pens[e.replace(Ki,"")]}t.calculative.worldAnchors.forEach((i=>{if(i.connectTo&&!e.find((t=>t.id===i.connectTo))){const e=this.store.pens[i.connectTo];if(e.type)return;Tt(e,It(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>=r.DisableMove)return!0})))return;const s=!n&&V(t,!0);he(this.activeRect,e,i);const a=this.getAllByPens(t);t.forEach((t=>{t.locked>=r.DisableMove||(t.type===o.Line?(function(t,e,i){t.x+=e,t.y+=i,t.anchors&&t.anchors.forEach((t=>{I(t,e,i)})),t.calculative.worldAnchors&&t.calculative.worldAnchors.forEach((t=>{I(t,e,i)}))}(t,e,i),this.checkDisconnect(t,a),this.store.path2dMap.set(t,L.path2dDraws[t.name](t)),n||(this.initLineRect(t),t.connectedLines?.forEach((t=>{const e=this.store.pens[t.lineId];this.initLineRect(e)})))):(he(t.calculative.worldRect,e,i),this.dirtyPenRect(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.getSizeCPs(),this.render(),this.tooltip.translate(e,i),n||(this.pushHistory({type:U.Update,pens:V(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 o=Et(t),r=Ct(t),s=_t(i,e===o?r:o);e.x=s.x,e.y=s.y,e.prev=void 0,e.next=void 0,n?n.anchor=s.id:St(i,s,t,e),this[t.lineName]&&this[t.lineName](this.store,t),this.store.path2dMap.set(t,L.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{for(const e in t)"x"===e||"y"===e||"width"===e||"height"===e||"initRect"===e||"object"==typeof t[e]&&"lineDash"!==e||(t.calculative[e]=t[e]);t.calculative.worldRect=t.calculative.initRect}this.dirtyPenRect(t,{worldRectIsReady:!0}),t.calculative.text!==t.text&&(t.calculative.text=t.text,j(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 o=It(n,i.lineAnchor);if(!o)return;if(n.autoFrom){const e=Et(n);e.id===o.id&&this.calcAutoAnchor(n,e,t,i)}if(n.autoTo){const e=Ct(n);e.id===o.id&&this.calcAutoAnchor(n,e,t,i)}const r=It(t,i.anchor);if(r){if(I(o,r.x-o.x,r.y-o.y),(n.autoPolyline??this.store.options.autoPolyline)&&"polyline"===n.lineName){let t=Et(n),e=Ct(n),i=!1;t.id===o.id?(t=o,i=!0):e.id===o.id&&(e=o,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,L.path2dDraws[n.name](n)),this.dirtyLines.add(n),e&&je(n)}}))}calcActiveRect(){const t=this.store.active.filter((t=>(!t.locked||t.locked{R(t,e,i.center)})),this.initLineRect(t),xt(t)):(t.calculative.rotate?t.calculative.rotate+=e:t.calculative.rotate=e,R(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.dirtyPenRect(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 this.store.animates.add(t)})),this.animate())}animate(){this.animateRendering||requestAnimationFrame((()=>{const t=Date.now();if(t-this.lastAnimateRender0&&this.animate());this.lastAnimateRender=t,this.animateRendering=!0;const e=[];let i=!1;for(const n of this.store.animates)if(!n.calculative.pause){if(!n.calculative.active||n.type||this.movingPens||(i=!0),n.type){if(!Ot(n)){if(n.keepAnimateState){for(const t in n)void 0!==n.calculative[t]&&("object"==typeof n[t]&&"lineDash"!==t||(n[t]=n.calculative[t]));xt(n)}else for(const t in n)"object"==typeof n[t]&&"lineDash"!==t||(n.calculative[t]=n[t]);e.push(n),this.nextAnimate(n)}}else Lt(n,t)?n.calculative.dirty&&(oe(n.calculative.worldRect),this.dirtyPenRect(n,{worldRectIsReady:!0,playingAnimate:!0})):(this.restoreNodeAnimate(n),e.push(n),this.nextAnimate(n)),this.updateLines(n,!0);this.dirty=!0}i&&this.calcActiveRect(),e.forEach((t=>{this.store.animates.delete(t)})),this.render(!1),this.animateRendering=!1,this.animate()}))}get clipboardName(){return"topology-clipboard"}copy(t){const{origin:e,scale:i}=this.store.data;this.store.clipboard={pens:this.getAllByPens(V(t||this.store.active,!0)),origin:V(e),scale:i},this.pasteOffset=10;const n=this.store.clipboard;localStorage.setItem(this.clipboardName,JSON.stringify({topology:!0,data:n})),navigator.clipboard?.writeText(JSON.stringify({topology:!0,data:n}))}cut(t){this.copy(t),this.delete(t)}async paste(){let t=await(navigator.clipboard?.readText());if(navigator.clipboard?.writeText(""),t||(t=localStorage.getItem(this.clipboardName)),t){let e;try{e=JSON.parse(t)}catch(t){return void console.warn("剪切板数据不是 json",t.message)}if(!e||!e.topology||!e.data)return;this.store.clipboard=e.data}if(this.beforeAddPens&&1!=await this.beforeAddPens(this.store.clipboard.pens))return;this.store.clipboard=V(this.store.clipboard,!0);const e=this.store.clipboard.pens.filter((t=>!t.parentId));for(const t of e)this.pastePen(t,void 0,this.store.clipboard);this.active(e),this.pushHistory({type:U.Add,pens:this.store.clipboard.pens}),this.render(),this.store.emitter.emit("add",this.store.clipboard.pens),localStorage.removeItem(this.clipboardName)}getAllByPens(t){const e=[];for(const i of t)e.push(...V(it(i,this.store),!0));return e.concat(t)}pastePen(t,e,i){const n=t.id;if(ee(t),t.parentId=e,!e&&he(t,this.pasteOffset,this.pasteOffset),t.type===o.Line?this.changeNodeConnectedLine(n,t,i.pens):this.changeLineAnchors(n,t,i.pens),!this.beforeAddPen||1==this.beforeAddPen(t)){if(this.makePen(t),!t.parentId){const e=this.getPenRect(t,i.origin,i.scale);this.setPenRect(t,e,!1)}const e=[];if(Array.isArray(t.children))for(const n of t.children){const o=i.pens.find((t=>t.id===n));o&&e.push(this.pastePen(o,t.id,i).id)}return t.children=e,t}return{}}changeLineAnchors(t,e,i){if(Array.isArray(e.connectedLines))for(let n=0;nt.id===o));if(r){const i=r.anchors[0],n=r.anchors[r.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 o of n){const n=o.connectTo;if(n){const r=i.find((t=>t.id===n));r?r.connectedLines?.forEach((i=>{i.lineId===t&&(i.lineId=e.id,i.lineAnchor=o.id)})):(o.connectTo=void 0,o.prev&&(o.prev.connectTo=void 0),o.next&&(o.next.connectTo=void 0))}}}async delete(t=this.store.active,e=!1){t&&t.length&&(this.beforeRemovePens&&1!=await this.beforeRemovePens(t)||(e||(t=t.filter((t=>!t.locked))),t&&t.length&&(this._del(t),this.initImageCanvas(t),this.inactive(),this.clearHover(),this.render(),this.pushHistory({type:U.Delete,pens:t}),this.store.emitter.emit("delete",t))))}_del(t){t&&t.forEach((t=>{if(t.parentId){if(this.getLockedParent(t))return void console.warn("父节点锁定");{const e=this.store.pens[t.parentId],i=e.children.indexOf(t.id);e.children.splice(i,1),this.delForce(t)}}else{if(t.locked)return;this.delForce(t)}}))}getLockedParent(t){if(!t.parentId)return!1;const e=et(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),t.children&&t.children.forEach((t=>{this.delForce(this.store.pens[t])})),t.onDestroy?.(t)}delConnectedLines(t){if(t.connectedLines)for(let e=0;et.id===n));e?.connectTo===t.id&&(e.connectTo=void 0,e.anchorId=void 0,e.prev&&(e.prev.connectTo=void 0),e.next&&(e.next.connectTo=void 0)),e=It(o,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=>{Tt(n,i,t,e)}))}))}createInput(){let t;this.inputParent.classList.add("topology-input"),this.inputRight.classList.add("right"),this.inputDiv.classList.add("input-div"),this.inputParent.appendChild(this.inputDiv),this.inputParent.appendChild(this.inputRight),this.inputParent.appendChild(this.dropdown),this.externalElements.appendChild(this.inputParent),this.inputParent.onmousedown=this.stopPropagation,this.inputDiv.onmousedown=this.stopPropagation,this.inputDiv.contentEditable="true",this.inputRight.onmousedown=this.stopPropagation,this.dropdown.onmousedown=this.stopPropagation,this.inputRight.style.transform="rotate(135deg)";for(let e=0;e{t.stopPropagation();const e=this.store.pens[this.inputDiv.dataset.penId];"block"===this.dropdown.style.display?(this.dropdown.style.display="none",this.inputRight.style.transform="rotate(135deg)"):e?.dropdownList&&this.store.data.locked&&(this.dropdown.style.display="block",this.inputRight.style.transform="rotate(315deg)"),this.store.emitter.emit("clickInput",e)},this.inputDiv.onkeyup=t=>{this.setDropdownList(!0);const e=this.store.pens[this.inputDiv.dataset.penId];this.store.emitter.emit("input",{pen:e,text:t.key}),t.stopPropagation()},this.inputDiv.onkeydown=t=>{t.stopPropagation()},this.inputDiv.onmousedown=this.stopPropagation,this.inputDiv.onwheel=t=>{t.stopPropagation()}}clearDropdownList(){if(this.dropdown.hasChildNodes())for(let t=0;te.id==t||e.tags&&e.tags.indexOf(t)>-1))}findOne(t){return this.store.data.pens.find((e=>e.id==t||e.tags&&e.tags.indexOf(t)>-1))}changePenId(t,e){if(t===e)throw new Error("oldId is same as newId");const i=this.store.pens[t];if(!i)throw new Error("old pen isn't exist");if(this.store.pens[e])throw new Error("new pen already exists");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],o=n.children?.findIndex((e=>e===t));-1!==o&&n.children?.splice(o,1,e)}i.children?.forEach((t=>{this.store.pens[t].parentId=e})),i.type===o.Line?this.changeNodeConnectedLine(t,i,this.store.data.pens):(this.changeLineAnchors(t,i,this.store.data.pens),i.connectedLines?.forEach((({lineId:t})=>{bt(this.store.pens[t])})))}updateValue(t,e){const i=this.getPenRect(t),n=t.name;Object.assign(t,e);const o=n!==t.name;e.newId&&this.changePenId(t.id,e.newId);let r,s=!1,a=!1,d=!1,f=!1,p=!1,v=!1,g=!1;for(const i in e)"rotate"===i&&(r=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),o&&(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.dirtyPenRect(t):(a&&F(t),f&&kt(this.store.pens,t),s&&L.path2dDraws[t.name]&&this.store.path2dMap.set(t,L.path2dDraws[t.name](t)));if(void 0!==r){const e=t.calculative.rotate;t.calculative.rotate=r,this.rotatePen(t,e-r,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)),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.dirtyPenRect(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=se(this.store.data.pens);if(!isFinite(n.width))throw new Error("can not to png, because width is not finite");const o=V(n),r=this.store.data,s=i&&!r.background&&this.store.bkImg;let a=!1,c=!1;if(s){if(n.x+=r.x,n.y+=r.y,re(n),le(n,this.canvasRect,!0))Object.assign(n,this.canvasRect);else{const t=ce([...ae(n),...ae(this.canvasRect)]);Object.assign(n,t)}a=0===n.x,c=0===n.y}const l=Z(t);n.x-=l[3],n.y-=l[0],n.width+=l[3]+l[1],n.height+=l[0]+l[2],re(n);const h=document.createElement("canvas");h.width=n.width,h.height=n.height;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?r.x:-o.x,c?r.y:-o.y):u.translate(-n.x,-n.y);for(const t of this.store.data.pens){if(!qt(t,this.store)||0==t.visible)continue;const{active:e}=t.calculative;t.calculative.active=!1,t.calculative.img?vt(u,t):dt(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.dirty=!0}addAnchorHand(){if(this.store.activeAnchor&&this.store.active&&1===this.store.active.length&&this.store.active[0].type){const t=[V(this.store.active[0],!0)];this.store.activeAnchor.prev?this.store.activeAnchor.next||(this.store.activeAnchor.next={...this.store.activeAnchor.prev},R(this.store.activeAnchor.next,180,this.store.activeAnchor),this.initLineRect(this.store.active[0]),this.dirty=!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},R(this.store.activeAnchor.prev,180,this.store.activeAnchor),this.initLineRect(this.store.active[0]),this.dirty=!0),this.pushHistory({type:U.Update,pens:[V(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=[V(this.store.active[0],!0)];this.hoverType===v.LineAnchorPrev?(this.store.activeAnchor.prev=void 0,this.initLineRect(this.store.active[0]),this.dirty=!0):this.hoverType===v.LineAnchorNext?(this.store.activeAnchor.next=void 0,this.initLineRect(this.store.active[0]),this.dirty=!0):(this.store.activeAnchor.prev=void 0,this.store.activeAnchor.next=void 0,this.initLineRect(this.store.active[0]),this.dirty=!0),this.pushHistory({type:U.Update,pens:[V(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=k.Mirror),this.store.activeAnchor.prevNextType=(this.store.activeAnchor.prevNextType+1)%3)}gotoView(t,e){const i=se(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,J()?(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)}window&&window.removeEventListener("resize",this.onResize),window&&window.removeEventListener("scroll",this.onScroll)}}var $i;!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.Function=5]="Function",t[t.WindowFn=6]="WindowFn",t[t.Emit=7]="Emit",t[t.StartVideo=8]="StartVideo",t[t.PauseVideo=9]="PauseVideo",t[t.StopVideo=10]="StopVideo"}($i||($i={}));class Xi{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="topology-map",this.box.onmousedown=this.onMouseDown,this.box.onmousemove=this.onMouseMove,this.box.onmouseup=this.onMouseUp;for(let t=0;tthis.ratio){const t=e.width/this.ratio;e.y-=(t-e.height)/2,e.height=t,re(e)}else{const t=e.height*this.ratio;e.x-=(t-e.width)/2,e.width=t,re(e)}const i=this.parent.canvasRect;let n=0,o=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)o=-e.y/e.height;else if(e.y+e.height>i.height){let t=0;i.height>e.height&&(t=i.height-e.height),o=(-e.y+t)/e.height}const r=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=r*this.boxWidth+"px",this.view.style.top=this.padding+o*this.boxHeight+"px",this.view.style.height=s*this.boxHeight+"px"}}}var Gi,Qi=i(176);class Ji{constructor(i,n={}){this.events={},this.facePen=Rt,this.getWords=z,this.calcTextLines=j,this.calcTextRect=F,this.calcTextDrawRect=H,this.register=M,this.registerCanvasDraw=D,this.registerAnchors=B,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":e.onValue?.(e),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;if(i.where){const{fn:n,fnJs:o,comparison:r,key:s,value:a}=i.where;if(n)e=n(t);else if(o){try{i.where.fn=new Function("pen",o)}catch(t){console.error("Error: make function:",t)}i.where.fn&&(e=i.where.fn(t))}else switch(r){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=X(+t[s],a);break;case"![)":e=!X(+t[s],a);break;case"[]":e=G(+t[s],a);break;case"![]":e=!G(+t[s],a)}}e&&this.events[i.action](t,i)}})),this.doEvent(this.store.pens[t.parentId],e))},this.renderPenRaw=vt,this.setElemPosition=Ft,this.store=((t="default")=>{var e;return L[t]||(L[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,active:[],animates:new Set,options:{...N},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)}))}}},L[t].id=t),L[t]})(Q()),this.setOptions(n),this.setDatabyOptions(n),this.init(i),this.register({rectangle:t,square:e,circle:ai,svgPath:Ae,diamond:ci,triangle:li,pentagon:ui,pentagram:fi,hexagon:gi,leftArrow:yi,rightArrow:mi,twowayArrow:wi,message:xi,cloud:bi,file:ki,people:Ai,line:Le,iframe:Xe,video:ti,gif:_i,mindNode:Li,mindLine:Ui}),this.registerCanvasDraw({cube:Re}),this.registerAnchors({triangle:hi,pentagon:di,pentagram:pi,mindNode:Bi,mindLine:Fi}),window&&(window.topology=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:o,gridColor:r,gridSize:s,fromArrow:a,toArrow:c,rule:l,ruleColor:h}=t;this.setRule({rule:l,ruleColor:h}),this.setGrid({grid:o,gridColor:r,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 Yi(this,"string"==typeof t?document.getElementById(t):t,this.store),this.resize(),this.canvas.listen()}initEventFns(){this.events[$i.Link]=(t,e)=>{e.value&&"string"==typeof e.value?window.open(e.value,e.params??"_blank"):console.warn("[topology] Link param is not a string")},this.events[$i.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})})),void this.render();console.warn("[topology] SetProps value is not an object")},this.events[$i.StartAnimate]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[topology] StartAnimate value is not a string"):this.startAnimate(e.value||[t])},this.events[$i.PauseAnimate]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[topology] PauseAnimate value is not a string"):this.pauseAnimate(e.value||[t])},this.events[$i.StopAnimate]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[topology] StopAnimate event value is not a string"):this.stopAnimate(e.value||[t])},this.events[$i.StartVideo]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[topology] StartVideo value is not a string"):this.startVideo(e.value||[t])},this.events[$i.PauseVideo]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[topology] PauseVideo value is not a string"):this.pauseVideo(e.value||[t])},this.events[$i.StopVideo]=(t,e)=>{e.value&&"string"!=typeof e.value?console.warn("[topology] StopVideo event value is not a string"):this.stopVideo(e.value||[t])},this.events[$i.Function]=(t,e)=>{if(e.value&&!e.fn)try{if("string"!=typeof e.value)throw new Error("[topology] Function value must be string");const t=e.value,i=t.replaceAll?t.replaceAll(".setValue(","._setValue("):t.replace(/.setValue\(/g,"._setValue(");e.fn=new Function("pen","params",i)}catch(t){console.error("[topology]: Error on make a function:",t)}e.fn?.(t,e.params)},this.events[$i.WindowFn]=(t,e)=>{"string"==typeof e.value?window&&window[e.value]&&window[e.value](t,e.params):console.warn("[topology] WindowFn value must be a string")},this.events[$i.Emit]=(t,e)=>{"string"==typeof e.value?this.store.emitter.emit(e.value,{pen:t,params:e.params}):console.warn("[topology] Emit value must be a string")}}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){return await this.canvas.addPen(t,e)}async addPens(t,e){return await this.canvas.addPens(t,e)}render(t){this.canvas.render(t)}setBackgroundImage(t){if(this.store.data.bkImage=t,this.canvas.canvasImageBottom.canvas.style.backgroundImage=t?`url(${t})`:"",t){const e=new Image;e.src=t,e.onload=()=>{this.store.bkImg=e}}else this.store.bkImg=null}setBackgroundColor(t=this.store.data.background){this.store.data.background=t,this.store.dirtyBackground=!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.dirtyBackground=!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.dirtyTop=!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=Q()),!e.calculative&&(e.calculative={canvas:this.canvas}),this.store.pens[e.id]=e;for(const e of t.pens)this.canvas.makePen(e)}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()}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&&Vi(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()}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=Et(t),n=Ct(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.active=[],e.hover=void 0,e.lastHover=void 0,e.animates.clear(),this.hideInput(),this.canvas.tooltip.hide(),this.canvas.clearCanvas(),this.store.dirtyBackground=!0,this.store.dirtyTop=!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.customeMoveDock=t}registerResizeDock(t){this.canvas.customeResizeDock=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)})),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.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=V(t);if(1===t.length&&t[0].type)return t[0].type=o.Node,this.canvas.active(t),this.pushHistory({type:U.Update,initPens:i,pens:V(t,!0)}),void this.render();const n=se(t);let s={id:Q(),name:"combine",...n,children:[],showChild:e};const a=t.find((t=>t.width===n.width&&t.height===n.height)),c=a&&null==e;c?(a.children||(a.children=[]),s=a):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=pe(t.calculative.worldRect,n);Object.assign(t,e),t.locked=t.lockedOnCombine??r.DisableMove})),this.canvas.active([s]);let l=1;c||(l=2,this.pushHistory({type:U.Add,pens:[s],step:l}),this.store.emitter.emit("add",[s])),this.pushHistory({type:U.Update,initPens:i,pens:t,step:l}),null!=e&&(t.forEach((t=>{Vt(t,!0)})),this.initImageCanvas([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=V(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=r.None,t.calculative.active=void 0,t.calculative.hover=!1,this.setVisible(t,!0)}));const n="combine"===t.name?3:2;this.pushHistory({type:U.Update,initPens:i,pens:e,step:n}),i=[V(t)],t.children=void 0,this.pushHistory({type:U.Update,initPens:i,pens:[t],step:n}),"combine"===t.name&&(this.delete([t]),this.store.histories[this.store.histories.length-1].step=n),this.inactive()}active(t,e=!0){this.canvas.active(t,e)}inactive(){this.canvas.inactive()}delete(t,e=!1){this.canvas.delete(t,e)}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 et(t,e)}data(){const t=V(this.store.data),{pens:e,paths:i}=this.store.data;t.version=C,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.doSocket(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=Q()),this.mqttClient=Qi.connect(this.store.data.mqtt,this.store.data.mqttOptions),this.mqttClient.on("message",((t,e)=>{this.doSocket(e.toString(),t)})),this.store.data.mqttTopics&&this.mqttClient.subscribe(this.store.data.mqttTopics.split(",")))}closeMqtt(){this.mqttClient?.end()}connectHttp(){this.closeHttp();const{http:t,httpTimeInterval:e}=this.store.data;t&&(this.httpTimer=setInterval((async()=>{const e=await fetch(t);if(e.ok){const t=await e.text();this.doSocket(t)}}),e||1e3))}closeHttp(){clearInterval(this.httpTimer),this.httpTimer=void 0}doSocket(t,e=""){if(this.socketFn)this.socketFn(t,e);else try{const e=JSON.parse(t),i=Array.isArray(e)?e:[e],n=this.store.data.pens.filter((t=>t.form)),o=i.filter((t=>t.dataId));o.length&&this.setValuesByDataId(n,o),i.forEach((t=>{t.dataId||this.setValue(t,{render:!1})})),this.render()}catch(t){console.warn("Invalid socket data:",t)}}setValuesByDataId(t=[],e){const i=[];t.forEach((t=>{t.form?.forEach((n=>{const o=n.dataIds;if(o)if(Array.isArray(o))"function"==typeof t.onBinds?i.push(...t.onBinds(t,e,n)):console.warn("Not support onBinds for pen:",t);else{const r=e.find((t=>t.dataId===o.dataId));r&&i.push({id:t.id,[n.key]:r.value})}}))})),i.forEach((t=>{this.setValue(t,{render:!1})}))}setValue(t,{render:e=!0}={}){this._setValue(t).forEach((t=>{this.store.emitter.emit("valueUpdate",t)})),e&&this.render()}_setValue(t){let e=[];if(t.id){const i=this.store.pens[t.id];i&&e.push(i)}else e=this.find(t.tag);return e.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))),this.canvas.updateValue(e,i),e.onValue?.(e)})),this.store.data.locked||!this.store.active.length||this.canvas.movingPens||this.canvas.calcActiveRect(),e}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=[V(t,!0)],n=[];t.children||(t.children=[]);const o=[];e.forEach((e=>{let s=V(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(V(t,!0)),t.children.splice(n,1),o.push(V(t,!0))}t.children.push(e.id),e.parentId=t.id;const a=pe(e.calculative.worldRect,t.calculative.worldRect);Object.assign(e,a),e.locked=e.lockedOnCombine??r.DisableMove,s?(i.push(s),o.push(V(e,!0))):n.push(V(e,!0))})),o.push(V(t,!0));let s=1;n.length&&(s=2,this.pushHistory({type:U.Add,pens:n,step:s})),this.pushHistory({type:U.Update,initPens:i,pens:o,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.topology.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 se(t)}fitView(t=!0,e=10){if(!this.hasView())return;const{canvas:i}=this.canvas,{offsetWidth:n,offsetHeight:o}=i;this.resize(n,o);const r=Z(e),s=this.getRect(),a=(n-r[1]-r[3])/s.width,c=(o-r[0]-r[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()}centerView(){if(!this.hasView())return;const t=this.getRect(),e=this.getViewCenter(),i=this.getPenRect(t);oe(i);const{center:n}=i,{scale:o,origin:r,x:s,y:a}=this.store.data;this.translate((e.x-r.x)/o-n.x-s/o,(e.y-r.y)/o-n.y-a/o);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){const e=V(t),i=t[0],{width:n,height:o}=this.getPenRect(i),r={};p.forEach((t=>{r[t]=i[t]}));for(let e=1;e!t.parentId))).length<=2)return;const n=V(e),o=e.reduce(((e,i)=>e+this.getPenRect(i)[t]),0),r=(i-o)/(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]+r,this._setValue({id:i.id,...e})}this.render(),this.pushHistory({type:U.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(se(t));!e&&(e=n.width);const o=V(t=t.filter((t=>!t.type&&!t.parentId)));let r=0;t.forEach((t=>{const e=this.getPenRect(t);e.height>r&&(r=e.height)}));let s=n.x,a=n.y;t.forEach(((o,c)=>{const l=this.getPenRect(o);if(l.x=s,l.y=a+r/2-l.height/2,this._setValue({id:o.id,...l}),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+=r+i)})),this.render(),this.pushHistory({type:U.Update,initPens:o,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 Xi(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=[...it(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=[...it(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],o=e.findIndex((t=>t.id===i.id));o>-1&&(e.unshift(e[o]),e.splice(o+1,1),this.initImageCanvas([i]))}}up(t,e=this.store.data.pens){const i=e.findIndex((e=>e.id===t.id));i>-1&&i!==e.length-1&&(e.splice(i+2,0,e[i]),e.splice(i,1),this.initImageCanvas([t]))}down(t,e=this.store.data.pens){const i=e.findIndex((e=>e.id===t.id));i>-1&&0!==i&&(e.splice(i-1,0,e[i]),e.splice(i+1,1),this.initImageCanvas([t]))}setLayer(t,e,i=this.store.data.pens){const n=i.findIndex((e=>e.id===t.id));n>-1&&(n>e?(i.splice(e,0,i[n]),i.splice(n+1,1)):n{const o=this.store.pens[n];if(o)switch(e){case"all":i.push(o);break;case"in":Ct(o).connectTo===t.id&&i.push(o);break;case"out":Et(o).connectTo===t.id&&i.push(o)}else console.warn(t,"node contain a error connectedLine")})),i}nextNode(t){if(t.type===o.Line){const e=this.store.pens[Ct(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===o.Line){const e=this.store.pens[Et(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}}toComponent(t=this.store.data.pens,e){if(1===t.length){const e=V(t[0]);return e.type=o.Node,e.id=void 0,[e]}const i=V(t,!0),n=se(i);let s={id:Q(),name:"combine",...n,children:[],showChild:e};const a=i.find((t=>t.width===n.width&&t.height===n.height)),c=a&&void 0===e;return c&&(a.children||(a.children=[]),s=a),i.forEach((t=>{if(t===s||t.parentId===s.id)return;if(t.parentId)return;s.children.push(t.id),t.parentId=s.id;const e=pe(t.calculative.worldRect,n);Object.assign(t,e),t.locked=t.lockedOnCombine??r.DisableMove})),V(c?i:[s,...i])}setVisible(t,e,i=!0){if(this.onSizeUpdate(),this._setValue({id:t.id,visible:e}),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){this.clear(!1),this.closeSocket(),this.store.emitter.all.clear(),this.canvas.destroy(),L[this.store.id]=void 0,L.path2dDraws={},this.canvas=void 0,t&&(L.htmlElements={})}}function Zi(t,e){t.onDestroy||(t.onDestroy=en,t.onAdd=tn);const i=e||new Path2D,{x:n,y:o,width:r,height:s,ex:a}=t.calculative.worldRect;let c=t.calculative.borderRadius||0,l=c;c<1&&(c*=r,l*=s);let h=c{const i=e.data.pens.findIndex((e=>e.id===t));i>-1&&(e.data.pens.splice(i,1),e.pens[t]=void 0)})),t.children=void 0}function nn(t,e){t.onDestroy||(t.onDestroy=rn,t.onAdd=on);const i=e||new Path2D,{x:n,y:o,width:r,height:s,ex:a}=t.calculative.worldRect;let c=t.calculative.borderRadius||0,l=c;c<1&&(c*=r,l*=s);let h=c{const i=e.data.pens.findIndex((e=>e.id===t));i>-1&&(e.data.pens.splice(i,1),e.pens[t]=void 0)})),t.children=void 0}function sn(){return{interfaceClass:Zi,simpleClass:nn}}function an(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;if(i.rect(n,o,r,s),i.closePath(),i instanceof Path2D)return i}function cn(t,e){const i=e.headHeight??50,{x:n,y:o,width:r,height:s,ey:a}=e.calculative.worldRect;let c=e.calculative.borderRadius||0,l=c;e.calculative.borderRadius<1&&(c*=r,l*=s);let h=c({id:n+"",x:e,y:i,penId:t.id})))}function mn(t,e){const i=e||new Path2D,{x:n,y:o,width:r,ex:s,ey:a}=t.calculative.worldRect,c=t.offsetX;let l=r/7;if(c>1?l=c:c>0&&(l=r*c),i.moveTo(n+l,o),i.lineTo(s,o),i.lineTo(n+r-l,a),i.lineTo(n,a),i.closePath(),i instanceof Path2D)return i}function wn(t,e){const i=e||new Path2D,{x:n,y:o,height:r,ex:s,ey:a}=t.calculative.worldRect,c=r/7;if(i.moveTo(n,o+c),i.bezierCurveTo(n,o-c/2|0,s,o-c/2|0,s,o+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 xn(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s,ex:a,ey:c}=t.calculative.worldRect,l=r/8;if(i.moveTo(n+l,o),i.lineTo(a-l,o),i.bezierCurveTo(a+l/3,o,a+l/3,c,a-l,c),i.lineTo(n+l,c),i.lineTo(n,o+s/2),i.closePath(),i instanceof Path2D)return i}function bn(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s,ex:a,center:c}=t.calculative.worldRect,l=c.x,h=o+6*s/7,u=s/6;if(i.moveTo(n,o),i.lineTo(a,o),i.lineTo(a,h),i.bezierCurveTo(a-20,h-u,l+r/5,h-u,l,h),i.bezierCurveTo(l-r/5,h+u,n,h+u,n,h),i.closePath(),i instanceof Path2D)return i}function kn(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 An(t,e){const i=e||new Path2D,{x:n,y:o,width:r,ex:s,ey:a}=t.calculative.worldRect,c=r/10;if(i.moveTo(n+2*c,o),i.bezierCurveTo(n-2*c/3,o,n-2*c/3,a,n+2*c,a),i.lineTo(s,a),i.bezierCurveTo(s-c,a,s-c,o,s,o),i.closePath(),i instanceof Path2D)return i}function Rn(t,e){const i=e||new Path2D,{x:n,y:o,width:r,ex:s,ey:a}=t.calculative.worldRect;i.moveTo(n,o),i.lineTo(s,o),i.lineTo(s,a),i.lineTo(n,a),i.closePath();const c=r/7;if(i.moveTo(n,o+c),i.lineTo(s,o+c),i.moveTo(n+c,o),i.lineTo(n+c,a),i instanceof Path2D)return i}function _n(t,e){const i=e||new Path2D,{x:n,y:o,height:r,ex:s,ey:a}=t.calculative.worldRect,c=r/4;if(i.moveTo(n,o+c),i.lineTo(s,o),i.lineTo(s,a),i.lineTo(n,a),i.closePath(),i instanceof Path2D)return i}function Pn(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 Sn(t,e){const i=e||new Path2D,{x:n,y:o,ex:r,ey:s}=t.calculative.worldRect;if(i.moveTo(n,o),i.lineTo(r,o),i.moveTo(n,s),i.lineTo(r,s),i instanceof Path2D)return i}function Tn(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 In(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s,ex:a,ey:c}=t.calculative.worldRect;if(i.ellipse(n+r/2,o+s/2,r/2,s/2,0,0,2*Math.PI),i.moveTo(n+r/2,c),i.lineTo(a,c),i.closePath(),i instanceof Path2D)return i}function En(t,e){const i=e||new Path2D,{x:n,y:o,width:r,ex:s,ey:a}=t.calculative.worldRect,c=r/7;if(i.moveTo(n,o),i.lineTo(s,o),i.lineTo(s,a),i.lineTo(n,a),i.closePath(),i.moveTo(n+c,o),i.lineTo(n+c,a),i.moveTo(s-c,o),i.lineTo(s-c,a),i instanceof Path2D)return i}function Cn(){return{flowComment:gn,flowData:mn,flowDb:wn,flowDisplay:xn,flowDocument:bn,flowExternStorage:An,flowInternalStorage:Rn,flowManually:_n,flowParallel:Sn,flowQueue:In,flowSubprocess:En}}function Ln(){return{flowDocument:kn,flowManually:Pn,flowParallel:Tn,flowComment:yn}}!function(t){t[t.Add=0]="Add",t[t.Replace=1]="Replace",t[t.ReplaceAll=2]="ReplaceAll"}(Gi||(Gi={}));const Mn={echarts:void 0};function Dn(t){t.onDestroy||(t.onDestroy=Bn,t.onMove=On,t.onResize=Nn,t.onRotate=On,t.onValue=Un,t.onBeforeValue=Fn,t.onChangeId=Hn,t.onBinds=jn);const e=new Path2D,i=t.calculative.worldRect;let n=Mn.echarts;if(!n&&window&&(n=window.echarts),t.echarts&&n){if("string"==typeof t.echarts)try{t.echarts=JSON.parse(t.echarts)}catch(t){}if(t.echarts){if(!Mn[t.id]||!Mn[t.id].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=i.width+"px",e.style.height=i.height+"px",document.body.appendChild(e),Mn[t.id]={div:e,chart:n.init(e,t.echarts.theme)},setTimeout((()=>{Mn[t.id].chart.setOption(t.echarts.option,!0),Mn[t.id].chart.resize(),setTimeout((()=>{const e=new Image;e.src=Mn[t.id].chart.getDataURL({pixelRatio:2}),t.calculative.img=e}),100)})),t.calculative.canvas.externalElements?.appendChild(e),Ft(t,e)}return e.rect(i.x,i.y,i.width,i.height),t.calculative.dirty&&Mn[t.id]&&Ft(t,Mn[t.id].div),e}}}function Bn(t){Mn[t.id].div.remove();let e=Mn.echarts;!e&&window&&(e=window.echarts),e&&e.dispose(Mn[t.id].chart),Mn[t.id]=void 0}function On(t){Mn[t.id]&&Ft(t,Mn[t.id].div)}function Nn(t){Mn[t.id]&&(Ft(t,Mn[t.id].div),Mn[t.id].chart.resize())}function Un(t){Mn[t.id]&&(Ft(t,Mn[t.id].div),Mn[t.id].chart.setOption(t.echarts.option,!0))}function Fn(t,e){if(e.echarts||!e.dataX&&!e.dataY)return e;const i=t.echarts,{max:n,replaceMode:o}=i;let r=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(o)if(o===Gi.Replace)if(u||d){if(("category"===u.type||"category"===d.type)&&r&&s){const t="category"===u.type?u.data:d.data;!Array.isArray(r)&&(r=[r]),!Array.isArray(s)&&(s=[s]),1===c?s.forEach(((e,i)=>{const n=t.indexOf(r[i]);a[0].data[n]=e})):a.forEach(((e,i)=>{s[i].forEach(((i,n)=>{const o=t.indexOf(r[n]);e.data[o]=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 o===Gi.ReplaceAll&&(r&&(u.data=r,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(r){!Array.isArray(r)&&(r=[r]);const t=u.data;t.push(...r),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 Hn(t,e,i){Mn[e]&&(Mn[i]=Mn[e],delete Mn[e])}function jn(t,e,i){const n=t.echarts,{xAxis:o,yAxis:r}=n.option;Array.isArray(o)&&o.length>1&&console.warn("echarts 只支持单 x 轴,多 x 轴将被忽略");const s=Array.isArray(o)?o[0]:o,a=Array.isArray(r)?r[0]:r,c=n.option.series;if(s||a){if("category"===s.type||"category"===a.type){const n=[],o=[];return("category"===s.type?s.data:a.data)?.forEach((t=>{const{dataId:r}=i.dataIds.find((e=>e.name===t));if(r){const i=e.find((t=>t.dataId===r));i&&(o.push(t),n.push(i.value))}})),[{id:t.id,dataY:n,dataX:o}]}if("time"===s.type){const n=[],o=+new Date;let r=!1;return 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([o,t.value]),r=!0)}n[s]=a})),r?(n.forEach(((t,e)=>{if(!t||0===t.length){const t=c[e].data[c[e].data.length-1];n[e]=[[o,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:o}=i.dataIds.find((e=>e.name===t.name));if(o){const i=e.find((t=>t.dataId===o));i&&n.push({name:t.name,value:i.value})}})),[{id:t.id,dataY:n}]}return[]}const zn={Highcharts:void 0};function Wn(t){t.onDestroy||(t.onDestroy=qn,t.onMove=Vn,t.onResize=Kn,t.onRotate=Vn,t.onValue=Yn,t.onChangeId=$n,t.onBeforeValue=Xn);const e=new Path2D,i=t.calculative.worldRect;if(!zn.Highcharts&&window&&(zn.Highcharts=window.Highcharts),t.highcharts&&zn.Highcharts){if("string"==typeof t.highcharts)try{t.highcharts=JSON.parse(t.highcharts.option)}catch(t){}if(t.highcharts){if(!zn[t.id]||!zn[t.id].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=i.width+"px",e.style.height=i.height+"px",e.style.minWidth="100px",e.style.minHeight="100px",e.id=t.id,document.body.appendChild(e),zn[t.id]={div:e,chart:void 0},setTimeout((()=>{zn[t.id].chart=zn.Highcharts.chart(t.id,t.highcharts.option)})),t.calculative.canvas.externalElements?.appendChild(e),Ft(t,e)}return e.rect(i.x,i.y,i.width,i.height),t.calculative.dirty&&zn[t.id]&&Ft(t,zn[t.id].div),e}}}function qn(t){zn[t.id].div.remove(),zn[t.id].chart.destroy(),zn[t.id]=void 0}function Vn(t){zn[t.id]&&Ft(t,zn[t.id].div)}function Kn(t){zn[t.id]&&(Ft(t,zn[t.id].div),setTimeout((()=>{zn[t.id].chart.reflow()}),100))}function Yn(t){zn[t.id]&&Ft(t,zn[t.id].div)}function $n(t,e,i){zn[e]&&(zn[e].div.id=i,zn[i]=zn[e],delete zn[e])}function Xn(t,e){if(e.highcharts)return zn[t.id].chart.update(e.highcharts.option),e;if(!e.dataX&&!e.dataY)return e;const i=t.highcharts,n=i.max;let o=e.dataX,r=e.dataY;const s=i.option.series.length;if(e.overwrite)o&&(i.option.xAxis.categories=o,i.option.xAxis.categories.splice(0,i.option.xAxis.categories.length-n)),r&&(1===s?(i.option.series[0].data=r,i.option.series[0].data.splice(0,i.option.series[0].data.length-n)):i.option.series.forEach(((t,e)=>{t.data=r[e],t.data.splice(0,t.data.length-n)}))),zn[t.id].chart.update(i.option);else{let e=[],a=null,c=!1;if(o){Array.isArray(o)||(o=[o]);const t=i.option.xAxis,r=Array.isArray(t)?t[0].categories:t.categories;r&&(r.push(...o),r.splice(0,r.length-n),c=!0),e=[...o]}r&&(1===s?(Array.isArray(r)||(r=[r]),a=[r]):(a=[],i.option.series.forEach(((t,e)=>{Array.isArray(r[e])||(r[e]=[r[e]]),a.push(r[e])})))),a&&zn[t.id].chart.series.forEach(((t,i)=>{a[i].forEach(((i,o)=>{let r=!1;n&&t.data.length>=n&&(r=!0);const s=c||null==e[o]?i:[e[o],i];t.addPoint(s,!0,r)}))}))}return delete e.dataX,delete e.dataY,delete e.overwrite,Object.assign(e,{highcharts:i})}const Gn={lightningChart:void 0};function Qn(t){t.onDestroy||(t.onDestroy=Zn,t.onMove=to,t.onResize=eo,t.onRotate=to,t.onValue=io,t.onChangeId=no);const e=new Path2D,i=t.calculative.worldRect;let n=Gn.lightningChart;if(!n&&window&&(n=window.lcjs),t.lightningCharts&&n){if("string"==typeof t.lightningCharts)try{t.lightningCharts=JSON.parse(t.lightningCharts)}catch(t){}if(t.lightningCharts){if(!Gn[t.id]||!Gn[t.id].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=i.width+"px",e.style.height=i.height+"px",e.id=t.id,document.body.appendChild(e),Gn[t.id]={div:e,chart:""},setTimeout((()=>{Jn(t)}),100),setTimeout((()=>{t.calculative.canvas.externalElements&&t.calculative.canvas.externalElements.appendChild(e),Ft(t,e)}),200)}return e.rect(i.x,i.y,i.width,i.height),t.calculative.dirty&&Gn[t.id]&&Ft(t,Gn[t.id].div),e}}}function Jn(t){const{lightningChart:e,PieChartTypes:i,LegendBoxBuilders:n,SliceLabelFormatters:o,Themes:r,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=r[t.lightningCharts.option.theme||"lightNew"];switch(Gn[t.id].chart=e(),t.lightningCharts.option.type){case"line":const e=Gn[t.id].chart.ChartXY({container:t.id}).setTitle(y);g.forEach((t=>{e.addLineSeries().setName(t.name).add(t.data)}));break;case"bar":const i=Gn[t.id].chart;let r;r=e=>{const o=[],r=[],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 o={name:t.name,value:t.data[t.figures.indexOf(n)]};return e.addRow("Department:",o.name).addRow("# of employees:",String(o.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),r.push(t),(()=>{let t=0;for(let e=0;e{for(const e of t)o.push({name:e,tick:a.addCustomTick(v.AxisTick).setGridStrokeLength(0).setTextFormatter((t=>e))})}}};const s=r({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=Gn[t.id].chart.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(o.NamePlusRelativeValue),w.addLegendBox(n.VerticalLegendBox).setAutoDispose({type:"max-width",maxWidth:.3}).add(w);break;case"gauge":const x=Gn[t.id].chart.Gauge({theme:m,container:t.id}).setTitle(y).setThickness(20).setAngleInterval(t.lightningCharts.option.startAngle||225,t.lightningCharts.option.endAngle||-45);let b=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);x.getDefaultSlice().setInterval(t.lightningCharts.option.min||0,t.lightningCharts.option.max||100).setValue(g).setFillStyle(new c({color:l(b[0],b[1],b[2])}))}}function Zn(t){Gn[t.id].div.remove();let e=Gn.lightningChart;!e&&window&&(e=window.lcjs),Gn[t.id]=void 0}function to(t){Gn[t.id]&&Ft(t,Gn[t.id].div)}function eo(t){Gn[t.id]&&Ft(t,Gn[t.id].div)}function io(t){Gn[t.id]&&(Jn(t),Ft(t,Gn[t.id].div))}function no(t,e,i){Gn[e]&&(Gn[e].div.id=i,Gn[i]=Gn[e],delete Gn[e])}function oo(t){Mn.echarts=t,Mn.echarts||window.echarts||ao("https://cdn.bootcdn.net/ajax/libs/echarts/5.1.2/echarts.min.js",void 0,!0),M({echarts:Dn})}function ro(t){zn.highcharts=t,zn.highcharts||window.Highcharts||ao("http://cdn.highcharts.com.cn/highcharts/highcharts.js",(()=>{ao("http://cdn.highcharts.com.cn/highcharts/highcharts-more.js",void 0,!0)})),M({highcharts:Wn})}function so(t){Gn.lightningChart=t,Gn.lightningChart||window.lcjs||ao("/js/lcjs.iife.js",void 0,!0),M({lightningCharts:Qn})}function ao(t,e,i){const n=document.createElement("script");n.type="text/javascript",n.src=t,n.addEventListener("load",(()=>{e?.(),i&&topology.render()})),document.body.appendChild(n)}function co(t,e){e.onAdd||(e.onAdd=lo,e.onMouseMove=fo,e.onMouseLeave=po,e.onMouseDown=vo,e.onShowInput=ho,e.onInput=uo,e.onValue=bo,e.onBeforeValue=ko);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 o=i*e.calculative.worldRect.height/e.tableHeight;t.beginPath(),t.moveTo(e.calculative.worldRect.x,e.calculative.worldRect.y+o),t.lineTo(e.calculative.worldRect.ex,e.calculative.worldRect.y+o),t.stroke()}n=e.colPos[e.colPos.length-1],e.colPos.forEach(((i,o)=>{if(i===n)return;const r=i*e.calculative.worldRect.width/e.tableWidth;t.beginPath(),t.moveTo(e.calculative.worldRect.x+r,e.calculative.worldRect.y),t.lineTo(e.calculative.worldRect.x+r,e.calculative.worldRect.ey),t.stroke()})),t.restore()}(t,e),function(t,e){if(!e.colPos)return;e.calculative.texts||(e.calculative.texts=[]);for(let i=0;i{t.fillText(e,c.x+c.width/2,c.y+s+(n+i)*o)}))}t.restore()}}}(t,e)}function lo(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 o=0;0!=t.table.header.show&&(o+=t.table.header.height||t.table.rowHeight,i.push(o));for(const e of t.table.data)o+=e.height||t.table.rowHeight,i.push(o);t.colPos=e,t.rowPos=i,t.tableWidth=n,t.tableHeight=o,t.width||(t.width=n,t.height=o,t.calculative.width=n,t.calculative.height=o,t.calculative.worldRect={x:t.x,y:t.y,height:t.height,width:t.width},re(t.calculative.worldRect))}(t)}function ho(t,e){if(!t.calculative.hoverCell)return;const i=yo(t,t.calculative.hoverCell.row,t.calculative.hoverCell.col);if(Array.isArray(i))return;t.calculative.inputCell=t.calculative.hoverCell;const n=wo(t,t.calculative.hoverCell.row,t.calculative.hoverCell.col);t.calculative.tempText=i.text||i+"",t.calculative.canvas.showInput(t,n,"#ffffff")}function uo(t,e){t.calculative.inputCell&&(mo(t,t.calculative.inputCell.row,t.calculative.inputCell.col,e),t.calculative.canvas.render())}function fo(t,e){t.calculative.hoverCell=go(t,e),t.calculative.canvas.render()}function po(t,e){t.calculative.hoverCell=void 0,t.calculative.canvas.render()}function vo(t,e){t.calculative.activeCell=go(t,e),t.calculative.canvas.render()}function go(t,e){const i=t.calculative.worldRect.width/t.tableWidth,n=t.calculative.worldRect.height/t.tableHeight,o={row:0,col:0};for(let n=0;nt.calculative.worldRect.x+t.colPos[n]*i&&(o.col=n+1);for(let i=0;it.calculative.worldRect.y+t.rowPos[i]*n&&(o.row=i+1);return o}function yo(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 mo(t,e,i,n){if(!t.table.data||!Array.isArray(t.table.data))return;let o;t.calculative.texts=void 0,0==t.table.header.show?(o=t.table.data[e],Array.isArray(o)||o.data&&Array.isArray(o.data)&&(o=o.data)):0===e?o=t.table.header.data:(o=t.table.data[e-1],Array.isArray(o)||o.data&&Array.isArray(o.data)&&(o=o.data)),o&&(o[i]instanceof Object?o[i].text=n:o[i]=n,t.calculative.canvas.store.emitter.emit("valueUpdate",t))}function wo(t,e,i){const n=t.calculative.worldRect.width/t.tableWidth,o=t.calculative.worldRect.height/t.tableHeight;let r=0,s=t.colPos[i]*n;i>0&&(r=t.colPos[i-1]*n);let a=0,c=t.rowPos[e]*o;return e>0&&(a=t.rowPos[e-1]*o),{x:t.calculative.worldRect.x+r,y:t.calculative.worldRect.y+a,ex:t.calculative.worldRect.x+s,ey:t.calculative.worldRect.y+c,width:s-r,height:c-a}}function xo(t,e,i){const n=t.calculative.worldRect.width/t.tableWidth,o=t.calculative.worldRect.height/t.tableHeight;let r=0,s=0,a=0;for(const t of i)s+t.width*n+20*n{if(i===n)return;const r=i*e.calculative.worldRect.width/e.tableWidth;t.beginPath(),t.moveTo(e.calculative.worldRect.x+r,e.calculative.worldRect.y),t.lineTo(e.calculative.worldRect.x+r,e.calculative.worldRect.ey),t.stroke()})),t.restore()}(t,e),function(t,e){if(!e.colPos)return;e.calculative.texts||(e.calculative.texts=[]);for(let i=0;it.col===n&&void 0===t.row&&t.pens));if(t.length>0){if(u[n]="",e.isFirstTime){let o=JSON.parse(JSON.stringify(t[0].pens));o.forEach((t=>{Object.assign(t,{row:i,col:n})})),Mo(e,h,o),e.calculative.canvas.parent.pushChildren(e,o)}continue}}else u[n]=void 0===o?"":o.text||o+"";if(!u[n])continue;u[n]=j(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,o=e.calculative.fontSize*e.calculative.lineHeight*1,r=u[n].length*o;let s=(h.height-r)/2;u[n].forEach(((e,n)=>{t.fillText(e,h.x+h.width/2,h.y+s+(n+i)*o)}))}t.restore()}}}(t,e),e.isFirstTime=!1}function Ro(t){t.isFirstTime=!0,function(t){const e=[],i=[];t.rowHeight||(t.rowHeight=40),t.colWidth||(t.colWidth=150);let n=0;const o=t.styles.filter((t=>void 0!==t.col&&void 0===t.row&&t.width));let r={};o.forEach((t=>{r[t.col]=t.width}));for(let i=0;ivoid 0===t.col&&void 0!==t.row&&t.height));let c={};a.forEach((t=>{c[t.row]=t.height}));for(let e=0;et.calculative.worldRect.x+t.colPos[n]*i&&(o.col=n+1);for(let i=0;it.calculative.worldRect.y+t.rowPos[i]*n&&(o.row=i+1);return o}function Co(t,e,i){if(!t.data||!Array.isArray(t.data))return;const n=t.data[e],o=t.styles.filter((t=>t.row===e&&t.col===i));if(Array.isArray(n))return{value:n[i],style:o.length>0?o[0]:{}};n.data&&Array.isArray(n.data)}function Lo(t,e,i){const n=t.calculative.worldRect.width/t.tableWidth,o=t.calculative.worldRect.height/t.tableHeight;let r=0,s=t.colPos[i]*n;i>0&&(r=t.colPos[i-1]*n);let a=0,c=t.rowPos[e]*o;return e>0&&(a=t.rowPos[e-1]*o),{x:t.calculative.worldRect.x+r,y:t.calculative.worldRect.y+a,ex:t.calculative.worldRect.x+s,ey:t.calculative.worldRect.y+c,width:s-r,height:c-a}}function Mo(t,e,i){const n=t.calculative.worldRect.width/t.tableWidth,o=t.calculative.worldRect.height/t.tableHeight;let r=0,s=0,a=0;for(const t of i)s+t.width*n+20*n{t.calculative.canvas.delete([t.calculative.canvas.findOne(e)],!0)})),t.calculative.texts=void 0,t.calculative.canvas.active([t])}}function Bo(t,e){if(t.calculative.isUpdateData=!1,e.table||null==e.col&&null==e.row)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),t.calculative.canvas.render(),delete e.col,delete e.row,e):e}function Oo(t,e){e.onAdd||(e.onAdd=No,e.onResize=No,e.onMouseMove=Ho,e.onMouseDown=Fo,e.onValue=jo),e.calculative.barRect||No(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,o=e.calculative.worldRect.y+e.calculative.barRect.y,r=e.calculative.barRect.width,s=e.calculative.barRect.height,a=s/2;t.moveTo(n+a,o),t.arcTo(n+r,o,n+r,o+s,a),t.arcTo(n+r,o+s,n,o+s,a),t.arcTo(n,o+s,e.x,e.y,a),t.arcTo(n,o,n+r,o,a),t.fill(),t.fillStyle=e.activeColor||i.activeColor,t.beginPath(),r=e.calculative.ballRect.x,t.moveTo(n+a,o),t.arcTo(n+r,o,n+r,o+s,a),t.arcTo(n+r,o+s,n,o+s,a),t.arcTo(n,o+s,e.x,e.y,a),t.arcTo(n,o,n+r,o,a),t.fill(),t.fillStyle="#ffffff",t.beginPath(),n=e.calculative.worldRect.x+e.calculative.ballRect.x,o=e.calculative.worldRect.y+e.calculative.ballRect.y+e.calculative.ballRect.height/2,t.lineWidth=e.calculative.ballRect.width/10,t.arc(n,o,e.calculative.ballRect.width/2,0,2*Math.PI),t.fill(),t.stroke()}function No(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 o=t.calculative.worldRect.width-t._textWidth*n;t.textLeft=o+10*n,t.calculative.textLeft=t.textLeft,t.calculative.barRect={x:0,y:(t.calculative.worldRect.height-t.barHeight*i)/2,width:o,height:t.barHeight*i},re(t.calculative.barRect),Uo(t)}function Uo(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},re(t.calculative.ballRect),t.calculative.text=t.value+t.unit,F(t)}function Fo(t,e){const i=e.x-t.calculative.worldRect.x;if(i>t.calculative.barRect.width)return;let n=Math.round(i/t.calculative.barRect.width*100);nt.max||n<0||n>100||(t.value=n,Uo(t),t.calculative.text=t.value+t.unit,F(t),t.calculative.canvas.store.emitter.emit("valueUpdate",t),t.calculative.canvas.render())}function Ho(t,e){t.calculative.canvas.mouseDown&&Fo(t,e)}function jo(t){Uo(t)}function zo(t,e){e.onClick||(e.onClick=Wo);let i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,o=e.calculative.worldRect.width,r=e.calculative.worldRect.height;o<1.5*r&&(o=1.5*r),t.beginPath(),t.arc(i+r/2,n+r/2,r/2,Math.PI/2,3*Math.PI/2),t.lineTo(i+o-r/2,n),t.arc(i+o-r/2,n+r/2,r/2,-Math.PI/2,Math.PI/2),t.lineTo(i+r/2,n+r),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*r,n+r/2),t.arc(i+o-r/2,n+r/2,r/2>2?r/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+r,n+r/2),t.arc(i+r/2,n+r/2,r/2>2?r/2-2:1,0,2*Math.PI),t.fill()),t.closePath()}function Wo(t){t.disable||(t.checked=!t.checked,t.calculative.canvas.store.emitter.emit("valueUpdate",t),t.calculative.canvas.render())}function qo(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 Vo(t){if("horizontal"==t.direction){const e=[];let i=0;const n=t.height;t.checkboxHeight=n,t.options.forEach(((o,r)=>{e.push(r*(40+n)+i),i+=qo(o.text,t)})),t.optionPos=e;const o=e.length*(40+n)+i;t.checkboxWidth=o,t.width=o,t.calculative.width=o,t.calculative.worldRect={x:t.x,y:t.y,height:t.height,width:t.width},re(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},re(t.calculative.worldRect))}}function Ko(t,e){e.onAdd||(e.onAdd=Yo,e.onMouseDown=$o,e.onValue=Xo);let i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,o=e.calculative.worldRect.height,r=e.calculative.worldRect.width;if(e.optionPos)if("horizontal"==e.direction){let s=2;for(let a=0;at.calculative.worldRect.x+t.optionPos[i]*t.calculative.worldRect.width/t.checkboxWidth&&e.xt.calculative.worldRect.y+t.optionPos[n]*i&&e.yt.calculative.worldRect.x+t.optionPos[n]*t.calculative.worldRect.width/t.checkboxWidth&&e.x{e!==i&&(t.isChecked=!1)}))}else if("vertical"==t.direction){const i=t.calculative.worldRect.height/t.checkboxHeight;let n=-1;for(let o=0;ot.calculative.worldRect.y+t.optionPos[o]*i&&e.y{e!==n&&(t.isChecked=!1)}))}t.calculative.canvas.render()}function Zo(t){Vo(t)}function tr(){return{radio:Go,switch:zo,slider:Oo,checkbox:Ko,table:co,table2:Ao}}function er(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect,a=s/6,c=r/4;if(i.moveTo(n+2*c,o+0),i.lineTo(n+2*c,o+a),i.moveTo(n,o+a+2*c),i.arc(n+2*c,o+a+2*c,2*c,1*Math.PI,2*Math.PI,!1),i.lineTo(n+4*c,o+5*a),i.lineTo(n,o+5*a),i.lineTo(n,o+a+2*c),i.moveTo(n+c,o+5*a),i.lineTo(n+c,o+6*a),i.moveTo(n+2*c,o+5*a),i.lineTo(n+2*c,o+6*a),i.moveTo(n+3*c,o+5*a),i.lineTo(n+3*c,o+6*a),i.closePath(),i instanceof Path2D)return i}function ir(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 nr(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect,a=s-r,c=.5*r;if(i.moveTo(n+r/2,o),i.lineTo(n+r/2,o+a),i.moveTo(n+r,o+c+a),i.arc(n+r/2,o+c+a,c,0,2*Math.PI,!1),i.closePath(),i instanceof Path2D)return i}function or(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 rr(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect,a=s/2,c=r/5;if(i.moveTo(n,o+a),i.lineTo(n+c,o+a),i.moveTo(n+5*c,o+a),i.ellipse(n+3*c,o+a,2*c,a,0,0,2*Math.PI),i.closePath(),i instanceof Path2D)return i}function sr(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 ar(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect,a=s/4,c=.5*r;if(i.moveTo(n+c,o),i.lineTo(n+c,o+a),i.moveTo(n,o+a),i.rect(n,o+a,2*c,2*a),i.moveTo(n+c,o+3*a),i.lineTo(n+c,o+4*a),i.closePath(),i instanceof Path2D)return i}function cr(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect,a=s/8,c=.25*r;if(i.moveTo(n+2*c,o),i.lineTo(n+2*c,o+2*a),i.lineTo(n+3*c,o+3*a),i.lineTo(n+3*c,o+5*a),i.lineTo(n+2*c,o+6*a),i.lineTo(n+1*c,o+5*a),i.lineTo(n+1*c,o+3*a),i.lineTo(n+2*c,o+2*a),i.moveTo(n+3*c,o+4*a),i.lineTo(n+4*c,o+4*a),i.moveTo(n+2*c,o+6*a),i.lineTo(n+2*c,o+8*a),i.closePath(),i instanceof Path2D)return i}function lr(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 hr(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect,a=r/2,c=s/10;if(i.moveTo(n+a,o),i.lineTo(n+a,o+c),i.moveTo(n+a,o+c),i.quadraticCurveTo(n+2*a,o+c,n+2*a,o+9*c),i.moveTo(n+a,o+c),i.quadraticCurveTo(n,o+c,n,o+9*c),i.quadraticCurveTo(n+a,o+6*c,n+2*a,o+9*c),i.moveTo(n+a,o+3*s/4),i.lineTo(n+a,o+s),i.moveTo(n+2*a/5,o+201*s/250),i.lineTo(n+2*a/5,o+s),i.moveTo(n+8*a/5,o+201*s/250),i.lineTo(n+8*a/5,o+s),i.closePath(),i instanceof Path2D)return i}function ur(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 dr(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect,a=s/6,c=r/4;if(i.moveTo(n+2*c,o+0),i.lineTo(n+2*c,o+a),i.moveTo(n,o+a+2*c),i.arc(n+2*c,o+a+2*c,2*c,1*Math.PI,2*Math.PI,!1),i.lineTo(n+4*c,o+5*a),i.lineTo(n,o+5*a),i.lineTo(n,o+a+2*c),i.moveTo(n,o+5*a-a/3),i.lineTo(n+4*c,o+5*a-a/3),i.moveTo(n+c,o+5*a),i.lineTo(n+c,o+6*a),i.moveTo(n+2*c,o+5*a),i.lineTo(n+2*c,o+6*a),i.moveTo(n+3*c,o+5*a),i.lineTo(n+3*c,o+6*a),i.closePath(),i instanceof Path2D)return i}function fr(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect,a=s/4,c=.5*r;if(i.moveTo(n+c,o),i.lineTo(n+c,o+a),i.lineTo(n+2*c,o+2*a),i.lineTo(n+2*c,o+4*a),i.lineTo(n,o+4*a),i.lineTo(n,o+2*a),i.lineTo(n+c,o+a),i.closePath(),i instanceof Path2D)return i}function pr(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect,a=s/4,c=r/2;if(i.moveTo(n+c,o),i.lineTo(n+c,o+a),i.lineTo(n+2*c,o+4*a),i.lineTo(n,o+4*a),i.lineTo(n+c,o+a),i.closePath(),i instanceof Path2D)return i}function vr(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect,a=s/3,c=.5*r;if(i.moveTo(n+c,o),i.lineTo(n+c,o+a),i.lineTo(n+r,o+2*a),i.lineTo(n+c,o+s),i.lineTo(n,o+2*a),i.lineTo(n+c,o+a),i.closePath(),i instanceof Path2D)return i}function gr(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 yr(t,e){const{x:i,y:n,width:o,height:r}=e.calculative.worldRect,s=o/2,a=r/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*r/4),t.lineTo(i+s,n+9*r/10),t.moveTo(i+2*s/5,n+201*r/250),t.lineTo(i+2*s/5,n+9*r/10),t.moveTo(i+8*s/5,n+201*r/250),t.lineTo(i+8*s/5,n+9*r/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+r),t.fillText("m",i+2*s/5,n+r),t.fillText("o",i+8*s/5,n+r),t.closePath()}function mr(t,e){const i=e||new Path2D,{x:n,y:o,width:r,height:s}=t.calculative.worldRect;let a=r/2,c=s/10;if(i.moveTo(n+a,o),i.lineTo(n+a,o+c),i.moveTo(n+a,o+c),i.quadraticCurveTo(n+2*a,o+c,n+2*a,o+9*c),i.moveTo(n+a,o+c),i.quadraticCurveTo(n,o+c,n,o+9*c),i.quadraticCurveTo(n+a,o+6*c,n+2*a,o+9*c),i.moveTo(n,o+10*c),i.quadraticCurveTo(n+a,o+7*c,n+2*a,o+10*c),i.moveTo(n+2*a/5,o+201*s/250+c),i.lineTo(n+2*a/5,o+s),i.moveTo(n+8*a/5,o+201*s/250+c),i.lineTo(n+8*a/5,o+s),i.closePath(),i instanceof Path2D)return i}function wr(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 xr(){return{andGate:er,basicEvent:nr,conditionalEvent:rr,event:ar,forbiddenGate:cr,orGate:hr,priorityAndGate:dr,switchEvent:fr,transferSymbol:pr,unexpandedEvent:vr,xorGate:mr}}function br(){return{votingGate:yr}}function kr(){return{andGate:ir,orGate:ur,priorityAndGate:ir,votingGate:ur,xorGate:wr,forbiddenGate:lr,basicEvent:or,unexpandedEvent:gr,conditionalEvent:sr,transferSymbol:or}}function Ar(t,e=15){let i=""+t;return i.indexOf(".")>=0&&(i=Number.parseFloat(i).toFixed(e)),Number.parseFloat(i)}function Rr(t){return"number"==typeof t&&Number.isFinite(t)}function _r(t,e){const i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,o=e.calculative.worldRect.width,r=e.calculative.worldRect.height;let s=[];if(e.echarts)for(let t=0;t0&&(i<0?i=0:n=0);const c=(i-n)/o;let l=Math.floor(Math.log10(c)-1);l=Math.pow(10,l);const h=c/l;let u,d=e[0]*l,f=-1;for(u=0;uh){d=e[u]*l;break}let p=i,v=n;function g(t){if(p=parseInt(""+(i/t+1))*t,v=parseInt(""+(n/t-1))*t,0===i&&(p=0),0===n&&(v=0),r&&p*v<0){const t=Math.max(Math.abs(p),Math.abs(v));p=t,v=-t}}if(g(d),s)return{max:Ar(p),min:Ar(v),interval:Ar(d),splitNumber:Math.round((p-v)/d)};if(!r||p*v>0){let t;t:do{if(t=Math.round((p-v)/d),(u-f)*(t-o)<0)for(;t=e.length-1||u<=0||t===o)break;f=u,d=t>o?e[++u]*l:e[--u]*l,g(d)}while(t!==o)}p=Ar(p),v=Ar(v);const y=Ar((p-v)/o);return{max:p,min:v,interval:y,splitNumber:o}}({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=(o-1*(l+1))/l;t.setLineDash([1,h]),t.moveTo(i,n+r+3),t.lineTo(i+o,n+r+3),t.stroke(),t.closePath(),t.beginPath(),t.lineWidth=1,t.setLineDash([]),t.moveTo(i,n+r),t.lineTo(i+o,n+r),t.stroke(),t.closePath(),t.beginPath(),t.fillStyle="#BFBFBF",t.strokeStyle="#E9E9E9",t.setLineDash([2,2]);for(let e=0;e{d=i+(1+a/2)+(a+1)*v,f=n+o-(u[v]-c.min)/(c.max-c.min)*o;let g=i+(1+a/2)+(a+1)*(v+1),y=n+o-(u[v+1]-c.min)/(c.max-c.min)*o,m=i+(1+a/2)+(a+1)*(v-1),w=n+o-(u[v-1]-c.min)/(c.max-c.min)*o,x=i+(1+a/2)+(a+1)*(v+2),b=n+o-(u[v+2]-c.min)/(c.max-c.min)*o;0===v?(m=i+(1+a/2)+(a+1)*v,w=n+o-(u[v]-c.min)/(c.max-c.min)*o):v===u.length-2&&(x=i+(1+a/2)+(a+1)*(v+1),b=n+o-(u[v+1]-c.min)/(c.max-c.min)*o),h.push({x:d,y:f}),e=d+(g-m)/4,r=f+(y-w)/4,s=g-(x-d)/4,l=y-(b-f)/4,t.bezierCurveTo(e,r,s,l,g,y)}))}else for(let e=1;e{t.beginPath(),t.strokeStyle="#fff",t.lineWidth=2,t.arc(e.x,e.y,4,0,2*Math.PI),t.stroke(),t.fill(),t.closePath()})),h=[]}}function Ir(t,e){if(e.xAxisData||e.data||!e.dataX&&!e.dataY)return e;const i=t.xAxisData,n=t.data,o=t.replaceMode;let r=[],s=[];return o?o===Sr.Replace?(e.dataX.forEach(((t,o)=>{let r=i.indexOf(t);n.forEach(((t,i)=>{t[r]=e.dataY[i][o]}))})),r=i,s=n):o===Sr.ReplaceAll&&(r=e.dataX,s=e.dataY):(r=[...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:r,data:s})}function Er(t,e){e.onBeforeValue||(e.onBeforeValue=Cr);const i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,o=e.calculative.worldRect.width,r=e.calculative.worldRect.height,s=!!e.echarts;e.echarts?(e.echarts.option.color||(e.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]),e.chartsColor=e.echarts.option.color):e.chartsColor||(e.chartsColor=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]);const a=s?e.echarts.option.series:e.data;let c=0;for(let l=0;lt+e.value),0):h.reduce(((t,e)=>t+e.value),0);const v=u*parseFloat(s?h.radius[0]:e.chartsRadius[l][0])/100,g=u*parseFloat(s?h.radius[1]:e.chartsRadius[l][1])/100;if(v>g)return;let y=0,m=0;t.strokeStyle=s&&h.itemStyle?.borderColor||"#fff",t.lineWidth=s&&h.itemStyle?.borderWidth||2;const w=s?h.data:h;w.forEach(((i,n)=>{m+=2*Math.PI*i.value/p,t.beginPath();let o=c+n;o>=e.chartsColor.length&&(o%=e.chartsColor.length),t.fillStyle=s?e.echarts.option.color[o]:e.chartsColor[o],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 r=(y+m)/2,a=d+(g+5)*Math.sin(r),l=f-(g+5)*Math.cos(r),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(r),l=f-(g-v)/2*Math.cos(r)):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(r),f-g*Math.cos(r)),t.lineTo(a,l)),t.font=u/10+"px AlibabaPuHuiTi-Regular, Alibaba PuHuiTi",t.textBaseline="middle",t.textAlign="center",r>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 Cr(t,e){if(e.data||!e.dataX&&!e.dataY)return e;const i=t.data,n=t.replaceMode;let o=[];return n?n===Sr.Replace?(e.dataY.forEach(((t,e)=>{t.forEach(((t,n)=>{let o=i[e].filter((e=>e.name===t.name));o.length>0&&(o[0].value=t.value)}))})),o=i):n===Sr.ReplaceAll&&(o=e.dataY):i.forEach(((t,i)=>{let n=[...t,...e.dataY[i]];o.push(n)})),delete e.dataX,delete e.dataY,Object.assign(e,{data:o})}function Lr(t,e){e.onBeforeValue||(e.onBeforeValue=Ir);const i=e.calculative.worldRect.x,n=e.calculative.worldRect.y,o=(e.calculative.worldRect.width,e.calculative.worldRect.height);let r=[];if(e.echarts&&!e.echarts.option.color&&(e.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]),e.echarts)for(let t=0;tr?r/2*9/10:o/2*9/10,l=i+o/2,h=n+r/2,u=(e={...s,...e}).echarts?e.echarts.option.series[0].data[0].value:e.value,d=e.startAngle-e.endAngle,f=e.background||"#E6EBF8";t.strokeStyle=f;let p=c/10;t.lineWidth=p,t.beginPath(),t.lineCap="round",t.arc(l,h,c,-e.startAngle/180*Math.PI,-e.endAngle/180*Math.PI),t.stroke(),t.closePath();let v=0;if(e.axisLine&&!e.isClock)for(let i=e.axisLine.length-1;i>=0;i--)e.axisLine[i][0]*(e.max-e.min).02?"end":o<-.02?"start":"center",t.textBaseline=r>.02?"top":r<-.02?"bottom":"middle",t.fillText(Pr(_*i+e.min,1),l+P*o,h-P*r),t.fill()}t.closePath();let S=1,T=["value"];if(e.isClock&&(S=3,T=["hourvalue","minutevalue","secondvalue"]),e.isClock)for(let i=0;i0&&(n=(e.startAngle-(e[T[i]]-e.min)/(5*e.max-e.min)*d)/180*Math.PI);let o=.8*c;"hourvalue"===T[i]&&(o=.6*c),"minutevalue"===T[i]&&(o=.7*c);let r=1*c/40;t.beginPath(),t.setLineDash([]),t.lineWidth=c/(i+1)/20,t.strokeStyle=e.color||"#999999",t.moveTo(l-3*r*Math.cos(n),h+3*r*Math.sin(n)),t.lineTo(l+o*Math.cos(n),h-o*Math.sin(n)),t.stroke()}else{let i=(e.startAngle-(u-e.min)/(e.max-e.min)*d)/180*Math.PI,n=.8*c,o=1*c/40;t.beginPath(),t.setLineDash([]),t.lineWidth=2,t.fillStyle=a,t.moveTo(l-3*o*Math.cos(i),h+3*o*Math.sin(i)),t.lineTo(l+o*Math.cos(i-Math.PI/2),h-o*Math.sin(i-Math.PI/2)),t.lineTo(l+n*Math.cos(i),h-n*Math.sin(i)),t.lineTo(l+o*Math.cos(i+Math.PI/2),h-o*Math.sin(i+Math.PI/2)),t.lineTo(l-3*o*Math.cos(i),h+3*o*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 Br(t){if(t.isClock)Mr=setInterval((()=>{var e=new Date,i=e.getSeconds(),n=e.getMinutes()+i/60,o=e.getHours()%12+n/60;t.calculative.canvas.parent.setValue({id:t.id,hourvalue:o,minutevalue:n,secondvalue:i})}),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 Or(t){clearInterval(Mr)}function Nr(){return{lineChart:Tr,histogram:Lr,pieChart:Er,gauge:Dr}}!function(t){t[t.Add=0]="Add",t[t.Replace=1]="Replace",t[t.ReplaceAll=2]="ReplaceAll"}(Sr||(Sr={})),window&&(window.Topology=Ji),window&&(window.registerCommonDiagram=function(){window.topology&&(oo(),ro(),so(),window.topology.register(Cn()),window.topology.registerAnchors(Ln()),window.topology.register(pn()),window.topology.registerCanvasDraw(vn()),window.topology.register(sn()),window.topology.register(ln()),window.topology.registerCanvasDraw(hn()),window.topology.registerCanvasDraw(tr()),window.topology.registerCanvasDraw(Nr()),window.topology.register(xr()),window.topology.registerCanvasDraw(br()),window.topology.registerAnchors(kr()))})})(),n})()})); -export function init(t,i,r,u){window.Topology&&(Topology.prototype.lock=function(n){this.store.data.locked=n;this.finishDrawLine(!0);this.canvas.drawingLineName="";this.stopPencil()},n=new Topology(t),n.connectSocket=function(){},n.open(JSON.parse(i)),n.lock(1),u.invokeMethodAsync(r))}export function push_data(t,i){n!==undefined&&n.doSocket(JSON.stringify(i))}var n=undefined; \ No newline at end of file +import BlazorComponent from"../../../_content/BootstrapBlazor/modules/base/blazor-component.js";export class BlazorTopology extends BlazorComponent{_init(){if(window.Topology){Topology.prototype.lock=function(n){this.store.data.locked=n;this.finishDrawLine(!0);this.canvas.drawingLineName="";this.stopPencil()};const n=this._config.arguments[0],t=this._config.arguments[1],i=this._config.arguments[2];this._topology=new Topology(this._element.getAttribute("id"));this._topology.connectSocket=function(){};this._topology.open(JSON.parse(t));this._topology.lock(1);n.invokeMethodAsync(i)}}_execute(n){const t=n[1];this._topology.doSocket(JSON.stringify(t))}} \ No newline at end of file