@fgbg/mdocs 0.8.21 → 0.8.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/agent-skills/changelog/SKILL.md +17 -1
- package/agent-skills/index.json +1 -1
- package/bin/mdocs.js +1 -1
- package/dist/server/cli/main.js +22 -1
- package/dist/server/cli/main.js.map +1 -1
- package/dist/server/cli/self-update.js +4 -0
- package/dist/server/cli/self-update.js.map +1 -1
- package/dist/server/documents/tree-and-folders.test.js +54 -3
- package/dist/server/documents/tree-and-folders.test.js.map +1 -1
- package/dist/server/documents/tree.service.js +66 -5
- package/dist/server/documents/tree.service.js.map +1 -1
- package/dist/server/routes/documents.routes.js +16 -0
- package/dist/server/routes/documents.routes.js.map +1 -1
- package/dist/web/assets/{AgentChatPanel-D95hI02c.js → AgentChatPanel-CtdLYtSw.js} +1 -1
- package/dist/web/assets/{AgentSkillFormCard-BtJ0QjLG.js → AgentSkillFormCard-DeZnOTQg.js} +2 -2
- package/dist/web/assets/AiWriteWorkbench-hUYjin2m.js +7 -0
- package/dist/web/assets/DiagramEditor-NtNY3sZL-C9hL71kf.js +2 -0
- package/dist/web/assets/DocumentEditor-BmmnuieO.js +21 -0
- package/dist/web/assets/{MergeView-DgFQHD5_.js → MergeView-CjhCBNPa.js} +1 -1
- package/dist/web/assets/{PlaygroundPage-Dg57Xxpl.js → PlaygroundPage-CgaNgQEp.js} +1 -1
- package/dist/web/assets/SettingsPage-Fl5Tu7u3.js +1 -0
- package/dist/web/assets/{Toolbar-0Y2wmGwe.js → Toolbar-BaKuyXey.js} +1 -1
- package/dist/web/assets/{VisitorPickerModal-COxtOvc4.js → VisitorPickerModal-DPyg6mIt.js} +1 -1
- package/dist/web/assets/{copy-nOl0d3Th.js → copy-UkvgEfIg.js} +1 -1
- package/dist/web/assets/diagram-BLCqfrbF.js +6257 -0
- package/dist/web/assets/index-Ct5Vt4tz.js +185 -0
- package/dist/web/assets/index-Dt_PAYaR.css +1 -0
- package/dist/web/assets/meta2d-D3b5RRN8.js +110 -0
- package/dist/web/assets/{meta2dEngine-BD2XbzaV-e28q005B.js → meta2dEngine-BD2XbzaV-2ovN6JHu.js} +1 -1
- package/dist/web/assets/{motion-D-I76zAi.js → motion-Bz_inm1R.js} +1 -1
- package/dist/web/assets/{plus-DvBbg6jL.js → plus-B-uEAM2g.js} +1 -1
- package/dist/web/assets/react-6CQL39Gs.js +2382 -0
- package/dist/web/assets/react-vendor-BJFXgntS.js +242 -0
- package/dist/web/assets/{ui-C3xtW1w8.js → ui-TwLH91RV.js} +133 -133
- package/dist/web/index.html +5 -5
- package/package.json +2 -2
- package/dist/web/assets/AiWriteWorkbench-Qam8cfY6.js +0 -6
- package/dist/web/assets/DiagramEditor-BTRe45TX-Did98cnP.js +0 -2
- package/dist/web/assets/DocumentEditor-DtSzkl6A.js +0 -21
- package/dist/web/assets/SettingsPage-CkYpe5v7.js +0 -1
- package/dist/web/assets/diagram-BJFhx-27.js +0 -3016
- package/dist/web/assets/index-B-XJ-ScV.js +0 -185
- package/dist/web/assets/index-CGvsjO9f.css +0 -1
- package/dist/web/assets/meta2d-C8Z4cn-d.js +0 -110
- package/dist/web/assets/react-BsVOIHR8.js +0 -2126
- package/dist/web/assets/react-vendor-BNpqFP9B.js +0 -242
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
var ma=Object.defineProperty;var pa=(e,t,i)=>t in e?ma(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var D=(e,t,i)=>pa(e,typeof t!="symbol"?t+"":t,i);import{d as Ut,g as wa}from"./react-vendor-BJFXgntS.js";function me(e,t){const i=t||new Path2D;if(e.name==="combine"&&!e.draw)return i instanceof Path2D?i:void 0;e.setTheme||(e.setTheme=ba);let s=e.calculative.borderRadius||0,r=s;const{x:a,y:o,width:l,height:n,ex:h,ey:c}=e.calculative.worldRect;s<1&&(s=l*s,r=n*r);let f=s<r?s:r;if(l<2*f&&(f=l/2),n<2*f&&(f=n/2),i.moveTo(a+f,o),i.arcTo(h,o,h,c,f),i.arcTo(h,c,a,c,f),i.arcTo(a,c,a,o,f),i.arcTo(a,o,h,o,f),i.closePath(),i instanceof Path2D)return i}function ba(e,t){if(e.affectByTheme){for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)){const s=t[i];e.hasOwnProperty(i)&&(e[i]=s),e.calculative.hasOwnProperty(i)&&(e.calculative[i]=s)}e.hoverTextColor=t.textPrimaryColor,e.iconColor=t.buttonBg,e.calculative.iconColor=t.buttonBg,e.hoverBackground=t.formBg,e.activeBackground=t.activeBg,e.color=t.borderColor,e.calculative.color=t.borderColor,e.textColor=t["textColor-9"],e.calculative.textColor=t["textColor-9"]}}const xa=me;function ka(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.ellipse(s+a/2,r+o/2,a/2,o/2,0,0,Math.PI*2),i instanceof Path2D)return i}var ut;(function(e){e[e.Node=0]="Node",e[e.Line=1]="Line"})(ut||(ut={}));var ct;(function(e){e[e.None=0]="None",e[e.DisableEdit=1]="DisableEdit",e[e.DisableMove=2]="DisableMove",e[e.DisableScale=3]="DisableScale",e[e.DisableMoveScale=4]="DisableMoveScale",e[e.Disable=10]="Disable"})(ct||(ct={}));var ks;(function(e){e[e.Default=0]="Default",e[e.In=1]="In",e[e.Out=2]="Out"})(ks||(ks={}));var ie;(function(e){e[e.None=0]="None",e[e.Linear=1]="Linear",e[e.Radial=2]="Radial"})(ie||(ie={}));var ht;(function(e){e[e.CanvasTemplate=1]="CanvasTemplate",e[e.CanvasImageBottom=2]="CanvasImageBottom",e[e.CanvasMain=3]="CanvasMain",e[e.CanvasImage=4]="CanvasImage"})(ht||(ht={}));const Ra=["text","textWidth","textHeight","textLeft","textTop","fontFamily","fontSize","lineHeight","fontStyle","fontWeight","textAlign","textBaseline","whiteSpace","ellipsis","keepDecimal","letterSpacing"],Ta=["x","y","width","height","flipX","flipY"],Ca=["paddingTop","paddingRight","paddingBottom","paddingLeft","flipX","flipY","visible","showChild"],Aa=["iconLeft","iconTop","iconRotate"],yr=["globalAlpha","flipY","flipX","x","y","width","height","iconWidth","iconHeight","imageRatio","iconLeft","iconTop","iconAlign","rotate","visible"];var pt;(function(e){e[e.Normal=0]="Normal",e[e.Beads=1]="Beads",e[e.Dot=2]="Dot",e[e.Arrow=3]="Arrow",e[e.WaterDrop=4]="WaterDrop",e[e.Custom=5]="Custom"})(pt||(pt={}));var Se;(function(e){e[e.Image=0]="Image",e[e.Icon=1]="Icon",e[e.Pen=2]="Pen",e[e.Element=3]="Element"})(Se||(Se={}));const $i=["gif","iframe","video","echarts","highcharts","lightningCharts","vue"],Di=["radio","checkbox","button","inputDom","slider","echarts"],Fe=new Set(["borderRadius","paddingLeft","paddingRight","paddingTop","paddingBottom","progress","progressColor","verticalProgress","reverseProgress","flipX","flipY","input","lineDash","lineCap","lineJoin","strokeType","lineGradientFromColor","lineGradientToColor","lineGradientAngle","color","hoverColor","activeColor","lineWidth","bkType","gradientFromColor","gradientToColor","gradientAngle","gradientRadius","hoverBackground","activeBackground","globalAlpha","anchorColor","anchorRadius","shadow","shadowColor","shadowBlur","shadowOffsetX","shadowOffsetY","textHasShadow","fontFamily","fontSize","textColor","hoverTextColor","activeTextColor","textBackground","fontStyle","fontWeight","textAlign","textBaseline","lineHeight","whiteSpace","textWidth","textHeight","textLeft","textTop","ellipsis","hiddenText","keepDecimal","borderWidth","borderColor","animateLineWidth","lineAnimateType","frames","animateColor","animateType","animateReverse","background","gradientColors","lineGradientColors","animateLineWidth","gradientSmooth","lineSmooth","animations","toArrow","fromArrow","dirMarkerLineWidth","lineName","textType","textGradientColors"]),Oi={textType:0,bkType:0,strokeType:0};function Sa(e){e.onAdd=void 0,e.onValue=void 0,e.onBeforeValue=void 0,e.onDestroy=void 0,e.onMove=void 0,e.onResize=void 0,e.onRotate=void 0,e.onClick=void 0,e.onMouseEnter=void 0,e.onMouseLeave=void 0,e.onMouseDown=void 0,e.onMouseMove=void 0,e.onMouseUp=void 0,e.onShowInput=void 0,e.onInput=void 0,e.onChangeId=void 0,e.onBinds=void 0,e.onStartVideo=void 0,e.onPauseVideo=void 0,e.onStopVideo=void 0,e.onRenderPenRaw=void 0,e.onKeyDown=void 0,e.onContextmenu=void 0,e.onScale=void 0,e.onWheel=void 0,e.onConnectLine=void 0}var st;(function(e){e[e.None=0]="None",e[e.LineAnchor=1]="LineAnchor",e[e.NodeAnchor=2]="NodeAnchor",e[e.Line=3]="Line",e[e.Node=4]="Node",e[e.Resize=5]="Resize",e[e.Rotate=6]="Rotate",e[e.LineAnchorPrev=7]="LineAnchorPrev",e[e.LineAnchorNext=8]="LineAnchorNext"})(st||(st={}));var ft;(function(e){e[e.None=0]="None",e[e.Translate=1]="Translate",e[e.Select=2]="Select",e[e.Resize=3]="Resize",e[e.AddAnchor=4]="AddAnchor"})(ft||(ft={}));var Qt;(function(e){e[e.None=0]="None",e[e.Down=1]="Down",e[e.Translate=2]="Translate"})(Qt||(Qt={}));var nt;(function(e){e[e.None=-1]="None",e[e.Up=0]="Up",e[e.Right=1]="Right",e[e.Bottom=2]="Bottom",e[e.Left=3]="Left"})(nt||(nt={}));const Rs=["nw-resize","ne-resize","se-resize","sw-resize"],Ts=["n-resize","e-resize","s-resize","w-resize"],Pa=["curve","polyline","line"],mr=["dash","lineWidth","lineCap","lineJoin","strokeType","color","lineGradientFromColor","lineGradientToColor","lineGradientAngle","globalAlpha","bkType","background","gradientFromColor","gradientToColor","gradientAngle","gradientRadius","fontFamily","fontSize","textColor","hoverTextColor","activeTextColor","textBackground","fontStyle","fontWeight","textAlign","textBaseline","lineHeight","whiteSpace","textLeft","textTop","flipX","flipY","lineDash","visible","iconColor"];var pe;(function(e){e[e.Mirror=0]="Mirror",e[e.Bilateral=1]="Bilateral",e[e.Free=2]="Free"})(pe||(pe={}));var At;(function(e){e[e.Default=0]="Default",e[e.In=1]="In",e[e.Out=2]="Out",e[e.DisableConnected=3]="DisableConnected",e[e.DisableConnectTo=4]="DisableConnectTo",e[e.Disable=10]="Disable"})(At||(At={}));var $t;(function(e){e[e.Default=0]="Default",e[e.Line=1]="Line"})($t||($t={}));function vt(e,t,i){if(!t||t%360===0)return;const s=t*Math.PI/180,r=(e.x-i.x)*Math.cos(s)-(e.y-i.y)*Math.sin(s)+i.x,a=(e.x-i.x)*Math.sin(s)+(e.y-i.y)*Math.cos(s)+i.y;e.x=r,e.y=a,e.prev&&vt(e.prev,t,i),e.next&&vt(e.next,t,i)}function Ce(e,t,i=5,s){if(t.type===$t.Line){let r=s.rotate;s.flipX&&(r*=-1),s.flipY&&(r*=-1);let a=t.rotate+r;return s.flipX&&(a*=-1),s.flipY&&(a*=-1),Jt(e,{x:t.x-t.length*s.calculative.canvas.store.data.scale/2,y:t.y-i,width:t.length*s.calculative.canvas.store.data.scale,height:i*2,rotate:a})}else return e.x>t.x-i&&e.x<t.x+i&&e.y>t.y-i&&e.y<t.y+i}function Pe(e,t,i){e.x=i.x-(i.x-e.x)*t,e.y=i.y-(i.y-e.y)*t}function jt(e,t){if(e.x===t.x)return e.y<=t.y?0:180;if(e.y===t.y)return e.x<t.x?270:90;const i=e.x-t.x,s=e.y-t.y;let r=Math.atan(Math.abs(i/s))/(2*Math.PI)*360;return i>0&&s>0?r=180-r:i<0&&s>0?r+=180:i<0&&s<0&&(r=360-r),r}function Mi(e,t){const i=e.x-t.x,s=e.y-t.y;return Math.sqrt(i*i+s*s)}function Ia(e,t){let i=nt.None;if(!t)return i;const s=e.x-t.x,r=e.y-t.y;return Math.abs(s)>Math.abs(r)?s>0?i=nt.Right:i=nt.Left:r>0?i=nt.Bottom:i=nt.Up,i}function Ye(e,t,i){e&&(e.x+=t,e.y+=i,e.next&&(e.next.x+=t,e.next.y+=i),e.prev&&(e.prev.x+=t,e.prev.y+=i))}function Cs(e,t){return e.anchorId===t.anchorId&&e.connectTo===t.connectTo}function ei(e,t,i){let s=Math.sqrt((e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y))/i.data.scale;t.rotate===0?e.x<t.x?i.pens[t.penId].flipX||(s*=-1):i.pens[t.penId].flipX&&(s*=-1):e.y<t.y?i.pens[t.penId].flipY||(s*=-1):i.pens[t.penId].flipY&&(s*=-1),e.distance=s}const _a="1.1.28",pr={version:_a},it={version:pr.version,path2dDraws:{},canvasDraws:{},anchors:{},lineAnimateDraws:{},htmlElements:{},gridDrawers:{}};function wr(e){Object.assign(it.path2dDraws,e)}function Ea(e){Object.assign(it.canvasDraws,e)}function Ma(e){Object.assign(it.anchors,e)}function La(e,t){it.gridDrawers[e]=t}function Da(e){delete it.gridDrawers[e]}function Oa(e){return{all:e=e||new Map,on:function(t,i){var s=e.get(t);s&&s.push(i)||e.set(t,[i])},off:function(t,i){var s=e.get(t);s&&s.splice(s.indexOf(i)>>>0,1)},emit:function(t,i){(e.get(t)||[]).slice().map(function(s){s(i)}),(e.get("*")||[]).slice().map(function(s){s(t,i)})}}}var ve;(function(e){e[e.None=-1]="None",e[e.Document=0]="Document",e[e.Canvas=1]="Canvas"})(ve||(ve={}));const Ba="#FFFFFF00",Na={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",rightCursor:"right.cur",downCursor:"down.cur",hoverCursor:"pointer",minScale:.1,maxScale:10,keydown:ve.Document,gridSize:20,gridColor:"#e2e2e2",ruleColor:"#888888",drawingLineName:"curve",interval:30,minFPSNumber:10,autoFPS:!0,animateInterval:30,autoPolyline:!0,autoAnchor:!0,autoAlignGrid:!1,animateColor:"#30EEDC",ruleLineColor:"#FF4101",shadowOffsetX:0,shadowOffsetY:0,shadowBlur:64,shadowColor:"#00000014",globalAlpha:1,defaultAnchors:[{x:.5,y:0},{x:1,y:.5},{x:.5,y:1},{x:0,y:.5}],measureTextWidth:!0,moveConnectedLine:!0,mouseRightActive:!0,disableClipboard:!1,drawingLineLength:0,disableTouchPadScale:!1,parentTouch:!0,cdn:"",polylineSpace:10,dirMarkers:!1,domShapes:[],containerShapes:["tablePlus"],textFlip:!0,textRotate:!0,unavailableKeys:[],diagramOptions:{},svgPathStroke:!0,reconnetTimes:10},Fa=["color","hoverColor","activeColor","disabledColor","background","activeBackground","hoverBackground","disabledBackground","anchorColor","hoverAnchorColor","anchorBackground","animateColor","textColor","ruleColor","ruleLineColor","gridColor","lineColor","penBackground","dockPenColor"],za={dark:{color:"#bdc7db",background:"#1e2430",parentBackground:"#080b0f",ruleColor:"#222E47",ruleOptions:{background:"#121924",textColor:"#6E7B91"}},light:{color:"#222222",background:"#FFFFFF",parentBackground:"#F0F1F2",ruleColor:"#C8D0E1",ruleOptions:{background:"#F7F8FA",textColor:"#C8D0E1"}}},Ve={cssRuleSelector:":root",style_prefix:"le5le_",vendor_css_prefix:"--le-",dark:["textColor-9: rgba(255,255,255,0.90)","textColor-6: rgba(255,255,255,0.60)","textColor-1: rgba(255,255,255,1)","textColor-4: rgba(255,255,255,0.40)","textPrimaryColor: #7f838c","textSecondColor: rgba(255,255,255,0.90)","textDisabledColor: rgba(255,255,255,0.40)","textActiveColor: #0052d9","buttonBg: #4583ff","buttonDisabledBg: #0057CC","buttonDisabledColor: #FFFFFF26","buttonGradient: linear-gradient(360deg,#4583ff, #33ccff)","containerBg: rgba(21,24,28,0.95)","tabBg: #303746","tabActiveBg: #4583ff","tabDisabledBg: #282e3b","tabDisabledColor: rgba(255,255,255,0.26)","tabActiveColor: rgba(255,255,255,0.90)","formBg: #2a2f36","datePickerCellActiveRangeBg: #2c4475","componentDisabledBg: #282e3b","dataPickerCellActiveBg: #001b52","activeBg: #25375b","popContentBg: #252b37","disabledBg: #7f838c","disabledBg-2: #282E3B","tableStripeColor: rgba(150,192,255,0.10)","tableMenuBg: #303746","tableMenuDividerBg: rgb(76 81 94)","tableMenuHandleBg: #454f64","tableMenuColor: #bdc7db","tableMenuBorderColor: transparent","tableColRowBg: #303746","tableColRowActiveBg: #4A5263","tableColRowColor: rgba(255,255,255,0.6)","paginationColor: rgba(255,255,255,0.6)","paginationActiveColor: #4583ff","paginationActiveBg: rgba(69,131,255,0.20)","sliderBg: #303746","sliderBtnBg: #000000","notificationBorderColor: transparent","notificationBg: #282e3b","borderColor: #424b61","borderOutsideColor: #4583ff","formBorderColor: #424b61","borderInsideColor: rgba(255,255,255,0.40)","shadow: 0px 1px 10px 0px rgba(0,0,0,0.05), 0px 4px 5px 0px rgba(0,0,0,0.08), 0px 2px 4px -1px rgba(0,0,0,0.12)","radius: 4px"],light:["textColor-9: rgba(0,0,0,0.90)","textColor-6: rgba(0,0,0,0.60)","textColor-1: rgba(0,0,0,1)","textColor-4: rgba(0,0,0,0.40)","textPrimaryColor: #7f838c","textSecondColor: #171B27","textDisabledColor: rgba(0, 0, 0, 0.6)","textActiveColor: #0052d9","buttonBg: #4583ff","buttonDisabledBg: #b5c7ff","buttonDisabledColor: #FFFFFF","buttonGradient: linear-gradient(360deg,#4583ff, #33ccff)","containerBg: #ffffff","tabBg: #f1f2f5","tabActiveBg: #4583ff","tabDisabledBg: #e2e6ea","tabDisabledColor: rgba(0,0,0,0.26)","tabActiveColor: #ffffff","formBg: #EFF1F4","datePickerCellActiveRangeBg: #f2f3ff","componentDisabledBg: #eee","dataPickerCellActiveBg: #edefff","activeBg: #f2f3ff","popContentBg: #ffffff","disabledBg: #7f838c","disabledBg-2: #E2E6EA","tableStripeColor: #f1f2f5","tableMenuBg: #ffffff","tableMenuDividerBg: #e2e6ea","tableMenuHandleBg: #ebedf1","tableMenuColor: rgba(0,0,0,0.60)","tableMenuBorderColor: #e2e6ea","tableColRowBg: #ebedf1","tableColRowActiveBg: #bcc4d0","tableColRowColor: rgba(0,0,0,0.4)","paginationColor: rgba(0,0,0,0.6)","paginationActiveColor: #ffffff","paginationActiveBg: #4583ff","sliderBg: #e2e6ea","sliderBtnBg: #ffffff","notificationBorderColor: transparent","notificationBg: #ffffff","borderColor: #d6dbe3","borderOutsideColor: #d6dbe3","formBorderColor: #d4d6d9","borderInsideColor: #e7e7e7","shadow: 0px 2px 4px 0px rgba(107,113,121,0.25)","radius: 4px"],camelCaseToHyphenated(e){return e.replace(/[A-Z]/g,t=>"-"+t.toLowerCase())},_addVendorCssPrefix(e){return e.map(t=>{const[i,s]=t.split(":");return`${this.vendor_css_prefix}${this.camelCaseToHyphenated(i.trim())}:${s.trim()}`})},createThemeSheet(e,t){const i=document.createElement("style");i.type="text/css",i.id=this.style_prefix+t,document.head.appendChild(i);const s=e||"dark",r=this.getTheme(s),a=`${this.cssRuleSelector} { ${r.join(";")} }`;i.innerHTML=a},destroyThemeSheet(e){const t=this.findStyleSheet(this.style_prefix+e);t&&document.head.removeChild(t.ownerNode)},addTheme(e,t){Object.assign(this,{[e]:t})},getTheme(e){return this._addVendorCssPrefix(this[e]||this.light)},getThemeObj(e="dark"){var s;const t=":";return(s=this[e])==null?void 0:s.reduce((r,a)=>{const[o,l]=a.split(t);return r[o]=l,r},{})},findStyleSheet(e){const t=document.styleSheets;for(let i=0;i<t.length;i++){const s=t[i];if(s.ownerNode&&s.ownerNode.id===e)return s}return null},updateCssRule(e,t){const s=this.getTheme(t),r=this.findStyleSheet(this.style_prefix+e);if(!r)return;let a=!1;for(let o=0;o<r.cssRules.length;o++)if(r.cssRules[o].selectorText===this.cssRuleSelector){a=!0;break}if(a)for(let o=0;o<r.cssRules.length;o++){const l=r.cssRules[o];if(l.selectorText===this.cssRuleSelector)if(r.insertRule){r.deleteRule(o);const n=`${this.cssRuleSelector} { ${s.join(";")} }`;r.insertRule(n,o)}else r.addRule&&(l.style.cssText=s.join(";"))}else if(r.insertRule){const o=`${this.cssRuleSelector} { ${s.join(";")} }`;r.insertRule(o,r.cssRules.length)}else if(r.addRule){const o=r.cssRules.find(l=>l.selectorText===this.cssRuleSelector);if(o){const l=s.join(";");o.style.cssText+=`; ${l}`}else r.addRule(this.cssRuleSelector,s.join(";"))}}};var rt;(function(e){e[e.Add=0]="Add",e[e.Update=1]="Update",e[e.Delete=2]="Delete",e[e.Replace=3]="Replace"})(rt||(rt={}));const ja=()=>({data:{x:0,y:0,scale:1,pens:[],origin:{x:0,y:0},center:{x:0,y:0},paths:{}},histories:[],pens:{},path2dMap:new WeakMap,animateMap:new WeakMap,active:[],animates:new Set,options:{...Na},theme:{...za},emitter:Oa(),bindDatas:{},bind:{},pensNetwork:{},cacheDatas:[],messageEvents:{},templatePens:{},globalTriggers:{}}),Wa=(e="default")=>(it[e]||(it[e]=ja(),it[e].id=e),it[e]),Ha=(e,t)=>{const i=e.data.template===t;if(i)for(const s of e.data.pens)s.canvasLayer,ht.CanvasTemplate;e.lastScale=e.data.scale,e.data={x:0,y:0,scale:1,pens:[],origin:{x:0,y:0},center:{x:0,y:0},paths:{},template:i?t:null,lineAnimateDraws:{}},e.sameTemplate=i,e.pens={},e.histories=[],e.historyIndex=null,e.path2dMap=new WeakMap,e.animateMap=new WeakMap,e.bindDatas={},e.bind={},e.pensNetwork={},e.active=[],e.hover=void 0,e.lastHover=void 0,e.animates.clear()};function qt(e){return typeof e=="number"&&!isNaN(e)}function yi(e){return e==null||typeof e=="string"&&e.trim()===""||!e&&e!==0&&e!=="0"&&e!==!1}function Yt(e){const{paddingTop:t,paddingBottom:i,paddingLeft:s,paddingRight:r,worldRect:a,canvas:o,text:l}=e.calculative;let{textLeft:n,textTop:h,textWidth:c,textHeight:f}=e.calculative,u=s,d=t;const v=a.width-s-r,g=a.height-t-i;c&&c<1&&(c*=a.width),f&&f<1&&(f*=a.height),c<e.calculative.fontSize&&(c=e.calculative.fontSize),u+=(n||0)+a.x,d+=(h||0)+a.y;const y=e.textAlign||o.store.options.textAlign,p=e.textBaseline||o.store.options.textBaseline;switch(y){case"center":u+=(v-(c||v))/2;break;case"right":u+=v-(c||v);break}switch(p){case"middle":d+=(g-(f||g))/2;break;case"bottom":d+=g-(f||g);break}const b={x:u,y:d,width:c||v,height:f||g};bt(b),e.calculative.worldTextRect=b,Ne(e),e.calculative.textDrawRect=void 0}function as(e,t){const i=t.calculative;if(yi(i.text))return;i.textLines||Ne(t);const{worldTextRect:s,textLines:r,fontSize:a,lineHeight:o,canvas:l}=i;if(!r)return;const n=a*o,h=r.length*n;t.calculative.fontsChecked!==!1&&(document.fonts.check(e.font)?t.calculative.fontsChecked=!1:t.calculative.fontsChecked=!0);const c=Va(e,t);let f=s.x+(s.width-c)/2,u=s.y+(s.height-h)/2;const{options:d}=l.store;switch(t.textAlign||d.textAlign){case"left":f=s.x;break;case"right":f=s.x+s.width-c;break}switch(t.textBaseline||d.textBaseline){case"top":u=s.y;break;case"bottom":u=s.ey-h;break}t.calculative.textDrawRect={x:f,y:u,width:c,height:h},bt(t.calculative.textDrawRect)}function Ne(e,t=e.calculative.text){const i=e.calculative;if(yi(t)){i.textLines=void 0;return}let s=typeof t=="string"?t:t.toString();const{whiteSpace:r,ellipsis:a}=e,{keepDecimal:o}=i;if(o!=null&&s.trim()!==""){const u=Number(s);isNaN(u)||(s=u.toFixed(o))}let l=[];const n=i.fontSize*i.lineHeight,h=i.worldTextRect.height,c=Math.floor(h/n),f=c>1?c:1;switch(r){case"nowrap":if(a!==!1){const v=As([...s],e);v[0]&&(l.push(v[0]),v.length>1&&Bi(l))}else l.push(s);break;case"pre-line":l=s.split(/[\n]/g),a!==!1&&l.length>f&&(l=l.slice(0,f),Bi(l));break;case"break-all":default:const u=s.split(/[\n]/g);let d=0;t:for(const v of u){const g=r==="break-all"?v.split(""):br(v);let y=As(g,e);if(y.length===0&&(y=[""]),a!=!1)for(const p of y)if(d++,d>f){Bi(l);break t}else l.push(p);else l.push(...y)}break}return i.textLines=l,l}function br(e=""){const t=[];let i="";for(let s=0;s<e.length;++s){const r=e.charCodeAt(s);r<33||r>126?(i&&(t.push(i),i=""),t.push(e[s])):i+=e[s]}return i&&t.push(i),t}function As(e,t){const i=t.calculative.canvas,s=i.offscreen.getContext("2d"),{fontStyle:r,fontWeight:a,fontSize:o,fontFamily:l,lineHeight:n}=t.calculative;s.save();const h=[];let c=e[0]||"";for(let f=1;f<e.length;++f){const u=e[f]||"",d=c+u;let v=0;if(i.store.options.measureTextWidth)s.font=_t({fontStyle:r,fontWeight:a,fontFamily:l||i.store.options.fontFamily,fontSize:o,lineHeight:n}),v=s.measureText(d).width;else{const y=d.match(/[^\x00-\xff]/g)||"",p=y.length*o,b=d.match(/\s/g)||"",m=b.length*o*.3,k=(d.length-y.length-b.length)*o*.6;v=p+m+k}const g=t.calculative.worldTextRect.width;v<=g+.1?c+=u:(c.length&&h.push(c),c=u)}return c.length&&h.push(c),s.restore(),h}function Va(e,t){let i=0;return t.calculative.textLineWidths=[],t.calculative.textLines&&t.calculative.textLines.forEach(s=>{let r;t.calculative.textType?r=Ua(s,t)+s.length*t.calculative.letterSpacing:r=e.measureText(s).width+s.length*t.calculative.letterSpacing,t.calculative.textLineWidths.push(r),i<r&&(i=r)}),i}function Ua(e,t){const i=t.calculative.fontSize,s=e.match(/[^\x00-\xff]/g)||"",r=s.length*i,a=e.match(/\s/g)||"",o=a.length*i*(t.CSmultiple||.5),l=(e.length-s.length-a.length)*i*(t.CEmultiple||.54);return r+o+l}function Bi(e){e[e.length-1]=e[e.length-1].slice(0,-3)+"..."}function qa(e){let t=e.text.split(`
|
|
2
|
+
`);const i=e.calculative.canvas,s=i.offscreen.getContext("2d"),{fontStyle:r,fontWeight:a,fontSize:o,fontFamily:l,lineHeight:n}=e.calculative;let h=0,c=0;s.save();for(let u=0;u<t.length;u++){if(i.store.options.measureTextWidth)s.font=_t({fontStyle:r,fontWeight:a,fontFamily:l||i.store.options.fontFamily,fontSize:o,lineHeight:n}),c=s.measureText(t[u]).width+t[u].length*e.calculative.letterSpacing;else{const d=t[u].match(/[^\x00-\xff]/g)||"",v=d.length*o,g=t[u].match(/\s/g)||"",y=g.length*o*.3,p=(t[u].length-d.length-g.length)*o*.6;c=v+y+p+t[u].length*e.calculative.letterSpacing}c>h&&(h=c)}s.restore();let f=t.length*o*n;e.textAlign==="left"||(e.textAlign==="right"?e.x=e.x-(h-e.width):e.x=e.x-(h-e.width)/2),e.textBaseline==="top"||(e.textBaseline==="bottom"?e.y=e.y-(f-e.height):e.y=e.y-(f-e.height)/2),e.height=f+5,e.width=h+5,e.calculative.canvas.updatePenRect(e),e.calculative.canvas.calcActiveRect()}function K(e,t=!1){if(Array.isArray(e)){const i=[];return e.forEach(s=>{i.push(K(s,t))}),i}else if(typeof e=="object"){if(e===null)return null;if(e.constructor===RegExp)return e;const i={};for(const s in e)if(!(["canvas","lastFrame","socketFn"].includes(s)||e[s]instanceof HTMLImageElement||e[s]instanceof HTMLCanvasElement||e[s]instanceof HTMLMediaElement)){{if(s==="calculative"&&!t)continue;if(s==="singleton"){t?i[s]={}:i[s]=e[s];continue}}i[s]=K(e[s],t)}return i}return e}function Yi(e,t,i){if(Array.isArray(e)){const s=[];return e.forEach(r=>{s.push(Yi(r,t,i))}),s}else if(typeof e=="object"){if(e===null)return null;for(const s in e)if(t.includes(s))if(Array.isArray(e[s]))e[s].forEach((r,a)=>{Number.isNaN(Number(r))||(e[s][a]=Number(r*i))});else{if(Number.isNaN(Number(e[s])))continue;e[s]=Number(e[s])*i}else e[s]=Yi(e[s],t,i);return e}return e}const Bt={};function xr(e,t,i){if(!Bt[t.fromArrow])return;const s=xt(t),{x:r,y:a}=s,o={x:r,y:a};if(o.step=(t.fromArrowSize||10)*i.data.scale,s.next)o.rotate=jt(s.next,s)+90;else{const n=t.calculative.worldAnchors[1];if(!n)return;n.prev?o.rotate=jt(n.prev,s)+90:o.rotate=jt(n,s)+90}e.save(),e.beginPath(),e.setLineDash([]);const l=t.fromArrowColor||t.calculative.color;l&&(e.strokeStyle=l),Bt[t.fromArrow](e,t,i,o),e.restore()}function kr(e,t,i){if(!Bt[t.toArrow]||t.calculative.worldAnchors.length<2)return;e.save();const s=dt(t),{x:r,y:a}=s,o={x:r,y:a};if(o.step=(t.toArrowSize||10)*i.data.scale,s.prev)o.rotate=jt(s.prev,s)+90;else{const n=t.calculative.worldAnchors[t.calculative.worldAnchors.length-2];n.next?o.rotate=jt(n.next,s)+90:o.rotate=jt(n,s)+90}e.beginPath(),e.setLineDash([]);const l=t.toArrowColor||t.calculative.color;l&&(e.strokeStyle=l),Bt[t.toArrow](e,t,i,o),e.restore()}Bt.triangleSolid=(e,t,i,s)=>{e.save(),e.translate(s.x,s.y),e.rotate(s.rotate*Math.PI/180),e.translate(-s.x,-s.y);const r=s.x-s.step;e.moveTo(r,s.y-s.step/4),e.lineTo(s.x,s.y),e.lineTo(r,s.y+s.step/4),e.closePath(),e.stroke(),e.fillStyle=e.strokeStyle,e.fill(),e.restore()};Bt.reTriangleSolid=(e,t,i,s)=>{e.save(),e.translate(s.x,s.y),e.rotate(s.rotate*Math.PI/180),e.translate(-s.x,-s.y);const r=s.x-s.step/2;e.moveTo(s.x,s.y-s.step/2),e.lineTo(r,s.y),e.lineTo(s.x,s.y+s.step/2),e.closePath(),e.stroke(),e.fillStyle=e.strokeStyle,e.fill(),e.restore()};Bt.triangle=(e,t,i,s)=>{e.save(),e.lineWidth<2&&(e.lineWidth=2),e.translate(s.x,s.y),e.rotate(s.rotate*Math.PI/180),e.translate(-s.x,-s.y);const r=s.x-s.step;e.moveTo(r,s.y-s.step/4),e.lineTo(s.x,s.y),e.lineTo(r,s.y+s.step/4),e.closePath(),e.stroke(),e.fillStyle=i.data.background||"#ffffff",e.fill(),e.restore()};Bt.circleSolid=(e,t,i,s)=>{e.save(),e.translate(s.x,s.y),e.rotate(s.rotate*Math.PI/180),e.translate(-s.x,-s.y);const r=s.step/2;e.arc(s.x-r,s.y,r,0,2*Math.PI),e.stroke(),e.fillStyle=e.strokeStyle,e.fill(),e.restore()};Bt.circle=(e,t,i,s)=>{e.save(),e.translate(s.x,s.y),e.rotate(s.rotate*Math.PI/180),e.translate(-s.x,-s.y);const r=s.step/2;e.arc(s.x-r,s.y,r,0,2*Math.PI),e.stroke(),e.fillStyle=i.data.background||"#ffffff",e.fill(),e.restore()};Bt.diamondSolid=(e,t,i,s)=>{e.save(),e.translate(s.x,s.y),e.rotate(s.rotate*Math.PI/180),e.translate(-s.x,-s.y);const r=s.x-s.step,a=s.step/2;e.moveTo(r,s.y),e.lineTo(r+a,s.y-a/2),e.lineTo(s.x,s.y),e.lineTo(r+a,s.y+a/2),e.closePath(),e.stroke(),e.fillStyle=e.strokeStyle,e.fill(),e.restore()};Bt.diamond=(e,t,i,s)=>{e.save(),e.translate(s.x,s.y),e.rotate(s.rotate*Math.PI/180),e.translate(-s.x,-s.y);const r=s.x-s.step,a=s.step/2;e.moveTo(r,s.y),e.lineTo(r+a,s.y-a/2),e.lineTo(s.x,s.y),e.lineTo(r+a,s.y+a/2),e.closePath(),e.stroke(),e.fillStyle=i.data.background||"#ffffff",e.fill(),e.restore()};Bt.line=(e,t,i,s)=>{e.save(),e.translate(s.x,s.y),e.rotate(s.rotate*Math.PI/180),e.translate(-s.x,-s.y);const r=s.x-s.step;e.moveTo(r,s.y-s.step/3),e.lineTo(s.x,s.y),e.lineTo(r,s.y+s.step/3),e.stroke(),e.restore()};Bt.lineUp=(e,t,i,s)=>{e.save(),e.translate(s.x,s.y),e.rotate(s.rotate*Math.PI/180),e.translate(-s.x,-s.y);const r=s.x-s.step;e.moveTo(r,s.y-s.step/3),e.lineTo(s.x,s.y),e.stroke(),e.restore()};Bt.lineDown=(e,t,i,s)=>{e.save(),e.translate(s.x,s.y),e.rotate(s.rotate*Math.PI/180),e.translate(-s.x,-s.y);const r=s.x-s.step;e.moveTo(r,s.y+s.step/3),e.lineTo(s.x,s.y),e.stroke(),e.restore()};function Xi(e){const t=parseInt,i=Math.round;let s=e.length,r={};if(s>9){const[a,o,l,n]=e=e.split(",");if(s=e.length,s<3||s>4)return null;r.r=t(a[3]=="a"?a.slice(5):a.slice(4)),r.g=t(o),r.b=t(l),r.a=n?parseFloat(n):-1}else{if(s==8||s==6||s<4)return null;s<6&&(e="#"+e[1]+e[1]+e[2]+e[2]+e[3]+e[3]+(s>4?e[4]+e[4]:"")),e=t(e.slice(1),16),s==9||s==5?(r.r=e>>24&255,r.g=e>>16&255,r.b=e>>8&255,r.a=i((e&255)/.255)/1e3):(r.r=e>>16,r.g=e>>8&255,r.b=e&255,r.a=-1)}return r}function St(e,t,i,s){let r,a,o,l,n,h,c,f=Math.round,u=typeof i=="string";return typeof e!="number"||e<-1||e>1||typeof t!="string"||t[0]!="r"&&t[0]!="#"||i&&!u||(c=t.length>9,c=u?i.length>9?!0:i=="c"?!c:!1:c,n=Xi(t),l=e<0,h=i&&i!="c"?Xi(i):l?{r:0,g:0,b:0,a:-1}:{r:255,g:255,b:255,a:-1},e=l?e*-1:e,l=1-e,!n||!h)?null:(s?(r=f(l*n.r+e*h.r),a=f(l*n.g+e*h.g),o=f(l*n.b+e*h.b)):(r=f((l*n.r**2+e*h.r**2)**.5),a=f((l*n.g**2+e*h.g**2)**.5),o=f((l*n.b**2+e*h.b**2)**.5)),u=n.a,h=h.a,n=u>=0||h>=0,u=n?u<0?h:h<0?u:u*l+h*e:0,c?"rgb"+(n?"a(":"(")+r+","+a+","+o+(n?","+f(u*1e3)/1e3:"")+")":"#"+(4294967296+r*16777216+a*65536+o*256+(n?f(u*255):0)).toString(16).slice(1,n?void 0:-2))}globalThis.pSBC=St;function mi(e,t){const i=Xi(e)||{r:0,g:0,b:0};return i.a<0?`rgba(${i.r},${i.g},${i.b},${t})`:`rgba(${i.r},${i.g},${i.b},${t+i.a})`}function Re(e,t){if(isNaN(e)){console.warn("realValue not number");return}if(typeof t!="string"){console.warn("collection must be string");return}const[i,s]=[t[0],t[t.length-1]];if(!["[","("].includes(i)){console.warn('collection must start with "[" or "("');return}if(!["]",")"].includes(s)){console.warn('collection must end with "]" or ")"');return}const r=t.substring(1,t.length-1).split(",");if(r.length!==2){console.warn("collection must have 2 numbers");return}const[a,o]=[+r[0],+r[1]];if(a>=o){console.warn("startNum must less than endNum");return}return e>a||i==="["&&e===a?e<o||s==="]"&&e===o:!1}function Te(e,t){if(typeof t!="string"){console.warn("collection must be string");return}const[i,s]=[t[0],t[t.length-1]];if(i!=="["||s!=="]"){console.warn('collection must start with "[" and end with "]"');return}const r=t.substring(1,t.length-1).split(",");for(const a of r)if(a.includes("..")){const[o,l]=a.split(".."),[n,h]=[+o,+l];if(n>=h){console.warn("startNum must less than endNum");return}if(e>=n&&e<=h)return!0}else if(e==a)return!0;return!1}function Rr(e,t,i){const s=1-e;return 3*s*s*e*t+3*s*e*e*i+e*e*e}function $a(e){const t=e.match(/^-?\d*\.?\d*/);if(e=t?t[0]:"",e.includes("-")&&e.indexOf("-")!==0&&(e=e.replace(/-/g,""),e&&(e="-"+e)),(e.match(/\./g)||[]).length>1){const s=e.split(".");e=s[0]+"."+s.slice(1).join("")}return e}function lt(){return((1+Math.random())*4294967296|0).toString(16).substring(1)}const Zt=e=>{let t=0,i=0,s=0,r=0;return typeof e=="number"?t=i=s=r=e:typeof e=="string"?t=i=s=r=parseInt(e,10):Array.isArray(e)&&(t=e[0],s=Ni(e[1])?e[0]:e[1],r=Ni(e[2])?e[0]:e[2],i=Ni(e[3])?s:e[3]),[t,s,r,i]};function Ni(e){return e==null}async function Ya(e){return new Promise((t,i)=>{const s=new FileReader;s.onload=r=>{t(r.target.result)},s.onerror=r=>{i(r)},s.readAsDataURL(e)})}async function Xa(e,t,i,s){const r=new FormData;if(r.append("file",e),i)for(const o in i)i.hasOwnProperty(o)&&r.append(o,i[o]);return(await(await fetch(t,{method:"POST",headers:s,body:r})).json()).url}function Ka(e,t,i){var s=document.createElement("link");s.href=e,s.rel="stylesheet",t&&(s.onload=t),document.head.appendChild(s)}function Ie(e){let t=e||window.location.search.split("?")[1];const i=new URLSearchParams(t);return Object.fromEntries(i.entries())}function pi(e){let t;const i=new RegExp("(^| )"+e+"=([^;]*)(;|$)");return(t=document.cookie.match(i))?decodeURIComponent(t[2]):""}var wi;(function(e){e[e.None=0]="None",e[e.LocalStorage=1]="LocalStorage",e[e.Cookie=2]="Cookie"})(wi||(wi={}));const Ga=location.host.indexOf("le5le.com")!==-1;function Ue(){let e="";const t=globalThis.le5leTokenName??"token";switch(globalThis.le5leTokenType){case wi.LocalStorage:e=localStorage.getItem(t);break;case wi.Cookie:e=pi(t);break;default:e=Ga?pi(t):localStorage.getItem(t)}return(globalThis.TokenPrefix??"Bearer ")+(globalThis.le5leTokenD?Tr(e):e)}function Tr(e){if(!e)return e;const t=e.split("");for(let i=0;i<Math.min(10,t.length);i++){const s=t[i],r=i+1;if(new RegExp("[0-9]","").test(s)){let o=parseInt(s,10)-r;for(;o<0;)o+=10;t[i]=o.toString()}else if(new RegExp("[A-Z]","").test(s)){let o=s.charCodeAt(0)-65-r;for(;o<0;)o+=26;t[i]=String.fromCharCode(o+65)}else if(new RegExp("[a-z]","").test(s)){let o=s.charCodeAt(0)-97-r;for(;o<0;)o+=26;t[i]=String.fromCharCode(o+97)}}return t.join("")}async function os(e,t){var n,h;if(globalThis.getMeta2dData)return await globalThis.getMeta2dData(t);const i=e.options.navigatorNetWork;let r=`/api/data/${location.href.includes("2d.")||location.href.includes("/2d")?"2d":"v"}/get`,a=((n=Ie())==null?void 0:n.id)||r.includes("${id}");if(!a&&((h=Ie())==null?void 0:h.data)){r=`./projects/${t}`;const f=new URL(window.location);f.searchParams.set("data",t),history.pushState({},"",f)}i!=null&&i.url&&(i.url.includes("${id}")?r=i.url.replace("${id}",t):r=i.url+((i==null?void 0:i.method)==="GET"?`?id=${t}`:""));let o=(i==null?void 0:i.method)||"POST";a||(o="GET");const l=await fetch(r,{headers:{Authorization:Ue()},method:o,body:o==="GET"?void 0:JSON.stringify({id:t})});if(l.ok){let c=await l.text();return c.constructor===Object||c.constructor===Array?c=JSON.parse(JSON.stringify(c)):typeof c=="string"&&(c=JSON.parse(c)),c.data&&(c=c.data),c}else e.emitter.emit("error",{type:"http",error:l})}function Et(e,t){if(t==null)return e;const i=t.split(".");for(;i.length&&(e=e[i.shift()]););return e}function bi(e,t,i){t!=null&&t.split(".").reduce((s,r,a)=>s[r]=t.split(".").length===++a?i:s[r]||{},e)}function Cr(){}function ns(e){return!!(e!=null&&e.allowScript)}function It(e,...t){return ns(e)?new Function(...t):Cr}function ii(e,...t){if(!ns(e))return async()=>{};const i=Object.getPrototypeOf(async function(){}).constructor;return new i(...t)}function Ja(e,t){return ns(e)?It(e,`return (${t})`)():Cr}function xi(e,t,i){const s=["天","一","二","三","四","五","六"];let r=new Date;t&&(r=new Date(t));const a=r.getFullYear(),o=r.getMonth()+1,l=r.getDate(),n=r.getDay(),h=r.getHours(),c=r.getMinutes(),f=r.getSeconds();if(!e)return`${a}:${o}:${l} ${h}:${c}:${f} 星期${s[n]}`;let u=It(i,"year","month","day","week","hours","minutes","seconds",`return ${e}`);const d=u(a,o,l,s[n],h,c,f);return u=null,d}const Fi=new WeakMap;function Qa(e,t,i){let s=Fi.get(e);return s?clearTimeout(s.timer):(s={},Fi.set(e,s)),new Promise((r,a)=>{s.timer=setTimeout(async()=>{r(await e(i)),Fi.delete(e)},t)})}class ls{static debounce(t,i,s=300){const r=Symbol(`${t.constructor.name}.${i}`);this.instances.has(t)||this.instances.set(t,{});const a=this.instances.get(t);return(...o)=>{a[r]&&clearTimeout(a[r]),a[r]=setTimeout(()=>{t[i](...o),delete a[r]},s)}}}D(ls,"instances",new WeakMap);const Ss="line",ki="repeat";function Za(e,t){if(!e||!t)return!1;let i=Mt(e);for(;i;){if(i.id===t.id)return!0;i=Mt(i)}return!1}function Mt(e,t){if(!e||!e.parentId||!e.calculative)return;const s=e.calculative.canvas.store.pens[e.parentId];return t&&Mt(s,t)||s}function Pt(e,t){if(!e||!e.children)return[];const i=[];return e.children.forEach(s=>{const r=t.pens[s];r&&(i.push(r),i.push(...Pt(r,t)))}),i}function cs(e,t){if(!e||!e.followers)return[];const i=[];return e.followers.forEach(s=>{const r=t.pens[s];r&&!r.parentId&&(i.push(r),i.push(...cs(r,t)))}),i}function to(e,t){const{worldRect:i,gradientFromColor:s,gradientToColor:r,gradientAngle:a}=t.calculative;return Sr(e,i,s,r,a)}function eo(e,t){const{worldRect:i,gradientFromColor:s,gradientToColor:r,gradientRadius:a}=t.calculative;if(!s||!r)return;const{width:o,height:l,center:n}=i,{x:h,y:c}=n;let f=o;f<l&&(f=l),f*=.5;const u=e.createRadialGradient(h,c,f*(a||0),h,c,f);return u.addColorStop(0,s),u.addColorStop(1,r),u}function io(e,t,i,s,r){let a=0;a=Math.PI/2-Math.atan2(s-t,i-e);const o=(e+i)/2,l=(t+s)/2,n=o+r*Math.sin(90*Math.PI/180-a),h=l+r*-Math.cos(90*Math.PI/180-a),c=o+r*Math.sin(270*Math.PI/180-a),f=l+r*-Math.cos(270*Math.PI/180-a);return[n,h,c,f]}function so(e,t){const{worldRect:i,gradientColors:s,gradientRadius:r}=t.calculative;if(!s)return;let a=t.calculative.gradientColors;t.calculative.checked&&(a=t.calculative.onGradientColors);const{width:o,height:l,center:n}=i,{x:h,y:c}=n;let f=o;f<l&&(f=l),f*=.5;const{colors:u}=oe(a),d=e.createRadialGradient(h,c,f*(r||0),h,c,f);return u.forEach(v=>{d.addColorStop(v.i,v.color)}),d}function ro(e,t){const{x:i,y:s,ex:r,width:a,height:o,center:l}=t.calculative.worldRect;let n=[{x:r,y:s+o/2},{x:i,y:s+o/2}],h=t.calculative.gradientColors;t.calculative.checked&&(h=t.calculative.onGradientColors);const{angle:c,colors:f}=oe(h);let u=Li(c,a,o);return n.forEach(d=>{vt(d,c,l)}),Qe(e,n,f,u)}function ao(e,t){const{worldRect:i,textGradientColors:s}=t.calculative;if(!s)return;const{width:r,height:a,center:o}=i,{x:l,y:n}=o;let h=r;h<a&&(h=a),h*=.5;const{colors:c}=oe(s),f=e.createRadialGradient(l,n,0,l,n,h);return c.forEach(u=>{f.addColorStop(u.i,u.color)}),f}function oo(e,t){!t.calculative.textDrawRect&&as(e,t),yt(t.calculative.textDrawRect);const{x:i,y:s,ex:r,width:a,height:o,center:l}=t.calculative.textDrawRect;let n=[{x:r,y:s+o/2},{x:i,y:s+o/2}];const{angle:h,colors:c}=oe(t.calculative.textGradientColors);let f=Li(h,a,o);return n.forEach(u=>{vt(u,h,l)}),Qe(e,n,c,f)}function no(e,t){const{worldIconRect:i,iconGradientColors:s}=t.calculative;if(!s||!i)return;const{x:r,y:a,ex:o,width:l,height:n,center:h}=i;let c=[{x:o,y:a+n/2},{x:r,y:a+n/2}];const{angle:f,colors:u}=oe(s);let d=Li(f,l,n);return c.forEach(v=>{vt(v,f,h)}),Qe(e,c,u,d)}function lo(e,t){const{worldIconRect:i,iconGradientColors:s,iconGradientRadius:r}=t.calculative;if(!s||!i)return;const{width:a,height:o,center:l}=i,{x:n,y:h}=l;let c=a;c<o&&(c=o),c*=.5;const{colors:f}=oe(s),u=e.createRadialGradient(n,h,c*(r||0),n,h,c);return f.forEach(d=>{u.addColorStop(d.i,d.color)}),u}function Li(e,t,i){const s=Math.atan(i/t)/Math.PI*180;let r=(e-90)%360,a=0;return r>s&&r<180-s||r>180+s&&r<360-s||r<0?(r>270?r=360-r:r>180?r=r-180:r>90&&(r=180-r),a=Math.abs(i/Math.sin(r/180*Math.PI)/2)):(r>270?r=360-r:r>180?r=r-180:r>90&&(r=180-r),a=Math.abs(t/Math.cos(r/180*Math.PI)/2)),a}function oe(e){if(typeof e!="string"||!e.startsWith("linear-gradient"))return{angle:0,colors:[]};const t=e.indexOf("("),i=e.lastIndexOf(")");if(t===-1||i===-1||i<=t)return{angle:0,colors:[]};const s=e.slice(t+1,i).trim(),r=co(s);if(r.length===0)return{angle:0,colors:[]};let a=0,o=0;const l=r[0].trim();l.endsWith("deg")?(a=parseFloat(l),o=1):l.startsWith("to ")&&(a=uo(l),o=1);const n=[];for(let c=o;c<r.length;c++){const f=ho(r[c].trim());f&&n.push(f)}if(n.length===0)return{angle:a,colors:[]};fo(n);const h=n.map(c=>({color:c.color,i:c.offset/100}));return{angle:a,colors:h}}function co(e){const t=[];let i="",s=0;for(let r=0;r<e.length;r++){const a=e[r];a==="("?(s++,i+=a):a===")"?(s--,i+=a):a===","&&s===0?(t.push(i),i=""):i+=a}return i.trim()&&t.push(i),t}function ho(e){if(!e)return null;const t=e.match(/^(.+?)\s+(\d+(?:\.\d+)?%)\s*$/);return t?{color:Ps(t[1].trim()),offset:parseFloat(t[2])}:{color:Ps(e)}}function Ps(e){return/^rgba?\s*\(/.test(e)?vo(e):e}function uo(e){return{"to top":90,"to right":180,"to bottom":270,"to left":0,"to top right":135,"to right top":135,"to bottom right":225,"to right bottom":225,"to bottom left":315,"to left bottom":315,"to top left":45,"to left top":45}[e]??0}function fo(e){if(e.length===0)return;e[0].offset==null&&(e[0].offset=0),e[e.length-1].offset==null&&(e[e.length-1].offset=100);let t=0;for(;t<e.length;)if(e[t].offset==null){let i=t-1,s=t+1;for(;s<e.length&&e[s].offset==null;)s++;const r=e[i].offset,a=e[s].offset,o=s-i;for(let l=1;l<o;l++)e[i+l].offset=r+(a-r)*(l/o);t=s}else t++}function vo(e){if(/rgba?/.test(e)){let t=e.split(",");if(t.length<3)return"";e="#";for(let i=0,s;s=t[i++];)if(i<4)s=parseInt(s.replace(/[^\d]/gi,""),10).toString(16),e+=s.length==1?"0"+s:s;else{s=s.replace(")","");let a=parseInt(s*255+"").toString(16);a=a.length===2?a:"0"+a,e+=a}e=e.toUpperCase()}return e}function go(e,t){const{x:i,y:s,ex:r,width:a,height:o,center:l}=t.calculative.worldRect;let n=[{x:r,y:s+o/2},{x:i,y:s+o/2}];const{angle:h,colors:c}=oe(t.calculative.lineGradientColors);let f=Li(h,a,o);return n.forEach(u=>{vt(u,h,l)}),Qe(e,n,c,f)}function Qe(e,t,i,s){let r=io(t[0].x,t[0].y,t[1].x,t[1].y,s),a=e.createLinearGradient(r[0],r[1],r[2],r[3]);return i.forEach(o=>{a.addColorStop(o.i,o.color)}),a}function le(e,t,i){let s=[];t.calculative.gradientColorStop?s=t.calculative.gradientColorStop:(s=oe(t.calculative.lineGradientColors).colors,t.calculative.gradientColorStop=s),e.strokeStyle=Qe(e,i,s,t.calculative.lineWidth/2),e.beginPath(),e.moveTo(i[0].x,i[0].y),e.lineTo(i[1].x,i[1].y),e.stroke()}function Ar(e,t){const i=t.calculative.worldAnchors;let s=t.calculative.lineWidth*(t.calculative.gradientSmooth||t.calculative.lineSmooth||0);for(let r=0;r<i.length-1;r++)if((t.lineName==="curve"||t.lineName==="mind")&&i[r].curvePoints){if(r>0){let l=i[r-1].curvePoints;l?si(e,t,s,l[l.length-1],i[r],i[r].curvePoints[0]):si(e,t,s,i[r-1],i[r],i[r].curvePoints[0]);let n=te(s,i[r],i[r].curvePoints[0]);le(e,t,[n,i[r].curvePoints[1]])}else le(e,t,[i[r],i[r].curvePoints[0]]),le(e,t,[i[r].curvePoints[0],i[r].curvePoints[1]]);let a=i[r].curvePoints.length-1;for(let l=1;l<a;l++)le(e,t,[i[r].curvePoints[l],i[r].curvePoints[l+1]]);let o=te(s,i[r+1],i[r].curvePoints[a]);le(e,t,[i[r].curvePoints[a],o])}else{let a=i[r],o=i[r+1];if(r>0&&r<i.length-1){let n=i[r-1].curvePoints;n?si(e,t,s,n[n.length-1],i[r],i[r+1]):si(e,t,s,i[r-1],i[r],i[r+1])}r>0&&r<i.length-1&&(a=te(s,i[r],i[r+1])),r<i.length-2&&(o=te(s,i[r+1],i[r]));let l=!1;if(r===0&&t.fromLineCap&&t.fromLineCap!=="butt"&&(e.save(),l=!0,e.lineCap=t.fromLineCap),r!==0&&r===i.length-2&&t.toLineCap&&t.toLineCap!=="butt"&&(e.save(),l=!0,e.lineCap=t.toLineCap),le(e,t,[a,o]),l&&e.restore(),i.length===2&&r===0){e.save(),l=!0,e.lineCap=t.toLineCap;let n=.1,h=.1;a.x-o.x===0?h=0:n=(a.y-o.y)/(a.x-o.x)*.1,le(e,t,[{x:o.x-h,y:o.y-n},o]),e.restore()}}}function te(e,t,i){let s=Math.sqrt((i.x-t.x)*(i.x-t.x)+(i.y-t.y)*(i.y-t.y));return s===0?{x:t.x,y:t.y}:e<s?{x:t.x+(i.x-t.x)*e/s,y:t.y+(i.y-t.y)*e/s}:{x:t.x+(i.x-t.x)/s/2,y:t.y+(i.y-t.y)/s/2}}function si(e,t,i,s,r,a){let o=te(i,r,s),l=te(i,r,a),n={x:r.x,y:r.y},h=yo(t.calculative.canvas.store.data.smoothNum||20,o,n,l);for(let c=0;c<h.length-1;c++)le(e,t,[{x:h[c].x,y:h[c].y},{x:h[c+1].x,y:h[c+1].y}])}function Is(e,t,i,s){let r=te(t,i,s),a={x:i.x,y:i.y};e.quadraticCurveTo(a.x,a.y,r.x,r.y)}function hs(e){const t=e.calculative.worldAnchors;let i=e.calculative.lineWidth*(e.calculative.gradientSmooth||e.calculative.lineSmooth||0);const s=new Path2D;for(let r=0;r<t.length-1;r++){t[r];let a=t[r+1];if(r==0&&s.moveTo(t[r].x,t[r].y),r>0&&r<t.length-1){let o=t[r-1].curvePoints;Is(s,i,t[r],t[r+1])}r>0&&r<t.length-1&&te(i,t[r],t[r+1]),r<t.length-2&&(a=te(i,t[r+1],t[r])),s.lineTo(a.x,a.y)}return s}function yo(e=100,t,i,s,r){let a=null;const o=[];!s&&!r?a=mo:s&&!r&&(a=po);for(let l=0;l<e;l++)o.push(a(l/e,t,i,s,r));return s&&o.push(s),o}function mo(e,t,i){const{x:s,y:r}=t,{x:a,y:o}=i;let l=s+(a-s)*e,n=r+(o-r)*e;return{x:l,y:n}}function po(e,t,i,s){const{x:r,y:a}=t,{x:o,y:l}=i,{x:n,y:h}=s;let c=(1-e)*(1-e)*r+2*e*(1-e)*o+e*e*n,f=(1-e)*(1-e)*a+2*e*(1-e)*l+e*e*h;return{x:c,y:f}}function wo(e,t){const{worldRect:i,lineGradientFromColor:s,lineGradientToColor:r,lineGradientAngle:a}=t.calculative;return Sr(e,i,s,r,a)}function Sr(e,t,i,s,r){if(!i||!s)return;const{x:a,y:o,center:l,ex:n,ey:h}=t,c={x:a,y:l.y},f={x:n,y:l.y};r%90===0&&r%180?(c.x=l.x,f.x=l.x,r%270?(c.y=o,f.y=h):(c.y=h,f.y=o)):r&&(vt(c,r,t.center),vt(f,r,t.center));const u=e.createLinearGradient(c.x,c.y,f.x,f.y);return u.addColorStop(0,i),u.addColorStop(1,s),u}function bo(e){const{worldIconRect:t,iconWidth:i,iconHeight:s,imgNaturalWidth:r,imgNaturalHeight:a,worldRect:o}=e.calculative;if(!t)return{x:o.x,y:o.y,width:o.width||r||e.calculative.img.naturalWidth,height:o.height||a||e.calculative.img.naturalHeight};let{x:l,y:n,width:h,height:c}=t;if(i&&(h=i),s&&(c=s),r&&a&&e.imageRatio){const f=t.width/r,u=t.height/a,d=Math.min(f,u),v=r/a;i?c=i/v:s?h=s*v:(h=d*r,c=d*a)}switch(l+=(t.width-h)/2,n+=(t.height-c)/2,e.iconAlign){case"top":n=t.y;break;case"bottom":n=t.ey-c;break;case"left":l=t.x;break;case"right":l=t.ex-h;break;case"left-top":l=t.x,n=t.y;break;case"right-top":l=t.ex-h,n=t.y;break;case"left-bottom":l=t.x,n=t.ey-c;break;case"right-bottom":l=t.ex-h,n=t.ey-c;break}return{x:l,y:n,width:h,height:c}}function Me(e,t){const{x:i,y:s,width:r,height:a}=bo(t),{worldIconRect:o,iconRotate:l}=t.calculative;let{img:n}=t.calculative;if(e.getSerializedSvg&&(n!=null&&n.toDataURL)){const h=new Image;h.src=n.toDataURL("image/png"),n=h}if(e.filter=t.filter,l){const{x:h,y:c}=o.center;e.translate(h,c),e.rotate(l*Math.PI/180),e.translate(-h,-c)}if(t.imageRadius){e.save();let h=t.calculative.imageRadius||0,c=h;const{x:f,y:u,width:d,height:v,ex:g,ey:y}=t.calculative.worldRect;h<1&&(h=d*h,c=v*c);let p=h<c?h:c;d<2*p&&(p=d/2),v<2*p&&(p=v/2),e.beginPath(),e.moveTo(f+p,u),e.arcTo(g,u,g,y,p),e.arcTo(g,y,f,y,p),e.arcTo(f,y,f,u,p),e.arcTo(f,u,g,u,p),e.clip(),e.drawImage(n,i,s,r,a),e.restore()}else{let h=s,c=0;if(t.thumbImg){let f=n.naturalWidth,u=n.naturalHeight;c=(a/r*f-u)/2,a-2*c<0&&(c=(a-u/f*r)/2),h=s+c}e.drawImage(n,i,h,r,a-2*c)}}function Gt(e,t){const{textColor:i,color:s}=e.calculative,{styles:r}=t;return i||s||r.textColor||r.color}function Pr(e,t){const{fontStyle:i,fontWeight:s,fontSize:r,fontFamily:a,lineHeight:o,text:l,hiddenText:n,canvas:h,textHasShadow:c,textBackground:f,textType:u}=t.calculative;if(t.input&&yi(t.text)&&t.calculative.canvas.inputDiv.dataset.penId!==t.id&&!t.onShowInput){e.save(),e.font=_t({fontStyle:i,fontWeight:s,fontFamily:a,fontSize:r,lineHeight:o}),e.textBaseline="top",e.fillStyle=t.placeholderColor||"#c0c0c0";const S=e.measureText(t.placeholder||"请输入").width,I=t.calculative.worldTextRect;let E=0;const z=r*o;let U=(I.height-z)/2;t.textAlign==="center"?E=(I.width-S)/2:t.textAlign==="right"&&(E=I.width-S),t.textBaseline==="top"?U=0:t.textBaseline==="bottom"&&(U=I.height-z),e.fillText(t.placeholder||"请输入",I.x+E,I.y+U+_s(e,t.placeholder||"请输入",z)),e.restore()}if(yi(l)||n||t.hiddenText)return;const d=h.store;e.save(),c||(e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0);let v;t.calculative.disabled?v=t.disabledTextColor||t.disabledColor||St(.4,Gt(t,d)):t.calculative.hover?v=t.hoverTextColor||t.hoverColor||d.styles.hoverColor:t.calculative.active&&(v=t.activeTextColor||t.activeColor||d.styles.activeColor);let g;u===ie.Linear?g=oo(e,t):u===ie.Radial&&(g=ao(e,t)),e.fillStyle=v||g||Gt(t,d),e.font=_t({fontStyle:i,fontWeight:s,fontFamily:a||d.options.fontFamily,fontSize:r,lineHeight:o}),(!t.calculative.textDrawRect||t.calculative.fontsChecked)&&as(e,t);const{x:y,y:p,width:b,height:m}=t.calculative.textDrawRect;f&&(e.save(),e.fillStyle=f,e.fillRect(y,p,b,m),e.restore());const k=t.textAlign||d.options.textAlign,A=r*o;t.calculative.textLines&&t.calculative.textLines.forEach((S,I)=>{const E=t.calculative.textLineWidths[I];let z=0;k==="center"?z=(b-E)/2:k==="right"&&(z=b-E);const U=p+I*A+_s(e,S,A);t.letterSpacing?xo(e,S,y+z,U,t.calculative.letterSpacing):e.fillText(S,y+z,U);const{textDecorationColor:T,textDecorationDash:R,textDecoration:C}=t;C&&ko(e,{x:y+z,y:U,width:E},{textDecorationColor:T,textDecorationDash:R,fontSize:r});const{textStrickoutColor:_,textStrickoutDash:B,textStrickout:j}=t;j&&Ro(e,{x:y+z,y:U,width:E},{textStrickoutColor:_,textStrickoutDash:B,fontSize:r})}),e.restore()}function _s(e,t,i){const s=e.measureText(t),{actualBoundingBoxAscent:r,actualBoundingBoxDescent:a}=s;return r||a?i/2+(r-a)/2:i*.55}function xo(e,t,i,s,r=0){if(r===0){e.fillText(t,i,s);return}let a=0;for(let o=0;o<t.length;o++)e.fillText(t[o],i+a,s),a+=e.measureText(t[o]).width+r}function ko(e,t,i){const{textDecorationColor:s,textDecorationDash:r,fontSize:a}=i;let{x:o,y:l,width:n}=t;switch(e.textBaseline){case"top":l+=a;break;case"middle":l+=a/2;break}e.save(),e.beginPath(),e.strokeStyle=s||e.fillStyle,e.lineWidth=1,e.moveTo(o,l),e.setLineDash(r||[]),e.lineTo(o+n,l),e.stroke(),e.restore()}function Ro(e,t,i){const{textStrickoutColor:s,textStrickoutDash:r,fontSize:a}=i;let{x:o,y:l,width:n}=t;switch(e.textBaseline){case"top":l+=a/2;break;case"bottom":l-=a/2;break}e.save(),e.beginPath(),e.strokeStyle=s||e.fillStyle,e.lineWidth=1,e.moveTo(o,l),e.setLineDash(r||[]),e.lineTo(o+n,l),e.stroke(),e.restore()}function Ir(e,t,i){if(i==null)return;const{fontStyle:s,fontWeight:r,fontSize:a,fontFamily:o,lineHeight:l,canvas:n}=t.calculative,h=n.store;e.save();let c;t.calculative.hover?c=t.hoverTextColor||t.hoverColor||h.styles.hoverColor:t.calculative.active&&(c=t.activeTextColor||t.activeColor||h.styles.activeColor),e.fillStyle=c||Gt(t,h),e.font=_t({fontStyle:s,fontWeight:r,fontFamily:o||h.options.fontFamily,fontSize:a,lineHeight:l});const f=e.measureText(i).width;let u,d;for(const v of t.calculative.worldAnchors){if(!d){d=v;continue}const g=Mi(d,v),y=Math.floor(g/f);u="";for(let b=0;b<y;b++)u+=i;const p=jt(d,v)-270;if(e.save(),p%360!==0){const{x:b,y:m}=d;e.translate(b,m);let k=p*Math.PI/180;e.rotate(k),e.translate(-b,-m)}e.fillText(u,d.x,d.y+l/2),e.restore(),d=v}e.restore()}function _r(e,t){const i=t.calculative.canvas.store;e.save(),e.shadowColor="",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0,e.textAlign="center",e.textBaseline="middle";const s=t.calculative.worldIconRect;let r=s.x+s.width/2,a=s.y+s.height/2;switch(t.iconAlign){case"top":a=s.y,e.textBaseline="top";break;case"bottom":a=s.ey,e.textBaseline="bottom";break;case"left":r=s.x,e.textAlign="left";break;case"right":r=s.ex,e.textAlign="right";break;case"left-top":r=s.x,a=s.y,e.textAlign="left",e.textBaseline="top";break;case"right-top":r=s.ex,a=s.y,e.textAlign="right",e.textBaseline="top";break;case"left-bottom":r=s.x,a=s.ey,e.textAlign="left",e.textBaseline="bottom";break;case"right-bottom":r=s.ex,a=s.ey,e.textAlign="right",e.textBaseline="bottom";break}const o=t.calculative.iconWeight;let l;const n=t.calculative.iconFamily;t.calculative.iconSize>0?l=t.calculative.iconSize:s.width>s.height?l=s.height:l=s.width,e.font=_t({fontSize:l,fontWeight:o,fontFamily:n});let h;t.calculative.iconType===ie.Linear?h=no(e,t):t.calculative.iconType===ie.Radial&&(h=lo(e,t)),e.fillStyle=h||t.calculative.iconColor||Gt(t,i),t.calculative.iconRotate&&(e.translate(s.center.x,s.center.y),e.rotate(t.calculative.iconRotate*Math.PI/180),e.translate(-s.center.x,-s.center.y)),e.beginPath(),e.fillText(t.calculative.icon,r,a),e.restore()}function Er(e,t){if(!t.input)return;const i=t.calculative.canvas.store.data.scale,s=t.calculative.canvas.inputDiv.dataset.penId,{x:r,y:a,width:o,height:l}=t.calculative.worldRect;e.save(),e.beginPath(),t.id===s?(e.moveTo(r+o-20*i,a+l/2+2*i),e.lineTo(r+o-14*i,a+l/2-4*i),e.lineTo(r+o-8*i,a+l/2+2*i)):(e.moveTo(r+o-20*i,a+l/2-4*i),e.lineTo(r+o-14*i,a+l/2+2*i),e.lineTo(r+o-8*i,a+l/2-4*i)),e.stroke(),e.restore()}function _t({fontStyle:e="normal",textDecoration:t="normal",fontWeight:i="normal",fontSize:s=12,fontFamily:r="Arial",lineHeight:a=1}={}){return`${e} ${t} ${i} ${s}px/${a} ${r}`}function we(e,t){const{x:i,ex:s,y:r,ey:a}=t.calculative.worldRect||{};t.calculative.flipX&&(e.translate(i+s,0),e.scale(-1,1)),t.calculative.flipY&&(e.translate(0,r+a),e.scale(1,-1))}function se(e,t,i=!1){if(t.parentId&&t.rotateByRoot){let s=Mt(t,!0);if(s){const{x:r,y:a}=s.calculative.worldRect.pivot||s.calculative.worldRect.center;e.translate(r,a);let o=s.calculative.rotate*Math.PI/180;i||(s.calculative.flipX&&(o*=-1),s.calculative.flipY&&(o*=-1)),e.rotate(o),e.translate(-r,-a)}}else{const{x:s,y:r}=t.calculative.worldRect.pivot||t.calculative.worldRect.center;e.translate(s,r);let a=t.calculative.rotate*Math.PI/180;i||(t.calculative.flipX&&(a*=-1),t.calculative.flipY&&(a*=-1)),e.rotate(a),e.translate(-s,-r)}}function de(e,t,i){var f;e.save(),e.translate(.5,.5),e.beginPath(),$o(e,t);const s=t.calculative.canvas.store,r=t.textFlip||s.options.textFlip,a=t.textRotate||s.options.textRotate;(!r||!a)&&e.save(),we(e,t),(t.rotateByRoot||t.calculative.rotate&&t.name!==Ss)&&se(e,t),(t.calculative.lineWidth>1||i)&&(e.lineWidth=t.calculative.lineWidth),jo(e,s,t);let o,l=!1,n;t.calculative.disabled?(n=t.disabledColor||s.styles.disabledColor||St(.4,t.calculative.color||s.styles.color),o=t.disabledBackground||s.styles.disabledBackground||St(.4,t.calculative.background||s.styles.penBackground)):t.mouseDownValid&&t.calculative.mouseDown?(n=t.mouseDownColor||St(-.4,t.calculative.color||s.styles.color),o=t.mouseDownBackground||St(-.4,t.calculative.background||s.styles.penBackground)):t.switch&&t.calculative.checked?t.calculative.bkType||(o=t.onBackground):t.calculative.hover?(n=t.hoverColor||s.styles.hoverColor,o=t.hoverBackground||s.styles.hoverBackground):t.calculative.active?(n=t.activeColor||s.styles.activeColor,o=t.activeBackground||s.styles.activeBackground):t.calculative.isDock&&(t.type===ut.Line?n=s.styles.dockPenColor:o=mi(s.styles.dockPenColor,.2));const h=t.calculative.strokeImg;if(t.calculative.strokeImage&&h)e.strokeStyle=n||e.createPattern(h,ki);else{let u;t.calculative.strokeType?t.calculative.lineGradientColors?t.name===Ss?l=!0:t.calculative.lineGradient?u=t.calculative.lineGradient:(u=go(e,t),t.calculative.lineGradient=u):u=wo(e,t):u=t.calculative.color||(t.type?s.data.lineColor:"")||s.styles.color,e.strokeStyle=n||u}const c=t.calculative.backgroundImg;if(t.calculative.backgroundImage&&c)e.fillStyle=o||e.createPattern(c,ki),o=!0;else{let u;const d=t.calculative.background||"";typeof d=="string"&&d.startsWith("linear-gradient")&&(t.calculative.gradientColors=d,t.calculative.bkType=ie.Linear),t.calculative.bkType===ie.Linear?t.calculative.gradientColors?t.calculative.gradient?u=t.calculative.gradient:(u=ro(e,t),t.calculative.gradient=u):u=to(e,t):t.calculative.bkType===ie.Radial?t.calculative.gradientColors?t.calculative.radialGradient?u=t.calculative.radialGradient:(u=so(e,t),t.calculative.radialGradient=u):u=eo(e,t):u=t.calculative.background||s.styles.penBackground,e.fillStyle=o||u,o=!!u}if(Mr(e,t),Lr(e,t),be(e,t),t.calculative.lineDash&&e.setLineDash(t.calculative.lineDash.map(u=>u*t.calculative.canvas.store.data.scale)),t.calculative.lineDashOffset&&(e.lineDashOffset=t.calculative.lineDashOffset),t.calculative.shadowColor&&(e.shadowColor=t.calculative.shadowColor,e.shadowOffsetX=t.calculative.shadowOffsetX,e.shadowOffsetY=t.calculative.shadowOffsetY,e.shadowBlur=t.calculative.shadowBlur),l?(Ar(e,t),Or(!0,e,t,s)):(Dr(!0,e,t,s,o),Vr(e,t)),!(t.image&&t.calculative.img)&&t.calculative.icon&&_r(e,t),t.dropdownList&&Er(e,t),(!r||!a)&&e.restore(),r&&!a&&we(e,t),!r&&a&&(t.rotateByRoot||t.calculative.rotate&&t.name!=="line")&&se(e,t,!0),Pr(e,t),t.type===ut.Line&&((f=t.fillTexts)==null?void 0:f.length)>0)for(const u of t.fillTexts)Ir(e,t,u);e.restore()}function Mr(e,t){const i=t.lineCap||(t.type?"round":"square");e.lineCap=i}function Lr(e,t){const i=t.lineJoin;i?e.lineJoin=i:t.type&&(e.lineJoin="round")}function Ri(e,t,i,s){var h,c;e.save(),i&&e.translate(-i.x,-i.y),(h=e.setAttrs)==null||h.call(e,t);let r=!1;const a=t.calculative.canvas.store,o=t.textFlip||a.options.textFlip,l=t.textRotate||a.options.textRotate;e.beginPath(),(!o||!l)&&e.save(),t.calculative.flipX&&(e.translate(t.calculative.worldRect.x+t.calculative.worldRect.ex,0),e.scale(-1,1)),t.calculative.flipY&&(e.translate(0,t.calculative.worldRect.y+t.calculative.worldRect.ey),e.scale(1,-1)),(t.rotateByRoot||t.calculative.rotate&&t.name!=="line")&&se(e,t),(t.calculative.lineWidth>1||s)&&(e.lineWidth=t.calculative.lineWidth);let n;if(t.calculative.hover)e.strokeStyle=t.hoverColor||a.styles.hoverColor,e.fillStyle=t.hoverBackground||a.styles.hoverBackground,n=t.hoverBackground||a.styles.hoverBackground;else if(t.calculative.active)e.strokeStyle=t.activeColor||a.styles.activeColor,e.fillStyle=t.activeBackground||a.styles.activeBackground,n=t.activeBackground||a.styles.activeBackground;else{if(t.strokeImage)t.calculative.strokeImg&&(e.strokeStyle=e.createPattern(t.calculative.strokeImg,ki),n=!0);else{let f;t.calculative.strokeType&&t.calculative.lineGradientColors&&t.name==="line"?r=!0:f=t.calculative.color||a.styles.color,e.strokeStyle=f}t.backgroundImage?t.calculative.backgroundImg&&(e.fillStyle=e.createPattern(t.calculative.backgroundImg,ki),n=!0):(e.fillStyle=t.background,n=!!t.background)}if(Mr(e,t),Lr(e,t),be(e,t),t.calculative.lineDash&&e.setLineDash(t.calculative.lineDash),t.calculative.lineDashOffset&&(e.lineDashOffset=t.calculative.lineDashOffset),t.calculative.shadowColor&&(e.shadowColor=t.calculative.shadowColor,e.shadowOffsetX=t.calculative.shadowOffsetX,e.shadowOffsetY=t.calculative.shadowOffsetY,e.shadowBlur=t.calculative.shadowBlur),r?(Ar(e,t),Or(!0,e,t,a)):(Dr(!1,e,t,a,n),Vr(e,t)),t.calculative.img?(e.save(),e.shadowColor="",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0,Me(e,t),e.restore()):t.calculative.icon&&_r(e,t),t.dropdownList&&Er(e,t),(!o||!l)&&e.restore(),o&&!l&&(t.calculative.flipX&&(e.translate(t.calculative.worldRect.x+t.calculative.worldRect.ex,0),e.scale(-1,1)),t.calculative.flipY&&(e.translate(0,t.calculative.worldRect.y+t.calculative.worldRect.ey),e.scale(1,-1))),!o&&l&&(t.rotateByRoot||t.calculative.rotate&&t.name!=="line")&&se(e,t,!0),Pr(e,t),t.type===ut.Line&&((c=t.fillTexts)==null?void 0:c.length)>0)for(const f of t.fillTexts)Ir(e,t,f);e.restore()}function Dr(e=!0,t,i,s,r){if(i.name==="drawCommand")return;const a=e?s.path2dMap.get(i):it.path2dDraws[i.name];let o=null,l=null;if(i.type===ut.Line&&(i.fromLineCap&&i.fromLineCap!=="butt"&&(t.lineCap="butt",o=new Path2D,o.moveTo(i.calculative.worldAnchors[0].x,i.calculative.worldAnchors[0].y),o.lineTo(i.calculative.worldAnchors[0].x,i.calculative.worldAnchors[0].y)),i.toLineCap&&i.toLineCap!=="butt"&&(t.lineCap="butt",l=new Path2D,l.moveTo(i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].x,i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].y),l.lineTo(i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].x,i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].y))),a){if(i.type===ut.Line&&i.borderWidth){t.save(),t.beginPath();const h=i.calculative.lineWidth+i.calculative.borderWidth;t.lineWidth=h,t.strokeStyle=i.borderColor,o&&(t.save(),t.lineCap=i.fromLineCap,t.stroke(o),t.restore()),a instanceof Path2D?(r&&t.fill(a),h&&t.stroke(a)):(a(i,t),r&&t.fill(),h&&t.stroke()),l&&(t.save(),t.lineCap=i.toLineCap,t.stroke(l),t.restore()),t.restore()}a instanceof Path2D?i.type?i.close&&r&&t.fill(a):r&&t.fill(a):(t.save(),a(i,t),r&&t.fill(),t.restore());const n=(i.calculative.progress-(i.calculative.min||0))/((i.calculative.max||1)-(i.calculative.min||0));if(n!=null&&!isNaN(n)){t.save();const{ex:h,x:c,y:f,width:u,height:d,ey:v}=i.calculative.worldRect;let g=null;if(i.calculative.verticalProgress?g=i.reverseProgress?t.createLinearGradient(c,f,c,f+d*n):t.createLinearGradient(c,v,c,f+d*(1-n)):g=i.reverseProgress?t.createLinearGradient(h,f,c+u*(1-n),f):t.createLinearGradient(c,f,c+u*n,f),i.calculative.progressGradientColors){const{colors:y}=oe(i.calculative.progressGradientColors);y.forEach(p=>{g.addColorStop(p.i,p.color)})}else{const y=i.calculative.progressColor||i.calculative.color||s.options.activeColor||s.data.color;g.addColorStop(0,y),g.addColorStop(1,y)}g.addColorStop(1,"transparent"),t.fillStyle=g,a instanceof Path2D?t.fill(a):(a(i,t),t.fill()),t.restore()}if(i.calculative.lineWidth&&(a instanceof Path2D?(s.options.svgPathStroke||i.name!=="svgPath")&&(o&&(t.save(),t.lineCap=i.fromLineCap,t.stroke(o),t.restore()),t.stroke(a),l&&(t.save(),t.lineCap=i.toLineCap,t.stroke(l),t.restore())):(a(i,t),t.stroke())),i.type){if(i.calculative.animatePos){if(t.save(),Br(t,i,s),i.lineAnimateType===pt.Arrow||i.lineAnimateType===pt.WaterDrop){let h=Kr(i,t);h instanceof Path2D?(t.stroke(h),t.fill(h)):(t.stroke(),t.fill())}else a instanceof Path2D?(o&&!i.lineAnimateType&&(t.save(),t.lineCap=i.fromLineCap,t.stroke(o),t.restore()),t.lineCap=i.lineCap,t.stroke(a)):(a(i,t),t.stroke());t.restore()}i.fromArrow&&xr(t,i,s),i.toArrow&&kr(t,i,s),Yr(t,i,s),i.calculative.active&&!i.calculative.pencil&&!s.options.disableAnchor&&!s.data.locked&&Nr(t,i)}}}function Or(e=!0,t,i,s){const r=e?s.path2dMap.get(i):it.path2dDraws[i.name];if(r&&i.type){if(i.calculative.animatePos){if(t.save(),Br(t,i,s),t.beginPath(),r instanceof Path2D)if(i.lineAnimateType===pt.Arrow||i.lineAnimateType===pt.WaterDrop){const a=Kr(i);t.stroke(a),t.fill(a)}else i.calculative.gradientSmooth||i.calculative.lineSmooth?(i.calculative.gradientAnimatePath||(i.calculative.gradientAnimatePath=hs(i)),i.calculative.gradientAnimatePath instanceof Path2D&&t.stroke(i.calculative.gradientAnimatePath)):t.stroke(r);else r(i,t),t.stroke();t.restore()}i.fromArrow&&xr(t,i,s),i.toArrow&&kr(t,i,s),Yr(t,i,s),i.calculative.active&&!i.calculative.pencil&&!s.options.disableAnchor&&!s.data.locked&&Nr(t,i)}}function Br(e,t,i){e.strokeStyle=t.lineAnimateType===pt.Custom?t.animateColor||Ba:t.animateColor||i.styles.animateColor,t.animateShadow&&(e.shadowBlur=t.animateShadowBlur||t.animateLineWidth||6,e.shadowColor=t.animateShadowColor||t.animateColor||i.styles.animateColor),t.calculative.animateLineWidth&&(e.lineWidth=t.calculative.animateLineWidth*i.data.scale),Array.isArray(t.lineAnimateType)?t.lineAnimateType.forEach(s=>{Es(t,i,s,e)}):Es(t,i,t.lineAnimateType,e)}function Es(e,t,i,s){let r=0;switch(i){case pt.Beads:e.animateReverse?s.lineDashOffset=e.calculative.animatePos:s.lineDashOffset=e.length-e.calculative.animatePos,r=e.calculative.lineWidth||5,r<5&&(r=5);const a=e.animateLineDash&&e.animateLineDash.map(o=>o*r/5);s.setLineDash(a||[r,r*2]);break;case pt.Dot:e.animateReverse?s.lineDashOffset=e.calculative.animatePos:s.lineDashOffset=e.length-e.calculative.animatePos,r=e.calculative.animateDotSize||e.calculative.lineWidth*2||6,r<6&&(r=6),r>40&&(r=40),s.lineWidth=(e.calculative.animateLineWidth||r)*t.data.scale,s.setLineDash([.1,e.length]);break;case pt.Arrow:s.fillStyle=e.animateColor||t.styles.animateColor,s.lineWidth=1;break;case pt.WaterDrop:s.fillStyle=e.animateColor||t.styles.animateColor,s.lineWidth=1;break;case pt.Custom:switch(e.lineAnimateTargetType){case Se.Image:if(e.lineAnimateImages??(e.lineAnimateImages=[]),e.lineAnimateImages.length>0){const n=e.lineAnimateImages.map((h,c)=>{const f=it.htmlElements[h];if(!f)e.calculative.canvas.__loadImage(h);else return f});ri(s,e,"image",n)}break;case Se.Icon:const o=e.lineAnimateIcon;ri(s,e,"icon",o);break;case Se.Pen:e.lineAnimatePens&&ri(s,e,"pen",e.lineAnimatePens);break;case Se.Element:const l=e.lineAnimateElement;ri(s,e,"element",l)}break;default:e.animateReverse?(s.lineDashOffset=Number.EPSILON,s.setLineDash([0,e.length-e.calculative.animatePos+1,e.calculative.animatePos])):s.setLineDash([e.calculative.animatePos,e.length+.01-e.calculative.animatePos]);break}}function ri(e,t,i,s){let r=null;switch(i){case"image":r=To(s);break;case"icon":r=Ao(s);break;case"pen":let a=t.calculative.canvas.find(s);t.lineAnimateElementCount=a.length,r=Co(a);break;case"element":if(r=it.lineAnimateDraws[s],!r)return;break}So(e,t,r)}function To(e){return function(t,i,s,r){const a=i.calculative.canvas.store.data.scale,o=i.lineAnimateElementWidth||10,l=i.lineAnimateElementHeight||10,n=e[r%e.length];n&&(t.save(),t.translate(s.x,s.y),t.rotate(s.rotate*Math.PI/180),t.scale(a,a),t.drawImage(n,-o/2,-l/2,o,l),t.restore())}}function Co(e){return function(t,i,s,r){const a=e[r%e.length];if(!a)return;const o=i.calculative.canvas.store.data.scale,l=i.calculative.canvas.store.data.origin,n=i.calculative.canvas.parent,h=a.width,c=a.height,f=s.x-h/2,u=s.y-c/2,d=(f-l.x)/o,v=(u-l.y)/o,g=h/o,y=c/o,p={x:d,y:v,width:g,height:y,rotate:s.rotate};n.setValue({id:a.id,...p},{render:!1,doEvent:!1,history:!1})}}function Ao(e){return function(t,i,s,r){const a=i.calculative.canvas.store.data.scale;t.beginPath(),t.translate(s.x,s.y),t.rotate(s.rotate*Math.PI/180),t.scale(a,a);const o=i.calculative.iconWeight;let l;const n=i.calculative.iconFamily;l=i.calculative.iconSize||Math.max(i.lineAnimateElementWidth||0,i.lineAnimateElementHeight||0)||10,t.font=_t({fontSize:l,fontWeight:o,fontFamily:n}),t.fillStyle=i.calculative.iconColor||Gt(i,i.calculative.canvas.parent.store),i.calculative.iconRotate&&t.rotate(i.calculative.iconRotate*Math.PI/180),t.beginPath(),t.fillText(e,0,0)}}function So(e,t,i){var a;const s=t.calculative.canvas.store.data.scale,r=Si(t)/s;if(t.lineAnimateLoopMode)Po(e,t,i,r,s);else{const o=Array.isArray(t.lineAnimateDash)?t.lineAnimateDash:((a=t.lineAnimateDash)==null?void 0:a.split(",").map(n=>Number(n)))||[10,20];Io(r,o,t.lineAnimateDashOffset,t.lineAnimateElementCount).forEach((n,h)=>{const c=Ki(t,n.start);if(c)try{e.save(),i(e,t,c,h),e.restore()}catch(f){e.restore(),console.warn(f)}})}}function Po(e,t,i,s,r){var h;const o=((Array.isArray(t.lineAnimateDash)?t.lineAnimateDash:((h=t.lineAnimateDash)==null?void 0:h.split(",").map(c=>Number(c)))||[10,20])[0]||30)*r,l=t.calculative.animatePos,n=t.calculative.worldAnchors;if(n.length>1){let c,f=0;for(let u=0;u<n.length;u++){let d=n[u];if(c){const v=t.length;let y=(l-f)%o-o,p=0;for(;y<v;){if(y>=0){const b=f+y,m=(l-b)/r;try{e.save();const k=Ki(t,m);k&&i(e,t,k,p),e.restore()}catch(k){e.restore(),console.warn(k)}}y+=o,p++}f+=v}c=d}if(t.close){let u=n[0];if(c){const d=Math.sqrt((u.x-c.x)**2+(u.y-c.y)**2);let g=(l-f)%o-o,y=0;for(;g<d;){if(g>=0){const p=f+g,b=(l-p)/r;try{e.save();const m=Ki(t,b);m&&i(e,t,m,y),e.restore()}catch(m){e.restore(),console.warn(m)}}g+=o,y++}}}}}function Io(e,t,i=0,s,r=0){const a=[];if(!t||t.length===0)return a.push({start:0,end:e,isDash:!0}),a;const o=t.reduce((c,f)=>c+f,0);let l=(-i+r)%o;l<0&&(l+=o);let n=0,h=0;for(s||(s=1/0);h<e&&n<s;)for(let c=0;c<t.length;c++){const f=t[c],u=c%2===0;let d=h,v=h+f-l;if(v>e&&(v=e),u&&v>d){const g=(d+r)%e,y=(v+r)%e;a.push({start:g,end:y,isDash:!0}),n+=1}if(h=v,l=0,h>=e||n>=s)break}return a}function Ki(e,t=0){const i=e.calculative.worldAnchors;if(!i||i.length<2)return null;const s={x:i[0].x,y:i[0].y},r=h=>h&&{...h,x:h.x-s.x,y:h.y-s.y};let a,o=null;if(i.forEach(h=>{if(o){const c=r(o);c.next=r(o.next);const f=r(h);f.prev=r(h.prev),a=$s(a,c,c.next,f.prev,f)}o=h}),e.close){const h=i[0],c=r(o);c.next=r(o.next);const f=r(h);f.prev=r(h.prev),a=$s(a,c,c.next,f.prev,f)}let l=0;e.animateReverse?l=e.length-e.calculative.animatePos-t*e.calculative.canvas.store.data.scale:l=e.calculative.animatePos-t*e.calculative.canvas.store.data.scale;const n=ln(a,l);return n?(n.x+=s.x,n.y+=s.y,n):null}function Nr(e,t){const i=t.calculative.canvas.store;e.save(),e.lineWidth=1,e.fillStyle=t.activeColor||i.styles.activeColor,t.calculative.worldAnchors.forEach(s=>{!s.hidden&&!s.isTemp&&_o(e,s,t)}),e.restore()}function _o(e,t,i){if(!t)return;const s=i.calculative.canvas.store.activeAnchor===i.calculative.activeAnchor&&i.calculative.activeAnchor===t;let r=3;i.calculative.lineWidth>3&&(r=i.calculative.lineWidth),i.anchorRadius&&(r=i.anchorRadius),t.radius&&(r=t.radius),s?(t.prev&&(e.save(),e.strokeStyle="#4dffff",e.beginPath(),e.moveTo(t.prev.x,t.prev.y),e.lineTo(t.x,t.y),e.stroke(),e.restore(),e.save(),e.fillStyle="#ffffff",e.beginPath(),e.arc(t.prev.x,t.prev.y,r,0,Math.PI*2),e.fill(),e.stroke(),e.restore()),t.next&&(e.save(),e.strokeStyle="#4dffff",e.beginPath(),e.moveTo(t.x,t.y),e.lineTo(t.next.x,t.next.y),e.stroke(),e.restore(),e.save(),e.fillStyle="#ffffff",e.beginPath(),e.arc(t.next.x,t.next.y,r,0,Math.PI*2),e.fill(),e.stroke(),e.restore(),e.beginPath(),e.arc(t.x,t.y,r,0,Math.PI*2),e.fill(),e.stroke()),e.beginPath(),e.arc(t.x,t.y,r,0,Math.PI*2),e.fill(),e.stroke()):(e.save(),e.fillStyle="#ffffff",e.beginPath(),e.arc(t.x,t.y,r,0,Math.PI*2),e.fill(),e.stroke(),e.restore())}function Fr(e){const t=e.calculative.canvas.store;let i={x:e.x,y:e.y};if(!e.parentId||e.parentId&&!t.pens[e.parentId])e.parentId=void 0,i.width=e.width,i.height=e.height,i.rotate=e.rotate,bt(i),yt(i),e.pivot&&Qi(i,e.pivot);else{const s=t.pens[e.parentId];let r=s.calculative.worldRect;r||(r=Fr(s)),i.x=r.x+r.width*e.x,i.y=r.y+r.height*e.y,i.width=r.width*e.width,i.height=r.height*e.height,s.flipX&&(i.x=r.width-(i.x-r.x+i.width)+r.x),s.flipY&&(i.y=r.height-(i.y-r.y+i.height)+r.y),bt(i),i.rotate=r.rotate+e.rotate,yt(i),e.pivot&&Qi(i,e.pivot)}return e.calculative.worldRect=i,us(e,i),i}function us(e,t){!e.paddingTop&&(e.calculative.paddingTop=0),!e.paddingBottom&&(e.calculative.paddingBottom=0),!e.paddingLeft&&(e.calculative.paddingLeft=0),!e.paddingRight&&(e.calculative.paddingRight=0),Math.abs(e.calculative.paddingTop)<1&&(e.calculative.paddingTop*=t.height),Math.abs(e.calculative.paddingBottom)<1&&(e.calculative.paddingBottom*=t.height),Math.abs(e.calculative.paddingLeft)<1&&(e.calculative.paddingLeft*=t.width),Math.abs(e.calculative.paddingRight)<1&&(e.calculative.paddingRight*=t.width)}function fi(e){const t=K(e.calculative.worldRect);if(delete t.pivot,!e.parentId){Object.assign(e,t);return}const s=e.calculative.canvas.store.pens[e.parentId].calculative.worldRect;Object.assign(e,ce(t,s))}function Le(e){const t=e.calculative.canvas.store;let i=[];if(e.anchors){let s=K(e.anchors);e.flipX&&e.name!=="line"&&s.forEach(r=>{r.x=.5-(r.x-.5)}),e.flipY&&e.name!=="line"&&s.forEach(r=>{r.y=.5-(r.y-.5)}),s.forEach(r=>{i.push(Eo(e,r))})}if(!i.length&&!e.type&&!e.calculative.canvas.parent.isCombine(e)){const{x:s,y:r,width:a,height:o}=e.calculative.worldRect;for(let l=0;l<t.options.defaultAnchors.length;l++){const n=t.options.defaultAnchors[l];i.push({id:`${l}`,penId:e.id,x:s+a*n.x,y:r+o*n.y})}}e.calculative.rotate&&e.name!=="line"&&i.forEach(s=>{vt(s,e.calculative.rotate,e.calculative.worldRect.pivot||e.calculative.worldRect.center)}),(!e.type||e.anchors)&&(e.calculative.worldAnchors=i),e.calculative.activeAnchor&&i.length&&(e.calculative.activeAnchor=i.find(s=>{s.id,e.calculative.activeAnchor.id})),e.calculative.gradientAnimatePath=void 0}function zr(e){var t;if((t=e.children)!=null&&t.length){let i=e.calculative.worldRect;e.children.forEach(s=>{const r=e.calculative.canvas.store.pens[s];r.calculative.initRect&&r.calculative.initRelativeRect&&(r.calculative.initRect.x=i.x+i.width*r.calculative.initRelativeRect.x,r.calculative.initRect.y=i.y+i.height*r.calculative.initRelativeRect.y,r.calculative.initRect.ex=r.calculative.initRect.x+i.width*r.calculative.initRelativeRect.width,r.calculative.initRect.ey=r.calculative.initRect.y+i.height+r.calculative.initRelativeRect.height,yt(r.calculative.initRect)),zr(r)})}}function Eo(e,t){const i={...t},{x:s,y:r,width:a,height:o}=e.calculative.worldRect;return i.x=s+a*t.x,i.y=r+o*t.y,t.prev&&(i.prev={penId:e.id,connectTo:t.prev.connectTo,x:s+a*t.prev.x,y:r+o*t.prev.y}),t.next&&(i.next={penId:e.id,connectTo:t.next.connectTo,x:s+a*t.next.x,y:r+o*t.next.y}),i}function Ms(e,t){if(!t.image&&!t.icon&&!t.thumbImg)return;const{paddingTop:i,paddingBottom:s,paddingLeft:r,paddingRight:a}=t.calculative;let o=r,l=i,n=t.calculative.worldRect.width-r-a,h=t.calculative.worldRect.height-i-s,c=t.calculative.iconLeft||0,f=t.calculative.iconTop||0;c&&Math.abs(c)<1&&(c=t.calculative.worldRect.width*c),f&&Math.abs(f)<1&&(f=t.calculative.worldRect.height*f),o+=c||0,l+=f||0,n-=c||0,h-=f||0;let u=t.calculative.iconRotate||0;if(t.parentId){const d=e[t.parentId].calculative;d&&(u+=d.rotate,u%=360)}o=t.calculative.worldRect.x+o,l=t.calculative.worldRect.y+l,t.calculative.worldIconRect={x:o,y:l,width:n,height:h,rotate:u},bt(t.calculative.worldIconRect),yt(t.calculative.worldIconRect)}function zt(e,t,i){De(e.calculative.worldRect,t,i,e.pivot),e.calculative.initRect&&De(e.calculative.initRect,t,i,e.pivot),e.calculative.prevFrameRect&&De(e.calculative.prevFrameRect,t,i,e.pivot),jr(e,t,i),e.calculative.x&&Pe(e.calculative,t,i),e.type&&Le(e)}function jr(e,t,i){var s;e&&(s=e.children)!=null&&s.length&&e.children.forEach(r=>{const a=e.calculative.canvas.store.pens[r];a&&(a.calculative.initRect&&De(a.calculative.initRect,t,i),jr(a,t,i))})}function Mo(e,t){e.anchors||(e.anchors=[]),e.calculative.worldAnchors||(e.calculative.worldAnchors=[]);const i={id:t.id,penId:e.id,x:t.x,y:t.y};if(e.calculative.worldAnchors.push(i),e.calculative.worldRect){e.rotate%360&&vt(t,-e.rotate,e.calculative.worldRect.center);const s={id:t.id,penId:e.id,x:(t.x-e.calculative.worldRect.x)/e.calculative.worldRect.width,y:(t.y-e.calculative.worldRect.y)/e.calculative.worldRect.height};e.anchors.push(s)}return i}function Lo(e,t,i){e.anchors||(e.anchors=[]),e.calculative.worldAnchors||(e.calculative.worldAnchors=[]);const s=tn(e,t,i);return e.calculative.worldAnchors.splice(i+1,0,s),e.anchors.splice(i+1,0,Xe(s,e.calculative.worldRect)),e.calculative.activeAnchor=s,s}function Do(e,t){if(!e||!e.calculative.worldAnchors)return;let i=e.calculative.worldAnchors.findIndex(s=>s.id===t.id);i>-1&&e.calculative.worldAnchors.splice(i,1),i=e.anchors.findIndex(s=>s.id===t.id),i>-1&&e.anchors.splice(i,1)}function Oe(e,t){if(!t||!t.calculative||!t.calculative.worldRect.center)return nt.None;if(e.anchorId){let i=t.anchors.filter(s=>s.id===e.anchorId);if(i.length&&i[0].direction>-1)return i[0].direction}return Ia(e,t.calculative.worldRect.center)}function _e(e,t){let i=1/0,s;return e.calculative.worldAnchors.forEach(r=>{const a=Mi(t,r);i>a&&(i=a,s=r)}),s}function Ls(e,t,i){e.x+=t,e.y+=i,e.anchors&&e.anchors.forEach(s=>{Ye(s,t,i)}),e.calculative.worldAnchors&&e.calculative.worldAnchors.forEach(s=>{Ye(s,t,i)})}function ds(e){if(e&&e.calculative&&e.calculative.worldAnchors.length){let t=dt(e);if(!e.anchors||!e.anchors.length)for(;e.calculative.worldAnchors.length&&t!==e.calculative.activeAnchor;)e.calculative.worldAnchors.pop(),t=dt(e);else t===e.calculative.activeAnchor?e.calculative.worldAnchors=[e.calculative.worldAnchors[0]]:e.calculative.worldAnchors[0]===e.calculative.activeAnchor&&(e.calculative.worldAnchors=[e.calculative.worldAnchors[e.calculative.worldAnchors.length-1]])}}function Tt(e,t,i,s){var l,n,h,c,f,u;if(!e||!t||!i||!s||t.twoWay===At.DisableConnected||t.twoWay===At.Disable||s.twoWay===At.DisableConnectTo||s.twoWay===At.Disable)return;if(t.twoWay===At.In){if(i.calculative.worldAnchors.length===1)return;const d=dt(i);if(s.id!==d.id)return}if(t.twoWay===At.Out){const d=xt(i);if(s.id!==d.id)return}if(s.connectTo===e.id&&s.anchorId===t.id)return;if(s.connectTo){const d=e.calculative.canvas.store.pens[s.connectTo];Ee(d,fe(d,s.anchorId),i,s)}e.connectedLines||(e.connectedLines=[]),e.connectedLines.findIndex(d=>d.lineId===i.id&&d.lineAnchor===s.id&&d.anchor===t.id)<0&&e.connectedLines.push({lineId:i.id,lineAnchor:s.id,anchor:t.id}),s.connectTo=e.id,s.anchorId=t.id,e.type&&Tt(i,s,e,t),e.calculative.canvas.store.emitter.emit("connectLine",{line:i,lineAnchor:s,pen:e,anchor:t});let a=((l=i.calculative.worldAnchors)==null?void 0:l.length)>=2?(n=i.calculative.worldAnchors)==null?void 0:n[0].connectTo:void 0,o=((h=i.calculative.worldAnchors)==null?void 0:h.length)>=2?(f=i.calculative.canvas.store.pens[(c=i.calculative.worldAnchors)==null?void 0:c[0].connectTo])==null?void 0:f.anchors.find(d=>{var v;return d.id===((v=i.calculative.worldAnchors)==null?void 0:v[0].anchorId)}):void 0;return(u=e.onConnectLine)==null||u.call(e,e,{line:i,lineAnchor:s,pen:e,anchor:t,fromPen:a,fromAnchor:o}),!0}function Ee(e,t,i,s){if(!(!e||!t||!i||!s)&&!(!e.connectedLines||!e.connectedLines.length))return i.lastConnected||(i.lastConnected={}),i.lastConnected[e.id]||(i.lastConnected[e.id]=K(e.connectedLines)),e.connectedLines.forEach((r,a,o)=>{(r.lineId===i.id||r.lineId===i.id)&&r.lineAnchor===s.id&&r.anchor===t.id&&o.splice(a,1)}),s.connectTo=void 0,s.anchorId=void 0,e.type&&t.connectTo===i.id&&t.anchorId===s.id&&Ee(i,s,e,t),e.calculative.canvas.store.emitter.emit("disconnectLine",{line:i,lineAnchor:s,pen:e,anchor:t}),!0}function fe(e,t){var i;if(!(!e||!t))return(i=e.calculative.worldAnchors)==null?void 0:i.find(s=>s.id===t)}function xt(e){if(!(!e||!e.calculative.worldAnchors))return e.calculative.worldAnchors[0]}function dt(e){if(!(!e||!e.calculative.worldAnchors))return e.calculative.worldAnchors[e.calculative.worldAnchors.length-1]}function Oo(e,t){var r,a;if(e.calculative.start===0||!e.frames||!e.frames.length)return e.calculative.start=void 0,0;if(!e.calculative.duration){e.calculative.duration=0;for(const o of e.frames){e.calculative.duration+=o.duration;for(const l in o)l!=="duration"&&!e[l]&&l==="scale"&&(e[l]=1)}}if(e.animateCycle||(e.animateCycle=1/0),e.calculative.start){let o=0;const l=Math.ceil((t-e.calculative.start)/e.calculative.duration);if(l>e.animateCycle)return e.currentAnimation=void 0,e.calculative.start=void 0,Os(e,1),0;const n=(t-e.calculative.start)%e.calculative.duration||e.calculative.duration;let h=0;for(const u of e.frames)if(h+=u.duration,n>h)e.frames[o].switch||(e.calculative.prevFrameRect=K(e.calculative.worldRect),e.frames[o].switch=!0),++o;else break;if(!e.frames[o])return!0;let c=!1;o!==e.calculative.frameIndex&&(c=!0,e.calculative.frameIndex=o,e.calculative.frameDuration=e.frames[o].duration,o>0&&(e.calculative.frameStart+=e.frames[o-1].duration),e.calculative.frameEnd=e.calculative.frameStart+e.calculative.frameDuration);let f=!1;if(l>e.calculative.cycleIndex&&(e.frames.forEach(u=>{u.switch=!1}),e.calculative.worldRect=K(e.calculative.initRect),e.calculative.prevFrameRect=K(e.calculative.initRect),e.calculative.cycleIndex=l,e.calculative.frameStart=e.calculative.start+e.calculative.duration*(l-1),f=!0),c||f)if(e.calculative.x=e.calculative.initRect.x,e.calculative.y=e.calculative.initRect.y,(a=e.children)!=null&&a.length&&!e.parentId?e.calculative.canvas.rotatePen(e,(e.calculative.initRect.rotate||0)-(e.calculative.rotate||0),e.calculative.initRect):e.calculative.rotate=e.calculative.initRect.rotate||0,o>0){e.prevFrame={};const u=e.frames[o-1];for(const d in u)e.prevFrame[d]=u[d];Object.assign(e.prevFrame,{rotate:u.rotate||0,x:u.x||0,y:u.y||0,scale:u.scale||1})}else Ds(e)}else{if(e.calculative.start=t,e.calculative.frameIndex=0,e.calculative.frameStart=e.calculative.start,e.calculative.frameDuration=e.frames[0].duration,e.calculative.frameEnd=e.calculative.frameStart+e.calculative.frameDuration,e.calculative.cycleIndex=1,e.calculative.x=e.calculative.worldRect.x,e.calculative.y=e.calculative.worldRect.y,e.calculative.initRect=K(e.calculative.worldRect),e.calculative.prevFrameRect=K(e.calculative.worldRect),e.parentId&&(e.calculative.initRelativeRect={x:e.x,y:e.y,width:e.width,height:e.height}),(r=e.children)!=null&&r.length){const o=e.calculative.canvas.store;e.calculative.childrenVisible={},e.children.forEach(l=>{e.calculative.childrenVisible[l]=o.pens[l].visible})}e.calculative.initRect.rotate=e.calculative.rotate||0,Ds(e)}const i=e.frames[e.calculative.frameIndex];let s=0;if(i.curveAnimate){const o=(t-e.calculative.frameStart)/e.calculative.frameDuration%1;let l=[];i.animateTimingFunction?l=Array.isArray(i.animateTimingFunction)?i.animateTimingFunction:i.animateTimingFunction.split(","):l=[.25,.25,.75,.75],s=Rr(o,l[1],l[3])}else s=(t-e.calculative.frameStart)/e.calculative.frameDuration%1;return s>0&&Os(e,s),!0}function Ds(e){e.prevFrame={};for(const t in e)(typeof e[t]!="object"||t==="lineDash")&&(e.prevFrame[t]=e[t]);e.prevFrame.rotate=0,e.prevFrame.x=0,e.prevFrame.y=0,e.prevFrame.scale=1}function Os(e,t){var r,a,o,l,n,h;if(t<0)return;t>1&&(t=1);const i=e.frames[e.calculative.frameIndex],s=e.calculative.canvas.store.data.scale;for(const c in i)if(c!=="duration"){if(c==="scale"){e.calculative.worldRect=K(e.calculative.prevFrameRect),De(e.calculative.worldRect,e.prevFrame.scale,e.calculative.worldRect.center);const f=e.prevFrame.scale+(i[c]-e.prevFrame.scale)*t;De(e.calculative.worldRect,f/e.prevFrame.scale,e.calculative.worldRect.center),e.calculative.patchFlags=!0}else if(c==="x"){const f=ze(e,c,e.calculative.frameIndex)*s;e.calculative.worldRect.x=e.calculative.initRect.x+f,e.calculative.worldRect.ex=e.calculative.initRect.ex+f,e.calculative.worldRect.center.x=e.calculative.initRect.center.x+f,(r=e.calculative.worldRect.pivot)!=null&&r.x&&(e.calculative.worldRect.pivot.x=((a=e.calculative.initRect.pivot)==null?void 0:a.x)+f),ye(e.calculative.worldRect,i[c]*t*s,0),e.calculative.patchFlags=!0}else if(c==="y"){const f=ze(e,c,e.calculative.frameIndex)*s;e.calculative.worldRect.y=e.calculative.initRect.y+f,e.calculative.worldRect.ey=e.calculative.initRect.ey+f,e.calculative.worldRect.center.y=e.calculative.initRect.center.y+f,(o=e.calculative.worldRect.pivot)!=null&&o.x&&(e.calculative.worldRect.pivot.y=((l=e.calculative.initRect.pivot)==null?void 0:l.y)+f),ye(e.calculative.worldRect,0,i[c]*t*s),e.calculative.patchFlags=!0}else if(c==="width"){const f=ze(e,c,e.calculative.frameIndex)*s;e.calculative.worldRect.width=e.calculative.initRect.width+f,e.calculative.worldRect.ex=e.calculative.initRect.ex+f,e.calculative.worldRect.center.x=e.calculative.initRect.center.x+f;let u=i[c]*t*s;e.calculative.worldRect.width+=u,e.calculative.worldRect.ex+=u,e.calculative.worldRect.center.x+=u,e.calculative.patchFlags=!0}else if(c==="height"){const f=ze(e,c,e.calculative.frameIndex)*s;e.calculative.worldRect.height=e.calculative.initRect.height+f,e.calculative.worldRect.ey=e.calculative.initRect.ey+f,e.calculative.worldRect.center.y=e.calculative.initRect.center.y+f;let u=i[c]*t*s;e.calculative.worldRect.height+=u,e.calculative.worldRect.ey+=u,e.calculative.worldRect.center.y+=u,e.calculative.patchFlags=!0}else if(c==="rotate"){e.prevFrame[c]>=360&&(e.prevFrame[c]%=360);const f=ze(e,c,e.calculative.frameIndex),u=(e.calculative.initRect.rotate+f+i[c]*t)%360-(e.calculative.rotate||0);(n=e.children)!=null&&n.length?e.calculative.canvas.rotatePen(e,u,e.calculative.initRect):e.calculative.rotate=(e.calculative.initRect.rotate+f+i[c]*t)%360,e.calculative.patchFlags=!0}else if(c==="image")e.image=i.image,e.calculative.image=void 0,e.calculative.canvas.loadImage(e),e.canvasLayer===ht.CanvasImageBottom?e.calculative.canvas.canvasImageBottom.init():e.canvasLayer===ht.CanvasImage&&e.calculative.canvas.canvasImage.init();else if(Bo(i[c],c,e)){e.prevFrame[c]==null&&(c==="globalAlpha"?e.prevFrame[c]=1:e.prevFrame[c]=0);const f=e.prevFrame[c]+(i[c]-e.prevFrame[c])*t;e.calculative[c]=Math.round(f*100)/100}else{if(c==="visible"&&!e.calculative.image){if((h=e.children)!=null&&h.length){const u=Pt(e,e.calculative.canvas.store);e.calculative.canvas.initImageCanvas(u)}}e.calculative[c]=i[c];const f={};f[c]=i[c],fs(e,f)}c==="text"&&Ne(e)}}function Bo(e,t,i){const s=["strokeType","bkType","showChild"];return typeof e=="number"&&i.linear!==!1&&!s.includes(t)}function No(e,t){if(e.calculative.start===0)return e.calculative.start=void 0,e.calculative.cycleStart=void 0,0;e.animateCycle||(e.animateCycle=1/0),e.animateSpan||(e.animateSpan=1);const i=(t-e.calculative.cycleStart)/1e3;if(e.curveAnimate){let s=[];e.animateTimingFunction?s=Array.isArray(e.animateTimingFunction)?e.animateTimingFunction:e.animateTimingFunction.split(","):s=[.25,.25,.75,.75];const r=e.duration||5,a=i/r,o=Rr(a,s[1],s[3]);e.calculative.animatePos=o*e.length}else e.calculative.animatePos+=e.animateSpan*(e.calculative.canvas.store.data.scale||1);if(e.calculative.cycleStart||(e.calculative.cycleStart=t),!e.calculative.start)e.calculative.start=Date.now(),e.calculative.animatePos=e.animateSpan*(e.calculative.canvas.store.data.scale||1),e.calculative.cycleIndex=1;else if(e.calculative.animatePos>e.length||e.curveAnimate&&i>e.duration){if(++e.calculative.cycleIndex,e.calculative.cycleIndex>e.animateCycle)return e.currentAnimation=void 0,e.calculative.start=void 0,e.calculative.cycleStart=void 0,0;e.calculative.cycleStart=void 0,e.calculative.animatePos=e.animateSpan}return!0}function Ae(e,t=!0){if(!e.children||e.childActive===!1)return;const i=e.calculative.canvas.store;e.children.forEach(s=>{const r=i.pens[s];r&&(r.calculative.active=t,Ae(r,t))})}function qe(e,t=!0){if(!e)return;const i=e.calculative.canvas.store;e.calculative.hover=t,e.childHover!==!1&&e.children&&e.children.forEach(s=>{var r,a;((r=i.pens[s])==null?void 0:r.hoverColor)==null&&((a=i.pens[s])==null?void 0:a.hoverBackground)==null&&qe(i.pens[s],t)})}function Ct(e,t){if(!t)return;const i=e.calculative.canvas.store,s=e.calculative.worldRect;if(t.style.opacity=e.globalAlpha+"",t.style.position="absolute",t.style.outline="none",t.style.left=s.x+i.data.x+"px",t.style.top=s.y+i.data.y+"px",t.style.width=s.width+"px",t.style.height=s.height+"px",e.name==="iframe"?t.style.opacity=e.calculative.inView?"1":"0":t.style.display=e.calculative.inView!=!1?e.calculative.cssDisplay||"inline":"none",!e.calculative.rotate&&(e.calculative.rotate=0),t.style.transform=`rotate(${e.calculative.rotate}deg)`,e.calculative.rotate||(e.calculative.flipX&&(t.style.transform="rotateY(180deg)"),e.calculative.flipY&&(t.style.transform="rotateX(180deg)"),e.calculative.flipX&&e.calculative.flipY&&(t.style.transform="rotateZ(180deg)")),t.style.zIndex=e.calculative.zIndex!==void 0?e.calculative.zIndex+"":"5",e.calculative.zIndex>e.calculative.canvas.maxZindex&&(e.calculative.canvas.maxZindex=e.calculative.zIndex),e.locked===ct.DisableEdit||e.locked===ct.DisableMove||i.data.locked?(t.style.userSelect="initial",t.style.pointerEvents="initial",e.name==="gif"&&(t.style.userSelect="none",t.style.pointerEvents="none")):(t.style.userSelect="none",t.style.pointerEvents="none"),e.className&&(t.className=e.className),e.styles)for(let r in e.styles)t.style[r]=e.styles[r]}async function Fo(e,t){if(t&&globalThis.html2canvas){const i=await globalThis.html2canvas(t);if(i){const s=new Image;s.src=i.toDataURL("image/png",.1),s.src.length>10&&(e.calculative.img=s)}}}function zi(e){return e.every(t=>t.locked)}function Bs(e){return e.every(t=>t.disableRotate)}function Wr(e,t,i){var s;e.rotateByRoot||(e.name==="line"?(e.calculative.worldAnchors.forEach(r=>{vt(r,t,i.center)}),zo(e),fi(e)):(e.calculative.rotate?e.calculative.rotate+=t:e.calculative.rotate=t,vt(e.calculative.worldRect.center,t,i.center),e.parentId&&(e.calculative.worldRect.x=e.calculative.worldRect.center.x-e.calculative.worldRect.width/2,e.calculative.worldRect.y=e.calculative.worldRect.center.y-e.calculative.worldRect.height/2,e.x=(e.calculative.worldRect.x-i.x)/i.width,e.y=(e.calculative.worldRect.y-i.y)/i.height)),(s=e.children)==null||s.forEach(r=>{const a=e.calculative.canvas.store.pens[r];Wr(a,t,i)}))}function zo(e){var r;if(!((r=e.calculative.worldAnchors)!=null&&r.length)||!isFinite(e.x)||!isFinite(e.x)||e.x==null||e.y==null)return;const t=Ji(e);e.parentId||Object.assign(e,t);const{fontSize:i,lineHeight:s}=e.calculative.canvas.store.options;e.fontSize?e.fontSize<0&&(e.fontSize=0,e.calculative.fontSize=0):(e.fontSize=i>=0?i:12,e.calculative.fontSize=e.fontSize*e.calculative.canvas.store.data.scale),e.lineHeight||(e.lineHeight=s,e.calculative.lineHeight=e.lineHeight),yt(t),e.calculative.worldRect=t,us(e,t),Yt(e),e.calculative.worldAnchors&&(e.anchors=e.calculative.worldAnchors.map(a=>Xe(a,e.calculative.worldRect)))}function Ns(e){return e.every(t=>t.disableSize||t.pivot)}function ze(e,t,i){if(!e.frames||!t)return 0;let s=0;for(let r=0;r<i;r++)e.frames[r]&&(s+=e.frames[r][t]||0);return s}function Ti(e,t){var s;let i=e;for(;i&&i.parentId;){const r=i;i=t.pens[i.parentId];const a=(s=i==null?void 0:i.calculative)==null?void 0:s.showChild;if(a!=null&&i.children[a]!==r.id)return!1}return!0}function Xt(e,t=!1){var r,a,o;const{store:i,canvasRect:s}=e.calculative.canvas;if(t&&((r=e.children)==null||r.forEach(l=>{const n=i.pens[l];n&&Xt(n,!0)})),e.calculative.inView=!0,Ti(e,i)?(e.visible==!1||e.calculative.visible==!1)&&(e.calculative.inView=!1,(e.canvasLayer===ht.CanvasImageBottom||e.canvasLayer===ht.CanvasImage)&&((a=e.frames)!=null&&a.length)&&(e.calculative.inView=e.frames.some(l=>l.hasOwnProperty("visible")))):e.calculative.inView=!1,e.calculative.inView){const{x:l,y:n,width:h,height:c,rotate:f}=e.calculative.worldRect,u={x:l+i.data.x,y:n+i.data.y,width:h,height:c,rotate:f};bt(u),ee(u,s)||(e.calculative.inView=!1)}i.data.locked&&e.calculative.inView&&(e.calculative.inView=Hr(e,i.options.roles)),(o=e.calculative.singleton)!=null&&o.div&&Ct(e,e.calculative.singleton.div)}function Hr(e,t){var i;return(i=e.roles)!=null&&i.length?t!=null&&t.length?t==null?void 0:t.some(s=>e.roles.includes(s)):!1:e.parentId?Hr(Mt(e,!1),t):e.calculative.inView}function jo(e,t,i){if(t.fillWorldTextRect){e.save(),e.fillStyle="#c3deb7";const{x:s,y:r,width:a,height:o}=i.calculative.worldTextRect;e.fillRect(s,r,a,o),e.restore()}}function be(e,t){const i=t.calculative.globalAlpha;typeof i=="number"&&i<1&&!isNaN(i)&&(e.globalAlpha=i)}function Vr(e,t){const i=Wo(e,t)||it.canvasDraws[t.name];i&&(e.save(),i(e,t),e.restore())}function Wo(e,t){const i=t.drawCommand;if(!(!i||t.name==="line"))return(s,r)=>{i.forEach(a=>{try{a.steps=a.steps.flat(1/0),a.steps.reduce((o,l)=>{const n=Ho(l,r,o.x,o.y);try{if(n.c){if(n.c.startsWith("_")){const c=n.c.split("_")[1];return typeof n.v.value=="number"&&(n.v.value*=r.calculative.canvas.store.data.scale),(n.p||s)[c]=n.v.value,{x:o.x,y:o.y}}let h=[];for(const c in n.v)h.push(n.v[c]);return(n.p||s)[n.c](...h),{x:n.startX||n.v.x,y:n.startY||n.v.y}}return{x:o.x,y:o.y}}catch{}},{})}catch{}}),s.stroke()}}function Ho(e,t,i,s){var a;const r={visio:qo,dxf:Vo,canvas:Uo};return((a=r[t.parseType])==null?void 0:a.call(r,e,t,i,s))||e}function Vo(e,t,i,s){const{x:r,y:a,width:o,height:l}=t.calculative.worldRect,{originWidth:n,originHeight:h}=t.dxfOrigin;switch(e.c){case"beginPath":return{c:"beginPath",v:{}};case"closePath":return{c:"closePath",v:{}};case"moveTo":return{c:"moveTo",v:{x:e.v.x*(o/n)+r,y:e.v.y*(l/h)+a}};case"lineTo":return{c:"lineTo",v:{x:e.v.x*(o/n)+r,y:e.v.y*(l/h)+a}};case"arc":return{c:"ellipse",v:{x:e.v.x*(o/n)+r,y:e.v.y*(l/h)+a,rx:e.v.xr*(o/n),ry:e.v.yr*(l/h),rotation:e.v.rotation||0,startAngle:e.v.startAngle,endAngle:e.v.endAngle,a:e.v.aclockwise??!0}};case"ellipse":return{c:"ellipse",v:{x:e.v.x*(o/n)+r,y:e.v.y*(l/h)+a,rx:e.v.xr*(o/n),ry:e.v.yr*(l/h),rotation:e.v.rotation||0,startAngle:e.v.startAngle,endAngle:e.v.endAngle,a:e.v.aclockwise??!0}};case"_font":return{c:"_font",v:{value:e.v.fontSize*t.calculative.canvas.store.data.scale+"px "+(e.v.fontFamily||t.calculative.canvas.store.options.fontFamily)}};case"_fillStyle":return{c:"_fillStyle",v:{value:t.color||e.v.value}};default:const c={c:e.c,v:{...e.v}};return c.v.x!==void 0&&(c.v.x=e.v.x*(o/n)+r),c.v.y!==void 0&&(c.v.y=e.v.y*(l/h)+a),c}}function Uo(e,t,i,s){const{x:r,y:a,width:o,height:l}=t.calculative.worldRect,{originWidth:n,originHeight:h}=t.origin;switch(e.c){case"beginPath":return{c:"beginPath",v:{}};case"closePath":return{c:"closePath",v:{}};case"moveTo":return{c:"moveTo",v:{x:e.v.x*(o/n)+r,y:e.v.y*(l/h)+a}};case"lineTo":return{c:"lineTo",v:{x:e.v.x*(o/n)+r,y:e.v.y*(l/h)+a}};case"arc":return{c:"ellipse",v:{x:e.v.x*(o/n)+r,y:e.v.y*(l/h)+a,rx:e.v.xr*(o/n),ry:e.v.yr*(l/h),rotation:e.v.rotation||0,startAngle:e.v.startAngle,endAngle:e.v.endAngle,a:e.v.aclockwise??!0}};case"ellipse":return{c:"ellipse",v:{x:e.v.x*(o/n)+r,y:e.v.y*(l/h)+a,rx:e.v.xr*(o/n),ry:e.v.yr*(l/h),rotation:e.v.rotation||0,startAngle:e.v.startAngle,endAngle:e.v.endAngle,a:e.v.aclockwise??!0}};case"_font":return{c:"_font",v:{value:e.v.fontSize*t.calculative.canvas.store.data.scale+"px "+(e.v.fontFamily||t.calculative.canvas.store.options.fontFamily)}};default:const c={c:e.c,v:{...e.v}};return c.v.x!==void 0&&(c.v.x=e.v.x*(o/n)+r),c.v.y!==void 0&&(c.v.y=e.v.y*(l/h)+a),c}}function qo(e,t,i,s){const{x:r,y:a,width:o,height:l}=t.calculative.worldRect,{width:n,height:h}=t.origin;switch(e.c){case"MoveTo":return{c:"moveTo",v:{x:+e.v.X*100*(o/n)+r,y:+e.v.Y*100*(l/h)+a}};case"RelMoveTo":return{c:"moveTo",v:{x:+e.v.X*n*(o/n)+r,y:+e.v.Y*h*(l/h)+a}};case"LineTo":return{c:"lineTo",v:{x:+e.v.X*100*(o/n)+r,y:+e.v.Y*100*(l/h)+a}};case"RelLineTo":return{c:"lineTo",v:{x:+e.v.X*n*(o/n)+r,y:+e.v.Y*h*(l/h)+a}};case"Ellipse":let c=e.v.X,f=e.v.Y,u=Math.abs(e.v.A-e.v.C),d=Math.abs(e.v.B-e.v.D);return{c:"ellipse",v:{x:c*100*(o/n)+r,y:f*100*(l/h)+a,radiuX:u*100*(o/n),radiuY:d*100*(l/h),rotation:0,startAngle:0,endAngle:Math.PI*2,anticlockwise:!0}};case"EllipticalArcTo":const v=e.v.X*100*(o/n)+r,g=e.v.Y*100*(l/h)+a,y=e.v.A*100*(o/n)+r,p=e.v.B*100*(l/h)+a;e.v.C;const b=e.v.D*(o/l)*(h/n),m=(v-i)*(p-s)-(g-s)*(y-i)>0,k=Fs(i,s,v,g,y,p,b);return!e.orign&&(e.orign={}),!e.orign.startA&&(e.orign.startA=ai(k.x0,k.y0,i,s)),!e.orign.endA&&(e.orign.endA=ai(k.x0,k.y0,v,g)),{c:"ellipse",v:{centerX:k.x0,centerY:k.y0,radiuX:k.a,radiuY:k.b,rotation:0,startAngle:e.orign.startA,endAngle:e.orign.endA,anticlockwise:m},startX:v,startY:g};case"RelEllipticalArcTo":const A=e.v.X*n*(o/n)+r,S=e.v.Y*h*(l/h)+a,I=e.v.A*n*(o/n)+r,E=e.v.B*h*(l/h)+a;e.v.C;const z=e.v.D*(o/l)*(h/n),U=(A-i)*(E-s)-(S-s)*(I-i)>0,T=Fs(i,s,A,S,I,E,z);return!e.orign&&(e.orign={}),!e.orign.startA&&(e.orign.startA=ai(T.x0,T.y0,i,s)),!e.orign.endA&&(e.orign.endA=ai(T.x0,T.y0,A,S)),{c:"ellipse",v:{centerX:T.x0,centerY:T.y0,radiuX:T.a,radiuY:T.b,rotation:0,startAngle:e.orign.startA,endAngle:e.orign.endA,anticlockwise:U},startX:A,startY:S};case"ArcTo":let R=e.v.X*100*o/n+r,C=e.v.Y*100*l/h+a,_=e.v.A*100*t.calculative.canvas.store.data.scale,B=(i+R)/2,j=(s+C)/2,X=Math.sqrt((R-i)**2+(C-s)**2);if(Math.abs(_)<.001||X<.001)return{c:"lineTo",v:{x:R,y:C}};let F=X*X/(8*Math.abs(_))+Math.abs(_)/2,L=-(C-s)/X,N=(R-i)/X,W=F-Math.abs(_),O=B-Math.sign(_)*L*W,q=j-Math.sign(_)*N*W,$=Math.atan2(s-q,i-O),Y=Math.atan2(C-q,R-O),Z=Y-$;for(;Z>Math.PI;)Z-=2*Math.PI;for(;Z<-Math.PI;)Z+=2*Math.PI;let J=_>0;return(J&&Z>0||!J&&Z<0)&&([$,Y]=[Y,$],J=!J),{c:"arc",v:{x:O,y:q,radius:F,startAngle:$,endAngle:Y,anticlockwise:J},startX:R,startY:C};default:const Q=K(e);return Object.entries(Q.v).forEach(([w,x])=>{var P,M;(P=w.endsWith)!=null&&P.call(w,"_x")?typeof x=="number"&&(Q.v[w]=x*(o/n)+r):(M=w.endsWith)!=null&&M.call(w,"_y")?typeof x=="number"&&(Q.v[w]=x*(l/h)+a):typeof x=="number"&&(Q.v[w]=x)}),Q}}function $o(e,t){e.filter=t.filter}function fs(e,t){for(const i in t)mr.includes(i)&&(i=="fontSize"&&t[i]<0&&(t[i]=0),e[i]=t[i],["fontSize","lineWidth"].includes(i)?(e.calculative[i]=t[i]*e.calculative.canvas.store.data.scale,Yt(e)):e.calculative[i]=t[i]),e.image&&e.name!=="gif"&&yr.includes(i)&&(e.calculative.canvas.store.patchFlagsTop=!0,e.calculative.canvas.store.patchFlagsBackground=!0,e.calculative.imageDrawed=!1);if(e.calculative.canvas.parent.isCombine(e)){const i=e.children;i==null||i.forEach(s=>{let r=K(t);e.calculative.childrenVisible&&e.calculative.childrenVisible[s]===!1&&delete r.visible;const a=e.calculative.canvas.store.pens[s];a&&fs(a,r)})}}function Fs(e,t,i,s,r,a,o){let l=(e-i)*(e+i)*(s-a)-(i-r)*(i+r)*(t-s)+o*o*(t-s)*(s-a)*(t-a),n=2*((e-i)*(s-a)-(i-r)*(t-s)),h=l/n,c=(e-i)*(i-r)*(e-r)+o*o*((i-r)*(t-s)*(t+s)-(e-i)*(s-a)*(s+a)),f=2*o*o*((i-r)*(t-s)-(e-i)*(s-a)),u=c/f,d=Math.sqrt(Math.pow(e-h,2)+Math.pow(o*(t-u),2)),v=d/o;return{x0:h,y0:u,a:d,b:v}}function ai(e,t,i,s){let r=i-e,a=s-t,o=Math.atan2(a,r);return o<0&&(o+=2*Math.PI),o}function zs(e,t,i){let s,r,a=1/0,o=1/0;const l=8;for(const n of e.data.pens){if(n.calculative.inView===!1)continue;vs(n).forEach(c=>{if(c===t||c===i)return;let f=(n.calculative.worldRect.center.x-t.x)*(n.calculative.worldRect.center.x-t.x)+(n.calculative.worldRect.center.y-t.y)*(n.calculative.worldRect.center.y-t.y);const u=Math.abs(c.x-t.x);u>0&&u<l&&f<a&&(s={x:Math.round(c.x)+.5,y:Math.round(c.y)+.5,prev:{x:Math.round(t.x)+.5,y:Math.round(t.y)+.5},step:c.x-t.x},a=f);const d=Math.abs(c.y-t.y);d>0&&d<l&&f<o&&(r={x:Math.round(c.x)+.5,y:Math.round(c.y)+.5,prev:{x:Math.round(t.x)+.5,y:Math.round(t.y)+.5},step:c.y-t.y},o=f)})}return{xDock:s,yDock:r}}function Yo(e,t,i,s){let r=[];return i.length===1?(r=K(vs(i[0])),r.forEach(a=>{a.x+=s.x,a.y+=s.y})):(yt(t),r=[t.center,...re(t)]),Ur(e,r,t,!0)}function vs(e){if(e.type){if(e.type===ut.Line)return e.calculative.worldAnchors}else{const t=re(e.calculative.worldRect);return yt(e.calculative.worldRect),[...e.calculative.worldAnchors,...t,e.calculative.worldRect.center]}}function Xo(e,t,i,s){const r=re(t);return Ur(e,r,t)}function Ur(e,t,i,s=!1){let r,a,o=1/0,l=1/0;const n=10,h=vn(i,n);return e.data.pens.forEach(c=>{const{inView:f,worldRect:u,active:d}=c.calculative;if(f===!1||!s&&d||fn(h,u)||c.type&&e.active.some(g=>qr(e,g,c)))return;const v=vs(c);if(v)for(const g of v)for(const y of t){const p=g.x-y.x,b=g.y-y.y,m=Math.abs(p),k=Math.abs(b);i.center||(i.center={x:i.x+i.width/2,y:i.y+i.height/2}),m<n&&m<o&&(r={x:Math.round(g.x)+.5,y:Math.round(g.y)+.5,step:p,prev:{x:Math.round(y.x)+.5,y:Math.round(y.y)+.5},penId:c.id,anchorId:y.id,dockAnchorId:g.id},o=m),k<n&&k<l&&(a={x:Math.round(g.x)+.5,y:Math.round(g.y)+.5,step:b,prev:{x:Math.round(y.x)+.5,y:Math.round(y.y)+.5},penId:c.id,anchorId:y.id,dockAnchorId:g.id},l=k)}}),{xDock:r,yDock:a}}function qr(e,t,i){if(!i.type)return!1;if(Array.isArray(t==null?void 0:t.connectedLines)){for(const s of t==null?void 0:t.connectedLines)if(s.lineId===i.id)return!0}if(Array.isArray(t==null?void 0:t.children))for(const s of t.children){const r=e.pens[s];if(qr(e,r,i))return!0}return!1}function Gi(e,t){return e.toFixed(12)==t}function Ko(e,t=4){let i=e.map(h=>h.calculative.worldRect);const s=i.map(h=>h.x),r=i.map(h=>h.y),a=s.reduce((h,c)=>h+c,0)/s.length,o=r.reduce((h,c)=>h+c,0)/r.length,l=Math.sqrt(s.map(h=>Math.pow(h-a,2)).reduce((h,c)=>h+c,0)/s.length),n=Math.sqrt(r.map(h=>Math.pow(h-o,2)).reduce((h,c)=>h+c,0)/r.length);return e.filter(h=>{let c=h.calculative.worldRect;const f=(c.x-a)/l,u=(c.y-o)/n;return Math.sqrt(f*f+u*u)>t})}function js(e){if(e.id=lt(),Array.isArray(e.anchors))for(const t of e.anchors)e.type&&(t.id=lt()),t.penId=e.id,t.prev&&(e.type&&(t.prev.id=lt()),t.prev.penId=e.id),t.next&&(e.type&&(t.next.id=lt()),t.next.penId=e.id)}function Go(){let e=null,t=new WeakMap;return(i,s,r,a=!1)=>{if(t.has(i)&&t.get(i)?e=t.get(i):t.set(i,e=new Map),typeof r!="function")return()=>{console.warn("[rewritePenLifeCycle] warn: not a function ")};let o=new Set,l=new Map;e.has(s)&&e.get(s)?o=e.get(s):(l.set(s,i[s]),e.set(s,o)),a?o.delete(r):o.add(r);let n=l.get(s),h=(...c)=>{n==null||n(...c),o.forEach(f=>{f(...c)})};i[s]=h}}let Jo=Go();function Qo(e){return!e.name&&!e.install?(console.error("installPenPlugin Error: Validation Failed"),!1):!0}function Zo(e,t,i){if(t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),i)t.calculative.activeAnchor&&(t.calculative.activeAnchor.next={penId:t.id,x:i.x,y:i.y},Mi(t.calculative.activeAnchor.next,t.calculative.activeAnchor)<5?t.calculative.activeAnchor.next=void 0:(t.calculative.activeAnchor.prev={...t.calculative.activeAnchor.next},vt(t.calculative.activeAnchor.prev,180,t.calculative.activeAnchor)));else{const s=t.calculative.worldAnchors[0];if(!s.next){const a=Oe(s,e.pens[s.connectTo]);Ws(s,a,50),s.prev=void 0}const r=t.calculative.worldAnchors[t.calculative.worldAnchors.length-1];if(r&&r!==s&&!r.prev){const a=Oe(r,e.pens[r.connectTo]);Ws(r,a,-50),r.next=void 0}}}function Ws(e,t,i){switch(t){case nt.Up:e.prev={penId:e.penId,x:e.x,y:e.y+i},e.next={penId:e.penId,x:e.x,y:e.y-i};break;case nt.Right:e.prev={penId:e.penId,x:e.x-i,y:e.y},e.next={penId:e.penId,x:e.x+i,y:e.y};break;case nt.Bottom:e.prev={penId:e.penId,x:e.x,y:e.y-i},e.next={penId:e.penId,x:e.x,y:e.y+i};break;case nt.Left:e.prev={penId:e.penId,x:e.x+i,y:e.y},e.next={penId:e.penId,x:e.x-i,y:e.y};break}}function ge(e,t,i,s){const r=1-e,a=r*r*t.x+2*r*e*i.x+e*e*s.x,o=r*r*t.y+2*r*e*i.y+e*e*s.y;return{x:a,y:o,step:e}}function Ci(e,t,i,s,r){const{x:a,y:o}=t,{x:l,y:n}=r,{x:h,y:c}=i,{x:f,y:u}=s,d=1-e,v=a*d*d*d+3*h*e*d*d+3*f*e*e*d+l*e*e*e,g=o*d*d*d+3*c*e*d*d+3*u*e*e*d+n*e*e*e;return{x:v,y:g,step:e}}function ne(e,t,i){return{x:e.x+i*(t.x-e.x),y:e.y+i*(t.y-e.y)}}function tn(e,t,i){let s=e.calculative.worldAnchors[i],r=e.calculative.worldAnchors[i+1];!r&&e.close&&(r=e.calculative.worldAnchors[0]);const a=t.step;let o;if(s.next&&r.prev){const l=s,n=s.next,h=r.prev,c=r,f=ne(l,n,a),u=ne(n,h,a),d=ne(h,c,a),v=ne(f,u,a),g=ne(u,d,a);o=ne(v,g,a),v.penId=e.id,o.prev=v,g.penId=e.id,o.next=g,s.next.x=f.x,s.next.y=f.y,r.prev.x=d.x,r.prev.y=d.y}else if(s.next||r.prev){const l=s,n=s.next||r.prev,h=r,c=ne(l,n,a),f=ne(n,h,a);o=t,c.penId=e.id,f.penId=e.id,o.prev=c,o.next=f,s.next=void 0,r.prev=void 0}else o=t;return o.penId=e.id,o.id=lt(),o.prevNextType=pe.Bilateral,o}function en(e,t,i){if(t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),t.calculative.worldAnchors.length<2)return;let s=t.calculative.activeAnchor,r=i||dt(t);if(!s||!r)return;const a=20,o=e.pens[s.connectTo];let l=Oe(s,o);switch(l===nt.None&&(r.x>s.x?l=nt.Right:l=nt.Left),s.next={id:lt(),penId:t.id,x:s.x,y:s.y,prevNextType:2},r.prev={id:lt(),penId:t.id,x:r.x,y:r.y,prevNextType:2},l){case nt.Up:s.next.y-=a,r.prev.y=s.y;break;case nt.Bottom:s.next.y+=a,r.prev.y=s.y;break;case nt.Left:s.next.x-=a,r.prev.x=s.x;break;default:s.next.x+=a,r.prev.x=s.x;break}}function sn(e,t){const i=t||new Path2D;if((e.lineName==="line"||e.lineName==="polyline")&&e.calculative.lineSmooth){let r=hs(e);if(i instanceof Path2D&&i.addPath(r),i instanceof Path2D)return i}const s=e.calculative.worldAnchors;if(s.length>1){let r;s.forEach(a=>{r?Hs(i,r,a):a.start=!0,r=a}),e.close&&(e.lineName==="curve"?Hs(i,r,s[0]):i.closePath())}if(i instanceof Path2D)return i}function rn(e,t,i){var a;if(t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),t.calculative.worldAnchors.length<2||((a=t.anchors)==null?void 0:a.length)>1)return;const s=xt(t),r=dt(t);!s||!r||!r.id||s===r||(s.next=void 0,ds(t),r.prev=void 0,t.calculative.worldAnchors.push(r))}function Hs(e,t,i){!i||i.isTemp||(t.start&&e.moveTo(t.x,t.y),t.next?i.prev?e.bezierCurveTo(t.next.x,t.next.y,i.prev.x,i.prev.y,i.x,i.y):e.quadraticCurveTo(t.next.x,t.next.y,i.x,i.y):i.prev?e.quadraticCurveTo(i.prev.x,i.prev.y,i.x,i.y):e.lineTo(i.x,i.y))}function Ji(e){return Si(e),Ze(gs(e))}function gs(e){const t=[];let i;return e.calculative.worldAnchors.forEach(s=>{i&&t.push(...Vs(i,s,e)),t.push(s),i=s}),e.close&&e.calculative.worldAnchors.length>1&&t.push(...Vs(i,e.calculative.worldAnchors[0],e)),t}function Ai(e){return e!=null&&e.lineWidth?e.lineWidth/2+4:4}function Vs(e,t,i){const s=[];if(!t)return s;let r=.02;if(e.lineLength&&!i.parentId&&(r=Ai(i)/e.lineLength),e.next)if(t.prev)for(let a=r;a<1;a+=r)s.push(Ci(a,e,e.next,t.prev,t));else for(let a=r;a<1;a+=r)s.push(ge(a,e,e.next,t));else if(t.prev)for(let a=r;a<1;a+=r)s.push(ge(a,e,t.prev,t));else s.push({x:t.x,y:t.y});return s.length>1&&(e.curvePoints=s),s}function an(e,t){const i=Ai(t);let s=0,r,a;for(const o of t.calculative.worldAnchors){if(r){if(a=Us(e,r,o,i),a)return{i:s,point:a};++s}r=o}if(t.close&&t.calculative.worldAnchors.length>1&&(a=Us(e,r,t.calculative.worldAnchors[0],i)))return{i:s,point:a}}function Us(e,t,i,s=4){if(!t.next&&!i.prev){const{x:r,y:a}=t,{x:o,y:l}=i,n=Math.min(r,o),h=Math.max(r,o),c=Math.min(a,l),f=Math.max(a,l);return e.x>=n-s&&e.x<=h+s&&e.y>=c-s&&e.y<=f+s?on(e,t,i,s):void 0}else if(t.curvePoints){for(const r of t.curvePoints)if(Ce(e,r,s))return r}}function on(e,t,i,s=4){if(t.x===i.x){if(Math.abs(e.x-t.x)<=s)return{x:t.x,y:e.y}}else{const r=(t.y-i.y)/(t.x-i.x),a=t.y-r*t.x;if(Math.abs((r*e.x+a-e.y)/Math.sqrt(r*r+1))<=s){const n=(e.x+r*e.y-r*a)/(r*r+1);return{x:n,y:r*n+a}}}}function qs(e,t,i,s){if(!t&&!i)return Math.sqrt(Math.pow(Math.abs(e.x-s.x),2)+Math.pow(Math.abs(e.y-s.y),2))||0;const r=document.createElementNS("http://www.w3.org/2000/svg","path");return t&&i?r.setAttribute("d",`M${e.x} ${e.y} C${t.x} ${t.y} ${i.x} ${i.y} ${s.x} ${s.y}`):t?r.setAttribute("d",`M${e.x} ${e.y} Q${t.x} ${t.y} ${s.x} ${s.y}`):r.setAttribute("d",`M${e.x} ${e.y} Q${i.x} ${i.y} ${s.x} ${s.y}`),r.getTotalLength()||0}function Si(e){if(e.calculative.worldAnchors.length<2)return 0;let t=0,i;if(e.calculative.worldAnchors.forEach(s=>{i&&(i.lineLength=qs(i,i.next,s.prev,s),t+=i.lineLength),i=s}),e.close){const s=xt(e);i.lineLength=qs(i,i.next,s.prev,s),t+=i.lineLength}return e.calculative.animatePos&&(e.calculative.animatePos=t/e.length*e.calculative.animatePos),e.length=t,t}function ji(e,t){const i=e.calculative.worldAnchors;for(let s=0;s<i.length-1;s++){const r=i[s],a=i[s+1];if(!r.next&&!a.prev){if($r(r,a,t))return!0}else if(nn(r,a,t))return!0}return!1}function $r(e,t,i){if(xe(e,i)||xe(t,i))return!0;const s=e.x,r=e.y,a=t.x,o=t.y;let l=i.x,n=i.y,h=i.ex,c=i.ey;const f=r-o,u=a-s,d=s*o-a*r;if(f*l+u*n+d>=0&&f*h+u*c+d<=0||f*l+u*n+d<=0&&f*h+u*c+d>=0||f*l+u*c+d>=0&&f*h+u*n+d<=0||f*l+u*c+d<=0&&f*h+u*n+d>=0){if(l>h){const v=l;l=h,h=v}if(n<c){const v=n;n=c,c=v}return!(s<l&&a<l||s>h&&a>h||r>n&&o>n||r<c&&o<c)}else return!1}function nn(e,t,i){if(!e.next&&!t.prev)return $r(e,t,i);if(e.next&&t.prev)for(let r=.02;r<1;r+=.02){const a=Ci(r,e,e.next,t.prev,t);if(xe(a,i))return!0}else if(e.next||t.prev)for(let r=.02;r<1;r+=.02){const a=ge(r,e,e.next||t.prev,t);if(xe(a,i))return!0}return!1}function $s(e,t,i,s,r){let a="";return e||(a+=`M${t.x} ${t.y} `,e=document.createElementNS("http://www.w3.org/2000/svg","path"),e.setAttribute("d",a)),a=e.getAttribute("d")||"",i&&s?a+=`C${i.x} ${i.y} ${s.x} ${s.y} ${r.x} ${r.y}`:i?a+=`Q${i.x} ${i.y} ${r.x} ${r.y}`:a+=`Q${(s==null?void 0:s.x)||t.x} ${(s==null?void 0:s.y)||t.y} ${r.x} ${r.y}`,e.setAttribute("d",a),e}function ln(e,t){const i=e.getTotalLength();if(t<0||t>i)return null;const s=Math.max(.01,i*1e-4),r=e.getPointAtLength(t),a=e.getPointAtLength(t-s),o=Math.atan2(r.y-a.y,r.x-a.x);return{x:r.x,y:r.y,rotate:o/Math.PI*180,progress:t/i}}function cn(e){const t=e.lineAnimateType;return t==null?!1:(Array.isArray(t)?t:[t]).some(s=>s===pt.Arrow||s===pt.WaterDrop)}function hn(e,t,i){e.beginPath(),e.moveTo(0,0),e.lineTo(-t,-i),e.moveTo(0,0),e.lineTo(-t,i),e.stroke()}function un(e,t,i,s,r,a){e.save(),e.translate(t,i),e.rotate(s),hn(e,r,a),e.restore()}function Ys(e,t,i){let s=0,r=t.length-1;for(;r-s>1;){const d=s+r>>1;t[d]<=i?s=d:r=d}const a=s,o=e[a],l=e[a+1],n=t[a+1]-t[a],h=n>1e-6?(i-t[a])/n:0,c=o.x+h*(l.x-o.x),f=o.y+h*(l.y-o.y),u=Math.atan2(l.y-o.y,l.x-o.x);return{x:c,y:f,ang:u}}function Yr(e,t,i){if(t.type!==ut.Line||!(t.dirMarkers||i.options.dirMarkers)||t.calculative.pencil)return;const r=t.calculative.worldAnchors;if(!r||r.length<2||t.calculative.animatePos&&cn(t))return;const a=i.options.drawDirMarkers;e.save(),e.setLineDash([]),e.shadowBlur=0,e.shadowColor="",e.shadowOffsetX=0,e.shadowOffsetY=0;const o=gs(t);if(o.length<2){e.restore();return}const l=i.data.scale,n=(t.dirMarkerInterval??i.options.dirMarkerInterval??40)*l,h=t.dirMarkerColor??i.options.dirMarkerColor??"#ffffff",c=t.calculative.lineWidth||2,f=(t.dirMarkerLineWidth??i.options.dirMarkerLineWidth)!=null?(t.dirMarkerLineWidth??i.options.dirMarkerLineWidth)*l:Math.min(c*.38,Math.max(.75,c*.14)),u=[0];let d=0;for(let g=0;g<o.length-1;g++){const y=o[g+1].x-o[g].x,p=o[g+1].y-o[g].y;d+=Math.sqrt(y*y+p*p),u.push(d)}if(d<=1e-6){e.restore();return}let v=[];for(let g=n/2;g<d;g+=n)v.push(g);if((v.length===0||v.length===1)&&(v=[d/2]),a){e.strokeStyle=h,e.lineWidth=f,e.lineJoin="round",e.lineCap="round";for(const g of v){const{x:y,y:p,ang:b}=Ys(o,u,g);a(e,y,p,b,h,t)}}else{const y=Math.max(0,c-f)*.38,p=c*.52;e.strokeStyle=h,e.lineWidth=f,e.lineJoin="round",e.lineCap="round";for(const b of v){const{x:m,y:k,ang:A}=Ys(o,u,b);un(e,m,k,A,p,y)}}e.restore()}function Jt(e,t){if(!t)return;if(t.ex==null&&bt(t),!t.rotate||t.rotate%360===0)return e.x>t.x&&e.x<t.ex&&e.y>t.y&&e.y<t.ey;t.center||yt(t);const i=[{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 i.forEach(s=>{vt(s,t.rotate,t.pivot||t.center)}),dn(e,i)}function xe(e,t,i=0){const{x:s,y:r,ex:a,ey:o}=t;return e.x>=s-i&&e.x<=a+i&&e.y>=r-i&&e.y<=o+i}function yt(e){e.center||(e.center={}),e.center.x=e.x+e.width/2,e.center.y=e.y+e.height/2}function bt(e){e.ex=e.x+e.width,e.ey=e.y+e.height}function Qi(e,t){e.pivot||(e.pivot={}),e.pivot.x=e.x+e.width*t.x,e.pivot.y=e.y+e.height*t.y}function dn(e,t){if(t.length<3)return!1;let i=!1,s=t[t.length-1];for(const r of t)s.y>e.y!=r.y>e.y&&r.x+(e.y-r.y)*(s.x-r.x)/(s.y-r.y)>e.x&&(i=!i),s=r;return i}function Vt(e){const t=[];e.forEach(s=>{if(s.isRuleLine)return;const r=s.calculative.worldRect;if(r){const a=re(r);t.push(...a)}});const i=Ze(t);return yt(i),i}function re(e){const t=[{x:e.x,y:e.y},{x:e.ex,y:e.y},{x:e.ex,y:e.ey},{x:e.x,y:e.ey}];return e.rotate&&(e.center||yt(e),t.forEach(i=>{vt(i,e.rotate,e.pivot||e.center)})),t}function Ze(e){let t=1/0,i=1/0,s=-1/0,r=-1/0;return e==null||e.forEach(a=>{!isFinite(a.x)||!isFinite(a.y)||(t=Math.min(t,a.x),i=Math.min(i,a.y),s=Math.max(s,a.x),r=Math.max(r,a.y))}),{x:t,y:i,ex:s,ey:r,width:s-t,height:r-i}}function ee(e,t,i){return e.rotate&&(e=Ze(re(e))),i?e.x>t.x&&e.ex<t.ex&&e.y>t.y&&e.ey<t.ey:!(e.x>t.ex||e.ex<t.x||e.ey<t.y||e.y>t.ey)}function fn(e,t){return(t.x>e.ex||t.ex<e.x)&&(t.y>e.ey||t.ey<e.y)}function vn(e,t){const i=Zt(t),s={x:e.x-i[3],y:e.y-i[0],width:e.width+i[1]+i[3],height:e.height+i[0]+i[2]};return bt(s),s}function ye(e,t,i){e.x+=t,e.y+=i,e.ex+=t,e.ey+=i,e.center&&(e.center.x+=t,e.center.y+=i),e.pivot&&(e.pivot.x+=t,e.pivot.y+=i)}function gn(e,t){const i=(e.to.y-e.from.y)/(e.to.x-e.from.x),s=(t.to.y-t.from.y)/(t.to.x-t.from.x);return Zi({k:i,point:e.from},{k:s,point:t.from})}function Zi(e,t){if(Gi(e.k,0))return{x:t.point.x,y:e.point.y};if(Gi(t.k,0))return{x:e.point.x,y:t.point.y};const i=e.point.y-e.k*e.point.x,r=(t.point.y-t.k*t.point.x-i)/(e.k-t.k),a=e.k*r+i;return{x:r,y:a}}function yn(e,t){const i=gn({from:e[0],to:e[2]},{from:e[1],to:e[3]});for(const s of e)vt(s,-t,i);return Ze(e)}function Xs(e,t,i,s){let r=e.rotate?e.rotate%360:0;if(r){const a=re(e),o=(a[0].y-a[1].y)/(a[0].x-a[1].x),l=(a[1].y-a[2].y)/(a[1].x-a[2].x);if(s<4){if(a[s].x+=t,e.ratio)if(s===0||s===2){let c=t*Math.tan((90-(360-r)-Math.atan(e.width/e.height)/Math.PI*180)/180*Math.PI);a[s].y+=c}else{let c=t*Math.tan((90-(360-r)+Math.atan(e.width/e.height)/Math.PI*180)/180*Math.PI);a[s].y+=c}else a[s].y+=i;const h=a[(s+2)%4];a[(s+1)%4]=Zi({k:s%2?l:o,point:a[s]},{k:s%2?o:l,point:h}),a[(s+4-1)%4]=Zi({k:s%2?o:l,point:a[s]},{k:s%2?l:o,point:h})}else{const h=[4,6].includes(s)?l:o;Gi(h,0)?(a[s%4].x+=t,a[(s+1)%4].x+=t):(a[s%4].y+=i,a[s%4].x+=i/h,a[(s+1)%4].y+=i,a[(s+1)%4].x+=i/h)}if((a[0].x-a[1].x)**2+(a[0].y-a[1].y)**2<25||(a[1].x-a[2].x)**2+(a[1].y-a[2].y)**2<25)return;const n=yn(a,e.rotate);yt(n),Object.assign(e,n);return}switch(s){case 0:if(e.width-t<5||e.height-i<5)break;e.x+=t,e.y+=i,e.width-=t,e.height-=i;break;case 1:if(e.width+t<5||e.height-i<5)break;e.ex+=t,e.y+=i,e.width+=t,e.height-=i;break;case 2:if(e.width+t<5||e.height+i<5)break;e.ex+=t,e.ey+=i,e.width+=t,e.height+=i;break;case 3:if(e.width-t<5||e.height+i<5)break;e.x+=t,e.ey+=i,e.width-=t,e.height+=i;break;case 4:if(e.height-i<5)break;e.y+=i,e.height-=i;break;case 5:if(e.width+t<5)break;e.ex+=t,e.width+=t;break;case 6:if(e.height+i<5)break;e.ey+=i,e.height+=i;break;case 7:if(e.width-t<5)break;e.x+=t,e.width-=t;break}}function De(e,t,i,s){e&&(e.width*=t,e.height*=t,Pe(e,t,i),bt(e),yt(e),s&&Qi(e,s))}function ce(e,t){const i={x:(e.x-t.x)/t.width,y:(e.y-t.y)/t.height,width:e.width/t.width,height:e.height/t.height};return bt(i),i}function Xe(e,t){const{x:i,y:s,width:r,height:a}=t,{penId:o,connectTo:l}=e,n=Object.assign({},e,{x:r?(e.x-i)/r:0,y:a?(e.y-s)/a:0});return e.prev&&(n.prev={penId:o,connectTo:l,x:r?(e.prev.x-i)/r:0,y:a?(e.prev.y-s)/a:0}),e.next&&(n.next={penId:o,connectTo:l,x:r?(e.next.x-i)/r:0,y:a?(e.next.y-s)/a:0}),n}function mn(e,t){let i=!1;for(let s=0,r=t.length-1;s<t.length;r=s++){let a=t[s].x,o=t[s].y,l=t[r].x,n=t[r].y;o>e.y!=n>e.y&&e.x<(l-a)*(e.y-o)/(n-o)+a&&(i=!i)}return i}const pn=/^[\t\n\f\r ]*([MLHVZCSQTAmlhvzcsqta])[\t\n\f\r ]*/,Ks=/^[01]/,gt=/^[+-]?(([0-9]*\.[0-9]+)|([0-9]+\.)|([0-9]+))([eE][+-]?[0-9]+)?/,wn=/^(([\t\n\f\r ]+,?[\t\n\f\r ]*)|(,[\t\n\f\r ]*))/,bn={M:[gt,gt],L:[gt,gt],H:[gt],V:[gt],Z:[],C:[gt,gt,gt,gt,gt,gt],S:[gt,gt,gt,gt],Q:[gt,gt,gt,gt],T:[gt,gt],A:[gt,gt,gt,Ks,Ks,gt,gt]};function xn(e){let t=0;const i=[];for(;t<e.length;){const s=e.slice(t).match(pn);if(s!==null){const r=s[1];t+=s[0].length;const a=Cn(r,e,t);t=a.cursor,i.push(...a.commands)}else throw new Error("malformed path (first error at "+t+")")}return{commands:i}}function Gs(e){let t=1/0,i=1/0,s=-1/0,r=-1/0;return Sn(e),e.commands.forEach(a=>{a.worldPoints.forEach((o,l)=>{l%2===0?(o<t&&(t=o),o>s&&(s=o)):(o<i&&(i=o),o>r&&(r=o))})}),{x:t,y:i,ex:s,ey:r,width:s-t+1,height:r-i+1}}function kn(e,t,i){i==null&&(i=t),e.commands.forEach((s,r)=>{if(!(s.relative&&r))switch(s.key){case"A":case"a":s.values[5]+=t,s.values[6]+=i;break;case"V":case"v":s.values[0]+=i;break;default:s.values.forEach((a,o)=>{s.values[o]=a+(o%2===0?t:i)});break}})}function Rn(e,t,i){i==null&&(i=t),e.commands.forEach(s=>{switch(s.key){case"A":case"a":const r=s.values[0],a=s.values[1],o=Math.PI*s.values[2]/180,l=Math.cos(o),n=Math.sin(o),h=a*a*i*i*l*l+r*r*i*i*n*n,c=2*t*i*l*n*(a*a-r*r),f=r*r*t*t*l*l+a*a*t*t*n*n,u=-(r*r*a*a*t*t*i*i),d=c*c-4*h*f,v=Math.sqrt((h-f)*(h-f)+c*c);s.values[2]=c!==0?Math.atan((f-h-v)/c)*180/Math.PI:h<f?0:90,s.values[0]=-Math.sqrt(2*d*u*(h+f+v))/d,s.values[1]=-Math.sqrt(2*d*u*(h+f-v))/d,s.values[5]*=t,s.values[6]*=i,s.values[4]=t*i>=0?s.values[4]:1-s.values[4];break;case"V":case"v":s.values[0]*=i;break;default:s.values.forEach((g,y)=>{s.values[y]=g*(y%2===0?t:i)});break}})}function Tn(e){let t="";return e.commands.forEach(i=>{t+=i.key+" ",i.values.forEach(s=>{t+=s+" "})}),t}function Cn(e,t,i){const s=bn[e.toUpperCase()],r=[];for(;i<=t.length;){const a={key:e,values:[]};for(const o of s){const l=t.slice(i).match(o);if(l!==null){a.values.push(+l[0]),i+=l[0].length;const n=t.slice(i).match(wn);n!==null&&(i+=n[0].length)}else{if(a.values.length===0)return{cursor:i,commands:r};throw new Error("malformed path (first error at "+i+")")}}if(a.relative=a.key.toUpperCase()!==a.key,r.push(a),s.length===0)return{cursor:i,commands:r};e==="m"&&(e="l"),e==="M"&&(e="L")}throw new Error("malformed path (first error at "+i+")")}function An(e,t){const i=[];let s=e.relative&&t?{x:t.worldPoints[t.worldPoints.length-2],y:t.worldPoints[t.worldPoints.length-1]}:{x:0,y:0};for(let r=0;r<e.values.length-1;r+=2)i.push(s.x+e.values[r]),i.push(s.y+e.values[r+1]);e.worldPoints=i}function Js(e,t,i,s,r,a,o,l,n){const h=Math.cos(o),c=Math.sin(o),f=(e-i)/2,u=(t-s)/2,d=h*f+c*u,v=-c*f+h*u;let g=r*r,y=a*a;const p=d*d,b=v*v,m=p/g+b/y;if(m>1){const B=Math.sqrt(m);r*=B,a*=B,g=r*r,y=a*a}const k=Math.sqrt(Math.max(0,(g*y-g*b-y*p)/(g*b+y*p))),A=l===n?-k:k,S=A*r*v/a,I=-A*a*d/r,E=h*S-c*I+(e+i)/2,z=c*S+h*I+(t+s)/2;let U=Math.atan2(v-I,d-S),R=Math.atan2(-v-I,-d-S)-U;n===0&&R>0?R-=2*Math.PI:n===1&&R<0&&(R+=2*Math.PI);const C=[e,t,i,s];function _(B){const j=U+R;let X=B;const F=2*Math.PI,L=Math.floor((U-X)/F);X+=L*F;const N=1e-10;let W;if(R>0?(W=X>=U-N&&X<=j+N||X+F>=U-N&&X+F<=j+N,X+F>=U-N&&X+F<=j+N&&(X+=F)):(W=X<=U+N&&X>=j-N||X-F<=U+N&&X-F>=j-N,X-F<=U+N&&X-F>=j-N&&(X-=F)),W){const O=Math.cos(X),q=Math.sin(X);C.push(E+r*O*h-a*q*c),C.push(z+r*O*c+a*q*h)}}if(Math.abs(h)>1e-10){const B=Math.atan(-a*c/(r*h));_(B),_(B+Math.PI)}else _(0),_(Math.PI);if(Math.abs(c)>1e-10){const B=Math.atan(a*h/(r*c));_(B),_(B+Math.PI)}else _(Math.PI/2),_(3*Math.PI/2);return C}function Sn(e){let t,i=0,s=0;e.commands.forEach(r=>{switch(r.key){case"Z":case"z":r.worldPoints=[i,s];break;case"H":r.worldPoints=[r.values[0],t.worldPoints[t.worldPoints.length-1]];break;case"h":r.worldPoints=[r.values[0]+t.worldPoints[t.worldPoints.length-2],t.worldPoints[t.worldPoints.length-1]];break;case"V":r.worldPoints=[t.worldPoints[t.worldPoints.length-2],r.values[0]];break;case"v":r.worldPoints=[t.worldPoints[t.worldPoints.length-2],r.values[0]+t.worldPoints[t.worldPoints.length-1]];break;case"A":r.worldPoints=Js(t.worldPoints[t.worldPoints.length-2],t.worldPoints[t.worldPoints.length-1],r.values[5],r.values[6],r.values[0],r.values[1],r.values[2]*Math.PI/180,r.values[3],r.values[4]);break;case"a":r.worldPoints=Js(t.worldPoints[t.worldPoints.length-2],t.worldPoints[t.worldPoints.length-1],t.worldPoints[t.worldPoints.length-2]+r.values[5],t.worldPoints[t.worldPoints.length-1]+r.values[6],r.values[0],r.values[1],r.values[2]*Math.PI/180,r.values[3],r.values[4]);break;default:An(r,t);break}(r.key==="M"||r.key==="m"||r.key==="Z"||r.key==="z")&&(i=r.worldPoints[r.worldPoints.length-2],s=r.worldPoints[r.worldPoints.length-1]),t=r})}function Pn(e,t){var n;const s=e.calculative.canvas.store.data.paths[e.pathId];if(!s)return new Path2D;const r=xn(s);e.calculative.svgRect=Gs(r),yt(e.calculative.svgRect),(e.calculative.svgRect.width!==e.calculative.worldRect.width||e.calculative.svgRect.height!==e.calculative.worldRect.height)&&Rn(r,e.calculative.worldRect.width/e.calculative.svgRect.width,e.calculative.worldRect.height/e.calculative.svgRect.height);const a=Gs(r);yt(a),kn(r,e.calculative.worldRect.x-a.x,e.calculative.worldRect.y-a.y);const o=Tn(r);if(t){(n=t.svgPath)==null||n.call(t,o);return}return new Path2D(o)}function In(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.moveTo(s+a/2,r),i.lineTo(s+a,r+o/2),i.lineTo(s+a/2,r+o),i.lineTo(s,r+o/2),i.lineTo(s+a/2,r),i.closePath(),i instanceof Path2D)return i}function _n(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.moveTo(s+a/2,r),i.lineTo(s+a,r+o),i.lineTo(s,r+o),i.lineTo(s+a/2,r),i.closePath(),i instanceof Path2D)return i}function En(e){const t=[{x:.5,y:0},{x:.75,y:.5},{x:.5,y:1},{x:.25,y:.5}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function Mn(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.moveTo(s+a/2,r),i.lineTo(s+a,r+o*2/5),i.lineTo(s+a*4/5,r+o),i.lineTo(s+a/5,r+o),i.lineTo(s,r+o*2/5),i.closePath(),i instanceof Path2D)return i}function Ln(e){const t=[{x:.5,y:0},{x:1,y:.4},{x:.8,y:1},{x:.2,y:1},{x:0,y:.4}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function Dn(e,t){e.onResize||(e.onResize=On);const i=t||new Path2D,{width:s,height:r,center:a}=e.calculative.worldRect,o=s>r?r:s,l=a.x,n=a.y,h=n-o/2,c=n-o/4,f=-(c-n)*Math.sin(Math.PI/180*324)+l,u=(c-n)*Math.cos(Math.PI/180*324)+n;i.moveTo(f,u);for(let d=0;d<5;++d)i.lineTo(-(h-n)*Math.sin(Math.PI/180*72*d)+l,(h-n)*Math.cos(Math.PI/180*72*d)+n),i.lineTo((f-l)*Math.cos(Math.PI/180*72*(d+1))-(u-n)*Math.sin(Math.PI/180*72*(d+1))+l,(f-l)*Math.sin(Math.PI/180*72*(d+1))+(u-n)*Math.cos(Math.PI/180*72*(d+1))+n);if(i.closePath(),i instanceof Path2D)return i}function Xr(e){const{width:t,height:i}=e,s=t>i?i:t,r=[];for(let a=0;a<5;++a)r.push({flag:1,id:String(a),penId:e.id,x:.5+s/2*Math.sin(Math.PI/180*72*a)/t,y:-s/2*Math.cos(Math.PI/180*72*a)/i+.5});e.anchors=r}function On(e){const t=e.anchors.filter(i=>i.flag!==1);Xr(e),e.anchors=e.anchors.concat(...t)}function Bn(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.moveTo(s+a/4,r),i.lineTo(s+a*3/4,r),i.lineTo(s+a,r+o/2),i.lineTo(s+a*3/4,r+o),i.lineTo(s+a*1/4,r+o),i.lineTo(s,r+o/2),i.lineTo(s+a/4,r),i.closePath(),i instanceof Path2D)return i}function Nn(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.moveTo(s,r+o/2),i.lineTo(s+o/2,r),i.lineTo(s+o/2,r+o/3),i.lineTo(s+a,r+o/3),i.lineTo(s+a,r+o*2/3),i.lineTo(s+o/2,r+o*2/3),i.lineTo(s+o/2,r+o*2/3),i.lineTo(s+o/2,r+o),i.closePath(),i instanceof Path2D)return i}function Fn(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.moveTo(s,r+o/3),i.lineTo(s+(a-o/2),r+o/3),i.lineTo(s+(a-o/2),r),i.lineTo(s+a,r+o/2),i.lineTo(s+(a-o/2),r+o),i.lineTo(s+(a-o/2),r+o*2/3),i.lineTo(s,r+o*2/3),i.closePath(),i instanceof Path2D)return i}function zn(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.moveTo(s,r+o/2),i.lineTo(s+o/2,r),i.lineTo(s+o/2,r+o/3),i.lineTo(s+(a-o/2),r+o/3),i.lineTo(s+(a-o/2),r),i.lineTo(s+a,r+o/2),i.lineTo(s+(a-o/2),r+o),i.lineTo(s+(a-o/2),r+o*2/3),i.lineTo(s+o/2,r+o*2/3),i.lineTo(s+o/2,r+o),i.closePath(),i instanceof Path2D)return i}function jn(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o,ey:l}=e.calculative.worldRect;if(i.moveTo(s,r),i.lineTo(s+a,r),i.lineTo(s+a,r+o*3/4),i.lineTo(s+a*8/16,r+o*3/4),i.lineTo(s+a/4,l),i.lineTo(s+a*5/16,r+o*3/4),i.lineTo(s,r+o*3/4),i.closePath(),i instanceof Path2D)return i}function Wn(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.moveTo(s+a/5,r+o*13/16),i.bezierCurveTo(s-a/15,r+o*13/16,s-a/15,r+o*7/16,s+a/5,r+o*7/16),i.bezierCurveTo(s+a/5,r,s+a*4/5,r,s+a*4/5,r+o*7/16),i.bezierCurveTo(s+a*16/15,r+o*7/16,s+a*16/15,r+o*13/16,s+a*4/5,r+o*13/16),i.closePath(),i instanceof Path2D)return i}function Hn(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:o,ey:l}=e.calculative.worldRect,n=a/6;if(i.moveTo(s,r),i.lineTo(o-n,r),i.lineTo(o,r+n),i.lineTo(o,l),i.lineTo(s,l),i.closePath(),i.moveTo(o-n,r),i.lineTo(o-n,r+n),i.lineTo(o,r+n),i.closePath(),i instanceof Path2D)return i}function Vn(e,t){const{x:i,y:s,width:r,ex:a,ey:o}=t.calculative.worldRect;let l=r*.25;const n=t.z;n>1?l=n*t.calculative.canvas.store.data.scale:n>0&&(l=r*n);const h={x:i,y:s+l},c={x:a-l,y:s+l},f={x:a-l,y:o};Wi(e,[h,c,f,{x:i,y:o}],t.backgroundFront||t.background,t.color),Wi(e,[h,{x:i+l,y:s},{x:a,y:s},c],t.backgroundUp||t.background,t.color),Wi(e,[c,{x:a,y:s},{x:a,y:o-l},f],t.backgroundRight||t.background,t.color)}function Wi(e,t,i="",s=""){e.save(),i&&(e.fillStyle=i),s&&(e.strokeStyle=s),e.beginPath();for(let r=0;r<t.length;++r)r?e.lineTo(t[r].x,t[r].y):e.moveTo(t[r].x,t[r].y);e.closePath(),i&&e.fill(),e.stroke(),e.restore()}function Un(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:o,ey:l}=e.calculative.worldRect,n=a/4,h=s+a/2;if(i.arc(h,r+n,n,0,Math.PI*2),i.moveTo(s,r+n*3),i.lineTo(o,r+n*3),i.moveTo(h,r+n*2),i.lineTo(h,r+n*4),i.moveTo(h,r+n*4),i.lineTo(s,l),i.moveTo(h,r+n*4),i.lineTo(o,l),i.closePath(),i instanceof Path2D)return i}let Dt=10;function qn(e,t,i){var g;if(t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),Dt=e.options.polylineSpace||10,t.calculative.worldAnchors.length<2)return;let s=xt(t),r=dt(t);if(!s||!r)return;let a;if((g=t.anchors)!=null&&g.length&&s===t.calculative.activeAnchor?(a=!0,s=r,r=xt(t)):(!t.anchors||!t.anchors.length)&&s!==t.calculative.activeAnchor&&(s=t.calculative.activeAnchor),!s||!r)return;s.next=void 0,r.prev=void 0;const o=r.connectTo;ds(t);const l=[],n=e.pens[s.connectTo],h=e.pens[r.connectTo],c=Oe(s,n),f=Oe(r,h);let u=Qs(s,c,Dt);u&&(s=u,l.push(u)),u=Qs(r,f,Dt);const d=r;let v;if(u&&(r=u,d.connectTo&&(u.y>d.y&&s.y<d.y||u.y<d.y&&s.y>d.y))){v=u;let y=Dt;s.x<u.x&&(y=-y),Math.abs(s.x-u.x)<y&&(y=-y),r={x:u.x+y,y:u.y,id:lt()}}switch(c){case nt.Up:l.push(...$n(s,r,f));break;case nt.Right:l.push(...Yn(s,r,f));break;case nt.Bottom:l.push(...Xn(s,r,f));break;case nt.Left:l.push(...Kn(s,r,f));break;default:l.push(...Gn(t,s,r));break}if(l.forEach(y=>{y.id=lt(),y.penId=t.id,t.calculative.worldAnchors.push(y)}),t.calculative.worldAnchors.push(r),v&&t.calculative.worldAnchors.push(v),u&&t.calculative.worldAnchors.push(d),a&&t.calculative.worldAnchors.reverse(),o){const y=t.calculative.worldAnchors.length-2;t.calculative.worldAnchors[y].isTemp=!1,t.calculative.worldAnchors[1].isTemp=!1}}function Qs(e,t,i){const s={x:e.x,y:e.y,id:lt()};switch(t){case nt.Up:s.y-=i;break;case nt.Right:s.x+=i;break;case nt.Bottom:s.y+=i;break;case nt.Left:s.x-=i;break;default:return}return s}function $n(e,t,i){if(e.x===t.x||e.y===t.y)return[];const s=[];let r,a;switch(i){case nt.Up:e.y<t.y?(r=t.x,a=e.y):(r=e.x,a=t.y),s.push({x:r,y:a});break;case nt.Bottom:if(r=t.x,a=e.y,t.y>e.y)r=e.x+(t.x-e.x)/2,s.push({x:r,y:e.y},{x:r,y:t.y});else{const o=(e.y+t.y)/2;s.push({x:e.x,y:o},{x:t.x,y:o})}break;case nt.Right:r=t.x,a=e.y,t.x<e.x&&t.y<e.y&&(r=e.x,a=t.y),s.push({x:r,y:a});break;case nt.Left:r=t.x,a=e.y,t.x>e.x&&t.y<e.y&&(r=e.x,a=t.y),s.push({x:r,y:a});break;default:if(t.y>e.y-Dt)r=e.x+(t.x-e.x)/2,s.push({x:r,y:e.y},{x:r,y:t.y});else{const o=(e.y+t.y+Dt)/2;s.push({x:e.x,y:o},{x:t.x,y:o})}break}return s}function Yn(e,t,i){if(e.x===t.x||e.y===t.y)return[];const s=[];let r,a;switch(i){case nt.Up:r=e.x,a=t.y,t.x>e.x&&t.y>e.y&&(r=t.x,a=e.y),s.push({x:r,y:a});break;case nt.Bottom:r=e.x,a=t.y,t.x>e.x&&t.y<e.y&&(r=t.x,a=e.y),s.push({x:r,y:a});break;case nt.Left:if(r=t.x,a=e.y,t.x<e.x)a=e.y+(t.y-e.y)/2,s.push({x:e.x,y:a},{x:t.x,y:a});else{const o=(e.x+t.x)/2;s.push({x:o,y:a},{x:o,y:t.y})}break;case nt.Right:t.x<e.x?s.push({x:e.x,y:t.y}):s.push({x:t.x,y:e.y});break;default:if(r=t.x,a=t.y,t.x<e.x+Dt)s.push({x:e.x,y:a});else{const o=(e.x+t.x-Dt)/2;s.push({x:o,y:e.y},{x:o,y:a})}break}return s}function Xn(e,t,i){if(e.x===t.x||e.y===t.y)return[];const s=[];let r,a;switch(i){case nt.Up:if(r=e.x,a=t.y,t.y<e.y)r=e.x+(t.x-e.x)/2,s.push({x:r,y:e.y},{x:r,y:t.y});else{const o=(e.y+t.y)/2;s.push({x:r,y:o},{x:t.x,y:o})}break;case nt.Right:r=t.x,a=e.y,t.x<e.x&&t.y>e.y&&(r=e.x,a=t.y),s.push({x:r,y:a});break;case nt.Bottom:e.y>t.y?(r=t.x,a=e.y):(r=e.x,a=t.y),s.push({x:r,y:a});break;case nt.Left:r=t.x,a=e.y,t.x>e.x&&t.y>e.y&&(r=e.x,a=t.y),s.push({x:r,y:a});break;default:if(r=e.x,t.y<e.y+Dt)r=e.x+(t.x-e.x)/2,s.push({x:r,y:e.y},{x:r,y:t.y});else{const o=(e.y+t.y-Dt)/2;s.push({x:r,y:o},{x:t.x,y:o})}break}return s}function Kn(e,t,i){if(e.x===t.x||e.y===t.y)return[];const s=[];let r,a;switch(i){case nt.Up:r=e.x,a=t.y,t.x<e.x&&t.y>e.y&&(r=t.x,a=e.y),s.push({x:r,y:a});break;case nt.Bottom:r=e.x,a=t.y,t.x<e.x&&t.y<e.y&&(r=t.x,a=e.y),s.push({x:r,y:a});break;case nt.Right:if(r=e.x,a=t.y,t.x>e.x)r=t.x,a=e.y+(t.y-e.y)/2,s.push({x:e.x,y:a},{x:t.x,y:a});else{const o=(e.x+t.x)/2;s.push({x:o,y:e.y},{x:o,y:t.y})}break;case nt.Left:t.x>e.x?s.push({x:e.x,y:t.y}):s.push({x:t.x,y:e.y});break;default:if(r=e.x,a=t.y,t.x<e.x-Dt){const o=(e.x+t.x+Dt)/2;s.push({x:o,y:e.y},{x:o,y:a})}else s.push({x:e.x,y:a});break}return s}function Gn(e,t,i){const s=[];e.calculative.drawlineH==null&&(e.calculative.drawlineH=Math.abs(i.x-t.x)>Math.abs(i.y-t.y));let r=e.calculative.worldAnchors.findIndex(a=>a.id==t.id);if(r>1){let a=e.calculative.worldAnchors[r-1];if(a.x===t.x&&a.y!==t.y)return s.push({x:i.x,y:t.y}),s;if(a.y===t.y&&a.x!==t.x)return s.push({x:t.x,y:i.y}),s}return e.calculative.worldAnchors.length&&(i.isTemp=void 0,e.calculative.drawlineH?(s.push({x:i.x,y:t.y}),Math.abs(i.y-t.y)<Dt&&(i.isTemp=!0)):(s.push({x:t.x,y:i.y}),Math.abs(i.x-t.x)<Dt&&(i.isTemp=!0))),s}function oi(e,t,i=!0){var r,a;let s=e.calculative.worldAnchors;i||(s=[],e.calculative.worldAnchors.forEach(o=>{s.unshift(o)}));for(let o=0;o<s.length&&s[o].id!==t.id;o++)if(s[o].y!==t.y||s[o].x===((r=s[o+1])==null?void 0:r.x)&&s[o].y!==((a=s[o+1])==null?void 0:a.y))return!1;return!0}function ni(e,t,i=!0){var r,a;let s=e.calculative.worldAnchors;i||(s=[],e.calculative.worldAnchors.forEach(o=>{s.unshift(o)}));for(let o=0;o<s.length&&s[o].id!==t.id;o++)if(s[o].x!==t.x||s[o].y===((r=s[o+1])==null?void 0:r.y)&&s[o].x!==((a=s[o+1])==null?void 0:a.x))return!1;return!0}function Jn(e,t,i){if(!e.calculative.worldAnchors)return;const s=e.calculative.worldAnchors.findIndex(n=>n.id===t.id),r=xt(e),a=dt(e);let o=e.calculative.worldAnchors[s-1],l=e.calculative.worldAnchors[s+1];if(e.calculative.h==null&&(r.connectTo&&(oi(e,t,!0)?e.calculative.h=!0:ni(e,t,!0)&&(e.calculative.h=!1)),e.calculative.h==null&&a.connectTo&&(oi(e,t,!1)?e.calculative.h=!0:ni(e,t,!1)&&(e.calculative.h=!1)),e.calculative.h==null&&(o?e.calculative.h=o.y===t.y:l&&(e.calculative.h=l.y===t.y))),e.calculative.h){if(t.x=i.x,r.connectTo&&oi(e,t,!0)){l&&l.y!==t.y&&(l.x=t.x);return}if(a.connectTo&&oi(e,t,!1)){o&&o.y!==t.y&&(o.x=t.x);return}const n=e.anchors[s];let h;for(let c=s-1;c>-1;c--)if(o=e.anchors[c],h==null&&(h=o.y===n.y),h===!0)if(o.y===n.y)e.calculative.worldAnchors[c].y=i.y;else break;else if(o.x===n.x)e.calculative.worldAnchors[c].x=i.x;else break;h=void 0;for(let c=s+1;c<e.calculative.worldAnchors.length&&(l=e.anchors[c],l);c++)if(h==null&&(h=l.y===n.y),h===!0)if(l.y===n.y)e.calculative.worldAnchors[c].y=i.y;else break;else if(l.x===n.x)e.calculative.worldAnchors[c].x=i.x;else break;t.y=i.y}else{if(t.y=i.y,r.connectTo&&ni(e,t,!0)){l&&l.x!==t.x&&(l.y=t.y);return}if(a.connectTo&&ni(e,t,!1)){o&&o.x!==t.x&&(o.y=t.y);return}const n=e.anchors[s];let h;for(let c=s-1;c>-1;c--)if(o=e.anchors[c],h==null&&(h=o.x===n.x),h===!0)if(o.x===n.x)e.calculative.worldAnchors[c].x=i.x;else break;else if(o.y===n.y)e.calculative.worldAnchors[c].y=i.y;else break;h=void 0;for(let c=s+1;c<e.calculative.worldAnchors.length&&(l=e.anchors[c],l);c++)if(h==null&&(h=l.x===n.x),h===!0)if(l.x===n.x)e.calculative.worldAnchors[c].x=i.x;else break;else if(l.y===n.y)e.calculative.worldAnchors[c].y=i.y;else break;t.x=i.x}}function ts(e,t,i,s){const r=[];let a,o,l,n,h,c,f,u,d,v,g,y,p,b;d=e[i],v=e[s],l=d.x,n=d.y,f=v.x-l,u=v.y-n,b=f*f+u*u,a=t;for(let m=i+1;m<s;m++)g=e[m],f!==0||u!==0?(y=((g.x-l)*f+(g.y-n)*u)/b,y>1?(h=g.x-v.x,c=g.y-v.y):y>0?(h=g.x-(l+f*y),c=g.y-(n+u*y)):(h=g.x-l,c=g.y-n)):(h=g.x-l,c=g.y-n),p=h*h+c*c,p>a&&(o=m,a=p);return a>t&&(o-i>1&&r.push(...ts(e,t,i,o)),r.push({id:e[o].id,penId:e[o].penId,x:e[o].x,y:e[o].y}),s-o>1&&r.push(...ts(e,t,o,s))),r}function Qn(e,t=.8,i=!1){if(e.length<3)return e;let s,r,a,o,l,n,h,c,f,u,d,v,g,y,p;const b=(m,k,A,S)=>(o=Math.sqrt(m*m+k*k),o>0?(v=m/o,y=k/o):(v=1,y=0),l=Math.sqrt(A*A+S*S),l>0?(g=A/l,p=S/l):(g=1,p=0),Math.acos(v*g+y*p));u=[],d=e.length,s=e[0],e[d-1],u.push({...e[0]});for(let m=0;m<d-1;m++){if(r=e[m],a=e[m+1],f=Math.abs(b(r.x-s.x,r.y-s.y,a.x-r.x,a.y-r.y)),o)if(f<t*3.14)if(i&&(o=Math.min(o,l),l=o),n=(v+g)/2,h=(y+p)/2,c=Math.sqrt(n*n+h*h),c===0)u.push({...r});else{n/=c,h/=c;const k={...r};k.prevNextType=pe.Bilateral,k.prev={penId:k.penId,x:r.x-n*o*.25,y:r.y-h*o*.25},k.next={penId:k.penId,x:r.x+n*l*.25,y:r.y+h*l*.25},u.push(k)}else u.push({...r});s=r}return u.push({...e[e.length-1]}),u}function Kr(e,t){const i=t||new Path2D;let s=e.calculative.worldAnchors,r=e.calculative.canvas.store.data.scale,a=(e.calculative.animateLineWidth||6)*r,o=(e.animateLineWidth*2||12)*r;e.lineAnimateType===pt.WaterDrop&&(o=(e.animateLineWidth*4||24)*r);let l=(e.animateInterval||100)*r,n=e.calculative.lineWidth*(e.calculative.lineSmooth||0),h=(e.calculative.animateLineWidth/2||3)*r;if(e.animateReverse&&(o=-o,a=-a),s.length>1){let c,f=0;if(e.close&&(s=K(s),s.push(s[0])),["polyline","line"].includes(e.lineName))for(let u=0;u<s.length;u++){let d=s[u];if(c){let v=je(c,d),g={x:c.x+(e.calculative.animatePos-f)%l*Math.cos(v*Math.PI/180),y:c.y-(e.calculative.animatePos-f)%l*Math.sin(v*Math.PI/180)};e.animateReverse&&(g={x:c.x+(e.length-(e.calculative.animatePos+f))%l*Math.cos(v*Math.PI/180),y:c.y-(e.length-(e.calculative.animatePos+f))%l*Math.sin(v*Math.PI/180)});let y=Math.sqrt((g.x-c.x)**2+(g.y-c.y)**2),p=Math.sqrt((d.x-c.x)**2+(d.y-c.y)**2);for(;y<p;)(e.animateReverse&&y-o<p||!e.animateReverse&&y>o)&&y>n+o&&p-y>n&&(e.lineAnimateType===pt.Arrow?We(i,g,a,v,h,o):e.lineAnimateType===pt.WaterDrop&&He(i,g,e.animateReverse,v,h,o)),g.x+=l*Math.cos(v*Math.PI/180),g.y-=l*Math.sin(v*Math.PI/180),y=Math.sqrt((g.x-c.x)**2+(g.y-c.y)**2)}c=d}else{let u,d=e.calculative.animatePos%l/l;d>1&&(d=1),e.animateReverse&&(d=1-d);let v=1/(s[0].lineLength/l),g=d*v,y;s.forEach(p=>{let b=p;if(u)if(v=1/(u.lineLength/l),u.next)if(b.prev)for(y=g;y<1;y+=v){let m=Ci(y,u,u.next,b.prev,b),k=Ci(y+.001,u,u.next,b.prev,b),A=je(m,k);e.lineAnimateType===pt.Arrow?We(i,m,a,A,h,o):e.lineAnimateType===pt.WaterDrop&&He(i,m,e.animateReverse,A,h,o)}else for(y=g;y<1;y+=v){let m=ge(y,u,u.next,b),k=ge(y+.001,u,u.next,b),A=je(m,k);e.lineAnimateType===pt.Arrow?We(i,m,a,A,h,o):e.lineAnimateType===pt.WaterDrop&&He(i,m,e.animateReverse,A,h,o)}else if(b.prev)for(y=g;y<1;y+=v){let m=ge(y,u,b.prev,b),k=ge(y+.001,u,b.prev,b),A=je(m,k);e.lineAnimateType===pt.Arrow?We(i,m,a,A,h,o):e.lineAnimateType===pt.WaterDrop&&He(i,m,e.animateReverse,A,h,o)}else{let m=je(u,b);for(y=g;y<1;y+=v){let k={x:u.x+(b.x-u.x)*y,y:u.y+(b.y-u.y)*y};e.lineAnimateType===pt.Arrow?We(i,k,a,m,h,o):e.lineAnimateType===pt.WaterDrop&&He(i,k,e.animateReverse,m,h,o)}}u=p,y?g=y-1:y=g})}}if(i instanceof Path2D)return i}function je(e,t){let i=t.x-e.x,s=t.y-e.y,r=Math.atan(s/i)*180/Math.PI;return t.x>=e.x?r=-r:r=180-r,r}function he(e,t,i){let s=(180-i)*Math.PI/180;return{x:(e.x-t.x)*Math.cos(s)-(e.y-t.y)*Math.sin(s)+t.x,y:(e.x-t.x)*Math.sin(s)+(e.y-t.y)*Math.cos(s)+t.y}}function We(e,t,i,s,r,a){let o=he({x:t.x+i,y:t.y+.57*i},{x:t.x,y:t.y},s),l=he({x:t.x+i,y:t.y-.57*i},{x:t.x,y:t.y},s),n=he({x:t.x+i,y:t.y+r/2},{x:t.x,y:t.y},s),h=he({x:t.x+a,y:t.y+r/2},{x:t.x,y:t.y},s),c=he({x:t.x+i,y:t.y-r/2},{x:t.x,y:t.y},s),f=he({x:t.x+a,y:t.y-r/2},{x:t.x,y:t.y},s);e.moveTo(o.x,o.y),e.lineTo(t.x,t.y),e.lineTo(l.x,l.y),e.lineTo(c.x,c.y),e.lineTo(f.x,f.y),e.lineTo(h.x,h.y),e.lineTo(n.x,n.y),e.lineTo(o.x,o.y)}function He(e,t,i,s,r,a){let o=r/2;i&&(o=-r/2);let l=he({x:t.x,y:t.y+o},{x:t.x,y:t.y},s),n=he({x:t.x+a,y:t.y},{x:t.x,y:t.y},s),h=Math.PI/2;i&&(h=-Math.PI/2),e.moveTo(t.x,t.y),e.arc(t.x,t.y,r/2,-h-s/180*Math.PI,h-s/180*Math.PI,!1),e.lineTo(n.x,n.y),e.lineTo(l.x,l.y)}const ae={};function Zn(){var e;for(const t in ae)(e=ae[t])==null||e.remove(),delete ae[t]}function tl(e){var t;for(const i in ae)e.some(s=>s.name=="iframe"&&s.iframe==i)||((t=ae[i])==null||t.remove(),delete ae[i])}function el(e){const t=ae[e.iframe];return t?(e.calculative.singleton.div=t,ys(e),!0):!1}function il(e){var i;e.onDestroy||(e.onDestroy=sl,e.onMove=li,e.onResize=li,e.onRotate=li,e.onValue=li,e.onMouseMove=al,e.onBeforeValue=rl,e.onRenderPenRaw=nl),e.calculative.singleton||(e.calculative.singleton={});const t=e.calculative.worldRect;if(!e.calculative.singleton.div){if(el(e))return;const s=document.createElement("div");s.style.position="absolute",s.style.outline="none",s.style.left="-9999px",s.style.top="-9999px",s.style.width=t.width+"px",s.style.height=t.height+"px",(i=e.calculative.canvas.externalElements)==null||i.parentElement.appendChild(s),Ct(e,s),e.calculative.singleton.div=s;const r=document.createElement("iframe");r.style.width="100%",r.style.height="100%",r.scrolling=e.scrolling||"no",r.frameBorder="0",r.style.border="none",r.src=e.iframe,r.allowFullscreen=!0,e.calculative.iframe=e.iframe,s.appendChild(r),ys(e)}return e.calculative.patchFlags&&Ct(e,e.calculative.singleton.div),e.onRenderPenRaw(e),new Path2D}function sl(e){Jr(e),e.calculative.singleton&&e.calculative.singleton.div&&(e.calculative.canvas.store.data.locked?(ae[e.calculative.iframe]=e.calculative.singleton.div,delete e.calculative.singleton.div):(e.calculative.singleton.div.remove(),ae[e.calculative.iframe]=null))}function li(e){e.calculative.singleton.div&&Ct(e,e.calculative.singleton.div)}function rl(e,t){if(t.iframe&&e.calculative.singleton.div&&(e.calculative.singleton.div.children[0].src=t.iframe,e.calculative.iframe=t.iframe),t.operationalRect||t["operationalRect.x"]!==void 0||t["operationalRect.y"]!==void 0||t["operationalRect.width"]!==void 0||t["operationalRect.height"]!==void 0){e.operationalRect||(e.operationalRect={});let i=K(t);i.operationalRect||(i.operationalRect={}),i["operationalRect.x"]!==void 0&&(i.operationalRect.x=i["operationalRect.x"]),i["operationalRect.y"]!==void 0&&(i.operationalRect.y=i["operationalRect.y"]),i["operationalRect.width"]!==void 0&&(i.operationalRect.width=i["operationalRect.width"]),i["operationalRect.height"]!==void 0&&(i.operationalRect.height=i["operationalRect.height"]),Object.assign(e.operationalRect,i.operationalRect),e.calculative.singleton.div&&(e.calculative.singleton.div.children.length===1?ys(e):(e.calculative.singleton.div.children[1].style.height=e.operationalRect.y*100+"%",e.calculative.singleton.div.children[1].style.left=e.operationalRect.x*100+"%",e.calculative.singleton.div.children[1].style.width=e.operationalRect.width*100+"%",e.calculative.singleton.div.children[2].style.width=(1-e.operationalRect.x-e.operationalRect.width)*100+"%",e.calculative.singleton.div.children[3].style.height=(1-e.operationalRect.y-e.operationalRect.height)*100+"%",e.calculative.singleton.div.children[3].style.left=e.operationalRect.x*100+"%",e.calculative.singleton.div.children[3].style.width=e.operationalRect.width*100+"%",e.calculative.singleton.div.children[4].style.width=e.operationalRect.x*100+"%"))}if(t.blur!==void 0)for(let i=1;i<5;i++)e.calculative.singleton.div.children[i]&&(e.calculative.singleton.div.children[i].style["backdrop-filter"]=`blur(${t.blur}px)`);if(t.blurBackground!==void 0)for(let i=1;i<5;i++)e.calculative.singleton.div.children[i]&&(e.calculative.singleton.div.children[i].style.backgroundColor=t.blurBackground);return t}function al(e,t){if(!(!e.calculative.canvas.store.data.locked&&!e.locked)&&Gr(e.operationalRect)&&e.calculative.zIndex<5&&t.x>e.x+e.width*e.operationalRect.x&&t.x<e.x+e.width*(e.operationalRect.x+e.operationalRect.width)&&t.y>e.y+e.height*e.operationalRect.y&&t.y<e.y+e.height*(e.operationalRect.y+e.operationalRect.height)&&e.calculative.singleton.div){let i=e.calculative.singleton.div.parentNode.children;for(let s=0;s<6;s++)i[s].style.pointerEvents="none"}}function Gr(e){return e?!e.width||!e.height?!1:(e.x===void 0&&(e.x=(1-e.width)/2),e.y===void 0&&(e.y=(1-e.height)/2),!0):!1}function ol(e){for(;e.childNodes.length>1;)e.removeChild(e.lastChild)}function ys(e){if(!Gr(e.operationalRect))return;const t=e.calculative.singleton.div;if(!t)return;t.childNodes.length>1&&ol(t);const i=navigator.userAgent.indexOf("Linux")>-1,s=document.createElement("div");s.style.position="absolute",s.style.left=e.operationalRect.x*100+"%",s.style.top="0px",s.style.width=e.operationalRect.width*100+"%",s.style.height=e.operationalRect.y*100+"%",!i&&e.blur&&(s.style["backdrop-filter"]=`blur(${e.blur}px)`),s.style.backgroundColor=e.blurBackground,t.appendChild(s);const r=document.createElement("div");r.style.position="absolute",r.style.right="0px",r.style.top="0px",r.style.width=(1-e.operationalRect.x-e.operationalRect.width)*100+"%",r.style.height="100%",!i&&e.blur&&(r.style["backdrop-filter"]=`blur(${e.blur}px)`),r.style.backgroundColor=e.blurBackground,t.appendChild(r);const a=document.createElement("div");a.style.position="absolute",a.style.left=e.operationalRect.x*100+"%",a.style.bottom="0px",a.style.width=e.operationalRect.width*100+"%",a.style.height=(1-e.operationalRect.y-e.operationalRect.height)*100+"%",!i&&e.blur&&(a.style["backdrop-filter"]=`blur(${e.blur}px)`),a.style.backgroundColor=e.blurBackground,t.appendChild(a);const o=document.createElement("div");o.style.position="absolute",o.style.left="0px",o.style.top="0px",o.style.width=e.operationalRect.x*100+"%",o.style.height="100%",!i&&e.blur&&(o.style["backdrop-filter"]=`blur(${e.blur}px)`),o.style.backgroundColor=e.blurBackground,t.appendChild(o);let l=()=>{Jr(e)};s.onmouseenter=l,a.onmouseenter=l,r.onmouseenter=l,o.onmouseenter=l,t.onmouseleave=l}function Jr(e){if(!(!e.calculative.canvas.store.data.locked&&!e.locked)&&e.calculative.zIndex<5){let t=e.calculative.singleton.div.parentNode.children;for(let i=1;i<6;i++)t[i].style.pointerEvents="initial"}}function nl(e){if(e.thumbImg&&!e.calculative.img){const t=new Image;t.crossOrigin=e.crossOrigin==="undefined"?void 0:e.crossOrigin||e.calculative.canvas.store.options.crossOrigin||"anonymous",e.calculative.canvas.store.options.cdn&&!(e.thumbImg.startsWith("http")||e.thumbImg.startsWith("//")||e.thumbImg.startsWith("data:image"))?t.src=e.calculative.canvas.store.options.cdn+e.thumbImg:t.src=e.thumbImg,t.onerror=i=>{t.remove(),e.calculative.img=void 0},e.calculative.img=t}}const Ot={},vi=['<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M473.088 125.44L256 256H52.224C23.552 256 0 279.552 0 308.224V716.8c0 28.16 23.04 51.2 51.2 51.2h204.8l217.088 130.56c16.896 10.24 38.912-2.048 38.912-22.016V147.456c0-19.968-21.504-32.256-38.912-22.016zM699.904 320.512c-20.992-18.944-53.248-17.408-72.192 3.584-18.944 20.992-17.408 53.248 3.584 72.192 0.512 0.512 58.368 54.784 58.368 121.344 0 37.888-19.456 74.752-58.368 110.08-20.992 18.944-22.528 51.2-3.584 72.192 10.24 11.264 24.064 16.896 37.888 16.896 12.288 0 24.576-4.608 34.304-13.312 61.44-55.296 92.16-117.76 92.16-185.856 0-112.64-88.576-193.536-92.16-197.12z" fill="" p-id="2434"></path><path d="M853.504 166.4c-20.992-18.944-53.248-16.896-72.192 4.096-18.944 20.992-16.896 53.248 4.096 72.192 1.536 1.024 135.68 122.88 135.68 280.576 0 90.624-45.568 177.152-135.68 257.536-20.992 18.944-23.04 51.2-4.096 72.192 10.24 11.264 24.064 16.896 38.4 16.896 12.288 0 24.576-4.096 34.304-12.8 112.64-100.864 169.984-212.992 169.984-333.824-1.024-202.752-163.84-350.208-170.496-356.864z"></path></svg>','<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" ><path d="M256 768H51.2c-28.16 0-51.2-23.04-51.2-51.2V308.224C0 279.552 23.552 256 52.224 256H256v512zM512 147.456v728.576c0 19.968-21.504 32.256-38.912 22.016L256 768V256l217.088-130.56c17.408-10.24 38.912 2.048 38.912 22.016zM623.104 656.896c-19.968-19.968-19.968-52.224 0-72.192l217.088-217.088c19.968-19.968 52.224-19.968 72.192 0 19.968 19.968 19.968 52.224 0 72.192l-217.088 217.088c-19.456 19.968-52.224 19.968-72.192 0z" fill="" p-id="2582"></path><path d="M623.104 367.104c19.968-19.968 52.224-19.968 72.192 0l217.088 217.088c19.968 19.968 19.968 52.224 0 72.192-19.968 19.968-52.224 19.968-72.192 0l-217.088-217.088c-19.968-19.456-19.968-52.224 0-72.192z"></path></svg>'];function ll(e){var t;if(e.onDestroy||(e.onDestroy=cl,e.onMove=Hi,e.onResize=Hi,e.onRotate=Hi,e.onClick=Zs,e.onValue=ul,e.onChangeId=hl),Ot[e.id])e.video&&e.calculative.media&&e.video!==e.calculative.video?(console.warn("video 更改, 此处是否执行?"),e.calculative.media.src=e.video,e.autoPlay&&(e.calculative.media.muted=!0,e.calculative.media.autoplay=!0),e.calculative.media.loop=e.playLoop,e.calculative.video=e.video):e.audio&&e.calculative.media&&e.audio!==e.calculative.audio&&(e.calculative.media.src=e.audio,e.autoPlay&&(e.calculative.media.muted=!0,e.calculative.media.autoplay=!0),e.calculative.media.loop=e.playLoop,e.calculative.audio=e.audio);else{const i=document.createElement("div"),s=document.createElement("div");s.style.position="absolute",s.style.outline="none",s.style.left="0",s.style.bottom="0",s.style.width="0",s.style.height="2px",s.style.background="#52c41a",s.style.zIndex="1",e.hideProgress&&(s.style.display="none");const r=document.createElement("div");r.innerHTML=vi[1],r.style.position="absolute",r.style.right="0",r.style.bottom="0",r.style.width="20px",r.style.height="20px",r.style.fill="hsla(0, 0%, 100%, .8)",r.style.zIndex="1",r.style.display="none",i.appendChild(s),i.appendChild(r),r.onclick=o=>{o.stopPropagation(),e.calculative.media.muted?(r.innerHTML=vi[0],e.calculative.media.muted=!1):(r.innerHTML=vi[1],e.calculative.media.muted=!0)},e.calculative.singleton||(e.calculative.singleton={div:i}),e.calculative.singleton.muted=r,i.onmouseenter=o=>{e.hideMuted||(r.style.display="block")},i.onmouseleave=o=>{r.style.display="none"},i.onclick=o=>{o.stopPropagation(),Zs(e)};let a;e.audio?(a=document.createElement("audio"),a.controls=e.controls,a.src=e.audio):(a=document.createElement("video"),a.src=e.video,a.crossOrigin=e.crossOrigin||"anonymous",e.calculative.img=a),a.loop=e.playLoop,a.ontimeupdate=()=>{Qr(s,a,e.calculative.worldRect.width)},a.onended=()=>{e.calculative.onended&&e.calculative.onended(e)},e.calculative.media=a,a.style.position="absolute",a.style.outline="none",a.style.left="0",a.style.top="0",a.style.width="100%",a.style.height="100%",a.style.objectFit=e.objectFit||"contain",i.appendChild(a),Ot[e.id]=i,(t=e.calculative.canvas.externalElements)==null||t.parentElement.appendChild(i),Ct(e,i),e.autoPlay&&(a.autoplay=!0,a.muted=!0)}return e.calculative.patchFlags&&Ct(e,Ot[e.id]),new Path2D}function cl(e){Ot[e.id].onclick=null,Ot[e.id].remove(),Ot[e.id]=void 0}function Hi(e){Ct(e,Ot[e.id]);const t=Ot[e.id].children[0],i=Ot[e.id].children[1];Qr(t,i,e.calculative.worldRect.width)}function Zs(e){e.calculative.media&&(e.calculative.media.muted=!1,e.calculative.singleton.muted.innerHTML=vi[0],e.calculative.media.paused?e.calculative.media.play():e.calculative.media.pause())}function Qr(e,t,i){e.style.width=t.currentTime/t.duration*i+"px"}function hl(e,t,i){Ot[t]&&(Ot[i]=Ot[t],delete Ot[t])}function ul(e){const t=Ot[e.id];if(!t)return;Ct(e,t),e.calculative.media||(e.calculative.media=t.querySelector("video"));const i=e.calculative.media.getAttribute("src");e.video?i!==e.video&&(e.calculative.media.src=e.video):e.audio&&i!==e.audio&&(e.calculative.media.src=e.audio),e.autoPlay&&(e.calculative.media.muted=!0,e.calculative.media.autoplay=!0),e.calculative.media.loop=e.playLoop}function Kt(){try{const e=new OffscreenCanvas(0,0),t=e.getContext("2d");return t&&t.arc?e:document.createElement("canvas")}catch{return document.createElement("canvas")}}class Ke{constructor(t,i){D(this,"parentElement");D(this,"store");D(this,"box");D(this,"text");D(this,"arrowUp");D(this,"arrowDown");D(this,"x");D(this,"y");D(this,"currentPen");this.parentElement=t,this.store=i,this.box=document.createElement("div"),this.text=document.createElement("div"),this.arrowUp=document.createElement("div"),this.arrowDown=document.createElement("div"),this.box.className="meta2d-tooltip",this.text.className="text",this.arrowUp.className="arrow",this.arrowDown.className="arrow down",this.box.appendChild(this.text),this.box.appendChild(this.arrowUp),this.box.appendChild(this.arrowDown),t.appendChild(this.box),this.box.onmouseleave=()=>{this.hide(),this.store.lastHover=void 0};let s;for(let r=0;r<document.styleSheets.length;r++)document.styleSheets[r].title==="le5le.com/tooltip"&&(s=document.styleSheets[r]);if(!s){let r=document.createElement("style");r.type="text/css",r.title="le5le.com/tooltip",document.head.appendChild(r),r=document.createElement("style"),r.type="text/css",document.head.appendChild(r),s=r.sheet,s.insertRule(".meta2d-tooltip{position:absolute;padding:8px 0;z-index:10;left: -9999px;top: -9999px;}"),s.insertRule(".meta2d-tooltip .text{max-width:320px;min-height:30px;max-height:400px;outline:none;padding:8px 16px;border-radius:4px;background:#777777;color:#ffffff;line-height:1.8;overflow-y:auto;}"),s.insertRule(".meta2d-tooltip .arrow{position:absolute;border:10px solid transparent;background:transparent;top:-5px;left:50%;transform:translateX(-50%)}"),s.insertRule(".meta2d-tooltip .arrow.down{top:initial;bottom: -1px;}")}}static getTitle(t){var i,s,r;if(t.titleFnJs&&!t.titleFn)try{t.titleFn=It((r=(s=(i=t.calculative)==null?void 0:i.canvas)==null?void 0:s.store)==null?void 0:r.options,"pen",t.titleFnJs)}catch(a){console.log("titleFnJs",a)}return t.titleFn?t.titleFn(t):String(t.title)}setText(t){const i=this.box.getBoundingClientRect();let s=globalThis.marked;const r=Ke.getTitle(t);if(s){this.text.innerHTML=s(r);const a=this.text.getElementsByTagName("A");for(let o=0;o<a.length;++o)a[o].setAttribute("target","_blank")}else this.text.innerHTML=r;return i}updateText(t){var r;if(((r=this.currentPen)==null?void 0:r.id)!==t.id||Ke.titleEmpty(t)||t.titleUnUpdate)return;const i=this.setText(t),s=this.box.getBoundingClientRect();this.changePositionByText(i,s)}changePositionByText(t,i){this.x-=(i.width-t.width)/2,this.y-=i.height-t.height,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px"}static titleEmpty(t){return!t.title&&!t.titleFn&&!t.titleFnJs}show(t,i){if(this.currentPen=t,Ke.titleEmpty(t)){let l=Mt(t,!0);l&&this.show(l,i);return}this.setText(t);const s=this.box.getBoundingClientRect(),r=t.calculative.worldRect;let a=t.calculative.canvas.store.data.x+i.x-s.width/2,o=t.calculative.canvas.store.data.y+i.y-s.height;t.type||(a=t.calculative.canvas.store.data.x+r.x-(s.width-r.width)/2,o=t.calculative.canvas.store.data.y+r.ey-s.height-r.height),o>0?(this.arrowUp.style.borderBottomColor="transparent",this.arrowDown.style.borderTopColor="#777777"):(o+=s.height+r.height+5,this.arrowUp.style.borderBottomColor="#777777",this.arrowDown.style.borderTopColor="transparent"),this.x=a,this.y=o,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px"}hide(){this.currentPen=null,this.x=-9999,this.box.style.left="-9999px"}translate(t,i){this.x<-1e3||(this.x+=t,this.y+=i,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px")}destroy(){this.box.onmouseleave=null}}class Zr{constructor(t){D(this,"parent");D(this,"h");D(this,"v");D(this,"isDownH");D(this,"isDownV");D(this,"x");D(this,"y");D(this,"hSize");D(this,"vSize");D(this,"scrollX");D(this,"scrollY");D(this,"lastScrollX");D(this,"lastScrollY");D(this,"rect");D(this,"isShow");D(this,"isV");D(this,"padding");D(this,"pageMode");D(this,"onMouseDownH",t=>{t.preventDefault(),t.stopPropagation(),this.isDownH=t.x,this.x=this.parent.store.data.x||0,this.lastScrollX=this.scrollX});D(this,"onMouseDownV",t=>{t.preventDefault(),t.stopPropagation(),this.isDownV=t.y,this.y=this.parent.store.data.y||0,this.lastScrollY=this.scrollY});D(this,"onMouseMove",t=>{if(this.isDownH){const i=t.x-this.isDownH;this.scrollX=this.lastScrollX+i,this.h.style.left=`${this.scrollX}px`,this.parent.store.data.x=this.x-i*this.rect.width/this.parent.parentElement.clientWidth}if(this.isDownV){const i=t.y-this.isDownV;if(this.pageMode&&this.canMouseMove(i))return;this.scrollY=this.lastScrollY+i,this.v.style.top=`${this.scrollY}px`,this.isV?this.parent.store.data.y=this.y-i*this.isV.h/this.parent.parentElement.clientHeight:this.parent.store.data.y=this.y-i*this.rect.height/this.parent.parentElement.clientHeight}(this.isDownH||this.isDownV)&&(this.parent.onMovePens(),this.parent.canvasTemplate.init(),this.parent.canvasImage.init(),this.parent.canvasImageBottom.init(),this.parent.render())});D(this,"onMouseUp",t=>{!this.isDownH&&!this.isDownV||(this.isDownH=void 0,this.isDownV=void 0,!this.isV&&(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.parent=t,this.h=document.createElement("div"),this.v=document.createElement("div"),this.parent.externalElements.appendChild(this.h),this.parent.externalElements.appendChild(this.v),this.h.className="meta2d-scroll h",this.h.onmousedown=this.onMouseDownH,this.v.className="meta2d-scroll v",this.v.onmousedown=this.onMouseDownV,document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp);let i;for(let s=0;s<document.styleSheets.length;s++)document.styleSheets[s].title==="le5le/scroll"&&(i=document.styleSheets[s]);if(!i){let s=document.createElement("style");s.type="text/css",s.title="le5le.com/scroll",document.head.appendChild(s),s=document.createElement("style"),s.type="text/css",document.head.appendChild(s),i=s.sheet,i.insertRule(".meta2d-scroll{position:absolute;width:8px;height:200px;background:#dddddd;border-radius:10px;z-index:20;cursor:default;}"),i.insertRule(".meta2d-scroll:hover{background:#cccccc;cursor:pointer}"),i.insertRule(".meta2d-scroll.v{right:0;top:calc(50% - 100px);}"),i.insertRule(".meta2d-scroll.h{bottom:2px;left:calc(50% - 100px);width:200px;height:8px;}")}this.init()}init(){this.isShow=!0,this.resize(),this.initPos(),this.getV()}getV(){const t=this.parent.store.data.width||this.parent.store.options.width,i=this.parent.store.data.height||this.parent.store.options.height;if(t&&i){const s=this.parent.store.data.scale;this.isV={w:t*s,h:i*s}}}canMouseMove(t){if(this.isV){let s=this.parent.store.data.origin;return t<0&&(Math.abs(s.y+this.parent.store.data.y-this.padding)<1||s.y+this.parent.store.data.y-this.padding>0)?(this.scrollY=0,this.v.style.top="0px",!0):t>0&&(Math.abs(s.y+this.isV.h-this.parent.height+this.parent.store.data.y-this.padding)<1||s.y+this.isV.h-this.parent.height+this.parent.store.data.y-this.padding<=0)?(this.parent.store.data.y=-(s.y+this.isV.h-this.parent.height+this.padding)-1,this.parent.onMovePens(),this.parent.canvasTemplate.init(),this.parent.canvasImage.init(),this.parent.canvasImageBottom.init(),this.parent.render(),!0):!1}const i=this.parent.parent.getRect();return t<0&&i.y+this.parent.store.data.y>=0||t>0&&i.ey-this.parent.height+this.parent.store.data.y<=0}changeMode(t){this.pageMode=!0,this.h.style.display="none";const i=this.parent.parent.getRect();if(i.height<this.parent.height&&(this.v.style.display="none"),this.isV){let s=i.height;this.padding=t||0,this.getV(),s=this.isV.h,this.v.style.top="0px",this.v.style.height=this.parent.parentElement.clientHeight/(s+this.padding||0)*this.parent.parentElement.clientHeight+"px",this.scrollY=0}}initPos(){this.scrollX=(this.parent.parentElement.clientWidth-this.hSize)/2,this.scrollY=(this.parent.parentElement.clientHeight-this.vSize)/2,this.h.style.left=`${this.scrollX}px`,this.v.style.top=`${this.scrollY}px`}resize(){this.rect=this.parent.parent.getRect(),this.rect.width<1400&&(this.rect.width=1400),this.rect.height<900&&(this.rect.height=900),this.parent.store.data.x>0?this.rect.width+=this.parent.store.data.x+(this.rect.x>0?0:this.rect.x):this.rect.width-=this.parent.store.data.x+(this.rect.x>0?0:this.rect.x),this.parent.store.data.y>0?this.rect.height+=this.parent.store.data.y+(this.rect.y>0?0:this.rect.y):this.rect.height-=this.parent.store.data.y+(this.rect.y>0?0:this.rect.y),this.rect.width<1400&&(this.rect.width=1400),this.rect.height<900&&(this.rect.height=900),this.hSize=1e3*this.parent.parentElement.clientWidth/this.rect.width/3,this.vSize=1e3*this.parent.parentElement.clientHeight/this.rect.height/3,this.h.style.width=this.hSize+"px",this.v.style.height=this.vSize+"px"}show(){this.isShow=!0,this.h.style.display="block",this.v.style.display="block",document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp)}hide(){this.isShow=!1,this.h.style.display="none",this.v.style.display="none",this.destroy()}translate(t,i){t&&(this.scrollX-=t*this.parent.parentElement.clientWidth/this.rect.width,this.h.style.left=`${this.scrollX}px`),i&&(this.scrollY-=i*this.parent.parentElement.clientHeight/this.rect.height,this.v.style.top=`${this.scrollY}px`)}wheel(t){let i=10;typeof t=="boolean"?t&&(i=-10):i=t,!(this.pageMode&&this.canMouseMove(i))&&(this.scrollY+=i,this.v.style.top=`${this.scrollY}px`,this.isV?this.parent.store.data.y-=i*this.isV.h/this.parent.parentElement.clientHeight:this.parent.store.data.y-=i*this.rect.height/this.parent.parentElement.clientHeight,this.parent.onMovePens(),this.parent.canvasTemplate.init(),this.parent.canvasImage.init(),this.parent.canvasImageBottom.init(),this.parent.render())}destroy(){document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp)}}class tr{constructor(t,i,s){D(this,"parentElement");D(this,"store");D(this,"isBottom");D(this,"canvas",document.createElement("canvas"));D(this,"otherOffsreen",Kt());D(this,"offscreen",Kt());D(this,"animateOffsScreen",Kt());D(this,"fitOffscreen",Kt());D(this,"fitFlag",!1);D(this,"currentFit");D(this,"activeFit");this.parentElement=t,this.store=i,this.isBottom=s,t.appendChild(this.canvas),this.canvas.style.backgroundRepeat="no-repeat",this.canvas.style.backgroundSize="100% 100%",this.canvas.style.position="absolute",this.canvas.style.top="0",this.canvas.style.left="0"}resize(t,i){this.canvas.style.width=t+"px",this.canvas.style.height=i+"px",t=t*this.store.dpiRatio|0,i=i*this.store.dpiRatio|0,this.canvas.width=t,this.canvas.height=i,this.otherOffsreen.width=t,this.otherOffsreen.height=i,this.offscreen.width=t,this.offscreen.height=i,this.animateOffsScreen.width=t,this.animateOffsScreen.height=i,this.fitOffscreen.width=t,this.fitOffscreen.height=i,this.otherOffsreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.otherOffsreen.getContext("2d").textBaseline="middle",this.offscreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.offscreen.getContext("2d").textBaseline="middle",this.animateOffsScreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.animateOffsScreen.getContext("2d").textBaseline="middle",this.fitOffscreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.fitOffscreen.getContext("2d").textBaseline="middle",this.init()}init(){this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.animateOffsScreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.fitOffscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height);for(const t of this.store.data.pens)this.hasImage(t)&&(t.calculative.imageDrawed=!1);this.isBottom?this.store.patchFlagsBackground=!0:this.store.patchFlagsTop=!0}clear(){this.otherOffsreen.getContext("2d").clearRect(0,0,this.otherOffsreen.width,this.otherOffsreen.height),this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.animateOffsScreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.fitOffscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.canvas.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height)}hasImage(t){return t.calculative.hasImage=t.calculative&&t.calculative.inView&&(this.isBottom&&t.canvasLayer===ht.CanvasImageBottom||!this.isBottom&&t.canvasLayer===ht.CanvasImage)&&t.image&&t.calculative.img&&t.name!=="gif",t.calculative.hasImage}render(){var o;let t=!1,i=!1;for(const l of this.store.data.pens)this.hasImage(l)&&(this.store.animates.has(l)?i=!0:l.calculative.imageDrawed||(t=!0),l.parentId&&this.store.animates.has(Mt(l,!0))&&(i=!0));const s=this.store.patchFlagsBackground,r=this.store.patchFlagsTop;if(r&&!this.isBottom){const l=this.otherOffsreen.getContext("2d");l.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderRule(l)}if(this.store.patchFlagsLast&&this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),t){const l=this.offscreen.getContext("2d");l.save(),l.clearRect(0,0,this.canvas.width,this.canvas.height),l.translate(this.store.data.x,this.store.data.y);for(const n of this.store.data.pens)!n.calculative.hasImage||this.store.animates.has(n)||this.store.animates.has(Mt(n,!0))||n.canvasLayer!==ht.CanvasTemplate&&(n.calculative.imageDrawed=!0,l.save(),we(l,n),(n.rotateByRoot||n.calculative.rotate)&&se(l,n),be(l,n),Me(l,n),l.restore());l.restore()}if(i){const l=this.animateOffsScreen.getContext("2d");l.save(),l.clearRect(0,0,this.canvas.width,this.canvas.height),l.translate(this.store.data.x,this.store.data.y);for(const n of this.store.animates)n.calculative.hasImage&&n.canvasLayer!==ht.CanvasTemplate&&(n.visible===!1||n.calculative.visible===!1||(n.calculative.imageDrawed=!0,l.save(),we(l,n),(n.rotateByRoot||n.calculative.rotate)&&se(l,n),be(l,n),Me(l,n),l.restore()));for(const n of this.store.data.pens)!n.calculative.hasImage||!n.parentId||n.canvasLayer!==ht.CanvasTemplate&&(n.visible===!1||n.calculative.visible===!1||this.store.animates.has(Mt(n,!0))&&(n.calculative.imageDrawed=!0,l.save(),we(l,n),(n.rotateByRoot||n.calculative.rotate)&&se(l,n),be(l,n),Me(l,n),l.restore()));l.restore()}if(!this.isBottom&&!this.store.data.locked&&this.fitFlag){const l=(this.store.data.width||this.store.options.width)*this.store.data.scale,n=(this.store.data.height||this.store.options.height)*this.store.data.scale,h=this.store.data.origin.x+this.store.data.x||this.store.options.x||0,c=this.store.data.origin.y+this.store.data.y||this.store.options.y||0,f=this.fitOffscreen.getContext("2d");f.save(),f.clearRect(0,0,this.canvas.width,this.canvas.height),f.fillStyle="#ffffff66",f.strokeStyle=this.store.styles.activeColor,(o=this.store.data.fits)==null||o.forEach((u,d)=>{f.fillRect(h+l*u.x,c+n*u.y,l*u.width,n*u.height),u.active&&f.strokeRect(h+l*u.x,c+n*u.y,l*u.width,n*u.height)}),f.restore()}if(t||i||s&&this.isBottom||r&&!this.isBottom){const l=this.canvas.getContext("2d");l.clearRect(0,0,this.canvas.width,this.canvas.height),this.isBottom&&(this.store.patchFlagsBackground=!1),l.drawImage(this.offscreen,0,0,this.canvas.width,this.canvas.height),l.drawImage(this.animateOffsScreen,0,0,this.canvas.width,this.canvas.height),this.isBottom||(l.drawImage(this.otherOffsreen,0,0,this.canvas.width,this.canvas.height),this.store.patchFlagsTop=!1,!this.store.data.locked&&this.fitFlag&&l.drawImage(this.fitOffscreen,0,0,this.canvas.width,this.canvas.height))}}renderRule(t){var m,k,A,S,I,E,z,U;const{data:i,options:s}=this.store,{rule:r,ruleColor:a,scale:o,origin:l}=i;if(!(r??s.rule))return;const n=o*10;t.save();const h=a||s.ruleColor||"#ccc";t.strokeStyle=mi(h,.7);const c=l.x+i.x,f=l.y+i.y,{width:u,height:d}=this.canvas;let v=((m=s.ruleOptions)==null?void 0:m.height)||20;(k=s.ruleOptions)!=null&&k.background&&(t.beginPath(),t.fillStyle=(A=s.ruleOptions)==null?void 0:A.background,t.rect(0,0,u,v),t.fill(),t.rect(0,0,v,d),t.fill()),(S=s.ruleOptions)!=null&&S.underline&&(t.beginPath(),t.fillStyle=mi(h,.7),t.moveTo(0,v),t.lineTo(u,v),t.stroke(),t.moveTo(v,0),t.lineTo(v,d),t.stroke());let g=v/4;((I=s.ruleOptions)==null?void 0:I.baseline)==="bottom"&&(g=v*3/4),t.beginPath(),t.lineWidth=v/2,t.lineDashOffset=-c%n,t.setLineDash([1,n-1]),t.moveTo(0,g),t.lineTo(u,g),t.stroke(),t.beginPath(),t.lineDashOffset=-f%n,t.moveTo(g,0),t.lineTo(g,d),t.stroke(),t.strokeStyle=h,t.beginPath(),t.lineWidth=v,t.lineDashOffset=-c%(n*10),t.setLineDash([1,n*10-1]),t.moveTo(0,v/2),t.lineTo(u,v/2),t.stroke(),t.beginPath(),t.lineDashOffset=-f%(n*10),t.moveTo(v/2,0),t.lineTo(v/2,d),t.stroke(),t.beginPath(),t.fillStyle=((E=s.ruleOptions)==null?void 0:E.textColor)||t.strokeStyle;let y=0-Math.floor(c/n/10)*100,p=((z=s.ruleOptions)==null?void 0:z.textTop)||16,b=((U=s.ruleOptions)==null?void 0:U.textLeft)||4;c<0&&(y-=100);for(let T=c%(n*10);T<u;T+=10*n,y+=100)n<3&&y%500||t.fillText(y.toString(),T+b,p);y=0-Math.floor(f/n/10)*100,f<0&&(y-=100);for(let T=f%(n*10);T<d;T+=10*n,y+=100)n<3&&y%500||(t.save(),t.beginPath(),t.translate(p,T-b),t.rotate(270*Math.PI/180),t.fillText(y.toString(),0,0),t.restore());t.restore()}}class dl{constructor(t,i,s){D(this,"parentCanvas");D(this,"parentElement");D(this,"store");D(this,"canvas",document.createElement("canvas"));D(this,"magnifierScreen",Kt());D(this,"offscreen",Kt());D(this,"domOffscreen",Kt());D(this,"magnifierSize",300);D(this,"magnifier");this.parentCanvas=t,this.parentElement=i,this.store=s,i.appendChild(this.canvas),this.canvas.style.backgroundRepeat="no-repeat",this.canvas.style.backgroundSize="100% 100%",this.canvas.style.position="absolute",this.canvas.style.top="0",this.canvas.style.left="0",this.canvas.style.pointerEvents="none"}resize(t,i){this.canvas.style.width=t+"px",this.canvas.style.height=i+"px",t=t*this.store.dpiRatio|0,i=i*this.store.dpiRatio|0,this.canvas.width=t,this.canvas.height=i,this.offscreen.width=t,this.offscreen.height=i,this.offscreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.offscreen.getContext("2d").textBaseline="middle",this.domOffscreen.width=t,this.domOffscreen.height=i,this.domOffscreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.domOffscreen.getContext("2d").textBaseline="middle",this.magnifierScreen.width=this.magnifierSize+5,this.magnifierScreen.height=this.magnifierSize+5}renderMagnifier(){if(!this.magnifier)return;const t=this.magnifierSize/2,i=this.magnifierSize+5,s=this.magnifierScreen.getContext("2d");s.clearRect(0,0,i,i),s.lineWidth=5,s.save(),s.translate(2.5,2.5),s.save(),s.arc(t,t,t,0,Math.PI*2,!1),s.clip(),s.translate(-t,-t),s.scale(2,2);const r={x:(this.parentCanvas.mousePos.x+this.store.data.x)*this.store.dpiRatio,y:(this.parentCanvas.mousePos.y+this.store.data.y)*this.store.dpiRatio};[this.parentCanvas.canvasTemplate.bgOffscreen,this.parentCanvas.canvasTemplate.offscreen,this.parentCanvas.canvasImageBottom.offscreen,this.parentCanvas.canvasImageBottom.animateOffsScreen,this.parentCanvas.offscreen,this.parentCanvas.canvasImage.offscreen,this.parentCanvas.canvasImage.animateOffsScreen,this.domOffscreen].forEach(n=>{s.drawImage(n,r.x-t,r.y-t,this.magnifierSize,this.magnifierSize,0,0,this.magnifierSize,this.magnifierSize)}),s.restore(),s.beginPath();const o=s.createRadialGradient(t,t,t-5,t,t,t);o.addColorStop(0,"rgba(0,0,0,0.2)"),o.addColorStop(.8,"rgb(200,200,200)"),o.addColorStop(.9,"rgb(200,200,200)"),o.addColorStop(1,"rgba(200,200,200,0.9)"),s.strokeStyle=o,s.arc(t,t,t,0,Math.PI*2,!1),s.stroke(),s.restore(),this.offscreen.getContext("2d").drawImage(this.magnifierScreen,0,0,this.magnifierSize+5,this.magnifierSize+5,(r.x-t-2.5)/this.store.dpiRatio,(r.y-t-2.5)/this.store.dpiRatio,(this.magnifierSize+5)/this.store.dpiRatio,(this.magnifierSize+5)/this.store.dpiRatio)}updateDomOffscreen(){const t=this.domOffscreen.getContext("2d");t.clearRect(0,0,this.domOffscreen.width,this.domOffscreen.height);for(const i of this.store.data.pens)if((i.externElement||i.name==="gif")&&i.calculative.img){t.save(),t.translate(this.store.data.x,this.store.data.y);const{x:s,y:r,width:a,height:o}=i.calculative.worldRect;t.drawImage(i.calculative.img,s,r,a,o),t.restore()}}render(){this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.renderMagnifier();const t=this.canvas.getContext("2d");t.clearRect(0,0,this.canvas.width,this.canvas.height),t.drawImage(this.offscreen,0,0,this.canvas.width,this.canvas.height)}}function ta(e){if(e.data.locked)throw new Error("canvas is locked")}class fl{constructor(t,i){D(this,"parentElement");D(this,"box");D(this,"iframe");D(this,"dialog");D(this,"close");D(this,"title");D(this,"body");D(this,"x");D(this,"y");D(this,"url");D(this,"meta2dDiv");D(this,"dialogMeta2d");D(this,"store");D(this,"data");this.parentElement=t,this.store=i,this.box=document.createElement("div"),this.dialog=document.createElement("div");let s=document.createElement("div");this.title=document.createElement("div"),this.close=document.createElement("span"),this.close.innerHTML=`
|
|
3
|
+
<svg fill="none" viewBox="0 0 16 16" width="1em" height="1em">
|
|
4
|
+
<path
|
|
5
|
+
fill="currentColor"
|
|
6
|
+
d="M8 8.92L11.08 12l.92-.92L8.92 8 12 4.92 11.08 4 8 7.08 4.92 4 4 4.92 7.08 8 4 11.08l.92.92L8 8.92z"
|
|
7
|
+
fill-opacity="0.9"
|
|
8
|
+
></path>
|
|
9
|
+
</svg>`,this.body=document.createElement("div"),this.iframe=document.createElement("iframe"),this.iframe.setAttribute("frameborder","0"),this.meta2dDiv=document.createElement("div"),this.box.className="meta2d-dialog_mask",this.dialog.className="meta2d-dialog",this.body.className="meta2d-dialog_body",s.className="meta2d-dialog_header",this.title.className="meta2d-dialog-content",this.close.className="meta2d-dialog-close",this.meta2dDiv.className="meta2d-dialog-meta2d",s.appendChild(this.title),s.appendChild(this.close),this.body.appendChild(this.iframe),this.body.appendChild(this.meta2dDiv),this.dialog.appendChild(s),this.dialog.appendChild(this.body),this.box.appendChild(this.dialog),t.appendChild(this.box),this.dialog.onclick=a=>{a.stopPropagation()},this.box.onclick=()=>{this.hide()},this.close.onclick=()=>{this.hide()};let r;for(let a=0;a<document.styleSheets.length;a++)document.styleSheets[a].title==="le5le.com/dialog"&&(r=document.styleSheets[a]);if(!r){let a=document.createElement("style");a.type="text/css",a.title="le5le.com/dialog",document.head.appendChild(a),a=document.createElement("style"),a.type="text/css",document.head.appendChild(a),r=a.sheet,r.insertRule(`.meta2d-dialog_mask {
|
|
10
|
+
display: none;
|
|
11
|
+
position: absolute;
|
|
12
|
+
top: 0%;
|
|
13
|
+
left: 0%;
|
|
14
|
+
width: 100%;
|
|
15
|
+
height: 100%;
|
|
16
|
+
background-color: #0000006f;
|
|
17
|
+
z-index: 9999;`),r.insertRule(`.meta2d-dialog_mask .meta2d-dialog {
|
|
18
|
+
position: absolute;
|
|
19
|
+
top: 15vh;
|
|
20
|
+
left: 10%;
|
|
21
|
+
width: 80%;
|
|
22
|
+
height:420px;
|
|
23
|
+
padding: 16px 20px;
|
|
24
|
+
border-radius: 9px;
|
|
25
|
+
z-index: 19999;
|
|
26
|
+
overflow: auto;
|
|
27
|
+
}`),r.insertRule(`.meta2d-dialog_header {
|
|
28
|
+
display: flex;
|
|
29
|
+
position: relative;
|
|
30
|
+
z-index: 999;
|
|
31
|
+
}`),r.insertRule(`.meta2d-dialog-content {
|
|
32
|
+
width: calc(100% - 20px);
|
|
33
|
+
font-weight: 600;
|
|
34
|
+
font-size: 14px;
|
|
35
|
+
color: #bdc7db;
|
|
36
|
+
padding-bottom:8px;
|
|
37
|
+
}`),r.insertRule(`.meta2d-dialog-close {
|
|
38
|
+
width: 20px;
|
|
39
|
+
height: 20px;
|
|
40
|
+
line-height: 20px;
|
|
41
|
+
text-align: center;
|
|
42
|
+
color: #617b91;
|
|
43
|
+
position: absolute;
|
|
44
|
+
right:20px;
|
|
45
|
+
top:2px;
|
|
46
|
+
display:none;
|
|
47
|
+
}`),r.insertRule(`.meta2d-dialog-close svg{
|
|
48
|
+
width: 18px;
|
|
49
|
+
height: 18px;
|
|
50
|
+
}`),r.insertRule(`.meta2d-dialog-close :hover{
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
}`),r.insertRule(`.meta2d-dialog_body{
|
|
53
|
+
width: 100%;
|
|
54
|
+
height: 100%;
|
|
55
|
+
} `),r.insertRule(`.meta2d-dialog_body iframe{
|
|
56
|
+
width: 100%;
|
|
57
|
+
height: 100%;
|
|
58
|
+
}`),r.insertRule(`.meta2d-dialog_body .meta2d-dialog-meta2d{
|
|
59
|
+
width: 100%;
|
|
60
|
+
height: 100%;
|
|
61
|
+
display: none;
|
|
62
|
+
}`)}}async show(t,i,s,r){if(!i)return;if(this.data=r,t&&(this.title.innerText=t),t?(this.dialog.style.padding="16px 20px",this.title.style.display="block",this.body.style.height="calc(100% - 30px)",this.close.style.top=((s==null?void 0:s.closeTop)||2)+"px",this.close.style.right=((s==null?void 0:s.closeRight)||2)+"px",this.dialog.style.background=(s==null?void 0:s.background)||this.store.data.background||"#1e2430"):(this.dialog.style.padding="0px",this.title.style.display="none",this.body.style.height="100%",this.body.style.overflow="hidden",this.close.style.top=((s==null?void 0:s.closeTop)||18)+"px",this.close.style.right=((s==null?void 0:s.closeRight)||20)+"px",this.body.style.background="transparent"),this.box.style.display="block",s){const{x:l,y:n,width:h,height:c}=this.detailRect(s);this.dialog.style.width=h,this.dialog.style.height=c,this.dialog.style.top=n,this.dialog.style.left=l,this.dialog.style.transform=`translate(${l==="50%"?"-50%":0}, ${n==="50%"?"-50%":0})`,this.box.style.background=s.maskBackground||"#0000006f"}const a=this.isUrl(i);let o=!1;if(a?(this.meta2dDiv.style.display="none",this.iframe.style.display="block"):(this.iframe.style.display="none",this.meta2dDiv.style.display="block"),a&&i!==this.url&&(this.iframe.setAttribute("src",i),this.url=i,o=!0),this.iframe.onload=()=>{(!this.dialogMeta2d||a)&&(this.close.style.display=s.hideClose?"none":"block",this.box.style.opacity="1")},!o&&(!this.dialogMeta2d||a)&&(this.box.style.opacity="1"),!a){this.meta2dDiv.style.display="block",this.dialogMeta2d||(globalThis.mainMeta2d=globalThis.meta2d,this.dialogMeta2d=new wc(this.meta2dDiv),globalThis.meta2d=globalThis.mainMeta2d);const l=await os(this.store,i);l&&(this.box.style.display="block",this.dialogMeta2d.clear(!0),this.dialogMeta2d.open(l,!1),this.dialogMeta2d.lock(1),this.dialogMeta2d.resize(),this.dialogMeta2d.fitView(!0,0),this.dialogMeta2d.render(!0))}}detailRect(t){const i=["x","y","width","height"];if(t)for(let s of i){let r=t[s];r&&(Number(r)?t[s]=r+"px":r.match(/\d+(px|vh|vw|%)$/)||(r=parseFloat(r),t[s]=isNaN(r)?void 0:r+"px"))}return{x:t.x||"50%",y:t.y||"50%",width:t.width||"80%",height:t.height||"420px"}}hide(){this.box.style.display="none",this.box.style.opacity="0",this.iframe.setAttribute("src","about:blank"),this.url="about:blank"}isUrl(t){return!!(t.startsWith("http")||t.includes("?")||t.includes("/"))}destroy(){var t;this.dialog.onclick=void 0,this.box.onclick=void 0,this.close.onclick=void 0,(t=this.dialogMeta2d)==null||t.destroy(!0)}}class Pi{constructor(t){D(this,"parentElement");D(this,"box");D(this,"currentAnchor");this.parentElement=t,this.box=document.createElement("div"),this.box.className="meta2d-title",t.appendChild(this.box);let i;for(let s=0;s<document.styleSheets.length;s++)document.styleSheets[s].title==="le5le.com/title"&&(i=document.styleSheets[s]);if(!i){let s=document.createElement("style");s.type="text/css",s.title="le5le.com/title",document.head.appendChild(s),s=document.createElement("style"),s.type="text/css",document.head.appendChild(s),i=s.sheet,i.insertRule(".meta2d-title{position:absolute;padding:0;z-index:10;left: -9999px;top: -9999px;background:#fff;color:#000; cursor: crosshair;border: 1px solid black;max-width:300px;overflow-wrap: break-word;}")}}static getTitle(t){}setText(t){this.box.innerText=t.title}updateText(t){var i;((i=this.currentAnchor)==null?void 0:i.id)===t.id&&(Pi.titleEmpty(t)||(this.setText(t),this.changePositionByAnchor(t)))}changePositionByAnchor(t){let i=this.parentElement.clientWidth,s=this.parentElement.clientHeight;t.x+20+300>i?(this.box.style.right=i-t.x+"px",this.box.style.left="auto"):(this.box.style.left=t.x+10+"px",this.box.style.right="auto"),t.y+10+100>s?(this.box.style.bottom=s-t.y+"px",this.box.style.top="auto"):(this.box.style.top=t.y+10+"px",this.box.style.bottom="auto")}static titleEmpty(t){return!t.title}show(t,i){if(Pi.titleEmpty(t))return;this.currentAnchor=t,this.setText(t);let s={x:i.calculative.canvas.store.data.x+t.x,y:i.calculative.canvas.store.data.y+t.y};this.changePositionByAnchor(s)}hide(){this.box.style.left="-9999px",this.box.innerText="",this.currentAnchor=null}destroy(){this.box.onmouseleave=null}}function vl(e,{area:t,align:i,size:s,color:r,rotate:a},o){if(e.lineWidth=1,e.strokeStyle=r,a){const l=a*Math.PI/180,n=l+Math.PI/2,h={x:Math.sin(l),y:-Math.cos(l)},c={x:Math.sin(n),y:-Math.cos(n)};er(e,t,s,h),er(e,t,s,c)}else{const l=i.x/s,n=i.y/s,h=s*10,c=i.x-Math.ceil(l)*s,f=i.y-Math.ceil(n)*s,u=t.x+t.width+h,d=t.y+t.height+h;e.beginPath();for(let v=c;v<=u;v+=s)e.moveTo(v,f),e.lineTo(v,t.y+t.height+h);for(let v=f;v<=d;v+=s)e.moveTo(c,v),e.lineTo(t.x+t.width+h,v);e.stroke()}return!1}function er(e,t,i,s,r){const a=[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}];let o=1/0,l=-1/0;a.forEach(h=>{const c=h.x*s.x+h.y*s.y;o=Math.min(o,c),l=Math.max(l,c)});const n=Math.ceil((l-o)/i);e.beginPath();for(let h=0;h<=n;h++){const c=o+h*i;let f=[];for(let u=0;u<a.length;u++){const d=a[u],v=a[(u+1)%a.length],g=s.x*(v.y-d.y)-s.y*(v.x-d.x);if(Math.abs(g)>1e-6){const y=(c-d.x*s.x-d.y*s.y)/(s.x*(v.x-d.x)+s.y*(v.y-d.y));if(y>=0&&y<=1){const p=d.x+y*(v.x-d.x),b=d.y+y*(v.y-d.y);f.push({x:p,y:b})}}}f.length>=2&&(e.moveTo(f[0].x,f[0].y),e.lineTo(f[1].x,f[1].y))}e.stroke()}function gl(e,{store:t,area:i,align:s,size:r,color:a},o){const l=a;e.fillStyle=l;const n=Math.max(.5,1.5*t.data.scale),h=s.x/r,c=s.y/r,f=r*10,u=s.x-Math.ceil(h)*r,d=s.y-Math.ceil(c)*r,v=i.x+i.width+f,g=i.y+i.height+f;for(let y=u+n;y<=v-n;y+=r)for(let p=d+n;p<=g-n;p+=r)e.beginPath(),e.arc(y,p,n,0,Math.PI*2),e.fill();return!0}class yl{constructor(t,i,s){D(this,"parentElement");D(this,"store");D(this,"canvas",document.createElement("canvas"));D(this,"offscreen",Kt());D(this,"bgOffscreen",Kt());D(this,"patchFlags");D(this,"bgPatchFlags");D(this,"parentCanvas");D(this,"fit");this.parentElement=t,this.store=i,t.appendChild(this.canvas),this.parentCanvas=s,this.canvas.style.backgroundRepeat="no-repeat",this.canvas.style.backgroundSize="100% 100%",this.canvas.style.position="absolute",this.canvas.style.top="0",this.canvas.style.left="0",it.gridDrawers.default||(it.gridDrawers.default=vl),it.gridDrawers.dot||(it.gridDrawers.dot=gl)}resize(t,i){this.canvas.style.width=t+"px",this.canvas.style.height=i+"px",t=t*this.store.dpiRatio|0,i=i*this.store.dpiRatio|0,this.canvas.width=t,this.canvas.height=i,this.bgOffscreen.width=t,this.bgOffscreen.height=i,this.offscreen.width=t,this.offscreen.height=i,this.bgOffscreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.bgOffscreen.getContext("2d").textBaseline="middle",this.offscreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.offscreen.getContext("2d").textBaseline="middle",this.init()}init(){this.bgOffscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.patchFlags=!0,this.bgPatchFlags=!0}hidden(){this.canvas.style.display="none"}show(){this.canvas.style.display="block"}clear(){this.bgOffscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.canvas.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.bgPatchFlags=!0,this.patchFlags=!0}render(){if(this.bgPatchFlags){const t=this.bgOffscreen.getContext("2d");t.clearRect(0,0,this.canvas.width,this.canvas.height);const i=this.store.data.width||this.store.options.width,s=this.store.data.height||this.store.options.height,r=this.store.data.x||this.store.options.x||0,a=this.store.data.y||this.store.options.y||0,o=this.store.data.background||this.store.styles.background;o&&(t.save(),t.fillStyle=o,t.globalAlpha=this.store.data.globalAlpha??this.store.options.globalAlpha,i&&s&&!this.fit?(t.shadowOffsetX=this.store.options.shadowOffsetX,t.shadowOffsetY=this.store.options.shadowOffsetY,t.shadowBlur=this.store.options.shadowBlur,t.shadowColor=this.store.options.shadowColor,t.fillRect(this.store.data.origin.x+r,this.store.data.origin.y+a,i*this.store.data.scale,s*this.store.data.scale)):t.fillRect(0,0,this.canvas.width,this.canvas.height),t.restore()),i&&s&&this.store.bkImg&&(t.save(),this.fit?t.drawImage(this.store.bkImg,0,0,this.canvas.offsetWidth,this.canvas.offsetHeight):t.drawImage(this.store.bkImg,this.store.data.origin.x+r,this.store.data.origin.y+a,i*this.store.data.scale,s*this.store.data.scale),t.restore()),this.renderGrid(t)}if(this.patchFlags){const t=this.offscreen.getContext("2d");t.save(),t.clearRect(0,0,this.canvas.width,this.canvas.height),t.translate(this.store.data.x,this.store.data.y);for(const i of this.store.data.pens)isFinite(i.x)&&i.canvasLayer===ht.CanvasTemplate&&i.calculative.inView&&(de(t,i),i.image&&i.name!=="gif"&&i.calculative.img&&(t.save(),we(t,i),(i.rotateByRoot||i.calculative.rotate)&&se(t,i),be(t,i),Me(t,i),t.restore()));t.restore()}if(this.patchFlags||this.bgPatchFlags){const t=this.canvas.getContext("2d");t.clearRect(0,0,this.canvas.width,this.canvas.height),t.drawImage(this.bgOffscreen,0,0,this.canvas.width,this.canvas.height),t.drawImage(this.offscreen,0,0,this.canvas.width,this.canvas.height),this.patchFlags=!1,this.bgPatchFlags=!1}}renderGrid(t){const{data:i,options:s}=this.store,r={x:this.parentCanvas.mousePos.x+this.parentCanvas.store.data.x,y:this.parentCanvas.mousePos.y+this.parentCanvas.store.data.y},{grid:a}=i;if(!(a??s.grid))return;const{gridRotate:o,gridColor:l,gridSize:n,scale:h,origin:c,gridScope:f}=i;let u=(n||s.gridSize)*h;u=u<0?0:u;const d=(i.width||s.width)*h,v=(i.height||s.height)*h,g=(i.x||s.x||0)+c.x,y=(i.y||s.y||0)+c.y,p=this.store.dpiRatio,b=this.canvas.width/p,m=this.canvas.height/p,k=f||s.gridScope,A=d&&v;t.save();let S;k==="full"?S={x:0,y:0,width:b,height:m}:k==="inner"?A?(S={x:g,y,width:d,height:v},t.beginPath(),t.rect(g,y,d,v),t.clip()):S={x:0,y:0,width:b,height:m}:k==="outer"?(S={x:0,y:0,width:b,height:m},A&&(t.beginPath(),t.rect(0,0,b,m),t.rect(g,y,d,v),t.clip("evenodd"))):A?(S={x:g,y,width:d,height:v},t.beginPath(),t.rect(g,y,d,v),t.clip()):S={x:0,y:0,width:b,height:m};const I={store:this.store,canvas:this.canvas,area:S,align:{x:g,y},size:u,color:l||s.gridColor,rotate:o,scale:h,mousePos:r},E=i.gridType||s.gridType||"default",z=it.gridDrawers[E]||it.gridDrawers.default;z&&(this.parentCanvas.store.options.gridAlwaysRender=z(t,I,r)),t.restore()}}const ml={info:{icon:'<svg fill="none" viewBox="0 0 24 24"><path fill="#0052d9" d="M12 23a11 11 0 100-22 11 11 0 000 22zM11 8.5v-2h2v2h-2zm2 1.5v7.5h-2V10h2z"></path></svg>'}};class pl{constructor(t,i){D(this,"parentElement");D(this,"store");D(this,"box");D(this,"text");D(this,"arrowUp");D(this,"arrowDown");D(this,"icon");D(this,"confirm");D(this,"cancel");D(this,"x");D(this,"y");this.parentElement=t,this.store=i,this.box=document.createElement("div"),this.text=document.createElement("div"),this.arrowUp=document.createElement("div"),this.arrowDown=document.createElement("div"),this.icon=document.createElement("div"),this.confirm=document.createElement("button"),this.cancel=document.createElement("button"),this.box.className="meta2d-popconfirm",this.text.className="text",this.arrowUp.className="arrow",this.arrowDown.className="arrow down",this.icon.className="icon",this.confirm.className="confirm",this.cancel.className="cancel",this.confirm.innerHTML="确定",this.cancel.innerHTML="取消",this.icon.innerHTML=ml.info.icon,this.box.appendChild(this.text),this.box.appendChild(this.arrowUp),this.box.appendChild(this.arrowDown),this.box.appendChild(this.confirm),this.box.appendChild(this.cancel),this.box.appendChild(this.icon),t.appendChild(this.box);let s;for(let r=0;r<document.styleSheets.length;r++)document.styleSheets[r].title==="le5le.com/popconfirm"&&(s=document.styleSheets[r]);if(!s){let r=document.createElement("style");r.type="text/css",r.title="le5le.com/popconfirm",document.head.appendChild(r),r=document.createElement("style"),r.type="text/css",document.head.appendChild(r),s=r.sheet,s.insertRule(".meta2d-popconfirm{position:absolute;z-index:999;left: -9999px;top: -9999px;padding:16px;max-width:400px;background:#fff;border-radius:6px;box-shadow:0 3px 14px 2px rgba(0, 0, 0, .05),0 8px 10px 1px rgba(0, 0, 0, 6%),0 5px 5px -3px rgba(0, 0, 0, 10%);}"),s.insertRule(".meta2d-popconfirm .text{outline:none;padding:0px 0px 40px 28px;border-radius:4px;color:rgba(0, 0, 0, 0.9);overflow-y:auto;line-height:22px;font-size:13px;}"),s.insertRule(".meta2d-popconfirm .arrow{position:absolute;border:10px solid transparent;background:transparent;top:-18px;left:50%;transform:translateX(-50%)}"),s.insertRule(".meta2d-popconfirm .arrow.down{top:initial;bottom: -18px;}"),s.insertRule(".meta2d-popconfirm .icon{position:absolute;width:22px;height:22px;left:16px;top:16px;}"),s.insertRule(".meta2d-popconfirm .confirm{position:absolute;right:16px;bottom:16px;width:40px;height:24px;text-align:center;background:#4582e6;color:#fff;border-radius:3px;border-color:transparent}"),s.insertRule(".meta2d-popconfirm .confirm:hover{background:#003cab;}"),s.insertRule(".meta2d-popconfirm .cancel{position:absolute;right:64px;bottom:16px;width:40px;height:24px;text-align:center;background:#dcdcdc;color:rgba(0, 0, 0, 0.9);border-radius:3px;border-color:transparent}"),s.insertRule(".meta2d-popconfirm .cancel:hover{background:#a6a6a6;}")}}show(t,i){if(!t)return;const s=this.box.getBoundingClientRect(),r=t.calculative.worldRect;let a=t.calculative.canvas.store.data.x+i.x-s.width/2,o=t.calculative.canvas.store.data.y+i.y-s.height-20;t.type||(a=t.calculative.canvas.store.data.x+r.x-(s.width-r.width)/2,o=t.calculative.canvas.store.data.y+r.ey-s.height-r.height),o>0?(this.arrowUp.style.borderBottomColor="transparent",this.arrowDown.style.borderTopColor="#fff",o-=10):(o+=s.height+r.height+5,o+=10,this.arrowUp.style.borderBottomColor="#fff",this.arrowDown.style.borderTopColor="transparent"),this.x=a,this.y=o,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px"}hide(){this.x=-9999,this.box.style.left="-9999px"}showModal(t,i,s){return new Promise(r=>{this.text.innerHTML=s||"确认执行操作吗?",this.show(t,i),this.confirm.onclick=()=>{r(!0),this.hide()},this.cancel.onclick=()=>{r(!1),this.hide()}})}destroy(){this.box=null}}const ir={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>1-(1-e)*(1-e),easeInOutQuad:e=>e<.5?2*e*e:1-Math.pow(-2*e+2,2)/2,easeInCubic:e=>e*e*e,easeOutCubic:e=>1-Math.pow(1-e,3),easeInOutCubic:e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,easeInQuart:e=>e*e*e*e,easeOutQuart:e=>1-Math.pow(1-e,4),easeInOutQuart:e=>e<.5?8*e*e*e*e:1-Math.pow(-2*e+2,4)/2,easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2};function wl(e){return ir[e]||ir.easeOutCubic}const Lt="-moving";class sr{constructor(t,i,s){D(this,"parent");D(this,"parentElement");D(this,"store");D(this,"canvas",document.createElement("canvas"));D(this,"offscreen",Kt());D(this,"width");D(this,"height");D(this,"externalElements",document.createElement("div"));D(this,"clientRect");D(this,"canvasRect");D(this,"activeRect");D(this,"initActiveRect");D(this,"dragRect");D(this,"lastRotate",0);D(this,"sizeCPs");D(this,"activeInitPos");D(this,"hoverType",st.None);D(this,"resizeIndex",0);D(this,"mouseDown");D(this,"hotkeyType");D(this,"mouseRight");D(this,"addCaches");D(this,"touchCenter");D(this,"initTouchDis");D(this,"initScale");D(this,"touchScaling");D(this,"touchMoving");D(this,"startTouches");D(this,"lastTouchY");D(this,"startDistance");D(this,"startCenter");D(this,"currentCenter");D(this,"lastOffsetX",0);D(this,"lastOffsetY",0);D(this,"drawingLineName");D(this,"drawLineFns",[...Pa]);D(this,"drawingLine");D(this,"pencil");D(this,"pencilLine");D(this,"movingPens");D(this,"patchFlagsLines",new Set);D(this,"dock");D(this,"prevAnchor");D(this,"nextAnchor");D(this,"lastMouseTime",0);D(this,"hoverTimer",0);D(this,"fitTimer",0);D(this,"willInactivePen");D(this,"patchFlags",!1);D(this,"lastRender",0);D(this,"touchStart",0);D(this,"touchStartTimer");D(this,"timer");D(this,"lastTapTime",0);D(this,"lastAnimateRender",0);D(this,"animateRendering",!1);D(this,"renderTimer");D(this,"viewAnimation");D(this,"viewAnimationTimer");D(this,"initPens");D(this,"pointSize",8);D(this,"pasteOffset",!0);D(this,"opening",!1);D(this,"maxZindex",5);D(this,"canMoveLine",!1);D(this,"randomIdObj");D(this,"keyOptions");D(this,"isMobile",/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));D(this,"beforeAddPen");D(this,"beforeAddPens");D(this,"beforeAddAnchor");D(this,"beforeRemovePens");D(this,"beforeRemoveAnchor");D(this,"customResizeDock");D(this,"customMoveDock");D(this,"inputParent",document.createElement("div"));D(this,"inputDiv",document.createElement("div"));D(this,"dropdown",document.createElement("ul"));D(this,"tooltip");D(this,"popconfirm");D(this,"title");D(this,"mousePos",{x:0,y:0});D(this,"scroll");D(this,"movingAnchor");D(this,"canvasTemplate");D(this,"canvasImage");D(this,"canvasImageBottom");D(this,"magnifierCanvas");D(this,"dialog");D(this,"autoPolylineFlag",!1);D(this,"stopPropagation",t=>{t.stopPropagation()});D(this,"curve",Zo);D(this,"polyline",qn);D(this,"mind",en);D(this,"line",rn);D(this,"onCopy",t=>{this.store.options.disableClipboard||t.target!==this.externalElements&&t.target!==document.body&&t.target.offsetParent!==this.externalElements||this.copy()});D(this,"onCut",t=>{this.store.options.disableClipboard||t.target!==this.externalElements&&t.target!==document.body&&t.target.offsetParent!==this.externalElements||this.cut()});D(this,"onPaste",async t=>{if(this.store.data.locked||this.store.options.disableClipboard||t.target!==this.externalElements&&t.target!==document.body&&t.target.offsetParent!==this.externalElements)return;let i;if(navigator.clipboard&&t.clipboardData){const s=t.clipboardData.items;if(s){for(let r=0;r<s.length;r++)if(s[r].type.indexOf("image")!==-1&&s[r].getAsFile()){i=!0;break}}}if(i){const s=t.clipboardData.items;if(s){for(let r=0;r<s.length;r++)if(s[r].type.indexOf("image")!==-1&&s[r].getAsFile()){const{x:a,y:o}=this.mousePos,l=s[r].getAsFile();let n=s[r].type.slice(6)==="gif"?"gif":"image";if(l!==null){const h=n==="gif",c=await this.fileToPen(l,h);c.height=c.height/c.width*100,c.width=100,c.x=a-50/2,c.y=o-c.height/c.width*50,c.externElement=h,this.addPens([c]),this.active([c]),this.copy([c])}}}}else this.paste()});D(this,"onMessage",t=>{if(typeof t.data!="string"||!t.data||t.data.startsWith("setImmediate")||t.data.startsWith("webpackHotUpdate"))return;let i=JSON.parse(t.data);typeof i=="object"?(i.name==="onload"&&this.dialog.iframe.contentWindow.postMessage(JSON.stringify({name:"dialog",data:this.dialog.data}),"*"),i.name==="closeDialog"&&this.dialog.hide(),this.parent.doMessageEvent(i.name,JSON.stringify(i.data))):this.parent.doMessageEvent(i)});D(this,"onwheel",t=>{if(this.viewAnimation=void 0,this.inputDiv.contentEditable==="true"||this.drawingLine||this.pencil)return;if(this.store.hover&&this.store.hover.onWheel){this.store.hover.onWheel(this.store.hover,t);return}if(this.store.data.disableScale||this.store.options.disableScale||(t.preventDefault(),t.stopPropagation(),this.mouseDown&&(this.hoverType===st.Node||this.hoverType===st.Line))||this.store.data.locked===ct.Disable||this.store.data.locked===ct.DisableScale||this.store.data.locked===ct.DisableMoveScale)return;if(!t.ctrlKey&&Math.abs(t.wheelDelta)<100&&t.deltaY.toString().indexOf(".")===-1){if(this.store.options.scroll&&!t.metaKey&&this.scroll){this.scroll.wheel(t.deltaY<0);return}const a=this.store.data.scale||1;this.translate(-t.deltaX/a,-t.deltaY/a);return}if(Math.abs(t.wheelDelta)>100&&this.store.options.scroll&&this.scroll&&!this.store.options.scrollButScale&&!(t.ctrlKey||t.metaKey)){this.scroll.wheel(t.deltaY<0);return}if(this.store.options.disableTouchPadScale)return;let i=.015;if(this.store.options.scaleOff)i=this.store.options.scaleOff,t.deltaY>0&&(i=-this.store.options.scaleOff);else if(/mac os /i.test(navigator.userAgent))t.ctrlKey?t.deltaY>0&&(i*=-1):i*=t.wheelDeltaY/240;else{let o=.2;t.deltaY.toString().indexOf(".")!==-1&&(o=.01),t.deltaY>0?i=-o:i=o}let{offsetX:s,offsetY:r}=t;this.scale(this.store.data.scale+i,{x:s,y:r}),this.externalElements.focus()});D(this,"onkeydown",t=>{var a,o,l;if(this.store.data.locked>=ct.DisableEdit&&t.target.tagName!=="INPUT"&&t.target.tagName!=="TEXTAREA"&&!t.target.dataset.meta2dIgnore&&this.store.active.forEach(n=>{var h;(h=n.onKeyDown)==null||h.call(n,n,t.key)}),this.store.data.locked>=ct.DisableEdit||t.target.tagName==="INPUT"||t.target.tagName==="TEXTAREA"||t.target.dataset.meta2dIgnore||this.store.options.unavailableKeys.includes(t.key))return;this.keyOptions||(this.keyOptions={}),this.keyOptions.altKey=t.altKey,this.keyOptions.shiftKey=t.shiftKey,this.keyOptions.ctrlKey=t.ctrlKey,this.keyOptions.metaKey=t.metaKey,this.keyOptions.F=!1,(t.key==="F"||t.key==="f")&&(this.keyOptions.F=!0);let i=10,s=10,r=null;if(this.store.options.strictScope){const n=this.store.data.width||this.store.options.width,h=this.store.data.height||this.store.options.height;n&&h&&(r={x:this.store.data.origin.x,y:this.store.data.origin.y,width:n*this.store.data.scale,height:h*this.store.data.scale})}switch(t.key){case" ":this.hotkeyType=ft.Translate;break;case"Control":this.drawingLine?this.drawingLine.calculative.drawlineH=!this.drawingLine.calculative.drawlineH:this.hotkeyType||(this.patchFlags=!0,this.hotkeyType=ft.Select);break;case"Meta":break;case"Shift":this.store.active.length===1&&this.store.active[0].type&&this.store.activeAnchor?this.toggleAnchorHand():this.hotkeyType||(this.patchFlags=!0,this.store.options.resizeMode||(this.hotkeyType=ft.Resize));break;case"Alt":if(!t.ctrlKey&&!t.shiftKey&&this.drawingLine){const n=dt(this.drawingLine);n!==this.drawingLine.calculative.activeAnchor?(ds(this.drawingLine),this.drawingLine.calculative.worldAnchors.push(n)):this.drawingLine.calculative.worldAnchors.push({x:n.x,y:n.y});const h=this.drawLineFns.indexOf(this.drawingLineName);this.drawingLineName=this.drawLineFns[(h+1)%this.drawLineFns.length],this.drawingLine.lineName=this.drawingLineName,this.drawline(),this.patchFlags=!0}t.preventDefault();break;case"a":case"A":t.ctrlKey||t.metaKey?(this.active(this.store.data.pens.filter(n=>!n.parentId&&n.locked!==ct.Disable)),t.preventDefault()):this.toggleAnchorMode();break;case"Delete":case"Backspace":if(this.canvasImage.fitFlag&&this.canvasImage.activeFit){this.deleteFit();break}!this.store.data.locked&&this.delete();break;case"ArrowLeft":if(this.movingAnchor){this.translateAnchor(-1,0);break}if(i=-1,t.shiftKey&&(i=-5),(t.ctrlKey||t.metaKey)&&(i=-10),i=i*this.store.data.scale,this.store.activeAnchor&&this.store.active&&this.store.active.length===1&&this.store.active[0].type){this.moveLineAnchor({x:this.store.activeAnchor.x+i,y:this.store.activeAnchor.y},{});break}r&&this.activeRect.x+i<r.x&&(i=r.x-this.activeRect.x),this.translatePens(this.store.active,i,0);break;case"ArrowUp":if(this.movingAnchor){this.translateAnchor(0,-1);break}if(s=-1,t.shiftKey&&(s=-5),(t.ctrlKey||t.metaKey)&&(s=-10),s=s*this.store.data.scale,r&&this.activeRect.y+s<r.y&&(s=r.y-this.activeRect.y),this.store.activeAnchor&&this.store.active&&this.store.active.length===1&&this.store.active[0].type){this.moveLineAnchor({x:this.store.activeAnchor.x,y:this.store.activeAnchor.y+s},{});break}this.translatePens(this.store.active,0,s);break;case"ArrowRight":if(this.movingAnchor){this.translateAnchor(1,0);break}if(i=1,t.shiftKey&&(i=5),(t.ctrlKey||t.metaKey)&&(i=10),i=i*this.store.data.scale,this.store.activeAnchor&&this.store.active&&this.store.active.length===1&&this.store.active[0].type){this.moveLineAnchor({x:this.store.activeAnchor.x+i,y:this.store.activeAnchor.y},{});break}r&&this.activeRect.x+this.activeRect.width+i>r.x+r.width&&(i=r.x+r.width-(this.activeRect.x+this.activeRect.width)),this.translatePens(this.store.active,i,0);break;case"ArrowDown":if(this.movingAnchor){this.translateAnchor(0,1);break}if(s=1,t.shiftKey&&(s=5),(t.ctrlKey||t.metaKey)&&(s=10),s=s*this.store.data.scale,r&&this.activeRect.y+this.activeRect.height+s>r.y+r.height&&(s=r.y+r.height-(this.activeRect.y+this.activeRect.height)),this.store.activeAnchor&&this.store.active&&this.store.active.length===1&&this.store.active[0].type){this.moveLineAnchor({x:this.store.activeAnchor.x,y:this.store.activeAnchor.y+s},{});break}this.translatePens(this.store.active,0,s);break;case"d":case"D":(a=this.store.active[0])!=null&&a.locked||this.removeAnchorHand();break;case"h":case"H":(o=this.store.active[0])!=null&&o.locked||this.addAnchorHand();break;case"m":case"M":this.toggleMagnifier();break;case"g":case"G":if(t.ctrlKey||t.metaKey){t.shiftKey?this.parent.uncombine():this.store.active.length>1&&this.parent.combine(this.store.active),t.preventDefault();break}this.hoverType===st.NodeAnchor&&(this.movingAnchor=this.store.hoverAnchor,this.externalElements.style.cursor="move");break;case"s":case"S":!this.store.data.locked&&this.hoverType===st.LineAnchor&&this.store.hover===this.store.active[0]&&this.splitLine(this.store.active[0],this.store.hoverAnchor),(t.ctrlKey||t.metaKey)&&this.store.emitter.emit("save",{event:t});break;case"c":case"C":(t.ctrlKey||t.metaKey)&&this.store.options.disableClipboard&&this.copy();break;case"x":case"X":(t.ctrlKey||t.metaKey)&&this.store.options.disableClipboard&&this.cut();break;case"√":case"v":case"V":!t.ctrlKey&&!t.metaKey&&(this.pencil&&this.stopPencil(),this.drawingLineName?(this.finishDrawline(),this.drawingLineName=""):this.drawingLineName=this.store.options.drawingLineName),!this.store.data.locked&&(t.ctrlKey||t.metaKey)&&(this.store.options.disableClipboard||!this.store.options.disableClipboard&&t.altKey)&&this.paste();break;case"b":case"B":this.drawingLineName&&(this.finishDrawline(),this.drawingLineName=""),this.pencil?this.stopPencil():this.drawingPencil();break;case"y":case"Y":(t.ctrlKey||t.metaKey)&&this.redo();break;case"z":case"Z":t.ctrlKey||t.metaKey?t.shiftKey?this.redo():this.undo():t.shiftKey&&this.redo();break;case"Enter":this.drawingLineName&&(this.finishDrawline(!0),this.store.active[0].anchors[0].connectTo?this.drawingLineName="":this.drawingLineName=this.store.options.drawingLineName),this.store.active&&(this.store.active.forEach(n=>{n.type?(n.close=!n.close,n.close&&gs(n),this.store.path2dMap.set(n,it.path2dDraws.line(n)),Si(n)):n.calculative.focus=!0}),this.render());break;case"Escape":this.drawingLineName&&this.finishDrawline(),this.drawingLineName=void 0,this.stopPencil(),this.store.active&&this.store.active.forEach(n=>{n.type||(n.calculative.focus=!1)}),this.movingPens&&(this.getAllByPens(this.movingPens).forEach(n=>{this.store.pens[n.id]=void 0}),this.movingPens=void 0,this.mouseDown=void 0,this.clearDock(),(l=this.store.active)==null||l.forEach(n=>{this.updateLines(n)}),this.calcActiveRect(),this.patchFlags=!0),this.hotkeyType=ft.None,this.movingAnchor=void 0,this.magnifierCanvas.magnifier&&(this.magnifierCanvas.magnifier=!1,this.patchFlags=!0);break;case"E":case"e":this.store.options.disableAnchor=!this.store.options.disableAnchor,this.store.emitter.emit("disableAnchor",this.store.options.disableAnchor);break;case"=":(t.ctrlKey||t.metaKey)&&(this.scale(this.store.data.scale+.1),t.preventDefault(),t.stopPropagation());break;case"-":(t.ctrlKey||t.metaKey)&&(this.scale(this.store.data.scale-.1),t.preventDefault(),t.stopPropagation());break;case"l":case"L":this.canMoveLine=!0;break;case"[":this.parent.down();break;case"]":this.parent.up();break;case"{":this.parent.bottom();break;case"}":this.parent.top();break;case"F":case"f":!this.store.data.locked&&(t.ctrlKey||t.metaKey)&&!this.store.options.disableClipboard&&this.paste(),this.setFollowers();break}this.render(!1)});D(this,"onkeyup",t=>{switch(t.key){case"l":case"L":this.canMoveLine=!1;break}this.hotkeyType&&this.render(),this.hotkeyType<ft.AddAnchor&&(this.hotkeyType=ft.None)});D(this,"ondrop",async t=>{if(this.store.data.locked){console.warn("canvas is locked, can not drop");return}t.preventDefault(),t.stopPropagation();const i=t.dataTransfer.getData("Meta2d")||t.dataTransfer.getData("Text");let s=null;try{i&&(s=JSON.parse(i))}catch{}if(!s){const{files:r}=t.dataTransfer;if(r.length&&r[0].type.match("image.*")&&!(this.addCaches&&this.addCaches.length)){const a=r[0].type==="image/gif";s=await this.fileToPen(r[0],a)}else if(this.addCaches&&this.addCaches.length)s=this.addCaches,this.addCaches=[];else{this.store.emitter.emit("drop",void 0);return}}if(s=Array.isArray(s)?s:[s],s[0]&&s[0].draggable!==!1){const r={x:t.offsetX,y:t.offsetY};this.calibrateMouse(r),await this.dropPens(s,r),this.addCaches=[],this.getContainerHover(r),this.mousePos.x=r.x,this.mousePos.y=r.y,this.store.emitter.emit("mouseup",{x:r.x,y:r.y,pen:this.store.hoverContainer})}this.store.emitter.emit("drop",s||i)});D(this,"ontouchstart",t=>{if(this.viewAnimation=void 0,this.lastTouchY=t.touches[0].clientY,this.store.data.locked===ct.Disable)return;const i=new Date().getTime(),s=i-this.lastTapTime;s<300&&s>0&&t.touches.length!==2&&this.ondblclick(t),this.lastTapTime=i,this.touchStartTimer&&clearTimeout(this.touchStartTimer),this.touchStartTimer=setTimeout(()=>{this.touchStart=performance.now();const r=t.touches[0].pageX-this.clientRect.x,a=t.touches[0].pageY-this.clientRect.y,o={x:r,y:a};if(this.calibrateMouse(o),this.getHover(o),this.onMouseDown({x:r,y:a,clientX:t.touches[0].clientX,clientY:t.touches[0].clientY,pageX:t.touches[0].pageX,pageY:t.touches[0].pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:1}),t.touches.length===2){this.mouseDown=void 0,this.initTouchDis=Math.hypot(t.touches[0].pageX-t.touches[1].pageX,t.touches[0].pageY-t.touches[1].pageY),this.initScale=this.store.data.scale,this.startTouches=t.touches,this.touchCenter={x:t.touches[0].pageX+(t.touches[1].pageX-t.touches[0].pageX)/2-this.clientRect.x,y:t.touches[0].pageY+(t.touches[1].pageY-t.touches[0].pageY)/2-this.clientRect.y},this.startDistance=this.getDistance(t.touches[0],t.touches[1]),this.startCenter=this.getCenter(t.touches[0],t.touches[1]),this.currentCenter={...this.startCenter},this.touchScaling=void 0,this.touchMoving=void 0;return}else t.touches.length===3&&(this.store.emitter.emit("contextmenu",{e:{x:r,y:a,clientX:t.touches[0].clientX,clientY:t.touches[0].clientY,pageX:t.touches[0].pageX,pageY:t.touches[0].pageY},clientRect:this.clientRect}),t.preventDefault(),t.stopPropagation());this.touchStartTimer=void 0},50)});D(this,"ontouchmove",t=>{var l,n;if(this.store.data.locked===ct.Disable)return;t.stopPropagation(),t.preventDefault();const i=performance.now();if(i-this.touchStart<50)return;this.touchStart=i;const s=t.touches,r=s.length,a=t.touches[0].pageX-this.clientRect.x,o=t.touches[0].pageY-this.clientRect.y;if(r===1){const h=this.lastTouchY-t.touches[0].clientY;if(h){const c={x:a,y:o};if(this.calibrateMouse(c),this.getHover(c),(l=this.store.hover)!=null&&l.onWheel){this.onwheel(this.touchToWheelEvent(t,h)),this.lastTouchY=t.touches[0].clientY;return}}if(this.store.options.scroll&&this.scroll&&!this.store.options.scrollButScale){if(!h)return;this.scroll.wheel(h),this.lastTouchY=t.touches[0].clientY;return}this.onMouseMove({x:a,y:o,clientX:t.changedTouches[0].clientX,clientY:t.changedTouches[0].clientY,pageX:t.changedTouches[0].pageX,pageY:t.changedTouches[0].pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:1})}else if(r===2&&((n=this.startTouches)==null?void 0:n.length)===2){if(this.mouseDown=void 0,!this.touchMoving&&!this.touchScaling){const h=this.getDistance(s[0],s[1]),c=this.getCenter(s[0],s[1]),f=h-this.startDistance,u=c.x-this.currentCenter.x,d=c.y-this.currentCenter.y,v=Math.sqrt(u*u+d*d);Math.abs(f)/this.startDistance>v/100?this.touchScaling=!0:v>5&&(this.touchMoving=!0)}if(this.touchScaling){if(this.store.data.disableScale||this.store.options.disableScale)return;const h=Math.hypot(s[0].pageX-s[1].pageX,s[0].pageY-s[1].pageY)/this.initTouchDis;this.scale(this.initScale*h,K(this.touchCenter))}if(this.touchMoving){if(this.store.data.locked>=ct.DisableMove&&this.store.data.locked!==ct.DisableScale||this.store.data.disableScale||this.store.options.disableScale)return;if(this.lastOffsetX){const{scale:h}=this.store.data;this.translate((a-this.lastOffsetX)/h,(o-this.lastOffsetY)/h)}this.lastOffsetX=a,this.lastOffsetY=o}}});D(this,"ontouchend",t=>{if(this.store.data.locked===ct.Disable)return;this.touchCenter=void 0,this.touchScaling=void 0,this.touchMoving=void 0,this.startTouches=void 0,this.lastOffsetX=0,this.lastOffsetY=0;const i=t.changedTouches[0].pageX-this.clientRect.x,s=t.changedTouches[0].pageY-this.clientRect.y;setTimeout(()=>{this.onMouseUp({x:i,y:s,clientX:t.changedTouches[0].clientX,clientY:t.changedTouches[0].clientY,pageX:t.changedTouches[0].pageX,pageY:t.changedTouches[0].pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:1}),this.render()},60)});D(this,"onGesturestart",t=>{t.preventDefault()});D(this,"onMouseDown",t=>{var i,s,r,a,o;if(this.viewAnimation=void 0,t.buttons===2&&!this.drawingLine&&(this.mouseRight=Qt.Down),this.hideInput(),this.popconfirm.hide(),this.store.data.locked===ct.Disable||t.buttons!==1&&t.buttons!==2){this.hoverType=st.None;return}if(!this.magnifierCanvas.magnifier){if(this.calibrateMouse(t),this.mousePos.x=t.x,this.mousePos.y=t.y,this.mouseDown=t,this.lastMouseTime=performance.now(),this.canvasImage.fitFlag){this.canvasImage.currentFit||this.calcuActiveFit();return}if(this.hotkeyType===ft.AddAnchor){this.setAnchor(this.store.pointAt);return}if(!this.store.options.autoAnchor&&!this.drawingLine&&t.shiftKey&&t.ctrlKey&&t.altKey){this.setAnchor(this.store.pointAt),this.drawingLineName=this.store.options.drawingLineName;const l=this.store.activeAnchor;if(!l)return;const n={id:lt(),x:l.x,y:l.y};this.drawingLine=this.createDrawingLine(n);let h=xt(this.drawingLine);this.drawingLine.calculative.activeAnchor=h,Tt(this.store.hover,l,this.drawingLine,n),this.drawline();return}if(!(this.hotkeyType===ft.Translate||this.mouseRight===Qt.Down&&!this.store.options.mouseRightActive)){if(this.drawingLine){if(this.store.hoverAnchor){const n=dt(this.drawingLine);this.store.hoverAnchor.type===$t.Line?ei(n,this.store.hoverAnchor,this.store):(n.x=this.store.hoverAnchor.x,n.y=this.store.hoverAnchor.y),Tt(this.store.hover,this.store.hoverAnchor,this.drawingLine,n),this.drawline(),this.finishDrawline(!0);return}if(!this.store.options.autoAnchor&&t.shiftKey&&t.altKey&&t.ctrlKey){this.setAnchor(this.store.pointAt);const n=dt(this.drawingLine),h=this.store.activeAnchor;if(!h)return;n.x=h.x,n.y=h.y,Tt(this.store.hover,h,this.drawingLine,n),this.drawline(),this.finishDrawline(!0);return}if(t.buttons===2||this.drawingLineName==="mind"&&((i=this.drawingLine)==null?void 0:i.calculative.worldAnchors.length)>1||this.store.options.drawingLineLength&&((s=this.drawingLine)==null?void 0:s.calculative.worldAnchors.length)>this.store.options.drawingLineLength){this.finishDrawline(!0),(r=this.store.active[0])!=null&&r.anchors[0].connectTo||this.store.active.length==0?this.drawingLineName="":this.drawingLineName=this.store.options.drawingLineName;return}if(this.store.options.autoAnchor&&this.hoverType===st.Node){const n=dt(this.drawingLine),h=_e(this.store.hover,t);n.x=h.x,n.y=h.y,this.drawingLine.autoTo=!0,Tt(this.store.hover,h,this.drawingLine,n),this.drawline(),this.finishDrawline(!0);return}const l=dt(this.drawingLine);l.isTemp?(this.drawingLine.calculative.activeAnchor=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2],l.isTemp=void 0):(this.drawingLine.calculative.activeAnchor=l,this.drawingLine.calculative.worldAnchors.push({x:l.x,y:l.y,penId:l.penId})),this.drawingLine.calculative.drawlineH=void 0,this.drawingLineName!=="polyline"&&this.drawline()}if(this.drawingLineName){if(this.hoverType===st.Node)if(this.store.options.autoAnchor){this.inactive(!0);const l=_e(this.store.hover,t);this.store.hoverAnchor=l;const n={id:lt(),x:l.x,y:l.y};this.drawingLine=this.createDrawingLine(n),this.drawingLine.autoFrom=!0,Tt(this.store.hover,l,this.drawingLine,n)}else this.inactive(),this.hoverType=st.None;else if(this.hoverType===st.NodeAnchor){this.drawingLineName=this.store.options.drawingLineName;const l={id:lt(),x:this.store.hoverAnchor.x,y:this.store.hoverAnchor.y};this.drawingLine=this.createDrawingLine(l),this.drawingLine.calculative.activeAnchor=l,Tt(this.store.hover,this.store.hoverAnchor,this.drawingLine,l)}else if(!this.drawingLine&&this.drawingLineName!=="curve"){this.inactive(!0);const l={id:lt(),x:t.x,y:t.y};this.drawingLine=this.createDrawingLine(l),this.drawingLine.calculative.activeAnchor=l}}else if(this.pencil){this.inactive(!0);const l=lt(),n={x:t.x,y:t.y,id:lt(),penId:l};this.pencilLine=this.getInitPencilLine(n)}else{switch(this.hoverType){case st.None:(this.store.data.rule||this.store.options.rule)&&!this.store.options.disableRuleLine&&this.addRuleLine(t),this.store.options.resizeMode&&(this.hotkeyType=ft.None),this.inactive();break;case st.Node:case st.Line:if(this.store.hover){if((a=this.store.active)!=null&&a.length&&this.store.active.length===1&&this.store.hover.id===this.store.active[0].id){this.calcActiveRect();break}const l=Mt(this.store.hover,!0);let n=l||this.store.hover;l&&(l.container||(o=this.store.options.containerShapes)!=null&&o.includes(l.name))&&(n=this.store.hover),t.ctrlKey&&!t.shiftKey?(n.calculative.active?this.willInactivePen=n:this.store.active.length>0&&(n.calculative.active=!0,Ae(n),this.store.active.push(n),this.store.emitter.emit("active",this.store.active)),this.patchFlags=!0):t.ctrlKey&&t.shiftKey&&this.store.hover.parentId?this.active([this.store.hover]):(!(this.activeRect&&Jt({x:t.x,y:t.y},this.activeRect))||this.store.active.length==1)&&(n.calculative.active||(this.active([n]),this.store.options.resizeMode&&(this.hotkeyType=ft.Resize))),this.calcActiveRect()}break;case st.LineAnchor:this.store.activeAnchor=this.store.hoverAnchor,this.store.hover.calculative.activeAnchor=this.store.hoverAnchor,this.active([this.store.hover]);break;case st.LineAnchorPrev:case st.LineAnchorNext:this.store.activeAnchor&&(this.prevAnchor={...this.store.activeAnchor.prev},this.nextAnchor={...this.store.activeAnchor.next});break;case st.Resize:this.activeInitPos=[],this.store.active.forEach(l=>{this.activeInitPos.push({x:(l.calculative.worldRect.x-this.activeRect.x)/this.activeRect.width,y:(l.calculative.worldRect.y-this.activeRect.y)/this.activeRect.height})});break}this.store.hover&&(this.store.hover.calculative.mouseDown=!0),this.store.emitter.emit("mousedown",{x:t.x,y:t.y,pen:this.store.hover})}this.render()}}});D(this,"onMouseMove",t=>{var s,r,a,o,l,n,h,c,f;if(this.store.data.locked===ct.Disable){this.hoverType=st.None;return}if(this.mouseDown&&!this.mouseDown.restore&&t.buttons!==1&&t.buttons!==2){this.onMouseUp(t);return}if(this.lastMouseTime){if(performance.now()-this.lastMouseTime<50){this.lastMouseTime=0;return}this.lastMouseTime=0}if(this.calibrateMouse(t),this.mousePos.x=t.x,this.mousePos.y=t.y,this.magnifierCanvas.magnifier){this.render();return}if(this.canvasImage.fitFlag&&this.canvasImage.activeFit){const u=performance.now();u-this.fitTimer>100&&(this.mouseDown?this.updateFit(t):this.inFitBorder(this.mousePos),this.fitTimer=u);return}if(this.mouseDown&&!this.store.options.disableTranslate&&!this.store.data.disableTranslate){this.mouseRight===Qt.Down&&(this.mouseRight=Qt.Translate);const u=this.store.active[0];if(u&&this.store.data.locked&&(u.locked===void 0||u.locked<ct.DisableMove)){(s=u==null?void 0:u.onMouseMove)==null||s.call(u,u,this.mousePos);return}if(this.store.data.locked===ct.DisableEdit||this.store.data.locked===ct.DisableScale||this.hotkeyType===ft.Translate||this.mouseRight===Qt.Translate){const{scale:d}=this.store.data;let v=(t.x-this.mouseDown.x)/d,g=(t.y-this.mouseDown.y)/d;t.shiftKey&&!t.ctrlKey&&(g=0),t.ctrlKey&&(v=0),this.translate(v,g);return}if(this.store.data.locked)return;if(!this.drawingLine&&!this.pencil){if(!this.drawingLineName&&!this.movingAnchor){if(this.hoverType===st.NodeAnchor){if(!this.store.hoverAnchor)return;this.drawingLineName=this.store.options.drawingLineName;const d={id:lt(),x:this.store.hoverAnchor.x,y:this.store.hoverAnchor.y};this.drawingLine=this.createDrawingLine(d),this.drawingLine.calculative.activeAnchor=d,Tt(this.store.hover,this.store.hoverAnchor,this.drawingLine,d),this.drawline();return}}else if(this.drawingLineName&&this.hoverType===st.None){const d={id:lt(),x:t.x,y:t.y};this.drawingLine=this.createDrawingLine(d),this.drawingLine.calculative.activeAnchor=d,this.drawline();return}if(t.buttons===1&&(t.ctrlKey||!this.hoverType&&!this.hotkeyType)&&!(t.ctrlKey&&(this.store.activeAnchor||(r=this.store.active)!=null&&r.length))){this.dragRect={x:Math.min(this.mouseDown.x,t.x),y:Math.min(this.mouseDown.y,t.y),ex:Math.max(this.mouseDown.x,t.x),ey:Math.max(this.mouseDown.y,t.y),width:Math.abs(t.x-this.mouseDown.x),height:Math.abs(t.y-this.mouseDown.y)},this.render();return}if(this.movingAnchor){const d=t.x-this.movingAnchor.x,v=t.y-this.movingAnchor.y;this.translateAnchor(d,v),this.render();return}else if(!((a=this.store.active[0])!=null&&a.locked)){const d={x:t.x,y:t.y};if(this.hoverType===st.LineAnchor){(this.dockInAnchor(t)||((o=this.store.active[0])==null?void 0:o.lineName)==="line")&&!this.store.options.disableDock&&!this.store.options.disableLineDock&&(this.clearDock(),this.dock=zs(this.store,d,this.store.activeAnchor),(l=this.dock)!=null&&l.xDock&&(d.x+=this.dock.xDock.step),(n=this.dock)!=null&&n.yDock&&(d.y+=this.dock.yDock.step)),this.moveLineAnchor(d,t);return}if(this.hoverType===st.LineAnchorPrev){this.moveLineAnchorPrev(t);return}if(this.hoverType===st.LineAnchorNext){this.moveLineAnchorNext(t);return}}if(this.hoverType===st.Rotate){this.rotatePens({x:t.x,y:t.y});return}if(this.hoverType===st.Resize){this.resizePens(t);return}if(this.hoverType===st.Node||this.hoverType===st.Line){const d=t.x-this.mouseDown.x,v=t.y-this.mouseDown.y,g=20;if(t.ctrlKey&&!t.shiftKey&&(Math.abs(d)>=g||Math.abs(v)>=g)&&(this.willInactivePen=void 0),this.store.active.length===1){const y=this.store.active[0];if((y.locked===void 0||y.locked<ct.DisableMove)&&((h=y==null?void 0:y.onMouseMove)==null||h.call(y,y,this.mousePos)),y.calculative.focus)return}this.movePens(t),this.getContainerHover(t);return}}else if(this.pencil){const{x:d,y:v}=t,g={x:d,y:v};g.id=lt(),g.penId=this.pencilLine.id,this.pencilLine.calculative.worldAnchors.push(g),this.store.path2dMap.set(this.pencilLine,it.path2dDraws[this.pencilLine.name](this.pencilLine)),this.patchFlags=!0}}if(this.drawingLine){const{x:u,y:d}=t,v={x:u,y:d};if(v.id=lt(),v.penId=this.drawingLine.id,!this.store.options.disableDock&&!this.store.options.disableLineDock&&(this.clearDock(),this.dock=zs(this.store,v),(c=this.dock)!=null&&c.xDock&&(v.x+=this.dock.xDock.step),(f=this.dock)!=null&&f.yDock&&(v.y+=this.dock.yDock.step)),this.mouseDown&&this.drawingLineName==="curve"&&!this.drawingLine.calculative.worldAnchors[0].connectTo)this.drawline(v);else{let g;if(this.drawingLine.calculative.worldAnchors.length>1&&(g=dt(this.drawingLine)),g?(g.prev=void 0,g.next=void 0,g.id||(g.id=lt()),g.x=v.x,g.y=v.y,g.connectTo=void 0):(g={...v},this.drawingLine.calculative.worldAnchors.push(g)),(this.hoverType===st.NodeAnchor||this.hoverType===st.LineAnchor)&&(this.store.hoverAnchor.type!==$t.Line&&(g.x=this.store.hoverAnchor.x,g.y=this.store.hoverAnchor.y),g.connectTo=this.store.hoverAnchor.penId,this.drawingLineName==="polyline"&&(g.isTemp=!1)),this.drawingLineName==="line"){if(t.ctrlKey&&!t.shiftKey)g.x=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].x;else if(t.shiftKey&&!t.ctrlKey)g.y=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].y;else if(t.shiftKey&&t.ctrlKey){let y=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2];this.getSpecialAngle(g,y)}}this.drawline()}}globalThis.debug&&console.time("hover");const i=performance.now();i-this.hoverTimer>50&&(this.hoverTimer=i,this.getHover(t)),globalThis.debug&&console.timeEnd("hover"),this.hotkeyType===ft.AddAnchor&&(this.patchFlags=!0),this.render(!1)});D(this,"onMouseUp",t=>{if(this.store.data.locked===ct.Disable){this.hoverType=st.None;return}if(this.mouseDown){if(this.mouseRight===Qt.Down&&(this.store.hover&&this.store.hover.onContextmenu?this.store.hover.onContextmenu(this.store.hover,t):this.store.emitter.emit("contextmenu",{e:t,clientRect:this.clientRect,pen:this.store.hover})),this.mouseRight=Qt.None,this.calibrateMouse(t),this.mousePos.x=t.x,this.mousePos.y=t.y,this.pencil&&this.finishPencil(),this.drawingLine){if(this.store.hoverAnchor){const i=dt(this.drawingLine);this.store.hoverAnchor.type===$t.Line?ei(i,this.store.hoverAnchor,this.store):(i.x=this.store.hoverAnchor.x,i.y=this.store.hoverAnchor.y),Tt(this.store.hover,this.store.hoverAnchor,this.drawingLine,i),this.drawline(),this.finishDrawline(!0);return}if(this.store.options.autoAnchor&&this.hoverType===st.Node){const i=dt(this.drawingLine),s=_e(this.store.hover,t);i.x=s.x,i.y=s.y,this.drawingLine.autoTo=!0,Tt(this.store.hover,s,this.drawingLine,i),this.drawline(),this.finishDrawline(!0);return}}if(this.hoverType===st.LineAnchor&&this.store.hover&&this.store.active[0]&&this.store.active[0].name==="line"&&this.store.active[0]!==this.store.hover){const i=this.store.active[0],s=xt(i),r=dt(i);if(this.store.hoverAnchor){const a=this.store.hover,o=xt(a)===this.store.hoverAnchor,l=dt(a)===this.store.hoverAnchor,n=s===this.store.activeAnchor,h=r===this.store.activeAnchor;if((t.ctrlKey||t.altKey)&&a.type===ut.Line&&(o||l)&&(n||h)){const c=a.calculative.worldAnchors.map(f=>({...f,penId:i.id}));o?c.shift():l&&c.pop(),(o&&n||l&&h)&&c.reverse(),n?(i.calculative.worldAnchors[0].connectTo=void 0,i.calculative.worldAnchors.unshift(...c)):h&&(i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].connectTo=void 0,i.calculative.worldAnchors.push(...c)),this.delete([a]),this.render()}else this.store.activeAnchor&&(this.store.hoverAnchor.type===$t.Line?ei(this.store.activeAnchor,this.store.hoverAnchor,this.store):(this.store.activeAnchor.x=this.store.hoverAnchor.x,this.store.activeAnchor.y=this.store.hoverAnchor.y),Tt(this.store.hover,this.store.hoverAnchor,i,this.store.activeAnchor));this[i.lineName]&&i.lineName!=="polyline"&&this[i.lineName](this.store,i),this.store.path2dMap.set(i,it.path2dDraws.line(i)),this.initLineRect(i)}else s===this.store.activeAnchor&&i.autoFrom?this.calcAutoAnchor(i,s,this.store.hover):r===this.store.activeAnchor&&i.autoTo&&this.calcAutoAnchor(i,r,this.store.hover)}if(this.addCaches&&this.addCaches.length){if(!this.store.data.locked){if(this.dragRect&&this.addCaches.length===1){const i=this.addCaches[0];i.width=this.dragRect.width/this.store.data.scale,i.height=this.dragRect.height/this.store.data.scale,t.x=(this.dragRect.x+this.dragRect.ex)/2,t.y=(this.dragRect.y+this.dragRect.ey)/2}this.dropPens(this.addCaches,t)}this.addCaches=void 0}if(this.hoverType===st.Rotate&&(this.getSizeCPs(),this.store.active.forEach(i=>{i.rotate=i.calculative.rotate})),this.patchFlagsLines.forEach(i=>{i.type&&this.initLineRect(i)}),this.patchFlagsLines.clear(),this.dragRect)if(this.canvasImage.fitFlag)this.makeFit();else{const i=this.store.data.pens.filter(s=>{if(s.visible===!1||s.locked>=ct.DisableMove||s.parentId||s.isRuleLine)return!1;if(ee(s.calculative.worldRect,this.dragRect,t.ctrlKey||this.store.options.dragAllIn))return s.type===ut.Line&&!this.store.options.dragAllIn?ji(s,this.dragRect):!0});this.active(i)}if(t.button!==2&&(Mi(this.mouseDown,t)<2&&(this.store.hover&&this.store.hover.input&&(this.store.hover.onShowInput?this.store.hover.onShowInput(this.store.hover,t):(this.store.hover.parentId&&this.active([this.store.hover]),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.hover.calculative.mouseDown=!1),this.store.hover!=this.store.hoverContainer&&this.store.emitter.emit("mouseup",{x:t.x,y:t.y,pen:this.store.hover}),this.store.emitter.emit("mouseup",{x:t.x,y:t.y,pen:this.store.hoverContainer})),this.willInactivePen){this.willInactivePen.calculative.active=void 0,Ae(this.willInactivePen,!1);const i=this.store.active.findIndex(s=>s===this.willInactivePen);i>=0&&this.store.active.splice(i,1),this.calcActiveRect(),this.willInactivePen=void 0,this.store.emitter.emit("inactive",[this.willInactivePen]),this.render()}this.movingPens&&(t.altKey&&!t.shiftKey?this.copyMovedPens():this.movedActivePens(t.ctrlKey&&t.shiftKey),this.getAllByPens(this.movingPens).forEach(i=>{this.store.pens[i.id]=void 0}),this.movingPens=void 0),this.store.active&&this.store.active[0]&&(this.store.active[0].calculative.h=void 0),this.mouseDown=void 0,this.lastOffsetX=0,this.lastOffsetY=0,this.clearDock(),this.dragRect=void 0,this.initActiveRect=void 0,this.render()}});D(this,"clearDock",()=>{var a,o,l,n;const t=(o=(a=this.dock)==null?void 0:a.xDock)==null?void 0:o.penId,i=(n=(l=this.dock)==null?void 0:l.yDock)==null?void 0:n.penId,s=this.store.pens[t];s&&(s.calculative.isDock=!1);const r=this.store.pens[i];r&&(r.calculative.isDock=!1),this.dock=void 0});D(this,"onResize",()=>{this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.resize(),this.timer=void 0},100)});D(this,"onScroll",()=>{this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.clientRect=this.canvas.getBoundingClientRect(),this.timer=void 0},100)});D(this,"calibrateMouse",t=>(t.x-=this.store.data.x,t.y-=this.store.data.y,t));D(this,"getContainerHover",t=>{var s;if(this.dragRect)return;const i=this.store.data.pens.filter(r=>{var a;return r.container||((a=this.store.options.containerShapes)==null?void 0:a.includes(r.name))});if(i.length)for(let r=i.length-1;r>=0;--r){const a=i[r];if(!(a.visible==!1||a.calculative.inView==!1||a.locked===ct.Disable)){if(Jt(t,a.calculative.worldRect))this.store.hoverContainer=a,(s=a==null?void 0:a.onMouseMove)==null||s.call(a,a,t),this.store.lastHoverContainer!==this.store.hoverContainer&&(this.patchFlags=!0,this.store.lastHoverContainer&&(this.store.lastHoverContainer.calculative.containerHover=!1,this.store.emitter.emit("leave",this.store.lastHoverContainer)),this.store.hoverContainer&&(this.store.hoverContainer.calculative.containerHover=!0,this.store.emitter.emit("enter",this.store.hoverContainer)),this.store.lastHoverContainer=this.store.hoverContainer);else if(a===this.store.hoverContainer&&(this.store.hoverContainer=void 0,this.store.lastHoverContainer!==this.store.hoverContainer)){this.patchFlags=!0;const o=this.store.lastHoverContainer.calculative.canvas.store.pens[this.store.lastHoverContainer.id+Lt];this.store.lastHoverContainer&&!o&&(this.store.lastHoverContainer.calculative.containerHover=!1,this.store.emitter.emit("leave",this.store.lastHoverContainer)),this.store.lastHoverContainer=this.store.hoverContainer}}}});D(this,"lastHoverType",st.None);D(this,"getHover",t=>{var r,a;if(this.dragRect||this.canvasImage.fitFlag)return;let i=st.None;this.store.hover=void 0,this.store.hoverAnchor=void 0,this.title.hide(),this.store.pointAt=void 0,this.store.pointAtIndex=void 0;const s=this.store.active.length===1&&this.store.active[0].type;if(!this.drawingLineName&&this.hotkeyType!==ft.AddAnchor&&this.activeRect&&!s&&!this.store.data.locked){const o=zi(this.store.active),l=Bs(this.store.active)||this.store.options.disableRotate,n=Ns(this.store.active)||this.store.options.disableSize;if(!o&&!l){const h={x:this.activeRect.center.x,y:this.activeRect.y-30};this.activeRect.rotate&&vt(h,this.activeRect.rotate,this.activeRect.pivot||this.activeRect.center),!this.hotkeyType&&Ce(t,h,this.pointSize)&&(i=st.Rotate,this.externalElements.style.cursor=`url("${this.store.options.rotateCursor}"), auto`)}if(!o&&!n)for(let h=0;h<8;h++){const c=h<4;if((this.hotkeyType===ft.Resize||c&&!this.hotkeyType)&&Ce(t,this.sizeCPs[h],this.pointSize)){let u=c?Rs:Ts,d=0;Math.abs(this.activeRect.rotate%90-45)<25?(u=c?Ts:Rs,d=Math.round((this.activeRect.rotate-45)/90)+(c?0:1)):d=Math.round(this.activeRect.rotate/90),i=st.Resize,this.resizeIndex=h,this.externalElements.style.cursor=u[(h+d)%4];break}}}i===st.None&&(i=this.inPens(t,this.store.data.pens)),!i&&!s&&Jt(t,this.activeRect)&&(i=st.Node,this.externalElements.style.cursor="move"),this.hoverType=i,i===st.None&&(this.drawingLineName||this.pencil?this.externalElements.style.cursor="crosshair":this.mouseDown||(this.externalElements.style.cursor="default"),this.store.hover=void 0),this.store.lastHover!==this.store.hover&&(this.patchFlags=!0,this.store.lastHover&&(this.store.lastHover.calculative.hover=!1,qe(Mt(this.store.lastHover,!0)||this.store.lastHover,!1),this.store.pens[this.store.lastHover.id]&&this.store.emitter.emit("leave",this.store.lastHover),this.tooltip.hide()),this.store.hover&&(this.store.hover.calculative.hover=!0,qe(Mt(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),[st.LineAnchor,st.NodeAnchor].includes(i)&&![st.LineAnchor,st.NodeAnchor].includes(this.lastHoverType)&&this.store.emitter.emit("enterAnchor",{pen:this.store.hover,anchor:this.store.hoverAnchor}),this.lastHoverType=i,(a=(r=this.store.hover)==null?void 0:r.onMouseMove)==null||a.call(r,this.store.hover,this.mousePos)});D(this,"inPens",(t,i)=>{var r;let s=st.None;t:for(let a=i.length-1;a>=0;--a){const o=i[a];if(o.visible==!1||o.calculative.inView==!1||o.locked===ct.Disable||this.store.data.locked&&o.name==="sceneContainer")continue;const l=this.store.data.locked&&o.ignoreEvent===!0,n=Ai(o);if(!(!o.calculative.active&&!xe(t,o.calculative.worldRect,n)&&!Jt(t,o.calculative.worldRect))){if(!l&&!this.store.data.locked&&this.hotkeyType!==ft.Resize&&o.calculative.worldAnchors){for(const h of o.calculative.worldAnchors)if(s=this.inAnchor(t,o,h),s){let c=K(h);Object.assign(c,t),this.title.show(c,o);break t}}if(o.type){if(l)continue;if(o.isRuleLine){let c=((r=this.store.options.ruleOptions)==null?void 0:r.height)||20;if(t.x+this.store.data.x>c&&t.y+this.store.data.y>c)break}const h=an(t,o);if(h){!this.store.data.locked&&!o.locked?this.hotkeyType===ft.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move":this.externalElements.style.cursor=o.hoverCursor||this.store.options.hoverCursor,o.calculative.disabled&&(this.externalElements.style.cursor="not-allowed"),this.store.hover=o,this.store.pointAt=h.point,this.store.pointAtIndex=h.i,this.initTemplateCanvas([this.store.hover]),s=st.Line;break}}else{if(o.children){const c=[];if(o.children.forEach(f=>{this.store.pens[f]&&c.push(this.store.pens[f])}),s=this.inPens(t,c),s)break}if(l)continue;let h=!1;if(o.name==="line"?h=xe(t,o.calculative.worldRect,o.lineWidth):h=Jt(t,o.calculative.worldRect),h){if(o.type===ut.Node&&o.name==="line"&&!mn(t,o.calculative.worldAnchors))continue;if(!this.store.data.locked&&!o.locked?this.hotkeyType===ft.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move":this.externalElements.style.cursor=o.hoverCursor||this.store.options.hoverCursor,o.calculative.disabled&&(this.externalElements.style.cursor="not-allowed"),this.store.hover=o,this.initTemplateCanvas([this.store.hover]),s=st.Node,this.store.pointAt=t,!t.ctrlKey){let{x:c,y:f,ex:u,ey:d,rotate:v,center:g}=this.store.hover.calculative.worldRect;if(v){const y=[{x:c,y:f},{x:u,y:f},{x:u,y:d},{x:c,y:d}];y.forEach(b=>{vt(b,v,g)});let p=y[y.length-1];for(const b of y){if(p.y>t.y!=b.y>t.y){const m=b.x+(t.y-b.y)*(p.x-b.x)/(p.y-b.y);Math.abs(m-this.store.pointAt.x)<10&&(this.store.pointAt.x=m)}p=b}}else this.store.pointAt.x-10<c?this.store.pointAt.x=c:this.store.pointAt.x+10>u&&(this.store.pointAt.x=u),this.store.pointAt.y-10<f?this.store.pointAt.y=f:this.store.pointAt.y+10>d&&(this.store.pointAt.y=d)}break}}}}return s});D(this,"dockInAnchor",t=>{var i,s;this.store.hover=void 0;for(let r=this.store.data.pens.length-1;r>=0;--r){const a=this.store.data.pens[r];if(a.visible==!1||a.locked===ct.Disable||this.store.data.locked&&a.ignoreEvent===!0||a===this.store.active[0])continue;let o=Ai(a);if(o+=2*this.store.options.anchorRadius,!!xe(t,a.calculative.worldRect,o)&&(this.store.hover=a,this.hotkeyType!==ft.Resize&&a.calculative.worldAnchors))for(const l of a.calculative.worldAnchors){if(l.twoWay===At.In){const n=dt(this.store.active[0]);if(this.store.activeAnchor.id!==n.id)continue}if(l.twoWay===At.Out){const n=xt(this.store.active[0]);if(this.store.activeAnchor.id!==n.id)continue}if(!(l.twoWay===At.DisableConnected||l.twoWay===At.Disable||((i=this.store.activeAnchor)==null?void 0:i.twoWay)===At.DisableConnectTo||((s=this.store.activeAnchor)==null?void 0:s.twoWay)===At.Disable)&&(this.title.hide(),this.inAnchor(t,a,l))){let n=K(l);return Object.assign(n,t),this.title.show(n,a),!0}}}});D(this,"__loadMap",new Map);D(this,"imageTimer");D(this,"templateImageTimer");D(this,"render",t=>{if(t&&(this.opening=!1),this.opening)return;let i;if(t==null||t===!0||t===1/0?(i=performance.now(),this.patchFlags=!0):t>1?i=t:i=performance.now(),!this.patchFlags){this.store.options.gridAlwaysRender&&(this.store.options.grid||this.store.data.grid)&&(this.canvasTemplate.bgPatchFlags=!0,this.canvasTemplate.render());return}if(t!=null)if(i-this.lastRender<this.store.options.interval){this.store.options.interval>this.store.options.minFPSNumber&&this.store.options.autoFPS&&(this.store.options.interval--,this.store.options.animateInterval=this.store.options.interval),this.renderTimer&&cancelAnimationFrame(this.renderTimer),this.renderTimer=requestAnimationFrame(this.render);return}else i-this.lastRender-this.store.options.interval>10&&this.store.options.autoFPS&&document.visibilityState==="visible"&&(this.store.options.interval++,this.store.options.animateInterval=this.store.options.interval);this.renderTimer=void 0,this.lastRender=i;const s=this.offscreen.getContext("2d");s.clearRect(0,0,this.offscreen.width,this.offscreen.height),s.save(),s.translate(this.store.data.x,this.store.data.y),globalThis.debugRender&&console.time("renderPens"),this.renderPens(),globalThis.debugRender&&console.timeEnd("renderPens"),this.renderBorder(),this.renderHoverPoint(),this.renderPensAnchors(),s.restore(),this.magnifierCanvas.magnifier&&this.magnifierCanvas.render();const r=this.canvas.getContext("2d");r.clearRect(0,0,this.canvas.width,this.canvas.height),r.drawImage(this.offscreen,0,0,this.width,this.height),this.canvasTemplate.render(),this.canvasImageBottom.render(),this.canvasImage.render(),this.patchFlags=!1});D(this,"renderPens",()=>{const t=this.offscreen.getContext("2d");t.strokeStyle=this.store.styles.color;for(const i of this.store.data.pens)isFinite(i.x)&&i.canvasLayer!==ht.CanvasTemplate&&i.calculative.inView&&(i.canvasLayer===ht.CanvasMain&&i.name!=="gif"&&i.image&&i.calculative.img&&(t.save(),we(t,i),(i.rotateByRoot||i.calculative.rotate)&&se(t,i),be(t,i),Me(t,i),t.restore()),de(t,i));this.drawingLine&&de(t,this.drawingLine),this.pencilLine&&de(t,this.pencilLine),this.movingPens&&this.movingPens.forEach(i=>{this.renderPenContainChild(t,i)})});D(this,"renderPenContainChild",(t,i)=>{var s;i.calculative.inView&&de(t,i),(s=i.children)==null||s.forEach(r=>{const a=this.store.pens[r];a&&this.renderPenContainChild(t,a)})});D(this,"renderBorder",()=>{if(!this.store.data.locked&&this.activeRect&&!(this.store.active.length===1&&this.store.active[0].type)&&!this.movingPens){const t=this.offscreen.getContext("2d");t.save(),t.translate(.5,.5);const i=this.activeRect.pivot||this.activeRect.center;if(this.activeRect.rotate&&(t.translate(i.x,i.y),t.rotate(this.activeRect.rotate*Math.PI/180),t.translate(-i.x,-i.y)),t.strokeStyle=this.store.styles.activeColor,t.globalAlpha=this.store.options.activeGlobalAlpha===void 0?.3:this.store.options.activeGlobalAlpha,t.beginPath(),t.lineWidth=this.store.options.activeLineWidth||1,t.setLineDash(this.store.options.activeLineDash||[]),t.strokeRect(this.activeRect.x,this.activeRect.y,this.activeRect.width,this.activeRect.height),t.setLineDash([]),t.lineWidth=1,t.globalAlpha=1,zi(this.store.active)||Bs(this.store.active)||this.store.options.disableRotate){t.restore();return}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.styles.activeColor,t.fillStyle="#ffffff",t.arc(this.activeRect.center.x,this.activeRect.y-30,5,0,Math.PI*2),t.fill(),t.stroke(),t.restore()}});D(this,"renderHoverPoint",()=>{if(this.store.data.locked)return;const t=this.offscreen.getContext("2d");if(t.save(),t.translate(.5,.5),!this.store.options.disableAnchor&&this.store.hover&&!this.store.hover.disableAnchor&&(this.hotkeyType!==ft.Resize||this.store.active.length!==1||this.store.active[0]!==this.store.hover)){const i=[...this.store.hover.calculative.worldAnchors];this.store.pointAt&&this.hotkeyType===ft.AddAnchor&&i.push(this.store.pointAt),i&&(t.strokeStyle=this.store.hover.anchorColor||this.store.styles.anchorColor,t.fillStyle=this.store.hover.anchorBackground||this.store.options.anchorBackground,i.forEach(s=>{if(s.hidden&&s.locked>ct.DisableEdit)return;if(s===this.store.hoverAnchor){t.save();const a=this.store.hover.hoverAnchorColor||this.store.options.hoverAnchorColor;t.strokeStyle=a,t.fillStyle=a}t.beginPath();let r=s.radius||this.store.hover.anchorRadius||this.store.options.anchorRadius;if(this.store.hover.type&&!s.radius&&!this.store.hover.anchorRadius&&(r=3,this.store.hover.calculative.lineWidth>3&&(r=this.store.hover.calculative.lineWidth)),s.type===$t.Line){let a=this.store.pens[s.penId].rotate||0;this.store.pens[s.penId].calculative.flipX&&(a*=-1),this.store.pens[s.penId].calculative.flipY&&(a*=-1);let o=s.rotate+a;this.store.pens[s.penId].calculative.flipX&&(o*=-1),this.store.pens[s.penId].calculative.flipY&&(o*=-1),t.save(),t.translate(s.x,s.y),t.rotate(o*Math.PI/180),t.translate(-s.x,-s.y),t.rect(s.x-s.length*this.store.data.scale/2,s.y-r,s.length*this.store.data.scale,r*2),t.restore()}else t.arc(s.x,s.y,r,0,Math.PI*2);if(this.store.hover.type&&this.store.hoverAnchor===s?(t.save(),t.strokeStyle=this.store.hover.activeColor||this.store.styles.activeColor,t.fillStyle=t.strokeStyle):(s.color||s.background)&&(t.save(),t.strokeStyle=s.color,t.fillStyle=s.background),t.fill(),t.stroke(),s===this.store.hoverAnchor&&t.restore(),(this.store.hover.type&&this.store.hoverAnchor===s||s.color||s.background)&&t.restore(),!this.store.hover.parentId&&this.store.hover.children&&this.store.hover.children.length>0&&s===this.store.hoverAnchor){t.save(),t.beginPath(),t.lineWidth=3;const a=this.store.hover.hoverAnchorColor||this.store.options.hoverAnchorColor;globalThis.pSBC&&(t.strokeStyle=globalThis.pSBC(.5,a)),t.arc(s.x,s.y,r+1.5,0,Math.PI*2),t.stroke(),t.restore()}}))}this.hotkeyType!==ft.AddAnchor&&!this.movingPens&&this.activeRect&&!(this.store.active.length===1&&this.store.active[0].type)&&!zi(this.store.active)&&!Ns(this.store.active)&&!this.store.options.disableSize&&(t.strokeStyle=this.store.styles.activeColor,t.fillStyle="#ffffff",this.sizeCPs.forEach((i,s)=>{this.activeRect.rotate&&(t.save(),t.translate(i.x,i.y),t.rotate(this.activeRect.rotate*Math.PI/180),t.translate(-i.x,-i.y)),(s<4||this.hotkeyType===ft.Resize)&&(t.beginPath(),t.fillRect(i.x-4.5,i.y-4.5,8,8),t.strokeRect(i.x-5.5,i.y-5.5,10,10)),this.activeRect.rotate&&t.restore()})),!this.store.data.locked&&this.dragRect&&(t.save(),t.fillStyle=mi(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()});D(this,"renderPensAnchors",()=>{for(const t of this.store.data.pens)isFinite(t.x)&&t.anchorVisible===!0&&this.renderAnchors(t)});D(this,"renderAnchors",t=>{const i=this.offscreen.getContext("2d");i.save(),i.translate(.5,.5),i.strokeStyle=t.anchorColor||this.store.styles.anchorColor,i.fillStyle=t.anchorBackground||this.store.options.anchorBackground;const{fontStyle:s,fontWeight:r,fontSize:a,fontFamily:o,lineHeight:l}=t.calculative,n=this.store.data.scale;t.calculative.worldAnchors.forEach((h,c)=>{var u,d,v,g,y,p;if(h.hidden||h.locked>ct.DisableEdit)return;if(h===this.store.hoverAnchor){i.save();const b=t.hoverAnchorColor||this.store.options.hoverAnchorColor;i.strokeStyle=b,i.fillStyle=b}i.beginPath();let f=h.radius||t.anchorRadius||this.store.options.anchorRadius;if(t.type&&!h.radius&&!t.anchorRadius&&(f=3,t.calculative.lineWidth>3&&(f=t.calculative.lineWidth)),h.type===$t.Line){let b=this.store.pens[h.penId].rotate||0;this.store.pens[h.penId].calculative.flipX&&(b*=-1),this.store.pens[h.penId].calculative.flipY&&(b*=-1);let m=h.rotate+b;this.store.pens[h.penId].calculative.flipX&&(m*=-1),this.store.pens[h.penId].calculative.flipY&&(m*=-1),i.save(),i.translate(h.x,h.y),i.rotate(m*Math.PI/180),i.translate(-h.x,-h.y),i.rect(h.x-h.length*this.store.data.scale/2,h.y-f,h.length*this.store.data.scale,f*2),i.restore()}else i.arc(h.x,h.y,f,0,Math.PI*2);if(t.type&&this.store.hoverAnchor===h?(i.save(),i.strokeStyle=t.activeColor||this.store.styles.activeColor,i.fillStyle=i.strokeStyle):(h.color||h.background)&&(i.save(),i.strokeStyle=h.color,i.fillStyle=h.background),i.fill(),i.stroke(),h===this.store.hoverAnchor&&i.restore(),(t.type&&this.store.hoverAnchor===h||h.color||h.background)&&i.restore(),h.label){i.save(),i.font=_t({fontStyle:((u=h.labelStyle)==null?void 0:u.fontStyle)||s,fontWeight:((d=h.labelStyle)==null?void 0:d.fontWeight)||r,fontFamily:((v=h.labelStyle)==null?void 0:v.fontFamily)||o,lineHeight:((g=h.labelStyle)==null?void 0:g.lineHeight)||l,fontSize:((y=h.labelStyle)==null?void 0:y.fontSize)*n||a});const b=t.anchors[c].x,m=t.anchors[c].y;let k=0,A=0;h.labelDirection!==void 0?h.labelDirection===nt.Left?(i.textAlign="right",i.textBaseline="middle",k=-(h.labelGap||10)*n):h.labelDirection===nt.Right?(i.textAlign="left",i.textBaseline="middle",k=(h.labelGap||10)*n):h.labelDirection===nt.Up?(i.textAlign="center",i.textBaseline="bottom",A=-(h.labelGap||5)*n):h.labelDirection===nt.Bottom&&(i.textAlign="center",i.textBaseline="top",A=(h.labelGap||5)*n):b<.1?(i.textAlign="left",i.textBaseline="middle",k=(h.labelGap||10)*n):b>.9?(i.textAlign="right",i.textBaseline="middle",k=-(h.labelGap||10)*n):(i.textAlign="center",m<.1?(i.textBaseline="top",A=(h.labelGap||5)*n):m>.9?(i.textBaseline="bottom",A=-(h.labelGap||5)*n):i.textBaseline="middle"),i.fillStyle=((p=h.labelStyle)==null?void 0:p.textColor)||Gt(t,this.store),i.fillText(h.label,h.x+k,h.y+A),i.restore()}if(!t.parentId&&t.children&&t.children.length>0&&h===this.store.hoverAnchor){i.save(),i.beginPath(),i.lineWidth=3;const b=t.hoverAnchorColor||this.store.options.hoverAnchorColor;globalThis.pSBC&&(i.strokeStyle=globalThis.pSBC(.5,b)),i.arc(h.x,h.y,f+1.5,0,Math.PI*2),i.stroke(),i.restore()}}),i.restore()});D(this,"transTimeout");D(this,"animateViewFrame",()=>{if(!this.viewAnimation)return;const t=performance.now(),{startTime:i,duration:s,fromX:r,fromY:a,fromScale:o,toX:l,toY:n,toScale:h,easing:c,center:f,pen:u}=this.viewAnimation;let d=Math.min(1,(t-i)/s);d=c(d);const v=this.store.data.scale,g=o+(h-o)*d,y=g/v;y!==1&&(this.store.data.scale=g,this.store.data.center=f,Pe(this.store.data.origin,y,f),this.store.data.pens.forEach(A=>{if(A.onScale&&A.onScale(A),!A.parentId){if(zt(A,y,f),A.isRuleLine){const S=1/y,I=A.calculative.worldRect.center;A.width&&A.height||zt(A,S,I)}this.updatePenRect(A,{worldRectIsReady:!0}),this.execPenResize(A)}}),this.calcActiveRect());let p,b;if(u){const A={x:this.width/2,y:this.height/2},S=A.x-u.calculative.worldRect.x-u.calculative.worldRect.width/2,I=A.y-u.calculative.worldRect.y-u.calculative.worldRect.height/2;p=r+(S-r)*d,b=a+(I-a)*d}else p=r+(l-r)*d,b=a+(n-a)*d;const m=this.store.data.x,k=this.store.data.y;if(this.store.data.x=p,this.store.data.y=b,this.scroll&&this.scroll.isShow&&this.scroll.translate(p-m,b-k),this.onMovePens(),this.canvasTemplate.init(),this.canvasImage.init(),this.canvasImageBottom.init(),this.render(),d<1)this.viewAnimationTimer=requestAnimationFrame(this.animateViewFrame);else{if(u||(this.store.data.x=l,this.store.data.y=n),Math.abs(this.store.data.scale-h)>.001){const A=h/this.store.data.scale;this.store.data.scale=h,this.store.data.center=f,Pe(this.store.data.origin,A,f),this.store.data.pens.forEach(S=>{if(S.onScale&&S.onScale(S),!S.parentId){if(zt(S,A,f),S.isRuleLine){const I=1/A,E=S.calculative.worldRect.center;S.width&&S.height||zt(S,I,E)}this.updatePenRect(S,{worldRectIsReady:!0}),this.execPenResize(S)}}),this.calcActiveRect(),this.onMovePens(),this.canvasTemplate.init(),this.canvasImage.init(),this.canvasImageBottom.init(),this.render()}this.viewAnimation=void 0,this.viewAnimationTimer=void 0,this.store.emitter.emit("scale",this.store.data.scale),this.store.emitter.emit("translate",{x:this.store.data.x,y:this.store.data.y})}});D(this,"pastePen",(t,i)=>{const s=t.id;if(js(t),t.parentId=i,t.type===ut.Line?this.changeNodeConnectedLine(s,t,this.store.clipboard.pens):this.changeLineAnchors(s,t,this.store.clipboard.pens),!t.parentId){const a=this.getPenRect(t,this.store.clipboard.origin,this.store.clipboard.scale),o=this.getPenRect(this.store.clipboard.initRect,this.store.clipboard.origin,this.store.clipboard.scale),{origin:l,scale:n}=this.store.data;t.x=l.x+a.x*n,t.y=l.y+a.y*n,t.width=a.width*n,t.height=a.height*n,o.x=l.x+o.x*n,o.y=l.y+o.y*n,yt(o),this.store.clipboard.pos&&(t.x-=o.center.x-this.store.clipboard.pos.x,t.y-=o.center.y-this.store.clipboard.pos.y),this.keyOptions&&this.keyOptions.altKey&&(this.keyOptions.ctrlKey||this.keyOptions.metaKey)?(t.x=-this.store.data.x+this.width/2-t.width/2,t.y=-this.store.data.y+this.height/2-t.height/2):this.keyOptions&&this.keyOptions.shiftKey&&(this.keyOptions.ctrlKey||this.keyOptions.metaKey||this.keyOptions.F)||(t.x+=this.store.clipboard.offset*this.store.data.scale,t.y+=this.store.clipboard.offset*this.store.data.scale)}this.makePen(t);const r=[];if(Array.isArray(t.children))for(const a of t.children){const o=this.store.clipboard.pens.find(l=>l.id===a);o&&r.push(this.pastePen(o,t.id).id)}return t.children=r,Xt(t,!0),t});D(this,"ondblclick",t=>{var i,s,r;if(this.store.hover&&(!this.store.data.locked||this.store.hover.dbInput)&&!this.store.options.disableInput)if(this.store.hover.onShowInput)this.store.hover.onShowInput(this.store.hover,t);else if(this.store.hover&&this.store.hover.parentId)if(((i=this.store.active)==null?void 0:i.length)===1&&this.store.active[0].id===this.store.hover.id)this.showInput(this.store.hover);else{if(this.store.pens[this.store.hover.parentId].children.forEach(a=>{this.store.pens[a].calculative.active=!1,this.store.pens[a].calculative.hover=!1}),this.store.hover.parentId){let a=this.store.hover.id;const o=this.calibrateMouse({x:t.offsetX,y:t.offsetY});let l=1/0;(r=(s=this.store.pens[this.store.hover.parentId])==null?void 0:s.children)==null||r.forEach(n=>{const h=this.store.pens[n];if(Jt(o,h.calculative.worldRect)){const c=Math.sqrt((o.x-h.calculative.worldRect.center.x)**2+(o.y-h.calculative.worldRect.center.y)**2);c<l&&(l=c,a=n)}}),this.store.hover=this.store.pens[a],this.store.pens[a].calculative.hover=!0}this.active([this.store.hover])}else this.showInput(this.store.hover);this.store.emitter.emit("dblclick",{x:t.x,y:t.y,pen:this.store.hover})});D(this,"showInput",(t,i,s="transparent")=>{if(!window||!this.store.hover||this.store.hover.locked||this.store.hover.externElement||this.store.hover.disableInput||this.store.hover.disabled)return;if(this.inputDiv.dataset.penId===t.id){this.inputDiv.dataset.isInput="true",this.inputDiv.contentEditable="true",this.inputDiv.focus();const c=window.getSelection();c.selectAllChildren(this.inputDiv),c.collapseToEnd(),this.inputDiv.scrollTop=this.inputDiv.scrollHeight,this.inputDiv.scrollLeft=this.inputDiv.scrollWidth;return}!i&&!t.dbInput?this.setInputStyle(t):(this.inputDiv.style.width="100%",this.inputDiv.style.height="100%");const r=i||t.calculative.worldTextRect,l=`${(t.calculative.tempText===void 0?t.text+""||"":t.calculative.tempText).replace(/\x20/g," ").split(/[\s\n]/).join("</div><div>")}</div>`.replace("</div>","").replace(/\<div\>\<\/div\>/g,"<div><br></div>");this.inputDiv.innerHTML=l,this.inputParent.style.left=r.x+this.store.data.x-(t.calculative.textLeft||0)+"px",this.inputParent.style.top=r.y+this.store.data.y-(t.calculative.textTop||0)+"px";let n=r.width;if(this.inputParent.style.width=(n<0?12:n)+"px",this.inputParent.style.height=r.height+(t.textTop||0)+"px",this.inputParent.style.zIndex="9999",this.inputParent.style.background=s,t.rotate%360?this.inputParent.style.transform=`rotate(${t.rotate}deg)`:this.inputParent.style.transform=null,this.inputParent.style.display="flex",this.inputDiv.dataset.penId=t.id,this.inputDiv.contentEditable=t.disableInput==null?"true":t.disableInput.toString(),t.dropdownList&&this.dropdown.style.display!=="block"){this.dropdown.style.background=t.dropdownBackground||this.store.styles.popContentBg||"#fff",this.dropdown.style.color=t.dropdownColor||"#bdc7db",this.dropdown.style.width=this.inputParent.style.width,this.dropdown.style.fontSize=(t.fontSize||12)+"px";const c=this.inputDiv.getBoundingClientRect();let f=window.innerHeight-c.top-c.height;f=f>200?200:f,this.dropdown.style.maxHeight=f+"px",this.setDropdownList(),this.externalElements.style.zIndex="9999"}this.inputDiv.contentEditable=t.readonly?"false":"true",this.inputDiv.focus();const h=window.getSelection();h.selectAllChildren(this.inputDiv),h.collapseToEnd(),this.inputDiv.scrollTop=this.inputDiv.scrollHeight,this.inputDiv.scrollLeft=this.inputDiv.scrollWidth,t.calculative.text=void 0,this.initTemplateCanvas([t]),this.render()});D(this,"setInputStyle",t=>{t.text||(t.text="");let i;for(let h=0;h<document.styleSheets.length;h++)document.styleSheets[h].title==="le5le.com"&&(i=document.styleSheets[h]);let s="overflow: scroll;",r="",a=1;const{scale:o}=this.store.data;t.fontSize<12&&(a=12/t.fontSize),t.textAlign?s+=`text-align: ${t.textAlign};`:s+="text-align: center;",t.textAlign&&t.whiteSpace==="pre-line"&&(s+=`align-items: ${{left:"start",center:"center",right:"end"}[t.textAlign]};`),t.textBaseline?s+=`justify-content: ${{top:"start",middle:"center",bottom:"end"}[t.textBaseline]};`:s+="justify-content: center;",t.fontFamily&&(s+=`font-family: ${t.fontFamily};`),t.fontSize&&(t.fontSize*o<12?s+=`font-size:${t.calculative.fontSize}px;`:s+=`font-size:${t.fontSize*o}px;`),s+=`color:${Gt(t,this.store)};`,t.fontStyle&&(s+=`font-style: ${t.fontStyle};`),t.fontWeight&&(s+=`font-weight: ${t.fontWeight};`);let l=0;if(t.textLeft&&(l=(o>1,t.textLeft*o),s+=`margin-left:${l}px;`),t.textTop&&(s+=`margin-top:${o>1,t.textTop*a}px;`),t.lineHeight&&(s+=`line-height:${o>1?t.fontSize*t.lineHeight*o:t.calculative.fontSize*t.lineHeight}px;`),t.textHeight)s+=`height:${o>1?t.textHeight*a*o:t.textHeight*a}px;`;else{let h=t.calculative.worldRect.height/o;h<0&&(h=0);let c=(t.fontSize*o<12,h*o*a);c<t.fontSize*t.lineHeight*o&&(c=t.fontSize*t.lineHeight*o,s+=`top:-${c/2}px;`),s+=`height:${c}px;`}t.letterSpacing&&(s+=`letter-spacing:${t.calculative.letterSpacing}px;`);let n=null;if(t.textWidth)n=t.calculative.textWidth,t.whiteSpace!=="pre-line"&&(n<t.fontSize?s+=`width:${t.fontSize*1.2*a}px;`:s+=`width:${o>1,n*a}px;`);else if(t.whiteSpace===void 0||t.whiteSpace==="break-all"){let h=(t.calculative.worldTextRect.width||12)/o;h<0&&(h=0),s+=`width:${t.fontSize*o<12,h*o-l}px;`}t.whiteSpace&&(t.whiteSpace==="pre-line"?s+="white-space:pre;":(s+=`white-space:${t.whiteSpace};`,t.whiteSpace==="nowrap"&&(r+="display:contents;"))),t.whiteSpace!=="nowrap"&&(t.fontSize*1.2*t.text.length,(n||t.calculative.worldRect.width/o)*Math.floor(t.calculative.worldRect.height/o/(t.lineHeight*t.fontSize))),i.deleteRule(0),i.deleteRule(0),i.insertRule(`.meta2d-input
|
|
63
|
+
.input-div{
|
|
64
|
+
resize:none;border:none;outline:none;background:transparent;position:absolute;flex-grow:1;height:100%;width: 100%;position:absolute;left:0;top:0;display:flex;flex-direction: column;cursor: text;${s}}`),i.insertRule(`.input-div div{${r}}`)});D(this,"hideInput",()=>{if(this.externalElements.style.zIndex="5",this.inputParent.style.display==="flex"){this.inputParent.style.display="none";const t=this.store.pens[this.inputDiv.dataset.penId];if(!t)return;if(t.calculative.text=t.text,this.inputDiv.dataset.value=this.inputDiv.innerHTML.replace(/\<div\>/g,`
|
|
65
|
+
`).replace(/\<\/div\>/g,"").replace(/\<br\>/g,"").replace(/ /g," ").replace(/(<([^>]+)>)/gi,""),this.inputDiv.dataset.value=this.convertSpecialCharacter(this.inputDiv.dataset.value),t.onInput)t.onInput(t,this.inputDiv.dataset.value);else if(t.text!==this.inputDiv.dataset.value){const i=[K(t,!0)];t.text=this.inputDiv.dataset.value,t.calculative.text=t.text,this.inputDiv.dataset.penId=void 0,t.text&&t.textAutoAdjust&&!t.parentId&&qa(t),Yt(t),this.patchFlags=!0,this.pushHistory({type:rt.Update,pens:[K(t,!0)],initPens:i}),this.store.emitter.emit("change",t),this.store.emitter.emit("valueUpdate",t)}else t.text===this.inputDiv.dataset.value&&t.calculative.textLines&&t.calculative.textLines.length==0&&Yt(t);this.initTemplateCanvas([t])}this.inputDiv.dataset.penId=void 0,this.dropdown.style.display="none",this.inputDiv.dataset.isInput="false",this.inputDiv.contentEditable="false",this.render()});D(this,"setDropdownList",t=>{this.clearDropdownList();const i=this.store.pens[this.inputDiv.dataset.penId];if(!this.store.data.locked&&!["tablePlus"].includes(i.name))return;if(this.dropdown.style.display="block",!i||!i.dropdownList){this.dropdown.style.display="none";return}if(!i.dropdownList.length){const a=document.createElement("div");a.innerText="None",a.style.padding="5px 12px",a.style.color="#ddd",this.dropdown.appendChild(a);return}const s=this.inputDiv.innerHTML.replace(/\<div\>/g,`
|
|
66
|
+
`).replace(/\<\/div\>/g,"").replace(/\<br\>/g,"");let r=0;for(const a of i.dropdownList){const o=typeof a=="string"?a:a.text;t&&s?o.includes(s)&&this.dropdownAppendOption(o,r):this.dropdownAppendOption(o,r),++r}if(!this.dropdown.hasChildNodes()){const a=document.createElement("div");a.innerText="None",a.style.padding="5px 12px",a.style.color="#ddd",this.dropdown.appendChild(a)}});D(this,"selectDropdown",t=>{t.stopPropagation();const i=t.target,s=this.store.pens[this.inputDiv.dataset.penId];if(!i||!s||!s.dropdownList)return;const r=+i.dataset.i,a=s.dropdownList[r];if(!a)return;const o=[K(s,!0)];typeof a=="object"?(this.updateValue(s,{...a}),s.calculative.text=void 0,this.calcActiveRect()):s.text=a+"",this.inputDiv.innerText=s.text,this.hideInput(),this.pushHistory({type:rt.Update,pens:[K(s,!0)],initPens:o}),this.render(),this.store.emitter.emit("change",s),this.store.emitter.emit("valueUpdate",s)});D(this,"inFitBorder",t=>{let i;const s=this.store.data.width||this.store.options.width,r=this.store.data.height||this.store.options.height;let a={x:(t.x-this.store.data.origin.x)/this.store.data.scale,y:(t.y-this.store.data.origin.y)/this.store.data.scale};const o=this.canvasImage.activeFit;this.externalElements.style.cursor="default",a.y>r*o.y-10&&a.y<r*o.y+10&&(i="top",this.externalElements.style.cursor="row-resize"),a.y>r*(o.y+o.height)-10&&a.y<r*(o.y+o.height)+10&&(i="bottom",this.externalElements.style.cursor="row-resize"),a.x>s*o.x-10&&a.x<s*o.x&&(i="left",this.externalElements.style.cursor="col-resize"),a.x>s*(o.x+o.width)-10&&a.x<s*(o.x+o.width)+10&&(i="right",this.externalElements.style.cursor="col-resize"),this.canvasImage.currentFit=i});this.parent=t,this.parentElement=i,this.store=s,this.canvasTemplate=new yl(i,s,this),this.canvasTemplate.canvas.style.zIndex="1",this.canvasImageBottom=new tr(i,s,!0),this.canvasImageBottom.canvas.style.zIndex="2",i.appendChild(this.canvas),this.canvas.style.position="absolute",this.canvas.style.backgroundRepeat="no-repeat",this.canvas.style.backgroundSize="100% 100%",this.canvas.style.zIndex="3",this.canvasImage=new tr(i,s),this.canvasImage.canvas.style.zIndex="4",this.magnifierCanvas=new dl(this,i,s),this.magnifierCanvas.canvas.style.zIndex="5",this.externalElements.style.position="absolute",this.externalElements.style.left="0",this.externalElements.style.top="0",this.externalElements.style.outline="none",this.externalElements.style.background="transparent",this.externalElements.style.zIndex="5",i.style.position="relative",i.style["-webkit-tap-highlight-color"]="transparent",i.appendChild(this.externalElements),this.createInput(),this.tooltip=new Ke(i,s),this.tooltip.box.onmouseleave=r=>{this.patchFlags=!0,this.store.lastHover&&(this.store.lastHover.calculative.hover=!1);let a=this.store.data.pens.find(o=>o.calculative.hover===!0);qe(a,!1)},this.popconfirm=new pl(i,s),this.dialog=new fl(i,s),this.title=new Pi(i),this.store.options.scroll&&(this.scroll=new Zr(this)),this.store.dpiRatio=globalThis.devicePixelRatio||1,this.store.dpiRatio<1?this.store.dpiRatio=1:this.store.dpiRatio>1&&this.store.dpiRatio<1.5&&(this.store.dpiRatio=1.5),this.clientRect=this.externalElements.getBoundingClientRect(),this.listen(),window==null||window.addEventListener("resize",this.onResize),window==null||window.addEventListener("scroll",this.onScroll),window==null||window.addEventListener("message",this.onMessage)}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(),this.store.options.interval=50,this.store.options.parentTouch?(this.parentElement.ontouchstart=this.ontouchstart,this.parentElement.ontouchmove=this.ontouchmove,this.parentElement.ontouchend=this.ontouchend):(this.externalElements.ontouchstart=this.ontouchstart,this.externalElements.ontouchmove=this.ontouchmove,this.externalElements.ontouchend=this.ontouchend),this.externalElements.onmousedown=t=>{this.isMobile||this.onMouseDown({x:t.offsetX,y:t.offsetY,clientX:t.clientX,clientY:t.clientY,pageX:t.pageX,pageY:t.pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons})},this.externalElements.onmousemove=t=>{this.isMobile||t.target===this.externalElements&&this.onMouseMove({x:t.offsetX,y:t.offsetY,clientX:t.clientX,clientY:t.clientY,pageX:t.pageX,pageY:t.pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons})},this.externalElements.onmouseup=t=>{this.isMobile||this.onMouseUp({x:t.offsetX,y:t.offsetY,clientX:t.clientX,clientY:t.clientY,pageX:t.pageX,pageY:t.pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons,button:t.button})},this.externalElements.onmouseleave=t=>{this.store.data.pens.forEach(i=>{i.calculative.hover&&(i.calculative.hover=!1)}),this.store.hover&&(this.store.hover.calculative.hover=!1,this.store.hover=void 0),this.render(),t.toElement!==this.tooltip.box&&t.toElement!==this.tooltip.arrowUp&&t.toElement!==this.tooltip.arrowDown&&(this.tooltip.hide(),this.store.lastHover=void 0)},this.externalElements.ondblclick=t=>{this.isMobile||this.ondblclick(t)},this.externalElements.tabIndex=0,this.externalElements.onblur=()=>{this.mouseDown=void 0},this.externalElements.onwheel=this.onwheel,document.addEventListener("copy",this.onCopy),document.addEventListener("cut",this.onCut),document.addEventListener("paste",this.onPaste),this.store.options.keydown){case ve.Document:document.addEventListener("keydown",this.onkeydown),document.addEventListener("keyup",this.onkeyup);break;case ve.Canvas:this.externalElements.addEventListener("keydown",this.onkeydown),this.externalElements.addEventListener("keyup",this.onkeyup);break}}touchToWheelEvent(t,i){const s=t.changedTouches[0]||t.touches[0];return{deltaX:0,deltaY:i,deltaZ:0,deltaMode:0,clientX:s.clientX,clientY:s.clientY,pageX:s.pageX,pageY:s.pageY,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,wheelDelta:-i,wheelDeltaY:-i,preventDefault:()=>t.preventDefault(),stopPropagation:()=>t.stopPropagation()}}splitLine(t,i){const s=t.calculative.worldAnchors,r=s.findIndex(c=>c===i);if([-1,0,s.length-1].includes(r))return;const a=K(t,!0),o=K(t,!0),l=lt();o.id=l,o.calculative.canvas=this,o.calculative.active=!1,o.calculative.hover=!1;const n=K(s.slice(0,r+1)),h=K(s.slice(r)).map(c=>(c.penId=l,c));t.calculative.worldAnchors=n,o.calculative.worldAnchors=h,this.initLineRect(t),this.initLineRect(o),this.store.data.pens.push(o),this.store.pens[l]=o,this.pushHistory({type:rt.Add,pens:[K(o,!0)],step:2}),this.pushHistory({type:rt.Update,initPens:[a],pens:[K(t,!0)],step:2})}translateAnchor(t,i){this.movingAnchor.x+=t,this.movingAnchor.y+=i;const s=this.movingAnchor.penId;if(s){const r=this.store.pens[s],a=r.calculative.worldRect;this.movingAnchor.x<a.x?this.movingAnchor.x=a.x:this.movingAnchor.x>a.ex&&(this.movingAnchor.x=a.ex),this.movingAnchor.y<a.y?this.movingAnchor.y=a.y:this.movingAnchor.y>a.ey&&(this.movingAnchor.y=a.ey);const o=Xe(this.movingAnchor,a),l=r.anchors.findIndex(n=>n.id===this.movingAnchor.id);r.anchors[l]=o,this.patchFlags=!0}}async fileToPen(t,i){let s="";return this.store.options.uploadFn?s=await this.store.options.uploadFn(t):this.store.options.uploadUrl?s=await Xa(t,this.store.options.uploadUrl,this.store.options.uploadParams,this.store.options.uploadHeaders):s=await Ya(t),new Promise((r,a)=>{const o=new Image;o.onload=()=>{it.htmlElements[s]=o,r({width:o.width,height:o.height,name:i?"gif":"image",image:s})},o.onerror=l=>{a(l)},o.crossOrigin=this.store.options.crossOrigin||"anonymous",o.src=s})}async dropPens(t,i){var n,h,c,f;this.randomIdObj={},this.parent.store.options.textPresetStyle&&t.length===1&&!t[0].temPreset&&t[0].name==="text"&&Object.assign(t[0],this.parent.store.options.textPresetStyle);for(const u of t)!u.parentId&&this.randomCombineId(u,t);if(Object.keys(this.randomIdObj).length!==0){const u=Object.keys(this.randomIdObj).join("|"),d=new RegExp(`(${u})`,"g");for(const v of t){if(v.type?(v.anchors[0].connectTo=this.randomIdObj[v.anchors[0].connectTo],v.anchors[v.anchors.length-1].connectTo=this.randomIdObj[v.anchors[v.anchors.length-1].connectTo]):(n=v.connectedLines)==null||n.forEach(g=>{g.lineAnchor=this.randomIdObj[g.lineAnchor],g.lineId=this.randomIdObj[g.lineId]}),(h=v.animations)!=null&&h.length){const g=JSON.stringify(v.animations).replace(d,y=>this.randomIdObj[y]);v.animations=JSON.parse(g)}if((c=v.triggers)!=null&&c.length){const g=JSON.stringify(v.triggers).replace(d,y=>this.randomIdObj[y]);v.triggers=JSON.parse(g)}if((f=v.events)!=null&&f.length){const g=JSON.stringify(v.events).replace(d,y=>this.randomIdObj[y]);v.events=JSON.parse(g)}}}for(const u of t)u.id||(u.id=lt()),!u.calculative&&(u.calculative={canvas:this}),this.store.pens[u.id]=u;let s=0,r=0,a=0;for(const u of t)u.parentId||(u.width*=this.store.data.scale,u.height*=this.store.data.scale,u.x=i.x-u.width/2+a,u.y=i.y-u.height/2+r,u.tags&&u.tags.includes("meta3d")&&(u.x=this.store.data.origin.x,u.y=this.store.data.origin.y),u.dataset&&(s%2===0?a=u.width-40*this.store.data.scale:a=0,s++,s%2===0&&(r+=u.height+10*this.store.data.scale),delete u.dataset),u.temOffsetX&&(u.x+=u.temOffsetX*this.store.data.scale,delete u.temOffsetX),u.temOffsetY&&(u.y+=u.temOffsetY*this.store.data.scale,delete u.temOffsetY));const o=this.store.data.width||this.store.options.width,l=this.store.data.height||this.store.options.height;if(o&&l){let u={x:this.store.data.origin.x,y:this.store.data.origin.y,width:o*this.store.data.scale,height:l*this.store.data.scale},d=!0;for(const v of t)if(!v.parentId){let g=[{x:v.x,y:v.y},{x:v.x+v.width,y:v.y},{x:v.x,y:v.y+v.height},{x:v.x+v.width,y:v.y+v.height},{x:v.x+v.width/2,y:v.y+v.height/2}];if(v.x===u.x&&v.y===u.y&&v.width===u.width&&v.height===u.height||g.some(y=>Jt(y,u))){d=!1,this.store.options.strictScope&&(v.x<u.x&&(v.x=u.x),v.y<u.y&&(v.y=u.y),v.x+v.width>u.x+u.width&&(v.x=u.x+u.width-v.width),v.y+v.height>u.y+u.height&&(v.y=u.y+u.height-v.height));break}}if(d){console.info("画笔在大屏范围外");return}}await this.addPens(t,!0),this.active(t.filter(u=>!u.parentId)),this.render(),this.externalElements.focus()}randomCombineId(t,i,s){let r=null;t.type?t.anchors[0].connectTo||t.anchors[t.anchors.length-1].connectTo?r=[t.id,t.anchors[0].id,t.anchors[t.anchors.length-1].id]:r=[t.id]:i.length>1&&(r=[t.id]),js(t),i.length>1&&(r.length===1?this.randomIdObj[r[0]]=t.id:(this.randomIdObj[r[0]]=t.id,this.randomIdObj[r[1]]=t.anchors[0].id,this.randomIdObj[r[2]]=t.anchors[t.anchors.length-1].id)),t.parentId=s;const a=[];if(Array.isArray(t.children))for(const o of t.children){const l=i.find(n=>n.id===o);l&&a.push(this.randomCombineId(l,i,t.id).id)}return t.children=a,t}async addPens(t,i,s){if(this.beforeAddPens&&await this.beforeAddPens(t)!=!0)return[];const r=[];for(const a of t)this.beforeAddPen&&this.beforeAddPen(a)!=!0||(s&&!a.parentId&&(a.x=a.x*this.store.data.scale+this.store.data.origin.x,a.y=a.y*this.store.data.scale+this.store.data.origin.y,a.width=a.width*this.store.data.scale,a.height=a.height*this.store.data.scale),this.makePen(a),r.push(a));return this.render(),this.store.emitter.emit("add",r),i&&this.pushHistory({type:rt.Add,pens:K(r,!0)}),r}addPensSync(t,i,s){const r=[];for(const a of t)this.beforeAddPen&&this.beforeAddPen(a)!=!0||(s&&!a.parentId&&(a.x=a.x*this.store.data.scale+this.store.data.origin.x,a.y=a.y*this.store.data.scale+this.store.data.origin.y,a.width=a.width*this.store.data.scale,a.height=a.height*this.store.data.scale),this.makePen(a),r.push(a));return this.render(),this.store.emitter.emit("add",r),i&&this.pushHistory({type:rt.Add,pens:K(r,!0)}),r}getDistance(t,i){const s=i.clientX-t.clientX,r=i.clientY-t.clientY;return Math.sqrt(s*s+r*r)}getCenter(t,i){return{x:(t.clientX+i.clientX)/2,y:(t.clientY+i.clientY)/2}}getInitPencilLine(t){const{data:i,options:s}=this.store,r=i.scale,a=i.lineWidth||1;return{id:t.penId,name:"line",x:t.x,y:t.y,type:ut.Line,calculative:{canvas:this,pencil:!0,active:!0,worldAnchors:[t],lineWidth:a*r},fromArrow:i.fromArrow||s.fromArrow,toArrow:i.toArrow||s.toArrow,lineWidth:a}}createDrawingLine(t){var o;this.inactive();const{data:i,options:s}=this.store,r=i.scale,a=i.lineWidth||1;return t.penId=lt(),{id:t.penId,name:"line",lineName:this.drawingLineName,x:t.x,y:t.y,type:ut.Line,calculative:{canvas:this,active:!0,worldAnchors:[t],...s.linePresetStyle,lineWidth:s.linePresetStyle&&s.linePresetStyle.lineWidth?((o=s.linePresetStyle)==null?void 0:o.lineWidth)*r:a*r},fromArrow:i.fromArrow||s.fromArrow,toArrow:i.toArrow||s.toArrow,lineWidth:a,...s.linePresetStyle}}addRuleLine(t){const{x:i,y:s,scale:r,origin:a}=this.store.data,o=t.x+i,l=t.y+s;let n=t.x,h=t.y,c=0,f=0,u=0,d=0;if(o<=l&&o<20)n=-i,c=this.width,u=1,t.ctrlKey||(h=Math.round((h-a.y)/(r*10))*(r*10)+a.y);else if(l<o&&l<20)h=-s,f=this.height,d=1,t.ctrlKey||(n=Math.round((n-a.x)/(r*10))*(r*10)+a.x);else return;this.addPen({isRuleLine:!0,type:ut.Line,name:"line",lineName:"line",x:n,y:h,width:c,height:f,color:this.store.options.ruleLineColor,anchors:[{x:0,y:0},{x:u,y:d}]})}clearRuleLines(){this.delete(this.ruleLines)}get ruleLines(){return this.store.data.pens.filter(t=>t.isRuleLine)}alignPenToGrid(t){var s;if(this.store.options.autoAlignGrid&&this.store.data.grid&&!t.type){const r=this.store.data.gridSize||this.store.options.gridSize,{origin:a,scale:o}=this.store.data,{x:l,y:n}=t,h={x:l,y:n},c=this.getPenRect(t),f=parseInt((c.x/r).toFixed()),u=parseInt((c.y/r).toFixed()),d=f*r,v=u*r;h.x=a.x+d*o,h.y=a.y+v*o,Object.assign(t,h),(s=t.onMove)==null||s.call(t,t),this.updatePenRect(t),this.calcActiveRect(),this.getSizeCPs()}}movedActivePens(t){let i=this.getAllFollowersByPens(this.store.active,!1);const s=K(i,!0),r=this.store.data.gridSize||this.store.options.gridSize,{origin:a,scale:o}=this.store.data,l=this.store.options.autoAlignGrid&&(this.store.data.grid||this.store.options.grid);if(i.forEach(u=>{var p;const d=this.movingPens.findIndex(b=>b.id===u.id+Lt);if(d<0)return;const{x:v,y:g}=this.movingPens[d],y={x:v,y:g};if(l&&!this.movingPens[d].type){const b=this.getPenRect(this.movingPens[d]),m=parseInt((b.x/r).toFixed()),k=parseInt((b.y/r).toFixed()),A=m*r,S=k*r;y.x=a.x+A*o,y.y=a.y+S*o}Object.assign(u,y),(p=u.onMove)==null||p.call(u,u),this.updatePenRect(u),this.updateLines(u),this.store.emitter.emit("updateLines",u),this.patchFlagsLines.forEach(b=>{b.type&&this.initLineRect(b)}),this.patchFlagsLines.clear(),u.calculative.x=u.x,u.calculative.y=u.y,u.calculative.initRect&&(u.calculative.initRect.x=u.calculative.x,u.calculative.initRect.y=u.calculative.y,u.calculative.initRect.ex=u.calculative.x+u.calculative.width,u.calculative.initRect.ey=u.calculative.y+u.calculative.height),zr(u),u.parentId&&this.parent.updateRectbyChild(u.calculative.worldRect,u,this.store.pens[u.parentId])}),this.initImageCanvas(this.store.active),this.initTemplateCanvas(this.store.active),!this.dock)return;const{xDock:n,yDock:h}=this.dock;let c;n&&(c=this.store.pens[n.penId]),!c&&h&&(c=this.store.pens[h.penId]);const f=K(this.store.active,!0);if(t&&this.store.active.length===1&&(c==null?void 0:c.type)===1&&(n!=null&&n.anchorId||h!=null&&h.anchorId)){const u=xt(c),d=dt(c);if(n!=null&&n.anchorId){const v=this.store.pens[this.store.active[0].id+Lt].calculative.worldAnchors.find(g=>g.id===n.anchorId);v.x===u.x&&v.y===u.y?(s.push(K(c,!0)),Tt(this.store.active[0],v,c,u),f.push(K(c,!0))):v.x===d.x&&v.y===d.y&&(s.push(K(c,!0)),Tt(this.store.active[0],v,c,d),f.push(K(c,!0)))}else if(h!=null&&h.anchorId){const v=this.store.pens[this.store.active[0].id+Lt].calculative.worldAnchors.find(g=>g.id===h.anchorId);v.x===u.x&&v.y===u.y?(s.push(K(c,!0)),Tt(this.store.active[0],v,c,u),f.push(K(c,!0))):v.x===d.x&&v.y===d.y&&(s.push(K(c,!0)),Tt(this.store.active[0],v,c,d),f.push(K(c,!0)))}}l&&(this.calcActiveRect(),this.getSizeCPs()),this.pushHistory({type:rt.Update,pens:f,initPens:s}),this.store.emitter.emit("translatePens",f)}copyMovedPens(){this.copy(this.store.active.map((t,i)=>{const{x:s,y:r}=this.movingPens[i];return this.updateLines(t),{...t,x:s,y:r}})),this.pasteOffset=!1,this.paste()}initImageCanvas(t){t.some(i=>this.hasImage(i,!1))&&this.canvasImage.init(),t.some(i=>this.hasImage(i,!0))&&this.canvasImageBottom.init()}initTemplateCanvas(t){t.some(i=>i.canvasLayer===ht.CanvasTemplate)&&this.canvasTemplate.init()}hasImage(t,i){var s;return t.image&&t.name!=="gif"?i?t.canvasLayer===ht.CanvasImageBottom:t.canvasLayer===ht.CanvasImage:(s=t.children)==null?void 0:s.some(r=>{const a=this.store.pens[r];return a&&this.hasImage(a,i)})}inactive(t){if(!this.store.active.length)return;this.initTemplateCanvas(this.store.active),this.store.active.forEach(s=>{s.calculative.active=void 0,s.calculative.activeAnchor=void 0,s.calculative.hover=!1,Ae(s,!1)});const i=[...this.store.active];this.store.active=[],this.activeRect=void 0,this.sizeCPs=void 0,this.store.activeAnchor=void 0,this.patchFlags=!0,!t&&this.store.emitter.emit("inactive",i)}active(t,i=!0){if(this.store.active&&this.store.active.length){i&&this.store.emitter.emit("inactive",this.store.active);for(const s of this.store.active)s.calculative.active=void 0,s.calculative.hover=!1,Ae(s,!1)}this.store.active=[],t.forEach(s=>{s.calculative.active=!0,Ae(s)}),this.store.active.push(...t),this.activeRect=void 0,this.calcActiveRect(),this.initTemplateCanvas(t),this.patchFlags=!0,i&&this.store.emitter.emit("active",this.store.active)}getSizeCPs(){this.sizeCPs=re(this.activeRect);const t=[{x:.5,y:0},{x:1,y:.5},{x:.5,y:1},{x:0,y:.5}],{x:i,y:s,width:r,height:a,rotate:o,center:l}=this.activeRect;t.forEach(n=>{const h={x:n.x*r+i,y:n.y*a+s};vt(h,o,l),this.sizeCPs.push(h)})}getSpecialAngle(t,i){let s=0;t.x-i.x!==0?(s=Math.atan((i.y-t.y)/(t.x-i.x))*180/Math.PI,t.x<i.x&&(s>0?s-=180:s+=180)):i.y>t.y?s=90:i.y<t.y&&(s=-90),s=Math.round(s/15)*15;let r=Math.sqrt((i.x-t.x)*(i.x-t.x)+(i.y-t.y)*(i.y-t.y));t.x=i.x+Math.cos(s/180*Math.PI)*r,t.y=i.y-Math.sin(s/180*Math.PI)*r}clearHover(){this.hoverType=st.None,this.store.hover=null,this.store.hoverAnchor=null}inAnchor(t,i,s){var r;if(this.store.hoverAnchor=void 0,this.movingAnchor=void 0,!s||s.locked>ct.DisableEdit||!(i.type&&i.calculative.active)&&this.store.options.disableAnchor||i.disableAnchor)return st.None;if((this.mouseDown||this.drawingLine)&&i.name==="line"&&s.connectTo){const a=this.findOne(s.connectTo);if(a!=null&&a.calculative&&!(a!=null&&a.calculative.active)){i=a;const o=a.calculative.worldAnchors.find(l=>l.id===s.anchorId);o&&(s=o)}}if(s.twoWay===At.Disable&&i.name!=="line")return st.None;if(i.name==="line"&&s.connectTo){let a=(r=this.findOne(s.connectTo))==null?void 0:r.anchors.find(o=>o.id===s.anchorId);if(a&&a.twoWay)return st.None}if(this.drawingLine){if(s.twoWay===At.Out)return st.None}else if(!(this.mouseDown&&this.hoverType===st.LineAnchor)){if(s.twoWay===At.In)return st.None}if(Ce(t,s,this.pointSize,s.penId?this.store.pens[s.penId]:void 0))return s!==this.store.hoverAnchor&&(this.patchFlags=!0),this.store.hoverAnchor=s,this.store.hover=i,i.type?s.connectTo&&!i.calculative.active&&(this.store.hover=this.store.pens[s.connectTo],this.store.hover)?(this.store.hoverAnchor=this.store.hover.calculative.worldAnchors.find(a=>a.id===s.anchorId),this.store.hoverAnchor?(this.externalElements.style.cursor="crosshair",st.NodeAnchor):st.None):(this.hotkeyType===ft.AddAnchor?this.externalElements.style.cursor="vertical-text":this.externalElements.style.cursor="pointer",st.LineAnchor):(this.hotkeyType===ft.AddAnchor?this.externalElements.style.cursor="vertical-text":this.externalElements.style.cursor="crosshair",st.NodeAnchor);if(!this.mouseDown&&i.type){if(i.calculative.active&&s.prev&&Ce(t,s.prev,this.pointSize))return this.store.hoverAnchor=s,this.store.hover=i,this.externalElements.style.cursor="pointer",st.LineAnchorPrev;if(i.calculative.active&&s.next&&Ce(t,s.next,this.pointSize))return this.store.hoverAnchor=s,this.store.hover=i,this.externalElements.style.cursor="pointer",st.LineAnchorNext}return st.None}resize(t,i){t=t||this.parentElement.clientWidth,i=i||this.parentElement.clientHeight,this.width=t,this.height=i,this.canvasRect={x:0,y:0,width:t,height:i},bt(this.canvasRect),this.canvas.style.width=t+"px",this.canvas.style.height=i+"px",this.externalElements.style.width=t+"px",this.externalElements.style.height=i+"px",this.canvasTemplate.resize(t,i),this.canvasImage.resize(t,i),this.canvasImageBottom.resize(t,i),this.magnifierCanvas.resize(t,i),t=t*this.store.dpiRatio|0,i=i*this.store.dpiRatio|0,this.canvas.width=t,this.canvas.height=i,this.offscreen.width=t,this.offscreen.height=i,this.clientRect=this.externalElements.getBoundingClientRect(),this.canvas.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.offscreen.getContext("2d").scale(this.store.dpiRatio,this.store.dpiRatio),this.offscreen.getContext("2d").textBaseline="middle";for(const s of this.store.data.pens)s.isRuleLine&&(s.width?s.height||(s.width=this.width):s.height=this.height,this.updatePenRect(s)),Xt(s);this.render()}clearCanvas(){this.activeRect=void 0,this.sizeCPs=void 0,this.__loadMap=new Map,this.canvas.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.offscreen.getContext("2d").clearRect(0,0,this.offscreen.width,this.offscreen.height),this.store.data.template||this.canvasTemplate.clear(),this.canvasImage.clear(),this.canvasImageBottom.clear()}async addPen(t,i,s,r){if(!(this.beforeAddPens&&await this.beforeAddPens([t])!=!0)&&!(this.beforeAddPen&&this.beforeAddPen(t)!=!0))return r&&(t.x=t.x*this.store.data.scale+this.store.data.origin.x,t.y=t.y*this.store.data.scale+this.store.data.origin.y,t.width=t.width*this.store.data.scale,t.height=t.height*this.store.data.scale),this.makePen(t),this.active([t]),this.render(),s&&this.store.emitter.emit("add",[t]),i&&this.pushHistory({type:rt.Add,pens:[t]}),t}addPenSync(t,i,s,r){if(!(this.beforeAddPen&&this.beforeAddPen(t)!=!0))return r&&(t.x=t.x*this.store.data.scale+this.store.data.origin.x,t.y=t.y*this.store.data.scale+this.store.data.origin.y,t.width=t.width*this.store.data.scale,t.height=t.height*this.store.data.scale),this.makePen(t),this.active([t]),this.render(),s&&this.store.emitter.emit("add",[t]),i&&this.pushHistory({type:rt.Add,pens:[t]}),t}pushHistory(t){var r;if(this.store.data.locked)return;const{origin:i,scale:s}=this.store.data;t.origin=K(i),t.scale=s,t.type!==rt.Update&&t.pens&&t.pens.forEach(a=>{a.calculative&&(a.calculative.layer=this.store.data.pens.findIndex(o=>o.id===a.id))}),this.store.historyIndex<this.store.histories.length-1&&this.store.histories.splice(this.store.historyIndex+1,this.store.histories.length-this.store.historyIndex-1),(r=t.pens)==null||r.forEach(a=>{let o;if(t.initPens)for(const l of t.initPens)l.id===a.id&&(o=l);if(o)for(const l in a)o[l]==null&&(o[l]=void 0)}),this.store.histories.push(t),this.store.historyIndex=this.store.histories.length-1,this.store.emitter.emit("update",{previous:t.initPens,current:t.pens})}undo(){if(this.store.data.locked||this.store.historyIndex==null||this.store.historyIndex<0)return;const t=this.store.histories[this.store.historyIndex--];this.doEditAction(t,!0);let i=t.step;for(;i>1;){const s=this.store.histories[this.store.historyIndex--];this.doEditAction(s,!0),i--}(t.type==rt.Add||t.type==rt.Delete||t.type==rt.Update)&&this.activeHistory()}redo(){if(this.store.data.locked||this.store.historyIndex==null||this.store.historyIndex>this.store.histories.length-2)return;const t=this.store.histories[++this.store.historyIndex];this.doEditAction(t,!1);let i=t.step;for(;i>1;){const s=this.store.histories[++this.store.historyIndex];this.doEditAction(s,!1),i--}(t.type==rt.Add||t.type==rt.Delete||t.type==rt.Update)&&this.activeHistory()}activeHistory(){let t=this.store.histories[this.store.historyIndex+1];const i=[];if(t&&t.type===rt.Update){t.pens.forEach(r=>{i.push(this.store.pens[r.id])}),this.active(i);return}let s=this.store.histories[this.store.historyIndex];s&&(s.type===rt.Add||s.type===rt.Delete)&&(s.pens.forEach(r=>{i.push(this.store.pens[r.id])}),this.active(i))}doEditAction(t,i){switch(this.inactive(),this.store.hoverAnchor=void 0,this.store.hover=void 0,t.type){case rt.Add:t.pens.forEach(a=>{var n;const o=K(a,!0),l=this.store.data.pens.findIndex(h=>h.id===o.id);if(l>-1){(n=o.onDestroy)==null||n.call(o,this.store.pens[o.id]);const h=o.parentId?this.store.pens[o.parentId]:void 0;h!=null&&h.children&&(h.children=h.children.filter(c=>c!==o.id)),this.store.data.pens.splice(l,1),this.store.pens[o.id]=void 0,o.calculative||(o.calculative={}),o.calculative.canvas=this,this.store.animates.delete(o),this.store.animateMap.delete(o)}}),t.type=rt.Delete;break;case rt.Update:const s=i?t.initPens:t.pens,r=i?t.pens:t.initPens;s.forEach(a=>{const o=K(a,!0),l=this.store.data.pens.findIndex(n=>n.id===o.id);if(l>-1){if(o.calculative=this.store.data.pens[l].calculative,this.store.data.pens[l].type&&this.store.data.pens[l].lastConnected){for(let h in this.store.data.pens[l].lastConnected)if(this.store.pens[h]){let c=K(this.store.data.pens[l].lastConnected[h]);this.store.pens[h].connectedLines=c,o.anchors.forEach(f=>{c.forEach(u=>{f.id===u.lineAnchor&&(f.connectTo=h)})})}}this.store.data.pens[l]=o,this.store.pens[o.id]=o;for(const h in o)(typeof o[h]!="object"||h==="lineDash")&&(o.calculative[h]=o[h]);o.calculative.image=void 0;const n=this.getPenRect(o,t.origin,t.scale);if(this.setPenRect(o,n,!1),this.updateLines(o,!0),o.calculative.canvas.parent.isCombine(o)){let h=r.find(c=>c.id===o.id);mr.forEach(c=>{o[c]!==h[c]&&this.parent.setValue({id:o.id,[c]:o[c]},{render:!0,doEvent:!1})})}}});break;case rt.Delete:t.pens.reverse().forEach(a=>{var l,n;const o=K(a,!0);if(o.calculative||(o.calculative={}),this.store.data.pens.splice(((l=o.calculative)==null?void 0:l.layer)!==-1?(n=o.calculative)==null?void 0:n.layer:this.store.data.pens.length,0,o),o.path&&!this.store.data.paths[o.pathId]&&(this.store.data.paths[o.pathId]=o.path),this.store.pens[o.id]=o,o.parentId&&(!this.store.pens[o.parentId].children&&(this.store.pens[o.parentId].children=[]),this.store.pens[o.parentId].children.includes(o.id)||this.store.pens[o.parentId].children.push(o.id)),o.type&&o.lastConnected)for(let h in o.lastConnected)this.store.pens[h]&&(this.store.pens[h].connectedLines=o.lastConnected[h]);o.calculative.canvas=this}),t.pens.reverse().forEach(a=>{const o=this.store.pens[a.id],l=this.getPenRect(o,t.origin,t.scale);this.setPenRect(o,l,!1),o.calculative.image=void 0,o.calculative.backgroundImage=void 0,o.calculative.strokeImage=void 0,this.loadImage(o)}),t.type=rt.Add;break;case rt.Replace:{const a=i?t.initPens:t.pens;(i?t.pens:t.initPens).forEach(l=>{var c;const n=K(l,!0);if(this.store.data.pens.findIndex(f=>f.id===n.id)>-1){(c=n.onDestroy)==null||c.call(n,this.store.data.pens.find(u=>u.id===n.id));const f=this.store.data.pens.findIndex(u=>u.id===n.id);this.store.data.pens.splice(f,1),this.store.pens[n.id]=void 0,n.calculative||(n.calculative={}),n.calculative.canvas=this,this.store.animates.delete(n),this.store.animateMap.delete(n)}}),a.reverse().forEach(l=>{var h,c;const n=K(l,!0);if(n.calculative||(n.calculative={}),this.store.data.pens.splice(((h=n.calculative)==null?void 0:h.layer)!==-1?(c=n.calculative)==null?void 0:c.layer:this.store.data.pens.length,0,n),this.store.pens[n.id]=n,n.type&&n.lastConnected)for(let f in n.lastConnected)this.store.pens[f]&&(this.store.pens[f].connectedLines=n.lastConnected[f]);n.calculative.canvas=this}),a.reverse().forEach(l=>{const n=this.store.data.pens.find(c=>c.id===l.id),h=this.getPenRect(n,t.origin,t.scale);this.setPenRect(n,h,!1),n.calculative.image=void 0,n.calculative.backgroundImage=void 0,n.calculative.strokeImage=void 0,this.loadImage(n)}),t.type=rt.Replace;break}}if(t.type===rt.Update){let s=[...t.pens,...t.initPens];this.initImageCanvas(s),this.initTemplateCanvas(s)}else this.initImageCanvas(t.pens),this.initTemplateCanvas(t.pens);this.parent.onSizeUpdate(),this.render(),this.store.emitter.emit(i?"undo":"redo",t)}makePen(t){var r;if(t.id||(t.id=lt()),Math.abs(this.store.lastScale-this.store.data.scale)<1e-4&&this.store.sameTemplate&&this.store.templatePens[t.id]&&t.canvasLayer===ht.CanvasTemplate){t=this.store.templatePens[t.id],this.store.data.pens.push(t),this.updatePenRect(t);return}if(t.copyIndex?(this.store.data.pens.splice(t.copyIndex+1,0,t),delete t.copyIndex):this.store.data.pens.push(t),this.store.pens[t.id]=t,t.path){!t.pathId&&(t.pathId=lt());const a=this.store.data.paths;!a[t.pathId]&&(a[t.pathId]=t.path),t.path=void 0}t.lineWidth==null&&(t.lineWidth=1);const{fontSize:i,lineHeight:s}=this.store.options;t.fontSize?t.fontSize<0&&(t.fontSize=0):t.fontSize=i>=0?i:12,t.lineHeight||(t.lineHeight=s),t.image&&t.name!=="gif"&&t.canvasLayer===void 0&&(t.isBottom?t.canvasLayer=ht.CanvasImageBottom:t.canvasLayer=ht.CanvasImage,delete t.isBottom),t.template&&(t.canvasLayer=ht.CanvasTemplate),t.calculative={canvas:this,singleton:(r=t.calculative)==null?void 0:r.singleton},(t.video||t.audio)&&(t.calculative.onended=a=>{this.nextAnimate(a)});for(const a in t)(typeof t[a]!="object"||a==="lineDash")&&(t.calculative[a]=t[a]);if(t.calculative.image=void 0,t.calculative.backgroundImage=void 0,t.calculative.strokeImage=void 0,!t.anchors&&it.anchors[t.name]&&(t.anchors||(t.anchors=[]),it.anchors[t.name](t)),!t.anchors){const a=K(this.store.options.defaultAnchors);a.forEach((o,l)=>{o.id=`${l}`,o.penId=t.id}),t.anchors=a}this.updatePenRect(t),!t.anchors&&t.calculative.worldAnchors&&(t.anchors=t.calculative.worldAnchors.map(a=>Xe(a,t.calculative.worldRect))),!t.rotate&&(t.rotate=0),t.lineAnimateImages??(t.lineAnimateImages=[]),t.lineAnimateImages&&t.lineAnimateImages.forEach(a=>{this.__loadImage(a)}),this.loadImage(t),this.parent.penNetwork(t)}drawline(t){var i;this.drawingLine&&((i=this[this.drawingLineName])==null||i.call(this,this.store,this.drawingLine,t),this.store.path2dMap.set(this.drawingLine,it.path2dDraws.line(this.drawingLine)),this.patchFlags=!0)}initLineRect(t){var a;if(!t)return;if(!((a=t.calculative.worldAnchors)!=null&&a.length)){this._del([t]);return}if(!isFinite(t.x)||!isFinite(t.x)||t.x==null||t.y==null)return;const i=Ji(t);t.parentId||Object.assign(t,i);const{fontSize:s,lineHeight:r}=this.store.options;t.fontSize||(t.fontSize=s>=0?s:12,t.calculative.fontSize=t.fontSize*this.store.data.scale),t.lineHeight||(t.lineHeight=r,t.calculative.lineHeight=t.lineHeight),yt(i),t.calculative.worldRect=i,us(t,i),Yt(t),Xt(t),t.calculative&&(t.calculative.gradientAnimatePath=void 0),this.store.path2dMap.set(t,it.path2dDraws[t.name](t)),t.calculative.worldAnchors&&(t.anchors=t.calculative.worldAnchors.map(o=>Xe(o,t.calculative.worldRect)))}drawingPencil(){ta(this.store),this.pencil=!0,this.externalElements.style.cursor="crosshair"}stopPencil(){this.pencil=!1,this.pencilLine=void 0,this.externalElements.style.cursor="default"}async finishDrawline(t){if(!this.drawingLine)return;const i=xt(this.drawingLine);let s=dt(this.drawingLine);if(s.isTemp&&(this.drawingLine.calculative.worldAnchors.pop(),s=dt(this.drawingLine)),!t&&(!s.connectTo&&this.drawingLine.calculative.worldAnchors.pop(),xt(this.drawingLine)===this.drawingLine.calculative.activeAnchor)){this.drawingLine=void 0,this.render();return}if(!i.connectTo||!s.connectTo){if(this.store.options.disableEmptyLine){i.connectTo&&(this.store.pens[i.connectTo].connectedLines=this.store.pens[i.connectTo].connectedLines.filter(o=>o.lineId!==this.drawingLine.id)),this.drawingLine=void 0,this.render();return}}else if(this.store.options.disableRepeatLine&&this.store.data.pens.find(l=>{if(l.type){const n=xt(l),h=dt(l);return Cs(n,i)&&Cs(h,s)}})){this.drawingLine=void 0,this.render();return}if(this.drawingLine.lineName==="polyline"&&!s.connectTo&&this.drawingLine.calculative.worldAnchors.length>2){let o=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2];Math.abs(o.x-s.x)/this.store.data.scale<5&&Math.abs(o.y-s.y)/this.store.data.scale<5&&this.drawingLine.calculative.worldAnchors.pop()}const r=Ji(this.drawingLine);Object.assign(this.drawingLine,r),this.drawingLine.calculative.worldRect=r,this.drawingLine.calculative.activeAnchor=dt(this.drawingLine),this.store.activeAnchor=this.drawingLine.calculative.activeAnchor,(!this.beforeAddPens||await this.beforeAddPens([this.drawingLine]))&&(!this.beforeAddPen||this.beforeAddPen(this.drawingLine))&&(this.initLineRect(this.drawingLine),this.store.data.pens.push(this.drawingLine),this.store.pens[this.drawingLine.id]=this.drawingLine,this.store.emitter.emit("add",[this.drawingLine]),this.active([this.drawingLine]),this.pushHistory({type:rt.Add,pens:K([this.drawingLine],!0)})),this.store.path2dMap.set(this.drawingLine,it.path2dDraws[this.drawingLine.name](this.drawingLine)),this.drawingLine=void 0,this.drawingLineName=void 0,this.render()}async finishPencil(){if(this.pencilLine){const t=ts(this.pencilLine.calculative.worldAnchors,10,0,this.pencilLine.calculative.worldAnchors.length-1);let i=xt(this.pencilLine);t.unshift({id:i.id,penId:i.penId,x:i.x,y:i.y}),i=dt(this.pencilLine),t.push({id:i.id,penId:i.penId,x:i.x,y:i.y}),this.pencilLine.calculative.worldAnchors=Qn(t),this.pencilLine.calculative.worldAnchors.length>1&&(this.pencilLine.calculative.pencil=!1,this.store.path2dMap.set(this.pencilLine,it.path2dDraws[this.pencilLine.name](this.pencilLine)),(!this.beforeAddPens||await this.beforeAddPens([this.pencilLine]))&&(!this.beforeAddPen||this.beforeAddPen(this.pencilLine))&&(this.initLineRect(this.pencilLine),this.store.data.pens.push(this.pencilLine),this.store.pens[this.pencilLine.id]=this.pencilLine,this.store.emitter.emit("add",[this.pencilLine]),this.active([this.pencilLine]),this.pushHistory({type:rt.Add,pens:K([this.pencilLine],!0)}))),this.pencilLine=void 0,this.render()}}firefoxLoadSvg(t){const i=new Image,s=new XMLHttpRequest;s.open("GET",t.image,!0),s.onload=()=>{const o=new DOMParser().parseFromString(s.responseText,"text/xml").getElementsByTagName("svg")[0],{width:l,height:n}=t.calculative.worldRect;o.setAttribute("width",`${l}px`),o.setAttribute("height",`${n}px`);const c="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(new XMLSerializer().serializeToString(o))));i.src=c,i.crossOrigin=t.crossOrigin||this.store.options.crossOrigin||"anonymous",i.onload=()=>{t.calculative.img=i,t.calculative.imgNaturalWidth=i.naturalWidth||t.iconWidth,t.calculative.imgNaturalHeight=i.naturalHeight||t.iconHeight,it.htmlElements[t.image]=i,this.imageLoaded(),t.canvasLayer===ht.CanvasTemplate&&this.templateImageLoaded()}},s.send()}loadImage(t){if(t.image!==t.calculative.image||!t.calculative.img){if(t.calculative.img=void 0,t.image)if(it.htmlElements[t.image]){const i=it.htmlElements[t.image];t.calculative.img=i,t.calculative.imgNaturalWidth=i.naturalWidth||t.iconWidth,t.calculative.imgNaturalHeight=i.naturalHeight||t.iconHeight,this.imageLoaded(),t.canvasLayer===ht.CanvasTemplate&&this.templateImageLoaded()}else if(navigator.userAgent.includes("Firefox")&&t.image.endsWith(".svg"))this.firefoxLoadSvg(t);else{const i=new Image;i.crossOrigin=t.crossOrigin==="undefined"?void 0:t.crossOrigin||this.store.options.crossOrigin||"anonymous",i.src=t.image,this.store.options.cdn&&!(t.image.startsWith("http")||t.image.startsWith("//")||t.image.startsWith("data:image"))&&(i.src=this.store.options.cdn+t.image),i.onload=()=>{t.calculative.img=i,t.calculative.imgNaturalWidth=i.naturalWidth||t.iconWidth,t.calculative.imgNaturalHeight=i.naturalHeight||t.iconHeight,it.htmlElements[t.image]=i,this.imageLoaded(),t.canvasLayer===ht.CanvasTemplate&&this.templateImageLoaded()}}t.calculative.image=t.image}if(t.backgroundImage!==t.calculative.backgroundImage){if(t.calculative.backgroundImg=void 0,t.backgroundImage)if(it.htmlElements[t.backgroundImage]){const i=it.htmlElements[t.backgroundImage];t.calculative.backgroundImg=i}else{const i=new Image;i.crossOrigin=t.crossOrigin||this.store.options.crossOrigin||"anonymous",i.src=t.backgroundImage,this.store.options.cdn&&!(t.backgroundImage.startsWith("http")||t.backgroundImage.startsWith("//")||t.backgroundImage.startsWith("data:image"))&&(i.src=this.store.options.cdn+t.backgroundImage),i.onload=()=>{t.calculative.backgroundImg=i,it.htmlElements[t.backgroundImage]=i,this.imageLoaded(),t.canvasLayer===ht.CanvasTemplate&&this.templateImageLoaded()}}t.calculative.backgroundImage=t.backgroundImage}if(t.strokeImage!==t.calculative.strokeImage){if(t.calculative.strokeImg=void 0,t.strokeImage)if(it.htmlElements[t.strokeImage]){const i=it.htmlElements[t.strokeImage];t.calculative.strokeImg=i}else{const i=new Image;i.crossOrigin=t.crossOrigin||this.store.options.crossOrigin||"anonymous",i.src=t.strokeImage,this.store.options.cdn&&!(t.strokeImage.startsWith("http")||t.strokeImage.startsWith("//")||t.strokeImage.startsWith("data:image"))&&(i.src=this.store.options.cdn+t.strokeImage),i.onload=()=>{t.calculative.strokeImg=i,it.htmlElements[t.strokeImage]=i,this.imageLoaded(),t.canvasLayer===ht.CanvasTemplate&&t.name!=="gif"&&this.templateImageLoaded()}}t.calculative.strokeImage=t.strokeImage}}__loadImage(t,i=5){if(this.__loadMap.has(t))return this.__loadMap.get(t);const s=new Promise((r,a)=>{if(it.htmlElements[t])r(it.htmlElements[t]);else{const o=new Image;o.crossOrigin=this.store.options.crossOrigin||"anonymous",this.store.options.cdn&&!(t.startsWith("http")||t.startsWith("//")||t.startsWith("data:image"))?o.src=this.store.options.cdn+t:o.src=t,o.onload=()=>{it.htmlElements[t]=o,this.__loadMap.delete(t),r(o)},o.onerror=()=>{i>0?(console.warn(`Image ${t} load failed, retrying... (${i})`),setTimeout(()=>{this.__loadMap.delete(t),this.__loadImage(t,i-1).then(r).catch(a)},1e3)):(this.__loadMap.set(t,0),a(new Error(`Failed to load image: ${t}`)))}}});return this.__loadMap.set(t,s),s}imageLoaded(){this.imageTimer&&clearTimeout(this.imageTimer),this.imageTimer=setTimeout(()=>{this.canvasImage.init(),this.canvasImageBottom.init(),this.render()},100)}templateImageLoaded(){this.templateImageTimer&&clearTimeout(this.templateImageTimer),this.templateImageTimer=setTimeout(()=>{this.canvasTemplate.init(),this.render()},100)}setCalculativeByScale(t){const i=this.store.data.scale;t.calculative.lineWidth=t.lineWidth*i,t.calculative.fontSize=t.fontSize*i,t.calculative.letterSpacing=(t.letterSpacing||0)*i,t.fontSize<1&&t.fontSize>0&&(t.calculative.fontSize=t.fontSize*t.calculative.worldRect.height),qt(t.iconSize)&&(t.calculative.iconSize=t.iconSize*i),qt(t.iconWidth)&&(t.calculative.iconWidth=t.iconWidth*i),qt(t.iconHeight)&&(t.calculative.iconHeight=t.iconHeight*i),qt(t.iconLeft)&&(t.calculative.iconLeft=t.iconLeft<1&&t.iconLeft>-1?t.iconLeft:t.iconLeft*i),qt(t.iconTop)&&(t.calculative.iconTop=t.iconTop<1&&t.iconTop>-1?t.iconTop:t.iconTop*i),qt(t.textWidth)&&(t.calculative.textWidth=t.textWidth<1&&t.textWidth>-1?t.textWidth:t.textWidth*i),qt(t.textHeight)&&(t.calculative.textHeight=t.textHeight<1&&t.textHeight>-1?t.textHeight:t.textHeight*i),qt(t.textLeft)&&(t.calculative.textLeft=t.textLeft<1&&t.textLeft>-1?t.textLeft*t.calculative.worldRect.width:t.textLeft*i),qt(t.textTop)&&(t.calculative.textTop=t.textTop<1&&t.textTop>-1?t.textTop*t.calculative.worldRect.height:t.textTop*i),qt(t.borderWidth)&&t.type===ut.Line&&t.borderWidth&&(t.calculative.borderWidth=t.borderWidth*i)}updatePenRect(t,{worldRectIsReady:i,playingAnimate:s}={}){i?fi(t):Fr(t),s||this.setCalculativeByScale(t),Le(t),Ms(this.store.pens,t),Yt(t),Xt(t),it.path2dDraws[t.name]&&this.store.path2dMap.set(t,it.path2dDraws[t.name](t)),t.calculative.patchFlags=!0,this.patchFlags=!0,t.children&&t.children.forEach(r=>{const a=this.store.pens[r];a&&this.updatePenRect(a,{worldRectIsReady:!1})}),t.type&&this.initLineRect(t),(t.bkType&&t.gradientColors||t.strokeType&&t.lineGradientColors)&&(t.calculative.gradientTimer&&clearTimeout(t.calculative.gradientTimer),t.calculative.gradientTimer=setTimeout(()=>{t.calculative.lineGradient&&(t.calculative.lineGradient=null),t.calculative.gradient&&(t.calculative.gradient=null),t.calculative.radialGradient&&(t.calculative.radialGradient=null),this.patchFlags=!0,t.calculative.gradientTimer=void 0},50))}initGlobalStyle(){if(this.store.options.themeOnlyCanvas||this.store.data.themeOnlyCanvas)return;const t={},i={},s={};Fa.forEach(n=>{var h;if(this.store.options[n]!=null&&this.store.options[n]!==""&&(t[n]=this.store.options[n]),this.store.data[n]!=null&&this.store.data[n]!==""&&(i[n]=this.store.data[n]),this.store.data.theme){const c=(h=this.store.theme[this.store.data.theme])==null?void 0:h[n];c!=null&&c!==""&&(s[n]=c)}}),this.store.styles={};let r="";const a=this.store.data.width||this.store.options.width,o=this.store.data.height||this.store.options.height;!a&&!o&&(r="default");const l=Ve.getThemeObj(this.store.data.theme||r);Object.assign(this.store.styles,t,i,s,l)}translate(t=0,i=0){if(this.store.data.x+=t*this.store.data.scale,this.store.data.y+=i*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.store.options.padding){let s=Zt(this.store.options.padding);const r=this.store.data.width||this.store.options.width,a=this.store.data.height||this.store.options.height;this.width<(r+s[1]+s[3])*this.store.data.scale&&(this.store.data.x+this.store.data.origin.x>s[3]*this.store.data.scale&&(this.store.data.x=s[3]*this.store.data.scale-this.store.data.origin.x),this.store.data.x+this.store.data.origin.x+r*this.store.data.scale<this.width-s[1]*this.store.data.scale&&(this.store.data.x=this.width-s[1]*this.store.data.scale-(this.store.data.origin.x+r*this.store.data.scale))),this.height<(a+s[0]+s[2])*this.store.data.scale&&(this.store.data.y+this.store.data.origin.y>s[0]*this.store.data.scale&&(this.store.data.y=s[0]*this.store.data.scale-this.store.data.origin.y),this.store.data.y+this.store.data.origin.y+a*this.store.data.scale<this.height-s[2]*this.store.data.scale&&(this.store.data.y=this.height-s[2]*this.store.data.scale-(this.store.data.origin.y+a*this.store.data.scale)))}this.store.data.asyncTranslate?(clearTimeout(this.transTimeout),this.transTimeout=setTimeout(()=>{this.canvasTemplate.init(),this.canvasImage.init(),this.canvasImageBottom.init(),this.render()},300)):(this.canvasTemplate.init(),this.canvasImage.init(),this.canvasImageBottom.init(),this.render()),this.store.emitter.emit("translate",{x:this.store.data.x,y:this.store.data.y}),this.tooltip.translate(t,i),this.scroll&&this.scroll.isShow&&this.scroll.translate(t,i),this.onMovePens()}onMovePens(){var i;const t=this.parent.map;t&&t.isShow&&t.setView();for(const s of this.store.data.pens)Xt(s),(i=s.onMove)==null||i.call(s,s),s.isRuleLine&&(s.width?s.height||(s.x=-this.store.data.x):s.y=-this.store.data.y,this.updatePenRect(s))}scale(t,i={x:0,y:0}){var l;const s=this.store.data.minScale||this.store.options.minScale,r=this.store.data.maxScale||this.store.options.maxScale;if(!(t>=s&&t<=r))return;this.calibrateMouse(i);const a=t/this.store.data.scale;this.store.data.scale=t,this.store.data.center=i,(l=this.store.clipboard)!=null&&l.pos&&Pe(this.store.clipboard.pos,a,i),Pe(this.store.data.origin,a,i),this.store.data.pens.forEach(n=>{if(n.onScale&&n.onScale(n),!n.parentId){if(zt(n,a,i),n.isRuleLine){const h=1/a,c=n.calculative.worldRect.center;n.width&&n.height||zt(n,h,c)}this.updatePenRect(n,{worldRectIsReady:!0}),this.execPenResize(n)}}),this.onMovePens(),this.calcActiveRect(),this.canvasTemplate.init(),this.canvasImage.init(),this.canvasImageBottom.init();const o=this.parent.map;o&&o.isShow&&o.setView(),this.render(),this.store.emitter.emit("scale",this.store.data.scale)}animateView(t){this.viewAnimationTimer&&(cancelAnimationFrame(this.viewAnimationTimer),this.viewAnimationTimer=void 0),this.viewAnimation=void 0;const i=t.duration??300,s=t.easing??"easeOutCubic",r=t.center?{...t.center}:{x:this.width/2,y:this.height/2};let a=t.x!==void 0?t.x:this.store.data.x,o=t.y!==void 0?t.y:this.store.data.y,l=t.scale!==void 0?t.scale:this.store.data.scale;const n=this.store.data.minScale||this.store.options.minScale,h=this.store.data.maxScale||this.store.options.maxScale;if(l<n&&(l=n),l>h&&(l=h),t.pen){const c={x:this.width/2,y:this.height/2};a=c.x-t.pen.calculative.worldRect.x-t.pen.calculative.worldRect.width/2,o=c.y-t.pen.calculative.worldRect.y-t.pen.calculative.worldRect.height/2}!t.pen&&Math.abs(a-this.store.data.x)<.5&&Math.abs(o-this.store.data.y)<.5&&Math.abs(l-this.store.data.scale)<.001||(this.calibrateMouse(r),this.viewAnimation={startTime:performance.now(),duration:i,fromX:this.store.data.x,fromY:this.store.data.y,fromScale:this.store.data.scale,toX:a,toY:o,toScale:l,easing:wl(s),center:r,pen:t.pen},this.animateViewFrame())}templateScale(t,i={x:0,y:0}){const{minScale:s,maxScale:r}=this.store.options;if(!(t>=s&&t<=r))return;const a=t/this.store.data.scale;this.store.data.scale=t,this.store.data.center={x:0,y:0},this.store.data.origin={x:0,y:0},this.store.data.pens.forEach(o=>{if(!o.parentId){if(zt(o,a,i),o.onScale&&o.onScale(o),o.isRuleLine){const l=a>1?1:1/a/a,n=o.calculative.worldRect.center;o.width&&o.height||zt(o,l,n)}this.execPenResize(o)}}),this.calcActiveRect()}rotatePens(t){this.initPens||(this.initPens=K(this.getAllByPens(this.store.active))),this.activeRect.rotate=jt(t,this.activeRect.center),this.activeRect.rotate%90<10&&(this.activeRect.rotate-=this.activeRect.rotate%90),this.activeRect.rotate%90>80&&(this.activeRect.rotate+=90-this.activeRect.rotate%90),this.store.active.length===1&&(this.lastRotate=this.store.active[0].rotate||0);const i=this.activeRect.rotate-this.lastRotate;for(const s of this.store.active){if(s.parentId)return;this.rotatePen(s,i,this.activeRect),s.onRotate&&s.onRotate(s),this.updateLines(s)}this.lastRotate=this.activeRect.rotate,this.getSizeCPs(),this.initImageCanvas(this.store.active),this.initTemplateCanvas(this.store.active),this.render(),this.store.emitter.emit("rotatePens",this.store.active),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.pushHistory({type:rt.Update,pens:K(this.getAllByPens(this.store.active)),initPens:this.initPens}),this.initPens=void 0},200)}resizePens(t){if(this.initPens||(this.initPens=K(this.store.active,!0)),!this.initActiveRect){this.initActiveRect=K(this.activeRect);return}const i={x:this.mouseDown.x,y:this.mouseDown.y},s={x:t.x,y:t.y};let r=s.x-i.x,a=s.y-i.y;const o=K(this.initActiveRect);if(Xs(o,r,a,this.resizeIndex),yt(o),!this.store.options.disableDock){this.clearDock();const d=this.customResizeDock||Xo;this.dock=d(this.store,o,this.store.active,this.resizeIndex);const{xDock:v,yDock:g}=this.dock;if(v){r+=v.step;const y=this.store.pens[v.penId];y.calculative.isDock=!0}if(g){a+=g.step;const y=this.store.pens[g.penId];y.calculative.isDock=!0}}const l=this.activeRect.width,n=this.activeRect.height;let h=r-this.lastOffsetX,c=a-this.lastOffsetY;if(this.lastOffsetX=r,this.lastOffsetY=a,(t.ctrlKey||this.initPens.length===1&&this.initPens[0].ratio)&&(c=([1,3].includes(this.resizeIndex)?-1:1)*(h*n)/l),this.activeRect.ratio=this.initPens[0].ratio,Xs(this.activeRect,h,c,this.resizeIndex),this.store.options.strictScope){const d=this.store.data.width||this.store.options.width,v=this.store.data.height||this.store.options.height;if(d&&v){let g={x:this.store.data.origin.x,y:this.store.data.origin.y,width:d*this.store.data.scale,height:v*this.store.data.scale};this.activeRect.x<g.x&&(this.activeRect.width=this.activeRect.width-(g.x-this.activeRect.x),this.activeRect.x=g.x),this.activeRect.y<g.y&&(this.activeRect.height=this.activeRect.height-(g.y-this.activeRect.y),this.activeRect.y=g.y),this.activeRect.x+this.activeRect.width>g.x+g.width&&(this.activeRect.width=this.activeRect.width-(this.activeRect.x+this.activeRect.width-(g.x+g.width)),this.activeRect.x=g.x+g.width-this.activeRect.width,this.activeRect.ex=this.activeRect.x+this.activeRect.width),this.activeRect.y+this.activeRect.height>g.y+g.height&&(this.activeRect.height=this.activeRect.height-(this.activeRect.y+this.activeRect.height-(g.y+g.height)),this.activeRect.y=g.y+g.height-this.activeRect.height,this.activeRect.ey=this.activeRect.y+this.activeRect.height)}}yt(this.activeRect);const f=this.activeRect.width/l,u=this.activeRect.height/n;this.store.active.forEach((d,v)=>{d.calculative.worldRect.x=this.activeInitPos[v].x*this.activeRect.width+this.activeRect.x,d.calculative.worldRect.y=this.activeInitPos[v].y*this.activeRect.height+this.activeRect.y,d.calculative.worldRect.width*=f,d.calculative.iconWidth&&(d.calculative.iconWidth*=f),d.calculative.worldRect.height*=u,d.calculative.iconHeight&&(d.calculative.iconHeight*=u),bt(d.calculative.worldRect),yt(d.calculative.worldRect),this.updatePenRect(d,{worldRectIsReady:!0}),this.execPenResize(d,!0),this.updateLines(d)}),this.getSizeCPs(),this.initImageCanvas(this.store.active),this.initTemplateCanvas(this.store.active),this.render(),this.store.emitter.emit("resizePens",this.store.active),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.pushHistory({type:rt.Update,pens:K(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0},200)}movePens(t){var l,n;if(!this.activeRect||this.store.data.locked)return;if(!this.initActiveRect){this.initActiveRect=K(this.activeRect);return}if(!this.store.options.moveConnectedLine&&!this.canMoveLine&&this.store.active.length===1&&((l=this.store.active[0].anchors[0])!=null&&l.connectTo||(n=this.store.active[0].anchors[this.store.active[0].anchors.length-1])!=null&&n.connectTo)||(this.movingPens||(this.initMovingPens(),this.store.active.forEach(h=>{qe(h,!1)}),this.store.hover=void 0),!this.mouseDown))return;let i=t.x-this.mouseDown.x,s=t.y-this.mouseDown.y;t.shiftKey&&!t.ctrlKey&&(s=0),t.ctrlKey&&(i=0);const r=K(this.initActiveRect);ye(r,i,s);let a=!1;if(this.store.options.strictScope){const h=this.store.data.width||this.store.options.width,c=this.store.data.height||this.store.options.height;if(h&&c){let f={x:this.store.data.origin.x,y:this.store.data.origin.y,width:h*this.store.data.scale,height:c*this.store.data.scale};r.x<f.x&&(r.x=f.x,a=!0),r.y<f.y&&(r.y=f.y,a=!0),r.x+r.width>f.x+f.width&&(r.x=f.x+f.width-r.width,a=!0),r.y+r.height>f.y+f.height&&(r.y=f.y+f.height-r.height,a=!0)}}const o={x:r.x-this.activeRect.x,y:r.y-this.activeRect.y};if(!this.store.options.disableDock&&!a){this.clearDock();const h=this.customMoveDock||Yo;this.dock=h(this.store,r,this.movingPens,o);const{xDock:c,yDock:f}=this.dock;let u;c&&(o.x+=c.step,u=this.store.pens[c.penId],u.calculative.isDock=!0),f&&(o.y+=f.step,u=this.store.pens[f.penId],u.calculative.isDock=!0)}this.translatePens(this.movingPens,o.x,o.y,!0)}changeIdsByMoving(t,i){t.id+=Lt,t.parentId&&i.find(s=>s.id===t.parentId)&&(t.parentId+=Lt),t.children&&(t.children=t.children.map(s=>s+Lt)),t.connectedLines&&(t.connectedLines=t.connectedLines.map(s=>(i.find(r=>r.id===s.lineId)&&(s.lineId+=Lt),s))),t.type&&t.calculative.worldAnchors&&(t.calculative.worldAnchors=t.calculative.worldAnchors.map(s=>(s.connectTo&&i.find(r=>r.id===s.connectTo)&&(s.connectTo+=Lt),s)))}initMovingPens(){var s,r;if(!this.store.options.moveConnectedLine&&!this.canMoveLine)for(let a=0;a<this.store.active.length;a++){const o=this.store.active[a];((s=o.anchors[0])!=null&&s.connectTo||(r=o.anchors[o.anchors.length-1])!=null&&r.connectTo)&&(this.store.active.splice(a,1),o.calculative.active=void 0,--a)}this.movingPens=K(this.store.active,!0),this.movingPens=this.getAllFollowersByPens(this.movingPens);const t=this.getAllByPens(this.movingPens),i=K(t,!0);t.forEach(a=>{this.changeIdsByMoving(a,i),this.store.pens[a.id]=a,a.calculative.canvas=this;const o={globalAlpha:.5};a.lineWidth===0&&(o.lineWidth=1),(a.name.endsWith("Dom")||$i.includes(a.name)||this.store.options.domShapes.includes(a.name)||a.image||a.isDom)&&(o.name="rectangle",o.onDestroy=void 0),this.updateValue(a,o),a.calculative.image=void 0})}moveLineAnchor(t,i){var l,n,h,c,f;if(!this.activeRect||this.store.data.locked)return;if(this.initPens||(this.initPens=K(this.store.active,!0)),(l=this.store.activeAnchor)!=null&&l.connectTo){const u=this.store.pens[this.store.activeAnchor.connectTo];Ee(u,fe(u,this.store.activeAnchor.anchorId),this.store.pens[this.store.activeAnchor.penId],this.store.activeAnchor)}let s=(n=this.store.activeAnchor)==null?void 0:n.id,r=(c=(h=this.store.pens[this.store.activeAnchor.penId])==null?void 0:h.connectedLines)==null?void 0:c.filter(u=>u.anchor===s);r&&r.length>0&&r.forEach(u=>{const d=this.store.pens[u.lineId];Ee(this.store.pens[this.store.activeAnchor.penId],this.store.activeAnchor,d,fe(d,u.lineAnchor))});const a=this.store.active[0];xt(a);const o=dt(a);if(a.lineName==="polyline"&&!i.shiftKey)Jn(a,this.store.activeAnchor,t);else{let u=0,d=0;if(a.lineName==="line"){let v=a.calculative.worldAnchors.findIndex(y=>y.id===this.store.activeAnchor.id);v===0&&(v=2);let g=a.calculative.worldAnchors[v-1];if(i.ctrlKey&&i.shiftKey){let y=K(t);this.getSpecialAngle(y,g),u=y.x-this.store.activeAnchor.x,d=y.y-this.store.activeAnchor.y}else if(!i.ctrlKey&&i.shiftKey){let y={x:t.x,y:g.y};u=y.x-this.store.activeAnchor.x,d=y.y-this.store.activeAnchor.y}else if(i.ctrlKey&&!i.shiftKey){let y={x:g.x,y:t.y};u=y.x-this.store.activeAnchor.x,d=y.y-this.store.activeAnchor.y}else u=t.x-this.store.activeAnchor.x,d=t.y-this.store.activeAnchor.y}else!i.ctrlKey&&i.shiftKey?(u=t.x-this.store.activeAnchor.x,d=0):i.ctrlKey&&!i.shiftKey?(u=0,d=t.y-this.store.activeAnchor.y):(u=t.x-this.store.activeAnchor.x,d=t.y-this.store.activeAnchor.y);Ye(this.store.activeAnchor,u,d),this.store.hover&&this.store.hoverAnchor&&this.store.hoverAnchor.penId!==this.store.activeAnchor.penId&&(this.store.hoverAnchor.type===$t.Line?(u=t.x-this.store.activeAnchor.x,d=t.y-this.store.activeAnchor.y,ei(this.store.activeAnchor,this.store.hoverAnchor,this.store)):(u=this.store.hoverAnchor.x-this.store.activeAnchor.x,d=this.store.hoverAnchor.y-this.store.activeAnchor.y),Ye(this.store.activeAnchor,u,d),o.prev=void 0,a.lineName!=="polyline"&&((f=this[a.lineName])==null||f.call(this,this.store,a)))}this.patchFlagsLines.add(a),this.store.path2dMap.set(a,it.path2dDraws[a.name](a)),this.render(),this.store.active[0].calculative&&(this.store.active[0].calculative.gradientAnimatePath=void 0),this.store.emitter.emit("moveLineAnchor",{pen:this.store.active[0],anchor:this.store.activeAnchor}),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.pushHistory({type:rt.Update,pens:K(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0},500)}moveLineAnchorPrev(t){if(!this.activeRect||this.store.data.locked||!this.store.activeAnchor)return;if(this.initPens||(this.initPens=K(this.store.active,!0)),this.store.activeAnchor.prev.x=t.x,this.store.activeAnchor.prev.y=t.y,this.store.activeAnchor.next){if(!this.store.activeAnchor.prevNextType)this.store.activeAnchor.next.x=t.x,this.store.activeAnchor.next.y=t.y,vt(this.store.activeAnchor.next,180,this.store.activeAnchor);else if(this.store.activeAnchor.prevNextType===pe.Bilateral&&this.prevAnchor){const s=jt(t,this.store.activeAnchor),r=jt(this.prevAnchor,this.store.activeAnchor);this.store.activeAnchor.next.x=this.nextAnchor.x,this.store.activeAnchor.next.y=this.nextAnchor.y,vt(this.store.activeAnchor.next,s-r,this.store.activeAnchor)}}const i=this.store.active[0];this.patchFlagsLines.add(i),this.store.path2dMap.set(i,it.path2dDraws[i.name](i)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.pushHistory({type:rt.Update,pens:K(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0},200)}moveLineAnchorNext(t){if(!this.activeRect||this.store.data.locked||!this.store.activeAnchor)return;if(this.initPens||(this.initPens=K(this.store.active,!0)),this.store.activeAnchor.next.x=t.x,this.store.activeAnchor.next.y=t.y,this.store.activeAnchor.prev){if(!this.store.activeAnchor.prevNextType)this.store.activeAnchor.prev.x=t.x,this.store.activeAnchor.prev.y=t.y,vt(this.store.activeAnchor.prev,180,this.store.activeAnchor);else if(this.store.activeAnchor.prevNextType===pe.Bilateral&&this.nextAnchor){const s=jt(t,this.store.activeAnchor),r=jt(this.nextAnchor,this.store.activeAnchor);this.store.activeAnchor.prev.x=this.prevAnchor.x,this.store.activeAnchor.prev.y=this.prevAnchor.y,vt(this.store.activeAnchor.prev,s-r,this.store.activeAnchor)}}const i=this.store.active[0];this.patchFlagsLines.add(i),this.store.path2dMap.set(i,it.path2dDraws[i.name](i)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.pushHistory({type:rt.Update,pens:K(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0},200)}async setAnchor(t){var r;const i=[K(this.store.hover,!0)],s=this.store.hover;if(this.store.hoverAnchor){if(this.beforeRemoveAnchor&&!await this.beforeRemoveAnchor(s,this.store.hoverAnchor))return;s.type===ut.Line&&((r=s.calculative.worldAnchors)==null?void 0:r.length)<=2?this.delete([s]):(Do(s,this.store.hoverAnchor),s.type===ut.Line&&this.initLineRect(s)),this.store.hoverAnchor=void 0,this.store.activeAnchor=void 0,this.externalElements.style.cursor="default"}else if(s){if(this.beforeAddAnchor&&!await this.beforeAddAnchor(s,this.store.pointAt))return;if(s.type===ut.Line){this.store.activeAnchor=Lo(s,this.store.pointAt,this.store.pointAtIndex),this.initLineRect(s);const a={x:t.x,y:t.y};this.getHover(a)}else{const a={id:lt(),x:t.x,y:t.y};this.store.activeAnchor=Mo(s,a)}}this.hotkeyType=ft.None,this.render(),s&&this.pushHistory({type:rt.Update,pens:[K(s,!0)],initPens:i})}checkDisconnect(t,i){if(t.id.indexOf(Lt)>0){const s=t.id;t=this.store.pens[s.replace(Lt,"")]}t.anchors.forEach(s=>{if(s.connectTo&&!i.find(r=>r.id===s.connectTo||r.id===s.connectTo+Lt)){const r=this.store.pens[s.connectTo];if(!r||r.type)return;Ee(r,fe(r,s.anchorId),t,s)}})}translatePens(t=this.store.active,i,s,r){if(!t||!t.length||t.some(n=>{if(n.locked>=ct.DisableMove)return!0}))return;const o=!r&&K(t,!0);this.activeRect&&ye(this.activeRect,i,s);const l=this.getAllByPens(t);t.forEach(n=>{var h,c;if(!(n.locked>=ct.DisableMove)){if(n.type===ut.Line){if(!this.store.options.moveConnectedLine&&!this.canMoveLine||n.isRuleLine)return;Ls(n,i,s),this.checkDisconnect(n,l),this.store.path2dMap.set(n,it.path2dDraws[n.name](n)),r||(this.initLineRect(n),(h=n.connectedLines)==null||h.forEach(f=>{const u=this.store.pens[f.lineId];this.initLineRect(u)}))}else ye(n.calculative.worldRect,i,s),this.updatePenRect(n,{worldRectIsReady:!0}),n.calculative.x=n.x,n.calculative.y=n.y,n.calculative.initRect&&(n.calculative.initRect.x=n.calculative.x,n.calculative.initRect.y=n.calculative.y,n.calculative.initRect.ex=n.calculative.x+n.calculative.width,n.calculative.initRect.ey=n.calculative.y+n.calculative.height);this.updateLines(n),(c=n.onMove)==null||c.call(n,n)}}),this.activeRect&&this.getSizeCPs(),this.render(),this.tooltip.translate(i,s),r||(this.pushHistory({type:rt.Update,pens:K(t,!0),initPens:o}),this.initImageCanvas(t),this.initTemplateCanvas(t),this.store.emitter.emit("translatePens",t)),this.store.emitter.emit("translatingPens",t)}templateTranslatePens(t=this.store.active,i,s){if(!t||!t.length)return;const r=this.getAllByPens(t);t.forEach(a=>{var o;if(a.type===ut.Line){if(!this.store.options.moveConnectedLine&&!this.canMoveLine)return;Ls(a,i,s),this.checkDisconnect(a,r),this.store.path2dMap.set(a,it.path2dDraws[a.name](a))}else ye(a.calculative.worldRect,i,s),this.updatePenRect(a,{worldRectIsReady:!0}),a.calculative.x=a.x,a.calculative.y=a.y,a.calculative.initRect&&(a.calculative.initRect.x=a.calculative.x,a.calculative.initRect.y=a.calculative.y,a.calculative.initRect.ex=a.calculative.x+a.calculative.width,a.calculative.initRect.ey=a.calculative.y+a.calculative.height);(o=a.onMove)==null||o.call(a,a)})}calcAutoAnchor(t,i,s,r){const a=xt(t),o=dt(t),l=_e(s,i===a?o:a);l&&(i.x=l.x,i.y=l.y,i.prev=void 0,i.next=void 0,r?r.anchor=l.id:Tt(s,l,t,i),this[t.lineName]&&this[t.lineName](this.store,t),this.store.path2dMap.set(t,it.path2dDraws.line(t)),this.initLineRect(t))}restoreNodeAnimate(t){var i,s;if(t.calculative.initRect){if(t.keepAnimateState)for(const r in t)t.calculative[r]!==void 0&&r!=="x"&&r!=="y"&&r!=="width"&&r!=="height"&&r!=="initRect"&&(typeof t[r]!="object"||r==="lineDash")&&(r==="fontSize"||r==="lineWidth"?t[r]=t.calculative[r]/t.calculative.canvas.store.data.scale:t[r]=t.calculative[r]);else{const r=t.calculative.initRect.rotate-t.calculative.rotate;for(const o in t)o!=="x"&&o!=="y"&&o!=="width"&&o!=="height"&&o!=="initRect"&&o!=="rotate"&&(typeof t[o]!="object"||o==="lineDash")&&(t.calculative[o]=t[o]);(i=t.children)!=null&&i.length?r&&Wr(t,r,t.calculative.worldRect):t.calculative.rotate=t.rotate;const a=K(this.store.animateMap.get(t));a&&(a.id=t.id,this.parent.setValue(a,{doEvent:!1,render:!0,history:!1})),t.calculative.worldRect=t.calculative.initRect}this.updatePenRect(t,{worldRectIsReady:!0}),this.updateLines(t),t.image&&t.name!=="gif"&&(this.canvasImage.init(),this.canvasImageBottom.init()),t.calculative.text!==t.text&&(t.calculative.text=t.text,Ne(t)),(s=this.store.active)!=null&&s.length&&this.calcActiveRect(),t.calculative.initRect=void 0}}updateLines(t,i){var s;(s=t.children)==null||s.forEach(r=>{const a=this.store.pens[r];a&&this.updateLines(a,i)}),t.connectedLines&&t.connectedLines.forEach((r,a)=>{const o=this.store.pens[r.lineId];if(!o||o.calculative.active)return;const l=fe(o,r.lineAnchor);if(!l)return;if(!l.connectTo){t.connectedLines.splice(a,1);return}if(o.autoFrom){const u=xt(o);u.id===l.id&&this.calcAutoAnchor(o,u,t,r)}if(o.autoTo){const u=dt(o);u.id===l.id&&this.calcAutoAnchor(o,u,t,r)}const n=fe(t,r.anchor);if(!n)return;let h=t.rotate;t.flipX&&(h*=-1),t.flipY&&(h*=-1);let c=l.distance*this.store.data.scale*Math.cos((h+n.rotate)/180*Math.PI)||0,f=l.distance*this.store.data.scale*Math.sin((h+n.rotate)/180*Math.PI)||0;if(t.flipX&&(c=-c),t.flipY&&(f=-f),Ye(l,n.x-l.x+c,n.y-l.y+f),this.store.options.autoPolyline&&!this.autoPolylineFlag&&o.autoPolyline!==!1&&o.lineName==="polyline"){let u=xt(o),d=dt(o),v=!1;u.id===l.id?(u=l,v=!0):d.id===l.id&&(d=l,v=!0),v&&(o.calculative.worldAnchors=[u,d],o.calculative.activeAnchor=u,this.polyline(this.store,o,d),this.initLineRect(o))}this.store.path2dMap.set(o,it.path2dDraws[o.name](o)),this.patchFlagsLines.add(o),o.calculative.gradientSmooth&&(o.calculative.gradientAnimatePath=hs(o)),i&&Si(o)})}calcActiveRect(){const t=this.store.active.filter(i=>(!i.locked||i.locked<ct.DisableMove)&&i.visible!=!1);if(t.length)t.length===1?(this.activeRect=K(t[0].calculative.worldRect),this.activeRect.rotate=t[0].calculative.rotate||0,yt(this.activeRect)):(this.activeRect=Vt(t),this.activeRect.rotate=0);else return;this.lastRotate=0,this.getSizeCPs()}rotatePen(t,i,s){t.rotateByRoot||(t.name==="line"?(t.calculative.worldAnchors.forEach(r=>{vt(r,i,s.center)}),this.initLineRect(t),fi(t)):(t.calculative.rotate?t.calculative.rotate+=i:t.calculative.rotate=i,vt(t.calculative.worldRect.center,i,s.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-s.x)/s.width,t.y=(t.calculative.worldRect.y-s.y)/s.height):(t.x=t.calculative.worldRect.center.x-t.width/2,t.y=t.calculative.worldRect.center.y-t.height/2),t.rotate=t.calculative.rotate,this.updatePenRect(t),t.children&&t.children.forEach(r=>{const a=this.store.pens[r];this.rotatePen(a,i,t.calculative.worldRect)})))}nextAnimate(t){if(!t)return;this.store.emitter.emit("animateEnd",t);let i;t.nextAnimate&&(i=this.store.data.pens.filter(s=>s.id===t.nextAnimate||s.tags&&s.tags.indexOf(t.nextAnimate)>-1)),i&&(i.forEach(s=>{var r,a,o,l,n;if(s.calculative.pause){const h=Date.now()-s.calculative.pause;s.calculative.pause=void 0,s.calculative.frameStart+=h,s.calculative.frameEnd+=h}else if(s.name==="video")s.calculative.media.currentTime=0,(r=s.calculative.media)==null||r.play(),(a=s.onStartVideo)==null||a.call(s,s);else if(s.type||(o=s.frames)!=null&&o.length||s.animations&&s.animations.length){if(s.type){if((n=s.animations)!=null&&n.length){const h=K(s.animations[0]);delete h.name,h.currentAnimation=0,this.parent.setValue({id:s.id,...h},{doEvent:!1,history:!1})}}else{if(!s.frames&&s.animations&&s.animations.length){let h=(l=s.animations)==null?void 0:l.findIndex(u=>u.autoPlay),c=h===-1?0:h;const f=K(s.animations[c]);delete f.name,f.currentAnimation=c,!s.type&&f.frames&&(f.showDuration=this.parent.calcAnimateDuration(f)),this.parent.setValue({id:s.id,...f},{doEvent:!1,history:!1})}this.store.animateMap.set(s,this.getFrameProps(s))}this.store.animates.add(s)}}),this.animate())}getFrameProps(t){let i={};return t.frames&&t.frames.forEach(s=>{for(let r in s)!["duration","x","y","width","height","rotate"].includes(r)&&!i[r]&&(i[r]=t[r])}),i}animate(){this.animateRendering||requestAnimationFrame(()=>{const t=Date.now();if(t-this.lastAnimateRender<this.store.options.animateInterval){this.store.animates.size>0&&this.animate();return}this.lastAnimateRender=t,this.animateRendering=!0;const i=[];let s=!1;for(const r of this.store.animates)if(!r.calculative.pause){if(r.calculative.active&&!r.type&&!this.movingPens&&(s=!0),!r.type)Oo(r,t)?r.calculative.patchFlags&&(yt(r.calculative.worldRect),this.updatePenRect(r,{worldRectIsReady:!0,playingAnimate:!0})):(requestAnimationFrame(()=>{this.restoreNodeAnimate(r)}),i.push(r),this.nextAnimate(r)),this.updateLines(r,!0);else if(!No(r,t)){if(r.keepAnimateState){for(const a in r)r.calculative[a]!==void 0&&a!=="length"&&(typeof r[a]!="object"||a==="lineDash")&&(a==="lineWidth"?r[a]=r.calculative[a]/r.calculative.canvas.store.data.scale:r[a]=r.calculative[a]);fi(r)}else for(const a in r)(typeof r[a]!="object"||a==="lineDash")&&(a==="lineWidth"?r.calculative[a]=r[a]*r.calculative.canvas.store.data.scale:r.calculative[a]=r[a]);i.push(r),this.nextAnimate(r)}this.patchFlags=!0}s&&this.calcActiveRect(),i.forEach(r=>{this.store.animates.delete(r)}),this.render(!1),this.animateRendering=!1,this.animate()})}get clipboardName(){return"meta2d-clipboard"}async copy(t,i=!0){const s=lt(),{origin:r,scale:a}=this.store.data;this.store.clipboard=void 0,localStorage.removeItem(this.clipboardName),sessionStorage.setItem("page",s);let o=K(t,!0);o||(o=K(this.store.active,!0),o.length===1&&o[0].parentId&&(o[0].parentId=void 0,o[0].x=o[0].calculative.worldRect.x,o[0].y=o[0].calculative.worldRect.y,o[0].width=o[0].calculative.worldRect.width,o[0].height=o[0].calculative.worldRect.height));let l=this.getAllByPens(o);l.forEach(h=>{var c;h.copyIndex=this.store.data.pens.findIndex(f=>f.id===h.id),(c=h.followers)!=null&&c.length&&(h.followers=void 0),h.pathId&&(h.path=this.store.data.paths[h.pathId])}),l.sort((h,c)=>h.copyIndex-c.copyIndex);const n={meta2d:!0,pens:l,origin:K(r),scale:a,page:s,initRect:K(this.activeRect),offset:10,mousePos:K(this.mousePos)};if(navigator.clipboard&&!this.store.options.disableClipboard&&!navigator.userAgent.includes("Firefox"))try{await navigator.clipboard.writeText(JSON.stringify(n))}catch{localStorage.setItem(this.clipboardName,JSON.stringify(n))}else localStorage.setItem(this.clipboardName,JSON.stringify(n));i&&this.store.emitter.emit("copy",n.pens)}cut(t){this.copy(t,!1),this.delete(t),this.store.emitter.emit("cut",t)}async paste(){var n,h;let t,i;if(navigator.clipboard&&!this.store.options.disableClipboard&&!navigator.userAgent.includes("Firefox"))try{t=await((n=navigator.clipboard)==null?void 0:n.readText())}catch{t=localStorage.getItem(this.clipboardName)}else t=localStorage.getItem(this.clipboardName);if(t){try{i=JSON.parse(t)}catch(c){console.warn("剪切板数据不是json",c.message);return}if(!i||!i.meta2d)return}else return;if(this.beforeAddPens&&await this.beforeAddPens(i.pens)!=!0)return;let s,r;this.store.clipboard&&(s=this.store.clipboard.offset+10,r=this.store.clipboard.pos),this.store.clipboard=K(i);const a=sessionStorage.getItem("page"),o=this.store.data.scale;if(this.store.clipboard.mousePos&&(Math.abs(this.store.clipboard.mousePos.x-this.mousePos.x)>100*o||Math.abs(this.store.clipboard.mousePos.y-this.mousePos.y)>100*o)){let c=-this.store.clipboard.initRect.width/this.store.clipboard.scale/10/o,f=-this.store.clipboard.initRect.height/this.store.clipboard.scale/10/o,u=(o-this.store.clipboard.scale)*this.store.clipboard.initRect.width/2+c,d=(o-this.store.clipboard.scale)*this.store.clipboard.initRect.height/2+f;o<this.store.clipboard.scale&&(u=(o-this.store.clipboard.scale)/((this.store.clipboard.scale-o)*100)*this.store.clipboard.initRect.width/2+c,d=(o-this.store.clipboard.scale)/((this.store.clipboard.scale-o)*100)*this.store.clipboard.initRect.height/2+f),this.store.clipboard.pens.length>1&&(u=(o-1)*this.store.clipboard.initRect.width/this.store.clipboard.scale/2,d=(o-1)*this.store.clipboard.initRect.height/this.store.clipboard.scale/2),this.store.clipboard.pos={x:this.mousePos.x-u,y:this.mousePos.y-d},this.store.clipboard.offset=0}else a!==i.page?(this.store.clipboard.pos={x:this.mousePos.x,y:this.mousePos.y},this.store.clipboard.offset=0):this.pasteOffset?(s&&(this.store.clipboard.offset=s),r&&(this.store.clipboard.pos=r)):(this.store.clipboard.offset=0,this.pasteOffset=!0);const l=this.store.clipboard.pens.filter(c=>!c.parentId);for(const c of l)this.pastePen(c,void 0);(h=this.keyOptions)!=null&&h.F||this.store.clipboard.pens.forEach(c=>{delete c.copyIndex}),sessionStorage.setItem("page",i.page),this.active(l),this.pushHistory({type:rt.Add,pens:this.store.clipboard.pens}),this.render(),this.store.emitter.emit("add",this.store.clipboard.pens),this.store.emitter.emit("paste",this.store.clipboard.pens)}getAllByPens(t){const i=[];for(const s of t)i.push(...K(Pt(s,this.store),!0));return i.concat(t)}getAllFollowersByPens(t,i=!0){const s=t;for(const r of t){let a=cs(r,this.store);i&&(a=K(a,!0));for(const o of a)s.find(l=>l.id===o.id)||s.push(o)}return s}setFollowers(t=this.store.active){if(t)if(t.length<2)t[0].followers=[];else{let i=t.map(r=>r.id);i.pop();const s=t[t.length-1];s.followers?i.forEach(r=>{s.followers.includes(r)||s.followers.push(r)}):s.followers=i}}changeLineAnchors(t,i,s){if(Array.isArray(i.connectedLines))for(let r=0;r<i.connectedLines.length;r++){const{lineId:a}=i.connectedLines[r],o=s.find(l=>l.id===a);if(o){const l=o.anchors[0],n=o.anchors[o.anchors.length-1];l.connectTo===t&&(l.connectTo=i.id),n.connectTo===t&&(n.connectTo=i.id)}else i.connectedLines.splice(r,1),r--}}changeNodeConnectedLine(t,i,s){var l;const r=i.anchors[0],a=i.anchors[i.anchors.length-1],o=[r,a];for(const n of o){const h=n.connectTo;if(h){const c=s.find(f=>f.id===h);c?(l=c.connectedLines)==null||l.forEach(f=>{f.lineId===t&&(f.lineId=i.id,f.lineAnchor=n.id)}):(n.connectTo=void 0,n.prev&&(n.prev.connectTo=void 0),n.next&&(n.next.connectTo=void 0))}}}async delete(t=this.store.active,i=!1,s=!0){if(!t||!t.length||this.beforeRemovePens&&await this.beforeRemovePens(t)!=!0||(i||(t=t.filter(a=>!a.locked)),!t||!t.length))return;const r=[];if(this._del(t,r,i),this.initImageCanvas(r),this.initTemplateCanvas(r),this.inactive(),this.clearHover(),this.render(),s){if(r.length===0)return;this.pushHistory({type:rt.Delete,pens:r})}this.store.emitter.emit("delete",t)}deleteSync(t=this.store.active,i=!1,s=!0){if(!t||!t.length||(i||(t=t.filter(a=>!a.locked)),!t||!t.length))return;const r=[];if(this._del(t,r,i),this.initImageCanvas(r),this.initTemplateCanvas(r),this.inactive(),this.clearHover(),this.render(),s){if(r.length===0)return;this.pushHistory({type:rt.Delete,pens:r})}this.store.emitter.emit("delete",t)}_del(t,i,s){t&&t.forEach(r=>{if(r.type&&(r.lastConnected={}),r.parentId)if(this.getLockedParent(r)){console.warn("父节点锁定");return}else{const o=Mt(r),l=o.children.indexOf(r.id);o.children.splice(l,1),i&&this.getDelPens(r,i),this.delForce(r)}else{if(!s&&r.locked)return;i&&this.getDelPens(r,i),this.delForce(r)}})}getDelPens(t,i){if(!t)return;if(this.store.data.pens.findIndex(r=>r.id===t.id)>-1){const r=this.store.pens[t.id];r&&r.calculative&&(r.calculative.active=void 0),r.pathId&&(r.path=this.store.data.paths[t.pathId]),i.push(r)}t.children&&t.children.forEach(r=>{this.getDelPens(this.store.pens[r],i)})}getLockedParent(t){if(!t.parentId)return!1;const i=Mt(t);if(i.locked)return i;this.getLockedParent(i)}delForce(t){var s;if(!t)return;const i=this.store.data.pens.findIndex(r=>r.id===t.id);i>-1&&(this.delConnectedLines(this.store.data.pens[i]),this.store.data.pens.splice(i,1),this.store.pens[t.id]=void 0,delete this.store.pens[t.id],t.pathId&&(this.store.data.pens.some(a=>a.pathId===t.pathId)||delete this.store.data.paths[t.pathId])),this.store.animates.delete(t),this.store.animateMap.delete(t),t.children&&t.children.forEach(r=>{this.delForce(this.store.pens[r])}),(s=t.onDestroy)==null||s.call(t,t)}delConnectedLines(t){var i;if(t.connectedLines)for(let s=0;s<t.connectedLines.length;s++){const{lineId:r,lineAnchor:a}=t.connectedLines[s],o=this.store.pens[r];if(o){let l=o.anchors.find(n=>n.id===a);(l==null?void 0:l.connectTo)===t.id&&(l.connectTo=void 0,l.anchorId=void 0,l.prev&&(l.prev.connectTo=void 0),l.next&&(l.next.connectTo=void 0)),l=fe(o,a),l&&(l.connectTo=void 0,l.anchorId=void 0,l.prev&&(l.prev.connectTo=void 0),l.next&&(l.next.connectTo=void 0))}}t.type&&((i=t.calculative.worldAnchors)==null||i.forEach((s,r)=>{var o;if(!s.connectTo)return;const a=this.store.pens[s.connectTo];a&&((o=a.calculative.worldAnchors)==null||o.forEach(l=>{Ee(a,l,t,s)}))}))}convertSpecialCharacter(t){var i={lt:"<",gt:">",nbsp:" ",amp:"&",quot:'"'};return t.replace(/&(lt|gt|nbsp|amp|quot);/gi,function(s,r){return i[r]})}createInput(){var i;this.inputParent.classList.add("meta2d-input"),this.inputDiv.classList.add("input-div"),this.inputParent.appendChild(this.inputDiv),this.dropdown.onmouseleave=()=>{this.store.hover=null},this.inputParent.appendChild(this.dropdown),this.externalElements.appendChild(this.inputParent),this.inputParent.onmousedown=this.stopPropagation,this.inputDiv.onmousedown=this.stopPropagation,this.inputDiv.contentEditable="false",this.dropdown.onmousedown=this.stopPropagation;let t;for(let s=0;s<document.styleSheets.length;s++)document.styleSheets[s].title==="le5le.com"&&(t=document.styleSheets[s]);if(!t){const s=document.createElement("style");s.title="le5le.com",document.head.appendChild(s),t=s.sheet,t.insertRule(".meta2d-input{display:none;position:absolute;outline:none;align-items: center;}"),t.insertRule(".meta2d-input textarea{resize:none;border:none;outline:none;background:transparent;flex-grow:1;height:100%;left:0;top:0}"),t.insertRule(".meta2d-input .right{width:10px;height:10px;flex-shrink:0;border-top: 1px solid;border-right: 1px solid;margin-right: 5px;transition: all .3s cubic-bezier(.645,.045,.355,1);position:absolute;right:1px;}"),t.insertRule(".meta2d-input ul{position:absolute;top:100%;margin-top:4px; width:calc(100% + 10px);min-height:30px;border-radius: 2px;box-shadow: 0 2px 8px #00000026;list-style-type: none;background-color: #fff;padding: 4px 0;max-height: 105px;overflow-y: auto;}"),t.insertRule(".meta2d-input ul li{padding: 5px 12px;line-height: 22px;white-space: nowrap;cursor: pointer;}"),t.insertRule(".meta2d-input ul li:hover{background: #eeeeee;}"),(i=CSS.supports)!=null&&i.call(CSS,"selector(.input-div::-webkit-scrollbar)")&&t.insertRule(".input-div::-webkit-scrollbar {display:none}"),t.insertRule(".input-div{scrollbar-width: none;}"),t.insertRule(".meta2d-input .input-div{resize:none;border:none;outline:none;background:transparent;flex-grow:1;height:100%;width: 100%;left:0;top:0;display:flex;text-align: center;justify-content: center;flex-direction: column;}"),t.insertRule(".input-div div{}")}this.inputDiv.onfocus=s=>{if(navigator.userAgent.includes("Firefox")){if(!s.target.innerText){let r=this.inputDiv.offsetWidth/2;window.getComputedStyle(this.inputDiv,null).textAlign!=="center"&&(r=0),this.inputDiv.innerHTML=`<br style="margin-left:${r}px;margin-top:4px;" />`}}else if(s.target.innerText)this.inputDiv.style.paddingTop="";else{let r=window.getComputedStyle(this.inputDiv,null);r.justifyContent==="center"&&(this.inputDiv.style.paddingTop=` ${this.inputDiv.offsetHeight/2-parseFloat(r.lineHeight)/2}px`)}},this.inputDiv.oninput=s=>{const r=this.store.pens[this.inputDiv.dataset.penId];if(r&&r.inputType==="number"){const a=s.target.innerText,o=$a(a);a!==o&&(s.preventDefault(),s.target.innerText=o)}if(navigator.userAgent.includes("Firefox")){if(!s.target.innerText.trim()){let a=this.inputDiv.offsetWidth/2;window.getComputedStyle(this.inputDiv,null).textAlign!=="center"&&(a=0),this.inputDiv.innerHTML=`<br style="margin-left:${a}px;margin-top:4px;" />`}}else if(s.target.innerText)this.inputDiv.style.paddingTop="";else{let a=window.getComputedStyle(this.inputDiv,null);a.justifyContent==="center"&&(this.inputDiv.style.paddingTop=` ${this.inputDiv.offsetHeight/2-parseFloat(a.lineHeight)/2}px`)}this.store.emitter.emit("input",r)},this.inputDiv.onclick=s=>{s.stopPropagation();const r=this.store.pens[this.inputDiv.dataset.penId];this.dropdown.style.display==="block"?this.dropdown.style.display="none":r!=null&&r.dropdownList&&this.store.data.locked&&(this.dropdown.style.display="block"),this.store.emitter.emit("clickInput",r)},this.inputDiv.onkeyup=s=>{this.setDropdownList(!0);const r=this.store.pens[this.inputDiv.dataset.penId];this.store.emitter.emit("input",{pen:r,text:s.key}),s.stopPropagation()},this.inputDiv.onkeydown=s=>{if(s.key==="Enter"){const r=this.store.pens[this.inputDiv.dataset.penId];r.input&&r.whiteSpace==="nowrap"&&this.hideInput()}s.stopPropagation()},this.inputDiv.onmousedown=this.stopPropagation,this.inputDiv.onwheel=s=>{s.stopPropagation()},this.inputDiv.onpaste=s=>{s.preventDefault();let r="";s.clipboardData&&s.clipboardData.getData&&(r=s.clipboardData.getData("text/plain")),document.execCommand("insertHTML",!1,r)}}clearDropdownList(){if(this.dropdown.hasChildNodes())for(let t=0;t<this.dropdown.childNodes.length;t++)this.dropdown.childNodes[t].remove(),--t}dropdownAppendOption(t,i){const s=document.createElement("li");s.onwheel=this.stopPropagation,s.innerText=t,s.style.overflow="hidden",s.style.textOverflow="ellipsis",s.title=t,s.style.zoom=this.store.data.scale,s.onmousedown=this.stopPropagation,s.dataset.i=i+"",s.onclick=this.selectDropdown,s.ontouchstart=this.selectDropdown;const r=this.store.pens[this.inputDiv.dataset.penId];s.onmouseenter=()=>{s.style.background=r.dropdownHoverBackground||this.store.styles.activeBg||"#eee",s.style.color=r.dropdownHoverColor||"#bdc7db"},s.onmouseleave=()=>{s.style.background=r.dropdownBackground||this.store.styles.popContentBg||"#fff",s.style.color=r.dropdownColor||"#bdc7db"},this.dropdown.appendChild(s)}find(t){return this.store.data.pens.filter(i=>i.id==t||i.tags&&i.tags.indexOf(t)>-1)}findOne(t){return this.store.data.pens.find(i=>i.id==t||i.tags&&i.tags.indexOf(t)>-1)}changePenId(t,i){var r,a,o,l,n,h,c;if(t===i)return;const s=this.store.pens[t];if(s&&!this.store.pens[i]){if(s.id=i,this.store.pens[i]=this.store.pens[t],(r=s.onChangeId)==null||r.call(s,s,t,i),delete this.store.pens[t],s.parentId){const f=this.store.pens[s.parentId],u=(a=f.children)==null?void 0:a.findIndex(d=>d===t);u!==-1&&((o=f.children)==null||o.splice(u,1,i))}(l=s.children)==null||l.forEach(f=>{const u=this.store.pens[f];u.parentId=i}),s.formId&&s.followers.forEach(f=>{const u=this.store.pens[f];u.formId=i}),s.type===ut.Line?this.changeNodeConnectedLine(t,s,this.store.data.pens):(this.changeLineAnchors(t,s,this.store.data.pens),(n=s.connectedLines)==null||n.forEach(({lineId:f})=>{const u=this.store.pens[f];Le(u)})),(h=s.anchors)==null||h.forEach(f=>f.penId=i),(c=s.calculative.worldAnchors)==null||c.forEach(f=>f.penId=i)}}updateValue(t,i){var v,g;const s=this.getPenRect(t),r=t.name;Object.assign(t,i);const a=r!==t.name;i.newId&&this.changePenId(t.id,i.newId);let o=!1,l=!1,n=!1,h=!1,c=!1,f=!1,u,d=!1;for(const y in i)y.indexOf(".")===-1?(y==="rotate"?t.disableRotate?t.rotate=t.calculative.rotate||0:u=t.calculative.rotate||0:y==="canvasLayer"||y==="isBottom"||y==="showChild"?f=!0:y==="image"&&(d=!0),(typeof t[y]!="object"||y==="lineDash")&&(!t.disableRotate||y!=="rotate")&&(t.calculative[y]=i[y]),Ra.includes(y)&&(l=!0),["name","borderRadius","lineSmooth","close"].includes(y)&&(o=!0),Ta.includes(y)&&(c=!0),Ca.includes(y)&&(n=!0),Aa.includes(y)&&(h=!0),t.image&&t.name!=="gif"&&yr.includes(y)&&(d=!0)):(delete t[y],bi(t,y,i[y])),y.split(".")[0]==="anchors"&&Le(t);if(this.setCalculativeByScale(t),a&&((v=t.onDestroy)==null||v.call(t,t),Sa(t)),c){const y={x:i.x??s.x,y:i.y??s.y,width:i.width??s.width,height:i.height??s.height};this.setPenRect(t,y,!1),this.updateLines(t,!0),this.store.active&&this.store.active.length&&t.id===this.store.active[0].id&&this.calcActiveRect()}else n?this.updatePenRect(t):(!t.hiddenText&&l&&Yt(t),h&&Ms(this.store.pens,t),o&&it.path2dDraws[t.name]&&this.store.path2dMap.set(t,it.path2dDraws[t.name](t)));if(u!==void 0){const y=t.calculative.rotate;t.calculative.rotate=u,this.rotatePen(t,y-u,t.calculative.worldRect)}(i.image||i.backgroundImage||i.strokeImage)&&(t.calculative.image=void 0,t.calculative.backgroundImage=void 0,t.calculative.strokeImage=void 0,this.loadImage(t)),i.lineGradientColors&&(t.calculative.lineGradient=void 0,t.calculative.gradientColorStop=void 0),i.gradientColors&&(t.calculative.gradient=void 0,t.calculative.radialGradient=void 0),i.gradientRadius&&(t.calculative.gradient=void 0,t.calculative.radialGradient=void 0),i.animateLineWidth&&(t.calculative.gradientAnimatePath=void 0),i.gradientSmooth&&(t.calculative.gradientAnimatePath=void 0),f?(this.canvasImage.init(),this.canvasImageBottom.init()):d&&(t.canvasLayer===void 0&&(t.canvasLayer=ht.CanvasImageBottom,t.calculative.canvasLayer=ht.CanvasImageBottom),t.canvasLayer===ht.CanvasImageBottom?this.canvasImageBottom.init():t.canvasLayer===ht.CanvasImage&&this.canvasImage.init()),(i.canvasLayer!==void 0||t.canvasLayer===ht.CanvasTemplate)&&this.initTemplateCanvas([t]),i.zIndex!==void 0&&(g=t.calculative.singleton)!=null&&g.div&&Ct(t,t.calculative.singleton.div)}execPenResize(t,i){var s,r;(s=t.onResize)==null||s.call(t,t,i),(r=t.children)==null||r.forEach(a=>{const o=this.store.pens[a];o&&this.execPenResize(o,i)})}setPenRect(t,i,s=!0){if(t.parentId)Object.assign(t,i);else{const{origin:r,scale:a}=this.store.data;t.x=r.x+i.x*a,t.y=r.y+i.y*a,t.width=i.width*a,t.height=i.height*a}this.updatePenRect(t),this.execPenResize(t,!0),s&&this.render()}getPenRect(t,i=this.store.data.origin,s=this.store.data.scale){if(t)return t.parentId?{x:t.x,y:t.y,width:t.width,height:t.height}:{x:(t.x-i.x)/s,y:(t.y-i.y)/s,width:t.width/s,height:t.height/s}}toPng(t=2,i,s=!1,r){var A;const a=Vt(this.store.data.pens),o=this.store.data.scale;if(!isFinite(a.width))throw new Error("can not to png, because width is not finite");const l=K(a),n=this.store.data,h=s&&this.store.bkImg;let c=!1,f=!1;if(h){if(a.x+=n.x,a.y+=n.y,bt(a),ee(a,this.canvasRect,!0))Object.assign(a,this.canvasRect);else{const S=Ze([...re(a),...re(this.canvasRect)]);Object.assign(a,S)}c=a.x===0,f=a.y===0}const u=this.store.data.width||this.store.options.width,d=this.store.data.height||this.store.options.height;let v=!1;u&&d&&!this.store.data.component&&(v=!0),v&&(a.x=this.store.data.origin.x,a.y=this.store.data.origin.y,a.width=u*this.store.data.scale,a.height=d*this.store.data.scale);const g=K(a),y=Zt(t);a.x-=y[3]*o,a.y-=y[0]*o,a.width+=(y[3]+y[1])*o,a.height+=(y[0]+y[2])*o;const p=(r||1920)/a.width;a.width*=p,a.height*=p,bt(a);const b=document.createElement("canvas");if(b.width=a.width,b.height=a.height,b.width>32767||b.height>32767||!navigator.userAgent.includes("Firefox")&&b.height*b.width>268435456||navigator.userAgent.includes("Firefox")&&b.height*b.width>472907776)throw new Error("can not to png, because the size exceeds the browser limit");const m=b.getContext("2d");m.textBaseline="middle",m.scale(p,p);const k=this.store.options.downloadBgTransparent?void 0:this.store.data.background||this.store.styles.background;if(k&&v&&(m.save(),m.fillStyle=k,m.fillRect(0,0,g.width+(y[1]+y[3])*o,g.height+(y[0]+y[2])*o),m.restore()),h)if(v)m.drawImage(this.store.bkImg,y[3]*o||0,y[0]*o||0,g.width,g.height);else{const S=a.x<0?-a.x:0,I=a.y<0?-a.y:0;m.drawImage(this.store.bkImg,S,I,this.canvasRect.width,this.canvasRect.height)}if(k&&!v)if(h){const S=a.x<0?-a.x:0,I=a.y<0?-a.y:0;m.save(),m.fillStyle=k,m.fillRect(S,I,this.canvasRect.width,this.canvasRect.height),m.restore()}else m.save(),m.fillStyle=k,m.fillRect(0,0,l.width+(y[3]+y[1])*o,l.height+(y[0]+y[2])*o),m.restore();h?v?m.translate(-a.x,-a.y):m.translate((c?n.x:-l.x)+y[3]*o||0,(f?n.y:-l.y)+y[0]*o||0):m.translate(-a.x,-a.y);for(const S of this.store.data.pens){if(!Ti(S,this.store)||S.visible==!1)continue;(A=S.onRenderPenRaw)==null||A.call(S,S);const{active:I}=S.calculative;S.calculative.active=!1,S.calculative.img?Ri(m,S):de(m,S,!0),S.calculative.active=I}if(i){b.toBlob(i);return}return b.toDataURL()}activeToPng(t=2,i){return this.pensToPng(this.store.active,t,i)}pensToPng(t=this.store.active,i=2,s){if(t.length===0)return;const r=this.getAllByPens(t);let a=r.map(d=>d.id);const o=Vt(r);if(!isFinite(o.width))throw new Error("can not to png, because width is not finite");const l=K(o),n=Zt(i);o.x-=n[3],o.y-=n[0],o.width+=n[3]+n[1],o.height+=n[0]+n[2],bt(o);const h=(s||o.width)/o.width;o.width*=h,o.height*=h;const c=document.createElement("canvas");if(c.width=o.width,c.height=o.height,c.width>32767||c.height>32767||!navigator.userAgent.includes("Firefox")&&c.height*c.width>268435456||navigator.userAgent.includes("Firefox")&&c.height*c.width>472907776)throw new Error("can not to png, because the size exceeds the browser limit");const f=c.getContext("2d");f.textBaseline="middle",f.scale(h,h);const u=this.store.options.downloadBgTransparent?void 0:this.store.data.background||this.store.styles.background;u&&(f.save(),f.fillStyle=u,f.fillRect(0,0,l.width+(n[3]+n[1]),l.height+(n[0]+n[2])),f.restore()),f.translate(-l.x+n[3],-l.y+n[0]);for(const d of this.store.data.pens)if(a.includes(d.id)){if(!Ti(d,this.store)||d.visible==!1)continue;const{active:v}=d.calculative;d.calculative.active=!1,d.calculative.img?Ri(f,d):de(f,d),d.calculative.active=v}return c.toDataURL()}toggleAnchorMode(){var t;if(this.hotkeyType)this.hotkeyType===ft.AddAnchor&&(this.hotkeyType=ft.None,this.store.hoverAnchor?this.externalElements.style.cursor="vertical-text":this.store.hover&&(this.externalElements.style.cursor="move"));else{if(this.store.options.disableAnchor||(t=this.store.hover)!=null&&t.disableAnchor)return;this.hotkeyType=ft.AddAnchor,this.store.hover&&(this.externalElements.style.cursor="pointer")}this.patchFlags=!0}addAnchorHand(){if(this.store.activeAnchor&&this.store.active&&this.store.active.length===1&&this.store.active[0].type){const t=[K(this.store.active[0],!0)];this.store.activeAnchor.prev?this.store.activeAnchor.next||(this.store.activeAnchor.next={...this.store.activeAnchor.prev},vt(this.store.activeAnchor.next,180,this.store.activeAnchor),this.initLineRect(this.store.active[0]),this.patchFlags=!0):(this.store.activeAnchor.next||(this.store.activeAnchor.next={penId:this.store.activeAnchor.penId,x:this.store.activeAnchor.x+50,y:this.store.activeAnchor.y}),this.store.activeAnchor.prev={...this.store.activeAnchor.next},vt(this.store.activeAnchor.prev,180,this.store.activeAnchor),this.initLineRect(this.store.active[0]),this.patchFlags=!0),this.pushHistory({type:rt.Update,pens:[K(this.store.active[0],!0)],initPens:t})}}removeAnchorHand(){if(this.store.activeAnchor&&this.store.active&&this.store.active.length===1&&this.store.active[0].type){const t=[K(this.store.active[0],!0)];this.hoverType===st.LineAnchorPrev?(this.store.activeAnchor.prev=void 0,this.initLineRect(this.store.active[0]),this.patchFlags=!0):this.hoverType===st.LineAnchorNext?(this.store.activeAnchor.next=void 0,this.initLineRect(this.store.active[0]),this.patchFlags=!0):(this.store.activeAnchor.prev=void 0,this.store.activeAnchor.next=void 0,this.initLineRect(this.store.active[0]),this.patchFlags=!0),this.pushHistory({type:rt.Update,pens:[K(this.store.active[0])],initPens:t})}}toggleAnchorHand(){this.store.active.length===1&&this.store.active[0].type&&this.store.activeAnchor&&(this.store.activeAnchor.prevNextType||(this.store.activeAnchor.prevNextType=pe.Mirror),this.store.activeAnchor.prevNextType=(this.store.activeAnchor.prevNextType+1)%3)}gotoView(t,i){let s=Vt(this.store.data.pens);if(!isFinite(s.width))throw new Error("can not move view, because width is not finite");const r=this.store.data.width||this.store.options.width,a=this.store.data.height||this.store.options.height;r&&a&&(s={x:this.store.data.origin.x,y:this.store.data.origin.y,width:r*this.store.data.scale,height:a*this.store.data.scale}),this.store.data.x=this.canvas.clientWidth/2-t*s.width-s.x,this.store.data.y=this.canvas.clientHeight/2-i*s.height-s.y,this.onMovePens(),this.canvasTemplate.init(),this.canvasImage.init(),this.canvasImageBottom.init(),this.render()}showMagnifier(){this.magnifierCanvas.canvas.style.zIndex="100",this.externalElements.style.zIndex="101",this.magnifierCanvas.magnifier=!0,this.magnifierCanvas.updateDomOffscreen(),this.externalElements.style.cursor="default",this.render()}hideMagnifier(){this.magnifierCanvas.canvas.style.zIndex="5",this.externalElements.style.zIndex="5",this.magnifierCanvas.magnifier=!1,this.externalElements.style.cursor="default",this.magnifierCanvas.render(),this.render()}showFit(){this.store.data.locked=0,this.canvasImage.fitFlag=!0,this.canvasImage.activeFit=void 0,this.canvasImage.currentFit=void 0,this.store.data.fits||(this.store.data.fits=[]),this.store.data.fits.forEach(t=>t.active=!1),this.canvasImage.init(),this.canvasImage.render()}hideFit(){this.canvasImage.fitFlag=!1,this.canvasImage.activeFit=void 0,this.canvasImage.currentFit=void 0,this.canvasImage.init(),this.canvasImage.render()}makeFit(){if(this.dragRect.width<100&&this.dragRect.height<100)return;const t=this.store.data.pens.filter(h=>{if(h.parentId||h.isRuleLine)return!1;if(ee(h.calculative.worldRect,this.dragRect,!0))return h.type===ut.Line&&!this.store.options.dragAllIn?ji(h,this.dragRect):!0});if(!t.length)return;const i=this.parent.getRect(t),s=this.store.data.scale,r=this.store.data.width||this.store.options.width,a=this.store.data.height||this.store.options.height;let o=(Math.floor(i.x)-this.store.data.origin.x)/s/r,l=(Math.floor(i.y)-this.store.data.origin.y)/s/a,n={x:o,y:l,width:(Math.ceil(i.width)+1)/s/r,height:(Math.ceil(i.height)+1)/s/a,children:t.map(h=>h.id),id:lt(),active:!0};n.x<-.1&&(n.x=-.1),n.y<-.1&&(n.y=-.1),n.width>.5?(n.left=!0,n.right=!0,n.leftValue=n.x,n.rightValue=1-(n.x+n.width)):n.x<.5?(n.left=!0,n.leftValue=n.x,n.x>.2&&n.x+n.width>.5&&(n.right=!0,n.rightValue=1-(n.x+n.width))):(n.right=!0,n.rightValue=1-(n.x+n.width)),n.leftValue<.05&&(n.leftValue=0),n.rightValue<.05&&(n.rightValue=0),n.height>.5?(n.top=!0,n.bottom=!0,n.topValue=n.y,n.bottomValue=1-(n.y+n.height)):n.y<.5?(n.top=!0,n.topValue=n.y):(n.bottom=!0,n.bottomValue=1-(n.y+n.height)),n.topValue<.05&&(n.topValue=0),n.bottomValue<.05&&(n.bottomValue=0),this.store.data.fits||(this.store.data.fits=[]),this.store.data.fits.forEach(h=>{h.active=!1}),this.store.data.fits.push(n),this.canvasImage.activeFit=n,this.store.emitter.emit("fit",n),this.canvasImage.init(),this.canvasImage.render()}updateFit(t){const i=this.store.data.scale,s=this.store.data.width||this.store.options.width,r=this.store.data.height||this.store.options.height;let a=(t.x-this.store.data.origin.x)/i/s,o=(t.y-this.store.data.origin.y)/i/r;if(this.canvasImage.currentFit){const l=this.canvasImage.activeFit;if(this.canvasImage.currentFit==="top"){o<-.1&&(o=-.1);let c=o-l.y;if(l.height-=c,l.height<.01){l.height=.01;return}l.y=o}if(this.canvasImage.currentFit==="bottom"&&(o>1.1&&(o=1.1),l.height=o-l.y,l.height<=.01&&(l.height=.01)),this.canvasImage.currentFit==="left"){a<-.1&&(a=-.1);let c=a-l.x;if(l.width-=c,l.width<.01){l.width=.01;return}l.x=a}this.canvasImage.currentFit==="right"&&(a>1.1&&(a=1.1),l.width=a-l.x,l.width<=.01&&(l.width=.01));let n={x:l.x*s*i+this.store.data.origin.x,y:l.y*r*i+this.store.data.origin.y,width:l.width*s*i,height:l.height*r*i};bt(n);const h=this.store.data.pens.filter(c=>{if(c.parentId||c.isRuleLine)return!1;if(ee(c.calculative.worldRect,n,!0))return c.type===ut.Line&&!this.store.options.dragAllIn?ji(c,n):!0});l.left=void 0,l.leftValue=void 0,l.right=void 0,l.rightValue=void 0,l.top=void 0,l.topValue=void 0,l.bottom=void 0,l.bottomValue=void 0,l.width>.5?(l.left=!0,l.right=!0,l.leftValue=l.x,l.rightValue=1-(l.x+l.width)):l.x<.5?(l.left=!0,l.leftValue=l.x,l.x>.2&&l.x+l.width>.5&&(l.right=!0,l.rightValue=1-(l.x+l.width))):(l.right=!0,l.rightValue=1-(l.x+l.width)),Math.abs(l.leftValue)<.05&&(l.leftValue=0),Math.abs(l.rightValue)<.05&&(l.rightValue=0),l.height>.5?(l.top=!0,l.bottom=!0,l.topValue=l.y,l.bottomValue=1-(l.y+l.height)):l.y<.5?(l.top=!0,l.topValue=l.y-0):(l.bottom=!0,l.bottomValue=1-(l.y+l.height)),Math.abs(l.topValue)<.05&&(l.topValue=0),Math.abs(l.bottomValue)<.05&&(l.bottomValue=0),l.children=h.map(c=>c.id),this.store.emitter.emit("fit",l),this.mouseDown.x=t.x,this.mouseDown.y=t.y,this.canvasImage.init(),this.canvasImage.render()}}updateFitRect(t=this.canvasImage.activeFit){const i=this.store.data.width||this.store.options.width,s=this.store.data.height||this.store.options.height;t.left&&(t.leftValue?t.x=Math.abs(t.leftValue)<1?t.leftValue:t.leftValue/i:t.x=0),t.right&&(t.rightValue?t.width=1-(Math.abs(t.rightValue)<1?t.rightValue:t.rightValue/i)-t.x:t.width=1-t.x),t.top&&(t.topValue?t.y=Math.abs(t.topValue)<1?t.topValue:t.topValue/s:t.y=0),t.bottom&&(t.bottomValue?t.height=1-(Math.abs(t.bottomValue)<1?t.bottomValue:t.bottomValue/s)-t.y:t.height=1-t.y),this.canvasImage.init(),this.canvasImage.render()}deleteFit(t=this.canvasImage.activeFit){if(!t)return;const i=this.store.data.fits.findIndex(s=>s.id===t.id);this.store.data.fits.splice(i,1),this.canvasImage.activeFit=void 0,this.canvasImage.init(),this.canvasImage.render(),this.store.emitter.emit("fit",void 0)}calcuActiveFit(){var l;const t=this.store.data.width||this.store.options.width,i=this.store.data.height||this.store.options.height;let s=(this.mouseDown.x-this.store.data.origin.x)/this.store.data.scale/t,r=(this.mouseDown.y-this.store.data.origin.y)/this.store.data.scale/i,a=-1,o=-1;(l=this.store.data.fits)==null||l.forEach((n,h)=>{n.ex=null,n.ey=null,Jt({x:s,y:r},n)&&(a=h),n.active&&(o=h)}),a!==-1&&a!==o?(this.canvasImage.activeFit=this.store.data.fits[a],this.store.data.fits[a].active=!0,o!==-1&&(this.store.data.fits[o].active=!1),this.store.emitter.emit("fit",this.store.data.fits[a])):a===-1&&o!==-1&&(this.store.data.fits[o].active=!1,this.store.emitter.emit("fit",void 0),this.canvasImage.activeFit=null),this.inactive(),this.canvasImage.init(),this.canvasImage.render()}toggleMagnifier(){this.magnifierCanvas.magnifier=!this.magnifierCanvas.magnifier,this.magnifierCanvas.magnifier&&(this.externalElements.style.cursor="default"),this.magnifierCanvas.render(),this.render()}destroy(){var t,i,s,r;switch(this.scroll&&this.scroll.destroy(),(t=this.tooltip)==null||t.destroy(),(i=this.dialog)==null||i.destroy(),(s=this.title)==null||s.destroy(),(r=this.popconfirm)==null||r.destroy(),this.externalElements.removeEventListener("gesturestart",this.onGesturestart),this.externalElements.ondragover=a=>a.preventDefault(),this.externalElements.ondrop=void 0,this.store.options.parentTouch?(this.parentElement.ontouchstart=void 0,this.parentElement.ontouchmove=void 0,this.parentElement.ontouchend=void 0):(this.externalElements.ontouchstart=void 0,this.externalElements.ontouchmove=void 0,this.externalElements.ontouchend=void 0),this.externalElements.onmousedown=void 0,this.externalElements.onmousemove=void 0,this.externalElements.onmouseup=void 0,this.externalElements.onmouseleave=void 0,this.externalElements.ondblclick=void 0,this.store.options.keydown){case ve.Document:document.removeEventListener("keydown",this.onkeydown),document.removeEventListener("keyup",this.onkeyup);break;case ve.Canvas:this.externalElements.removeEventListener("keydown",this.onkeydown),this.externalElements.removeEventListener("keyup",this.onkeyup);break}document.removeEventListener("copy",this.onCopy),document.removeEventListener("cut",this.onCut),document.removeEventListener("paste",this.onPaste),window&&window.removeEventListener("message",this.onMessage),window&&window.removeEventListener("resize",this.onResize),window&&window.removeEventListener("scroll",this.onScroll),this.parentElement.innerHTML=""}}function bl(e,t){const i=t||new Path2D;e.onDestroy||(e.onDestroy=xl,e.onMouseLeave=kl,e.onMouseUp=Rl),e.formId=e.id;let s=e.calculative.borderRadius||0,r=s;const{x:a,y:o,width:l,height:n,ex:h,ey:c}=e.calculative.worldRect,{x:f}=e.calculative.worldTextRect;s<1&&(s=l*s,r=n*r);let u=s<r?s:r;if(l<2*u&&(u=l/2),n<2*u&&(u=n/2),i.moveTo(a+u,o),i.arcTo(h,o,h,c,u),i.arcTo(h,c,a,c,u),i.arcTo(a,c,a,o,u),i.arcTo(a,o,h,o,u),i instanceof Path2D)return i}function xl(e){e.followers.forEach(t=>{let i=e.calculative.canvas.store.pens[t];i.formKey=void 0,i.formValue=void 0,i.formType=void 0,i.formId=void 0})}function kl(e){const t=e.calculative.canvas.store.active;t&&t.length&&t.forEach(i=>{if(e.followers){let s=e.followers.findIndex(r=>r===i.id);if(s!==-1){const r=e.calculative.canvas.store.pens[i.id+Lt];r&&r.calculative&&(ee(r.calculative.worldRect,e.calculative.worldRect,!0)||(e.followers.splice(s,1),delete i.formKey,delete i.formValue,delete i.formType,delete i.formId))}}})}function Rl(e){const t=e.calculative.canvas.store.active;t&&t.length&&t.forEach(i=>{let s=e.calculative.canvas.store.pens[i.id+Lt];if(s||(s=e.calculative.canvas.store.pens[i.id]),s&&s.calculative){let r=K(e.calculative.worldRect);r.x-=1,r.y-=1,r.width+=2,r.height+=2,ee(s.calculative.worldRect,r,!0)&&(e.followers||(e.followers=[]),e.followers.includes(i.id)||e.followers.push(i.id),i.formId=e.id,Al(i))}})}function Vi(e,t){if(e.formId&&e.formKey&&e.formValue){const i=e.calculative.canvas.store.pens[e.formId];i&&(i.formData||(i.formData={}),i.formData[e.formKey]=e[e.formValue])}}function Tl(e){const t=e.calculative.canvas.store.pens[e.formId];for(let i=t.followers.length-1;i>=0;i--){let s=t.followers[i];const r=e.calculative.canvas.store.pens[s];if(r&&r.formId&&r.formKey&&t.formData[r.formKey]){const a=r[r.formValue];let o="";Array.isArray(a)&&(o=[]),e.calculative.canvas.parent.setValue({id:r.id,[r.formValue]:o},{render:!1,doEvent:!1,history:!1})}r||t.followers.splice(i,1)}t.formData={},e.calculative.canvas.parent.render()}const Cl={progress:"progress",cascadeFilterDom:"checked",treeFilterDom:"checked",dateRangePickerDom:"pickerTimes",datePickerDom:"pickerTimes",slider:"value",switch:"checked",inputDom:"text",checkbox:"selectedKeys",radio:"selectKey",rectangle:"text"};function Al(e){e.name==="rectangle"&&!e.input&&!e.dropdownList||(e.formValue=Cl[e.name])}function Sl(e,t){e.onDestroy||(e.onAdd=Pl,e.onDestroy=El,e.onMove=Ll,e.onBeforeValue=Ml,e.onMouseDown=Dl,e.onMouseUp=Ol);const i=t||new Path2D;if(i instanceof Path2D)return i}async function Pl(e){e.sceneId||(e.sceneId=lt())}const es=async(e,t)=>{var l;const i=e.calculative.canvas.store,s=i.data.origin,r=i.data.scale,a=t||e.vId,o=await os(i,a);if(o&&((l=o.pens)!=null&&l.length)){const n=o.scale,h=o.origin;o.pens.forEach(f=>{f.parentId||(f.width=f.width/n,f.height=f.height/n,f.x=(f.x-h.x)/n+(e.x-s.x)/r,f.y=(f.y-h.y)/n+(e.y-s.y)/r),f.p_sceneId||(f.p_sceneId=e.sceneId,f.name!=="sceneContainer"&&(f.p_vId=a))}),e.calculative.canvas.parent.addPens(o.pens,!1,!0)}Bl(e)},Ii=e=>{const t=e.calculative.canvas.parent;Il(e).forEach(s=>{t.canvas.delForce(s)}),t.canvas.canvasTemplate.init(),t.canvas.canvasImage.init(),t.canvas.canvasImageBottom.init(),t.render()},Il=e=>{let t=[];return e.calculative.canvas.parent.store.data.pens.forEach(s=>{s.p_sceneId&&e.sceneId&&s.p_sceneId===e.sceneId&&s.id!==e.id&&(s.calculative.locked=0,s.locked=0,t.push(s))}),t},_l=async e=>{e.calculative.drag&&e.calculative.active&&!(e.locked>1)&&(e.calculative.drag=!1,Ii(e),es(e))};function El(e){Ii(e)}function Ml(e,t){return t.vId&&(Ii(e),es(e,t.vId)),(t.x!==void 0||t.y!==void 0)&&(Ii(e),es(e)),t}function Ll(e){Qa(_l,500,e)}function Dl(e,t){e.calculative.drag=!0}function Ol(e,t){e.calculative.drag=!1}function Bl(e){let t=e.calculative.canvas.store.data.pens,i=t.findIndex(r=>r.id===e.id);if(i<0||i>=t.length)return t;const s=t.splice(i,1)[0];t.push(s)}function Nl(e){const t=new Path2D;if(e.calculative.worldRect,e.calculative.singleton||(e.calculative.singleton={}),e.onDestroy||(e.onDestroy=Fl,e.onResize=rr,e.onRenderPenRaw=zl,e.onMove=ar),!e.calculative.singleton.div){const i=e.html.iframe?document.createElement("iframe"):document.createElement("div");e.html.iframe?(i.srcdoc=e.html.content||"",i.onload=()=>{i.style.overflow="hidden",i.style.border="none",i.scrolling="no",ms(e)}):i.innerHTML=e.html.content||"",i.style.position="absolute",i.style.outline="none",i.style.border="none",i.style.overflow="hidden",i.style.left="-9999px",i.style.top="-9999px",e.calculative.canvas.externalElements.parentElement.appendChild(i),e.calculative.singleton.div=i,rr(e),Ct(e,i)}return ar(e),t}function Fl(e){e.calculative.singleton&&e.calculative.singleton.div&&(e.calculative.singleton.div.remove(),delete e.calculative.singleton.div)}function rr(e){const{width:t,height:i}=window.meta2d.getPenRect(e);e.calculative.singleton._width=t,e.calculative.singleton._height=i,requestAnimationFrame(()=>ms(e))}function ar(e){requestAnimationFrame(()=>{const t=e.calculative.worldRect,i=e.calculative.canvas.store,s=e.calculative.singleton.div;s&&(s.style.width=e.calculative.singleton._width+"px",s.style.height=e.calculative.singleton._height+"px",s.style.left=t.x+i.data.x-1/2*e.calculative.singleton._width+1/2*t.width+"px",s.style.top=t.y+i.data.y-1/2*e.calculative.singleton._height+1/2*t.height+"px",s.style.scale=e.calculative.canvas.store.data.scale)})}function ms(e){var s,r;const t=(s=e.calculative.singleton)==null?void 0:s.div;if(!t)return;const i=e.html.iframe?(r=t.contentDocument)==null?void 0:r.querySelector("body"):t;i&&Fo(e,i)}function zl(e){ms(e)}function jl(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=s+a/2,n=r+o/2,h=Math.min(a,o)/2,c=e.calculative.startAngle??45,f=e.calculative.endAngle??135,u=(c-90)*Math.PI/180,d=(f-90)*Math.PI/180;if(i.moveTo(l,n),i.arc(l,n,h,u,d),i.closePath(),i instanceof Path2D)return i}function Wl(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=s+a/2,n=r+o/2,h=a/2,c=o/2,f=e.calculative.startAngle??0,u=e.calculative.endAngle??180,d=(f-90)*Math.PI/180,v=(u-90)*Math.PI/180;if(i.ellipse(l,n,h,c,0,d,v),i instanceof Path2D)return i}function Hl(e,t){const i=t||new Path2D;if(Vl(e).forEach(({x:r,y:a},o)=>{o?i.lineTo(r,a):i.moveTo(r,a)}),i.closePath(),i instanceof Path2D)return i}function Vl(e){const{x:t,y:i,width:s,height:r}=e.calculative.worldRect,a=t+s/2,o=i+r/2,l=Math.min(s,r)/2,n=Math.max(3,Math.round(Number(e.calculative.sides||e.calculative.sideCount||e.calculative.edgeCount)||5)),h=-Math.PI/2;return new Array(n).fill(0).map((c,f)=>{const u=h+Math.PI*2*f/n;return{x:a+l*Math.cos(u),y:o+l*Math.sin(u)}})}function Ul(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=s+a/2,n=r+o/2,h=Math.min(a,o)/2,c=8,f=Math.PI*2/c;let u=-Math.PI/2;i.moveTo(l+h*Math.cos(u),n+h*Math.sin(u));for(let d=1;d<=c;d++)u+=f,i.lineTo(l+h*Math.cos(u),n+h*Math.sin(u));if(i.closePath(),i instanceof Path2D)return i}function ql(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=e.calculative.topRatio||.5,n=a*l,h=s+(a-n)/2,c=h+n;if(i.moveTo(h,r),i.lineTo(c,r),i.lineTo(s+a,r+o),i.lineTo(s,r+o),i.closePath(),i instanceof Path2D)return i}function $l(e){const t=e.calculative.topRatio||.5;e.anchors=[{id:"0",penId:e.id,x:0+(1-t)/2,y:0},{id:"1",penId:e.id,x:1-(1-t)/2,y:0},{id:"2",penId:e.id,x:0,y:1},{id:"3",penId:e.id,x:1,y:1}]}function Yl(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=e.calculative.barRatio||.3,n=a*l,h=o*l,c=s+a/2,f=r+o/2;if(i.rect(c-n/2,r,n,o),i.rect(s,f-h/2,a,h),i instanceof Path2D)return i}function Xl(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.moveTo(s,r+o),i.lineTo(s,r),i.lineTo(s+a,r+o),i.closePath(),i instanceof Path2D)return i}function Kl(e){e.anchors=[{id:"0",penId:e.id,x:0,y:0},{id:"1",penId:e.id,x:0,y:1},{id:"2",penId:e.id,x:1,y:1}]}function Gl(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=e.calculative.skewRatio||.2,n=a*l;if(i.moveTo(s+n,r),i.lineTo(s+a,r),i.lineTo(s+a-n,r+o),i.lineTo(s,r+o),i.closePath(),i instanceof Path2D)return i}function Jl(e){const t=e.calculative.skewRatio||.2;e.anchors=[{id:"0",penId:e.id,x:t,y:0},{id:"1",penId:e.id,x:1,y:0},{id:"2",penId:e.id,x:0,y:1},{id:"3",penId:e.id,x:1-t,y:1}]}const Rt={};function Ql(e){e.onDestroy||(e.onDestroy=Zl,e.onMove=or,e.onResize=tc,e.onRotate=or,e.onValue=ec,e.onChangeId=ic);const t=new Path2D;if(!e.image)return;const s=e.calculative.canvas.store.id+"-"+e.id;if(!Rt[s]){const r=new Image;r.crossOrigin=e.crossOrigin||e.calculative.canvas.parent.store.options.crossOrigin||"anonymous",r.src=e.image,e.calculative.canvas.parent.store.options.cdn&&!(e.image.startsWith("http")||e.image.startsWith("//")||e.image.startsWith("data:image"))&&(r.src=e.calculative.canvas.parent.store.options.cdn+e.image),Rt[s]=r,r.onload=()=>{var a;Rt[s]===r&&(e.calculative.img=r,e.calculative.imgNaturalWidth=r.naturalWidth||e.iconWidth,e.calculative.imgNaturalHeight=r.naturalHeight||e.iconHeight,(a=e.calculative.canvas.externalElements)==null||a.parentElement.appendChild(r),Je(e,r))}}return e.calculative.patchFlags&&Rt[s]&&Je(e,Rt[s]),t}function Zl(e){const i=e.calculative.canvas.store.id+"-"+e.id;Rt[i]&&(Rt[i].remove(),Rt[i]=void 0)}function or(e){const i=e.calculative.canvas.store.id+"-"+e.id;Rt[i]&&Je(e,Rt[i])}function tc(e){const i=e.calculative.canvas.store.id+"-"+e.id;Rt[i]&&Je(e,Rt[i])}function ec(e){const i=e.calculative.canvas.store.id+"-"+e.id;Rt[i]&&(Je(e,Rt[i]),Rt[i].getAttribute("src")!==e.image&&(Rt[i].src=e.image))}function ic(e,t,i){const s=e.calculative.canvas.store.id;Rt[s+"-"+t]&&(Rt[s+"-"+i]=Rt[s+"-"+t],delete Rt[s+"-"+t])}function Je(e,t){t.style.objectFit=e.imageRatio?"contain":"fill",Ct(e,t)}function sc(e,t){return e.onResize||(e.onResize=ea,e.onValue=rc),me(e,t)}function ea(e){const t=e.anchors.filter(i=>i.flag!==1);ia(e),e.anchors=e.anchors.concat(...t)}function rc(e){ea(e),Le(e)}function ia(e){const t=[],{x:i,y:s,width:r,height:a}=e,o=ac(e),l=5;for(let f=0;f<l;f++){if(f===2)continue;let u=i+r*(f+1)/(l+1),d=s;u<i+o?d=hi(i+o,d+o,u,o,-1):u>i+r-o&&(d=hi(i+r-o,d+o,u,o,-1)),t.push({id:String(t.length),flag:1,penId:e.id,x:(u-i)/r,y:(d-s)/a})}const n=3;for(let f=0;f<n;f++){let u=s+a*(f+1)/(n+1),d=i+r;u<s+o?d=ci(d-o,s+o,u,o):u>s+a-o&&(d=ci(d-o,s+a-o,u,o)),t.push({id:String(t.length),flag:1,penId:e.id,x:(d-i)/r,y:(u-s)/a})}const h=5;for(let f=0;f<h;f++){if(f===2)continue;let u=i+r*(f+1)/(h+1),d=s+a;u<i+o?d=hi(i+o,d-o,u,o):u>i+r-o&&(d=hi(i+r-o,d-o,u,o)),t.push({id:String(t.length),flag:1,penId:e.id,x:(u-i)/r,y:(d-s)/a})}const c=3;for(let f=0;f<c;f++){let u=s+a*(f+1)/(c+1),d=i;u<s+o?d=ci(d+o,s+o,u,o,-1):u>s+a-o&&(d=ci(d+o,s+a-o,u,o,-1)),t.push({id:String(t.length),flag:1,penId:e.id,x:(d-i)/r,y:(u-s)/a})}e.anchors=t}function ac(e){let t=e.calculative.borderRadius||0,i=e.calculative.borderRadius||0;const{width:s,height:r}=e;e.calculative.borderRadius<1&&(t=s*e.calculative.borderRadius,i=r*e.calculative.borderRadius);let a=t<i?t:i;return s<2*a&&(a=s/2),r<2*a&&(a=r/2),a}function ci(e,t,i,s,r=1){return r*Math.sqrt(s**2-(i-t)**2)+e}function hi(e,t,i,s,r=1){return r*Math.sqrt(s**2-(i-e)**2)+t}function oc(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.moveTo(s,r+o),i.lineTo(s+a,r+o),i.closePath(),i instanceof Path2D)return i}function nc(e){const t=[{x:0,y:1},{x:1,y:1}];e.anchors=t.map(({x:i,y:s},r)=>({id:r+"",x:i,y:s,penId:e.id}))}function lc(){return{rectangle:me,square:xa,circle:ka,htmlDom:Nl,svgPath:Pn,diamond:In,triangle:_n,pentagon:Mn,pentagram:Dn,hexagon:Bn,leftArrow:Nn,rightArrow:Fn,twowayArrow:zn,message:jn,cloud:Wn,file:Hn,people:Un,line:sn,iframe:il,video:ll,gif:Ql,mindNode:sc,mindLine:oc,mindNode2:me,form:bl,combine:me,sceneContainer:Sl,sector:jl,chord:Wl,polygon:Hl,octagon:Ul,trapezoid:ql,crosse:Yl,rightTriangle:Xl,parallelogram:Gl}}function cc(){return{triangle:En,pentagon:Ln,pentagram:Xr,mindNode:ia,mindLine:nc,rightTriangle:Kl,trapezoid:$l,parallelogram:Jl}}var kt;(function(e){e[e.Link=0]="Link",e[e.SetProps=1]="SetProps",e[e.StartAnimate=2]="StartAnimate",e[e.PauseAnimate=3]="PauseAnimate",e[e.StopAnimate=4]="StopAnimate",e[e.JS=5]="JS",e[e.GlobalFn=6]="GlobalFn",e[e.Emit=7]="Emit",e[e.StartVideo=8]="StartVideo",e[e.PauseVideo=9]="PauseVideo",e[e.StopVideo=10]="StopVideo",e[e.SendPropData=11]="SendPropData",e[e.SendVarData=12]="SendVarData",e[e.Navigator=13]="Navigator",e[e.Dialog=14]="Dialog",e[e.SendData=15]="SendData",e[e.PostMessage=16]="PostMessage",e[e.PostMessageToParent=17]="PostMessageToParent",e[e.Message=18]="Message"})(kt||(kt={}));class hc{constructor(t){D(this,"parent");D(this,"box");D(this,"boxWidth",320);D(this,"boxHeight",180);D(this,"ratio",this.boxWidth/this.boxHeight);D(this,"padding",5);D(this,"img");D(this,"isShow");D(this,"isDown");D(this,"view");D(this,"timer");D(this,"onMouseDown",t=>{t.preventDefault(),t.stopPropagation(),this.isDown=!0});D(this,"onMouseMove",t=>{if(t.preventDefault(),t.stopPropagation(),this.isDown)try{this.parent.gotoView(t.offsetX/this.box.clientWidth,t.offsetY/this.box.clientHeight)}catch(i){console.warn(i.message),this.isDown=!1}});D(this,"onMouseUp",t=>{t.preventDefault(),t.stopPropagation();try{this.parent.gotoView(t.offsetX/this.box.clientWidth,t.offsetY/this.box.clientHeight)}catch(i){console.warn(i.message)}finally{this.isDown=!1}});D(this,"onWheel",t=>{let i=.015;if(this.parent.store.options.scaleOff)i=this.parent.store.options.scaleOff,t.deltaY>0&&(i=-this.parent.store.options.scaleOff);else if(/mac os /i.test(navigator.userAgent))t.ctrlKey?t.deltaY>0&&(i*=-1):i*=t.wheelDeltaY/240;else{let n=.2;t.deltaY.toString().indexOf(".")!==-1&&(n=.01),t.deltaY>0?i=-n:i=n}let{offsetX:s,offsetY:r}=t;const a=this.parent.store.data.width||this.parent.store.options.width,o=this.parent.store.data.height||this.parent.store.options.height;if(a&&o)s=s/this.boxWidth*a*this.parent.store.data.scale+this.parent.store.data.origin.x+this.parent.store.data.x,r=r/this.boxHeight*o*this.parent.store.data.scale+this.parent.store.data.origin.y+this.parent.store.data.y;else{const l=this.parent.parent.getRect();s=s/this.boxWidth*l.width+l.x+this.parent.store.data.x,r=r/this.boxHeight*l.height+l.y+this.parent.store.data.y}this.parent.scale(this.parent.store.data.scale+i,{x:s,y:r})});var s;this.parent=t,this.box=document.createElement("div"),this.img=new Image,this.view=document.createElement("div"),this.box.appendChild(this.img),this.box.appendChild(this.view),(s=this.parent.externalElements)==null||s.parentElement.appendChild(this.box),this.box.className="meta2d-map",this.box.onmousedown=this.onMouseDown,this.box.onmousemove=this.onMouseMove,this.box.onmouseup=this.onMouseUp,this.box.onwheel=this.onWheel;let i;for(let r=0;r<document.styleSheets.length;r++)document.styleSheets[r].title==="le5le/map"&&(i=document.styleSheets[r]);if(!i){let r=document.createElement("style");r.type="text/css",r.title="le5le.com/map",document.head.appendChild(r),r=document.createElement("style"),r.type="text/css",document.head.appendChild(r),i=r.sheet,i.insertRule(`.meta2d-map{display:flex;width:${this.boxWidth+2*this.padding}px;height:${this.boxHeight+2*this.padding}px;padding:${this.padding}px;background:#f4f4f4;border:1px solid #ffffff;box-shadow: 0px 0px 14px 0px rgba(0,10,38,0.30);border-radius:8px;position:absolute;z-index:9999;right:0;bottom:0;justify-content:center;align-items:center;cursor:default;user-select:none;overflow: hidden;}`),i.insertRule(".meta2d-map img{max-width:100%;max-height:100%;pointer-events: none;}"),i.insertRule(".meta2d-map div{pointer-events: none;border:1px solid #1890ff;position:absolute}")}}show(){this.box.style.display="flex",this.parent.store.data.pens.length?(this.img.style.display="block",this.img.src=this.parent.toPng(0,void 0,!0),this.setView()):this.img.style.display="none",this.isShow=!0}hide(){this.box.style.display="none",this.isShow=!1}setView(){const t=this.parent.store.data;if(t.pens.length){let i=Vt(t.pens);const s=this.parent.store.data.width||this.parent.store.options.width,r=this.parent.store.data.height||this.parent.store.options.height;if(s&&r?i={x:this.parent.store.data.origin.x,y:this.parent.store.data.origin.y,width:s*this.parent.store.data.scale,height:r*this.parent.store.data.scale}:(clearTimeout(this.timer),this.timer=setTimeout(()=>{this.parent.store.bkImg&&(this.img.src=this.parent.toPng(0,void 0,!0))},300)),ye(i,t.x,t.y),i.width/i.height>this.ratio){const f=i.width/this.ratio;i.y-=(f-i.height)/2,i.height=f,bt(i)}else{const f=i.height*this.ratio;i.x-=(f-i.width)/2,i.width=f,bt(i)}const o=this.parent.canvasRect;let l=0,n=0;if(i.x<0)l=-i.x/i.width;else if(i.x+i.width>o.width){let f=0;o.width>i.width&&(f=o.width-i.width),l=(-i.x+f)/i.width}if(i.y<0)n=-i.y/i.height;else if(i.y+i.height>o.height){let f=0;o.height>i.height&&(f=o.height-i.height),n=(-i.y+f)/i.height}const h=o.width>i.width?1:o.width/i.width,c=o.height>i.height?1:o.height/i.height;this.view.style.left=this.padding+l*this.boxWidth+"px",this.view.style.width=h*this.boxWidth+"px",this.view.style.top=this.padding+n*this.boxHeight+"px",this.view.style.height=c*this.boxHeight+"px"}}}function ui(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var sa={exports:{}};(function(e,t){(function(i){e.exports=i()})(function(){return function(){return function i(s,r,a){function o(h,c){if(!r[h]){if(!s[h]){var f=typeof ui=="function"&&ui;if(!c&&f)return f(h,!0);if(l)return l(h,!0);var u=new Error("Cannot find module '"+h+"'");throw u.code="MODULE_NOT_FOUND",u}var d=r[h]={exports:{}};s[h][0].call(d.exports,function(v){return o(s[h][1][v]||v)},d,d.exports,i,s,r,a)}return r[h].exports}for(var l=typeof ui=="function"&&ui,n=0;n<a.length;n++)o(a[n]);return o}}()({1:[function(i,s,r){(function(a,o){(function(){const l=i("events").EventEmitter,n=i("./store"),h=i("./topic-alias-recv"),c=i("./topic-alias-send"),f=i("mqtt-packet"),u=i("./default-message-id-provider"),d=i("readable-stream").Writable,v=i("inherits"),g=i("reinterval"),y=i("rfdc/default"),p=i("./validations"),b=i("xtend"),m=i("debug")("mqttjs:client"),k=a?a.nextTick:function(C){setTimeout(C,0)},A=o.setImmediate||function(C){k(C)},S={keepalive:60,reschedulePings:!0,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:1e3,connectTimeout:3e4,clean:!0,resubscribe:!0},I={0:"",1:"Unacceptable protocol version",2:"Identifier rejected",3:"Server unavailable",4:"Bad username or password",5:"Not authorized",16:"No matching subscribers",17:"No subscription existed",128:"Unspecified error",129:"Malformed Packet",130:"Protocol Error",131:"Implementation specific error",132:"Unsupported Protocol Version",133:"Client Identifier not valid",134:"Bad User Name or Password",135:"Not authorized",136:"Server unavailable",137:"Server busy",138:"Banned",139:"Server shutting down",140:"Bad authentication method",141:"Keep Alive timeout",142:"Session taken over",143:"Topic Filter invalid",144:"Topic Name invalid",145:"Packet identifier in use",146:"Packet Identifier not found",147:"Receive Maximum exceeded",148:"Topic Alias invalid",149:"Packet too large",150:"Message rate too high",151:"Quota exceeded",152:"Administrative action",153:"Payload format invalid",154:"Retain not supported",155:"QoS not supported",156:"Use another server",157:"Server moved",158:"Shared Subscriptions not supported",159:"Connection rate exceeded",160:"Maximum connect time",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"};function E(C,_){let B;_.properties&&(B=_.properties.topicAlias);let j=_.topic.toString();if(j.length===0){if(B===void 0)return new Error("Unregistered Topic Alias");if((j=C.topicAliasSend.getTopicByAlias(B))===void 0)return new Error("Unregistered Topic Alias");_.topic=j}B&&delete _.properties.topicAlias}function z(C,_,B){m("sendPacket :: packet: %O",_),m("sendPacket :: emitting `packetsend`"),C.emit("packetsend",_),m("sendPacket :: writing to stream");const j=f.writeToStream(_,C.stream,C.options);m("sendPacket :: writeToStream result %s",j),!j&&B&&B!==T?(m("sendPacket :: handle events on `drain` once through callback."),C.stream.once("drain",B)):B&&(m("sendPacket :: invoking cb"),B())}function U(C,_,B,j){m("storeAndSend :: store packet with cmd %s to outgoingStore",_.cmd);let X,F=_;if(F.cmd==="publish"&&(F=y(_),X=E(C,F)))return B&&B(X);C.outgoingStore.put(F,function(L){if(L)return B&&B(L);j(),z(C,_,B)})}function T(C){m("nop ::",C)}function R(C,_){let B;const j=this;if(!(this instanceof R))return new R(C,_);for(B in this.options=_||{},S)this.options[B]===void 0?this.options[B]=S[B]:this.options[B]=_[B];m("MqttClient :: options.protocol",_.protocol),m("MqttClient :: options.protocolVersion",_.protocolVersion),m("MqttClient :: options.username",_.username),m("MqttClient :: options.keepalive",_.keepalive),m("MqttClient :: options.reconnectPeriod",_.reconnectPeriod),m("MqttClient :: options.rejectUnauthorized",_.rejectUnauthorized),m("MqttClient :: options.topicAliasMaximum",_.topicAliasMaximum),this.options.clientId=typeof _.clientId=="string"?_.clientId:"mqttjs_"+Math.random().toString(16).substr(2,8),m("MqttClient :: clientId",this.options.clientId),this.options.customHandleAcks=_.protocolVersion===5&&_.customHandleAcks?_.customHandleAcks:function(){arguments[3](0)},this.streamBuilder=C,this.messageIdProvider=this.options.messageIdProvider===void 0?new u:this.options.messageIdProvider,this.outgoingStore=_.outgoingStore||new n,this.incomingStore=_.incomingStore||new n,this.queueQoSZero=_.queueQoSZero===void 0||_.queueQoSZero,this._resubscribeTopics={},this.messageIdToTopic={},this.pingTimer=null,this.connected=!1,this.disconnecting=!1,this.queue=[],this.connackTimer=null,this.reconnectTimer=null,this._storeProcessing=!1,this._packetIdsDuringStoreProcessing={},this._storeProcessingQueue=[],this.outgoing={},this._firstConnection=!0,_.topicAliasMaximum>0&&(_.topicAliasMaximum>65535?m("MqttClient :: options.topicAliasMaximum is out of range"):this.topicAliasRecv=new h(_.topicAliasMaximum)),this.on("connect",function(){const X=this.queue;m("connect :: sending queued packets"),function F(){const L=X.shift();m("deliver :: entry %o",L);let N=null;if(!L)return void j._resubscribe();N=L.packet,m("deliver :: call _sendPacket for %o",N);let W=!0;N.messageId&&N.messageId!==0&&(j.messageIdProvider.register(N.messageId)||(W=!1)),W?j._sendPacket(N,function(O){L.cb&&L.cb(O),F()}):(m("messageId: %d has already used. The message is skipped and removed.",N.messageId),F())}()}),this.on("close",function(){m("close :: connected set to `false`"),this.connected=!1,m("close :: clearing connackTimer"),clearTimeout(this.connackTimer),m("close :: clearing ping timer"),j.pingTimer!==null&&(j.pingTimer.clear(),j.pingTimer=null),this.topicAliasRecv&&this.topicAliasRecv.clear(),m("close :: calling _setupReconnect"),this._setupReconnect()}),l.call(this),m("MqttClient :: setting up stream"),this._setupStream()}v(R,l),R.prototype._setupStream=function(){const C=this,_=new d,B=f.parser(this.options);let j=null;const X=[];function F(){if(X.length)k(L);else{const W=j;j=null,W()}}function L(){m("work :: getting next packet in queue");const W=X.shift();if(W)m("work :: packet pulled from queue"),C._handlePacket(W,F);else{m("work :: no packets in queue");const O=j;j=null,m("work :: done flag is %s",!!O),O&&O()}}m("_setupStream :: calling method to clear reconnect"),this._clearReconnect(),m("_setupStream :: using streamBuilder provided to client to create stream"),this.stream=this.streamBuilder(this),B.on("packet",function(W){m("parser :: on packet push to packets array."),X.push(W)}),_._write=function(W,O,q){j=q,m("writable stream :: parsing buffer"),B.parse(W),L()},m("_setupStream :: pipe stream to writable stream"),this.stream.pipe(_),this.stream.on("error",function(W){m("streamErrorHandler :: error",W.message),W.code?(m("streamErrorHandler :: emitting error"),C.emit("error",W)):T(W)}),this.stream.on("close",function(){var W;m("(%s)stream :: on close",C.options.clientId),(W=C.outgoing)&&(m("flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"),Object.keys(W).forEach(function(O){W[O].volatile&&typeof W[O].cb=="function"&&(W[O].cb(new Error("Connection closed")),delete W[O])})),m("stream: emit close to MqttClient"),C.emit("close")}),m("_setupStream: sending packet `connect`");const N=Object.create(this.options);if(N.cmd="connect",this.topicAliasRecv&&(N.properties||(N.properties={}),this.topicAliasRecv&&(N.properties.topicAliasMaximum=this.topicAliasRecv.max)),z(this,N),B.on("error",this.emit.bind(this,"error")),this.options.properties){if(!this.options.properties.authenticationMethod&&this.options.properties.authenticationData)return C.end(()=>this.emit("error",new Error("Packet has no Authentication Method"))),this;this.options.properties.authenticationMethod&&this.options.authPacket&&typeof this.options.authPacket=="object"&&z(this,b({cmd:"auth",reasonCode:0},this.options.authPacket))}this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout(function(){m("!!connectTimeout hit!! Calling _cleanUp with force `true`"),C._cleanUp(!0)},this.options.connectTimeout)},R.prototype._handlePacket=function(C,_){const B=this.options;if(B.protocolVersion===5&&B.properties&&B.properties.maximumPacketSize&&B.properties.maximumPacketSize<C.length)return this.emit("error",new Error("exceeding packets size "+C.cmd)),this.end({reasonCode:149,properties:{reasonString:"Maximum packet size was exceeded"}}),this;switch(m("_handlePacket :: emitting packetreceive"),this.emit("packetreceive",C),C.cmd){case"publish":this._handlePublish(C,_);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":this._handleAck(C),_();break;case"pubrel":this._handlePubrel(C,_);break;case"connack":this._handleConnack(C),_();break;case"auth":this._handleAuth(C),_();break;case"pingresp":this._handlePingresp(C),_();break;case"disconnect":this._handleDisconnect(C),_()}},R.prototype._checkDisconnecting=function(C){return this.disconnecting&&(C&&C!==T?C(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting},R.prototype.publish=function(C,_,B,j){m("publish :: message `%s` to topic `%s`",_,C);const X=this.options;if(typeof B=="function"&&(j=B,B=null),B=b({qos:0,retain:!1,dup:!1},B),this._checkDisconnecting(j))return this;const F=this,L=function(){let N=0;if((B.qos===1||B.qos===2)&&(N=F._nextId())===null)return m("No messageId left"),!1;const W={cmd:"publish",topic:C,payload:_,qos:B.qos,retain:B.retain,messageId:N,dup:B.dup};switch(X.protocolVersion===5&&(W.properties=B.properties),m("publish :: qos",B.qos),B.qos){case 1:case 2:F.outgoing[W.messageId]={volatile:!1,cb:j||T},m("MqttClient:publish: packet cmd: %s",W.cmd),F._sendPacket(W,void 0,B.cbStorePut);break;default:m("MqttClient:publish: packet cmd: %s",W.cmd),F._sendPacket(W,j,B.cbStorePut)}return!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!L())&&this._storeProcessingQueue.push({invoke:L,cbStorePut:B.cbStorePut,callback:j}),this},R.prototype.subscribe=function(){const C=this,_=new Array(arguments.length);for(let $=0;$<arguments.length;$++)_[$]=arguments[$];const B=[];let j=_.shift();const X=j.resubscribe;let F=_.pop()||T,L=_.pop();const N=this.options.protocolVersion;delete j.resubscribe,typeof j=="string"&&(j=[j]),typeof F!="function"&&(L=F,F=T);const W=p.validateTopics(j);if(W!==null)return A(F,new Error("Invalid topic "+W)),this;if(this._checkDisconnecting(F))return m("subscribe: discconecting true"),this;const O={qos:0};if(N===5&&(O.nl=!1,O.rap=!1,O.rh=0),L=b(O,L),Array.isArray(j)?j.forEach(function($){if(m("subscribe: array topic %s",$),!Object.prototype.hasOwnProperty.call(C._resubscribeTopics,$)||C._resubscribeTopics[$].qos<L.qos||X){const Y={topic:$,qos:L.qos};N===5&&(Y.nl=L.nl,Y.rap=L.rap,Y.rh=L.rh,Y.properties=L.properties),m("subscribe: pushing topic `%s` and qos `%s` to subs list",Y.topic,Y.qos),B.push(Y)}}):Object.keys(j).forEach(function($){if(m("subscribe: object topic %s",$),!Object.prototype.hasOwnProperty.call(C._resubscribeTopics,$)||C._resubscribeTopics[$].qos<j[$].qos||X){const Y={topic:$,qos:j[$].qos};N===5&&(Y.nl=j[$].nl,Y.rap=j[$].rap,Y.rh=j[$].rh,Y.properties=L.properties),m("subscribe: pushing `%s` to subs list",Y),B.push(Y)}}),!B.length)return F(null,[]),this;const q=function(){const $=C._nextId();if($===null)return m("No messageId left"),!1;const Y={cmd:"subscribe",subscriptions:B,qos:1,retain:!1,dup:!1,messageId:$};if(L.properties&&(Y.properties=L.properties),C.options.resubscribe){m("subscribe :: resubscribe true");const Z=[];B.forEach(function(J){if(C.options.reconnectPeriod>0){const Q={qos:J.qos};N===5&&(Q.nl=J.nl||!1,Q.rap=J.rap||!1,Q.rh=J.rh||0,Q.properties=J.properties),C._resubscribeTopics[J.topic]=Q,Z.push(J.topic)}}),C.messageIdToTopic[Y.messageId]=Z}return C.outgoing[Y.messageId]={volatile:!0,cb:function(Z,J){if(!Z){const Q=J.granted;for(let w=0;w<Q.length;w+=1)B[w].qos=Q[w]}F(Z,B)}},m("subscribe :: call _sendPacket"),C._sendPacket(Y),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!q())&&this._storeProcessingQueue.push({invoke:q,callback:F}),this},R.prototype.unsubscribe=function(){const C=this,_=new Array(arguments.length);for(let N=0;N<arguments.length;N++)_[N]=arguments[N];let B=_.shift(),j=_.pop()||T,X=_.pop();typeof B=="string"&&(B=[B]),typeof j!="function"&&(X=j,j=T);const F=p.validateTopics(B);if(F!==null)return A(j,new Error("Invalid topic "+F)),this;if(C._checkDisconnecting(j))return this;const L=function(){const N=C._nextId();if(N===null)return m("No messageId left"),!1;const W={cmd:"unsubscribe",qos:1,messageId:N};return typeof B=="string"?W.unsubscriptions=[B]:Array.isArray(B)&&(W.unsubscriptions=B),C.options.resubscribe&&W.unsubscriptions.forEach(function(O){delete C._resubscribeTopics[O]}),typeof X=="object"&&X.properties&&(W.properties=X.properties),C.outgoing[W.messageId]={volatile:!0,cb:j},m("unsubscribe: call _sendPacket"),C._sendPacket(W),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!L())&&this._storeProcessingQueue.push({invoke:L,callback:j}),this},R.prototype.end=function(C,_,B){const j=this;function X(){m("end :: (%s) :: finish :: calling _cleanUp with force %s",j.options.clientId,C),j._cleanUp(C,()=>{m("end :: finish :: calling process.nextTick on closeStores"),k((function(){m("end :: closeStores: closing incoming and outgoing stores"),j.disconnected=!0,j.incomingStore.close(function(F){j.outgoingStore.close(function(L){if(m("end :: closeStores: emitting end"),j.emit("end"),B){const N=F||L;m("end :: closeStores: invoking callback with args"),B(N)}})}),j._deferredReconnect&&j._deferredReconnect()}).bind(j))},_)}return m("end :: (%s)",this.options.clientId),C!=null&&typeof C=="boolean"||(B=_||T,_=C,C=!1,typeof _!="object"&&(B=_,_=null,typeof B!="function"&&(B=T))),typeof _!="object"&&(B=_,_=null),m("end :: cb? %s",!!B),B=B||T,this.disconnecting?(B(),this):(this._clearReconnect(),this.disconnecting=!0,!C&&Object.keys(this.outgoing).length>0?(m("end :: (%s) :: calling finish in 10ms once outgoing is empty",j.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,X,10))):(m("end :: (%s) :: immediately calling finish",j.options.clientId),X()),this)},R.prototype.removeOutgoingMessage=function(C){const _=this.outgoing[C]?this.outgoing[C].cb:null;return delete this.outgoing[C],this.outgoingStore.del({messageId:C},function(){_(new Error("Message removed"))}),this},R.prototype.reconnect=function(C){m("client reconnect");const _=this,B=function(){C?(_.options.incomingStore=C.incomingStore,_.options.outgoingStore=C.outgoingStore):(_.options.incomingStore=null,_.options.outgoingStore=null),_.incomingStore=_.options.incomingStore||new n,_.outgoingStore=_.options.outgoingStore||new n,_.disconnecting=!1,_.disconnected=!1,_._deferredReconnect=null,_._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=B:B(),this},R.prototype._reconnect=function(){m("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end(()=>{this._setupStream()}),m("client already connected. disconnecting first.")):(m("_reconnect: calling _setupStream"),this._setupStream())},R.prototype._setupReconnect=function(){const C=this;!C.disconnecting&&!C.reconnectTimer&&C.options.reconnectPeriod>0?(this.reconnecting||(m("_setupReconnect :: emit `offline` state"),this.emit("offline"),m("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),m("_setupReconnect :: setting reconnectTimer for %d ms",C.options.reconnectPeriod),C.reconnectTimer=setInterval(function(){m("reconnectTimer :: reconnect triggered!"),C._reconnect()},C.options.reconnectPeriod)):m("_setupReconnect :: doing nothing...")},R.prototype._clearReconnect=function(){m("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},R.prototype._cleanUp=function(C,_){const B=arguments[2];if(_&&(m("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",_)),m("_cleanUp :: forced? %s",C),C)this.options.reconnectPeriod===0&&this.options.clean&&(j=this.outgoing)&&(m("flush: queue exists? %b",!!j),Object.keys(j).forEach(function(X){typeof j[X].cb=="function"&&(j[X].cb(new Error("Connection closed")),delete j[X])})),m("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{const X=b({cmd:"disconnect"},B);m("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(X,A.bind(null,this.stream.end.bind(this.stream)))}var j;this.disconnecting||(m("_cleanUp :: client not disconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),this.pingTimer!==null&&(m("_cleanUp :: clearing pingTimer"),this.pingTimer.clear(),this.pingTimer=null),_&&!this.connected&&(m("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",_),_())},R.prototype._sendPacket=function(C,_,B){m("_sendPacket :: (%s) :: start",this.options.clientId),B=B||T,_=_||T;const j=function(X,F){if(X.options.protocolVersion===5&&F.cmd==="publish"){let L;F.properties&&(L=F.properties.topicAlias);const N=F.topic.toString();if(X.topicAliasSend)if(L){if(N.length!==0&&(m("applyTopicAlias :: register topic: %s - alias: %d",N,L),!X.topicAliasSend.put(N,L)))return m("applyTopicAlias :: error out of range. topic: %s - alias: %d",N,L),new Error("Sending Topic Alias out of range")}else N.length!==0&&(X.options.autoAssignTopicAlias?(L=X.topicAliasSend.getAliasByTopic(N))?(F.topic="",F.properties={...F.properties,topicAlias:L},m("applyTopicAlias :: auto assign(use) topic: %s - alias: %d",N,L)):(L=X.topicAliasSend.getLruAlias(),X.topicAliasSend.put(N,L),F.properties={...F.properties,topicAlias:L},m("applyTopicAlias :: auto assign topic: %s - alias: %d",N,L)):X.options.autoUseTopicAlias&&(L=X.topicAliasSend.getAliasByTopic(N))&&(F.topic="",F.properties={...F.properties,topicAlias:L},m("applyTopicAlias :: auto use topic: %s - alias: %d",N,L)));else if(L)return m("applyTopicAlias :: error out of range. topic: %s - alias: %d",N,L),new Error("Sending Topic Alias out of range")}}(this,C);if(j)_(j);else{if(!this.connected)return C.cmd==="auth"?(this._shiftPingInterval(),void z(this,C,_)):(m("_sendPacket :: client not connected. Storing packet offline."),void this._storePacket(C,_,B));switch(this._shiftPingInterval(),C.cmd){case"publish":break;case"pubrel":return void U(this,C,_,B);default:return void z(this,C,_)}switch(C.qos){case 2:case 1:U(this,C,_,B);break;case 0:default:z(this,C,_)}m("_sendPacket :: (%s) :: end",this.options.clientId)}},R.prototype._storePacket=function(C,_,B){m("_storePacket :: packet: %o",C),m("_storePacket :: cb? %s",!!_),B=B||T;let j=C;if(j.cmd==="publish"){const X=E(this,j=y(C));if(X)return _&&_(X)}(j.qos||0)===0&&this.queueQoSZero||j.cmd!=="publish"?this.queue.push({packet:j,cb:_}):j.qos>0?(_=this.outgoing[j.messageId]?this.outgoing[j.messageId].cb:null,this.outgoingStore.put(j,function(X){if(X)return _&&_(X);B()})):_&&_(new Error("No connection to broker"))},R.prototype._setupPingTimer=function(){m("_setupPingTimer :: keepalive %d (seconds)",this.options.keepalive);const C=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=g(function(){C._checkPing()},1e3*this.options.keepalive))},R.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},R.prototype._checkPing=function(){m("_checkPing :: checking ping..."),this.pingResp?(m("_checkPing :: ping response received. Clearing flag and sending `pingreq`"),this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):(m("_checkPing :: calling _cleanUp with force true"),this._cleanUp(!0))},R.prototype._handlePingresp=function(){this.pingResp=!0},R.prototype._handleConnack=function(C){m("_handleConnack");const _=this.options,B=_.protocolVersion===5?C.reasonCode:C.returnCode;if(clearTimeout(this.connackTimer),delete this.topicAliasSend,C.properties){if(C.properties.topicAliasMaximum){if(C.properties.topicAliasMaximum>65535)return void this.emit("error",new Error("topicAliasMaximum from broker is out of range"));C.properties.topicAliasMaximum>0&&(this.topicAliasSend=new c(C.properties.topicAliasMaximum))}C.properties.serverKeepAlive&&_.keepalive&&(_.keepalive=C.properties.serverKeepAlive,this._shiftPingInterval()),C.properties.maximumPacketSize&&(_.properties||(_.properties={}),_.properties.maximumPacketSize=C.properties.maximumPacketSize)}if(B===0)this.reconnecting=!1,this._onConnect(C);else if(B>0){const j=new Error("Connection refused: "+I[B]);j.code=B,this.emit("error",j)}},R.prototype._handleAuth=function(C){const _=this.options.protocolVersion,B=_===5?C.reasonCode:C.returnCode;if(_!==5){const X=new Error("Protocol error: Auth packets are only supported in MQTT 5. Your version:"+_);return X.code=B,void this.emit("error",X)}const j=this;this.handleAuth(C,function(X,F){if(X)j.emit("error",X);else if(B===24)j.reconnecting=!1,j._sendPacket(F);else{const L=new Error("Connection refused: "+I[B]);X.code=B,j.emit("error",L)}})},R.prototype.handleAuth=function(C,_){_()},R.prototype._handlePublish=function(C,_){m("_handlePublish: packet %o",C),_=_!==void 0?_:T;let B=C.topic.toString();const j=C.payload,X=C.qos,F=C.messageId,L=this,N=this.options,W=[0,16,128,131,135,144,145,151,153];if(this.options.protocolVersion===5){let O;if(C.properties&&(O=C.properties.topicAlias),O!==void 0)if(B.length===0){if(!(O>0&&O<=65535))return m("_handlePublish :: topic alias out of range. alias: %d",O),void this.emit("error",new Error("Received Topic Alias is out of range"));{const q=this.topicAliasRecv.getTopicByAlias(O);if(!q)return m("_handlePublish :: unregistered topic alias. alias: %d",O),void this.emit("error",new Error("Received unregistered Topic Alias"));m("_handlePublish :: topic complemented by alias. topic: %s - alias: %d",B=q,O)}}else{if(!this.topicAliasRecv.put(B,O))return m("_handlePublish :: topic alias out of range. alias: %d",O),void this.emit("error",new Error("Received Topic Alias is out of range"));m("_handlePublish :: registered topic: %s - alias: %d",B,O)}}switch(m("_handlePublish: qos %d",X),X){case 2:N.customHandleAcks(B,j,C,function(O,q){return O instanceof Error||(q=O,O=null),O?L.emit("error",O):W.indexOf(q)===-1?L.emit("error",new Error("Wrong reason code for pubrec")):void(q?L._sendPacket({cmd:"pubrec",messageId:F,reasonCode:q},_):L.incomingStore.put(C,function(){L._sendPacket({cmd:"pubrec",messageId:F},_)}))});break;case 1:N.customHandleAcks(B,j,C,function(O,q){return O instanceof Error||(q=O,O=null),O?L.emit("error",O):W.indexOf(q)===-1?L.emit("error",new Error("Wrong reason code for puback")):(q||L.emit("message",B,j,C),void L.handleMessage(C,function($){if($)return _&&_($);L._sendPacket({cmd:"puback",messageId:F,reasonCode:q},_)}))});break;case 0:this.emit("message",B,j,C),this.handleMessage(C,_);break;default:m("_handlePublish: unknown QoS. Doing nothing.")}},R.prototype.handleMessage=function(C,_){_()},R.prototype._handleAck=function(C){const _=C.messageId,B=C.cmd;let j=null;const X=this.outgoing[_]?this.outgoing[_].cb:null,F=this;let L;if(X){switch(m("_handleAck :: packet type",B),B){case"pubcomp":case"puback":{const N=C.reasonCode;N&&N>0&&N!==16&&((L=new Error("Publish error: "+I[N])).code=N,X(L,C)),delete this.outgoing[_],this.outgoingStore.del(C,X),this.messageIdProvider.deallocate(_),this._invokeStoreProcessingQueue();break}case"pubrec":{j={cmd:"pubrel",qos:2,messageId:_};const N=C.reasonCode;N&&N>0&&N!==16?((L=new Error("Publish error: "+I[N])).code=N,X(L,C)):this._sendPacket(j);break}case"suback":delete this.outgoing[_],this.messageIdProvider.deallocate(_);for(let N=0;N<C.granted.length;N++)if(128&C.granted[N]){const W=this.messageIdToTopic[_];W&&W.forEach(function(O){delete F._resubscribeTopics[O]})}this._invokeStoreProcessingQueue(),X(null,C);break;case"unsuback":delete this.outgoing[_],this.messageIdProvider.deallocate(_),this._invokeStoreProcessingQueue(),X(null);break;default:F.emit("error",new Error("unrecognized packet type"))}this.disconnecting&&Object.keys(this.outgoing).length===0&&this.emit("outgoingEmpty")}else m("_handleAck :: Server sent an ack in error. Ignoring.")},R.prototype._handlePubrel=function(C,_){m("handling pubrel packet"),_=_!==void 0?_:T;const B=this,j={cmd:"pubcomp",messageId:C.messageId};B.incomingStore.get(C,function(X,F){X?B._sendPacket(j,_):(B.emit("message",F.topic,F.payload,F),B.handleMessage(F,function(L){if(L)return _(L);B.incomingStore.del(F,T),B._sendPacket(j,_)}))})},R.prototype._handleDisconnect=function(C){this.emit("disconnect",C)},R.prototype._nextId=function(){return this.messageIdProvider.allocate()},R.prototype.getLastMessageId=function(){return this.messageIdProvider.getLastAllocated()},R.prototype._resubscribe=function(){m("_resubscribe");const C=Object.keys(this._resubscribeTopics);if(!this._firstConnection&&(this.options.clean||this.options.protocolVersion===5&&!this.connackPacket.sessionPresent)&&C.length>0)if(this.options.resubscribe)if(this.options.protocolVersion===5){m("_resubscribe: protocolVersion 5");for(let _=0;_<C.length;_++){const B={};B[C[_]]=this._resubscribeTopics[C[_]],B.resubscribe=!0,this.subscribe(B,{properties:B[C[_]].properties})}}else this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics);else this._resubscribeTopics={};this._firstConnection=!1},R.prototype._onConnect=function(C){if(this.disconnected)return void this.emit("connect",C);const _=this;this.connackPacket=C,this.messageIdProvider.clear(),this._setupPingTimer(),this.connected=!0,function B(){let j=_.outgoingStore.createStream();function X(){_._storeProcessing=!1,_._packetIdsDuringStoreProcessing={}}function F(){j.destroy(),j=null,_._flushStoreProcessingQueue(),X()}_.once("close",F),j.on("error",function(L){X(),_._flushStoreProcessingQueue(),_.removeListener("close",F),_.emit("error",L)}),j.on("end",function(){let L=!0;for(const N in _._packetIdsDuringStoreProcessing)if(!_._packetIdsDuringStoreProcessing[N]){L=!1;break}L?(X(),_.removeListener("close",F),_._invokeAllStoreProcessingQueue(),_.emit("connect",C)):B()}),function L(){if(!j)return;_._storeProcessing=!0;const N=j.read(1);let W;N?_._packetIdsDuringStoreProcessing[N.messageId]?L():_.disconnecting||_.reconnectTimer?j.destroy&&j.destroy():(W=_.outgoing[N.messageId]?_.outgoing[N.messageId].cb:null,_.outgoing[N.messageId]={volatile:!1,cb:function(O,q){W&&W(O,q),L()}},_._packetIdsDuringStoreProcessing[N.messageId]=!0,_.messageIdProvider.register(N.messageId)?_._sendPacket(N):m("messageId: %d has already used.",N.messageId)):j.once("readable",L)}()}()},R.prototype._invokeStoreProcessingQueue=function(){if(this._storeProcessingQueue.length>0){const C=this._storeProcessingQueue[0];if(C&&C.invoke())return this._storeProcessingQueue.shift(),!0}return!1},R.prototype._invokeAllStoreProcessingQueue=function(){for(;this._invokeStoreProcessingQueue(););},R.prototype._flushStoreProcessingQueue=function(){for(const C of this._storeProcessingQueue)C.cbStorePut&&C.cbStorePut(new Error("Connection closed")),C.callback&&C.callback(new Error("Connection closed"));this._storeProcessingQueue.splice(0)},s.exports=R}).call(this)}).call(this,i("_process"),typeof Ut<"u"?Ut:typeof self<"u"?self:typeof window<"u"?window:{})},{"./default-message-id-provider":7,"./store":8,"./topic-alias-recv":9,"./topic-alias-send":10,"./validations":11,_process:50,debug:18,events:22,inherits:24,"mqtt-packet":40,"readable-stream":69,reinterval:70,"rfdc/default":71,xtend:81}],2:[function(i,s,r){const{Buffer:a}=i("buffer"),o=i("readable-stream").Transform,l=i("duplexify");let n,h,c,f=!1;s.exports=function(u,d){if(d.hostname=d.hostname||d.host,!d.hostname)throw new Error("Could not determine host. Specify host manually.");const v=d.protocolId==="MQIsdp"&&d.protocolVersion===3?"mqttv3.1":"mqtt";(function(y){y.hostname||(y.hostname="localhost"),y.path||(y.path="/"),y.wsOptions||(y.wsOptions={})})(d);const g=function(y,p){const b=y.protocol==="alis"?"wss":"ws";let m=b+"://"+y.hostname+y.path;return y.port&&y.port!==80&&y.port!==443&&(m=b+"://"+y.hostname+":"+y.port+y.path),typeof y.transformWsUrl=="function"&&(m=y.transformWsUrl(m,y,p)),m}(d,u);return(n=d.my).connectSocket({url:g,protocols:v}),h=function(){const y=new o;return y._write=function(p,b,m){n.sendSocketMessage({data:p.buffer,success:function(){m()},fail:function(){m(new Error)}})},y._flush=function(p){n.closeSocket({success:function(){p()}})},y}(),c=l.obj(),f||(f=!0,n.onSocketOpen(function(){c.setReadable(h),c.setWritable(h),c.emit("connect")}),n.onSocketMessage(function(y){if(typeof y.data=="string"){const p=a.from(y.data,"base64");h.push(p)}else{const p=new FileReader;p.addEventListener("load",function(){let b=p.result;b=b instanceof ArrayBuffer?a.from(b):a.from(b,"utf8"),h.push(b)}),p.readAsArrayBuffer(y.data)}}),n.onSocketClose(function(){c.end(),c.destroy()}),n.onSocketError(function(y){c.destroy(y)})),c}},{buffer:17,duplexify:20,"readable-stream":69}],3:[function(i,s,r){const a=i("net"),o=i("debug")("mqttjs:tcp");s.exports=function(l,n){n.port=n.port||1883,n.hostname=n.hostname||n.host||"localhost";const h=n.port,c=n.hostname;return o("port %d and host %s",h,c),a.createConnection(h,c)}},{debug:18,net:16}],4:[function(i,s,r){const a=i("tls"),o=i("net"),l=i("debug")("mqttjs:tls");s.exports=function(n,h){h.port=h.port||8883,h.host=h.hostname||h.host||"localhost",o.isIP(h.host)===0&&(h.servername=h.host),h.rejectUnauthorized=h.rejectUnauthorized!==!1,delete h.path,l("port %d host %s rejectUnauthorized %b",h.port,h.host,h.rejectUnauthorized);const c=a.connect(h);function f(u){h.rejectUnauthorized&&n.emit("error",u),c.end()}return c.on("secureConnect",function(){h.rejectUnauthorized&&!c.authorized?c.emit("error",new Error("TLS not authorized")):c.removeListener("error",f)}),c.on("error",f),c}},{debug:18,net:16,tls:16}],5:[function(i,s,r){(function(a){(function(){const{Buffer:o}=i("buffer"),l=i("ws"),n=i("debug")("mqttjs:ws"),h=i("duplexify"),c=i("readable-stream").Transform,f=["rejectUnauthorized","ca","cert","key","pfx","passphrase"],u=a!==void 0&&a.title==="browser"||typeof __webpack_require__=="function";function d(g,y){let p=g.protocol+"://"+g.hostname+":"+g.port+g.path;return typeof g.transformWsUrl=="function"&&(p=g.transformWsUrl(p,g,y)),p}function v(g){const y=g;return g.hostname||(y.hostname="localhost"),g.port||(g.protocol==="wss"?y.port=443:y.port=80),g.path||(y.path="/"),g.wsOptions||(y.wsOptions={}),u||g.protocol!=="wss"||f.forEach(function(p){Object.prototype.hasOwnProperty.call(g,p)&&!Object.prototype.hasOwnProperty.call(g.wsOptions,p)&&(y.wsOptions[p]=g[p])}),y}s.exports=u?function(g,y){let p;n("browserStreamBuilder");const b=function(C){const _=v(C);if(_.hostname||(_.hostname=_.host),!_.hostname){if(typeof document>"u")throw new Error("Could not determine host. Specify host manually.");const B=new URL(document.URL);_.hostname=B.hostname,_.port||(_.port=B.port)}return _.objectMode===void 0&&(_.objectMode=!(_.binary===!0||_.binary===void 0)),_}(y).browserBufferSize||524288,m=y.browserBufferTimeout||1e3,k=!y.objectMode,A=function(C,_){const B=_.protocolId==="MQIsdp"&&_.protocolVersion===3?"mqttv3.1":"mqtt",j=d(_,C),X=new WebSocket(j,[B]);return X.binaryType="arraybuffer",X}(g,y),S=function(C,_,B){const j=new c({objectModeMode:C.objectMode});return j._write=_,j._flush=B,j}(y,function C(_,B,j){A.bufferedAmount>b&&setTimeout(C,m,_,B,j),k&&typeof _=="string"&&(_=o.from(_,"utf8"));try{A.send(_)}catch(X){return j(X)}j()},function(C){A.close(),C()});y.objectMode||(S._writev=R),S.on("close",()=>{A.close()});const I=A.addEventListener!==void 0;function E(){p.setReadable(S),p.setWritable(S),p.emit("connect")}function z(){p.end(),p.destroy()}function U(C){p.destroy(C)}function T(C){let _=C.data;_=_ instanceof ArrayBuffer?o.from(_):o.from(_,"utf8"),S.push(_)}function R(C,_){const B=new Array(C.length);for(let j=0;j<C.length;j++)typeof C[j].chunk=="string"?B[j]=o.from(C[j],"utf8"):B[j]=C[j].chunk;this._write(o.concat(B),"binary",_)}return A.readyState===A.OPEN?p=S:(p=p=h(void 0,void 0,y),y.objectMode||(p._writev=R),I?A.addEventListener("open",E):A.onopen=E),p.socket=A,I?(A.addEventListener("close",z),A.addEventListener("error",U),A.addEventListener("message",T)):(A.onclose=z,A.onerror=U,A.onmessage=T),p}:function(g,y){n("streamBuilder");const p=v(y),b=d(p,g),m=function(A,S,I){n("createWebSocket"),n("protocol: "+I.protocolId+" "+I.protocolVersion);const E=I.protocolId==="MQIsdp"&&I.protocolVersion===3?"mqttv3.1":"mqtt";return n("creating new Websocket for url: "+S+" and protocol: "+E),new l(S,[E],I.wsOptions)}(0,b,p),k=l.createWebSocketStream(m,p.wsOptions);return k.url=b,m.on("close",()=>{k.destroy()}),k}}).call(this)}).call(this,i("_process"))},{_process:50,buffer:17,debug:18,duplexify:20,"readable-stream":69,ws:80}],6:[function(i,s,r){const{Buffer:a}=i("buffer"),o=i("readable-stream").Transform,l=i("duplexify");let n,h,c;s.exports=function(f,u){if(u.hostname=u.hostname||u.host,!u.hostname)throw new Error("Could not determine host. Specify host manually.");const d=u.protocolId==="MQIsdp"&&u.protocolVersion===3?"mqttv3.1":"mqtt";(function(y){y.hostname||(y.hostname="localhost"),y.path||(y.path="/"),y.wsOptions||(y.wsOptions={})})(u);const v=function(y,p){const b=y.protocol==="wxs"?"wss":"ws";let m=b+"://"+y.hostname+y.path;return y.port&&y.port!==80&&y.port!==443&&(m=b+"://"+y.hostname+":"+y.port+y.path),typeof y.transformWsUrl=="function"&&(m=y.transformWsUrl(m,y,p)),m}(u,f);n=wx.connectSocket({url:v,protocols:[d]}),h=function(){const y=new o;return y._write=function(p,b,m){n.send({data:p.buffer,success:function(){m()},fail:function(k){m(new Error(k))}})},y._flush=function(p){n.close({success:function(){p()}})},y}(),(c=l.obj())._destroy=function(y,p){n.close({success:function(){p&&p(y)}})};const g=c.destroy;return c.destroy=(function(){c.destroy=g;const y=this;setTimeout(function(){n.close({fail:function(){y._destroy(new Error)}})},0)}).bind(c),n.onOpen(function(){c.setReadable(h),c.setWritable(h),c.emit("connect")}),n.onMessage(function(y){let p=y.data;p=p instanceof ArrayBuffer?a.from(p):a.from(p,"utf8"),h.push(p)}),n.onClose(function(){c.end(),c.destroy()}),n.onError(function(y){c.destroy(new Error(y.errMsg))}),c}},{buffer:17,duplexify:20,"readable-stream":69}],7:[function(i,s,r){function a(){if(!(this instanceof a))return new a;this.nextId=Math.max(1,Math.floor(65535*Math.random()))}a.prototype.allocate=function(){const o=this.nextId++;return this.nextId===65536&&(this.nextId=1),o},a.prototype.getLastAllocated=function(){return this.nextId===1?65535:this.nextId-1},a.prototype.register=function(o){return!0},a.prototype.deallocate=function(o){},a.prototype.clear=function(){},s.exports=a},{}],8:[function(i,s,r){const a=i("xtend"),o=i("readable-stream").Readable,l={objectMode:!0},n={clean:!0};function h(c){if(!(this instanceof h))return new h(c);this.options=c||{},this.options=a(n,c),this._inflights=new Map}h.prototype.put=function(c,f){return this._inflights.set(c.messageId,c),f&&f(),this},h.prototype.createStream=function(){const c=new o(l),f=[];let u=!1,d=0;return this._inflights.forEach(function(v,g){f.push(v)}),c._read=function(){!u&&d<f.length?this.push(f[d++]):this.push(null)},c.destroy=function(){if(u)return;const v=this;u=!0,setTimeout(function(){v.emit("close")},0)},c},h.prototype.del=function(c,f){return(c=this._inflights.get(c.messageId))?(this._inflights.delete(c.messageId),f(null,c)):f&&f(new Error("missing packet")),this},h.prototype.get=function(c,f){return(c=this._inflights.get(c.messageId))?f(null,c):f&&f(new Error("missing packet")),this},h.prototype.close=function(c){this.options.clean&&(this._inflights=null),c&&c()},s.exports=h},{"readable-stream":69,xtend:81}],9:[function(i,s,r){function a(o){if(!(this instanceof a))return new a(o);this.aliasToTopic={},this.max=o}a.prototype.put=function(o,l){return!(l===0||l>this.max)&&(this.aliasToTopic[l]=o,this.length=Object.keys(this.aliasToTopic).length,!0)},a.prototype.getTopicByAlias=function(o){return this.aliasToTopic[o]},a.prototype.clear=function(){this.aliasToTopic={}},s.exports=a},{}],10:[function(i,s,r){const a=i("lru-cache"),o=i("number-allocator").NumberAllocator;function l(n){if(!(this instanceof l))return new l(n);n>0&&(this.aliasToTopic=new a({max:n}),this.topicToAlias={},this.numberAllocator=new o(1,n),this.max=n,this.length=0)}l.prototype.put=function(n,h){if(h===0||h>this.max)return!1;const c=this.aliasToTopic.get(h);return c&&delete this.topicToAlias[c],this.aliasToTopic.set(h,n),this.topicToAlias[n]=h,this.numberAllocator.use(h),this.length=this.aliasToTopic.length,!0},l.prototype.getTopicByAlias=function(n){return this.aliasToTopic.get(n)},l.prototype.getAliasByTopic=function(n){const h=this.topicToAlias[n];return h!==void 0&&this.aliasToTopic.get(h),h},l.prototype.clear=function(){this.aliasToTopic.reset(),this.topicToAlias={},this.numberAllocator.clear(),this.length=0},l.prototype.getLruAlias=function(){return this.numberAllocator.firstVacant()||this.aliasToTopic.keys()[this.aliasToTopic.length-1]},s.exports=l},{"lru-cache":37,"number-allocator":46}],11:[function(i,s,r){function a(o){const l=o.split("/");for(let n=0;n<l.length;n++)if(l[n]!=="+"){if(l[n]==="#")return n===l.length-1;if(l[n].indexOf("+")!==-1||l[n].indexOf("#")!==-1)return!1}return!0}s.exports={validateTopics:function(o){if(o.length===0)return"empty_topic_list";for(let l=0;l<o.length;l++)if(!a(o[l]))return o[l];return null}}},{}],12:[function(i,s,r){(function(a){(function(){const o=i("../client"),l=i("../store"),n=i("url"),h=i("xtend"),c=i("debug")("mqttjs"),f={};function u(d,v){if(c("connecting to an MQTT broker..."),typeof d!="object"||v||(v=d,d=null),v=v||{},d){const y=n.parse(d,!0);if(y.port!=null&&(y.port=Number(y.port)),(v=h(y,v)).protocol===null)throw new Error("Missing protocol");v.protocol=v.protocol.replace(/:$/,"")}if(function(y){let p;y.auth&&((p=y.auth.match(/^(.+):(.+)$/))?(y.username=p[1],y.password=p[2]):y.username=y.auth)}(v),v.query&&typeof v.query.clientId=="string"&&(v.clientId=v.query.clientId),v.cert&&v.key){if(!v.protocol)throw new Error("Missing secure protocol key");if(["mqtts","wss","wxs","alis"].indexOf(v.protocol)===-1)switch(v.protocol){case"mqtt":v.protocol="mqtts";break;case"ws":v.protocol="wss";break;case"wx":v.protocol="wxs";break;case"ali":v.protocol="alis";break;default:throw new Error('Unknown protocol for secure connection: "'+v.protocol+'"!')}}if(!f[v.protocol]){const y=["mqtts","wss"].indexOf(v.protocol)!==-1;v.protocol=["mqtt","mqtts","ws","wss","wx","wxs","ali","alis"].filter(function(p,b){return(!y||b%2!=0)&&typeof f[p]=="function"})[0]}if(v.clean===!1&&!v.clientId)throw new Error("Missing clientId for unclean clients");v.protocol&&(v.defaultProtocol=v.protocol);const g=new o(function(y){return v.servers&&(y._reconnectCount&&y._reconnectCount!==v.servers.length||(y._reconnectCount=0),v.host=v.servers[y._reconnectCount].host,v.port=v.servers[y._reconnectCount].port,v.protocol=v.servers[y._reconnectCount].protocol?v.servers[y._reconnectCount].protocol:v.defaultProtocol,v.hostname=v.host,y._reconnectCount++),c("calling streambuilder for",v.protocol),f[v.protocol](y,v)},v);return g.on("error",function(){}),g}a!==void 0&&a.title!=="browser"||typeof __webpack_require__!="function"?(f.mqtt=i("./tcp"),f.tcp=i("./tcp"),f.ssl=i("./tls"),f.tls=i("./tls"),f.mqtts=i("./tls")):(f.wx=i("./wx"),f.wxs=i("./wx"),f.ali=i("./ali"),f.alis=i("./ali")),f.ws=i("./ws"),f.wss=i("./ws"),s.exports=u,s.exports.connect=u,s.exports.MqttClient=o,s.exports.Store=l}).call(this)}).call(this,i("_process"))},{"../client":1,"../store":8,"./ali":2,"./tcp":3,"./tls":4,"./ws":5,"./wx":6,_process:50,debug:18,url:76,xtend:81}],13:[function(i,s,r){r.byteLength=function(d){var v=f(d),g=v[0],y=v[1];return 3*(g+y)/4-y},r.toByteArray=function(d){var v,g,y=f(d),p=y[0],b=y[1],m=new l(function(S,I,E){return 3*(I+E)/4-E}(0,p,b)),k=0,A=b>0?p-4:p;for(g=0;g<A;g+=4)v=o[d.charCodeAt(g)]<<18|o[d.charCodeAt(g+1)]<<12|o[d.charCodeAt(g+2)]<<6|o[d.charCodeAt(g+3)],m[k++]=v>>16&255,m[k++]=v>>8&255,m[k++]=255&v;return b===2&&(v=o[d.charCodeAt(g)]<<2|o[d.charCodeAt(g+1)]>>4,m[k++]=255&v),b===1&&(v=o[d.charCodeAt(g)]<<10|o[d.charCodeAt(g+1)]<<4|o[d.charCodeAt(g+2)]>>2,m[k++]=v>>8&255,m[k++]=255&v),m},r.fromByteArray=function(d){for(var v,g=d.length,y=g%3,p=[],b=0,m=g-y;b<m;b+=16383)p.push(u(d,b,b+16383>m?m:b+16383));return y===1?(v=d[g-1],p.push(a[v>>2]+a[v<<4&63]+"==")):y===2&&(v=(d[g-2]<<8)+d[g-1],p.push(a[v>>10]+a[v>>4&63]+a[v<<2&63]+"=")),p.join("")};for(var a=[],o=[],l=typeof Uint8Array<"u"?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=0,c=n.length;h<c;++h)a[h]=n[h],o[n.charCodeAt(h)]=h;function f(d){var v=d.length;if(v%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var g=d.indexOf("=");return g===-1&&(g=v),[g,g===v?0:4-g%4]}function u(d,v,g){for(var y,p,b=[],m=v;m<g;m+=3)y=(d[m]<<16&16711680)+(d[m+1]<<8&65280)+(255&d[m+2]),b.push(a[(p=y)>>18&63]+a[p>>12&63]+a[p>>6&63]+a[63&p]);return b.join("")}o[45]=62,o[95]=63},{}],14:[function(i,s,r){const{Buffer:a}=i("buffer"),o=Symbol.for("BufferList");function l(n){if(!(this instanceof l))return new l(n);l._init.call(this,n)}l._init=function(n){Object.defineProperty(this,o,{value:!0}),this._bufs=[],this.length=0,n&&this.append(n)},l.prototype._new=function(n){return new l(n)},l.prototype._offset=function(n){if(n===0)return[0,0];let h=0;for(let c=0;c<this._bufs.length;c++){const f=h+this._bufs[c].length;if(n<f||c===this._bufs.length-1)return[c,n-h];h=f}},l.prototype._reverseOffset=function(n){const h=n[0];let c=n[1];for(let f=0;f<h;f++)c+=this._bufs[f].length;return c},l.prototype.get=function(n){if(n>this.length||n<0)return;const h=this._offset(n);return this._bufs[h[0]][h[1]]},l.prototype.slice=function(n,h){return typeof n=="number"&&n<0&&(n+=this.length),typeof h=="number"&&h<0&&(h+=this.length),this.copy(null,0,n,h)},l.prototype.copy=function(n,h,c,f){if((typeof c!="number"||c<0)&&(c=0),(typeof f!="number"||f>this.length)&&(f=this.length),c>=this.length||f<=0)return n||a.alloc(0);const u=!!n,d=this._offset(c),v=f-c;let g=v,y=u&&h||0,p=d[1];if(c===0&&f===this.length){if(!u)return this._bufs.length===1?this._bufs[0]:a.concat(this._bufs,this.length);for(let b=0;b<this._bufs.length;b++)this._bufs[b].copy(n,y),y+=this._bufs[b].length;return n}if(g<=this._bufs[d[0]].length-p)return u?this._bufs[d[0]].copy(n,h,p,p+g):this._bufs[d[0]].slice(p,p+g);u||(n=a.allocUnsafe(v));for(let b=d[0];b<this._bufs.length;b++){const m=this._bufs[b].length-p;if(!(g>m)){this._bufs[b].copy(n,y,p,p+g),y+=m;break}this._bufs[b].copy(n,y,p),y+=m,g-=m,p&&(p=0)}return n.length>y?n.slice(0,y):n},l.prototype.shallowSlice=function(n,h){if(n=n||0,h=typeof h!="number"?this.length:h,n<0&&(n+=this.length),h<0&&(h+=this.length),n===h)return this._new();const c=this._offset(n),f=this._offset(h),u=this._bufs.slice(c[0],f[0]+1);return f[1]===0?u.pop():u[u.length-1]=u[u.length-1].slice(0,f[1]),c[1]!==0&&(u[0]=u[0].slice(c[1])),this._new(u)},l.prototype.toString=function(n,h,c){return this.slice(h,c).toString(n)},l.prototype.consume=function(n){if(n=Math.trunc(n),Number.isNaN(n)||n<=0)return this;for(;this._bufs.length;){if(!(n>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(n),this.length-=n;break}n-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},l.prototype.duplicate=function(){const n=this._new();for(let h=0;h<this._bufs.length;h++)n.append(this._bufs[h]);return n},l.prototype.append=function(n){if(n==null)return this;if(n.buffer)this._appendBuffer(a.from(n.buffer,n.byteOffset,n.byteLength));else if(Array.isArray(n))for(let h=0;h<n.length;h++)this.append(n[h]);else if(this._isBufferList(n))for(let h=0;h<n._bufs.length;h++)this.append(n._bufs[h]);else typeof n=="number"&&(n=n.toString()),this._appendBuffer(a.from(n));return this},l.prototype._appendBuffer=function(n){this._bufs.push(n),this.length+=n.length},l.prototype.indexOf=function(n,h,c){if(c===void 0&&typeof h=="string"&&(c=h,h=void 0),typeof n=="function"||Array.isArray(n))throw new TypeError('The "value" argument must be one of type string, Buffer, BufferList, or Uint8Array.');if(typeof n=="number"?n=a.from([n]):typeof n=="string"?n=a.from(n,c):this._isBufferList(n)?n=n.slice():Array.isArray(n.buffer)?n=a.from(n.buffer,n.byteOffset,n.byteLength):a.isBuffer(n)||(n=a.from(n)),h=Number(h||0),isNaN(h)&&(h=0),h<0&&(h=this.length+h),h<0&&(h=0),n.length===0)return h>this.length?this.length:h;const f=this._offset(h);let u=f[0],d=f[1];for(;u<this._bufs.length;u++){const v=this._bufs[u];for(;d<v.length;)if(v.length-d>=n.length){const g=v.indexOf(n,d);if(g!==-1)return this._reverseOffset([u,g]);d=v.length-n.length+1}else{const g=this._reverseOffset([u,d]);if(this._match(g,n))return g;d++}d=0}return-1},l.prototype._match=function(n,h){if(this.length-n<h.length)return!1;for(let c=0;c<h.length;c++)if(this.get(n+c)!==h[c])return!1;return!0},function(){const n={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1,readIntBE:null,readIntLE:null,readUIntBE:null,readUIntLE:null};for(const h in n)(function(c){l.prototype[c]=n[c]===null?function(f,u){return this.slice(f,f+u)[c](0,u)}:function(f=0){return this.slice(f,f+n[c])[c](0)}})(h)}(),l.prototype._isBufferList=function(n){return n instanceof l||l.isBufferList(n)},l.isBufferList=function(n){return n!=null&&n[o]},s.exports=l},{buffer:17}],15:[function(i,s,r){const a=i("readable-stream").Duplex,o=i("inherits"),l=i("./BufferList");function n(h){if(!(this instanceof n))return new n(h);if(typeof h=="function"){this._callback=h;const c=(function(f){this._callback&&(this._callback(f),this._callback=null)}).bind(this);this.on("pipe",function(f){f.on("error",c)}),this.on("unpipe",function(f){f.removeListener("error",c)}),h=null}l._init.call(this,h),a.call(this)}o(n,a),Object.assign(n.prototype,l.prototype),n.prototype._new=function(h){return new n(h)},n.prototype._write=function(h,c,f){this._appendBuffer(h),typeof f=="function"&&f()},n.prototype._read=function(h){if(!this.length)return this.push(null);h=Math.min(h,this.length),this.push(this.slice(0,h)),this.consume(h)},n.prototype.end=function(h){a.prototype.end.call(this,h),this._callback&&(this._callback(null,this.slice()),this._callback=null)},n.prototype._destroy=function(h,c){this._bufs.length=0,this.length=0,c(h)},n.prototype._isBufferList=function(h){return h instanceof n||h instanceof l||n.isBufferList(h)},n.isBufferList=l.isBufferList,s.exports=n,s.exports.BufferListStream=n,s.exports.BufferList=l},{"./BufferList":14,inherits:24,"readable-stream":69}],16:[function(i,s,r){},{}],17:[function(i,s,r){(function(a){(function(){var o=i("base64-js"),l=i("ieee754");r.Buffer=c,r.SlowBuffer=function(w){return+w!=w&&(w=0),c.alloc(+w)},r.INSPECT_MAX_BYTES=50;var n=2147483647;function h(w){if(w>n)throw new RangeError('The value "'+w+'" is invalid for option "size"');var x=new Uint8Array(w);return x.__proto__=c.prototype,x}function c(w,x,P){if(typeof w=="number"){if(typeof x=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return d(w)}return f(w,x,P)}function f(w,x,P){if(typeof w=="string")return function(V,G){if(typeof G=="string"&&G!==""||(G="utf8"),!c.isEncoding(G))throw new TypeError("Unknown encoding: "+G);var et=0|y(V,G),tt=h(et),at=tt.write(V,G);return at!==et&&(tt=tt.slice(0,at)),tt}(w,x);if(ArrayBuffer.isView(w))return v(w);if(w==null)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof w);if(J(w,ArrayBuffer)||w&&J(w.buffer,ArrayBuffer))return function(V,G,et){if(G<0||V.byteLength<G)throw new RangeError('"offset" is outside of buffer bounds');if(V.byteLength<G+(et||0))throw new RangeError('"length" is outside of buffer bounds');var tt;return tt=G===void 0&&et===void 0?new Uint8Array(V):et===void 0?new Uint8Array(V,G):new Uint8Array(V,G,et),tt.__proto__=c.prototype,tt}(w,x,P);if(typeof w=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var M=w.valueOf&&w.valueOf();if(M!=null&&M!==w)return c.from(M,x,P);var H=function(V){if(c.isBuffer(V)){var G=0|g(V.length),et=h(G);return et.length===0||V.copy(et,0,0,G),et}if(V.length!==void 0)return typeof V.length!="number"||Q(V.length)?h(0):v(V);if(V.type==="Buffer"&&Array.isArray(V.data))return v(V.data)}(w);if(H)return H;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof w[Symbol.toPrimitive]=="function")return c.from(w[Symbol.toPrimitive]("string"),x,P);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof w)}function u(w){if(typeof w!="number")throw new TypeError('"size" argument must be of type number');if(w<0)throw new RangeError('The value "'+w+'" is invalid for option "size"')}function d(w){return u(w),h(w<0?0:0|g(w))}function v(w){for(var x=w.length<0?0:0|g(w.length),P=h(x),M=0;M<x;M+=1)P[M]=255&w[M];return P}function g(w){if(w>=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return 0|w}function y(w,x){if(c.isBuffer(w))return w.length;if(ArrayBuffer.isView(w)||J(w,ArrayBuffer))return w.byteLength;if(typeof w!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof w);var P=w.length,M=arguments.length>2&&arguments[2]===!0;if(!M&&P===0)return 0;for(var H=!1;;)switch(x){case"ascii":case"latin1":case"binary":return P;case"utf8":case"utf-8":return $(w).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*P;case"hex":return P>>>1;case"base64":return Y(w).length;default:if(H)return M?-1:$(w).length;x=(""+x).toLowerCase(),H=!0}}function p(w,x,P){var M=w[x];w[x]=w[P],w[P]=M}function b(w,x,P,M,H){if(w.length===0)return-1;if(typeof P=="string"?(M=P,P=0):P>2147483647?P=2147483647:P<-2147483648&&(P=-2147483648),Q(P=+P)&&(P=H?0:w.length-1),P<0&&(P=w.length+P),P>=w.length){if(H)return-1;P=w.length-1}else if(P<0){if(!H)return-1;P=0}if(typeof x=="string"&&(x=c.from(x,M)),c.isBuffer(x))return x.length===0?-1:m(w,x,P,M,H);if(typeof x=="number")return x&=255,typeof Uint8Array.prototype.indexOf=="function"?H?Uint8Array.prototype.indexOf.call(w,x,P):Uint8Array.prototype.lastIndexOf.call(w,x,P):m(w,[x],P,M,H);throw new TypeError("val must be string, number or Buffer")}function m(w,x,P,M,H){var V,G=1,et=w.length,tt=x.length;if(M!==void 0&&((M=String(M).toLowerCase())==="ucs2"||M==="ucs-2"||M==="utf16le"||M==="utf-16le")){if(w.length<2||x.length<2)return-1;G=2,et/=2,tt/=2,P/=2}function at(Ht,mt){return G===1?Ht[mt]:Ht.readUInt16BE(mt*G)}if(H){var ot=-1;for(V=P;V<et;V++)if(at(w,V)===at(x,ot===-1?0:V-ot)){if(ot===-1&&(ot=V),V-ot+1===tt)return ot*G}else ot!==-1&&(V-=V-ot),ot=-1}else for(P+tt>et&&(P=et-tt),V=P;V>=0;V--){for(var Wt=!0,Ft=0;Ft<tt;Ft++)if(at(w,V+Ft)!==at(x,Ft)){Wt=!1;break}if(Wt)return V}return-1}function k(w,x,P,M){P=Number(P)||0;var H=w.length-P;M?(M=Number(M))>H&&(M=H):M=H;var V=x.length;M>V/2&&(M=V/2);for(var G=0;G<M;++G){var et=parseInt(x.substr(2*G,2),16);if(Q(et))return G;w[P+G]=et}return G}function A(w,x,P,M){return Z($(x,w.length-P),w,P,M)}function S(w,x,P,M){return Z(function(H){for(var V=[],G=0;G<H.length;++G)V.push(255&H.charCodeAt(G));return V}(x),w,P,M)}function I(w,x,P,M){return S(w,x,P,M)}function E(w,x,P,M){return Z(Y(x),w,P,M)}function z(w,x,P,M){return Z(function(H,V){for(var G,et,tt,at=[],ot=0;ot<H.length&&!((V-=2)<0);++ot)G=H.charCodeAt(ot),et=G>>8,tt=G%256,at.push(tt),at.push(et);return at}(x,w.length-P),w,P,M)}function U(w,x,P){return x===0&&P===w.length?o.fromByteArray(w):o.fromByteArray(w.slice(x,P))}function T(w,x,P){P=Math.min(w.length,P);for(var M=[],H=x;H<P;){var V,G,et,tt,at=w[H],ot=null,Wt=at>239?4:at>223?3:at>191?2:1;if(H+Wt<=P)switch(Wt){case 1:at<128&&(ot=at);break;case 2:(192&(V=w[H+1]))==128&&(tt=(31&at)<<6|63&V)>127&&(ot=tt);break;case 3:V=w[H+1],G=w[H+2],(192&V)==128&&(192&G)==128&&(tt=(15&at)<<12|(63&V)<<6|63&G)>2047&&(tt<55296||tt>57343)&&(ot=tt);break;case 4:V=w[H+1],G=w[H+2],et=w[H+3],(192&V)==128&&(192&G)==128&&(192&et)==128&&(tt=(15&at)<<18|(63&V)<<12|(63&G)<<6|63&et)>65535&&tt<1114112&&(ot=tt)}ot===null?(ot=65533,Wt=1):ot>65535&&(ot-=65536,M.push(ot>>>10&1023|55296),ot=56320|1023&ot),M.push(ot),H+=Wt}return function(Ft){var Ht=Ft.length;if(Ht<=R)return String.fromCharCode.apply(String,Ft);for(var mt="",wt=0;wt<Ht;)mt+=String.fromCharCode.apply(String,Ft.slice(wt,wt+=R));return mt}(M)}r.kMaxLength=n,c.TYPED_ARRAY_SUPPORT=function(){try{var w=new Uint8Array(1);return w.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},w.foo()===42}catch{return!1}}(),c.TYPED_ARRAY_SUPPORT||typeof console>"u"||typeof console.error!="function"||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(c.prototype,"parent",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.buffer}}),Object.defineProperty(c.prototype,"offset",{enumerable:!0,get:function(){if(c.isBuffer(this))return this.byteOffset}}),typeof Symbol<"u"&&Symbol.species!=null&&c[Symbol.species]===c&&Object.defineProperty(c,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),c.poolSize=8192,c.from=function(w,x,P){return f(w,x,P)},c.prototype.__proto__=Uint8Array.prototype,c.__proto__=Uint8Array,c.alloc=function(w,x,P){return function(M,H,V){return u(M),M<=0?h(M):H!==void 0?typeof V=="string"?h(M).fill(H,V):h(M).fill(H):h(M)}(w,x,P)},c.allocUnsafe=function(w){return d(w)},c.allocUnsafeSlow=function(w){return d(w)},c.isBuffer=function(w){return w!=null&&w._isBuffer===!0&&w!==c.prototype},c.compare=function(w,x){if(J(w,Uint8Array)&&(w=c.from(w,w.offset,w.byteLength)),J(x,Uint8Array)&&(x=c.from(x,x.offset,x.byteLength)),!c.isBuffer(w)||!c.isBuffer(x))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(w===x)return 0;for(var P=w.length,M=x.length,H=0,V=Math.min(P,M);H<V;++H)if(w[H]!==x[H]){P=w[H],M=x[H];break}return P<M?-1:M<P?1:0},c.isEncoding=function(w){switch(String(w).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},c.concat=function(w,x){if(!Array.isArray(w))throw new TypeError('"list" argument must be an Array of Buffers');if(w.length===0)return c.alloc(0);var P;if(x===void 0)for(x=0,P=0;P<w.length;++P)x+=w[P].length;var M=c.allocUnsafe(x),H=0;for(P=0;P<w.length;++P){var V=w[P];if(J(V,Uint8Array)&&(V=c.from(V)),!c.isBuffer(V))throw new TypeError('"list" argument must be an Array of Buffers');V.copy(M,H),H+=V.length}return M},c.byteLength=y,c.prototype._isBuffer=!0,c.prototype.swap16=function(){var w=this.length;if(w%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var x=0;x<w;x+=2)p(this,x,x+1);return this},c.prototype.swap32=function(){var w=this.length;if(w%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var x=0;x<w;x+=4)p(this,x,x+3),p(this,x+1,x+2);return this},c.prototype.swap64=function(){var w=this.length;if(w%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var x=0;x<w;x+=8)p(this,x,x+7),p(this,x+1,x+6),p(this,x+2,x+5),p(this,x+3,x+4);return this},c.prototype.toString=function(){var w=this.length;return w===0?"":arguments.length===0?T(this,0,w):(function(x,P,M){var H=!1;if((P===void 0||P<0)&&(P=0),P>this.length||((M===void 0||M>this.length)&&(M=this.length),M<=0)||(M>>>=0)<=(P>>>=0))return"";for(x||(x="utf8");;)switch(x){case"hex":return B(this,P,M);case"utf8":case"utf-8":return T(this,P,M);case"ascii":return C(this,P,M);case"latin1":case"binary":return _(this,P,M);case"base64":return U(this,P,M);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j(this,P,M);default:if(H)throw new TypeError("Unknown encoding: "+x);x=(x+"").toLowerCase(),H=!0}}).apply(this,arguments)},c.prototype.toLocaleString=c.prototype.toString,c.prototype.equals=function(w){if(!c.isBuffer(w))throw new TypeError("Argument must be a Buffer");return this===w||c.compare(this,w)===0},c.prototype.inspect=function(){var w="",x=r.INSPECT_MAX_BYTES;return w=this.toString("hex",0,x).replace(/(.{2})/g,"$1 ").trim(),this.length>x&&(w+=" ... "),"<Buffer "+w+">"},c.prototype.compare=function(w,x,P,M,H){if(J(w,Uint8Array)&&(w=c.from(w,w.offset,w.byteLength)),!c.isBuffer(w))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof w);if(x===void 0&&(x=0),P===void 0&&(P=w?w.length:0),M===void 0&&(M=0),H===void 0&&(H=this.length),x<0||P>w.length||M<0||H>this.length)throw new RangeError("out of range index");if(M>=H&&x>=P)return 0;if(M>=H)return-1;if(x>=P)return 1;if(x>>>=0,P>>>=0,M>>>=0,H>>>=0,this===w)return 0;for(var V=H-M,G=P-x,et=Math.min(V,G),tt=this.slice(M,H),at=w.slice(x,P),ot=0;ot<et;++ot)if(tt[ot]!==at[ot]){V=tt[ot],G=at[ot];break}return V<G?-1:G<V?1:0},c.prototype.includes=function(w,x,P){return this.indexOf(w,x,P)!==-1},c.prototype.indexOf=function(w,x,P){return b(this,w,x,P,!0)},c.prototype.lastIndexOf=function(w,x,P){return b(this,w,x,P,!1)},c.prototype.write=function(w,x,P,M){if(x===void 0)M="utf8",P=this.length,x=0;else if(P===void 0&&typeof x=="string")M=x,P=this.length,x=0;else{if(!isFinite(x))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");x>>>=0,isFinite(P)?(P>>>=0,M===void 0&&(M="utf8")):(M=P,P=void 0)}var H=this.length-x;if((P===void 0||P>H)&&(P=H),w.length>0&&(P<0||x<0)||x>this.length)throw new RangeError("Attempt to write outside buffer bounds");M||(M="utf8");for(var V=!1;;)switch(M){case"hex":return k(this,w,x,P);case"utf8":case"utf-8":return A(this,w,x,P);case"ascii":return S(this,w,x,P);case"latin1":case"binary":return I(this,w,x,P);case"base64":return E(this,w,x,P);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return z(this,w,x,P);default:if(V)throw new TypeError("Unknown encoding: "+M);M=(""+M).toLowerCase(),V=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var R=4096;function C(w,x,P){var M="";P=Math.min(w.length,P);for(var H=x;H<P;++H)M+=String.fromCharCode(127&w[H]);return M}function _(w,x,P){var M="";P=Math.min(w.length,P);for(var H=x;H<P;++H)M+=String.fromCharCode(w[H]);return M}function B(w,x,P){var M=w.length;(!x||x<0)&&(x=0),(!P||P<0||P>M)&&(P=M);for(var H="",V=x;V<P;++V)H+=q(w[V]);return H}function j(w,x,P){for(var M=w.slice(x,P),H="",V=0;V<M.length;V+=2)H+=String.fromCharCode(M[V]+256*M[V+1]);return H}function X(w,x,P){if(w%1!=0||w<0)throw new RangeError("offset is not uint");if(w+x>P)throw new RangeError("Trying to access beyond buffer length")}function F(w,x,P,M,H,V){if(!c.isBuffer(w))throw new TypeError('"buffer" argument must be a Buffer instance');if(x>H||x<V)throw new RangeError('"value" argument is out of bounds');if(P+M>w.length)throw new RangeError("Index out of range")}function L(w,x,P,M,H,V){if(P+M>w.length)throw new RangeError("Index out of range");if(P<0)throw new RangeError("Index out of range")}function N(w,x,P,M,H){return x=+x,P>>>=0,H||L(w,0,P,4),l.write(w,x,P,M,23,4),P+4}function W(w,x,P,M,H){return x=+x,P>>>=0,H||L(w,0,P,8),l.write(w,x,P,M,52,8),P+8}c.prototype.slice=function(w,x){var P=this.length;w=~~w,x=x===void 0?P:~~x,w<0?(w+=P)<0&&(w=0):w>P&&(w=P),x<0?(x+=P)<0&&(x=0):x>P&&(x=P),x<w&&(x=w);var M=this.subarray(w,x);return M.__proto__=c.prototype,M},c.prototype.readUIntLE=function(w,x,P){w>>>=0,x>>>=0,P||X(w,x,this.length);for(var M=this[w],H=1,V=0;++V<x&&(H*=256);)M+=this[w+V]*H;return M},c.prototype.readUIntBE=function(w,x,P){w>>>=0,x>>>=0,P||X(w,x,this.length);for(var M=this[w+--x],H=1;x>0&&(H*=256);)M+=this[w+--x]*H;return M},c.prototype.readUInt8=function(w,x){return w>>>=0,x||X(w,1,this.length),this[w]},c.prototype.readUInt16LE=function(w,x){return w>>>=0,x||X(w,2,this.length),this[w]|this[w+1]<<8},c.prototype.readUInt16BE=function(w,x){return w>>>=0,x||X(w,2,this.length),this[w]<<8|this[w+1]},c.prototype.readUInt32LE=function(w,x){return w>>>=0,x||X(w,4,this.length),(this[w]|this[w+1]<<8|this[w+2]<<16)+16777216*this[w+3]},c.prototype.readUInt32BE=function(w,x){return w>>>=0,x||X(w,4,this.length),16777216*this[w]+(this[w+1]<<16|this[w+2]<<8|this[w+3])},c.prototype.readIntLE=function(w,x,P){w>>>=0,x>>>=0,P||X(w,x,this.length);for(var M=this[w],H=1,V=0;++V<x&&(H*=256);)M+=this[w+V]*H;return M>=(H*=128)&&(M-=Math.pow(2,8*x)),M},c.prototype.readIntBE=function(w,x,P){w>>>=0,x>>>=0,P||X(w,x,this.length);for(var M=x,H=1,V=this[w+--M];M>0&&(H*=256);)V+=this[w+--M]*H;return V>=(H*=128)&&(V-=Math.pow(2,8*x)),V},c.prototype.readInt8=function(w,x){return w>>>=0,x||X(w,1,this.length),128&this[w]?-1*(255-this[w]+1):this[w]},c.prototype.readInt16LE=function(w,x){w>>>=0,x||X(w,2,this.length);var P=this[w]|this[w+1]<<8;return 32768&P?4294901760|P:P},c.prototype.readInt16BE=function(w,x){w>>>=0,x||X(w,2,this.length);var P=this[w+1]|this[w]<<8;return 32768&P?4294901760|P:P},c.prototype.readInt32LE=function(w,x){return w>>>=0,x||X(w,4,this.length),this[w]|this[w+1]<<8|this[w+2]<<16|this[w+3]<<24},c.prototype.readInt32BE=function(w,x){return w>>>=0,x||X(w,4,this.length),this[w]<<24|this[w+1]<<16|this[w+2]<<8|this[w+3]},c.prototype.readFloatLE=function(w,x){return w>>>=0,x||X(w,4,this.length),l.read(this,w,!0,23,4)},c.prototype.readFloatBE=function(w,x){return w>>>=0,x||X(w,4,this.length),l.read(this,w,!1,23,4)},c.prototype.readDoubleLE=function(w,x){return w>>>=0,x||X(w,8,this.length),l.read(this,w,!0,52,8)},c.prototype.readDoubleBE=function(w,x){return w>>>=0,x||X(w,8,this.length),l.read(this,w,!1,52,8)},c.prototype.writeUIntLE=function(w,x,P,M){w=+w,x>>>=0,P>>>=0,M||F(this,w,x,P,Math.pow(2,8*P)-1,0);var H=1,V=0;for(this[x]=255&w;++V<P&&(H*=256);)this[x+V]=w/H&255;return x+P},c.prototype.writeUIntBE=function(w,x,P,M){w=+w,x>>>=0,P>>>=0,M||F(this,w,x,P,Math.pow(2,8*P)-1,0);var H=P-1,V=1;for(this[x+H]=255&w;--H>=0&&(V*=256);)this[x+H]=w/V&255;return x+P},c.prototype.writeUInt8=function(w,x,P){return w=+w,x>>>=0,P||F(this,w,x,1,255,0),this[x]=255&w,x+1},c.prototype.writeUInt16LE=function(w,x,P){return w=+w,x>>>=0,P||F(this,w,x,2,65535,0),this[x]=255&w,this[x+1]=w>>>8,x+2},c.prototype.writeUInt16BE=function(w,x,P){return w=+w,x>>>=0,P||F(this,w,x,2,65535,0),this[x]=w>>>8,this[x+1]=255&w,x+2},c.prototype.writeUInt32LE=function(w,x,P){return w=+w,x>>>=0,P||F(this,w,x,4,4294967295,0),this[x+3]=w>>>24,this[x+2]=w>>>16,this[x+1]=w>>>8,this[x]=255&w,x+4},c.prototype.writeUInt32BE=function(w,x,P){return w=+w,x>>>=0,P||F(this,w,x,4,4294967295,0),this[x]=w>>>24,this[x+1]=w>>>16,this[x+2]=w>>>8,this[x+3]=255&w,x+4},c.prototype.writeIntLE=function(w,x,P,M){if(w=+w,x>>>=0,!M){var H=Math.pow(2,8*P-1);F(this,w,x,P,H-1,-H)}var V=0,G=1,et=0;for(this[x]=255&w;++V<P&&(G*=256);)w<0&&et===0&&this[x+V-1]!==0&&(et=1),this[x+V]=(w/G>>0)-et&255;return x+P},c.prototype.writeIntBE=function(w,x,P,M){if(w=+w,x>>>=0,!M){var H=Math.pow(2,8*P-1);F(this,w,x,P,H-1,-H)}var V=P-1,G=1,et=0;for(this[x+V]=255&w;--V>=0&&(G*=256);)w<0&&et===0&&this[x+V+1]!==0&&(et=1),this[x+V]=(w/G>>0)-et&255;return x+P},c.prototype.writeInt8=function(w,x,P){return w=+w,x>>>=0,P||F(this,w,x,1,127,-128),w<0&&(w=255+w+1),this[x]=255&w,x+1},c.prototype.writeInt16LE=function(w,x,P){return w=+w,x>>>=0,P||F(this,w,x,2,32767,-32768),this[x]=255&w,this[x+1]=w>>>8,x+2},c.prototype.writeInt16BE=function(w,x,P){return w=+w,x>>>=0,P||F(this,w,x,2,32767,-32768),this[x]=w>>>8,this[x+1]=255&w,x+2},c.prototype.writeInt32LE=function(w,x,P){return w=+w,x>>>=0,P||F(this,w,x,4,2147483647,-2147483648),this[x]=255&w,this[x+1]=w>>>8,this[x+2]=w>>>16,this[x+3]=w>>>24,x+4},c.prototype.writeInt32BE=function(w,x,P){return w=+w,x>>>=0,P||F(this,w,x,4,2147483647,-2147483648),w<0&&(w=4294967295+w+1),this[x]=w>>>24,this[x+1]=w>>>16,this[x+2]=w>>>8,this[x+3]=255&w,x+4},c.prototype.writeFloatLE=function(w,x,P){return N(this,w,x,!0,P)},c.prototype.writeFloatBE=function(w,x,P){return N(this,w,x,!1,P)},c.prototype.writeDoubleLE=function(w,x,P){return W(this,w,x,!0,P)},c.prototype.writeDoubleBE=function(w,x,P){return W(this,w,x,!1,P)},c.prototype.copy=function(w,x,P,M){if(!c.isBuffer(w))throw new TypeError("argument should be a Buffer");if(P||(P=0),M||M===0||(M=this.length),x>=w.length&&(x=w.length),x||(x=0),M>0&&M<P&&(M=P),M===P||w.length===0||this.length===0)return 0;if(x<0)throw new RangeError("targetStart out of bounds");if(P<0||P>=this.length)throw new RangeError("Index out of range");if(M<0)throw new RangeError("sourceEnd out of bounds");M>this.length&&(M=this.length),w.length-x<M-P&&(M=w.length-x+P);var H=M-P;if(this===w&&typeof Uint8Array.prototype.copyWithin=="function")this.copyWithin(x,P,M);else if(this===w&&P<x&&x<M)for(var V=H-1;V>=0;--V)w[V+x]=this[V+P];else Uint8Array.prototype.set.call(w,this.subarray(P,M),x);return H},c.prototype.fill=function(w,x,P,M){if(typeof w=="string"){if(typeof x=="string"?(M=x,x=0,P=this.length):typeof P=="string"&&(M=P,P=this.length),M!==void 0&&typeof M!="string")throw new TypeError("encoding must be a string");if(typeof M=="string"&&!c.isEncoding(M))throw new TypeError("Unknown encoding: "+M);if(w.length===1){var H=w.charCodeAt(0);(M==="utf8"&&H<128||M==="latin1")&&(w=H)}}else typeof w=="number"&&(w&=255);if(x<0||this.length<x||this.length<P)throw new RangeError("Out of range index");if(P<=x)return this;var V;if(x>>>=0,P=P===void 0?this.length:P>>>0,w||(w=0),typeof w=="number")for(V=x;V<P;++V)this[V]=w;else{var G=c.isBuffer(w)?w:c.from(w,M),et=G.length;if(et===0)throw new TypeError('The value "'+w+'" is invalid for argument "value"');for(V=0;V<P-x;++V)this[V+x]=G[V%et]}return this};var O=/[^+/0-9A-Za-z-_]/g;function q(w){return w<16?"0"+w.toString(16):w.toString(16)}function $(w,x){var P;x=x||1/0;for(var M=w.length,H=null,V=[],G=0;G<M;++G){if((P=w.charCodeAt(G))>55295&&P<57344){if(!H){if(P>56319){(x-=3)>-1&&V.push(239,191,189);continue}if(G+1===M){(x-=3)>-1&&V.push(239,191,189);continue}H=P;continue}if(P<56320){(x-=3)>-1&&V.push(239,191,189),H=P;continue}P=65536+(H-55296<<10|P-56320)}else H&&(x-=3)>-1&&V.push(239,191,189);if(H=null,P<128){if((x-=1)<0)break;V.push(P)}else if(P<2048){if((x-=2)<0)break;V.push(P>>6|192,63&P|128)}else if(P<65536){if((x-=3)<0)break;V.push(P>>12|224,P>>6&63|128,63&P|128)}else{if(!(P<1114112))throw new Error("Invalid code point");if((x-=4)<0)break;V.push(P>>18|240,P>>12&63|128,P>>6&63|128,63&P|128)}}return V}function Y(w){return o.toByteArray(function(x){if((x=(x=x.split("=")[0]).trim().replace(O,"")).length<2)return"";for(;x.length%4!=0;)x+="=";return x}(w))}function Z(w,x,P,M){for(var H=0;H<M&&!(H+P>=x.length||H>=w.length);++H)x[H+P]=w[H];return H}function J(w,x){return w instanceof x||w!=null&&w.constructor!=null&&w.constructor.name!=null&&w.constructor.name===x.name}function Q(w){return w!=w}}).call(this)}).call(this,i("buffer").Buffer)},{"base64-js":13,buffer:17,ieee754:23}],18:[function(i,s,r){(function(a){(function(){r.formatArgs=function(l){if(l[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+l[0]+(this.useColors?"%c ":" ")+"+"+s.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;l.splice(1,0,n,"color: inherit");let h=0,c=0;l[0].replace(/%[a-zA-Z%]/g,f=>{f!=="%%"&&f==="%c"&&(c=++h)}),l.splice(c,0,n)},r.save=function(l){try{l?r.storage.setItem("debug",l):r.storage.removeItem("debug")}catch{}},r.load=function(){let l;try{l=r.storage.getItem("debug")}catch{}return!l&&a!==void 0&&"env"in a&&(l=a.env.DEBUG),l},r.useColors=function(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},r.storage=function(){try{return localStorage}catch{}}(),r.destroy=(()=>{let l=!1;return()=>{l||(l=!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`."))}})(),r.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"],r.log=console.debug||console.log||(()=>{}),s.exports=i("./common")(r);const{formatters:o}=s.exports;o.j=function(l){try{return JSON.stringify(l)}catch(n){return"[UnexpectedJSONParseError]: "+n.message}}}).call(this)}).call(this,i("_process"))},{"./common":19,_process:50}],19:[function(i,s,r){s.exports=function(a){function o(h){let c,f,u,d=null;function v(...g){if(!v.enabled)return;const y=v,p=Number(new Date),b=p-(c||p);y.diff=b,y.prev=c,y.curr=p,c=p,g[0]=o.coerce(g[0]),typeof g[0]!="string"&&g.unshift("%O");let m=0;g[0]=g[0].replace(/%([a-zA-Z%])/g,(k,A)=>{if(k==="%%")return"%";m++;const S=o.formatters[A];if(typeof S=="function"){const I=g[m];k=S.call(y,I),g.splice(m,1),m--}return k}),o.formatArgs.call(y,g),(y.log||o.log).apply(y,g)}return v.namespace=h,v.useColors=o.useColors(),v.color=o.selectColor(h),v.extend=l,v.destroy=o.destroy,Object.defineProperty(v,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(f!==o.namespaces&&(f=o.namespaces,u=o.enabled(h)),u),set:g=>{d=g}}),typeof o.init=="function"&&o.init(v),v}function l(h,c){const f=o(this.namespace+(c===void 0?":":c)+h);return f.log=this.log,f}function n(h){return h.toString().substring(2,h.toString().length-2).replace(/\.\*\?$/,"*")}return o.debug=o,o.default=o,o.coerce=function(h){return h instanceof Error?h.stack||h.message:h},o.disable=function(){const h=[...o.names.map(n),...o.skips.map(n).map(c=>"-"+c)].join(",");return o.enable(""),h},o.enable=function(h){let c;o.save(h),o.namespaces=h,o.names=[],o.skips=[];const f=(typeof h=="string"?h:"").split(/[\s,]+/),u=f.length;for(c=0;c<u;c++)f[c]&&((h=f[c].replace(/\*/g,".*?"))[0]==="-"?o.skips.push(new RegExp("^"+h.substr(1)+"$")):o.names.push(new RegExp("^"+h+"$")))},o.enabled=function(h){if(h[h.length-1]==="*")return!0;let c,f;for(c=0,f=o.skips.length;c<f;c++)if(o.skips[c].test(h))return!1;for(c=0,f=o.names.length;c<f;c++)if(o.names[c].test(h))return!0;return!1},o.humanize=i("ms"),o.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(a).forEach(h=>{o[h]=a[h]}),o.names=[],o.skips=[],o.formatters={},o.selectColor=function(h){let c=0;for(let f=0;f<h.length;f++)c=(c<<5)-c+h.charCodeAt(f),c|=0;return o.colors[Math.abs(c)%o.colors.length]},o.enable(o.load()),o}},{ms:45}],20:[function(i,s,r){(function(a,o){(function(){var l=i("readable-stream"),n=i("end-of-stream"),h=i("inherits"),c=i("stream-shift"),f=o.from&&o.from!==Uint8Array.from?o.from([0]):new o([0]),u=function(y,p){y._corked?y.once("uncork",p):p()},d=function(y,p){return function(b){b?function(m,k){m._autoDestroy&&m.destroy(k)}(y,b.message==="premature close"?null:b):p&&!y._ended&&y.end()}},v=function(){},g=function(y,p,b){if(!(this instanceof g))return new g(y,p,b);l.Duplex.call(this,b),this._writable=null,this._readable=null,this._readable2=null,this._autoDestroy=!b||b.autoDestroy!==!1,this._forwardDestroy=!b||b.destroy!==!1,this._forwardEnd=!b||b.end!==!1,this._corked=1,this._ondrain=null,this._drained=!1,this._forwarding=!1,this._unwrite=null,this._unread=null,this._ended=!1,this.destroyed=!1,y&&this.setWritable(y),p&&this.setReadable(p)};h(g,l.Duplex),g.obj=function(y,p,b){return b||(b={}),b.objectMode=!0,b.highWaterMark=16,new g(y,p,b)},g.prototype.cork=function(){++this._corked==1&&this.emit("cork")},g.prototype.uncork=function(){this._corked&&--this._corked==0&&this.emit("uncork")},g.prototype.setWritable=function(y){if(this._unwrite&&this._unwrite(),this.destroyed)y&&y.destroy&&y.destroy();else if(y!==null&&y!==!1){var p=this,b=n(y,{writable:!0,readable:!1},d(this,this._forwardEnd)),m=function(){var k=p._ondrain;p._ondrain=null,k&&k()};this._unwrite&&a.nextTick(m),this._writable=y,this._writable.on("drain",m),this._unwrite=function(){p._writable.removeListener("drain",m),b()},this.uncork()}else this.end()},g.prototype.setReadable=function(y){if(this._unread&&this._unread(),this.destroyed)y&&y.destroy&&y.destroy();else{if(y===null||y===!1)return this.push(null),void this.resume();var p,b=this,m=n(y,{writable:!1,readable:!0},d(this)),k=function(){b._forward()},A=function(){b.push(null)};this._drained=!0,this._readable=y,this._readable2=y._readableState?y:(p=y,new l.Readable({objectMode:!0,highWaterMark:16}).wrap(p)),this._readable2.on("readable",k),this._readable2.on("end",A),this._unread=function(){b._readable2.removeListener("readable",k),b._readable2.removeListener("end",A),m()},this._forward()}},g.prototype._read=function(){this._drained=!0,this._forward()},g.prototype._forward=function(){if(!this._forwarding&&this._readable2&&this._drained){var y;for(this._forwarding=!0;this._drained&&(y=c(this._readable2))!==null;)this.destroyed||(this._drained=this.push(y));this._forwarding=!1}},g.prototype.destroy=function(y,p){if(p||(p=v),this.destroyed)return p(null);this.destroyed=!0;var b=this;a.nextTick(function(){b._destroy(y),p(null)})},g.prototype._destroy=function(y){if(y){var p=this._ondrain;this._ondrain=null,p?p(y):this.emit("error",y)}this._forwardDestroy&&(this._readable&&this._readable.destroy&&this._readable.destroy(),this._writable&&this._writable.destroy&&this._writable.destroy()),this.emit("close")},g.prototype._write=function(y,p,b){if(!this.destroyed)return this._corked?u(this,this._write.bind(this,y,p,b)):y===f?this._finish(b):this._writable?void(this._writable.write(y)===!1?this._ondrain=b:this.destroyed||b()):b()},g.prototype._finish=function(y){var p=this;this.emit("preend"),u(this,function(){var b,m;b=p._forwardEnd&&p._writable,m=function(){p._writableState.prefinished===!1&&(p._writableState.prefinished=!0),p.emit("prefinish"),u(p,y)},b?b._writableState&&b._writableState.finished?m():b._writableState?b.end(m):(b.end(),m()):m()})},g.prototype.end=function(y,p,b){return typeof y=="function"?this.end(null,null,y):typeof p=="function"?this.end(y,null,p):(this._ended=!0,y&&this.write(y),this._writableState.ending||this._writableState.destroyed||this.write(f),l.Writable.prototype.end.call(this,b))},s.exports=g}).call(this)}).call(this,i("_process"),i("buffer").Buffer)},{_process:50,buffer:17,"end-of-stream":21,inherits:24,"readable-stream":69,"stream-shift":74}],21:[function(i,s,r){(function(a){(function(){var o=i("once"),l=function(){},n=function(h,c,f){if(typeof c=="function")return n(h,null,c);c||(c={}),f=o(f||l);var u=h._writableState,d=h._readableState,v=c.readable||c.readable!==!1&&h.readable,g=c.writable||c.writable!==!1&&h.writable,y=!1,p=function(){h.writable||b()},b=function(){g=!1,v||f.call(h)},m=function(){v=!1,g||f.call(h)},k=function(z){f.call(h,z?new Error("exited with error code: "+z):null)},A=function(z){f.call(h,z)},S=function(){a.nextTick(I)},I=function(){if(!y)return(!v||d&&d.ended&&!d.destroyed)&&(!g||u&&u.ended&&!u.destroyed)?void 0:f.call(h,new Error("premature close"))},E=function(){h.req.on("finish",b)};return function(z){return z.setHeader&&typeof z.abort=="function"}(h)?(h.on("complete",b),h.on("abort",S),h.req?E():h.on("request",E)):g&&!u&&(h.on("end",p),h.on("close",p)),function(z){return z.stdio&&Array.isArray(z.stdio)&&z.stdio.length===3}(h)&&h.on("exit",k),h.on("end",m),h.on("finish",b),c.error!==!1&&h.on("error",A),h.on("close",S),function(){y=!0,h.removeListener("complete",b),h.removeListener("abort",S),h.removeListener("request",E),h.req&&h.req.removeListener("finish",b),h.removeListener("end",p),h.removeListener("close",p),h.removeListener("finish",b),h.removeListener("exit",k),h.removeListener("end",m),h.removeListener("error",A),h.removeListener("close",S)}};s.exports=n}).call(this)}).call(this,i("_process"))},{_process:50,once:48}],22:[function(i,s,r){var a=Object.create||function(m){var k=function(){};return k.prototype=m,new k},o=Object.keys||function(m){var k=[];for(var A in m)Object.prototype.hasOwnProperty.call(m,A)&&k.push(A);return A},l=Function.prototype.bind||function(m){var k=this;return function(){return k.apply(m,arguments)}};function n(){this._events&&Object.prototype.hasOwnProperty.call(this,"_events")||(this._events=a(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0}s.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0;var h,c=10;try{var f={};Object.defineProperty&&Object.defineProperty(f,"x",{value:0}),h=f.x===0}catch{h=!1}function u(m){return m._maxListeners===void 0?n.defaultMaxListeners:m._maxListeners}function d(m,k,A,S){var I,E,z;if(typeof A!="function")throw new TypeError('"listener" argument must be a function');if((E=m._events)?(E.newListener&&(m.emit("newListener",k,A.listener?A.listener:A),E=m._events),z=E[k]):(E=m._events=a(null),m._eventsCount=0),z){if(typeof z=="function"?z=E[k]=S?[A,z]:[z,A]:S?z.unshift(A):z.push(A),!z.warned&&(I=u(m))&&I>0&&z.length>I){z.warned=!0;var U=new Error("Possible EventEmitter memory leak detected. "+z.length+' "'+String(k)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');U.name="MaxListenersExceededWarning",U.emitter=m,U.type=k,U.count=z.length,typeof console=="object"&&console.warn&&console.warn("%s: %s",U.name,U.message)}}else z=E[k]=A,++m._eventsCount;return m}function v(){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 m=new Array(arguments.length),k=0;k<m.length;++k)m[k]=arguments[k];this.listener.apply(this.target,m)}}function g(m,k,A){var S={fired:!1,wrapFn:void 0,target:m,type:k,listener:A},I=l.call(v,S);return I.listener=A,S.wrapFn=I,I}function y(m,k,A){var S=m._events;if(!S)return[];var I=S[k];return I?typeof I=="function"?A?[I.listener||I]:[I]:A?function(E){for(var z=new Array(E.length),U=0;U<z.length;++U)z[U]=E[U].listener||E[U];return z}(I):b(I,I.length):[]}function p(m){var k=this._events;if(k){var A=k[m];if(typeof A=="function")return 1;if(A)return A.length}return 0}function b(m,k){for(var A=new Array(k),S=0;S<k;++S)A[S]=m[S];return A}h?Object.defineProperty(n,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(m){if(typeof m!="number"||m<0||m!=m)throw new TypeError('"defaultMaxListeners" must be a positive number');c=m}}):n.defaultMaxListeners=c,n.prototype.setMaxListeners=function(m){if(typeof m!="number"||m<0||isNaN(m))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=m,this},n.prototype.getMaxListeners=function(){return u(this)},n.prototype.emit=function(m){var k,A,S,I,E,z,U=m==="error";if(z=this._events)U=U&&z.error==null;else if(!U)return!1;if(U){if(arguments.length>1&&(k=arguments[1]),k instanceof Error)throw k;var T=new Error('Unhandled "error" event. ('+k+")");throw T.context=k,T}if(!(A=z[m]))return!1;var R=typeof A=="function";switch(S=arguments.length){case 1:(function(C,_,B){if(_)C.call(B);else for(var j=C.length,X=b(C,j),F=0;F<j;++F)X[F].call(B)})(A,R,this);break;case 2:(function(C,_,B,j){if(_)C.call(B,j);else for(var X=C.length,F=b(C,X),L=0;L<X;++L)F[L].call(B,j)})(A,R,this,arguments[1]);break;case 3:(function(C,_,B,j,X){if(_)C.call(B,j,X);else for(var F=C.length,L=b(C,F),N=0;N<F;++N)L[N].call(B,j,X)})(A,R,this,arguments[1],arguments[2]);break;case 4:(function(C,_,B,j,X,F){if(_)C.call(B,j,X,F);else for(var L=C.length,N=b(C,L),W=0;W<L;++W)N[W].call(B,j,X,F)})(A,R,this,arguments[1],arguments[2],arguments[3]);break;default:for(I=new Array(S-1),E=1;E<S;E++)I[E-1]=arguments[E];(function(C,_,B,j){if(_)C.apply(B,j);else for(var X=C.length,F=b(C,X),L=0;L<X;++L)F[L].apply(B,j)})(A,R,this,I)}return!0},n.prototype.addListener=function(m,k){return d(this,m,k,!1)},n.prototype.on=n.prototype.addListener,n.prototype.prependListener=function(m,k){return d(this,m,k,!0)},n.prototype.once=function(m,k){if(typeof k!="function")throw new TypeError('"listener" argument must be a function');return this.on(m,g(this,m,k)),this},n.prototype.prependOnceListener=function(m,k){if(typeof k!="function")throw new TypeError('"listener" argument must be a function');return this.prependListener(m,g(this,m,k)),this},n.prototype.removeListener=function(m,k){var A,S,I,E,z;if(typeof k!="function")throw new TypeError('"listener" argument must be a function');if(!(S=this._events))return this;if(!(A=S[m]))return this;if(A===k||A.listener===k)--this._eventsCount==0?this._events=a(null):(delete S[m],S.removeListener&&this.emit("removeListener",m,A.listener||k));else if(typeof A!="function"){for(I=-1,E=A.length-1;E>=0;E--)if(A[E]===k||A[E].listener===k){z=A[E].listener,I=E;break}if(I<0)return this;I===0?A.shift():function(U,T){for(var R=T,C=R+1,_=U.length;C<_;R+=1,C+=1)U[R]=U[C];U.pop()}(A,I),A.length===1&&(S[m]=A[0]),S.removeListener&&this.emit("removeListener",m,z||k)}return this},n.prototype.removeAllListeners=function(m){var k,A,S;if(!(A=this._events))return this;if(!A.removeListener)return arguments.length===0?(this._events=a(null),this._eventsCount=0):A[m]&&(--this._eventsCount==0?this._events=a(null):delete A[m]),this;if(arguments.length===0){var I,E=o(A);for(S=0;S<E.length;++S)(I=E[S])!=="removeListener"&&this.removeAllListeners(I);return this.removeAllListeners("removeListener"),this._events=a(null),this._eventsCount=0,this}if(typeof(k=A[m])=="function")this.removeListener(m,k);else if(k)for(S=k.length-1;S>=0;S--)this.removeListener(m,k[S]);return this},n.prototype.listeners=function(m){return y(this,m,!0)},n.prototype.rawListeners=function(m){return y(this,m,!1)},n.listenerCount=function(m,k){return typeof m.listenerCount=="function"?m.listenerCount(k):p.call(m,k)},n.prototype.listenerCount=p,n.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],23:[function(i,s,r){r.read=function(a,o,l,n,h){var c,f,u=8*h-n-1,d=(1<<u)-1,v=d>>1,g=-7,y=l?h-1:0,p=l?-1:1,b=a[o+y];for(y+=p,c=b&(1<<-g)-1,b>>=-g,g+=u;g>0;c=256*c+a[o+y],y+=p,g-=8);for(f=c&(1<<-g)-1,c>>=-g,g+=n;g>0;f=256*f+a[o+y],y+=p,g-=8);if(c===0)c=1-v;else{if(c===d)return f?NaN:1/0*(b?-1:1);f+=Math.pow(2,n),c-=v}return(b?-1:1)*f*Math.pow(2,c-n)},r.write=function(a,o,l,n,h,c){var f,u,d,v=8*c-h-1,g=(1<<v)-1,y=g>>1,p=h===23?Math.pow(2,-24)-Math.pow(2,-77):0,b=n?0:c-1,m=n?1:-1,k=o<0||o===0&&1/o<0?1:0;for(o=Math.abs(o),isNaN(o)||o===1/0?(u=isNaN(o)?1:0,f=g):(f=Math.floor(Math.log(o)/Math.LN2),o*(d=Math.pow(2,-f))<1&&(f--,d*=2),(o+=f+y>=1?p/d:p*Math.pow(2,1-y))*d>=2&&(f++,d/=2),f+y>=g?(u=0,f=g):f+y>=1?(u=(o*d-1)*Math.pow(2,h),f+=y):(u=o*Math.pow(2,y-1)*Math.pow(2,h),f=0));h>=8;a[l+b]=255&u,b+=m,u/=256,h-=8);for(f=f<<h|u,v+=h;v>0;a[l+b]=255&f,b+=m,f/=256,v-=8);a[l+b-m]|=128*k}},{}],24:[function(i,s,r){typeof Object.create=="function"?s.exports=function(a,o){o&&(a.super_=o,a.prototype=Object.create(o.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}))}:s.exports=function(a,o){if(o){a.super_=o;var l=function(){};l.prototype=o.prototype,a.prototype=new l,a.prototype.constructor=a}}},{}],25:[function(i,s,r){Object.defineProperty(r,"__esModule",{value:!0});var a=function(){function o(l,n){this.color=!0,this.key=void 0,this.value=void 0,this.parent=void 0,this.brother=void 0,this.leftChild=void 0,this.rightChild=void 0,this.key=l,this.value=n}return o.prototype.rotateLeft=function(){var l=this.parent,n=this.brother,h=this.leftChild,c=this.rightChild;if(!c)throw new Error("unknown error");var f=c.leftChild,u=c.rightChild;return l&&(l.leftChild===this?l.leftChild=c:l.rightChild===this&&(l.rightChild=c)),c.parent=l,c.brother=n,c.leftChild=this,c.rightChild=u,n&&(n.brother=c),this.parent=c,this.brother=u,this.leftChild=h,this.rightChild=f,u&&(u.parent=c,u.brother=this),h&&(h.parent=this,h.brother=f),f&&(f.parent=this,f.brother=h),c},o.prototype.rotateRight=function(){var l=this.parent,n=this.brother,h=this.leftChild;if(!h)throw new Error("unknown error");var c=this.rightChild,f=h.leftChild,u=h.rightChild;return l&&(l.leftChild===this?l.leftChild=h:l.rightChild===this&&(l.rightChild=h)),h.parent=l,h.brother=n,h.leftChild=f,h.rightChild=this,n&&(n.brother=h),f&&(f.parent=h,f.brother=this),this.parent=h,this.brother=f,this.leftChild=u,this.rightChild=c,u&&(u.parent=this,u.brother=c),c&&(c.parent=this,c.brother=u),h},o.prototype.remove=function(){if(this.leftChild||this.rightChild)throw new Error("can only remove leaf node");this.parent&&(this===this.parent.leftChild?this.parent.leftChild=void 0:this===this.parent.rightChild&&(this.parent.rightChild=void 0)),this.brother&&(this.brother.brother=void 0),this.key=void 0,this.value=void 0,this.parent=void 0,this.brother=void 0},o.TreeNodeColorType={red:!0,black:!1},o}();Object.freeze(a),r.default=a},{}],26:[function(i,s,r){var a=this&&this.__generator||function(l,n){var h,c,f,u,d={label:0,sent:function(){if(1&f[0])throw f[1];return f[1]},trys:[],ops:[]};return u={next:v(0),throw:v(1),return:v(2)},typeof Symbol=="function"&&(u[Symbol.iterator]=function(){return this}),u;function v(g){return function(y){return function(p){if(h)throw new TypeError("Generator is already executing.");for(;d;)try{if(h=1,c&&(f=2&p[0]?c.return:p[0]?c.throw||((f=c.return)&&f.call(c),0):c.next)&&!(f=f.call(c,p[1])).done)return f;switch(c=0,f&&(p=[2&p[0],f.value]),p[0]){case 0:case 1:f=p;break;case 4:return d.label++,{value:p[1],done:!1};case 5:d.label++,c=p[1],p=[0];continue;case 7:p=d.ops.pop(),d.trys.pop();continue;default:if(!(f=(f=d.trys).length>0&&f[f.length-1])&&(p[0]===6||p[0]===2)){d=0;continue}if(p[0]===3&&(!f||p[1]>f[0]&&p[1]<f[3])){d.label=p[1];break}if(p[0]===6&&d.label<f[1]){d.label=f[1],f=p;break}if(f&&d.label<f[2]){d.label=f[2],d.ops.push(p);break}f[2]&&d.ops.pop(),d.trys.pop();continue}p=n.call(l,d)}catch(b){p=[6,b],c=0}finally{h=f=0}if(5&p[0])throw p[1];return{value:p[0]?p[1]:void 0,done:!0}}([g,y])}}};function o(l){var n=this;l===void 0&&(l=[]);var h=[],c=0,f=0,u=0,d=0,v=0,g=0;this.size=function(){return g},this.empty=function(){return g===0},this.clear=function(){c=u=f=d=v=g=0,p.call(this,o.bucketSize),g=0},this.front=function(){return h[c][f]},this.back=function(){return h[u][d]},this.forEach=function(b){if(!this.empty()){var m=0;if(c!==u){for(A=f;A<o.bucketSize;++A)b(h[c][A],m++);for(A=c+1;A<u;++A)for(var k=0;k<o.bucketSize;++k)b(h[A][k],m++);for(A=0;A<=d;++A)b(h[u][A],m++)}else for(var A=f;A<=d;++A)b(h[c][A],m++)}};var y=function(b){var m=c*o.bucketSize+f,k=m+b,A=u*o.bucketSize+d;if(k<m||k>A)throw new Error("pos should more than 0 and less than queue's size");return{curNodeBucketIndex:Math.floor(k/o.bucketSize),curNodePointerIndex:k%o.bucketSize}};this.getElementByPos=function(b){var m=y(b),k=m.curNodeBucketIndex,A=m.curNodePointerIndex;return h[k][A]},this.eraseElementByPos=function(b){var m=this;if(b<0||b>g)throw new Error("pos should more than 0 and less than queue's size");if(b===0)this.popFront();else if(b===this.size())this.popBack();else{for(var k=[],A=b+1;A<g;++A)k.push(this.getElementByPos(A));this.cut(b),this.popBack(),k.forEach(function(S){return m.pushBack(S)})}},this.eraseElementByValue=function(b){if(!this.empty()){var m=[];this.forEach(function(S){S!==b&&m.push(S)});for(var k=m.length,A=0;A<k;++A)this.setElementByPos(A,m[A]);this.cut(k-1)}};var p=function(b){for(var m=[],k=b*o.sigma,A=Math.max(Math.ceil(k/o.bucketSize),2),S=0;S<A;++S)m.push(new Array(o.bucketSize));var I=Math.ceil(b/o.bucketSize),E=Math.floor(A/2)-Math.floor(I/2),z=E,U=0;if(this.size())for(S=0;S<I;++S){for(var T=0;T<o.bucketSize;++T)if(m[E+S][T]=this.front(),this.popFront(),this.empty()){z=E+S,U=T;break}if(this.empty())break}h=m,c=E,f=0,u=z,d=U,v=A,g=b};this.pushBack=function(b){this.empty()||(u===v-1&&d===o.bucketSize-1&&p.call(this,this.size()),d<o.bucketSize-1?++d:u<v-1&&(++u,d=0)),++g,h[u][d]=b},this.popBack=function(){this.empty()||(this.size()!==1&&(d>0?--d:c<u&&(--u,d=o.bucketSize-1)),g>0&&--g)},this.setElementByPos=function(b,m){var k=y(b),A=k.curNodeBucketIndex,S=k.curNodePointerIndex;h[A][S]=m},this.insert=function(b,m,k){var A=this;if(k===void 0&&(k=1),b===0)for(;k--;)this.pushFront(m);else if(b===this.size())for(;k--;)this.pushBack(m);else{for(var S=[],I=b;I<g;++I)S.push(this.getElementByPos(I));for(this.cut(b-1),I=0;I<k;++I)this.pushBack(m);S.forEach(function(E){return A.pushBack(E)})}},this.find=function(b){if(c===u){for(var m=f;m<=d;++m)if(h[c][m]===b)return!0;return!1}for(m=f;m<o.bucketSize;++m)if(h[c][m]===b)return!0;for(m=c+1;m<u;++m)for(var k=0;k<o.bucketSize;++k)if(h[m][k]===b)return!0;for(m=0;m<=d;++m)if(h[u][m]===b)return!0;return!1},this.reverse=function(){for(var b=0,m=g-1;b<m;){var k=this.getElementByPos(b);this.setElementByPos(b,this.getElementByPos(m)),this.setElementByPos(m,k),++b,--m}},this.unique=function(){if(!this.empty()){var b=[],m=this.front();this.forEach(function(A,S){S!==0&&A===m||(b.push(A),m=A)});for(var k=0;k<g;++k)this.setElementByPos(k,b[k]);this.cut(b.length-1)}},this.sort=function(b){var m=[];this.forEach(function(A){m.push(A)}),m.sort(b);for(var k=0;k<g;++k)this.setElementByPos(k,m[k])},this.pushFront=function(b){this.empty()||(c===0&&f===0&&p.call(this,this.size()),f>0?--f:c>0&&(--c,f=o.bucketSize-1)),++g,h[c][f]=b},this.popFront=function(){this.empty()||(this.size()!==1&&(f<o.bucketSize-1?++f:c<u&&(++c,f=0)),g>0&&--g)},this.shrinkToFit=function(){var b=this,m=[];this.forEach(function(I){m.push(I)});var k=m.length;h=[];for(var A=Math.ceil(k/o.bucketSize),S=0;S<A;++S)h.push(new Array(o.bucketSize));this.clear(),m.forEach(function(I){return b.pushBack(I)})},this.cut=function(b){if(b<0)this.clear();else{var m=y(b),k=m.curNodeBucketIndex,A=m.curNodePointerIndex;u=k,d=A,g=b+1}},this[Symbol.iterator]=function(){return function(){var b,m;return a(this,function(k){switch(k.label){case 0:if(g===0)return[2];if(c!==u)return[3,5];m=f,k.label=1;case 1:return m<=d?[4,h[c][m]]:[3,4];case 2:k.sent(),k.label=3;case 3:return++m,[3,1];case 4:return[2];case 5:m=f,k.label=6;case 6:return m<o.bucketSize?[4,h[c][m]]:[3,9];case 7:k.sent(),k.label=8;case 8:return++m,[3,6];case 9:m=c+1,k.label=10;case 10:if(!(m<u))return[3,15];b=0,k.label=11;case 11:return b<o.bucketSize?[4,h[m][b]]:[3,14];case 12:k.sent(),k.label=13;case 13:return++b,[3,11];case 14:return++m,[3,10];case 15:m=0,k.label=16;case 16:return m<=d?[4,h[u][m]]:[3,19];case 17:k.sent(),k.label=18;case 18:return++m,[3,16];case 19:return[2]}})}()},function(){var b=o.bucketSize;l.size?b=l.size():l.length&&(b=l.length);var m=b*o.sigma;v=Math.ceil(m/o.bucketSize),v=Math.max(v,3);for(var k=0;k<v;++k)h.push(new Array(o.bucketSize));var A=Math.ceil(b/o.bucketSize);c=Math.floor(v/2)-Math.floor(A/2),u=c,l.forEach(function(S){return n.pushBack(S)})}(),Object.freeze(this)}Object.defineProperty(r,"__esModule",{value:!0}),o.sigma=3,o.bucketSize=5e3,Object.freeze(o),r.default=o},{}],27:[function(i,s,r){var a=this&&this.__generator||function(c,f){var u,d,v,g,y={label:0,sent:function(){if(1&v[0])throw v[1];return v[1]},trys:[],ops:[]};return g={next:p(0),throw:p(1),return:p(2)},typeof Symbol=="function"&&(g[Symbol.iterator]=function(){return this}),g;function p(b){return function(m){return function(k){if(u)throw new TypeError("Generator is already executing.");for(;y;)try{if(u=1,d&&(v=2&k[0]?d.return:k[0]?d.throw||((v=d.return)&&v.call(d),0):d.next)&&!(v=v.call(d,k[1])).done)return v;switch(d=0,v&&(k=[2&k[0],v.value]),k[0]){case 0:case 1:v=k;break;case 4:return y.label++,{value:k[1],done:!1};case 5:y.label++,d=k[1],k=[0];continue;case 7:k=y.ops.pop(),y.trys.pop();continue;default:if(!(v=(v=y.trys).length>0&&v[v.length-1])&&(k[0]===6||k[0]===2)){y=0;continue}if(k[0]===3&&(!v||k[1]>v[0]&&k[1]<v[3])){y.label=k[1];break}if(k[0]===6&&y.label<v[1]){y.label=v[1],v=k;break}if(v&&y.label<v[2]){y.label=v[2],y.ops.push(k);break}v[2]&&y.ops.pop(),y.trys.pop();continue}k=f.call(c,y)}catch(A){k=[6,A],d=0}finally{u=v=0}if(5&k[0])throw k[1];return{value:k[0]?k[1]:void 0,done:!0}}([b,m])}}},o=this&&this.__values||function(c){var f=typeof Symbol=="function"&&Symbol.iterator,u=f&&c[f],d=0;if(u)return u.call(c);if(c&&typeof c.length=="number")return{next:function(){return c&&d>=c.length&&(c=void 0),{value:c&&c[d++],done:!c}}};throw new TypeError(f?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var l=i("../LinkList/LinkList"),n=i("../Map/Map");function h(c,f,u){var d=this;if(c===void 0&&(c=[]),f===void 0&&(f=h.initSize),u=u||function(p){var b,m,k=0,A="";if(typeof p=="number")k=((k=Math.floor(p))<<5)-k,k&=k;else{A=typeof p!="string"?JSON.stringify(p):p;try{for(var S=o(A),I=S.next();!I.done;I=S.next())k=(k<<5)-k+I.value.charCodeAt(0),k&=k}catch(E){b={error:E}}finally{try{I&&!I.done&&(m=S.return)&&m.call(S)}finally{if(b)throw b.error}}}return k^=k>>>16},(f&f-1)!=0)throw new Error("initBucketNum must be 2 to the power of n");var v=0,g=[],y=Math.max(h.initSize,Math.min(h.maxSize,f));this.size=function(){return v},this.empty=function(){return v===0},this.clear=function(){v=0,y=f,g=[]},this.forEach=function(p){var b=0;g.forEach(function(m){m.forEach(function(k){p(k,b++)})})},this.setElement=function(p,b){var m,k;if(p==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(b!=null){var A=u(p)&y-1;if(g[A]){var S=g[A].size();if(g[A]instanceof l.default){try{for(var I=o(g[A]),E=I.next();!E.done;E=I.next()){var z=E.value;if(z.key===p)return void(z.value=b)}}catch(T){m={error:T}}finally{try{E&&!E.done&&(k=I.return)&&k.call(I)}finally{if(m)throw m.error}}g[A].pushBack({key:p,value:b}),g[A].size()>=h.treeifyThreshold&&(g[A]=new n.default(g[A]))}else g[A].setElement(p,b);var U=g[A].size();v+=U-S}else++v,g[A]=new l.default([{key:p,value:b}]);v>y*h.sigma&&(function(T){if(!(T>=h.maxSize)){y=2*T;var R=[];g.forEach(function(C,_){if(!C.empty()){if(C instanceof l.default&&C.size()===1){var B=C.front(),j=B.key,X=B.value;R[u(j)&y-1]=new l.default([{key:j,value:X}])}else if(C instanceof n.default){var F=new l.default,L=new l.default;C.forEach(function(O){u(O.key)&T?L.pushBack(O):F.pushBack(O)}),F.size()>h.untreeifyThreshold?R[_]=new n.default(F):F.size()&&(R[_]=F),L.size()>h.untreeifyThreshold?R[_+T]=new n.default(L):L.size()&&(R[_+T]=L)}else{var N=new l.default,W=new l.default;C.forEach(function(O){u(O.key)&T?W.pushBack(O):N.pushBack(O)}),N.size()&&(R[_]=N),W.size()&&(R[_+T]=W)}g[_].clear()}}),g=R}}).call(this,y)}else this.eraseElementByKey(p)},this.getElementByKey=function(p){var b,m,k=u(p)&y-1;if(g[k]){if(g[k]instanceof n.default)return g[k].getElementByKey(p);try{for(var A=o(g[k]),S=A.next();!S.done;S=A.next()){var I=S.value;if(I.key===p)return I.value}}catch(E){b={error:E}}finally{try{S&&!S.done&&(m=A.return)&&m.call(A)}finally{if(b)throw b.error}}}},this.eraseElementByKey=function(p){var b,m,k=u(p)&y-1;if(g[k]){var A=g[k].size();if(g[k]instanceof n.default)g[k].eraseElementByKey(p),g[k].size()<=h.untreeifyThreshold&&(g[k]=new l.default(g[k]));else{var S=-1;try{for(var I=o(g[k]),E=I.next();!E.done;E=I.next())if(++S,E.value.key===p){g[k].eraseElementByPos(S);break}}catch(U){b={error:U}}finally{try{E&&!E.done&&(m=I.return)&&m.call(I)}finally{if(b)throw b.error}}}var z=g[k].size();v+=z-A}},this.find=function(p){var b,m,k=u(p)&y-1;if(!g[k])return!1;if(g[k]instanceof n.default)return g[k].find(p);try{for(var A=o(g[k]),S=A.next();!S.done;S=A.next())if(S.value.key===p)return!0}catch(I){b={error:I}}finally{try{S&&!S.done&&(m=A.return)&&m.call(A)}finally{if(b)throw b.error}}return!1},this[Symbol.iterator]=function(){return function(){var p,b,m,k,A,S;return a(this,function(I){switch(I.label){case 0:p=0,I.label=1;case 1:if(!(p<y))return[3,10];for(;p<y&&!g[p];)++p;if(p>=y)return[3,10];I.label=2;case 2:I.trys.push([2,7,8,9]),A=void 0,b=o(g[p]),m=b.next(),I.label=3;case 3:return m.done?[3,6]:[4,m.value];case 4:I.sent(),I.label=5;case 5:return m=b.next(),[3,3];case 6:return[3,9];case 7:return k=I.sent(),A={error:k},[3,9];case 8:try{m&&!m.done&&(S=b.return)&&S.call(b)}finally{if(A)throw A.error}return[7];case 9:return++p,[3,1];case 10:return[2]}})}()},c.forEach(function(p){var b=p.key,m=p.value;return d.setElement(b,m)}),Object.freeze(this)}h.initSize=16,h.maxSize=1<<30,h.sigma=.75,h.treeifyThreshold=8,h.untreeifyThreshold=6,h.minTreeifySize=64,Object.freeze(h),r.default=h},{"../LinkList/LinkList":29,"../Map/Map":30}],28:[function(i,s,r){var a=this&&this.__generator||function(c,f){var u,d,v,g,y={label:0,sent:function(){if(1&v[0])throw v[1];return v[1]},trys:[],ops:[]};return g={next:p(0),throw:p(1),return:p(2)},typeof Symbol=="function"&&(g[Symbol.iterator]=function(){return this}),g;function p(b){return function(m){return function(k){if(u)throw new TypeError("Generator is already executing.");for(;y;)try{if(u=1,d&&(v=2&k[0]?d.return:k[0]?d.throw||((v=d.return)&&v.call(d),0):d.next)&&!(v=v.call(d,k[1])).done)return v;switch(d=0,v&&(k=[2&k[0],v.value]),k[0]){case 0:case 1:v=k;break;case 4:return y.label++,{value:k[1],done:!1};case 5:y.label++,d=k[1],k=[0];continue;case 7:k=y.ops.pop(),y.trys.pop();continue;default:if(!(v=(v=y.trys).length>0&&v[v.length-1])&&(k[0]===6||k[0]===2)){y=0;continue}if(k[0]===3&&(!v||k[1]>v[0]&&k[1]<v[3])){y.label=k[1];break}if(k[0]===6&&y.label<v[1]){y.label=v[1],v=k;break}if(v&&y.label<v[2]){y.label=v[2],y.ops.push(k);break}v[2]&&y.ops.pop(),y.trys.pop();continue}k=f.call(c,y)}catch(A){k=[6,A],d=0}finally{u=v=0}if(5&k[0])throw k[1];return{value:k[0]?k[1]:void 0,done:!0}}([b,m])}}},o=this&&this.__values||function(c){var f=typeof Symbol=="function"&&Symbol.iterator,u=f&&c[f],d=0;if(u)return u.call(c);if(c&&typeof c.length=="number")return{next:function(){return c&&d>=c.length&&(c=void 0),{value:c&&c[d++],done:!c}}};throw new TypeError(f?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var l=i("../Set/Set"),n=i("../LinkList/LinkList");function h(c,f,u){var d=this;if(c===void 0&&(c=[]),f===void 0&&(f=h.initSize),u=u||function(p){var b=0,m="";if(typeof p=="number")b=((b=Math.floor(p))<<5)-b,b&=b;else{m=typeof p!="string"?JSON.stringify(p):p;for(var k=0;k<m.length;k++)b=(b<<5)-b+m.charCodeAt(k),b&=b}return b^=b>>>16},(f&f-1)!=0)throw new Error("initBucketNum must be 2 to the power of n");var v=0,g=[],y=Math.max(h.initSize,Math.min(h.maxSize,f));this.size=function(){return v},this.empty=function(){return v===0},this.clear=function(){v=0,y=f,g=[]},this.forEach=function(p){var b=0;g.forEach(function(m){m.forEach(function(k){p(k,b++)})})},this.insert=function(p){if(p==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");var b=u(p)&y-1;if(g[b]){var m=g[b].size();if(g[b]instanceof n.default){if(g[b].find(p))return;g[b].pushBack(p),g[b].size()>=h.treeifyThreshold&&(g[b]=new l.default(g[b]))}else g[b].insert(p);var k=g[b].size();v+=k-m}else g[b]=new n.default([p]),++v;v>y*h.sigma&&(function(A){if(!(A>=h.maxSize)){y=2*A;var S=[];g.forEach(function(I,E){if(!I.empty()){if(I instanceof n.default&&I.size()===1){var z=I.front();if(z===void 0)throw new Error("unknown error");S[u(z)&y-1]=new n.default([z])}else if(I instanceof l.default){var U=new n.default,T=new n.default;I.forEach(function(_){u(_)&A?T.pushBack(_):U.pushBack(_)}),U.size()>h.untreeifyThreshold?S[E]=new l.default(U):U.size()&&(S[E]=U),T.size()>h.untreeifyThreshold?S[E+A]=new l.default(T):T.size()&&(S[E+A]=T)}else{var R=new n.default,C=new n.default;I.forEach(function(_){u(_)&A?C.pushBack(_):R.pushBack(_)}),R.size()&&(S[E]=R),C.size()&&(S[E+A]=C)}g[E].clear()}}),g=S}}).call(this,y)},this.eraseElementByValue=function(p){var b=u(p)&y-1;if(g[b]){var m=g[b].size();g[b].eraseElementByValue(p),g[b]instanceof l.default&&g[b].size()<=h.untreeifyThreshold&&(g[b]=new n.default(g[b]));var k=g[b].size();v+=k-m}},this.find=function(p){var b=u(p)&y-1;return!!g[b]&&g[b].find(p)},this[Symbol.iterator]=function(){return function(){var p,b,m,k,A,S;return a(this,function(I){switch(I.label){case 0:p=0,I.label=1;case 1:if(!(p<y))return[3,10];for(;p<y&&!g[p];)++p;if(p>=y)return[3,10];I.label=2;case 2:I.trys.push([2,7,8,9]),A=void 0,b=o(g[p]),m=b.next(),I.label=3;case 3:return m.done?[3,6]:[4,m.value];case 4:I.sent(),I.label=5;case 5:return m=b.next(),[3,3];case 6:return[3,9];case 7:return k=I.sent(),A={error:k},[3,9];case 8:try{m&&!m.done&&(S=b.return)&&S.call(b)}finally{if(A)throw A.error}return[7];case 9:return++p,[3,1];case 10:return[2]}})}()},c.forEach(function(p){return d.insert(p)}),Object.freeze(this)}h.initSize=16,h.maxSize=1<<30,h.sigma=.75,h.treeifyThreshold=8,h.untreeifyThreshold=6,h.minTreeifySize=64,Object.freeze(h),r.default=h},{"../LinkList/LinkList":29,"../Set/Set":33}],29:[function(i,s,r){var a=this&&this.__generator||function(n,h){var c,f,u,d,v={label:0,sent:function(){if(1&u[0])throw u[1];return u[1]},trys:[],ops:[]};return d={next:g(0),throw:g(1),return:g(2)},typeof Symbol=="function"&&(d[Symbol.iterator]=function(){return this}),d;function g(y){return function(p){return function(b){if(c)throw new TypeError("Generator is already executing.");for(;v;)try{if(c=1,f&&(u=2&b[0]?f.return:b[0]?f.throw||((u=f.return)&&u.call(f),0):f.next)&&!(u=u.call(f,b[1])).done)return u;switch(f=0,u&&(b=[2&b[0],u.value]),b[0]){case 0:case 1:u=b;break;case 4:return v.label++,{value:b[1],done:!1};case 5:v.label++,f=b[1],b=[0];continue;case 7:b=v.ops.pop(),v.trys.pop();continue;default:if(!(u=(u=v.trys).length>0&&u[u.length-1])&&(b[0]===6||b[0]===2)){v=0;continue}if(b[0]===3&&(!u||b[1]>u[0]&&b[1]<u[3])){v.label=b[1];break}if(b[0]===6&&v.label<u[1]){v.label=u[1],u=b;break}if(u&&v.label<u[2]){v.label=u[2],v.ops.push(b);break}u[2]&&v.ops.pop(),v.trys.pop();continue}b=h.call(n,v)}catch(m){b=[6,m],f=0}finally{c=u=0}if(5&b[0])throw b[1];return{value:b[0]?b[1]:void 0,done:!0}}([y,p])}}};Object.defineProperty(r,"__esModule",{value:!0});var o=function(){return function(n){this.value=void 0,this.pre=void 0,this.next=void 0,this.value=n}}();function l(n){var h=this;n===void 0&&(n=[]);var c=0,f=void 0,u=void 0;this.size=function(){return c},this.empty=function(){return c===0},this.clear=function(){f=u=void 0,c=0},this.front=function(){return f==null?void 0:f.value},this.back=function(){return u==null?void 0:u.value},this.forEach=function(d){for(var v=f,g=0;v;){if(v.value===void 0)throw new Error("unknown error");d(v.value,g++),v=v.next}},this.getElementByPos=function(d){if(d<0||d>=c)throw new Error("pos must more then 0 and less then the list length");for(var v=f;d--&&v;)v=v.next;if(!v||v.value===void 0)throw new Error("unknown error");return v.value},this.eraseElementByPos=function(d){if(d<0||d>=c)throw new Error("erase pos must more then 0 and less then the list length");if(d===0)this.popFront();else if(d===c-1)this.popBack();else{for(var v=f;d--;){if(!(v!=null&&v.next))throw new Error("unknown error");v=v.next}if(!v||!v.pre||!v.next)throw new Error("unknown error");var g=v.pre,y=v.next;y.pre=g,g.next=y,c>0&&--c}},this.eraseElementByValue=function(d){for(;f&&f.value===d;)this.popFront();for(;u&&u.value===d;)this.popBack();if(f)for(var v=f;v;){if(v.value===d){var g=v.pre,y=v.next;y&&(y.pre=g),g&&(g.next=y),c>0&&--c}v=v.next}},this.pushBack=function(d){if(d==null)throw new Error("you can't push null or undefined here");++c;var v=new o(d);u?(u.next=v,v.pre=u,u=v):f=u=v},this.popBack=function(){u&&(c>0&&--c,u&&(f===u?f=u=void 0:(u=u.pre)&&(u.next=void 0)))},this.setElementByPos=function(d,v){if(v==null)throw new Error("you can't set null or undefined here");if(d<0||d>=c)throw new Error("pos must more then 0 and less then the list length");for(var g=f;d--;){if(!g)throw new Error("unknown error");g=g.next}g&&(g.value=v)},this.insert=function(d,v,g){if(g===void 0&&(g=1),v==null)throw new Error("you can't insert null or undefined here");if(d<0||d>c)throw new Error("insert pos must more then 0 and less then or equal to the list length");if(g<0)throw new Error("insert size must more than 0");if(d===0)for(;g--;)this.pushFront(v);else if(d===c)for(;g--;)this.pushBack(v);else{for(var y=f,p=1;p<d;++p){if(!(y!=null&&y.next))throw new Error("unknown error");y=y==null?void 0:y.next}if(!y)throw new Error("unknown error");var b=y.next;for(c+=g;g--;)y.next=new o(v),y.next.pre=y,y=y.next;y.next=b,b&&(b.pre=y)}},this.find=function(d){for(var v=f;v;){if(v.value===d)return!0;v=v.next}return!1},this.reverse=function(){for(var d=f,v=u,g=0;d&&v&&2*g<c;){var y=d.value;d.value=v.value,v.value=y,d=d.next,v=v.pre,++g}},this.unique=function(){for(var d=f;d;){for(var v=d;v&&v.next&&v.value===v.next.value;)v=v.next,c>0&&--c;d.next=v.next,d.next&&(d.next.pre=d),d=d.next}},this.sort=function(d){var v=[];this.forEach(function(y){v.push(y)}),v.sort(d);var g=f;v.forEach(function(y){g&&(g.value=y,g=g.next)})},this.pushFront=function(d){if(d==null)throw new Error("you can't push null or undefined here");++c;var v=new o(d);f?(v.next=f,f.pre=v,f=v):f=u=v},this.popFront=function(){f&&(c>0&&--c,f&&(f===u?f=u=void 0:(f=f.next)&&(f.pre=void 0)))},this.merge=function(d){var v=this,g=f;d.forEach(function(y){for(;g&&g.value!==void 0&&g.value<=y;)g=g.next;if(g===void 0)v.pushBack(y),g=u;else if(g===f)v.pushFront(y),g=f;else{++c;var p=g.pre;p&&(p.next=new o(y),p.next.pre=p,p.next.next=g,g&&(g.pre=p.next))}})},this[Symbol.iterator]=function(){return function(){var d;return a(this,function(v){switch(v.label){case 0:d=f,v.label=1;case 1:if(d===void 0)return[3,3];if(!d.value)throw new Error("unknown error");return[4,d.value];case 2:return v.sent(),d=d.next,[3,1];case 3:return[2]}})}()},n.forEach(function(d){return h.pushBack(d)}),Object.freeze(this)}Object.freeze(l),r.default=l},{}],30:[function(i,s,r){var a=this&&this.__generator||function(h,c){var f,u,d,v,g={label:0,sent:function(){if(1&d[0])throw d[1];return d[1]},trys:[],ops:[]};return v={next:y(0),throw:y(1),return:y(2)},typeof Symbol=="function"&&(v[Symbol.iterator]=function(){return this}),v;function y(p){return function(b){return function(m){if(f)throw new TypeError("Generator is already executing.");for(;g;)try{if(f=1,u&&(d=2&m[0]?u.return:m[0]?u.throw||((d=u.return)&&d.call(u),0):u.next)&&!(d=d.call(u,m[1])).done)return d;switch(u=0,d&&(m=[2&m[0],d.value]),m[0]){case 0:case 1:d=m;break;case 4:return g.label++,{value:m[1],done:!1};case 5:g.label++,u=m[1],m=[0];continue;case 7:m=g.ops.pop(),g.trys.pop();continue;default:if(!(d=(d=g.trys).length>0&&d[d.length-1])&&(m[0]===6||m[0]===2)){g=0;continue}if(m[0]===3&&(!d||m[1]>d[0]&&m[1]<d[3])){g.label=m[1];break}if(m[0]===6&&g.label<d[1]){g.label=d[1],d=m;break}if(d&&g.label<d[2]){g.label=d[2],g.ops.push(m);break}d[2]&&g.ops.pop(),g.trys.pop();continue}m=c.call(h,g)}catch(k){m=[6,k],u=0}finally{f=d=0}if(5&m[0])throw m[1];return{value:m[0]?m[1]:void 0,done:!0}}([p,b])}}},o=this&&this.__values||function(h){var c=typeof Symbol=="function"&&Symbol.iterator,f=c&&h[c],u=0;if(f)return f.call(h);if(h&&typeof h.length=="number")return{next:function(){return h&&u>=h.length&&(h=void 0),{value:h&&h[u++],done:!h}}};throw new TypeError(c?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var l=i("../Base/TreeNode");function n(h,c){var f=this;h===void 0&&(h=[]),c=c||function(T,R){return T<R?-1:T>R?1:0};var u=0,d=new l.default;d.color=l.default.TreeNodeColorType.black,this.size=function(){return u},this.empty=function(){return u===0},this.clear=function(){u=0,d.key=d.value=void 0,d.leftChild=d.rightChild=d.brother=void 0};var v=function(T){if(!T||T.key===void 0)throw new Error("unknown error");return T.leftChild?v(T.leftChild):T},g=function(T){if(!T||T.key===void 0)throw new Error("unknown error");return T.rightChild?g(T.rightChild):T};this.front=function(){if(!this.empty()){var T=v(d);if(T.key===void 0||T.value===void 0)throw new Error("unknown error");return{key:T.key,value:T.value}}},this.back=function(){if(!this.empty()){var T=g(d);if(T.key===void 0||T.value===void 0)throw new Error("unknown error");return{key:T.key,value:T.value}}},this.forEach=function(T){var R,C,_=0;try{for(var B=o(this),j=B.next();!j.done;j=B.next())T(j.value,_++)}catch(X){R={error:X}}finally{try{j&&!j.done&&(C=B.return)&&C.call(B)}finally{if(R)throw R.error}}},this.getElementByPos=function(T){var R,C;if(T<0||T>=this.size())throw new Error("pos must more than 0 and less than set's size");var _=0;try{for(var B=o(this),j=B.next();!j.done;j=B.next()){var X=j.value;if(_===T)return X;++_}}catch(F){R={error:F}}finally{try{j&&!j.done&&(C=B.return)&&C.call(B)}finally{if(R)throw R.error}}throw new Error("unknown Error")};var y=function(T,R){if(T&&T.key!==void 0&&T.value!==void 0){var C=c(T.key,R);return C===0?{key:T.key,value:T.value}:C<0?y(T.rightChild,R):y(T.leftChild,R)||{key:T.key,value:T.value}}};this.lowerBound=function(T){return y(d,T)};var p=function(T,R){if(T&&T.key!==void 0&&T.value!==void 0)return c(T.key,R)<=0?p(T.rightChild,R):p(T.leftChild,R)||{key:T.key,value:T.value}};this.upperBound=function(T){return p(d,T)};var b=function(T,R){if(T&&T.key!==void 0&&T.value!==void 0){var C=c(T.key,R);return C===0?{key:T.key,value:T.value}:C>0?b(T.leftChild,R):b(T.rightChild,R)||{key:T.key,value:T.value}}};this.reverseLowerBound=function(T){return b(d,T)};var m=function(T,R){if(T&&T.key!==void 0&&T.value!==void 0)return c(T.key,R)>=0?m(T.leftChild,R):m(T.rightChild,R)||{key:T.key,value:T.value}};this.reverseUpperBound=function(T){return m(d,T)};var k=function(T){var R=T.parent;if(!R){if(T===d)return;throw new Error("unknown error")}if(T.color!==l.default.TreeNodeColorType.red){var C=T.brother;if(!C)throw new Error("unknown error");if(T===R.leftChild)if(C.color===l.default.TreeNodeColorType.red){C.color=l.default.TreeNodeColorType.black,R.color=l.default.TreeNodeColorType.red;var _=R.rotateLeft();d===R&&(d=_),k(T)}else C.color===l.default.TreeNodeColorType.black&&(C.rightChild&&C.rightChild.color===l.default.TreeNodeColorType.red?(C.color=R.color,R.color=l.default.TreeNodeColorType.black,C.rightChild&&(C.rightChild.color=l.default.TreeNodeColorType.black),_=R.rotateLeft(),d===R&&(d=_),T.color=l.default.TreeNodeColorType.black):C.rightChild&&C.rightChild.color!==l.default.TreeNodeColorType.black||!C.leftChild||C.leftChild.color!==l.default.TreeNodeColorType.red?C.leftChild&&C.leftChild.color!==l.default.TreeNodeColorType.black||C.rightChild&&C.rightChild.color!==l.default.TreeNodeColorType.black||(C.color=l.default.TreeNodeColorType.red,k(R)):(C.color=l.default.TreeNodeColorType.red,C.leftChild&&(C.leftChild.color=l.default.TreeNodeColorType.black),_=C.rotateRight(),d===C&&(d=_),k(T)));else T===R.rightChild&&(C.color===l.default.TreeNodeColorType.red?(C.color=l.default.TreeNodeColorType.black,R.color=l.default.TreeNodeColorType.red,_=R.rotateRight(),d===R&&(d=_),k(T)):C.color===l.default.TreeNodeColorType.black&&(C.leftChild&&C.leftChild.color===l.default.TreeNodeColorType.red?(C.color=R.color,R.color=l.default.TreeNodeColorType.black,C.leftChild&&(C.leftChild.color=l.default.TreeNodeColorType.black),_=R.rotateRight(),d===R&&(d=_),T.color=l.default.TreeNodeColorType.black):C.leftChild&&C.leftChild.color!==l.default.TreeNodeColorType.black||!C.rightChild||C.rightChild.color!==l.default.TreeNodeColorType.red?C.leftChild&&C.leftChild.color!==l.default.TreeNodeColorType.black||C.rightChild&&C.rightChild.color!==l.default.TreeNodeColorType.black||(C.color=l.default.TreeNodeColorType.red,k(R)):(C.color=l.default.TreeNodeColorType.red,C.rightChild&&(C.rightChild.color=l.default.TreeNodeColorType.black),_=C.rotateLeft(),d===C&&(d=_),k(T))))}else T.color=l.default.TreeNodeColorType.black},A=function(T){for(var R=T;R.leftChild||R.rightChild;){if(R.rightChild){R=v(R.rightChild);var C=T.key;T.key=R.key,R.key=C;var _=T.value;T.value=R.value,R.value=_,T=R}R.leftChild&&(R=g(R.leftChild),C=T.key,T.key=R.key,R.key=C,_=T.value,T.value=R.value,R.value=_,T=R)}k(R),R&&R.remove(),--u,d.color=l.default.TreeNodeColorType.black},S=function(T,R){return!(!T||T.key===void 0)&&(!!S(T.leftChild,R)||!!R(T)||S(T.rightChild,R))};this.eraseElementByPos=function(T){if(T<0||T>=u)throw new Error("pos must more than 0 and less than set's size");var R=0;S(d,function(C){return T===R?(A(C),!0):(++R,!1)})},this.eraseElementByKey=function(T){if(!this.empty()){var R=z(d,T);R!==void 0&&R.key!==void 0&&c(R.key,T)===0&&A(R)}};var I=function(T,R){if(!T||T.key===void 0)throw new Error("unknown error");var C=c(R,T.key);return C<0?T.leftChild?I(T.leftChild,R):(T.leftChild=new l.default,T.leftChild.parent=T,T.leftChild.brother=T.rightChild,T.rightChild&&(T.rightChild.brother=T.leftChild),T.leftChild):C>0?T.rightChild?I(T.rightChild,R):(T.rightChild=new l.default,T.rightChild.parent=T,T.rightChild.brother=T.leftChild,T.leftChild&&(T.leftChild.brother=T.rightChild),T.rightChild):T},E=function(T){var R=T.parent;if(!R){if(T===d)return;throw new Error("unknown error")}if(R.color!==l.default.TreeNodeColorType.black&&R.color===l.default.TreeNodeColorType.red){var C=R.brother,_=R.parent;if(!_)throw new Error("unknown error");if(C&&C.color===l.default.TreeNodeColorType.red)C.color=R.color=l.default.TreeNodeColorType.black,_.color=l.default.TreeNodeColorType.red,E(_);else if(!C||C.color===l.default.TreeNodeColorType.black)if(R===_.leftChild)if(T===R.leftChild){R.color=l.default.TreeNodeColorType.black,_.color=l.default.TreeNodeColorType.red;var B=_.rotateRight();_===d&&(d=B)}else T===R.rightChild&&(B=R.rotateLeft(),_===d&&(d=B),E(R));else R===_.rightChild&&(T===R.leftChild?(B=R.rotateRight(),_===d&&(d=B),E(R)):T===R.rightChild&&(R.color=l.default.TreeNodeColorType.black,_.color=l.default.TreeNodeColorType.red,B=_.rotateLeft(),_===d&&(d=B)))}};this.setElement=function(T,R){if(T==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(R!=null){if(this.empty())return++u,d.key=T,d.value=R,void(d.color=l.default.TreeNodeColorType.black);var C=I(d,T);C.key===void 0||c(C.key,T)!==0?(++u,C.key=T,C.value=R,E(C),d.color=l.default.TreeNodeColorType.black):C.value=R}else this.eraseElementByKey(T)};var z=function(T,R){if(T&&T.key!==void 0){var C=c(R,T.key);return C<0?z(T.leftChild,R):C>0?z(T.rightChild,R):T}};this.find=function(T){return!!z(d,T)},this.getElementByKey=function(T){var R=z(d,T);if((R==null?void 0:R.key)===void 0||(R==null?void 0:R.value)===void 0)throw new Error("unknown error");return R.value},this.union=function(T){var R=this;T.forEach(function(C){var _=C.key,B=C.value;return R.setElement(_,B)})},this.getHeight=function(){if(this.empty())return 0;var T=function(R){return R?Math.max(T(R.leftChild),T(R.rightChild))+1:1};return T(d)};var U=function(T){return a(this,function(R){switch(R.label){case 0:return T&&T.key!==void 0&&T.value!==void 0?[5,o(U(T.leftChild))]:[2];case 1:return R.sent(),[4,{key:T.key,value:T.value}];case 2:return R.sent(),[5,o(U(T.rightChild))];case 3:return R.sent(),[2]}})};this[Symbol.iterator]=function(){return U(d)},h.forEach(function(T){var R=T.key,C=T.value;return f.setElement(R,C)}),Object.freeze(this)}Object.freeze(n),r.default=n},{"../Base/TreeNode":25}],31:[function(i,s,r){function a(o,l){o===void 0&&(o=[]),l=l||function(u,d){return u>d?-1:u<d?1:0};var n=[];o.forEach(function(u){return n.push(u)});var h=n.length,c=function(u,d){if(u<0||u>=h)throw new Error("unknown error");if(d<0||d>=h)throw new Error("unknown error");var v=n[u];n[u]=n[d],n[d]=v},f=function(u){if(u<0||u>=h)throw new Error("unknown error");var d=2*u+1,v=2*u+2;d<h&&l(n[u],n[d])>0&&c(u,d),v<h&&l(n[u],n[v])>0&&c(u,v)};(function(){for(var u=Math.floor((h-1)/2);u>=0;--u)for(var d=u,v=2*d+1;v<h;){var g=v+1,y=v;if(g<h&&l(n[v],n[g])>0&&(y=g),l(n[d],n[y])<=0)break;c(d,y),v=2*(d=y)+1}})(),this.size=function(){return h},this.empty=function(){return h===0},this.clear=function(){h=0,n.length=0},this.push=function(u){if(n.push(u),++h!==1)for(var d=h-1;d>0;){var v=Math.floor((d-1)/2);if(l(n[v],u)<=0)break;f(v),d=v}},this.pop=function(){if(!this.empty())if(this.size()!==1){var u=n[h-1];--h;for(var d=0;d<this.size();){var v=2*d+1,g=2*d+2;if(v>=this.size())break;var y=v;if(g<this.size()&&l(n[v],n[g])>0&&(y=g),l(n[y],u)>=0)break;n[d]=n[y],d=y}n[d]=u}else--h},this.top=function(){return n[0]},Object.freeze(this)}Object.defineProperty(r,"__esModule",{value:!0}),Object.freeze(a),r.default=a},{}],32:[function(i,s,r){Object.defineProperty(r,"__esModule",{value:!0});var a=i("../LinkList/LinkList");function o(l){l===void 0&&(l=[]);var n=new a.default(l);this.size=function(){return n.size()},this.empty=function(){return n.empty()},this.clear=function(){n.clear()},this.push=function(h){n.pushBack(h)},this.pop=function(){n.popFront()},this.front=function(){return n.front()},Object.freeze(this)}Object.freeze(o),r.default=o},{"../LinkList/LinkList":29}],33:[function(i,s,r){var a=this&&this.__generator||function(h,c){var f,u,d,v,g={label:0,sent:function(){if(1&d[0])throw d[1];return d[1]},trys:[],ops:[]};return v={next:y(0),throw:y(1),return:y(2)},typeof Symbol=="function"&&(v[Symbol.iterator]=function(){return this}),v;function y(p){return function(b){return function(m){if(f)throw new TypeError("Generator is already executing.");for(;g;)try{if(f=1,u&&(d=2&m[0]?u.return:m[0]?u.throw||((d=u.return)&&d.call(u),0):u.next)&&!(d=d.call(u,m[1])).done)return d;switch(u=0,d&&(m=[2&m[0],d.value]),m[0]){case 0:case 1:d=m;break;case 4:return g.label++,{value:m[1],done:!1};case 5:g.label++,u=m[1],m=[0];continue;case 7:m=g.ops.pop(),g.trys.pop();continue;default:if(!(d=(d=g.trys).length>0&&d[d.length-1])&&(m[0]===6||m[0]===2)){g=0;continue}if(m[0]===3&&(!d||m[1]>d[0]&&m[1]<d[3])){g.label=m[1];break}if(m[0]===6&&g.label<d[1]){g.label=d[1],d=m;break}if(d&&g.label<d[2]){g.label=d[2],g.ops.push(m);break}d[2]&&g.ops.pop(),g.trys.pop();continue}m=c.call(h,g)}catch(k){m=[6,k],u=0}finally{f=d=0}if(5&m[0])throw m[1];return{value:m[0]?m[1]:void 0,done:!0}}([p,b])}}},o=this&&this.__values||function(h){var c=typeof Symbol=="function"&&Symbol.iterator,f=c&&h[c],u=0;if(f)return f.call(h);if(h&&typeof h.length=="number")return{next:function(){return h&&u>=h.length&&(h=void 0),{value:h&&h[u++],done:!h}}};throw new TypeError(c?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var l=i("../Base/TreeNode");function n(h,c){var f=this;h===void 0&&(h=[]),c=c||function(T,R){return T<R?-1:T>R?1:0};var u=0,d=new l.default;d.color=l.default.TreeNodeColorType.black,this.size=function(){return u},this.empty=function(){return u===0},this.clear=function(){u=0,d.key=void 0,d.leftChild=d.rightChild=d.brother=d.parent=void 0,d.color=l.default.TreeNodeColorType.black};var v=function(T){if(!T||T.key===void 0)throw new Error("unknown error");return T.leftChild?v(T.leftChild):T},g=function(T){if(!T||T.key===void 0)throw new Error("unknown error");return T.rightChild?g(T.rightChild):T};this.front=function(){if(!this.empty())return v(d).key},this.back=function(){if(!this.empty())return g(d).key},this.forEach=function(T){var R,C,_=0;try{for(var B=o(this),j=B.next();!j.done;j=B.next())T(j.value,_++)}catch(X){R={error:X}}finally{try{j&&!j.done&&(C=B.return)&&C.call(B)}finally{if(R)throw R.error}}},this.getElementByPos=function(T){var R,C;if(T<0||T>=this.size())throw new Error("pos must more than 0 and less than set's size");var _=0;try{for(var B=o(this),j=B.next();!j.done;j=B.next()){var X=j.value;if(_===T)return X;++_}}catch(F){R={error:F}}finally{try{j&&!j.done&&(C=B.return)&&C.call(B)}finally{if(R)throw R.error}}throw new Error("unknown error")};var y=function(T){var R=T.parent;if(!R){if(T===d)return;throw new Error("unknown error")}if(T.color!==l.default.TreeNodeColorType.red){var C=T.brother;if(!C)throw new Error("unknown error");if(T===R.leftChild)if(C.color===l.default.TreeNodeColorType.red){C.color=l.default.TreeNodeColorType.black,R.color=l.default.TreeNodeColorType.red;var _=R.rotateLeft();d===R&&(d=_),y(T)}else C.color===l.default.TreeNodeColorType.black&&(C.rightChild&&C.rightChild.color===l.default.TreeNodeColorType.red?(C.color=R.color,R.color=l.default.TreeNodeColorType.black,C.rightChild&&(C.rightChild.color=l.default.TreeNodeColorType.black),_=R.rotateLeft(),d===R&&(d=_),T.color=l.default.TreeNodeColorType.black):C.rightChild&&C.rightChild.color!==l.default.TreeNodeColorType.black||!C.leftChild||C.leftChild.color!==l.default.TreeNodeColorType.red?C.leftChild&&C.leftChild.color!==l.default.TreeNodeColorType.black||C.rightChild&&C.rightChild.color!==l.default.TreeNodeColorType.black||(C.color=l.default.TreeNodeColorType.red,y(R)):(C.color=l.default.TreeNodeColorType.red,C.leftChild&&(C.leftChild.color=l.default.TreeNodeColorType.black),_=C.rotateRight(),d===C&&(d=_),y(T)));else T===R.rightChild&&(C.color===l.default.TreeNodeColorType.red?(C.color=l.default.TreeNodeColorType.black,R.color=l.default.TreeNodeColorType.red,_=R.rotateRight(),d===R&&(d=_),y(T)):C.color===l.default.TreeNodeColorType.black&&(C.leftChild&&C.leftChild.color===l.default.TreeNodeColorType.red?(C.color=R.color,R.color=l.default.TreeNodeColorType.black,C.leftChild&&(C.leftChild.color=l.default.TreeNodeColorType.black),_=R.rotateRight(),d===R&&(d=_),T.color=l.default.TreeNodeColorType.black):C.leftChild&&C.leftChild.color!==l.default.TreeNodeColorType.black||!C.rightChild||C.rightChild.color!==l.default.TreeNodeColorType.red?C.leftChild&&C.leftChild.color!==l.default.TreeNodeColorType.black||C.rightChild&&C.rightChild.color!==l.default.TreeNodeColorType.black||(C.color=l.default.TreeNodeColorType.red,y(R)):(C.color=l.default.TreeNodeColorType.red,C.rightChild&&(C.rightChild.color=l.default.TreeNodeColorType.black),_=C.rotateLeft(),d===C&&(d=_),y(T))))}else T.color=l.default.TreeNodeColorType.black},p=function(T){for(var R=T;R.leftChild||R.rightChild;){if(R.rightChild){R=v(R.rightChild);var C=T.key;T.key=R.key,R.key=C,T=R}R.leftChild&&(R=g(R.leftChild),C=T.key,T.key=R.key,R.key=C,T=R)}y(R),R&&R.remove(),--u,d.color=l.default.TreeNodeColorType.black},b=function(T,R){return!(!T||T.key===void 0)&&(!!b(T.leftChild,R)||!!R(T)||b(T.rightChild,R))};this.eraseElementByPos=function(T){if(T<0||T>=u)throw new Error("pos must more than 0 and less than set's size");var R=0;b(d,function(C){return T===R?(p(C),!0):(++R,!1)})},this.eraseElementByValue=function(T){if(!this.empty()){var R=A(d,T);R!==void 0&&R.key!==void 0&&c(R.key,T)===0&&p(R)}};var m=function(T,R){if(!T||T.key===void 0)throw new Error("unknown error");var C=c(R,T.key);return C<0?T.leftChild?m(T.leftChild,R):(T.leftChild=new l.default,T.leftChild.parent=T,T.leftChild.brother=T.rightChild,T.rightChild&&(T.rightChild.brother=T.leftChild),T.leftChild):C>0?T.rightChild?m(T.rightChild,R):(T.rightChild=new l.default,T.rightChild.parent=T,T.rightChild.brother=T.leftChild,T.leftChild&&(T.leftChild.brother=T.rightChild),T.rightChild):T},k=function(T){var R=T.parent;if(!R){if(T===d)return;throw new Error("unknown error")}if(R.color!==l.default.TreeNodeColorType.black&&R.color===l.default.TreeNodeColorType.red){var C=R.brother,_=R.parent;if(!_)throw new Error("unknown error");if(C&&C.color===l.default.TreeNodeColorType.red)C.color=R.color=l.default.TreeNodeColorType.black,_.color=l.default.TreeNodeColorType.red,k(_);else if(!C||C.color===l.default.TreeNodeColorType.black)if(R===_.leftChild)if(T===R.leftChild){R.color=l.default.TreeNodeColorType.black,_.color=l.default.TreeNodeColorType.red;var B=_.rotateRight();_===d&&(d=B)}else T===R.rightChild&&(B=R.rotateLeft(),_===d&&(d=B),k(R));else R===_.rightChild&&(T===R.leftChild?(B=R.rotateRight(),_===d&&(d=B),k(R)):T===R.rightChild&&(R.color=l.default.TreeNodeColorType.black,_.color=l.default.TreeNodeColorType.red,B=_.rotateLeft(),_===d&&(d=B)))}};this.insert=function(T){if(T==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(this.empty())return++u,d.key=T,void(d.color=l.default.TreeNodeColorType.black);var R=m(d,T);R.key!==void 0&&c(R.key,T)===0||(++u,R.key=T,k(R),d.color=l.default.TreeNodeColorType.black)};var A=function(T,R){if(T&&T.key!==void 0){var C=c(R,T.key);return C<0?A(T.leftChild,R):C>0?A(T.rightChild,R):T}};this.find=function(T){var R=A(d,T);return R!==void 0&&R.key!==void 0&&c(R.key,T)===0};var S=function(T,R){if(T&&T.key!==void 0){var C=c(T.key,R);if(C===0)return T.key;if(C<0)return S(T.rightChild,R);var _=S(T.leftChild,R);return _!==void 0?_:T.key}};this.lowerBound=function(T){return S(d,T)};var I=function(T,R){if(T&&T.key!==void 0){if(c(T.key,R)<=0)return I(T.rightChild,R);var C=I(T.leftChild,R);return C!==void 0?C:T.key}};this.upperBound=function(T){return I(d,T)};var E=function(T,R){if(T&&T.key!==void 0){var C=c(T.key,R);if(C===0)return T.key;if(C>0)return E(T.leftChild,R);var _=E(T.rightChild,R);return _!==void 0?_:T.key}};this.reverseLowerBound=function(T){return E(d,T)};var z=function(T,R){if(T&&T.key!==void 0){if(c(T.key,R)>=0)return z(T.leftChild,R);var C=z(T.rightChild,R);return C!==void 0?C:T.key}};this.reverseUpperBound=function(T){return z(d,T)},this.union=function(T){var R=this;T.forEach(function(C){return R.insert(C)})},this.getHeight=function(){if(this.empty())return 0;var T=function(R){return R?Math.max(T(R.leftChild),T(R.rightChild))+1:1};return T(d)};var U=function(T){return a(this,function(R){switch(R.label){case 0:return T&&T.key!==void 0?[5,o(U(T.leftChild))]:[2];case 1:return R.sent(),[4,T.key];case 2:return R.sent(),[5,o(U(T.rightChild))];case 3:return R.sent(),[2]}})};this[Symbol.iterator]=function(){return U(d)},h.forEach(function(T){return f.insert(T)}),Object.freeze(this)}Object.freeze(n),r.default=n},{"../Base/TreeNode":25}],34:[function(i,s,r){function a(o){var l=this;o===void 0&&(o=[]);var n=0,h=[];this.size=function(){return n},this.empty=function(){return n===0},this.clear=function(){n=0,h.length=0},this.push=function(c){h.push(c),++n},this.pop=function(){h.pop(),n>0&&--n},this.top=function(){return h[n-1]},o.forEach(function(c){return l.push(c)}),Object.freeze(this)}Object.defineProperty(r,"__esModule",{value:!0}),Object.freeze(a),r.default=a},{}],35:[function(i,s,r){var a=this&&this.__generator||function(c,f){var u,d,v,g,y={label:0,sent:function(){if(1&v[0])throw v[1];return v[1]},trys:[],ops:[]};return g={next:p(0),throw:p(1),return:p(2)},typeof Symbol=="function"&&(g[Symbol.iterator]=function(){return this}),g;function p(b){return function(m){return function(k){if(u)throw new TypeError("Generator is already executing.");for(;y;)try{if(u=1,d&&(v=2&k[0]?d.return:k[0]?d.throw||((v=d.return)&&v.call(d),0):d.next)&&!(v=v.call(d,k[1])).done)return v;switch(d=0,v&&(k=[2&k[0],v.value]),k[0]){case 0:case 1:v=k;break;case 4:return y.label++,{value:k[1],done:!1};case 5:y.label++,d=k[1],k=[0];continue;case 7:k=y.ops.pop(),y.trys.pop();continue;default:if(!(v=(v=y.trys).length>0&&v[v.length-1])&&(k[0]===6||k[0]===2)){y=0;continue}if(k[0]===3&&(!v||k[1]>v[0]&&k[1]<v[3])){y.label=k[1];break}if(k[0]===6&&y.label<v[1]){y.label=v[1],v=k;break}if(v&&y.label<v[2]){y.label=v[2],y.ops.push(k);break}v[2]&&y.ops.pop(),y.trys.pop();continue}k=f.call(c,y)}catch(A){k=[6,A],d=0}finally{u=v=0}if(5&k[0])throw k[1];return{value:k[0]?k[1]:void 0,done:!0}}([b,m])}}},o=this&&this.__read||function(c,f){var u=typeof Symbol=="function"&&c[Symbol.iterator];if(!u)return c;var d,v,g=u.call(c),y=[];try{for(;(f===void 0||f-- >0)&&!(d=g.next()).done;)y.push(d.value)}catch(p){v={error:p}}finally{try{d&&!d.done&&(u=g.return)&&u.call(g)}finally{if(v)throw v.error}}return y},l=this&&this.__spreadArray||function(c,f,u){if(u||arguments.length===2)for(var d,v=0,g=f.length;v<g;v++)!d&&v in f||(d||(d=Array.prototype.slice.call(f,0,v)),d[v]=f[v]);return c.concat(d||Array.prototype.slice.call(f))},n=this&&this.__values||function(c){var f=typeof Symbol=="function"&&Symbol.iterator,u=f&&c[f],d=0;if(u)return u.call(c);if(c&&typeof c.length=="number")return{next:function(){return c&&d>=c.length&&(c=void 0),{value:c&&c[d++],done:!c}}};throw new TypeError(f?"Object is not iterable.":"Symbol.iterator is not defined.")};function h(c){var f=this;c===void 0&&(c=[]);var u=0,d=[];this.size=function(){return u},this.empty=function(){return u===0},this.clear=function(){u=0,d.length=0},this.front=function(){if(!this.empty())return d[0]},this.back=function(){if(!this.empty())return d[u-1]},this.forEach=function(v){d.forEach(v)},this.getElementByPos=function(v){if(v<0||v>=u)throw new Error("pos must more than 0 and less than vector's size");return d[v]},this.eraseElementByPos=function(v){if(v<0||v>=u)throw new Error("pos must more than 0 and less than vector's size");for(var g=v;g<u-1;++g)d[g]=d[g+1];this.popBack()},this.eraseElementByValue=function(v){var g=[];this.forEach(function(p){p!==v&&g.push(p)}),g.forEach(function(p,b){d[b]=p});for(var y=g.length;u>y;)this.popBack()},this.pushBack=function(v){d.push(v),++u},this.popBack=function(){d.pop(),u>0&&--u},this.setElementByPos=function(v,g){if(v<0||v>=u)throw new Error("pos must more than 0 and less than vector's size");d[v]=g},this.insert=function(v,g,y){if(y===void 0&&(y=1),v<0||v>u)throw new Error("pos must more than 0 and less than or equal to vector's size");d.splice.apply(d,l([v,0],o(new Array(y).fill(g)),!1)),u+=y},this.find=function(v){return d.includes(v)},this.reverse=function(){d.reverse()},this.unique=function(){var v,g=[];this.forEach(function(p,b){b!==0&&p===v||(g.push(p),v=p)}),g.forEach(function(p,b){d[b]=p});for(var y=g.length;u>y;)this.popBack()},this.sort=function(v){d.sort(v)},this[Symbol.iterator]=function(){return function(){return a(this,function(v){switch(v.label){case 0:return[5,n(d)];case 1:return[2,v.sent()]}})}()},c.forEach(function(v){return f.pushBack(v)}),Object.freeze(this)}Object.defineProperty(r,"__esModule",{value:!0}),Object.freeze(h),r.default=h},{}],36:[function(i,s,r){Object.defineProperty(r,"__esModule",{value:!0}),r.HashMap=r.HashSet=r.Map=r.Set=r.PriorityQueue=r.Deque=r.LinkList=r.Queue=r.Stack=r.Vector=void 0;var a=i("./Vector/Vector");r.Vector=a.default;var o=i("./Stack/Stack");r.Stack=o.default;var l=i("./Queue/Queue");r.Queue=l.default;var n=i("./LinkList/LinkList");r.LinkList=n.default;var h=i("./Deque/Deque");r.Deque=h.default;var c=i("./PriorityQueue/PriorityQueue");r.PriorityQueue=c.default;var f=i("./Set/Set");r.Set=f.default;var u=i("./Map/Map");r.Map=u.default;var d=i("./HashSet/HashSet");r.HashSet=d.default;var v=i("./HashMap/HashMap");r.HashMap=v.default},{"./Deque/Deque":26,"./HashMap/HashMap":27,"./HashSet/HashSet":28,"./LinkList/LinkList":29,"./Map/Map":30,"./PriorityQueue/PriorityQueue":31,"./Queue/Queue":32,"./Set/Set":33,"./Stack/Stack":34,"./Vector/Vector":35}],37:[function(i,s,r){const a=i("yallist"),o=Symbol("max"),l=Symbol("length"),n=Symbol("lengthCalculator"),h=Symbol("allowStale"),c=Symbol("maxAge"),f=Symbol("dispose"),u=Symbol("noDisposeOnSet"),d=Symbol("lruList"),v=Symbol("cache"),g=Symbol("updateAgeOnGet"),y=()=>1,p=(I,E,z)=>{const U=I[v].get(E);if(U){const T=U.value;if(b(I,T)){if(k(I,U),!I[h])return}else z&&(I[g]&&(U.value.now=Date.now()),I[d].unshiftNode(U));return T.value}},b=(I,E)=>{if(!E||!E.maxAge&&!I[c])return!1;const z=Date.now()-E.now;return E.maxAge?z>E.maxAge:I[c]&&z>I[c]},m=I=>{if(I[l]>I[o])for(let E=I[d].tail;I[l]>I[o]&&E!==null;){const z=E.prev;k(I,E),E=z}},k=(I,E)=>{if(E){const z=E.value;I[f]&&I[f](z.key,z.value),I[l]-=z.length,I[v].delete(z.key),I[d].removeNode(E)}};class A{constructor(E,z,U,T,R){this.key=E,this.value=z,this.length=U,this.now=T,this.maxAge=R||0}}const S=(I,E,z,U)=>{let T=z.value;b(I,T)&&(k(I,z),I[h]||(T=void 0)),T&&E.call(U,T.value,T.key,I)};s.exports=class{constructor(I){if(typeof I=="number"&&(I={max:I}),I||(I={}),I.max&&(typeof I.max!="number"||I.max<0))throw new TypeError("max must be a non-negative number");this[o]=I.max||1/0;const E=I.length||y;if(this[n]=typeof E!="function"?y:E,this[h]=I.stale||!1,I.maxAge&&typeof I.maxAge!="number")throw new TypeError("maxAge must be a number");this[c]=I.maxAge||0,this[f]=I.dispose,this[u]=I.noDisposeOnSet||!1,this[g]=I.updateAgeOnGet||!1,this.reset()}set max(I){if(typeof I!="number"||I<0)throw new TypeError("max must be a non-negative number");this[o]=I||1/0,m(this)}get max(){return this[o]}set allowStale(I){this[h]=!!I}get allowStale(){return this[h]}set maxAge(I){if(typeof I!="number")throw new TypeError("maxAge must be a non-negative number");this[c]=I,m(this)}get maxAge(){return this[c]}set lengthCalculator(I){typeof I!="function"&&(I=y),I!==this[n]&&(this[n]=I,this[l]=0,this[d].forEach(E=>{E.length=this[n](E.value,E.key),this[l]+=E.length})),m(this)}get lengthCalculator(){return this[n]}get length(){return this[l]}get itemCount(){return this[d].length}rforEach(I,E){E=E||this;for(let z=this[d].tail;z!==null;){const U=z.prev;S(this,I,z,E),z=U}}forEach(I,E){E=E||this;for(let z=this[d].head;z!==null;){const U=z.next;S(this,I,z,E),z=U}}keys(){return this[d].toArray().map(I=>I.key)}values(){return this[d].toArray().map(I=>I.value)}reset(){this[f]&&this[d]&&this[d].length&&this[d].forEach(I=>this[f](I.key,I.value)),this[v]=new Map,this[d]=new a,this[l]=0}dump(){return this[d].map(I=>!b(this,I)&&{k:I.key,v:I.value,e:I.now+(I.maxAge||0)}).toArray().filter(I=>I)}dumpLru(){return this[d]}set(I,E,z){if((z=z||this[c])&&typeof z!="number")throw new TypeError("maxAge must be a number");const U=z?Date.now():0,T=this[n](E,I);if(this[v].has(I)){if(T>this[o])return k(this,this[v].get(I)),!1;const C=this[v].get(I).value;return this[f]&&(this[u]||this[f](I,C.value)),C.now=U,C.maxAge=z,C.value=E,this[l]+=T-C.length,C.length=T,this.get(I),m(this),!0}const R=new A(I,E,T,U,z);return R.length>this[o]?(this[f]&&this[f](I,E),!1):(this[l]+=R.length,this[d].unshift(R),this[v].set(I,this[d].head),m(this),!0)}has(I){if(!this[v].has(I))return!1;const E=this[v].get(I).value;return!b(this,E)}get(I){return p(this,I,!0)}peek(I){return p(this,I,!1)}pop(){const I=this[d].tail;return I?(k(this,I),I.value):null}del(I){k(this,this[v].get(I))}load(I){this.reset();const E=Date.now();for(let z=I.length-1;z>=0;z--){const U=I[z],T=U.e||0;if(T===0)this.set(U.k,U.v);else{const R=T-E;R>0&&this.set(U.k,U.v,R)}}}prune(){this[v].forEach((I,E)=>p(this,E,!1))}}},{yallist:83}],38:[function(i,s,r){(function(a){(function(){const o=s.exports;o.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"},o.codes={};for(const n in o.types){const h=o.types[n];o.codes[h]=n}o.CMD_SHIFT=4,o.CMD_MASK=240,o.DUP_MASK=8,o.QOS_MASK=3,o.QOS_SHIFT=1,o.RETAIN_MASK=1,o.VARBYTEINT_MASK=127,o.VARBYTEINT_FIN_MASK=128,o.VARBYTEINT_MAX=268435455,o.SESSIONPRESENT_MASK=1,o.SESSIONPRESENT_HEADER=a.from([o.SESSIONPRESENT_MASK]),o.CONNACK_HEADER=a.from([o.codes.connack<<o.CMD_SHIFT]),o.USERNAME_MASK=128,o.PASSWORD_MASK=64,o.WILL_RETAIN_MASK=32,o.WILL_QOS_MASK=24,o.WILL_QOS_SHIFT=3,o.WILL_FLAG_MASK=4,o.CLEAN_SESSION_MASK=2,o.CONNECT_HEADER=a.from([o.codes.connect<<o.CMD_SHIFT]),o.properties={sessionExpiryInterval:17,willDelayInterval:24,receiveMaximum:33,maximumPacketSize:39,topicAliasMaximum:34,requestResponseInformation:25,requestProblemInformation:23,userProperties:38,authenticationMethod:21,authenticationData:22,payloadFormatIndicator:1,messageExpiryInterval:2,contentType:3,responseTopic:8,correlationData:9,maximumQoS:36,retainAvailable:37,assignedClientIdentifier:18,reasonString:31,wildcardSubscriptionAvailable:40,subscriptionIdentifiersAvailable:41,sharedSubscriptionAvailable:42,serverKeepAlive:19,responseInformation:26,serverReference:28,topicAlias:35,subscriptionIdentifier:11},o.propertiesCodes={};for(const n in o.properties){const h=o.properties[n];o.propertiesCodes[h]=n}function l(n){return[0,1,2].map(h=>[0,1].map(c=>[0,1].map(f=>{const u=a.alloc(1);return u.writeUInt8(o.codes[n]<<o.CMD_SHIFT|(c?o.DUP_MASK:0)|h<<o.QOS_SHIFT|f,0,!0),u})))}o.propertiesTypes={sessionExpiryInterval:"int32",willDelayInterval:"int32",receiveMaximum:"int16",maximumPacketSize:"int32",topicAliasMaximum:"int16",requestResponseInformation:"byte",requestProblemInformation:"byte",userProperties:"pair",authenticationMethod:"string",authenticationData:"binary",payloadFormatIndicator:"byte",messageExpiryInterval:"int32",contentType:"string",responseTopic:"string",correlationData:"binary",maximumQoS:"int8",retainAvailable:"byte",assignedClientIdentifier:"string",reasonString:"string",wildcardSubscriptionAvailable:"byte",subscriptionIdentifiersAvailable:"byte",sharedSubscriptionAvailable:"byte",serverKeepAlive:"int16",responseInformation:"string",serverReference:"string",topicAlias:"int16",subscriptionIdentifier:"var"},o.PUBLISH_HEADER=l("publish"),o.SUBSCRIBE_HEADER=l("subscribe"),o.SUBSCRIBE_OPTIONS_QOS_MASK=3,o.SUBSCRIBE_OPTIONS_NL_MASK=1,o.SUBSCRIBE_OPTIONS_NL_SHIFT=2,o.SUBSCRIBE_OPTIONS_RAP_MASK=1,o.SUBSCRIBE_OPTIONS_RAP_SHIFT=3,o.SUBSCRIBE_OPTIONS_RH_MASK=3,o.SUBSCRIBE_OPTIONS_RH_SHIFT=4,o.SUBSCRIBE_OPTIONS_RH=[0,16,32],o.SUBSCRIBE_OPTIONS_NL=4,o.SUBSCRIBE_OPTIONS_RAP=8,o.SUBSCRIBE_OPTIONS_QOS=[0,1,2],o.UNSUBSCRIBE_HEADER=l("unsubscribe"),o.ACKS={unsuback:l("unsuback"),puback:l("puback"),pubcomp:l("pubcomp"),pubrel:l("pubrel"),pubrec:l("pubrec")},o.SUBACK_HEADER=a.from([o.codes.suback<<o.CMD_SHIFT]),o.VERSION3=a.from([3]),o.VERSION4=a.from([4]),o.VERSION5=a.from([5]),o.VERSION131=a.from([131]),o.VERSION132=a.from([132]),o.QOS=[0,1,2].map(n=>a.from([n])),o.EMPTY={pingreq:a.from([o.codes.pingreq<<4,0]),pingresp:a.from([o.codes.pingresp<<4,0]),disconnect:a.from([o.codes.disconnect<<4,0])}}).call(this)}).call(this,i("buffer").Buffer)},{buffer:17}],39:[function(i,s,r){(function(a){(function(){const o=i("./writeToStream"),l=i("events");class n extends l{constructor(){super(),this._array=new Array(20),this._i=0}write(c){return this._array[this._i++]=c,!0}concat(){let c=0;const f=new Array(this._array.length),u=this._array;let d,v=0;for(d=0;d<u.length&&u[d]!==void 0;d++)typeof u[d]!="string"?f[d]=u[d].length:f[d]=a.byteLength(u[d]),c+=f[d];const g=a.allocUnsafe(c);for(d=0;d<u.length&&u[d]!==void 0;d++)typeof u[d]!="string"?(u[d].copy(g,v),v+=f[d]):(g.write(u[d],v),v+=f[d]);return g}}s.exports=function(h,c){const f=new n;return o(h,f,c),f.concat()}}).call(this)}).call(this,i("buffer").Buffer)},{"./writeToStream":44,buffer:17,events:22}],40:[function(i,s,r){r.parser=i("./parser").parser,r.generate=i("./generate"),r.writeToStream=i("./writeToStream")},{"./generate":39,"./parser":43,"./writeToStream":44}],41:[function(i,s,r){(function(a){(function(){const l={},n=a.isBuffer(a.from([1,2]).subarray(0,1));function h(c){const f=a.allocUnsafe(2);return f.writeUInt8(c>>8,0),f.writeUInt8(255&c,1),f}s.exports={cache:l,generateCache:function(){for(let c=0;c<65536;c++)l[c]=h(c)},generateNumber:h,genBufVariableByteInt:function(c){let f=0,u=0;const d=a.allocUnsafe(4);do f=c%128|0,(c=c/128|0)>0&&(f|=128),d.writeUInt8(f,u++);while(c>0&&u<4);return c>0&&(u=0),n?d.subarray(0,u):d.slice(0,u)},generate4ByteBuffer:function(c){const f=a.allocUnsafe(4);return f.writeUInt32BE(c,0),f}}}).call(this)}).call(this,i("buffer").Buffer)},{buffer:17}],42:[function(i,s,r){s.exports=class{constructor(){this.cmd=null,this.retain=!1,this.qos=0,this.dup=!1,this.length=-1,this.topic=null,this.payload=null}}},{}],43:[function(i,s,r){const a=i("bl"),o=i("events"),l=i("./packet"),n=i("./constants"),h=i("debug")("mqtt-packet:parser");class c extends o{constructor(){super(),this.parser=this.constructor.parser}static parser(u){return this instanceof c?(this.settings=u||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):new c().parser(u)}_resetState(){h("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new l,this.error=null,this._list=a(),this._stateCounter=0}parse(u){for(this.error&&this._resetState(),this._list.append(u),h("parse: current state: %s",this._states[this._stateCounter]);(this.packet.length!==-1||this._list.length>0)&&this[this._states[this._stateCounter]]()&&!this.error;)this._stateCounter++,h("parse: state complete. _stateCounter is now: %d",this._stateCounter),h("parse: packet.length: %d, buffer list length: %d",this.packet.length,this._list.length),this._stateCounter>=this._states.length&&(this._stateCounter=0);return h("parse: exited while loop. packet: %d, buffer list length: %d",this.packet.length,this._list.length),this._list.length}_parseHeader(){const u=this._list.readUInt8(0);return this.packet.cmd=n.types[u>>n.CMD_SHIFT],this.packet.retain=(u&n.RETAIN_MASK)!=0,this.packet.qos=u>>n.QOS_SHIFT&n.QOS_MASK,this.packet.dup=(u&n.DUP_MASK)!=0,h("_parseHeader: packet: %o",this.packet),this._list.consume(1),!0}_parseLength(){const u=this._parseVarByteNum(!0);return u&&(this.packet.length=u.value,this._list.consume(u.bytes)),h("_parseLength %d",u.value),!!u}_parsePayload(){h("_parsePayload: payload %O",this._list);let u=!1;if(this.packet.length===0||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"))}u=!0}return h("_parsePayload complete result: %s",u),u}_parseConnect(){let u,d,v,g;h("_parseConnect");const y={},p=this.packet,b=this._parseString();if(b===null)return this._emitError(new Error("Cannot parse protocolId"));if(b!=="MQTT"&&b!=="MQIsdp")return this._emitError(new Error("Invalid protocolId"));if(p.protocolId=b,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(p.protocolVersion=this._list.readUInt8(this._pos),p.protocolVersion>=128&&(p.bridgeMode=!0,p.protocolVersion=p.protocolVersion-128),p.protocolVersion!==3&&p.protocolVersion!==4&&p.protocolVersion!==5)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(y.username=this._list.readUInt8(this._pos)&n.USERNAME_MASK,y.password=this._list.readUInt8(this._pos)&n.PASSWORD_MASK,y.will=this._list.readUInt8(this._pos)&n.WILL_FLAG_MASK,y.will&&(p.will={},p.will.retain=(this._list.readUInt8(this._pos)&n.WILL_RETAIN_MASK)!=0,p.will.qos=(this._list.readUInt8(this._pos)&n.WILL_QOS_MASK)>>n.WILL_QOS_SHIFT),p.clean=(this._list.readUInt8(this._pos)&n.CLEAN_SESSION_MASK)!=0,this._pos++,p.keepalive=this._parseNum(),p.keepalive===-1)return this._emitError(new Error("Packet too short"));if(p.protocolVersion===5){const k=this._parseProperties();Object.getOwnPropertyNames(k).length&&(p.properties=k)}const m=this._parseString();if(m===null)return this._emitError(new Error("Packet too short"));if(p.clientId=m,h("_parseConnect: packet.clientId: %s",p.clientId),y.will){if(p.protocolVersion===5){const k=this._parseProperties();Object.getOwnPropertyNames(k).length&&(p.will.properties=k)}if((u=this._parseString())===null)return this._emitError(new Error("Cannot parse will topic"));if(p.will.topic=u,h("_parseConnect: packet.will.topic: %s",p.will.topic),(d=this._parseBuffer())===null)return this._emitError(new Error("Cannot parse will payload"));p.will.payload=d,h("_parseConnect: packet.will.paylaod: %s",p.will.payload)}if(y.username){if((g=this._parseString())===null)return this._emitError(new Error("Cannot parse username"));p.username=g,h("_parseConnect: packet.username: %s",p.username)}if(y.password){if((v=this._parseBuffer())===null)return this._emitError(new Error("Cannot parse password"));p.password=v}return this.settings=p,h("_parseConnect: complete"),p}_parseConnack(){h("_parseConnack");const u=this.packet;if(this._list.length<1)return null;if(u.sessionPresent=!!(this._list.readUInt8(this._pos++)&n.SESSIONPRESENT_MASK),this.settings.protocolVersion===5)this._list.length>=2?u.reasonCode=this._list.readUInt8(this._pos++):u.reasonCode=0;else{if(this._list.length<2)return null;u.returnCode=this._list.readUInt8(this._pos++)}if(u.returnCode===-1||u.reasonCode===-1)return this._emitError(new Error("Cannot parse return code"));if(this.settings.protocolVersion===5){const d=this._parseProperties();Object.getOwnPropertyNames(d).length&&(u.properties=d)}h("_parseConnack: complete")}_parsePublish(){h("_parsePublish");const u=this.packet;if(u.topic=this._parseString(),u.topic===null)return this._emitError(new Error("Cannot parse topic"));if(!(u.qos>0)||this._parseMessageId()){if(this.settings.protocolVersion===5){const d=this._parseProperties();Object.getOwnPropertyNames(d).length&&(u.properties=d)}u.payload=this._list.slice(this._pos,u.length),h("_parsePublish: payload from buffer list: %o",u.payload)}}_parseSubscribe(){h("_parseSubscribe");const u=this.packet;let d,v,g,y,p,b,m;if(u.qos!==1)return this._emitError(new Error("Wrong subscribe header"));if(u.subscriptions=[],this._parseMessageId()){if(this.settings.protocolVersion===5){const k=this._parseProperties();Object.getOwnPropertyNames(k).length&&(u.properties=k)}for(;this._pos<u.length;){if((d=this._parseString())===null)return this._emitError(new Error("Cannot parse topic"));if(this._pos>=u.length)return this._emitError(new Error("Malformed Subscribe Payload"));g=(v=this._parseByte())&n.SUBSCRIBE_OPTIONS_QOS_MASK,b=(v>>n.SUBSCRIBE_OPTIONS_NL_SHIFT&n.SUBSCRIBE_OPTIONS_NL_MASK)!=0,p=(v>>n.SUBSCRIBE_OPTIONS_RAP_SHIFT&n.SUBSCRIBE_OPTIONS_RAP_MASK)!=0,y=v>>n.SUBSCRIBE_OPTIONS_RH_SHIFT&n.SUBSCRIBE_OPTIONS_RH_MASK,m={topic:d,qos:g},this.settings.protocolVersion===5?(m.nl=b,m.rap=p,m.rh=y):this.settings.bridgeMode&&(m.rh=0,m.rap=!0,m.nl=!0),h("_parseSubscribe: push subscription `%s` to subscription",m),u.subscriptions.push(m)}}}_parseSuback(){h("_parseSuback");const u=this.packet;if(this.packet.granted=[],this._parseMessageId()){if(this.settings.protocolVersion===5){const d=this._parseProperties();Object.getOwnPropertyNames(d).length&&(u.properties=d)}for(;this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseUnsubscribe(){h("_parseUnsubscribe");const u=this.packet;if(u.unsubscriptions=[],this._parseMessageId()){if(this.settings.protocolVersion===5){const d=this._parseProperties();Object.getOwnPropertyNames(d).length&&(u.properties=d)}for(;this._pos<u.length;){const d=this._parseString();if(d===null)return this._emitError(new Error("Cannot parse topic"));h("_parseUnsubscribe: push topic `%s` to unsubscriptions",d),u.unsubscriptions.push(d)}}}_parseUnsuback(){h("_parseUnsuback");const u=this.packet;if(!this._parseMessageId())return this._emitError(new Error("Cannot parse messageId"));if(this.settings.protocolVersion===5){const d=this._parseProperties();for(Object.getOwnPropertyNames(d).length&&(u.properties=d),u.granted=[];this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseConfirmation(){h("_parseConfirmation: packet.cmd: `%s`",this.packet.cmd);const u=this.packet;if(this._parseMessageId(),this.settings.protocolVersion===5&&(u.length>2?(u.reasonCode=this._parseByte(),h("_parseConfirmation: packet.reasonCode `%d`",u.reasonCode)):u.reasonCode=0,u.length>3)){const d=this._parseProperties();Object.getOwnPropertyNames(d).length&&(u.properties=d)}return!0}_parseDisconnect(){const u=this.packet;if(h("_parseDisconnect"),this.settings.protocolVersion===5){this._list.length>0?u.reasonCode=this._parseByte():u.reasonCode=0;const d=this._parseProperties();Object.getOwnPropertyNames(d).length&&(u.properties=d)}return h("_parseDisconnect result: true"),!0}_parseAuth(){h("_parseAuth");const u=this.packet;if(this.settings.protocolVersion!==5)return this._emitError(new Error("Not supported auth packet for this version MQTT"));u.reasonCode=this._parseByte();const d=this._parseProperties();return Object.getOwnPropertyNames(d).length&&(u.properties=d),h("_parseAuth: result: true"),!0}_parseMessageId(){const u=this.packet;return u.messageId=this._parseNum(),u.messageId===null?(this._emitError(new Error("Cannot parse messageId")),!1):(h("_parseMessageId: packet.messageId %d",u.messageId),!0)}_parseString(u){const d=this._parseNum(),v=d+this._pos;if(d===-1||v>this._list.length||v>this.packet.length)return null;const g=this._list.toString("utf8",this._pos,v);return this._pos+=d,h("_parseString: result: %s",g),g}_parseStringPair(){return h("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){const u=this._parseNum(),d=u+this._pos;if(u===-1||d>this._list.length||d>this.packet.length)return null;const v=this._list.slice(this._pos,d);return this._pos+=u,h("_parseBuffer: result: %o",v),v}_parseNum(){if(this._list.length-this._pos<2)return-1;const u=this._list.readUInt16BE(this._pos);return this._pos+=2,h("_parseNum: result: %s",u),u}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;const u=this._list.readUInt32BE(this._pos);return this._pos+=4,h("_parse4ByteNum: result: %s",u),u}_parseVarByteNum(u){h("_parseVarByteNum");let d,v=0,g=1,y=0,p=!1;const b=this._pos?this._pos:0;for(;v<4&&b+v<this._list.length;){if(y+=g*((d=this._list.readUInt8(b+v++))&n.VARBYTEINT_MASK),g*=128,(d&n.VARBYTEINT_FIN_MASK)==0){p=!0;break}if(this._list.length<=v)break}return!p&&v===4&&this._list.length>=v&&this._emitError(new Error("Invalid variable byte integer")),b&&(this._pos+=v),h("_parseVarByteNum: result: %o",p=!!p&&(u?{bytes:v,value:y}:y)),p}_parseByte(){let u;return this._pos<this._list.length&&(u=this._list.readUInt8(this._pos),this._pos++),h("_parseByte: result: %o",u),u}_parseByType(u){switch(h("_parseByType: type: %s",u),u){case"byte":return this._parseByte()!==0;case"int8":return this._parseByte();case"int16":return this._parseNum();case"int32":return this._parse4ByteNum();case"var":return this._parseVarByteNum();case"string":return this._parseString();case"pair":return this._parseStringPair();case"binary":return this._parseBuffer()}}_parseProperties(){h("_parseProperties");const u=this._parseVarByteNum(),d=this._pos+u,v={};for(;this._pos<d;){const g=this._parseByte();if(!g)return this._emitError(new Error("Cannot parse property code type")),!1;const y=n.propertiesCodes[g];if(!y)return this._emitError(new Error("Unknown property")),!1;if(y!=="userProperties")v[y]?Array.isArray(v[y])?v[y].push(this._parseByType(n.propertiesTypes[y])):(v[y]=[v[y]],v[y].push(this._parseByType(n.propertiesTypes[y]))):v[y]=this._parseByType(n.propertiesTypes[y]);else{v[y]||(v[y]=Object.create(null));const p=this._parseByType(n.propertiesTypes[y]);if(v[y][p.name])if(Array.isArray(v[y][p.name]))v[y][p.name].push(p.value);else{const b=v[y][p.name];v[y][p.name]=[b],v[y][p.name].push(p.value)}else v[y][p.name]=p.value}}return v}_newPacket(){return h("_newPacket"),this.packet&&(this._list.consume(this.packet.length),h("_newPacket: parser emit packet: packet.cmd: %s, packet.payload: %s, packet.length: %d",this.packet.cmd,this.packet.payload,this.packet.length),this.emit("packet",this.packet)),h("_newPacket: new packet"),this.packet=new l,this._pos=0,!0}_emitError(u){h("_emitError"),this.error=u,this.emit("error",u)}}s.exports=c},{"./constants":38,"./packet":42,bl:15,debug:18,events:22}],44:[function(i,s,r){(function(a){(function(){const o=i("./constants"),l=a.allocUnsafe(0),n=a.from([0]),h=i("./numbers"),c=i("process-nextick-args").nextTick,f=i("debug")("mqtt-packet:writeToStream"),u=h.cache,d=h.generateNumber,v=h.generateCache,g=h.genBufVariableByteInt,y=h.generate4ByteBuffer;let p=z,b=!0;function m(F,L,N){switch(f("generate called"),L.cork&&(L.cork(),c(k,L)),b&&(b=!1,v()),f("generate: packet.cmd: %s",F.cmd),F.cmd){case"connect":return function(W,O,q){const $=W||{},Y=$.protocolId||"MQTT";let Z=$.protocolVersion||4;const J=$.will;let Q=$.clean;const w=$.keepalive||0,x=$.clientId||"",P=$.username,M=$.password,H=$.properties;Q===void 0&&(Q=!0);let V=0;if(typeof Y!="string"&&!a.isBuffer(Y))return O.emit("error",new Error("Invalid protocolId")),!1;if(V+=Y.length+2,Z!==3&&Z!==4&&Z!==5)return O.emit("error",new Error("Invalid protocol version")),!1;if(V+=1,(typeof x=="string"||a.isBuffer(x))&&(x||Z>=4)&&(x||Q))V+=a.byteLength(x)+2;else{if(Z<4)return O.emit("error",new Error("clientId must be supplied before 3.1.1")),!1;if(1*Q==0)return O.emit("error",new Error("clientId must be given if cleanSession set to 0")),!1}if(typeof w!="number"||w<0||w>65535||w%1!=0)return O.emit("error",new Error("Invalid keepalive")),!1;if(V+=2,V+=1,Z===5){var G=R(O,H);if(!G)return!1;V+=G.length}if(J){if(typeof J!="object")return O.emit("error",new Error("Invalid will")),!1;if(!J.topic||typeof J.topic!="string")return O.emit("error",new Error("Invalid will topic")),!1;if(V+=a.byteLength(J.topic)+2,V+=2,J.payload){if(!(J.payload.length>=0))return O.emit("error",new Error("Invalid will payload")),!1;typeof J.payload=="string"?V+=a.byteLength(J.payload):V+=J.payload.length}var et={};if(Z===5){if(!(et=R(O,J.properties)))return!1;V+=et.length}}let tt=!1;if(P!=null){if(!X(P))return O.emit("error",new Error("Invalid username")),!1;tt=!0,V+=a.byteLength(P)+2}if(M!=null){if(!tt)return O.emit("error",new Error("Username is required to use password")),!1;if(!X(M))return O.emit("error",new Error("Invalid password")),!1;V+=j(M)+2}O.write(o.CONNECT_HEADER),S(O,V),T(O,Y),$.bridgeMode&&(Z+=128),O.write(Z===131?o.VERSION131:Z===132?o.VERSION132:Z===4?o.VERSION4:Z===5?o.VERSION5:o.VERSION3);let at=0;return at|=P!=null?o.USERNAME_MASK:0,at|=M!=null?o.PASSWORD_MASK:0,at|=J&&J.retain?o.WILL_RETAIN_MASK:0,at|=J&&J.qos?J.qos<<o.WILL_QOS_SHIFT:0,at|=J?o.WILL_FLAG_MASK:0,at|=Q?o.CLEAN_SESSION_MASK:0,O.write(a.from([at])),p(O,w),Z===5&&G.write(),T(O,x),J&&(Z===5&&et.write(),I(O,J.topic),T(O,J.payload)),P!=null&&T(O,P),M!=null&&T(O,M),!0}(F,L);case"connack":return function(W,O,q){const $=q?q.protocolVersion:4,Y=W||{},Z=$===5?Y.reasonCode:Y.returnCode,J=Y.properties;let Q=2;if(typeof Z!="number")return O.emit("error",new Error("Invalid return code")),!1;let w=null;if($===5){if(!(w=R(O,J)))return!1;Q+=w.length}return O.write(o.CONNACK_HEADER),S(O,Q),O.write(Y.sessionPresent?o.SESSIONPRESENT_HEADER:n),O.write(a.from([Z])),w!=null&&w.write(),!0}(F,L,N);case"publish":return function(W,O,q){f("publish: packet: %o",W);const $=q?q.protocolVersion:4,Y=W||{},Z=Y.qos||0,J=Y.retain?o.RETAIN_MASK:0,Q=Y.topic,w=Y.payload||l,x=Y.messageId,P=Y.properties;let M=0;if(typeof Q=="string")M+=a.byteLength(Q)+2;else{if(!a.isBuffer(Q))return O.emit("error",new Error("Invalid topic")),!1;M+=Q.length+2}if(a.isBuffer(w)?M+=w.length:M+=a.byteLength(w),Z&&typeof x!="number")return O.emit("error",new Error("Invalid messageId")),!1;Z&&(M+=2);let H=null;if($===5){if(!(H=R(O,P)))return!1;M+=H.length}return O.write(o.PUBLISH_HEADER[Z][Y.dup?1:0][J?1:0]),S(O,M),p(O,j(Q)),O.write(Q),Z>0&&p(O,x),H!=null&&H.write(),f("publish: payload: %o",w),O.write(w)}(F,L,N);case"puback":case"pubrec":case"pubrel":case"pubcomp":return function(W,O,q){const $=q?q.protocolVersion:4,Y=W||{},Z=Y.cmd||"puback",J=Y.messageId,Q=Y.dup&&Z==="pubrel"?o.DUP_MASK:0;let w=0;const x=Y.reasonCode,P=Y.properties;let M=$===5?3:2;if(Z==="pubrel"&&(w=1),typeof J!="number")return O.emit("error",new Error("Invalid messageId")),!1;let H=null;if($===5&&typeof P=="object"){if(!(H=C(O,P,q,M)))return!1;M+=H.length}return O.write(o.ACKS[Z][w][Q][0]),S(O,M),p(O,J),$===5&&O.write(a.from([x])),H!==null&&H.write(),!0}(F,L,N);case"subscribe":return function(W,O,q){f("subscribe: packet: ");const $=q?q.protocolVersion:4,Y=W||{},Z=Y.dup?o.DUP_MASK:0,J=Y.messageId,Q=Y.subscriptions,w=Y.properties;let x=0;if(typeof J!="number")return O.emit("error",new Error("Invalid messageId")),!1;x+=2;let P=null;if($===5){if(!(P=R(O,w)))return!1;x+=P.length}if(typeof Q!="object"||!Q.length)return O.emit("error",new Error("Invalid subscriptions")),!1;for(let H=0;H<Q.length;H+=1){const V=Q[H].topic,G=Q[H].qos;if(typeof V!="string")return O.emit("error",new Error("Invalid subscriptions - invalid topic")),!1;if(typeof G!="number")return O.emit("error",new Error("Invalid subscriptions - invalid qos")),!1;if($===5){if(typeof(Q[H].nl||!1)!="boolean")return O.emit("error",new Error("Invalid subscriptions - invalid No Local")),!1;if(typeof(Q[H].rap||!1)!="boolean")return O.emit("error",new Error("Invalid subscriptions - invalid Retain as Published")),!1;const at=Q[H].rh||0;if(typeof at!="number"||at>2)return O.emit("error",new Error("Invalid subscriptions - invalid Retain Handling")),!1}x+=a.byteLength(V)+2+1}f("subscribe: writing to stream: %o",o.SUBSCRIBE_HEADER),O.write(o.SUBSCRIBE_HEADER[1][Z?1:0][0]),S(O,x),p(O,J),P!==null&&P.write();let M=!0;for(const H of Q){const V=H.topic,G=H.qos,et=+H.nl,tt=+H.rap,at=H.rh;let ot;I(O,V),ot=o.SUBSCRIBE_OPTIONS_QOS[G],$===5&&(ot|=et?o.SUBSCRIBE_OPTIONS_NL:0,ot|=tt?o.SUBSCRIBE_OPTIONS_RAP:0,ot|=at?o.SUBSCRIBE_OPTIONS_RH[at]:0),M=O.write(a.from([ot]))}return M}(F,L,N);case"suback":return function(W,O,q){const $=q?q.protocolVersion:4,Y=W||{},Z=Y.messageId,J=Y.granted,Q=Y.properties;let w=0;if(typeof Z!="number")return O.emit("error",new Error("Invalid messageId")),!1;if(w+=2,typeof J!="object"||!J.length)return O.emit("error",new Error("Invalid qos vector")),!1;for(let P=0;P<J.length;P+=1){if(typeof J[P]!="number")return O.emit("error",new Error("Invalid qos vector")),!1;w+=1}let x=null;if($===5){if(!(x=C(O,Q,q,w)))return!1;w+=x.length}return O.write(o.SUBACK_HEADER),S(O,w),p(O,Z),x!==null&&x.write(),O.write(a.from(J))}(F,L,N);case"unsubscribe":return function(W,O,q){const $=q?q.protocolVersion:4,Y=W||{},Z=Y.messageId,J=Y.dup?o.DUP_MASK:0,Q=Y.unsubscriptions,w=Y.properties;let x=0;if(typeof Z!="number")return O.emit("error",new Error("Invalid messageId")),!1;if(x+=2,typeof Q!="object"||!Q.length)return O.emit("error",new Error("Invalid unsubscriptions")),!1;for(let H=0;H<Q.length;H+=1){if(typeof Q[H]!="string")return O.emit("error",new Error("Invalid unsubscriptions")),!1;x+=a.byteLength(Q[H])+2}let P=null;if($===5){if(!(P=R(O,w)))return!1;x+=P.length}O.write(o.UNSUBSCRIBE_HEADER[1][J?1:0][0]),S(O,x),p(O,Z),P!==null&&P.write();let M=!0;for(let H=0;H<Q.length;H++)M=I(O,Q[H]);return M}(F,L,N);case"unsuback":return function(W,O,q){const $=q?q.protocolVersion:4,Y=W||{},Z=Y.messageId,J=Y.dup?o.DUP_MASK:0,Q=Y.granted,w=Y.properties,x=Y.cmd;let P=2;if(typeof Z!="number")return O.emit("error",new Error("Invalid messageId")),!1;if($===5){if(typeof Q!="object"||!Q.length)return O.emit("error",new Error("Invalid qos vector")),!1;for(let H=0;H<Q.length;H+=1){if(typeof Q[H]!="number")return O.emit("error",new Error("Invalid qos vector")),!1;P+=1}}let M=null;if($===5){if(!(M=C(O,w,q,P)))return!1;P+=M.length}return O.write(o.ACKS[x][0][J][0]),S(O,P),p(O,Z),M!==null&&M.write(),$===5&&O.write(a.from(Q)),!0}(F,L,N);case"pingreq":case"pingresp":return function(W,O,q){return O.write(o.EMPTY[W.cmd])}(F,L);case"disconnect":return function(W,O,q){const $=q?q.protocolVersion:4,Y=W||{},Z=Y.reasonCode,J=Y.properties;let Q=$===5?1:0,w=null;if($===5){if(!(w=C(O,J,q,Q)))return!1;Q+=w.length}return O.write(a.from([o.codes.disconnect<<4])),S(O,Q),$===5&&O.write(a.from([Z])),w!==null&&w.write(),!0}(F,L,N);case"auth":return function(W,O,q){const $=q?q.protocolVersion:4,Y=W||{},Z=Y.reasonCode,J=Y.properties;let Q=$===5?1:0;$!==5&&O.emit("error",new Error("Invalid mqtt version for auth packet"));const w=C(O,J,q,Q);return w?(Q+=w.length,O.write(a.from([o.codes.auth<<4])),S(O,Q),O.write(a.from([Z])),w!==null&&w.write(),!0):!1}(F,L,N);default:return L.emit("error",new Error("Unknown command")),!1}}function k(F){F.uncork()}Object.defineProperty(m,"cacheNumbers",{get:()=>p===z,set(F){F?(u&&Object.keys(u).length!==0||(b=!0),p=z):(b=!1,p=U)}});const A={};function S(F,L){if(L>o.VARBYTEINT_MAX)return F.emit("error",new Error(`Invalid variable byte integer: ${L}`)),!1;let N=A[L];return N||(N=g(L),L<16384&&(A[L]=N)),f("writeVarByteInt: writing to stream: %o",N),F.write(N)}function I(F,L){const N=a.byteLength(L);return p(F,N),f("writeString: %s",L),F.write(L,"utf8")}function E(F,L,N){I(F,L),I(F,N)}function z(F,L){return f("writeNumberCached: number: %d",L),f("writeNumberCached: %o",u[L]),F.write(u[L])}function U(F,L){const N=d(L);return f("writeNumberGenerated: %o",N),F.write(N)}function T(F,L){typeof L=="string"?I(F,L):L?(p(F,L.length),F.write(L)):p(F,0)}function R(F,L){if(typeof L!="object"||L.length!=null)return{length:1,write(){B(F,{},0)}};let N=0;function W(O,q){let $=0;switch(o.propertiesTypes[O]){case"byte":if(typeof q!="boolean")return F.emit("error",new Error(`Invalid ${O}: ${q}`)),!1;$+=2;break;case"int8":if(typeof q!="number"||q<0||q>255)return F.emit("error",new Error(`Invalid ${O}: ${q}`)),!1;$+=2;break;case"binary":if(q&&q===null)return F.emit("error",new Error(`Invalid ${O}: ${q}`)),!1;$+=1+a.byteLength(q)+2;break;case"int16":if(typeof q!="number"||q<0||q>65535)return F.emit("error",new Error(`Invalid ${O}: ${q}`)),!1;$+=3;break;case"int32":if(typeof q!="number"||q<0||q>4294967295)return F.emit("error",new Error(`Invalid ${O}: ${q}`)),!1;$+=5;break;case"var":if(typeof q!="number"||q<0||q>268435455)return F.emit("error",new Error(`Invalid ${O}: ${q}`)),!1;$+=1+a.byteLength(g(q));break;case"string":if(typeof q!="string")return F.emit("error",new Error(`Invalid ${O}: ${q}`)),!1;$+=3+a.byteLength(q.toString());break;case"pair":if(typeof q!="object")return F.emit("error",new Error(`Invalid ${O}: ${q}`)),!1;$+=Object.getOwnPropertyNames(q).reduce((Y,Z)=>{const J=q[Z];return Array.isArray(J)?Y+=J.reduce((Q,w)=>Q+=3+a.byteLength(Z.toString())+2+a.byteLength(w.toString()),0):Y+=3+a.byteLength(Z.toString())+2+a.byteLength(q[Z].toString()),Y},0);break;default:return F.emit("error",new Error(`Invalid property ${O}: ${q}`)),!1}return $}if(L)for(const O in L){let q=0,$=0;const Y=L[O];if(Array.isArray(Y))for(let Z=0;Z<Y.length;Z++){if(!($=W(O,Y[Z])))return!1;q+=$}else{if(!($=W(O,Y)))return!1;q=$}if(!q)return!1;N+=q}return{length:a.byteLength(g(N))+N,write(){B(F,L,N)}}}function C(F,L,N,W){const O=["reasonString","userProperties"],q=N&&N.properties&&N.properties.maximumPacketSize?N.properties.maximumPacketSize:0;let $=R(F,L);if(q)for(;W+$.length>q;){const Y=O.shift();if(!Y||!L[Y])return!1;delete L[Y],$=R(F,L)}return $}function _(F,L,N){switch(o.propertiesTypes[L]){case"byte":F.write(a.from([o.properties[L]])),F.write(a.from([+N]));break;case"int8":F.write(a.from([o.properties[L]])),F.write(a.from([N]));break;case"binary":F.write(a.from([o.properties[L]])),T(F,N);break;case"int16":F.write(a.from([o.properties[L]])),p(F,N);break;case"int32":F.write(a.from([o.properties[L]])),function(W,O){const q=y(O);f("write4ByteNumber: %o",q),W.write(q)}(F,N);break;case"var":F.write(a.from([o.properties[L]])),S(F,N);break;case"string":F.write(a.from([o.properties[L]])),I(F,N);break;case"pair":Object.getOwnPropertyNames(N).forEach(W=>{const O=N[W];Array.isArray(O)?O.forEach(q=>{F.write(a.from([o.properties[L]])),E(F,W.toString(),q.toString())}):(F.write(a.from([o.properties[L]])),E(F,W.toString(),O.toString()))});break;default:return F.emit("error",new Error(`Invalid property ${L} value: ${N}`)),!1}}function B(F,L,N){S(F,N);for(const W in L)if(Object.prototype.hasOwnProperty.call(L,W)&&L[W]!==null){const O=L[W];if(Array.isArray(O))for(let q=0;q<O.length;q++)_(F,W,O[q]);else _(F,W,O)}}function j(F){return F?F instanceof a?F.length:a.byteLength(F):0}function X(F){return typeof F=="string"||F instanceof a}s.exports=m}).call(this)}).call(this,i("buffer").Buffer)},{"./constants":38,"./numbers":41,buffer:17,debug:18,"process-nextick-args":49}],45:[function(i,s,r){var a=1e3,o=60*a,l=60*o,n=24*l,h=7*n,c=365.25*n;function f(u,d,v,g){var y=d>=1.5*v;return Math.round(u/v)+" "+g+(y?"s":"")}s.exports=function(u,d){d=d||{};var v=typeof u;if(v==="string"&&u.length>0)return function(g){if(!((g=String(g)).length>100)){var y=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(g);if(y){var p=parseFloat(y[1]);switch((y[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return p*c;case"weeks":case"week":case"w":return p*h;case"days":case"day":case"d":return p*n;case"hours":case"hour":case"hrs":case"hr":case"h":return p*l;case"minutes":case"minute":case"mins":case"min":case"m":return p*o;case"seconds":case"second":case"secs":case"sec":case"s":return p*a;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return p;default:return}}}}(u);if(v==="number"&&isFinite(u))return d.long?function(g){var y=Math.abs(g);return y>=n?f(g,y,n,"day"):y>=l?f(g,y,l,"hour"):y>=o?f(g,y,o,"minute"):y>=a?f(g,y,a,"second"):g+" ms"}(u):function(g){var y=Math.abs(g);return y>=n?Math.round(g/n)+"d":y>=l?Math.round(g/l)+"h":y>=o?Math.round(g/o)+"m":y>=a?Math.round(g/a)+"s":g+"ms"}(u);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(u))}},{}],46:[function(i,s,r){const a=i("./lib/number-allocator.js");s.exports.NumberAllocator=a},{"./lib/number-allocator.js":47}],47:[function(i,s,r){const a=i("js-sdsl").Set,o=i("debug")("number-allocator:trace"),l=i("debug")("number-allocator:error");function n(c,f){this.low=c,this.high=f}function h(c,f){if(!(this instanceof h))return new h(c,f);this.min=c,this.max=f,this.ss=new a([],(u,d)=>u.compare(d)),o("Create"),this.clear()}n.prototype.equals=function(c){return this.low===c.low&&this.high===c.high},n.prototype.compare=function(c){return this.low<c.low&&this.high<c.low?-1:c.low<this.low&&c.high<this.low?1:0},h.prototype.firstVacant=function(){return this.ss.size()===0?null:this.ss.front().low},h.prototype.alloc=function(){if(this.ss.size()===0)return o("alloc():empty"),null;const c=this.ss.front(),f=c.low;return f+1<=c.high?++c.low:this.ss.eraseElementByPos(0),o("alloc():"+f),f},h.prototype.use=function(c){const f=new n(c,c),u=this.ss.lowerBound(f);if(u){if(u.equals(f))return this.ss.eraseElementByValue(u),o("use():"+c),!0;if(u.low>c)return!1;if(u.low===c)return++u.low,o("use():"+c),!0;if(u.high===c)return--u.high,o("use():"+c),!0;const d=u.low;return u.low=c+1,this.ss.insert(new n(d,c-1)),o("use():"+c),!0}return o("use():failed"),!1},h.prototype.free=function(c){if(c<this.min||c>this.max)return void l("free():"+c+" is out of range");const f=new n(c,c),u=this.ss.lowerBound(f);if(u){if(u.low<=c&&c<=u.high)return void l("free():"+c+" has already been vacant");if(u===this.ss.front())c+1===u.low?--u.low:this.ss.insert(f);else{const d=this.ss.reverseLowerBound(f);d.high+1===c?c+1===u.low?(this.ss.eraseElementByValue(d),u.low=d.low):d.high=c:c+1===u.low?u.low=c:this.ss.insert(f)}}else{if(u===this.ss.front())return void this.ss.insert(f);const d=this.ss.reverseLowerBound(f);d.high+1===c?d.high=c:this.ss.insert(f)}o("free():"+c)},h.prototype.clear=function(){o("clear()"),this.ss.clear(),this.ss.insert(new n(this.min,this.max))},h.prototype.intervalCount=function(){return this.ss.size()},h.prototype.dump=function(){console.log("length:"+this.ss.size());for(const c of this.ss)console.log(c)},s.exports=h},{debug:18,"js-sdsl":36}],48:[function(i,s,r){var a=i("wrappy");function o(n){var h=function(){return h.called?h.value:(h.called=!0,h.value=n.apply(this,arguments))};return h.called=!1,h}function l(n){var h=function(){if(h.called)throw new Error(h.onceError);return h.called=!0,h.value=n.apply(this,arguments)},c=n.name||"Function wrapped with `once`";return h.onceError=c+" shouldn't be called more than once",h.called=!1,h}s.exports=a(o),s.exports.strict=a(l),o.proto=o(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return o(this)},configurable:!0}),Object.defineProperty(Function.prototype,"onceStrict",{value:function(){return l(this)},configurable:!0})})},{wrappy:79}],49:[function(i,s,r){(function(a){(function(){a===void 0||!a.version||a.version.indexOf("v0.")===0||a.version.indexOf("v1.")===0&&a.version.indexOf("v1.8.")!==0?s.exports={nextTick:function(o,l,n,h){if(typeof o!="function")throw new TypeError('"callback" argument must be a function');var c,f,u=arguments.length;switch(u){case 0:case 1:return a.nextTick(o);case 2:return a.nextTick(function(){o.call(null,l)});case 3:return a.nextTick(function(){o.call(null,l,n)});case 4:return a.nextTick(function(){o.call(null,l,n,h)});default:for(c=new Array(u-1),f=0;f<c.length;)c[f++]=arguments[f];return a.nextTick(function(){o.apply(null,c)})}}}:s.exports=a}).call(this)}).call(this,i("_process"))},{_process:50}],50:[function(i,s,r){var a,o,l=s.exports={};function n(){throw new Error("setTimeout has not been defined")}function h(){throw new Error("clearTimeout has not been defined")}function c(m){if(a===setTimeout)return setTimeout(m,0);if((a===n||!a)&&setTimeout)return a=setTimeout,setTimeout(m,0);try{return a(m,0)}catch{try{return a.call(null,m,0)}catch{return a.call(this,m,0)}}}(function(){try{a=typeof setTimeout=="function"?setTimeout:n}catch{a=n}try{o=typeof clearTimeout=="function"?clearTimeout:h}catch{o=h}})();var f,u=[],d=!1,v=-1;function g(){d&&f&&(d=!1,f.length?u=f.concat(u):v=-1,u.length&&y())}function y(){if(!d){var m=c(g);d=!0;for(var k=u.length;k;){for(f=u,u=[];++v<k;)f&&f[v].run();v=-1,k=u.length}f=null,d=!1,function(A){if(o===clearTimeout)return clearTimeout(A);if((o===h||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(A);try{o(A)}catch{try{return o.call(null,A)}catch{return o.call(this,A)}}}(m)}}function p(m,k){this.fun=m,this.array=k}function b(){}l.nextTick=function(m){var k=new Array(arguments.length-1);if(arguments.length>1)for(var A=1;A<arguments.length;A++)k[A-1]=arguments[A];u.push(new p(m,k)),u.length!==1||d||c(y)},p.prototype.run=function(){this.fun.apply(null,this.array)},l.title="browser",l.browser=!0,l.env={},l.argv=[],l.version="",l.versions={},l.on=b,l.addListener=b,l.once=b,l.off=b,l.removeListener=b,l.removeAllListeners=b,l.emit=b,l.prependListener=b,l.prependOnceListener=b,l.listeners=function(m){return[]},l.binding=function(m){throw new Error("process.binding is not supported")},l.cwd=function(){return"/"},l.chdir=function(m){throw new Error("process.chdir is not supported")},l.umask=function(){return 0}},{}],51:[function(i,s,r){(function(a){(function(){(function(o){var l=typeof r=="object"&&r&&!r.nodeType&&r,n=typeof s=="object"&&s&&!s.nodeType&&s,h=typeof a=="object"&&a;h.global!==h&&h.window!==h&&h.self!==h||(o=h);var c,f,u=2147483647,d=36,v=1,g=26,y=38,p=700,b=72,m=128,k="-",A=/^xn--/,S=/[^\x20-\x7E]/,I=/[\x2E\u3002\uFF0E\uFF61]/g,E={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},z=d-v,U=Math.floor,T=String.fromCharCode;function R(W){throw new RangeError(E[W])}function C(W,O){for(var q=W.length,$=[];q--;)$[q]=O(W[q]);return $}function _(W,O){var q=W.split("@"),$="";return q.length>1&&($=q[0]+"@",W=q[1]),$+C((W=W.replace(I,".")).split("."),O).join(".")}function B(W){for(var O,q,$=[],Y=0,Z=W.length;Y<Z;)(O=W.charCodeAt(Y++))>=55296&&O<=56319&&Y<Z?(64512&(q=W.charCodeAt(Y++)))==56320?$.push(((1023&O)<<10)+(1023&q)+65536):($.push(O),Y--):$.push(O);return $}function j(W){return C(W,function(O){var q="";return O>65535&&(q+=T((O-=65536)>>>10&1023|55296),O=56320|1023&O),q+=T(O)}).join("")}function X(W,O){return W+22+75*(W<26)-((O!=0)<<5)}function F(W,O,q){var $=0;for(W=q?U(W/p):W>>1,W+=U(W/O);W>z*g>>1;$+=d)W=U(W/z);return U($+(z+1)*W/(W+y))}function L(W){var O,q,$,Y,Z,J,Q,w,x,P,M,H=[],V=W.length,G=0,et=m,tt=b;for((q=W.lastIndexOf(k))<0&&(q=0),$=0;$<q;++$)W.charCodeAt($)>=128&&R("not-basic"),H.push(W.charCodeAt($));for(Y=q>0?q+1:0;Y<V;){for(Z=G,J=1,Q=d;Y>=V&&R("invalid-input"),((w=(M=W.charCodeAt(Y++))-48<10?M-22:M-65<26?M-65:M-97<26?M-97:d)>=d||w>U((u-G)/J))&&R("overflow"),G+=w*J,!(w<(x=Q<=tt?v:Q>=tt+g?g:Q-tt));Q+=d)J>U(u/(P=d-x))&&R("overflow"),J*=P;tt=F(G-Z,O=H.length+1,Z==0),U(G/O)>u-et&&R("overflow"),et+=U(G/O),G%=O,H.splice(G++,0,et)}return j(H)}function N(W){var O,q,$,Y,Z,J,Q,w,x,P,M,H,V,G,et,tt=[];for(H=(W=B(W)).length,O=m,q=0,Z=b,J=0;J<H;++J)(M=W[J])<128&&tt.push(T(M));for($=Y=tt.length,Y&&tt.push(k);$<H;){for(Q=u,J=0;J<H;++J)(M=W[J])>=O&&M<Q&&(Q=M);for(Q-O>U((u-q)/(V=$+1))&&R("overflow"),q+=(Q-O)*V,O=Q,J=0;J<H;++J)if((M=W[J])<O&&++q>u&&R("overflow"),M==O){for(w=q,x=d;!(w<(P=x<=Z?v:x>=Z+g?g:x-Z));x+=d)et=w-P,G=d-P,tt.push(T(X(P+et%G,0))),w=U(et/G);tt.push(T(X(w,0))),Z=F(q,V,$==Y),q=0,++$}++q,++O}return tt.join("")}if(c={version:"1.4.1",ucs2:{decode:B,encode:j},decode:L,encode:N,toASCII:function(W){return _(W,function(O){return S.test(O)?"xn--"+N(O):O})},toUnicode:function(W){return _(W,function(O){return A.test(O)?L(O.slice(4).toLowerCase()):O})}},l&&n)if(s.exports==l)n.exports=c;else for(f in c)c.hasOwnProperty(f)&&(l[f]=c[f]);else o.punycode=c})(this)}).call(this)}).call(this,typeof Ut<"u"?Ut:typeof self<"u"?self:typeof window<"u"?window:{})},{}],52:[function(i,s,r){function a(l,n){return Object.prototype.hasOwnProperty.call(l,n)}s.exports=function(l,n,h,c){n=n||"&",h=h||"=";var f={};if(typeof l!="string"||l.length===0)return f;var u=/\+/g;l=l.split(n);var d=1e3;c&&typeof c.maxKeys=="number"&&(d=c.maxKeys);var v=l.length;d>0&&v>d&&(v=d);for(var g=0;g<v;++g){var y,p,b,m,k=l[g].replace(u,"%20"),A=k.indexOf(h);A>=0?(y=k.substr(0,A),p=k.substr(A+1)):(y=k,p=""),b=decodeURIComponent(y),m=decodeURIComponent(p),a(f,b)?o(f[b])?f[b].push(m):f[b]=[f[b],m]:f[b]=m}return f};var o=Array.isArray||function(l){return Object.prototype.toString.call(l)==="[object Array]"}},{}],53:[function(i,s,r){var a=function(h){switch(typeof h){case"string":return h;case"boolean":return h?"true":"false";case"number":return isFinite(h)?h:"";default:return""}};s.exports=function(h,c,f,u){return c=c||"&",f=f||"=",h===null&&(h=void 0),typeof h=="object"?l(n(h),function(d){var v=encodeURIComponent(a(d))+f;return o(h[d])?l(h[d],function(g){return v+encodeURIComponent(a(g))}).join(c):v+encodeURIComponent(a(h[d]))}).join(c):u?encodeURIComponent(a(u))+f+encodeURIComponent(a(h)):""};var o=Array.isArray||function(h){return Object.prototype.toString.call(h)==="[object Array]"};function l(h,c){if(h.map)return h.map(c);for(var f=[],u=0;u<h.length;u++)f.push(c(h[u],u));return f}var n=Object.keys||function(h){var c=[];for(var f in h)Object.prototype.hasOwnProperty.call(h,f)&&c.push(f);return c}},{}],54:[function(i,s,r){r.decode=r.parse=i("./decode"),r.encode=r.stringify=i("./encode")},{"./decode":52,"./encode":53}],55:[function(i,s,r){var a={};function o(n,h,c){c||(c=Error);var f=function(u){var d,v;function g(y,p,b){return u.call(this,function(m,k,A){return typeof h=="string"?h:h(m,k,A)}(y,p,b))||this}return v=u,(d=g).prototype=Object.create(v.prototype),d.prototype.constructor=d,d.__proto__=v,g}(c);f.prototype.name=c.name,f.prototype.code=n,a[n]=f}function l(n,h){if(Array.isArray(n)){var c=n.length;return n=n.map(function(f){return String(f)}),c>2?"one of ".concat(h," ").concat(n.slice(0,c-1).join(", "),", or ")+n[c-1]:c===2?"one of ".concat(h," ").concat(n[0]," or ").concat(n[1]):"of ".concat(h," ").concat(n[0])}return"of ".concat(h," ").concat(String(n))}o("ERR_INVALID_OPT_VALUE",function(n,h){return'The value "'+h+'" is invalid for option "'+n+'"'},TypeError),o("ERR_INVALID_ARG_TYPE",function(n,h,c){var f,u,d;if(typeof h=="string"&&(u="not ",h.substr(0,u.length)===u)?(f="must not be",h=h.replace(/^not /,"")):f="must be",function(g,y,p){return(p===void 0||p>g.length)&&(p=g.length),g.substring(p-y.length,p)===y}(n," argument"))d="The ".concat(n," ").concat(f," ").concat(l(h,"type"));else{var v=function(g,y,p){return typeof p!="number"&&(p=0),!(p+y.length>g.length)&&g.indexOf(y,p)!==-1}(n,".")?"property":"argument";d='The "'.concat(n,'" ').concat(v," ").concat(f," ").concat(l(h,"type"))}return d+=". Received type ".concat(typeof c)},TypeError),o("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),o("ERR_METHOD_NOT_IMPLEMENTED",function(n){return"The "+n+" method is not implemented"}),o("ERR_STREAM_PREMATURE_CLOSE","Premature close"),o("ERR_STREAM_DESTROYED",function(n){return"Cannot call "+n+" after a stream was destroyed"}),o("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),o("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),o("ERR_STREAM_WRITE_AFTER_END","write after end"),o("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),o("ERR_UNKNOWN_ENCODING",function(n){return"Unknown encoding: "+n},TypeError),o("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),s.exports.codes=a},{}],56:[function(i,s,r){(function(a){(function(){var o=Object.keys||function(g){var y=[];for(var p in g)y.push(p);return y};s.exports=u;var l=i("./_stream_readable"),n=i("./_stream_writable");i("inherits")(u,l);for(var h=o(n.prototype),c=0;c<h.length;c++){var f=h[c];u.prototype[f]||(u.prototype[f]=n.prototype[f])}function u(g){if(!(this instanceof u))return new u(g);l.call(this,g),n.call(this,g),this.allowHalfOpen=!0,g&&(g.readable===!1&&(this.readable=!1),g.writable===!1&&(this.writable=!1),g.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",d)))}function d(){this._writableState.ended||a.nextTick(v,this)}function v(g){g.end()}Object.defineProperty(u.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(u.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(u.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(u.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._writableState!==void 0&&this._readableState.destroyed&&this._writableState.destroyed},set:function(g){this._readableState!==void 0&&this._writableState!==void 0&&(this._readableState.destroyed=g,this._writableState.destroyed=g)}})}).call(this)}).call(this,i("_process"))},{"./_stream_readable":58,"./_stream_writable":60,_process:50,inherits:24}],57:[function(i,s,r){s.exports=o;var a=i("./_stream_transform");function o(l){if(!(this instanceof o))return new o(l);a.call(this,l)}i("inherits")(o,a),o.prototype._transform=function(l,n,h){h(null,l)}},{"./_stream_transform":59,inherits:24}],58:[function(i,s,r){(function(a,o){(function(){var l;s.exports=R,R.ReadableState=T,i("events").EventEmitter;var n=function(w,x){return w.listeners(x).length},h=i("./internal/streams/stream"),c=i("buffer").Buffer,f=o.Uint8Array||function(){},u,d=i("util");u=d&&d.debuglog?d.debuglog("stream"):function(){};var v,g,y,p=i("./internal/streams/buffer_list"),b=i("./internal/streams/destroy"),m=i("./internal/streams/state").getHighWaterMark,k=i("../errors").codes,A=k.ERR_INVALID_ARG_TYPE,S=k.ERR_STREAM_PUSH_AFTER_EOF,I=k.ERR_METHOD_NOT_IMPLEMENTED,E=k.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;i("inherits")(R,h);var z=b.errorOrDestroy,U=["error","close","destroy","pause","resume"];function T(w,x,P){l=l||i("./_stream_duplex"),w=w||{},typeof P!="boolean"&&(P=x instanceof l),this.objectMode=!!w.objectMode,P&&(this.objectMode=this.objectMode||!!w.readableObjectMode),this.highWaterMark=m(this,w,"readableHighWaterMark",P),this.buffer=new p,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=w.emitClose!==!1,this.autoDestroy=!!w.autoDestroy,this.destroyed=!1,this.defaultEncoding=w.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,w.encoding&&(v||(v=i("string_decoder/").StringDecoder),this.decoder=new v(w.encoding),this.encoding=w.encoding)}function R(w){if(l=l||i("./_stream_duplex"),!(this instanceof R))return new R(w);var x=this instanceof l;this._readableState=new T(w,this,x),this.readable=!0,w&&(typeof w.read=="function"&&(this._read=w.read),typeof w.destroy=="function"&&(this._destroy=w.destroy)),h.call(this)}function C(w,x,P,M,H){u("readableAddChunk",x);var V,G=w._readableState;if(x===null)G.reading=!1,function(et,tt){if(u("onEofChunk"),!tt.ended){if(tt.decoder){var at=tt.decoder.end();at&&at.length&&(tt.buffer.push(at),tt.length+=tt.objectMode?1:at.length)}tt.ended=!0,tt.sync?X(et):(tt.needReadable=!1,tt.emittedReadable||(tt.emittedReadable=!0,F(et)))}}(w,G);else if(H||(V=function(et,tt){var at;ot=tt,c.isBuffer(ot)||ot instanceof f||typeof tt=="string"||tt===void 0||et.objectMode||(at=new A("chunk",["string","Buffer","Uint8Array"],tt));var ot;return at}(G,x)),V)z(w,V);else if(G.objectMode||x&&x.length>0)if(typeof x=="string"||G.objectMode||Object.getPrototypeOf(x)===c.prototype||(x=function(et){return c.from(et)}(x)),M)G.endEmitted?z(w,new E):_(w,G,x,!0);else if(G.ended)z(w,new S);else{if(G.destroyed)return!1;G.reading=!1,G.decoder&&!P?(x=G.decoder.write(x),G.objectMode||x.length!==0?_(w,G,x,!1):L(w,G)):_(w,G,x,!1)}else M||(G.reading=!1,L(w,G));return!G.ended&&(G.length<G.highWaterMark||G.length===0)}function _(w,x,P,M){x.flowing&&x.length===0&&!x.sync?(x.awaitDrain=0,w.emit("data",P)):(x.length+=x.objectMode?1:P.length,M?x.buffer.unshift(P):x.buffer.push(P),x.needReadable&&X(w)),L(w,x)}Object.defineProperty(R.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._readableState.destroyed},set:function(w){this._readableState&&(this._readableState.destroyed=w)}}),R.prototype.destroy=b.destroy,R.prototype._undestroy=b.undestroy,R.prototype._destroy=function(w,x){x(w)},R.prototype.push=function(w,x){var P,M=this._readableState;return M.objectMode?P=!0:typeof w=="string"&&((x=x||M.defaultEncoding)!==M.encoding&&(w=c.from(w,x),x=""),P=!0),C(this,w,x,!1,P)},R.prototype.unshift=function(w){return C(this,w,null,!0,!1)},R.prototype.isPaused=function(){return this._readableState.flowing===!1},R.prototype.setEncoding=function(w){v||(v=i("string_decoder/").StringDecoder);var x=new v(w);this._readableState.decoder=x,this._readableState.encoding=this._readableState.decoder.encoding;for(var P=this._readableState.buffer.head,M="";P!==null;)M+=x.write(P.data),P=P.next;return this._readableState.buffer.clear(),M!==""&&this._readableState.buffer.push(M),this._readableState.length=M.length,this};var B=1073741824;function j(w,x){return w<=0||x.length===0&&x.ended?0:x.objectMode?1:w!=w?x.flowing&&x.length?x.buffer.head.data.length:x.length:(w>x.highWaterMark&&(x.highWaterMark=function(P){return P>=B?P=B:(P--,P|=P>>>1,P|=P>>>2,P|=P>>>4,P|=P>>>8,P|=P>>>16,P++),P}(w)),w<=x.length?w:x.ended?x.length:(x.needReadable=!0,0))}function X(w){var x=w._readableState;u("emitReadable",x.needReadable,x.emittedReadable),x.needReadable=!1,x.emittedReadable||(u("emitReadable",x.flowing),x.emittedReadable=!0,a.nextTick(F,w))}function F(w){var x=w._readableState;u("emitReadable_",x.destroyed,x.length,x.ended),x.destroyed||!x.length&&!x.ended||(w.emit("readable"),x.emittedReadable=!1),x.needReadable=!x.flowing&&!x.ended&&x.length<=x.highWaterMark,$(w)}function L(w,x){x.readingMore||(x.readingMore=!0,a.nextTick(N,w,x))}function N(w,x){for(;!x.reading&&!x.ended&&(x.length<x.highWaterMark||x.flowing&&x.length===0);){var P=x.length;if(u("maybeReadMore read 0"),w.read(0),P===x.length)break}x.readingMore=!1}function W(w){var x=w._readableState;x.readableListening=w.listenerCount("readable")>0,x.resumeScheduled&&!x.paused?x.flowing=!0:w.listenerCount("data")>0&&w.resume()}function O(w){u("readable nexttick read 0"),w.read(0)}function q(w,x){u("resume",x.reading),x.reading||w.read(0),x.resumeScheduled=!1,w.emit("resume"),$(w),x.flowing&&!x.reading&&w.read(0)}function $(w){var x=w._readableState;for(u("flow",x.flowing);x.flowing&&w.read()!==null;);}function Y(w,x){return x.length===0?null:(x.objectMode?P=x.buffer.shift():!w||w>=x.length?(P=x.decoder?x.buffer.join(""):x.buffer.length===1?x.buffer.first():x.buffer.concat(x.length),x.buffer.clear()):P=x.buffer.consume(w,x.decoder),P);var P}function Z(w){var x=w._readableState;u("endReadable",x.endEmitted),x.endEmitted||(x.ended=!0,a.nextTick(J,x,w))}function J(w,x){if(u("endReadableNT",w.endEmitted,w.length),!w.endEmitted&&w.length===0&&(w.endEmitted=!0,x.readable=!1,x.emit("end"),w.autoDestroy)){var P=x._writableState;(!P||P.autoDestroy&&P.finished)&&x.destroy()}}function Q(w,x){for(var P=0,M=w.length;P<M;P++)if(w[P]===x)return P;return-1}R.prototype.read=function(w){u("read",w),w=parseInt(w,10);var x=this._readableState,P=w;if(w!==0&&(x.emittedReadable=!1),w===0&&x.needReadable&&((x.highWaterMark!==0?x.length>=x.highWaterMark:x.length>0)||x.ended))return u("read: emitReadable",x.length,x.ended),x.length===0&&x.ended?Z(this):X(this),null;if((w=j(w,x))===0&&x.ended)return x.length===0&&Z(this),null;var M,H=x.needReadable;return u("need readable",H),(x.length===0||x.length-w<x.highWaterMark)&&u("length less than watermark",H=!0),x.ended||x.reading?u("reading or ended",H=!1):H&&(u("do read"),x.reading=!0,x.sync=!0,x.length===0&&(x.needReadable=!0),this._read(x.highWaterMark),x.sync=!1,x.reading||(w=j(P,x))),(M=w>0?Y(w,x):null)===null?(x.needReadable=x.length<=x.highWaterMark,w=0):(x.length-=w,x.awaitDrain=0),x.length===0&&(x.ended||(x.needReadable=!0),P!==w&&x.ended&&Z(this)),M!==null&&this.emit("data",M),M},R.prototype._read=function(w){z(this,new I("_read()"))},R.prototype.pipe=function(w,x){var P=this,M=this._readableState;switch(M.pipesCount){case 0:M.pipes=w;break;case 1:M.pipes=[M.pipes,w];break;default:M.pipes.push(w)}M.pipesCount+=1,u("pipe count=%d opts=%j",M.pipesCount,x);var H=(!x||x.end!==!1)&&w!==a.stdout&&w!==a.stderr?G:Ht;function V(mt,wt){u("onunpipe"),mt===P&&wt&&wt.hasUnpiped===!1&&(wt.hasUnpiped=!0,u("cleanup"),w.removeListener("close",Wt),w.removeListener("finish",Ft),w.removeListener("drain",et),w.removeListener("error",ot),w.removeListener("unpipe",V),P.removeListener("end",G),P.removeListener("end",Ht),P.removeListener("data",at),tt=!0,!M.awaitDrain||w._writableState&&!w._writableState.needDrain||et())}function G(){u("onend"),w.end()}M.endEmitted?a.nextTick(H):P.once("end",H),w.on("unpipe",V);var et=function(mt){return function(){var wt=mt._readableState;u("pipeOnDrain",wt.awaitDrain),wt.awaitDrain&&wt.awaitDrain--,wt.awaitDrain===0&&n(mt,"data")&&(wt.flowing=!0,$(mt))}}(P);w.on("drain",et);var tt=!1;function at(mt){u("ondata");var wt=w.write(mt);u("dest.write",wt),wt===!1&&((M.pipesCount===1&&M.pipes===w||M.pipesCount>1&&Q(M.pipes,w)!==-1)&&!tt&&(u("false write response, pause",M.awaitDrain),M.awaitDrain++),P.pause())}function ot(mt){u("onerror",mt),Ht(),w.removeListener("error",ot),n(w,"error")===0&&z(w,mt)}function Wt(){w.removeListener("finish",Ft),Ht()}function Ft(){u("onfinish"),w.removeListener("close",Wt),Ht()}function Ht(){u("unpipe"),P.unpipe(w)}return P.on("data",at),function(mt,wt,ti){if(typeof mt.prependListener=="function")return mt.prependListener(wt,ti);mt._events&&mt._events[wt]?Array.isArray(mt._events[wt])?mt._events[wt].unshift(ti):mt._events[wt]=[ti,mt._events[wt]]:mt.on(wt,ti)}(w,"error",ot),w.once("close",Wt),w.once("finish",Ft),w.emit("pipe",P),M.flowing||(u("pipe resume"),P.resume()),w},R.prototype.unpipe=function(w){var x=this._readableState,P={hasUnpiped:!1};if(x.pipesCount===0)return this;if(x.pipesCount===1)return w&&w!==x.pipes?this:(w||(w=x.pipes),x.pipes=null,x.pipesCount=0,x.flowing=!1,w&&w.emit("unpipe",this,P),this);if(!w){var M=x.pipes,H=x.pipesCount;x.pipes=null,x.pipesCount=0,x.flowing=!1;for(var V=0;V<H;V++)M[V].emit("unpipe",this,{hasUnpiped:!1});return this}var G=Q(x.pipes,w);return G===-1?this:(x.pipes.splice(G,1),x.pipesCount-=1,x.pipesCount===1&&(x.pipes=x.pipes[0]),w.emit("unpipe",this,P),this)},R.prototype.on=function(w,x){var P=h.prototype.on.call(this,w,x),M=this._readableState;return w==="data"?(M.readableListening=this.listenerCount("readable")>0,M.flowing!==!1&&this.resume()):w==="readable"&&(M.endEmitted||M.readableListening||(M.readableListening=M.needReadable=!0,M.flowing=!1,M.emittedReadable=!1,u("on readable",M.length,M.reading),M.length?X(this):M.reading||a.nextTick(O,this))),P},R.prototype.addListener=R.prototype.on,R.prototype.removeListener=function(w,x){var P=h.prototype.removeListener.call(this,w,x);return w==="readable"&&a.nextTick(W,this),P},R.prototype.removeAllListeners=function(w){var x=h.prototype.removeAllListeners.apply(this,arguments);return w!=="readable"&&w!==void 0||a.nextTick(W,this),x},R.prototype.resume=function(){var w=this._readableState;return w.flowing||(u("resume"),w.flowing=!w.readableListening,function(x,P){P.resumeScheduled||(P.resumeScheduled=!0,a.nextTick(q,x,P))}(this,w)),w.paused=!1,this},R.prototype.pause=function(){return u("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(u("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},R.prototype.wrap=function(w){var x=this,P=this._readableState,M=!1;for(var H in w.on("end",function(){if(u("wrapped end"),P.decoder&&!P.ended){var G=P.decoder.end();G&&G.length&&x.push(G)}x.push(null)}),w.on("data",function(G){u("wrapped data"),P.decoder&&(G=P.decoder.write(G)),(!P.objectMode||G!=null)&&(P.objectMode||G&&G.length)&&(x.push(G)||(M=!0,w.pause()))}),w)this[H]===void 0&&typeof w[H]=="function"&&(this[H]=function(G){return function(){return w[G].apply(w,arguments)}}(H));for(var V=0;V<U.length;V++)w.on(U[V],this.emit.bind(this,U[V]));return this._read=function(G){u("wrapped _read",G),M&&(M=!1,w.resume())},this},typeof Symbol=="function"&&(R.prototype[Symbol.asyncIterator]=function(){return g===void 0&&(g=i("./internal/streams/async_iterator")),g(this)}),Object.defineProperty(R.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(R.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(R.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(w){this._readableState&&(this._readableState.flowing=w)}}),R._fromList=Y,Object.defineProperty(R.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),typeof Symbol=="function"&&(R.from=function(w,x){return y===void 0&&(y=i("./internal/streams/from")),y(R,w,x)})}).call(this)}).call(this,i("_process"),typeof Ut<"u"?Ut:typeof self<"u"?self:typeof window<"u"?window:{})},{"../errors":55,"./_stream_duplex":56,"./internal/streams/async_iterator":61,"./internal/streams/buffer_list":62,"./internal/streams/destroy":63,"./internal/streams/from":65,"./internal/streams/state":67,"./internal/streams/stream":68,_process:50,buffer:17,events:22,inherits:24,"string_decoder/":75,util:16}],59:[function(i,s,r){s.exports=f;var a=i("../errors").codes,o=a.ERR_METHOD_NOT_IMPLEMENTED,l=a.ERR_MULTIPLE_CALLBACK,n=a.ERR_TRANSFORM_ALREADY_TRANSFORMING,h=a.ERR_TRANSFORM_WITH_LENGTH_0,c=i("./_stream_duplex");function f(v){if(!(this instanceof f))return new f(v);c.call(this,v),this._transformState={afterTransform:(function(g,y){var p=this._transformState;p.transforming=!1;var b=p.writecb;if(b===null)return this.emit("error",new l);p.writechunk=null,p.writecb=null,y!=null&&this.push(y),b(g);var m=this._readableState;m.reading=!1,(m.needReadable||m.length<m.highWaterMark)&&this._read(m.highWaterMark)}).bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,v&&(typeof v.transform=="function"&&(this._transform=v.transform),typeof v.flush=="function"&&(this._flush=v.flush)),this.on("prefinish",u)}function u(){var v=this;typeof this._flush!="function"||this._readableState.destroyed?d(this,null,null):this._flush(function(g,y){d(v,g,y)})}function d(v,g,y){if(g)return v.emit("error",g);if(y!=null&&v.push(y),v._writableState.length)throw new h;if(v._transformState.transforming)throw new n;return v.push(null)}i("inherits")(f,c),f.prototype.push=function(v,g){return this._transformState.needTransform=!1,c.prototype.push.call(this,v,g)},f.prototype._transform=function(v,g,y){y(new o("_transform()"))},f.prototype._write=function(v,g,y){var p=this._transformState;if(p.writecb=y,p.writechunk=v,p.writeencoding=g,!p.transforming){var b=this._readableState;(p.needTransform||b.needReadable||b.length<b.highWaterMark)&&this._read(b.highWaterMark)}},f.prototype._read=function(v){var g=this._transformState;g.writechunk===null||g.transforming?g.needTransform=!0:(g.transforming=!0,this._transform(g.writechunk,g.writeencoding,g.afterTransform))},f.prototype._destroy=function(v,g){c.prototype._destroy.call(this,v,function(y){g(y)})}},{"../errors":55,"./_stream_duplex":56,inherits:24}],60:[function(i,s,r){(function(a,o){(function(){function l(L){var N=this;this.next=null,this.entry=null,this.finish=function(){(function(W,O,q){var $=W.entry;for(W.entry=null;$;){var Y=$.callback;O.pendingcb--,Y(q),$=$.next}O.corkedRequestsFree.next=W})(N,L)}}var n;s.exports=R,R.WritableState=T;var h={deprecate:i("util-deprecate")},c=i("./internal/streams/stream"),f=i("buffer").Buffer,u=o.Uint8Array||function(){},d,v=i("./internal/streams/destroy"),g=i("./internal/streams/state").getHighWaterMark,y=i("../errors").codes,p=y.ERR_INVALID_ARG_TYPE,b=y.ERR_METHOD_NOT_IMPLEMENTED,m=y.ERR_MULTIPLE_CALLBACK,k=y.ERR_STREAM_CANNOT_PIPE,A=y.ERR_STREAM_DESTROYED,S=y.ERR_STREAM_NULL_VALUES,I=y.ERR_STREAM_WRITE_AFTER_END,E=y.ERR_UNKNOWN_ENCODING,z=v.errorOrDestroy;function U(){}function T(L,N,W){n=n||i("./_stream_duplex"),L=L||{},typeof W!="boolean"&&(W=N instanceof n),this.objectMode=!!L.objectMode,W&&(this.objectMode=this.objectMode||!!L.writableObjectMode),this.highWaterMark=g(this,L,"writableHighWaterMark",W),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var O=L.decodeStrings===!1;this.decodeStrings=!O,this.defaultEncoding=L.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(q){(function($,Y){var Z=$._writableState,J=Z.sync,Q=Z.writecb;if(typeof Q!="function")throw new m;if(function(x){x.writing=!1,x.writecb=null,x.length-=x.writelen,x.writelen=0}(Z),Y)(function(x,P,M,H,V){--P.pendingcb,M?(a.nextTick(V,H),a.nextTick(F,x,P),x._writableState.errorEmitted=!0,z(x,H)):(V(H),x._writableState.errorEmitted=!0,z(x,H),F(x,P))})($,Z,J,Y,Q);else{var w=j(Z)||$.destroyed;w||Z.corked||Z.bufferProcessing||!Z.bufferedRequest||B($,Z),J?a.nextTick(_,$,Z,w,Q):_($,Z,w,Q)}})(N,q)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=L.emitClose!==!1,this.autoDestroy=!!L.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new l(this)}function R(L){var N=this instanceof(n=n||i("./_stream_duplex"));if(!N&&!d.call(R,this))return new R(L);this._writableState=new T(L,this,N),this.writable=!0,L&&(typeof L.write=="function"&&(this._write=L.write),typeof L.writev=="function"&&(this._writev=L.writev),typeof L.destroy=="function"&&(this._destroy=L.destroy),typeof L.final=="function"&&(this._final=L.final)),c.call(this)}function C(L,N,W,O,q,$,Y){N.writelen=O,N.writecb=Y,N.writing=!0,N.sync=!0,N.destroyed?N.onwrite(new A("write")):W?L._writev(q,N.onwrite):L._write(q,$,N.onwrite),N.sync=!1}function _(L,N,W,O){W||function(q,$){$.length===0&&$.needDrain&&($.needDrain=!1,q.emit("drain"))}(L,N),N.pendingcb--,O(),F(L,N)}function B(L,N){N.bufferProcessing=!0;var W=N.bufferedRequest;if(L._writev&&W&&W.next){var O=N.bufferedRequestCount,q=new Array(O),$=N.corkedRequestsFree;$.entry=W;for(var Y=0,Z=!0;W;)q[Y]=W,W.isBuf||(Z=!1),W=W.next,Y+=1;q.allBuffers=Z,C(L,N,!0,N.length,q,"",$.finish),N.pendingcb++,N.lastBufferedRequest=null,$.next?(N.corkedRequestsFree=$.next,$.next=null):N.corkedRequestsFree=new l(N),N.bufferedRequestCount=0}else{for(;W;){var J=W.chunk,Q=W.encoding,w=W.callback;if(C(L,N,!1,N.objectMode?1:J.length,J,Q,w),W=W.next,N.bufferedRequestCount--,N.writing)break}W===null&&(N.lastBufferedRequest=null)}N.bufferedRequest=W,N.bufferProcessing=!1}function j(L){return L.ending&&L.length===0&&L.bufferedRequest===null&&!L.finished&&!L.writing}function X(L,N){L._final(function(W){N.pendingcb--,W&&z(L,W),N.prefinished=!0,L.emit("prefinish"),F(L,N)})}function F(L,N){var W=j(N);if(W&&(function(q,$){$.prefinished||$.finalCalled||(typeof q._final!="function"||$.destroyed?($.prefinished=!0,q.emit("prefinish")):($.pendingcb++,$.finalCalled=!0,a.nextTick(X,q,$)))}(L,N),N.pendingcb===0&&(N.finished=!0,L.emit("finish"),N.autoDestroy))){var O=L._readableState;(!O||O.autoDestroy&&O.endEmitted)&&L.destroy()}return W}i("inherits")(R,c),T.prototype.getBuffer=function(){for(var L=this.bufferedRequest,N=[];L;)N.push(L),L=L.next;return N},function(){try{Object.defineProperty(T.prototype,"buffer",{get:h.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}}(),typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(d=Function.prototype[Symbol.hasInstance],Object.defineProperty(R,Symbol.hasInstance,{value:function(L){return!!d.call(this,L)||this===R&&L&&L._writableState instanceof T}})):d=function(L){return L instanceof this},R.prototype.pipe=function(){z(this,new k)},R.prototype.write=function(L,N,W){var O,q=this._writableState,$=!1,Y=!q.objectMode&&(O=L,f.isBuffer(O)||O instanceof u);return Y&&!f.isBuffer(L)&&(L=function(Z){return f.from(Z)}(L)),typeof N=="function"&&(W=N,N=null),Y?N="buffer":N||(N=q.defaultEncoding),typeof W!="function"&&(W=U),q.ending?function(Z,J){var Q=new I;z(Z,Q),a.nextTick(J,Q)}(this,W):(Y||function(Z,J,Q,w){var x;return Q===null?x=new S:typeof Q=="string"||J.objectMode||(x=new p("chunk",["string","Buffer"],Q)),!x||(z(Z,x),a.nextTick(w,x),!1)}(this,q,L,W))&&(q.pendingcb++,$=function(Z,J,Q,w,x,P){if(!Q){var M=function(et,tt,at){return et.objectMode||et.decodeStrings===!1||typeof tt!="string"||(tt=f.from(tt,at)),tt}(J,w,x);w!==M&&(Q=!0,x="buffer",w=M)}var H=J.objectMode?1:w.length;J.length+=H;var V=J.length<J.highWaterMark;if(V||(J.needDrain=!0),J.writing||J.corked){var G=J.lastBufferedRequest;J.lastBufferedRequest={chunk:w,encoding:x,isBuf:Q,callback:P,next:null},G?G.next=J.lastBufferedRequest:J.bufferedRequest=J.lastBufferedRequest,J.bufferedRequestCount+=1}else C(Z,J,!1,H,w,x,P);return V}(this,q,Y,L,N,W)),$},R.prototype.cork=function(){this._writableState.corked++},R.prototype.uncork=function(){var L=this._writableState;L.corked&&(L.corked--,L.writing||L.corked||L.bufferProcessing||!L.bufferedRequest||B(this,L))},R.prototype.setDefaultEncoding=function(L){if(typeof L=="string"&&(L=L.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((L+"").toLowerCase())>-1))throw new E(L);return this._writableState.defaultEncoding=L,this},Object.defineProperty(R.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(R.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),R.prototype._write=function(L,N,W){W(new b("_write()"))},R.prototype._writev=null,R.prototype.end=function(L,N,W){var O=this._writableState;return typeof L=="function"?(W=L,L=null,N=null):typeof N=="function"&&(W=N,N=null),L!=null&&this.write(L,N),O.corked&&(O.corked=1,this.uncork()),O.ending||function(q,$,Y){$.ending=!0,F(q,$),Y&&($.finished?a.nextTick(Y):q.once("finish",Y)),$.ended=!0,q.writable=!1}(this,O,W),this},Object.defineProperty(R.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(R.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState!==void 0&&this._writableState.destroyed},set:function(L){this._writableState&&(this._writableState.destroyed=L)}}),R.prototype.destroy=v.destroy,R.prototype._undestroy=v.undestroy,R.prototype._destroy=function(L,N){N(L)}}).call(this)}).call(this,i("_process"),typeof Ut<"u"?Ut:typeof self<"u"?self:typeof window<"u"?window:{})},{"../errors":55,"./_stream_duplex":56,"./internal/streams/destroy":63,"./internal/streams/state":67,"./internal/streams/stream":68,_process:50,buffer:17,inherits:24,"util-deprecate":78}],61:[function(i,s,r){(function(a){(function(){var o;function l(k,A,S){return A in k?Object.defineProperty(k,A,{value:S,enumerable:!0,configurable:!0,writable:!0}):k[A]=S,k}var n=i("./end-of-stream"),h=Symbol("lastResolve"),c=Symbol("lastReject"),f=Symbol("error"),u=Symbol("ended"),d=Symbol("lastPromise"),v=Symbol("handlePromise"),g=Symbol("stream");function y(k,A){return{value:k,done:A}}function p(k){var A=k[h];if(A!==null){var S=k[g].read();S!==null&&(k[d]=null,k[h]=null,k[c]=null,A(y(S,!1)))}}var b=Object.getPrototypeOf(function(){}),m=Object.setPrototypeOf((l(o={get stream(){return this[g]},next:function(){var k=this,A=this[f];if(A!==null)return Promise.reject(A);if(this[u])return Promise.resolve(y(void 0,!0));if(this[g].destroyed)return new Promise(function(z,U){a.nextTick(function(){k[f]?U(k[f]):z(y(void 0,!0))})});var S,I=this[d];if(I)S=new Promise(function(z,U){return function(T,R){z.then(function(){U[u]?T(y(void 0,!0)):U[v](T,R)},R)}}(I,this));else{var E=this[g].read();if(E!==null)return Promise.resolve(y(E,!1));S=new Promise(this[v])}return this[d]=S,S}},Symbol.asyncIterator,function(){return this}),l(o,"return",function(){var k=this;return new Promise(function(A,S){k[g].destroy(null,function(I){I?S(I):A(y(void 0,!0))})})}),o),b);s.exports=function(k){var A,S=Object.create(m,(l(A={},g,{value:k,writable:!0}),l(A,h,{value:null,writable:!0}),l(A,c,{value:null,writable:!0}),l(A,f,{value:null,writable:!0}),l(A,u,{value:k._readableState.endEmitted,writable:!0}),l(A,v,{value:function(I,E){var z=S[g].read();z?(S[d]=null,S[h]=null,S[c]=null,I(y(z,!1))):(S[h]=I,S[c]=E)},writable:!0}),A));return S[d]=null,n(k,function(I){if(I&&I.code!=="ERR_STREAM_PREMATURE_CLOSE"){var E=S[c];return E!==null&&(S[d]=null,S[h]=null,S[c]=null,E(I)),void(S[f]=I)}var z=S[h];z!==null&&(S[d]=null,S[h]=null,S[c]=null,z(y(void 0,!0))),S[u]=!0}),k.on("readable",(function(I){a.nextTick(p,I)}).bind(null,S)),S}}).call(this)}).call(this,i("_process"))},{"./end-of-stream":64,_process:50}],62:[function(i,s,r){function a(f,u){var d=Object.keys(f);if(Object.getOwnPropertySymbols){var v=Object.getOwnPropertySymbols(f);u&&(v=v.filter(function(g){return Object.getOwnPropertyDescriptor(f,g).enumerable})),d.push.apply(d,v)}return d}function o(f,u,d){return u in f?Object.defineProperty(f,u,{value:d,enumerable:!0,configurable:!0,writable:!0}):f[u]=d,f}function l(f,u){for(var d=0;d<u.length;d++){var v=u[d];v.enumerable=v.enumerable||!1,v.configurable=!0,"value"in v&&(v.writable=!0),Object.defineProperty(f,v.key,v)}}var n=i("buffer").Buffer,h=i("util").inspect,c=h&&h.custom||"inspect";s.exports=function(){function f(){(function(v,g){if(!(v instanceof g))throw new TypeError("Cannot call a class as a function")})(this,f),this.head=null,this.tail=null,this.length=0}var u,d;return u=f,(d=[{key:"push",value:function(v){var g={data:v,next:null};this.length>0?this.tail.next=g:this.head=g,this.tail=g,++this.length}},{key:"unshift",value:function(v){var g={data:v,next:this.head};this.length===0&&(this.tail=g),this.head=g,++this.length}},{key:"shift",value:function(){if(this.length!==0){var v=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,v}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(v){if(this.length===0)return"";for(var g=this.head,y=""+g.data;g=g.next;)y+=v+g.data;return y}},{key:"concat",value:function(v){if(this.length===0)return n.alloc(0);for(var g,y,p,b=n.allocUnsafe(v>>>0),m=this.head,k=0;m;)g=m.data,y=b,p=k,n.prototype.copy.call(g,y,p),k+=m.data.length,m=m.next;return b}},{key:"consume",value:function(v,g){var y;return v<this.head.data.length?(y=this.head.data.slice(0,v),this.head.data=this.head.data.slice(v)):y=v===this.head.data.length?this.shift():g?this._getString(v):this._getBuffer(v),y}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(v){var g=this.head,y=1,p=g.data;for(v-=p.length;g=g.next;){var b=g.data,m=v>b.length?b.length:v;if(m===b.length?p+=b:p+=b.slice(0,v),(v-=m)===0){m===b.length?(++y,g.next?this.head=g.next:this.head=this.tail=null):(this.head=g,g.data=b.slice(m));break}++y}return this.length-=y,p}},{key:"_getBuffer",value:function(v){var g=n.allocUnsafe(v),y=this.head,p=1;for(y.data.copy(g),v-=y.data.length;y=y.next;){var b=y.data,m=v>b.length?b.length:v;if(b.copy(g,g.length-v,0,m),(v-=m)===0){m===b.length?(++p,y.next?this.head=y.next:this.head=this.tail=null):(this.head=y,y.data=b.slice(m));break}++p}return this.length-=p,g}},{key:c,value:function(v,g){return h(this,function(y){for(var p=1;p<arguments.length;p++){var b=arguments[p]!=null?arguments[p]:{};p%2?a(Object(b),!0).forEach(function(m){o(y,m,b[m])}):Object.getOwnPropertyDescriptors?Object.defineProperties(y,Object.getOwnPropertyDescriptors(b)):a(Object(b)).forEach(function(m){Object.defineProperty(y,m,Object.getOwnPropertyDescriptor(b,m))})}return y}({},g,{depth:0,customInspect:!1}))}}])&&l(u.prototype,d),f}()},{buffer:17,util:16}],63:[function(i,s,r){(function(a){(function(){function o(h,c){n(h,c),l(h)}function l(h){h._writableState&&!h._writableState.emitClose||h._readableState&&!h._readableState.emitClose||h.emit("close")}function n(h,c){h.emit("error",c)}s.exports={destroy:function(h,c){var f=this,u=this._readableState&&this._readableState.destroyed,d=this._writableState&&this._writableState.destroyed;return u||d?(c?c(h):h&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,a.nextTick(n,this,h)):a.nextTick(n,this,h)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(h||null,function(v){!c&&v?f._writableState?f._writableState.errorEmitted?a.nextTick(l,f):(f._writableState.errorEmitted=!0,a.nextTick(o,f,v)):a.nextTick(o,f,v):c?(a.nextTick(l,f),c(v)):a.nextTick(l,f)}),this)},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)},errorOrDestroy:function(h,c){var f=h._readableState,u=h._writableState;f&&f.autoDestroy||u&&u.autoDestroy?h.destroy(c):h.emit("error",c)}}}).call(this)}).call(this,i("_process"))},{_process:50}],64:[function(i,s,r){var a=i("../../../errors").codes.ERR_STREAM_PREMATURE_CLOSE;function o(){}s.exports=function l(n,h,c){if(typeof h=="function")return l(n,null,h);h||(h={}),c=function(A){var S=!1;return function(){if(!S){S=!0;for(var I=arguments.length,E=new Array(I),z=0;z<I;z++)E[z]=arguments[z];A.apply(this,E)}}}(c||o);var f=h.readable||h.readable!==!1&&n.readable,u=h.writable||h.writable!==!1&&n.writable,d=function(){n.writable||g()},v=n._writableState&&n._writableState.finished,g=function(){u=!1,v=!0,f||c.call(n)},y=n._readableState&&n._readableState.endEmitted,p=function(){f=!1,y=!0,u||c.call(n)},b=function(A){c.call(n,A)},m=function(){var A;return f&&!y?(n._readableState&&n._readableState.ended||(A=new a),c.call(n,A)):u&&!v?(n._writableState&&n._writableState.ended||(A=new a),c.call(n,A)):void 0},k=function(){n.req.on("finish",g)};return function(A){return A.setHeader&&typeof A.abort=="function"}(n)?(n.on("complete",g),n.on("abort",m),n.req?k():n.on("request",k)):u&&!n._writableState&&(n.on("end",d),n.on("close",d)),n.on("end",p),n.on("finish",g),h.error!==!1&&n.on("error",b),n.on("close",m),function(){n.removeListener("complete",g),n.removeListener("abort",m),n.removeListener("request",k),n.req&&n.req.removeListener("finish",g),n.removeListener("end",d),n.removeListener("close",d),n.removeListener("finish",g),n.removeListener("end",p),n.removeListener("error",b),n.removeListener("close",m)}}},{"../../../errors":55}],65:[function(i,s,r){s.exports=function(){throw new Error("Readable.from is not available in the browser")}},{}],66:[function(i,s,r){var a,o=i("../../../errors").codes,l=o.ERR_MISSING_ARGS,n=o.ERR_STREAM_DESTROYED;function h(u){if(u)throw u}function c(u){u()}function f(u,d){return u.pipe(d)}s.exports=function(){for(var u=arguments.length,d=new Array(u),v=0;v<u;v++)d[v]=arguments[v];var g,y=function(b){return b.length?typeof b[b.length-1]!="function"?h:b.pop():h}(d);if(Array.isArray(d[0])&&(d=d[0]),d.length<2)throw new l("streams");var p=d.map(function(b,m){var k=m<d.length-1;return function(A,S,I,E){E=function(T){var R=!1;return function(){R||(R=!0,T.apply(void 0,arguments))}}(E);var z=!1;A.on("close",function(){z=!0}),a===void 0&&(a=i("./end-of-stream")),a(A,{readable:S,writable:I},function(T){if(T)return E(T);z=!0,E()});var U=!1;return function(T){if(!z&&!U)return U=!0,function(R){return R.setHeader&&typeof R.abort=="function"}(A)?A.abort():typeof A.destroy=="function"?A.destroy():void E(T||new n("pipe"))}}(b,k,m>0,function(A){g||(g=A),A&&p.forEach(c),k||(p.forEach(c),y(g))})});return d.reduce(f)}},{"../../../errors":55,"./end-of-stream":64}],67:[function(i,s,r){var a=i("../../../errors").codes.ERR_INVALID_OPT_VALUE;s.exports={getHighWaterMark:function(o,l,n,h){var c=function(f,u,d){return f.highWaterMark!=null?f.highWaterMark:u?f[d]:null}(l,h,n);if(c!=null){if(!isFinite(c)||Math.floor(c)!==c||c<0)throw new a(h?n:"highWaterMark",c);return Math.floor(c)}return o.objectMode?16:16384}}},{"../../../errors":55}],68:[function(i,s,r){s.exports=i("events").EventEmitter},{events:22}],69:[function(i,s,r){(r=s.exports=i("./lib/_stream_readable.js")).Stream=r,r.Readable=r,r.Writable=i("./lib/_stream_writable.js"),r.Duplex=i("./lib/_stream_duplex.js"),r.Transform=i("./lib/_stream_transform.js"),r.PassThrough=i("./lib/_stream_passthrough.js"),r.finished=i("./lib/internal/streams/end-of-stream.js"),r.pipeline=i("./lib/internal/streams/pipeline.js")},{"./lib/_stream_duplex.js":56,"./lib/_stream_passthrough.js":57,"./lib/_stream_readable.js":58,"./lib/_stream_transform.js":59,"./lib/_stream_writable.js":60,"./lib/internal/streams/end-of-stream.js":64,"./lib/internal/streams/pipeline.js":66}],70:[function(i,s,r){s.exports=function(){if(typeof arguments[0]!="function")throw new Error("callback needed");if(typeof arguments[1]!="number")throw new Error("interval needed");var a;if(arguments.length>0){a=new Array(arguments.length-2);for(var o=0;o<a.length;o++)a[o]=arguments[o+2]}return new function(l,n,h){var c=this;this._callback=l,this._args=h,this._interval=setInterval(l,n,this._args),this.reschedule=function(f){f||(f=c._interval),c._interval&&clearInterval(c._interval),c._interval=setInterval(c._callback,f,c._args)},this.clear=function(){c._interval&&(clearInterval(c._interval),c._interval=void 0)},this.destroy=function(){c._interval&&clearInterval(c._interval),c._callback=void 0,c._interval=void 0,c._args=void 0}}(arguments[0],arguments[1],a)}},{}],71:[function(i,s,r){s.exports=i("./index.js")()},{"./index.js":72}],72:[function(i,s,r){(function(a){(function(){function o(l){return l instanceof a?a.from(l):new l.constructor(l.buffer.slice(),l.byteOffset,l.length)}s.exports=function(l){return(l=l||{}).circles?function(h){var c=[],f=[];return h.proto?function d(v){if(typeof v!="object"||v===null)return v;if(v instanceof Date)return new Date(v);if(Array.isArray(v))return u(v,d);if(v instanceof Map)return new Map(u(Array.from(v),d));if(v instanceof Set)return new Set(u(Array.from(v),d));var g={};for(var y in c.push(v),f.push(g),v){var p=v[y];if(typeof p!="object"||p===null)g[y]=p;else if(p instanceof Date)g[y]=new Date(p);else if(p instanceof Map)g[y]=new Map(u(Array.from(p),d));else if(p instanceof Set)g[y]=new Set(u(Array.from(p),d));else if(ArrayBuffer.isView(p))g[y]=o(p);else{var b=c.indexOf(p);g[y]=b!==-1?f[b]:d(p)}}return c.pop(),f.pop(),g}:function d(v){if(typeof v!="object"||v===null)return v;if(v instanceof Date)return new Date(v);if(Array.isArray(v))return u(v,d);if(v instanceof Map)return new Map(u(Array.from(v),d));if(v instanceof Set)return new Set(u(Array.from(v),d));var g={};for(var y in c.push(v),f.push(g),v)if(Object.hasOwnProperty.call(v,y)!==!1){var p=v[y];if(typeof p!="object"||p===null)g[y]=p;else if(p instanceof Date)g[y]=new Date(p);else if(p instanceof Map)g[y]=new Map(u(Array.from(p),d));else if(p instanceof Set)g[y]=new Set(u(Array.from(p),d));else if(ArrayBuffer.isView(p))g[y]=o(p);else{var b=c.indexOf(p);g[y]=b!==-1?f[b]:d(p)}}return c.pop(),f.pop(),g};function u(d,v){for(var g=Object.keys(d),y=new Array(g.length),p=0;p<g.length;p++){var b=g[p],m=d[b];if(typeof m!="object"||m===null)y[b]=m;else if(m instanceof Date)y[b]=new Date(m);else if(ArrayBuffer.isView(m))y[b]=o(m);else{var k=c.indexOf(m);y[b]=k!==-1?f[k]:v(m)}}return y}}(l):l.proto?function h(c){if(typeof c!="object"||c===null)return c;if(c instanceof Date)return new Date(c);if(Array.isArray(c))return n(c,h);if(c instanceof Map)return new Map(n(Array.from(c),h));if(c instanceof Set)return new Set(n(Array.from(c),h));var f={};for(var u in c){var d=c[u];typeof d!="object"||d===null?f[u]=d:d instanceof Date?f[u]=new Date(d):d instanceof Map?f[u]=new Map(n(Array.from(d),h)):d instanceof Set?f[u]=new Set(n(Array.from(d),h)):ArrayBuffer.isView(d)?f[u]=o(d):f[u]=h(d)}return f}:function h(c){if(typeof c!="object"||c===null)return c;if(c instanceof Date)return new Date(c);if(Array.isArray(c))return n(c,h);if(c instanceof Map)return new Map(n(Array.from(c),h));if(c instanceof Set)return new Set(n(Array.from(c),h));var f={};for(var u in c)if(Object.hasOwnProperty.call(c,u)!==!1){var d=c[u];typeof d!="object"||d===null?f[u]=d:d instanceof Date?f[u]=new Date(d):d instanceof Map?f[u]=new Map(n(Array.from(d),h)):d instanceof Set?f[u]=new Set(n(Array.from(d),h)):ArrayBuffer.isView(d)?f[u]=o(d):f[u]=h(d)}return f};function n(h,c){for(var f=Object.keys(h),u=new Array(f.length),d=0;d<f.length;d++){var v=f[d],g=h[v];typeof g!="object"||g===null?u[v]=g:g instanceof Date?u[v]=new Date(g):ArrayBuffer.isView(g)?u[v]=o(g):u[v]=c(g)}return u}}}).call(this)}).call(this,i("buffer").Buffer)},{buffer:17}],73:[function(i,s,r){var a=i("buffer"),o=a.Buffer;function l(h,c){for(var f in h)c[f]=h[f]}function n(h,c,f){return o(h,c,f)}o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?s.exports=a:(l(a,r),r.Buffer=n),n.prototype=Object.create(o.prototype),l(o,n),n.from=function(h,c,f){if(typeof h=="number")throw new TypeError("Argument must not be a number");return o(h,c,f)},n.alloc=function(h,c,f){if(typeof h!="number")throw new TypeError("Argument must be a number");var u=o(h);return c!==void 0?typeof f=="string"?u.fill(c,f):u.fill(c):u.fill(0),u},n.allocUnsafe=function(h){if(typeof h!="number")throw new TypeError("Argument must be a number");return o(h)},n.allocUnsafeSlow=function(h){if(typeof h!="number")throw new TypeError("Argument must be a number");return a.SlowBuffer(h)}},{buffer:17}],74:[function(i,s,r){s.exports=function(a){var o=a._readableState;return o?o.objectMode||typeof a._duplexState=="number"?a.read():a.read((l=o,l.buffer.length?l.buffer.head?l.buffer.head.data.length:l.buffer[0].length:l.length)):null;var l}},{}],75:[function(i,s,r){var a=i("safe-buffer").Buffer,o=a.isEncoding||function(y){switch((y=""+y)&&y.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function l(y){var p;switch(this.encoding=function(b){var m=function(k){if(!k)return"utf8";for(var A;;)switch(k){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return k;default:if(A)return;k=(""+k).toLowerCase(),A=!0}}(b);if(typeof m!="string"&&(a.isEncoding===o||!o(b)))throw new Error("Unknown encoding: "+b);return m||b}(y),this.encoding){case"utf16le":this.text=c,this.end=f,p=4;break;case"utf8":this.fillLast=h,p=4;break;case"base64":this.text=u,this.end=d,p=3;break;default:return this.write=v,void(this.end=g)}this.lastNeed=0,this.lastTotal=0,this.lastChar=a.allocUnsafe(p)}function n(y){return y<=127?0:y>>5==6?2:y>>4==14?3:y>>3==30?4:y>>6==2?-1:-2}function h(y){var p=this.lastTotal-this.lastNeed,b=function(m,k,A){if((192&k[0])!=128)return m.lastNeed=0,"�";if(m.lastNeed>1&&k.length>1){if((192&k[1])!=128)return m.lastNeed=1,"�";if(m.lastNeed>2&&k.length>2&&(192&k[2])!=128)return m.lastNeed=2,"�"}}(this,y);return b!==void 0?b:this.lastNeed<=y.length?(y.copy(this.lastChar,p,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(y.copy(this.lastChar,p,0,y.length),void(this.lastNeed-=y.length))}function c(y,p){if((y.length-p)%2==0){var b=y.toString("utf16le",p);if(b){var m=b.charCodeAt(b.length-1);if(m>=55296&&m<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=y[y.length-2],this.lastChar[1]=y[y.length-1],b.slice(0,-1)}return b}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=y[y.length-1],y.toString("utf16le",p,y.length-1)}function f(y){var p=y&&y.length?this.write(y):"";if(this.lastNeed){var b=this.lastTotal-this.lastNeed;return p+this.lastChar.toString("utf16le",0,b)}return p}function u(y,p){var b=(y.length-p)%3;return b===0?y.toString("base64",p):(this.lastNeed=3-b,this.lastTotal=3,b===1?this.lastChar[0]=y[y.length-1]:(this.lastChar[0]=y[y.length-2],this.lastChar[1]=y[y.length-1]),y.toString("base64",p,y.length-b))}function d(y){var p=y&&y.length?this.write(y):"";return this.lastNeed?p+this.lastChar.toString("base64",0,3-this.lastNeed):p}function v(y){return y.toString(this.encoding)}function g(y){return y&&y.length?this.write(y):""}r.StringDecoder=l,l.prototype.write=function(y){if(y.length===0)return"";var p,b;if(this.lastNeed){if((p=this.fillLast(y))===void 0)return"";b=this.lastNeed,this.lastNeed=0}else b=0;return b<y.length?p?p+this.text(y,b):this.text(y,b):p||""},l.prototype.end=function(y){var p=y&&y.length?this.write(y):"";return this.lastNeed?p+"�":p},l.prototype.text=function(y,p){var b=function(k,A,S){var I=A.length-1;if(I<S)return 0;var E=n(A[I]);return E>=0?(E>0&&(k.lastNeed=E-1),E):--I<S||E===-2?0:(E=n(A[I]))>=0?(E>0&&(k.lastNeed=E-2),E):--I<S||E===-2?0:(E=n(A[I]))>=0?(E>0&&(E===2?E=0:k.lastNeed=E-3),E):0}(this,y,p);if(!this.lastNeed)return y.toString("utf8",p);this.lastTotal=b;var m=y.length-(b-this.lastNeed);return y.copy(this.lastChar,0,m),y.toString("utf8",p,m)},l.prototype.fillLast=function(y){if(this.lastNeed<=y.length)return y.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);y.copy(this.lastChar,this.lastTotal-this.lastNeed,0,y.length),this.lastNeed-=y.length}},{"safe-buffer":73}],76:[function(i,s,r){var a=i("punycode"),o=i("./util");function l(){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}r.parse=A,r.resolve=function(S,I){return A(S,!1,!0).resolve(I)},r.resolveObject=function(S,I){return S?A(S,!1,!0).resolveObject(I):I},r.format=function(S){return o.isString(S)&&(S=A(S)),S instanceof l?S.format():l.prototype.format.call(S)},r.Url=l;var n=/^([a-z0-9.+-]+:)/i,h=/:[0-9]*$/,c=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,f=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r",`
|
|
67
|
+
`," "]),u=["'"].concat(f),d=["%","/","?",";","#"].concat(u),v=["/","?","#"],g=/^[+a-z0-9A-Z_-]{0,63}$/,y=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,p={javascript:!0,"javascript:":!0},b={javascript:!0,"javascript:":!0},m={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},k=i("querystring");function A(S,I,E){if(S&&o.isObject(S)&&S instanceof l)return S;var z=new l;return z.parse(S,I,E),z}l.prototype.parse=function(S,I,E){if(!o.isString(S))throw new TypeError("Parameter 'url' must be a string, not "+typeof S);var z=S.indexOf("?"),U=z!==-1&&z<S.indexOf("#")?"?":"#",T=S.split(U);T[0]=T[0].replace(/\\/g,"/");var R=S=T.join(U);if(R=R.trim(),!E&&S.split("#").length===1){var C=c.exec(R);if(C)return this.path=R,this.href=R,this.pathname=C[1],C[2]?(this.search=C[2],this.query=I?k.parse(this.search.substr(1)):this.search.substr(1)):I&&(this.search="",this.query={}),this}var _=n.exec(R);if(_){var B=(_=_[0]).toLowerCase();this.protocol=B,R=R.substr(_.length)}if(E||_||R.match(/^\/\/[^@\/]+@[^@\/]+/)){var j=R.substr(0,2)==="//";!j||_&&b[_]||(R=R.substr(2),this.slashes=!0)}if(!b[_]&&(j||_&&!m[_])){for(var X,F,L=-1,N=0;N<v.length;N++)(W=R.indexOf(v[N]))!==-1&&(L===-1||W<L)&&(L=W);for((F=L===-1?R.lastIndexOf("@"):R.lastIndexOf("@",L))!==-1&&(X=R.slice(0,F),R=R.slice(F+1),this.auth=decodeURIComponent(X)),L=-1,N=0;N<d.length;N++){var W;(W=R.indexOf(d[N]))!==-1&&(L===-1||W<L)&&(L=W)}L===-1&&(L=R.length),this.host=R.slice(0,L),R=R.slice(L),this.parseHost(),this.hostname=this.hostname||"";var O=this.hostname[0]==="["&&this.hostname[this.hostname.length-1]==="]";if(!O)for(var q=this.hostname.split(/\./),$=(N=0,q.length);N<$;N++){var Y=q[N];if(Y&&!Y.match(g)){for(var Z="",J=0,Q=Y.length;J<Q;J++)Y.charCodeAt(J)>127?Z+="x":Z+=Y[J];if(!Z.match(g)){var w=q.slice(0,N),x=q.slice(N+1),P=Y.match(y);P&&(w.push(P[1]),x.unshift(P[2])),x.length&&(R="/"+x.join(".")+R),this.hostname=w.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),O||(this.hostname=a.toASCII(this.hostname));var M=this.port?":"+this.port:"",H=this.hostname||"";this.host=H+M,this.href+=this.host,O&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),R[0]!=="/"&&(R="/"+R))}if(!p[B])for(N=0,$=u.length;N<$;N++){var V=u[N];if(R.indexOf(V)!==-1){var G=encodeURIComponent(V);G===V&&(G=escape(V)),R=R.split(V).join(G)}}var et=R.indexOf("#");et!==-1&&(this.hash=R.substr(et),R=R.slice(0,et));var tt=R.indexOf("?");if(tt!==-1?(this.search=R.substr(tt),this.query=R.substr(tt+1),I&&(this.query=k.parse(this.query)),R=R.slice(0,tt)):I&&(this.search="",this.query={}),R&&(this.pathname=R),m[B]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){M=this.pathname||"";var at=this.search||"";this.path=M+at}return this.href=this.format(),this},l.prototype.format=function(){var S=this.auth||"";S&&(S=(S=encodeURIComponent(S)).replace(/%3A/i,":"),S+="@");var I=this.protocol||"",E=this.pathname||"",z=this.hash||"",U=!1,T="";this.host?U=S+this.host:this.hostname&&(U=S+(this.hostname.indexOf(":")===-1?this.hostname:"["+this.hostname+"]"),this.port&&(U+=":"+this.port)),this.query&&o.isObject(this.query)&&Object.keys(this.query).length&&(T=k.stringify(this.query));var R=this.search||T&&"?"+T||"";return I&&I.substr(-1)!==":"&&(I+=":"),this.slashes||(!I||m[I])&&U!==!1?(U="//"+(U||""),E&&E.charAt(0)!=="/"&&(E="/"+E)):U||(U=""),z&&z.charAt(0)!=="#"&&(z="#"+z),R&&R.charAt(0)!=="?"&&(R="?"+R),I+U+(E=E.replace(/[?#]/g,function(C){return encodeURIComponent(C)}))+(R=R.replace("#","%23"))+z},l.prototype.resolve=function(S){return this.resolveObject(A(S,!1,!0)).format()},l.prototype.resolveObject=function(S){if(o.isString(S)){var I=new l;I.parse(S,!1,!0),S=I}for(var E=new l,z=Object.keys(this),U=0;U<z.length;U++){var T=z[U];E[T]=this[T]}if(E.hash=S.hash,S.href==="")return E.href=E.format(),E;if(S.slashes&&!S.protocol){for(var R=Object.keys(S),C=0;C<R.length;C++){var _=R[C];_!=="protocol"&&(E[_]=S[_])}return m[E.protocol]&&E.hostname&&!E.pathname&&(E.path=E.pathname="/"),E.href=E.format(),E}if(S.protocol&&S.protocol!==E.protocol){if(!m[S.protocol]){for(var B=Object.keys(S),j=0;j<B.length;j++){var X=B[j];E[X]=S[X]}return E.href=E.format(),E}if(E.protocol=S.protocol,S.host||b[S.protocol])E.pathname=S.pathname;else{for(var F=(S.pathname||"").split("/");F.length&&!(S.host=F.shift()););S.host||(S.host=""),S.hostname||(S.hostname=""),F[0]!==""&&F.unshift(""),F.length<2&&F.unshift(""),E.pathname=F.join("/")}if(E.search=S.search,E.query=S.query,E.host=S.host||"",E.auth=S.auth,E.hostname=S.hostname||S.host,E.port=S.port,E.pathname||E.search){var L=E.pathname||"",N=E.search||"";E.path=L+N}return E.slashes=E.slashes||S.slashes,E.href=E.format(),E}var W=E.pathname&&E.pathname.charAt(0)==="/",O=S.host||S.pathname&&S.pathname.charAt(0)==="/",q=O||W||E.host&&S.pathname,$=q,Y=E.pathname&&E.pathname.split("/")||[],Z=(F=S.pathname&&S.pathname.split("/")||[],E.protocol&&!m[E.protocol]);if(Z&&(E.hostname="",E.port=null,E.host&&(Y[0]===""?Y[0]=E.host:Y.unshift(E.host)),E.host="",S.protocol&&(S.hostname=null,S.port=null,S.host&&(F[0]===""?F[0]=S.host:F.unshift(S.host)),S.host=null),q=q&&(F[0]===""||Y[0]==="")),O)E.host=S.host||S.host===""?S.host:E.host,E.hostname=S.hostname||S.hostname===""?S.hostname:E.hostname,E.search=S.search,E.query=S.query,Y=F;else if(F.length)Y||(Y=[]),Y.pop(),Y=Y.concat(F),E.search=S.search,E.query=S.query;else if(!o.isNullOrUndefined(S.search))return Z&&(E.hostname=E.host=Y.shift(),(P=!!(E.host&&E.host.indexOf("@")>0)&&E.host.split("@"))&&(E.auth=P.shift(),E.host=E.hostname=P.shift())),E.search=S.search,E.query=S.query,o.isNull(E.pathname)&&o.isNull(E.search)||(E.path=(E.pathname?E.pathname:"")+(E.search?E.search:"")),E.href=E.format(),E;if(!Y.length)return E.pathname=null,E.search?E.path="/"+E.search:E.path=null,E.href=E.format(),E;for(var J=Y.slice(-1)[0],Q=(E.host||S.host||Y.length>1)&&(J==="."||J==="..")||J==="",w=0,x=Y.length;x>=0;x--)(J=Y[x])==="."?Y.splice(x,1):J===".."?(Y.splice(x,1),w++):w&&(Y.splice(x,1),w--);if(!q&&!$)for(;w--;w)Y.unshift("..");!q||Y[0]===""||Y[0]&&Y[0].charAt(0)==="/"||Y.unshift(""),Q&&Y.join("/").substr(-1)!=="/"&&Y.push("");var P,M=Y[0]===""||Y[0]&&Y[0].charAt(0)==="/";return Z&&(E.hostname=E.host=M?"":Y.length?Y.shift():"",(P=!!(E.host&&E.host.indexOf("@")>0)&&E.host.split("@"))&&(E.auth=P.shift(),E.host=E.hostname=P.shift())),(q=q||E.host&&Y.length)&&!M&&Y.unshift(""),Y.length?E.pathname=Y.join("/"):(E.pathname=null,E.path=null),o.isNull(E.pathname)&&o.isNull(E.search)||(E.path=(E.pathname?E.pathname:"")+(E.search?E.search:"")),E.auth=S.auth||E.auth,E.slashes=E.slashes||S.slashes,E.href=E.format(),E},l.prototype.parseHost=function(){var S=this.host,I=h.exec(S);I&&((I=I[0])!==":"&&(this.port=I.substr(1)),S=S.substr(0,S.length-I.length)),S&&(this.hostname=S)}},{"./util":77,punycode:51,querystring:54}],77:[function(i,s,r){s.exports={isString:function(a){return typeof a=="string"},isObject:function(a){return typeof a=="object"&&a!==null},isNull:function(a){return a===null},isNullOrUndefined:function(a){return a==null}}},{}],78:[function(i,s,r){(function(a){(function(){function o(l){try{if(!a.localStorage)return!1}catch{return!1}var n=a.localStorage[l];return n!=null&&String(n).toLowerCase()==="true"}s.exports=function(l,n){if(o("noDeprecation"))return l;var h=!1;return function(){if(!h){if(o("throwDeprecation"))throw new Error(n);o("traceDeprecation")?console.trace(n):console.warn(n),h=!0}return l.apply(this,arguments)}}}).call(this)}).call(this,typeof Ut<"u"?Ut:typeof self<"u"?self:typeof window<"u"?window:{})},{}],79:[function(i,s,r){s.exports=function a(o,l){if(o&&l)return a(o)(l);if(typeof o!="function")throw new TypeError("need wrapper function");return Object.keys(o).forEach(function(h){n[h]=o[h]}),n;function n(){for(var h=new Array(arguments.length),c=0;c<h.length;c++)h[c]=arguments[c];var f=o.apply(this,h),u=h[h.length-1];return typeof f=="function"&&f!==u&&Object.keys(u).forEach(function(d){f[d]=u[d]}),f}}},{}],80:[function(i,s,r){s.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}},{}],81:[function(i,s,r){s.exports=function(){for(var o={},l=0;l<arguments.length;l++){var n=arguments[l];for(var h in n)a.call(n,h)&&(o[h]=n[h])}return o};var a=Object.prototype.hasOwnProperty},{}],82:[function(i,s,r){s.exports=function(a){a.prototype[Symbol.iterator]=function*(){for(let o=this.head;o;o=o.next)yield o.value}}},{}],83:[function(i,s,r){function a(c){var f=this;if(f instanceof a||(f=new a),f.tail=null,f.head=null,f.length=0,c&&typeof c.forEach=="function")c.forEach(function(v){f.push(v)});else if(arguments.length>0)for(var u=0,d=arguments.length;u<d;u++)f.push(arguments[u]);return f}function o(c,f,u){var d=f===c.head?new h(u,null,f,c):new h(u,f,f.next,c);return d.next===null&&(c.tail=d),d.prev===null&&(c.head=d),c.length++,d}function l(c,f){c.tail=new h(f,c.tail,null,c),c.head||(c.head=c.tail),c.length++}function n(c,f){c.head=new h(f,null,c.head,c),c.tail||(c.tail=c.head),c.length++}function h(c,f,u,d){if(!(this instanceof h))return new h(c,f,u,d);this.list=d,this.value=c,f?(f.next=this,this.prev=f):this.prev=null,u?(u.prev=this,this.next=u):this.next=null}s.exports=a,a.Node=h,a.create=a,a.prototype.removeNode=function(c){if(c.list!==this)throw new Error("removing node which does not belong to this list");var f=c.next,u=c.prev;return f&&(f.prev=u),u&&(u.next=f),c===this.head&&(this.head=f),c===this.tail&&(this.tail=u),c.list.length--,c.next=null,c.prev=null,c.list=null,f},a.prototype.unshiftNode=function(c){if(c!==this.head){c.list&&c.list.removeNode(c);var f=this.head;c.list=this,c.next=f,f&&(f.prev=c),this.head=c,this.tail||(this.tail=c),this.length++}},a.prototype.pushNode=function(c){if(c!==this.tail){c.list&&c.list.removeNode(c);var f=this.tail;c.list=this,c.prev=f,f&&(f.next=c),this.tail=c,this.head||(this.head=c),this.length++}},a.prototype.push=function(){for(var c=0,f=arguments.length;c<f;c++)l(this,arguments[c]);return this.length},a.prototype.unshift=function(){for(var c=0,f=arguments.length;c<f;c++)n(this,arguments[c]);return this.length},a.prototype.pop=function(){if(this.tail){var c=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,c}},a.prototype.shift=function(){if(this.head){var c=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,c}},a.prototype.forEach=function(c,f){f=f||this;for(var u=this.head,d=0;u!==null;d++)c.call(f,u.value,d,this),u=u.next},a.prototype.forEachReverse=function(c,f){f=f||this;for(var u=this.tail,d=this.length-1;u!==null;d--)c.call(f,u.value,d,this),u=u.prev},a.prototype.get=function(c){for(var f=0,u=this.head;u!==null&&f<c;f++)u=u.next;if(f===c&&u!==null)return u.value},a.prototype.getReverse=function(c){for(var f=0,u=this.tail;u!==null&&f<c;f++)u=u.prev;if(f===c&&u!==null)return u.value},a.prototype.map=function(c,f){f=f||this;for(var u=new a,d=this.head;d!==null;)u.push(c.call(f,d.value,this)),d=d.next;return u},a.prototype.mapReverse=function(c,f){f=f||this;for(var u=new a,d=this.tail;d!==null;)u.push(c.call(f,d.value,this)),d=d.prev;return u},a.prototype.reduce=function(c,f){var u,d=this.head;if(arguments.length>1)u=f;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");d=this.head.next,u=this.head.value}for(var v=0;d!==null;v++)u=c(u,d.value,v),d=d.next;return u},a.prototype.reduceReverse=function(c,f){var u,d=this.tail;if(arguments.length>1)u=f;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");d=this.tail.prev,u=this.tail.value}for(var v=this.length-1;d!==null;v--)u=c(u,d.value,v),d=d.prev;return u},a.prototype.toArray=function(){for(var c=new Array(this.length),f=0,u=this.head;u!==null;f++)c[f]=u.value,u=u.next;return c},a.prototype.toArrayReverse=function(){for(var c=new Array(this.length),f=0,u=this.tail;u!==null;f++)c[f]=u.value,u=u.prev;return c},a.prototype.slice=function(c,f){(f=f||this.length)<0&&(f+=this.length),(c=c||0)<0&&(c+=this.length);var u=new a;if(f<c||f<0)return u;c<0&&(c=0),f>this.length&&(f=this.length);for(var d=0,v=this.head;v!==null&&d<c;d++)v=v.next;for(;v!==null&&d<f;d++,v=v.next)u.push(v.value);return u},a.prototype.sliceReverse=function(c,f){(f=f||this.length)<0&&(f+=this.length),(c=c||0)<0&&(c+=this.length);var u=new a;if(f<c||f<0)return u;c<0&&(c=0),f>this.length&&(f=this.length);for(var d=this.length,v=this.tail;v!==null&&d>f;d--)v=v.prev;for(;v!==null&&d>c;d--,v=v.prev)u.push(v.value);return u},a.prototype.splice=function(c,f,...u){c>this.length&&(c=this.length-1),c<0&&(c=this.length+c);for(var d=0,v=this.head;v!==null&&d<c;d++)v=v.next;var g=[];for(d=0;v&&d<f;d++)g.push(v.value),v=this.removeNode(v);for(v===null&&(v=this.tail),v!==this.head&&v!==this.tail&&(v=v.prev),d=0;d<u.length;d++)v=o(this,v,u[d]);return g},a.prototype.reverse=function(){for(var c=this.head,f=this.tail,u=c;u!==null;u=u.prev){var d=u.prev;u.prev=u.next,u.next=d}return this.head=f,this.tail=c,this};try{i("./iterator.js")(a)}catch{}},{"./iterator.js":82}]},{},[12])(12)})})(sa);var di=sa.exports;const nr={success:{color:"#2ba471",icon:'<svg fill="none" viewBox="0 0 24 24"><path d="M12 23a11 11 0 100-22 11 11 0 000 22zM7.5 10.59l3 3 6-6L17.91 9l-7.41 7.41L6.09 12l1.41-1.41z"></path></svg>'},info:{color:"#0052d9",icon:'<svg fill="none" viewBox="0 0 24 24"><path d="M12 23a11 11 0 100-22 11 11 0 000 22zM11 8.5v-2h2v2h-2zm2 1.5v7.5h-2V10h2z"></path></svg>'},warning:{color:"#e37318",icon:'<svg fill="none" viewBox="0 0 24 24"><path d="M12 1a11 11 0 110 22 11 11 0 010-22zm-1 13h2V6.5h-2V14zm2 1.5h-2v2h2v-2z"></path></svg>'},error:{color:"#d54941",icon:'<svg fill="none" viewBox="0 0 24 24"><path d="M12 1a11 11 0 110 22 11 11 0 010-22zm-1 13h2V6.5h-2V14zm2 1.5h-2v2h2v-2z"></path></svg>'},question:{color:"#0052d9",icon:'<svg fill="none" viewBox="0 0 24 24"><path d="M12 23a11 11 0 100-22 11 11 0 000 22zm-.17-11.11c.43-.53.97-.97 1.4-1.32A2 2 0 0012 7a2 2 0 00-1.89 1.33l-.33.95L7.9 8.6l.34-.94a4 4 0 116.24 4.47 7 7 0 00-1.1 1.01c-.27.34-.37.61-.37.85v1.25h-2V14c0-.87.39-1.57.83-2.11zM11 18.25v-2h2v2h-2z"></path></svg>'}},Nt={};class uc{constructor(t,i){D(this,"parentElement");D(this,"box");D(this,"icon");D(this,"text");D(this,"closeBtn");D(this,"duration");D(this,"content");D(this,"theme");D(this,"placement");D(this,"height");D(this,"id");this.parentElement=t,this.box=document.createElement("div"),this.icon=document.createElement("div"),this.text=document.createElement("div"),this.box.className="meta2d-message",this.icon.className="icon",this.text.className="text",this.icon.innerHTML=nr[i.theme||"info"].icon,this.text.innerHTML=i.content,this.box.appendChild(this.icon),this.box.appendChild(this.text),i.closeBtn&&(this.closeBtn=document.createElement("div"),this.closeBtn.className="close",this.closeBtn.innerHTML="x",this.closeBtn.onclick=()=>{this.close()},this.box.appendChild(this.closeBtn)),t.appendChild(this.box);let s;for(let r=0;r<document.styleSheets.length;r++)document.styleSheets[r].title==="le5le.com/message"&&(s=document.styleSheets[r]);if(!s){let r=document.createElement("style");r.type="text/css",r.title="le5le.com/message",document.head.appendChild(r),r=document.createElement("style"),r.type="text/css",document.head.appendChild(r),s=r.sheet,s.insertRule(`.meta2d-message{
|
|
68
|
+
position:absolute;
|
|
69
|
+
z-index:999;
|
|
70
|
+
transform: translateX(-50%);
|
|
71
|
+
padding:12px 16px;
|
|
72
|
+
max-width:400px;
|
|
73
|
+
background:#fff;
|
|
74
|
+
border-radius:6px;
|
|
75
|
+
box-shadow:0 3px 14px 2px rgba(0, 0, 0, .05),0 8px 10px 1px rgba(0, 0, 0, 6%),0 5px 5px -3px rgba(0, 0, 0, 10%);
|
|
76
|
+
display:flex;
|
|
77
|
+
animation: fadein .5s;}`),s.insertRule(`
|
|
78
|
+
@keyframes fadein {
|
|
79
|
+
0% {
|
|
80
|
+
transform: translate(-50%, -100%);
|
|
81
|
+
}
|
|
82
|
+
100% {
|
|
83
|
+
transform: translate(-50%,0);
|
|
84
|
+
}
|
|
85
|
+
}`),s.insertRule(".meta2d-message .icon{width:20px;height:20px;}"),s.insertRule(".meta2d-message .text{color:rgba(0, 0, 0, 0.9);font-size:12px;margin-left:8px;line-height:20px;}"),s.insertRule(".meta2d-message .close{width:20px;height:20px;padding-left: 16px; cursor: pointer;}")}this.id=i.id||lt(),this.duration=i.duration??3e3,this.placement=i.placement||"top",this.theme=i.theme||"info",this.height=i.height}init(){Nt[this.id]=this,this.duration&&setTimeout(()=>{this.close()},this.duration);let t=-1;Object.keys(Nt).forEach(i=>{var s;((s=Nt[i])==null?void 0:s.placement)===this.placement&&t++}),this.setPosition(this.placement,t),this.icon.children[0].style.fill=nr[this.theme].color}setPosition(t,i=0){switch(t){case"top":this.box.style.top=`${30+i*(this.height||60)}px`,this.box.style.left="50%";break;case"bottom":this.box.style.bottom=`${30+i*(this.height||60)}px`,this.box.style.left="50%";break;case"left":this.box.style.top=`${30+i*(this.height||60)}px`,this.box.style.left="30px";break;case"right":this.box.style.top=`${30+i*(this.height||60)}px`,this.box.style.right="30px";break}}close(){Object.keys(Nt).forEach(t=>{var i;if(((i=Nt[t])==null?void 0:i.placement)===this.placement)switch(this.placement){case"top":case"left":case"right":Nt[t].box.style.top=parseInt(Nt[t].box.style.top)-60+"px";break;case"bottom":Nt[t].box.style.bottom=parseInt(Nt[t].box.style.bottom)-60+"px";break}}),Nt[this.id]=null,delete Nt[this.id],this.box.remove()}}function dc(e,t){if(e.jetLinksList.length){let i=t.url;i.startsWith("/")&&(i=(location.protocol==="https:"?"wss://":"ws://")+window.location.host+i),e.jetLinksClient=new WebSocket(`${i}/${localStorage.getItem("X-Access-Token")||pi("X-Access-Token")||new URLSearchParams(location.search).get("X-Access-Token")||""}`),e.jetLinksClient.onmessage=s=>{var a;const r=JSON.parse(s.data);if(r.payload)if((a=r.payload)!=null&&a.properties){const o=[];for(let l in r.payload.properties)o.push({id:`${r.payload.headers.productId}#${r.payload.deviceId}#${l}`,value:r.payload.properties[l]});e.setDatas(o,{history:!1})}else r.topic.startsWith("/notifications")&&ra(e,r)},e.jetLinksClient.onopen=()=>{e.jetLinksList.forEach(s=>{e.jetLinksClient.send(JSON.stringify({type:"sub",topic:`/device${s.topic}/message/property/report`,parameter:{deviceId:s.deviceId,properties:s.properties,history:1},id:s.topic+"-"+lt()}))}),t.notification&&e.jetLinksClient.send(JSON.stringify({type:"sub",topic:"/notifications",id:"notification",parameter:{}}))}}}function ra(e,t){var o,l;let i=t.payload.topicName,s=t.payload.message,r=t.payload.notifyTime,a=`<div style="padding:0px 12px 0px 0px;width:300px;">
|
|
86
|
+
<div style="display:flex;height: 20px;justify-content: space-between">
|
|
87
|
+
<div style="color: #000000d9;
|
|
88
|
+
font-size: 14px;
|
|
89
|
+
font-weight: 700;">${i}</div><div style="color: #00000073;">${fc(r)}</div>
|
|
90
|
+
</div>
|
|
91
|
+
<span>${s}</span>
|
|
92
|
+
</div>`;e.message({content:a,duration:0,closeBtn:!0,placement:"right",height:75}),(o=t.payload.detail)!=null&&o.alarmConfigId&&mc(e,(l=t.payload.detail)==null?void 0:l.alarmConfigId)}globalThis.doWarning=ra;function fc(e){const t=new Date(e),i=t.getFullYear(),s=(t.getMonth()+1+"").padStart(2,"0"),r=(t.getDate()+"").padStart(2,"0"),a=(t.getHours()+"").padStart(2,"0"),o=(t.getMinutes()+"").padStart(2,"0"),l=(t.getSeconds()+"").padStart(2,"0");return i+"-"+s+"-"+r+" "+a+":"+o+":"+l}function vc(e){e.jetLinksClient&&(e.jetLinksClient.close(),e.jetLinksClient=void 0)}function gc(e,t,i){const s=[];return i.list.forEach((r,a)=>{var l,n;const o=r.params?e.findOne(r.params):t;s[a]={deviceId:o.deviceId,productId:o.productId,properties:{}};for(let h in r.value)if(r.value[h]===void 0||r.value[h]===""){const c=(l=o.realTimes)==null?void 0:l.find(f=>f.propertyId===h);c&&(s[a].properties[h]=o[c.key])}else if(typeof r.value[h]=="string"&&((n=r.value[h])==null?void 0:n.indexOf("${"))>-1){let c=r.value[h].match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));c!=null&&c.length&&(s[a].properties[h]=o[c[0]]??e.getDynamicParam(c[0]))}else s[a].properties[h]=r.value[h]}),s}async function yc(e,t){t.forEach(async i=>{let s=i.deviceId;if(s&&s.indexOf("${")>-1){let a=s.match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));a!=null&&a.length&&(s=e.getDynamicParam(a[0])||s)}(await fetch(`/api/device-instance/${s}/property`,{headers:{"X-Access-Token":localStorage.getItem("X-Access-Token")||new URLSearchParams(location.search).get("X-Access-Token")||"","Content-Type":"application/json"},method:"put",body:JSON.stringify(i.properties)})).ok?(console.info("发送成功"),e.message({theme:"success",content:"下发成功"})):e.message({theme:"error",content:"下发失败"})})}async function mc(e,t){const i=await fetch(`/api/alarm/config/${t}`,{headers:{"X-Access-Token":localStorage.getItem("X-Access-Token")||new URLSearchParams(location.search).get("X-Access-Token")||"","Content-Type":"application/json"},method:"GET"});if(i.ok){let s=await i.json();s.result.media&&aa(e,s.result.media,s.result.playTimes)}}function aa(e,t,i){if(e.store.globalAudio||(e.store.globalAudio=document.createElement("audio")),e.store.globalAudio.src=t,e.store.globalAudio.play(),i===-1)e.store.globalAudio.loop=!0;else{e.store.globalAudio.loop=!1;let s=0;e.store.globalAudio.onended=()=>{s++,s<i&&e.store.globalAudio.play()}}}globalThis.createAudio=aa;const pc=/^echarts/;class wc{constructor(t,i={}){D(this,"store");D(this,"canvas");D(this,"websocket");D(this,"mqttClient");D(this,"websockets");D(this,"mqttClients");D(this,"eventSources");D(this,"penPluginMap",new Map);D(this,"socketFn");D(this,"events",{});D(this,"map");D(this,"mapTimer");D(this,"fillViewSnapshot",null);D(this,"facePen",Oe);D(this,"getWords",br);D(this,"calcTextLines",Ne);D(this,"calcTextRect",Yt);D(this,"calcTextDrawRect",as);D(this,"jetLinksList",[]);D(this,"jetLinksClient");D(this,"register",wr);D(this,"registerCanvasDraw",Ea);D(this,"registerAnchors",Ma);D(this,"registerGridDrawer",La);D(this,"unregisterGridDrawer",Da);D(this,"registerLineAnimateDraws",(t,i)=>{this.store.data.lineAnimateDraws[t]=i,it.lineAnimateDraws[t]=It(this.store.options,"ctx","pen","state","index",i)});D(this,"websocketTimes",0);D(this,"mqttTimes",0);D(this,"httpTimer");D(this,"httpTimerList",[]);D(this,"updateTimer");D(this,"updateTimerList",[]);D(this,"sqlTimerList",[]);D(this,"iotMqttClient");D(this,"iotTimer");D(this,"onEvent",(t,i)=>{switch(t){case"add":i.forEach(s=>{var r;(r=s.onAdd)==null||r.call(s,s)}),this.onSizeUpdate();break;case"enter":i&&i.onMouseEnter&&i.onMouseEnter(i,this.canvas.mousePos),this.store.data.locked&&this.doEvent(i,t);break;case"leave":i&&i.onMouseLeave&&i.onMouseLeave(i,this.canvas.mousePos),this.store.data.locked&&this.doEvent(i,t);break;case"active":case"inactive":this.store.data.locked&&i.forEach(s=>{this.doEvent(s,t)});break;case"click":if(this.store.data.locked&&i.pen&&!i.pen.disabled&&i.pen.switch&&(i.pen.checked=!i.pen.checked,i.pen.calculative.checked=i.pen.checked,i.pen.calculative.gradient=void 0,i.pen.calculative.radialGradient=void 0),i.pen&&i.pen.formId){const s=this.store.pens[i.pen.formId];i.pen.formType==="submit"?this.store.data.locked&&s&&!s.disabled&&this.doEvent(s,"submit"):i.pen.formType==="reset"&&(Tl(i.pen),this.store.data.locked&&s&&!s.disabled&&this.doEvent(s,"reset"))}i.pen&&i.pen.onClick&&!i.pen.disabled&&i.pen.onClick(i.pen,this.canvas.mousePos),this.store.data.locked&&i.pen&&!i.pen.disabled&&this.doEvent(i.pen,t);break;case"contextmenu":i.pen&&i.pen.onContextmenu&&!i.pen.disabled&&i.pen.onContextmenu(i.pen,this.canvas.mousePos),this.store.data.locked&&i.pen&&!i.pen.disabled&&this.doEvent(i.pen,t);break;case"mousedown":i.pen&&i.pen.onMouseDown&&!i.pen.disabled&&i.pen.onMouseDown(i.pen,this.canvas.mousePos),this.store.data.locked&&i.pen&&!i.pen.disabled&&this.doEvent(i.pen,t);break;case"mouseup":i.pen&&i.pen.onMouseUp&&!i.pen.disabled&&i.pen.onMouseUp(i.pen,this.canvas.mousePos),this.store.data.locked&&i.pen&&!i.pen.disabled&&this.doEvent(i.pen,t);break;case"dblclick":this.store.data.locked&&i.pen&&!i.pen.disabled&&this.doEvent(i.pen,t);break;case"valueUpdate":i&&Vi(i,i.formValue),this.store.data.locked&&this.doEvent(i,t),this.canvas.tooltip.updateText(i);break;case"update":case"delete":case"translatePens":case"rotatePens":case"resizePens":this.onSizeUpdate();break;case"navigator":this.store.data.id||console.warn("请先保存当前图纸"),this.navigatorTo(i.params);break;case"input":this.store.data.locked&&i&&!i.disabled&&this.doEvent(i,t);break;case"change":i.pen?(Vi(i.pen),this.store.data.locked&&!i.pen.disabled&&this.doEvent(i.pen,t)):(Vi(i),this.store.data.locked&&i&&!i.disabled&&this.doEvent(i,t));break}this.doMessageEvent(t,i)});D(this,"doEvent",(t,i)=>{var a,o,l,n,h,c,f,u,d,v;if(!t)return;let s=!1,r=[];if((a=t.events)==null||a.forEach((g,y)=>{var p;if(g.actions&&g.actions.length){if(g.name===i){let b=!1;g.conditions&&g.conditions.length?g.conditionType==="and"?b=g.conditions.every(m=>this.judgeCondition(t,m.key,m)):g.conditionType==="or"&&(b=g.conditions.some(m=>this.judgeCondition(t,m.key,m))):b=!0,b&&r.push(y)}}else if(s=!0,this.events[g.action]&&g.name===i){let b=!((p=g.where)!=null&&p.type);if(g.where){const{fn:m,fnJs:k,comparison:A,key:S,value:I}=g.where;if(m)b=m(t,{meta2d:this});else if(k){try{g.where.fn=It(this.store.options,"pen","context",k)}catch(E){console.error("Error: make function:",E,"code:",k)}g.where.fn&&(b=g.where.fn(t,{meta2d:this}))}else{let E=t[S];switch(["x","y","width","height"].includes(S)&&(E=this.getPenRect(t)[S]),A){case">":b=E>+I;break;case">=":b=E>=+I;break;case"<":b=E<+I;break;case"<=":b=E<=+I;break;case"=":case"==":b=E==I;break;case"!=":b=E!=I;break;case"[)":b=Re(+E,I);break;case"![)":b=!Re(+E,I);break;case"[]":b=Te(E,I);break;case"![]":b=!Te(E,I);break}}}b&&r.push(y)}}),s?(o=t.events)==null||o.forEach((g,y)=>{r.includes(y)&&this.events[g.action](t,g)}):(l=t.events)==null||l.forEach(async(g,y)=>{if(r.includes(y)){if(g.confirm&&!await this.canvas.popconfirm.showModal(t,this.canvas.mousePos,g.confirmTitle))return;g.actions.forEach(p=>{p.timeout?setTimeout(()=>{this.events[p.action]&&this.events[p.action](t,p)},p.timeout):this.events[p.action]&&this.events[p.action](t,p)})}}),i==="valueUpdate"){(n=t.realTimes)==null||n.forEach(y=>{var b,m;let p=[];(b=y.triggers)==null||b.forEach((k,A)=>{var I;let S=!1;(I=k.conditions)!=null&&I.length?k.conditionType==="and"?S=k.conditions.every(E=>this.judgeCondition(t,y.key,E)):k.conditionType==="or"&&(S=k.conditions.some(E=>this.judgeCondition(t,y.key,E))):S=!0,S&&p.push(A)}),(m=y.triggers)==null||m.forEach((k,A)=>{var S;p.includes(A)&&((S=k.actions)==null||S.forEach(I=>{I.timeout?setTimeout(()=>{this.events[I.action]&&this.events[I.action](t,I)},I.timeout):this.events[I.action](t,I)}))})});let g=[];if((h=this.store.globalTriggers[t.id])==null||h.forEach((y,p)=>{var m;let b=!1;(m=y.conditions)!=null&&m.length?y.conditionType==="and"?b=y.conditions.every(k=>this.judgeCondition(this.store.pens[k.source],k.key,k)):y.conditionType==="or"&&(b=y.conditions.some(k=>this.judgeCondition(this.store.pens[k.source],k.key,k))):b=!0,b&&g.push(p)}),(c=this.store.globalTriggers[t.id])==null||c.forEach((y,p)=>{var b;g.includes(p)&&((b=y.actions)==null||b.forEach(m=>{m.timeout?setTimeout(()=>{this.events[m.action]&&this.events[m.action](t,m)},m.timeout):this.events[m.action](t,m)}))}),(f=t.triggers)!=null&&f.length){for(let y of t.triggers)if((u=y.status)!=null&&u.length)for(let p of y.status){let b=!1;if((d=p.conditions)!=null&&d.length?p.conditionType==="and"?b=p.conditions.every(m=>this.judgeCondition(t,m.key,m)):p.conditionType==="or"&&(b=p.conditions.some(m=>this.judgeCondition(t,m.key,m))):b=!0,b){(v=p.actions)==null||v.forEach(m=>{m.timeout?setTimeout(()=>{this.events[m.action]&&this.events[m.action](t,m)},m.timeout):this.events[m.action](t,m)});break}}}}this.doEvent(this.store.pens[t.parentId],i)});D(this,"doDataEvent",t=>{var r,a,o;if(!((r=this.store.data.dataEvents)!=null&&r.length))return;const i=t.reduce((l,{dataId:n,id:h,value:c})=>(l[h||n]=c,l),{});let s=[];(a=this.store.data.dataEvents)==null||a.forEach((l,n)=>{let h=!1;l.conditions&&l.conditions.length?l.conditionType==="and"?h=l.conditions.every(c=>this.dataJudegeCondition(i,c.key,c)):l.conditionType==="or"&&(h=l.conditions.some(c=>this.dataJudegeCondition(i,c.key,c))):h=!0,h&&s.push(n)}),(o=this.store.data.dataEvents)==null||o.forEach((l,n)=>{var h;s.includes(n)&&((h=l.actions)==null||h.forEach(c=>{this.events[c.action](i,c)}))})});D(this,"renderPenRaw",Ri);D(this,"setElemPosition",Ct);D(this,"setLifeCycleFunc",Jo);this.store=Wa(lt()),this.setOptions(i),this.setDatabyOptions(i),this.init(t),this.register(lc()),this.registerCanvasDraw({cube:Vn}),this.registerAnchors(cc()),globalThis.meta2d=this,this.initEventFns(),this.store.emitter.on("*",this.onEvent)}get beforeAddPen(){return this.canvas.beforeAddPen}set beforeAddPen(t){this.canvas.beforeAddPen=t}get beforeAddPens(){return this.canvas.beforeAddPens}set beforeAddPens(t){this.canvas.beforeAddPens=t}get beforeAddAnchor(){return this.canvas.beforeAddAnchor}set beforeAddAnchor(t){this.canvas.beforeAddAnchor=t}get beforeRemovePens(){return this.canvas.beforeRemovePens}set beforeRemovePens(t){this.canvas.beforeRemovePens=t}get beforeRemoveAnchor(){return this.canvas.beforeRemoveAnchor}set beforeRemoveAnchor(t){this.canvas.beforeRemoveAnchor=t}setOptions(t={}){var i,s,r;if((t.grid!==void 0||t.gridColor!==void 0||t.gridSize!==void 0)&&this.canvas&&(this.canvas.canvasTemplate.bgPatchFlags=!0),(t.rule!==void 0||t.ruleColor!==void 0||t.ruleOptions!==void 0)&&(this.store.patchFlagsTop=!0,t.ruleOptions&&(i=this.store.options)!=null&&i.ruleOptions&&(Object.assign(this.store.options.ruleOptions,t.ruleOptions),t.ruleOptions=this.store.options.ruleOptions)),t.background!==void 0&&this.canvas&&(this.canvas.canvasTemplate.bgPatchFlags=!0),t.resizeMode!==void 0&&(t.resizeMode||(this.canvas.hotkeyType=ft.None)),(t.width!==void 0||t.height!==void 0)&&(this.canvas&&(this.canvas.canvasTemplate.bgPatchFlags=!0),this.canvas&&this.canvas.canvasTemplate.canvas.style.backgroundImage&&(this.canvas.canvasTemplate.canvas.style.backgroundImage="")),this.store.options=Object.assign(this.store.options,t),t.roles&&((s=this.store.data.pens)!=null&&s.length))for(const a of this.store.data.pens)Xt(a);this.canvas&&t.scroll!==void 0&&(t.scroll?(!this.canvas.scroll&&(this.canvas.scroll=new Zr(this.canvas)),this.canvas.scroll.show()):this.canvas.scroll&&this.canvas.scroll.hide()),(r=this.canvas)==null||r.initGlobalStyle()}getOptions(){return this.store.options}registerTheme(t,i){if(!Array.isArray(i))return;const s=/^\s*\S+\s*:\s*\S+\s*$/;if(!i.every(l=>s.test(l)))return;const a={},o=[];for(let l=0;l<i.length;l++){const h=i[l].split(":"),c=h[0].trim(),f=h[1].trim();o.push([c,f].join(":")),a[c]=f}Ve.addTheme(t,o),this.store.theme[t]=a}setTheme(t){if(this.store.data.theme=t,this.setBackgroundColor(this.store.theme[t].background),this.canvas.parentElement.style.background=this.store.theme[t].parentBackground,this.setOptions({ruleColor:this.store.theme[t].ruleColor,ruleOptions:this.store.theme[t].ruleOptions}),!(this.store.options.themeOnlyCanvas||this.store.data.themeOnlyCanvas)){this.store.data.color=this.store.theme[t].color,Ve.updateCssRule(this.store.id,t),this.canvas.initGlobalStyle();for(let i=0;i<this.store.data.pens.length;i++){const s=this.store.data.pens[i];s.setTheme&&s.setTheme(s,this.store.styles)}}this.render()}setDatabyOptions(t={}){const{color:i,activeColor:s,activeBackground:r,grid:a,gridColor:o,gridSize:l,gridType:n,gridScope:h,fromArrow:c,toArrow:f,rule:u,ruleColor:d,textColor:v,x:g=0,y=0}=t;this.setRule({rule:u,ruleColor:d}),this.setGrid({grid:a,gridColor:o,gridSize:l,gridType:n,gridScope:h}),this.store.data=Object.assign(this.store.data,{textColor:v,color:i,activeColor:s,activeBackground:r,fromArrow:c,toArrow:f,x:g,y})}init(t){typeof t=="string"?this.canvas=new sr(this,document.getElementById(t),this.store):this.canvas=new sr(this,t,this.store),this.canvas.initGlobalStyle(),this.resize(),this.canvas.listen(),Ve.createThemeSheet(this.store.data.theme,this.store.id)}initEventFns(){this.events[kt.Link]=(t,i)=>{var s;if(window&&i.value&&typeof i.value=="string"){let r=i.value;if(r.includes("${")){let a=(s=r.match(/\$\{([^}]+)\}/g))==null?void 0:s.map(o=>o.slice(2,-1));a&&(a==null||a.forEach(o=>{r=r.replace(`\${${o}}`,Et(t,o)||this.getDynamicParam(o))}))}window.open(r,i.params??"_blank");return}console.warn("[meta2d] Link param is not a string")},this.events[kt.SetProps]=(t,i)=>{var r,a,o;const s=i.value;if(s&&typeof s=="object"){const l=i.params?this.find(i.params):this.find(t.id),n={};for(let h in s)if((r=s[h])!=null&&r.id)n[h]=(a=this.store.pens[s[h].id])==null?void 0:a[s[h].key];else if(typeof s[h]=="string"&&s[h].includes("${")){let c=s[h],f=(o=c.match(/\$\{([^}]+)\}/g))==null?void 0:o.map(u=>u.slice(2,-1));f&&f.forEach(u=>{c=c.replace(`\${${u}}`,Et(t,u)||this.getDynamicParam(u))}),n[h]=c}else if(typeof s[h]=="string"&&(s[h].startsWith("{")&&s[h].endsWith("}")||s[h].startsWith("[")&&s[h].endsWith("]")))try{n[h]=JSON.parse(s[h])}catch{n[h]=s[h]}else n[h]=s[h];l.forEach(h=>{n.hasOwnProperty("visible")&&h.visible!==n.visible&&this.setVisible(h,n.visible),this.setValue({id:h.id,...n},{render:!1,doEvent:!1})}),this.render();return}console.warn("[meta2d] SetProps value is not an object")},this.events[kt.StartAnimate]=(t,i)=>{let s=t;if(i.value&&(s=this.findOne(i.value)),!(this.store.animates.has(s)&&!s.calculative.pause&&s.animateName===i.params)){if(i.targetType&&i.params){this.startAnimate(i.value||[t],i.params);return}if(!i.value||typeof i.value=="string"){this.startAnimate(i.value||[t]);return}console.warn("[meta2d] StartAnimate value is not a string")}},this.events[kt.PauseAnimate]=(t,i)=>{if(!i.value||typeof i.value=="string"){this.pauseAnimate(i.value||[t]);return}console.warn("[meta2d] PauseAnimate value is not a string")},this.events[kt.StopAnimate]=(t,i)=>{if(!i.value||typeof i.value=="string"){if(i.value){let s=this.findOne(i.value);if(!this.store.animates.has(s))return}else if(!this.store.animates.has(t))return;this.stopAnimate(i.value||[t]);return}console.warn("[meta2d] StopAnimate event value is not a string")},this.events[kt.StartVideo]=(t,i)=>{if(!i.value||typeof i.value=="string"){this.startVideo(i.value||[t]);return}console.warn("[meta2d] StartVideo value is not a string")},this.events[kt.PauseVideo]=(t,i)=>{if(!i.value||typeof i.value=="string"){this.pauseVideo(i.value||[t]);return}console.warn("[meta2d] PauseVideo value is not a string")},this.events[kt.StopVideo]=(t,i)=>{if(!i.value||typeof i.value=="string"){this.stopVideo(i.value||[t]);return}console.warn("[meta2d] StopVideo event value is not a string")},this.events[kt.JS]=(t,i,s)=>{var r;if(i.value&&!i.fn)try{if(typeof i.value!="string")throw new Error("[meta2d] Function value must be string");const a=i.value;i.fn=It(this.store.options,"pen","params","context",a)}catch(a){console.error("[meta2d]: Error on make a function:",a,"code:",i.value)}(r=i.fn)==null||r.call(i,t,s||i.params,{meta2d:this,eventName:i.name})},this.events[kt.GlobalFn]=(t,i)=>{if(typeof i.value!="string"){console.warn("[meta2d] GlobalFn value must be a string");return}globalThis[i.value]&&globalThis[i.value](t,i.params)},this.events[kt.Emit]=(t,i)=>{if(typeof i.value!="string"){console.warn("[meta2d] Emit value must be a string");return}this.store.emitter.emit(i.value,{pen:t,params:i.params,eventName:i.name})},this.events[kt.SendPropData]=(t,i)=>{const s=K(i.value);if(s&&typeof s=="object"){const r=i.params?this.findOne(i.params):t;for(let a in s)(s[a]===void 0||s[a]==="")&&(s[a]=r[a]);s.id=r.id,this.doSendDataEvent(s,i.extend);return}console.warn("[meta2d] SendPropData value is not an object")},this.events[kt.SendVarData]=(t,i)=>{var r;const s=K(i.value);if(s&&typeof s=="object"){const a=i.params?this.findOne(i.params):t;let o=[];for(let l in s){let n={dataId:l,value:s[l]};if(!n.value){let h=(r=a.form)==null?void 0:r.find(c=>c.dataIds&&c.dataIds.dataId===n.dataId);h&&(n.value=a[h.key])}o.push(n)}this.doSendDataEvent(o,i.extend);return}console.warn("[meta2d] SendVarData value is not an object")},this.events[kt.Navigator]=(t,i)=>{i.value&&typeof i.value=="string"&&this.navigatorTo(i.value)},this.events[kt.Dialog]=(t,i)=>{var s;if(i.params&&typeof i.params=="string"){let r=i.params;if(i.params.includes("${")){let o=(s=i.params.match(/\$\{([^}]+)\}/g))==null?void 0:s.map(l=>l.slice(2,-1));o&&(o==null||o.forEach(l=>{r=r.replace(`\${${l}}`,Et(t,l)||this.getDynamicParam(l))}))}Object.keys(i.extend).forEach(o=>{["x","y","width","height"].includes(o)||(r.indexOf("?")!==-1?r+=`&${o}=${i.extend[o]}`:r+=`?${o}=${i.extend[o]}`)});let a=this.getEventData(i.list,t);Object.keys(a).length&&(a=null),this.canvas.dialog.show(i.value,r,i.extend,a)}},this.events[kt.SendData]=(t,i)=>{var r,a,o,l;if((r=i.data)!=null&&r.length){const n=this.getSendData(i.data,t);t.formId&&t.formData&&Object.assign(n,t.formData),this.sendDataToNetWork(n,t,i);return}if((a=i.list)!=null&&a.length){if(i.network&&i.network.protocol==="ADIIOT"){const h=gc(this,t,i);h.length&&yc(this,h);return}const n=this.getEventData(i.list,t);t.deviceId&&(n.deviceId=t.deviceId),t.formId&&t.formData&&Object.assign(n,t.formData),this.sendDataToNetWork(n,t,i);return}const s=K(i.value);if(s&&typeof s=="object"&&i.targetType==="id"){const n=i.params?this.findOne(i.params):t;for(let h in s)if(s[h]===void 0||s[h]==="")s[h]=Et(n,h);else if(typeof s[h]=="string"&&((o=s[h])==null?void 0:o.indexOf("${"))>-1){let c=(l=s[h].match(/\$\{([^}]+)\}/g))==null?void 0:l.map(f=>f.slice(2,-1));c!=null&&c.length&&(s[h]=Et(n,h[0])??this.getDynamicParam(c[0]))}n.deviceId&&(s.deviceId=n.deviceId),this.sendDataToNetWork(s,t,i);return}},this.events[kt.PostMessage]=(t,i)=>{if(typeof i.value!="string"){console.warn("[meta2d] Emit value must be a string");return}const s=i.params?this.findOne(i.params):t;if(s.name!=="iframe"||!s.iframe){console.warn("不是嵌入页面");return}let r=Ie(s.iframe.split("?")[1]),a=this.getSendData(i.data,t);i.list&&(a=this.getEventData(i.list,t)),s.calculative.singleton.div.children[0].contentWindow.postMessage(JSON.stringify({name:i.value,id:r.id,data:a}),"*")},this.events[kt.PostMessageToParent]=(t,i)=>{if(typeof i.value!="string"){console.warn("[meta2d] Emit value must be a string");return}let s=this.getSendData(i.data,t);i.list&&(s=this.getEventData(i.list,t)),window.parent.postMessage(JSON.stringify({name:i.value,data:s}),"*")},this.events[kt.Message]=(t,i,s)=>{let r=i.params,a=i.value;!a&&s&&s.type==="http"&&(a=s.error.statusText,r||(r="error")),this.message({theme:r,content:a,...i.extend})}}getSendData(t,i){const s={};return t==null||t.forEach(r=>{var a;if(r.prop)if(r.id&&r.id!=="固定值"){const o=this.findOne(r.id);s[r.prop]=Et(o,r.key)}else if(typeof r.value=="string"&&r.value.includes("${")){let o=r.value,l=(a=o.match(/\$\{([^}]+)\}/g))==null?void 0:a.map(n=>n.slice(2,-1));l&&l.forEach(n=>{o=o.replace(`\${${n}}`,Et(i,n)||this.getDynamicParam(n))}),s[r.prop]=o}else s[r.prop]=this.convertType(r.value,r.type)}),s}convertType(t,i){var s;if(typeof t=="string"){if(["switch","bool","boolean"].includes(i)){if(t==="false")return!1;if(t==="true")return!0}else if(["integer","number","int","enum","double","float"].includes(i)&&!isNaN(Number(t)))return Number(t)}else if(typeof t=="object"){let r=JSON.stringify(t),a=(s=r.match(/\$\{([^}]+)\}/g))==null?void 0:s.map(o=>o.slice(2,-1));if(a!=null&&a.length)for(let o=0;o<a.length;o++)r=r.replace(`\${${a[o]}}`,this.getDynamicParam(a[o]));return JSON.parse(r)}return t}getEventData(t,i){const s={};return t!=null&&t.length&&t.forEach(r=>{var o,l;const a=r.params?this.findOne(r.params):i;for(let n in r.value)if(r.value[n]===void 0||r.value[n]==="")s[n]=a[n];else if(typeof r.value[n]=="string"&&((o=r.value[n])==null?void 0:o.indexOf("${"))>-1){let h=(l=r.value[n].match(/\$\{([^}]+)\}/g))==null?void 0:l.map(c=>c.slice(2,-1));h!=null&&h.length&&(s[n]=a[h[0]]??this.getDynamicParam(h[0]))}else s[n]=r.value[n]}),Object.keys(s).length?s:{}}message(t){new uc(this.canvas.parentElement,t).init()}closeAll(){for(let t in Nt)Nt[t].close()}async navigatorTo(t){var r,a;if(!t)return;if((r=Ie())==null?void 0:r.id){const o=new URL(window.location);o.searchParams.set("id",t),history.pushState({},"",o)}const s=await os(this.store,t);if(s){s.locked=1,(a=s.fits)!=null&&a.length&&(globalThis.meta2dData=JSON.stringify(s)),this.canvas.opening=!0,this.open(s),this.lock(1);const o=this.store.data.width||this.store.options.width,l=this.store.data.height||this.store.options.height;o&&l?this.fitSizeView(!0,0):this.fitView(!0,10),this.render(!0)}}doSendDataEvent(t,i){let s=JSON.stringify(t);this.mqttClient&&this.mqttClient.connected&&(i?i.split(",").forEach(r=>{this.mqttClient.publish(r,s)}):this.store.data.mqttTopics&&this.store.data.mqttTopics.split(",").forEach(r=>{this.mqttClient.publish(r,s)})),this.websocket&&this.websocket.readyState===1&&this.websocket.send(s),(this.store.data.https||this.store.data.http)&&this.sendDatabyHttp(s),this.store.emitter.emit("sendData",s)}async sendDataToNetWork(t,i,s){var a,o,l,n,h,c;const r=K(s.network);if(r.data&&(Object.assign(r,r.data),delete r.data),r.protocol==="iot"){if(this.store.data.iot.room){let f={token:this.store.data.iot.token,data:t};if(t.name){const u=Object.keys(t).filter(d=>t[d]==="aggregate");if(u.length){const d=K(t);u.forEach(g=>{delete d[g]}),delete d.name,d.start&&typeof d.start=="string"&&(d.start=Math.floor(new Date(d.start).getTime()/1e3)),d.end&&typeof d.end=="string"&&(d.end=Math.floor(new Date(d.end).getTime()/1e3));let v=[];u.forEach(g=>{let y=g.split("#");v.push({token:this.store.data.iot.token,deviceId:y[0],key:y[1],name:y[1]+"_"+t.name,...d})}),this.iotMqttClient&&this.iotMqttClient.publish(`le5le-iot/${this.store.data.iot.room}/property/aggregate`,JSON.stringify(v));return}}this.iotMqttClient&&this.iotMqttClient.publish(`le5le-iot/${this.store.data.iot.room}/properties/set`,JSON.stringify(f))}else this.iotMqttClient&&this.iotMqttClient.publish(`le5le-iot/property/set/${(a=this.store.data.iot)==null?void 0:a.token}`,JSON.stringify(t));return}if(r.url){if(r.protocol==="http"){if(typeof r.headers=="object"){let v=JSON.stringify(r.headers),g=(o=v.match(/\$\{([^}]+)\}/g))==null?void 0:o.map(y=>y.slice(2,-1));if(g!=null&&g.length)for(let y=0;y<g.length;y++)v=v.replace(`\${${g[y]}}`,this.getDynamicParam(g[y]));r.headers=JSON.parse(v)}let f,u=r.url;if(r.method==="GET"&&Object.keys(t).length!==0&&(u.includes("?")?f="&"+Object.keys(t).map(v=>v+"="+t[v]).join("&"):f="?"+Object.keys(t).map(v=>v+"="+t[v]).join("&")),u.indexOf("${")>-1){let v=(l=u.match(/\$\{([^}]+)\}/g))==null?void 0:l.map(g=>g.slice(2,-1));v&&v.forEach(g=>{u=u.replace(`\${${g}}`,Et(i,g)||this.getDynamicParam(g))})}const d=await fetch(u+(f||""),{headers:r.headers||{},method:r.method,body:r.method==="POST"?JSON.stringify(t):void 0});if(d.ok){if(s.callback){const v=await d.text();if(!s.fn)try{if(typeof s.callback!="string")throw new Error("[meta2d] Function callback must be string");const g=s.callback;s.fn=It(this.store.options,"pen","data","context",g)}catch(g){console.error("[meta2d]: Error on make a function:",g,"code:",s.callback)}(n=s.fn)==null||n.call(s,i,v,{meta2d:this,e:s})}console.info("http消息发送成功")}else this.store.emitter.emit("error",{type:"http",error:d})}else if(r.protocol==="mqtt"){const f=(h=this.mqttClients)==null?void 0:h.filter(u=>u.options.href===r.url);if(f&&f.length)f[0].connected&&r.topics.split(",").forEach(u=>{f[0].publish(u,JSON.stringify(t))});else{let u=di.connect(r.url,r.options);u.on("connect",()=>{console.info("mqtt连接成功"),r.topics.split(",").forEach(d=>{u.publish(d,JSON.stringify(t)),setTimeout(()=>{u==null||u.end()},1e3)})})}}else if(r.protocol==="websocket"){const f=(c=this.websockets)==null?void 0:c.filter(u=>u.url===r.url);if(f&&f.length)f[0].readyState===1&&f[0].send(JSON.stringify(t));else{let u=new WebSocket(r.url,r.protocols||void 0);u.onopen=function(){console.info("websocket连接成功"),u.send(JSON.stringify(t)),setTimeout(()=>{u.close()},100)}}}}}resize(t,i){this.canvas.resize(t,i),this.render(),this.store.emitter.emit("resize",{width:t,height:i}),this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.init()}async addPen(t,i,s=!0,r=!1){return await this.canvas.addPen(t,i,s,r)}addPenSync(t,i,s=!0,r=!0){return this.canvas.addPenSync(t,i,s,r)}addPensSync(t,i,s=!0){return this.canvas.addPensSync(t,i,s)}async addPens(t,i,s=!1){return await this.canvas.addPens(t,i,s)}render(t){var i;(i=this.canvas)==null||i.render(t)}async setBackgroundImage(t,i){var l,n,h,c;let s=this;async function r(f){return new Promise(u=>{const d=new Image;d.src=f,s.store.options.cdn&&!(f.startsWith("http")||f.startsWith("//")||f.startsWith("data:image"))&&(d.src=s.store.options.cdn+f),d.crossOrigin=s.store.options.crossOrigin||"anonymous",d.onload=()=>{u(d)}})}this.store.data.bkImage=t;const a=(i==null?void 0:i.width)||((l=this.store.data)==null?void 0:l.width)||((n=this.store.options)==null?void 0:n.width),o=(i==null?void 0:i.height)||((h=this.store.data)==null?void 0:h.height)||((c=this.store.options)==null?void 0:c.height);if(a&&o?(this.canvas.canvasTemplate.canvas.style.backgroundImage=null,this.canvas&&(this.canvas.canvasTemplate.bgPatchFlags=!0)):this.canvas.canvasTemplate.canvas.style.backgroundImage=t?`url('${t}')`:"",t){const f=await r(t);this.store.bkImg=f,a&&o&&this.canvas&&(this.canvas.canvasTemplate.init(),this.render())}else this.store.bkImg=null}setBackgroundColor(t=this.store.data.background){this.store.data.background=t,this.canvas&&(this.canvas.canvasTemplate.bgPatchFlags=!0)}setGrid({grid:t=this.store.data.grid,gridColor:i=this.store.data.gridColor,gridSize:s=this.store.data.gridSize,gridRotate:r=this.store.data.gridRotate,gridType:a=this.store.data.gridType,gridScope:o=this.store.data.gridScope}={}){this.store.data.grid=t,this.store.data.gridColor=i,this.store.data.gridSize=s<0?0:s,this.store.data.gridRotate=r,this.store.data.gridType=a,this.store.data.gridScope=o,this.canvas&&(this.canvas.canvasTemplate.bgPatchFlags=!0)}setRule({rule:t=this.store.data.rule,ruleColor:i=this.store.data.ruleColor}={}){this.store.data.rule=t,this.store.data.ruleColor=i,this.store.patchFlagsTop=!0}open(t,i=!0){if(this.clear(!1,t==null?void 0:t.template),this.fillViewSnapshot=null,this.canvas.autoPolylineFlag=!0,t){t.theme&&this.setTheme(t.theme),tl(t.pens),this.setBackgroundImage(t.bkImage,t),Object.assign(this.store.data,t),this.store.data.pens=[];for(const s of t.pens)s.id||(s.id=lt()),!s.calculative&&(s.calculative={canvas:this.canvas}),this.store.pens[s.id]=s;for(const s of t.pens)this.canvas.makePen(s)}if(this.canvas.patchFlagsLines.forEach(s=>{s.type&&this.canvas.initLineRect(s)}),this.store.data.template||(this.store.data.template=lt()),i||(this.canvas.opening=!0),this.doInitJS(),this.initBindDatas(),this.initBinds(),this.doInitFn(),this.loadLineAnimateDraws(),this.initMessageEvents(),this.initGlobalTriggers(),this.startAnimate(),this.startVideo(),this.listenSocket(),this.connectSocket(),this.connectNetwork(),this.startDataMock(),this.canvas.initGlobalStyle(),this.render(),setTimeout(()=>{const s=this.store.data.pens.find(r=>r.autofocus);s&&this.focus(s.id)},100),this.store.data.iconUrls)for(const s of this.store.data.iconUrls)Ka(s,()=>{this.render()});this.canvas.autoPolylineFlag=!1,this.store.emitter.emit("opened"),this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.init()}dirtyData(t){const i=this.store.data.pens,s=this.store.data.width||this.store.options.width,r=this.store.data.height||this.store.options.height,a=[];for(let o=i.length-1;o>=0;o--){let l=i[o];if(l.parentId){const n=this.store.pens[l.parentId];(l.x>10||l.y>10||l.width>10||l.height>10||!n.children||!n.children.includes(l.id))&&a.push(l)}if(s&&r){let n=this.getPenRect(l);(n.x<-10||n.y<-10||n.x+n.width>s||n.y+n.height>r)&&a.push(l)}l.name==="line"&&l.anchors.length<2&&a.push(l)}return(!s||!r)&&Ko(i).forEach(l=>{a.filter(h=>h.id===l.id).length||a.push(l)}),t&&this.active(a),a}clearDirtyData(){let t=this.dirtyData();this.delete(t,!0)}cacheData(t){if(t&&this.store.options.cacheLength){let i=this.store.cacheDatas.findIndex(s=>s.data&&s.data._id===t);if(i===-1)this.store.cacheDatas.push({data:K(this.store.data,!0)}),this.store.cacheDatas.length>this.store.options.cacheLength&&this.store.cacheDatas.shift();else{let s=this.store.cacheDatas.splice(i,1)[0];this.store.cacheDatas.push(s)}}}loadCacheData(t){let i=this.store.cacheDatas.findIndex(s=>s.data&&s.data._id===t);i!==-1&&(this.store.data=this.store.cacheDatas[i].data,this.setBackgroundImage(this.store.data.bkImage),this.store.pens={},this.store.data.pens.forEach(s=>{s.calculative.canvas=this.canvas,this.store.pens[s.id]=s,it.path2dDraws[s.name]&&this.store.path2dMap.set(s,it.path2dDraws[s.name](s)),s.type&&this.store.path2dMap.set(s,it.path2dDraws[s.name](s)),s.image&&(s.calculative.imageDrawed=!1,this.canvas.loadImage(s))}),this.render())}loadLineAnimateDraws(){it.lineAnimateDraws={},Object.entries(this.store.data.lineAnimateDraws).forEach(([t,i])=>{it.lineAnimateDraws[t]=It(this.store.options,"ctx","pen","state","index",i)})}statistics(){const t=this.store.data.pens.length,i=this.store.data.pens.filter(l=>l.image).length,s=this.store.data.pens.filter(l=>l.image&&l.calculative.inView).length,r=this.store.data.pens.filter(l=>l.name.endsWith("Dom")||$i.includes(l.name)||this.store.options.domShapes.includes(l.name)||l.externElement||l.isDom).length,a=this.store.animates.size;let o=0;return Object.keys(this.store.bind).forEach(l=>{o+=this.store.bind[l].length}),Object.keys(this.store.bindDatas).forEach(l=>{o+=this.store.bindDatas[l].length}),{图元总数量:t,图片图元数量:i,图片图元绘制数量:s,dom图元数量:r,正在执行的动画数量:a,数据点数量:o}}initBindDatas(){this.store.bindDatas={},this.store.data.pens.forEach(t=>{var i;(i=t.form)==null||i.forEach(s=>{let r;s.dataIds&&(Array.isArray(s.dataIds)?r=s.dataIds:r=[s.dataIds]),r==null||r.forEach(a=>{this.store.bindDatas[a.dataId]||(this.store.bindDatas[a.dataId]=[]),this.store.bindDatas[a.dataId].push({id:t.id,formItem:s})})})})}initBinds(){this.jetLinksList=[],this.store.bind={};const t=[],i=[],s=[];this.store.data.pens.forEach(r=>{var a,o;(a=r.realTimes)==null||a.forEach(l=>{var n;if(l.bind&&l.bind.id){const h=(n=this.store.data.networks)==null?void 0:n.some(v=>v.protocol==="ADIIOT");let c=l.productId||r.productId,f=l.deviceId||r.deviceId,u=l.propertyId,d=!1;if(h){if(c&&typeof c=="string"&&c.indexOf("${")>-1){let v=c.match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));v!=null&&v.length&&(c=this.getDynamicParam(v[0])||c),d=!0}if(f&&typeof f=="string"&&f.indexOf("${")>-1){let v=f.match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));v!=null&&v.length&&(f=this.getDynamicParam(v[0])||f),d=!0}if(u&&typeof u=="string"&&u.indexOf("${")>-1){let v=u.match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));v!=null&&v.length&&(u=this.getDynamicParam(v[0])||u),d=!0}d&&l.bind&&(l.bind.id=c+"#"+f+"#"+u)}if(this.store.bind[l.bind.id]||(this.store.bind[l.bind.id]=[]),this.store.bind[l.bind.id].push({id:r.id,key:l.key}),h&&c&&f&&u){const v=this.jetLinksList.findIndex(g=>g.topic.startsWith(`/${c}/${f}`));v>-1?this.jetLinksList[v].properties.includes(l.propertyId)||this.jetLinksList[v].properties.push(l.propertyId):this.jetLinksList.push({topic:`/${c}/${f}`,deviceId:f,properties:[l.propertyId]})}if(l.bind.class==="iot")if(l.bind.compute_name){s.findIndex(y=>y.id===l.bind.id)===-1&&s.push(K(l.bind));let g=t.findIndex(y=>y.deviceId===l.bind.deviceId);g>-1?t[g].properties.includes(l.bind.key)||t[g].properties.push(l.bind.key):t.push({deviceId:l.bind.deviceId,properties:[l.bind.key],token:l.bind.token})}else{let v=l.bind.id.split("#"),g=t.findIndex(p=>p.deviceId===v[0]);g>-1?t[g].properties.includes(v[1])||t[g].properties.push(v[1]):t.push({deviceId:v[0],properties:[v[1]],token:l.bind.token}),i.findIndex(p=>p.key===l.bind.id)===-1&&i.push({key:l.bind.id,label:l.bind.label})}else if(l.bind.class==="sql"){let v=l.bind.id.split("#");const g=this.store.data.sqls.find(y=>y.bindId===v[0]);if(g){g.keys||(g.keys=[]),v.shift();const y=v.join("#");g.keys.includes(y)||g.keys.push(y)}}}}),(o=r.events)==null||o.forEach(l=>{var h;const n=(h=l.actions)==null?void 0:h.filter(c=>c.action===kt.SendData);n==null||n.forEach(c=>{var f;(f=c.data)==null||f.forEach(u=>{if(u.class==="iot"){let d=u.prop.split("#"),v=t.findIndex(g=>g.deviceId===d[0]);v>-1?t[v].properties.includes(d[1])||t[v].properties.push(d[1]):t.push({deviceId:d[0],properties:[d[1]],token:u.token})}})})})}),this.store.data.iot||(this.store.data.iot={}),t.length?this.store.data.iot.devices=t:delete this.store.data.iot.devices,i.length?this.store.data.iot.list=i:delete this.store.data.iot.list,s.length&&(this.store.data.iot.computes=s)}connectSocket(){this.connectWebsocket(),this.connectMqtt(),this.connectHttp()}doInitJS(){const t=this.store.data.initJs;if(t&&t.trim())try{let i=It(this.store.options,"context",t);i({meta2d:this}),i=null}catch(i){console.warn("initJs error",i)}}doInitFn(){let t=Ie(),i=[];for(let s in t)t.hasOwnProperty(s)&&s.startsWith("bind-")&&i.push({id:s.replace("bind-",""),dataId:s.replace("bind-",""),value:t[s]});i.length&&this.setDatas(i,{history:!1})}drawLine(t){t&&ta(this.store),this.canvas.drawingLineName=t}alignPenToGrid(t){this.canvas.alignPenToGrid(t)}drawingPencil(){this.canvas.drawingPencil()}stopPencil(){this.canvas.stopPencil()}lock(t){this.store.data.locked=t,this.finishDrawLine(!0),this.canvas.drawingLineName="",this.stopPencil(),this.store.data.pens.forEach(i=>{var s;i.externElement===!0&&(s=i.calculative.singleton)!=null&&s.div&&Ct(i,i.calculative.singleton.div)}),t>0&&this.initMessageEvents()}async finishDrawLine(t){await this.canvas.finishDrawline(t)}async finishPencil(){await this.canvas.finishPencil()}updateLineType(t,i){if(!t||t.name!="line"||!i||!this.canvas[i])return;t.lineName=i;const s=xt(t),r=dt(t);s.prev=void 0,s.next=void 0,r.prev=void 0,r.next=void 0,t.calculative.worldAnchors=[s,r],t.calculative.activeAnchor=s,this.canvas[i](this.store,t,r),t.lineName==="curve"&&(s.prev={penId:s.penId,x:s.x-50,y:s.y},s.next={penId:s.penId,x:s.x+50,y:s.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()}addDrawLineFn(t,i){this.canvas[t]=i,this.canvas.drawLineFns.push(t)}removeDrawLineFn(t){const i=this.canvas.drawLineFns.indexOf(t);i>-1&&this.canvas.drawLineFns.splice(i,1)}showMagnifier(){this.canvas.showMagnifier()}hideMagnifier(){this.canvas.hideMagnifier()}toggleMagnifier(){this.canvas.toggleMagnifier()}clear(t=!0,i){var s;for(const r of this.store.data.pens)(s=r.onDestroy)==null||s.call(r,r);Ha(this.store,i),this.hideInput(),this.canvas.tooltip.hide(),this.map&&this.map.isShow&&(this.map.show(),this.map.setView()),this.canvas.clearCanvas(),sessionStorage.removeItem("page"),this.store.clipboard=void 0,this.store.sameTemplate||(this.canvas.canvasTemplate.bgPatchFlags=!0),this.store.patchFlagsBackground=!0,this.store.patchFlagsTop=!0,this.setBackgroundImage(void 0),t&&this.render()}emit(t,i){this.store.emitter.emit(t,i)}on(t,i){return this.store.emitter.on(t,i),this}off(t,i){return this.store.emitter.off(t,i),this}updateLineAnimateDraws(t,i){i&&(delete this.store.data.lineAnimateDraws[t],delete it.lineAnimateDraws[t],i!==-1&&this.registerLineAnimateDraws(i.name||t,i.code))}registerMoveDock(t){this.canvas.customMoveDock=t}registerResizeDock(t){this.canvas.customResizeDock=t}find(t){return this.canvas.find(t)}findOne(t){return this.canvas.findOne(t)}getPenRect(t){return this.canvas.getPenRect(t)}setPenRect(t,i,s=!0){this.canvas.setPenRect(t,i,s)}startAnimate(t,i){let s;t?typeof t=="string"?(s=this.find(t),s.forEach(r=>{(!r.calculative.pause||r.currentAnimation!==i)&&this.stopAnimate([r])})):(s=t,s.forEach(r=>{(!r.calculative.pause||r.currentAnimation!==i)&&this.stopAnimate([r])})):s=this.store.data.pens.filter(r=>(r.type||r.frames)&&r.autoPlay||r.animations&&r.animations.length&&r.animations.findIndex(a=>a.autoPlay)!==-1),s.length&&(s.forEach(r=>{var a,o;if(r.calculative.pause){const l=Date.now()-r.calculative.pause;r.calculative.pause=void 0,r.calculative.frameStart+=l,r.calculative.frameEnd+=l}else{let l=-1;if(i!==void 0&&r.animations){if(typeof i=="string"){if(l=r.animations.findIndex(n=>n.name===i),l===-1)return}else if(typeof i=="number")if(r.animations.length>i)l=i;else return}else i===void 0&&(l=(a=r.animations)==null?void 0:a.findIndex(n=>n.autoPlay),l===-1&&((o=r.animations)!=null&&o.length)&&(l=0));if(l!==-1&&l!==void 0){const n=K(r.animations[l]);n.animateCycle||(n.animateCycle=0),n.animateName=n.name,delete n.name,n.currentAnimation=l,!r.type&&n.frames&&(n.showDuration=this.calcAnimateDuration(n)),this.setValue({id:r.id,...n},{doEvent:!1,history:!1})}this.store.animates.add(r),r.type||this.store.animateMap.set(r,r.calculative.canvas.getFrameProps(r))}}),this.initImageCanvas(s),this.canvas.animate())}pauseAnimate(t){let i=[];t?typeof t=="string"?i=this.find(t):i=t:this.store.animates.forEach(s=>{i.push(s)}),i.forEach(s=>{s.calculative.pause||(s.calculative.pause=Date.now())})}stopAnimate(t){let i=[];t?typeof t=="string"?i=this.find(t):i=t:this.store.animates.forEach(s=>{i.push(s)}),i.forEach(s=>{s.currentAnimation=void 0,s.calculative.pause=void 0,s.calculative.start=void 0,s.calculative.cycleStart=void 0,s.calculative.duration=void 0,s.calculative.animatePos=0,this.store.animates.delete(s),this.canvas.restoreNodeAnimate(s),this.canvas.updateLines(s),this.store.animateMap.delete(s)}),this.initImageCanvas(i),this.store.data.locked===ct.None&&setTimeout(()=>{var s;(s=this.canvas)==null||s.calcActiveRect(),this.render()},20)}startVideo(t){let i;t?typeof t=="string"?i=this.find(t):i=t:i=this.store.data.pens.filter(s=>(s.video||s.audio)&&s.autoPlay),i.forEach(s=>{var r,a;(r=s.calculative.media)==null||r.play(),(a=s.onStartVideo)==null||a.call(s,s)})}pauseVideo(t){let i=[];t?typeof t=="string"?i=this.find(t):i=t:i=this.store.data.pens.filter(s=>(s.video||s.audio)&&s.autoPlay),i.forEach(s=>{var r,a;(r=s.calculative.media)==null||r.pause(),(a=s.onPauseVideo)==null||a.call(s,s)})}stopVideo(t){let i=[];t?typeof t=="string"?i=this.find(t):i=t:i=this.store.data.pens.filter(s=>(s.video||s.audio)&&s.autoPlay),i.forEach(s=>{var r;s.calculative.media&&(s.calculative.media.currentTime=0,s.calculative.media.pause()),(r=s.onStopVideo)==null||r.call(s,s)})}calcAnimateDuration(t){return t.frames.reduce((i,s)=>i+s.duration,0)}combine(t=this.store.active,i,s=!0){if(!t||!t.length)return;const r=K(t);if(t.length===1&&t[0].type){t[0].type=ut.Node,this.canvas.active(t),this.pushHistory({type:rt.Update,initPens:r,pens:K(t,!0)}),this.render();return}const a=Vt(t);let o={id:lt(),name:"combine",...a,children:[],showChild:i};this.canvas.makePen(o);const l=K(o);let n=1/0;return t.forEach(h=>{const c=this.store.data.pens.findIndex(u=>u.id===h.id);if(c<n&&(n=c),h===o||h.parentId===o.id||h.id===o.id)return;o.children.push(h.id),h.parentId=o.id;const f=ce(h.calculative.worldRect,a);Object.assign(h,f),h.locked=h.lockedOnCombine??ct.None,h.locked=h.interaction||Di.includes(h.name)?0:h.locked}),this.store.data.pens.splice(n,0,o),this.store.data.pens.pop(),s&&this.canvas.active([o]),this.pushHistory({type:rt.Add,pens:[l],step:3}),this.pushHistory({type:rt.Update,initPens:[l],pens:[o],step:3}),this.pushHistory({type:rt.Update,initPens:r,pens:t,step:3}),i!=null&&(t.forEach(h=>{Xt(h,!0)}),this.initImageCanvas([o])),this.store.emitter.emit("combine",[o]),this.render(),o}uncombine(t){if(!t&&this.store.active&&(t=this.store.active[0]),!t||!t.children)return;const i=t.children.map(a=>this.store.pens[a]);let s=K(i);i.forEach(a=>{a.parentId=void 0,a.x=a.calculative.worldRect.x,a.y=a.calculative.worldRect.y,a.width=a.calculative.worldRect.width,a.height=a.calculative.worldRect.height,a.locked=ct.None,a.calculative.active=void 0,a.calculative.hover=!1,this.setVisible(a,!0)});const r=this.isCombine(t)?3:2;this.pushHistory({type:rt.Update,initPens:s,pens:i,step:r}),s=[K(t)],this.inactive(),t.children=void 0,this.pushHistory({type:rt.Update,initPens:s,pens:[t],step:r}),this.isCombine(t)&&(this.delete([t]),this.store.histories[this.store.histories.length-1].step=r)}clearCombine(t){if(!t&&this.store.active&&(t=this.store.active[0]),!t||!t.children)return;const i=Pt(t,this.store);i.forEach(r=>{r.parentId=void 0,r.x=r.calculative.worldRect.x,r.y=r.calculative.worldRect.y,r.width=r.calculative.worldRect.width,r.height=r.calculative.worldRect.height,r.locked=ct.None,r.calculative.active=void 0,r.calculative.hover=!1,r.showChild!==void 0&&this.setVisible(r,!0),r.children=void 0});const s=[];i.forEach((r,a)=>{r.name==="combine"&&(r.children=void 0,s.push(r))}),this.delete(s,!0,!1),t.children=void 0,this.isCombine(t)&&this.delete([t],!0,!1),this.inactive()}appendChild(t=this.store.active){if(!t||t.length<2)return;const i=t.findIndex(s=>s.name==="combine"&&s.showChild!==void 0);if(i!==-1){let s=t[i];const r=Vt(t);Object.assign(s,r),Object.assign(s.calculative.worldRect,r),Le(s),s.children.forEach(a=>{const o=this.store.pens[a],l=ce(o.calculative.worldRect,r);Object.assign(o,l)}),t.forEach(a=>{if(a.id!==s.id){s.children.push(a.id),a.parentId=s.id;const o=ce(a.calculative.worldRect,r);Object.assign(a,o),a.locked=a.lockedOnCombine??ct.DisableMove,a.locked=a.interaction||Di.includes(a.name)?0:a.locked,Xt(a,!0)}}),this.initImageCanvas(t),this.render()}else console.warn("Invalid operation!")}updateRectbyChild(t,i,s){if(bt(t),yt(t),i.calculative.worldRect=t,s.container&&ee(t,s.calculative.worldRect,!0)){const r=ce(t,s.calculative.worldRect);Object.assign(i,r)}else{if(s.container){let r=Math.min(t.x,s.calculative.worldRect.x),a=Math.min(t.y,s.calculative.worldRect.y),o=Math.max(t.ex,s.calculative.worldRect.ex),l=Math.max(t.ey,s.calculative.worldRect.ey);s.calculative.worldRect={x:r,y:a,width:o-r,height:l-a,ex:o,ey:l},yt(s.calculative.worldRect)}else{const r=s.children.map(a=>this.store.pens[a]);s.calculative.worldRect=Vt(r)}s.parentId||Object.assign(s,s.calculative.worldRect),s.children.forEach(r=>{const a=this.store.pens[r],o=ce(a.calculative.worldRect,s.calculative.worldRect);Object.assign(a,o)}),s.parentId&&this.updateRectbyChild(s.calculative.worldRect,s,this.store.pens[s.parentId])}this.canvas.updatePenRect(s),this.render()}isCombine(t){return!!(t.name==="combine"||t.children&&t.children.length>0)}active(t,i=!0){this.canvas.active(t,i)}inactive(){this.canvas.inactive()}activeAll(){this.canvas.active(this.store.data.pens.filter(t=>!t.parentId&&t.locked!==ct.Disable)),this.render()}focus(t){const i=this.findOne(t);i&&(this.store.hover=i,this.store.hover.calculative.hover=!0,this.showInput(i))}delete(t,i=!1,s=!0){this.canvas.delete(t,i,s)}deleteSync(t,i=!1,s=!0){this.canvas.deleteSync(t,i,s)}scale(t,i={x:0,y:0}){this.canvas.scale(t,i)}translate(t,i){this.canvas.translate(t,i)}translatePens(t,i,s){this.canvas.translatePens(t,i,s)}getParent(t,i){return Mt(t,i)}getAllChildren(t){return Pt(t,this.store)}getAllFollowers(t){return cs(t,this.store)}data(){this.initBinds();const t=K(this.store.data),{pens:i,paths:s}=this.store.data;t.version=pr.version,t.paths={};for(const r in s)Object.prototype.hasOwnProperty.call(s,r)&&i.find(a=>a.pathId===r)&&(t.paths[r]=s[r]);return t.dataPoints=[...Object.keys(this.store.bind),...Object.keys(this.store.bindDatas)],t}copy(t){this.canvas.copy(t)}cut(t){this.canvas.cut(t)}paste(){this.canvas.paste()}undo(){this.canvas.undo()}redo(){this.canvas.redo()}listenSocket(){try{let t;const i=this.store.data.socketCbJs;if(i&&(t=It(this.store.options,"e","context",i)),!t)return this.socketFn=null,!1;this.socketFn=t}catch(t){return console.error("Create the function for socket:",t),!1}return!0}connectWebsocket(t){if(this.closeWebsocket(),t&&(this.store.data.websocket=t),this.store.data.websocket){try{this.websocket=new WebSocket(this.store.data.websocket,this.store.data.websocketProtocols||void 0)}catch(i){this.store.emitter.emit("error",{type:"websocket",error:i});return}this.websocket.onmessage=i=>{this.socketCallback(i.data,{type:"websocket",url:this.store.data.websocket})},this.websocket.onerror=i=>{this.store.emitter.emit("error",{type:"websocket",error:i})},this.websocket.onclose=()=>{if(this.store.options.reconnetTimes&&(this.websocketTimes++,this.websocketTimes>=this.store.options.reconnetTimes)){this.websocketTimes=0,this.closeWebsocket();return}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){if(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=lt());const i={...this.store.data.mqttOptions};i.username||delete i.username,i.password||delete i.password;const{username:s,password:r}=i;s&&r||!s&&!r?(this.mqttClient=di.connect(this.store.data.mqtt,i),this.mqttClient.on("message",(a,o)=>{this.socketCallback(o.toString(),{topic:a,type:"mqtt",url:this.store.data.mqtt})}),this.mqttClient.on("error",a=>{this.store.emitter.emit("error",{type:"mqtt",error:a})}),this.mqttClient.on("close",()=>{this.store.options.reconnetTimes&&(this.mqttTimes++,this.mqttTimes>=this.store.options.reconnetTimes&&(this.mqttTimes=0,this.closeMqtt()))}),this.store.data.mqttTopics&&this.mqttClient.subscribe(this.store.data.mqttTopics.split(","))):console.warn("缺少用户名或密码")}}closeMqtt(){var t;(t=this.mqttClient)==null||t.end()}connectHttp(){this.closeHttp();const{https:t}=this.store.data;if(t)this.store.data.cancelFirstConnect||t.forEach(async i=>{this.oldRequestHttp(i)}),t.forEach((i,s)=>{i.http&&i.httpTimeInterval!==0&&(i.times=0,this.httpTimerList[s]=setInterval(async()=>{this.oldRequestHttp(i),this.store.options.reconnetTimes&&i.times>=this.store.options.reconnetTimes&&(i.times=0,clearInterval(this.httpTimerList[s]),this.httpTimerList[s]=void 0)},i.httpTimeInterval||1e3))});else{const{http:i,httpTimeInterval:s,httpHeaders:r}=this.store.data;i&&(this.httpTimer=setInterval(async()=>{const a=await fetch(i,{headers:r});if(a.ok){const o=await a.text();this.socketCallback(o,{type:"http",url:i})}},s||1e3))}}async oldRequestHttp(t){let i=K(t);if(i.http){const s=await fetch(i.http,{headers:i.httpHeaders,method:i.method||"GET",body:i.method==="POST"?JSON.stringify(i.body):void 0});if(s.ok){const r=await s.text();this.socketCallback(r,{type:"http",url:i.http})}else t.times++,this.store.emitter.emit("error",{type:"http",error:s})}}async sendDatabyHttp(t){const{https:i}=this.store.data;if(i)i.forEach(async s=>{s.http&&(await fetch(s.http,{method:"post",body:t,headers:s.httpHeaders})).ok&&console.info("http消息发送成功")});else{const{http:s,httpHeaders:r}=this.store.data;s&&(await fetch(s,{method:"post",body:t,headers:r})).ok&&console.info("http消息发送成功")}}closeHttp(){clearInterval(this.httpTimer),this.httpTimer=void 0,this.httpTimerList&&this.httpTimerList.forEach(t=>{clearInterval(t),t=void 0})}connectNetwork(){this.closeNetwork();const{networks:t}=this.store.data,i=[];if(t){let s=0,r=0,a=0,o=0;this.mqttClients=[],this.websockets=[],this.eventSources=[],t.forEach(async l=>{l.protocol==="mqtt"?(l.index=s,this.connectNetMqtt(l),s+=1):l.protocol==="websocket"?(l.index=a,this.connectNetWebSocket(l),a+=1):l.protocol==="http"?(l.index=r,i.push({url:l.url,interval:l.interval,headers:l.headers||void 0,method:l.method,body:l.body,enable:l.enable,index:l.index,once:l.once}),r+=1):l.protocol==="ADIIOT"?dc(this,l):l.protocol==="SSE"&&(l.index=o,this.connectSSE(l),o+=1)})}this.onNetworkConnect(i),this.connectIot(),this.connectSqls()}reconnectNetwork(t){var s,r,a;const i=(s=this.store.data.networks)==null?void 0:s[t];if(i)if(i.protocol==="mqtt")this.mqttClients&&((r=this.mqttClients[i.index])==null||r.end()),this.connectNetMqtt(i);else if(i.protocol==="websocket")this.websockets&&this.websockets[i.index]&&(this.websockets[i.index].onclose=void 0,this.websockets[i.index].close(),this.websockets[i.index]=void 0),this.connectNetWebSocket(i);else if(i.protocol==="http"){this.updateTimerList&&(clearInterval(this.updateTimerList[i.index]),this.updateTimerList[i.index]=void 0);const o=K(i);this.store.data.cancelFirstConnect||this.requestHttp(o),i.interval!==0&&(this.updateTimerList[i.index]=setInterval(async()=>{this.requestHttp(o)},o.interval||1e3))}else i.protocol==="SSE"&&(this.eventSources&&((a=this.eventSources[i.index])==null||a.close(),this.eventSources[i.index]=void 0),this.connectSSE(i))}async connectIot(){var h,c;const{iot:t}=this.store.data;if(!(t&&((h=t==null?void 0:t.devices)!=null&&h.length))||t&&t.enable===!1)return;let{url:i,password:s,username:r}=await this.getMqttUrl();if(i||(i=globalThis.iotUrl),!i){console.warn("iot Request address error");return}const{token:a,room:o,data:l}=await this.getIotToken(t.devices,t.protocol==="websocket"?1:void 0,t.room);l&&this.socketCallback(JSON.stringify(l),{type:"iot",url:i,method:"mqtt"}),o&&(t.room=o),t.token=a;const n={username:r,password:s,clientId:"client-"+Math.random().toString(16).slice(2,8)};if(this.iotMqttClient=di.connect(i,n),this.iotMqttClient.on("message",(f,u)=>{this.socketCallback(u.toString(),{topic:`le5le-iot/properties/${a}`,type:"iot",url:i,method:"mqtt"})}),this.iotMqttClient.on("error",f=>{this.store.emitter.emit("error",{type:"mqtt",error:f})}),t.room?this.iotMqttClient.subscribe(`le5le-iot/${t.room}/properties/get`):this.iotMqttClient.subscribe(`le5le-iot/properties/${a}`),this.iotTimer=setInterval(()=>{t.room?this.iotMqttClient&&this.iotMqttClient.publish("le5le-iot/subscribe/ping",t.room):this.iotMqttClient&&this.iotMqttClient.publish("le5le-iot/subscribe/ping",a)},3e5),(c=this.store.data.iot.computes)!=null&&c.length){let f=!1;this.store.data.iot.computes.forEach(u=>{u.times>0&&(f=!0)}),this.iotAggregatePublish(this.store.data.iot.computes),t.times=0,f&&(t.interval=setInterval(()=>{t.times+=1;let u=this.store.data.iot.computes.filter(d=>d.times&&t.times%d.times===0);u.length&&this.iotAggregatePublish(u)},1e3))}}iotAggregateBuild(t){let i={token:this.store.data.iot.token,deviceId:t.deviceId,key:t.key,name:t.key+"_"+t.compute_name};return["aggregate","start","end","groupBy","limit","recent"].forEach(s=>{if(t[s])if(t[s].indexOf("${")>-1){let r=t[s].match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));i[s]=this.getDynamicParam(r[0])}else(s==="start"||s==="end")&&typeof t[s]=="string"?i[s]=Math.floor(new Date(t[s]).getTime()/1e3):i[s]=t[s]}),i}iotAggregatePublish(t){if(this.iotMqttClient){let i=t.map(s=>this.iotAggregateBuild(s));this.iotMqttClient.publish(`le5le-iot/${this.store.data.iot.room}/property/aggregate`,JSON.stringify(i))}}closeIot(){if(this.iotMqttClient){const{iot:t}=this.store.data;t.interval&&(clearInterval(t.interval),t.interval=void 0),t!=null&&t.token&&this.unsubscribeIot(t.token,t.room),this.iotMqttClient.end(),this.iotMqttClient=void 0}clearInterval(this.iotTimer),this.iotTimer=void 0}connectSqls(){const{sqls:t}=this.store.data;t&&t.length&&t.forEach(async(i,s)=>{i.enable!==!1&&(await this.doSqlCode(i),i.interval&&(i.index=s,this.sqlTimerList[s]=setInterval(async()=>{await this.doSqlCode(i)},i.interval)))})}async connectSSE(t){if(t.enable!==!1){if(t.preJs&&(t.preFn||(t.preFn=ii(this.store.options,"network",t.preJs)),t.preFn)){const i=await t.preFn(t);i&&(t=i)}this.eventSources[t.index]=new EventSource(t.url,{withCredentials:t.withCredentials}),this.eventSources[t.index].onmessage=i=>{this.socketCallback(i.data,{type:"SSE",url:t.url,name:t.name,net:t})},this.eventSources[t.index].onerror=i=>{this.store.emitter.emit("error",{type:"SSE",error:i})}}}closeSSE(){this.eventSources&&this.eventSources.forEach(t=>{t&&(t.close(),t=void 0)})}async connectNetMqtt(t){var r,a,o;if(t.enable===!1)return;if(t.preJs&&(t.preFn||(t.preFn=ii(this.store.options,"network",t.preJs)),t.preFn)){const l=await t.preFn(t);l&&(t=l)}t.options.clientId&&!t.options.customClientId&&(t.options.clientId=lt());let i=t.url;if(i.indexOf("${")>-1){let l=(r=i.match(/\$\{([^}]+)\}/g))==null?void 0:r.map(n=>n.slice(2,-1));l&&l.forEach(n=>{i=i.replace(`\${${n}}`,this.getDynamicParam(n))})}t.times=0;let s=K(t.options);if(s!=null&&s.username&&s.username.includes("${")){let l=(a=s.username.match(/\$\{([^}]+)\}/g))==null?void 0:a.map(n=>n.slice(2,-1));l&&l.forEach(n=>{s.username=s.username.replace(`\${${n}}`,this.getDynamicParam(n))})}if(s!=null&&s.password&&s.password.includes("${")){let l=(o=s.password.match(/\$\{([^}]+)\}/g))==null?void 0:o.map(n=>n.slice(2,-1));l&&l.forEach(n=>{s.password=s.password.replace(`\${${n}}`,this.getDynamicParam(n))})}s.hasOwnProperty("keepalive")||Object.assign(s,{keepallive:30}),s.hasOwnProperty("reconnectPeriod")||Object.assign(s,{reconnectPeriod:5e3}),s.hasOwnProperty("connectTimeout")||Object.assign(s,{connectTimeout:10*1e3}),this.mqttClients[t.index]=di.connect(i,s),this.mqttClients[t.index].on("message",(l,n)=>{this.socketCallback(n.toString(),{topic:l,type:"mqtt",url:t.url,name:t.name,net:t})}),this.mqttClients[t.index].on("error",l=>{this.store.emitter.emit("error",{type:"mqtt",error:l})}),this.mqttClients[t.index].on("connect",l=>{var n;if(!l.sessionPresent&&t.topics){let h=t.topics;if(h.indexOf("${")>-1){let c=(n=h.match(/\$\{([^}]+)\}/g))==null?void 0:n.map(f=>f.slice(2,-1));c&&c.forEach(f=>{h=h.replace(`\${${f}}`,this.getDynamicParam(f))})}this.mqttClients[t.index].subscribe(h.split(","),{qos:1},c=>{c&&console.error("订阅失败:",c)})}})}async connectNetWebSocket(t){var s,r;if(this.websockets[t.index]&&(this.websockets[t.index].onclose=void 0,(s=this.websockets[t.index])==null||s.close(),this.websockets[t.index]=void 0),t.enable===!1)return;if(t.preJs&&(t.preFn||(t.preFn=ii(this.store.options,"network",t.preJs)),t.preFn)){const a=await t.preFn(t);a&&(t=a)}let i=t.url;if(i.indexOf("${")>-1){let a=(r=i.match(/\$\{([^}]+)\}/g))==null?void 0:r.map(o=>o.slice(2,-1));a&&a.forEach(o=>{i=i.replace(`\${${o}}`,this.getDynamicParam(o))})}this.websockets[t.index]=new WebSocket(i,t.protocols||void 0),this.websockets[t.index].onmessage=a=>{this.socketCallback(a.data,{type:"websocket",url:t.url,name:t.name,net:t})},this.websockets[t.index].onerror=a=>{this.store.emitter.emit("error",{type:"websocket",error:a})},this.websockets[t.index].onclose=()=>{var a;if(this.store.options.reconnetTimes&&(t.times++,t.times>=this.store.options.reconnetTimes)){t.times=0,this.websockets[t.index].onclose=void 0,(a=this.websockets[t.index])==null||a.close(),this.websockets[t.index]=void 0;return}setTimeout(()=>{console.info("Canvas websocket closed and reconneting..."),this.connectNetWebSocket(t)},2e3)}}async getMqttUrl(){const t=await fetch("/api/iot/app/mqtt",{method:"GET",headers:{Authorization:Ue()}});if(t.ok){const i=await t.text();let s=JSON.parse(i);return s.wssPort||s.wsPort?{username:s.username,password:s.password,url:`${location.protocol==="https:"?"wss":"ws"}://${s.host}:${location.protocol==="https:"?s.wssPort:s.wsPort}${s.path}`}:void 0}}async getIotToken(t,i,s){const r=await fetch("/api/iot/subscribe/properties",{method:"POST",headers:{Authorization:Ue()},body:JSON.stringify({devices:t,type:i,room:s})});if(r.ok)return await r.json()}async unsubscribeIot(t,i){return await fetch("/api/iot/unsubscribe/properties",{method:"POST",headers:{Authorization:Ue()},body:JSON.stringify({token:t,room:i})})}async doSqlCode(t){var a;const i=t.method||"get";let s=t.sql;i==="list"&&t.pageSize!==-1&&(t.dbType==="oracle"?s.includes("OFFSET")||(s+=` OFFSET ${((t.current||1)-1)*(t.pageSize||20)} ROWS FETCH NEXT ${t.pageSize||20} ROWS ONLY`):s.includes("LIMIT")||(s+=` LIMIT ${t.pageSize||20}`+(t.current>1?" OFFSET "+(t.current-1)*(t.pageSize||20):"")));const r=await fetch(`/api/iot/data/sql/${i}`,{method:"POST",headers:{Authorization:Ue()},body:JSON.stringify({dbId:t.dbId||t.dbid,sql:s})});if(r.ok){let o=await r.text();if(o){const l=[];if(o=JSON.parse(o),o.error){this.store.emitter.emit("error",{type:"sql",error:o.error});return}(a=t.keys)==null||a.forEach(n=>{l.push({id:t.bindId+"#"+n,value:Et(o,n.split("#").join("."))})}),l.push({id:t.bindId,value:o}),this.socketCallback(JSON.stringify(l),{type:"sql",url:`/api/iot/data/sql/${i}`,method:i})}}}randomString(t){t=t||32;let i="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",s=i.length,r="";for(let a=0;a<t;a++)r+=i.charAt(Math.floor(Math.random()*s));return r}mockValue(t){let i;if(t.enableMock&&t.mock!==void 0)if(t.type==="float")if(t.mock&&t.mock.indexOf(",")!==-1){let s=t.mock.split(","),r=Math.floor(Math.random()*s.length);i=parseFloat(s[r])}else if(t.mock&&t.mock.indexOf("-")!==-1){let s,r,a,o=t.mock.split("-");if(t.mock.charAt(0)==="-"?o.length===4?(s=-parseFloat(o[3]),r=-parseFloat(o[1]),a=o[3]):(s=parseFloat(o[2]),r=-parseFloat(o[1]),a=o[2]):(s=parseFloat(o[1]),r=parseFloat(o[0]),a=o[1]),(a+"").indexOf(".")!==-1){let l=(a+"").split(".")[1].length;i=(Math.random()*(s-r)+r).toFixed(l)}else i=Math.random()*(s-r)+r}else i=parseFloat(t.mock);else if(t.type==="integer")if(t.mock&&t.mock.indexOf(",")!==-1){let s=t.mock.split(","),r=Math.floor(Math.random()*s.length);i=parseInt(s[r])}else if(t.mock&&t.mock.indexOf("-")!==-1){let s,r,a=t.mock.split("-");t.mock.charAt(0)==="-"?a.length===4?(s=-parseFloat(a[3]),r=-parseFloat(a[1])):(s=parseFloat(a[2]),r=-parseFloat(a[1])):(s=parseInt(a[1]),r=parseInt(a[0])),i=parseInt(Math.random()*(s-r)+r+"")}else i=parseInt(t.mock);else if(t.type==="bool")typeof t.mock=="boolean"?i=t.mock:t.mock==="true"?i=!0:t.mock==="false"?i=!1:i=Math.random()<.5;else if(t.type==="object"||t.type==="array")t.mock;else if(t.mock&&t.mock.indexOf(",")!==-1){let s=t.mock.split(","),r=Math.floor(Math.random()*s.length);i=s[r]}else if(t.mock&&t.mock.startsWith("[")&&t.mock.endsWith("]")){let s=parseInt(t.mock.substring(1,t.mock.length-1));i=this.randomString(s)}else i=t.mock;return i}dataMock(){var i,s;let t=[];(s=(i=this.store.data.dataset)==null?void 0:i.devices)==null||s.forEach(r=>{let a=this.mockValue(r);a!==void 0&&t.push({id:r.id,value:a})}),t.length&&this.setDatas(t,{render:!0,doEvent:!0,history:!1})}networkMock(){if(this.store.data.networks&&this.store.data.networks.length){let t=[];this.store.data.networks.forEach(i=>{var s;i.enable===!1&&((s=i.children)==null||s.forEach(r=>{let a=K(r);a.enableMock=!0;let o=this.mockValue(a);o!==void 0&&t.push({id:r.id,value:o})}))}),t.length&&this.setDatas(t,{render:!0,doEvent:!0,history:!1})}}startDataMock(){this.store.data.enableMock?(this.stopDataMock(),this.initBinds(),this.updateTimer=setInterval(()=>{this.store.data.pens.forEach(i=>{this.penMock(i)}),this.networkMock(),this.render()},this.store.data.networkInterval||1e3)):this.stopDataMock()}stopDataMock(){clearInterval(this.updateTimer),this.updateTimer=void 0}penMock(t){var i;if(t.realTimes){let s={};if(t.realTimes.forEach(r=>{let a=this.mockValue(r);a!==void 0&&(s[r.key]=a)}),Object.keys(s).length){let r=t.onBeforeValue?t.onBeforeValue(t,s):s;this.canvas.updateValue(t,r),(i=t.onValue)==null||i.call(t,t),this.store.emitter.emit("valueUpdate",t)}}}penNetwork(t){if(!t.apiUrl)return;const i={url:t.apiUrl,method:t.apiMethod,headers:t.apiHeaders,body:t.apiBody};this.requestHttp(i),t.apiEnable?(this.store.pensNetwork||(this.store.pensNetwork={}),this.store.pensNetwork[t.id]=i):delete this.store.pensNetwork[t.id]}getDynamicParam(t){let i=localStorage.getItem(t);return globalThis.le5leTokenD&&[globalThis.le5leSSOTokenName??"ssotoken",globalThis.le5leTokenName??"token"].includes(t)&&(i=Tr(i)),Ie()[t]||i||pi(t)||globalThis[t]||""}onNetworkConnect(t){if(t&&t.length){if(this.store.pensNetwork)for(let i in this.store.pensNetwork)t.push(this.store.pensNetwork[i]);this.store.data.cancelFirstConnect||t.forEach(async i=>{i.enable!==!1&&this.requestHttp(i)}),t.forEach((i,s)=>{i.times=0,i.interval!==0&&i.enable!==!1&&(i.once?setTimeout(async()=>{this.requestHttp(i)},i.interval||1e3):this.updateTimerList[s]=setInterval(async()=>{this.requestHttp(i),this.store.options.reconnetTimes&&i.times>=this.store.options.reconnetTimes&&(i.times=0,clearInterval(this.updateTimerList[s]),this.updateTimerList[s]=void 0)},i.interval||1e3))})}}async requestHttp(t){var r,a,o,l;let i=K(t);const s=(r=this.store.data.networks)==null?void 0:r.filter(n=>n.protocol==="http")[i.index];if(s!=null&&s.preJs&&(s.preFn||(s.preFn=ii(this.store.options,"network",s.preJs)),s.preFn)){const n=await s.preFn(i);n&&(i=n)}if(i.url){if(i.url.indexOf("${")>-1){let h=(a=i.url.match(/\$\{([^}]+)\}/g))==null?void 0:a.map(c=>c.slice(2,-1));h&&h.forEach(c=>{i.url=i.url.replace(`\${${c}}`,this.getDynamicParam(c))})}if(typeof i.headers=="object"){let h=JSON.stringify(i.headers),c=(o=h.match(/\$\{([^}]+)\}/g))==null?void 0:o.map(f=>f.slice(2,-1));if(c!=null&&c.length)for(let f=0;f<c.length;f++)h=h.replace(`\${${c[f]}}`,this.getDynamicParam(c[f]));i.headers=JSON.parse(h)}if(typeof i.body=="object"){let h=JSON.stringify(i.body),c=(l=h.match(/\$\{([^}]+)\}/g))==null?void 0:l.map(f=>f.slice(2,-1));if(c!=null&&c.length)for(let f=0;f<c.length;f++)h=h.replace(`\${${c[f]}}`,this.getDynamicParam(c[f]));i.body=JSON.parse(h)}const n=await fetch(i.url,{headers:i.headers,method:i.method,body:i.method==="GET"?void 0:JSON.stringify(i.body)});if(n.ok){const h=await n.text();this.socketCallback(h,{type:"http",method:i.method,url:i.url,name:i.name,net:s})}else t.times++,this.store.emitter.emit("error",{type:"http",error:n})}}closeNetwork(){this.mqttClients&&this.mqttClients.forEach(t=>{t.end()}),this.websockets&&this.websockets.forEach(t=>{t&&(t.onclose=void 0,t.close(),t=void 0)}),this.mqttClients=void 0,this.websockets=void 0,this.updateTimerList&&this.updateTimerList.forEach(t=>{clearInterval(t),t=void 0}),this.sqlTimerList&&this.sqlTimerList.forEach(t=>{clearInterval(t),t=void 0}),this.closeIot(),vc(this),this.closeSSE()}socketCallback(t,i){var a,o;this.store.emitter.emit("socket",{message:t,context:i});let s=t;if((a=i.net)!=null&&a.socketCbJs&&((o=i.net)!=null&&o.socketFn||(i.net.socketFn=It(this.store.options,"e","context",i.net.socketCbJs)),i.net.socketFn)){if(s=i.net.socketFn(t,{meta2d:this,type:i.type,topic:i.topic,url:i.url,method:i.method}),!s)return;s&&s!==!0&&(t=s)}if(this.socketFn&&(s=this.socketFn(t,{meta2d:this,type:i.type,topic:i.topic,url:i.url,method:i.method,net:i.net}),!s))return;s===!0&&(s=t);let r;if(s.constructor===Object||s.constructor===Array)r=s;else if(typeof s=="string")try{r=JSON.parse(s)}catch(l){console.warn("Invalid socket data:",r,l)}else return;r&&(Array.isArray(r)||(r=[r]),r.length&&(r[0].dataId?this.setDatas(r):(r.forEach(l=>{this.setValue(l,{render:!1})}),this.render())))}setDatas(t,{render:i=!0,doEvent:s=!0,history:r}={}){const a=new Map;t.forEach(n=>{var h,c;(h=this.store.bindDatas[n.dataId])==null||h.forEach(f=>{const u=this.store.pens[f.id];if(!u)return;let d=a.get(u);if(!u.noOnBinds&&typeof u.onBinds=="function"){if(d)return;a.set(u,u.onBinds(u,t,f.formItem));return}d?d[f.formItem.key]=n.value:(d={id:f.id,[f.formItem.key]:n.value},a.set(u,d))}),(c=this.store.bind[n.id||n.dataId])==null||c.forEach(f=>{const u=this.store.pens[f.id];if(!u)return;let d=a.get(u);d?d[f.key]=n.value:(d={id:f.id,[f.key]:n.value},a.set(u,d))})}),this.store.data.locked&&this.doDataEvent(t);let o,l;r&&(o=[]),a.forEach((n,h)=>{this.setValue(n,{render:!1,doEvent:s,history:!1}),r&&(o.push(K(h,!0)),l.push(h))}),i&&this.render(),r&&this.pushHistory({type:rt.Update,initPens:o,pens:l})}setValue(t,{render:i=!0,doEvent:s=!0,history:r}={}){let a=[];if(!t)return;if(t.id){if(t.id===this.store.data.id){this.setDatabyOptions(t),t.bkImage&&this.setBackgroundImage(t.bkImage),t.background&&this.setBackgroundColor(t.background),this.render();return}const l=this.store.pens[t.id];if(l)a=[l];else{let n=this.store.bind[t.id];if(n&&n.length){a=[],this.setDatas([t],{render:i,doEvent:s,history:r});return}}}else if(t.dataId){a=[],this.setDatas([t],{render:i,doEvent:s,history:r});return}else if(t.tag)a=this.find(t.tag);else{let l=[];for(let n in t)l.push({dataId:n,id:n,value:t[n]});l.length&&this.setDatas(l,{render:i,doEvent:s,history:r});return}r=r&&!this.store.data.locked;let o;if(r&&(o=K(a)),a.forEach(l=>{var h;if(l.name==="echarts"&&!l.onBeforeValue&&Object.keys(t).some(f=>pc.test(f)))return;const n=l.onBeforeValue?l.onBeforeValue(l,t):t;t.frames&&(this.stopAnimate([l]),t.showDuration||(t.showDuration=t.frames.reduce((c,f)=>c+f.duration,0))),fs(l,n),this.canvas.updateValue(l,n),(h=l.onValue)==null||h.call(l,l)}),!this.store.data.locked&&this.store.active.length&&!this.canvas.movingPens&&this.canvas.calcActiveRect(),r){let l=K(a);this.pushHistory({type:rt.Update,initPens:o,pens:l})}s&&a.forEach(l=>{this.store.emitter.emit("valueUpdate",l)}),i&&this.render()}_setValue(t,i=!1){this.setValue(t,{history:i,render:!1,doEvent:!1})}pushHistory(t){this.canvas.pushHistory(t)}showInput(t,i){this.canvas.showInput(t,i)}hideInput(){this.canvas.hideInput()}clearDropdownList(){this.canvas.clearDropdownList()}clearRuleLines(){this.canvas.clearRuleLines()}doMessageEvent(t,i){this.store.messageEvents[t]&&this.store.messageEvents[t].forEach(s=>{let r=!1;s.event.conditions&&s.event.conditions.length?s.event.conditionType==="and"?r=s.event.conditions.every(a=>this.judgeCondition(s.pen,a.key,a)):s.event.conditionType==="or"&&(r=s.event.conditions.some(a=>this.judgeCondition(s.pen,a.key,a))):r=!0,r&&s.event.actions.forEach(a=>{a.timeout?setTimeout(()=>{this.events[a.action](s.pen,a,i)},a.timeout):this.events[a.action](s.pen,a,i)})})}initGlobalTriggers(){var t;this.store.globalTriggers={},(t=this.store.data.triggers)==null||t.forEach(i=>{i.conditions.forEach(s=>{s.source&&(this.store.globalTriggers[s.source]||(this.store.globalTriggers[s.source]=[]),this.store.globalTriggers[s.source].includes(i)||this.store.globalTriggers[s.source].push(i))})})}initMessageEvents(){this.store.messageEvents={},this.store.data.pens.forEach(t=>{var i;(i=t.events)==null||i.forEach(s=>{s.name==="message"&&s.message&&(this.store.messageEvents[s.message]||(this.store.messageEvents[s.message]=[]),this.store.messageEvents[s.message].push({pen:t,event:s}))})})}dataJudegeCondition(t,i,s){const{type:r,target:a,fnJs:o,fn:l,operator:n,valueType:h}=s;let c=!1;if(r==="fn"){if(l)c=l(t,{meta2d:this});else if(o){try{s.fn=It(this.store.options,"data","context",o)}catch(f){console.error("Error: make function:",f)}s.fn&&(c=s.fn(t,{meta2d:this}))}}else{let f=s.value;h==="prop"&&(f=t[s.value]);let u=t[i];switch(n){case">":c=u>+f;break;case">=":c=u>=+f;break;case"<":c=u<+f;break;case"<=":c=u<=+f;break;case"=":case"==":c=u==f;break;case"!=":c=u!=f;break;case"[)":c=Re(+u,f);break;case"![)":c=!Re(+u,f);break;case"[]":c=Te(u,f);break;case"![]":c=!Te(u,f);break}}return c}judgeCondition(t,i,s){const{type:r,target:a,fnJs:o,fn:l,operator:n,valueType:h}=s;let c=!1;if(r==="fn"){if(l)c=l(t,{meta2d:this});else if(o){try{s.fn=It(this.store.options,"pen","context",o)}catch(f){console.error("Error: make function:",f)}s.fn&&(c=s.fn(t,{meta2d:this}))}}else{let f=s.value;h==="prop"&&(f=this.store.pens[a][s.value]);let u=Et(t,i);switch(["x","y","width","height"].includes(i)&&(u=this.getPenRect(t)[i]),n){case">":c=u>+f;break;case">=":c=u>=+f;break;case"<":c=u<+f;break;case"<=":c=u<=+f;break;case"=":case"==":c=u==f;break;case"!=":c=u!=f;break;case"[)":c=Re(+u,f);break;case"![)":c=!Re(+u,f);break;case"[]":c=Te(u,f);break;case"![]":c=!Te(u,f);break}}return c}pushChildren(t,i){const s=[K(t,!0)],r=[];t.children||(t.children=[]);const a=[];i.forEach(l=>{let n=K(l,!0);if((!l.id||!this.store.pens[l.id])&&(this.canvas.makePen(l),n=null),l.parentId){const c=this.store.pens[l.parentId],f=c.children.findIndex(u=>u===l.id);s.push(K(c,!0)),c.children.splice(f,1),a.push(K(c,!0))}t.children.push(l.id),l.parentId=t.id;const h=ce(l.calculative.worldRect,t.calculative.worldRect);Object.assign(l,h),l.locked=l.lockedOnCombine??ct.DisableMove,l.locked=l.interaction||Di.includes(l.name)?0:l.locked,n?(s.push(n),a.push(K(l,!0))):r.push(K(l,!0))}),a.push(K(t,!0));let o=1;r.length&&(o=2,this.pushHistory({type:rt.Add,pens:r,step:o})),this.pushHistory({type:rt.Update,initPens:s,pens:a,step:o})}toPng(t,i,s=!1,r){return this.canvas.toPng(t,i,s,r)}activeToPng(t,i){return this.canvas.activeToPng(t,i)}pensToPng(t=this.store.active,i,s){return this.canvas.pensToPng(t,i,s)}downloadPng(t,i,s){var r;for(const a of this.store.data.pens)(a.calculative.img||["iframe"].includes(a.name))&&((r=a.onRenderPenRaw)==null||r.call(a,a));setTimeout(()=>{const a=document.createElement("a");a.setAttribute("download",(t||this.store.data.name||"le5le.meta2d")+".png"),a.setAttribute("href",this.toPng(i,void 0,!0,s));const o=document.createEvent("MouseEvents");o.initEvent("click",!0,!0),a.dispatchEvent(o)},1e3)}downloadSvg(t){if(!window.C2S)throw console.error("请先加载乐吾乐官网下的canvas2svg.js","https://assets.le5lecdn.com/2d/canvas2svg.js"),new Error("请先加载乐吾乐官网下的canvas2svg.js");let i=!1;const s=this.store.data.width||this.store.options.width,r=this.store.data.height||this.store.options.height;s&&r&&!this.store.data.component&&(i=!0);const a=this.getRect();i&&(a.x=this.store.data.origin.x,a.y=this.store.data.origin.y,a.width=s*this.store.data.scale,a.height=r*this.store.data.scale),a.x-=10,a.y-=10;const o=new window.C2S(a.width+20,a.height+20);o.textBaseline="middle",o.strokeStyle=this.store.styles.color;const l=this.store.options.downloadBgTransparent?void 0:this.store.data.background||this.store.styles.background;l&&i&&(o.save(),o.fillStyle=l,o.fillRect(0,0,a.width,a.height),o.restore()),this.store.bkImg&&i&&o.drawImage(this.store.bkImg,0,0,a.width,a.height),l&&!i&&(o.save(),o.fillStyle=l,o.fillRect(0,0,a.width+20,a.height+20),o.restore());for(const v of this.store.data.pens)v.visible==!1||!Ti(v,this.store)||Ri(o,v,a,!0);let n=o.getSerializedSvg();t!=null&&t.length&&(n=n.replace("<defs/>",`<defs>
|
|
93
|
+
<style type="text/css">
|
|
94
|
+
${t.join(`
|
|
95
|
+
`)}
|
|
96
|
+
</style>
|
|
97
|
+
{{bk}}
|
|
98
|
+
</defs>
|
|
99
|
+
{{bkRect}}`)),l?(n=n.replace("{{bk}}",""),n=n.replace("{{bkRect}}",`<rect x="0" y="0" width="100%" height="100%" fill="${l}"></rect>`)):(n=n.replace("{{bk}}",""),n=n.replace("{{bkRect}}","")),n=n.replace(/--le5le--/g,"&#x");const h=window.URL,c=new Blob([n]),f=h.createObjectURL(c),u=document.createElement("a");u.setAttribute("download",`${this.store.data.name||"le5le.meta2d"}.svg`),u.setAttribute("href",f);const d=document.createEvent("MouseEvents");d.initEvent("click",!0,!0),u.dispatchEvent(d)}getRect(t=this.store.data.pens){return Vt(t)}hiddenTemplate(){this.canvas.canvasTemplate.hidden()}showTemplate(){this.canvas.canvasTemplate.show()}lockTemplate(t){this.store.data.pens.forEach(i=>{i.canvasLayer===ht.CanvasTemplate&&(i.locked=t)})}fitView(t=!0,i=10,s=!0){var u,d;if(!this.hasView())return;const{canvas:r}=this.canvas,{offsetWidth:a,offsetHeight:o}=r;this.resize(a,o);const l=Zt(i),n=this.getRect(),h=(a-l[1]-l[3])/n.width,c=(o-l[0]-l[2])/n.height;let f=h;t?f=h>c?c:h:f=h>c?h:c,s&&((u=this.store.data.fits)!=null&&u.length)&&(this.canvas.opening=!0),this.scale(f*this.store.data.scale),this.centerView(),s&&((d=this.store.data.fits)!=null&&d.length)&&this.fillView()}fillView(){var h,c,f,u;if(this.store.options.unFill)return;let t={x:this.store.data.origin.x,y:this.store.data.origin.y,width:this.store.data.width*this.store.data.scale,height:this.store.data.height*this.store.data.scale};(isNaN(t.width)||isNaN(t.height))&&(t=this.getRect());const i=new Set;(h=this.store.data.fits)==null||h.forEach(d=>{var v;(v=d.children)==null||v.forEach(g=>i.add(g))});const s=(d,v,g)=>{var y;!d||d.name!=="tablePlus"||g!=null&&g.has(d.id)||(g==null||g.add(d.id),d.colWidth=(d.colWidth??150)*v,(y=d.styles)==null||y.forEach(p=>{p.width&&(p.width*=v)}))},r=(d,v,g)=>{var y;s(d,v,g),(y=d.children)!=null&&y.length&&Pt(d,this.store).forEach(p=>{s(p,v,g)})},{origin:a,scale:o}=this.store.data;if(this.fillViewSnapshot)this.fillViewSnapshot.forEach((d,v)=>{var y,p,b,m;const g=this.store.pens[v];g&&(d.colWidth!==void 0&&(g.colWidth=d.colWidth),d.styleWidths&&((y=g.styles)==null||y.forEach((k,A)=>{d.styleWidths[A]!==void 0&&(k.width=d.styleWidths[A])})),!d.onlyTablePlus&&(g.x=a.x+d.x*o,g.y=a.y+d.y*o,g.width=d.width*o,g.height=d.height*o,d.textWidth!==void 0&&(g.textWidth=d.textWidth*o),d.imageRatio!==void 0&&(g.imageRatio=d.imageRatio),d.ratio!==void 0&&(g.ratio=d.ratio),g.name==="iframe"&&d.operationalRect&&(g.operationalRect=K(d.operationalRect),(p=g.onBeforeValue)==null||p.call(g,g,{operationalRect:g.operationalRect})),this.canvas.updatePenRect(g,{worldRectIsReady:!1}),g.externElement&&((b=g.onResize)==null||b.call(g,g)),(m=g.children)!=null&&m.length&&Pt(g,this.store).forEach(k=>{var A;k.externElement&&((A=k.onResize)==null||A.call(k,k))})))});else{this.fillViewSnapshot=new Map;const d=(v,g=!1)=>{var p;const y=v.calculative.worldRect;this.fillViewSnapshot.set(v.id,{onlyTablePlus:g,x:g?void 0:(y.x-a.x)/o,y:g?void 0:(y.y-a.y)/o,width:g?void 0:y.width/o,height:g?void 0:y.height/o,textWidth:!g&&v.textWidth!=null?v.textWidth/o:void 0,colWidth:v.name==="tablePlus"?v.colWidth:void 0,styleWidths:v.name==="tablePlus"?(p=v.styles)==null?void 0:p.map(b=>b.width):void 0,imageRatio:g?void 0:v.imageRatio,ratio:g?void 0:v.ratio,operationalRect:!g&&v.name==="iframe"&&v.operationalRect?K(v.operationalRect):void 0})};(c=this.store.data.fits)==null||c.forEach(v=>{v.children.forEach(g=>{var p;const y=this.store.pens[g];y&&(d(y),(p=y.children)!=null&&p.length&&Pt(y,this.store).forEach(b=>{b.name==="tablePlus"&&!this.fillViewSnapshot.has(b.id)&&d(b,!0)}))})}),this.store.data.pens.filter(v=>v.name==="iframe").forEach(v=>d(v))}const l=this.canvas.width-t.width,n=this.canvas.height-t.height;if(Math.abs(l)>10){(f=this.store.data.fits)==null||f.forEach(g=>{let y=[];g.children.forEach(b=>{this.store.pens[b]&&(this.store.pens[b].locked=ct.None,y.push(this.store.pens[b]))});let p=l/2;if(g.left&&g.right){let b=g.leftValue,m=g.rightValue;b?b=Math.abs(b)<1?b*t.width:b:b=0,m?m=Math.abs(m)<1?m*t.width:m:m=0;let k=(this.canvas.width-b-m)/(t.width-b-m);const A=new Set;y.forEach(S=>{var I,E;S.image&&S.imageRatio&&S.calculative.worldRect.width/this.canvas.width>.1&&(S.imageRatio=!1,S.ratio=!1),r(S,k,A),Math.abs(g.leftValue)<1?S.calculative.worldRect.x=t.x-l/2+b+(S.calculative.worldRect.x-t.x-b)*k:S.calculative.worldRect.x=t.x-l/2+b+(S.calculative.worldRect.x-t.x)*k,S.calculative.worldRect.width*=k,S.calculative.worldRect.ex=S.calculative.worldRect.x+S.calculative.worldRect.width,S.calculative.width=S.calculative.worldRect.width,S.calculative.x=S.calculative.worldRect.x,S.width=S.calculative.worldRect.width,S.x=S.calculative.worldRect.x,S.textWidth*=k,S.calculative.textWidth*=k,this.canvas.updatePenRect(S,{worldRectIsReady:!1}),S.externElement&&((I=S.onResize)==null||I.call(S,S)),(E=S.children)!=null&&E.length&&Pt(S,this.store).forEach(U=>{var T;U.externElement&&((T=U.onResize)==null||T.call(U,U))})})}else g.left?(p=-p,g.leftValue&&(p+=Math.abs(g.leftValue)<1?g.leftValue*this.canvas.width:g.leftValue),this.translatePens(y,p,0)):g.right&&(g.rightValue&&(p=p-(Math.abs(g.rightValue)<1?g.rightValue*this.canvas.width:g.rightValue)),this.translatePens(y,p,0))});const d=this.store.data.pens.filter(g=>g.name==="iframe"&&!i.has(g.id));d==null||d.forEach(g=>{var p,b;const y=g.calculative.worldRect;if(y.width/t.width>.8){let m=y.width;g.calculative.worldRect.x=y.x-l/2,g.calculative.worldRect.width=y.width+l,g.calculative.worldRect.ex=y.ex+l,g.operationalRect&&(g.operationalRect.x=g.operationalRect.x*m/g.calculative.worldRect.width,g.operationalRect.width=(g.calculative.worldRect.width-(1-g.operationalRect.width)*m)/g.calculative.worldRect.width,(p=g.onBeforeValue)==null||p.call(g,g,{operationalRect:g.operationalRect})),(b=g.onResize)==null||b.call(g,g)}});const v=this.store.data.pens.filter(g=>g.name==="video");v==null||v.forEach(g=>{var p;const y=g.calculative.worldRect;y.width/this.canvas.width>.8&&(g.calculative.worldRect.x=y.x-l/2,g.calculative.worldRect.width=y.width+l,g.calculative.worldRect.ex=y.ex+l,(p=g.onResize)==null||p.call(g,g))})}if(Math.abs(n)>10){(u=this.store.data.fits)==null||u.forEach(g=>{let y=[];g.children.forEach(b=>{this.store.pens[b]&&(this.store.pens[b].locked=ct.None,y.push(this.store.pens[b]))});let p=n/2;if(g.top&&g.bottom){let b=g.topValue,m=g.bottomValue;b?b=Math.abs(b)<1?b*this.canvas.height:b:b=0,m?m=Math.abs(m)<1?m*this.canvas.height:m:m=0;let k=(this.canvas.height-b-m)/t.height;y.forEach(A=>{var S,I;A.image&&A.imageRatio&&A.calculative.worldRect.height/this.canvas.height>.1&&(A.imageRatio=!1,A.ratio=!1),A.calculative.worldRect.y=t.y-n/2+b+(A.calculative.worldRect.y-t.y)*k,A.calculative.worldRect.height*=k,A.calculative.worldRect.ey=A.calculative.worldRect.y+A.calculative.worldRect.height,A.calculative.height=A.calculative.worldRect.height,A.calculative.y=A.calculative.worldRect.y,A.height=A.calculative.worldRect.height,A.y=A.calculative.worldRect.y,this.canvas.updatePenRect(A,{worldRectIsReady:!1}),A.externElement&&((S=A.onResize)==null||S.call(A,A)),(I=A.children)!=null&&I.length&&Pt(A,this.store).forEach(z=>{var U;z.externElement&&((U=z.onResize)==null||U.call(z,z))})})}else g.top?(p=-p,g.topValue&&(p+=Math.abs(g.topValue)<1?g.topValue*this.canvas.height:g.topValue),this.translatePens(y,0,p)):g.bottom&&(g.bottomValue&&(p=p-(Math.abs(g.bottomValue)<1?g.bottomValue*this.canvas.height:g.bottomValue)),this.translatePens(y,0,p))});const d=this.store.data.pens.filter(g=>g.name==="iframe"&&!i.has(g.id));d==null||d.forEach(g=>{var p,b;const y=g.calculative.worldRect;if(y.height/t.height>.8){let m=y.height;g.calculative.worldRect.y=y.y-n/2,g.calculative.worldRect.height=y.height+n,g.calculative.worldRect.ey=y.ey+n,g.operationalRect&&(g.operationalRect.y=g.operationalRect.y*m/g.calculative.worldRect.width,g.operationalRect.height=(g.calculative.worldRect.height-(1-g.operationalRect.height)*m)/g.calculative.worldRect.height,(p=g.onBeforeValue)==null||p.call(g,g,{operationalRect:g.operationalRect})),(b=g.onResize)==null||b.call(g,g)}});const v=this.store.data.pens.filter(g=>g.name==="video");v==null||v.forEach(g=>{var p;const y=g.calculative.worldRect;y.height/this.canvas.height>.8&&(g.calculative.worldRect.y=y.y-n/2,g.calculative.worldRect.height=y.height+n,g.calculative.worldRect.ey=y.ey+n,(p=g.onResize)==null||p.call(g,g))})}this.canvas.canvasTemplate.fit=!0,this.canvas.canvasTemplate.init(),this.canvas.canvasImage.init(),this.canvas.canvasImageBottom.init(),this.render(!0)}scaleView(){const t=window.innerWidth/window.innerHeight,i=this.getRect(),s=i.width/i.height;if(Math.abs(t-s)<.001)return;let r;t>s?r=`scale(${t/s},1)`:r=`scale(1,${s/t})`,this.canvas.parentElement.style.transform=r}setFits(){if(!this.store.data.fits){const t=this.store.data.pens.filter(i=>!i.parentId).map(i=>i.id);this.store.data.fits=[{bottom:!0,bottomValue:0,left:!0,leftValue:0,right:!0,rightValue:0,top:!0,topValue:0,x:0,y:0,height:1,width:1,children:t}]}}trimPens(){let t=this.store.data.pens.filter(i=>i.name==="line"&&i.anchors.length<2);this.delete(t)}fitTemplateView(t=!0,i=10){if(!this.hasView())return;const{canvas:s}=this.canvas,{offsetWidth:r,offsetHeight:a}=s,o=Zt(i),l=this.getRect(),n=(r-o[1]-o[3])/l.width,h=(a-o[0]-o[2])/l.height;let c=n;t?c=n>h?h:n:c=n>h?n:h,this.canvas.templateScale(c*this.store.data.scale);let f=this.getRect(),u=this.store.data.pens.filter(d=>!d.parentId);this.canvas.templateTranslatePens(u,-f.x,-f.y),this.store.data.pens.forEach(d=>{d.type?this.canvas.initLineRect(d):this.canvas.updateLines(d)}),this.centerView()}fitSizeView(t=!0,i=10,s=!0){var d,v;const{canvas:r}=this.canvas,{offsetWidth:a,offsetHeight:o}=r;this.resize(a,o);const l=Zt(i),n=(this.store.data.width||this.store.options.width)*this.store.data.scale,h=(this.store.data.height||this.store.options.height)*this.store.data.scale,c=(a-l[1]-l[3])/n,f=(o-l[0]-l[2])/h;let u=c;t==="width"?u=c:t==="height"?u=f:t?u=c>f?f:c:u=c>f?c:f,s&&((d=this.store.data.fits)!=null&&d.length)&&(this.canvas.opening=!0),this.scale(u*this.store.data.scale),this.centerSizeView(),s&&((v=this.store.data.fits)!=null&&v.length)&&this.fillView()}centerSizeView(){const t=this.getViewCenter(),i=this.store.data.width||this.store.options.width,s=this.store.data.height||this.store.options.height,r={x:0,y:0,width:i,height:s};yt(r);const{center:a}=r,{scale:o,origin:l,x:n,y:h}=this.store.data;this.translate((t.x-l.x)/o-a.x-n/o,(t.y-l.y)/o-a.y-h/o);const{canvas:c}=this.canvas,f=(c.scrollWidth-c.offsetWidth)/2,u=(c.scrollHeight-c.offsetHeight)/2;c.scrollTo(f,u)}scrollView(t=10,i=!1){if(!this.hasView()||!this.canvas.scroll)return;const{canvas:s}=this.canvas,{offsetWidth:r,offsetHeight:a}=s;this.resize(r,a);const o=Zt(t);let l=null;const n=this.store.data.width||this.store.options.width,h=this.store.data.height||this.store.options.height;n&&h?l={width:n*this.store.data.scale,height:h*this.store.data.scale}:l=this.getRect();const c=(r-o[1]-o[3])/l.width;this.scale(c*this.store.data.scale),this.topView(o[0]),i&&this.canvas.scroll.changeMode(o[0])}screenView(t=10,i=!0){if(!this.hasView())return;const{canvas:s}=this.canvas,{offsetWidth:r,offsetHeight:a}=s;this.resize(r,a);const o=Zt(t),l=this.getRect();let n=(r-o[1]-o[3])/l.width;i||(n=(a-o[0]-o[2])/l.height),this.scale(n*this.store.data.scale),this.topView(o[0])}topView(t=10){if(!this.hasView())return;const i=this.getRect(),s=this.getViewCenter(),r=this.store.data.width||this.store.options.width,a=this.store.data.height||this.store.options.height;let o=null;r&&a?o={x:0,y:0,width:r,height:a}:o=this.getPenRect(i),yt(o);const{center:l}=o,{scale:n,origin:h,x:c,y:f}=this.store.data;this.translate((s.x-h.x)/n-l.x-c/n,(t-h.y)/n-o.y-f/n);const{canvas:u}=this.canvas,d=(u.scrollWidth-u.offsetWidth)/2,v=(u.scrollHeight-u.offsetHeight)/2;u.scrollTo(d,v)}centerView(){if(!this.hasView())return;const t=this.getRect(),i=this.getViewCenter(),s=this.getPenRect(t);yt(s);const{center:r}=s,{scale:a,origin:o,x:l,y:n}=this.store.data;this.translate((i.x-o.x)/a-r.x-l/a,(i.y-o.y)/a-r.y-n/a);const{canvas:h}=this.canvas,c=(h.scrollWidth-h.offsetWidth)/2,f=(h.scrollHeight-h.offsetHeight)/2;h.scrollTo(c,f)}hasView(){return!!this.store.data.pens.filter(t=>!t.isRuleLine).length}getViewCenter(){const{width:t,height:i}=this.canvas;return{x:t/2,y:i/2}}beSameByFirst(t=this.store.data.pens,i){const s=K(t),r=t[0],{width:a,height:o}=this.getPenRect(r);for(let l=1;l<t.length;l++){const n=t[l];i==="width"?this.setValue({id:n.id,width:a},{render:!1,doEvent:!1}):i==="height"?this.setValue({id:n.id,height:o},{render:!1,doEvent:!1}):this.setValue({id:n.id,width:a,height:o},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:rt.Update,initPens:s,pens:t})}beSameByLast(t=this.store.data.pens,i){const s=K(t),r=t[t.length-1],{width:a,height:o}=this.getPenRect(r);for(let l=0;l<t.length-1;l++){const n=t[l];i==="width"?this.setValue({id:n.id,width:a},{render:!1,doEvent:!1}):i==="height"?this.setValue({id:n.id,height:o},{render:!1,doEvent:!1}):this.setValue({id:n.id,width:a,height:o},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:rt.Update,initPens:s,pens:t})}formatPainterByFirst(t=this.store.data.pens){const i=K(t),s=t[0],r={};Fe.forEach(a=>{r[a]=s[a]});for(let a=1;a<t.length;a++){const o=t[a];this.setValue({id:o.id,...Oi,...r},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:rt.Update,initPens:i,pens:t})}formatPainterByLast(t=this.store.data.pens){const i=K(t),s=t[t.length-1],r={};Fe.forEach(a=>{r[a]=s[a]});for(let a=0;a<t.length-1;a++){const o=t[a];this.setValue({id:o.id,...Oi,...r},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:rt.Update,initPens:i,pens:t})}setFormatPainter(){const t=this.store.active,i={};if(t.length>0){const s=t[0];Fe.forEach(r=>{i[r]=s[r]!==void 0?s[r]:this.store.options.defaultFormat[r]||this.store.data[r]||this.store.options[r]})}else Fe.forEach(s=>{this.store.options.defaultFormat[s]||this.store.data[s]||this.store.options[s]});localStorage.setItem("meta2d-formatPainter",JSON.stringify(i))}formatPainter(){const t=this.store.active,i=K(t),s=JSON.parse(localStorage.getItem("meta2d-formatPainter"));for(let r=0;r<t.length;r++){const a=t[r];this.setValue({id:a.id,...Oi,...s},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:rt.Update,initPens:i,pens:t})}clearFormatPainter(){const t=this.store.active,i=K(t);Fe.forEach(s=>{for(let r=0;r<t.length;r++){const a=t[r],{fontSize:o,lineHeight:l}=this.store.options;s==="lineWidth"?(a.lineWidth=1,a.calculative.lineWidth=1):s==="fontSize"?(a.fontSize=o,a.calculative.fontSize=o):s==="lineHeight"?(a.lineHeight=l,a.calculative.lineHeight=l):(delete a[s],delete a.calculative[s])}}),this.render(),this.pushHistory({type:rt.Update,initPens:i,pens:t})}alignNodes(t,i=this.store.data.pens,s){!s&&(s=this.getPenRect(this.getRect(i)));const r=K(i);for(const a of i)this.alignPen(t,a,s);this.initImageCanvas(i),this.initTemplateCanvas(i),this.render(),this.pushHistory({type:rt.Update,initPens:r,pens:i})}alignNodesV(t,i=this.store.data.pens,s=!1){const r=this.store.data.width||this.store.options.width,a=this.store.data.height||this.store.options.height;let o={x:0,y:0,width:r,height:a};const l=K(i);if(s){const n=this.store.data.scale,h=this.getRect(i),c=(h.x-this.store.data.origin.x)/n,f=(h.y-this.store.data.origin.y)/n,u=h.width/n,d=h.height/n;let v=0,g=0;switch(t){case"left":v=-c;break;case"right":v=r-(c+u);break;case"top":g=-f;break;case"bottom":g=a-(f+d);break;case"center":v=r/2-(c+u/2);break;case"middle":g=a/2-(f+d/2);break}this.translatePens(i,v*n,g*n)}else for(const n of i)this.alignPen(t,n,o);this.initImageCanvas(i),this.initTemplateCanvas(i),this.render(),this.pushHistory({type:rt.Update,initPens:l,pens:i})}alignNodesByFirst(t,i=this.store.data.pens){const s=K(i),r=i[0],a=this.getPenRect(r);for(let o=1;o<i.length;o++){const l=i[o];this.alignPen(t,l,a)}this.initImageCanvas(i),this.initTemplateCanvas(i),this.render(),this.pushHistory({type:rt.Update,initPens:s,pens:i})}alignNodesByLast(t,i=this.store.data.pens){const s=K(i),r=i[i.length-1],a=this.getPenRect(r);for(let o=0;o<i.length-1;o++){const l=i[o];this.alignPen(t,l,a)}this.initImageCanvas(i),this.initTemplateCanvas(i),this.render(),this.pushHistory({type:rt.Update,initPens:s,pens:i})}alignPen(t,i,s){const r=this.getPenRect(i);switch(t){case"left":r.x=s.x;break;case"right":r.x=s.x+s.width-r.width;break;case"top":r.y=s.y;break;case"bottom":r.y=s.y+s.height-r.height;break;case"center":r.x=s.x+s.width/2-r.width/2;break;case"middle":r.y=s.y+s.height/2-r.height/2;break}this.setValue({id:i.id,...r},{render:!1,doEvent:!1})}spaceBetweenByDirection(t,i=this.store.data.pens,s){if(!s){let h=1/0,c=-1/0,f=t==="width"?"x":"y";i.forEach(u=>{h=Math.min(h,u.calculative.worldRect[f]),c=Math.max(c,u.calculative.worldRect["e"+f])}),s=(c-h)/this.store.data.scale}if(i=i.filter(h=>!h.parentId),i.length<=2)return;const r=K(i),a=i.reduce((h,c)=>{const f=this.getPenRect(c);return h+f[t]},0),o=(s-a)/(i.length-1);i=i.sort((h,c)=>t==="width"?h.x-c.x:h.y-c.y);const l=this.getPenRect(i[0]);let n=t==="width"?l.x:l.y;for(const h of i){const c=this.getPenRect(h);t==="width"?c.x=n:c.y=n,n+=c[t]+o,this.setValue({id:h.id,...c},{render:!1,doEvent:!1})}this.initImageCanvas(i),this.initTemplateCanvas(i),this.render(),this.pushHistory({type:rt.Update,initPens:r,pens:i})}spaceBetween(t,i){this.spaceBetweenByDirection("width",t,i)}spaceBetweenColumn(t,i){this.spaceBetweenByDirection("height",t,i)}layout(t=this.store.data.pens,i,s=30){const r=this.getPenRect(Vt(t));!i&&(i=r.width),t=t.filter(h=>!h.type&&!h.parentId);const a=K(t);let o=0;t.forEach(h=>{const c=this.getPenRect(h);c.height>o&&(o=c.height)});let l=r.x,n=r.y;t.forEach((h,c)=>{const f=this.getPenRect(h);if(f.x=l,f.y=n+o/2-f.height/2,this.setValue({id:h.id,...f},{render:!1,doEvent:!1}),c===t.length-1)return;const u=l+f.width-r.x,d=this.getPenRect(t[c+1]);Math.round(i-u)>=Math.round(d.width+s)?l+=f.width+s:(l=r.x,n+=o+s)}),this.initImageCanvas(t),this.initTemplateCanvas(t),this.render(),this.pushHistory({type:rt.Update,initPens:a,pens:t})}gotoView(t){var a;const i=this.getViewCenter(),s=i.x-t.calculative.worldRect.x-t.calculative.worldRect.width/2,r=i.y-t.calculative.worldRect.y-t.calculative.worldRect.height/2;this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.translate(s-this.store.data.x,r-this.store.data.y),this.store.data.x=s,this.store.data.y=r;for(const o of this.store.data.pens)Xt(o),(a=o.onMove)==null||a.call(o,o);this.canvas.canvasTemplate.init(),this.canvas.canvasImage.init(),this.canvas.canvasImageBottom.init(),this.render()}animateView(t){this.canvas.animateView(t)}showMap(){this.map||(this.map=new hc(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&&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){t||(t=this.store.active),Array.isArray(t)||(t=[t]);for(const i of t){const s=this.store.data.pens,r=[...Pt(i,this.store),i].map(o=>o.id);s.filter(o=>r.includes(o.id)).forEach(o=>{const l=s.findIndex(n=>n.id===o.id);l>-1&&(s.push(s[l]),s.splice(l,1),this.initTemplateCanvas([o]),this.initImageCanvas([o])),this.specificLayerMove(o,"top")})}this.store.emitter.emit("layer",{type:"top",pens:t})}initImageCanvas(t){this.canvas&&this.canvas.initImageCanvas(t)}initTemplateCanvas(t){this.canvas&&this.canvas.initTemplateCanvas(t)}bottom(t){t||(t=this.store.active),Array.isArray(t)||(t=[t]);for(const i of t){const s=this.store.data.pens,r=[...Pt(i,this.store),i].map(o=>o.id),a=s.filter(o=>r.includes(o.id));for(let o=a.length-1;o>=0;o--){const l=a[o],n=s.findIndex(h=>h.id===l.id);n>-1&&(s.unshift(s[n]),s.splice(n+1,1),this.initTemplateCanvas([l]),this.initImageCanvas([l])),this.specificLayerMove(l,"bottom")}}this.store.emitter.emit("layer",{type:"bottom",pens:t})}upByArea(t){if(this.store.data.pens.findIndex(n=>n.id===t.id)===-1){console.warn("upByArea: pen not in canvas");return}const s=[t,...Pt(t,this.store)];let r=s.map(n=>this.store.data.pens.findIndex(h=>h.id===n.id));r.includes(-1)&&(console.warn("upByArea: pen children not in canvas"),r=r.filter(n=>n!==-1));const a=Math.min(...r),o=t.calculative.worldRect,l=this.store.data.pens.findIndex((n,h)=>{if(h<=a||n.id===t.id||Za(n,t))return!1;const c=n.calculative.worldRect;return ee(o,c)});if(l===-1){this.up(t);return}this.store.data.pens.splice(l+1,0,...s);for(const n of s){const h=this.store.data.pens.findIndex(c=>c.id===n.id);h>-1&&this.store.data.pens.splice(h,1)}this.initImageCanvas([t])}specificLayerMove(t,i){var s;if(t.image&&t.name!=="gif"){let r=ht.CanvasImageBottom;i==="top"?r=ht.CanvasImage:(i==="up"||i==="down")&&(r=ht.CanvasMain),this.setValue({id:t.id,canvasLayer:r},{render:!1,doEvent:!1,history:!1})}else if(t.name.endsWith("Dom")||$i.includes(t.name)||this.store.options.domShapes.includes(t.name)||t.externElement||t.name==="gif"){let r=0;i==="top"?(t.calculative.canvas.maxZindex+=1,r=t.calculative.canvas.maxZindex):i==="up"?r=t.calculative.zIndex===void 0?6:t.calculative.zIndex+1:i==="down"&&(r=t.calculative.zIndex===void 0?3:t.calculative.zIndex-1,r<0&&(r=0)),this.setValue({id:t.id,zIndex:r},{render:!1,doEvent:!1,history:!1}),(s=t.calculative.singleton)!=null&&s.div&&Ct(t,t.calculative.singleton.div)}}up(t){t||(t=this.store.active),Array.isArray(t)||(t=[t]);for(const i of t){const s=this.store.data.pens;if(i.children&&i.children.length){const r=[...Pt(i,this.store),i],a=[];for(let n=0;n<s.length;n++){const h=s[n];r.findIndex(c=>c.id===h.id)!==-1&&(h.temIndex=n,a.push(h))}let o=-1,l=0;a.forEach(n=>{n.temIndex-=l,s.splice(n.temIndex,1),l+=1,o=n.temIndex,delete n.temIndex,this.specificLayerMove(n,"up")}),s.splice(o+1,0,...a),this.initTemplateCanvas(a),this.initImageCanvas(a)}else{const r=s.findIndex(a=>a.id===i.id);r>-1&&r!==s.length-1&&(s.splice(r+2,0,s[r]),s.splice(r,1),this.initTemplateCanvas([i]),this.initImageCanvas([i])),this.specificLayerMove(i,"up")}}this.store.emitter.emit("layer",{type:"up",pens:t})}down(t){t||(t=this.store.active),Array.isArray(t)||(t=[t]);for(const i of t){const s=this.store.data.pens;if(i.children&&i.children.length){const r=[...Pt(i,this.store),i],a=[];for(let n=0;n<s.length;n++){const h=s[n];r.findIndex(c=>c.id===h.id)!==-1&&(h.temIndex=n,a.push(h))}let o=-1,l=0;a.forEach((n,h)=>{n.temIndex-=l,s.splice(n.temIndex,1),l+=1,h===0&&(o=n.temIndex),delete n.temIndex,this.specificLayerMove(n,"down")}),s.splice(o-1,0,...a),this.initTemplateCanvas(a),this.initImageCanvas(a)}else{const r=s.findIndex(a=>a.id===i.id);r>-1&&r!==0&&(s.splice(r-1,0,s[r]),s.splice(r+1,1),this.initTemplateCanvas([i]),this.initImageCanvas([i])),this.specificLayerMove(i,"down")}}this.store.emitter.emit("layer",{type:"down",pens:t})}setLayer(t,i,s=this.store.data.pens){const r=s.findIndex(a=>a.id===t.id);r>-1&&(r>i?(s.splice(i,0,s[r]),s.splice(r+1,1)):r<i&&(s.splice(i,0,s[r]),s.splice(r,1))),this.initTemplateCanvas([t]),this.initImageCanvas([t])}changePenId(t,i){this.canvas.changePenId(t,i)}getLines(t,i="all"){var r;if(t.type===ut.Line)return[];const s=[];return(r=t.connectedLines)==null||r.forEach(({lineId:a})=>{const o=this.store.pens[a];if(!o){console.warn(t,"node contain a error connectedLine");return}if(!s.find(l=>l.id===o.id))switch(i){case"all":s.push(o);break;case"in":dt(o).connectTo===t.id&&s.push(o);break;case"out":xt(o).connectTo===t.id&&s.push(o);break}}),s}nextNode(t){if(t.type===ut.Line){const i=this.store.pens[dt(t).connectTo];return i?[i]:[]}else{const i=this.getLines(t,"out"),s=[];return i.forEach(r=>{const a=this.nextNode(r);for(const o of a)!s.find(n=>n.id===o.id)&&s.push(o)}),s}}previousNode(t){if(t.type===ut.Line){const i=this.store.pens[xt(t).connectTo];return i?[i]:[]}else{const i=this.getLines(t,"in"),s=[];return i.forEach(r=>{const a=this.previousNode(r);for(const o of a)!s.find(n=>n.id===o.id)&&s.push(o)}),s}}getNext(t){var s;if(t.type===ut.Line){console.warn("非连线节点");return}const i=[];return(s=t.connectedLines)==null||s.forEach(({lineId:r,anchor:a})=>{var n,h;const o=(n=t.anchors)==null?void 0:n.filter(c=>c.id===a)[0],l=this.findOne(r);if(l.anchors[0].connectTo==t.id){const c=l.anchors[l.anchors.length-1].connectTo;if(c){const f=this.findOne(c),u=(h=f.connectedLines)==null?void 0:h.filter(v=>v.lineId===l.id)[0],d=f.anchors.filter(v=>v.id===u.anchor)[0];i.push({from:t,fromAnchor:o,line:l,to:f,toAnchor:d})}}}),i}addAnchor(t,i,s){if(!t)return;if(t.anchors||(t.anchors=[]),t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),t.type===ut.Line&&(s<0&&(s=t.anchors.length+1+s),s>t.anchors.length&&(s=t.anchors.length),s<0&&(s=0),s==0&&t.anchors[0].connectTo||s==t.anchors.length&&t.anchors[s-1].connectTo)){console.warn("端点存在连接关系");return}let r=null,a=null;i.x<=1&&i.x>=0&&i.y<=1&&i.y>=0?(a={id:i.id||lt(),penId:t.id,x:t.calculative.worldRect.x+t.calculative.worldRect.width*i.x,y:t.calculative.worldRect.y+t.calculative.worldRect.height*i.y},t.calculative.worldRect&&t.rotate%360&&vt(a,t.rotate,t.calculative.worldRect.center),r={id:a.id,penId:t.id,x:i.x,y:i.y}):(a={id:i.id||lt(),penId:t.id,x:i.x,y:i.y},t.calculative.worldRect&&(t.rotate%360&&vt(i,-t.rotate,t.calculative.worldRect.center),r={id:a.id,penId:t.id,x:(i.x-t.calculative.worldRect.x)/t.calculative.worldRect.width,y:(i.y-t.calculative.worldRect.y)/t.calculative.worldRect.height})),t.type===ut.Line?(t.calculative.worldAnchors.splice(s,0,a),t.anchors.splice(s,0,r),this.canvas.updateLines(t),this.canvas.initLineRect(t),this.render()):(t.calculative.worldAnchors.push(a),t.anchors.push(r))}connectLine(t,i,s,r,a=!0){if(!s){const h=i.calculative.worldRect;s=_e(t,{x:h.x+h.width/2,y:h.y+h.height/2})}if(!r){const h=t.calculative.worldRect;r=_e(i,{x:h.x+h.width/2,y:h.y+h.height/2})}const o=Math.abs(s.x-r.x),n={height:Math.abs(s.y-r.y),lineName:"line",lineWidth:1,name:"line",type:1,width:o,x:Math.min(s.x,r.x),y:Math.min(s.y,r.y),anchors:[{x:s.x>r.x?1:0,y:s.y>r.y?1:0,id:lt()},{x:s.x>r.x?0:1,y:s.x>r.x?0:1,id:lt()}]};return this.addPens([n]),Tt(t,s,n,n.calculative.worldAnchors[0]),Tt(i,r,n,n.calculative.worldAnchors[1]),n.calculative.active=!1,this.canvas.updateLines(n),this.canvas.updateLines(t),this.canvas.updateLines(i),this.canvas.initLineRect(n),a&&this.render(),n}toComponent(t=this.store.data.pens,i,s){if(t.length===1){const c=K(t[0]);return c.type=ut.Node,c.id=void 0,[c]}const r=K(t,!0),a=Vt(r);let o={id:lt(),name:"combine",...a,children:[],showChild:i};s&&(o.anchors=[{id:"0",penId:o.id,x:.5,y:0},{id:"1",penId:o.id,x:1,y:.5},{id:"2",penId:o.id,x:.5,y:1},{id:"3",penId:o.id,x:0,y:.5}]);const l=r.filter(c=>!c.parentId),n=r.find(c=>c.width===a.width&&c.height===a.height),h=n&&i===void 0;return l.length===1?o=l[0]:h&&(n.children||(n.children=[]),o=n),r.forEach(c=>{if(c===o||c.parentId===o.id||c.parentId)return;o.children.push(c.id),c.parentId=o.id;const f=ce(c.calculative.worldRect,a);Object.assign(c,f),c.locked=c.lockedOnCombine??ct.DisableMove}),h||l.length===1?K(r):K([o,...r])}installPenPlugins(t,i){if(!t.tag&&!t.name&&!t.id)return;let s;t.id?s="id":t.tag?s="tag":t.name&&(s="name"),i.forEach(r=>{let a=r.plugin,o=r.options;if(a&&Qo(a)&&s)if(a.install(t,o),!this.penPluginMap.has(a))this.penPluginMap.set(a,[{[s]:t[s],option:o}]);else{let l=this.penPluginMap.get(a).find(n=>n[s]===t[s]);l?l.option=o:this.penPluginMap.get(a).push({[s]:t[s],option:o})}})}uninstallPenPlugins(t,i){let s;t.id?s="id":t.tag?s="tag":t.name&&(s="name"),s&&i.forEach(r=>{let a=r.plugin;a.uninstall(t,r.options);let o=this.penPluginMap.get(a),l=o.findIndex(n=>n[s]===t[s]);l!==-1&&(o.splice(l,1),o.length===0&&this.penPluginMap.delete(a))})}setVisible(t,i,s=!0){if(this.onSizeUpdate(),this.setValue({id:t.id,visible:i},{render:!1,doEvent:!1}),t.children)for(const a of t.children){const o=this.store.pens[a];o&&this.setVisible(o,i,!1)}let r=Pt(t,this.store);r.push(t),this.initImageCanvas(r),s&&this.render()}clearHover(){this.canvas.clearHover()}closeSocket(){this.closeWebsocket(),this.closeMqtt(),this.closeHttp()}destroy(t){if(this.clear(!1),Zn(),this.stopDataMock(),this.closeSocket(),this.closeNetwork(),this.closeAll(),Ve.destroyThemeSheet(this.store.id),this.store.emitter.all.clear(),this.canvas.destroy(),this.canvas=void 0,it[this.store.id]=void 0,!t){for(const i in it)delete it[i];it.path2dDraws={},it.canvasDraws={},it.anchors={},it.htmlElements={},it.lineAnimateDraws={},it.gridDrawers={}}}}var oa={exports:{}};/*!!
|
|
100
|
+
* Canvas 2 Svg v1.0.15
|
|
101
|
+
* A low level canvas to SVG converter. Uses a mock canvas context to build an SVG document.
|
|
102
|
+
*
|
|
103
|
+
* Licensed under the MIT license:
|
|
104
|
+
* http://www.opensource.org/licenses/mit-license.php
|
|
105
|
+
*
|
|
106
|
+
* Author:
|
|
107
|
+
* Kerry Liu
|
|
108
|
+
*
|
|
109
|
+
* Copyright (c) 2014 Gliffy Inc.
|
|
110
|
+
*/(function(e){(function(){var t,i,s,r,a;function o(u,d){var v=Object.keys(d),g;for(g=0;g<v.length;g++)u=u.replace(new RegExp("\\{"+v[g]+"\\}","gi"),d[v[g]]);return u}function l(u){var d,v,g;if(!u)throw new Error("cannot create a random attribute name for an undefined object");d="ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",v="";do for(v="",g=0;g<12;g++)v+=d[Math.floor(Math.random()*d.length)];while(u[v]);return v}function n(u,d){var v,g,y={},p;for(u=u.split(","),d=d||10,v=0;v<u.length;v+=2)g="&"+u[v+1]+";",p=parseInt(u[v],d),y[g]="&#"+p+";";return y["\\xa0"]=" ",y}function h(u){var d={left:"start",right:"end",center:"middle",start:"start",end:"end"};return d[u]||d.start}function c(u){var d={alphabetic:"alphabetic",hanging:"hanging",top:"text-before-edge",bottom:"text-after-edge",middle:"central"};return d[u]||d.alphabetic}a=n("50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,t9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro",32),t={strokeStyle:{svgAttr:"stroke",canvas:"#000000",svg:"none",apply:"stroke"},fillStyle:{svgAttr:"fill",canvas:"#000000",svg:null,apply:"fill"},lineCap:{svgAttr:"stroke-linecap",canvas:"butt",svg:"butt",apply:"stroke"},lineJoin:{svgAttr:"stroke-linejoin",canvas:"miter",svg:"miter",apply:"stroke"},miterLimit:{svgAttr:"stroke-miterlimit",canvas:10,svg:4,apply:"stroke"},lineWidth:{svgAttr:"stroke-width",canvas:1,svg:1,apply:"stroke"},globalAlpha:{svgAttr:"opacity",canvas:1,svg:1,apply:"fill stroke"},font:{canvas:"10px sans-serif"},shadowColor:{canvas:"#000000"},shadowOffsetX:{canvas:0},shadowOffsetY:{canvas:0},shadowBlur:{canvas:0},textAlign:{canvas:"start"},textBaseline:{canvas:"alphabetic"}},s=function(u,d){this.__root=u,this.__ctx=d},s.prototype.addColorStop=function(u,d){var v=this.__ctx.__createElement("stop"),g,y;v.setAttribute("offset",u),d.indexOf("rgba")!==-1?(g=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi,y=g.exec(d),v.setAttribute("stop-color",o("rgb({r},{g},{b})",{r:y[1],g:y[2],b:y[3]})),v.setAttribute("stop-opacity",y[4])):v.setAttribute("stop-color",d),this.__root.appendChild(v)},r=function(u,d){this.__root=u,this.__ctx=d},i=function(u){var d={width:500,height:500,enableMirroring:!1},v;if(arguments.length>1?(v=d,v.width=arguments[0],v.height=arguments[1]):u?v=u:v=d,!(this instanceof i))return new i(v);this.width=v.width||d.width,this.height=v.height||d.height,this.enableMirroring=v.enableMirroring!==void 0?v.enableMirroring:d.enableMirroring,this.canvas=this,this.__document=v.document||document,this.__canvas=this.__document.createElement("canvas"),this.__ctx=this.__canvas.getContext("2d"),this.__setDefaultStyles(),this.__stack=[this.__getStyleState()],this.__groupStack=[],this.__root=this.__document.createElementNS("http://www.w3.org/2000/svg","svg"),this.__root.setAttribute("version",1.1),this.__root.setAttribute("xmlns","http://www.w3.org/2000/svg"),this.__root.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink"),this.__root.setAttribute("width",this.width),this.__root.setAttribute("height",this.height),this.__ids={},this.__defs=this.__document.createElementNS("http://www.w3.org/2000/svg","defs"),this.__root.appendChild(this.__defs),this.__currentElement=this.__document.createElementNS("http://www.w3.org/2000/svg","g"),this.__root.appendChild(this.__currentElement)},i.prototype.__createElement=function(u,d,v){typeof d>"u"&&(d={});var g=this.__document.createElementNS("http://www.w3.org/2000/svg",u),y=Object.keys(d),p,b;for(v&&(g.setAttribute("fill","none"),g.setAttribute("stroke","none")),p=0;p<y.length;p++)b=y[p],g.setAttribute(b,d[b]);return g},i.prototype.__setDefaultStyles=function(){var u=Object.keys(t),d,v;for(d=0;d<u.length;d++)v=u[d],this[v]=t[v].canvas},i.prototype.__applyStyleState=function(u){var d=Object.keys(u),v,g;for(v=0;v<d.length;v++)g=d[v],this[g]=u[g]},i.prototype.__getStyleState=function(){var u,d={},v=Object.keys(t),g;for(u=0;u<v.length;u++)g=v[u],d[g]=this[g];return d},i.prototype.__applyStyleToCurrentElement=function(u){var d=Object.keys(t),v,g,y,p,b,m;for(v=0;v<d.length;v++)if(g=t[d[v]],y=this[d[v]],g.apply)if(g.apply.indexOf("fill")!==-1&&y instanceof r){if(y.__ctx)for(;y.__ctx.__defs.childNodes.length;)p=y.__ctx.__defs.childNodes[0].getAttribute("id"),this.__ids[p]=p,this.__defs.appendChild(y.__ctx.__defs.childNodes[0]);this.__currentElement.setAttribute("fill",o("url(#{id})",{id:y.__root.getAttribute("id")}))}else g.apply.indexOf("fill")!==-1&&y instanceof s?this.__currentElement.setAttribute("fill",o("url(#{id})",{id:y.__root.getAttribute("id")})):g.apply.indexOf(u)!==-1&&g.svg!==y&&((g.svgAttr==="stroke"||g.svgAttr==="fill")&&y.indexOf("rgba")!==-1?(b=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi,m=b.exec(y),this.__currentElement.setAttribute(g.svgAttr,o("rgb({r},{g},{b})",{r:m[1],g:m[2],b:m[3]})),this.__currentElement.setAttribute(g.svgAttr+"-opacity",m[4])):this.__currentElement.setAttribute(g.svgAttr,y))},i.prototype.__closestGroupOrSvg=function(u){return u=u||this.__currentElement,u.nodeName==="g"||u.nodeName==="svg"?u:this.__closestGroupOrSvg(u.parentNode)},i.prototype.getSerializedSvg=function(u){var d=new XMLSerializer().serializeToString(this.__root),v,g,y,p,b,m;if(m=/xmlns="http:\/\/www\.w3\.org\/2000\/svg".+xmlns="http:\/\/www\.w3\.org\/2000\/svg/gi,m.test(d)&&(d=d.replace('xmlns="http://www.w3.org/2000/svg','xmlns:xlink="http://www.w3.org/1999/xlink')),u)for(v=Object.keys(a),g=0;g<v.length;g++)y=v[g],p=a[y],b=new RegExp(y,"gi"),b.test(d)&&(d=d.replace(b,p));return d},i.prototype.getSvg=function(){return this.__root},i.prototype.save=function(){var u=this.__createElement("g"),d=this.__closestGroupOrSvg();this.__groupStack.push(d),d.appendChild(u),this.__currentElement=u,this.__stack.push(this.__getStyleState())},i.prototype.restore=function(){this.__currentElement=this.__groupStack.pop();var u=this.__stack.pop();this.__applyStyleState(u)},i.prototype.__addTransform=function(u){var d=this.__closestGroupOrSvg();if(d.childNodes.length>0){var v=this.__createElement("g");d.appendChild(v),this.__currentElement=v}var g=this.__currentElement.getAttribute("transform");g?g+=" ":g="",g+=u,this.__currentElement.setAttribute("transform",g)},i.prototype.scale=function(u,d){d===void 0&&(d=u),this.__addTransform(o("scale({x},{y})",{x:u,y:d}))},i.prototype.rotate=function(u){var d=u*180/Math.PI;this.__addTransform(o("rotate({angle},{cx},{cy})",{angle:d,cx:0,cy:0}))},i.prototype.translate=function(u,d){this.__addTransform(o("translate({x},{y})",{x:u,y:d}))},i.prototype.transform=function(u,d,v,g,y,p){this.__addTransform(o("matrix({a},{b},{c},{d},{e},{f})",{a:u,b:d,c:v,d:g,e:y,f:p}))},i.prototype.beginPath=function(){var u,d;this.__currentDefaultPath="",this.__currentPosition={},u=this.__createElement("path",{},!0),d=this.__closestGroupOrSvg(),d.appendChild(u),this.__currentElement=u},i.prototype.__applyCurrentDefaultPath=function(){if(this.__currentElement.nodeName==="path"){var u=this.__currentDefaultPath;this.__currentElement.setAttribute("d",u)}else throw new Error("Attempted to apply path command to node "+this.__currentElement.nodeName)},i.prototype.__addPathCommand=function(u){this.__currentDefaultPath+=" ",this.__currentDefaultPath+=u},i.prototype.moveTo=function(u,d){this.__currentElement.nodeName!=="path"&&this.beginPath(),this.__currentPosition={x:u,y:d},this.__addPathCommand(o("M {x} {y}",{x:u,y:d}))},i.prototype.closePath=function(){this.__addPathCommand("Z")},i.prototype.lineTo=function(u,d){this.__currentPosition={x:u,y:d},this.__currentDefaultPath.indexOf("M")>-1?this.__addPathCommand(o("L {x} {y}",{x:u,y:d})):this.__addPathCommand(o("M {x} {y}",{x:u,y:d}))},i.prototype.bezierCurveTo=function(u,d,v,g,y,p){this.__currentPosition={x:y,y:p},this.__addPathCommand(o("C {cp1x} {cp1y} {cp2x} {cp2y} {x} {y}",{cp1x:u,cp1y:d,cp2x:v,cp2y:g,x:y,y:p}))},i.prototype.quadraticCurveTo=function(u,d,v,g){this.__currentPosition={x:v,y:g},this.__addPathCommand(o("Q {cpx} {cpy} {x} {y}",{cpx:u,cpy:d,x:v,y:g}))};var f=function(u){var d=Math.sqrt(u[0]*u[0]+u[1]*u[1]);return[u[0]/d,u[1]/d]};i.prototype.arcTo=function(u,d,v,g,y){var p=this.__currentPosition&&this.__currentPosition.x,b=this.__currentPosition&&this.__currentPosition.y;if(!(typeof p>"u"||typeof b>"u")){if(y<0)throw new Error("IndexSizeError: The radius provided ("+y+") is negative.");if(p===u&&b===d||u===v&&d===g||y===0){this.lineTo(u,d);return}var m=f([p-u,b-d]),k=f([v-u,g-d]);if(m[0]*k[1]===m[1]*k[0]){this.lineTo(u,d);return}var A=m[0]*k[0]+m[1]*k[1],S=Math.acos(Math.abs(A)),I=f([m[0]+k[0],m[1]+k[1]]),E=y/Math.sin(S/2),z=u+E*I[0],U=d+E*I[1],T=[-m[1],m[0]],R=[k[1],-k[0]],C=function(j){var X=j[0],F=j[1];return F>=0?Math.acos(X):-Math.acos(X)},_=C(T),B=C(R);this.lineTo(z+T[0]*y,U+T[1]*y),this.arc(z,U,y,_,B)}},i.prototype.stroke=function(){this.__currentElement.nodeName==="path"&&this.__currentElement.setAttribute("paint-order","fill stroke markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("stroke")},i.prototype.fill=function(){this.__currentElement.nodeName==="path"&&this.__currentElement.setAttribute("paint-order","stroke fill markers"),this.__applyCurrentDefaultPath(),this.__applyStyleToCurrentElement("fill")},i.prototype.rect=function(u,d,v,g){this.__currentElement.nodeName!=="path"&&this.beginPath(),this.moveTo(u,d),this.lineTo(u+v,d),this.lineTo(u+v,d+g),this.lineTo(u,d+g),this.lineTo(u,d),this.closePath()},i.prototype.fillRect=function(u,d,v,g){var y,p;y=this.__createElement("rect",{x:u,y:d,width:v,height:g},!0),p=this.__closestGroupOrSvg(),p.appendChild(y),this.__currentElement=y,this.__applyStyleToCurrentElement("fill")},i.prototype.strokeRect=function(u,d,v,g){var y,p;y=this.__createElement("rect",{x:u,y:d,width:v,height:g},!0),p=this.__closestGroupOrSvg(),p.appendChild(y),this.__currentElement=y,this.__applyStyleToCurrentElement("stroke")},i.prototype.clearRect=function(u,d,v,g){var y,p=this.__closestGroupOrSvg();y=this.__createElement("rect",{x:u,y:d,width:v,height:g,fill:"#FFFFFF"},!0),p.appendChild(y)},i.prototype.createLinearGradient=function(u,d,v,g){var y=this.__createElement("linearGradient",{id:l(this.__ids),x1:u+"px",x2:v+"px",y1:d+"px",y2:g+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(y),new s(y,this)},i.prototype.createRadialGradient=function(u,d,v,g,y,p){var b=this.__createElement("radialGradient",{id:l(this.__ids),cx:g+"px",cy:y+"px",r:p+"px",fx:u+"px",fy:d+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(b),new s(b,this)},i.prototype.__parseFont=function(){var u=/^\s*(?=(?:(?:[-a-z]+\s*){0,2}(italic|oblique))?)(?=(?:(?:[-a-z]+\s*){0,2}(small-caps))?)(?=(?:(?:[-a-z]+\s*){0,2}(bold(?:er)?|lighter|[1-9]00))?)(?:(?:normal|\1|\2|\3)\s*){0,3}((?:xx?-)?(?:small|large)|medium|smaller|larger|[.\d]+(?:\%|in|[cem]m|ex|p[ctx]))(?:\s*\/\s*(normal|[.\d]+(?:\%|in|[cem]m|ex|p[ctx])))?\s*([-,\"\sa-z]+?)\s*$/i,d=u.exec(this.font),v={style:d[1]||"normal",size:d[4]||"10px",family:d[6]||"sans-serif",weight:d[3]||"normal",decoration:d[2]||"normal",href:null};return this.__fontUnderline==="underline"&&(v.decoration="underline"),this.__fontHref&&(v.href=this.__fontHref),v},i.prototype.__wrapTextLink=function(u,d){if(u.href){var v=this.__createElement("a");return v.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",u.href),v.appendChild(d),v}return d},i.prototype.__applyText=function(u,d,v,g){var y=this.__parseFont(),p=this.__closestGroupOrSvg(),b=this.__createElement("text",{"font-family":y.family,"font-size":y.size,"font-style":y.style,"font-weight":y.weight,"text-decoration":y.decoration,x:d,y:v,"text-anchor":h(this.textAlign),"dominant-baseline":c(this.textBaseline)},!0);b.appendChild(this.__document.createTextNode(u)),this.__currentElement=b,this.__applyStyleToCurrentElement(g),p.appendChild(this.__wrapTextLink(y,b))},i.prototype.fillText=function(u,d,v){this.__applyText(u,d,v,"fill")},i.prototype.strokeText=function(u,d,v){this.__applyText(u,d,v,"stroke")},i.prototype.measureText=function(u){return this.__ctx.font=this.font,this.__ctx.measureText(u)},i.prototype.arc=function(u,d,v,g,y,p){if(g!==y){g=g%(2*Math.PI),y=y%(2*Math.PI),g===y&&(y=(y+2*Math.PI-.001*(p?-1:1))%(2*Math.PI));var b=u+v*Math.cos(y),m=d+v*Math.sin(y),k=u+v*Math.cos(g),A=d+v*Math.sin(g),S=p?0:1,I=0,E=y-g;E<0&&(E+=2*Math.PI),p?I=E>Math.PI?0:1:I=E>Math.PI?1:0,this.lineTo(k,A),this.__addPathCommand(o("A {rx} {ry} {xAxisRotation} {largeArcFlag} {sweepFlag} {endX} {endY}",{rx:v,ry:v,xAxisRotation:0,largeArcFlag:I,sweepFlag:S,endX:b,endY:m})),this.__currentPosition={x:b,y:m}}},i.prototype.clip=function(){var u=this.__closestGroupOrSvg(),d=this.__createElement("clipPath"),v=l(this.__ids),g=this.__createElement("g");u.removeChild(this.__currentElement),d.setAttribute("id",v),d.appendChild(this.__currentElement),this.__defs.appendChild(d),u.setAttribute("clip-path",o("url(#{id})",{id:v})),u.appendChild(g),this.__currentElement=g},i.prototype.drawImage=function(){var u=Array.prototype.slice.call(arguments),d=u[0],v,g,y,p,b=0,m=0,k,A,S,I,E,z,U,T,R,C,_;if(u.length===3)v=u[1],g=u[2],k=d.width,A=d.height,y=k,p=A;else if(u.length===5)v=u[1],g=u[2],y=u[3],p=u[4],k=d.width,A=d.height;else if(u.length===9)b=u[1],m=u[2],k=u[3],A=u[4],v=u[5],g=u[6],y=u[7],p=u[8];else throw new Error("Inavlid number of arguments passed to drawImage: "+arguments.length);if(S=this.__closestGroupOrSvg(),U=this.__currentElement,d instanceof i){for(I=d.getSvg(),E=I.childNodes[0];E.childNodes.length;)_=E.childNodes[0].getAttribute("id"),this.__ids[_]=_,this.__defs.appendChild(E.childNodes[0]);z=I.childNodes[1],S.appendChild(z),this.__currentElement=z,this.translate(v,g),this.__currentElement=U}else(d.nodeName==="CANVAS"||d.nodeName==="IMG")&&(T=this.__createElement("image"),T.setAttribute("width",y),T.setAttribute("height",p),T.setAttribute("preserveAspectRatio","none"),(b||m||k!==d.width||A!==d.height)&&(R=this.__document.createElement("canvas"),R.width=y,R.height=p,C=R.getContext("2d"),C.drawImage(d,b,m,k,A,0,0,y,p),d=R),T.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",d.nodeName==="CANVAS"?d.toDataURL():d.getAttribute("src")),S.appendChild(T),this.__currentElement=T,this.translate(v,g),this.__currentElement=U)},i.prototype.createPattern=function(u,d){var v=this.__document.createElementNS("http://www.w3.org/2000/svg","pattern"),g=l(this.__ids),y;return v.setAttribute("id",g),v.setAttribute("width",u.width),v.setAttribute("height",u.height),u.nodeName==="CANVAS"||u.nodeName==="IMG"?(y=this.__document.createElementNS("http://www.w3.org/2000/svg","image"),y.setAttribute("width",u.width),y.setAttribute("height",u.height),y.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",u.nodeName==="CANVAS"?u.toDataURL():u.getAttribute("src")),v.appendChild(y),this.__defs.appendChild(v)):u instanceof i&&(v.appendChild(u.__root.childNodes[1]),this.__defs.appendChild(v)),new r(v,this)},i.prototype.drawFocusRing=function(){},i.prototype.createImageData=function(){},i.prototype.getImageData=function(){},i.prototype.putImageData=function(){},i.prototype.globalCompositeOperation=function(){},i.prototype.setTransform=function(){},typeof window=="object"&&(window.C2S=i),e.exports=i})()})(oa);var bc=oa.exports;const ku=wa(bc);function xc(e,t){const{x:i,y:s,width:r,height:a}=t.calculative.worldRect;e.beginPath(),e.ellipse(i+r/2,s+a/2,r/2,a/2,0,0,Math.PI*2),e.stroke(),e.beginPath(),e.fillStyle=e.strokeStyle,e.ellipse(i+r/2,s+a/2,r/4,a/4,0,0,Math.PI*2),e.fill()}function kc(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o,ey:l}=e.calculative.worldRect,n=e.calculative.lineLeft||.08;let h=e.calculative.borderRadius||0,c=h;h<1&&(h=a*h,c=o*h);let f=h<c?h:c;if(a<2*f&&(f=a/2),o<2*f&&(f=o/2),i.moveTo(s+f,r),i.arcTo(s+a,r,s+a,r+o,f),i.arcTo(s+a,r+o,s,r+o,f),i.arcTo(s,r+o,s,r,f),i.arcTo(s,r,s+a,r,f),i.closePath(),i.moveTo(s+n*a,r),i.lineTo(s+n*a,l),i instanceof Path2D)return i}function Rc(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o,ex:l}=e.calculative.worldRect,n=e.calculative.lineTop||.08;let h=e.calculative.borderRadius||0,c=h;h<1&&(h=a*h,c=o*c);let f=h<c?h:c;if(a<2*f&&(f=a/2),o<2*f&&(f=o/2),i.moveTo(s+f,r),i.arcTo(s+a,r,s+a,r+o,f),i.arcTo(s+a,r+o,s,r+o,f),i.arcTo(s,r+o,s,r,f),i.arcTo(s,r,s+a,r,f),i.closePath(),i.moveTo(s,r+n*o),i.lineTo(l,r+n*o),i instanceof Path2D)return i}function Ru(){return{forkV:me,forkH:me,swimlaneH:kc,swimlaneV:Rc}}function Tu(){return{activityFinal:xc}}const lr={enter:"mouseover",leave:"mouseout"};var Ge;(function(e){e[e.Add=0]="Add",e[e.Replace=1]="Replace",e[e.ReplaceAll=2]="ReplaceAll"})(Ge||(Ge={}));let is=["fontSize","nameGap","margin","width","symbolSize","itemWidth","itemHeight","fontWeight","top","left","right","bottom","zoom","edgeSymbolSize","nodeWidth","nodeGap","distance","length","length2","offsetCenter","size","symbolOffset","padding","barWidth","symbolOffset","shadowOffsetY","shadowOffsetX","itemGap"];const Tc=["formatter","color"];function ke(e,t,i){var r,a;const s=(a=(r=e.calculative)==null?void 0:r.singleton)==null?void 0:a.echart;if(!s)return!1;if(t==null)return console.warn("[meta2d:echarts] Skip setOption because option is empty.",e),!1;try{return s.setOption(t,i),!0}catch(o){return console.error("[meta2d:echarts] setOption failed.",{penId:e.id,option:t,opts:i,error:o}),!1}}function ps(e){var a,o,l,n,h;const t=(o=(a=e.calculative)==null?void 0:a.singleton)==null?void 0:o.echart,i=(n=(l=e.calculative)==null?void 0:l.singleton)==null?void 0:n.div;if(!t||!i||!i.isConnected)return!1;const{width:s,height:r}=((h=e.calculative)==null?void 0:h.worldRect)||{};if(!(s>0)||!(r>0))return console.warn("[meta2d:echarts] Skip resize because container size is invalid.",{penId:e.id,width:s,height:r}),!1;try{return t.resize(),!0}catch(c){return console.error("[meta2d:echarts] resize failed.",{penId:e.id,width:s,height:r,error:c}),!1}}function Cc(e){var r,a;let t=globalThis.echarts;if(!e.echarts||!t)return;if(typeof e.echarts=="string")try{e.echarts=JSON.parse(e.echarts)}catch{}is=((r=e.calculative.canvas.store.options.diagramOptions.chart)==null?void 0:r.keyWords)||is,e.onDestroy||(e.onDestroy=Sc,e.onMove=gi,e.onResize=Pc,e.onRotate=gi,e.onValue=_c,e.onBeforeValue=Ec,e.onBinds=Lc,e.onMouseEnter=gi,e.onRenderPenRaw=Ui,e.onScale=Ic),e.calculative.singleton||(e.calculative.singleton={});const i=new Path2D,s=e.calculative.worldRect;if(!e.calculative.singleton.div){const o=document.createElement("div");o.style.position="absolute",o.style.outline="none",o.style.left="-9999px",o.style.top="-9999px",o.style.width=s.width+"px",o.style.height=s.height+"px",document.body.appendChild(o),(a=e.calculative.canvas.externalElements)==null||a.parentElement.appendChild(o),Ct(e,o),e.calculative.singleton.div=o,e.calculative.singleton.echart=t.init(o,e.echarts.theme),Ac(e),e.calculative.singleton.echartsReady=!0,e.echarts.geoName&&!t.getMap(e.echarts.geoName)&&(e.echarts.geoJson?t.registerMap(e.echarts.geoName,e.echarts.geoJson):e.echarts.geoUrl&&(e.calculative.singleton.echartsReady=!1,fetch(e.echarts.geoUrl).then(l=>{l.text().then(n=>{if(typeof n=="string")try{n=JSON.parse(n)}catch{}if(n.constructor!==Object&&n.constructor!==Array){console.warn("Invalid data:",n);return}t.registerMap(e.echarts.geoName,n),e.calculative.singleton.echartsReady=!0,ke(e,_i(e.echarts.option,e.calculative.canvas.store.data.scale,e.calculative.canvas.store.options),!0),ps(e),setTimeout(()=>{Ui(e)},300)})}))),e.calculative.singleton.echartsReady&&setTimeout(()=>{if(e.echarts.initJs){const n=It(e.calculative.canvas.store.options,"myChart","context",`return async function () { ${e.echarts.initJs}}`)(e.calculative.singleton.echart,{meta2d:this,pen:e});n==null||n().then(h=>{if(h&&ke(e,h,!0)){let f=e.calculative.singleton.echart.getOption();e.echarts.option=f}})}else ke(e,_i(e.echarts.option,e.calculative.canvas.store.data.scale,e.calculative.canvas.store.options),!0);setTimeout(()=>Ui(e),300)})}return i}function Ac(e){var s;const t=e.calculative.singleton.echart,i=["click","dblclick","mousedown","mousemove","mouseup","mouseover","mouseout","globalout","contextmenu"];(s=e.events)==null||s.forEach(r=>{r.actions&&r.actions.length&&i.includes(lr[r.name]||r.name)&&t.getZr().on(lr[r.name]||r.name,a=>{let o=!1;r.conditions&&r.conditions.length?r.conditionType==="and"?o=r.conditions.every(l=>e.calculative.canvas.parent.judgeCondition(e,l.key,l)):r.conditionType==="or"&&(o=r.conditions.some(l=>e.calculative.canvas.parent.judgeCondition(e,l.key,l))):o=!0,o&&r.actions.forEach(l=>{if(l.timeout){let n=setTimeout(()=>{e.calculative.canvas.parent.events[l.action]&&(e.calculative.canvas.parent.events[l.action](e,l,a),clearTimeout(n),n=null)},l.timeout)}else e.calculative.canvas.parent.events[l.action]&&e.calculative.canvas.parent.events[l.action](e,l,a)})})})}function Sc(e){if(e.calculative.singleton&&e.calculative.singleton.div){e.calculative.singleton.div.remove();let t=globalThis.echarts;t&&t.dispose(e.calculative.singleton.echart),delete e.calculative.singleton.div,delete e.calculative.singleton.echart}}function gi(e){e.calculative.singleton.div&&Ct(e,e.calculative.singleton.div)}function Pc(e){e.debounceTime?(e.resizeFn||(e.resizeFn=cr,e.debounceResize=ls.debounce(e,"resizeFn",e.debounceTime)),e.debounceResize(e)):cr(e)}function cr(e){var t;gi(e),(t=e.calculative.singleton)!=null&&t.echart&&ps(e)}function Ic(e){e.debounceTime?(e.scaleFn||(e.scaleFn=hr,e.debounceScale=ls.debounce(e,"scaleFn",e.debounceTime)),e.debounceScale(e)):hr(e)}function hr(e){var i,s;if(!e.calculative.singleton.echart)return;let t=globalThis.echarts;if(Ct(e,e.calculative.singleton.div),!(e.echarts.geoName&&!t.getMap(e.echarts.geoName))){if(!(e.echarts.diabled||e.echarts.disabled)&&!e.echarts.initJs){if((i=e.echarts.option)!=null&&i.dataZoom){const r=e.calculative.singleton.echart.getOption();if(r!=null&&r.dataZoom){const a=r.dataZoom;(s=e.echarts.option.dataZoom)==null||s.forEach((o,l)=>{a[l]&&(o.start=a[l].start,o.end=a[l].end)})}}ke(e,_i(e.echarts.option,e.calculative.canvas.store.data.scale,e.calculative.canvas.store.options),!0)}ps(e)}}function _c(e){var t,i;if(e.calculative.singleton.echart&&(Ct(e,e.calculative.singleton.div),e.calculative.singleton.echartsReady))if(e.calculative.partialOption){const s=e.calculative.partialOption.echarts.option;(Array.isArray((t=e.echarts)==null?void 0:t.replaceMerge)?(i=e.echarts)==null?void 0:i.replaceMerge.some(a=>s[a]):!1)?ke(e,K(s),{replaceMerge:e.echarts.replaceMerge}):ke(e,K(s))}else ke(e,_i(e.echarts.option,e.calculative.canvas.store.data.scale,e.calculative.canvas.store.options),!0)}function Ec(e,t){var v,g,y;if(e.calculative.partialOption=null,t.echarts){let p=globalThis.echarts;return t.echarts.geoName&&!p.getMap(t.echarts.geoName)&&(t.echarts.geoJson?p.registerMap(t.echarts.geoName,t.echarts.geoJson):t.echarts.geoUrl&&(e.calculative.singleton.echartsReady=!1,fetch(t.echarts.geoUrl).then(b=>{b.text().then(m=>{if(typeof m=="string")try{m=JSON.parse(m)}catch{}if(m.constructor!==Object&&m.constructor!==Array){console.warn("Invalid data:",m);return}return p.registerMap(t.echarts.geoName,m),e.calculative.singleton.echartsReady=!0,e.onValue(e),!1})}))),t}if(e.realTimes&&e.realTimes.length){e.echarts.dataMap&&t.data&&(t=Mc(e,t));let p=Object.keys(t);const{xAxis:b,yAxis:m}=e.echarts.option,{max:k,replaceMode:A,timeFormat:S,autoGetTime:I=!0}=e.echarts;let E=[],z=!1,U=e.realTimes.filter(T=>T.bind&&T.bind.class==="iot"&&T.bind.compute_name);if(U.length&&U.find(R=>p.includes(R.key))){let R={},C=[];for(let _ in t)_.includes("echarts.option.series")&&(R[_]=Object.fromEntries(t[_]),C.push(...Object.keys(R[_])));C=[...new Set(C)].sort((_,B)=>_-B);for(let _ in t)_.includes("echarts.option.series")&&(R[_]=C.map(B=>R[_][B]));return(C[0]+"").length===19&&(C=C.map(_=>_/1e6)),C=C.map(_=>{var B,j,X;return xi(S||"`${year}:${month}:${day} ${hours}:${minutes}:${seconds}`",_,(X=(j=(B=e.calculative)==null?void 0:B.canvas)==null?void 0:j.store)==null?void 0:X.options)}),R["echarts.option.xAxis.data"]=C,R}for(let T in t)if(T.includes("echarts.option")){z=!0,T.includes("series.links.")&&(z=!1);let R=Et(e,T);if(Array.isArray(R)&&A===Ge.Add&&(R.push(t[T]),k&&R.splice(0,R.length-k),t[T]=R,I&&!p.includes("echarts.option.xAxis.data"))){let C="echarts.option.xAxis.data";if(!t[C]){Array.isArray(b)&&b.length&&(C="echarts.option.xAxis.0.data");let _=Et(e,C),B=xi(S||"`${hours}:${minutes}:${seconds}`",void 0,(y=(g=(v=e.calculative)==null?void 0:v.canvas)==null?void 0:g.store)==null?void 0:y.options);_.push(B),k&&_.splice(0,_.length-k),t[C]=_}}if(T.includes(".data.")){let C=T.substring(0,T.indexOf(".data.")+5);E.includes(C)||E.push(C)}}if(z){const T=K(t);e.calculative.partialOption=Dc(T,e),E.forEach(R=>{let C=Et(e,R);bi(e.calculative.partialOption,R,C)})}return t}if(!t.dataX&&!t.dataY)return t;const i=e.echarts,{max:s,replaceMode:r}=i;let a=t.dataX,o=t.dataY,l=[];o&&l.push("echarts.option.series");const n=i.option.series,h=n.length,{xAxis:c,yAxis:f}=i.option;Array.isArray(c)&&c.length>1&&console.warn("echarts 只支持单 x 轴,多 x 轴将被忽略");const u=Array.isArray(c)?c[0]:c,d=Array.isArray(f)?f[0]:f;if(r)if(r===Ge.Replace){if(!u&&!d)o&&(h===1?(!Array.isArray(o)&&(o=[o]),o.forEach((p,b)=>{const m=n[0].data.find(k=>k.name===p.name);m&&(m.value=p.value)})):n.forEach((p,b)=>{Array.isArray(o[b])||(o[b]=[o[b]]),o[b].forEach((m,k)=>{const A=p.data.find(S=>S.name===m.name);A&&(A.value=m.value)})}));else if((u.type==="category"||d.type==="category")&&a&&o){const p=u.type==="category"?u.data:d.data;!Array.isArray(a)&&(a=[a]),!Array.isArray(o)&&(o=[o]),u.type==="category"?l.push("echarts.option.xAxis"):l.push("echarts.option.yAxis"),h===1?o.forEach((b,m)=>{const k=p.indexOf(a[m]);n[0].data[k]=b}):n.forEach((b,m)=>{o[m].forEach((k,A)=>{const S=p.indexOf(a[A]);b.data[S]=k})})}}else r===Ge.ReplaceAll&&(a&&(u.data=a,u.data.splice(0,u.data.length-s),l.push("echarts.option.xAxis")),o&&(h===1?(n[0].data=o,n[0].data.splice(0,n[0].data.length-s)):n.forEach((p,b)=>{p.data=o[b],p.data.splice(0,p.data.length-s)})));else{if(a){!Array.isArray(a)&&(a=[a]);const p=u.data;p.push(...a),p.splice(0,p.length-s),l.push("echarts.option.xAxis")}if(o)if(h===1){!Array.isArray(o)&&(o=[o]);const p=n[0].data;p.push(...o),p.splice(0,p.length-s)}else n.forEach((p,b)=>{Array.isArray(o[b])||(o[b]=[o[b]]);const m=p.data;m.push(...o[b]),m.splice(0,m.length-s)})}return e.calculative.partialOption={},l.forEach(p=>{let b=Et(e,p);bi(e.calculative.partialOption,p,b)}),delete t.dataX,delete t.dataY,Object.assign(t,{echarts:i})}function Mc(e,t){var i,s,r,a,o;if(!e.echarts.dataMap||!t.data)return t;if(t.data){let l={};if(Array.isArray(t.data))for(const n in e.echarts.dataMap)e.echarts.dataMap.hasOwnProperty(n)&&((i=e.echarts.timeKeys)!=null&&i.length&&e.echarts.timeKeys.includes(e.echarts.dataMap[n])?l[n]=t.data.map(h=>{var c,f,u;return xi(e.echarts.timeFormat,h[e.echarts.dataMap[n]],(u=(f=(c=e.calculative)==null?void 0:c.canvas)==null?void 0:f.store)==null?void 0:u.options)}):l[n]=t.data.map(h=>h[e.echarts.dataMap[n]]));else for(const n in e.echarts.dataMap)e.echarts.dataMap.hasOwnProperty(n)&&((s=e.echarts.timeKeys)!=null&&s.length&&e.echarts.timeKeys.includes(e.echarts.dataMap[n])?l[n]=xi(e.echarts.timeFormat,t.data[e.echarts.dataMap[n]],(o=(a=(r=e.calculative)==null?void 0:r.canvas)==null?void 0:a.store)==null?void 0:o.options):l[n]=t.data[e.echarts.dataMap[n]]);return delete t.data,Object.assign(t,l),t}}function Lc(e,t,i){if(i.key!=="dataY")return;const s=e.echarts,{xAxis:r,yAxis:a}=s.option;Array.isArray(r)&&r.length>1&&console.warn("echarts 只支持单 x 轴,多 x 轴将被忽略");const o=Array.isArray(r)?r[0]:r,l=Array.isArray(a)?a[0]:a,n=s.option.series;if(!o&&!l){const h=[];if(Array.isArray(n)&&n.length===1)return n[0].data.forEach(c=>{const{dataId:f}=i.dataIds.find(u=>u.name===c.name);if(f){const u=t.find(d=>d.dataId===f);u&&h.push({name:c.name,value:u.value})}}),{id:e.id,dataY:h}}else if(o.type==="category"||l.type==="category"){const h=[],c=[],f=o.type==="category"?o.data:l.data;return f==null||f.forEach(u=>{const{dataId:d}=i.dataIds.find(v=>v.name===u);if(d){const v=t.find(g=>g.dataId===d);v&&(c.push(u),h.push(v.value))}}),{id:e.id,dataY:h,dataX:c}}else if(o.type==="time"){const h=[],c=+new Date;let f=!1;if(n.forEach((u,d)=>{const v=[],{dataId:g}=i.dataIds.find(y=>y.name===u.name);if(g){const y=t.find(p=>p.dataId===g);y&&(v.push([c,y.value]),f=!0)}h[d]=v}),f)h.forEach((u,d)=>{if(!u||u.length===0){const v=n[d].data[n[d].data.length-1];h[d]=[[c,v[1]]]}});else return;return{id:e.id,dataY:h.length===1?h[0]:h}}}function Ui(e){var i,s;const t=new Image;try{t.src=(s=(i=e.calculative.singleton)==null?void 0:i.echart)==null?void 0:s.getDataURL({pixelRatio:2})}catch(r){console.error("[meta2d:echarts] getDataURL failed.",{penId:e.id,error:r});return}e.calculative.img=t}function _i(e,t,i){const s=K(e);if(s.dataZoom){let r=["right","top","width","height","left","bottom"];for(let a=0;a<r.length;a++)s.dataZoom.forEach(o=>{isNaN(o[r[a]])||(o[r[a]]*=t)})}return Yi(s,is,t),ss(s,Tc,i),s}function Dc(e,t){const i={};return Object.keys(e).forEach(s=>{const r=s.split(".");let a=i;r.forEach((o,l)=>{const n=!isNaN(parseInt(o));if(l===6){let h=r.slice(0,7).join(".");bi(t,s,e[s]);let c=Et(t,h);a[r[l]]=c}else{if(l>6)return;if(l===r.length-1)n?(Array.isArray(a)||(a=[]),a[parseInt(o)]=e[s]):a[o]=e[s];else if(n){const h=parseInt(o);if(Array.isArray(a)||a[r[l-1]],a[h]||(a[h]={}),Array.isArray(a))for(let c=0;c<parseInt(o);c++)a[c]||(a[c]={});a=a[h]}else a[o]||(["series","yAxis","xAxis"].includes(o)&&!isNaN(parseInt(r[l+1]))?a[o]=[]:a[o]={}),a=a[o]}})}),i}function Oc(e){if(typeof e!="string")return!1;const t=e.trim(),i=/^\s*function(\s+\w+)?\s*\([^)]*\)\s*\{[\s\S]*\}\s*$/,s=/^\s*(\([^)]*\)|\w+)\s*=>\s*(\{[\s\S]*\}|[^{}]+)\s*$/;return i.test(t)||s.test(t)}function ss(e,t,i){if(Array.isArray(e)){const s=[];return e.forEach(r=>{s.push(ss(r,t,i))}),s}else if(typeof e=="object"){if(e===null)return null;for(const s in e)t.includes(s)?Oc(e[s])&&(e[s]=Ja(i,e[s])):e[s]=ss(e[s],t,i);return e}return e}function Cu(e){wr({echarts:Cc})}function Bc(e,t){e.onDestroy||(e.onDestroy=Fc,e.onAdd=Nc);const i=t||new Path2D,{x:s,y:r,width:a,height:o,ex:l}=e.calculative.worldRect;let n=e.calculative.borderRadius||0,h=n;n<1&&(n*=a,h*=o);let c=n<h?n:h;a<2*c&&(c=a/2),o<2*c&&(c=o/2),i.moveTo(s+c,r),i.arcTo(s+a,r,s+a,r+o,c),i.arcTo(s+a,r+o,s,r+o,c),i.arcTo(s,r+o,s,r,c),i.arcTo(s,r,s+a,r,c);const f=.2*o;i.moveTo(s,r+f),i.lineTo(l,r+f);const u=r+f+(o-f)/2;if(i.moveTo(s,u),i.lineTo(l,u),i.closePath(),i instanceof Path2D)return i}function Nc(e){const{x:t,y:i,width:s,height:r}=e.calculative.worldRect,a=e.list,o={name:"text",x:t,y:i+.2*r,width:s,height:.4*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10},l={name:"text",x:t,y:i+.6*r,width:s,height:.4*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10};Object.assign(o,a[0]),Object.assign(l,a[1]),e.calculative.canvas.makePen(o),e.calculative.canvas.makePen(l),e.calculative.canvas.parent.pushChildren(e,[o]),e.calculative.canvas.parent.pushChildren(e,[l])}function Fc(e){const t=e.calculative.canvas.store;e.children.forEach(i=>{const s=t.data.pens.findIndex(r=>r.id===i);s>-1&&(t.data.pens.splice(s,1),t.pens[i]=void 0)}),e.children=void 0}function zc(e,t){e.onDestroy||(e.onDestroy=Wc,e.onAdd=jc);const i=t||new Path2D,{x:s,y:r,width:a,height:o,ex:l}=e.calculative.worldRect;let n=e.calculative.borderRadius||0,h=n;n<1&&(n=a*n,h=o*h);let c=n<h?n:h;a<2*c&&(c=a/2),o<2*c&&(c=o/2),i.moveTo(s+c,r),i.arcTo(s+a,r,s+a,r+o,c),i.lineTo(s+a,r+o-c),i.arcTo(s+a,r+o,s,r+o,c),i.arcTo(s,r+o,s,r,c),i.arcTo(s,r,s+a,r,c);const f=.2*o;if(i.moveTo(s,r+f),i.lineTo(l,r+f),i.closePath(),i instanceof Path2D)return i}function jc(e){const{x:t,y:i,width:s,height:r}=e.calculative.worldRect,a=e.list;let o={name:"text",x:t,y:i+.2*r,width:s,height:.8*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10};Object.assign(o,a[0]),e.calculative.canvas.makePen(o),e.calculative.canvas.parent.pushChildren(e,[o])}function Wc(e){const t=e.calculative.canvas.store;e.children.forEach(i=>{const s=t.data.pens.findIndex(r=>r.id===i);s>-1&&(t.data.pens.splice(s,1),t.pens[i]=void 0)}),e.children=[]}function Au(){return{interfaceClass:Bc,simpleClass:zc}}function Hc(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ey:o}=e.calculative.worldRect,l=a/4;if(i.moveTo(s+l,r),i.lineTo(s,r),i.lineTo(s,o),i.lineTo(s+l,o),i instanceof Path2D)return i}function Vc(e){const t=[{x:.25,y:0},{x:.25,y:1},{x:0,y:.5}];e.anchors=t.map(({x:i,y:s},r)=>({id:r+"",x:i,y:s,penId:e.id}))}function Uc(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:o,ey:l}=e.calculative.worldRect,n=e.offsetX;let h=a/7;if(n>1?h=n:n>0&&(h=a*n),i.moveTo(s+h,r),i.lineTo(o,r),i.lineTo(s+a-h,l),i.lineTo(s,l),i.closePath(),i instanceof Path2D)return i}function qc(e){const t=[{x:.5,y:0},{x:.9285714285714286,y:.5},{x:.5,y:1},{x:.07142857142857142,y:.5}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function $c(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o,ex:l,ey:n}=e.calculative.worldRect,h=a/8;if(i.moveTo(s+h,r),i.lineTo(l-h,r),i.bezierCurveTo(l+h/3,r,l+h/3,n,l-h,n),i.lineTo(s+h,n),i.lineTo(s,r+o/2),i.closePath(),i instanceof Path2D)return i}function Yc(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o,ex:l,center:n}=e.calculative.worldRect,h=n.x,c=r+o*6/7,f=o/6;if(i.moveTo(s,r),i.lineTo(l,r),i.lineTo(l,c),i.bezierCurveTo(l-20,c-f,h+a/5,c-f,h,c),i.bezierCurveTo(h-a/5,c+f,s,c+f,s,c),i.closePath(),i instanceof Path2D)return i}function Xc(e){const t=[{x:.5,y:0},{x:1,y:.5},{x:.5,y:.8571428571428571},{x:0,y:.5}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function Kc(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:o,ey:l}=e.calculative.worldRect,n=a/10;if(i.moveTo(s+n*2,r),i.bezierCurveTo(s-n*2/3,r,s-n*2/3,l,s+n*2,l),i.lineTo(o,l),i.bezierCurveTo(o-n,l,o-n,r,o,r),i.closePath(),i instanceof Path2D)return i}function Gc(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:o,ey:l}=e.calculative.worldRect;i.moveTo(s,r),i.lineTo(o,r),i.lineTo(o,l),i.lineTo(s,l),i.closePath();const n=a/7;if(i.moveTo(s,r+n),i.lineTo(o,r+n),i.moveTo(s+n,r),i.lineTo(s+n,l),i instanceof Path2D)return i}function Jc(e,t){const i=t||new Path2D,{x:s,y:r,height:a,ex:o,ey:l}=e.calculative.worldRect,n=a/4;if(i.moveTo(s,r+n),i.lineTo(o,r),i.lineTo(o,l),i.lineTo(s,l),i.closePath(),i instanceof Path2D)return i}function Qc(e){const t=[{x:.5,y:.125},{x:1,y:.5},{x:.5,y:1},{x:0,y:.5}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function Zc(e,t){const i=t||new Path2D,{x:s,y:r,ex:a,ey:o}=e.calculative.worldRect;if(i.moveTo(s,r),i.lineTo(a,r),i.moveTo(s,o),i.lineTo(a,o),i instanceof Path2D)return i}function th(e){const t=[{x:.5,y:0},{x:.5,y:1}];e.anchors=t.map(({x:i,y:s},r)=>({id:r+"",x:i,y:s,penId:e.id}))}function eh(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o,ex:l,ey:n}=e.calculative.worldRect;if(i.ellipse(s+a/2,r+o/2,a/2,o/2,0,0,Math.PI*2),i.moveTo(s+a/2,n),i.lineTo(l,n),i.closePath(),i instanceof Path2D)return i}function ih(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:o,ey:l}=e.calculative.worldRect,n=a/7;if(i.moveTo(s,r),i.lineTo(o,r),i.lineTo(o,l),i.lineTo(s,l),i.closePath(),i.moveTo(s+n,r),i.lineTo(s+n,l),i.moveTo(o-n,r),i.lineTo(o-n,l),i instanceof Path2D)return i}function sh(e,t){const i=t||new Path2D,{x:s,y:r,height:a,ex:o,ey:l}=e.calculative.worldRect,n=a/7;if(i.moveTo(s,r+n),i.bezierCurveTo(s,r-n/2|0,o,r-n/2|0,o,r+n),i.lineTo(o,l-n),i.bezierCurveTo(o,l+n/2|0,s,l+n/2|0,s,l-n),i.closePath(),i.moveTo(s,l-n),i.bezierCurveTo(s,l-n*2|0,o,l-n*2|0,o,l-n),i instanceof Path2D)return i}function Su(){return{flowComment:Hc,flowData:Uc,flowDb:sh,flowDisplay:$c,flowDocument:Yc,flowExternStorage:Kc,flowInternalStorage:Gc,flowManually:Jc,flowParallel:Zc,flowQueue:eh,flowSubprocess:ih}}function Pu(){return{flowDocument:Xc,flowManually:Qc,flowParallel:th,flowComment:Vc,flowData:qc}}var Ei;(function(e){e[e.Add=0]="Add",e[e.Replace=1]="Replace",e[e.ReplaceAll=2]="ReplaceAll"})(Ei||(Ei={}));function na(e,t){const i=t.calculative.worldRect.height*14/16,r=(e.match(/[\u4e00-\u9fa5]/g)||"").length;return(e.length-r)*i*.6+r*i}function la(e){if(e.direction=="horizontal"){const t=[];let i=0;const s=e.height;e.checkboxHeight=s,e.options.forEach((a,o)=>{t.push(o*(40+s)+i),i+=na(a.text,e)}),e.optionPos=t;const r=t.length*(40+s)+i;e.checkboxWidth=r,e.width=r,e.calculative.width=r,e.calculative.worldRect={x:e.x,y:e.y,height:e.height,width:e.width,center:{x:e.x+e.width/2,y:e.y+e.height/2}},bt(e.calculative.worldRect)}else if(e.direction=="vertical"){e.optionInterval==null&&(e.optionInterval=20),e.optionHeight||(e.optionHeight=20);const t=[];e.options.forEach((s,r)=>{t.push(r*(e.optionInterval+e.optionHeight))}),e.optionPos=t;const i=t[t.length-1]+e.optionHeight;e.checkboxHeight=i,e.width||(e.height=i,e.calculative.height=i,e.calculative.worldRect={x:e.x,y:e.y,height:e.height,width:e.width,center:{x:e.x+e.width/2,y:e.y+e.height/2}},bt(e.calculative.worldRect))}}function ur(e,t){t.onAdd||(t.onAdd=ca,(!t.rowPos||!t.colPos||!t.calculative.maxOffsetY)&&t.onAdd(t),t.onMouseMove=hh,t.onMouseLeave=uh,t.onMouseDown=dh,t.onShowInput=lh,t.onInput=ch,t.onValue=gh,t.onBeforeValue=yh,t.onMouseEnter=xh,t.onWheel=mh,t.onDestroy=wh),t.data.length!==t.rowPos.length&&(t.initWorldRect=null,t.calculative.isUpdateData=!0,t.onValue(t)),t.data[0].length!==t.colPos.length&&(t.initWorldRect=null,t.calculative.isUpdateData=!0,t.onValue(t));const i=t.calculative.canvas.store;if(t.calculative.canvas.store.data,t.calculative.canvas.store.options,t.color=t.color||i.styles.color,t.textColor=t.textColor||t.color||i.styles.textColor,t.activeColor=t.activeColor||i.styles.activeColor,t.hoverColor=t.hoverColor||i.styles.hoverColor,t.activeBackground=t.activeBackground||i.styles.activeBackground,t.hoverBackground=t.hoverBackground||i.styles.hoverBackground,!t.hasHeader){e.save(),e.beginPath();const{x:s,y:r,width:a,height:o}=t.calculative.worldRect;e.fillStyle="#fff0",e.rect(s-1,r-1,a+2,o+2),e.fill(),e.clip()}oh(e,t),nh(e,t),rh(e,t),e.restore(),t.isFirstTime=!1}function rh(e,t){if(!t.calculative.hover||!t.calculative.hoverCell||t.calculative.isInput||!t.calculative.isHover)return;let i=t.calculative.worldRect,s=t.calculative.canvas.mousePos;if(!(s.x>i.x&&s.x<i.x+i.width&&s.y>i.y&&s.y<i.y+i.height)){t.calculative.hover=!1,t.calculative.isHover=!1,t.calculative.hoverCell=void 0;return}const{row:r,col:a}=t.calculative.hoverCell,{x:o,y:l}=t.calculative.canvas.mousePos;if(!t.data[r])return;let n=t.data[r][a];if(typeof n=="object"||!n)return;e.save(),e.beginPath(),e.textAlign="start",e.textBaseline="middle",e.font=e.font=(t.calculative.fontStyle||"")+" normal "+(t.calculative.fontWeight||"")+" "+(t.calculative.fontSize||12)+"px "+t.calculative.fontFamily;const h=e.measureText(n).width;e.beginPath(),e.fillStyle="#fff",e.strokeStyle="#000",e.moveTo(o,l),e.rect(o-10,l,h+20,20),e.fill(),e.stroke(),e.beginPath(),e.fillStyle="#000",e.fillText(n,o,l+10),e.restore()}function ah(e){const t=[],i=[],s={};e.rowHeight||(e.rowHeight=40),e.colWidth||(e.colWidth=150);let r=0;const a=e.styles&&e.styles.filter(y=>y.col!==void 0&&y.row===void 0&&y.width);let o={};a&&a.forEach(y=>{o[y.col]=y.width});for(let y=0;y<e.data[0].length;y++){r+=(o[y]||e.colWidth)*e.calculative.canvas.store.data.scale,t.push(r);let p=e.styles&&e.styles.filter(b=>b.col===y&&b.row===void 0);p&&(s[y]=p[0])}let l=0;const n=e.styles&&e.styles.filter(y=>y.col===void 0&&y.row!==void 0&&y.height);let h={};n&&n.forEach(y=>{h[y.row]=y.height});let c=l;for(let y=0;y<e.data.length;y++)l+=(h[y]||e.rowHeight)*e.calculative.canvas.store.data.scale,i.push(l),y<e.maxNum&&(c=l);if(e.calculative.maxOffsetY=(l-c)/e.calculative.canvas.store.data.scale,e.initWorldRect)return;e.colPos=t,e.rowPos=i,e.colStyle=s,e.initScale=e.calculative.canvas.store.data.scale,e.tableWidth=r,e.tableHeight=c||l;let f=c||l,u=r,d=f;e.parentId&&(r=u/e.calculative.canvas.parent.store.pens[e.parentId].calculative.worldRect.width,d=f/e.calculative.canvas.parent.store.pens[e.parentId].calculative.worldRect.height),e.calculative.width=r,e.calculative.height=d,e.calculative.width=r,e.calculative.height=d,e.height||(e.height=e.calculative.height),e.width||(e.width=e.calculative.width);let v=e.x,g=e.y;if(e.parentId){let y=e.calculative.canvas.store.pens[e.parentId];v=y.calculative.worldRect.x+y.calculative.worldRect.width*e.x,g=y.calculative.worldRect.y+y.calculative.worldRect.height*e.y}e.calculative.worldRect={x:v,y:g,height:f,width:u},e.width=e.calculative.width,e.height=e.calculative.height,e.initWorldRect||(e.initWorldRect={width:e.calculative.worldRect.width,height:e.calculative.worldRect.height}),bt(e.calculative.worldRect)}function oh(e,t){if(!t.colPos)return;const{x:i,y:s,width:r,height:a,ex:o,ey:l}=t.calculative.worldRect;e.save(),e.beginPath(),e.strokeStyle=t.color;let n=t.calculative.borderRadius||0,h=n;n<1&&(n=r*n,h=a*h);let c=n<h?n:h;if(r<2*c&&(c=r/2),a<2*c&&(c=a/2),e.moveTo(i+c,s),e.arcTo(o,s,o,l,c),e.arcTo(o,l,i,l,c),e.arcTo(i,l,i,s,c),e.arcTo(i,s,o,s,c),t.background&&(e.fillStyle=t.background,e.fill()),t.bordered!==!1&&(e.strokeStyle=t.borderColor||t.color||"#424B61",e.stroke()),t.hLine!==!1){let f=t.rowPos[t.rowPos.length-1];t.hasHeader&&(e.beginPath(),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y+t.rowPos[0]*t.calculative.worldRect.height/t.tableHeight),e.lineTo(t.calculative.worldRect.ex,t.calculative.worldRect.y+t.rowPos[0]*t.calculative.worldRect.height/t.tableHeight),e.strokeStyle=t.borderColor||t.color||"#424B61",e.stroke());for(const u of t.rowPos){if(u===f)continue;const d=u*t.calculative.worldRect.height/t.tableHeight-t.offsetY*t.calculative.canvas.store.data.scale;if(t.hasHeader){if(d<0+t.rowPos[0]||d>t.calculative.worldRect.height)continue}else if(d<0||d>t.calculative.worldRect.height)continue;e.beginPath(),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y+d),e.lineTo(t.calculative.worldRect.ex,t.calculative.worldRect.y+d),e.strokeStyle=t.borderColor||t.color||"#424B61",e.stroke()}}if(t.vLine!==!1){let f=t.colPos[t.colPos.length-1];t.colPos.forEach((u,d)=>{if(u===f)return;const v=u*t.calculative.worldRect.width/t.tableWidth;e.beginPath(),e.moveTo(t.calculative.worldRect.x+v,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+v,t.calculative.worldRect.ey),e.strokeStyle=t.borderColor||t.color||"#424B61",e.stroke()})}e.restore()}function nh(e,t){var s,r,a,o,l;if(!t.colPos)return;t.calculative.texts||(t.calculative.texts=[]);const i=1;for(let n=0;n<t.rowPos.length;n++){if(t.hasHeader&&n===1){e.save(),e.beginPath();const{x:c,y:f,width:u,height:d}=t.calculative.worldRect;e.fillStyle="#fff0",e.rect(c-1,f+t.rowPos[0]*t.calculative.worldRect.height/t.tableHeight-1,u+2,d-t.rowPos[0]*t.calculative.worldRect.height/t.tableHeight+2),e.fill(),e.clip()}let{style:h}=fh(t,n);for(let c=0;c<t.colPos.length;c++){let{value:f,style:u}=ua(t,n,c),d=!0;if(Array.isArray(u)&&u.length>0){let E=0;u.forEach((z,U)=>{z.wheres&&z.wheres.every(R=>{var B,j,X;let C=It((X=(j=(B=t.calculative)==null?void 0:B.canvas)==null?void 0:j.store)==null?void 0:X.options,"attr",`return attr ${R.comparison} ${R.value}`);const _=C(f);return C=null,_})&&(E=U)}),u=u[E]}else u.wheres&&Array.isArray(u.wheres)&&(d=!1,d=u.wheres.every(function(E){var T,R,C;let z=It((C=(R=(T=t.calculative)==null?void 0:T.canvas)==null?void 0:R.store)==null?void 0:C.options,"attr",`return attr ${E.comparison} ${E.value}`);const U=z(f);return z=null,U}));let v=t.color,g=t.textColor||t.color,y=null,p=null,b=null,m=null;d&&(v=u.color||h.color||t.color,g=u.textColor||h.textColor||t.textColor,y=u.background||h.background,p=(u.fontSize||h.fontSize||0)*t.calculative.canvas.store.data.scale,b=u.fontWeight||h.fontWeight,m=u.fontStyle||h.fontStyle);let k;t.stripe&&(t.hasHeader!==!1?n%2===1&&(y=y||t.stripeColor||"#407FFF1F"):n%2===0&&(y=y||t.stripeColor||"#407FFF1F")),t.calculative.active&&((s=t.calculative.activeCell)==null?void 0:s.row)===n&&((r=t.calculative.activeCell)==null?void 0:r.col)===c&&(v=t.activeColor,y=t.activeBackground,k=v,g=t.activeTextColor||t.activeColor),t.calculative.hover&&((a=t.calculative.hoverCell)==null?void 0:a.row)===n&&((o=t.calculative.hoverCell)==null?void 0:o.col)===c&&(v=t.hoverColor,y=t.hoverBackground,g=t.hoverTextColor||t.hoverColor,k=v);const A=fa(t,n,c);if(A.y+A.height<t.calculative.worldRect.y||A.y>t.calculative.worldRect.height+t.calculative.worldRect.y)continue;y&&(e.save(),e.beginPath(),e.fillStyle=y,e.fillRect(A.x,A.y,A.width+.25*t.calculative.canvas.store.data.scale,A.height),e.restore()),k&&(e.save(),e.beginPath(),e.strokeStyle=k,e.strokeRect(A.x,A.y,A.width,A.height),e.restore()),t.calculative.worldTextRect=A;let S=t.calculative.texts[n];if(t.calculative.texts[n]||(S=[],t.calculative.texts.push(S)),S[c]==null){if(typeof f=="object"){const E=t.styles&&t.styles.filter(z=>z.col===c&&z.row===void 0&&z.pens);if(E.length>0){if(S[c]="",t.isFirstTime){t.maxNum&&t.hasHeader&&n>=t.maxNum&&(f.visible=!1);let z=JSON.parse(JSON.stringify(E[0].pens));z.forEach(U=>{Object.assign(U,{row:n,col:c},f),U.activeBackground=U.background,U.hoverBackground=U.background,U.activeColor=U.color,U.hoverColor=U.color,U.activeTextColor=U.textColor,U.hoverTextColor=U.textColor,U.height*=t.calculative.canvas.store.data.scale,U.width*=t.calculative.canvas.store.data.scale}),vh(t,A,z),t.calculative.canvas.parent.pushChildren(t,z)}continue}}else f===void 0?S[c]="":S[c]=f.text||f+"";if(!S[c])continue;S[c]=Ne(t,S[c])}if(!S[c])continue;e.save(),e.beginPath(),e.fillStyle=g,e.textAlign="center",e.textBaseline="middle",e.font=(m||t.calculative.fontStyle||"")+" normal "+(b||t.calculative.fontWeight||"")+" "+(p||t.calculative.fontSize||12)*i+"px "+t.calculative.fontFamily;let I=t.colStyle&&((l=t.colStyle[c])==null?void 0:l.textAlign);if(I&&(e.textAlign=I),S[c].length===1)I==="left"?e.fillText(S[c][0],A.x,A.y+A.height/2):I==="right"?e.fillText(S[c][0],A.x+A.width,A.y+A.height/2):e.fillText(S[c][0],A.x+A.width/2,A.y+A.height/2);else{const z=(p||t.calculative.fontSize)*t.calculative.lineHeight*i,U=S[c].length*z;let T=(A.height-U)/2;I==="left"?S[c].forEach((R,C)=>{e.fillText(R,A.x,A.y+T+(C+.55)*z)}):I==="right"?S[c].forEach((R,C)=>{e.fillText(R,A.x+A.width,A.y+T+(C+.55)*z)}):S[c].forEach((R,C)=>{e.fillText(R,A.x+A.width/2,A.y+T+(C+.55)*z)})}e.restore()}}}function ca(e){var t;bs(e),(t=e.children)!=null&&t.length||(e.isFirstTime=!0),e.offsetY||(e.offsetY=0),ah(e)}function lh(e,t){if(!e.calculative.hoverCell)return;const{value:i}=ua(e,e.calculative.hoverCell.row,e.calculative.hoverCell.col);if(typeof i=="object")return;e.calculative.isHover=!1,e.calculative.isInput=!0,e.calculative.canvas.render(),e.calculative.inputCell=e.calculative.hoverCell;const s=fa(e,e.calculative.hoverCell.row,e.calculative.hoverCell.col);e.calculative.tempText=i.text||i+"",e.calculative.canvas.showInput(e,s,"#ffffff")}function ch(e,t){e.calculative.inputCell&&(da(e,e.calculative.inputCell.row,e.calculative.inputCell.col,t),e.calculative.isInput=!1,e.calculative.isHover=!0,e.calculative.canvas.render())}function hh(e,t){e.timer&&(e.calculative.isHover=!1,clearTimeout(e.timer)),e.timer=setTimeout(()=>{e.calculative.isHover=!0,e.calculative.canvas.render()},500),e.calculative.hoverCell=ha(e,t),e.calculative.canvas.render()}function uh(e,t){bs(e),e.calculative.hoverCell=void 0,e.calculative.canvas.render()}function dh(e,t){e.calculative.activeCell=ha(e,t),e.calculative.canvas.render()}function ha(e,t){const i=e.calculative.worldRect.width/e.tableWidth,s=e.calculative.worldRect.height/e.tableHeight,r={row:0,col:0};for(let a=0;a<e.colPos.length;a++)t.x>e.calculative.worldRect.x+e.colPos[a]*i&&(r.col=a+1);for(let a=0;a<e.rowPos.length;a++)t.y>e.calculative.worldRect.y+e.rowPos[a]*s-e.offsetY*e.calculative.canvas.store.data.scale&&(r.row=a+1);return r}function ua(e,t,i){if(!e.data||!Array.isArray(e.data))return;const s=e.data[t],r=e.styles&&e.styles.filter(a=>a.row===t&&a.col===i);if(Array.isArray(s))return{value:s[i],style:(r==null?void 0:r.length)>0?r.length>1?r:r[0]:{}};if(!s.data||!Array.isArray(s.data))return}function fh(e,t){if(!e.data||!Array.isArray(e.data))return;const i=e.data[t],s=e.styles&&e.styles.filter(r=>r.row===t&&r.col===void 0);if(Array.isArray(i))return{value:i,style:(s==null?void 0:s.length)>0?s[0]:{}};if(!i.data||!Array.isArray(i.data))return}function da(e,t,i,s){if(!e.data||!Array.isArray(e.data))return;e.isFirstTime=!1,e.calculative.texts=void 0;let r=e.data[t];r&&(r[i]instanceof Object||(r[i]=s),e.calculative.canvas.store.emitter.emit("valueUpdate",e))}function fa(e,t,i){const s=e.calculative.worldRect.width/e.tableWidth,r=e.calculative.worldRect.height/e.tableHeight;let a=0,o=e.colPos[i]*s;i>0&&(a=e.colPos[i-1]*s);let l=0,n=e.rowPos[t]*r;t>0&&(l=e.rowPos[t-1]*r);let h=e.offsetY*e.calculative.canvas.store.data.scale;return t===0&&e.hasHeader&&(h=0),{x:e.calculative.worldRect.x+a,y:e.calculative.worldRect.y+l-h,ex:e.calculative.worldRect.x+o,ey:e.calculative.worldRect.y+n-h,width:o-a,height:n-l}}function vh(e,t,i){if(!(i&&i.length))return;const s=e.calculative.worldRect.width/e.tableWidth,r=e.calculative.worldRect.height/e.tableHeight;let a=1,o=1;e.initWorldRect&&(e.calculative.worldRect.width!==e.initWorldRect.width&&(a=e.calculative.worldRect.width/e.initWorldRect.width),e.calculative.worldRect.height!==e.initWorldRect.height&&(o=e.calculative.worldRect.height/e.initWorldRect.height));let l=0,n=0,h=0;const c=e.calculative.canvas.store.data.scale;if(i.length>1){for(const f of i)n+f.width*s+20*c*s<t.width?(f.x=t.x+n+10*c*s,f.y=t.y+h+10*c*r,n+=(f.width+10*c)*s,l=Math.max(l,h+(f.height+10*c)*r)):(n=0,h=l,f.x=t.x+n+10*c*s,f.y=t.y+h+10*c*r,l+=(f.height+10*c)*r);if(l+20*c*r<t.height){const f=(t.height-l-10*c*r)/2;for(const u of i)u.y+=f}}else i[0].x=t.x+(t.width-i[0].width)/2,i[0].y=t.y+(t.height-i[0].height)/2;i.forEach(f=>{f.width=f.width*a,f.height=f.height*o})}function gh(e){if(e.calculative.isUpdateData){delete e.calculative.isUpdateData;let t=K(e.children);e.children=[],ca(e),t&&t.forEach(i=>{e.calculative.canvas.delForce(e.calculative.canvas.findOne(i))}),e.calculative.texts=void 0}}function yh(e,t){if(e.calculative.isUpdateData=!1,e.swiper!==void 0&&(e.swiper?bs(e):ws(e)),t.styles&&(e.initWorldRect=void 0),t.table||t.col==null&&t.row==null){if(t.dataY){const s=e.replaceMode;let r=[];return s?s===Ei.Replace?(r=e.data,t.dataX&&t.dataX.forEach((a,o)=>{r[a]=t.dataY[o]})):s===Ei.ReplaceAll&&(t.dataX?r[0]=t.dataX:r[0]=e.data[0],r=r.concat(t.dataY)):r=e.data.concat(t.dataY),delete t.dataX,delete t.dataY,e.calculative.isUpdateData=!0,Object.assign(t,{data:r})}(t.data||t.styles||t.maxNum||t.rowHeight||t.colWidth)&&(e.calculative.isUpdateData=!0,e.initWorldRect=null);for(let s of Object.keys(t))s.includes("data.")&&(e.calculative.isUpdateData=!0);return t}let i=e.data[t.row];return i&&(i[t.col]instanceof Object||(i[t.col]=t.value),da(e,t.row,t.col,t.value),e.calculative.canvas.render(),delete t.col,delete t.row),t}function mh(e,t){if(!e.locked&&!e.calculative.canvas.store.data.locked||!e.maxNum)return;let i=0;t.deltaY>0?i=4:i=-4,rs(e,i)}function rs(e,t){var i;e.offsetY||(e.offsetY=0),e.offsetY+=t,e.offsetY>e.calculative.maxOffsetY&&(e.offsetY=e.calculative.maxOffsetY),e.offsetY<0&&(e.offsetY=0),(i=e.children)==null||i.forEach(s=>{const r=e.calculative.canvas.store.pens[s];ph(e,r)}),e.calculative.canvas.render()}function ph(e,t){if(!t)return;t.oldY||(t.oldY=t.y);const{y:i,height:s}=t.calculative.worldRect,{y:r,height:a}=e.calculative.worldRect,o=e.calculative.canvas.store.data.scale;e.calculative.worldRect.height/e.tableHeight;const l=e.rowHeight;t.y=t.oldY-e.offsetY*o/e.calculative.worldRect.height;const n=l*(e.initScale||1)/e.tableHeight*e.maxNum;if(e.calculative.canvas.updatePenRect(t),e.hasHeader)if(t.y<e.rowPos[0]/e.tableHeight){if(t.calculative.visible=!1,t.visible=!1,t.y<e.rowPos[0]/e.tableHeight/2){t.oldY+=n;let h=t.row+e.maxNum;if(!e.data[h])return;let c=K(e.data[h][t.col]);c.background&&(c.activeBackground=c.background,c.hoverBackground=c.background),c.color&&(c.hoverColor=c.color,c.activeColor=c.color),c.textColor&&(c.activeTextColor=c.textColor,c.hoverTextColor=c.textColor),Object.assign(t,c,{row:h}),Object.assign(t.calculative,c,{row:h})}}else if(t.y+t.height>1){if(t.calculative.visible=!1,t.visible=!1,t.y+t.height/2>1){t.oldY-=n;let h=t.row-e.maxNum;if(!e.data[h])return;let c=K(e.data[h][t.col]);c.background&&(c.activeBackground=c.background,c.hoverBackground=c.background),c.color&&(c.hoverColor=c.color,c.activeColor=c.color),c.textColor&&(c.activeTextColor=c.textColor,c.hoverTextColor=c.textColor),Object.assign(t,c,{row:h}),Object.assign(t.calculative,c,{row:h})}}else t.visible=!0,t.calculative.visible=!0;else if(t.y<0){if(t.calculative.visible=!1,t.visible=!1,t.y<-l/e.tableHeight/2){t.oldY+=n;let h=t.row+e.maxNum;if(!e.data[h])return;let c=K(e.data[h][t.col]);c.background&&(c.activeBackground=c.background,c.hoverBackground=c.background),c.color&&(c.hoverColor=c.color,c.activeColor=c.color),c.textColor&&(c.activeTextColor=c.textColor,c.hoverTextColor=c.textColor),Object.assign(t,c,{row:h}),Object.assign(t.calculative,c,{row:h})}}else if(t.y+t.height>1){if(t.calculative.visible=!1,t.visible=!1,t.y+t.height/2>1){t.oldY-=n;let h=t.row-e.maxNum;if(!e.data[h])return;let c=K(e.data[h][t.col]);c.background&&(c.activeBackground=c.background,c.hoverBackground=c.background),c.color&&(c.hoverColor=c.color,c.activeColor=c.color),c.textColor&&(c.activeTextColor=c.textColor,c.hoverTextColor=c.textColor),Object.assign(t,c,{row:h}),Object.assign(t.calculative,c,{row:h})}}else t.calculative.visible=!0,t.visible=!0}function wh(e){ws(e)}function ws(e){e.interval&&(globalThis.clearInterval(e.interval),e.interval=null)}function bs(e){if(e.maxNum&&e.swiper){if(e.interval)return;e.interval=globalThis.setInterval(()=>{e.offsetY>=e.calculative.maxOffsetY?(e.offsetY=0,bh(e)):e.offsetY%e.rowHeight?rs(e,1):(e.calculative.stap||(e.calculative.stap=0),e.calculative.stap+=1,e.calculative.stap==12&&(e.calculative.stap=0,rs(e,1)))},50)}}function bh(e){var t;(t=e.children)==null||t.forEach(i=>{const s=e.rowHeight,r=e.calculative.canvas.store.pens[i];if(!r)return;const a=s*(e.initScale||1)/e.tableHeight*e.maxNum;r.oldY-=a;const o=r.row-e.maxNum;if(!e.data[o])return;let l=K(e.data[o][r.col]);l.background&&(l.activeBackground=l.background,l.hoverBackground=l.background),l.color&&(l.hoverColor=l.color,l.activeColor=l.color),l.textColor&&(l.activeTextColor=l.textColor,l.hoverTextColor=l.textColor),r.calculative.visible=!0,r.visible=!0,Object.assign(r,l,{row:o}),Object.assign(r.calculative,l,{row:o})}),e.calculative.canvas.render()}function xh(e){ws(e)}function kh(e,t){t.onClick||(t.onClick=Rh,t.setTheme=Th);let i=t.calculative.worldRect.x,s=t.calculative.worldRect.y,r=t.calculative.worldRect.width,a=t.calculative.worldRect.height;r<a*1.5&&(r=1.5*a),e.beginPath(),e.arc(i+a/2,s+a/2,a/2,Math.PI/2,Math.PI*3/2),e.lineTo(i+r-a/2,s),e.arc(i+r-a/2,s+a/2,a/2,-Math.PI/2,Math.PI/2),e.lineTo(i+a/2,s+a),t.checked?(e.fillStyle=t.onColor,(t.disabled||t.disable)&&(e.fillStyle=t.disableOnColor||St(.6,t.onColor)),t.lineWidth&&(e.strokeStyle=t.onStrokeColor,e.stroke()),e.fill(),e.closePath(),e.beginPath(),e.fillStyle="#ffffff",e.moveTo(i+a*2,s+a/2),e.arc(i+r-a/2,s+a/2,a/2>2?a/2-2:1,0,Math.PI*2),e.fill()):(e.fillStyle=t.offColor,(t.disabled||t.disable)&&(e.fillStyle=t.disableOffColor||St(.6,t.offColor)),t.lineWidth&&(e.strokeStyle=t.offStrokeColor,e.stroke()),e.fill(),e.closePath(),e.beginPath(),e.fillStyle="#ffffff",e.moveTo(i+a,s+a/2),e.arc(i+a/2,s+a/2,a/2>2?a/2-2:1,0,Math.PI*2),e.fill()),e.closePath()}function Rh(e){e.disableDefaultClick||e.disabled||e.disable||(e.checked=!e.checked,e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render())}function Th(e,t){for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)){const s=t[i];e.hasOwnProperty(i)&&(e[i]=s),e.calculative.hasOwnProperty(i)&&(e.calculative[i]=s)}e.onStrokeColor=t.borderColor,e.offStrokeColor=t.borderColor}function Ch(e,t){t.onAdd||(t.onAdd=$e,t.onResize=$e,t.onMove=$e,t.onMouseMove=Ah,t.onMouseDown=va,t.onValue=Sh,t.onBeforeValue=Ph,t.onMouseUp=_h,t.setTheme=Ih),t.calculative.barRect||$e(t);const i=t.calculative.canvas.store;t.calculative.canvas.store.options;let s=t.background;t.disabled&&(s=t.disabledBackground||St(.6,s)),e.fillStyle=s,e.beginPath();let r=t.calculative.worldRect.x+t.calculative.barRect.x,a=t.calculative.worldRect.y+t.calculative.barRect.y,o=t.calculative.barRect.width,l=t.calculative.barRect.height,n=l/2;e.moveTo(r+n,a),e.arcTo(r+o,a,r+o,a+l,n),e.arcTo(r+o,a+l,r,a+l,n),e.arcTo(r,a+l,r,a,n),e.arcTo(r,a,r+o,a,n),e.fill();let h=t.activeColor||i.styles.activeColor;t.disabled&&(h=t.disabledColor||St(.6,h)),e.fillStyle=h,e.beginPath(),o=t.calculative.ballRect.x,e.moveTo(r+n,a),e.arcTo(r+o,a,r+o,a+l,n),e.arcTo(r+o,a+l,r,a+l,n),e.arcTo(r,a+l,r,a,n),e.arcTo(r,a,r+o,a,n),e.fill(),e.fillStyle=t.btnBackground||"#fff",e.strokeStyle=h,e.lineWidth=2,e.beginPath();const c=t.calculative.canvas.store.data.scale;r=t.calculative.worldRect.x+t.calculative.ballRect.x+20*c,a=t.calculative.worldRect.y+t.calculative.ballRect.y+t.calculative.ballRect.height/2,e.lineWidth=t.calculative.ballRect.width/10,e.arc(r,a,t.calculative.ballRect.width/2,0,Math.PI*2),e.fill(),e.stroke()}function $e(e){if(e._textWidth||(e._textWidth=e.textWidth||50,e._fontSize=e.fontSize||12),e.textWidth=e.calculative.worldRect.width,e.calculative.textWidth=e.textWidth,e.unit||(e.unit="%"),e.sliderWidth||(e.sliderWidth=e.width),e.sliderHeight||(e.sliderHeight=e.height),!e.calculative.worldRect)return;e.calculative.worldRect.width/e.sliderWidth;const t=e.calculative.worldRect.height/e.sliderHeight,i=e.calculative.canvas.store.data.scale,s=e.calculative.worldRect.width-3*e.calculative.fontSize;e.calculative.barRect={x:0+20*i,y:(e.calculative.worldRect.height-e.barHeight*t)/2,width:s-20*i,height:e.barHeight*t},bt(e.calculative.barRect),xs(e)}function xs(e){const t=e.calculative.barRect.height*3.5,i=e.calculative.barRect.width*e.value/100;e.calculative.ballRect={x:i,y:(e.calculative.worldRect.height-t)/2,width:t,height:t},bt(e.calculative.ballRect),e.calculative.text=e.value+e.unit,Yt(e)}function va(e,t){if(e.disabled)return;let i=0;const s=e.calculative.canvas.store.data.scale,r=t.x-e.calculative.worldRect.x-20*s;if(r>e.calculative.barRect.width)i=100;else{let a=r/e.calculative.barRect.width*100;if(a<1?i=0:a>99?i=100:i=Math.round(a),i<e.min||i>e.max||i<0||i>100)return}e.value=i,xs(e),e.calculative.text=e.value+e.unit,Yt(e),e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render()}function Ah(e,t){e.calculative.canvas.mouseDown&&va(e,t)}function Sh(e){e.calculative.isUpdateData&&(delete e.calculative.isUpdateData,$e(e)),xs(e)}function Ph(e,t){return e.calculative.isUpdateData=!1,(t.textWidth||t.barHeight)&&(t.textWidth&&(e._textWidth=0),e.calculative.isUpdateData=!0),t}function Ih(e,t){for(const i in t)if(Object.prototype.hasOwnProperty.call(t,i)){const s=t[i];e.hasOwnProperty(i)&&(e[i]=s),e.calculative.hasOwnProperty(i)&&(e.calculative[i]=s)}e.background=t.sliderBg,e.calculative.background=t.sliderBg,e.btnBackground=t.sliderBtnBg,e.calculative.btnBackground=t.sliderBtnBg,e.activeColor=t.tabActiveBg,e.calculative.activeColor=t.tabActiveBg}function _h(e,t){e.calculative.canvas.store.emitter.emit("change",e)}function Eh(e,t){t.onMouseDown||(t.onMouseDown=Mh),t.options||(t.options=t.data);let i=t.calculative.worldRect.x,s=t.calculative.worldRect.y,r=t.calculative.worldRect.height;t.calculative.worldRect.width;const{fontStyle:a,fontWeight:o,fontSize:l,fontFamily:n,lineHeight:h}=t.calculative;let c=2;e.beginPath(),e.moveTo(i,s),e.arcTo(i+r,s,i+r,s+r,c),e.arcTo(i+r,s+r,i,s+r,c),e.arcTo(i,s+r,i,s,c),e.arcTo(i,s,i+r,s,c),e.strokeStyle="#d9d9d9",e.fillStyle="#ffffff00",t.checked&&(e.fillStyle=t.background||"#1890ff",e.strokeStyle=t.background||"#1890ff"),(t.isForbidden||t.disabled)&&(e.fillStyle=t.disabledBackground||St(.6,t.background)||"#ebebeb",e.strokeStyle=t.disabledColor||St(.6,t.color)||"#d9d9d9"),e.closePath(),e.fill(),e.stroke(),e.save(),t.checked&&(e.beginPath(),e.lineWidth=r/10,e.strokeStyle="#ffffff",e.moveTo(i+102/506*r,s+r/2),e.lineTo(i+220/506*r,s+346/460*r),e.lineTo(i+404/506*r,s+142/460*r),e.stroke()),e.restore(),e.save(),e.fillStyle=t.disabled||t.isForbidden?t.disabledTextColor||St(.6,t.textColor||t.color)||"#00000040":Gt(t,t.calculative.canvas.parent.store)||"#000000d9",e.textAlign="start",e.textBaseline="middle",e.font=_t({fontStyle:a,fontWeight:o,fontFamily:n||t.calculative.canvas.parent.store.options.fontFamily,fontSize:l,lineHeight:h}),e.fillText(t.value+"",i+r+10,s+r/2),e.restore()}function Mh(e,t){e.isForbidden||(e.checked=!e.checked,e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render())}function Lh(e,t){t.options||(t.options=t.data),t.onAdd||(t.onAdd=Dh,t.optionPos||(t.onAdd(t),t.calculative.canvas.parent.active([t])),t.onMouseDown=Oh,t.onValue=Bh,t.onBeforeValue=Nh);let i=t.calculative.worldRect.x,s=t.calculative.worldRect.y,r=t.calculative.worldRect.height,a=t.calculative.worldRect.width;if(!t.optionPos)return;const{fontStyle:o,fontWeight:l,fontSize:n,fontFamily:h,lineHeight:c}=t.calculative;if(t.direction=="horizontal")for(let f=0;f<t.optionPos.length;f++){const u=t.optionPos[f]*a/t.checkboxWidth,d=t.options[f].isForbidden||t.disabled;e.beginPath(),e.arc(i+u+r/2,s+r/2,r/2,0,Math.PI*2),e.strokeStyle="#d9d9d9",e.fillStyle="#ffffff00",t.options[f].text===t.checked&&(e.strokeStyle=t.options[f].background||t.background||"#1890ff"),d&&(e.fillStyle=t.disabledBackground||St(.6,t.background)||"#ebebeb",e.strokeStyle=t.disabledColor||St(.6,t.color)||"#d9d9d9",t.options[f].text===t.checked&&(e.fillStyle="#ffffff00")),e.closePath(),e.fill(),e.stroke(),e.save(),t.options[f].text===t.checked&&(e.beginPath(),e.strokeStyle=t.options[f].background?t.options[f].background+"20":t.background||"#1890ff20",d&&(e.strokeStyle=t.disabledBackground||St(.6,t.background)||"#ebebeb"),e.arc(i+r/2+u,s+r/2,r/2+1.5,0,Math.PI*2),e.stroke(),e.closePath(),e.beginPath(),e.fillStyle=t.options[f].background||t.background||"#1890ff",d&&(e.fillStyle=t.disabledBackground||St(.6,t.background)||"#ebebeb"),e.arc(i+r/2+u,s+r/2,r/4,0,Math.PI*2),e.fill(),e.closePath()),e.restore(),e.save(),e.fillStyle=d?t.disabledTextColor||"#00000040":Gt(t,t.calculative.canvas.parent.store)||"#000000d9";const v=t.calculative.worldRect.height*14/16;e.textAlign="start",e.textBaseline="middle",e.font=_t({fontStyle:o,fontWeight:l,fontFamily:h||t.calculative.canvas.parent.store.options.fontFamily,fontSize:v,lineHeight:c}),e.fillText(t.options[f].text,i+r+u+10/t.checkboxWidth*a,s+r/2),e.restore()}else if(t.direction=="vertical"){const f=t.optionHeight*r/t.checkboxHeight;for(let u=0;u<t.optionPos.length;u++){const d=t.optionPos[u]*r/t.checkboxHeight,v=t.options[u].isForbidden;e.beginPath(),e.arc(i+f/2,s+f/2+d,f/2,0,Math.PI*2),e.strokeStyle="#d9d9d9",e.fillStyle="#ffffff00",t.options[u].text===t.checked&&(e.strokeStyle=t.options[u].background||"#1890ff"),v&&(e.fillStyle="#ebebeb",e.strokeStyle="#d9d9d9"),e.closePath(),e.fill(),e.stroke(),e.save(),!v&&t.options[u].text===t.checked&&(e.beginPath(),e.strokeStyle=t.options[u].background?t.options[u].background+"20":"#1890ff20",e.arc(i+f/2,s+f/2+d,f/2+1.5,0,Math.PI*2),e.stroke(),e.closePath(),e.beginPath(),e.fillStyle=t.options[u].background||"#1890ff",e.arc(i+f/2,s+f/2+d,f/4,0,Math.PI*2),e.fill(),e.closePath()),e.restore(),e.save(),e.fillStyle=v?"#00000040":Gt(t,t.calculative.canvas.parent.store)||"#000000d9";const g=14*t.calculative.worldRect.height/t.checkboxHeight;e.textAlign="start",e.textBaseline="middle",e.font=_t({fontStyle:o,fontWeight:l,fontFamily:h||t.calculative.canvas.parent.store.options.fontFamily,fontSize:g,lineHeight:c}),e.fillText(t.options[u].text,i+f+10,s+f/2+d),e.restore()}}}function Dh(e){la(e)}function Oh(e,t){if(e.direction=="horizontal")for(let i=0;i<e.optionPos.length;i++)!e.options[i].isForbidden&&t.x>e.calculative.worldRect.x+e.optionPos[i]*e.calculative.worldRect.width/e.checkboxWidth&&t.x<e.calculative.worldRect.x+(e.optionPos[i]+e.height)/e.checkboxWidth*e.calculative.worldRect.width+na(e.options[i].text,e)+10/e.checkboxWidth*e.calculative.worldRect.width&&(e.checked=e.options[i].text,e.calculative.canvas.store.emitter.emit("valueUpdate",e));else if(e.direction=="vertical"){const i=e.calculative.worldRect.height/e.checkboxHeight;for(let s=0;s<e.optionPos.length;s++)!e.options[s].isForbidden&&t.y>e.calculative.worldRect.y+e.optionPos[s]*i&&t.y<e.calculative.worldRect.y+(e.optionPos[s]+e.optionHeight)*i&&(e.checked=e.options[s].text,e.calculative.canvas.store.emitter.emit("valueUpdate",e))}e.calculative.canvas.render()}function Bh(e){e.calculative.flag&&la(e)}function Nh(e,t){return e.calculative.flag=!1,(t.options!==void 0||t.direction!==void 0||t.optionInterval!==void 0||t.optionHeight!==void 0)&&(e.calculative.flag=!0),t}function Iu(){return{radio:Lh,switch:kh,slider:Ch,checkbox:Eh,table:ur,table2:ur}}function Fh(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=o/6,n=a/4;if(i.moveTo(s+n*2,r+0),i.lineTo(s+n*2,r+l),i.moveTo(s,r+l+n*2),i.arc(s+n*2,r+l+n*2,n*2,Math.PI*1,Math.PI*2,!1),i.lineTo(s+n*4,r+l*5),i.lineTo(s,r+l*5),i.lineTo(s,r+l+n*2),i.moveTo(s+n,r+l*5),i.lineTo(s+n,r+l*6),i.moveTo(s+n*2,r+l*5),i.lineTo(s+n*2,r+l*6),i.moveTo(s+n*3,r+l*5),i.lineTo(s+n*3,r+l*6),i.closePath(),i instanceof Path2D)return i}function dr(e){const t=[{x:.5,y:0},{x:.25,y:1},{x:.5,y:1},{x:.75,y:1}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function zh(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=o-a,n=.5*a;if(i.moveTo(s+a/2,r),i.lineTo(s+a/2,r+l),i.moveTo(s+a,r+n+l),i.arc(s+a/2,r+n+l,n,0,Math.PI*2,!1),i.closePath(),i instanceof Path2D)return i}function fr(e){const t=[{x:.5,y:0},{x:.5,y:1}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function jh(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=o/2,n=a/5;if(i.moveTo(s,r+l),i.lineTo(s+n,r+l),i.moveTo(s+n*5,r+l),i.ellipse(s+n*3,r+l,2*n,l,0,0,Math.PI*2),i.closePath(),i instanceof Path2D)return i}function Wh(e){const t=[{x:.6,y:0},{x:1,y:.5},{x:.6,y:1},{x:0,y:.5}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function Hh(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=o/4,n=.5*a;if(i.moveTo(s+n,r),i.lineTo(s+n,r+l),i.moveTo(s,r+l),i.rect(s,r+l,n*2,l*2),i.moveTo(s+n,r+3*l),i.lineTo(s+n,r+4*l),i.closePath(),i instanceof Path2D)return i}function Vh(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=o/8,n=.25*a;if(i.moveTo(s+n*2,r),i.lineTo(s+n*2,r+l*2),i.lineTo(s+n*3,r+l*3),i.lineTo(s+n*3,r+l*5),i.lineTo(s+n*2,r+l*6),i.lineTo(s+n*1,r+l*5),i.lineTo(s+n*1,r+l*3),i.lineTo(s+n*2,r+l*2),i.moveTo(s+n*3,r+l*4),i.lineTo(s+n*4,r+l*4),i.moveTo(s+n*2,r+l*6),i.lineTo(s+n*2,r+l*8),i.closePath(),i instanceof Path2D)return i}function Uh(e){const t=[{x:.5,y:0},{x:1,y:.5},{x:.5,y:1}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function qh(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=a/2,n=o/10;if(i.moveTo(s+l,r),i.lineTo(s+l,r+n),i.moveTo(s+l,r+n),i.quadraticCurveTo(s+l*2,r+n,s+l*2,r+n*9),i.moveTo(s+l,r+n),i.quadraticCurveTo(s,r+n,s,r+n*9),i.quadraticCurveTo(s+l,r+n*6,s+l*2,r+n*9),i.moveTo(s+l,r+o*3/4),i.lineTo(s+l,r+o),i.moveTo(s+l*2/5,r+o*201/250),i.lineTo(s+l*2/5,r+o),i.moveTo(s+l*8/5,r+o*201/250),i.lineTo(s+l*8/5,r+o),i.closePath(),i instanceof Path2D)return i}function vr(e){const t=[{x:.5,y:0},{x:.2,y:1},{x:.5,y:1},{x:.8,y:1}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function $h(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=o/6,n=a/4;if(i.moveTo(s+n*2,r+0),i.lineTo(s+n*2,r+l),i.moveTo(s,r+l+n*2),i.arc(s+n*2,r+l+n*2,n*2,Math.PI*1,Math.PI*2,!1),i.lineTo(s+n*4,r+l*5),i.lineTo(s,r+l*5),i.lineTo(s,r+l+n*2),i.moveTo(s,r+l*5-l/3),i.lineTo(s+n*4,r+l*5-l/3),i.moveTo(s+n,r+l*5),i.lineTo(s+n,r+l*6),i.moveTo(s+n*2,r+l*5),i.lineTo(s+n*2,r+l*6),i.moveTo(s+n*3,r+l*5),i.lineTo(s+n*3,r+l*6),i.closePath(),i instanceof Path2D)return i}function Yh(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=o/4,n=.5*a;if(i.moveTo(s+n,r),i.lineTo(s+n,r+l),i.lineTo(s+n*2,r+l*2),i.lineTo(s+n*2,r+l*4),i.lineTo(s,r+l*4),i.lineTo(s,r+l*2),i.lineTo(s+n,r+l),i.closePath(),i instanceof Path2D)return i}function Xh(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=o/4,n=a/2;if(i.moveTo(s+n,r),i.lineTo(s+n,r+l),i.lineTo(s+n*2,r+l*4),i.lineTo(s,r+l*4),i.lineTo(s+n,r+l),i.closePath(),i instanceof Path2D)return i}function Kh(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect,l=o/3,n=.5*a;if(i.moveTo(s+n,r),i.lineTo(s+n,r+l),i.lineTo(s+a,r+2*l),i.lineTo(s+n,r+o),i.lineTo(s,r+2*l),i.lineTo(s+n,r+l),i.closePath(),i instanceof Path2D)return i}function Gh(e){const t=[{x:.5,y:0},{x:1,y:.6666666666666666},{x:.5,y:1},{x:0,y:.6666666666666666}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function Jh(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;let l=a/2,n=o/10;if(i.moveTo(s+l,r),i.lineTo(s+l,r+n),i.moveTo(s+l,r+n),i.quadraticCurveTo(s+l*2,r+n,s+l*2,r+n*9),i.moveTo(s+l,r+n),i.quadraticCurveTo(s,r+n,s,r+n*9),i.quadraticCurveTo(s+l,r+n*6,s+l*2,r+n*9),i.moveTo(s,r+n*10),i.quadraticCurveTo(s+l,r+n*7,s+l*2,r+n*10),i.moveTo(s+l*2/5,r+o*201/250+n),i.lineTo(s+l*2/5,r+o),i.moveTo(s+l*8/5,r+o*201/250+n),i.lineTo(s+l*8/5,r+o),i.closePath(),i instanceof Path2D)return i}function Qh(e){const t=[{x:.5,y:0},{x:.2,y:1},{x:.8,y:1}];e.anchors=t.map(({x:i,y:s},r)=>({id:`${r}`,penId:e.id,x:i,y:s}))}function Zh(e,t){const{x:i,y:s,width:r,height:a}=t.calculative.worldRect,o=r/2,l=a/10;e.beginPath(),e.moveTo(i+o,s),e.lineTo(i+o,s+l),e.moveTo(i+o,s+l),e.quadraticCurveTo(i+o*2,s+l,i+o*2,s+l*9),e.moveTo(i+o,s+l),e.quadraticCurveTo(i,s+l,i,s+l*9),e.quadraticCurveTo(i+o,s+l*6,i+o*2,s+l*9),e.moveTo(i+o,s+a*3/4),e.lineTo(i+o,s+a*9/10),e.moveTo(i+o*2/5,s+a*201/250),e.lineTo(i+o*2/5,s+a*9/10),e.moveTo(i+o*8/5,s+a*201/250),e.lineTo(i+o*8/5,s+a*9/10),e.stroke(),e.closePath(),e.beginPath();const n=o*2>l*10?l:o/5;e.fillStyle="#333333",e.font=n+"px Arial",e.textBaseline="bottom",e.textAlign="center",e.fillText("o",i+o,s+a),e.fillText("m",i+o*2/5,s+a),e.fillText("o",i+o*8/5,s+a),e.closePath()}function _u(){return{andGate:Fh,basicEvent:zh,conditionalEvent:jh,event:Hh,forbiddenGate:Vh,orGate:qh,priorityAndGate:$h,switchEvent:Yh,transferSymbol:Xh,unexpandedEvent:Kh,xorGate:Jh}}function Eu(){return{votingGate:Zh}}function Mu(){return{andGate:dr,orGate:vr,priorityAndGate:dr,votingGate:vr,xorGate:Qh,forbiddenGate:Uh,basicEvent:fr,unexpandedEvent:Gh,conditionalEvent:Wh,transferSymbol:fr}}const tu=15;function ue(e,t=tu){let i=""+e;return i.indexOf(".")>=0&&(i=Number.parseFloat(i).toFixed(t)),Number.parseFloat(i)}function qi(e){return typeof e=="number"&&Number.isFinite(e)}function eu(e){e={max:null,min:null,splitNumber:4,symmetrical:!1,deviation:!1,preferZero:!1,...e};const t=[10,15,20,25,30,40,50,60,70,80,90,100,150];let{max:i,min:s,splitNumber:r,symmetrical:a,deviation:o,preferZero:l}=e;if(!qi(i)||!qi(s)||i<s)return{splitNumber:r};if(i===s&&i===0)return{max:ue(t[0]*r),min:s,interval:t[0],splitNumber:r};i===s&&(l=!0),(!qi(r)||r<=0)&&(r=4),l&&i*s>0&&(i<0?i=0:s=0);const n=(i-s)/r;let h=Math.floor(Math.log10(n)-1);h=Math.pow(10,h);const c=n/h;let f=t[0]*h,u=-1,d;for(d=0;d<t.length;d++)if(t[d]>c){f=t[d]*h;break}let v=i,g=s;function y(b){if(v=parseInt(""+(i/b+1))*b,g=parseInt(""+(s/b-1))*b,i===0&&(v=0),s===0&&(g=0),a&&v*g<0){const m=Math.max(Math.abs(v),Math.abs(g));v=m,g=-m}}if(y(f),o)return{max:ue(v),min:ue(g),interval:ue(f),splitNumber:Math.round((v-g)/f)};if(!a||v*g>0){let b;t:do{if(b=Math.round((v-g)/f),(d-u)*(b-r)<0){for(;b<r;)if(g-s<=v-i&&g!==0||v===0?g-=f:v+=f,b++,b===r)break t}if(d>=t.length-1||d<=0||b===r)break;u=d,b>r?f=t[++d]*h:f=t[--d]*h,y(f)}while(b!==r)}v=ue(v),g=ue(g);const p=ue((v-g)/r);return{max:v,min:g,interval:p,splitNumber:r}}function ga(e,t){var y,p,b,m,k,A,S,I,E,z,U,T,R,C,_,B,j,X,F,L,N,W,O,q,$,Y,Z,J;const i=t.calculative.worldRect.x,s=t.calculative.worldRect.y,r=t.calculative.worldRect.width,a=t.calculative.worldRect.height;let o=t.calculative.canvas.store.data.scale,l=[];if(t.echarts)for(let Q=0;Q<t.echarts.option.series.length;Q++)l.push(t.echarts.option.series[Q].data);else l=t.data;let n=[];for(let Q=0;Q<l.length;Q++)n=n.concat(l[Q]);let h={max:Math.max.apply(null,n),min:Math.min.apply(null,n),splitNumber:5},c=eu(h),f=t.echarts?t.echarts.option.xAxis.data.length:t.xAxisData.length;e.beginPath(),e.strokeStyle="#BFBFBF",e.lineWidth=6*o,e.lineCap="butt";let u=(r-1*(f+1))/f;e.setLineDash([1,u]),e.moveTo(i,s+a+3*o),e.lineTo(i+r,s+a+3*o),e.stroke(),e.closePath(),e.beginPath(),e.lineWidth=1*o,e.setLineDash([]),e.moveTo(i,s+a),e.lineTo(i+r,s+a),e.stroke(),e.closePath(),e.beginPath(),e.fillStyle="#BFBFBF",e.strokeStyle="#E9E9E9",e.setLineDash([2,2]);let d={fontStyle:((p=(y=t.yAxis)==null?void 0:y.axisLabel)==null?void 0:p.fontStyle)||t.fontStyle,textDecoration:(m=(b=t.yAxis)==null?void 0:b.axisLabel)==null?void 0:m.textDecoration,fontWeight:((A=(k=t.yAxis)==null?void 0:k.axisLabel)==null?void 0:A.fontWeight)||t.fontWeight,fontFamily:((I=(S=t.yAxis)==null?void 0:S.axisLabel)==null?void 0:I.fontFamily)||t.fontFamily,fontSize:((z=(E=t.yAxis)==null?void 0:E.axisLabel)==null?void 0:z.fontSize)||t.fontSize,lineHeight:((T=(U=t.yAxis)==null?void 0:U.axisLabel)==null?void 0:T.lineHeight)||t.lineHeight};e.fillStyle=((C=(R=t.yAxis)==null?void 0:R.axisLabel)==null?void 0:C.fontColor)||t.color;for(let Q=0;Q<c.splitNumber+1;Q++){let w=Q*a/c.splitNumber;e.textAlign="right",e.textBaseline="middle",e.font=_t(d),e.fillText(c.max-Q*c.interval+"",i-10*o,s+w),e.fill(),Q<c.splitNumber&&(e.beginPath(),e.moveTo(i,s+w),e.lineTo(i+r,s+w),e.stroke())}e.closePath(),e.beginPath(),e.strokeStyle="#BFBFBF";let v=t.echarts?t.echarts.option.xAxis.data:t.xAxisData,g=0;for(let Q=0;Q<v.length;Q++){g=i+(1+u/2)+(u+1)*Q,e.textAlign="center",e.textBaseline="top";let w={fontStyle:((B=(_=t.xAxis)==null?void 0:_.axisLabel)==null?void 0:B.fontStyle)||t.calculative.fontStyle,textDecoration:(X=(j=t.xAxis)==null?void 0:j.axisLabel)==null?void 0:X.textDecoration,fontWeight:((L=(F=t.xAxis)==null?void 0:F.axisLabel)==null?void 0:L.fontWeight)||t.calculative.fontWeight,fontFamily:((W=(N=t.xAxis)==null?void 0:N.axisLabel)==null?void 0:W.fontFamily)||t.calculative.fontFamily,fontSize:((q=(O=t.xAxis)==null?void 0:O.axisLabel)==null?void 0:q.fontSize)||t.calculative.fontSize,lineHeight:((Y=($=t.xAxis)==null?void 0:$.axisLabel)==null?void 0:Y.lineHeight)||t.calculative.lineHeight};e.font=_t(w),e.fillStyle=((J=(Z=t.xAxis)==null?void 0:Z.axisLabel)==null?void 0:J.fontColor)||t.calculative.color,e.fillText(v[Q],g,s+a+10*o),e.fill()}return e.closePath(),e.setLineDash([]),{dash:u,normalizedOption:c}}function iu(e,t){if(!isNaN(e))return Math.round(Number(e)*1e3)/1e3}var Be;(function(e){e[e.Add=0]="Add",e[e.Replace=1]="Replace",e[e.ReplaceAll=2]="ReplaceAll"})(Be||(Be={}));function su(e,t){t.onBeforeValue||(t.onBeforeValue=ya);const i=t.calculative.worldRect.x,s=t.calculative.worldRect.y;t.calculative.worldRect.width;const r=t.calculative.worldRect.height;let a=t.calculative.canvas.store.data.scale,o=[];t.echarts&&!t.echarts.option.color&&(t.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]);let l=ga(e,t),n=l.dash,h=l.normalizedOption;const c=!!(t.echarts?t.echarts.option.series[0].smooth:t.smooth);let f=[];if(t.echarts)for(let u=0;u<t.echarts.option.series.length;u++)o.push(t.echarts.option.series[u].data);else o=t.data;for(let u=0;u<o.length;u++){e.beginPath();let d=o[u];e.strokeStyle=t.echarts?t.echarts.option.color[u]:t.chartsColor[u],e.fillStyle=t.echarts?t.echarts.option.color[u]:t.chartsColor[u];let v=i+(1+n/2),g=s+r-(d[0]-h.min)/(h.max-h.min)*r;if(e.moveTo(v,g),f.push({x:v,y:g}),c)if(d.length<=2)for(let y=1;y<d.length;y++)v=i+(1+n/2)+(n+1)*y,g=s+r-(d[y]-h.min)/(h.max-h.min)*r,e.lineTo(v,g),f.push({x:v,y:g});else{let y,p,b,m;d.forEach((k,A)=>{v=i+(1+n/2)+(n+1)*A,g=s+r-(d[A]-h.min)/(h.max-h.min)*r;let S=i+(1+n/2)+(n+1)*(A+1),I=s+r-(d[A+1]-h.min)/(h.max-h.min)*r,E=i+(1+n/2)+(n+1)*(A-1),z=s+r-(d[A-1]-h.min)/(h.max-h.min)*r,U=i+(1+n/2)+(n+1)*(A+2),T=s+r-(d[A+2]-h.min)/(h.max-h.min)*r;A===0?(E=i+(1+n/2)+(n+1)*A,z=s+r-(d[A]-h.min)/(h.max-h.min)*r):A===d.length-2&&(U=i+(1+n/2)+(n+1)*(A+1),T=s+r-(d[A+1]-h.min)/(h.max-h.min)*r),f.push({x:v,y:g}),y=v+(S-E)/4,p=g+(I-z)/4,b=S-(U-v)/4,m=I-(T-g)/4,e.bezierCurveTo(y,p,b,m,S,I)})}else for(let y=1;y<d.length;y++)v=i+(1+n/2)+(n+1)*y,g=s+r-(d[y]-h.min)/(h.max-h.min)*r,e.lineTo(v,g),f.push({x:v,y:g});e.stroke(),e.closePath(),e.save(),f.forEach((y,p)=>{e.beginPath(),e.strokeStyle="#fff",e.lineWidth=2*a,e.arc(y.x,y.y,4*a,0,Math.PI*2),e.stroke(),e.fill(),e.closePath()}),e.restore(),f=[]}}function ya(e,t){if(t.xAxisData||t.data||!t.dataX&&!t.dataY)return t;const i=e.xAxisData,s=e.data,r=e.replaceMode;let a=[],o=[];return r?r===Be.Replace?(t.dataX.forEach((l,n)=>{let h=i.indexOf(l);s.forEach((c,f)=>{c[h]=t.dataY[f][n]})}),a=i,o=s):r===Be.ReplaceAll&&(a=t.dataX,o=t.dataY):(a=[...i,...t.dataX],s.forEach((l,n)=>{let h=[...l,...t.dataY[n]];o.push(h)})),delete t.dataX,delete t.dataY,Object.assign(t,{xAxisData:a,data:o})}function ru(e,t){var c,f;t.onBeforeValue||(t.onBeforeValue=au);let i=t.calculative.canvas.store.data.scale;const s=t.calculative.worldRect.x,r=t.calculative.worldRect.y,a=t.calculative.worldRect.width,o=t.calculative.worldRect.height,l=!!t.echarts;t.echarts?(t.echarts.option.color||(t.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]),t.chartsColor=t.echarts.option.color):t.chartsColor||(t.chartsColor=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]);const n=l?t.echarts.option.series:t.data;let h=0;for(let u=0;u<n.length;u++){let d=n[u],v=a/2;o<a&&(v=o/2);const g=s+a/2,y=r+o/2;let p=0;l?p=d.data.reduce((I,E)=>I+E.value,0):p=d.reduce((I,E)=>I+E.value,0);const b=v*parseFloat(l?d.radius[0]:t.chartsRadius[u][0])/100,m=v*parseFloat(l?d.radius[1]:t.chartsRadius[u][1])/100;if(b>m)return;let k=0,A=0;e.strokeStyle=l&&((c=d.itemStyle)==null?void 0:c.borderColor)||"#fff",e.lineWidth=(l&&((f=d.itemStyle)==null?void 0:f.borderWidth)||2)*i;const S=l?d.data:d;S.forEach((I,E)=>{var B,j,X,F,L,N,W,O,q,$;A+=Math.PI*2*I.value/p,e.beginPath();let z=h+E;z>=t.chartsColor.length&&(z=z%t.chartsColor.length),e.fillStyle=l?t.echarts.option.color[z]:t.chartsColor[z],e.moveTo(g+b*Math.sin(A),y-b*Math.cos(A)),e.arc(g,y,b,-Math.PI/2+A,-Math.PI/2+k,!0),e.lineTo(g+m*Math.sin(k),y-m*Math.cos(k)),e.arc(g,y,m,-Math.PI/2+k,-Math.PI/2+A),e.lineTo(g+b*Math.sin(A),y-b*Math.cos(A)),e.stroke(),e.fill(),e.closePath();let U=(k+A)/2,T=g+(m+10*i)*Math.sin(U),R=y-(m+10*i)*Math.cos(U),C=e.fillStyle;d.label||(d.label={position:"outside",show:!0}),l&&["inner","inside"].includes(d.label.position)?(e.fillStyle="#ffffff",T=g+(m-b)/2*Math.sin(U),R=y-(m-b)/2*Math.cos(U)):l&&d.label.position=="outside",d.labelLine||(d.labelLine={show:!0}),(l&&d.labelLine.show!==!1||!l)&&(e.beginPath(),e.strokeStyle=l?t.echarts.option.color[h+E]:t.chartsColor[h+E],e.moveTo(g+m*Math.sin(U),y-m*Math.cos(U)),e.lineTo(T,R));let _={fontStyle:((B=t.tickLabel)==null?void 0:B.fontStyle)||t.calculative.fontStyle,fontWeight:((j=t.tickLabel)==null?void 0:j.fontWeight)||t.calculative.fontWeight,fontFamily:((X=t.tickLabel)==null?void 0:X.fontFamily)||t.calculative.fontFamily,lineHeight:((F=t.tickLabel)==null?void 0:F.lineHeight)||t.calculative.lineHeight,fontSize:(((L=t.tickLabel)==null?void 0:L.fontSize)||t.calculative.fontSize)*i};e.font=_t(_),e.textBaseline="middle",e.textAlign="center",U>Math.PI?((l&&d.label.position==="outside"||!l)&&(e.textAlign="end"),(l&&d.labelLine.show!==!1||!l&&(((W=(N=t.tickLabel)==null?void 0:N.labelLine)==null?void 0:W.show)??!0))&&e.lineTo(T-5*i,R),(l&&d.label.show!==!1||!l&&(((O=t.tickLabel)==null?void 0:O.show)??!0))&&e.fillText(I.name,T-5*i,R)):((l&&d.label.position==="outside"||!l)&&(e.textAlign="start"),(l&&d.labelLine.show!==!1||!l)&&e.lineTo(T+5*i,R),(l&&d.label.show!==!1||!l&&(((q=t.tickLabel)==null?void 0:q.show)??!0))&&e.fillText(I.name,T+5*i,R)),e.stroke(),e.closePath(),e.fillStyle=C,e.strokeStyle=l&&(($=d.itemStyle)==null?void 0:$.borderColor)||"#fff",k=A}),h+=S.length}}function au(e,t){if(t.data||!t.dataX&&!t.dataY)return t;const i=e.data,s=e.replaceMode;let r=[];return s?s===Be.Replace?(t.dataY.forEach((a,o)=>{a.forEach((l,n)=>{let h=i[o].filter(c=>c.name===l.name);h.length>0&&(h[0].value=l.value)})}),r=i):s===Be.ReplaceAll&&(r=t.dataY):i.forEach((a,o)=>{let l=[...a,...t.dataY[o]];r.push(l)}),delete t.dataX,delete t.dataY,Object.assign(t,{data:r})}function ou(e,t){t.onBeforeValue||(t.onBeforeValue=ya);let i=t.calculative.canvas.store.data.scale;const s=t.calculative.worldRect.x,r=t.calculative.worldRect.y;t.calculative.worldRect.width;const a=t.calculative.worldRect.height;let o=[];if(t.echarts&&!t.echarts.option.color&&(t.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]),t.echarts)for(let f=0;f<t.echarts.option.series.length;f++)o.push(t.echarts.option.series[f].data);else o=t.data;let l=ga(e,t),n=l.dash,h=l.normalizedOption,c=n*4/5/o.length;for(let f=0;f<o.length;f++){e.beginPath();let u=o[f];e.fillStyle=t.echarts?t.echarts.option.color[f]:t.chartsColor[f],e.strokeStyle="#ffffff",e.lineWidth=1*i;let d=0,v=0,g=0;for(let y=0;y<u.length;y++)d=s+(1+.1*n)+(n+1)*y+c*f,g=(u[y]-h.min)/(h.max-h.min)*a,v=r+a-g,e.rect(d,v,c-1,g-1),e.stroke(),e.fill();e.closePath()}}function nu(e,t){var F,L,N,W,O,q,$,Y,Z,J,Q,w,x,P;t.onAdd||(t.onAdd=lu,t.onDestroy=cu,t.onClick=hu,t.clockInterval&&(t.onDestroy(t),t.onAdd(t)));const i=t.calculative.worldRect.x,s=t.calculative.worldRect.y,r=t.calculative.worldRect.width,a=t.calculative.worldRect.height;let o=t.calculative.canvas.store.data.scale,l={startAngle:225,endAngle:-45,min:0,max:100,splitNumber:10};if(t.echarts&&t.echarts.option){let M=t.echarts.option.series[0];t.startAngle=M.startAngle||l.startAngle,t.endAngle=M.endAngle||l.endAngle,t.min=M.min||l.min,t.max=M.max||l.max,t.axisLine=M.axisLine.lineStyle.color,t.unit=M.detail.formatter.replace("{value}",""),t.value=M.data[0].value,t.splitNumber=M.splitNumber||l.splitNumber}t={...l,...t};let n=r>a?a/2*9/10:r/2*9/10,h=i+r/2,c=s+a/2,f=t.echarts?t.echarts.option.series[0].data[0].value:t.value,u,d=t.startAngle-t.endAngle,v=t.background||"#E6EBF8";e.strokeStyle=v;let g=n/10;e.lineWidth=g,e.beginPath(),e.lineCap="round",e.arc(h,c,n,-t.startAngle/180*Math.PI,-t.endAngle/180*Math.PI),e.stroke(),e.closePath();let y=0;if(t.axisLine&&!t.isClock)for(let M=t.axisLine.length-1;M>=0;M--)t.axisLine[M][0]*(t.max-t.min)<f?y=t.axisLine[M][0]:(y=(f-t.min)/(t.max-t.min),u=t.axisLine[M][1]),e.beginPath(),e.strokeStyle=t.axisLine[M][1],e.arc(h,c,n,-t.startAngle/180*Math.PI,(-t.startAngle+y*d)/180*Math.PI),e.stroke(),e.closePath();e.lineCap="butt";let p=2*o,b=n-g;b<0&&(b=0);let m=d/180*Math.PI*b,k=(m-p*t.splitNumber)/t.splitNumber,A=d/180*Math.PI*p/2/m;e.beginPath(),e.strokeStyle=t.color||"#999999",e.lineWidth=n/20,e.setLineDash([p,k]),e.arc(h,c,b,-t.startAngle/180*Math.PI-A,-t.endAngle/180*Math.PI+A),e.stroke(),e.closePath();let S=1*o,I=n-g;I<0&&(I=0);let E=d/180*Math.PI*I,z=(E-S*5*t.splitNumber)/5/t.splitNumber,U=d/180*Math.PI*S/2/E;e.beginPath(),e.strokeStyle=t.color||"#999999",e.lineWidth=n/40,e.setLineDash([S,z]),e.arc(h,c,I,-t.startAngle/180*Math.PI-U,-t.endAngle/180*Math.PI+U),e.stroke(),e.closePath(),e.beginPath();let T=t.max-t.min,R=T/t.splitNumber,C={fontStyle:((F=t.tickLabel)==null?void 0:F.fontStyle)||t.calculative.fontStyle,textDecoration:((L=t.tickLabel)==null?void 0:L.textDecoration)||t.textDecoration,fontWeight:((N=t.tickLabel)==null?void 0:N.fontWeight)||t.calculative.fontWeight,fontFamily:((W=t.tickLabel)==null?void 0:W.fontFamily)||t.calculative.fontFamily,fontSize:(((O=t.tickLabel)==null?void 0:O.fontSize)||t.calculative.fontSize)*o,lineHeight:((q=t.tickLabel)==null?void 0:q.lineHeight)||t.calculative.lineHeight};e.font=_t(C);let _=n-g-n/20;for(let M=0;M<=t.splitNumber;M++){if(Math.abs(t.startAngle)+Math.abs(t.endAngle)===360&&M==0)continue;let H=t.startAngle-R*M/T*d,V=Math.cos(H/180*Math.PI),G=Math.sin(H/180*Math.PI);e.fillStyle=(($=t.tickLabel)==null?void 0:$.color)||"#999999",V>.02?e.textAlign="end":V<-.02?e.textAlign="start":e.textAlign="center",G>.02?e.textBaseline="top":G<-.02?e.textBaseline="bottom":e.textBaseline="middle",e.fillText(iu(R*M+t.min),h+_*V,c-_*G),e.fill()}e.closePath();let B=1,j=["value"];if(t.isClock&&(B=3,j=["hourvalue","minutevalue","secondvalue"]),t.isClock)for(let M=0;M<B;M++){let H=(t.startAngle-(t[j[M]]-t.min)/(t.max-t.min)*d)/180*Math.PI;M>0&&(H=(t.startAngle-(t[j[M]]-t.min)/(t.max*5-t.min)*d)/180*Math.PI);let V=4/5*n;j[M]==="hourvalue"&&(V=3/5*n),j[M]==="minutevalue"&&(V=3.5/5*n);let G=n*1/40;e.beginPath(),e.setLineDash([]),e.lineWidth=n/(M+1)/20,e.strokeStyle=t.color||"#999999",e.moveTo(h-G*3*Math.cos(H),c+G*3*Math.sin(H)),e.lineTo(h+V*Math.cos(H),c-V*Math.sin(H)),e.stroke()}else{let M=(t.startAngle-(f-t.min)/(t.max-t.min)*d)/180*Math.PI,H=4/5*n,V=n*1/40;e.beginPath(),e.setLineDash([]),e.lineWidth=2,e.fillStyle=u,e.moveTo(h-V*3*Math.cos(M),c+V*3*Math.sin(M)),e.lineTo(h+V*Math.cos(M-Math.PI/2),c-V*Math.sin(M-Math.PI/2)),e.lineTo(h+H*Math.cos(M),c-H*Math.sin(M)),e.lineTo(h+V*Math.cos(M+Math.PI/2),c-V*Math.sin(M+Math.PI/2)),e.lineTo(h-V*3*Math.cos(M),c+V*3*Math.sin(M)),e.fill()}e.beginPath(),e.textAlign="center",e.textBaseline="middle";let X={fontStyle:((Y=t.titleLabel)==null?void 0:Y.fontStyle)||t.calculative.fontStyle,textDecoration:((Z=t.titleLabel)==null?void 0:Z.textDecoration)||t.textDecoration,fontWeight:((J=t.titleLabel)==null?void 0:J.fontWeight)||t.calculative.fontWeight,fontFamily:((Q=t.titleLabel)==null?void 0:Q.fontFamily)||t.calculative.fontFamily,fontSize:(((w=t.titleLabel)==null?void 0:w.fontSize)||t.calculative.fontSize)*o,lineHeight:((x=t.titleLabel)==null?void 0:x.lineHeight)||t.calculative.lineHeight};e.font=_t(X),e.fillStyle=((P=t.titleLabel)==null?void 0:P.color)||u,t.isClock?e.fillText(("0"+parseInt(t.hourvalue)).slice(-2)+":"+("0"+parseInt(t.minutevalue)).slice(-2)+":"+("0"+parseInt(t.secondvalue)).slice(-2),h,c+n/2):e.fillText(f+" "+(t.unit||""),h,c+n/2),e.fill(),t.isClock&&(e.beginPath(),e.fillStyle=t.color||"#999999",e.strokeStyle="#ffffff",e.arc(h,c,n/20,0,Math.PI*2),e.stroke(),e.fill(),e.closePath())}function lu(e){if(e.isClock)e.clockInterval=setInterval(()=>{let t=new Date,i=t.getSeconds(),s=t.getMinutes()+i/60,r=t.getHours()%12+s/60;e.calculative.canvas.parent.setValue({id:e.id,hourvalue:r,minutevalue:s,secondvalue:i},{render:!0,doEvent:!1})},1e3);else{const t=e.value;e.value=0,e.frames=[{duration:2e3,value:t}],e.calculative.canvas.parent.startAnimate(e.id),setTimeout(()=>{e.value=t},1e3)}}function cu(e){e.clockInterval&&(clearInterval(e.clockInterval),e.clockInterval=void 0)}function hu(e){e.isClock&&(e.onDestroy(e),e.onAdd(e))}function uu(e,t){if(t.onBeforeValue||(t.onBeforeValue=du),t.calculative.update===void 0&&(t.calculative.update=!0),t.calculative.update){const i=fu(t);i&&(t.calculative.img||(t.calculative.img=new Image),t.calculative.img.src=i),t.calculative.update=!1}if(t.calculative.img){const{x:i,y:s,width:r,height:a}=t.calculative.worldRect;e.drawImage(t.calculative.img,i,s,r,a)}}function du(e,t){return(t.data||t.min||t.max||t.chartsColor)&&(e.calculative.update=!0),t}function fu(e){var y,p;const{width:t,height:i}=e.calculative.worldRect,s=e.data,r=(s==null?void 0:s.length)||0,a=r>0?s[0].length:0,o=document.createElement("canvas");o.style.width=`${t}px`,o.style.height=`${i}px`,o.width=t,o.height=i;const l=o.width,n=o.height,h=o.getContext("2d");(p=(y=e.calculative)==null?void 0:y.canvas)==null||p.getPenRect(e);const c=(a-1)/l,f=(r-1)/n;if(r===0||a===0){console.warn("无效数据维度");return}const u=h.createImageData(l,n),d=u.data,v=vu(s,r,a),g=yu(e.min,e.max,e.chartsColor);for(let b=0;b<n;b++){const m=b*f;for(let k=0;k<l;k++){const A=k*c,S=gu(e,v,A,m),{r:I,g:E,b:z}=g(S),U=(b*l+k)*4;d[U]=I,d[U+1]=E,d[U+2]=z,d[U+3]=255}}return h.putImageData(u,0,0),o.toDataURL()}function vu(e,t,i){const r=t+4,a=i+2*2,o=Array(r).fill(null).map(()=>Array(a).fill(0));for(let l=0;l<t;l++)for(let n=0;n<i;n++)o[l+2][n+2]=e[l][n];for(let l=0;l<2;l++)for(let n=0;n<a;n++)o[l][n]=o[2+(2-l-1)][n];for(let l=0;l<2;l++){let n=r-2+l,h=r-2-1-l;for(let c=0;c<a;c++)o[n][c]=o[h][c]}for(let l=0;l<2;l++)for(let n=0;n<r;n++)o[n][l]=o[n][2+(2-l-1)];for(let l=0;l<2;l++){let n=a-2+l,h=a-2-1-l;for(let c=0;c<r;c++)o[c][n]=o[c][h]}return o}function gu(e,t,i,s){const a=i+2,o=s+2,l=Math.floor(a),n=Math.floor(o),h=a-l,c=o-n;let f=0;for(let u=-1;u<=2;u++){const d=gr(u-h);for(let v=-1;v<=2;v++){const g=gr(v-c),y=t[n+v][l+u];f+=y*d*g}}return Math.min(e.max,Math.max(e.min,f))}function gr(e,t=-.5){return e=Math.abs(e),e<=1?(t+2)*e*e*e-(t+3)*e*e+1:e<2?t*e*e*e-5*t*e*e+8*t*e-4*t:0}function yu(e,t,i){const s=i.length,r=[];for(let a=0;a<s;a++){const o=a/(s-1),l=mu(i[a]);r.push({pos:o,rgb:l})}return function(a){let o=(a-e)/(t-e);o=Math.min(1,Math.max(0,o));let l=0;for(;l<r.length-1&&!(o<=r[l+1].pos);l++);const n=r[l],h=r[l+1];if(o<=n.pos)return n.rgb;if(o>=h.pos)return h.rgb;const c=(o-n.pos)/(h.pos-n.pos),f=Math.round(n.rgb.r+(h.rgb.r-n.rgb.r)*c),u=Math.round(n.rgb.g+(h.rgb.g-n.rgb.g)*c),d=Math.round(n.rgb.b+(h.rgb.b-n.rgb.b)*c);return{r:f,g:u,b:d}}}function mu(e){const t=document.createElement("div");t.style.color=e,t.style.display="none",document.body.appendChild(t);const i=window.getComputedStyle(t).color;document.body.removeChild(t);const s=i.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(!s)throw new Error(`无法解析颜色: ${e}`);return{r:parseInt(s[1]),g:parseInt(s[2]),b:parseInt(s[3])}}function Lu(){return{lineChart:su,histogram:ou,pieChart:ru,gauge:nu,heatmap:uu}}function pu(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:o}=e.calculative.worldRect;if(i.rect(s,r,a,o),i.closePath(),i instanceof Path2D)return i}function wu(e,t){const i=t.headHeight??50,{x:s,y:r,width:a,height:o,ey:l}=t.calculative.worldRect;let n=t.calculative.borderRadius||0,h=n;t.calculative.borderRadius<1&&(n*=a,h*=o);let c=n<h?n:h;a<2*c&&(c=a/2),i<2*c&&(c=i/2),e.beginPath(),e.moveTo(s+c,r),e.arcTo(s+a,r,s+a,r+i,c),e.arcTo(s+a,r+i,s,r+i,c),e.arcTo(s,r+i,s,r,c),e.arcTo(s,r,s+a,r,c),e.closePath(),e.stroke(),e.save(),e.beginPath(),e.lineWidth=1,e.setLineDash([7,7]);const f=s+a/2;e.moveTo(f,r+i+1),e.lineTo(f,l),e.stroke(),e.restore()}function Du(){return{sequenceFocus:pu}}function Ou(){return{lifeline:wu}}export{ku as C,wc as M,Ma as a,Ea as b,Cu as c,Pu as d,Ru as e,Su as f,Tu as g,Au as h,Ti as i,Ou as j,Iu as k,Lu as l,_u as m,Eu as n,Mu as o,wr as r,Du as s};
|