diff --git a/BootstrapBlazor.sln b/BootstrapBlazor.sln index 9417a81444858ed4b7a0ed02db2abf39fc760199..e11a70b3625530f617368fb168b9bed85f87e1b4 100644 --- a/BootstrapBlazor.sln +++ b/BootstrapBlazor.sln @@ -124,6 +124,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BootstrapBlazor.SummerNote" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestEditor", "test\UnitTestEditor\UnitTestEditor.csproj", "{9552B649-17E2-4BCA-8774-664C83A960CB}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BootstrapBlazor.Topology", "src\Extensions\Components\BootstrapBlazor.Topology\BootstrapBlazor.Topology.csproj", "{6312863E-771D-4EFE-9B9D-071A01222E7A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -206,6 +208,10 @@ Global {9552B649-17E2-4BCA-8774-664C83A960CB}.Debug|Any CPU.Build.0 = Debug|Any CPU {9552B649-17E2-4BCA-8774-664C83A960CB}.Release|Any CPU.ActiveCfg = Release|Any CPU {9552B649-17E2-4BCA-8774-664C83A960CB}.Release|Any CPU.Build.0 = Release|Any CPU + {6312863E-771D-4EFE-9B9D-071A01222E7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6312863E-771D-4EFE-9B9D-071A01222E7A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6312863E-771D-4EFE-9B9D-071A01222E7A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6312863E-771D-4EFE-9B9D-071A01222E7A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -240,6 +246,7 @@ Global {4ED606D8-D252-4573-8F0F-B69502ADB7ED} = {CD062AB6-244D-402A-8F33-C37DAC5856CC} {2FFC1564-EF75-454B-9D8E-A437A1737CEC} = {CD062AB6-244D-402A-8F33-C37DAC5856CC} {9552B649-17E2-4BCA-8774-664C83A960CB} = {7C1D79F1-87BC-42C1-BD5A-CDE4044AC1BD} + {6312863E-771D-4EFE-9B9D-071A01222E7A} = {CD062AB6-244D-402A-8F33-C37DAC5856CC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0DCB0756-34FA-4FD0-AE1D-D3F08B5B3A6B} diff --git a/src/BootstrapBlazor.Shared/BootstrapBlazor.Shared.csproj b/src/BootstrapBlazor.Shared/BootstrapBlazor.Shared.csproj index 1b3756ac74b7c5a114d26790e784381966d56952..13fd85f6adadecc9d4647e348c607b88aff6c417 100644 --- a/src/BootstrapBlazor.Shared/BootstrapBlazor.Shared.csproj +++ b/src/BootstrapBlazor.Shared/BootstrapBlazor.Shared.csproj @@ -27,6 +27,7 @@ + diff --git a/src/BootstrapBlazor.Shared/Samples/Topologys.razor b/src/BootstrapBlazor.Shared/Samples/Topologys.razor new file mode 100644 index 0000000000000000000000000000000000000000..bbef94c187520ca0c5331b6708eaa4e4759decb3 --- /dev/null +++ b/src/BootstrapBlazor.Shared/Samples/Topologys.razor @@ -0,0 +1,5 @@ +@page "/topologys" + +
+ +
diff --git a/src/BootstrapBlazor.Shared/Samples/Topologys.razor.cs b/src/BootstrapBlazor.Shared/Samples/Topologys.razor.cs new file mode 100644 index 0000000000000000000000000000000000000000..611ad089eb010f10cc73f98ddee9540f2a6a8d83 --- /dev/null +++ b/src/BootstrapBlazor.Shared/Samples/Topologys.razor.cs @@ -0,0 +1,29 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using BootstrapBlazor.Components; + +namespace BootstrapBlazor.Shared.Samples; + +/// +/// 图标库 +/// +public partial class Topologys +{ + private string? Content { get; set; } = "{\"x\":0,\"y\":0,\"scale\":1,\"pens\":[{\"text\":\"正方形\",\"width\":100,\"height\":100,\"name\":\"square\",\"form\":[{\"key\":\"text\",\"type\":\"text\",\"name\":\"文本\"}],\"id\":\"af2712f\",\"children\":[],\"x\":399,\"y\":160,\"lineWidth\":1,\"fontSize\":12,\"lineHeight\":1.5,\"anchors\":[{\"id\":\"0\",\"penId\":\"af2712f\",\"x\":0.5,\"y\":0},{\"id\":\"1\",\"penId\":\"af2712f\",\"x\":1,\"y\":0.5},{\"id\":\"2\",\"penId\":\"af2712f\",\"x\":0.5,\"y\":1},{\"id\":\"3\",\"penId\":\"af2712f\",\"x\":0,\"y\":0.5}],\"rotate\":0}],\"origin\":{\"x\":0,\"y\":0},\"center\":{\"x\":0,\"y\":0},\"paths\":{},\"component\":false,\"version\":\"1.1.5\",\"websocket\": \"\"}"; + + private Task> GetData(CancellationToken token) + { + var data = new List() + { + new TopologyItem() + { + Text = DateTime.Now.ToString(), + ID = "af2712f", + Tag = "zhengfangxing" + } + }; + return Task.FromResult(data.AsEnumerable()); + } +} diff --git a/src/BootstrapBlazor.Shared/Samples/Topologys.razor.css b/src/BootstrapBlazor.Shared/Samples/Topologys.razor.css new file mode 100644 index 0000000000000000000000000000000000000000..08cf794fc9791a56a6e54da1aae78f4f71159e5b --- /dev/null +++ b/src/BootstrapBlazor.Shared/Samples/Topologys.razor.css @@ -0,0 +1,4 @@ +.topology { + height: calc(100vh - 278px); + width: 100%; +} diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index f76f8fb774a56956b1afbaef5ec955194815ca5d..f77a5430fdbde7071375701582ba7b1810c82c20 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 6.6.9 + 6.6.10 diff --git a/src/BootstrapBlazor/Utils/JSModule.cs b/src/BootstrapBlazor/Utils/JSModule.cs index c290fbf20e3a3b2d512fa01a96a1ae66b9d8e558..a2a24f44291e24e0541881a8b019b6a7f4d47c6e 100644 --- a/src/BootstrapBlazor/Utils/JSModule.cs +++ b/src/BootstrapBlazor/Utils/JSModule.cs @@ -34,6 +34,15 @@ public class JSModule : IAsyncDisposable /// public virtual ValueTask InvokeVoidAsync(string identifier, params object?[] args) => Module.InvokeVoidAsync(identifier, args); + /// + /// InvokeVoidAsync 方法 + /// + /// + /// + /// + /// + public virtual ValueTask InvokeVoidAsync(string identifier, CancellationToken token, params object?[] args) => Module.InvokeVoidAsync(identifier, token, args); + /// /// InvokeVoidAsync 方法 /// diff --git a/src/Extensions/Components/BootstrapBlazor.FlowChart/BootstrapBlazor.Topology.csproj b/src/Extensions/Components/BootstrapBlazor.FlowChart/BootstrapBlazor.Topology.csproj new file mode 100644 index 0000000000000000000000000000000000000000..de4619a34819ee08a67fd13e8968de379a873f0a --- /dev/null +++ b/src/Extensions/Components/BootstrapBlazor.FlowChart/BootstrapBlazor.Topology.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/BootstrapBlazor.Topology.csproj b/src/Extensions/Components/BootstrapBlazor.Topology/BootstrapBlazor.Topology.csproj new file mode 100644 index 0000000000000000000000000000000000000000..96b1e38ec4a47389e2eb2fec1b2047ad88454dca --- /dev/null +++ b/src/Extensions/Components/BootstrapBlazor.Topology/BootstrapBlazor.Topology.csproj @@ -0,0 +1,23 @@ + + + + 6.0.1 + + + + Bootstrap Blazor WebAssembly wasm UI Components Topology FlowChart + Bootstrap UI components extensions of FlowChart + + + + + + + + + + true + + + + diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor new file mode 100644 index 0000000000000000000000000000000000000000..1988fae3b6210efdc065e1733c18200178af55b6 --- /dev/null +++ b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor @@ -0,0 +1,4 @@ +@namespace BootstrapBlazor.Components +@inherits IdComponentBase + +
diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor.cs b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor.cs new file mode 100644 index 0000000000000000000000000000000000000000..384d8973c3641653ac7a93bb4f34526d3936e289 --- /dev/null +++ b/src/Extensions/Components/BootstrapBlazor.Topology/Components/Topology/Topology.razor.cs @@ -0,0 +1,111 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using Microsoft.AspNetCore.Components; + +namespace BootstrapBlazor.Components; + +/// +/// Topology 组件类 +/// +public partial class Topology : IDisposable +{ + /// + /// 获得/设置 JSON 文件内容 + /// + [Parameter] + [NotNull] +#if NET6_0_OR_GREATER + [EditorRequired] +#endif + public string? Content { get; set; } + + /// + /// 获得/设置 获取推送数据回调委托方法 + /// + [Parameter] + [NotNull] + public Func>>? OnQueryAsync { 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) + { + if (!isInited) + { + if (!string.IsNullOrEmpty(Content)) + { + isInited = true; + Module = await JSRuntime.LoadModule("./_content/BootstrapBlazor.Topology/js/topology_bundle.js", false); + await Module.InvokeVoidAsync("init", Id, Content); + + _ = Task.Run(async () => + { + if (!disposing) + { + CancelToken = new CancellationTokenSource(); + while (CancelToken != null && !CancelToken.IsCancellationRequested) + { + try + { + await Task.Delay(2000, CancelToken.Token); + + var data = await OnQueryAsync(CancelToken.Token); + await Module.InvokeVoidAsync("push_data", CancelToken.Token, Id, data); + } + catch (TaskCanceledException) + { + + } + } + } + }); + } + } + } + + private bool disposing = false; + + /// + /// Dispose 方法 + /// + /// + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + if (CancelToken != null) + { + CancelToken.Cancel(); + CancelToken.Dispose(); + CancelToken = null; + } + } + } + + /// + /// Dispose 方法 + /// + /// + public void Dispose() + { + disposing = true; + Dispose(true); + GC.SuppressFinalize(this); + } +} diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/Components/TopologyItem.cs b/src/Extensions/Components/BootstrapBlazor.Topology/Components/TopologyItem.cs new file mode 100644 index 0000000000000000000000000000000000000000..e97659e1ee324aa0b6b8a563c51e2616c865aef0 --- /dev/null +++ b/src/Extensions/Components/BootstrapBlazor.Topology/Components/TopologyItem.cs @@ -0,0 +1,36 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +namespace BootstrapBlazor.Components; + +/// +/// Topology 数据项实体类 +/// +public class TopologyItem +{ + /// + /// + /// + public string? ID { get; set; } + + /// + /// + /// + public string? Tag { get; set; } + + /// + /// + /// + public string? Text { get; set; } + + /// + /// + /// + public double ShowChild { get; set; } + + /// + /// + /// + public string? TextColor { get; set; } +} diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/logo.png b/src/Extensions/Components/BootstrapBlazor.Topology/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..a30290780f1d7fbb242279e1ed64a94be6341d16 Binary files /dev/null and b/src/Extensions/Components/BootstrapBlazor.Topology/logo.png differ diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/wwwroot/js/topology.js b/src/Extensions/Components/BootstrapBlazor.Topology/wwwroot/js/topology.js new file mode 100644 index 0000000000000000000000000000000000000000..cc19a4c21a94bac0537bd8ee72c5fb67394f205a --- /dev/null +++ b/src/Extensions/Components/BootstrapBlazor.Topology/wwwroot/js/topology.js @@ -0,0 +1 @@ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Le5le=e():t.Le5le=e()}(self,(function(){return(()=>{var t={131:(t,e,i)=>{"use strict";function r(t,e){e||(e=new Path2D);let i=t.calculative.borderRadius||0,r=t.calculative.borderRadius||0;i<1&&(i=t.calculative.worldRect.width*i,r=t.calculative.worldRect.height*r);let n=ioi,activityDiagram:()=>wi,classPens:()=>di,flowPens:()=>Pi,sequencePens:()=>fi});const n=r;var o,s,a,c,l;!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"}(s||(s={})),function(t){t[t.Default=0]="Default",t[t.In=1]="In",t[t.Out=2]="Out"}(a||(a={})),function(t){t[t.None=0]="None",t[t.Linear=1]="Linear",t[t.Radial=2]="Radial"}(c||(c={})),function(t){t[t.None=0]="None",t[t.Horizontal=1]="Horizontal",t[t.Vertical=2]="Vertical"}(l||(l={}));const h=["text","textWidth","textHeight","textLeft","textTop","fontFamily","fontSize","lineHeight","fontStyle","fontWeight","textAlign","textBaseline","whiteSpace","ellipsis"],u=["x","y","width","height","rotate","paddingTop","paddingRight","paddingBottom","paddingLeft"],d=["iconLeft","iconTop","iconRotate"],p=["gif","div","iframe","video","echarts","highcharts","lightningCharts"],f=new Set(["borderRadius","rotate","paddingLeft","paddingRight","paddingTop","paddingBottom","progress","progressColor","verticalProgress","flip","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,y,g,w;!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"}(y||(y={})),function(t){t[t.None=0]="None",t[t.Down=1]="Down",t[t.Translate=2]="Translate"}(g||(g={})),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"}(w||(w={}));const m=["nw-resize","ne-resize","se-resize","sw-resize"],x=["n-resize","e-resize","s-resize","w-resize"],b=["curve","polyline","line"];var R,_;function k(t,e,i){if(!e||e%360==0)return;const r=e*Math.PI/180,n=(t.x-i.x)*Math.cos(r)-(t.y-i.y)*Math.sin(r)+i.x,o=(t.x-i.x)*Math.sin(r)+(t.y-i.y)*Math.cos(r)+i.y;t.x=n,t.y=o,t.prev&&k(t.prev,e,i),t.next&&k(t.next,e,i)}function A(t,e,i=5){return t.x>e.x-i&&t.xe.y-i&&t.y0&&r>0?n=180-n:i<0&&r>0?n+=180:i<0&&r<0&&(n=360-n),n}function T(t,e){const i=t.x-e.x,r=t.y-e.y;return Math.sqrt(i*i+r*r)}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 P(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"}(R||(R={})),function(t){t[t.Default=0]="Default",t[t.In=1]="In",t[t.Out=2]="Out"}(_||(_={}));const C="1.0.5",L={version:C,path2dDraws:{},canvasDraws:{},anchors:{},htmlElements:{},paths:{}};var M;!function(t){t[t.None=-1]="None",t[t.Document=0]="Document",t[t.Canvas=1]="Canvas"}(M||(M={}));const D={textColor:"#222222",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:M.Document,gridSize:20,gridColor:"#e2e2e2",ruleColor:"#888888",drawingLineName:"curve",interval:30,animateInterval:30,autoPolyline:!0,autoAnchor:!0,animateColor:"#ff4d4f"};var N;!function(t){t[t.Add=0]="Add",t[t.Update=1]="Update",t[t.Delete=2]="Delete"}(N||(N={}));const O=t=>{t.data={x:0,y:0,scale:1,pens:[],origin:{x:0,y:0},center:{x:0,y:0}},t.pens={},t.histories=[],t.historyIndex=null,t.path2dMap=new WeakMap,t.active=[],t.hover=void 0,t.lastHover=void 0,t.animates.clear()};function B(t){const{paddingTop:e,paddingBottom:i,paddingLeft:r,paddingRight:n}=t.calculative;let o=r,s=e,a=t.calculative.textWidth||t.calculative.worldRect.width;a<1&&(a*=t.calculative.worldRect.width);let c=t.calculative.textHeight||t.calculative.worldRect.height;c<1&&(c*=t.calculative.worldRect.height);let l=a-r-n,h=c-e-i,u=t.calculative.textLeft,d=t.calculative.textTop;u&&Math.abs(u)<1&&(u=t.calculative.worldRect.width*u),d&&Math.abs(d)<1&&(d=t.calculative.worldRect.height*d),o+=u||0,s+=d||0,l-=u||0,h-=d||0,o=t.calculative.worldRect.x+o,s=t.calculative.worldRect.y+s;const p={x:o,y:s,width:l,height:h,ex:o+l,ey:s+h};t.calculative.worldTextRect=p,j(t),t.calculative.textDrawRect=void 0}function U(t,e){const i=e.calculative.fontSize*e.calculative.lineHeight,r=e.calculative.textLines.length*i,n=function(t,e){let i=0;return e.calculative.textLineWidths=[],e.calculative.textLines.forEach((r=>{const n=t.measureText(r).width;e.calculative.textLineWidths.push(n),i{if(n<0)return;const r=function(t,e){const i=[];let r=t[0]||"";for(let n=1;n1?r.forEach((e=>{if(n<0)return;n+=t.calculative.fontSize*t.calculative.lineHeight;const r=t.calculative.worldTextRect.height;n>r&&(e.slice(0,-3),e+="...",n=-1),i.push(e)})):i.push(...r)}))}return(t.calculative.keepDecimal||0===t.calculative.keepDecimal)&&i.forEach(((e,r)=>{const n=Number(e);isNaN(n)||(i[r]=n.toFixed(t.calculative.keepDecimal))})),t.calculative.textLines=i,i}function F(t){const e=[];let i="";t||(t="");for(let r=0;r126?(i&&(e.push(i),i=""),e.push(t[r])):i+=t[r]}return i&&e.push(i),e}function H(t,e=!1){if(Array.isArray(t)){const i=[];return t.forEach((t=>{i.push(H(t,e))})),i}if("object"==typeof t){if(null===t)return null;if(t.constructor===RegExp)return t;const i={};for(let r in t)["canvas","lastFrame"].includes(r)||t[r]instanceof HTMLImageElement||t[r]instanceof HTMLMediaElement||("calculative"!==r||e)&&(i[r]=H(t[r],e));return i}return t}const z={};function W(t,e){const i=function(t){const e=parseInt,i=Math.round;let r=t.length,n={};if(r>9){const[i,o,s,a]=t=t.split(",");if(r=t.length,r<3||r>4)return null;n.r=e("a"==i[3]?i.slice(5):i.slice(4)),n.g=e(o),n.b=e(s),n.a=a?parseFloat(a):-1}else{if(8==r||6==r||r<4)return null;r<6&&(t="#"+t[1]+t[1]+t[2]+t[2]+t[3]+t[3]+(r>4?t[4]+t[4]:"")),t=e(t.slice(1),16),9==r||5==r?(n.r=t>>24&255,n.g=t>>16&255,n.b=t>>8&255,n.a=i((255&t)/.255)/1e3):(n.r=t>>16,n.g=t>>8&255,n.b=255&t,n.a=-1)}return n}(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 q(t,e){if(!t||!t.parentId||!t.calculative)return;const i=t.calculative.canvas.store;return e&&q(i.pens[t.parentId],e)||i.pens[t.parentId]}function V(t,e,i,r,n){if(!i||!r)return;const o={x:e.x,y:e.center.y},s={x:e.ex,y:e.center.y};n%90==0&&n%180?n%270?(o.x=e.center.x,o.y=e.y,s.x=e.center.x,s.y=e.ey):(o.x=e.center.x,o.y=e.ey,s.x=e.center.x,s.y=e.y):n&&(k(o,n,e.center),k(s,n,e.center));const a=t.createLinearGradient(o.x,o.y,s.x,s.y);return a.addColorStop(0,i),a.addColorStop(1,r),a}function K(t,e){if(t.save(),t.translate(.5,.5),t.beginPath(),e.calculative.flip===l.Horizontal?(t.translate(e.calculative.worldRect.x+e.calculative.worldRect.ex+.5,.5),t.scale(-1,1)):e.calculative.flip===l.Vertical&&(t.translate(.5,e.calculative.worldRect.y+e.calculative.worldRect.ey+.5),t.scale(1,-1)),e.calculative.rotate&&"line"!==e.name){t.translate(e.calculative.worldRect.center.x,e.calculative.worldRect.center.y);let i=e.calculative.rotate*Math.PI/180;e.calculative.flip&&(i*=-1),t.rotate(i),t.translate(-e.calculative.worldRect.center.x,-e.calculative.worldRect.center.y)}e.calculative.lineWidth>1&&(t.lineWidth=e.calculative.lineWidth);const i=e.calculative.canvas.store;let r,n=!0;if(e.calculative.hover)t.strokeStyle=e.hoverColor||i.options.hoverColor,r=e.hoverBackground||i.options.hoverBackground,t.fillStyle=r,r&&(n=!1);else if(e.calculative.active)t.strokeStyle=e.activeColor||i.options.activeColor,r=e.activeBackground||i.options.activeBackground,t.fillStyle=r,r&&(n=!1);else if(e.calculative.isDock)e.type===o.Line?t.strokeStyle=i.options.dockPenColor:(r=W(i.options.dockPenColor,.2),t.fillStyle=r,r&&(n=!1));else if(e.calculative.strokeImage)e.calculative.strokeImg&&(t.strokeStyle=t.createPattern(e.calculative.strokeImg,"repeat"),r=!0);else{let i;i=e.calculative.strokeType===c.Linear?function(t,e){return V(t,e.calculative.worldRect,e.calculative.lineGradientFromColor,e.calculative.lineGradientToColor,e.calculative.lineGradientAngle)}(t,e):e.calculative.color,t.strokeStyle=i}if(n)if(e.calculative.backgroundImage)e.calculative.backgroundImg&&(t.fillStyle=t.createPattern(e.calculative.backgroundImg,"repeat"),r=!0);else{let n;n=e.calculative.bkType===c.Linear?function(t,e){return V(t,e.calculative.worldRect,e.calculative.gradientFromColor,e.calculative.gradientToColor,e.calculative.gradientAngle)}(t,e):e.calculative.bkType===c.Radial?function(t,e){if(!e.calculative.gradientFromColor||!e.calculative.gradientToColor)return;const{worldRect:i}=e.calculative;let r=i.width;r{!i.hidden&&!i.isTemp&&function(t,e,i){if(!e)return;const r=i.calculative.activeAnchor===e;let n=3;i.calculative.lineWidth>3&&(n=i.calculative.lineWidth),r?(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,n,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,n,0,2*Math.PI),t.fill(),t.stroke(),t.restore(),t.beginPath(),t.arc(e.x,e.y,n,0,2*Math.PI),t.fill(),t.stroke()),t.beginPath(),t.arc(e.x,e.y,n,0,2*Math.PI),t.fill(),t.stroke()):(t.save(),t.fillStyle="#ffffff",t.beginPath(),t.arc(e.x,e.y,n,0,2*Math.PI),t.fill(),t.stroke(),t.restore())}(t,i,e)})),t.restore()}(t,e)}}if(L.canvasDraws[e.name]&&(t.save(),L.canvasDraws[e.name](t,e,i),t.restore()),"gif"!==e.name&&e.image&&e.calculative.img){t.save(),t.shadowColor="",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0;const i=e.calculative.worldIconRect;let r=i.x,n=i.y,o=i.width,s=i.height;if(e.calculative.iconWidth&&(o=e.calculative.iconWidth),e.calculative.iconHeight&&(s=e.calculative.iconHeight),e.calculative.imgNaturalWidth&&e.calculative.imgNaturalHeight&&e.imageRatio){let t=i.width/e.calculative.imgNaturalWidth,r=i.height/e.calculative.imgNaturalHeight,n=t>r?r:t;const a=e.calculative.imgNaturalWidth/e.calculative.imgNaturalHeight;e.calculative.iconWidth?s=e.calculative.iconWidth/a:e.calculative.iconHeight?o=e.calculative.iconHeight*a:(o=n*e.calculative.imgNaturalWidth,s=n*e.calculative.imgNaturalHeight)}switch(r+=(i.width-o)/2,n+=(i.height-s)/2,e.iconAlign){case"top":n=i.y;break;case"bottom":n=i.ey-s;break;case"left":r=i.x;break;case"right":r=i.ex-o;break;case"left-top":r=i.x,n=i.y;break;case"right-top":r=i.ex-o,n=i.y;break;case"left-bottom":r=i.x,n=i.ey-s;break;case"right-bottom":r=i.ex-o,n=i.ey-s}e.calculative.iconRotate&&(t.translate(i.center.x,i.center.y),t.rotate(e.calculative.iconRotate*Math.PI/180),t.translate(-i.center.x,-i.center.y)),t.drawImage(e.calculative.img,r,n,o,s),t.restore()}else if(e.calculative.icon){t.save(),t.shadowColor="",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0,t.textAlign="center",t.textBaseline="middle";const r=e.calculative.worldIconRect;let n=r.x+r.width/2,o=r.y+r.height/2;switch(e.iconAlign){case"top":o=r.y,t.textBaseline="top";break;case"bottom":o=r.ey,t.textBaseline="bottom";break;case"left":n=r.x,t.textAlign="left";break;case"right":n=r.ex,t.textAlign="right";break;case"left-top":n=r.x,o=r.y,t.textAlign="left",t.textBaseline="top";break;case"right-top":n=r.ex,o=r.y,t.textAlign="right",t.textBaseline="top";break;case"left-bottom":n=r.x,o=r.ey,t.textAlign="left",t.textBaseline="bottom";break;case"right-bottom":n=r.ex,o=r.ey,t.textAlign="right",t.textBaseline="bottom"}e.calculative.iconSize>0?t.font=`${e.calculative.iconWeight||"normal"} ${e.calculative.iconSize}px '${e.calculative.iconFamily}'`:r.width>r.height?t.font=`${e.calculative.iconWeight||"normal"} ${r.height}px '${e.calculative.iconFamily}'`:t.font=`${e.calculative.iconWeight||"normal"} ${r.width}px '${e.calculative.iconFamily}'`,t.fillStyle=e.calculative.iconColor||e.calculative.textColor||i.options.textColor,e.calculative.iconRotate&&(t.translate(r.center.x,r.center.y),t.rotate(e.calculative.iconRotate*Math.PI/180),t.translate(-r.center.x,-r.center.y)),t.beginPath(),t.fillText(e.calculative.icon,n,o),t.restore()}if(e.calculative.text&&!e.calculative.hiddenText){t.save(),e.calculative.textHasShadow||(t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),r=e.calculative.hover?e.hoverTextColor||e.hoverColor||i.options.hoverColor:e.calculative.active?e.activeTextColor||e.activeColor||i.options.activeColor:void 0,t.fillStyle=r||e.calculative.textColor||e.calculative.color||i.data.color||i.options.color,t.font=`${e.calculative.fontStyle||"normal"} normal ${e.calculative.fontWeight||"normal"} ${e.calculative.fontSize}px/${e.calculative.lineHeight} ${e.calculative.fontFamily||i.options.fontFamily}`,!e.calculative.textDrawRect&&U(t,e),e.calculative.textBackground&&(t.save(),t.fillStyle=e.calculative.textBackground,t.fillRect(e.calculative.textDrawRect.x,e.calculative.textDrawRect.y,e.calculative.textDrawRect.width,e.calculative.textDrawRect.height),t.restore());const n=.55,{width:o}=e.calculative.textDrawRect,s=e.textAlign||i.options.textAlign;e.calculative.textLines.forEach(((i,r)=>{let a=0;"center"===s?a=(o-e.calculative.textLineWidths[r])/2:"right"===s&&(a=o-e.calculative.textLineWidths[r]),t.fillText(i,e.calculative.textDrawRect.x+a,e.calculative.textDrawRect.y+(r+n)*e.calculative.fontSize*e.calculative.lineHeight)})),t.restore()}t.restore()}function $(t){const e=t.calculative.canvas.store;let i={x:t.x,y:t.y};if(t.parentId){let r=e.pens[t.parentId].calculative.worldRect;r||(r=$(e.pens[t.parentId])),i.x=r.x+r.width*t.x,i.y=r.y+r.height*t.y,i.width=r.width*t.width,i.height=r.height*t.height,Math.abs(t.x)>1&&(i.x=r.x+t.x),Math.abs(t.y)>1&&(i.y=r.y+t.y),t.width>1&&!wt(t.height,1)&&(i.width=t.width),t.height>1&&!wt(t.height,1)&&(i.height=t.height),i.ex=i.x+i.width,i.ey=i.y+i.height,i.rotate=r.rotate+t.rotate,i.center={x:i.x+i.width/2,y:i.y+i.height/2}}else i.ex=t.x+t.width,i.ey=t.y+t.height,i.width=t.width,i.height=t.height,i.rotate=t.rotate,i.center={x:i.x+i.width/2,y:i.y+i.height/2};return t.calculative.worldRect=i,Y(t,i),i}function Y(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 X(t){if(!t.parentId)return t.x=t.calculative.worldRect.x,t.y=t.calculative.worldRect.y,t.width=t.calculative.worldRect.width,void(t.height=t.calculative.worldRect.height);const e=t.calculative.canvas.store.pens[t.parentId].calculative.worldRect;t.x=(t.calculative.worldRect.x-e.x)/e.width,t.y=(t.calculative.worldRect.y-e.y)/e.height,t.width=t.calculative.worldRect.width/e.width,t.height=t.calculative.worldRect.height/e.height}function Q(t){const e=t.calculative.canvas.store;if((t.disableAnchor||e.options.disableAnchor)&&!t.type)return void(t.calculative.worldAnchors=[]);const i=[];t.anchors&&t.anchors.forEach((e=>{i.push(function(t,e){const i={...e};return i.x=t.calculative.worldRect.x+t.calculative.worldRect.width*e.x,i.y=t.calculative.worldRect.y+t.calculative.worldRect.height*e.y,e.prev&&(i.prev={penId:t.id,connectTo:e.prev.connectTo,x:t.calculative.worldRect.x+t.calculative.worldRect.width*e.prev.x,y:t.calculative.worldRect.y+t.calculative.worldRect.height*e.prev.y}),e.next&&(i.next={penId:t.id,connectTo:e.next.connectTo,x:t.calculative.worldRect.x+t.calculative.worldRect.width*e.next.x,y:t.calculative.worldRect.y+t.calculative.worldRect.height*e.next.y}),i}(t,e))})),i.length||t.type||"combine"===t.name||(i.push({id:"0",penId:t.id,x:t.calculative.worldRect.x+.5*t.calculative.worldRect.width,y:t.calculative.worldRect.y}),i.push({id:"1",penId:t.id,x:t.calculative.worldRect.x+t.calculative.worldRect.width,y:t.calculative.worldRect.y+.5*t.calculative.worldRect.height}),i.push({id:"2",penId:t.id,x:t.calculative.worldRect.x+.5*t.calculative.worldRect.width,y:t.calculative.worldRect.y+t.calculative.worldRect.height}),i.push({id:"3",penId:t.id,x:t.calculative.worldRect.x,y:t.calculative.worldRect.y+.5*t.calculative.worldRect.height})),t.calculative.rotate&&i.forEach((e=>{k(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 G(t,e){const{paddingTop:i,paddingBottom:r,paddingLeft:n,paddingRight:o}=e.calculative;let s=n,a=i,c=e.calculative.worldRect.width-n-o,l=e.calculative.worldRect.height-i-r,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,ex:s+c,ey:a+l,rotate:d},Rt(e.calculative.worldIconRect)}function J(t,e){return e&&e.calculative&&e.calculative.worldRect.center?function(t,e){let i=w.None;if(!e)return i;const r=t.x-e.x,n=t.y-e.y;return i=Math.abs(r)>Math.abs(n)?r>0?w.Right:w.Left:n>0?w.Bottom:w.Up,i}(t,e.calculative.worldRect.center):w.None}function Z(t,e){let i,r=1/0;return t.calculative.worldAnchors.forEach((t=>{const n=T(e,t);r>n&&(r=n,i=t)})),i}function tt(t){if(t&&t.calculative&&t.calculative.worldAnchors.length){let e=t.calculative.worldAnchors[t.calculative.worldAnchors.length-1];for(;t.calculative.worldAnchors.length&&e!==t.calculative.activeAnchor;)t.calculative.worldAnchors.pop(),e=t.calculative.worldAnchors[t.calculative.worldAnchors.length-1]}}function et(t,e,i,r){t&&e&&i&&r&&(t.connectedLines||(t.connectedLines=[]),t.connectedLines.findIndex((t=>t.lineId===e&&t.lineAnchor===i&&t.anchor===r))<0&&t.connectedLines.push({lineId:e,lineAnchor:i,anchor:r}))}function it(t,e,i,r){if(!(t&&e&&i&&r))return;t.connectedLines||(t.connectedLines=[]);const n=t.connectedLines.findIndex((t=>t.lineId===e&&t.lineAnchor===i&&t.anchor===r));n>-1&&t.connectedLines.splice(n,1)}function rt(t,e){if(t&&e&&t.calculative.worldAnchors)for(const i of t.calculative.worldAnchors)if(i.id===e)return i}function nt(t){if(t&&t.calculative.worldAnchors)return t.calculative.worldAnchors[0]}function ot(t){if(t&&t.calculative.worldAnchors)return t.calculative.worldAnchors[t.calculative.worldAnchors.length-1]}function st(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]||(t[i]="scale"===i?1:void 0)}}if(t.animateCycle||(t.animateCycle=1/0),t.calculative.start){if(e>t.calculative.frameEnd){if(t.lastFrame={rotate:t.frames[t.calculative.frameIndex].rotate||0,x:t.frames[t.calculative.frameIndex].x||0,y:t.frames[t.calculative.frameIndex].y||0,width:(t.frames[t.calculative.frameIndex].scale||1)*t.calculative.initRect.width},t.calculative.x=t.calculative.worldRect.x,t.calculative.y=t.calculative.worldRect.y,t.calculative._rotate=t.calculative.rotate||0,++t.calculative.frameIndex>=t.frames.length){++t.calculative.cycleIndex,t.calculative.frameIndex=0;for(const e in t)"rotate"!==e&&"x"!==e&&"y"!==e&&"scale"!==e||(t.lastFrame[e]=0);t.calculative.x=t.calculative.initRect.x,t.calculative.y=t.calculative.initRect.y}if(t.calculative.cycleIndex>t.animateCycle)return t.calculative.start=void 0,0;t.calculative.frameStart=t.calculative.frameEnd,t.calculative.frameDuration=t.frames[t.calculative.frameIndex].duration,t.calculative.frameEnd=t.calculative.frameStart+t.calculative.frameDuration;for(const e in t)"rotate"===e||"x"===e||"y"===e||"width"===e||"initRect"===e||"object"==typeof t[e]&&"lineDash"!==e||(t.lastFrame[e]=t.calculative[e])}}else{t.calculative.start=Date.now(),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.lastFrame={};for(const e in t)"object"==typeof t[e]&&"lineDash"!==e||(t.lastFrame[e]=t[e]);t.lastFrame.rotate=0,t.lastFrame.x=0,t.lastFrame.y=0,t.lastFrame.width=t.calculative.worldRect.width,t.calculative.x=t.calculative.worldRect.x,t.calculative.y=t.calculative.worldRect.y,t.calculative.initRect=H(t.calculative.worldRect)}const i=t.frames[t.calculative.frameIndex];let r=(e-t.calculative.frameStart)/t.calculative.frameDuration%1;if(r>0){let e,n;for(const o in i)if("duration"!==o){if("scale"===o){const o=t.lastFrame.width+(i.scale*t.calculative.initRect.width-t.lastFrame.width)*r;e=t.calculative.worldRect,n=o/e.width,e.width*=n,e.height*=n,t.calculative.dirty=!0}else if("x"===o)Et(t.calculative.worldRect,t.calculative.x+(i[o]-t.lastFrame[o])*r-t.calculative.worldRect.x,0),t.calculative.dirty=!0;else if("y"===o)Et(t.calculative.worldRect,0,t.calculative.y+(i[o]-t.lastFrame[o])*r-t.calculative.worldRect.y),t.calculative.dirty=!0;else if("rotate"===o)t.calculative._rotate||(t.calculative._rotate=t.rotate||0),t.lastFrame[o]>=360&&(t.lastFrame[o]%=360),t.calculative.rotate=(t.calculative._rotate+(i[o]-t.lastFrame[o])*r)%360,t.calculative.dirty=!0;else if(at(i[o],o,t)){t.lastFrame[o]||(t.lastFrame[o]=0);const e=t.lastFrame[o]+(i[o]-t.lastFrame[o])*r;t.calculative[o]=Math.round(100*e)/100}else t.calculative[o]=i[o];"text"===o&&j(t)}e&&(S(e,n,e.center),e.ex=e.x+e.width,e.ey=e.y+e.height,e.center={x:e.x+e.width/2,y:e.y+e.height/2})}return!0}function at(t,e,i){return"number"==typeof t&&!1!==i.linear&&!["strokeType","bkType"].includes(e)}function ct(t,e){if(0===t.calculative.start)return t.calculative.start=void 0,t.calculative.frameStart=void 0,0;if(t.animateCycle||(t.animateCycle=1/0),t.animateSpan||(t.animateSpan=1),!t.calculative.duration&&t.frames){t.calculative.duration=0;for(const e of t.frames){t.calculative.duration+=e.duration;for(const i in e)"duration"===i||t[i]||(t[i]=void 0)}}if(t.calculative.animatePos+=t.animateSpan,t.calculative.start){if(e>t.calculative.frameEnd||t.calculative.animatePos>t.length){if(t.calculative.animatePos>t.length&&(t.calculative.frameIndex=0,++t.calculative.cycleIndex),t.calculative.cycleIndex>t.animateCycle)return t.calculative.start=void 0,0;if(t.calculative.animatePos=t.animateSpan,t.frames&&t.frames.length){t.calculative.frameStart=t.calculative.frameEnd,t.calculative.frameDuration=t.frames[t.calculative.frameIndex].duration,t.calculative.frameEnd=t.calculative.frameStart+t.calculative.frameDuration,t.lastFrame={};for(const e in t)"object"==typeof t[e]&&"lineDash"!==e||(t.lastFrame[e]=t.calculative[e])}}}else{t.calculative.start=Date.now(),t.calculative.animatePos=t.animateSpan,t.calculative.frameIndex=0,t.calculative.frameStart=t.calculative.start,t.frames&&t.frames.length&&(t.calculative.frameDuration=t.frames[0].duration,t.calculative.frameEnd=t.calculative.frameStart+t.calculative.frameDuration),t.calculative.cycleIndex=1,t.lastFrame={};for(const e in t)"object"==typeof t[e]&&"lineDash"!==e||(t.lastFrame[e]=t[e])}if(!t.calculative.inView||!t.frames||!t.frames.length)return!0;const i=t.frames[t.calculative.frameIndex];let r=(e-t.calculative.frameStart)/t.calculative.frameDuration;if(r>0)for(const e in i)if("duration"!==e){if("number"==typeof i[e]&&!1!==t.linear)if(t[e]||(t[e]=0),t.calculative[e]||(t.calculative[e]=0),t.calculative.frameIndex||t.calculative.cycleIndex){const n=t.lastFrame[e]+(i[e]-t.lastFrame[e])*r;t.calculative[e]=Math.round(100*n)/100}else t.calculative[e]=Math.round(t[e]+i[e]*r*100)/100;else t.calculative[e]=i[e];"text"===e&&j(t)}return!0}function lt(t,e=!0){if(!t.children)return;const i=t.calculative.canvas.store;t.children.forEach((t=>{const r=i.pens[t];r&&(r.calculative.active=e,lt(r,e))}))}function ht(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&&ht(i.pens[t],e)}))}function ut(t,e){if(!e)return;const i=t.calculative.canvas.store,r=t.calculative.worldRect;e.style.position="absolute",e.style.outline="none",e.style.left=r.x+i.data.x+"px",e.style.top=r.y+i.data.y+"px",e.style.width=r.width+"px",e.style.height=r.height+"px",e.style.display=0!=t.calculative.visible?"inline":"none",!t.calculative.rotate&&(t.calculative.rotate=0),e.style.transform=`rotate(${t.calculative.rotate}deg)`,t.locked||i.data.locked?(e.style.userSelect="initial",e.style.pointerEvents="initial"):(e.style.userSelect="none",e.style.pointerEvents="none")}function dt(t){for(const e of t)if(!e.locked)return!1;return!0}function pt(t){for(const e of t)if(!e.disableRotate)return!1;return!0}function ft(t){for(const e of t)if(!e.disableSize)return!1;return!0}function vt(t){if(!t.type){const e=kt(t.calculative.worldRect);return Rt(t.calculative.worldRect),[...e,...t.calculative.worldAnchors,t.calculative.worldRect.center]}if(t.type===o.Line)return t.calculative.worldAnchors}function yt(t,e){let i,r,n=1/0,o=1/0;for(const s of t.data.pens){if(!1===s.calculative.inView)continue;if(gt(t,t.active,s.id))continue;const a=vt(s);for(const t of a)for(const a of e){const e=t.x-a.x,c=t.y-a.y,l=Math.abs(e),h=Math.abs(c);l<8&&lt.parentId===r.id));if(gt(t,e,i))return!0}return!1}function wt(t,e){return t.toFixed(12)==e}function mt(t){if(t.id=Ht(),Array.isArray(t.anchors))for(const e of t.anchors)t.type&&(e.id=Ht()),e.penId=t.id,e.prev&&(t.type&&(e.prev.id=Ht()),e.prev.penId=t.id),e.next&&(t.type&&(e.next.id=Ht()),e.next.penId=t.id)}function xt(t,e){if(!e)return;if(null==e.ex&&(e.ex=e.x+e.width,e.ey=e.y+e.height),!e.rotate||e.width<20||e.height<20||e.rotate%360==0)return t.x>e.x&&t.xe.y&&t.y{k(t,e.rotate,e.center)})),function(t,e){if(e.length<3)return!1;let i=!1,r=e[e.length-1];for(const n of e)r.y>t.y!=n.y>t.y&&n.x+(t.y-n.y)*(r.x-n.x)/(r.y-n.y)>t.x&&(i=!i),r=n;return i}(t,i)}function bt(t,e,i=0){const{x:r,y:n,ex:o,ey:s}=e;return t.x>=r-i&&t.x<=o+i&&t.y>=n-i&&t.y<=s+i}function Rt(t){t.center||(t.center={}),t.center.x=t.x+t.width/2,t.center.y=t.y+t.height/2}function _t(t){const e=[];t.forEach((t=>{const i=t.calculative.worldRect;if(i){const t=kt(i);e.push(...t)}}));const i=At(e);return Rt(i),i}function kt(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||Rt(t),e.forEach((e=>{k(e,t.rotate,t.center)}))),e}function At(t){let e=1/0,i=1/0,r=-1/0,n=-1/0;return t.forEach((t=>{isFinite(t.x)&&isFinite(t.y)&&(e=Math.min(e,t.x),i=Math.min(i,t.y),r=Math.max(r,t.x),n=Math.max(n,t.y))})),{x:e,y:i,ex:r,ey:n,width:r-e,height:n-i}}function St(t,e,i){return t.rotate&&(t=At(kt(t))),i?t.x>e.x&&t.exe.y&&t.eye.ex||t.exe.ey)}function Et(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 Tt(t,e){if(wt(t.k,0))return{x:e.point.x,y:t.point.y};if(wt(e.k,0))return{x:t.point.x,y:e.point.y};const i=t.point.y-t.k*t.point.x,r=(e.point.y-e.k*e.point.x-i)/(t.k-e.k);return{x:r,y:t.k*r+i}}function It(t,e,i,r){if(t.rotate&&t.rotate%360){const n=kt(t),o=(n[0].y-n[1].y)/(n[0].x-n[1].x),s=(n[1].y-n[2].y)/(n[1].x-n[2].x);if(r<4){n[r].x+=e,n[r].y+=i;const t=n[(r+2)%4];n[(r+1)%4]=Tt({k:r%2?s:o,point:n[r]},{k:r%2?o:s,point:t}),n[(r+4-1)%4]=Tt({k:r%2?o:s,point:n[r]},{k:r%2?s:o,point:t})}else{const t=[4,6].includes(r)?s:o;wt(t,0)?(n[r%4].x+=e,n[(r+1)%4].x+=e):(n[r%4].y+=i,n[r%4].x+=i/t,n[(r+1)%4].y+=i,n[(r+1)%4].x+=i/t)}if((n[0].x-n[1].x)**2+(n[0].y-n[1].y)**2<25||(n[1].x-n[2].x)**2+(n[1].y-n[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),r=(e.to.y-e.from.y)/(e.to.x-e.from.x);return Tt({k:i,point:t.from},{k:r,point:e.from})}({from:t[0],to:t[2]},{from:t[1],to:t[3]});for(const r of t)k(r,-e,i);return At(t)}(n,t.rotate);return Rt(a),void Object.assign(t,a)}switch(r){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 Pt(t,e,i){t&&(t.width*=e,t.height*=e,S(t,e,i),t.ex=t.x+t.width,t.ey=t.y+t.height,t.center={x:t.x+t.width/2,y:t.y+t.height/2})}function Ct(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 i.ex=i.x+i.width,i.ey=i.y+i.height,i}function Lt(t,e){const i={id:t.id,penId:t.penId,connectTo:t.connectTo,x:e.width?(t.x-e.x)/e.width:0,y:e.height?(t.y-e.y)/e.height:0,anchorId:t.anchorId,prevNextType:t.prevNextType,hidden:t.hidden};return t.prev&&(i.prev={penId:t.penId,connectTo:t.connectTo,x:e.width?(t.prev.x-e.x)/e.width:0,y:e.height?(t.prev.y-e.y)/e.height:0}),t.next&&(i.next={penId:t.penId,connectTo:t.connectTo,x:e.width?(t.next.x-e.x)/e.width:0,y:e.height?(t.next.y-e.y)/e.height:0}),i}z.triangleSolid=(t,e,i,r)=>{t.save(),t.translate(r.x,r.y),t.rotate(r.rotate*Math.PI/180),t.translate(-r.x,-r.y);const n=r.x-r.step;t.moveTo(n,r.y-r.step/4),t.lineTo(r.x,r.y),t.lineTo(n,r.y+r.step/4),t.closePath(),t.stroke(),t.fillStyle=t.strokeStyle,t.fill(),t.restore()},z.triangle=(t,e,i,r)=>{t.save(),t.lineWidth<2&&(t.lineWidth=2),t.translate(r.x,r.y),t.rotate(r.rotate*Math.PI/180),t.translate(-r.x,-r.y);const n=r.x-r.step;t.moveTo(n,r.y-r.step/4),t.lineTo(r.x,r.y),t.lineTo(n,r.y+r.step/4),t.closePath(),t.stroke(),t.fillStyle=i.data.background||"#ffffff",t.fill(),t.restore()},z.circleSolid=(t,e,i,r)=>{t.save(),t.translate(r.x,r.y),t.rotate(r.rotate*Math.PI/180),t.translate(-r.x,-r.y);const n=r.step/2;t.arc(r.x-n,r.y,n,0,2*Math.PI),t.stroke(),t.fillStyle=t.strokeStyle,t.fill(),t.restore()},z.circle=(t,e,i,r)=>{t.save(),t.translate(r.x,r.y),t.rotate(r.rotate*Math.PI/180),t.translate(-r.x,-r.y);const n=r.step/2;t.arc(r.x-n,r.y,n,0,2*Math.PI),t.stroke(),t.fillStyle=i.data.background||"#ffffff",t.fill(),t.restore()},z.diamondSolid=(t,e,i,r)=>{t.save(),t.translate(r.x,r.y),t.rotate(r.rotate*Math.PI/180),t.translate(-r.x,-r.y);const n=r.x-r.step,o=r.step/2;t.moveTo(n,r.y),t.lineTo(n+o,r.y-o/2),t.lineTo(r.x,r.y),t.lineTo(n+o,r.y+o/2),t.closePath(),t.stroke(),t.fillStyle=t.strokeStyle,t.fill(),t.restore()},z.diamond=(t,e,i,r)=>{t.save(),t.translate(r.x,r.y),t.rotate(r.rotate*Math.PI/180),t.translate(-r.x,-r.y);const n=r.x-r.step,o=r.step/2;t.moveTo(n,r.y),t.lineTo(n+o,r.y-o/2),t.lineTo(r.x,r.y),t.lineTo(n+o,r.y+o/2),t.closePath(),t.stroke(),t.fillStyle=i.data.background||"#ffffff",t.fill(),t.restore()},z.line=(t,e,i,r)=>{t.save(),t.translate(r.x,r.y),t.rotate(r.rotate*Math.PI/180),t.translate(-r.x,-r.y);const n=r.x-r.step;t.moveTo(n,r.y-r.step/3),t.lineTo(r.x,r.y),t.lineTo(n,r.y+r.step/3),t.stroke(),t.restore()},z.lineUp=(t,e,i,r)=>{t.save(),t.translate(r.x,r.y),t.rotate(r.rotate*Math.PI/180),t.translate(-r.x,-r.y);const n=r.x-r.step;t.moveTo(n,r.y-r.step/3),t.lineTo(r.x,r.y),t.stroke(),t.restore()},z.lineDown=(t,e,i,r)=>{t.save(),t.translate(r.x,r.y),t.rotate(r.rotate*Math.PI/180),t.translate(-r.x,-r.y);const n=r.x-r.step;t.moveTo(n,r.y+r.step/3),t.lineTo(r.x,r.y),t.stroke(),t.restore()};const Mt=/^[\t\n\f\r ]*([MLHVZCSQTAmlhvzcsqta])[\t\n\f\r ]*/,Dt=/^[01]/,Nt=/^[+-]?(([0-9]*\.[0-9]+)|([0-9]+\.)|([0-9]+))([eE][+-]?[0-9]+)?/,Ot=/^(([\t\n\f\r ]+,?[\t\n\f\r ]*)|(,[\t\n\f\r ]*))/,Bt={M:[Nt,Nt],L:[Nt,Nt],H:[Nt],V:[Nt],Z:[],C:[Nt,Nt,Nt,Nt,Nt,Nt],S:[Nt,Nt,Nt,Nt],Q:[Nt,Nt,Nt,Nt],T:[Nt,Nt],A:[Nt,Nt,Nt,Dt,Dt,Nt,Nt]};function Ut(t){let e=1/0,i=1/0,r=-1/0,n=-1/0;return function(t){let e,i=0,r=0;t.commands.forEach((t=>{switch(t.key){case"Z":case"z":t.worldPoints=[i,r];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":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 r=t.relative&&e?{x:e.worldPoints[e.worldPoints.length-2],y:e.worldPoints[e.worldPoints.length-1]}:{x:0,y:0};for(let e=0;e{t.worldPoints.forEach(((t,o)=>{o%2==0?(tr&&(r=t)):(tn&&(n=t))}))})),--e,--i,{x:e,y:i,ex:r,ey:n,width:r-e+1,height:n-i+1}}function jt(t,e,i){const r=Bt[t.toUpperCase()],n=[];for(;i<=e.length;){const o={key:t,values:[]};for(const t of r){const r=e.slice(i).match(t);if(null===r){if(0===o.values.length)return{cursor:i,commands:n};throw new Error("malformed path (first error at "+i+")")}{o.values.push(+r[0]),i+=r[0].length;const t=e.slice(i).match(Ot);null!==t&&(i+=t[0].length)}}if(o.relative=o.key.toUpperCase()!==o.key,n.push(o),0===r.length)return{cursor:i,commands:n};"m"===t&&(t="l"),"M"===t&&(t="L")}throw new Error("malformed path (first error at "+i+")")}function Ft(t,e){const i=L.paths[t.pathId];if(!i)return new Path2D;const r=function(t){let e=0,i=[];for(;e{switch(t.key){case"A":case"a":const r=t.values[0],n=t.values[1],o=Math.PI*t.values[2]/180,s=Math.cos(o),a=Math.sin(o),c=n*n*i*i*s*s+r*r*i*i*a*a,l=2*e*i*s*a*(n*n-r*r),h=r*r*e*e*s*s+n*n*e*e*a*a,u=-r*r*n*n*e*e*i*i,d=l*l-4*c*h,p=Math.sqrt((c-h)*(c-h)+l*l);t.values[2]=0!==l?180*Math.atan((h-c-p)/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(((r,n)=>{t.values[n]=r*(n%2==0?e:i)}))}}))}(r,t.calculative.worldRect.width/t.calculative.svgRect.width,t.calculative.worldRect.height/t.calculative.svgRect.height);const n=Ut(r);Rt(n),function(t,e,i){null==i&&(i=e),t.commands.forEach(((t,r)=>{if(!t.relative||!r)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(((r,n)=>{t.values[n]=r+(n%2==0?e:i)}))}}))}(r,t.calculative.worldRect.x-n.x,t.calculative.worldRect.y-n.y);const o=function(t){let e="";return t.commands.forEach((t=>{e+=t.key+" ",t.values.forEach((t=>{e+=t+" "}))})),e}(r);return e?(e.svgPath&&e.svgPath(o),e):new Path2D(o)}function Ht(){return(4294967296*(1+Math.random())|0).toString(16).substring(1)}function zt(t,e,i){if(e.calculative.worldAnchors||(e.calculative.worldAnchors=[]),i)e.calculative.activeAnchor&&(e.calculative.activeAnchor.next={penId:e.id,x:i.x,y:i.y},T(e.calculative.activeAnchor.next,e.calculative.activeAnchor)<5?e.calculative.activeAnchor.next=void 0:(e.calculative.activeAnchor.prev={...e.calculative.activeAnchor.next},k(e.calculative.activeAnchor.prev,180,e.calculative.activeAnchor)));else{const i=e.calculative.worldAnchors[0];i.next||(Wt(i,J(i,t.pens[i.connectTo]),50),i.prev=void 0);const r=e.calculative.worldAnchors[e.calculative.worldAnchors.length-1];r&&r!==i&&!r.prev&&(Wt(r,J(r,t.pens[r.connectTo]),-50),r.next=void 0)}}function Wt(t,e,i){switch(e){case w.Up:t.prev={penId:t.penId,x:t.x,y:t.y+i},t.next={penId:t.penId,x:t.x,y:t.y-i};break;case w.Right:t.prev={penId:t.penId,x:t.x-i,y:t.y},t.next={penId:t.penId,x:t.x+i,y:t.y};break;case w.Bottom:t.prev={penId:t.penId,x:t.x,y:t.y-i},t.next={penId:t.penId,x:t.x,y:t.y+i};break;case w.Left:t.prev={penId:t.penId,x:t.x+i,y:t.y},t.next={penId:t.penId,x:t.x-i,y:t.y}}}function qt(t,e,i,r){const n=1-t;return{x:n*n*e.x+2*n*t*i.x+t*t*r.x,y:n*n*e.y+2*n*t*i.y+t*t*r.y,step:t}}function Vt(t,e,i,r,n){const{x:o,y:s}=e,{x:a,y:c}=n,{x:l,y:h}=i,{x:u,y:d}=r,p=1-t;return{x:o*p*p*p+3*l*t*p*p+3*u*t*t*p+a*t*t*t,y:s*p*p*p+3*h*t*p*p+3*d*t*t*p+c*t*t*t,step:t}}function Kt(t,e,i){return{x:t.x+i*(e.x-t.x),y:t.y+i*(e.y-t.y)}}function $t(t,e,i){if(e.calculative.worldAnchors||(e.calculative.worldAnchors=[]),e.calculative.worldAnchors.length<2)return;let r=e.calculative.activeAnchor,n=i||e.calculative.worldAnchors[e.calculative.worldAnchors.length-1];if(!r||!n)return;let o=J(r,t.pens[r.connectTo]);switch(o===w.None&&(o=n.x>r.x?w.Right:w.Left),r.next={id:Ht(),penId:e.id,x:r.x,y:r.y,prevNextType:2},n.prev={id:Ht(),penId:e.id,x:n.x,y:n.y,prevNextType:2},o){case w.Up:r.next.y-=20,n.prev.y=r.y;break;case w.Bottom:r.next.y+=20,n.prev.y=r.y;break;case w.Left:r.next.x-=20,n.prev.x=r.x;break;default:r.next.x+=20,n.prev.x=r.x}}function Yt(t,e){if(e||(e=new Path2D),t.calculative.worldAnchors.length>1){let i;t.calculative.worldAnchors.forEach((t=>{i?Qt(e,i,t):t.start=!0,i=t})),t.close&&Qt(e,i,t.calculative.worldAnchors[0])}return e}function Xt(t,e,i){if(e.calculative.worldAnchors||(e.calculative.worldAnchors=[]),e.calculative.worldAnchors.length<2)return;let r=e.calculative.activeAnchor,n=e.calculative.worldAnchors[e.calculative.worldAnchors.length-1];r&&n&&n.id&&r!==n&&(r.next=void 0,tt(e),n.prev=void 0,e.calculative.worldAnchors.push(n))}function Qt(t,e,i){i&&!i.isTemp&&(e.next?i.prev?(e.start&&t.moveTo(e.x,e.y),t.bezierCurveTo(e.next.x,e.next.y,i.prev.x,i.prev.y,i.x,i.y)):(e.start&&t.moveTo(e.x,e.y),t.quadraticCurveTo(e.next.x,e.next.y,i.x,i.y)):i.prev?(e.start&&t.moveTo(e.x,e.y),t.quadraticCurveTo(i.prev.x,i.prev.y,i.x,i.y)):(e.start&&t.moveTo(e.x,e.y),t.lineTo(i.x,i.y)))}function Gt(t){return ie(t),At(function(t){const e=[];let i;return t.calculative.worldAnchors.forEach((r=>{e.push(r),i&&e.push(...Jt(i,r,t)),i=r})),t.close&&t.calculative.worldAnchors.length>1&&e.push(...Jt(i,t.calculative.worldAnchors[0],t)),e}(t))}function Jt(t,e,i){const r=[];if(!e)return r;let n=.02;if(t.lineLength){let e=4;i&&i.lineWidth&&(e+=i.lineWidth/2),n=e/t.lineLength}if(t.next)if(e.prev)for(let i=n;i<1;i+=n)r.push(Vt(i,t,t.next,e.prev,e));else for(let i=n;i<1;i+=n)r.push(qt(i,t,t.next,e));else if(e.prev)for(let i=n;i<1;i+=n)r.push(qt(i,t,e.prev,e));else r.push({x:e.x,y:e.y});return r.length>1&&(t.curvePoints=r),r}function Zt(t,e){let i=4;e.lineWidth&&(i+=e.lineWidth/2);let r,n,o=0;for(const s of e.calculative.worldAnchors){if(r){if(n=te(t,r,s,i),n)return{i:o,point:n};++o}r=s}if(e.close&&e.calculative.worldAnchors.length>1&&(n=te(t,r,e.calculative.worldAnchors[0],i)))return{i:o,point:n}}function te(t,e,i,r=4){if(!e.next&&!i.prev){const{x:n,y:o}=e,{x:s,y:a}=i,c=Math.min(n,s),l=Math.max(n,s),h=Math.min(o,a),u=Math.max(o,a);if(!(t.x>=c-r&&t.x<=l+r&&t.y>=h-r&&t.y<=u+r))return;return function(t,e,i,r=4){if(e.x===i.x){if(Math.abs(t.x-e.x)<=r)return{x:e.x,y:t.y}}else{const n=(e.y-i.y)/(e.x-i.x),o=e.y-n*e.x;if(Math.abs((n*t.x+o-t.y)/Math.sqrt(n*n+1))<=r){const e=(t.x+n*t.y-n*o)/(n*n+1);return{x:e,y:n*e+o}}}}(t,e,i,r)}if(e.curvePoints)for(const i of e.curvePoints)if(A(t,i,r))return i}function ee(t,e,i,r){if(!e&&!i)return Math.sqrt(Math.pow(Math.abs(t.x-r.x),2)+Math.pow(Math.abs(t.y-r.y),2))||0;const n=document.createElementNS("http://www.w3.org/2000/svg","path");return e&&i?n.setAttribute("d",`M${t.x} ${t.y} C${e.x} ${e.y} ${i.x} ${i.y} ${r.x} ${r.y}`):e?n.setAttribute("d",`M${t.x} ${t.y} Q${e.x} ${e.y} ${r.x} ${r.y}`):n.setAttribute("d",`M${t.x} ${t.y} Q${i.x} ${i.y} ${r.x} ${r.y}`),n.getTotalLength()||0}function ie(t){if(t.calculative.worldAnchors.length<2)return 0;let e,i=0;if(t.calculative.worldAnchors.forEach((t=>{e&&(e.lineLength=ee(e,e.next,t.prev,t),i+=e.lineLength),e=t})),t.close){let r=t.calculative.worldAnchors[0];e.lineLength=ee(e,e.next,r.prev,r),i+=e.lineLength}return t.length=i,i}const re=30;function ne(t,e,i){if(e.calculative.worldAnchors||(e.calculative.worldAnchors=[]),e.calculative.worldAnchors.length<2)return;let r=e.calculative.activeAnchor,n=e.calculative.worldAnchors[e.calculative.worldAnchors.length-1];if(!r||!n||!n.id||r===n)return;if(r.next=void 0,tt(e),r.x===n.x||r.y===n.y)return void e.calculative.worldAnchors.push(n);const o=[],s=t.pens[r.connectTo],a=t.pens[n.connectTo],c=J(r,s),l=J(n,a);let h,u=oe(r,c,re);switch(u&&(r=u,o.push(u)),u=oe(n,l,re),u&&(n.connectTo&&(h=n),n=u),c){case w.Up:o.push(...function(t,e,i){if(t.x===e.x||t.y===e.y)return[];const r=[];let n,o;switch(i){case w.Bottom:if(n=e.x,o=t.y,e.y>t.y)n=t.x+(e.x-t.x)/2,r.push({x:n,y:t.y},{x:n,y:e.y});else{const i=(t.y+e.y)/2;r.push({x:t.x,y:i},{x:e.x,y:i})}break;case w.Right:n=e.x,o=t.y,e.xt.x&&e.yt.y-re)n=t.x+(e.x-t.x)/2,r.push({x:n,y:t.y},{x:n,y:e.y});else{const i=(t.y+e.y+re)/2;r.push({x:t.x,y:i},{x:e.x,y:i})}}return r}(r,n,l));break;case w.Right:o.push(...function(t,e,i){if(t.x===e.x||t.y===e.y)return[];const r=[];let n,o;switch(i){case w.Up:n=t.x,o=e.y,e.x>t.x&&e.y>t.y&&(n=e.x,o=t.y),r.push({x:n,y:o});break;case w.Bottom:n=t.x,o=e.y,e.x>t.x&&e.yt.y&&(n=t.x,o=e.y),r.push({x:n,y:o});break;case w.Left:n=e.x,o=t.y,e.x>t.x&&e.y>t.y&&(n=t.x,o=e.y),r.push({x:n,y:o});break;default:if(n=t.x,e.yt.y&&(n=e.x,o=t.y),r.push({x:n,y:o});break;case w.Bottom:n=t.x,o=e.y,e.xt.x)n=e.x,o=t.y+(e.y-t.y)/2,r.push({x:t.x,y:o},{x:e.x,y:o});else{const i=(t.x+e.x)/2;r.push({x:i,y:t.y},{x:i,y:e.y})}break;default:if(n=t.x,o=e.y,e.xMath.abs(i.y-e.y)),t.calculative.worldAnchors.length&&(i.isTemp=void 0,t.calculative.drawlineH?(r.push({x:i.x,y:e.y}),Math.abs(i.y-e.y){t.id=Ht(),t.penId=e.id,e.calculative.worldAnchors.push(t)})),e.calculative.worldAnchors.push(n),h&&e.calculative.worldAnchors.push(h)}function oe(t,e,i){const r={x:t.x,y:t.y,id:Ht()};switch(e){case w.Up:r.y-=i;break;case w.Right:r.x+=i;break;case w.Bottom:r.y+=i;break;case w.Left:r.x-=i;break;default:return}return r}function se(t,e,i,r){const n=[];let o,s,a,c,l,h,u,d,p,f,v,y,g,w;p=t[i],f=t[r],a=p.x,c=p.y,u=f.x-a,d=f.y-c,w=u*u+d*d,o=e;for(let e=i+1;e1?(l=v.x-f.x,h=v.y-f.y):y>0?(l=v.x-(a+u*y),h=v.y-(c+d*y)):(l=v.x-a,h=v.y-c)):(l=v.x-a,h=v.y-c),g=l*l+h*h,g>o&&(s=e,o=g);return o>e&&(s-i>1&&n.push(...se(t,e,i,s)),n.push({id:t[s].id,penId:t[s].penId,x:t[s].x,y:t[s].y}),r-s>1&&n.push(...se(t,e,s,r))),n}const ae={};function ce(t){if(t.onDestroy||(t.onDestroy=le,t.onMove=he,t.onResize=he,t.onRotate=he,t.onValue=he),ae[t.id])t.iframe!==t.calculative.iframe&&(ae[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,ae[t.id]=e,t.calculative.iframe=t.iframe,t.calculative.canvas.externalElements&&t.calculative.canvas.externalElements.appendChild(e),ut(t,e)}return t.calculative.dirty&&ut(t,ae[t.id]),new Path2D}function le(t){ae[t.id].remove(),ae[t.id]=void 0}function he(t){ut(t,ae[t.id])}const ue={};function de(t){if(t.onDestroy=pe,t.onMove=fe,t.onResize=fe,t.onRotate=fe,t.onClick=ve,t.onValue=fe,ue[t.id])t.video&&t.calculative.media&&t.video!==t.calculative.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 r;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?(r=document.createElement("video"),r.src=t.video):t.audio&&(r=document.createElement("audio"),r.src=t.audio),r.loop=t.playLoop,r.ontimeupdate=()=>{ye(i,r,t.calculative.worldRect.width)},r.onended=()=>{t.calculative.onended&&t.calculative.onended(t)},t.calculative.media=r,r.style.position="absolute",r.style.outline="none",r.style.left="0",r.style.top="0",r.style.width="100%",r.style.height="100%",e.appendChild(r),ue[t.id]=e,t.calculative.canvas.externalElements&&t.calculative.canvas.externalElements.appendChild(e),ut(t,e),t.autoPlay&&(r.autoplay=!0,r.muted=!0)}return t.calculative.dirty&&ut(t,ue[t.id]),new Path2D}function pe(t){ue[t.id].remove(),ue[t.id]=void 0}function fe(t){ut(t,ue[t.id]),ye(ue[t.id].children[0],ue[t.id].children[1],t.calculative.worldRect.width)}function ve(t){t.calculative.media&&(t.calculative.media.muted=!1,t.calculative.media.paused?t.calculative.media.play():t.calculative.media.pause())}function ye(t,e,i){t.style.width=e.currentTime/e.duration*i+"px"}function ge(t,e){return e||(e=new Path2D),e.ellipse(t.calculative.worldRect.x+t.calculative.worldRect.width/2,t.calculative.worldRect.y+t.calculative.worldRect.height/2,t.calculative.worldRect.width/2,t.calculative.worldRect.height/2,0,0,2*Math.PI),e}function we(t,e){return e||(e=new Path2D),e.moveTo(t.calculative.worldRect.x+t.calculative.worldRect.width/2,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y+t.calculative.worldRect.height/2),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width/2,t.calculative.worldRect.y+t.calculative.worldRect.height),e.lineTo(t.calculative.worldRect.x,t.calculative.worldRect.y+t.calculative.worldRect.height/2),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width/2,t.calculative.worldRect.y),e.closePath(),e}function me(t,e){return e||(e=new Path2D),e.moveTo(t.calculative.worldRect.x+t.calculative.worldRect.width/2,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y+t.calculative.worldRect.height),e.lineTo(t.calculative.worldRect.x,t.calculative.worldRect.y+t.calculative.worldRect.height),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width/2,t.calculative.worldRect.y),e.closePath(),e}function xe(t){const e=[];e.push({id:"0",penId:t.id,x:.5,y:0}),e.push({id:"1",penId:t.id,x:.75,y:.5}),e.push({id:"2",penId:t.id,x:.5,y:1}),e.push({id:"3",penId:t.id,x:.25,y:.5}),t.anchors=e}function be(t,e){return e||(e=new Path2D),e.moveTo(t.calculative.worldRect.x+t.calculative.worldRect.width/2,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y+2*t.calculative.worldRect.height/5),e.lineTo(t.calculative.worldRect.x+4*t.calculative.worldRect.width/5,t.calculative.worldRect.y+t.calculative.worldRect.height),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width/5,t.calculative.worldRect.y+t.calculative.worldRect.height),e.lineTo(t.calculative.worldRect.x,t.calculative.worldRect.y+2*t.calculative.worldRect.height/5),e.closePath(),e}function Re(t){const e=[];e.push({id:"0",penId:t.id,x:.5,y:0}),e.push({id:"1",penId:t.id,x:1,y:.4}),e.push({id:"2",penId:t.id,x:.8,y:1}),e.push({id:"3",penId:t.id,x:.2,y:1}),e.push({id:"4",penId:t.id,x:0,y:.4}),t.anchors=e}function _e(t,e){t.onDestroy||(t.onResize=Ae),e||(e=new Path2D);const i=t.calculative.worldRect.width>t.calculative.worldRect.height?t.calculative.worldRect.height:t.calculative.worldRect.width,r=t.calculative.worldRect.x+t.calculative.worldRect.width/2,n=t.calculative.worldRect.y+t.calculative.worldRect.height/2,o=n-i/2,s=n-i/4,a=-(s-n)*Math.sin(Math.PI/180*324)+r,c=(s-n)*Math.cos(Math.PI/180*324)+n;e.moveTo(a,c);for(let t=0;t<5;++t)e.lineTo(-(o-n)*Math.sin(Math.PI/180*72*t)+r,(o-n)*Math.cos(Math.PI/180*72*t)+n),e.lineTo((a-r)*Math.cos(Math.PI/180*72*(t+1))-(c-n)*Math.sin(Math.PI/180*72*(t+1))+r,(a-r)*Math.sin(Math.PI/180*72*(t+1))+(c-n)*Math.cos(Math.PI/180*72*(t+1))+n);return e.closePath(),e}function ke(t){const{width:e,height:i}=t,r=e>i?i:e,n=[];for(let o=0;o<5;++o)n.push({flag:1,id:String(o),penId:t.id,x:.5+r/2*Math.sin(Math.PI/180*72*o)/e,y:-r/2*Math.cos(Math.PI/180*72*o)/i+.5});t.anchors=n}function Ae(t){const e=t.anchors.filter((t=>1!==t.flag));ke(t),t.anchors=t.anchors.concat(...e)}function Se(t,e){return e||(e=new Path2D),e.moveTo(t.calculative.worldRect.x+t.calculative.worldRect.width/4,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+3*t.calculative.worldRect.width/4,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y+t.calculative.worldRect.height/2),e.lineTo(t.calculative.worldRect.x+3*t.calculative.worldRect.width/4,t.calculative.worldRect.y+t.calculative.worldRect.height),e.lineTo(t.calculative.worldRect.x+1*t.calculative.worldRect.width/4,t.calculative.worldRect.y+t.calculative.worldRect.height),e.lineTo(t.calculative.worldRect.x,t.calculative.worldRect.y+t.calculative.worldRect.height/2),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width/4,t.calculative.worldRect.y),e.closePath(),e}function Ee(t,e){return e||(e=new Path2D),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y+t.calculative.worldRect.height/2),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.height/2,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.height/2,t.calculative.worldRect.y+t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y+t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y+2*t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.height/2,t.calculative.worldRect.y+2*t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.height/2,t.calculative.worldRect.y+2*t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.height/2,t.calculative.worldRect.y+t.calculative.worldRect.height),e.closePath(),e}function Te(t,e){return e||(e=new Path2D),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y+t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x+(t.calculative.worldRect.width-t.calculative.worldRect.height/2),t.calculative.worldRect.y+t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x+(t.calculative.worldRect.width-t.calculative.worldRect.height/2),t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y+t.calculative.worldRect.height/2),e.lineTo(t.calculative.worldRect.x+(t.calculative.worldRect.width-t.calculative.worldRect.height/2),t.calculative.worldRect.y+t.calculative.worldRect.height),e.lineTo(t.calculative.worldRect.x+(t.calculative.worldRect.width-t.calculative.worldRect.height/2),t.calculative.worldRect.y+2*t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x,t.calculative.worldRect.y+2*t.calculative.worldRect.height/3),e.closePath(),e}function Ie(t,e){return e||(e=new Path2D),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y+t.calculative.worldRect.height/2),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.height/2,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.height/2,t.calculative.worldRect.y+t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x+(t.calculative.worldRect.width-t.calculative.worldRect.height/2),t.calculative.worldRect.y+t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x+(t.calculative.worldRect.width-t.calculative.worldRect.height/2),t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y+t.calculative.worldRect.height/2),e.lineTo(t.calculative.worldRect.x+(t.calculative.worldRect.width-t.calculative.worldRect.height/2),t.calculative.worldRect.y+t.calculative.worldRect.height),e.lineTo(t.calculative.worldRect.x+(t.calculative.worldRect.width-t.calculative.worldRect.height/2),t.calculative.worldRect.y+2*t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.height/2,t.calculative.worldRect.y+2*t.calculative.worldRect.height/3),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.height/2,t.calculative.worldRect.y+t.calculative.worldRect.height),e.closePath(),e}function Pe(t,e){return e||(e=new Path2D),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y+3*t.calculative.worldRect.height/4),e.lineTo(t.calculative.worldRect.x+8*t.calculative.worldRect.width/16,t.calculative.worldRect.y+3*t.calculative.worldRect.height/4),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width/4,t.calculative.worldRect.ey),e.lineTo(t.calculative.worldRect.x+5*t.calculative.worldRect.width/16,t.calculative.worldRect.y+3*t.calculative.worldRect.height/4),e.lineTo(t.calculative.worldRect.x,t.calculative.worldRect.y+3*t.calculative.worldRect.height/4),e.closePath(),e}function Ce(t,e){return e||(e=new Path2D),e.moveTo(t.calculative.worldRect.x+t.calculative.worldRect.width/5,t.calculative.worldRect.y+13*t.calculative.worldRect.height/16),e.bezierCurveTo(t.calculative.worldRect.x-t.calculative.worldRect.width/15,t.calculative.worldRect.y+13*t.calculative.worldRect.height/16,t.calculative.worldRect.x-t.calculative.worldRect.width/15,t.calculative.worldRect.y+7*t.calculative.worldRect.height/16,t.calculative.worldRect.x+t.calculative.worldRect.width/5,t.calculative.worldRect.y+7*t.calculative.worldRect.height/16),e.bezierCurveTo(t.calculative.worldRect.x+t.calculative.worldRect.width/5,t.calculative.worldRect.y,t.calculative.worldRect.x+4*t.calculative.worldRect.width/5,t.calculative.worldRect.y,t.calculative.worldRect.x+4*t.calculative.worldRect.width/5,t.calculative.worldRect.y+7*t.calculative.worldRect.height/16),e.bezierCurveTo(t.calculative.worldRect.x+16*t.calculative.worldRect.width/15,t.calculative.worldRect.y+7*t.calculative.worldRect.height/16,t.calculative.worldRect.x+16*t.calculative.worldRect.width/15,t.calculative.worldRect.y+13*t.calculative.worldRect.height/16,t.calculative.worldRect.x+4*t.calculative.worldRect.width/5,t.calculative.worldRect.y+13*t.calculative.worldRect.height/16),e.closePath(),e}function Le(t,e){e||(e=new Path2D);const i=t.calculative.worldRect.width/6;return e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.ex-i,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.ex,t.calculative.worldRect.y+i),e.lineTo(t.calculative.worldRect.ex,t.calculative.worldRect.ey),e.lineTo(t.calculative.worldRect.x,t.calculative.worldRect.ey),e.closePath(),e.moveTo(t.calculative.worldRect.ex-i,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.ex-i,t.calculative.worldRect.y+i),e.lineTo(t.calculative.worldRect.ex,t.calculative.worldRect.y+i),e.closePath(),e}function Me(t,e){e||(e=new Path2D);const i=t.calculative.worldRect.width/4;return e.moveTo(t.calculative.worldRect.x+i,t.calculative.worldRect.y),e.rect(t.calculative.worldRect.x+i,t.calculative.worldRect.y,t.calculative.worldRect.width-i,t.calculative.worldRect.height-i),e.moveTo(t.calculative.worldRect.x+i,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x,t.calculative.worldRect.y+i),e.moveTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width-i,t.calculative.worldRect.y+i),e.moveTo(t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.y+t.calculative.worldRect.height-i),e.lineTo(t.calculative.worldRect.x+t.calculative.worldRect.width-i,t.calculative.worldRect.y+t.calculative.worldRect.height),e.moveTo(t.calculative.worldRect.x+i,t.calculative.worldRect.y+t.calculative.worldRect.height-i),e.lineTo(t.calculative.worldRect.x,t.calculative.worldRect.y+t.calculative.worldRect.height),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y+i),e.rect(t.calculative.worldRect.x,t.calculative.worldRect.y+i,t.calculative.worldRect.width-i,t.calculative.worldRect.height-i),e.closePath(),e}function De(t,e){e||(e=new Path2D);const i=t.calculative.worldRect.width/4,r=t.calculative.worldRect.x+t.calculative.worldRect.width/2;return e.arc(r,t.calculative.worldRect.y+i,i,0,2*Math.PI),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y+3*i),e.lineTo(t.calculative.worldRect.ex,t.calculative.worldRect.y+3*i),e.moveTo(r,t.calculative.worldRect.y+2*i),e.lineTo(r,t.calculative.worldRect.y+4*i),e.moveTo(r,t.calculative.worldRect.y+4*i),e.lineTo(t.calculative.worldRect.x,t.calculative.worldRect.ey),e.moveTo(r,t.calculative.worldRect.y+4*i),e.lineTo(t.calculative.worldRect.ex,t.calculative.worldRect.ey),e.closePath(),e}const Ne={};function Oe(t){t.onDestroy||(t.onDestroy=Be,t.onMove=Ue,t.onResize=je,t.onRotate=Ue,t.onValue=Fe);const e=new Path2D;if(t.image){if(!Ne[t.id]){const e=new Image;e.crossOrigin="anonymous",e.src=t.image,Ne[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&&t.calculative.canvas.externalElements.appendChild(e),ut(t,e)}}return t.calculative.dirty&&Ne[t.id]&&ut(t,Ne[t.id]),e}}function Be(t){Ne[t.id].remove(),Ne[t.id]=void 0}function Ue(t){Ne[t.id]&&ut(t,Ne[t.id])}function je(t){Ne[t.id]&&ut(t,Ne[t.id].div)}function Fe(t){Ne[t.id]&&Ne[t.id].src!==t.image&&(ut(t,Ne[t.id].div),Ne[t.id].src=t.image)}function He(t,e){return t.onDestroy||(t.onResize=ze,t.onValue=We),r(t,e)}function ze(t){const e=t.anchors.filter((t=>1!==t.flag));qe(t),t.anchors=t.anchors.concat(...e)}function We(t){ze(t),Q(t)}function qe(t){const e=[],{x:i,y:r,width:n,height:o}=t,s=function(t){let e=t.calculative.borderRadius||0,i=t.calculative.borderRadius||0;const{width:r,height:n}=t;t.calculative.borderRadius<1&&(e=r*t.calculative.borderRadius,i=n*t.calculative.borderRadius);let o=ei+n-s&&(l=Ke(i+n-s,l+s,c,s,-1)),e.push({id:String(e.length),flag:1,penId:t.id,x:(c-i)/n,y:(l-r)/o})}for(let a=0;a<3;a++){let c=r+o*(a+1)/4,l=i+n;cr+o-s&&(l=Ve(l-s,r+o-s,c,s)),e.push({id:String(e.length),flag:1,penId:t.id,x:(l-i)/n,y:(c-r)/o})}for(let a=0;a<5;a++){if(2===a)continue;let c=i+n*(a+1)/6,l=r+o;ci+n-s&&(l=Ke(i+n-s,l-s,c,s)),e.push({id:String(e.length),flag:1,penId:t.id,x:(c-i)/n,y:(l-r)/o})}for(let a=0;a<3;a++){let c=r+o*(a+1)/4,l=i;cr+o-s&&(l=Ve(l+s,r+o-s,c,s,-1)),e.push({id:String(e.length),flag:1,penId:t.id,x:(l-i)/n,y:(c-r)/o})}t.anchors=e}function Ve(t,e,i,r,n=1){return n*Math.sqrt(r**2-(i-e)**2)+t}function Ke(t,e,i,r,n=1){return n*Math.sqrt(r**2-(i-t)**2)+e}function $e(t,e){e||(e=new Path2D);const{x:i,y:r,width:n,height:o}=t.calculative.worldRect;return e.moveTo(i,r+o),e.lineTo(i+n,r+o),e.closePath(),e}function Ye(t){const e=[];e.push({id:"0",x:0,y:1}),e.push({id:"0",x:1,y:1}),t.anchors=e}function Xe(){return/Android|webOS|iPad|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)}const Qe=t=>{let e=0,i=0,r=0,n=0;return"number"==typeof t?e=i=r=n=t:"string"==typeof t?e=i=r=n=parseInt(t,10):Array.isArray(t)&&(e=t[0],r=Ge(t[1])?t[0]:t[1],n=Ge(t[2])?t[0]:t[2],i=Ge(t[3])?r:t[3]),[e,r,n,i]};function Ge(t){return null==t}function Je(){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 Ze{constructor(t){let e;this.parentElement=t,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);for(let t=0;t0?(this.arrowUp.style.borderBottomColor="transparent",this.arrowDown.style.borderTopColor="#777777"):(a+=n.height+o.height+5,this.arrowUp.style.borderBottomColor="#777777",this.arrowDown.style.borderTopColor="transparent"),this.x=s,this.y=a,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px"}hide(){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")}}class ti{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,this.parent.dirty=!0}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.parent.dirty=!0}(this.isDownH||this.isDownV)&&(this.parent.render(),this.parent.onMovePens())},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.dirty=!0,this.parent.render(),this.parent.onMovePens()}destroy(){document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp)}}class ei{constructor(t,e,i){this.parent=t,this.parentElement=e,this.store=i,this.canvas=document.createElement("canvas"),this.offscreen=Je(),this.magnifierScreen=Je(),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.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.input=document.createElement("textarea"),this.inputRight=document.createElement("div"),this.dropdown=document.createElement("ul"),this.mousePos={x:0,y:0},this.magnifierSize=300,this.alreadyCopy=!1,this.onwheel=t=>{if(t.target!==this.externalElements)return;if(t.preventDefault(),t.stopPropagation(),this.store.options.scroll&&!t.ctrlKey&&this.scroll)return void this.scroll.wheel(t.deltaY<0);if(this.store.options.disableScale)return;if(this.store.data.locked===s.Disable)return;const e=t.wheelDeltaY?t.wheelDeltaY===-3*t.deltaY:0===t.deltaMode,i=performance.now();if(i-this.touchStart<50)return;this.touchStart=i;let r=t.x-(this.bounding.left||this.bounding.x),n=t.y-(this.bounding.top||this.bounding.y);e?this.translate(t.wheelDeltaX,t.wheelDeltaY):t.deltaY<0?this.scale(this.store.data.scale+.1,{x:r,y:n}):this.scale(this.store.data.scale-.1,{x:r,y:n}),this.externalElements.focus()},this.onkeydown=t=>{if(this.store.data.locked>=s.DisableMove||"INPUT"===t.target.tagName||"TEXTAREA"===t.target.tagName)return;let e=10,i=10;switch(t.key){case" ":this.hotkeyType=y.Translate;break;case"Control":this.drawingLine?this.drawingLine.calculative.drawlineH=!this.drawingLine.calculative.drawlineH:this.hotkeyType||(this.dirty=!0,this.hotkeyType=y.Select);break;case"Meta":case"Alt":break;case"Shift":if(this.drawingLine){const t=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-1];t!==this.drawingLine.calculative.activeAnchor?(tt(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=y.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.translateMovingAnchor(-1,0);break}e=-10,t.shiftKey&&(e=-5),t.ctrlKey&&(e=-1),this.translatePens(this.store.active,e,0);break;case"ArrowUp":if(this.movingAnchor){this.translateMovingAnchor(0,-1);break}i=-10,t.shiftKey&&(i=-5),t.ctrlKey&&(i=-1),this.translatePens(this.store.active,0,i);break;case"ArrowRight":if(this.movingAnchor){this.translateMovingAnchor(1,0);break}t.shiftKey&&(e=5),t.ctrlKey&&(e=1),this.translatePens(this.store.active,e,0);break;case"ArrowDown":if(this.movingAnchor){this.translateMovingAnchor(0,1);break}t.shiftKey&&(i=5),t.ctrlKey&&(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"v":case"V":t.ctrlKey||t.metaKey?this.paste():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(),this.drawingLineName=this.store.options.drawingLineName):this.store.active&&(this.store.active.forEach((t=>{"line"===t.name&&(t.type&&!t.close?t.type=o.Node:!t.type&&t.close&&(t.type=o.Line),t.close=!t.close,this.store.path2dMap.set(t,L.path2dDraws[t.name](t)),this.dirty=!0)})),this.render());break;case"Escape":this.drawingLineName&&this.finishDrawline(),this.drawingLineName=void 0,this.stopPencil(),this.movingPens&&(this.movingPens=void 0,this.mouseDown=void 0,this.clearDock(),this.store.active?.forEach((t=>{this.updateLines(t)})),this.calcActiveRect(),this.render(1/0)),this.hotkeyType=y.None,this.movingAnchor=void 0,this.magnifier&&(this.magnifier=!1,this.render(1/0))}this.render()},this.onkeyup=t=>{"Alt"===t.key&&this.drawingLine&&(this.store.options.autoAnchor=!this.store.options.autoAnchor),this.hotkeyType&&this.render(1/0),this.hotkeyType{if(!this.store.data.locked)try{t.preventDefault(),t.stopPropagation();const e=t.dataTransfer.getData("Topology")||t.dataTransfer.getData("Text");let i=null;if(!e){const e=t.dataTransfer.files;e.length&&(i=await this.fileToPen(e[0]))}!i&&(i=JSON.parse(e)),i=Array.isArray(i)?i:[i];const r={x:t.offsetX,y:t.offsetY};this.calibrateMouse(r),this.dropPens(i,r)}catch{}},this.ontouchstart=t=>{this.touchStart=performance.now();const e=t.changedTouches[0].pageX,i=t.changedTouches[0].pageY;t.touches.length>1?this.touches=t.touches:!t.target.dataset.l&&this.onMouseDown({x:e,y:i,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:1})},this.ontouchmove=t=>{t.stopPropagation();const e=t.touches,i=e.length;!this.touchCenter&&i>1&&(this.touchCenter={x:e[0].pageX+(e[1].pageX-e[0].pageX)/2,y:e[0].pageY+(e[1].pageY-e[0].pageY)/2});const r=performance.now();if(r-this.touchStart<50)return;this.touchStart=r;const n=t.touches[0].pageX,o=t.touches[0].pageY;if(i>1)if(2===i){if(r-this.touchStart<200)return;const i=t.scale||Math.hypot(e[0].pageX-e[1].pageX,e[0].pageY-e[1].pageY)/Math.hypot(this.touches[0].pageX-this.touches[1].pageX,this.touches[0].pageY-this.touches[1].pageY);t.preventDefault(),i<0?this.scale(this.store.data.scale+.1,this.touchCenter):this.scale(this.store.data.scale-.1,this.touchCenter)}else 3===i&&this.translate(n,o);else t.preventDefault(),this.onMouseMove({x:n,y:o,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:1})},this.ontouchend=t=>{this.touches=void 0,this.touchCenter=void 0;const e=t.changedTouches[0].pageX,i=t.changedTouches[0].pageY;this.onMouseUp({x:e,y:i,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:1})},this.onGesturestart=t=>{t.preventDefault()},this.onMouseDown=t=>{if(this.hideInput(),this.store.data.locked===s.Disable||1!==t.buttons&&2!==t.buttons)this.hoverType=v.None;else if(!this.magnifier)if(2!==t.buttons||this.drawingLine||(this.mouseRight=g.Down),t.x-=this.bounding.left||this.bounding.x,t.y-=this.bounding.top||this.bounding.y,this.calibrateMouse(t),this.mousePos.x=t.x,this.mousePos.y=t.y,this.mouseDown=t,this.lastMouseTime=performance.now(),this.hotkeyType!==y.AddAnchor){if(this.translateX=t.x,this.translateY=t.y,(!t.ctrlKey||this.hoverType)&&this.hotkeyType!==y.Translate&&this.mouseRight!==g.Down){if(this.hoverType!==v.NodeAnchor||this.drawingLineName||this.movingAnchor||(this.drawingLineName=this.store.options.drawingLineName),this.drawingLineName){this.inactive(!0);const e={x:t.x,y:t.y,id:Ht()};if(this.hoverType&&this.hoverType1){const t=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-1];return t.connectTo=this.store.hover.id,t.anchorId=this.store.hoverAnchor.id,et(this.store.pens[this.store.hover.id],this.drawingLine.id,t.id,t.anchorId),void this.finishDrawline(!0)}if(2===t.buttons||"mind"===this.drawingLineName&&this.drawingLine?.calculative.worldAnchors.length>1)return this.finishDrawline(!0),void(this.drawingLineName=this.store.options.drawingLineName);if(this.hoverType===v.Node){let t=!1;if(this.store.options.autoAnchor&&(this.drawingLine||(this.drawingLine={id:Ht(),name:"line",lineName:this.drawingLineName,x:e.x,y:e.y,type:o.Line,calculative:{canvas:this,active:!0,worldAnchors:[e],lineWidth:this.store.data.lineWidth||1},fromArrow:this.store.data.fromArrow||this.store.options.fromArrow,toArrow:this.store.data.toArrow||this.store.options.toArrow,lineWidth:this.store.data.lineWidth||1},t=!0),this.store.hoverAnchor=Z(this.store.hover,this.drawingLine.calculative.worldAnchors[0]),this.drawingLine.autoTo=!0,e.connectTo=this.store.hover.id,e.anchorId=this.store.hoverAnchor.id,t&&et(this.store.pens[this.store.hover.id],this.drawingLine.id,e.id,this.store.hoverAnchor.id)),!t&&this.store.hoverAnchor&&this.drawingLine){const t=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-1];return t.x=this.store.hoverAnchor.x,t.y=this.store.hoverAnchor.y,t.connectTo=this.store.hover.id,t.anchorId=this.store.hoverAnchor.id,et(this.store.pens[this.store.hover.id],this.drawingLine.id,t.id,this.store.hoverAnchor.id),this.drawline(),void this.finishDrawline(!0)}}if(this.hoverType&&this.hoverType{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(t)},this.onMouseMove=t=>{if(this.store.data.locked!==s.Disable)if(!this.mouseDown||this.mouseDown.restore||1===t.buttons||2===t.buttons){if(this.lastMouseTime){if(performance.now()-this.lastMouseTime<50)return void(this.lastMouseTime=0);this.lastMouseTime=0}if(t.x-=this.bounding.left||this.bounding.x,t.y-=this.bounding.top||this.bounding.y,this.calibrateMouse(t),this.mousePos.x=t.x,this.mousePos.y=t.y,this.magnifier)this.render(1/0);else{if(this.mouseDown&&(this.mouseRight===g.Down&&(this.mouseRight=g.Translate),(this.store.data.locked===s.DisableEdit||t.ctrlKey&&!this.hoverType||this.hotkeyType===y.Translate||this.mouseRight===g.Translate)&&this.translateX&&this.translateY&&!this.store.options.disableTranslate&&(!this.store.data.locked||this.mouseRight===g.Translate||this.store.data.locked1&&(t=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-1],it(this.store.pens[t.connectTo],this.drawingLine.id,t.id,t.anchorId)),t?(t.prev=void 0,t.next=void 0,t.id||(t.id=Ht()),t.x=e.x,t.y=e.y,t.connectTo=void 0):(t={...e},this.drawingLine.calculative.worldAnchors.push(t)),this.hoverType&&this.hoverType=r||Math.abs(i)>=r)||(this.alreadyCopy=!0,this.willInactivePen=void 0),1===this.store.active.length&&(this.store.data.locked!==s.DisableMove&&this.store.active[0].locked!==s.DisableMove||this.store.active[0]?.onMouseMove&&this.store.active[0].onMouseMove(this.store.active[0],this.mousePos)),void this.movePens(t)}if(!this.store.active[0]?.locked){if(this.hoverType===v.LineAnchor)return this.getAnchorDock(t),void this.moveLineAnchor(t);if(this.hoverType===v.LineAnchorPrev)return void this.moveLineAnchorPrev(t);if(this.hoverType===v.LineAnchorNext)return void this.moveLineAnchorNext(t)}if(!this.dragRect)return}window&&window.debug&&console.time("hover"),this.willGetHover(t),window&&window.debug&&console.timeEnd("hover"),this.hotkeyType===y.AddAnchor&&(this.dirty=!0),this.render()}}else this.onMouseUp(t);else this.hoverType=v.None},this.hoverTimer=0,this.onMouseUp=t=>{if(this.store.data.locked!==s.Disable){if(t.x-=this.bounding.left||this.bounding.x,t.y-=this.bounding.top||this.bounding.y,this.mouseRight===g.Down&&(console.log("contextmenu on core"),this.store.emitter.emit("contextmenu",{e:t,bounding:this.bounding})),this.mouseRight=g.None,this.calibrateMouse(t),this.mousePos.x=t.x,this.mousePos.y=t.y,this.pencil&&this.finishPencil(),this.hoverType&&this.hoverType1){const t=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-1];return t.connectTo=this.store.hover.id,t.anchorId=this.store.hoverAnchor.id,et(this.store.pens[this.store.hover.id],this.drawingLine.id,t.id,t.anchorId),void this.finishDrawline(!0)}if(this.mouseDown&&this.hoverType===v.LineAnchor&&this.store.hover&&this.store.active[0]&&this.store.active[0]!==this.store.hover){const t=this.store.active[0],e=nt(t),i=ot(t);this.store.hoverAnchor?(e===this.store.activeAnchor?t.autoFrom=void 0:t.autoTo=void 0,this.store.activeAnchor.x=this.store.hoverAnchor.x,this.store.activeAnchor.y=this.store.hoverAnchor.y,this.store.activeAnchor.prev=void 0,this.store.activeAnchor.next=void 0,this.store.activeAnchor.connectTo=this.store.hover.id,et(this.store.pens[this.store.activeAnchor.connectTo],this.store.activeAnchor.penId,this.store.activeAnchor.id,this.store.activeAnchor.anchorId),this[t.lineName]&&this[t.lineName](this.store,t),this.store.path2dMap.set(t,L.path2dDraws.line(t)),this.initLineRect(t)):e===this.store.activeAnchor&&t.autoFrom?this.calcAutoAnchor(t,e,this.store.hover):i===this.store.activeAnchor&&t.autoTo&&this.calcAutoAnchor(t,i,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=>0!=t.visible&&t.locked!==s.Disable&&!t.parentId&&St(t.calculative.worldRect,this.dragRect,this.store.options.dragAllIn)));this.active(t)}if(2!==t.button&&this.mouseDown&&(T(this.mouseDown,t)<2&&(this.store.hover&&this.store.hover.input&&this.showInput(this.store.hover),this.store.emitter.emit("click",{x:t.x,y:t.y,pen:this.store.hover})),this.store.hover&&this.store.emitter.emit("mouseup",{x:t.x,y:t.y,pen:this.store.hover})),this.willInactivePen&&(this.willInactivePen.calculative.active=void 0,lt(this.willInactivePen,!1),this.store.active.splice(this.store.active.findIndex((t=>t===this.willInactivePen)),1),this.calcActiveRect(),this.willInactivePen=void 0,this.store.emitter.emit("inactive",[this.willInactivePen]),this.render(1/0)),this.mouseDown=void 0,this.lastOffsetX=0,this.lastOffsetY=0,this.clearDock(),this.dragRect=void 0,this.initActiveRect=void 0,this.movingPens){if(this.alreadyCopy)this.copy(this.store.active.map(((t,e)=>{const{x:i,y:r}=this.movingPens[e];return{...t,x:i,y:r}}))),this.pasteOffset=0,this.paste(),this.alreadyCopy=!1;else{const t=H(this.store.active);this.store.active.forEach(((t,e)=>{const{x:i,y:r}=this.movingPens[e];Object.assign(t,{x:i,y:r}),t.onMove&&t.onMove(t),this.dirtyPenRect(t),this.updateLines(t)})),this.pushHistory({type:N.Update,pens:H(this.store.active),initPens:t})}this.movingPens=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 r=this.store.pens[e];r&&(r.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.bounding=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.activeRect&&!i&&!this.store.data.locked){const i=dt(this.store.active),r=pt(this.store.active)||this.store.options.disableRotate,n=ft(this.store.active)||this.store.options.disableSize;if(!i&&!r){const i={x:this.activeRect.center.x,y:this.activeRect.y-30};this.activeRect.rotate&&k(i,this.activeRect.rotate,this.activeRect.center),!this.hotkeyType&&A(t,i,this.pointSize)&&(e=v.Rotate,this.externalElements.style.cursor=`url("${this.store.options.rotateCursor}"), auto`)}if(!(this.hotkeyType&&this.hotkeyType!==y.Resize||i||n))for(let i=0;i<4;i++)if(A(t,this.sizeCPs[i],this.pointSize)){let t=m,r=0;Math.abs(this.activeRect.rotate%90-45)<25?(t=x,r=Math.round((this.activeRect.rotate-45)/90)):r=Math.round(this.activeRect.rotate/90),e=v.Resize,this.resizeIndex=i,this.externalElements.style.cursor=t[(i+r)%4];break}if(this.hotkeyType===y.Resize&&!i&&!n)for(let i=4;i<8;i++)if(A(t,this.sizeCPs[i],this.pointSize)){let t=x,r=0;Math.abs(this.activeRect.rotate%90-45)<25?(t=m,r=Math.round((this.activeRect.rotate-45)/90)+1):r=Math.round(this.activeRect.rotate/90),e=v.Resize,this.resizeIndex=i,this.externalElements.style.cursor=t[(i+r)%4];break}}e===v.None&&(e=this.inPens(t,this.store.active),e===v.None&&(e=this.inPens(t,this.store.data.pens))),e||i||!xt(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,ht(q(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,ht(q(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.onMouseMove(this.store.hover,this.mousePos)},this.inPens=(t,e)=>{let i=v.None;for(let r=e.length-1;r>=0;--r){const n=e[r];if(0==n.visible||0==n.calculative.inView||n.locked===s.Disable)continue;let o=4;if(n.lineWidth&&(o+=n.lineWidth/2),n.calculative.active||bt(t,n.calculative.worldRect,o)||xt(t,n.calculative.worldRect)){if(!this.store.data.locked&&this.hotkeyType!==y.Resize){if(n.calculative.worldAnchors)for(const e of n.calculative.worldAnchors)if(i=this.inAnchor(t,n,e),i)break;if(i)break}if(n.type){const e=Zt(t,n);if(e){this.store.data.locked||n.locked?this.externalElements.style.cursor=this.store.options.hoverCursor:this.hotkeyType===y.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move",this.store.hover=n,this.store.pointAt=e.point,this.store.pointAtIndex=e.i,i=v.Line;break}}else{if(n.children){const e=[];if(n.children.forEach((t=>{e.push(this.store.pens[t])})),i=this.inPens(t,e),i)break}if(xt(t,n.calculative.worldRect)){this.store.data.locked||n.locked?this.externalElements.style.cursor=this.store.options.hoverCursor:this.hotkeyType===y.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move",this.store.hover=n,i=v.Node,this.store.pointAt=t;break}}}}return i},this.getAnchorDock=t=>{this.store.hover=void 0;let e=v.None;for(let i=this.store.data.pens.length-1;i>=0;--i){const r=this.store.data.pens[i];if(0==r.visible||r.locked===s.Disable||r===this.store.active[0])continue;let n=4;if(r.lineWidth&&(n+=r.lineWidth/2),bt(t,r.calculative.worldRect,n)&&(this.store.hover=r,this.hotkeyType!==y.Resize)){if(r.calculative.worldAnchors)for(const i of r.calculative.worldAnchors)if(e=this.inAnchor(t,r,i),e)break;if(e)break}}},this.render=t=>{if(t===1/0&&(this.dirty=!0,t=performance.now()),!this.dirty)return;if(null==t&&(t=performance.now()),t-this.lastRender{const t=this.offscreen.getContext("2d");t.save(),t.strokeStyle=this.store.data.color||this.store.options.color;const e={x:0,y:0,ex:this.width,ey:this.height,width:this.width,height:this.height};for(const i of this.store.data.pens){if(isFinite(i.x)||console.warn(i,"画笔的 x 不合法"),i.parentId){const t=this.store.pens[i.parentId],e=t?.calculative?.showChild;if(null!=e&&t.children[e]!==i.id){i.calculative.inView=!1;continue}}if(0==i.visible||0==i.calculative.visible){i.calculative.inView=!1;continue}const r=i.calculative.worldRect.x+this.store.data.x,n=i.calculative.worldRect.y+this.store.data.y;St({x:r,y:n,width:i.calculative.worldRect.width,height:i.calculative.worldRect.height,ex:r+i.calculative.worldRect.width,ey:n+i.calculative.worldRect.height,rotate:i.calculative.worldRect.rotate},e)?(i.calculative.inView=!0,K(t,i)):i.calculative.inView=!1}this.drawingLine&&K(t,this.drawingLine),this.pencilLine&&K(t,this.pencilLine),this.movingPens&&this.movingPens.forEach((e=>{K(t,e)})),t.restore()},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,dt(this.store.active)||pt(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.hover&&(this.hotkeyType!==y.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===y.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===y.AddAnchor||this.movingPens||!this.activeRect||1===this.store.active.length&&this.store.active[0].type||dt(this.store.active)||ft(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===y.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=W(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.input.dataset.penId===t.id)return void this.input.focus();const r=e||t.calculative.worldTextRect;this.input.value=t.calculative.tempText||t.text||"",this.inputParent.style.left=r.x+this.store.data.x+5+"px",this.inputParent.style.top=r.y+this.store.data.y+5+"px",this.inputParent.style.width=r.width-10+"px",this.inputParent.style.height=r.height-10+"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.input.dataset.penId=t.id,this.input.readOnly=t.disableInput,t.dropdownList&&"block"!==this.dropdown.style.display?this.setDropdownList():this.inputRight.style.display="none",this.input.focus(),t.calculative.text="",this.render(1/0)},this.hideInput=()=>{if("flex"===this.inputParent.style.display){this.inputParent.style.display="none";const t=this.store.pens[this.input.dataset.penId];if(!t)return;t.calculative.text=t.text,t.onInput?t.onInput(t,this.input.value):t.text!==this.input.value&&(this.initPens=[H(t)],t.text=this.input.value,t.calculative.text=t.text,this.input.dataset.penId=void 0,B(t),this.dirty=!0,this.pushHistory({type:N.Update,pens:[H(t)],initPens:this.initPens}),this.store.emitter.emit("valueUpdate",t))}this.input.dataset.penId=void 0,this.dropdown.style.display="none"},this.setDropdownList=t=>{this.clearDropdownList(),this.dropdown.style.display="block",this.inputRight.style.display="block",setTimeout((()=>{this.inputRight.style.transform="rotate(315deg)"}));const e=this.store.pens[this.input.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.input.value;let r=0;for(const n of e.dropdownList){if(t&&i){if((n.text||n+"").indexOf(i)>-1){const t=document.createElement("li");t.innerText=n.text||n,t.dataset.l="1",t.dataset.i=r+"",t.onclick=this.selectDropdown,this.dropdown.appendChild(t)}}else{const t=document.createElement("li");t.innerText=n.text||n,t.dataset.l="1",t.dataset.i=r+"",t.onclick=this.selectDropdown,this.dropdown.appendChild(t)}++r}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.input.dataset.penId];if(!e||!i||!i.dropdownList)return;const r=+e.dataset.i;if(i.dropdownList[r]){if(this.initPens=[H(i)],"object"==typeof i.dropdownList[r]){const t=this.getPenRect(i);this.updateValue(i,{...t,...i.dropdownList[r]}),i.calculative.text="",this.calcActiveRect()}else i.text=i.dropdownList[r]+"";this.input.value=i.text,this.dropdown.style.display="none",this.inputRight.style.transform="rotate(135deg)",this.pushHistory({type:N.Update,pens:[H(i)],initPens:this.initPens}),this.render(1/0),this.store.emitter.emit("valueUpdate",i)}},e.appendChild(this.canvas),this.canvas.style.backgroundRepeat="no-repeat",this.canvas.style.backgroundSize="100% 100%",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.magnifierScreen.width=this.magnifierSize+5,this.magnifierScreen.height=this.magnifierSize+5,this.tooltip=new Ze(e),this.store.options.scroll&&(this.scroll=new ti(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.bounding=this.externalElements.getBoundingClientRect(),this.listen(),this.curve=zt,this.polyline=ne,this.mind=$t,this.line=Xt,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(),Xe()?(this.store.options.interval=50,this.externalElements.ontouchstart=this.ontouchstart,this.externalElements.ontouchmove=this.ontouchmove,this.externalElements.ontouchend=this.ontouchend):(this.externalElements.onmousedown=t=>{!t.target.dataset.l&&this.onMouseDown({x:t.x,y:t.y,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons})},this.externalElements.onmousemove=t=>{this.onMouseMove({x:t.x,y:t.y,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons})},this.externalElements.onmouseup=t=>{this.onMouseUp({x:t.x,y:t.y,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons,button:t.button})}),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 M.Document:document.addEventListener("keydown",this.onkeydown),document.addEventListener("keyup",this.onkeyup);break;case M.Canvas:this.externalElements.addEventListener("keydown",this.onkeydown),this.externalElements.addEventListener("keyup",this.onkeyup)}}translateMovingAnchor(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 r=Lt(this.movingAnchor,e),n=t.anchors.findIndex((t=>t.id===this.movingAnchor.id));t.anchors[n]=r,this.dirty=!0}}async fileToPen(t){let e="";return e=this.store.options.uploadFn?await this.store.options.uploadFn(t):this.store.options.uploadUrl?await async function(t,e,i,r){const n=new FormData;if(n.append("file",t),i)for(const t in i)n.append(t,i[t]);const o=await fetch(e,{method:"POST",headers:r,body:n});return(await o.json()).url}(t,this.store.options.uploadUrl,this.store.options.uploadParams,this.store.options.uploadHeaders):await async function(t){return new Promise(((e,i)=>{const r=new FileReader;r.onload=t=>{e(t.target.result)},r.onerror=t=>{i(t)},r.readAsDataURL(t)}))}(t),new Promise(((t,i)=>{const r=new Image;r.onload=()=>{L.htmlElements[e]=r,t({width:r.width,height:r.height,name:"image",image:e})},r.onerror=t=>{i(t)},r.src=e}))}dropPens(t,e){for(const e of t)!e.parentId&&Array.isArray(e.children)&&e.children.length>0&&this.randomCombineId(e,t);for(const e of t)e.id||(e.id=Ht()),!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);this.addPens(t,!0),this.active(t.filter((t=>!t.parentId))),this.render(),this.externalElements.focus()}randomCombineId(t,e,i){mt(t),t.parentId=i;const r=[];if(Array.isArray(t.children))for(const i of t.children){const n=e.find((t=>t.id===i));n&&r.push(this.randomCombineId(n,e,t.id).id)}return t.children=r,t}addPens(t,e){const i=[];for(let e of t)this.beforeAddPen&&1!=this.beforeAddPen(e)||(this.makePen(e),i.push(e));return this.render(1/0),this.store.emitter.emit("add",i),e&&this.pushHistory({type:N.Add,pens:H(i,!0)}),i}willGetHover(t){const e=performance.now();e-this.hoverTimer>40&&(this.hoverTimer=e,this.getHover(t))}inactive(t){this.store.active.length&&(this.store.active.forEach((t=>{t.calculative.active=void 0,t.calculative.activeAnchor=void 0,lt(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,lt(t,!1);this.store.active=[],t.forEach((t=>{t.calculative.active=!0,lt(t)})),this.store.active.push(...t),this.calcActiveRect(),this.dirty=!0,e&&this.store.emitter.emit("active",this.store.active)}getSizeCPs(){this.sizeCPs=kt(this.activeRect);let t={x:this.activeRect.x+.5*this.activeRect.width,y:this.activeRect.y};k(t,this.activeRect.rotate,this.activeRect.center),this.sizeCPs.push(t),t={x:this.activeRect.ex,y:this.activeRect.y+.5*this.activeRect.height},k(t,this.activeRect.rotate,this.activeRect.center),this.sizeCPs.push(t),t={x:this.activeRect.x+.5*this.activeRect.width,y:this.activeRect.ey},k(t,this.activeRect.rotate,this.activeRect.center),this.sizeCPs.push(t),t={x:this.activeRect.x,y:this.activeRect.y+.5*this.activeRect.height},k(t,this.activeRect.rotate,this.activeRect.center),this.sizeCPs.push(t)}inAnchor(t,e,i){if(this.store.hoverAnchor=void 0,this.movingAnchor=void 0,!i)return v.None;if(A(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.hoverAnchor=this.store.hover.calculative.worldAnchors.find((t=>t.id===i.anchorId)),this.externalElements.style.cursor="crosshair",v.NodeAnchor):(this.hotkeyType===y.AddAnchor?this.externalElements.style.cursor="vertical-text":this.externalElements.style.cursor="pointer",v.LineAnchor):(this.hotkeyType===y.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&&A(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&&A(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.canvas.style.width=t+"px",this.canvas.style.height=e+"px",this.externalElements.style.width=t+"px",this.externalElements.style.height=e+"px",t=t*this.store.dpiRatio|0,e=e*this.store.dpiRatio|0,this.canvas.width=t,this.canvas.height=e,this.offscreen.width=t,this.offscreen.height=e,this.bounding=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(1/0)}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)}addPen(t,e){if(!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:N.Add,pens:[t]}),t}pushHistory(t){this.store.data.locked||(t.type!==N.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 N.Add:t.pens.forEach((t=>{const e=this.store.data.pens.findIndex((e=>e.id===t.id));e>-1&&(this.store.data.pens.splice(e,1),this.store.pens[t.id]=void 0)})),t.type=N.Delete;break;case N.Update:(e?t.initPens:t.pens).forEach((t=>{const e=this.store.data.pens.findIndex((e=>e.id===t.id));if(e>-1){t.calculative=this.store.data.pens[e].calculative,this.store.data.pens[e]=t,this.store.pens[t.id]=t;for(const e in t)"object"==typeof t[e]&&"lineDash"!==e||(t.calculative[e]=t[e]);t.calculative.image=void 0,this.dirtyPenRect(t),this.updateLines(t,!0)}}));break;case N.Delete:t.pens.forEach((t=>{this.store.data.pens.splice(t.calculative.layer,0,t),this.store.pens[t.id]=t,t.calculative.canvas||(t.calculative.canvas=this,L.path2dDraws[t.name]&&this.store.path2dMap.set(t,L.path2dDraws[t.name](t)))})),t.type=N.Add}this.render(1/0),this.store.emitter.emit(e?"undo":"redo",t)}makePen(t){t.id||(t.id=Ht()),this.store.data.pens.push(t),this.store.pens[t.id]=t,t.path&&(t.pathId||(t.pathId=Ht()),L.paths[t.pathId]||(L.paths[t.pathId]=t.path),t.path=void 0),t.lineWidth||0===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.forEach((e=>{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)}))),!t.rotate&&(t.rotate=0),this.loadImage(t)}drawline(t){this.drawingLine&&(this[this.drawingLineName]&&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=Gt(t);t.parentId||(t.x=e.x,t.y=e.y,t.width=e.width,t.height=e.height);const{fontSize:i,lineHeight:r}=this.store.options;t.fontSize||(t.fontSize=i,t.calculative.fontSize=t.fontSize*this.store.data.scale),t.lineHeight||(t.lineHeight=r,t.calculative.lineHeight=t.lineHeight),Rt(e),t.calculative.worldRect=e,Y(t,e),B(t),this.store.path2dMap.set(t,L.path2dDraws[t.name](t)),t.calculative.worldAnchors&&(t.anchors=[],t.calculative.worldAnchors.forEach((e=>{t.anchors.push(Lt(e,t.calculative.worldRect))})))}drawingPencil(){this.pencil=!0,this.externalElements.style.cursor="crosshair"}stopPencil(){this.pencil=!1,this.pencilLine=void 0,this.externalElements.style.cursor="default"}finishDrawline(t){if(!this.drawingLine)return;const e=this.drawingLine.calculative.worldAnchors[0];let i=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-1];if(i.isTemp&&(this.drawingLine.calculative.worldAnchors.pop(),i=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-1]),!t&&!i.connectTo&&this.drawingLine.calculative.worldAnchors.pop(),!t&&this.drawingLine.calculative.worldAnchors[0]===this.drawingLine.calculative.activeAnchor)return this.drawingLine=void 0,void this.render(1/0);if(e.connectTo&&i.connectTo){if(this.store.options.disableRepeatLine&&this.store.data.pens.find((t=>{if(t.type){const r=t.calculative.worldAnchors[0],n=t.calculative.worldAnchors[t.calculative.worldAnchors.length-1];return P(r,e)&&P(n,i)}})))return this.drawingLine=void 0,void this.render(1/0)}else if(this.store.options.disableEmptyLine)return this.drawingLine=void 0,void this.render(1/0);const r=Gt(this.drawingLine);this.drawingLine.x=r.x,this.drawingLine.y=r.y,this.drawingLine.width=r.width,this.drawingLine.height=r.height,this.drawingLine.calculative.worldRect=r,this.drawingLine.calculative.activeAnchor=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-1],this.store.activeAnchor=this.drawingLine.calculative.activeAnchor,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:N.Add,pens:[this.drawingLine]})),this.store.path2dMap.set(this.drawingLine,L.path2dDraws[this.drawingLine.name](this.drawingLine)),this.render(1/0),this.drawingLine=void 0,this.drawingLineName=void 0}finishPencil(){if(this.pencilLine){let t=se(this.pencilLine.calculative.worldAnchors,10,0,this.pencilLine.calculative.worldAnchors.length-1),e=this.pencilLine.calculative.worldAnchors[0];t.unshift({id:e.id,penId:e.penId,x:e.x,y:e.y}),e=this.pencilLine.calculative.worldAnchors[this.pencilLine.calculative.worldAnchors.length-1],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 r,n,o,s,a,c,l,h,u,d,p,f,v,y,g,w;const m=(t,e,i,r)=>(s=Math.sqrt(t*t+e*e),s>0?(v=t/s,g=e/s):(v=1,g=0),a=Math.sqrt(i*i+r*r),a>0?(y=i/a,w=r/a):(y=1,w=0),Math.acos(v*y+g*w));p=[],f=t.length,r=t[0],h=t[f-1],p.push({...t[0]});for(let h=0;h1&&(this.pencilLine.calculative.pencil=void 0,this.store.path2dMap.set(this.pencilLine,L.path2dDraws[this.pencilLine.name](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:N.Add,pens:[this.pencilLine]})),this.render(1/0)),this.pencilLine=void 0}}firefoxLoadSvg(t){const e=new Image,i=new XMLHttpRequest;i.open("GET",t.image,!0),i.onload=()=>{const r=(new DOMParser).parseFromString(i.responseText,"text/xml").getElementsByTagName("svg")[0],{width:n,height:o}=t.calculative.worldRect;r.setAttribute("width",`${n}px`),r.setAttribute("height",`${o}px`);const s="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent((new XMLSerializer).serializeToString(r))));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.dirty=!0,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}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.dirty=!0,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.dirty=!0,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.dirty=!0,this.imageLoaded()}}t.calculative.strokeImage=t.strokeImage}}imageLoaded(){this.imageTimer&&clearTimeout(this.imageTimer),this.imageTimer=setTimeout((()=>{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,e,i){e?X(t):$(t),i||this.setCalculativeByScale(t),Q(t),G(this.store.pens,t),B(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)})),t.type&&this.initLineRect(t)}translate(t,e){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.render(1/0),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(){for(const t of this.store.data.pens)t.onMove&&t.onMove(t)}scale(t,e={x:0,y:0}){const{minScale:i,maxScale:r}=this.store.options;if(tr)return;this.calibrateMouse(e),this.dirty=!0;const n=t/this.store.data.scale;this.store.data.scale=t,this.store.data.center=e,S(this.store.data.origin,n,e),this.store.data.pens.forEach((t=>{t.parentId||(function(t,e,i){Pt(t.calculative.worldRect,e,i),t.calculative.initRect&&Pt(t.calculative.initRect,e,i),t.lastFrame&&t.lastFrame.width&&(t.lastFrame.width*=e),t.calculative.x&&S(t.calculative,e,i),t.type&&Q(t)}(t,n,e),this.dirtyPenRect(t,!0),t.onResize&&t.onResize(t))})),this.calcActiveRect(),this.render(1/0),this.store.emitter.emit("scale",this.store.data.scale)}rotatePens(t){this.initPens||(this.initPens=H(this.store.active)),this.activeRect.rotate=E(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(let t of this.store.active){if(t.parentId)return;this.rotatePen(t,e,this.activeRect),t.onRotate&&t.onRotate(t)}this.lastRotate=this.activeRect.rotate,this.getSizeCPs(),this.render(1/0),this.store.emitter.emit("rotatePens",this.store.active),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0;const t=this.store.active,e=[];for(let i of t)e.push(H(i));this.pushHistory({type:N.Update,pens:e,initPens:this.initPens}),this.initPens=void 0}),200)}resizePens(t){if(this.initPens||(this.initPens=H(this.store.active)),!this.initActiveRect)return void(this.initActiveRect=H(this.activeRect));const e=this.mouseDown.x,i=this.mouseDown.y;let r=t.x-e,n=t.y-i;const o=H(this.initActiveRect);It(o,r,n,this.resizeIndex),Rt(o),this.store.options.disableDockLine||(this.clearDock(),this.customeResizeDock?this.dock=this.customeResizeDock(this.store,o,this.store.active,this.resizeIndex):this.dock=function(t,e,i,r){return yt(t,kt(e))}(this.store,o,this.store.active,this.resizeIndex),this.dock.xDock&&(r+=this.dock.xDock.step,this.store.pens[this.dock.xDock.penId].calculative.isDock=!0),this.dock.yDock&&(n+=this.dock.yDock.step,this.store.pens[this.dock.yDock.penId].calculative.isDock=!0));const s=this.activeRect.width,a=this.activeRect.height;let c=r-this.lastOffsetX,l=n-this.lastOffsetY;this.lastOffsetX=r,this.lastOffsetY=n,t.ctrlKey&&(l=([1,3].includes(this.resizeIndex)?-1:1)*(c*a)/s),It(this.activeRect,c,l,this.resizeIndex),Rt(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),t.calculative.worldRect.ex=t.calculative.worldRect.x+t.calculative.worldRect.width,t.calculative.worldRect.ey=t.calculative.worldRect.y+t.calculative.worldRect.height,t.calculative.worldRect.center={x:t.calculative.worldRect.x+t.calculative.worldRect.width/2,y:t.calculative.worldRect.y+t.calculative.worldRect.height/2},t.onResize&&t.onResize(t),this.dirtyPenRect(t,!0),this.updateLines(t)})),this.getSizeCPs(),this.render(1/0),this.store.emitter.emit("resizePens",this.store.active),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0;const t=this.store.active,e=[];for(let i of t)e.push(H(i));this.pushHistory({type:N.Update,pens:e,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=H(this.activeRect));this.movingPens||(this.movingPens=H(this.store.active,!0),this.movingPens.forEach((t=>{t.calculative.canvas=this;const e={globalAlpha:.5};[...p,"image","combine"].includes(t.name)&&(e.name="rectangle",e.onMove=void 0),this.updateValue(t,e),t.calculative.image=void 0,t.calculative.icon=void 0})),this.store.active.forEach((t=>{ht(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 r=H(this.initActiveRect);Et(r,e,i);const n={x:r.x-this.activeRect.x,y:r.y-this.activeRect.y};this.store.options.disableDockLine||(this.clearDock(),this.customeMoveDock?this.dock=this.customeMoveDock(this.store,r,this.movingPens,n):this.dock=function(t,e,i,r){const n=H(function(t){if(1===t.length)return vt(t[0]);const e=_t(t);return vt({type:o.Node,calculative:{worldRect:e,worldAnchors:[]}})}(i));return n.forEach((t=>{t.x+=r.x,t.y+=r.y})),yt(t,n)}(this.store,0,this.movingPens,n),this.dock.xDock&&(n.x+=this.dock.xDock.step,this.store.pens[this.dock.xDock.penId].calculative.isDock=!0),this.dock.yDock&&(n.y+=this.dock.yDock.step,this.store.pens[this.dock.yDock.penId].calculative.isDock=!0)),this.translatePens(this.movingPens,n.x,n.y,!0)}moveLineAnchor(t){if(!this.activeRect||this.store.data.locked)return;this.initPens||(this.initPens=H(this.store.active)),this.store.activeAnchor&&(this.store.activeAnchor.connectTo&&it(this.store.pens[this.store.activeAnchor.connectTo],this.store.activeAnchor.penId,this.store.activeAnchor.id,this.store.activeAnchor.anchorId),this.store.activeAnchor.connectTo=void 0);let e=t.x-this.mouseDown.x,i=t.y-this.mouseDown.y,r=e-this.lastOffsetX,n=i-this.lastOffsetY;this.lastOffsetX=e,this.lastOffsetY=i,I(this.store.activeAnchor,r,n),this.store.hover&&this.store.hoverAnchor&&this.store.hoverAnchor.penId!==this.store.activeAnchor.penId?(this.store.activeAnchor.connectTo=this.store.hover.id,this.store.activeAnchor.anchorId=this.store.hoverAnchor.id,r=this.store.hoverAnchor.x-this.store.activeAnchor.x,n=this.store.hoverAnchor.y-this.store.activeAnchor.y,I(this.store.activeAnchor,r,n)):this.store.options.disableDockLine||(this.dock=function(t,e,i){let r,n,o=1/0,s=1/0;for(const a of i.data.pens)!1!==a.calculative.inView&&vt(a).forEach((i=>{if(i===e)return;const a=Math.abs(i.x-t.x);a<8&&a{this.timer=void 0;const t=this.store.active;this.store.emitter.emit("update",t);const e=[];for(let i of t)e.push(H(i));this.pushHistory({type:N.Update,pens:e,initPens:this.initPens}),this.initPens=void 0}),200)}moveLineAnchorPrev(t){if(!this.activeRect||this.store.data.locked)return;if(this.initPens||(this.initPens=H(this.store.active)),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===R.Bilateral){const e=E(t,this.store.activeAnchor),i=E(this.prevAnchor,this.store.activeAnchor);this.store.activeAnchor.next.x=this.nextAnchor.x,this.store.activeAnchor.next.y=this.nextAnchor.y,k(this.store.activeAnchor.next,e-i,this.store.activeAnchor)}}else this.store.activeAnchor.next.x=t.x,this.store.activeAnchor.next.y=t.y,k(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(1/0),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0;const t=this.store.active;this.store.emitter.emit("update",t);const e=[];for(let i of t)e.push(H(i));this.pushHistory({type:N.Update,pens:e,initPens:this.initPens}),this.initPens=void 0}),200)}moveLineAnchorNext(t){if(!this.activeRect||this.store.data.locked)return;if(this.initPens||(this.initPens=H(this.store.active)),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===R.Bilateral){const e=E(t,this.store.activeAnchor),i=E(this.nextAnchor,this.store.activeAnchor);this.store.activeAnchor.prev.x=this.prevAnchor.x,this.store.activeAnchor.prev.y=this.prevAnchor.y,k(this.store.activeAnchor.prev,e-i,this.store.activeAnchor)}}else this.store.activeAnchor.prev.x=t.x,this.store.activeAnchor.prev.y=t.y,k(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(1/0),this.timer&&clearTimeout(this.timer),this.timer=setTimeout((()=>{this.timer=void 0;const t=this.store.active;this.store.emitter.emit("update",t);const e=[];for(let i of t)e.push(H(i));this.pushHistory({type:N.Update,pens:e,initPens:this.initPens}),this.initPens=void 0}),200)}setAnchor(t){if(this.initPens=[H(this.store.hover)],this.store.hoverAnchor)!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)}(this.store.hover,this.store.hoverAnchor),this.store.hover.type&&this.initLineRect(this.store.hover),this.store.hoverAnchor=void 0,this.store.activeAnchor=void 0,this.externalElements.style.cursor="default";else if(this.store.hover)if(this.store.hover.type){this.store.activeAnchor=function(t,e,i){t.anchors||(t.anchors=[]),t.calculative.worldAnchors||(t.calculative.worldAnchors=[]);const r=function(t,e,i){let r=t.calculative.worldAnchors[i],n=t.calculative.worldAnchors[i+1];const o=e.step;let s;if(r.next&&n.prev){const e=r,i=r.next,a=n.prev,c=n,l=Kt(e,i,o),h=Kt(i,a,o),u=Kt(a,c,o),d=Kt(l,h,o),p=Kt(h,u,o);s=Kt(d,p,o),d.penId=t.id,s.prev=d,p.penId=t.id,s.next=p,r.next.x=l.x,r.next.y=l.y,n.prev.x=u.x,n.prev.y=u.y}else if(r.next||n.prev){const i=r,a=r.next||n.prev,c=n,l=Kt(i,a,o),h=Kt(a,c,o);s=e,l.penId=t.id,h.penId=t.id,s.prev=l,s.next=h,r.next=void 0,n.prev=void 0}else s=e;return s.penId=t.id,s.id=Ht(),s.prevNextType=R.Bilateral,s}(t,e,i);return t.calculative.worldAnchors.splice(i+1,0,r),t.anchors.splice(i+1,0,Lt(r,t.calculative.worldRect)),t.calculative.activeAnchor=r,r}(this.store.hover,this.store.pointAt,this.store.pointAtIndex),this.initLineRect(this.store.hover);const e={x:t.x,y:t.y};this.getHover(e)}else{const e={id:Ht(),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&&k(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}(this.store.hover,e)}this.hotkeyType=y.None,this.render(1/0),this.store.emitter.emit("update",[this.store.hover]),this.pushHistory({type:N.Update,pens:[H(this.store.hover)],initPens:this.initPens}),this.initPens=void 0}translatePens(t,e,i,r){if(!t||t.length<1||1===t.length&&t[0].type&&t[0].anchors.findIndex((t=>t.connectTo))>-1)return!1;r||(this.initPens=H(t)),Et(this.activeRect,e,i),t.forEach((t=>{t.locked>=s.DisableMove||(t.type?(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.dirtyLines.add(t),this.store.path2dMap.set(t,L.path2dDraws[t.name](t))):(Et(t.calculative.worldRect,e,i),this.dirtyPenRect(t,!0),t.calculative.x=t.x,t.calculative.y=t.y,this.updateLines(t)),t.onMove&&t.onMove(t))})),this.getSizeCPs(),this.dirtyLines.forEach((t=>{r&&!t.text||t.type&&this.initLineRect(t)})),this.render(1/0),this.tooltip.translate(e,i),this.store.emitter.emit("translatePens",t),r||(this.pushHistory({type:N.Update,pens:H(t),initPens:this.initPens}),this.initPens=void 0)}calcAutoAnchor(t,e,i,r){const n=nt(t),o=ot(t),s=Z(i,e===n?o:n);e.x=s.x,e.y=s.y,e.prev=void 0,e.next=void 0,e.connectTo=i.id,r?r.anchor=s.id:i.connectedLines.push({lineId:t.id,lineAnchor:e.id,anchor:s.id}),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]=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,!t.keepAnimateState),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 r=this.store.pens[i.lineId];if(!r)return;const n=rt(r,i.lineAnchor);if(!n)return;if(r.autoFrom){const e=nt(r);e.id===n.id&&this.calcAutoAnchor(r,e,t,i)}if(r.autoTo){const e=ot(r);e.id===n.id&&this.calcAutoAnchor(r,e,t,i)}const o=rt(t,i.anchor);if(o){if(I(n,o.x-n.x,o.y-n.y),!1!==r.autoPolyline&&(this.store.options.autoPolyline||r.autoPolyline)&&"polyline"===r.lineName){let t=r.calculative.worldAnchors[0],e=r.calculative.worldAnchors[r.calculative.worldAnchors.length-1],i=!1;t.id===n.id?(t=n,i=!0):e.id===n.id&&(e=n,i=!0),i&&(r.calculative.worldAnchors=[t,e],r.calculative.activeAnchor=t,this.polyline(this.store,r,e),this.initLineRect(r))}this.store.path2dMap.set(r,L.path2dDraws[r.name](r)),this.dirtyLines.add(r),e&&ie(r)}}))}calcActiveRect(){const t=this.store.active.filter((t=>!t.locked||t.locked{k(t,e,i.center)})),this.initLineRect(t)):(t.calculative.rotate?t.calculative.rotate+=e:t.calculative.rotate=e,k(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 r=this.store.pens[i];this.rotatePen(r,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(let r of this.store.animates)if(!r.calculative.pause){if(r.calculative.active&&!r.type&&(i=!0),r.type){if(!ct(r,t)){if(r.keepAnimateState){for(const t in r)void 0!==r.calculative[t]&&("object"==typeof r[t]&&"lineDash"!==t||(r[t]=r.calculative[t]));X(r)}else for(const t in r)"object"==typeof r[t]&&"lineDash"!==t||(r.calculative[t]=r[t]);e.push(r),this.nextAnimate(r)}}else st(r,t)?r.calculative.dirty&&this.dirtyPenRect(r,!0,!0):(this.restoreNodeAnimate(r),e.push(r),this.nextAnimate(r)),this.updateLines(r,!0);this.dirty=!0}i&&this.calcActiveRect(),e.forEach((t=>{this.store.animates.delete(t)})),this.render(),this.animateRendering=!1,this.animate()}))}get clipboardName(){return"topology-clipboard"}copy(t){this.store.clipboard=t||this.store.active,this.pasteOffset=10;const e=H(this.store.clipboard);localStorage.setItem(this.clipboardName,JSON.stringify({topology:!0,data:e})),navigator.clipboard?.writeText(JSON.stringify({topology:!0,data:e}))}cut(t){this.copy(t),this.delete(this.store.clipboard)}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}this.store.clipboard=H(this.store.clipboard);const e=this.getAddPens(this.store.clipboard);for(const t of this.store.clipboard)this.pastePen(t,void 0,e);this.active(this.store.clipboard),this.pushHistory({type:N.Add,pens:e}),this.render(),this.store.emitter.emit("add",e),localStorage.removeItem(this.clipboardName)}getAddPens(t){const e=[];for(const i of t)i.children?.forEach((t=>{e.find((e=>e.id===t))||e.push(H(this.store.pens[t]))}));return e.concat(t)}pastePen(t,e,i=[]){const r=t.id;if(mt(t),t.parentId=e,!e&&Et(t,this.pasteOffset,this.pasteOffset),t.type===o.Line?this.changeNodeConnectedLine(r,t,i):this.changeLineAnchors(r,t,i),!this.beforeAddPen||1==this.beforeAddPen(t)){this.makePen(t);const e=[];if(Array.isArray(t.children))for(const r of t.children){const n=i.find((t=>t.id===r));n&&e.push(this.pastePen(n,t.id,i).id)}return t.children=e,t}}changeLineAnchors(t,e,i){if(Array.isArray(e.connectedLines))for(let r=0;rt.id===n));if(o){const i=o.anchors[0],r=o.anchors[o.anchors.length-1];i.connectTo===t&&(i.connectTo=e.id),r.connectTo===t&&(r.connectTo=e.id)}else e.connectedLines.splice(r,1),r--}}changeNodeConnectedLine(t,e,i){const r=[e.anchors[0],e.anchors[e.anchors.length-1]];for(const n of r){const r=n.connectTo;if(r){const o=i.find((t=>t.id===r));o?o.connectedLines?.forEach((i=>{i.lineId===t&&(i.lineId=e.id,i.lineAnchor=n.id)})):(n.connectTo=void 0,n.prev&&(n.prev.connectTo=void 0),n.next&&(n.next.connectTo=void 0))}}}delete(t,e=!1,i=!1){t||(t=this.store.active),t&&t.length&&(t.forEach((t=>{if(!i&&t.locked&&!e)return;const r=this.store.data.pens.findIndex((e=>e.id===t.id));if(r>-1&&(this.delLineConnectTo(this.store.data.pens[r]),this.store.data.pens.splice(r,1),this.store.pens[t.id]=void 0),t.onDestroy&&t.onDestroy(t),Array.isArray(t.children)){const e=this.store.data.pens.filter((e=>t.children.includes(e.id)));this.delete(e,!0,i)}})),this.inactive(),this.store.hoverAnchor=void 0,this.store.hover=void 0,this.render(1/0),this.pushHistory({type:N.Delete,pens:t}),this.store.emitter.emit("delete",t))}delLineConnectTo(t){t.connectedLines?.forEach((e=>{const i=this.store.pens[e.lineId];if(i){const e=i.anchors[0],r=i.anchors[i.anchors.length-1];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)),r.connectTo===t.id&&(r.connectTo=void 0,r.anchorId=void 0,r.prev&&(r.prev.connectTo=void 0),r.next&&(r.next.connectTo=void 0)),Q(i),Gt(i)}}))}createInput(){let t;this.inputParent.classList.add("topology-input"),this.inputRight.classList.add("right"),this.inputParent.appendChild(this.input),this.inputParent.appendChild(this.inputRight),this.inputParent.appendChild(this.dropdown),this.externalElements.appendChild(this.inputParent),this.inputParent.dataset.l="1",this.input.dataset.l="1",this.inputRight.dataset.l="1",this.dropdown.dataset.l="1",this.inputRight.style.transform="rotate(135deg)";for(let e=0;e{const t=this.store.pens[this.input.dataset.penId];"block"===this.dropdown.style.display?(this.dropdown.style.display="none",this.inputRight.style.transform="rotate(135deg)"):t?.dropdownList&&(this.dropdown.style.display="block",this.inputRight.style.transform="rotate(315deg)"),this.store.emitter.emit("clickInput",t)},this.input.onkeyup=t=>{this.setDropdownList(!0);const e=this.store.pens[this.input.dataset.penId];this.store.emitter.emit("input",{pen:e,text:t.key})}}clearDropdownList(){if(this.dropdown.hasChildNodes())for(let t=0;tt.preventDefault(),this.externalElements.ondrop=void 0,Xe()?(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.ondblclick=void 0,this.store.options.keydown){case M.Document:document.removeEventListener("keydown",this.onkeydown),document.removeEventListener("keyup",this.onkeyup);break;case M.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 ii;!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"}(ii||(ii={}));class ri{constructor(t){let e;this.parent=t,this.onMouseDown=t=>{t.preventDefault(),t.stopPropagation(),this.isDown=!0},this.onMouseMove=t=>{t.preventDefault(),t.stopPropagation(),this.isDown&&this.parent.gotoView(t.offsetX/this.box.clientWidth,t.offsetY/this.box.clientHeight)},this.onMouseUp=t=>{t.preventDefault(),t.stopPropagation(),this.parent.gotoView(t.offsetX/this.box.clientWidth,t.offsetY/this.box.clientHeight),this.isDown=!1},this.box=document.createElement("div"),this.img=new Image,this.box.appendChild(this.img),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;t{switch(t){case"add":e.forEach((t=>{t.onAdd&&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.onValue(e),this.store.data.locked&&this.doEvent(e,t);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)if(i.where.fn)e=i.where.fn(t);else if(i.where.fnJs){try{i.where.fn=new Function("pen","params",i.where.fnJs)}catch(t){console.error("Error: make function:",t)}i.where.fn&&(e=i.where.fn(t))}else switch(i.where.comparison){case">":e=t[i.where.key]>+i.where.value;break;case">=":e=t[i.where.key]>=+i.where.value;break;case"<":e=t[i.where.key]<+i.where.value;break;case"<=":e=t[i.where.key]<=+i.where.value;break;case"=":case"==":e=t[i.where.key]==i.where.value;break;case"!=":e=t[i.where.key]!=i.where.value}e&&this.events[i.action](t,i)}})),this.doEvent(this.store.pens[t.parentId],e))},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}},histories:[],pens:{},path2dMap:new WeakMap,active:[],animates:new Set,options:{...D},emitter:{all:e=e||new Map,on:function(t,i){var r=e.get(t);r&&r.push(i)||e.set(t,[i])},off:function(t,i){var r=e.get(t);r&&r.splice(r.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]})(Ht()),this.setOptions(e),this.init(t),this.register({rectangle:r,square:n,circle:ge,svgPath:Ft,diamond:we,triangle:me,pentagon:be,pentagram:_e,hexagon:Se,leftArrow:Ee,rightArrow:Te,twowayArrow:Ie,message:Pe,cloud:Ce,file:Le,cube:Me,people:De,line:Yt,iframe:ce,video:de,gif:Oe,mindNode:He,mindLine:$e}),this.registerAnchors({triangle:xe,pentagon:Re,pentagram:ke,mindNode:qe,mindLine:Ye}),window&&(window.topology=this),this.facePen=J,this.initEventFns(),this.store.emitter.on("*",this.onEvent),this.getWords=F,this.calcTextLines=j,this.calcTextRect=B,this.calcTextDrawRect=U}get beforeAddPen(){return this.canvas.beforeAddPen}set beforeAddPen(t){this.canvas.beforeAddPen=t}get beforeAddAnchor(){return this.canvas.beforeAddAnchor}set beforeAddAnchor(t){this.canvas.beforeAddAnchor=t}get beforeRemovePen(){return this.canvas.beforeRemovePen}set beforeRemovePen(t){this.canvas.beforeRemovePen=t}get beforeRemoveAnchor(){return this.canvas.beforeAddAnchor}set beforeRemoveAnchor(t){this.canvas.beforeAddAnchor=t}setOptions(t={}){this.store.options=Object.assign(this.store.options,t)}getOptions(){return this.store.options}init(t){this.canvas=new ei(this,"string"==typeof t?document.getElementById(t):t,this.store),this.resize(),this.canvas.listen()}initEventFns(){this.events[ii.Link]=(t,e)=>{window.open(e.value,void 0===e.params?"_blank":e.params)},this.events[ii.SetProps]=(t,e)=>{const i=this.getPenRect(t);this.setValue({id:t.id,...i,...e.value})},this.events[ii.StartAnimate]=(t,e)=>{e.value?this.startAnimate(e.value):this.startAnimate([t])},this.events[ii.PauseAnimate]=(t,e)=>{e.value?this.pauseAnimate(e.value):this.pauseAnimate([t])},this.events[ii.StopAnimate]=(t,e)=>{e.value?this.stopAnimate(e.value):this.stopAnimate([t])},this.events[ii.Function]=(t,e)=>{if(!e.fn)try{e.fn=new Function("pen","params",e.value)}catch(t){console.error("Error: make function:",t)}e.fn&&e.fn(t,e.params)},this.events[ii.WindowFn]=(t,e)=>{window&&window[e.value]&&window[e.value](t,e.params)},this.events[ii.Emit]=(t,e)=>{this.store.emitter.emit(e.value,{pen:t,params:e.params})}}resize(t,e){this.canvas.resize(t,e),this.canvas.render(),this.store.emitter.emit("resize",{width:t,height:e}),this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.init()}addPen(t,e){return this.canvas.addPen(t,e)}addPens(t,e){return this.canvas.addPens(t,e)}render(t){this.canvas.render(t)}setBackgroundImage(t){this.store.data.bkImage=t,this.canvas.canvas.style.backgroundImage=`url(${t})`}open(t){for(const t of this.store.data.pens)t.onDestroy&&t.onDestroy(t);if(O(this.store),this.hideInput(),this.canvas.tooltip.hide(),this.canvas.activeRect=void 0,this.canvas.sizeCPs=void 0,t){t.paths&&Object.assign(L.paths,t.paths),this.setBackgroundImage(t.bkImage),Object.assign(this.store.data,t),this.store.data.pens=[];for(const e of t.pens)e.id||(e.id=Ht()),!e.calculative&&(e.calculative={canvas:this.canvas}),this.store.pens[e.id]=e;for(const e of t.pens)this.canvas.makePen(e)}this.canvas.render(1/0),this.listenSocket(),this.connectSocket(),this.startAnimate(),this.doInitJS(),this.store.emitter.emit("opened"),this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.init()}connectSocket(){this.connectWebsocket(),this.connectMqtt()}doInitJS(){this.store.data.initJs&&this.store.data.initJs.trim()&&new Function(this.store.data.initJs)()}drawLine(t){this.canvas.drawingLineName=t}drawingPencil(){this.canvas.drawingPencil()}stopPencil(){this.canvas.stopPencil()}finishDrawLine(t){this.canvas.finishDrawline(t)}finishPencil(){this.canvas.finishPencil()}updateLineType(t,e){if(!t||"line"!=t.name||!e||!this.canvas[e])return;t.lineName=e;const i=t.calculative.worldAnchors[0],r=t.calculative.worldAnchors[t.calculative.worldAnchors.length-1];i.prev=void 0,i.next=void 0,r.prev=void 0,r.next=void 0,t.calculative.worldAnchors=[i,r],t.calculative.activeAnchor=i,this.canvas[e](this.store,t,r),"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},r.prev={penId:r.penId,x:r.x-50,y:r.y},r.next={penId:r.penId,x:r.x+50,y:r.y}),t.calculative.activeAnchor=void 0,this.canvas.initLineRect(t),this.render(1/0)}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(){O(this.store),this.canvas.clearCanvas(),this.canvas.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}register(t){!function(t){Object.assign(L.path2dDraws,t)}(t)}registerCanvasDraw(t){!function(t){Object.assign(L.canvasDraws,t)}(t)}registerAnchors(t){var e;e=t,Object.assign(L.anchors,e)}registerMoveDock(t){this.canvas.customeMoveDock=t}registerResizeDock(t){this.canvas.customeResizeDock=t}find(t){return this.store.data.pens.filter((e=>e.id==t||e.tags&&e.tags.indexOf(t)>-1))}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.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.animatePos=0,this.store.animates.delete(t),this.canvas.restoreNodeAnimate(t)})),this.canvas.calcActiveRect(),this.render(1/0)}calcAnimateDuration(t){return t.frames.reduce(((t,e)=>t+e.duration),0)}combine(t,e){if(t||(t=this.store.active),!t||!t.length)return;const i=H(t);if(1===t.length&&t[0].type)return t[0].type=o.Node,this.canvas.active(t),this.pushHistory({type:N.Update,initPens:i,pens:H(t,!0)}),void this.render();const r=_t(t);let n={id:Ht(),name:"combine",x:r.x,y:r.y,width:r.width,height:r.height,children:[],showChild:e};const a=t.find((t=>t.width===r.width&&t.height===r.height));a&&null==e?(a.children||(a.children=[]),n=a):this.canvas.makePen(n),t.forEach((t=>{if(t===n||t.parentId===n.id)return;n.children.push(t.id),t.parentId=n.id;const e=Ct(t.calculative.worldRect,r);t.x=e.x,t.y=e.y,t.width=e.width,t.height=e.height,t.locked=s.DisableMove})),this.canvas.active([n]),this.pushHistory({type:N.Add,pens:[n],step:2}),this.pushHistory({type:N.Update,initPens:i,pens:t,step:2}),this.render(),this.store.emitter.emit("add",[n])}uncombine(t){if(!t&&this.store.active&&(t=this.store.active[0]),!t||!t.children)return;const e=this.store.data.pens.filter((e=>t.children.includes(e.id)));let i=H(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=s.None,t.calculative.active=void 0,t.calculative.hover=!1}));const r="combine"===t.name?3:2;this.pushHistory({type:N.Update,initPens:i,pens:e,step:r}),i=[H(t)],t.children=void 0,this.pushHistory({type:N.Update,initPens:i,pens:[t],step:r}),"combine"===t.name&&(this.delete([t]),this.store.histories[this.store.histories.length-1].step=r),this.inactive()}active(t,e=!0){this.canvas.active(t,e)}inactive(){this.canvas.inactive()}delete(t,e=!1){this.canvas.delete(t,void 0,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 q(t,e)}data(){const t=H(this.store.data);return t.version=C,t.paths=L.paths,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;if(this.store.data.socketCbJs&&(t=new Function("e",this.store.data.socketCbJs)),!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=Ht()),this.mqttClient=ni.connect(this.store.data.mqtt,this.store.data.mqttOptions),this.mqttClient.on("message",((t,e)=>{this.doSocket(e.toString())})),this.store.data.mqttTopics&&this.mqttClient.subscribe(this.store.data.mqttTopics.split(",")))}closeMqtt(){this.mqttClient?.end()}doSocket(t){if(this.socketFn)this.socketFn(t);else try{t=JSON.parse(t),Array.isArray(t)||(t=[t]),t.forEach((t=>{this.setValue(t,!0,!1)})),this.render(1/0)}catch(t){console.warn("Invalid socket data:",t)}}setValue(t,e=!1,i=!0){(this.find(t.id||t.tag)||[]).forEach((i=>{let r=t;i.onBeforeValue&&(r=i.onBeforeValue(i,t)),this.updateValue(i,r),i.onValue&&i.onValue(i),e&&this.store.data.locked&&this.doEvent(i,"valueUpdate")})),!this.store.data.locked&&this.store.active.length&&this.canvas.calcActiveRect(),i&&this.render(1/0)}updateValue(t,e){this.canvas.updateValue(t,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){t.children||(t.children=[]),e.forEach((e=>{if(e.calculative||this.canvas.makePen(e),e.parentId){const t=this.store.pens[e.parentId],i=t.children.findIndex((t=>t===e.id));t.children.splice(i,1)}t.children.push(e.id),e.parentId=t.id;const i=Ct(e.calculative.worldRect,t.calculative.worldRect);e.x=i.x,e.y=i.y,e.width=i.width,e.height=i.height,e.locked=s.DisableMove,this.store.pens[e.id]=e}))}renderPenRaw(t,e,i){!function(t,e,i){if(t.save(),i&&t.translate(-i.x,-i.y),t.beginPath(),t.setAttrs&&t.setAttrs(e),e.calculative.flip&&(e.calculative.flip===l.Horizontal?(i?t.translate(e.calculative.worldRect.x+e.calculative.worldRect.ex-i.x,-i.y):t.translate(e.calculative.worldRect.x+e.calculative.worldRect.ex,0),t.scale(-1,1)):e.calculative.flip===l.Vertical&&(i?t.translate(-i.x,e.calculative.worldRect.y+e.calculative.worldRect.ey-i.x):t.translate(0,e.calculative.worldRect.y+e.calculative.worldRect.ey),t.scale(1,-1))),e.calculative.rotate&&"line"!==e.name){t.translate(e.calculative.worldRect.center.x,e.calculative.worldRect.center.y);let i=e.calculative.rotate*Math.PI/180;e.calculative.flip&&(i*=-1),t.rotate(i),t.translate(-e.calculative.worldRect.center.x,-e.calculative.worldRect.center.y)}e.calculative.lineWidth>1&&(t.lineWidth=e.calculative.lineWidth);const r=e.calculative.canvas.store;let n;if(e.calculative.hover?(t.strokeStyle=e.hoverColor||r.options.hoverColor,t.fillStyle=e.hoverBackground||r.options.hoverBackground,n=e.hoverBackground||r.options.hoverBackground):e.calculative.active?(t.strokeStyle=e.activeColor||r.options.activeColor,t.fillStyle=e.activeBackground||r.options.activeBackground,n=e.activeBackground||r.options.activeBackground):(e.strokeImage?e.calculative.strokeImg&&(t.strokeStyle=t.createPattern(e.calculative.strokeImg,"repeat"),n=!0):t.strokeStyle=e.calculative.color||"#000000",e.backgroundImage?e.calculative.backgroundImg&&(t.fillStyle=t.createPattern(e.calculative.backgroundImg,"repeat"),n=!0):(t.fillStyle=e.background,n=!!e.background)),e.calculative.lineCap?t.lineCap=e.calculative.lineCap:e.type&&(t.lineCap="round"),e.calculative.lineJoin?t.lineJoin=e.calculative.lineJoin:e.type&&(t.lineJoin="round"),e.calculative.globalAlpha<1&&(t.globalAlpha=e.calculative.globalAlpha),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),L.path2dDraws[e.name]){if(e.type===o.Line&&e.borderWidth){t.save(),t.beginPath();const i=e.calculative.lineWidth+e.calculative.borderWidth;t.lineWidth=i,t.strokeStyle=e.borderColor,L.path2dDraws[e.name](e,t),n&&t.fill(),i&&t.stroke(),t.restore()}t.save(),t.beginPath(),L.path2dDraws[e.name](e,t),n&&t.fill(),e.calculative.lineWidth&&t.stroke(),t.restore();const i=e.calculative.progress||e.progress;if(null!=i){t.save();let n=t.createLinearGradient(e.calculative.worldRect.x,e.calculative.worldRect.y,e.calculative.worldRect.x+e.calculative.worldRect.width*i,e.calculative.worldRect.y);e.verticalProgress&&(n=t.createLinearGradient(e.calculative.worldRect.x,e.calculative.worldRect.ey,e.calculative.worldRect.x,e.calculative.worldRect.y+e.calculative.worldRect.height*(1-i)));const o=e.progressColor||e.color||r.options.activeColor;n.addColorStop(0,o),n.addColorStop(1,o),n.addColorStop(1,"transparent"),t.fillStyle=n,t.beginPath(),L.path2dDraws[e.name](e,t),t.fill(),t.restore()}}if(L.canvasDraws[e.name]){t.save();const i=L.canvasDraws[e.name](t,e,r);if(t.restore(),i)return}if(e.image&&e.calculative.img){t.save(),t.shadowColor="",t.shadowBlur=0;const i=e.calculative.worldIconRect;let r=i.x,n=i.y,o=i.width,s=i.height;if(e.calculative.iconWidth&&(o=e.calculative.iconWidth),e.calculative.iconHeight&&(s=e.calculative.iconHeight),e.calculative.imgNaturalWidth&&e.calculative.imgNaturalHeight){let t=i.width/e.calculative.imgNaturalWidth,r=i.height/e.calculative.imgNaturalHeight,n=t>r?r:t;e.iconWidth?s=n*e.iconWidth:o=n*e.calculative.imgNaturalWidth,s=e.iconHeight?n*e.iconHeight:n*e.calculative.imgNaturalHeight}r+=(i.width-o)/2,n+=(i.height-s)/2,e.iconRotate&&(t.translate(i.center.x,i.center.y),t.rotate(e.iconRotate*Math.PI/180),t.translate(-i.center.x,-i.center.y)),t.drawImage(e.calculative.img,r,n,o,s),t.restore()}else if(e.icon){t.save(),t.shadowColor="",t.shadowBlur=0,t.textAlign="center",t.textBaseline="middle";const i=e.calculative.worldIconRect;let n=i.x+i.width/2,o=i.y+i.height/2;switch(e.iconAlign){case"top":o=i.y,t.textBaseline="top";break;case"bottom":o=i.ey,t.textBaseline="bottom";break;case"left":n=i.x,t.textAlign="left";break;case"right":n=i.ex,t.textAlign="right";break;case"left-top":n=i.x,o=i.y,t.textAlign="left",t.textBaseline="top";break;case"right-top":n=i.ex,o=i.y,t.textAlign="right",t.textBaseline="top";break;case"left-bottom":n=i.x,o=i.ey,t.textAlign="left",t.textBaseline="bottom";break;case"right-bottom":n=i.ex,o=i.ey,t.textAlign="right",t.textBaseline="bottom"}e.calculative.iconSize>0?t.font=`${e.calculative.iconWeight||"normal"} ${e.calculative.iconSize}px '${e.calculative.iconFamily}'`:i.width>i.height?t.font=`${e.calculative.iconWeight||"normal"} ${i.height}px '${e.calculative.iconFamily}'`:t.font=`${e.calculative.iconWeight||"normal"} ${i.width}px '${e.calculative.iconFamily}'`,t.fillStyle=e.iconColor||e.textColor||r.options.textColor,e.calculative.worldRect.rotate&&(t.translate(i.center.x,i.center.y),t.rotate(e.calculative.worldRect.rotate*Math.PI/180),t.translate(-i.center.x,-i.center.y)),t.beginPath(),t.fillText(e.icon,n,o),t.restore()}if(e.calculative.text&&!e.calculative.hiddenText){t.save(),e.calculative.textHasShadow||(t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),t.fillStyle=e.calculative.textColor||e.calculative.color,t.font=`${e.calculative.fontStyle||"normal"} normal ${e.calculative.fontWeight||"normal"} ${e.calculative.fontSize}px/${e.calculative.lineHeight} ${e.calculative.fontFamily||r.options.fontFamily}`,!e.calculative.textDrawRect&&U(t,e),e.calculative.textBackground&&(t.save(),t.fillStyle=e.calculative.textBackground,t.fillRect(e.calculative.textDrawRect.x,e.calculative.textDrawRect.y,e.calculative.textDrawRect.width,e.calculative.textDrawRect.height),t.restore());const i=.55,{width:n}=e.calculative.textDrawRect,o=e.textAlign||r.options.textAlign;e.calculative.textLines.forEach(((r,s)=>{let a=0;"center"===o?a=(n-e.calculative.textLineWidths[s])/2:"right"===o&&(a=n-e.calculative.textLineWidths[s]),t.fillText(r,e.calculative.textDrawRect.x+a,e.calculative.textDrawRect.y+(s+i)*e.calculative.fontSize*e.calculative.lineHeight)})),t.restore()}t.restore()}(t,e,i)}toPng(t=0,e){return this.canvas.toPng(t,e)}downloadPng(t,e=0){const i=document.createElement("a");i.setAttribute("download",t||"le5le.topology.png"),i.setAttribute("href",this.toPng(e));const r=document.createEvent("MouseEvents");r.initEvent("click",!0,!0),i.dispatchEvent(r)}getRect(t){return t||(t=this.store.data.pens),_t(t)}fitView(t=!0,e=10){if(!this.hasView())return;const{canvas:i}=this.canvas,{offsetWidth:r,offsetHeight:n}=i;this.resize(r,n);const o=Qe(e),s=this.getRect(),a=(r-o[1]-o[3])/s.width,c=(n-o[0]-o[2])/s.height;let l=a;l=t?a>c?c:a:a>c?a:c,this.scale(l*this.store.data.scale),this.centerView()}centerView(){if(!this.hasView())return;const t=this.getRect(),e=this.getViewCenter(),i=this.getPenRect(t);Rt(i);const{center:r}=i,{scale:n,origin:o,x:s,y:a}=this.store.data;this.translate((e.x-o.x)/n-r.x-s/n,(e.y-o.y)/n-r.y-a/n);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.length}getViewCenter(){const{width:t,height:e}=this.canvas;return{x:t/2,y:e/2}}beSameByFirst(t=this.store.data.pens,e=!1){const i=H(t),r=t[0],{width:n,height:o}=this.getPenRect(r),s={};f.forEach((t=>{s[t]=r[t]}));for(let i=1;i!t.parentId))).length<=2)return;const n=H(e),o=e.reduce(((e,i)=>e+this.getPenRect(i)[t]),0),s=(i-o)/(e.length-1);e=e.sort(((e,i)=>"width"===t?e.x-i.x:e.y-i.y));const a=this.getPenRect(e[0]);let c="width"===t?a.x:a.y;for(const i of e){const e=this.getPenRect(i);"width"===t?e.x=c:e.y=c,c+=e[t]+s,this.setValue({id:i.id,...e},r,!1)}this.render(1/0),this.pushHistory({type:N.Update,initPens:n,pens:e})}spaceBetween(t,e,i=!1){this.spaceBetweenByDirection("width",t,e,i)}spaceBetweenColumn(t,e,i=!1){this.spaceBetweenByDirection("height",t,e,i)}layout(t=this.store.data.pens,e,i=30,r=!1){const n=this.getPenRect(_t(t));!e&&(e=n.width);const o=H(t=t.filter((t=>!t.type&&!t.parentId)));let s=0;t.forEach((t=>{const e=this.getPenRect(t);e.height>s&&(s=e.height)}));let a=n.x,c=n.y;t.forEach(((o,l)=>{const h=this.getPenRect(o);if(h.x=a,h.y=c+s/2-h.height/2,this.setValue({id:o.id,...h},r,!1),l===t.length-1)return;const u=a+h.width-n.x,d=this.getPenRect(t[l+1]);Math.round(e-u)>=Math.round(d.width+i)?a+=h.width+i:(a=n.x,c+=s+i)})),this.render(1/0),this.pushHistory({type:N.Update,initPens:o,pens:t})}gotoView(t){const e=this.getViewCenter(),i=e.x-t.calculative.worldRect.x-t.calculative.worldRect.width/2,r=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,r-this.store.data.y),this.store.data.x=i,this.store.data.y=r,this.canvas.render(1/0)}showMap(){this.map||(this.map=new ri(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){e||(e=this.store.data.pens);const i=e.findIndex((e=>e.id===t.id));i>-1&&(e.push(e[i]),e.splice(i,1))}bottom(t,e){e||(e=this.store.data.pens);const i=e.findIndex((e=>e.id===t.id));i>-1&&(e.unshift(e[i]),e.splice(i+1,1))}up(t,e){e||(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))}down(t,e){e||(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))}setLayer(t,e,i){i||(i=this.store.data.pens);const r=i.findIndex((e=>e.id===t.id));r>-1&&(r>e?(i.splice(e,0,i[r]),i.splice(r+1,1)):r{const n=this.find(r.lineId);if(1===n.length)switch(e){case"all":i.push(n[0]);break;case"in":n[0].anchors[n[0].anchors.length-1].connectTo===t.id&&i.push(n[0]);break;case"out":n[0].anchors[0].connectTo===t.id&&i.push(n[0])}})),i}nextNode(t){if(t.type){const e=t.anchors[t.anchors.length-1].connectTo;return this.find(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){const e=t.anchors[0].connectTo;return this.find(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,e){if(t||(t=this.store.data.pens),1===t.length)return t[0].type=o.Node,H(t);const i=_t(t);let r={id:Ht(),name:"combine",x:i.x,y:i.y,width:i.width,height:i.height,children:[],showChild:e};const n=t.find((t=>t.width===i.width&&t.height===i.height));return n&&void 0===e?(n.children||(n.children=[]),r=n):this.canvas.makePen(r),t.forEach((t=>{if(t===r||t.parentId===r.id)return;if(t.parentId)return;r.children.push(t.id),t.parentId=r.id;const e=Ct(t.calculative.worldRect,i);t.x=e.x,t.y=e.y,t.width=e.width,t.height=e.height,t.locked=s.DisableMove})),H(t)}setVisible(t,e,i=!1){if(this.setValue({id:t.id,visible:e},i,!1),t.children)for(const r of t.children){const t=this.find(r)[0];t&&this.setVisible(t,e,i)}}destroy(t){for(const t of this.store.data.pens)t.onDestroy&&t.onDestroy(t);this.closeWebsocket(),this.closeMqtt(),O(this.store),this.store.emitter.all.clear(),this.canvas.destroy(),L[this.store.id]=void 0,L.path2dDraws={},this.canvas=void 0,t&&(L.htmlElements={})}}function si(t){t.onDestroy||(t.onDestroy=ci,t.onAdd=ai);const e=new Path2D;t.calculative.borderRadius||(t.calculative.borderRadius=0);let i=t.calculative.borderRadius,r=t.calculative.borderRadius;t.calculative.borderRadius<1&&(i=t.calculative.worldRect.width*t.calculative.borderRadius,r=t.calculative.worldRect.height*t.calculative.borderRadius);let n=i{const i=t.calculative.canvas.parent.store.data.pens.findIndex((t=>t.id===e));i>-1&&(t.calculative.canvas.parent.store.data.pens.splice(i,1),t.calculative.canvas.parent.store.pens[e]=void 0)})),t.children=void 0}function li(t){t.onDestroy||(t.onDestroy=ui,t.onAdd=hi);const e=new Path2D;t.calculative.borderRadius||(t.calculative.borderRadius=0);let i=t.calculative.borderRadius,r=t.calculative.borderRadius;t.calculative.borderRadius<1&&(i=t.calculative.worldRect.width*t.calculative.borderRadius,r=t.calculative.worldRect.height*t.calculative.borderRadius);let n=i{const i=t.calculative.canvas.parent.store.data.pens.findIndex((t=>t.id===e));i>-1&&(t.calculative.canvas.parent.store.data.pens.splice(i,1),t.calculative.canvas.parent.store.pens[e]=void 0)})),t.children=void 0}function di(){return{interfaceClass:si,simpleClass:li}}function pi(t,e){return e||(e=new Path2D),e.rect(t.calculative.worldRect.x,t.calculative.worldRect.y,t.calculative.worldRect.width,t.calculative.worldRect.height),e.closePath(),e}function fi(){return{sequenceFocus:pi}}function vi(t){const e=new Path2D;t.calculative.borderRadius||(t.calculative.borderRadius=0);const i=t.calculative.worldRect;let r=t.calculative.borderRadius,n=t.calculative.borderRadius;t.calculative.borderRadius<1&&(r=i.width*t.calculative.borderRadius,n=i.height*t.calculative.borderRadius);let o=r{t.exports=function t(e,i,r){function n(s,a){if(!i[s]){if(!e[s]){if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var l=i[s]={exports:{}};e[s][0].call(l.exports,(function(t){return n(e[s][1][t]||t)}),l,l.exports,t,e,i,r)}return i[s].exports}for(var o=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&&w(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.maximumPacketSizeo.properties.topicAliasMaximum||!o.properties.topicAliasMaximum&&i.properties.topicAlias))&&delete n.properties.topicAlias),d("publish :: qos",i.qos),i.qos){case 1:case 2:this.outgoing[n.messageId]={volatile:!1,cb:r||x},this._storeProcessing?(d("_storeProcessing enabled"),this._packetIdsDuringStoreProcessing[n.messageId]=!1,this._storePacket(n,void 0,i.cbStorePut)):(d("MqttClient:publish: packet cmd: %s",n.cmd),this._sendPacket(n,void 0,i.cbStorePut));break;default:this._storeProcessing?(d("_storeProcessing enabled"),this._storePacket(n,r,i.cbStorePut)):(d("MqttClient:publish: packet cmd: %s",n.cmd),this._sendPacket(n,r,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===p&&(e.nl=t.nl||!1,e.rap=t.rap||!1,e.rh=t.rh||0,e.properties=t.properties),l._resubscribeTopics[t.topic]=e,y.push(t.topic)}})),l.messageIdToTopic[t.messageId]=y}return this.outgoing[t.messageId]={volatile:!0,cb:function(t,e){if(!t)for(var i=e.granted,r=0;r{d("end :: finish :: calling process.nextTick on closeStores"),p(function(){d("end :: closeStores: closing incoming and outgoing stores"),r.disconnected=!0,r.incomingStore.close((function(t){r.outgoingStore.close((function(e){if(d("end :: closeStores: emitting end"),r.emit("end"),i){let r=t||e;d("end :: closeStores: invoking callback with args"),i(r)}}))})),r._deferredReconnect&&r._deferredReconnect()}.bind(r))}),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",r.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,n,10))):(d("end :: (%s) :: immediately calling finish",r.options.clientId),n()),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 o,e.outgoingStore=e.options.outgoingStore||new o,e.disconnecting=!1,e.disconnected=!1,e._deferredReconnect=null,e._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=i:i(),this},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,r=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 n=u({cmd:"disconnect"},r);d("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(n,f.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 m(this,t,e,i);default:return void w(this,t,e)}switch(t.qos){case 2:case 1:m(this,t,e,i);break;default:w(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 r=new Error("Connection refused: "+g[i]);r.code=i,this.emit("error",r)}},b.prototype._handlePublish=function(t,e){d("_handlePublish: packet %o",t),e=void 0!==e?e:x;var i=t.topic.toString(),r=t.payload,n=t.qos,o=t.messageId,s=this,a=this.options,c=[0,16,128,131,135,144,145,151,153];switch(d("_handlePublish: qos %d",n),n){case 2:a.customHandleAcks(i,r,t,(function(i,r){return i instanceof Error||(r=i,i=null),i?s.emit("error",i):-1===c.indexOf(r)?s.emit("error",new Error("Wrong reason code for pubrec")):void(r?s._sendPacket({cmd:"pubrec",messageId:o,reasonCode:r},e):s.incomingStore.put(t,(function(){s._sendPacket({cmd:"pubrec",messageId:o},e)})))}));break;case 1:a.customHandleAcks(i,r,t,(function(n,a){return n instanceof Error||(a=n,n=null),n?s.emit("error",n):-1===c.indexOf(a)?s.emit("error",new Error("Wrong reason code for puback")):(a||s.emit("message",i,r,t),void s.handleMessage(t,(function(t){if(t)return e&&e(t);s._sendPacket({cmd:"puback",messageId:o,reasonCode:a},e)})))}));break;case 0:this.emit("message",i,r,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,r=t.cmd,n=null,o=this.outgoing[i]?this.outgoing[i].cb:null,s=this;if(o){switch(d("_handleAck :: packet type",r),r){case"pubcomp":case"puback":var a=t.reasonCode;a&&a>0&&16!==a&&((e=new Error("Publish error: "+g[a])).code=a,o(e,t)),delete this.outgoing[i],this.outgoingStore.del(t,o);break;case"pubrec":n={cmd:"pubrel",qos:2,messageId:i};var c=t.reasonCode;c&&c>0&&16!==c?((e=new Error("Publish error: "+g[c])).code=c,o(e,t)):this._sendPacket(n);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;ir&&setTimeout(t,o,e,i,s),l&&"string"==typeof e&&(e=n.from(e,"utf8"));try{h.send(e)}catch(t){return s(t)}s()}));e.objectMode||(p._writev=m),p.on("close",(()=>{h.close()}));const f=void 0!==h.addEventListener;function v(){i.setReadable(p),i.setWritable(p),i.emit("connect")}function y(){i.end(),i.destroy()}function g(t){i.destroy(t)}function w(t){let e=t.data;e=e instanceof ArrayBuffer?n.from(e):n.from(e,"utf8"),p.push(e)}function m(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 r,n,o,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",r=i+"://"+t.hostname+t.path;return t.port&&80!==t.port&&443!==t.port&&(r=i+"://"+t.hostname+":"+t.port+t.path),"function"==typeof t.transformWsUrl&&(r=t.transformWsUrl(r,t,e)),r}(e,t);r=wx.connectSocket({url:l,protocols:[c]}),n=function(){var t=new s;return t._write=function(t,e,i){r.send({data:t.buffer,success:function(){i()},fail:function(t){i(new Error(t))}})},t._flush=function(t){r.close({success:function(){t()}})},t}(),(o=a.obj())._destroy=function(t,e){r.close({success:function(){e&&e(t)}})};var h=o.destroy;return o.destroy=function(){o.destroy=h;var t=this;setTimeout((function(){r.close({fail:function(){t._destroy(new Error)}})}),0)}.bind(o),r.onOpen((function(){o.setReadable(n),o.setWritable(n),o.emit("connect")})),r.onMessage((function(t){var e=t.data;e=e instanceof ArrayBuffer?i.from(e):i.from(e,"utf8"),n.push(e)})),r.onClose((function(){o.end(),o.destroy()})),r.onError((function(t){o.destroy(new Error(t.errMsg))})),o}}).call(this)}).call(this,t("buffer").Buffer)},{buffer:14,duplexify:17,"readable-stream":51}],7:[function(t,e,i){"use strict";var r=t("xtend"),n=t("readable-stream").Readable,o={objectMode:!0},s={clean:!0};function a(t){if(!(this instanceof a))return new a(t);this.options=t||{},this.options=r(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 n(o),e=!1,i=[],r=0;return this._inflights.forEach((function(t,e){i.push(t)})),t._read=function(){!e&&r0?s-4:s;for(i=0;i>16&255,c[h++]=e>>8&255,c[h++]=255&e;return 2===a&&(e=n[t.charCodeAt(i)]<<2|n[t.charCodeAt(i+1)]>>4,c[h++]=255&e),1===a&&(e=n[t.charCodeAt(i)]<<10|n[t.charCodeAt(i+1)]<<4|n[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,n=i%3,o=[],s=0,a=i-n;sa?a:s+16383));return 1===n?(e=t[i-1],o.push(r[e>>2]+r[e<<4&63]+"==")):2===n&&(e=(t[i-2]<<8)+t[i-1],o.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),o.join("")};for(var r=[],n=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=s.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function h(t,e,i){for(var n,o,s=[],a=e;a>18&63]+r[o>>12&63]+r[o>>6&63]+r[63&o]);return s.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},{}],11:[function(t,e,i){"use strict";const{Buffer:r}=t("buffer"),n=Symbol.for("BufferList");function o(t){if(!(this instanceof o))return new o(t);o._init.call(this,t)}o._init=function(t){Object.defineProperty(this,n,{value:!0}),this._bufs=[],this.length=0,t&&this.append(t)},o.prototype._new=function(t){return new o(t)},o.prototype._offset=function(t){if(0===t)return[0,0];let e=0;for(let i=0;ithis.length||t<0)return;const e=this._offset(t);return this._bufs[e[0]][e[1]]},o.prototype.slice=function(t,e){return"number"==typeof t&&t<0&&(t+=this.length),"number"==typeof e&&e<0&&(e+=this.length),this.copy(null,0,t,e)},o.prototype.copy=function(t,e,i,n){if(("number"!=typeof i||i<0)&&(i=0),("number"!=typeof n||n>this.length)&&(n=this.length),i>=this.length)return t||r.alloc(0);if(n<=0)return t||r.alloc(0);const o=!!t,s=this._offset(i),a=n-i;let c=a,l=o&&e||0,h=s[1];if(0===i&&n===this.length){if(!o)return 1===this._bufs.length?this._bufs[0]:r.concat(this._bufs,this.length);for(let e=0;ei)){this._bufs[e].copy(t,l,h,h+c),l+=i;break}this._bufs[e].copy(t,l,h),l+=i,c-=i,h&&(h=0)}return t.length>l?t.slice(0,l):t},o.prototype.shallowSlice=function(t,e){if(t=t||0,e="number"!=typeof e?this.length:e,t<0&&(t+=this.length),e<0&&(e+=this.length),t===e)return this._new();const i=this._offset(t),r=this._offset(e),n=this._bufs.slice(i[0],r[0]+1);return 0===r[1]?n.pop():n[n.length-1]=n[n.length-1].slice(0,r[1]),0!==i[1]&&(n[0]=n[0].slice(i[1])),this._new(n)},o.prototype.toString=function(t,e,i){return this.slice(e,i).toString(t)},o.prototype.consume=function(t){if(t=Math.trunc(t),Number.isNaN(t)||t<=0)return this;for(;this._bufs.length;){if(!(t>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(t),this.length-=t;break}t-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},o.prototype.duplicate=function(){const t=this._new();for(let e=0;ethis.length?this.length:e;const n=this._offset(e);let o=n[0],s=n[1];for(;o=t.length){const i=e.indexOf(t,s);if(-1!==i)return this._reverseOffset([o,i]);s=e.length-t.length+1}else{const e=this._reverseOffset([o,s]);if(this._match(e,t))return e;s++}s=0}return-1},o.prototype._match=function(t,e){if(this.length-tn)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),r=o(i),n=r.write(t,e);return n!==i&&(r=r.slice(0,n)),r}(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(j(t,ArrayBuffer)||t&&j(t.buffer,ArrayBuffer))return function(t,e,i){if(e<0||t.byteLength=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return 0|t}function d(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||j(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,r=arguments.length>2&&!0===arguments[2];if(!r&&0===i)return 0;for(var n=!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 B(t).length;default:if(n)return r?-1:O(t).length;e=(""+e).toLowerCase(),n=!0}}function p(t,e,i){var r=t[e];t[e]=t[i],t[i]=r}function f(t,e,i,r,n){if(0===t.length)return-1;if("string"==typeof i?(r=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),F(i=+i)&&(i=n?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(n)return-1;i=t.length-1}else if(i<0){if(!n)return-1;i=0}if("string"==typeof e&&(e=s.from(e,r)),s.isBuffer(e))return 0===e.length?-1:v(t,e,i,r,n);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?n?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):v(t,[e],i,r,n);throw new TypeError("val must be string, number or Buffer")}function v(t,e,i,r,n){var o,s=1,a=t.length,c=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){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(n){var h=-1;for(o=i;oa&&(i=a-c),o=i;o>=0;o--){for(var u=!0,d=0;dn&&(r=n):r=n;var o=e.length;r>o/2&&(r=o/2);for(var s=0;s>8,n=i%256,o.push(n),o.push(r);return o}(e,t.length-i),t,i,r)}function R(t,i,r){return 0===i&&r===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(i,r))}function _(t,e,i){i=Math.min(t.length,i);for(var r=[],n=e;n239?4:l>223?3:l>191?2:1;if(n+u<=i)switch(u){case 1:l<128&&(h=l);break;case 2:128==(192&(o=t[n+1]))&&(c=(31&l)<<6|63&o)>127&&(h=c);break;case 3:o=t[n+1],s=t[n+2],128==(192&o)&&128==(192&s)&&(c=(15&l)<<12|(63&o)<<6|63&s)>2047&&(c<55296||c>57343)&&(h=c);break;case 4:o=t[n+1],s=t[n+2],a=t[n+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(c=(15&l)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&c<1114112&&(h=c)}null===h?(h=65533,u=1):h>65535&&(h-=65536,r.push(h>>>10&1023|55296),h=56320|1023&h),r.push(h),n+=u}return function(t){var e=t.length;if(e<=k)return String.fromCharCode.apply(String,t);for(var i="",r=0;rthis.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 E(this,e,i);case"utf8":case"utf-8":return _(this,e,i);case"ascii":return A(this,e,i);case"latin1":case"binary":return S(this,e,i);case"base64":return R(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,e,i);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!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,r,n){if(j(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===r&&(r=0),void 0===n&&(n=this.length),e<0||i>t.length||r<0||n>this.length)throw new RangeError("out of range index");if(r>=n&&e>=i)return 0;if(r>=n)return-1;if(e>=i)return 1;if(this===t)return 0;for(var o=(n>>>=0)-(r>>>=0),a=(i>>>=0)-(e>>>=0),c=Math.min(o,a),l=this.slice(r,n),h=t.slice(e,i),u=0;u>>=0,isFinite(i)?(i>>>=0,void 0===r&&(r="utf8")):(r=i,i=void 0)}var n=this.length-e;if((void 0===i||i>n)&&(i=n),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return y(this,t,e,i);case"utf8":case"utf-8":return g(this,t,e,i);case"ascii":return w(this,t,e,i);case"latin1":case"binary":return m(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(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var k=4096;function A(t,e,i){var r="";i=Math.min(t.length,i);for(var n=e;nr)&&(i=r);for(var n="",o=e;oi)throw new RangeError("Trying to access beyond buffer length")}function P(t,e,i,r,n,o){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>n||et.length)throw new RangeError("Index out of range")}function C(t,e,i,r,n,o){if(i+r>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function L(t,e,i,n,o){return e=+e,i>>>=0,o||C(t,0,i,4),r.write(t,e,i,n,23,4),i+4}function M(t,e,i,n,o){return e=+e,i>>>=0,o||C(t,0,i,8),r.write(t,e,i,n,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 r=this[t],n=1,o=0;++o>>=0,e>>>=0,i||I(t,e,this.length);for(var r=this[t+--e],n=1;e>0&&(n*=256);)r+=this[t+--e]*n;return r},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 r=this[t],n=1,o=0;++o=(n*=128)&&(r-=Math.pow(2,8*e)),r},s.prototype.readIntBE=function(t,e,i){t>>>=0,e>>>=0,i||I(t,e,this.length);for(var r=e,n=1,o=this[t+--r];r>0&&(n*=256);)o+=this[t+--r]*n;return o>=(n*=128)&&(o-=Math.pow(2,8*e)),o},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),r.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||I(t,4,this.length),r.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||I(t,8,this.length),r.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||I(t,8,this.length),r.read(this,t,!1,52,8)},s.prototype.writeUIntLE=function(t,e,i,r){t=+t,e>>>=0,i>>>=0,r||P(this,t,e,i,Math.pow(2,8*i)-1,0);var n=1,o=0;for(this[e]=255&t;++o>>=0,i>>>=0,r||P(this,t,e,i,Math.pow(2,8*i)-1,0);var n=i-1,o=1;for(this[e+n]=255&t;--n>=0&&(o*=256);)this[e+n]=t/o&255;return e+i},s.prototype.writeUInt8=function(t,e,i){return t=+t,e>>>=0,i||P(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||P(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||P(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||P(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||P(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,r){if(t=+t,e>>>=0,!r){var n=Math.pow(2,8*i-1);P(this,t,e,i,n-1,-n)}var o=0,s=1,a=0;for(this[e]=255&t;++o>0)-a&255;return e+i},s.prototype.writeIntBE=function(t,e,i,r){if(t=+t,e>>>=0,!r){var n=Math.pow(2,8*i-1);P(this,t,e,i,n-1,-n)}var o=i-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+i},s.prototype.writeInt8=function(t,e,i){return t=+t,e>>>=0,i||P(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||P(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||P(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||P(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||P(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,r){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(i||(i=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r=this.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e=0;--o)t[o+e]=this[o+i];else Uint8Array.prototype.set.call(t,this.subarray(i,r),e);return n},s.prototype.fill=function(t,e,i,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,i=this.length):"string"==typeof i&&(r=i,i=this.length),void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!s.isEncoding(r))throw new TypeError("Unknown encoding: "+r);if(1===t.length){var n=t.charCodeAt(0);("utf8"===r&&n<128||"latin1"===r)&&(t=n)}}else"number"==typeof t&&(t&=255);if(e<0||this.length>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(o=e;o55295&&i<57344){if(!n){if(i>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&o.push(239,191,189);continue}n=i;continue}if(i<56320){(e-=3)>-1&&o.push(239,191,189),n=i;continue}i=65536+(n-55296<<10|i-56320)}else n&&(e-=3)>-1&&o.push(239,191,189);if(n=null,i<128){if((e-=1)<0)break;o.push(i)}else if(i<2048){if((e-=2)<0)break;o.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;o.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return o}function B(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,r){for(var n=0;n=e.length||n>=t.length);++n)e[n+i]=t[n];return n}function j(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function F(t){return t!=t}}).call(this)}).call(this,t("buffer").Buffer)},{"base64-js":10,buffer:14,ieee754:20}],15:[function(t,e,i){(function(r){(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 r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,(t=>{"%%"!==t&&"%c"===t&&(n=++r)})),t.splice(n,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!==r&&"env"in r&&(t=r.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:n}=e.exports;n.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,n=null;function o(...t){if(!o.enabled)return;const r=o,n=Number(new Date),s=n-(e||n);r.diff=s,r.prev=e,r.curr=n,e=n,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,n)=>{if("%%"===e)return"%";a++;const o=i.formatters[n];if("function"==typeof o){const i=t[a];e=o.call(r,i),t.splice(a,1),a--}return e})),i.formatArgs.call(r,t),(r.log||i.log).apply(r,t)}return o.namespace=t,o.useColors=i.useColors(),o.color=i.selectColor(t),o.extend=r,o.destroy=i.destroy,Object.defineProperty(o,"enabled",{enumerable:!0,configurable:!1,get:()=>null===n?i.enabled(t):n,set:t=>{n=t}}),"function"==typeof i.init&&i.init(o),o}function r(t,e){const r=i(this.namespace+(void 0===e?":":e)+t);return r.log=this.log,r}function n(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(n),...i.skips.map(n).map((t=>"-"+t))].join(",");return i.enable(""),t},i.enable=function(t){let e;i.save(t),i.names=[],i.skips=[];const r=("string"==typeof t?t:"").split(/[\s,]+/),n=r.length;for(e=0;e{i[t]=e[t]})),i.names=[],i.skips=[],i.formatters={},i.selectColor=function(t){let e=0;for(let i=0;i0&&a.length>o){a.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+a.length+' "'+String(e)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=a.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",c.name,c.message)}}else a=s[e]=i,++t._eventsCount;return t}function d(){if(!this.fired)switch(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:for(var t=new Array(arguments.length),e=0;e1&&(e=arguments[1]),e instanceof Error)throw e;var c=new Error('Unhandled "error" event. ('+e+")");throw c.context=e,c}if(!(i=s[t]))return!1;var l="function"==typeof i;switch(r=arguments.length){case 1:!function(t,e,i){if(e)t.call(i);else for(var r=t.length,n=y(t,r),o=0;o=0;s--)if(i[s]===e||i[s].listener===e){a=i[s].listener,o=s;break}if(o<0)return this;0===o?i.shift():function(t,e){for(var i=e,r=i+1,n=t.length;r=0;o--)this.removeListener(t,e[o]);return this},s.prototype.listeners=function(t){return f(this,t,!0)},s.prototype.rawListeners=function(t){return f(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,r,n){var o,s,a=8*n-r-1,c=(1<>1,h=-7,u=i?n-1:0,d=i?-1:1,p=t[e+u];for(u+=d,o=p&(1<<-h)-1,p>>=-h,h+=a;h>0;o=256*o+t[e+u],u+=d,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=r;h>0;s=256*s+t[e+u],u+=d,h-=8);if(0===o)o=1-l;else{if(o===c)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,r),o-=l}return(p?-1:1)*s*Math.pow(2,o-r)},i.write=function(t,e,i,r,n,o){var s,a,c,l=8*o-n-1,h=(1<>1,d=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:o-1,f=r?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,n),s+=u):(a=e*Math.pow(2,u-1)*Math.pow(2,n),s=0));n>=8;t[i+p]=255&a,p+=f,a/=256,n-=8);for(s=s<0;t[i+p]=255&s,p+=f,s/=256,l-=8);t[i+p-f]|=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((n=>[0,1].map((o=>{const s=t.alloc(1);return s.writeUInt8(i.codes[e]<t.from([e]))),i.EMPTY={pingreq:t.from([i.codes.pingreq<<4,0]),pingresp:t.from([i.codes.pingresp<<4,0]),disconnect:t.from([i.codes.disconnect<<4,0])}}).call(this)}).call(this,t("buffer").Buffer)},{buffer:14}],23:[function(t,e,i){(function(i){(function(){const r=t("./writeToStream"),n=t("events");class o extends n{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),r=this._array;let n,o=0;for(n=0;n>8,0),i.writeUInt8(255&e,1),i}e.exports={cache:i,generateCache:function(){for(let t=0;t<65536;t++)i[t]=n(t)},generateNumber:n,genBufVariableByteInt:function(e){let i=0,n=0;const o=t.allocUnsafe(4);do{i=e%128|0,(e=e/128|0)>0&&(i|=128),o.writeUInt8(i,n++)}while(e>0&&n<4);return e>0&&(n=0),r?o.subarray(0,n):o.slice(0,n)},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 r=t("bl"),n=t("events"),o=t("./packet"),s=t("./constants"),a=t("debug")("mqtt-packet:parser");class c extends n{constructor(){super(),this.parser=this.constructor.parser}static parser(t){return this instanceof c?(this.settings=t||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):(new c).parser(t)}_resetState(){a("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new o,this.error=null,this._list=r(),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,r;a("_parseConnect");const n={},o=this.packet,c=this._parseString();if(null===c)return this._emitError(new Error("Cannot parse protocolId"));if("MQTT"!==c&&"MQIsdp"!==c)return this._emitError(new Error("Invalid protocolId"));if(o.protocolId=c,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(o.protocolVersion=this._list.readUInt8(this._pos),o.protocolVersion>=128&&(o.bridgeMode=!0,o.protocolVersion=o.protocolVersion-128),3!==o.protocolVersion&&4!==o.protocolVersion&&5!==o.protocolVersion)return this._emitError(new Error("Invalid protocol version"));if(this._pos++,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(n.username=this._list.readUInt8(this._pos)&s.USERNAME_MASK,n.password=this._list.readUInt8(this._pos)&s.PASSWORD_MASK,n.will=this._list.readUInt8(this._pos)&s.WILL_FLAG_MASK,n.will&&(o.will={},o.will.retain=0!=(this._list.readUInt8(this._pos)&s.WILL_RETAIN_MASK),o.will.qos=(this._list.readUInt8(this._pos)&s.WILL_QOS_MASK)>>s.WILL_QOS_SHIFT),o.clean=0!=(this._list.readUInt8(this._pos)&s.CLEAN_SESSION_MASK),this._pos++,o.keepalive=this._parseNum(),-1===o.keepalive)return this._emitError(new Error("Packet too short"));if(5===o.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(o.properties=t)}const l=this._parseString();if(null===l)return this._emitError(new Error("Packet too short"));if(o.clientId=l,a("_parseConnect: packet.clientId: %s",o.clientId),n.will){if(5===o.protocolVersion){const t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(o.will.properties=t)}if(null===(t=this._parseString()))return this._emitError(new Error("Cannot parse will topic"));if(o.will.topic=t,a("_parseConnect: packet.will.topic: %s",o.will.topic),null===(e=this._parseBuffer()))return this._emitError(new Error("Cannot parse will payload"));o.will.payload=e,a("_parseConnect: packet.will.paylaod: %s",o.will.payload)}if(n.username){if(null===(r=this._parseString()))return this._emitError(new Error("Cannot parse username"));o.username=r,a("_parseConnect: packet.username: %s",o.username)}if(n.password){if(null===(i=this._parseBuffer()))return this._emitError(new Error("Cannot parse password"));o.password=i}return this.settings=o,a("_parseConnect: complete"),o}_parseConnack(){a("_parseConnack");const t=this.packet;if(this._list.length<1)return null;if(t.sessionPresent=!!(this._list.readUInt8(this._pos++)&s.SESSIONPRESENT_MASK),5===this.settings.protocolVersion)this._list.length>=2?t.reasonCode=this._list.readUInt8(this._pos++):t.reasonCode=0;else{if(this._list.length<2)return null;t.returnCode=this._list.readUInt8(this._pos++)}if(-1===t.returnCode||-1===t.reasonCode)return this._emitError(new Error("Cannot parse return code"));if(5===this.settings.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}a("_parseConnack: complete")}_parsePublish(){a("_parsePublish");const t=this.packet;if(t.topic=this._parseString(),null===t.topic)return this._emitError(new Error("Cannot parse topic"));if(!(t.qos>0)||this._parseMessageId()){if(5===this.settings.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}t.payload=this._list.slice(this._pos,t.length),a("_parsePublish: payload from buffer list: %o",t.payload)}}_parseSubscribe(){a("_parseSubscribe");const t=this.packet;let e,i,r,n,o,c,l;if(1!==t.qos)return this._emitError(new Error("Wrong subscribe header"));if(t.subscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){const e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(t.properties=e)}for(;this._pos=t.length)return this._emitError(new Error("Malformed Subscribe Payload"));r=(i=this._parseByte())&s.SUBSCRIBE_OPTIONS_QOS_MASK,c=0!=(i>>s.SUBSCRIBE_OPTIONS_NL_SHIFT&s.SUBSCRIBE_OPTIONS_NL_MASK),o=0!=(i>>s.SUBSCRIBE_OPTIONS_RAP_SHIFT&s.SUBSCRIBE_OPTIONS_RAP_MASK),n=i>>s.SUBSCRIBE_OPTIONS_RH_SHIFT&s.SUBSCRIBE_OPTIONS_RH_MASK,l={topic:e,qos:r},5===this.settings.protocolVersion?(l.nl=c,l.rap=o,l.rh=n):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 r=this._list.toString("utf8",this._pos,i);return this._pos+=e,a("_parseString: result: %s",r),r}_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,r=1,n=0,o=!1;const c=this._pos?this._pos:0;for(;i<4&&c+i=i&&this._emitError(new Error("Invalid variable byte integer")),c&&(this._pos+=i),a("_parseVarByteNum: result: %o",o=!!o&&(t?{bytes:i,value:n}:n)),o}_parseByte(){let t;return this._pos=4)&&(u||l))y+=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(y+=2,y+=1,5===a){var g=A(e,v);if(!g)return!1;y+=g.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(y+=i.byteLength(c.topic)+2,y+=2,c.payload){if(!(c.payload.length>=0))return e.emit("error",new Error("Invalid will payload")),!1;"string"==typeof c.payload?y+=i.byteLength(c.payload):y+=c.payload.length}var w={};if(5===a){if(!(w=A(e,c.properties)))return!1;y+=w.length}}let b=!1;if(null!=d){if(!P(d))return e.emit("error",new Error("Invalid username")),!1;b=!0,y+=i.byteLength(d)+2}if(null!=p){if(!b)return e.emit("error",new Error("Username is required to use password")),!1;if(!P(p))return e.emit("error",new Error("Invalid password")),!1;y+=I(p)+2}e.write(r.CONNECT_HEADER),m(e,y),k(e,s),o.bridgeMode&&(a+=128),e.write(131===a?r.VERSION131:132===a?r.VERSION132:4===a?r.VERSION4:5===a?r.VERSION5:r.VERSION3);let R=0;return R|=null!=d?r.USERNAME_MASK:0,R|=null!=p?r.PASSWORD_MASK:0,R|=c&&c.retain?r.WILL_RETAIN_MASK:0,R|=c&&c.qos?c.qos<0&&f(e,p),null!=g&&g.write(),c("publish: payload: %o",d),e.write(d)}(t,e,s);case"puback":case"pubrec":case"pubrel":case"pubcomp":return function(t,e,n){const o=n?n.protocolVersion:4,s=t||{},a=s.cmd||"puback",c=s.messageId,l=s.dup&&"pubrel"===a?r.DUP_MASK:0;let h=0;const u=s.reasonCode,d=s.properties;let p=5===o?3:2;if("pubrel"===a&&(h=1),"number"!=typeof c)return e.emit("error",new Error("Invalid messageId")),!1;let v=null;if(5===o&&"object"==typeof d){if(!(v=S(e,d,n,p)))return!1;p+=v.length}return e.write(r.ACKS[a][h][l][0]),m(e,p),f(e,c),5===o&&e.write(i.from([u])),null!==v&&v.write(),!0}(t,e,s);case"subscribe":return function(t,e,n){c("subscribe: packet: ");const o=n?n.protocolVersion:4,s=t||{},a=s.dup?r.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 p=null;if(5===o){if(!(p=A(e,u)))return!1;d+=p.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(r)+2+1}c("subscribe: writing to stream: %o",r.SUBSCRIBE_HEADER),e.write(r.SUBSCRIBE_HEADER[1][a?1:0][0]),m(e,d),f(e,l),null!==p&&p.write();let v=!0;for(const t of h){const n=t.topic,s=t.qos,a=+t.nl,c=+t.rap,l=t.rh;let h;x(e,n),h=r.SUBSCRIBE_OPTIONS_QOS[s],5===o&&(h|=a?r.SUBSCRIBE_OPTIONS_NL:0,h|=c?r.SUBSCRIBE_OPTIONS_RAP:0,h|=l?r.SUBSCRIBE_OPTIONS_RH[l]:0),v=e.write(i.from([h]))}return v}(t,e,s);case"suback":return function(t,e,n){const o=n?n.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;tf===R,set(t){t?(l&&0!==Object.keys(l).length||(v=!0),f=R):(v=!1,f=_)}});const w={};function m(t,e){if(e>r.VARBYTEINT_MAX)return t.emit("error",new Error(`Invalid variable byte integer: ${e}`)),!1;let i=w[e];return i||(i=d(e),e<16384&&(w[e]=i)),c("writeVarByteInt: writing to stream: %o",i),t.write(i)}function x(t,e){const r=i.byteLength(e);return f(t,r),c("writeString: %s",e),t.write(e,"utf8")}function b(t,e,i){x(t,e),x(t,i)}function R(t,e){return c("writeNumberCached: number: %d",e),c("writeNumberCached: %o",l[e]),t.write(l[e])}function _(t,e){const i=h(e);return c("writeNumberGenerated: %o",i),t.write(i)}function k(t,e){"string"==typeof e?x(t,e):e?(f(t,e.length),t.write(e)):f(t,0)}function A(t,e){if("object"!=typeof e||null!=e.length)return{length:1,write(){T(t,{},0)}};let n=0;function o(e,n){let o=0;switch(r.propertiesTypes[e]){case"byte":if("boolean"!=typeof n)return t.emit("error",new Error(`Invalid ${e}: ${n}`)),!1;o+=2;break;case"int8":if("number"!=typeof n||n<0||n>255)return t.emit("error",new Error(`Invalid ${e}: ${n}`)),!1;o+=2;break;case"binary":if(n&&null===n)return t.emit("error",new Error(`Invalid ${e}: ${n}`)),!1;o+=1+i.byteLength(n)+2;break;case"int16":if("number"!=typeof n||n<0||n>65535)return t.emit("error",new Error(`Invalid ${e}: ${n}`)),!1;o+=3;break;case"int32":if("number"!=typeof n||n<0||n>4294967295)return t.emit("error",new Error(`Invalid ${e}: ${n}`)),!1;o+=5;break;case"var":if("number"!=typeof n||n<0||n>268435455)return t.emit("error",new Error(`Invalid ${e}: ${n}`)),!1;o+=1+i.byteLength(d(n));break;case"string":if("string"!=typeof n)return t.emit("error",new Error(`Invalid ${e}: ${n}`)),!1;o+=3+i.byteLength(n.toString());break;case"pair":if("object"!=typeof n)return t.emit("error",new Error(`Invalid ${e}: ${n}`)),!1;o+=Object.getOwnPropertyNames(n).reduce(((t,e)=>{const r=n[e];return Array.isArray(r)?t+=r.reduce(((t,r)=>t+(3+i.byteLength(e.toString())+2+i.byteLength(r.toString()))),0):t+=3+i.byteLength(e.toString())+2+i.byteLength(n[e].toString()),t}),0);break;default:return t.emit("error",new Error(`Invalid property ${e}: ${n}`)),!1}return o}if(e)for(const t in e){let i=0,r=0;const s=e[t];if(Array.isArray(s))for(let e=0;eo;){const i=n.shift();if(!i||!e[i])return!1;delete e[i],s=A(t,e)}return s}function E(t,e,n){switch(r.propertiesTypes[e]){case"byte":t.write(i.from([r.properties[e]])),t.write(i.from([+n]));break;case"int8":t.write(i.from([r.properties[e]])),t.write(i.from([n]));break;case"binary":t.write(i.from([r.properties[e]])),k(t,n);break;case"int16":t.write(i.from([r.properties[e]])),f(t,n);break;case"int32":t.write(i.from([r.properties[e]])),function(t,e){const i=p(e);c("write4ByteNumber: %o",i),t.write(i)}(t,n);break;case"var":t.write(i.from([r.properties[e]])),m(t,n);break;case"string":t.write(i.from([r.properties[e]])),x(t,n);break;case"pair":Object.getOwnPropertyNames(n).forEach((o=>{const s=n[o];Array.isArray(s)?s.forEach((n=>{t.write(i.from([r.properties[e]])),b(t,o.toString(),n.toString())})):(t.write(i.from([r.properties[e]])),b(t,o.toString(),s.toString()))}));break;default:return t.emit("error",new Error(`Invalid property ${e} value: ${n}`)),!1}}function T(t,e,i){m(t,i);for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)&&null!==e[i]){const r=e[i];if(Array.isArray(r))for(let e=0;e=1.5*i;return Math.round(t/i)+" "+r+(n?"s":"")}e.exports=function(t,e){e=e||{};var i=typeof t;if("string"===i&&t.length>0)return function(t){if(!((t=String(t)).length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(e){var i=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*i;case"weeks":case"week":case"w":return 6048e5*i;case"days":case"day":case"d":return i*s;case"hours":case"hour":case"hrs":case"hr":case"h":return i*o;case"minutes":case"minute":case"mins":case"min":case"m":return i*n;case"seconds":case"second":case"secs":case"sec":case"s":return i*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:return}}}}(t);if("number"===i&&isFinite(t))return e.long?function(t){var e=Math.abs(t);return e>=s?a(t,e,s,"day"):e>=o?a(t,e,o,"hour"):e>=n?a(t,e,n,"minute"):e>=r?a(t,e,r,"second"):t+" ms"}(t):function(t){var e=Math.abs(t);return e>=s?Math.round(t/s)+"d":e>=o?Math.round(t/o)+"h":e>=n?Math.round(t/n)+"m":e>=r?Math.round(t/r)+"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 r=t("wrappy");function n(t){var e=function(){return e.called?e.value:(e.called=!0,e.value=t.apply(this,arguments))};return e.called=!1,e}function o(t){var e=function(){if(e.called)throw new Error(e.onceError);return e.called=!0,e.value=t.apply(this,arguments)},i=t.name||"Function wrapped with `once`";return e.onceError=i+" shouldn't be called more than once",e.called=!1,e}e.exports=r(n),e.exports.strict=r(o),n.proto=n((function(){Object.defineProperty(Function.prototype,"once",{value:function(){return n(this)},configurable:!0}),Object.defineProperty(Function.prototype,"onceStrict",{value:function(){return o(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,r,n){if("function"!=typeof e)throw new TypeError('"callback" argument must be a function');var o,s,a=arguments.length;switch(a){case 0:case 1:return t.nextTick(e);case 2:return t.nextTick((function(){e.call(null,i)}));case 3:return t.nextTick((function(){e.call(null,i,r)}));case 4:return t.nextTick((function(){e.call(null,i,r,n)}));default:for(o=new Array(a-1),s=0;s1)for(var i=1;i= 0x80 (not a basic code point)","invalid-input":"Invalid input"},v=Math.floor,y=String.fromCharCode;function g(t){throw new RangeError(f[t])}function w(t,e){for(var i=t.length,r=[];i--;)r[i]=e(t[i]);return r}function m(t,e){var i=t.split("@"),r="";return i.length>1&&(r=i[0]+"@",t=i[1]),r+w((t=t.replace(p,".")).split("."),e).join(".")}function x(t){for(var e,i,r=[],n=0,o=t.length;n=55296&&e<=56319&&n65535&&(e+=y((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+y(t)})).join("")}function R(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function _(t,e,i){var r=0;for(t=i?v(t/700):t>>1,t+=v(t/e);t>455;r+=h)t=v(t/35);return v(r+36*t/(t+38))}function k(t){var e,i,r,n,o,s,a,c,u,d,p,f=[],y=t.length,w=0,m=128,x=72;for((i=t.lastIndexOf("-"))<0&&(i=0),r=0;r=128&&g("not-basic"),f.push(t.charCodeAt(r));for(n=i>0?i+1:0;n=y&&g("invalid-input"),((c=(p=t.charCodeAt(n++))-48<10?p-22:p-65<26?p-65:p-97<26?p-97:h)>=h||c>v((l-w)/s))&&g("overflow"),w+=c*s,!(c<(u=a<=x?1:a>=x+26?26:a-x));a+=h)s>v(l/(d=h-u))&&g("overflow"),s*=d;x=_(w-o,e=f.length+1,0==o),v(w/e)>l-m&&g("overflow"),m+=v(w/e),w%=e,f.splice(w++,0,m)}return b(f)}function A(t){var e,i,r,n,o,s,a,c,u,d,p,f,w,m,b,k=[];for(f=(t=x(t)).length,e=128,i=0,o=72,s=0;s=e&&pv((l-i)/(w=r+1))&&g("overflow"),i+=(a-e)*w,e=a,s=0;sl&&g("overflow"),p==e){for(c=i,u=h;!(c<(d=u<=o?1:u>=o+26?26:u-o));u+=h)b=c-d,m=h-d,k.push(y(R(d+b%m,0))),c=v(b/m);k.push(y(R(c,0))),o=_(i,w,r==n),i=0,++r}++i,++e}return k.join("")}if(a={version:"1.4.1",ucs2:{decode:x,encode:b},decode:k,encode:A,toASCII:function(t){return m(t,(function(t){return d.test(t)?"xn--"+A(t):t}))},toUnicode:function(t){return m(t,(function(t){return u.test(t)?k(t.slice(4).toLowerCase()):t}))}},n&&o)if(e.exports==n)o.exports=a;else for(c in a)a.hasOwnProperty(c)&&(n[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 r(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.exports=function(t,e,i,o){e=e||"&",i=i||"=";var s={};if("string"!=typeof t||0===t.length)return s;var a=/\+/g;t=t.split(e);var c=1e3;o&&"number"==typeof o.maxKeys&&(c=o.maxKeys);var l=t.length;c>0&&l>c&&(l=c);for(var h=0;h=0?(u=v.substr(0,y),d=v.substr(y+1)):(u=v,d=""),p=decodeURIComponent(u),f=decodeURIComponent(d),r(s,p)?n(s[p])?s[p].push(f):s[p]=[s[p],f]:s[p]=f}return s};var n=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},{}],35:[function(t,e,i){"use strict";var r=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};e.exports=function(t,e,i,a){return e=e||"&",i=i||"=",null===t&&(t=void 0),"object"==typeof t?o(s(t),(function(s){var a=encodeURIComponent(r(s))+i;return n(t[s])?o(t[s],(function(t){return a+encodeURIComponent(r(t))})).join(e):a+encodeURIComponent(r(t[s]))})).join(e):a?encodeURIComponent(r(a))+i+encodeURIComponent(r(t)):""};var n=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function o(t,e){if(t.map)return t.map(e);for(var i=[],r=0;r2?"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))}n("ERR_INVALID_OPT_VALUE",(function(t,e){return'The value "'+e+'" is invalid for option "'+t+'"'}),TypeError),n("ERR_INVALID_ARG_TYPE",(function(t,e,i){var r,n,s;if("string"==typeof e&&(n="not ",e.substr(0,n.length)===n)?(r="must not be",e=e.replace(/^not /,"")):r="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(r," ").concat(o(e,"type"));else{var a=function(t,e,i){return"number"!=typeof i&&(i=0),!(i+".".length>t.length)&&-1!==t.indexOf(".",i)}(t)?"property":"argument";s='The "'.concat(t,'" ').concat(a," ").concat(r," ").concat(o(e,"type"))}return s+". Received type ".concat(typeof i)}),TypeError),n("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),n("ERR_METHOD_NOT_IMPLEMENTED",(function(t){return"The "+t+" method is not implemented"})),n("ERR_STREAM_PREMATURE_CLOSE","Premature close"),n("ERR_STREAM_DESTROYED",(function(t){return"Cannot call "+t+" after a stream was destroyed"})),n("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),n("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),n("ERR_STREAM_WRITE_AFTER_END","write after end"),n("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),n("ERR_UNKNOWN_ENCODING",(function(t){return"Unknown encoding: "+t}),TypeError),n("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),e.exports.codes=r},{}],38:[function(t,e,i){(function(i){(function(){"use strict";var r=Object.keys||function(t){var e=[];for(var i in t)e.push(i);return e};e.exports=l;var n=t("./_stream_readable"),o=t("./_stream_writable");t("inherits")(l,n);for(var s=r(o.prototype),a=0;a0)if("string"==typeof e||a.objectMode||Object.getPrototypeOf(e)===c.prototype||(e=function(t){return c.from(t)}(e)),r)a.endEmitted?R(t,new b):E(t,a,e,!0);else if(a.ended)R(t,new m);else{if(a.destroyed)return!1;a.reading=!1,a.decoder&&!i?(e=a.decoder.write(e),a.objectMode||0!==e.length?E(t,a,e,!1):L(t,a)):E(t,a,e,!1)}else r||(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 P(t){var e=t._readableState;o("emitReadable",e.needReadable,e.emittedReadable),e.needReadable=!1,e.emittedReadable||(o("emitReadable",e.flowing),e.emittedReadable=!0,i.nextTick(C,t))}function C(t){var e=t._readableState;o("emitReadable_",e.destroyed,e.length,e.ended),e.destroyed||!e.length&&!e.ended||(t.emit("readable"),e.emittedReadable=!1),e.needReadable=!e.flowing&&!e.ended&&e.length<=e.highWaterMark,B(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 N(t){o("readable nexttick read 0"),t.read(0)}function O(t,e){o("resume",e.reading),e.reading||t.read(0),e.resumeScheduled=!1,t.emit("resume"),B(t),e.flowing&&!e.reading&&t.read(0)}function B(t){var e=t._readableState;for(o("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 j(t){var e=t._readableState;o("endReadable",e.endEmitted),e.endEmitted||(e.ended=!0,i.nextTick(F,e,t))}function F(t,e){if(o("endReadableNT",t.endEmitted,t.length),!t.endEmitted&&0===t.length&&(t.endEmitted=!0,e.readable=!1,e.emit("end"),t.autoDestroy)){var i=e._writableState;(!i||i.autoDestroy&&i.finished)&&e.destroy()}}function H(t,e){for(var i=0,r=t.length;i=e.highWaterMark:e.length>0)||e.ended))return o("read: emitReadable",e.length,e.ended),0===e.length&&e.ended?j(this):P(this),null;if(0===(t=I(t,e))&&e.ended)return 0===e.length&&j(this),null;var r,n=e.needReadable;return o("need readable",n),(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&&j(this)),null!==r&&this.emit("data",r),r},A.prototype._read=function(t){R(this,new x("_read()"))},A.prototype.pipe=function(t,e){var r=this,n=this._readableState;switch(n.pipesCount){case 0:n.pipes=t;break;case 1:n.pipes=[n.pipes,t];break;default:n.pipes.push(t)}n.pipesCount+=1,o("pipe count=%d opts=%j",n.pipesCount,e);var a=e&&!1===e.end||t===i.stdout||t===i.stderr?v:c;function c(){o("onend"),t.end()}n.endEmitted?i.nextTick(a):r.once("end",a),t.on("unpipe",(function e(i,s){o("onunpipe"),i===r&&s&&!1===s.hasUnpiped&&(s.hasUnpiped=!0,o("cleanup"),t.removeListener("close",p),t.removeListener("finish",f),t.removeListener("drain",l),t.removeListener("error",d),t.removeListener("unpipe",e),r.removeListener("end",c),r.removeListener("end",v),r.removeListener("data",u),h=!0,!n.awaitDrain||t._writableState&&!t._writableState.needDrain||l())}));var l=function(t){return function(){var e=t._readableState;o("pipeOnDrain",e.awaitDrain),e.awaitDrain&&e.awaitDrain--,0===e.awaitDrain&&s(t,"data")&&(e.flowing=!0,B(t))}}(r);t.on("drain",l);var h=!1;function u(e){o("ondata");var i=t.write(e);o("dest.write",i),!1===i&&((1===n.pipesCount&&n.pipes===t||n.pipesCount>1&&-1!==H(n.pipes,t))&&!h&&(o("false write response, pause",n.awaitDrain),n.awaitDrain++),r.pause())}function d(e){o("onerror",e),v(),t.removeListener("error",d),0===s(t,"error")&&R(t,e)}function p(){t.removeListener("finish",f),v()}function f(){o("onfinish"),t.removeListener("close",p),v()}function v(){o("unpipe"),r.unpipe(t)}return r.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",p),t.once("finish",f),t.emit("pipe",r),n.flowing||(o("pipe resume"),r.resume()),t},A.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 r=e.pipes,n=e.pipesCount;e.pipes=null,e.pipesCount=0,e.flowing=!1;for(var o=0;o0,!1!==n.flowing&&this.resume()):"readable"===t&&(n.endEmitted||n.readableListening||(n.readableListening=n.needReadable=!0,n.flowing=!1,n.emittedReadable=!1,o("on readable",n.length,n.reading),n.length?P(this):n.reading||i.nextTick(N,this))),r},A.prototype.addListener=A.prototype.on,A.prototype.removeListener=function(t,e){var r=a.prototype.removeListener.call(this,t,e);return"readable"===t&&i.nextTick(D,this),r},A.prototype.removeAllListeners=function(t){var e=a.prototype.removeAllListeners.apply(this,arguments);return"readable"!==t&&void 0!==t||i.nextTick(D,this),e},A.prototype.resume=function(){var t=this._readableState;return t.flowing||(o("resume"),t.flowing=!t.readableListening,function(t,e){e.resumeScheduled||(e.resumeScheduled=!0,i.nextTick(O,t,e))}(this,t)),t.paused=!1,this},A.prototype.pause=function(){return o("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(o("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},A.prototype.wrap=function(t){var e=this,i=this._readableState,r=!1;for(var n in t.on("end",(function(){if(o("wrapped end"),i.decoder&&!i.ended){var t=i.decoder.end();t&&t.length&&e.push(t)}e.push(null)})),t.on("data",(function(n){o("wrapped data"),i.decoder&&(n=i.decoder.write(n)),(!i.objectMode||null!=n)&&(i.objectMode||n&&n.length)&&(e.push(n)||(r=!0,t.pause()))})),t)void 0===this[n]&&"function"==typeof t[n]&&(this[n]=function(e){return function(){return t[e].apply(t,arguments)}}(n));for(var s=0;s<_.length;s++)t.on(_[s],this.emit.bind(this,_[s]));return this._read=function(e){o("wrapped _read",e),r&&(r=!1,t.resume())},this},"function"==typeof Symbol&&(A.prototype[Symbol.asyncIterator]=function(){return void 0===d&&(d=t("./internal/streams/async_iterator")),d(this)}),Object.defineProperty(A.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(A.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(A.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(t){this._readableState&&(this._readableState.flowing=t)}}),A._fromList=U,Object.defineProperty(A.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),"function"==typeof Symbol&&(A.from=function(e,i){return void 0===p&&(p=t("./internal/streams/from")),p(A,e,i)})}).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/async_iterator":43,"./internal/streams/buffer_list":44,"./internal/streams/destroy":45,"./internal/streams/from":47,"./internal/streams/state":49,"./internal/streams/stream":50,_process:32,buffer:14,events:19,inherits:21,"string_decoder/":55,util:13}],41:[function(t,e,i){"use strict";e.exports=l;var r=t("../errors").codes,n=r.ERR_METHOD_NOT_IMPLEMENTED,o=r.ERR_MULTIPLE_CALLBACK,s=r.ERR_TRANSFORM_ALREADY_TRANSFORMING,a=r.ERR_TRANSFORM_WITH_LENGTH_0,c=t("./_stream_duplex");function l(t){if(!(this instanceof l))return new l(t);c.call(this,t),this._transformState={afterTransform:function(t,e){var i=this._transformState;i.transforming=!1;var r=i.writecb;if(null===r)return this.emit("error",new o);i.writechunk=null,i.writecb=null,null!=e&&this.push(e),r(t);var n=this._readableState;n.reading=!1,(n.needReadable||n.length-1))throw new b(t);return this._writableState.defaultEncoding=t,this},Object.defineProperty(A.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(A.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),A.prototype._write=function(t,e,i){i(new v("_write()"))},A.prototype._writev=null,A.prototype.end=function(t,e,r){var n=this._writableState;return"function"==typeof t?(r=t,t=null,e=null):"function"==typeof e&&(r=e,e=null),null!=t&&this.write(t,e),n.corked&&(n.corked=1,this.uncork()),n.ending||function(t,e,r){e.ending=!0,C(t,e),r&&(e.finished?i.nextTick(r):t.once("finish",r)),e.ended=!0,t.writable=!1}(this,n,r),this},Object.defineProperty(A.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(A.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(t){this._writableState&&(this._writableState.destroyed=t)}}),A.prototype.destroy=u.destroy,A.prototype._undestroy=u.undestroy,A.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 r;function n(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}var o=t("./end-of-stream"),s=Symbol("lastResolve"),a=Symbol("lastReject"),c=Symbol("error"),l=Symbol("ended"),h=Symbol("lastPromise"),u=Symbol("handlePromise"),d=Symbol("stream");function p(t,e){return{value:t,done:e}}function f(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(p(i,!1)))}}var v=Object.getPrototypeOf((function(){})),y=Object.setPrototypeOf((n(r={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(p(void 0,!0));if(this[d].destroyed)return new Promise((function(e,r){i.nextTick((function(){t[c]?r(t[c]):e(p(void 0,!0))}))}));var r,n=this[h];if(n)r=new Promise(function(t,e){return function(i,r){t.then((function(){e[l]?i(p(void 0,!0)):e[u](i,r)}),r)}}(n,this));else{var o=this[d].read();if(null!==o)return Promise.resolve(p(o,!1));r=new Promise(this[u])}return this[h]=r,r}},Symbol.asyncIterator,(function(){return this})),n(r,"return",(function(){var t=this;return new Promise((function(e,i){t[d].destroy(null,(function(t){t?i(t):e(p(void 0,!0))}))}))})),r),v);e.exports=function(t){var e,r=Object.create(y,(n(e={},d,{value:t,writable:!0}),n(e,s,{value:null,writable:!0}),n(e,a,{value:null,writable:!0}),n(e,c,{value:null,writable:!0}),n(e,l,{value:t._readableState.endEmitted,writable:!0}),n(e,u,{value:function(t,e){var i=r[d].read();i?(r[h]=null,r[s]=null,r[a]=null,t(p(i,!1))):(r[s]=t,r[a]=e)},writable:!0}),e));return r[h]=null,o(t,(function(t){if(t&&"ERR_STREAM_PREMATURE_CLOSE"!==t.code){var e=r[a];return null!==e&&(r[h]=null,r[s]=null,r[a]=null,e(t)),void(r[c]=t)}var i=r[s];null!==i&&(r[h]=null,r[s]=null,r[a]=null,i(p(void 0,!0))),r[l]=!0})),t.on("readable",function(t){i.nextTick(f,t)}.bind(null,r)),r}}).call(this)}).call(this,t("_process"))},{"./end-of-stream":46,_process:32}],44:[function(t,e,i){"use strict";function r(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,r)}return i}function n(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function o(t,e){for(var i=0;i0?this.tail.next=e:this.head=e,this.tail=e,++this.length}},{key:"unshift",value:function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length}},{key:"shift",value:function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(t){if(0===this.length)return"";for(var e=this.head,i=""+e.data;e=e.next;)i+=t+e.data;return i}},{key:"concat",value:function(t){if(0===this.length)return s.alloc(0);for(var e,i,r,n=s.allocUnsafe(t>>>0),o=this.head,a=0;o;)e=o.data,i=n,r=a,s.prototype.copy.call(e,i,r),a+=o.data.length,o=o.next;return n}},{key:"consume",value:function(t,e){var i;return tn.length?n.length:t;if(o===n.length?r+=n:r+=n.slice(0,t),0==(t-=o)){o===n.length?(++i,e.next?this.head=e.next:this.head=this.tail=null):(this.head=e,e.data=n.slice(o));break}++i}return this.length-=i,r}},{key:"_getBuffer",value:function(t){var e=s.allocUnsafe(t),i=this.head,r=1;for(i.data.copy(e),t-=i.data.length;i=i.next;){var n=i.data,o=t>n.length?n.length:t;if(n.copy(e,e.length-t,0,o),0==(t-=o)){o===n.length?(++r,i.next?this.head=i.next:this.head=this.tail=null):(this.head=i,i.data=n.slice(o));break}++r}return this.length-=r,e}},{key:c,value:function(t,e){return a(this,function(t){for(var e=1;e0,(function(t){h||(h=t),t&&d.forEach(c),o||(d.forEach(c),u(h))}))}));return i.reduce(l)}},{"../../../errors":37,"./end-of-stream":46}],49:[function(t,e,i){"use strict";var r=t("../../../errors").codes.ERR_INVALID_OPT_VALUE;e.exports={getHighWaterMark:function(t,e,i,n){var o=function(t,e,i){return null!=t.highWaterMark?t.highWaterMark:e?t[i]:null}(e,n,i);if(null!=o){if(!isFinite(o)||Math.floor(o)!==o||o<0)throw new r(n?i:"highWaterMark",o);return Math.floor(o)}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 r=i.charCodeAt(i.length-1);if(r>=55296&&r<=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 p(t){return t&&t.length?this.write(t):""}i.StringDecoder=o,o.prototype.write=function(t){if(0===t.length)return"";var e,i;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return"";i=this.lastNeed,this.lastNeed=0}else i=0;return i=0?(n>0&&(t.lastNeed=n-1),n):--r=0?(n>0&&(t.lastNeed=n-2),n):--r=0?(n>0&&(2===n?n=0:t.lastNeed=n-3),n):0}(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=i;var r=t.length-(i-this.lastNeed);return t.copy(this.lastChar,0,r),t.toString("utf8",e,r)},o.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length}},{"safe-buffer":53}],56:[function(t,e,i){"use strict";var r=t("punycode"),n=t("./util");function o(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}i.parse=m,i.resolve=function(t,e){return m(t,!1,!0).resolve(e)},i.resolveObject=function(t,e){return t?m(t,!1,!0).resolveObject(e):e},i.format=function(t){return n.isString(t)&&(t=m(t)),t instanceof o?t.format():o.prototype.format.call(t)},i.Url=o;var s=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,c=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,l=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),h=["'"].concat(l),u=["%","/","?",";","#"].concat(h),d=["/","?","#"],p=/^[+a-z0-9A-Z_-]{0,63}$/,f=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,v={javascript:!0,"javascript:":!0},y={javascript:!0,"javascript:":!0},g={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},w=t("querystring");function m(t,e,i){if(t&&n.isObject(t)&&t instanceof o)return t;var r=new o;return r.parse(t,e,i),r}o.prototype.parse=function(t,e,i){if(!n.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var o=t.indexOf("?"),a=-1!==o&&o127?M+="x":M+=L[D];if(!M.match(p)){var O=P.slice(0,E),B=P.slice(E+1),U=L.match(f);U&&(O.push(U[1]),B.unshift(U[2])),B.length&&(m="/"+B.join(".")+m),this.hostname=O.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),I||(this.hostname=r.toASCII(this.hostname));var j=this.port?":"+this.port:"",F=this.hostname||"";this.host=F+j,this.href+=this.host,I&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==m[0]&&(m="/"+m))}if(!v[R])for(E=0,C=h.length;E0)&&i.host.split("@"))&&(i.auth=I.shift(),i.host=i.hostname=I.shift())),i.search=t.search,i.query=t.query,n.isNull(i.pathname)&&n.isNull(i.search)||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.href=i.format(),i;if(!_.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],S=(i.host||t.host||_.length>1)&&("."===A||".."===A)||""===A,E=0,T=_.length;T>=0;T--)"."===(A=_[T])?_.splice(T,1):".."===A?(_.splice(T,1),E++):E&&(_.splice(T,1),E--);if(!b&&!R)for(;E--;E)_.unshift("..");!b||""===_[0]||_[0]&&"/"===_[0].charAt(0)||_.unshift(""),S&&"/"!==_.join("/").substr(-1)&&_.push("");var I,P=""===_[0]||_[0]&&"/"===_[0].charAt(0);return k&&(i.hostname=i.host=P?"":_.length?_.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&&_.length)&&!P&&_.unshift(""),_.length?i.pathname=_.join("/"):(i.pathname=null,i.path=null),n.isNull(i.pathname)&&n.isNull(i.search)||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.auth=t.auth||i.auth,i.slashes=i.slashes||t.slashes,i.href=i.format(),i},o.prototype.parseHost=function(){var t=this.host,e=a.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},{"./util":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,r){(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 r=!1;return function(){if(!r){if(i("throwDeprecation"))throw new Error(e);i("traceDeprecation")?console.trace(e):console.warn(e),r=!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){r[t]=e[t]})),r;function r(){for(var t=new Array(arguments.length),i=0;i{for(var r in e)i.o(e,r)&&!i.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},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})},i(131)})()})); \ No newline at end of file diff --git a/src/Extensions/Components/BootstrapBlazor.Topology/wwwroot/js/topology_bundle.js b/src/Extensions/Components/BootstrapBlazor.Topology/wwwroot/js/topology_bundle.js new file mode 100644 index 0000000000000000000000000000000000000000..9ba14db059e25fdd0f32d08afe26bad053b55f33 --- /dev/null +++ b/src/Extensions/Components/BootstrapBlazor.Topology/wwwroot/js/topology_bundle.js @@ -0,0 +1,29 @@ +var topology = undefined; + +export function init(id, data) { + BootstrapBlazorModules.addScript('_content/BootstrapBlazor.Topology/js/topology.js'); + + var handle = setInterval(function () { + if (window.Topology) { + clearInterval(handle); + Topology.prototype.lock = function (status) { + this.store.data.locked = status; + this.finishDrawLine(!0); + this.canvas.drawingLineName = ""; + this.stopPencil(); + } + + topology = new Topology(id); + topology.connectSocket = function () { + }; + topology.open(JSON.parse(data)); + topology.lock(1); + } + }, 200); +} + +export function push_data(id, data) { + if (topology !== undefined) { + topology.doSocket(JSON.stringify(data)); + } +}