@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
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
var dt=Object.defineProperty;var ut=(e,t,i)=>t in e?dt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var B=(e,t,i)=>ut(e,typeof t!="symbol"?t+"":t,i);import{d as commonjsGlobal,g as getDefaultExportFromCjs}from"./react-vendor-BNpqFP9B.js";function rectangle(e,t){const i=t||new Path2D;if(e.name==="combine"&&!e.draw)return i instanceof Path2D?i:void 0;e.setTheme||(e.setTheme=setTheme$2);let s=e.calculative.borderRadius||0,r=s;const{x:a,y:n,width:c,height:l,ex:u,ey:h}=e.calculative.worldRect;s<1&&(s=c*s,r=l*r);let v=s<r?s:r;if(c<2*v&&(v=c/2),l<2*v&&(v=l/2),i.moveTo(a+v,n),i.arcTo(u,n,u,h,v),i.arcTo(u,h,a,h,v),i.arcTo(a,h,a,n,v),i.arcTo(a,n,u,n,v),i.closePath(),i instanceof Path2D)return i}function setTheme$2(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 square=rectangle;function circle(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;if(i.ellipse(s+a/2,r+n/2,a/2,n/2,0,0,Math.PI*2),i instanceof Path2D)return i}var PenType;(function(e){e[e.Node=0]="Node",e[e.Line=1]="Line"})(PenType||(PenType={}));var LockState;(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"})(LockState||(LockState={}));var AnchorMode;(function(e){e[e.Default=0]="Default",e[e.In=1]="In",e[e.Out=2]="Out"})(AnchorMode||(AnchorMode={}));var Gradient;(function(e){e[e.None=0]="None",e[e.Linear=1]="Linear",e[e.Radial=2]="Radial"})(Gradient||(Gradient={}));var CanvasLayer;(function(e){e[e.CanvasTemplate=1]="CanvasTemplate",e[e.CanvasImageBottom=2]="CanvasImageBottom",e[e.CanvasMain=3]="CanvasMain",e[e.CanvasImage=4]="CanvasImage"})(CanvasLayer||(CanvasLayer={}));const needCalcTextRectProps=["text","textWidth","textHeight","textLeft","textTop","fontFamily","fontSize","lineHeight","fontStyle","fontWeight","textAlign","textBaseline","whiteSpace","ellipsis","keepDecimal","letterSpacing"],needSetPenProps=["x","y","width","height","flipX","flipY"],needPatchFlagsPenRectProps=["paddingTop","paddingRight","paddingBottom","paddingLeft","flipX","flipY","visible","showChild"],needCalcIconRectProps=["iconLeft","iconTop","iconRotate"],needImgCanvasPatchFlagsProps=["globalAlpha","flipY","flipX","x","y","width","height","iconWidth","iconHeight","imageRatio","iconLeft","iconTop","iconAlign","rotate","visible"];var LineAnimateType;(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"})(LineAnimateType||(LineAnimateType={}));var lineAnimateTargetType;(function(e){e[e.Image=0]="Image",e[e.Icon=1]="Icon",e[e.Pen=2]="Pen",e[e.Element=3]="Element"})(lineAnimateTargetType||(lineAnimateTargetType={}));const isDomShapes=["gif","iframe","video","echarts","highcharts","lightningCharts","vue"],isInteraction=["radio","checkbox","button","inputDom","slider","echarts"],formatAttrs=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","lineName","textType","textGradientColors"]),defaultFormat={textType:0,bkType:0,strokeType:0};function clearLifeCycle(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 HoverType;(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"})(HoverType||(HoverType={}));var HotkeyType;(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"})(HotkeyType||(HotkeyType={}));var MouseRight;(function(e){e[e.None=0]="None",e[e.Down=1]="Down",e[e.Translate=2]="Translate"})(MouseRight||(MouseRight={}));var Direction;(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"})(Direction||(Direction={}));const defaultCursors=["nw-resize","ne-resize","se-resize","sw-resize"],rotatedCursors=["n-resize","e-resize","s-resize","w-resize"],defaultDrawLineFns=["curve","polyline","line"],inheritanceProps=["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 PrevNextType;(function(e){e[e.Mirror=0]="Mirror",e[e.Bilateral=1]="Bilateral",e[e.Free=2]="Free"})(PrevNextType||(PrevNextType={}));var TwoWay;(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"})(TwoWay||(TwoWay={}));var PointType;(function(e){e[e.Default=0]="Default",e[e.Line=1]="Line"})(PointType||(PointType={}));function rotatePoint(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&&rotatePoint(e.prev,t,i),e.next&&rotatePoint(e.next,t,i)}function hitPoint(e,t,i=5,s){if(t.type===PointType.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),pointInRect(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 scalePoint(e,t,i){e.x=i.x-(i.x-e.x)*t,e.y=i.y-(i.y-e.y)*t}function calcRotate(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 distance(e,t){const i=e.x-t.x,s=e.y-t.y;return Math.sqrt(i*i+s*s)}function facePoint(e,t){let i=Direction.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=Direction.Right:i=Direction.Left:r>0?i=Direction.Bottom:i=Direction.Up,i}function translatePoint(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 samePoint(e,t){return e.anchorId===t.anchorId&&e.connectTo===t.connectTo}function getDistance(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 version="1.1.19",pkg={version},globalStore={version:pkg.version,path2dDraws:{},canvasDraws:{},anchors:{},lineAnimateDraws:{},htmlElements:{}};function register$1(e){Object.assign(globalStore.path2dDraws,e)}function registerCanvasDraw(e){Object.assign(globalStore.canvasDraws,e)}function registerAnchors(e){Object.assign(globalStore.anchors,e)}function mitt(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 KeydownType;(function(e){e[e.None=-1]="None",e[e.Document=0]="Document",e[e.Canvas=1]="Canvas"})(KeydownType||(KeydownType={}));const defaultOptions={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:KeydownType.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},themeKeys=["color","hoverColor","activeColor","disabledColor","background","activeBackground","hoverBackground","disabledBackground","anchorColor","hoverAnchorColor","anchorBackground","animateColor","textColor","ruleColor","ruleLineColor","gridColor","lineColor","penBackground","dockPenColor"],defaultTheme={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"}}},le5leTheme={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[n,c]=a.split(t);return r[n]=c,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 n=0;n<r.cssRules.length;n++)if(r.cssRules[n].selectorText===this.cssRuleSelector){a=!0;break}if(a)for(let n=0;n<r.cssRules.length;n++){const c=r.cssRules[n];if(c.selectorText===this.cssRuleSelector)if(r.insertRule){r.deleteRule(n);const l=`${this.cssRuleSelector} { ${s.join(";")} }`;r.insertRule(l,n)}else r.addRule&&(c.style.cssText=s.join(";"))}else if(r.insertRule){const n=`${this.cssRuleSelector} { ${s.join(";")} }`;r.insertRule(n,r.cssRules.length)}else if(r.addRule){const n=r.cssRules.find(c=>c.selectorText===this.cssRuleSelector);if(n){const c=s.join(";");n.style.cssText+=`; ${c}`}else r.addRule(this.cssRuleSelector,s.join(";"))}}};var EditType;(function(e){e[e.Add=0]="Add",e[e.Update=1]="Update",e[e.Delete=2]="Delete",e[e.Replace=3]="Replace"})(EditType||(EditType={}));const createStore=()=>({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:{...defaultOptions},theme:{...defaultTheme},emitter:mitt(),bindDatas:{},bind:{},pensNetwork:{},cacheDatas:[],messageEvents:{},templatePens:{},globalTriggers:{}}),useStore=(e="default")=>(globalStore[e]||(globalStore[e]=createStore(),globalStore[e].id=e),globalStore[e]),clearStore=(e,t)=>{const i=e.data.template===t;if(i)for(const s of e.data.pens)s.canvasLayer,CanvasLayer.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 isNumber(e){return typeof e=="number"&&!isNaN(e)}function isEmptyText(e){return e==null||typeof e=="string"&&e.trim()===""||!e&&e!==0&&e!=="0"&&e!==!1}function calcTextRect(e){const{paddingTop:t,paddingBottom:i,paddingLeft:s,paddingRight:r,worldRect:a,canvas:n,text:c}=e.calculative;let{textLeft:l,textTop:u,textWidth:h,textHeight:v}=e.calculative,f=s,g=t;const y=a.width-s-r,p=a.height-t-i;h&&h<1&&(h*=a.width),v&&v<1&&(v*=a.height),h<e.calculative.fontSize&&(h=e.calculative.fontSize),f+=(l||0)+a.x,g+=(u||0)+a.y;const m=e.textAlign||n.store.options.textAlign,x=e.textBaseline||n.store.options.textBaseline;switch(m){case"center":f+=(y-(h||y))/2;break;case"right":f+=y-(h||y);break}switch(x){case"middle":g+=(p-(v||p))/2;break;case"bottom":g+=p-(v||p);break}const k={x:f,y:g,width:h||y,height:v||p};calcRightBottom(k),e.calculative.worldTextRect=k,calcTextLines(e),e.calculative.textDrawRect=void 0}function calcTextDrawRect(e,t){const i=t.calculative;if(isEmptyText(i.text))return;i.textLines||calcTextLines(t);const{worldTextRect:s,textLines:r,fontSize:a,lineHeight:n,canvas:c}=i;if(!r)return;const l=a*n,u=r.length*l;t.calculative.fontsChecked!==!1&&(document.fonts.check(e.font)?t.calculative.fontsChecked=!1:t.calculative.fontsChecked=!0);const h=calcTextAdaptionWidth(e,t);let v=s.x+(s.width-h)/2,f=s.y+(s.height-u)/2;const{options:g}=c.store;switch(t.textAlign||g.textAlign){case"left":v=s.x;break;case"right":v=s.x+s.width-h;break}switch(t.textBaseline||g.textBaseline){case"top":f=s.y;break;case"bottom":f=s.ey-u;break}t.calculative.textDrawRect={x:v,y:f,width:h,height:u},calcRightBottom(t.calculative.textDrawRect)}function calcTextLines(e,t=e.calculative.text){const i=e.calculative;if(isEmptyText(t)){i.textLines=void 0;return}let s=typeof t=="string"?t:t.toString();const{whiteSpace:r,ellipsis:a}=e,{keepDecimal:n}=i;if(n!=null&&s.trim()!==""){const f=Number(s);isNaN(f)||(s=f.toFixed(n))}let c=[];const l=i.fontSize*i.lineHeight,u=i.worldTextRect.height,h=Math.floor(u/l),v=h>1?h:1;switch(r){case"nowrap":if(a!==!1){const y=wrapLines([...s],e);y[0]&&(c.push(y[0]),y.length>1&&setEllipsisOnLastLine(c))}else c.push(s);break;case"pre-line":c=s.split(/[\n]/g),a!==!1&&c.length>v&&(c=c.slice(0,v),setEllipsisOnLastLine(c));break;case"break-all":default:const f=s.split(/[\n]/g);let g=0;t:for(const y of f){const p=r==="break-all"?y.split(""):getWords(y);let m=wrapLines(p,e);if(m.length===0&&(m=[""]),a!=!1)for(const x of m)if(g++,g>v){setEllipsisOnLastLine(c);break t}else c.push(x);else c.push(...m)}break}return i.textLines=c,c}function getWords(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 wrapLines(e,t){const i=t.calculative.canvas,s=i.offscreen.getContext("2d"),{fontStyle:r,fontWeight:a,fontSize:n,fontFamily:c,lineHeight:l}=t.calculative;s.save();const u=[];let h=e[0]||"";for(let v=1;v<e.length;++v){const f=e[v]||"",g=h+f;let y=0;if(i.store.options.measureTextWidth)s.font=getFont({fontStyle:r,fontWeight:a,fontFamily:c||i.store.options.fontFamily,fontSize:n,lineHeight:l}),y=s.measureText(g).width;else{const m=g.match(/[^\x00-\xff]/g)||"",x=m.length*n,k=g.match(/\s/g)||"",w=k.length*n*.3,C=(g.length-m.length-k.length)*n*.6;y=x+w+C}const p=t.calculative.worldTextRect.width;y<=p+.1?h+=f:(h.length&&u.push(h),h=f)}return h.length&&u.push(h),s.restore(),u}function calcTextAdaptionWidth(e,t){let i=0;return t.calculative.textLineWidths=[],t.calculative.textLines&&t.calculative.textLines.forEach(s=>{let r;t.calculative.textType?r=getFontWith(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 getFontWith(e,t){const i=t.calculative.fontSize,s=e.match(/[^\x00-\xff]/g)||"",r=s.length*i,a=e.match(/\s/g)||"",n=a.length*i*(t.CSmultiple||.5),c=(e.length-s.length-a.length)*i*(t.CEmultiple||.54);return r+n+c}function setEllipsisOnLastLine(e){e[e.length-1]=e[e.length-1].slice(0,-3)+"..."}function calcTextAutoWidth(e){let t=e.text.split(`
|
|
2
|
-
`);const i=e.calculative.canvas,s=i.offscreen.getContext("2d"),{fontStyle:r,fontWeight:a,fontSize:n,fontFamily:c,lineHeight:l}=e.calculative;let u=0,h=0;s.save();for(let f=0;f<t.length;f++){if(i.store.options.measureTextWidth)s.font=getFont({fontStyle:r,fontWeight:a,fontFamily:c||i.store.options.fontFamily,fontSize:n,lineHeight:l}),h=s.measureText(t[f]).width+t[f].length*e.calculative.letterSpacing;else{const g=t[f].match(/[^\x00-\xff]/g)||"",y=g.length*n,p=t[f].match(/\s/g)||"",m=p.length*n*.3,x=(t[f].length-g.length-p.length)*n*.6;h=y+m+x+t[f].length*e.calculative.letterSpacing}h>u&&(u=h)}s.restore();let v=t.length*n*l;e.textAlign==="left"||(e.textAlign==="right"?e.x=e.x-(u-e.width):e.x=e.x-(u-e.width)/2),e.textBaseline==="top"||(e.textBaseline==="bottom"?e.y=e.y-(v-e.height):e.y=e.y-(v-e.height)/2),e.height=v+5,e.width=u+5,e.calculative.canvas.updatePenRect(e),e.calculative.canvas.calcActiveRect()}function deepClone(e,t=!1){if(Array.isArray(e)){const i=[];return e.forEach(s=>{i.push(deepClone(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 HTMLMediaElement)){{if(s==="calculative"&&!t)continue;if(s==="singleton"){t?i[s]={}:i[s]=e[s];continue}}i[s]=deepClone(e[s],t)}return i}return e}function deepSetValue(e,t,i){if(Array.isArray(e)){const s=[];return e.forEach(r=>{s.push(deepSetValue(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]=deepSetValue(e[s],t,i);return e}return e}const arrows={};function renderFromArrow(e,t,i){if(!arrows[t.fromArrow])return;const s=getFromAnchor(t),{x:r,y:a}=s,n={x:r,y:a};if(n.step=(t.fromArrowSize||10)*i.data.scale,s.next)n.rotate=calcRotate(s.next,s)+90;else{const l=t.calculative.worldAnchors[1];if(!l)return;l.prev?n.rotate=calcRotate(l.prev,s)+90:n.rotate=calcRotate(l,s)+90}e.save(),e.beginPath(),e.setLineDash([]);const c=t.fromArrowColor||t.calculative.color;c&&(e.strokeStyle=c),arrows[t.fromArrow](e,t,i,n),e.restore()}function renderToArrow(e,t,i){if(!arrows[t.toArrow]||t.calculative.worldAnchors.length<2)return;e.save();const s=getToAnchor(t),{x:r,y:a}=s,n={x:r,y:a};if(n.step=(t.toArrowSize||10)*i.data.scale,s.prev)n.rotate=calcRotate(s.prev,s)+90;else{const l=t.calculative.worldAnchors[t.calculative.worldAnchors.length-2];l.next?n.rotate=calcRotate(l.next,s)+90:n.rotate=calcRotate(l,s)+90}e.beginPath(),e.setLineDash([]);const c=t.toArrowColor||t.calculative.color;c&&(e.strokeStyle=c),arrows[t.toArrow](e,t,i,n),e.restore()}arrows.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()};arrows.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()};arrows.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()};arrows.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()};arrows.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()};arrows.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()};arrows.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()};arrows.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()};arrows.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()};arrows.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 pSBCr(e){const t=parseInt,i=Math.round;let s=e.length,r={};if(s>9){const[a,n,c,l]=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(n),r.b=t(c),r.a=l?parseFloat(l):-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 pSBC(e,t,i,s){let r,a,n,c,l,u,h,v=Math.round,f=typeof i=="string";return typeof e!="number"||e<-1||e>1||typeof t!="string"||t[0]!="r"&&t[0]!="#"||i&&!f||(h=t.length>9,h=f?i.length>9?!0:i=="c"?!h:!1:h,l=pSBCr(t),c=e<0,u=i&&i!="c"?pSBCr(i):c?{r:0,g:0,b:0,a:-1}:{r:255,g:255,b:255,a:-1},e=c?e*-1:e,c=1-e,!l||!u)?null:(s?(r=v(c*l.r+e*u.r),a=v(c*l.g+e*u.g),n=v(c*l.b+e*u.b)):(r=v((c*l.r**2+e*u.r**2)**.5),a=v((c*l.g**2+e*u.g**2)**.5),n=v((c*l.b**2+e*u.b**2)**.5)),f=l.a,u=u.a,l=f>=0||u>=0,f=l?f<0?u:u<0?f:f*c+u*e:0,h?"rgb"+(l?"a(":"(")+r+","+a+","+n+(l?","+v(f*1e3)/1e3:"")+")":"#"+(4294967296+r*16777216+a*65536+n*256+(l?v(f*255):0)).toString(16).slice(1,l?void 0:-2))}globalThis.pSBC=pSBC;function rgba(e,t){const i=pSBCr(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 valueInRange(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,n]=[+r[0],+r[1]];if(a>=n){console.warn("startNum must less than endNum");return}return e>a||i==="["&&e===a?e<n||s==="]"&&e===n:!1}function valueInArray(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[n,c]=a.split(".."),[l,u]=[+n,+c];if(l>=u){console.warn("startNum must less than endNum");return}if(e>=l&&e<=u)return!0}else if(e==a)return!0;return!1}function cubicBezierY(e,t,i){const s=1-e;return 3*s*s*e*t+3*s*e*e*i+e*e*e}function toNumber(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 s8(){return((1+Math.random())*4294967296|0).toString(16).substring(1)}const formatPadding=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=isNil(e[1])?e[0]:e[1],r=isNil(e[2])?e[0]:e[2],i=isNil(e[3])?s:e[3]),[t,s,r,i]};function isNil(e){return e==null}async function fileToBase64(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 uploadFile(e,t,i,s){const r=new FormData;if(r.append("file",e),i)for(const n in i)i.hasOwnProperty(n)&&r.append(n,i[n]);return(await(await fetch(t,{method:"POST",headers:s,body:r})).json()).url}function loadCss(e,t,i){var s=document.createElement("link");s.href=e,s.rel="stylesheet",t&&(s.onload=t),document.head.appendChild(s)}function queryURLParams(e){let t=e||window.location.search.split("?")[1];const i=new URLSearchParams(t);return Object.fromEntries(i.entries())}function getCookie(e){let t;const i=new RegExp("(^| )"+e+"=([^;]*)(;|$)");return(t=document.cookie.match(i))?decodeURIComponent(t[2]):""}var TokenType;(function(e){e[e.None=0]="None",e[e.LocalStorage=1]="LocalStorage",e[e.Cookie=2]="Cookie"})(TokenType||(TokenType={}));const isLe5le=location.host.indexOf("le5le.com")!==-1;function getToken(){let e="";const t=globalThis.le5leTokenName??"token";switch(globalThis.le5leTokenType){case TokenType.LocalStorage:e=localStorage.getItem(t);break;case TokenType.Cookie:e=getCookie(t);break;default:e=isLe5le?getCookie(t):localStorage.getItem(t)}return(globalThis.TokenPrefix??"Bearer ")+(globalThis.le5leTokenD?d(e):e)}function d(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 n=parseInt(s,10)-r;for(;n<0;)n+=10;t[i]=n.toString()}else if(new RegExp("[A-Z]","").test(s)){let n=s.charCodeAt(0)-65-r;for(;n<0;)n+=26;t[i]=String.fromCharCode(n+65)}else if(new RegExp("[a-z]","").test(s)){let n=s.charCodeAt(0)-97-r;for(;n<0;)n+=26;t[i]=String.fromCharCode(n+97)}}return t.join("")}async function getMeta2dData(e,t){var l,u;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=((l=queryURLParams())==null?void 0:l.id)||r.includes("${id}");if(!a&&((u=queryURLParams())==null?void 0:u.data)){r=`./projects/${t}`;const v=new URL(window.location);v.searchParams.set("data",t),history.pushState({},"",v)}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 n=(i==null?void 0:i.method)||"POST";a||(n="GET");const c=await fetch(r,{headers:{Authorization:getToken()},method:n,body:n==="GET"?void 0:JSON.stringify({id:t})});if(c.ok){let h=await c.text();return h.constructor===Object||h.constructor===Array?h=JSON.parse(JSON.stringify(h)):typeof h=="string"&&(h=JSON.parse(h)),h.data&&(h=h.data),h}else e.emitter.emit("error",{type:"http",error:c})}function getter(e,t){if(t==null)return e;const i=t.split(".");for(;i.length&&(e=e[i.shift()]););return e}function setter(e,t,i){t!=null&&t.split(".").reduce((s,r,a)=>s[r]=t.split(".").length===++a?i:s[r]||{},e)}function formatTime(e,t){const i=["天","一","二","三","四","五","六"];let s=new Date;t&&(s=new Date(t));const r=s.getFullYear(),a=s.getMonth()+1,n=s.getDate(),c=s.getDay(),l=s.getHours(),u=s.getMinutes(),h=s.getSeconds();let v=new Function("year","month","day","week","hours","minutes","seconds",e?`return ${e}`:"return `${year}:${month}:${day} ${hours}:${minutes}:${seconds} 星期${week}`");const f=v(r,a,n,i[c],l,u,h);return v=null,f}const debounces=new WeakMap;function debounce(e,t,i){let s=debounces.get(e);return s?clearTimeout(s.timer):(s={},debounces.set(e,s)),new Promise((r,a)=>{s.timer=setTimeout(async()=>{r(await e(i)),debounces.delete(e)},t)})}class InstanceDebouncer{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(...n)=>{a[r]&&clearTimeout(a[r]),a[r]=setTimeout(()=>{t[i](...n),delete a[r]},s)}}}B(InstanceDebouncer,"instances",new WeakMap);const LINE="line",REPEAT="repeat";function isAncestor(e,t){if(!e||!t)return!1;let i=getParent(e);for(;i;){if(i.id===t.id)return!0;i=getParent(i)}return!1}function getParent(e,t){if(!e||!e.parentId||!e.calculative)return;const s=e.calculative.canvas.store.pens[e.parentId];return t&&getParent(s,t)||s}function getAllChildren(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(...getAllChildren(r,t)))}),i}function getAllFollowers(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(...getAllFollowers(r,t)))}),i}function drawBkLinearGradient(e,t){const{worldRect:i,gradientFromColor:s,gradientToColor:r,gradientAngle:a}=t.calculative;return linearGradient(e,i,s,r,a)}function drawBkRadialGradient(e,t){const{worldRect:i,gradientFromColor:s,gradientToColor:r,gradientRadius:a}=t.calculative;if(!s||!r)return;const{width:n,height:c,center:l}=i,{x:u,y:h}=l;let v=n;v<c&&(v=c),v*=.5;const f=e.createRadialGradient(u,h,v*(a||0),u,h,v);return f.addColorStop(0,s),f.addColorStop(1,r),f}function getLinearGradientPoints(e,t,i,s,r){let a=0;a=Math.PI/2-Math.atan2(s-t,i-e);const n=(e+i)/2,c=(t+s)/2,l=n+r*Math.sin(90*Math.PI/180-a),u=c+r*-Math.cos(90*Math.PI/180-a),h=n+r*Math.sin(270*Math.PI/180-a),v=c+r*-Math.cos(270*Math.PI/180-a);return[l,u,h,v]}function getBkRadialGradient(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:n,height:c,center:l}=i,{x:u,y:h}=l;let v=n;v<c&&(v=c),v*=.5;const{colors:f}=formatGradient(a),g=e.createRadialGradient(u,h,v*(r||0),u,h,v);return f.forEach(y=>{g.addColorStop(y.i,y.color)}),g}function getBkGradient(e,t){const{x:i,y:s,ex:r,width:a,height:n,center:c}=t.calculative.worldRect;let l=[{x:r,y:s+n/2},{x:i,y:s+n/2}],u=t.calculative.gradientColors;t.calculative.checked&&(u=t.calculative.onGradientColors);const{angle:h,colors:v}=formatGradient(u);let f=getGradientR(h,a,n);return l.forEach(g=>{rotatePoint(g,h,c)}),getLinearGradient(e,l,v,f)}function getTextRadialGradient(e,t){const{worldRect:i,textGradientColors:s}=t.calculative;if(!s)return;const{width:r,height:a,center:n}=i,{x:c,y:l}=n;let u=r;u<a&&(u=a),u*=.5;const{colors:h}=formatGradient(s),v=e.createRadialGradient(c,l,0,c,l,u);return h.forEach(f=>{v.addColorStop(f.i,f.color)}),v}function getTextGradient(e,t){!t.calculative.textDrawRect&&calcTextDrawRect(e,t),calcCenter(t.calculative.textDrawRect);const{x:i,y:s,ex:r,width:a,height:n,center:c}=t.calculative.textDrawRect;let l=[{x:r,y:s+n/2},{x:i,y:s+n/2}];const{angle:u,colors:h}=formatGradient(t.calculative.textGradientColors);let v=getGradientR(u,a,n);return l.forEach(f=>{rotatePoint(f,u,c)}),getLinearGradient(e,l,h,v)}function getGradientR(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 formatGradient(e){if(typeof e=="string"&&e.startsWith("linear-gradient")){let t=e.slice(16,-2).split("deg,");if(t.length>1){let i=t[1].split("%,");const s=[];return i.forEach(r=>{if(/rgba?/.test(r)){let a=r.split(") ");s.push({color:rgbaToHex(a[0]+")"),i:parseFloat(a[1])/100})}else{let a=r.split(" ");a.length>2?s.push({color:a[1],i:parseFloat(a[2])/100}):s.push({color:a[0],i:parseFloat(a[1])/100})}}),{angle:parseFloat(t[0]),colors:s}}else return{angle:parseFloat(t[0]),colors:[]}}else return{angle:0,colors:[]}}function rgbaToHex(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 getLineGradient(e,t){const{x:i,y:s,ex:r,width:a,height:n,center:c}=t.calculative.worldRect;let l=[{x:r,y:s+n/2},{x:i,y:s+n/2}];const{angle:u,colors:h}=formatGradient(t.calculative.lineGradientColors);let v=getGradientR(u,a,n);return l.forEach(f=>{rotatePoint(f,u,c)}),getLinearGradient(e,l,h,v)}function getLinearGradient(e,t,i,s){let r=getLinearGradientPoints(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(n=>{a.addColorStop(n.i,n.color)}),a}function drawLinearGradientLine(e,t,i){let s=[];t.calculative.gradientColorStop?s=t.calculative.gradientColorStop:(s=formatGradient(t.calculative.lineGradientColors).colors,t.calculative.gradientColorStop=s),e.strokeStyle=getLinearGradient(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 ctxDrawLinearGradientPath(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 c=i[r-1].curvePoints;c?smoothTransition(e,t,s,c[c.length-1],i[r],i[r].curvePoints[0]):smoothTransition(e,t,s,i[r-1],i[r],i[r].curvePoints[0]);let l=getSmoothAdjacent(s,i[r],i[r].curvePoints[0]);drawLinearGradientLine(e,t,[l,i[r].curvePoints[1]])}else drawLinearGradientLine(e,t,[i[r],i[r].curvePoints[0]]),drawLinearGradientLine(e,t,[i[r].curvePoints[0],i[r].curvePoints[1]]);let a=i[r].curvePoints.length-1;for(let c=1;c<a;c++)drawLinearGradientLine(e,t,[i[r].curvePoints[c],i[r].curvePoints[c+1]]);let n=getSmoothAdjacent(s,i[r+1],i[r].curvePoints[a]);drawLinearGradientLine(e,t,[i[r].curvePoints[a],n])}else{let a=i[r],n=i[r+1];if(r>0&&r<i.length-1){let l=i[r-1].curvePoints;l?smoothTransition(e,t,s,l[l.length-1],i[r],i[r+1]):smoothTransition(e,t,s,i[r-1],i[r],i[r+1])}r>0&&r<i.length-1&&(a=getSmoothAdjacent(s,i[r],i[r+1])),r<i.length-2&&(n=getSmoothAdjacent(s,i[r+1],i[r]));let c=!1;if(r===0&&t.fromLineCap&&t.fromLineCap!=="butt"&&(e.save(),c=!0,e.lineCap=t.fromLineCap),r!==0&&r===i.length-2&&t.toLineCap&&t.toLineCap!=="butt"&&(e.save(),c=!0,e.lineCap=t.toLineCap),drawLinearGradientLine(e,t,[a,n]),c&&e.restore(),i.length===2&&r===0){e.save(),c=!0,e.lineCap=t.toLineCap;let l=.1,u=.1;a.x-n.x===0?u=0:l=(a.y-n.y)/(a.x-n.x)*.1,drawLinearGradientLine(e,t,[{x:n.x-u,y:n.y-l},n]),e.restore()}}}function getSmoothAdjacent(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 smoothTransition(e,t,i,s,r,a){let n=getSmoothAdjacent(i,r,s),c=getSmoothAdjacent(i,r,a),l={x:r.x,y:r.y},u=getBezierPoints(t.calculative.canvas.store.data.smoothNum||20,n,l,c);for(let h=0;h<u.length-1;h++)drawLinearGradientLine(e,t,[{x:u[h].x,y:u[h].y},{x:u[h+1].x,y:u[h+1].y}])}function smoothAnimateTransition(e,t,i,s){let r=getSmoothAdjacent(t,i,s),a={x:i.x,y:i.y};e.quadraticCurveTo(a.x,a.y,r.x,r.y)}function getGradientAnimatePath(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 n=t[r-1].curvePoints;smoothAnimateTransition(s,i,t[r],t[r+1])}r>0&&r<t.length-1&&getSmoothAdjacent(i,t[r],t[r+1]),r<t.length-2&&(a=getSmoothAdjacent(i,t[r+1],t[r])),s.lineTo(a.x,a.y)}return s}function getBezierPoints(e=100,t,i,s,r){let a=null;const n=[];!s&&!r?a=oneBezier:s&&!r&&(a=twoBezier);for(let c=0;c<e;c++)n.push(a(c/e,t,i,s,r));return s&&n.push(s),n}function oneBezier(e,t,i){const{x:s,y:r}=t,{x:a,y:n}=i;let c=s+(a-s)*e,l=r+(n-r)*e;return{x:c,y:l}}function twoBezier(e,t,i,s){const{x:r,y:a}=t,{x:n,y:c}=i,{x:l,y:u}=s;let h=(1-e)*(1-e)*r+2*e*(1-e)*n+e*e*l,v=(1-e)*(1-e)*a+2*e*(1-e)*c+e*e*u;return{x:h,y:v}}function strokeLinearGradient(e,t){const{worldRect:i,lineGradientFromColor:s,lineGradientToColor:r,lineGradientAngle:a}=t.calculative;return linearGradient(e,i,s,r,a)}function linearGradient(e,t,i,s,r){if(!i||!s)return;const{x:a,y:n,center:c,ex:l,ey:u}=t,h={x:a,y:c.y},v={x:l,y:c.y};r%90===0&&r%180?(h.x=c.x,v.x=c.x,r%270?(h.y=n,v.y=u):(h.y=u,v.y=n)):r&&(rotatePoint(h,r,t.center),rotatePoint(v,r,t.center));const f=e.createLinearGradient(h.x,h.y,v.x,v.y);return f.addColorStop(0,i),f.addColorStop(1,s),f}function getImagePosition(e){const{worldIconRect:t,iconWidth:i,iconHeight:s,imgNaturalWidth:r,imgNaturalHeight:a,worldRect:n}=e.calculative;if(!t)return{x:n.x,y:n.y,width:n.width||r||e.calculative.img.naturalWidth,height:n.height||a||e.calculative.img.naturalHeight};let{x:c,y:l,width:u,height:h}=t;if(i&&(u=i),s&&(h=s),r&&a&&e.imageRatio){const v=t.width/r,f=t.height/a,g=Math.min(v,f),y=r/a;i?h=i/y:s?u=s*y:(u=g*r,h=g*a)}switch(c+=(t.width-u)/2,l+=(t.height-h)/2,e.iconAlign){case"top":l=t.y;break;case"bottom":l=t.ey-h;break;case"left":c=t.x;break;case"right":c=t.ex-u;break;case"left-top":c=t.x,l=t.y;break;case"right-top":c=t.ex-u,l=t.y;break;case"left-bottom":c=t.x,l=t.ey-h;break;case"right-bottom":c=t.ex-u,l=t.ey-h;break}return{x:c,y:l,width:u,height:h}}function drawImage(e,t){const{x:i,y:s,width:r,height:a}=getImagePosition(t),{worldIconRect:n,iconRotate:c,img:l}=t.calculative;if(e.filter=t.filter,c){const{x:u,y:h}=n.center;e.translate(u,h),e.rotate(c*Math.PI/180),e.translate(-u,-h)}if(t.imageRadius){e.save();let u=t.calculative.imageRadius||0,h=u;const{x:v,y:f,width:g,height:y,ex:p,ey:m}=t.calculative.worldRect;u<1&&(u=g*u,h=y*h);let x=u<h?u:h;g<2*x&&(x=g/2),y<2*x&&(x=y/2),e.beginPath(),e.moveTo(v+x,f),e.arcTo(p,f,p,m,x),e.arcTo(p,m,v,m,x),e.arcTo(v,m,v,f,x),e.arcTo(v,f,p,f,x),e.clip(),e.drawImage(l,i,s,r,a),e.restore()}else{let u=s,h=0;if(t.thumbImg){let v=l.naturalWidth,f=l.naturalHeight;h=(a/r*v-f)/2,a-2*h<0&&(h=(a-f/v*r)/2),u=s+h}e.drawImage(l,i,u,r,a-2*h)}}function getTextColor(e,t){const{textColor:i,color:s}=e.calculative,{styles:r}=t;return i||s||r.textColor||r.color}function drawText(e,t){const{fontStyle:i,fontWeight:s,fontSize:r,fontFamily:a,lineHeight:n,text:c,hiddenText:l,canvas:u,textHasShadow:h,textBackground:v,textType:f}=t.calculative;if(t.input&&isEmptyText(t.text)&&t.calculative.canvas.inputDiv.dataset.penId!==t.id&&!t.onShowInput){e.save(),e.font=getFont({fontStyle:i,fontWeight:s,fontFamily:a,fontSize:r,lineHeight:n}),e.textBaseline="top",e.fillStyle=t.placeholderColor||"#c0c0c0";const L=e.measureText(t.placeholder||"请输入").width,E=t.calculative.worldTextRect;let F=0,q=(E.height-t.calculative.fontSize)/2;t.textAlign==="center"?F=(E.width-L)/2:t.textAlign==="right"&&(F=E.width-L),t.textBaseline==="top"?q=0:t.textBaseline==="bottom"&&(q=E.height-t.calculative.fontSize),e.fillText(t.placeholder||"请输入",E.x+F,E.y+q),e.restore()}if(isEmptyText(c)||l||t.hiddenText)return;const g=u.store;e.save(),h||(e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0);let y;t.calculative.disabled?y=t.disabledTextColor||t.disabledColor||pSBC(.4,getTextColor(t,g)):t.calculative.hover?y=t.hoverTextColor||t.hoverColor||g.styles.hoverColor:t.calculative.active&&(y=t.activeTextColor||t.activeColor||g.styles.activeColor);let p;f===Gradient.Linear?p=getTextGradient(e,t):f===Gradient.Radial&&(p=getTextRadialGradient(e,t)),e.fillStyle=y||p||getTextColor(t,g),e.font=getFont({fontStyle:i,fontWeight:s,fontFamily:a||g.options.fontFamily,fontSize:r,lineHeight:n}),(!t.calculative.textDrawRect||t.calculative.fontsChecked)&&calcTextDrawRect(e,t);const{x:m,y:x,width:k,height:w}=t.calculative.textDrawRect;v&&(e.save(),e.fillStyle=v,e.fillRect(m,x,k,w),e.restore());const C=.55,I=t.textAlign||g.options.textAlign,_=r*n;t.calculative.textLines&&t.calculative.textLines.forEach((L,E)=>{const F=t.calculative.textLineWidths[E];let q=0;I==="center"?q=(k-F)/2:I==="right"&&(q=k-F),t.letterSpacing?fillTextWithSpacing(e,L,m+q,x+(E+C)*_,t.calculative.letterSpacing):e.fillText(L,m+q,x+(E+C)*_);const{textDecorationColor:R,textDecorationDash:A,textDecoration:P}=t;P&&drawUnderLine(e,{x:m+q,y:x+(E+C)*_,width:F},{textDecorationColor:R,textDecorationDash:A,fontSize:r});const{textStrickoutColor:M,textStrickoutDash:H,textStrickout:$}=t;$&&drawStrickout(e,{x:m+q,y:x+(E+C)*_,width:F},{textStrickoutColor:M,textStrickoutDash:H,fontSize:r})}),e.restore()}function fillTextWithSpacing(e,t,i,s,r=0){if(r===0){e.fillText(t,i,s);return}let a=0;for(let n=0;n<t.length;n++)e.fillText(t[n],i+a,s),a+=e.measureText(t[n]).width+r}function drawUnderLine(e,t,i){const{textDecorationColor:s,textDecorationDash:r,fontSize:a}=i;let{x:n,y:c,width:l}=t;switch(e.textBaseline){case"top":c+=a;break;case"middle":c+=a/2;break}e.save(),e.beginPath(),e.strokeStyle=s||e.fillStyle,e.lineWidth=1,e.moveTo(n,c),e.setLineDash(r||[]),e.lineTo(n+l,c),e.stroke(),e.restore()}function drawStrickout(e,t,i){const{textStrickoutColor:s,textStrickoutDash:r,fontSize:a}=i;let{x:n,y:c,width:l}=t;switch(e.textBaseline){case"top":c+=a/2;break;case"bottom":c-=a/2;break}e.save(),e.beginPath(),e.strokeStyle=s||e.fillStyle,e.lineWidth=1,e.moveTo(n,c),e.setLineDash(r||[]),e.lineTo(n+l,c),e.stroke(),e.restore()}function drawFillText(e,t,i){if(i==null)return;const{fontStyle:s,fontWeight:r,fontSize:a,fontFamily:n,lineHeight:c,canvas:l}=t.calculative,u=l.store;e.save();let h;t.calculative.hover?h=t.hoverTextColor||t.hoverColor||u.styles.hoverColor:t.calculative.active&&(h=t.activeTextColor||t.activeColor||u.styles.activeColor),e.fillStyle=h||getTextColor(t,u),e.font=getFont({fontStyle:s,fontWeight:r,fontFamily:n||u.options.fontFamily,fontSize:a,lineHeight:c});const v=e.measureText(i).width;let f,g;for(const y of t.calculative.worldAnchors){if(!g){g=y;continue}const p=distance(g,y),m=Math.floor(p/v);f="";for(let k=0;k<m;k++)f+=i;const x=calcRotate(g,y)-270;if(e.save(),x%360!==0){const{x:k,y:w}=g;e.translate(k,w);let C=x*Math.PI/180;e.rotate(C),e.translate(-k,-w)}e.fillText(f,g.x,g.y+c/2),e.restore(),g=y}e.restore()}function drawIcon(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 n=t.calculative.iconWeight;let c;const l=t.calculative.iconFamily;t.calculative.iconSize>0?c=t.calculative.iconSize:s.width>s.height?c=s.height:c=s.width,e.font=getFont({fontSize:c,fontWeight:n,fontFamily:l}),e.fillStyle=t.calculative.iconColor||getTextColor(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 drawDropdown(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:n,height:c}=t.calculative.worldRect;e.save(),e.beginPath(),t.id===s?(e.moveTo(r+n-20*i,a+c/2+2*i),e.lineTo(r+n-14*i,a+c/2-4*i),e.lineTo(r+n-8*i,a+c/2+2*i)):(e.moveTo(r+n-20*i,a+c/2-4*i),e.lineTo(r+n-14*i,a+c/2+2*i),e.lineTo(r+n-8*i,a+c/2-4*i)),e.stroke(),e.restore()}function getFont({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 ctxFlip(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 ctxRotate(e,t,i=!1){if(t.parentId&&t.rotateByRoot){let s=getParent(t,!0);if(s){const{x:r,y:a}=s.calculative.worldRect.pivot||s.calculative.worldRect.center;e.translate(r,a);let n=s.calculative.rotate*Math.PI/180;i||(s.calculative.flipX&&(n*=-1),s.calculative.flipY&&(n*=-1)),e.rotate(n),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 renderPen(e,t,i){var v;e.save(),e.translate(.5,.5),e.beginPath(),drawFilter(e,t);const s=t.calculative.canvas.store,r=t.textFlip||s.options.textFlip,a=t.textRotate||s.options.textRotate;(!r||!a)&&e.save(),ctxFlip(e,t),(t.rotateByRoot||t.calculative.rotate&&t.name!==LINE)&&ctxRotate(e,t),(t.calculative.lineWidth>1||i)&&(e.lineWidth=t.calculative.lineWidth),inspectRect(e,s,t);let n,c=!1,l;t.calculative.disabled?(l=t.disabledColor||s.styles.disabledColor||pSBC(.4,t.calculative.color||s.styles.color),n=t.disabledBackground||s.styles.disabledBackground||pSBC(.4,t.calculative.background||s.styles.penBackground)):t.mouseDownValid&&t.calculative.mouseDown?(l=t.mouseDownColor||pSBC(-.4,t.calculative.color||s.styles.color),n=t.mouseDownBackground||pSBC(-.4,t.calculative.background||s.styles.penBackground)):t.switch&&t.calculative.checked?t.calculative.bkType||(n=t.onBackground):t.calculative.hover?(l=t.hoverColor||s.styles.hoverColor,n=t.hoverBackground||s.styles.hoverBackground):t.calculative.active?(l=t.activeColor||s.styles.activeColor,n=t.activeBackground||s.styles.activeBackground):t.calculative.isDock&&(t.type===PenType.Line?l=s.styles.dockPenColor:n=rgba(s.styles.dockPenColor,.2));const u=t.calculative.strokeImg;if(t.calculative.strokeImage&&u)e.strokeStyle=l||e.createPattern(u,REPEAT);else{let f;t.calculative.strokeType?t.calculative.lineGradientColors?t.name===LINE?c=!0:t.calculative.lineGradient?f=t.calculative.lineGradient:(f=getLineGradient(e,t),t.calculative.lineGradient=f):f=strokeLinearGradient(e,t):f=t.calculative.color||(t.type?s.data.lineColor:"")||s.styles.color,e.strokeStyle=l||f}const h=t.calculative.backgroundImg;if(t.calculative.backgroundImage&&h)e.fillStyle=n||e.createPattern(h,REPEAT),n=!0;else{let f;t.calculative.bkType===Gradient.Linear?t.calculative.gradientColors?t.calculative.gradient?f=t.calculative.gradient:(f=getBkGradient(e,t),t.calculative.gradient=f):f=drawBkLinearGradient(e,t):t.calculative.bkType===Gradient.Radial?t.calculative.gradientColors?t.calculative.radialGradient?f=t.calculative.radialGradient:(f=getBkRadialGradient(e,t),t.calculative.radialGradient=f):f=drawBkRadialGradient(e,t):f=t.calculative.background||s.styles.penBackground,e.fillStyle=n||f,n=!!f}if(setLineCap(e,t),setLineJoin(e,t),setGlobalAlpha(e,t),t.calculative.lineDash&&e.setLineDash(t.calculative.lineDash.map(f=>f*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),c?(ctxDrawLinearGradientPath(e,t),ctxDrawLinePath(!0,e,t,s)):(ctxDrawPath(!0,e,t,s,n),ctxDrawCanvas(e,t)),!(t.image&&t.calculative.img)&&t.calculative.icon&&drawIcon(e,t),t.dropdownList&&drawDropdown(e,t),(!r||!a)&&e.restore(),r&&!a&&ctxFlip(e,t),!r&&a&&(t.rotateByRoot||t.calculative.rotate&&t.name!=="line")&&ctxRotate(e,t,!0),drawText(e,t),t.type===PenType.Line&&((v=t.fillTexts)==null?void 0:v.length)>0)for(const f of t.fillTexts)drawFillText(e,t,f);e.restore()}function setLineCap(e,t){const i=t.lineCap||(t.type?"round":"square");e.lineCap=i}function setLineJoin(e,t){const i=t.lineJoin;i?e.lineJoin=i:t.type&&(e.lineJoin="round")}function renderPenRaw$1(e,t,i,s){var u,h;e.save(),i&&e.translate(-i.x,-i.y),(u=e.setAttrs)==null||u.call(e,t);let r=!1;const a=t.calculative.canvas.store,n=t.textFlip||a.options.textFlip,c=t.textRotate||a.options.textRotate;e.beginPath(),(!n||!c)&&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")&&ctxRotate(e,t),(t.calculative.lineWidth>1||s)&&(e.lineWidth=t.calculative.lineWidth);let l;if(t.calculative.hover)e.strokeStyle=t.hoverColor||a.styles.hoverColor,e.fillStyle=t.hoverBackground||a.styles.hoverBackground,l=t.hoverBackground||a.styles.hoverBackground;else if(t.calculative.active)e.strokeStyle=t.activeColor||a.styles.activeColor,e.fillStyle=t.activeBackground||a.styles.activeBackground,l=t.activeBackground||a.styles.activeBackground;else{if(t.strokeImage)t.calculative.strokeImg&&(e.strokeStyle=e.createPattern(t.calculative.strokeImg,REPEAT),l=!0);else{let v;t.calculative.strokeType&&t.calculative.lineGradientColors&&t.name==="line"?r=!0:v=t.calculative.color||a.styles.color,e.strokeStyle=v}t.backgroundImage?t.calculative.backgroundImg&&(e.fillStyle=e.createPattern(t.calculative.backgroundImg,REPEAT),l=!0):(e.fillStyle=t.background,l=!!t.background)}if(setLineCap(e,t),setLineJoin(e,t),setGlobalAlpha(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?(ctxDrawLinearGradientPath(e,t),ctxDrawLinePath(!0,e,t,a)):(ctxDrawPath(!1,e,t,a,l),ctxDrawCanvas(e,t)),t.calculative.img?(e.save(),e.shadowColor="",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0,drawImage(e,t),e.restore()):t.calculative.icon&&drawIcon(e,t),t.dropdownList&&drawDropdown(e,t),(!n||!c)&&e.restore(),n&&!c&&(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))),!n&&c&&(t.rotateByRoot||t.calculative.rotate&&t.name!=="line")&&ctxRotate(e,t,!0),drawText(e,t),t.type===PenType.Line&&((h=t.fillTexts)==null?void 0:h.length)>0)for(const v of t.fillTexts)drawFillText(e,t,v);e.restore()}function ctxDrawPath(e=!0,t,i,s,r){if(i.name==="drawCommand")return;const a=e?s.path2dMap.get(i):globalStore.path2dDraws[i.name];let n=null,c=null;if(i.type===PenType.Line&&(i.fromLineCap&&i.fromLineCap!=="butt"&&(t.lineCap="butt",n=new Path2D,n.moveTo(i.calculative.worldAnchors[0].x,i.calculative.worldAnchors[0].y),n.lineTo(i.calculative.worldAnchors[0].x,i.calculative.worldAnchors[0].y)),i.toLineCap&&i.toLineCap!=="butt"&&(t.lineCap="butt",c=new Path2D,c.moveTo(i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].x,i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].y),c.lineTo(i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].x,i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].y))),a){if(i.type===PenType.Line&&i.borderWidth){t.save(),t.beginPath();const u=i.calculative.lineWidth+i.calculative.borderWidth;t.lineWidth=u,t.strokeStyle=i.borderColor,n&&(t.save(),t.lineCap=i.fromLineCap,t.stroke(n),t.restore()),a instanceof Path2D?(r&&t.fill(a),u&&t.stroke(a)):(a(i,t),r&&t.fill(),u&&t.stroke()),c&&(t.save(),t.lineCap=i.toLineCap,t.stroke(c),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 l=(i.calculative.progress-(i.calculative.min||0))/((i.calculative.max||1)-(i.calculative.min||0));if(l!=null&&!isNaN(l)){t.save();const{ex:u,x:h,y:v,width:f,height:g,ey:y}=i.calculative.worldRect;let p=null;if(i.calculative.verticalProgress?p=i.reverseProgress?t.createLinearGradient(h,v,h,v+g*l):t.createLinearGradient(h,y,h,v+g*(1-l)):p=i.reverseProgress?t.createLinearGradient(u,v,h+f*(1-l),v):t.createLinearGradient(h,v,h+f*l,v),i.calculative.progressGradientColors){const{colors:m}=formatGradient(i.calculative.progressGradientColors);m.forEach(x=>{p.addColorStop(x.i,x.color)})}else{const m=i.calculative.progressColor||i.calculative.color||s.options.activeColor||s.data.color;p.addColorStop(0,m),p.addColorStop(1,m)}p.addColorStop(1,"transparent"),t.fillStyle=p,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")&&(n&&(t.save(),t.lineCap=i.fromLineCap,t.stroke(n),t.restore()),t.stroke(a),c&&(t.save(),t.lineCap=i.toLineCap,t.stroke(c),t.restore())):(a(i,t),t.stroke())),i.type){if(i.calculative.animatePos){if(t.save(),setCtxLineAnimate(t,i,s),i.lineAnimateType===LineAnimateType.Arrow||i.lineAnimateType===LineAnimateType.WaterDrop){let u=drawArrow(i,t);u instanceof Path2D?(t.stroke(u),t.fill(u)):(t.stroke(),t.fill())}else a instanceof Path2D?(n&&!i.lineAnimateType&&(t.save(),t.lineCap=i.fromLineCap,t.stroke(n),t.restore()),t.lineCap=i.lineCap,t.stroke(a)):(a(i,t),t.stroke());t.restore()}i.fromArrow&&renderFromArrow(t,i,s),i.toArrow&&renderToArrow(t,i,s),renderLineDirectionMarkers(t,i,s),i.calculative.active&&!i.calculative.pencil&&!s.options.disableAnchor&&!s.data.locked&&renderLineAnchors(t,i)}}}function ctxDrawLinePath(e=!0,t,i,s){const r=e?s.path2dMap.get(i):globalStore.path2dDraws[i.name];if(r&&i.type){if(i.calculative.animatePos){if(t.save(),setCtxLineAnimate(t,i,s),t.beginPath(),r instanceof Path2D)if(i.lineName==="polyline"||i.lineName==="line")if(i.lineAnimateType===LineAnimateType.Arrow||i.lineAnimateType===LineAnimateType.WaterDrop){const a=drawArrow(i);t.stroke(a),t.fill(a)}else i.calculative.gradientSmooth||i.calculative.lineSmooth?(i.calculative.gradientAnimatePath||(i.calculative.gradientAnimatePath=getGradientAnimatePath(i)),i.calculative.gradientAnimatePath instanceof Path2D&&t.stroke(i.calculative.gradientAnimatePath)):t.stroke(r);else t.stroke(r);else r(i,t),t.stroke();t.restore()}i.fromArrow&&renderFromArrow(t,i,s),i.toArrow&&renderToArrow(t,i,s),renderLineDirectionMarkers(t,i,s),i.calculative.active&&!i.calculative.pencil&&!s.options.disableAnchor&&!s.data.locked&&renderLineAnchors(t,i)}}function setCtxLineAnimate(e,t,i){e.strokeStyle=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=>{renderLineAnimate(t,i,s,e)}):renderLineAnimate(t,i,t.lineAnimateType,e)}function renderLineAnimate(e,t,i,s){let r=0;switch(i){case LineAnimateType.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(n=>n*r/5);s.setLineDash(a||[r,r*2]);break;case LineAnimateType.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 LineAnimateType.Arrow:s.fillStyle=e.animateColor||t.styles.animateColor,s.lineWidth=1;break;case LineAnimateType.WaterDrop:s.fillStyle=e.animateColor||t.styles.animateColor,s.lineWidth=1;break;case LineAnimateType.Custom:switch(e.lineAnimateTargetType){case lineAnimateTargetType.Image:if(e.lineAnimateImages??(e.lineAnimateImages=[]),e.lineAnimateImages.length>0){const l=e.lineAnimateImages.map((u,h)=>{const v=globalStore.htmlElements[u];if(!v)e.calculative.canvas.__loadImage(u);else return v});setElementAnimateOnLine(s,e,"image",l)}break;case lineAnimateTargetType.Icon:const n=e.lineAnimateIcon;setElementAnimateOnLine(s,e,"icon",n);break;case lineAnimateTargetType.Pen:e.lineAnimatePens&&setElementAnimateOnLine(s,e,"pen",e.lineAnimatePens);break;case lineAnimateTargetType.Element:const c=e.lineAnimateElement;setElementAnimateOnLine(s,e,"element",c)}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 setElementAnimateOnLine(e,t,i,s){let r=null;switch(i){case"image":r=lineAnimateImageRender(s);break;case"icon":r=lineAnimateIconRender(s);break;case"pen":let a=t.calculative.canvas.find(s);t.lineAnimateElementCount=a.length,r=lineAnimatePenRender(a);break;case"element":if(r=globalStore.lineAnimateDraws[s],!r)return;break}renderElementOnLine(e,t,r)}function lineAnimateImageRender(e){return function(t,i,s,r){const a=i.calculative.canvas.store.data.scale,n=i.lineAnimateElementWidth||10,c=i.lineAnimateElementHeight||10,l=e[r%e.length];l&&(t.save(),t.translate(s.x,s.y),t.rotate(s.rotate*Math.PI/180),t.scale(a,a),t.drawImage(l,-n/2,-c/2,n,c),t.restore())}}function lineAnimatePenRender(e){return function(t,i,s,r){const a=e[r%e.length];if(!a)return;const n=i.calculative.canvas.store.data.scale,c=i.calculative.canvas.store.data.origin,l=i.calculative.canvas.parent,u=a.width,h=a.height,v=s.x-u/2,f=s.y-h/2,g=(v-c.x)/n,y=(f-c.y)/n,p=u/n,m=h/n,x={x:g,y,width:p,height:m,rotate:s.rotate};l.setValue({id:a.id,...x})}}function lineAnimateIconRender(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 n=i.calculative.iconWeight;let c;const l=i.calculative.iconFamily;c=i.calculative.iconSize||Math.max(i.lineAnimateElementWidth||0,i.lineAnimateElementHeight||0)||10,t.font=getFont({fontSize:c,fontWeight:n,fontFamily:l}),t.fillStyle=i.calculative.iconColor||getTextColor(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 renderElementOnLine(e,t,i){var a;const s=t.calculative.canvas.store.data.scale,r=getLineLength(t)/s;if(t.lineAnimateLoopMode)renderLoopElementsOnLine(e,t,i,r,s);else{const n=Array.isArray(t.lineAnimateDash)?t.lineAnimateDash:((a=t.lineAnimateDash)==null?void 0:a.split(",").map(l=>Number(l)))||[10,20];computeLineDashSegments(r,n,t.lineAnimateDashOffset,t.lineAnimateElementCount).forEach((l,u)=>{const h=calculateLineFrameStates(t,l.start);if(h)try{e.save(),i(e,t,h,u),e.restore()}catch(v){e.restore(),console.warn(v)}})}}function renderLoopElementsOnLine(e,t,i,s,r){var u;const n=((Array.isArray(t.lineAnimateDash)?t.lineAnimateDash:((u=t.lineAnimateDash)==null?void 0:u.split(",").map(h=>Number(h)))||[10,20])[0]||30)*r,c=t.calculative.animatePos,l=t.calculative.worldAnchors;if(l.length>1){let h,v=0;for(let f=0;f<l.length;f++){let g=l[f];if(h){const y=t.length;let m=(c-v)%n-n,x=0;for(;m<y;){if(m>=0){const k=v+m,w=(c-k)/r;try{e.save();const C=calculateLineFrameStates(t,w);C&&i(e,t,C,x),e.restore()}catch(C){e.restore(),console.warn(C)}}m+=n,x++}v+=y}h=g}if(t.close){let f=l[0];if(h){const g=Math.sqrt((f.x-h.x)**2+(f.y-h.y)**2);let p=(c-v)%n-n,m=0;for(;p<g;){if(p>=0){const x=v+p,k=(c-x)/r;try{e.save();const w=calculateLineFrameStates(t,k);w&&i(e,t,w,m),e.restore()}catch(w){e.restore(),console.warn(w)}}p+=n,m++}}}}}function computeLineDashSegments(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 n=t.reduce((h,v)=>h+v,0);let c=(-i+r)%n;c<0&&(c+=n);let l=0,u=0;for(s||(s=1/0);u<e&&l<s;)for(let h=0;h<t.length;h++){const v=t[h],f=h%2===0;let g=u,y=u+v-c;if(y>e&&(y=e),f&&y>g){const p=(g+r)%e,m=(y+r)%e;a.push({start:p,end:m,isDash:!0}),l+=1}if(u=y,c=0,u>=e||l>=s)break}return a}function calculateLineFrameStates(e,t=0){let i,s=null;if(e.calculative.worldAnchors.forEach(n=>{s&&(i=createSvgPath(i,s,s.next,n.prev,n)),s=n}),e.close){let n=e.calculative.worldAnchors[0];i=createSvgPath(i,s,s.next,n.prev,n)}let r=0;return e.animateReverse?r=e.length-e.calculative.animatePos-t*e.calculative.canvas.store.data.scale:r=e.calculative.animatePos-t*e.calculative.canvas.store.data.scale,getLinePointPosAndAngle(i,r)}function renderLineAnchors(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&&renderAnchor(e,s,t)}),e.restore()}function renderAnchor(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 calcWorldRects(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,calcRightBottom(i),calcCenter(i),e.pivot&&calcPivot(i,e.pivot);else{const s=t.pens[e.parentId];let r=s.calculative.worldRect;r||(r=calcWorldRects(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),calcRightBottom(i),i.rotate=r.rotate+e.rotate,calcCenter(i),e.pivot&&calcPivot(i,e.pivot)}return e.calculative.worldRect=i,calcPadding(e,i),i}function calcPadding(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 calcPenRect(e){const t=deepClone(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,calcRelativeRect(t,s))}function calcWorldAnchors(e){const t=e.calculative.canvas.store;let i=[];if(e.anchors){let s=deepClone(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(calcWorldPointOfPen(e,r))})}if(!i.length&&!e.type&&!e.calculative.canvas.parent.isCombine(e)){const{x:s,y:r,width:a,height:n}=e.calculative.worldRect;for(let c=0;c<t.options.defaultAnchors.length;c++){const l=t.options.defaultAnchors[c];i.push({id:`${c}`,penId:e.id,x:s+a*l.x,y:r+n*l.y})}}e.calculative.rotate&&e.name!=="line"&&i.forEach(s=>{rotatePoint(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 calcChildrenInitRect(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,calcCenter(r.calculative.initRect)),calcChildrenInitRect(r)})}}function calcWorldPointOfPen(e,t){const i={...t},{x:s,y:r,width:a,height:n}=e.calculative.worldRect;return i.x=s+a*t.x,i.y=r+n*t.y,t.prev&&(i.prev={penId:e.id,connectTo:t.prev.connectTo,x:s+a*t.prev.x,y:r+n*t.prev.y}),t.next&&(i.next={penId:e.id,connectTo:t.next.connectTo,x:s+a*t.next.x,y:r+n*t.next.y}),i}function calcIconRect(e,t){if(!t.image&&!t.icon&&!t.thumbImg)return;const{paddingTop:i,paddingBottom:s,paddingLeft:r,paddingRight:a}=t.calculative;let n=r,c=i,l=t.calculative.worldRect.width-r-a,u=t.calculative.worldRect.height-i-s,h=t.calculative.iconLeft||0,v=t.calculative.iconTop||0;h&&Math.abs(h)<1&&(h=t.calculative.worldRect.width*h),v&&Math.abs(v)<1&&(v=t.calculative.worldRect.height*v),n+=h||0,c+=v||0,l-=h||0,u-=v||0;let f=t.calculative.iconRotate||0;if(t.parentId){const g=e[t.parentId].calculative;g&&(f+=g.rotate,f%=360)}n=t.calculative.worldRect.x+n,c=t.calculative.worldRect.y+c,t.calculative.worldIconRect={x:n,y:c,width:l,height:u,rotate:f},calcRightBottom(t.calculative.worldIconRect),calcCenter(t.calculative.worldIconRect)}function scalePen(e,t,i){scaleRect(e.calculative.worldRect,t,i,e.pivot),e.calculative.initRect&&scaleRect(e.calculative.initRect,t,i,e.pivot),e.calculative.prevFrameRect&&scaleRect(e.calculative.prevFrameRect,t,i,e.pivot),scaleChildrenInitRect(e,t,i),e.calculative.x&&scalePoint(e.calculative,t,i),e.type&&calcWorldAnchors(e)}function scaleChildrenInitRect(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&&scaleRect(a.calculative.initRect,t,i),scaleChildrenInitRect(a,t,i))})}function pushPenAnchor(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&&rotatePoint(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 addLineAnchor(e,t,i){e.anchors||(e.anchors=[]),e.calculative.worldAnchors||(e.calculative.worldAnchors=[]);const s=getSplitAnchor(e,t,i);return e.calculative.worldAnchors.splice(i+1,0,s),e.anchors.splice(i+1,0,calcRelativePoint(s,e.calculative.worldRect)),e.calculative.activeAnchor=s,s}function removePenAnchor(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 facePen(e,t){if(!t||!t.calculative||!t.calculative.worldRect.center)return Direction.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 facePoint(e,t.calculative.worldRect.center)}function nearestAnchor(e,t){let i=1/0,s;return e.calculative.worldAnchors.forEach(r=>{const a=distance(t,r);i>a&&(i=a,s=r)}),s}function translateLine(e,t,i){e.x+=t,e.y+=i,e.anchors&&e.anchors.forEach(s=>{translatePoint(s,t,i)}),e.calculative.worldAnchors&&e.calculative.worldAnchors.forEach(s=>{translatePoint(s,t,i)})}function deleteTempAnchor(e){if(e&&e.calculative&&e.calculative.worldAnchors.length){let t=getToAnchor(e);if(!e.anchors||!e.anchors.length)for(;e.calculative.worldAnchors.length&&t!==e.calculative.activeAnchor;)e.calculative.worldAnchors.pop(),t=getToAnchor(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 connectLine(e,t,i,s){var c,l,u,h,v,f;if(!e||!t||!i||!s||t.twoWay===TwoWay.DisableConnected||t.twoWay===TwoWay.Disable||s.twoWay===TwoWay.DisableConnectTo||s.twoWay===TwoWay.Disable)return;if(t.twoWay===TwoWay.In){if(i.calculative.worldAnchors.length===1)return;const g=getToAnchor(i);if(s.id!==g.id)return}if(t.twoWay===TwoWay.Out){const g=getFromAnchor(i);if(s.id!==g.id)return}if(s.connectTo===e.id&&s.anchorId===t.id)return;if(s.connectTo){const g=e.calculative.canvas.store.pens[s.connectTo];disconnectLine(g,getAnchor(g,s.anchorId),i,s)}e.connectedLines||(e.connectedLines=[]),e.connectedLines.findIndex(g=>g.lineId===i.id&&g.lineAnchor===s.id&&g.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&&connectLine(i,s,e,t),e.calculative.canvas.store.emitter.emit("connectLine",{line:i,lineAnchor:s,pen:e,anchor:t});let a=((c=i.calculative.worldAnchors)==null?void 0:c.length)>=2?(l=i.calculative.worldAnchors)==null?void 0:l[0].connectTo:void 0,n=((u=i.calculative.worldAnchors)==null?void 0:u.length)>=2?(v=i.calculative.canvas.store.pens[(h=i.calculative.worldAnchors)==null?void 0:h[0].connectTo])==null?void 0:v.anchors.find(g=>{var y;return g.id===((y=i.calculative.worldAnchors)==null?void 0:y[0].anchorId)}):void 0;return(f=e.onConnectLine)==null||f.call(e,e,{line:i,lineAnchor:s,pen:e,anchor:t,fromPen:a,fromAnchor:n}),!0}function disconnectLine(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]=deepClone(e.connectedLines)),e.connectedLines.forEach((r,a,n)=>{(r.lineId===i.id||r.lineId===i.id)&&r.lineAnchor===s.id&&r.anchor===t.id&&n.splice(a,1)}),s.connectTo=void 0,s.anchorId=void 0,e.type&&t.connectTo===i.id&&t.anchorId===s.id&&disconnectLine(i,s,e,t),e.calculative.canvas.store.emitter.emit("disconnectLine",{line:i,lineAnchor:s,pen:e,anchor:t}),!0}function getAnchor(e,t){var i;if(!(!e||!t))return(i=e.calculative.worldAnchors)==null?void 0:i.find(s=>s.id===t)}function getFromAnchor(e){if(!(!e||!e.calculative.worldAnchors))return e.calculative.worldAnchors[0]}function getToAnchor(e){if(!(!e||!e.calculative.worldAnchors))return e.calculative.worldAnchors[e.calculative.worldAnchors.length-1]}function setNodeAnimate(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 n of e.frames){e.calculative.duration+=n.duration;for(const c in n)c!=="duration"&&!e[c]&&c==="scale"&&(e[c]=1)}}if(e.animateCycle||(e.animateCycle=1/0),e.calculative.start){let n=0;const c=Math.ceil((t-e.calculative.start)/e.calculative.duration);if(c>e.animateCycle)return e.currentAnimation=void 0,e.calculative.start=void 0,setNodeAnimateProcess(e,1),0;const l=(t-e.calculative.start)%e.calculative.duration||e.calculative.duration;let u=0;for(const f of e.frames)if(u+=f.duration,l>u)e.frames[n].switch||(e.calculative.prevFrameRect=deepClone(e.calculative.worldRect),e.frames[n].switch=!0),++n;else break;if(!e.frames[n])return!0;let h=!1;n!==e.calculative.frameIndex&&(h=!0,e.calculative.frameIndex=n,e.calculative.frameDuration=e.frames[n].duration,n>0&&(e.calculative.frameStart+=e.frames[n-1].duration),e.calculative.frameEnd=e.calculative.frameStart+e.calculative.frameDuration);let v=!1;if(c>e.calculative.cycleIndex&&(e.frames.forEach(f=>{f.switch=!1}),e.calculative.worldRect=deepClone(e.calculative.initRect),e.calculative.prevFrameRect=deepClone(e.calculative.initRect),e.calculative.cycleIndex=c,e.calculative.frameStart=e.calculative.start+e.calculative.duration*(c-1),v=!0),h||v)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,n>0){e.prevFrame={};const f=e.frames[n-1];for(const g in f)e.prevFrame[g]=f[g];Object.assign(e.prevFrame,{rotate:f.rotate||0,x:f.x||0,y:f.y||0,scale:f.scale||1})}else initPrevFrame(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=deepClone(e.calculative.worldRect),e.calculative.prevFrameRect=deepClone(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 n=e.calculative.canvas.store;e.calculative.childrenVisible={},e.children.forEach(c=>{e.calculative.childrenVisible[c]=n.pens[c].visible})}e.calculative.initRect.rotate=e.calculative.rotate||0,initPrevFrame(e)}const i=e.frames[e.calculative.frameIndex];let s=0;if(i.curveAnimate){const n=(t-e.calculative.frameStart)/e.calculative.frameDuration%1;let c=[];i.animateTimingFunction?c=Array.isArray(i.animateTimingFunction)?i.animateTimingFunction:i.animateTimingFunction.split(","):c=[.25,.25,.75,.75],s=cubicBezierY(n,c[1],c[3])}else s=(t-e.calculative.frameStart)/e.calculative.frameDuration%1;return s>0&&setNodeAnimateProcess(e,s),!0}function initPrevFrame(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 setNodeAnimateProcess(e,t){var r,a,n,c,l,u;if(t<0)return;t>1&&(t=1);const i=e.frames[e.calculative.frameIndex],s=e.calculative.canvas.store.data.scale;for(const h in i)if(h!=="duration"){if(h==="scale"){e.calculative.worldRect=deepClone(e.calculative.prevFrameRect),scaleRect(e.calculative.worldRect,e.prevFrame.scale,e.calculative.worldRect.center);const v=e.prevFrame.scale+(i[h]-e.prevFrame.scale)*t;scaleRect(e.calculative.worldRect,v/e.prevFrame.scale,e.calculative.worldRect.center),e.calculative.patchFlags=!0}else if(h==="x"){const v=getFrameValue(e,h,e.calculative.frameIndex)*s;e.calculative.worldRect.x=e.calculative.initRect.x+v,e.calculative.worldRect.ex=e.calculative.initRect.ex+v,e.calculative.worldRect.center.x=e.calculative.initRect.center.x+v,(r=e.calculative.worldRect.pivot)!=null&&r.x&&(e.calculative.worldRect.pivot.x=((a=e.calculative.initRect.pivot)==null?void 0:a.x)+v),translateRect(e.calculative.worldRect,i[h]*t*s,0),e.calculative.patchFlags=!0}else if(h==="y"){const v=getFrameValue(e,h,e.calculative.frameIndex)*s;e.calculative.worldRect.y=e.calculative.initRect.y+v,e.calculative.worldRect.ey=e.calculative.initRect.ey+v,e.calculative.worldRect.center.y=e.calculative.initRect.center.y+v,(n=e.calculative.worldRect.pivot)!=null&&n.x&&(e.calculative.worldRect.pivot.y=((c=e.calculative.initRect.pivot)==null?void 0:c.y)+v),translateRect(e.calculative.worldRect,0,i[h]*t*s),e.calculative.patchFlags=!0}else if(h==="width"){const v=getFrameValue(e,h,e.calculative.frameIndex)*s;e.calculative.worldRect.width=e.calculative.initRect.width+v,e.calculative.worldRect.ex=e.calculative.initRect.ex+v,e.calculative.worldRect.center.x=e.calculative.initRect.center.x+v;let f=i[h]*t*s;e.calculative.worldRect.width+=f,e.calculative.worldRect.ex+=f,e.calculative.worldRect.center.x+=f,e.calculative.patchFlags=!0}else if(h==="height"){const v=getFrameValue(e,h,e.calculative.frameIndex)*s;e.calculative.worldRect.height=e.calculative.initRect.height+v,e.calculative.worldRect.ey=e.calculative.initRect.ey+v,e.calculative.worldRect.center.y=e.calculative.initRect.center.y+v;let f=i[h]*t*s;e.calculative.worldRect.height+=f,e.calculative.worldRect.ey+=f,e.calculative.worldRect.center.y+=f,e.calculative.patchFlags=!0}else if(h==="rotate"){e.prevFrame[h]>=360&&(e.prevFrame[h]%=360);const v=getFrameValue(e,h,e.calculative.frameIndex),f=(e.calculative.initRect.rotate+v+i[h]*t)%360-(e.calculative.rotate||0);(l=e.children)!=null&&l.length?e.calculative.canvas.rotatePen(e,f,e.calculative.initRect):e.calculative.rotate=(e.calculative.initRect.rotate+v+i[h]*t)%360,e.calculative.patchFlags=!0}else if(h==="image")e.image=i.image,e.calculative.image=void 0,e.calculative.canvas.loadImage(e),e.canvasLayer===CanvasLayer.CanvasImageBottom?e.calculative.canvas.canvasImageBottom.init():e.canvasLayer===CanvasLayer.CanvasImage&&e.calculative.canvas.canvasImage.init();else if(isLinear(i[h],h,e)){e.prevFrame[h]==null&&(h==="globalAlpha"?e.prevFrame[h]=1:e.prevFrame[h]=0);const v=e.prevFrame[h]+(i[h]-e.prevFrame[h])*t;e.calculative[h]=Math.round(v*100)/100}else{if(h==="visible"&&!e.calculative.image){if((u=e.children)!=null&&u.length){const f=getAllChildren(e,e.calculative.canvas.store);e.calculative.canvas.initImageCanvas(f)}}e.calculative[h]=i[h];const v={};v[h]=i[h],setChildValue(e,v)}h==="text"&&calcTextLines(e)}}function isLinear(e,t,i){const s=["strokeType","bkType","showChild"];return typeof e=="number"&&i.linear!==!1&&!s.includes(t)}function setLineAnimate(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,n=cubicBezierY(a,s[1],s[3]);e.calculative.animatePos=n*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 setChildrenActive(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,setChildrenActive(r,t))})}function setHover(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&&setHover(i.pens[s],t)})}function setElemPosition(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===LockState.DisableEdit||e.locked===LockState.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]}function getPensLock(e){return e.every(t=>t.locked)}function getPensDisableRotate(e){return e.every(t=>t.disableRotate)}function rotatePen(e,t,i){var s;e.rotateByRoot||(e.name==="line"?(e.calculative.worldAnchors.forEach(r=>{rotatePoint(r,t,i.center)}),initLineRect(e),calcPenRect(e)):(e.calculative.rotate?e.calculative.rotate+=t:e.calculative.rotate=t,rotatePoint(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];rotatePen(a,t,i)}))}function initLineRect(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=getLineRect(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),calcCenter(t),e.calculative.worldRect=t,calcPadding(e,t),calcTextRect(e),e.calculative.worldAnchors&&(e.anchors=e.calculative.worldAnchors.map(a=>calcRelativePoint(a,e.calculative.worldRect)))}function getPensDisableResize(e){return e.every(t=>t.disableSize||t.pivot)}function getFrameValue(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 isShowChild(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 calcInView(e,t=!1){var r,a,n;const{store:i,canvasRect:s}=e.calculative.canvas;if(t&&((r=e.children)==null||r.forEach(c=>{const l=i.pens[c];l&&calcInView(l,!0)})),e.calculative.inView=!0,isShowChild(e,i)?(e.visible==!1||e.calculative.visible==!1)&&(e.calculative.inView=!1,(e.canvasLayer===CanvasLayer.CanvasImageBottom||e.canvasLayer===CanvasLayer.CanvasImage)&&((a=e.frames)!=null&&a.length)&&(e.calculative.inView=e.frames.some(c=>c.hasOwnProperty("visible")))):e.calculative.inView=!1,e.calculative.inView){const{x:c,y:l,width:u,height:h,rotate:v}=e.calculative.worldRect,f={x:c+i.data.x,y:l+i.data.y,width:u,height:h,rotate:v};calcRightBottom(f),rectInRect(f,s)||(e.calculative.inView=!1)}i.data.locked&&e.calculative.inView&&(e.calculative.inView=hasPermission(e,i.options.roles)),(n=e.calculative.singleton)!=null&&n.div&&setElemPosition(e,e.calculative.singleton.div)}function hasPermission(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?hasPermission(getParent(e,!1),t):e.calculative.inView}function inspectRect(e,t,i){if(t.fillWorldTextRect){e.save(),e.fillStyle="#c3deb7";const{x:s,y:r,width:a,height:n}=i.calculative.worldTextRect;e.fillRect(s,r,a,n),e.restore()}}function setGlobalAlpha(e,t){const i=t.calculative.globalAlpha;typeof i=="number"&&i<1&&!isNaN(i)&&(e.globalAlpha=i)}function ctxDrawCanvas(e,t){const i=drawFuncGenerator(e,t)||globalStore.canvasDraws[t.name];i&&(e.save(),i(e,t),e.restore())}function drawFuncGenerator(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((n,c)=>{const l=commandTransfer(c,r,n.x,n.y);try{if(l.c){if(l.c.startsWith("_")){const h=l.c.split("_")[1];return typeof l.v.value=="number"&&(l.v.value*=r.calculative.canvas.store.data.scale),(l.p||s)[h]=l.v.value,{x:n.x,y:n.y}}let u=[];for(const h in l.v)u.push(l.v[h]);return(l.p||s)[l.c](...u),{x:l.startX||l.v.x,y:l.startY||l.v.y}}return{x:n.x,y:n.y}}catch{}},{})}catch{}}),s.stroke()}}function commandTransfer(e,t,i,s){var a;const r={visio:dealWithVisio,dxf:dealWithDXF,canvas:dealWithCanvas};return((a=r[t.parseType])==null?void 0:a.call(r,e,t,i,s))||e}function dealWithDXF(e,t,i,s){const{x:r,y:a,width:n,height:c}=t.calculative.worldRect,{originWidth:l,originHeight:u}=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*(n/l)+r,y:e.v.y*(c/u)+a}};case"lineTo":return{c:"lineTo",v:{x:e.v.x*(n/l)+r,y:e.v.y*(c/u)+a}};case"arc":return{c:"ellipse",v:{x:e.v.x*(n/l)+r,y:e.v.y*(c/u)+a,rx:e.v.xr*(n/l),ry:e.v.yr*(c/u),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*(n/l)+r,y:e.v.y*(c/u)+a,rx:e.v.xr*(n/l),ry:e.v.yr*(c/u),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 h={c:e.c,v:{...e.v}};return h.v.x!==void 0&&(h.v.x=e.v.x*(n/l)+r),h.v.y!==void 0&&(h.v.y=e.v.y*(c/u)+a),h}}function dealWithCanvas(e,t,i,s){const{x:r,y:a,width:n,height:c}=t.calculative.worldRect,{originWidth:l,originHeight:u}=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*(n/l)+r,y:e.v.y*(c/u)+a}};case"lineTo":return{c:"lineTo",v:{x:e.v.x*(n/l)+r,y:e.v.y*(c/u)+a}};case"arc":return{c:"ellipse",v:{x:e.v.x*(n/l)+r,y:e.v.y*(c/u)+a,rx:e.v.xr*(n/l),ry:e.v.yr*(c/u),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*(n/l)+r,y:e.v.y*(c/u)+a,rx:e.v.xr*(n/l),ry:e.v.yr*(c/u),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 h={c:e.c,v:{...e.v}};return h.v.x!==void 0&&(h.v.x=e.v.x*(n/l)+r),h.v.y!==void 0&&(h.v.y=e.v.y*(c/u)+a),h}}function dealWithVisio(e,t,i,s){const{x:r,y:a,width:n,height:c}=t.calculative.worldRect,{width:l,height:u}=t.origin;switch(e.c){case"MoveTo":return{c:"moveTo",v:{x:+e.v.X*100*(n/l)+r,y:+e.v.Y*100*(c/u)+a}};case"RelMoveTo":return{c:"moveTo",v:{x:+e.v.X*l*(n/l)+r,y:+e.v.Y*u*(c/u)+a}};case"LineTo":return{c:"lineTo",v:{x:+e.v.X*100*(n/l)+r,y:+e.v.Y*100*(c/u)+a}};case"RelLineTo":return{c:"lineTo",v:{x:+e.v.X*l*(n/l)+r,y:+e.v.Y*u*(c/u)+a}};case"Ellipse":let h=e.v.X,v=e.v.Y,f=Math.abs(e.v.A-e.v.C),g=Math.abs(e.v.B-e.v.D);return{c:"ellipse",v:{x:h*100*(n/l)+r,y:v*100*(c/u)+a,radiuX:f*100*(n/l),radiuY:g*100*(c/u),rotation:0,startAngle:0,endAngle:Math.PI*2,anticlockwise:!0}};case"EllipticalArcTo":const y=e.v.X*100*(n/l)+r,p=e.v.Y*100*(c/u)+a,m=e.v.A*100*(n/l)+r,x=e.v.B*100*(c/u)+a;e.v.C;const k=e.v.D*(n/c)*(u/l),w=(y-i)*(x-s)-(p-s)*(m-i)>0,C=calculateEllipseParameters(i,s,y,p,m,x,k);return!e.orign&&(e.orign={}),!e.orign.startA&&(e.orign.startA=calculateAngleInRadians(C.x0,C.y0,i,s)),!e.orign.endA&&(e.orign.endA=calculateAngleInRadians(C.x0,C.y0,y,p)),{c:"ellipse",v:{centerX:C.x0,centerY:C.y0,radiuX:C.a,radiuY:C.b,rotation:0,startAngle:e.orign.startA,endAngle:e.orign.endA,anticlockwise:w},startX:y,startY:p};case"RelEllipticalArcTo":const I=e.v.X*l*(n/l)+r,_=e.v.Y*u*(c/u)+a,L=e.v.A*l*(n/l)+r,E=e.v.B*u*(c/u)+a;e.v.C;const F=e.v.D*(n/c)*(u/l),q=(I-i)*(E-s)-(_-s)*(L-i)>0,R=calculateEllipseParameters(i,s,I,_,L,E,F);return!e.orign&&(e.orign={}),!e.orign.startA&&(e.orign.startA=calculateAngleInRadians(R.x0,R.y0,i,s)),!e.orign.endA&&(e.orign.endA=calculateAngleInRadians(R.x0,R.y0,I,_)),{c:"ellipse",v:{centerX:R.x0,centerY:R.y0,radiuX:R.a,radiuY:R.b,rotation:0,startAngle:e.orign.startA,endAngle:e.orign.endA,anticlockwise:q},startX:I,startY:_};case"ArcTo":let A=e.v.X*100*n/l+r,P=e.v.Y*100*c/u+a,M=e.v.A*100*t.calculative.canvas.store.data.scale,H=(i+A)/2,$=(s+P)/2,X=Math.sqrt((A-i)**2+(P-s)**2);if(Math.abs(M)<.001||X<.001)return{c:"lineTo",v:{x:A,y:P}};let j=X*X/(8*Math.abs(M))+Math.abs(M)/2,O=-(P-s)/X,z=(A-i)/X,V=j-Math.abs(M),N=H-Math.sign(M)*O*V,Y=$-Math.sign(M)*z*V,K=Math.atan2(s-Y,i-N),G=Math.atan2(P-Y,A-N),tt=G-K;for(;tt>Math.PI;)tt-=2*Math.PI;for(;tt<-Math.PI;)tt+=2*Math.PI;let Q=M>0;return(Q&&tt>0||!Q&&tt<0)&&([K,G]=[G,K],Q=!Q),{c:"arc",v:{x:N,y:Y,radius:j,startAngle:K,endAngle:G,anticlockwise:Q},startX:A,startY:P};default:const Z=deepClone(e);return Object.entries(Z.v).forEach(([b,T])=>{var S,D;(S=b.endsWith)!=null&&S.call(b,"_x")?typeof T=="number"&&(Z.v[b]=T*(n/l)+r):(D=b.endsWith)!=null&&D.call(b,"_y")?typeof T=="number"&&(Z.v[b]=T*(c/u)+a):typeof T=="number"&&(Z.v[b]=T)}),Z}}function drawFilter(e,t){e.filter=t.filter}function setChildValue(e,t){for(const i in t)inheritanceProps.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,calcTextRect(e)):e.calculative[i]=t[i]),e.image&&e.name!=="gif"&&needImgCanvasPatchFlagsProps.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=deepClone(t);e.calculative.childrenVisible&&e.calculative.childrenVisible[s]===!1&&delete r.visible;const a=e.calculative.canvas.store.pens[s];a&&setChildValue(a,r)})}}function calculateEllipseParameters(e,t,i,s,r,a,n){let c=(e-i)*(e+i)*(s-a)-(i-r)*(i+r)*(t-s)+n*n*(t-s)*(s-a)*(t-a),l=2*((e-i)*(s-a)-(i-r)*(t-s)),u=c/l,h=(e-i)*(i-r)*(e-r)+n*n*((i-r)*(t-s)*(t+s)-(e-i)*(s-a)*(s+a)),v=2*n*n*((i-r)*(t-s)-(e-i)*(s-a)),f=h/v,g=Math.sqrt(Math.pow(e-u,2)+Math.pow(n*(t-f),2)),y=g/n;return{x0:u,y0:f,a:g,b:y}}function calculateAngleInRadians(e,t,i,s){let r=i-e,a=s-t,n=Math.atan2(a,r);return n<0&&(n+=2*Math.PI),n}function calcAnchorDock(e,t,i){let s,r,a=1/0,n=1/0;const c=8;for(const l of e.data.pens){if(l.calculative.inView===!1)continue;getPointsByPen(l).forEach(h=>{if(h===t||h===i)return;let v=(l.calculative.worldRect.center.x-t.x)*(l.calculative.worldRect.center.x-t.x)+(l.calculative.worldRect.center.y-t.y)*(l.calculative.worldRect.center.y-t.y);const f=Math.abs(h.x-t.x);f>0&&f<c&&v<a&&(s={x:Math.round(h.x)+.5,y:Math.round(h.y)+.5,prev:{x:Math.round(t.x)+.5,y:Math.round(t.y)+.5},step:h.x-t.x},a=v);const g=Math.abs(h.y-t.y);g>0&&g<c&&v<n&&(r={x:Math.round(h.x)+.5,y:Math.round(h.y)+.5,prev:{x:Math.round(t.x)+.5,y:Math.round(t.y)+.5},step:h.y-t.y},n=v)})}return{xDock:s,yDock:r}}function calcMoveDock(e,t,i,s){let r=[];return i.length===1?(r=deepClone(getPointsByPen(i[0])),r.forEach(a=>{a.x+=s.x,a.y+=s.y})):(calcCenter(t),r=[t.center,...rectToPoints(t)]),calcDockByPoints(e,r,t,!0)}function getPointsByPen(e){if(e.type){if(e.type===PenType.Line)return e.calculative.worldAnchors}else{const t=rectToPoints(e.calculative.worldRect);return calcCenter(e.calculative.worldRect),[...e.calculative.worldAnchors,...t,e.calculative.worldRect.center]}}function calcResizeDock(e,t,i,s){const r=rectToPoints(t);return calcDockByPoints(e,r,t)}function calcDockByPoints(e,t,i,s=!1){let r,a,n=1/0,c=1/0;const l=10,u=expandRect(i,l);return e.data.pens.forEach(h=>{const{inView:v,worldRect:f,active:g}=h.calculative;if(v===!1||!s&&g||rectInFourAngRect(u,f)||h.type&&e.active.some(p=>isConnectLine(e,p,h)))return;const y=getPointsByPen(h);if(y)for(const p of y)for(const m of t){const x=p.x-m.x,k=p.y-m.y,w=Math.abs(x),C=Math.abs(k);i.center||(i.center={x:i.x+i.width/2,y:i.y+i.height/2}),w<l&&w<n&&(r={x:Math.round(p.x)+.5,y:Math.round(p.y)+.5,step:x,prev:{x:Math.round(m.x)+.5,y:Math.round(m.y)+.5},penId:h.id,anchorId:m.id,dockAnchorId:p.id},n=w),C<l&&C<c&&(a={x:Math.round(p.x)+.5,y:Math.round(p.y)+.5,step:k,prev:{x:Math.round(m.x)+.5,y:Math.round(m.y)+.5},penId:h.id,anchorId:m.id,dockAnchorId:p.id},c=C)}}),{xDock:r,yDock:a}}function isConnectLine(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(isConnectLine(e,r,i))return!0}return!1}function isEqual(e,t){return e.toFixed(12)==t}function findOutliersByZScore(e,t=4){let i=e.map(u=>u.calculative.worldRect);const s=i.map(u=>u.x),r=i.map(u=>u.y),a=s.reduce((u,h)=>u+h,0)/s.length,n=r.reduce((u,h)=>u+h,0)/r.length,c=Math.sqrt(s.map(u=>Math.pow(u-a,2)).reduce((u,h)=>u+h,0)/s.length),l=Math.sqrt(r.map(u=>Math.pow(u-n,2)).reduce((u,h)=>u+h,0)/r.length);return e.filter(u=>{let h=u.calculative.worldRect;const v=(h.x-a)/c,f=(h.y-n)/l;return Math.sqrt(v*v+f*f)>t})}function randomId(e){if(e.id=s8(),Array.isArray(e.anchors))for(const t of e.anchors)e.type&&(t.id=s8()),t.penId=e.id,t.prev&&(e.type&&(t.prev.id=s8()),t.prev.penId=e.id),t.next&&(e.type&&(t.next.id=s8()),t.next.penId=e.id)}function rewritePenLifeCycle(){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 n=new Set,c=new Map;e.has(s)&&e.get(s)?n=e.get(s):(c.set(s,i[s]),e.set(s,n)),a?n.delete(r):n.add(r);let l=c.get(s),u=(...h)=>{l==null||l(...h),n.forEach(v=>{v(...h)})};i[s]=u}}let setLifeCycleFunc=rewritePenLifeCycle();function validationPlugin(e){return!e.name&&!e.install?(console.error("installPenPlugin Error: Validation Failed"),!1):!0}function curve(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},distance(t.calculative.activeAnchor.next,t.calculative.activeAnchor)<5?t.calculative.activeAnchor.next=void 0:(t.calculative.activeAnchor.prev={...t.calculative.activeAnchor.next},rotatePoint(t.calculative.activeAnchor.prev,180,t.calculative.activeAnchor)));else{const s=t.calculative.worldAnchors[0];if(!s.next){const a=facePen(s,e.pens[s.connectTo]);calcCurveCP(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=facePen(r,e.pens[r.connectTo]);calcCurveCP(r,a,-50),r.next=void 0}}}function calcCurveCP(e,t,i){switch(t){case Direction.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 Direction.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 Direction.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 Direction.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 getQuadraticPoint(e,t,i,s){const r=1-e,a=r*r*t.x+2*r*e*i.x+e*e*s.x,n=r*r*t.y+2*r*e*i.y+e*e*s.y;return{x:a,y:n,step:e}}function getBezierPoint(e,t,i,s,r){const{x:a,y:n}=t,{x:c,y:l}=r,{x:u,y:h}=i,{x:v,y:f}=s,g=1-e,y=a*g*g*g+3*u*e*g*g+3*v*e*e*g+c*e*e*e,p=n*g*g*g+3*h*e*g*g+3*f*e*e*g+l*e*e*e;return{x:y,y:p,step:e}}function lerp(e,t,i){return{x:e.x+i*(t.x-e.x),y:e.y+i*(t.y-e.y)}}function getSplitAnchor(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 n;if(s.next&&r.prev){const c=s,l=s.next,u=r.prev,h=r,v=lerp(c,l,a),f=lerp(l,u,a),g=lerp(u,h,a),y=lerp(v,f,a),p=lerp(f,g,a);n=lerp(y,p,a),y.penId=e.id,n.prev=y,p.penId=e.id,n.next=p,s.next.x=v.x,s.next.y=v.y,r.prev.x=g.x,r.prev.y=g.y}else if(s.next||r.prev){const c=s,l=s.next||r.prev,u=r,h=lerp(c,l,a),v=lerp(l,u,a);n=t,h.penId=e.id,v.penId=e.id,n.prev=h,n.next=v,s.next=void 0,r.prev=void 0}else n=t;return n.penId=e.id,n.id=s8(),n.prevNextType=PrevNextType.Bilateral,n}function mind(e,t,i){if(t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),t.calculative.worldAnchors.length<2)return;let s=t.calculative.activeAnchor,r=i||getToAnchor(t);if(!s||!r)return;const a=20,n=e.pens[s.connectTo];let c=facePen(s,n);switch(c===Direction.None&&(r.x>s.x?c=Direction.Right:c=Direction.Left),s.next={id:s8(),penId:t.id,x:s.x,y:s.y,prevNextType:2},r.prev={id:s8(),penId:t.id,x:r.x,y:r.y,prevNextType:2},c){case Direction.Up:s.next.y-=a,r.prev.y=s.y;break;case Direction.Bottom:s.next.y+=a,r.prev.y=s.y;break;case Direction.Left:s.next.x-=a,r.prev.x=s.x;break;default:s.next.x+=a,r.prev.x=s.x;break}}function line(e,t){const i=t||new Path2D;if((e.lineName==="line"||e.lineName==="polyline")&&e.calculative.lineSmooth){let r=getGradientAnimatePath(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?draw(i,r,a):a.start=!0,r=a}),e.close&&(e.lineName==="curve"?draw(i,r,s[0]):i.closePath())}if(i instanceof Path2D)return i}function lineSegment(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=getFromAnchor(t),r=getToAnchor(t);!s||!r||!r.id||s===r||(s.next=void 0,deleteTempAnchor(t),r.prev=void 0,t.calculative.worldAnchors.push(r))}function draw(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 getLineRect(e){return getLineLength(e),getRectOfPoints(getLinePoints(e))}function getLinePoints(e){const t=[];let i;return e.calculative.worldAnchors.forEach(s=>{i&&t.push(...getPoints(i,s,e)),t.push(s),i=s}),e.close&&e.calculative.worldAnchors.length>1&&t.push(...getPoints(i,e.calculative.worldAnchors[0],e)),t}function getLineR(e){return e!=null&&e.lineWidth?e.lineWidth/2+4:4}function getPoints(e,t,i){const s=[];if(!t)return s;let r=.02;if(e.lineLength&&!i.parentId&&(r=getLineR(i)/e.lineLength),e.next)if(t.prev)for(let a=r;a<1;a+=r)s.push(getBezierPoint(a,e,e.next,t.prev,t));else for(let a=r;a<1;a+=r)s.push(getQuadraticPoint(a,e,e.next,t));else if(t.prev)for(let a=r;a<1;a+=r)s.push(getQuadraticPoint(a,e,t.prev,t));else s.push({x:t.x,y:t.y});return s.length>1&&(e.curvePoints=s),s}function pointInLine(e,t){const i=getLineR(t);let s=0,r,a;for(const n of t.calculative.worldAnchors){if(r){if(a=pointInLineSegment(e,r,n,i),a)return{i:s,point:a};++s}r=n}if(t.close&&t.calculative.worldAnchors.length>1&&(a=pointInLineSegment(e,r,t.calculative.worldAnchors[0],i)))return{i:s,point:a}}function pointInLineSegment(e,t,i,s=4){if(!t.next&&!i.prev){const{x:r,y:a}=t,{x:n,y:c}=i,l=Math.min(r,n),u=Math.max(r,n),h=Math.min(a,c),v=Math.max(a,c);return e.x>=l-s&&e.x<=u+s&&e.y>=h-s&&e.y<=v+s?pointToLine(e,t,i,s):void 0}else if(t.curvePoints){for(const r of t.curvePoints)if(hitPoint(e,r,s))return r}}function pointToLine(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 l=(e.x+r*e.y-r*a)/(r*r+1);return{x:l,y:r*l+a}}}}function lineLen(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 getLineLength(e){if(e.calculative.worldAnchors.length<2)return 0;let t=0,i;if(e.calculative.worldAnchors.forEach(s=>{i&&(i.lineLength=lineLen(i,i.next,s.prev,s),t+=i.lineLength),i=s}),e.close){const s=getFromAnchor(e);i.lineLength=lineLen(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 lineInRect(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(isLineIntersectRectangle(r,a,t))return!0}else if(isBezierIntersectRectangle(r,a,t))return!0}return!1}function isLineIntersectRectangle(e,t,i){if(pointInSimpleRect(e,i)||pointInSimpleRect(t,i))return!0;const s=e.x,r=e.y,a=t.x,n=t.y;let c=i.x,l=i.y,u=i.ex,h=i.ey;const v=r-n,f=a-s,g=s*n-a*r;if(v*c+f*l+g>=0&&v*u+f*h+g<=0||v*c+f*l+g<=0&&v*u+f*h+g>=0||v*c+f*h+g>=0&&v*u+f*l+g<=0||v*c+f*h+g<=0&&v*u+f*l+g>=0){if(c>u){const y=c;c=u,u=y}if(l<h){const y=l;l=h,h=y}return!(s<c&&a<c||s>u&&a>u||r>l&&n>l||r<h&&n<h)}else return!1}function isBezierIntersectRectangle(e,t,i){if(!e.next&&!t.prev)return isLineIntersectRectangle(e,t,i);if(e.next&&t.prev)for(let r=.02;r<1;r+=.02){const a=getBezierPoint(r,e,e.next,t.prev,t);if(pointInSimpleRect(a,i))return!0}else if(e.next||t.prev)for(let r=.02;r<1;r+=.02){const a=getQuadraticPoint(r,e,e.next||t.prev,t);if(pointInSimpleRect(a,i))return!0}return!1}function createSvgPath(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 getLinePointPosAndAngle(e,t){const i=e.getTotalLength();if(t<0||t>i)return null;const s=.01,r=e.getPointAtLength(t),a=e.getPointAtLength(t-s),n=Math.atan2(r.y-a.y,r.x-a.x);return{x:r.x,y:r.y,rotate:n/Math.PI*180,progress:t/i}}function lineHasArrowOrWaterDropAnimate(e){const t=e.lineAnimateType;return t==null?!1:(Array.isArray(t)?t:[t]).some(s=>s===LineAnimateType.Arrow||s===LineAnimateType.WaterDrop)}function strokeChevronV(e,t,i){e.beginPath(),e.moveTo(0,0),e.lineTo(-t,-i),e.moveTo(0,0),e.lineTo(-t,i),e.stroke()}function drawDefaultLineDirectionChevron(e,t,i,s,r,a){e.save(),e.translate(t,i),e.rotate(s),strokeChevronV(e,r,a),e.restore()}function pointAndAngleOnPolyline(e,t,i){let s=0,r=t.length-1;for(;r-s>1;){const g=s+r>>1;t[g]<=i?s=g:r=g}const a=s,n=e[a],c=e[a+1],l=t[a+1]-t[a],u=l>1e-6?(i-t[a])/l:0,h=n.x+u*(c.x-n.x),v=n.y+u*(c.y-n.y),f=Math.atan2(c.y-n.y,c.x-n.x);return{x:h,y:v,ang:f}}function renderLineDirectionMarkers(e,t,i){if(t.type!==PenType.Line||!(t.dirMarkers!==void 0?t.dirMarkers:i.options.dirMarkers)||t.calculative.pencil)return;const r=t.calculative.worldAnchors;if(!r||r.length<2||t.calculative.animatePos&&lineHasArrowOrWaterDropAnimate(t))return;const a=i.options.drawDirMarkers;e.save(),e.setLineDash([]),e.shadowBlur=0,e.shadowColor="",e.shadowOffsetX=0,e.shadowOffsetY=0;const n=getLinePoints(t);if(n.length<2){e.restore();return}const c=i.data.scale,l=(t.dirMarkerInterval??i.options.dirMarkerInterval??40)*c,u=t.dirMarkerColor??i.options.dirMarkerColor??"#ffffff",h=[0];let v=0;for(let g=0;g<n.length-1;g++){const y=n[g+1].x-n[g].x,p=n[g+1].y-n[g].y;v+=Math.sqrt(y*y+p*p),h.push(v)}if(v<=1e-6){e.restore();return}let f=[];for(let g=l/2;g<v;g+=l)f.push(g);if((f.length===0||f.length===1)&&(f=[v/2]),a)for(const g of f){const{x:y,y:p,ang:m}=pointAndAngleOnPolyline(n,h,g);a(e,y,p,m,u,t)}else{const g=t.calculative.lineWidth||2,y=Math.min(g*.38,Math.max(.75,g*.14)),m=Math.max(0,g-y)*.38,x=g*.52;e.strokeStyle=u,e.lineWidth=y,e.lineJoin="round",e.lineCap="round";for(const k of f){const{x:w,y:C,ang:I}=pointAndAngleOnPolyline(n,h,k);drawDefaultLineDirectionChevron(e,w,C,I,x,m)}}e.restore()}function pointInRect(e,t){if(!t)return;if(t.ex==null&&calcRightBottom(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||calcCenter(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=>{rotatePoint(s,t.rotate,t.pivot||t.center)}),pointInVertices(e,i)}function pointInSimpleRect(e,t,i=0){const{x:s,y:r,ex:a,ey:n}=t;return e.x>=s-i&&e.x<=a+i&&e.y>=r-i&&e.y<=n+i}function calcCenter(e){e.center||(e.center={}),e.center.x=e.x+e.width/2,e.center.y=e.y+e.height/2}function calcRightBottom(e){e.ex=e.x+e.width,e.ey=e.y+e.height}function calcPivot(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 pointInVertices(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 getRect$1(e){const t=[];e.forEach(s=>{if(s.isRuleLine)return;const r=s.calculative.worldRect;if(r){const a=rectToPoints(r);t.push(...a)}});const i=getRectOfPoints(t);return calcCenter(i),i}function rectToPoints(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||calcCenter(e),t.forEach(i=>{rotatePoint(i,e.rotate,e.pivot||e.center)})),t}function getRectOfPoints(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 rectInRect(e,t,i){return e.rotate&&(e=getRectOfPoints(rectToPoints(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 rectInFourAngRect(e,t){return(t.x>e.ex||t.ex<e.x)&&(t.y>e.ey||t.ey<e.y)}function expandRect(e,t){const i=formatPadding(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 calcRightBottom(s),s}function translateRect(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 getIntersectPoint(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 getIntersectPointByK({k:i,point:e.from},{k:s,point:t.from})}function getIntersectPointByK(e,t){if(isEqual(e.k,0))return{x:t.point.x,y:e.point.y};if(isEqual(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 pointsToRect(e,t){const i=getIntersectPoint({from:e[0],to:e[2]},{from:e[1],to:e[3]});for(const s of e)rotatePoint(s,-t,i);return getRectOfPoints(e)}function resizeRect(e,t,i,s){let r=e.rotate?e.rotate%360:0;if(r){const a=rectToPoints(e),n=(a[0].y-a[1].y)/(a[0].x-a[1].x),c=(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 h=t*Math.tan((90-(360-r)-Math.atan(e.width/e.height)/Math.PI*180)/180*Math.PI);a[s].y+=h}else{let h=t*Math.tan((90-(360-r)+Math.atan(e.width/e.height)/Math.PI*180)/180*Math.PI);a[s].y+=h}else a[s].y+=i;const u=a[(s+2)%4];a[(s+1)%4]=getIntersectPointByK({k:s%2?c:n,point:a[s]},{k:s%2?n:c,point:u}),a[(s+4-1)%4]=getIntersectPointByK({k:s%2?n:c,point:a[s]},{k:s%2?c:n,point:u})}else{const u=[4,6].includes(s)?c:n;isEqual(u,0)?(a[s%4].x+=t,a[(s+1)%4].x+=t):(a[s%4].y+=i,a[s%4].x+=i/u,a[(s+1)%4].y+=i,a[(s+1)%4].x+=i/u)}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 l=pointsToRect(a,e.rotate);calcCenter(l),Object.assign(e,l);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 scaleRect(e,t,i,s){e&&(e.width*=t,e.height*=t,scalePoint(e,t,i),calcRightBottom(e),calcCenter(e),s&&calcPivot(e,s))}function calcRelativeRect(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 calcRightBottom(i),i}function calcRelativePoint(e,t){const{x:i,y:s,width:r,height:a}=t,{penId:n,connectTo:c}=e,l=Object.assign({},e,{x:r?(e.x-i)/r:0,y:a?(e.y-s)/a:0});return e.prev&&(l.prev={penId:n,connectTo:c,x:r?(e.prev.x-i)/r:0,y:a?(e.prev.y-s)/a:0}),e.next&&(l.next={penId:n,connectTo:c,x:r?(e.next.x-i)/r:0,y:a?(e.next.y-s)/a:0}),l}function pointInPolygon(e,t){let i=!1;for(let s=0,r=t.length-1;s<t.length;r=s++){let a=t[s].x,n=t[s].y,c=t[r].x,l=t[r].y;n>e.y!=l>e.y&&e.x<(c-a)*(e.y-n)/(l-n)+a&&(i=!i)}return i}const commandRegex=/^[\t\n\f\r ]*([MLHVZCSQTAmlhvzcsqta])[\t\n\f\r ]*/,flagRegex=/^[01]/,numberRegex=/^[+-]?(([0-9]*\.[0-9]+)|([0-9]+\.)|([0-9]+))([eE][+-]?[0-9]+)?/,commaWsp=/^(([\t\n\f\r ]+,?[\t\n\f\r ]*)|(,[\t\n\f\r ]*))/,grammar={M:[numberRegex,numberRegex],L:[numberRegex,numberRegex],H:[numberRegex],V:[numberRegex],Z:[],C:[numberRegex,numberRegex,numberRegex,numberRegex,numberRegex,numberRegex],S:[numberRegex,numberRegex,numberRegex,numberRegex],Q:[numberRegex,numberRegex,numberRegex,numberRegex],T:[numberRegex,numberRegex],A:[numberRegex,numberRegex,numberRegex,flagRegex,flagRegex,numberRegex,numberRegex]};function parseSvgPath(e){let t=0;const i=[];for(;t<e.length;){const s=e.slice(t).match(commandRegex);if(s!==null){const r=s[1];t+=s[0].length;const a=parseCommands(r,e,t);t=a.cursor,i.push(...a.commands)}else throw new Error("malformed path (first error at "+t+")")}return{commands:i}}function getRect(e){let t=1/0,i=1/0,s=-1/0,r=-1/0;return calcWorldPositions(e),e.commands.forEach(a=>{a.worldPoints.forEach((n,c)=>{c%2===0?(n<t&&(t=n),n>s&&(s=n)):(n<i&&(i=n),n>r&&(r=n))})}),{x:t,y:i,ex:s,ey:r,width:s-t+1,height:r-i+1}}function translatePath(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,n)=>{s.values[n]=a+(n%2===0?t:i)});break}})}function scalePath(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],n=Math.PI*s.values[2]/180,c=Math.cos(n),l=Math.sin(n),u=a*a*i*i*c*c+r*r*i*i*l*l,h=2*t*i*c*l*(a*a-r*r),v=r*r*t*t*c*c+a*a*t*t*l*l,f=-(r*r*a*a*t*t*i*i),g=h*h-4*u*v,y=Math.sqrt((u-v)*(u-v)+h*h);s.values[2]=h!==0?Math.atan((v-u-y)/h)*180/Math.PI:u<v?0:90,s.values[0]=-Math.sqrt(2*g*f*(u+v+y))/g,s.values[1]=-Math.sqrt(2*g*f*(u+v-y))/g,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((p,m)=>{s.values[m]=p*(m%2===0?t:i)});break}})}function pathToString(e){let t="";return e.commands.forEach(i=>{t+=i.key+" ",i.values.forEach(s=>{t+=s+" "})}),t}function parseCommands(e,t,i){const s=grammar[e.toUpperCase()],r=[];for(;i<=t.length;){const a={key:e,values:[]};for(const n of s){const c=t.slice(i).match(n);if(c!==null){a.values.push(+c[0]),i+=c[0].length;const l=t.slice(i).match(commaWsp);l!==null&&(i+=l[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 calcWorldPoints(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 calcWorldPositions(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=[t.worldPoints[t.worldPoints.length-2],r.values[0]+t.worldPoints[t.worldPoints.length-1]];break;default:calcWorldPoints(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 svgPath(e,t){var l;const s=e.calculative.canvas.store.data.paths[e.pathId];if(!s)return new Path2D;const r=parseSvgPath(s);e.calculative.svgRect=getRect(r),calcCenter(e.calculative.svgRect),(e.calculative.svgRect.width!==e.calculative.worldRect.width||e.calculative.svgRect.height!==e.calculative.worldRect.height)&&scalePath(r,e.calculative.worldRect.width/e.calculative.svgRect.width,e.calculative.worldRect.height/e.calculative.svgRect.height);const a=getRect(r);calcCenter(a),translatePath(r,e.calculative.worldRect.x-a.x,e.calculative.worldRect.y-a.y);const n=pathToString(r);if(t){(l=t.svgPath)==null||l.call(t,n);return}return new Path2D(n)}function diamond(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;if(i.moveTo(s+a/2,r),i.lineTo(s+a,r+n/2),i.lineTo(s+a/2,r+n),i.lineTo(s,r+n/2),i.lineTo(s+a/2,r),i.closePath(),i instanceof Path2D)return i}function triangle(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;if(i.moveTo(s+a/2,r),i.lineTo(s+a,r+n),i.lineTo(s,r+n),i.lineTo(s+a/2,r),i.closePath(),i instanceof Path2D)return i}function triangleAnchors(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 pentagon(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;if(i.moveTo(s+a/2,r),i.lineTo(s+a,r+n*2/5),i.lineTo(s+a*4/5,r+n),i.lineTo(s+a/5,r+n),i.lineTo(s,r+n*2/5),i.closePath(),i instanceof Path2D)return i}function pentagonAnchors(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 pentagram(e,t){e.onResize||(e.onResize=resize$3);const i=t||new Path2D,{width:s,height:r,center:a}=e.calculative.worldRect,n=s>r?r:s,c=a.x,l=a.y,u=l-n/2,h=l-n/4,v=-(h-l)*Math.sin(Math.PI/180*324)+c,f=(h-l)*Math.cos(Math.PI/180*324)+l;i.moveTo(v,f);for(let g=0;g<5;++g)i.lineTo(-(u-l)*Math.sin(Math.PI/180*72*g)+c,(u-l)*Math.cos(Math.PI/180*72*g)+l),i.lineTo((v-c)*Math.cos(Math.PI/180*72*(g+1))-(f-l)*Math.sin(Math.PI/180*72*(g+1))+c,(v-c)*Math.sin(Math.PI/180*72*(g+1))+(f-l)*Math.cos(Math.PI/180*72*(g+1))+l);if(i.closePath(),i instanceof Path2D)return i}function pentagramAnchors(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 resize$3(e){const t=e.anchors.filter(i=>i.flag!==1);pentagramAnchors(e),e.anchors=e.anchors.concat(...t)}function hexagon(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;if(i.moveTo(s+a/4,r),i.lineTo(s+a*3/4,r),i.lineTo(s+a,r+n/2),i.lineTo(s+a*3/4,r+n),i.lineTo(s+a*1/4,r+n),i.lineTo(s,r+n/2),i.lineTo(s+a/4,r),i.closePath(),i instanceof Path2D)return i}function leftArrow(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;if(i.moveTo(s,r+n/2),i.lineTo(s+n/2,r),i.lineTo(s+n/2,r+n/3),i.lineTo(s+a,r+n/3),i.lineTo(s+a,r+n*2/3),i.lineTo(s+n/2,r+n*2/3),i.lineTo(s+n/2,r+n*2/3),i.lineTo(s+n/2,r+n),i.closePath(),i instanceof Path2D)return i}function rightArrow(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;if(i.moveTo(s,r+n/3),i.lineTo(s+(a-n/2),r+n/3),i.lineTo(s+(a-n/2),r),i.lineTo(s+a,r+n/2),i.lineTo(s+(a-n/2),r+n),i.lineTo(s+(a-n/2),r+n*2/3),i.lineTo(s,r+n*2/3),i.closePath(),i instanceof Path2D)return i}function twowayArrow(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;if(i.moveTo(s,r+n/2),i.lineTo(s+n/2,r),i.lineTo(s+n/2,r+n/3),i.lineTo(s+(a-n/2),r+n/3),i.lineTo(s+(a-n/2),r),i.lineTo(s+a,r+n/2),i.lineTo(s+(a-n/2),r+n),i.lineTo(s+(a-n/2),r+n*2/3),i.lineTo(s+n/2,r+n*2/3),i.lineTo(s+n/2,r+n),i.closePath(),i instanceof Path2D)return i}function message(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n,ey:c}=e.calculative.worldRect;if(i.moveTo(s,r),i.lineTo(s+a,r),i.lineTo(s+a,r+n*3/4),i.lineTo(s+a*8/16,r+n*3/4),i.lineTo(s+a/4,c),i.lineTo(s+a*5/16,r+n*3/4),i.lineTo(s,r+n*3/4),i.closePath(),i instanceof Path2D)return i}function cloud(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;if(i.moveTo(s+a/5,r+n*13/16),i.bezierCurveTo(s-a/15,r+n*13/16,s-a/15,r+n*7/16,s+a/5,r+n*7/16),i.bezierCurveTo(s+a/5,r,s+a*4/5,r,s+a*4/5,r+n*7/16),i.bezierCurveTo(s+a*16/15,r+n*7/16,s+a*16/15,r+n*13/16,s+a*4/5,r+n*13/16),i.closePath(),i instanceof Path2D)return i}function file(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:n,ey:c}=e.calculative.worldRect,l=a/6;if(i.moveTo(s,r),i.lineTo(n-l,r),i.lineTo(n,r+l),i.lineTo(n,c),i.lineTo(s,c),i.closePath(),i.moveTo(n-l,r),i.lineTo(n-l,r+l),i.lineTo(n,r+l),i.closePath(),i instanceof Path2D)return i}function cube(e,t){const{x:i,y:s,width:r,ex:a,ey:n}=t.calculative.worldRect;let c=r*.25;const l=t.z;l>1?c=l*t.calculative.canvas.store.data.scale:l>0&&(c=r*l);const u={x:i,y:s+c},h={x:a-c,y:s+c},v={x:a-c,y:n};face(e,[u,h,v,{x:i,y:n}],t.backgroundFront||t.background,t.color),face(e,[u,{x:i+c,y:s},{x:a,y:s},h],t.backgroundUp||t.background,t.color),face(e,[h,{x:a,y:s},{x:a,y:n-c},v],t.backgroundRight||t.background,t.color)}function face(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 people(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:n,ey:c}=e.calculative.worldRect,l=a/4,u=s+a/2;if(i.arc(u,r+l,l,0,Math.PI*2),i.moveTo(s,r+l*3),i.lineTo(n,r+l*3),i.moveTo(u,r+l*2),i.lineTo(u,r+l*4),i.moveTo(u,r+l*4),i.lineTo(s,c),i.moveTo(u,r+l*4),i.lineTo(n,c),i.closePath(),i instanceof Path2D)return i}let faceSpace=10;function polyline(e,t,i){var p;if(t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),faceSpace=e.options.polylineSpace||10,t.calculative.worldAnchors.length<2)return;let s=getFromAnchor(t),r=getToAnchor(t);if(!s||!r)return;let a;if((p=t.anchors)!=null&&p.length&&s===t.calculative.activeAnchor?(a=!0,s=r,r=getFromAnchor(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 n=r.connectTo;deleteTempAnchor(t);const c=[],l=e.pens[s.connectTo],u=e.pens[r.connectTo],h=facePen(s,l),v=facePen(r,u);let f=getFacePoint(s,h,faceSpace);f&&(s=f,c.push(f)),f=getFacePoint(r,v,faceSpace);const g=r;let y;if(f&&(r=f,g.connectTo&&(f.y>g.y&&s.y<g.y||f.y<g.y&&s.y>g.y))){y=f;let m=faceSpace;s.x<f.x&&(m=-m),Math.abs(s.x-f.x)<m&&(m=-m),r={x:f.x+m,y:f.y,id:s8()}}switch(h){case Direction.Up:c.push(...getNextPointsOfUp(s,r,v));break;case Direction.Right:c.push(...getNextPointsOfRight(s,r,v));break;case Direction.Bottom:c.push(...getNextPointsOfBottom(s,r,v));break;case Direction.Left:c.push(...getNextPointsOfLeft(s,r,v));break;default:c.push(...getNextPoints(t,s,r));break}if(c.forEach(m=>{m.id=s8(),m.penId=t.id,t.calculative.worldAnchors.push(m)}),t.calculative.worldAnchors.push(r),y&&t.calculative.worldAnchors.push(y),f&&t.calculative.worldAnchors.push(g),a&&t.calculative.worldAnchors.reverse(),n){const m=t.calculative.worldAnchors.length-2;t.calculative.worldAnchors[m].isTemp=!1,t.calculative.worldAnchors[1].isTemp=!1}}function getFacePoint(e,t,i){const s={x:e.x,y:e.y,id:s8()};switch(t){case Direction.Up:s.y-=i;break;case Direction.Right:s.x+=i;break;case Direction.Bottom:s.y+=i;break;case Direction.Left:s.x-=i;break;default:return}return s}function getNextPointsOfUp(e,t,i){if(e.x===t.x||e.y===t.y)return[];const s=[];let r,a;switch(i){case Direction.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 Direction.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 n=(e.y+t.y)/2;s.push({x:e.x,y:n},{x:t.x,y:n})}break;case Direction.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 Direction.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-faceSpace)r=e.x+(t.x-e.x)/2,s.push({x:r,y:e.y},{x:r,y:t.y});else{const n=(e.y+t.y+faceSpace)/2;s.push({x:e.x,y:n},{x:t.x,y:n})}break}return s}function getNextPointsOfRight(e,t,i){if(e.x===t.x||e.y===t.y)return[];const s=[];let r,a;switch(i){case Direction.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 Direction.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 Direction.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 n=(e.x+t.x)/2;s.push({x:n,y:a},{x:n,y:t.y})}break;case Direction.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+faceSpace)s.push({x:e.x,y:a});else{const n=(e.x+t.x-faceSpace)/2;s.push({x:n,y:e.y},{x:n,y:a})}break}return s}function getNextPointsOfBottom(e,t,i){if(e.x===t.x||e.y===t.y)return[];const s=[];let r,a;switch(i){case Direction.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 n=(e.y+t.y)/2;s.push({x:r,y:n},{x:t.x,y:n})}break;case Direction.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 Direction.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 Direction.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+faceSpace)r=e.x+(t.x-e.x)/2,s.push({x:r,y:e.y},{x:r,y:t.y});else{const n=(e.y+t.y-faceSpace)/2;s.push({x:r,y:n},{x:t.x,y:n})}break}return s}function getNextPointsOfLeft(e,t,i){if(e.x===t.x||e.y===t.y)return[];const s=[];let r,a;switch(i){case Direction.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 Direction.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 Direction.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 n=(e.x+t.x)/2;s.push({x:n,y:e.y},{x:n,y:t.y})}break;case Direction.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-faceSpace){const n=(e.x+t.x+faceSpace)/2;s.push({x:n,y:e.y},{x:n,y:a})}else s.push({x:e.x,y:a});break}return s}function getNextPoints(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)<faceSpace&&(i.isTemp=!0)):(s.push({x:t.x,y:i.y}),Math.abs(i.x-t.x)<faceSpace&&(i.isTemp=!0))),s}function anchorInHorizontal(e,t,i=!0){var r,a;let s=e.calculative.worldAnchors;i||(s=[],e.calculative.worldAnchors.forEach(n=>{s.unshift(n)}));for(let n=0;n<s.length&&s[n].id!==t.id;n++)if(s[n].y!==t.y||s[n].x===((r=s[n+1])==null?void 0:r.x)&&s[n].y!==((a=s[n+1])==null?void 0:a.y))return!1;return!0}function anchorInVertical(e,t,i=!0){var r,a;let s=e.calculative.worldAnchors;i||(s=[],e.calculative.worldAnchors.forEach(n=>{s.unshift(n)}));for(let n=0;n<s.length&&s[n].id!==t.id;n++)if(s[n].x!==t.x||s[n].y===((r=s[n+1])==null?void 0:r.y)&&s[n].x!==((a=s[n+1])==null?void 0:a.x))return!1;return!0}function translatePolylineAnchor(e,t,i){if(!e.calculative.worldAnchors)return;const s=e.calculative.worldAnchors.findIndex(l=>l.id===t.id),r=getFromAnchor(e),a=getToAnchor(e);let n=e.calculative.worldAnchors[s-1],c=e.calculative.worldAnchors[s+1];if(e.calculative.h==null&&(r.connectTo&&(anchorInHorizontal(e,t,!0)?e.calculative.h=!0:anchorInVertical(e,t,!0)&&(e.calculative.h=!1)),e.calculative.h==null&&a.connectTo&&(anchorInHorizontal(e,t,!1)?e.calculative.h=!0:anchorInVertical(e,t,!1)&&(e.calculative.h=!1)),e.calculative.h==null&&(n?e.calculative.h=n.y===t.y:c&&(e.calculative.h=c.y===t.y))),e.calculative.h){if(t.x=i.x,r.connectTo&&anchorInHorizontal(e,t,!0)){c&&c.y!==t.y&&(c.x=t.x);return}if(a.connectTo&&anchorInHorizontal(e,t,!1)){n&&n.y!==t.y&&(n.x=t.x);return}const l=e.anchors[s];let u;for(let h=s-1;h>-1;h--)if(n=e.anchors[h],u==null&&(u=n.y===l.y),u===!0)if(n.y===l.y)e.calculative.worldAnchors[h].y=i.y;else break;else if(n.x===l.x)e.calculative.worldAnchors[h].x=i.x;else break;u=void 0;for(let h=s+1;h<e.calculative.worldAnchors.length&&(c=e.anchors[h],c);h++)if(u==null&&(u=c.y===l.y),u===!0)if(c.y===l.y)e.calculative.worldAnchors[h].y=i.y;else break;else if(c.x===l.x)e.calculative.worldAnchors[h].x=i.x;else break;t.y=i.y}else{if(t.y=i.y,r.connectTo&&anchorInVertical(e,t,!0)){c&&c.x!==t.x&&(c.y=t.y);return}if(a.connectTo&&anchorInVertical(e,t,!1)){n&&n.x!==t.x&&(n.y=t.y);return}const l=e.anchors[s];let u;for(let h=s-1;h>-1;h--)if(n=e.anchors[h],u==null&&(u=n.x===l.x),u===!0)if(n.x===l.x)e.calculative.worldAnchors[h].x=i.x;else break;else if(n.y===l.y)e.calculative.worldAnchors[h].y=i.y;else break;u=void 0;for(let h=s+1;h<e.calculative.worldAnchors.length&&(c=e.anchors[h],c);h++)if(u==null&&(u=c.x===l.x),u===!0)if(c.x===l.x)e.calculative.worldAnchors[h].x=i.x;else break;else if(c.y===l.y)e.calculative.worldAnchors[h].y=i.y;else break;t.x=i.x}}function simplify(e,t,i,s){const r=[];let a,n,c,l,u,h,v,f,g,y,p,m,x,k;g=e[i],y=e[s],c=g.x,l=g.y,v=y.x-c,f=y.y-l,k=v*v+f*f,a=t;for(let w=i+1;w<s;w++)p=e[w],v!==0||f!==0?(m=((p.x-c)*v+(p.y-l)*f)/k,m>1?(u=p.x-y.x,h=p.y-y.y):m>0?(u=p.x-(c+v*m),h=p.y-(l+f*m)):(u=p.x-c,h=p.y-l)):(u=p.x-c,h=p.y-l),x=u*u+h*h,x>a&&(n=w,a=x);return a>t&&(n-i>1&&r.push(...simplify(e,t,i,n)),r.push({id:e[n].id,penId:e[n].penId,x:e[n].x,y:e[n].y}),s-n>1&&r.push(...simplify(e,t,n,s))),r}function smoothLine(e,t=.8,i=!1){if(e.length<3)return e;let s,r,a,n,c,l,u,h,v,f,g,y,p,m,x;const k=(w,C,I,_)=>(n=Math.sqrt(w*w+C*C),n>0?(y=w/n,m=C/n):(y=1,m=0),c=Math.sqrt(I*I+_*_),c>0?(p=I/c,x=_/c):(p=1,x=0),Math.acos(y*p+m*x));f=[],g=e.length,s=e[0],e[g-1],f.push({...e[0]});for(let w=0;w<g-1;w++){if(r=e[w],a=e[w+1],v=Math.abs(k(r.x-s.x,r.y-s.y,a.x-r.x,a.y-r.y)),n)if(v<t*3.14)if(i&&(n=Math.min(n,c),c=n),l=(y+p)/2,u=(m+x)/2,h=Math.sqrt(l*l+u*u),h===0)f.push({...r});else{l/=h,u/=h;const C={...r};C.prevNextType=PrevNextType.Bilateral,C.prev={penId:C.penId,x:r.x-l*n*.25,y:r.y-u*n*.25},C.next={penId:C.penId,x:r.x+l*c*.25,y:r.y+u*c*.25},f.push(C)}else f.push({...r});s=r}return f.push({...e[e.length-1]}),f}function drawArrow(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,n=(e.animateLineWidth*2||12)*r;e.lineAnimateType===LineAnimateType.WaterDrop&&(n=(e.animateLineWidth*4||24)*r);let c=(e.animateInterval||100)*r,l=e.calculative.lineWidth*(e.calculative.lineSmooth||0),u=(e.calculative.animateLineWidth/2||3)*r;if(e.animateReverse&&(n=-n,a=-a),s.length>1){let h,v=0;if(e.close&&(s=deepClone(s),s.push(s[0])),["polyline","line"].includes(e.lineName))for(let f=0;f<s.length;f++){let g=s[f];if(h){let y=getAngle(h,g),p={x:h.x+(e.calculative.animatePos-v)%c*Math.cos(y*Math.PI/180),y:h.y-(e.calculative.animatePos-v)%c*Math.sin(y*Math.PI/180)};e.animateReverse&&(p={x:h.x+(e.length-(e.calculative.animatePos+v))%c*Math.cos(y*Math.PI/180),y:h.y-(e.length-(e.calculative.animatePos+v))%c*Math.sin(y*Math.PI/180)});let m=Math.sqrt((p.x-h.x)**2+(p.y-h.y)**2),x=Math.sqrt((g.x-h.x)**2+(g.y-h.y)**2);for(;m<x;)(e.animateReverse&&m-n<x||!e.animateReverse&&m>n)&&m>l+n&&x-m>l&&(e.lineAnimateType===LineAnimateType.Arrow?arrow(i,p,a,y,u,n):e.lineAnimateType===LineAnimateType.WaterDrop&&waterDrop(i,p,e.animateReverse,y,u,n)),p.x+=c*Math.cos(y*Math.PI/180),p.y-=c*Math.sin(y*Math.PI/180),m=Math.sqrt((p.x-h.x)**2+(p.y-h.y)**2)}h=g}else{let f,g=e.calculative.animatePos%c/c;g>1&&(g=1),e.animateReverse&&(g=1-g);let y=1/(s[0].lineLength/c),p=g*y,m;s.forEach(x=>{let k=x;if(f)if(y=1/(f.lineLength/c),f.next)if(k.prev)for(m=p;m<1;m+=y){let w=getBezierPoint(m,f,f.next,k.prev,k),C=getBezierPoint(m+.001,f,f.next,k.prev,k),I=getAngle(w,C);e.lineAnimateType===LineAnimateType.Arrow?arrow(i,w,a,I,u,n):e.lineAnimateType===LineAnimateType.WaterDrop&&waterDrop(i,w,e.animateReverse,I,u,n)}else for(m=p;m<1;m+=y){let w=getQuadraticPoint(m,f,f.next,k),C=getQuadraticPoint(m+.001,f,f.next,k),I=getAngle(w,C);e.lineAnimateType===LineAnimateType.Arrow?arrow(i,w,a,I,u,n):e.lineAnimateType===LineAnimateType.WaterDrop&&waterDrop(i,w,e.animateReverse,I,u,n)}else if(k.prev)for(m=p;m<1;m+=y){let w=getQuadraticPoint(m,f,k.prev,k),C=getQuadraticPoint(m+.001,f,k.prev,k),I=getAngle(w,C);e.lineAnimateType===LineAnimateType.Arrow?arrow(i,w,a,I,u,n):e.lineAnimateType===LineAnimateType.WaterDrop&&waterDrop(i,w,e.animateReverse,I,u,n)}else{let w=getAngle(f,k);for(m=p;m<1;m+=y){let C={x:f.x+(k.x-f.x)*m,y:f.y+(k.y-f.y)*m};e.lineAnimateType===LineAnimateType.Arrow?arrow(i,C,a,w,u,n):e.lineAnimateType===LineAnimateType.WaterDrop&&waterDrop(i,C,e.animateReverse,w,u,n)}}f=x,m?p=m-1:m=p})}}if(i instanceof Path2D)return i}function getAngle(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 getRotatePoint(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 arrow(e,t,i,s,r,a){let n=getRotatePoint({x:t.x+i,y:t.y+.57*i},{x:t.x,y:t.y},s),c=getRotatePoint({x:t.x+i,y:t.y-.57*i},{x:t.x,y:t.y},s),l=getRotatePoint({x:t.x+i,y:t.y+r/2},{x:t.x,y:t.y},s),u=getRotatePoint({x:t.x+a,y:t.y+r/2},{x:t.x,y:t.y},s),h=getRotatePoint({x:t.x+i,y:t.y-r/2},{x:t.x,y:t.y},s),v=getRotatePoint({x:t.x+a,y:t.y-r/2},{x:t.x,y:t.y},s);e.moveTo(n.x,n.y),e.lineTo(t.x,t.y),e.lineTo(c.x,c.y),e.lineTo(h.x,h.y),e.lineTo(v.x,v.y),e.lineTo(u.x,u.y),e.lineTo(l.x,l.y),e.lineTo(n.x,n.y)}function waterDrop(e,t,i,s,r,a){let n=r/2;i&&(n=-r/2);let c=getRotatePoint({x:t.x,y:t.y+n},{x:t.x,y:t.y},s),l=getRotatePoint({x:t.x+a,y:t.y},{x:t.x,y:t.y},s),u=Math.PI/2;i&&(u=-Math.PI/2),e.moveTo(t.x,t.y),e.arc(t.x,t.y,r/2,-u-s/180*Math.PI,u-s/180*Math.PI,!1),e.lineTo(l.x,l.y),e.lineTo(c.x,c.y)}const iframes={};function clearIframes(){var e;for(const t in iframes)(e=iframes[t])==null||e.remove(),iframes[t]=null}function updateIframes(e){var t;for(const i in iframes)e.some(s=>s.name=="iframe"&&s.iframe==i)||((t=iframes[i])==null||t.remove(),iframes[i]=null)}function matchIframe(e){const t=iframes[e.iframe];return t?(e.calculative.singleton.div=t,generateAroundDiv(e),!0):!1}function iframe(e){var i;e.onDestroy||(e.onDestroy=destory$5,e.onMove=move$4,e.onResize=move$4,e.onRotate=move$4,e.onValue=move$4,e.onMouseMove=mouseMove$1,e.onBeforeValue=beforeValue$7,e.onRenderPenRaw=renderPenRaw),e.calculative.singleton||(e.calculative.singleton={});const t=e.calculative.worldRect;if(!e.calculative.singleton.div){if(matchIframe(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),setElemPosition(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),generateAroundDiv(e),r.onload=()=>{r.setAttribute("document.domain","")}}return e.calculative.patchFlags&&setElemPosition(e,e.calculative.singleton.div),e.onRenderPenRaw(e),new Path2D}function destory$5(e){updatePointerEvents(e),e.calculative.singleton&&e.calculative.singleton.div&&(e.calculative.canvas.store.data.locked?(iframes[e.calculative.iframe]=e.calculative.singleton.div,delete e.calculative.singleton.div):(e.calculative.singleton.div.remove(),iframes[e.calculative.iframe]=null))}function move$4(e){e.calculative.singleton.div&&setElemPosition(e,e.calculative.singleton.div)}function beforeValue$7(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=deepClone(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?generateAroundDiv(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 mouseMove$1(e,t){if(!(!e.calculative.canvas.store.data.locked&&!e.locked)&&initOperationalRect(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 initOperationalRect(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 removeAllButFirst(e){for(;e.childNodes.length>1;)e.removeChild(e.lastChild)}function generateAroundDiv(e){if(!initOperationalRect(e.operationalRect))return;const t=e.calculative.singleton.div;if(!t)return;t.childNodes.length>1&&removeAllButFirst(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 n=document.createElement("div");n.style.position="absolute",n.style.left="0px",n.style.top="0px",n.style.width=e.operationalRect.x*100+"%",n.style.height="100%",!i&&e.blur&&(n.style["backdrop-filter"]=`blur(${e.blur}px)`),n.style.backgroundColor=e.blurBackground,t.appendChild(n);let c=()=>{updatePointerEvents(e)};s.onmouseenter=c,a.onmouseenter=c,r.onmouseenter=c,n.onmouseenter=c,t.onmouseleave=c}function updatePointerEvents(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 renderPenRaw(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 videos={},mutedIcons=['<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 video(e){var t;if(e.onDestroy||(e.onDestroy=destory$4,e.onMove=move$3,e.onResize=move$3,e.onRotate=move$3,e.onClick=click$1,e.onValue=value$3,e.onChangeId=changeId$1),videos[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=mutedIcons[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=n=>{n.stopPropagation(),e.calculative.media.muted?(r.innerHTML=mutedIcons[0],e.calculative.media.muted=!1):(r.innerHTML=mutedIcons[1],e.calculative.media.muted=!0)},e.calculative.singleton||(e.calculative.singleton={div:i}),e.calculative.singleton.muted=r,i.onmouseenter=n=>{e.hideMuted||(r.style.display="block")},i.onmouseleave=n=>{r.style.display="none"},i.onclick=n=>{n.stopPropagation(),click$1(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=()=>{resizeProcessWidth(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),videos[e.id]=i,(t=e.calculative.canvas.externalElements)==null||t.parentElement.appendChild(i),setElemPosition(e,i),e.autoPlay&&(a.autoplay=!0,a.muted=!0)}return e.calculative.patchFlags&&setElemPosition(e,videos[e.id]),new Path2D}function destory$4(e){videos[e.id].onclick=null,videos[e.id].remove(),videos[e.id]=void 0}function move$3(e){setElemPosition(e,videos[e.id]);const t=videos[e.id].children[0],i=videos[e.id].children[1];resizeProcessWidth(t,i,e.calculative.worldRect.width)}function click$1(e){e.calculative.media&&(e.calculative.media.muted=!1,e.calculative.singleton.muted.innerHTML=mutedIcons[0],e.calculative.media.paused?e.calculative.media.play():e.calculative.media.pause())}function resizeProcessWidth(e,t,i){e.style.width=t.currentTime/t.duration*i+"px"}function changeId$1(e,t,i){videos[t]&&(videos[i]=videos[t],delete videos[t])}function value$3(e){const t=videos[e.id];if(!t)return;setElemPosition(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 createOffscreen(){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 Tooltip{constructor(t,i){B(this,"parentElement");B(this,"store");B(this,"box");B(this,"text");B(this,"arrowUp");B(this,"arrowDown");B(this,"x");B(this,"y");B(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){if(t.titleFnJs&&!t.titleFn)try{t.titleFn=new Function("pen",t.titleFnJs)}catch(i){console.log("titleFnJs",i)}return t.titleFn?t.titleFn(t):String(t.title)}setText(t){const i=this.box.getBoundingClientRect();let s=globalThis.marked;const r=Tooltip.getTitle(t);if(s){this.text.innerHTML=s(r);const a=this.text.getElementsByTagName("A");for(let n=0;n<a.length;++n)a[n].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||Tooltip.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,Tooltip.titleEmpty(t)){let c=getParent(t,!0);c&&this.show(c,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,n=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,n=t.calculative.canvas.store.data.y+r.ey-s.height-r.height),n>0?(this.arrowUp.style.borderBottomColor="transparent",this.arrowDown.style.borderTopColor="#777777"):(n+=s.height+r.height+5,this.arrowUp.style.borderBottomColor="#777777",this.arrowDown.style.borderTopColor="transparent"),this.x=a,this.y=n,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 Scroll{constructor(t){B(this,"parent");B(this,"h");B(this,"v");B(this,"isDownH");B(this,"isDownV");B(this,"x");B(this,"y");B(this,"hSize");B(this,"vSize");B(this,"scrollX");B(this,"scrollY");B(this,"lastScrollX");B(this,"lastScrollY");B(this,"rect");B(this,"isShow");B(this,"isV");B(this,"padding");B(this,"pageMode");B(this,"onMouseDownH",t=>{t.preventDefault(),t.stopPropagation(),this.isDownH=t.x,this.x=this.parent.store.data.x||0,this.lastScrollX=this.scrollX});B(this,"onMouseDownV",t=>{t.preventDefault(),t.stopPropagation(),this.isDownV=t.y,this.y=this.parent.store.data.y||0,this.lastScrollY=this.scrollY});B(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())});B(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 CanvasImage{constructor(t,i,s){B(this,"parentElement");B(this,"store");B(this,"isBottom");B(this,"canvas",document.createElement("canvas"));B(this,"otherOffsreen",createOffscreen());B(this,"offscreen",createOffscreen());B(this,"animateOffsScreen",createOffscreen());B(this,"fitOffscreen",createOffscreen());B(this,"fitFlag",!1);B(this,"currentFit");B(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===CanvasLayer.CanvasImageBottom||!this.isBottom&&t.canvasLayer===CanvasLayer.CanvasImage)&&t.image&&t.calculative.img&&t.name!=="gif",t.calculative.hasImage}render(){var n;let t=!1,i=!1;for(const c of this.store.data.pens)this.hasImage(c)&&(this.store.animates.has(c)?i=!0:c.calculative.imageDrawed||(t=!0),c.parentId&&this.store.animates.has(getParent(c,!0))&&(i=!0));const s=this.store.patchFlagsBackground,r=this.store.patchFlagsTop;if(r&&!this.isBottom){const c=this.otherOffsreen.getContext("2d");c.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderRule(c)}if(this.store.patchFlagsLast&&this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),t){const c=this.offscreen.getContext("2d");c.save(),c.clearRect(0,0,this.canvas.width,this.canvas.height),c.translate(this.store.data.x,this.store.data.y);for(const l of this.store.data.pens)!l.calculative.hasImage||this.store.animates.has(l)||this.store.animates.has(getParent(l,!0))||l.canvasLayer!==CanvasLayer.CanvasTemplate&&(l.calculative.imageDrawed=!0,c.save(),ctxFlip(c,l),(l.rotateByRoot||l.calculative.rotate)&&ctxRotate(c,l),setGlobalAlpha(c,l),drawImage(c,l),c.restore());c.restore()}if(i){const c=this.animateOffsScreen.getContext("2d");c.save(),c.clearRect(0,0,this.canvas.width,this.canvas.height),c.translate(this.store.data.x,this.store.data.y);for(const l of this.store.animates)l.calculative.hasImage&&l.canvasLayer!==CanvasLayer.CanvasTemplate&&(l.visible===!1||l.calculative.visible===!1||(l.calculative.imageDrawed=!0,c.save(),ctxFlip(c,l),(l.rotateByRoot||l.calculative.rotate)&&ctxRotate(c,l),setGlobalAlpha(c,l),drawImage(c,l),c.restore()));for(const l of this.store.data.pens)!l.calculative.hasImage||!l.parentId||l.canvasLayer!==CanvasLayer.CanvasTemplate&&(l.visible===!1||l.calculative.visible===!1||this.store.animates.has(getParent(l,!0))&&(l.calculative.imageDrawed=!0,c.save(),ctxFlip(c,l),(l.rotateByRoot||l.calculative.rotate)&&ctxRotate(c,l),setGlobalAlpha(c,l),drawImage(c,l),c.restore()));c.restore()}if(!this.isBottom&&!this.store.data.locked&&this.fitFlag){const c=(this.store.data.width||this.store.options.width)*this.store.data.scale,l=(this.store.data.height||this.store.options.height)*this.store.data.scale,u=this.store.data.origin.x+this.store.data.x||this.store.options.x||0,h=this.store.data.origin.y+this.store.data.y||this.store.options.y||0,v=this.fitOffscreen.getContext("2d");v.save(),v.clearRect(0,0,this.canvas.width,this.canvas.height),v.fillStyle="#ffffff66",v.strokeStyle=this.store.styles.activeColor,(n=this.store.data.fits)==null||n.forEach((f,g)=>{v.fillRect(u+c*f.x,h+l*f.y,c*f.width,l*f.height),f.active&&v.strokeRect(u+c*f.x,h+l*f.y,c*f.width,l*f.height)}),v.restore()}if(t||i||s&&this.isBottom||r&&!this.isBottom){const c=this.canvas.getContext("2d");c.clearRect(0,0,this.canvas.width,this.canvas.height),this.isBottom&&(this.store.patchFlagsBackground=!1),c.drawImage(this.offscreen,0,0,this.canvas.width,this.canvas.height),c.drawImage(this.animateOffsScreen,0,0,this.canvas.width,this.canvas.height),this.isBottom||(c.drawImage(this.otherOffsreen,0,0,this.canvas.width,this.canvas.height),this.store.patchFlagsTop=!1,!this.store.data.locked&&this.fitFlag&&c.drawImage(this.fitOffscreen,0,0,this.canvas.width,this.canvas.height))}}renderRule(t){var w,C,I,_,L,E,F,q;const{data:i,options:s}=this.store,{rule:r,ruleColor:a,scale:n,origin:c}=i;if(!(r??s.rule))return;const l=n*10;t.save();const u=a||s.ruleColor||"#ccc";t.strokeStyle=rgba(u,.7);const h=c.x+i.x,v=c.y+i.y,{width:f,height:g}=this.canvas;let y=((w=s.ruleOptions)==null?void 0:w.height)||20;(C=s.ruleOptions)!=null&&C.background&&(t.beginPath(),t.fillStyle=(I=s.ruleOptions)==null?void 0:I.background,t.rect(0,0,f,y),t.fill(),t.rect(0,0,y,g),t.fill()),(_=s.ruleOptions)!=null&&_.underline&&(t.beginPath(),t.fillStyle=rgba(u,.7),t.moveTo(0,y),t.lineTo(f,y),t.stroke(),t.moveTo(y,0),t.lineTo(y,g),t.stroke());let p=y/4;((L=s.ruleOptions)==null?void 0:L.baseline)==="bottom"&&(p=y*3/4),t.beginPath(),t.lineWidth=y/2,t.lineDashOffset=-h%l,t.setLineDash([1,l-1]),t.moveTo(0,p),t.lineTo(f,p),t.stroke(),t.beginPath(),t.lineDashOffset=-v%l,t.moveTo(p,0),t.lineTo(p,g),t.stroke(),t.strokeStyle=u,t.beginPath(),t.lineWidth=y,t.lineDashOffset=-h%(l*10),t.setLineDash([1,l*10-1]),t.moveTo(0,y/2),t.lineTo(f,y/2),t.stroke(),t.beginPath(),t.lineDashOffset=-v%(l*10),t.moveTo(y/2,0),t.lineTo(y/2,g),t.stroke(),t.beginPath(),t.fillStyle=((E=s.ruleOptions)==null?void 0:E.textColor)||t.strokeStyle;let m=0-Math.floor(h/l/10)*100,x=((F=s.ruleOptions)==null?void 0:F.textTop)||16,k=((q=s.ruleOptions)==null?void 0:q.textLeft)||4;h<0&&(m-=100);for(let R=h%(l*10);R<f;R+=10*l,m+=100)l<3&&m%500||t.fillText(m.toString(),R+k,x);m=0-Math.floor(v/l/10)*100,v<0&&(m-=100);for(let R=v%(l*10);R<g;R+=10*l,m+=100)l<3&&m%500||(t.save(),t.beginPath(),t.translate(x,R-k),t.rotate(270*Math.PI/180),t.fillText(m.toString(),0,0),t.restore());t.restore()}}class MagnifierCanvas{constructor(t,i,s){B(this,"parentCanvas");B(this,"parentElement");B(this,"store");B(this,"canvas",document.createElement("canvas"));B(this,"magnifierScreen",createOffscreen());B(this,"offscreen",createOffscreen());B(this,"domOffscreen",createOffscreen());B(this,"magnifierSize",300);B(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(l=>{s.drawImage(l,r.x-t,r.y-t,this.magnifierSize,this.magnifierSize,0,0,this.magnifierSize,this.magnifierSize)}),s.restore(),s.beginPath();const n=s.createRadialGradient(t,t,t-5,t,t,t);n.addColorStop(0,"rgba(0,0,0,0.2)"),n.addColorStop(.8,"rgb(200,200,200)"),n.addColorStop(.9,"rgb(200,200,200)"),n.addColorStop(1,"rgba(200,200,200,0.9)"),s.strokeStyle=n,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:n}=i.calculative.worldRect;t.drawImage(i.calculative.img,s,r,a,n),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 lockedError(e){if(e.data.locked)throw new Error("canvas is locked")}class Dialog{constructor(t,i){B(this,"parentElement");B(this,"box");B(this,"iframe");B(this,"dialog");B(this,"close");B(this,"title");B(this,"body");B(this,"x");B(this,"y");B(this,"url");B(this,"meta2dDiv");B(this,"dialogMeta2d");B(this,"store");B(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:c,y:l,width:u,height:h}=this.detailRect(s);this.dialog.style.width=u,this.dialog.style.height=h,this.dialog.style.top=l,this.dialog.style.left=c,this.dialog.style.transform=`translate(${c==="50%"?"-50%":0}, ${l==="50%"?"-50%":0})`,this.box.style.background=s.maskBackground||"#0000006f"}const a=this.isUrl(i);let n=!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,n=!0),this.iframe.onload=()=>{(!this.dialogMeta2d||a)&&(this.close.style.display=s.hideClose?"none":"block",this.box.style.opacity="1")},!n&&(!this.dialogMeta2d||a)&&(this.box.style.opacity="1"),!a){this.meta2dDiv.style.display="block",this.dialogMeta2d||(globalThis.mainMeta2d=globalThis.meta2d,this.dialogMeta2d=new Meta2d(this.meta2dDiv),globalThis.meta2d=globalThis.mainMeta2d);const c=await getMeta2dData(this.store,i);c&&(this.box.style.display="block",this.dialogMeta2d.clear(!0),this.dialogMeta2d.open(c,!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 Title{constructor(t){B(this,"parentElement");B(this,"box");B(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&&(Title.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(Title.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}}class CanvasTemplate{constructor(t,i){B(this,"parentElement");B(this,"store");B(this,"canvas",document.createElement("canvas"));B(this,"offscreen",createOffscreen());B(this,"bgOffscreen",createOffscreen());B(this,"patchFlags");B(this,"bgPatchFlags");B(this,"fit");this.parentElement=t,this.store=i,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.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,n=this.store.data.background||this.store.styles.background;n&&(t.save(),t.fillStyle=n,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===CanvasLayer.CanvasTemplate&&i.calculative.inView&&(renderPen(t,i),i.image&&i.name!=="gif"&&i.calculative.img&&(t.save(),ctxFlip(t,i),(i.rotateByRoot||i.calculative.rotate)&&ctxRotate(t,i),setGlobalAlpha(t,i),drawImage(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,{grid:r,gridRotate:a,gridColor:n,gridSize:c,scale:l,origin:u}=i;if(!(r??s.grid))return;t.save();const h=(i.width||s.width)*l,v=(i.height||s.height)*l,f=(i.x||s.x||0)+u.x,g=(i.y||s.y||0)+u.y;t.lineWidth=1,t.strokeStyle=n||s.gridColor,t.beginPath();let y=(c||s.gridSize)*l;if(y=y<0?0:y,!h||!v){const p=this.store.dpiRatio,m=this.canvas.width/p,x=this.canvas.height/p,k=f/y,w=g/y,C=y*10,I=f-Math.ceil(k)*y,_=g-Math.ceil(w)*y,L=m+I+C,E=x+_+C;if(a){const F=a*Math.PI/180,q=F+Math.PI/2,R={x:Math.sin(F),y:-Math.cos(F)},A={x:Math.sin(q),y:-Math.cos(q)};drawPreciseLines(t,m,x,y,R),drawPreciseLines(t,m,x,y,A)}else{for(let F=I;F<=L;F+=y)t.moveTo(F,_),t.lineTo(F,x+_+C);for(let F=_;F<=E;F+=y)t.moveTo(I,F),t.lineTo(m+I+C,F)}}else if(a){const p=a*Math.PI/180,m=p+Math.PI/2,x={x:Math.sin(p),y:-Math.cos(p)},k={x:Math.sin(m),y:-Math.cos(m)};drawPreciseLinesInRect(t,f,g,h,v,y,x),drawPreciseLinesInRect(t,f,g,h,v,y,k)}else{const p=h+f,m=v+g;for(let x=f;x<=p;x+=y)t.moveTo(x,g),t.lineTo(x,v+g);for(let x=g;x<=m;x+=y)t.moveTo(f,x),t.lineTo(h+f,x)}t.stroke(),t.restore()}}function drawPreciseLines(e,t,i,s,r,a){const n=[{x:0,y:0},{x:t,y:0},{x:t,y:i},{x:0,y:i}];let c=1/0,l=-1/0;n.forEach(h=>{const v=h.x*r.x+h.y*r.y;c=Math.min(c,v),l=Math.max(l,v)});const u=Math.ceil((l-c)/s);e.beginPath();for(let h=0;h<=u;h++){const v=c+h*s;let f=[];for(let g=0;g<n.length;g++){const y=n[g],p=n[(g+1)%n.length],m=r.x*(p.y-y.y)-r.y*(p.x-y.x);if(Math.abs(m)>1e-6){const x=(v-y.x*r.x-y.y*r.y)/(r.x*(p.x-y.x)+r.y*(p.y-y.y));if(x>=0&&x<=1){const k=y.x+x*(p.x-y.x),w=y.y+x*(p.y-y.y);f.push({x:k,y:w})}}}f.length>=2&&(e.moveTo(f[0].x,f[0].y),e.lineTo(f[1].x,f[1].y))}e.stroke()}function drawPreciseLinesInRect(e,t,i,s,r,a,n,c){const l=[{x:t,y:i},{x:t+s,y:i},{x:t+s,y:i+r},{x:t,y:i+r}];let u=1/0,h=-1/0;l.forEach(y=>{const p=y.x*n.x+y.y*n.y;u=Math.min(u,p),h=Math.max(h,p)});const v=h-u,f=Math.ceil(v/a),g=u;e.beginPath();for(let y=0;y<=f;y++){const p=g+y*a,m=[];for(let x=0;x<l.length;x++){const k=l[x],w=l[(x+1)%4],C=w.x-k.x,I=w.y-k.y,_=n.x*I-n.y*C;if(Math.abs(_)>1e-6){const L=(p-k.x*n.x-k.y*n.y)/(n.x*C+n.y*I);L>=0&&L<=1&&m.push({x:k.x+L*C,y:k.y+L*I})}}m.length>=2&&(e.moveTo(m[0].x,m[0].y),e.lineTo(m[1].x,m[1].y))}e.stroke()}const status$1={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 Popconfirm{constructor(t,i){B(this,"parentElement");B(this,"store");B(this,"box");B(this,"text");B(this,"arrowUp");B(this,"arrowDown");B(this,"icon");B(this,"confirm");B(this,"cancel");B(this,"x");B(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=status$1.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,n=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,n=t.calculative.canvas.store.data.y+r.ey-s.height-r.height),n>0?(this.arrowUp.style.borderBottomColor="transparent",this.arrowDown.style.borderTopColor="#fff",n-=10):(n+=s.height+r.height+5,n+=10,this.arrowUp.style.borderBottomColor="#fff",this.arrowDown.style.borderTopColor="transparent"),this.x=a,this.y=n,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 movingSuffix="-moving";class Canvas{constructor(t,i,s){B(this,"parent");B(this,"parentElement");B(this,"store");B(this,"canvas",document.createElement("canvas"));B(this,"offscreen",createOffscreen());B(this,"width");B(this,"height");B(this,"externalElements",document.createElement("div"));B(this,"clientRect");B(this,"canvasRect");B(this,"activeRect");B(this,"initActiveRect");B(this,"dragRect");B(this,"lastRotate",0);B(this,"sizeCPs");B(this,"activeInitPos");B(this,"hoverType",HoverType.None);B(this,"resizeIndex",0);B(this,"mouseDown");B(this,"hotkeyType");B(this,"mouseRight");B(this,"addCaches");B(this,"touchCenter");B(this,"initTouchDis");B(this,"initScale");B(this,"touchScaling");B(this,"touchMoving");B(this,"startTouches");B(this,"lastTouchY");B(this,"startDistance");B(this,"startCenter");B(this,"currentCenter");B(this,"lastOffsetX",0);B(this,"lastOffsetY",0);B(this,"drawingLineName");B(this,"drawLineFns",[...defaultDrawLineFns]);B(this,"drawingLine");B(this,"pencil");B(this,"pencilLine");B(this,"movingPens");B(this,"patchFlagsLines",new Set);B(this,"dock");B(this,"prevAnchor");B(this,"nextAnchor");B(this,"lastMouseTime",0);B(this,"hoverTimer",0);B(this,"fitTimer",0);B(this,"willInactivePen");B(this,"patchFlags",!1);B(this,"lastRender",0);B(this,"touchStart",0);B(this,"touchStartTimer");B(this,"timer");B(this,"lastTapTime",0);B(this,"lastAnimateRender",0);B(this,"animateRendering",!1);B(this,"renderTimer");B(this,"initPens");B(this,"pointSize",8);B(this,"pasteOffset",!0);B(this,"opening",!1);B(this,"maxZindex",5);B(this,"canMoveLine",!1);B(this,"randomIdObj");B(this,"keyOptions");B(this,"isMobile",/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));B(this,"beforeAddPen");B(this,"beforeAddPens");B(this,"beforeAddAnchor");B(this,"beforeRemovePens");B(this,"beforeRemoveAnchor");B(this,"customResizeDock");B(this,"customMoveDock");B(this,"inputParent",document.createElement("div"));B(this,"inputDiv",document.createElement("div"));B(this,"dropdown",document.createElement("ul"));B(this,"tooltip");B(this,"popconfirm");B(this,"title");B(this,"mousePos",{x:0,y:0});B(this,"scroll");B(this,"movingAnchor");B(this,"canvasTemplate");B(this,"canvasImage");B(this,"canvasImageBottom");B(this,"magnifierCanvas");B(this,"dialog");B(this,"autoPolylineFlag",!1);B(this,"stopPropagation",t=>{t.stopPropagation()});B(this,"curve",curve);B(this,"polyline",polyline);B(this,"mind",mind);B(this,"line",lineSegment);B(this,"onCopy",t=>{this.store.options.disableClipboard||t.target!==this.externalElements&&t.target!==document.body&&t.target.offsetParent!==this.externalElements||this.copy()});B(this,"onCut",t=>{this.store.options.disableClipboard||t.target!==this.externalElements&&t.target!==document.body&&t.target.offsetParent!==this.externalElements||this.cut()});B(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:n}=this.mousePos,c=s[r].getAsFile();let l=s[r].type.slice(6)==="gif"?"gif":"image";if(c!==null){const u=l==="gif",h=await this.fileToPen(c,u);h.height=h.height/h.width*100,h.width=100,h.x=a-50/2,h.y=n-h.height/h.width*50,h.externElement=u,this.addPens([h]),this.active([h]),this.copy([h])}}}}else this.paste()});B(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)});B(this,"onwheel",t=>{if(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===HoverType.Node||this.hoverType===HoverType.Line))||this.store.data.locked===LockState.Disable||this.store.data.locked===LockState.DisableScale||this.store.data.locked===LockState.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 n=.2;t.deltaY.toString().indexOf(".")!==-1&&(n=.01),t.deltaY>0?i=-n:i=n}let{offsetX:s,offsetY:r}=t;this.scale(this.store.data.scale+i,{x:s,y:r}),this.externalElements.focus()});B(this,"onkeydown",t=>{var a,n,c;if(this.store.data.locked>=LockState.DisableEdit&&t.target.tagName!=="INPUT"&&t.target.tagName!=="TEXTAREA"&&!t.target.dataset.meta2dIgnore&&this.store.active.forEach(l=>{var u;(u=l.onKeyDown)==null||u.call(l,l,t.key)}),this.store.data.locked>=LockState.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 l=this.store.data.width||this.store.options.width,u=this.store.data.height||this.store.options.height;l&&u&&(r={x:this.store.data.origin.x,y:this.store.data.origin.y,width:l*this.store.data.scale,height:u*this.store.data.scale})}switch(t.key){case" ":this.hotkeyType=HotkeyType.Translate;break;case"Control":this.drawingLine?this.drawingLine.calculative.drawlineH=!this.drawingLine.calculative.drawlineH:this.hotkeyType||(this.patchFlags=!0,this.hotkeyType=HotkeyType.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=HotkeyType.Resize));break;case"Alt":if(!t.ctrlKey&&!t.shiftKey&&this.drawingLine){const l=getToAnchor(this.drawingLine);l!==this.drawingLine.calculative.activeAnchor?(deleteTempAnchor(this.drawingLine),this.drawingLine.calculative.worldAnchors.push(l)):this.drawingLine.calculative.worldAnchors.push({x:l.x,y:l.y});const u=this.drawLineFns.indexOf(this.drawingLineName);this.drawingLineName=this.drawLineFns[(u+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(l=>!l.parentId&&l.locked!==LockState.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":(n=this.store.active[0])!=null&&n.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===HoverType.NodeAnchor&&(this.movingAnchor=this.store.hoverAnchor,this.externalElements.style.cursor="move");break;case"s":case"S":!this.store.data.locked&&this.hoverType===HoverType.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(l=>{l.type?(l.close=!l.close,l.close&&getLinePoints(l),this.store.path2dMap.set(l,globalStore.path2dDraws.line(l)),getLineLength(l)):l.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(l=>{l.type||(l.calculative.focus=!1)}),this.movingPens&&(this.getAllByPens(this.movingPens).forEach(l=>{this.store.pens[l.id]=void 0}),this.movingPens=void 0,this.mouseDown=void 0,this.clearDock(),(c=this.store.active)==null||c.forEach(l=>{this.updateLines(l)}),this.calcActiveRect(),this.patchFlags=!0),this.hotkeyType=HotkeyType.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)});B(this,"onkeyup",t=>{switch(t.key){case"l":case"L":this.canMoveLine=!1;break}this.hotkeyType&&this.render(),this.hotkeyType<HotkeyType.AddAnchor&&(this.hotkeyType=HotkeyType.None)});B(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)});B(this,"ontouchstart",t=>{if(this.lastTouchY=t.touches[0].clientY,this.store.data.locked===LockState.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,n={x:r,y:a};if(this.calibrateMouse(n),this.getHover(n),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)});B(this,"ontouchmove",t=>{var c;if(this.store.data.locked===LockState.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,n=t.touches[0].pageY-this.clientRect.y;if(r===1){if(this.store.options.scroll&&this.scroll&&!this.store.options.scrollButScale){let l=this.lastTouchY-t.touches[0].clientY;this.scroll.wheel(l),this.lastTouchY=t.touches[0].clientY;return}this.onMouseMove({x:a,y:n,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&&((c=this.startTouches)==null?void 0:c.length)===2){if(this.mouseDown=void 0,!this.touchMoving&&!this.touchScaling){const l=this.getDistance(s[0],s[1]),u=this.getCenter(s[0],s[1]),h=l-this.startDistance,v=u.x-this.currentCenter.x,f=u.y-this.currentCenter.y,g=Math.sqrt(v*v+f*f);Math.abs(h)/this.startDistance>g/100?this.touchScaling=!0:g>5&&(this.touchMoving=!0)}if(this.touchScaling){if(this.store.data.disableScale||this.store.options.disableScale)return;const l=Math.hypot(s[0].pageX-s[1].pageX,s[0].pageY-s[1].pageY)/this.initTouchDis;this.scale(this.initScale*l,deepClone(this.touchCenter))}if(this.touchMoving){if(this.store.data.locked>=LockState.DisableMove&&this.store.data.locked!==LockState.DisableScale||this.store.data.disableScale||this.store.options.disableScale)return;if(this.lastOffsetX){const{scale:l}=this.store.data;this.translate((a-this.lastOffsetX)/l,(n-this.lastOffsetY)/l)}this.lastOffsetX=a,this.lastOffsetY=n}}});B(this,"ontouchend",t=>{if(this.store.data.locked===LockState.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)});B(this,"onGesturestart",t=>{t.preventDefault()});B(this,"onMouseDown",t=>{var i,s,r,a,n;if(t.buttons===2&&!this.drawingLine&&(this.mouseRight=MouseRight.Down),this.hideInput(),this.popconfirm.hide(),this.store.data.locked===LockState.Disable||t.buttons!==1&&t.buttons!==2){this.hoverType=HoverType.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===HotkeyType.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 c=this.store.activeAnchor;if(!c)return;const l={id:s8(),x:c.x,y:c.y};this.drawingLine=this.createDrawingLine(l);let u=getFromAnchor(this.drawingLine);this.drawingLine.calculative.activeAnchor=u,connectLine(this.store.hover,c,this.drawingLine,l),this.drawline();return}if(!(this.hotkeyType===HotkeyType.Translate||this.mouseRight===MouseRight.Down&&!this.store.options.mouseRightActive)){if(this.drawingLine){if(this.store.hoverAnchor){const l=getToAnchor(this.drawingLine);this.store.hoverAnchor.type===PointType.Line?getDistance(l,this.store.hoverAnchor,this.store):(l.x=this.store.hoverAnchor.x,l.y=this.store.hoverAnchor.y),connectLine(this.store.hover,this.store.hoverAnchor,this.drawingLine,l),this.drawline(),this.finishDrawline(!0);return}if(!this.store.options.autoAnchor&&t.shiftKey&&t.altKey&&t.ctrlKey){this.setAnchor(this.store.pointAt);const l=getToAnchor(this.drawingLine),u=this.store.activeAnchor;if(!u)return;l.x=u.x,l.y=u.y,connectLine(this.store.hover,u,this.drawingLine,l),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===HoverType.Node){const l=getToAnchor(this.drawingLine),u=nearestAnchor(this.store.hover,t);l.x=u.x,l.y=u.y,this.drawingLine.autoTo=!0,connectLine(this.store.hover,u,this.drawingLine,l),this.drawline(),this.finishDrawline(!0);return}const c=getToAnchor(this.drawingLine);c.isTemp?(this.drawingLine.calculative.activeAnchor=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2],c.isTemp=void 0):(this.drawingLine.calculative.activeAnchor=c,this.drawingLine.calculative.worldAnchors.push({x:c.x,y:c.y,penId:c.penId})),this.drawingLine.calculative.drawlineH=void 0,this.drawingLineName!=="polyline"&&this.drawline()}if(this.drawingLineName){if(this.hoverType===HoverType.Node)if(this.store.options.autoAnchor){this.inactive(!0);const c=nearestAnchor(this.store.hover,t);this.store.hoverAnchor=c;const l={id:s8(),x:c.x,y:c.y};this.drawingLine=this.createDrawingLine(l),this.drawingLine.autoFrom=!0,connectLine(this.store.hover,c,this.drawingLine,l)}else this.inactive(),this.hoverType=HoverType.None;else if(this.hoverType===HoverType.NodeAnchor){this.drawingLineName=this.store.options.drawingLineName;const c={id:s8(),x:this.store.hoverAnchor.x,y:this.store.hoverAnchor.y};this.drawingLine=this.createDrawingLine(c),this.drawingLine.calculative.activeAnchor=c,connectLine(this.store.hover,this.store.hoverAnchor,this.drawingLine,c)}else if(!this.drawingLine&&this.drawingLineName!=="curve"){this.inactive(!0);const c={id:s8(),x:t.x,y:t.y};this.drawingLine=this.createDrawingLine(c),this.drawingLine.calculative.activeAnchor=c}}else if(this.pencil){this.inactive(!0);const c=s8(),l={x:t.x,y:t.y,id:s8(),penId:c};this.pencilLine=this.getInitPencilLine(l)}else{switch(this.hoverType){case HoverType.None:(this.store.data.rule||this.store.options.rule)&&!this.store.options.disableRuleLine&&this.addRuleLine(t),this.store.options.resizeMode&&(this.hotkeyType=HotkeyType.None),this.inactive();break;case HoverType.Node:case HoverType.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 c=getParent(this.store.hover,!0);let l=c||this.store.hover;c&&(c.container||(n=this.store.options.containerShapes)!=null&&n.includes(c.name))&&(l=this.store.hover),t.ctrlKey&&!t.shiftKey?(l.calculative.active?this.willInactivePen=l:this.store.active.length>0&&(l.calculative.active=!0,setChildrenActive(l),this.store.active.push(l),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&&pointInRect({x:t.x,y:t.y},this.activeRect))||this.store.active.length==1)&&(l.calculative.active||(this.active([l]),this.store.options.resizeMode&&(this.hotkeyType=HotkeyType.Resize))),this.calcActiveRect()}break;case HoverType.LineAnchor:this.store.activeAnchor=this.store.hoverAnchor,this.store.hover.calculative.activeAnchor=this.store.hoverAnchor,this.active([this.store.hover]);break;case HoverType.LineAnchorPrev:case HoverType.LineAnchorNext:this.store.activeAnchor&&(this.prevAnchor={...this.store.activeAnchor.prev},this.nextAnchor={...this.store.activeAnchor.next});break;case HoverType.Resize:this.activeInitPos=[],this.store.active.forEach(c=>{this.activeInitPos.push({x:(c.calculative.worldRect.x-this.activeRect.x)/this.activeRect.width,y:(c.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()}}});B(this,"onMouseMove",t=>{var s,r,a,n,c,l,u,h,v;if(this.store.data.locked===LockState.Disable){this.hoverType=HoverType.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 f=performance.now();f-this.fitTimer>100&&(this.mouseDown?this.updateFit(t):this.inFitBorder(this.mousePos),this.fitTimer=f);return}if(this.mouseDown&&!this.store.options.disableTranslate&&!this.store.data.disableTranslate){this.mouseRight===MouseRight.Down&&(this.mouseRight=MouseRight.Translate);const f=this.store.active[0];if(f&&this.store.data.locked&&(f.locked===void 0||f.locked<LockState.DisableMove)){(s=f==null?void 0:f.onMouseMove)==null||s.call(f,f,this.mousePos);return}if(this.store.data.locked===LockState.DisableEdit||this.store.data.locked===LockState.DisableScale||this.hotkeyType===HotkeyType.Translate||this.mouseRight===MouseRight.Translate){const{scale:g}=this.store.data;let y=(t.x-this.mouseDown.x)/g,p=(t.y-this.mouseDown.y)/g;t.shiftKey&&!t.ctrlKey&&(p=0),t.ctrlKey&&(y=0),this.translate(y,p);return}if(this.store.data.locked)return;if(!this.drawingLine&&!this.pencil){if(!this.drawingLineName&&!this.movingAnchor){if(this.hoverType===HoverType.NodeAnchor){if(!this.store.hoverAnchor)return;this.drawingLineName=this.store.options.drawingLineName;const g={id:s8(),x:this.store.hoverAnchor.x,y:this.store.hoverAnchor.y};this.drawingLine=this.createDrawingLine(g),this.drawingLine.calculative.activeAnchor=g,connectLine(this.store.hover,this.store.hoverAnchor,this.drawingLine,g),this.drawline();return}}else if(this.drawingLineName&&this.hoverType===HoverType.None){const g={id:s8(),x:t.x,y:t.y};this.drawingLine=this.createDrawingLine(g),this.drawingLine.calculative.activeAnchor=g,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 g=t.x-this.movingAnchor.x,y=t.y-this.movingAnchor.y;this.translateAnchor(g,y),this.render();return}else if(!((a=this.store.active[0])!=null&&a.locked)){const g={x:t.x,y:t.y};if(this.hoverType===HoverType.LineAnchor){(this.dockInAnchor(t)||((n=this.store.active[0])==null?void 0:n.lineName)==="line")&&!this.store.options.disableDock&&!this.store.options.disableLineDock&&(this.clearDock(),this.dock=calcAnchorDock(this.store,g,this.store.activeAnchor),(c=this.dock)!=null&&c.xDock&&(g.x+=this.dock.xDock.step),(l=this.dock)!=null&&l.yDock&&(g.y+=this.dock.yDock.step)),this.moveLineAnchor(g,t);return}if(this.hoverType===HoverType.LineAnchorPrev){this.moveLineAnchorPrev(t);return}if(this.hoverType===HoverType.LineAnchorNext){this.moveLineAnchorNext(t);return}}if(this.hoverType===HoverType.Rotate){this.rotatePens({x:t.x,y:t.y});return}if(this.hoverType===HoverType.Resize){this.resizePens(t);return}if(this.hoverType===HoverType.Node||this.hoverType===HoverType.Line){const g=t.x-this.mouseDown.x,y=t.y-this.mouseDown.y,p=20;if(t.ctrlKey&&!t.shiftKey&&(Math.abs(g)>=p||Math.abs(y)>=p)&&(this.willInactivePen=void 0),this.store.active.length===1){const m=this.store.active[0];if((m.locked===void 0||m.locked<LockState.DisableMove)&&((u=m==null?void 0:m.onMouseMove)==null||u.call(m,m,this.mousePos)),m.calculative.focus)return}this.movePens(t),this.getContainerHover(t);return}}else if(this.pencil){const{x:g,y}=t,p={x:g,y};p.id=s8(),p.penId=this.pencilLine.id,this.pencilLine.calculative.worldAnchors.push(p),this.store.path2dMap.set(this.pencilLine,globalStore.path2dDraws[this.pencilLine.name](this.pencilLine)),this.patchFlags=!0}}if(this.drawingLine){const{x:f,y:g}=t,y={x:f,y:g};if(y.id=s8(),y.penId=this.drawingLine.id,!this.store.options.disableDock&&!this.store.options.disableLineDock&&(this.clearDock(),this.dock=calcAnchorDock(this.store,y),(h=this.dock)!=null&&h.xDock&&(y.x+=this.dock.xDock.step),(v=this.dock)!=null&&v.yDock&&(y.y+=this.dock.yDock.step)),this.mouseDown&&this.drawingLineName==="curve"&&!this.drawingLine.calculative.worldAnchors[0].connectTo)this.drawline(y);else{let p;if(this.drawingLine.calculative.worldAnchors.length>1&&(p=getToAnchor(this.drawingLine)),p?(p.prev=void 0,p.next=void 0,p.id||(p.id=s8()),p.x=y.x,p.y=y.y,p.connectTo=void 0):(p={...y},this.drawingLine.calculative.worldAnchors.push(p)),(this.hoverType===HoverType.NodeAnchor||this.hoverType===HoverType.LineAnchor)&&(this.store.hoverAnchor.type!==PointType.Line&&(p.x=this.store.hoverAnchor.x,p.y=this.store.hoverAnchor.y),p.connectTo=this.store.hoverAnchor.penId,this.drawingLineName==="polyline"&&(p.isTemp=!1)),this.drawingLineName==="line"){if(t.ctrlKey&&!t.shiftKey)p.x=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].x;else if(t.shiftKey&&!t.ctrlKey)p.y=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].y;else if(t.shiftKey&&t.ctrlKey){let m=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2];this.getSpecialAngle(p,m)}}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===HotkeyType.AddAnchor&&(this.patchFlags=!0),this.render(!1)});B(this,"onMouseUp",t=>{if(this.store.data.locked===LockState.Disable){this.hoverType=HoverType.None;return}if(this.mouseDown){if(this.mouseRight===MouseRight.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=MouseRight.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=getToAnchor(this.drawingLine);this.store.hoverAnchor.type===PointType.Line?getDistance(i,this.store.hoverAnchor,this.store):(i.x=this.store.hoverAnchor.x,i.y=this.store.hoverAnchor.y),connectLine(this.store.hover,this.store.hoverAnchor,this.drawingLine,i),this.drawline(),this.finishDrawline(!0);return}if(this.store.options.autoAnchor&&this.hoverType===HoverType.Node){const i=getToAnchor(this.drawingLine),s=nearestAnchor(this.store.hover,t);i.x=s.x,i.y=s.y,this.drawingLine.autoTo=!0,connectLine(this.store.hover,s,this.drawingLine,i),this.drawline(),this.finishDrawline(!0);return}}if(this.hoverType===HoverType.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=getFromAnchor(i),r=getToAnchor(i);if(this.store.hoverAnchor){const a=this.store.hover,n=getFromAnchor(a)===this.store.hoverAnchor,c=getToAnchor(a)===this.store.hoverAnchor,l=s===this.store.activeAnchor,u=r===this.store.activeAnchor;if((t.ctrlKey||t.altKey)&&a.type===PenType.Line&&(n||c)&&(l||u)){const h=a.calculative.worldAnchors.map(v=>({...v,penId:i.id}));n?h.shift():c&&h.pop(),(n&&l||c&&u)&&h.reverse(),l?(i.calculative.worldAnchors[0].connectTo=void 0,i.calculative.worldAnchors.unshift(...h)):u&&(i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].connectTo=void 0,i.calculative.worldAnchors.push(...h)),this.delete([a]),this.render()}else this.store.activeAnchor&&(this.store.hoverAnchor.type===PointType.Line?getDistance(this.store.activeAnchor,this.store.hoverAnchor,this.store):(this.store.activeAnchor.x=this.store.hoverAnchor.x,this.store.activeAnchor.y=this.store.hoverAnchor.y),connectLine(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,globalStore.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===HoverType.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>=LockState.DisableMove||s.parentId||s.isRuleLine)return!1;if(rectInRect(s.calculative.worldRect,this.dragRect,t.ctrlKey||this.store.options.dragAllIn))return s.type===PenType.Line&&!this.store.options.dragAllIn?lineInRect(s,this.dragRect):!0});this.active(i)}if(t.button!==2&&(distance(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,setChildrenActive(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()}});B(this,"clearDock",()=>{var a,n,c,l;const t=(n=(a=this.dock)==null?void 0:a.xDock)==null?void 0:n.penId,i=(l=(c=this.dock)==null?void 0:c.yDock)==null?void 0:l.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});B(this,"onResize",()=>{this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.resize(),this.timer=void 0},100)});B(this,"onScroll",()=>{this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.clientRect=this.canvas.getBoundingClientRect(),this.timer=void 0},100)});B(this,"calibrateMouse",t=>(t.x-=this.store.data.x,t.y-=this.store.data.y,t));B(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===LockState.Disable)){if(pointInRect(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 n=this.store.lastHoverContainer.calculative.canvas.store.pens[this.store.lastHoverContainer.id+movingSuffix];this.store.lastHoverContainer&&!n&&(this.store.lastHoverContainer.calculative.containerHover=!1,this.store.emitter.emit("leave",this.store.lastHoverContainer)),this.store.lastHoverContainer=this.store.hoverContainer}}}});B(this,"lastHoverType",HoverType.None);B(this,"getHover",t=>{var r,a;if(this.dragRect||this.canvasImage.fitFlag)return;let i=HoverType.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!==HotkeyType.AddAnchor&&this.activeRect&&!s&&!this.store.data.locked){const n=getPensLock(this.store.active),c=getPensDisableRotate(this.store.active)||this.store.options.disableRotate,l=getPensDisableResize(this.store.active)||this.store.options.disableSize;if(!n&&!c){const u={x:this.activeRect.center.x,y:this.activeRect.y-30};this.activeRect.rotate&&rotatePoint(u,this.activeRect.rotate,this.activeRect.pivot||this.activeRect.center),!this.hotkeyType&&hitPoint(t,u,this.pointSize)&&(i=HoverType.Rotate,this.externalElements.style.cursor=`url("${this.store.options.rotateCursor}"), auto`)}if(!n&&!l)for(let u=0;u<8;u++){const h=u<4;if((this.hotkeyType===HotkeyType.Resize||h&&!this.hotkeyType)&&hitPoint(t,this.sizeCPs[u],this.pointSize)){let f=h?defaultCursors:rotatedCursors,g=0;Math.abs(this.activeRect.rotate%90-45)<25?(f=h?rotatedCursors:defaultCursors,g=Math.round((this.activeRect.rotate-45)/90)+(h?0:1)):g=Math.round(this.activeRect.rotate/90),i=HoverType.Resize,this.resizeIndex=u,this.externalElements.style.cursor=f[(u+g)%4];break}}}i===HoverType.None&&(i=this.inPens(t,this.store.data.pens)),!i&&!s&&pointInRect(t,this.activeRect)&&(i=HoverType.Node,this.externalElements.style.cursor="move"),this.hoverType=i,i===HoverType.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,setHover(getParent(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,setHover(getParent(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),[HoverType.LineAnchor,HoverType.NodeAnchor].includes(i)&&![HoverType.LineAnchor,HoverType.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)});B(this,"inPens",(t,i)=>{var r;let s=HoverType.None;t:for(let a=i.length-1;a>=0;--a){const n=i[a];if(n.visible==!1||n.calculative.inView==!1||n.locked===LockState.Disable||this.store.data.locked&&n.name==="sceneContainer")continue;const c=getLineR(n);if(!(!n.calculative.active&&!pointInSimpleRect(t,n.calculative.worldRect,c)&&!pointInRect(t,n.calculative.worldRect))){if(!this.store.data.locked&&this.hotkeyType!==HotkeyType.Resize&&n.calculative.worldAnchors){for(const l of n.calculative.worldAnchors)if(s=this.inAnchor(t,n,l),s){let u=deepClone(l);Object.assign(u,t),this.title.show(u,n);break t}}if(n.type){if(n.isRuleLine){let u=((r=this.store.options.ruleOptions)==null?void 0:r.height)||20;if(t.x+this.store.data.x>u&&t.y+this.store.data.y>u)break}const l=pointInLine(t,n);if(l){!this.store.data.locked&&!n.locked?this.hotkeyType===HotkeyType.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move":this.externalElements.style.cursor=n.hoverCursor||this.store.options.hoverCursor,n.calculative.disabled&&(this.externalElements.style.cursor="not-allowed"),this.store.hover=n,this.store.pointAt=l.point,this.store.pointAtIndex=l.i,this.initTemplateCanvas([this.store.hover]),s=HoverType.Line;break}}else{if(n.children){const u=[];if(n.children.forEach(h=>{this.store.pens[h]&&u.push(this.store.pens[h])}),s=this.inPens(t,u),s)break}let l=!1;if(n.name==="line"?l=pointInSimpleRect(t,n.calculative.worldRect,n.lineWidth):l=pointInRect(t,n.calculative.worldRect),l){if(n.type===PenType.Node&&n.name==="line"&&!pointInPolygon(t,n.calculative.worldAnchors))continue;if(!this.store.data.locked&&!n.locked?this.hotkeyType===HotkeyType.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move":this.externalElements.style.cursor=n.hoverCursor||this.store.options.hoverCursor,n.calculative.disabled&&(this.externalElements.style.cursor="not-allowed"),this.store.hover=n,this.initTemplateCanvas([this.store.hover]),s=HoverType.Node,this.store.pointAt=t,!t.ctrlKey){let{x:u,y:h,ex:v,ey:f,rotate:g,center:y}=this.store.hover.calculative.worldRect;if(g){const p=[{x:u,y:h},{x:v,y:h},{x:v,y:f},{x:u,y:f}];p.forEach(x=>{rotatePoint(x,g,y)});let m=p[p.length-1];for(const x of p){if(m.y>t.y!=x.y>t.y){const k=x.x+(t.y-x.y)*(m.x-x.x)/(m.y-x.y);Math.abs(k-this.store.pointAt.x)<10&&(this.store.pointAt.x=k)}m=x}}else this.store.pointAt.x-10<u?this.store.pointAt.x=u:this.store.pointAt.x+10>v&&(this.store.pointAt.x=v),this.store.pointAt.y-10<h?this.store.pointAt.y=h:this.store.pointAt.y+10>f&&(this.store.pointAt.y=f)}break}}}}return s});B(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===LockState.Disable||a===this.store.active[0])continue;let n=getLineR(a);if(n+=2*this.store.options.anchorRadius,!!pointInSimpleRect(t,a.calculative.worldRect,n)&&(this.store.hover=a,this.hotkeyType!==HotkeyType.Resize&&a.calculative.worldAnchors))for(const c of a.calculative.worldAnchors){if(c.twoWay===TwoWay.In){const l=getToAnchor(this.store.active[0]);if(this.store.activeAnchor.id!==l.id)continue}if(c.twoWay===TwoWay.Out){const l=getFromAnchor(this.store.active[0]);if(this.store.activeAnchor.id!==l.id)continue}if(!(c.twoWay===TwoWay.DisableConnected||c.twoWay===TwoWay.Disable||((i=this.store.activeAnchor)==null?void 0:i.twoWay)===TwoWay.DisableConnectTo||((s=this.store.activeAnchor)==null?void 0:s.twoWay)===TwoWay.Disable)&&(this.title.hide(),this.inAnchor(t,a,c))){let l=deepClone(c);return Object.assign(l,t),this.title.show(l,a),!0}}}});B(this,"__loadMap",new Map);B(this,"imageTimer");B(this,"templateImageTimer");B(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)return;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});B(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!==CanvasLayer.CanvasTemplate&&i.calculative.inView&&(i.canvasLayer===CanvasLayer.CanvasMain&&i.name!=="gif"&&i.image&&i.calculative.img&&(t.save(),ctxFlip(t,i),(i.rotateByRoot||i.calculative.rotate)&&ctxRotate(t,i),setGlobalAlpha(t,i),drawImage(t,i),t.restore()),renderPen(t,i));this.drawingLine&&renderPen(t,this.drawingLine),this.pencilLine&&renderPen(t,this.pencilLine),this.movingPens&&this.movingPens.forEach(i=>{this.renderPenContainChild(t,i)})});B(this,"renderPenContainChild",(t,i)=>{var s;i.calculative.inView&&renderPen(t,i),(s=i.children)==null||s.forEach(r=>{const a=this.store.pens[r];a&&this.renderPenContainChild(t,a)})});B(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,getPensLock(this.store.active)||getPensDisableRotate(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()}});B(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!==HotkeyType.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===HotkeyType.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>LockState.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===PointType.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 n=s.rotate+a;this.store.pens[s.penId].calculative.flipX&&(n*=-1),this.store.pens[s.penId].calculative.flipY&&(n*=-1),t.save(),t.translate(s.x,s.y),t.rotate(n*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!==HotkeyType.AddAnchor&&!this.movingPens&&this.activeRect&&!(this.store.active.length===1&&this.store.active[0].type)&&!getPensLock(this.store.active)&&!getPensDisableResize(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===HotkeyType.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=rgba(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()});B(this,"renderPensAnchors",()=>{for(const t of this.store.data.pens)isFinite(t.x)&&t.anchorVisible===!0&&this.renderAnchors(t)});B(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,t.calculative.worldAnchors.forEach(s=>{if(s.hidden||s.locked>LockState.DisableEdit)return;if(s===this.store.hoverAnchor){i.save();const a=t.hoverAnchorColor||this.store.options.hoverAnchorColor;i.strokeStyle=a,i.fillStyle=a}i.beginPath();let r=s.radius||t.anchorRadius||this.store.options.anchorRadius;if(t.type&&!s.radius&&!t.anchorRadius&&(r=3,t.calculative.lineWidth>3&&(r=t.calculative.lineWidth)),s.type===PointType.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 n=s.rotate+a;this.store.pens[s.penId].calculative.flipX&&(n*=-1),this.store.pens[s.penId].calculative.flipY&&(n*=-1),i.save(),i.translate(s.x,s.y),i.rotate(n*Math.PI/180),i.translate(-s.x,-s.y),i.rect(s.x-s.length*this.store.data.scale/2,s.y-r,s.length*this.store.data.scale,r*2),i.restore()}else i.arc(s.x,s.y,r,0,Math.PI*2);if(t.type&&this.store.hoverAnchor===s?(i.save(),i.strokeStyle=t.activeColor||this.store.styles.activeColor,i.fillStyle=i.strokeStyle):(s.color||s.background)&&(i.save(),i.strokeStyle=s.color,i.fillStyle=s.background),i.fill(),i.stroke(),s===this.store.hoverAnchor&&i.restore(),(t.type&&this.store.hoverAnchor===s||s.color||s.background)&&i.restore(),!t.parentId&&t.children&&t.children.length>0&&s===this.store.hoverAnchor){i.save(),i.beginPath(),i.lineWidth=3;const a=t.hoverAnchorColor||this.store.options.hoverAnchorColor;globalThis.pSBC&&(i.strokeStyle=globalThis.pSBC(.5,a)),i.arc(s.x,s.y,r+1.5,0,Math.PI*2),i.stroke(),i.restore()}}),i.restore()});B(this,"transTimeout");B(this,"pastePen",(t,i)=>{const s=t.id;if(randomId(t),t.parentId=i,t.type===PenType.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),n=this.getPenRect(this.store.clipboard.initRect,this.store.clipboard.origin,this.store.clipboard.scale),{origin:c,scale:l}=this.store.data;t.x=c.x+a.x*l,t.y=c.y+a.y*l,t.width=a.width*l,t.height=a.height*l,n.x=c.x+n.x*l,n.y=c.y+n.y*l,calcCenter(n),this.store.clipboard.pos&&(t.x-=n.center.x-this.store.clipboard.pos.x,t.y-=n.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 n=this.store.clipboard.pens.find(c=>c.id===a);n&&r.push(this.pastePen(n,t.id).id)}return t.children=r,calcInView(t,!0),t});B(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 n=this.calibrateMouse({x:t.offsetX,y:t.offsetY});let c=1/0;(r=(s=this.store.pens[this.store.hover.parentId])==null?void 0:s.children)==null||r.forEach(l=>{const u=this.store.pens[l];if(pointInRect(n,u.calculative.worldRect)){const h=Math.sqrt((n.x-u.calculative.worldRect.center.x)**2+(n.y-u.calculative.worldRect.center.y)**2);h<c&&(c=h,a=l)}}),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})});B(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 h=window.getSelection();h.selectAllChildren(this.inputDiv),h.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,c=`${(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=c,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 l=r.width;if(this.inputParent.style.width=(l<0?12:l)+"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 h=this.inputDiv.getBoundingClientRect();let v=window.innerHeight-h.top-h.height;v=v>200?200:v,this.dropdown.style.maxHeight=v+"px",this.setDropdownList(),this.externalElements.style.zIndex="9999"}this.inputDiv.contentEditable=t.readonly?"false":"true",this.inputDiv.focus();const u=window.getSelection();u.selectAllChildren(this.inputDiv),u.collapseToEnd(),this.inputDiv.scrollTop=this.inputDiv.scrollHeight,this.inputDiv.scrollLeft=this.inputDiv.scrollWidth,t.calculative.text=void 0,this.initTemplateCanvas([t]),this.render()});B(this,"setInputStyle",t=>{t.text||(t.text="");let i;for(let l=0;l<document.styleSheets.length;l++)document.styleSheets[l].title==="le5le.com"&&(i=document.styleSheets[l]);let s="overflow: scroll;",r="",a=1;const{scale:n}=this.store.data;if(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*n<12?s+=`font-size:${t.calculative.fontSize}px;`:s+=`font-size:${t.fontSize*n}px;`),s+=`color:${getTextColor(t,this.store)};`,t.fontStyle&&(s+=`font-style: ${t.fontStyle};`),t.fontWeight&&(s+=`font-weight: ${t.fontWeight};`),t.textLeft&&(s+=`margin-left:${n>1,t.textLeft*n}px;`),t.textTop&&(s+=`margin-top:${n>1,t.textTop*a}px;`),t.lineHeight&&(s+=`line-height:${n>1?t.fontSize*t.lineHeight*n:t.calculative.fontSize*t.lineHeight}px;`),t.textHeight)s+=`height:${n>1?t.textHeight*a*n:t.textHeight*a}px;`;else{let l=t.calculative.worldRect.height/n;l<0&&(l=0);let u=(t.fontSize*n<12,l*n*a);u<t.fontSize*t.lineHeight*n&&(u=t.fontSize*t.lineHeight*n,s+=`top:-${u/2}px;`),s+=`height:${u}px;`}t.letterSpacing&&(s+=`letter-spacing:${t.calculative.letterSpacing}px;`);let c=null;if(t.textWidth)c=t.calculative.textWidth,t.whiteSpace!=="pre-line"&&(c<t.fontSize?s+=`width:${t.fontSize*1.2*a}px;`:s+=`width:${n>1,c*a}px;`);else if(t.whiteSpace===void 0||t.whiteSpace==="break-all"){let l=(t.calculative.worldTextRect.width||12)/n;l<0&&(l=0),s+=`width:${t.fontSize*n<12,l*n}px;`}if(t.whiteSpace&&(t.whiteSpace==="pre-line"?s+="white-space:pre;":(s+=`white-space:${t.whiteSpace};`,t.whiteSpace==="nowrap"&&(r+="display:contents;"))),t.whiteSpace!=="nowrap"){let l=t.fontSize*1.2*t.text.length,u=(c||t.calculative.worldRect.width/n)*Math.floor(t.calculative.worldRect.height/n/(t.lineHeight*t.fontSize));l>u&&(s+="justify-content: start;")}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}}`)});B(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=[deepClone(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&&calcTextAutoWidth(t),calcTextRect(t),this.patchFlags=!0,this.pushHistory({type:EditType.Update,pens:[deepClone(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&&calcTextRect(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()});B(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 n=typeof a=="string"?a:a.text;t&&s?n.includes(s)&&this.dropdownAppendOption(n,r):this.dropdownAppendOption(n,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)}});B(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 n=[deepClone(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:EditType.Update,pens:[deepClone(s,!0)],initPens:n}),this.render(),this.store.emitter.emit("change",s),this.store.emitter.emit("valueUpdate",s)});B(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 n=this.canvasImage.activeFit;this.externalElements.style.cursor="default",a.y>r*n.y-10&&a.y<r*n.y+10&&(i="top",this.externalElements.style.cursor="row-resize"),a.y>r*(n.y+n.height)-10&&a.y<r*(n.y+n.height)+10&&(i="bottom",this.externalElements.style.cursor="row-resize"),a.x>s*n.x-10&&a.x<s*n.x&&(i="left",this.externalElements.style.cursor="col-resize"),a.x>s*(n.x+n.width)-10&&a.x<s*(n.x+n.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 CanvasTemplate(i,s),this.canvasTemplate.canvas.style.zIndex="1",this.canvasImageBottom=new CanvasImage(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 CanvasImage(i,s),this.canvasImage.canvas.style.zIndex="4",this.magnifierCanvas=new MagnifierCanvas(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 Tooltip(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(n=>n.calculative.hover===!0);setHover(a,!1)},this.popconfirm=new Popconfirm(i,s),this.dialog=new Dialog(i,s),this.title=new Title(i),this.store.options.scroll&&(this.scroll=new Scroll(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 KeydownType.Document:document.addEventListener("keydown",this.onkeydown),document.addEventListener("keyup",this.onkeyup);break;case KeydownType.Canvas:this.externalElements.addEventListener("keydown",this.onkeydown),this.externalElements.addEventListener("keyup",this.onkeyup);break}}splitLine(t,i){const s=t.calculative.worldAnchors,r=s.findIndex(h=>h===i);if([-1,0,s.length-1].includes(r))return;const a=deepClone(t,!0),n=deepClone(t,!0),c=s8();n.id=c,n.calculative.canvas=this,n.calculative.active=!1,n.calculative.hover=!1;const l=deepClone(s.slice(0,r+1)),u=deepClone(s.slice(r)).map(h=>(h.penId=c,h));t.calculative.worldAnchors=l,n.calculative.worldAnchors=u,this.initLineRect(t),this.initLineRect(n),this.store.data.pens.push(n),this.store.pens[c]=n,this.pushHistory({type:EditType.Add,pens:[deepClone(n,!0)],step:2}),this.pushHistory({type:EditType.Update,initPens:[a],pens:[deepClone(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 n=calcRelativePoint(this.movingAnchor,a),c=r.anchors.findIndex(l=>l.id===this.movingAnchor.id);r.anchors[c]=n,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 uploadFile(t,this.store.options.uploadUrl,this.store.options.uploadParams,this.store.options.uploadHeaders):s=await fileToBase64(t),new Promise((r,a)=>{const n=new Image;n.onload=()=>{globalStore.htmlElements[s]=n,r({width:n.width,height:n.height,name:i?"gif":"image",image:s})},n.onerror=c=>{a(c)},n.crossOrigin=this.store.options.crossOrigin||"anonymous",n.src=s})}async dropPens(t,i){var l,u,h,v;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 f of t)!f.parentId&&this.randomCombineId(f,t);if(Object.keys(this.randomIdObj).length!==0){const f=Object.keys(this.randomIdObj).join("|"),g=new RegExp(`(${f})`,"g");for(const y of t){if(y.type?(y.anchors[0].connectTo=this.randomIdObj[y.anchors[0].connectTo],y.anchors[y.anchors.length-1].connectTo=this.randomIdObj[y.anchors[y.anchors.length-1].connectTo]):(l=y.connectedLines)==null||l.forEach(p=>{p.lineAnchor=this.randomIdObj[p.lineAnchor],p.lineId=this.randomIdObj[p.lineId]}),(u=y.animations)!=null&&u.length){const p=JSON.stringify(y.animations).replace(g,m=>this.randomIdObj[m]);y.animations=JSON.parse(p)}if((h=y.triggers)!=null&&h.length){const p=JSON.stringify(y.triggers).replace(g,m=>this.randomIdObj[m]);y.triggers=JSON.parse(p)}if((v=y.events)!=null&&v.length){const p=JSON.stringify(y.events).replace(g,m=>this.randomIdObj[m]);y.events=JSON.parse(p)}}}for(const f of t)f.id||(f.id=s8()),!f.calculative&&(f.calculative={canvas:this}),this.store.pens[f.id]=f;let s=0,r=0,a=0;for(const f of t)f.parentId||(f.width*=this.store.data.scale,f.height*=this.store.data.scale,f.x=i.x-f.width/2+a,f.y=i.y-f.height/2+r,f.tags&&f.tags.includes("meta3d")&&(f.x=this.store.data.origin.x,f.y=this.store.data.origin.y),f.dataset&&(s%2===0?a=f.width-40*this.store.data.scale:a=0,s++,s%2===0&&(r+=f.height+10*this.store.data.scale),delete f.dataset),f.temOffsetX&&(f.x+=f.temOffsetX*this.store.data.scale,delete f.temOffsetX),f.temOffsetY&&(f.y+=f.temOffsetY*this.store.data.scale,delete f.temOffsetY));const n=this.store.data.width||this.store.options.width,c=this.store.data.height||this.store.options.height;if(n&&c){let f={x:this.store.data.origin.x,y:this.store.data.origin.y,width:n*this.store.data.scale,height:c*this.store.data.scale},g=!0;for(const y of t)if(!y.parentId){let p=[{x:y.x,y:y.y},{x:y.x+y.width,y:y.y},{x:y.x,y:y.y+y.height},{x:y.x+y.width,y:y.y+y.height},{x:y.x+y.width/2,y:y.y+y.height/2}];if(y.x===f.x&&y.y===f.y&&y.width===f.width&&y.height===f.height||p.some(m=>pointInRect(m,f))){g=!1,this.store.options.strictScope&&(y.x<f.x&&(y.x=f.x),y.y<f.y&&(y.y=f.y),y.x+y.width>f.x+f.width&&(y.x=f.x+f.width-y.width),y.y+y.height>f.y+f.height&&(y.y=f.y+f.height-y.height));break}}if(g){console.info("画笔在大屏范围外");return}}await this.addPens(t,!0),this.active(t.filter(f=>!f.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]),randomId(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 n of t.children){const c=i.find(l=>l.id===n);c&&a.push(this.randomCombineId(c,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:EditType.Add,pens:deepClone(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:PenType.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 n;this.inactive();const{data:i,options:s}=this.store,r=i.scale,a=i.lineWidth||1;return t.penId=s8(),{id:t.penId,name:"line",lineName:this.drawingLineName,x:t.x,y:t.y,type:PenType.Line,calculative:{canvas:this,active:!0,worldAnchors:[t],...s.linePresetStyle,lineWidth:s.linePresetStyle&&s.linePresetStyle.lineWidth?((n=s.linePresetStyle)==null?void 0:n.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,n=t.x+i,c=t.y+s;let l=t.x,u=t.y,h=0,v=0,f=0,g=0;if(n<=c&&n<20)l=-i,h=this.width,f=1,t.ctrlKey||(u=Math.round((u-a.y)/(r*10))*(r*10)+a.y);else if(c<n&&c<20)u=-s,v=this.height,g=1,t.ctrlKey||(l=Math.round((l-a.x)/(r*10))*(r*10)+a.x);else return;this.addPen({isRuleLine:!0,type:PenType.Line,name:"line",lineName:"line",x:l,y:u,width:h,height:v,color:this.store.options.ruleLineColor,anchors:[{x:0,y:0},{x:f,y:g}]})}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:n}=this.store.data,{x:c,y:l}=t,u={x:c,y:l},h=this.getPenRect(t),v=parseInt((h.x/r).toFixed()),f=parseInt((h.y/r).toFixed()),g=v*r,y=f*r;u.x=a.x+g*n,u.y=a.y+y*n,Object.assign(t,u),(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=deepClone(i,!0),r=this.store.data.gridSize||this.store.options.gridSize,{origin:a,scale:n}=this.store.data,c=this.store.options.autoAlignGrid&&(this.store.data.grid||this.store.options.grid);if(i.forEach(f=>{var x;const g=this.movingPens.findIndex(k=>k.id===f.id+movingSuffix);if(g<0)return;const{x:y,y:p}=this.movingPens[g],m={x:y,y:p};if(c&&!this.movingPens[g].type){const k=this.getPenRect(this.movingPens[g]),w=parseInt((k.x/r).toFixed()),C=parseInt((k.y/r).toFixed()),I=w*r,_=C*r;m.x=a.x+I*n,m.y=a.y+_*n}Object.assign(f,m),(x=f.onMove)==null||x.call(f,f),this.updatePenRect(f),this.updateLines(f),this.store.emitter.emit("updateLines",f),this.patchFlagsLines.forEach(k=>{k.type&&this.initLineRect(k)}),this.patchFlagsLines.clear(),f.calculative.x=f.x,f.calculative.y=f.y,f.calculative.initRect&&(f.calculative.initRect.x=f.calculative.x,f.calculative.initRect.y=f.calculative.y,f.calculative.initRect.ex=f.calculative.x+f.calculative.width,f.calculative.initRect.ey=f.calculative.y+f.calculative.height),calcChildrenInitRect(f),f.parentId&&this.parent.updateRectbyChild(f.calculative.worldRect,f,this.store.pens[f.parentId])}),this.initImageCanvas(this.store.active),this.initTemplateCanvas(this.store.active),!this.dock)return;const{xDock:l,yDock:u}=this.dock;let h;l&&(h=this.store.pens[l.penId]),!h&&u&&(h=this.store.pens[u.penId]);const v=deepClone(this.store.active,!0);if(t&&this.store.active.length===1&&(h==null?void 0:h.type)===1&&(l!=null&&l.anchorId||u!=null&&u.anchorId)){const f=getFromAnchor(h),g=getToAnchor(h);if(l!=null&&l.anchorId){const y=this.store.pens[this.store.active[0].id+movingSuffix].calculative.worldAnchors.find(p=>p.id===l.anchorId);y.x===f.x&&y.y===f.y?(s.push(deepClone(h,!0)),connectLine(this.store.active[0],y,h,f),v.push(deepClone(h,!0))):y.x===g.x&&y.y===g.y&&(s.push(deepClone(h,!0)),connectLine(this.store.active[0],y,h,g),v.push(deepClone(h,!0)))}else if(u!=null&&u.anchorId){const y=this.store.pens[this.store.active[0].id+movingSuffix].calculative.worldAnchors.find(p=>p.id===u.anchorId);y.x===f.x&&y.y===f.y?(s.push(deepClone(h,!0)),connectLine(this.store.active[0],y,h,f),v.push(deepClone(h,!0))):y.x===g.x&&y.y===g.y&&(s.push(deepClone(h,!0)),connectLine(this.store.active[0],y,h,g),v.push(deepClone(h,!0)))}}c&&(this.calcActiveRect(),this.getSizeCPs()),this.pushHistory({type:EditType.Update,pens:v,initPens:s}),this.store.emitter.emit("translatePens",v)}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===CanvasLayer.CanvasTemplate)&&this.canvasTemplate.init()}hasImage(t,i){var s;return t.image&&t.name!=="gif"?i?t.canvasLayer===CanvasLayer.CanvasImageBottom:t.canvasLayer===CanvasLayer.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,setChildrenActive(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,setChildrenActive(s,!1)}this.store.active=[],t.forEach(s=>{s.calculative.active=!0,setChildrenActive(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=rectToPoints(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:n,center:c}=this.activeRect;t.forEach(l=>{const u={x:l.x*r+i,y:l.y*a+s};rotatePoint(u,n,c),this.sizeCPs.push(u)})}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=HoverType.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>LockState.DisableEdit||!(i.type&&i.calculative.active)&&this.store.options.disableAnchor||i.disableAnchor)return HoverType.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 n=a.calculative.worldAnchors.find(c=>c.id===s.anchorId);n&&(s=n)}}if(s.twoWay===TwoWay.Disable&&i.name!=="line")return HoverType.None;if(i.name==="line"&&s.connectTo){let a=(r=this.findOne(s.connectTo))==null?void 0:r.anchors.find(n=>n.id===s.anchorId);if(a&&a.twoWay)return HoverType.None}if(this.drawingLine){if(s.twoWay===TwoWay.Out)return HoverType.None}else if(!(this.mouseDown&&this.hoverType===HoverType.LineAnchor)){if(s.twoWay===TwoWay.In)return HoverType.None}if(hitPoint(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",HoverType.NodeAnchor):HoverType.None):(this.hotkeyType===HotkeyType.AddAnchor?this.externalElements.style.cursor="vertical-text":this.externalElements.style.cursor="pointer",HoverType.LineAnchor):(this.hotkeyType===HotkeyType.AddAnchor?this.externalElements.style.cursor="vertical-text":this.externalElements.style.cursor="crosshair",HoverType.NodeAnchor);if(!this.mouseDown&&i.type){if(i.calculative.active&&s.prev&&hitPoint(t,s.prev,this.pointSize))return this.store.hoverAnchor=s,this.store.hover=i,this.externalElements.style.cursor="pointer",HoverType.LineAnchorPrev;if(i.calculative.active&&s.next&&hitPoint(t,s.next,this.pointSize))return this.store.hoverAnchor=s,this.store.hover=i,this.externalElements.style.cursor="pointer",HoverType.LineAnchorNext}return HoverType.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},calcRightBottom(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)),calcInView(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:EditType.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:EditType.Add,pens:[t]}),t}pushHistory(t){var r;if(this.store.data.locked)return;const{origin:i,scale:s}=this.store.data;t.origin=deepClone(i),t.scale=s,t.type!==EditType.Update&&t.pens&&t.pens.forEach(a=>{a.calculative&&(a.calculative.layer=this.store.data.pens.findIndex(n=>n.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 n;if(t.initPens)for(const c of t.initPens)c.id===a.id&&(n=c);if(n)for(const c in a)n[c]==null&&(n[c]=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==EditType.Add||t.type==EditType.Delete||t.type==EditType.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==EditType.Add||t.type==EditType.Delete||t.type==EditType.Update)&&this.activeHistory()}activeHistory(){let t=this.store.histories[this.store.historyIndex+1];const i=[];if(t&&t.type===EditType.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===EditType.Add||s.type===EditType.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 EditType.Add:t.pens.forEach(a=>{var l;const n=deepClone(a,!0),c=this.store.data.pens.findIndex(u=>u.id===n.id);c>-1&&((l=n.onDestroy)==null||l.call(n,this.store.pens[n.id]),this.store.data.pens.splice(c,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))}),t.type=EditType.Delete;break;case EditType.Update:const s=i?t.initPens:t.pens,r=i?t.pens:t.initPens;s.forEach(a=>{const n=deepClone(a,!0),c=this.store.data.pens.findIndex(l=>l.id===n.id);if(c>-1){if(n.calculative=this.store.data.pens[c].calculative,this.store.data.pens[c].type&&this.store.data.pens[c].lastConnected){for(let u in this.store.data.pens[c].lastConnected)if(this.store.pens[u]){let h=deepClone(this.store.data.pens[c].lastConnected[u]);this.store.pens[u].connectedLines=h,n.anchors.forEach(v=>{h.forEach(f=>{v.id===f.lineAnchor&&(v.connectTo=u)})})}}this.store.data.pens[c]=n,this.store.pens[n.id]=n;for(const u in n)(typeof n[u]!="object"||u==="lineDash")&&(n.calculative[u]=n[u]);n.calculative.image=void 0;const l=this.getPenRect(n,t.origin,t.scale);if(this.setPenRect(n,l,!1),this.updateLines(n,!0),n.calculative.canvas.parent.isCombine(n)){let u=r.find(h=>h.id===n.id);inheritanceProps.forEach(h=>{n[h]!==u[h]&&this.parent.setValue({id:n.id,[h]:n[h]},{render:!0,doEvent:!1})})}}});break;case EditType.Delete:t.pens.reverse().forEach(a=>{var c,l;const n=deepClone(a,!0);if(n.calculative||(n.calculative={}),this.store.data.pens.splice(((c=n.calculative)==null?void 0:c.layer)!==-1?(l=n.calculative)==null?void 0:l.layer:this.store.data.pens.length,0,n),n.path&&!this.store.data.paths[n.pathId]&&(this.store.data.paths[n.pathId]=n.path),this.store.pens[n.id]=n,n.type&&n.lastConnected)for(let u in n.lastConnected)this.store.pens[u]&&(this.store.pens[u].connectedLines=n.lastConnected[u]);n.calculative.canvas=this}),t.pens.reverse().forEach(a=>{const n=this.store.pens[a.id],c=this.getPenRect(n,t.origin,t.scale);this.setPenRect(n,c,!1),n.calculative.image=void 0,n.calculative.backgroundImage=void 0,n.calculative.strokeImage=void 0,this.loadImage(n)}),t.type=EditType.Add;break;case EditType.Replace:{const a=i?t.initPens:t.pens;(i?t.pens:t.initPens).forEach(c=>{var h;const l=deepClone(c,!0);if(this.store.data.pens.findIndex(v=>v.id===l.id)>-1){(h=l.onDestroy)==null||h.call(l,this.store.data.pens.find(f=>f.id===l.id));const v=this.store.data.pens.findIndex(f=>f.id===l.id);this.store.data.pens.splice(v,1),this.store.pens[l.id]=void 0,l.calculative||(l.calculative={}),l.calculative.canvas=this,this.store.animates.delete(l),this.store.animateMap.delete(l)}}),a.reverse().forEach(c=>{var u,h;const l=deepClone(c,!0);if(l.calculative||(l.calculative={}),this.store.data.pens.splice(((u=l.calculative)==null?void 0:u.layer)!==-1?(h=l.calculative)==null?void 0:h.layer:this.store.data.pens.length,0,l),this.store.pens[l.id]=l,l.type&&l.lastConnected)for(let v in l.lastConnected)this.store.pens[v]&&(this.store.pens[v].connectedLines=l.lastConnected[v]);l.calculative.canvas=this}),a.reverse().forEach(c=>{const l=this.store.data.pens.find(h=>h.id===c.id),u=this.getPenRect(l,t.origin,t.scale);this.setPenRect(l,u,!1),l.calculative.image=void 0,l.calculative.backgroundImage=void 0,l.calculative.strokeImage=void 0,this.loadImage(l)}),t.type=EditType.Replace;break}}if(t.type===EditType.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=s8()),Math.abs(this.store.lastScale-this.store.data.scale)<1e-4&&this.store.sameTemplate&&this.store.templatePens[t.id]&&t.canvasLayer===CanvasLayer.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=s8());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=CanvasLayer.CanvasImageBottom:t.canvasLayer=CanvasLayer.CanvasImage,delete t.isBottom),t.template&&(t.canvasLayer=CanvasLayer.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&&globalStore.anchors[t.name]&&(t.anchors||(t.anchors=[]),globalStore.anchors[t.name](t)),!t.anchors){const a=deepClone(this.store.options.defaultAnchors);a.forEach((n,c)=>{n.id=`${c}`,n.penId=t.id}),t.anchors=a}this.updatePenRect(t),!t.anchors&&t.calculative.worldAnchors&&(t.anchors=t.calculative.worldAnchors.map(a=>calcRelativePoint(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,globalStore.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=getLineRect(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),calcCenter(i),t.calculative.worldRect=i,calcPadding(t,i),calcTextRect(t),calcInView(t),t.calculative&&(t.calculative.gradientAnimatePath=void 0),this.store.path2dMap.set(t,globalStore.path2dDraws[t.name](t)),t.calculative.worldAnchors&&(t.anchors=t.calculative.worldAnchors.map(n=>calcRelativePoint(n,t.calculative.worldRect)))}drawingPencil(){lockedError(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=getFromAnchor(this.drawingLine);let s=getToAnchor(this.drawingLine);if(s.isTemp&&(this.drawingLine.calculative.worldAnchors.pop(),s=getToAnchor(this.drawingLine)),!t&&(!s.connectTo&&this.drawingLine.calculative.worldAnchors.pop(),getFromAnchor(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(n=>n.lineId!==this.drawingLine.id)),this.drawingLine=void 0,this.render();return}}else if(this.store.options.disableRepeatLine&&this.store.data.pens.find(c=>{if(c.type){const l=getFromAnchor(c),u=getToAnchor(c);return samePoint(l,i)&&samePoint(u,s)}})){this.drawingLine=void 0,this.render();return}if(this.drawingLine.lineName==="polyline"&&!s.connectTo&&this.drawingLine.calculative.worldAnchors.length>2){let n=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2];Math.abs(n.x-s.x)/this.store.data.scale<5&&Math.abs(n.y-s.y)/this.store.data.scale<5&&this.drawingLine.calculative.worldAnchors.pop()}const r=getLineRect(this.drawingLine);Object.assign(this.drawingLine,r),this.drawingLine.calculative.worldRect=r,this.drawingLine.calculative.activeAnchor=getToAnchor(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:EditType.Add,pens:deepClone([this.drawingLine],!0)})),this.store.path2dMap.set(this.drawingLine,globalStore.path2dDraws[this.drawingLine.name](this.drawingLine)),this.drawingLine=void 0,this.drawingLineName=void 0,this.render()}async finishPencil(){if(this.pencilLine){const t=simplify(this.pencilLine.calculative.worldAnchors,10,0,this.pencilLine.calculative.worldAnchors.length-1);let i=getFromAnchor(this.pencilLine);t.unshift({id:i.id,penId:i.penId,x:i.x,y:i.y}),i=getToAnchor(this.pencilLine),t.push({id:i.id,penId:i.penId,x:i.x,y:i.y}),this.pencilLine.calculative.worldAnchors=smoothLine(t),this.pencilLine.calculative.worldAnchors.length>1&&(this.pencilLine.calculative.pencil=!1,this.store.path2dMap.set(this.pencilLine,globalStore.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:EditType.Add,pens:deepClone([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 n=new DOMParser().parseFromString(s.responseText,"text/xml").getElementsByTagName("svg")[0],{width:c,height:l}=t.calculative.worldRect;n.setAttribute("width",`${c}px`),n.setAttribute("height",`${l}px`);const h="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(new XMLSerializer().serializeToString(n))));i.src=h,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,globalStore.htmlElements[t.image]=i,this.imageLoaded(),t.canvasLayer===CanvasLayer.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(globalStore.htmlElements[t.image]){const i=globalStore.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===CanvasLayer.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,globalStore.htmlElements[t.image]=i,this.imageLoaded(),t.canvasLayer===CanvasLayer.CanvasTemplate&&this.templateImageLoaded()}}t.calculative.image=t.image}if(t.backgroundImage!==t.calculative.backgroundImage){if(t.calculative.backgroundImg=void 0,t.backgroundImage)if(globalStore.htmlElements[t.backgroundImage]){const i=globalStore.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,globalStore.htmlElements[t.backgroundImage]=i,this.imageLoaded(),t.canvasLayer===CanvasLayer.CanvasTemplate&&this.templateImageLoaded()}}t.calculative.backgroundImage=t.backgroundImage}if(t.strokeImage!==t.calculative.strokeImage){if(t.calculative.strokeImg=void 0,t.strokeImage)if(globalStore.htmlElements[t.strokeImage]){const i=globalStore.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,globalStore.htmlElements[t.strokeImage]=i,this.imageLoaded(),t.canvasLayer===CanvasLayer.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(globalStore.htmlElements[t])r(globalStore.htmlElements[t]);else{const n=new Image;n.crossOrigin=this.store.options.crossOrigin||"anonymous",this.store.options.cdn&&!(t.startsWith("http")||t.startsWith("//")||t.startsWith("data:image"))?n.src=this.store.options.cdn+t:n.src=t,n.onload=()=>{globalStore.htmlElements[t]=n,this.__loadMap.delete(t),r(n)},n.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),isNumber(t.iconSize)&&(t.calculative.iconSize=t.iconSize*i),isNumber(t.iconWidth)&&(t.calculative.iconWidth=t.iconWidth*i),isNumber(t.iconHeight)&&(t.calculative.iconHeight=t.iconHeight*i),isNumber(t.iconLeft)&&(t.calculative.iconLeft=t.iconLeft<1&&t.iconLeft>-1?t.iconLeft:t.iconLeft*i),isNumber(t.iconTop)&&(t.calculative.iconTop=t.iconTop<1&&t.iconTop>-1?t.iconTop:t.iconTop*i),isNumber(t.textWidth)&&(t.calculative.textWidth=t.textWidth<1&&t.textWidth>-1?t.textWidth:t.textWidth*i),isNumber(t.textHeight)&&(t.calculative.textHeight=t.textHeight<1&&t.textHeight>-1?t.textHeight:t.textHeight*i),isNumber(t.textLeft)&&(t.calculative.textLeft=t.textLeft<1&&t.textLeft>-1?t.textLeft*t.calculative.worldRect.width:t.textLeft*i),isNumber(t.textTop)&&(t.calculative.textTop=t.textTop<1&&t.textTop>-1?t.textTop*t.calculative.worldRect.height:t.textTop*i),isNumber(t.borderWidth)&&t.type===PenType.Line&&t.borderWidth&&(t.calculative.borderWidth=t.borderWidth*i)}updatePenRect(t,{worldRectIsReady:i,playingAnimate:s}={}){i?calcPenRect(t):calcWorldRects(t),s||this.setCalculativeByScale(t),calcWorldAnchors(t),calcIconRect(this.store.pens,t),calcTextRect(t),calcInView(t),globalStore.path2dDraws[t.name]&&this.store.path2dMap.set(t,globalStore.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={};themeKeys.forEach(l=>{var u;if(this.store.options[l]!=null&&this.store.options[l]!==""&&(t[l]=this.store.options[l]),this.store.data[l]!=null&&this.store.data[l]!==""&&(i[l]=this.store.data[l]),this.store.data.theme){const h=(u=this.store.theme[this.store.data.theme])==null?void 0:u[l];h!=null&&h!==""&&(s[l]=h)}}),this.store.styles={};let r="";const a=this.store.data.width||this.store.options.width,n=this.store.data.height||this.store.options.height;!a&&!n&&(r="default");const c=le5leTheme.getThemeObj(this.store.data.theme||r);Object.assign(this.store.styles,t,i,s,c)}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=formatPadding(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)calcInView(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 c;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,(c=this.store.clipboard)!=null&&c.pos&&scalePoint(this.store.clipboard.pos,a,i),scalePoint(this.store.data.origin,a,i),this.store.data.pens.forEach(l=>{if(l.onScale&&l.onScale(l),!l.parentId){if(scalePen(l,a,i),l.isRuleLine){const u=1/a,h=l.calculative.worldRect.center;l.width&&l.height||scalePen(l,u,h)}this.updatePenRect(l,{worldRectIsReady:!0}),this.execPenResize(l)}}),this.onMovePens(),this.calcActiveRect(),this.canvasTemplate.init(),this.canvasImage.init(),this.canvasImageBottom.init();const n=this.parent.map;n&&n.isShow&&n.setView(),this.render(),this.store.emitter.emit("scale",this.store.data.scale)}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(n=>{if(!n.parentId){if(scalePen(n,a,i),n.onScale&&n.onScale(n),n.isRuleLine){const c=a>1?1:1/a/a,l=n.calculative.worldRect.center;n.width&&n.height||scalePen(n,c,l)}this.execPenResize(n)}}),this.calcActiveRect()}rotatePens(t){this.initPens||(this.initPens=deepClone(this.getAllByPens(this.store.active))),this.activeRect.rotate=calcRotate(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:EditType.Update,pens:deepClone(this.getAllByPens(this.store.active)),initPens:this.initPens}),this.initPens=void 0},200)}resizePens(t){if(this.initPens||(this.initPens=deepClone(this.store.active,!0)),!this.initActiveRect){this.initActiveRect=deepClone(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 n=deepClone(this.initActiveRect);if(resizeRect(n,r,a,this.resizeIndex),calcCenter(n),!this.store.options.disableDock){this.clearDock();const g=this.customResizeDock||calcResizeDock;this.dock=g(this.store,n,this.store.active,this.resizeIndex);const{xDock:y,yDock:p}=this.dock;if(y){r+=y.step;const m=this.store.pens[y.penId];m.calculative.isDock=!0}if(p){a+=p.step;const m=this.store.pens[p.penId];m.calculative.isDock=!0}}const c=this.activeRect.width,l=this.activeRect.height;let u=r-this.lastOffsetX,h=a-this.lastOffsetY;if(this.lastOffsetX=r,this.lastOffsetY=a,(t.ctrlKey||this.initPens.length===1&&this.initPens[0].ratio)&&(h=([1,3].includes(this.resizeIndex)?-1:1)*(u*l)/c),this.activeRect.ratio=this.initPens[0].ratio,resizeRect(this.activeRect,u,h,this.resizeIndex),this.store.options.strictScope){const g=this.store.data.width||this.store.options.width,y=this.store.data.height||this.store.options.height;if(g&&y){let p={x:this.store.data.origin.x,y:this.store.data.origin.y,width:g*this.store.data.scale,height:y*this.store.data.scale};this.activeRect.x<p.x&&(this.activeRect.width=this.activeRect.width-(p.x-this.activeRect.x),this.activeRect.x=p.x),this.activeRect.y<p.y&&(this.activeRect.height=this.activeRect.height-(p.y-this.activeRect.y),this.activeRect.y=p.y),this.activeRect.x+this.activeRect.width>p.x+p.width&&(this.activeRect.width=this.activeRect.width-(this.activeRect.x+this.activeRect.width-(p.x+p.width)),this.activeRect.x=p.x+p.width-this.activeRect.width,this.activeRect.ex=this.activeRect.x+this.activeRect.width),this.activeRect.y+this.activeRect.height>p.y+p.height&&(this.activeRect.height=this.activeRect.height-(this.activeRect.y+this.activeRect.height-(p.y+p.height)),this.activeRect.y=p.y+p.height-this.activeRect.height,this.activeRect.ey=this.activeRect.y+this.activeRect.height)}}calcCenter(this.activeRect);const v=this.activeRect.width/c,f=this.activeRect.height/l;this.store.active.forEach((g,y)=>{g.calculative.worldRect.x=this.activeInitPos[y].x*this.activeRect.width+this.activeRect.x,g.calculative.worldRect.y=this.activeInitPos[y].y*this.activeRect.height+this.activeRect.y,g.calculative.worldRect.width*=v,g.calculative.iconWidth&&(g.calculative.iconWidth*=v),g.calculative.worldRect.height*=f,g.calculative.iconHeight&&(g.calculative.iconHeight*=f),calcRightBottom(g.calculative.worldRect),calcCenter(g.calculative.worldRect),this.updatePenRect(g,{worldRectIsReady:!0}),this.execPenResize(g,!0),this.updateLines(g)}),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:EditType.Update,pens:deepClone(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0},200)}movePens(t){var c,l;if(!this.activeRect||this.store.data.locked)return;if(!this.initActiveRect){this.initActiveRect=deepClone(this.activeRect);return}if(!this.store.options.moveConnectedLine&&!this.canMoveLine&&this.store.active.length===1&&((c=this.store.active[0].anchors[0])!=null&&c.connectTo||(l=this.store.active[0].anchors[this.store.active[0].anchors.length-1])!=null&&l.connectTo)||(this.movingPens||(this.initMovingPens(),this.store.active.forEach(u=>{setHover(u,!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=deepClone(this.initActiveRect);translateRect(r,i,s);let a=!1;if(this.store.options.strictScope){const u=this.store.data.width||this.store.options.width,h=this.store.data.height||this.store.options.height;if(u&&h){let v={x:this.store.data.origin.x,y:this.store.data.origin.y,width:u*this.store.data.scale,height:h*this.store.data.scale};r.x<v.x&&(r.x=v.x,a=!0),r.y<v.y&&(r.y=v.y,a=!0),r.x+r.width>v.x+v.width&&(r.x=v.x+v.width-r.width,a=!0),r.y+r.height>v.y+v.height&&(r.y=v.y+v.height-r.height,a=!0)}}const n={x:r.x-this.activeRect.x,y:r.y-this.activeRect.y};if(!this.store.options.disableDock&&!a){this.clearDock();const u=this.customMoveDock||calcMoveDock;this.dock=u(this.store,r,this.movingPens,n);const{xDock:h,yDock:v}=this.dock;let f;h&&(n.x+=h.step,f=this.store.pens[h.penId],f.calculative.isDock=!0),v&&(n.y+=v.step,f=this.store.pens[v.penId],f.calculative.isDock=!0)}this.translatePens(this.movingPens,n.x,n.y,!0)}changeIdsByMoving(t,i){t.id+=movingSuffix,t.parentId&&i.find(s=>s.id===t.parentId)&&(t.parentId+=movingSuffix),t.children&&(t.children=t.children.map(s=>s+movingSuffix)),t.connectedLines&&(t.connectedLines=t.connectedLines.map(s=>(i.find(r=>r.id===s.lineId)&&(s.lineId+=movingSuffix),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+=movingSuffix),s)))}initMovingPens(){var s,r;if(!this.store.options.moveConnectedLine&&!this.canMoveLine)for(let a=0;a<this.store.active.length;a++){const n=this.store.active[a];((s=n.anchors[0])!=null&&s.connectTo||(r=n.anchors[n.anchors.length-1])!=null&&r.connectTo)&&(this.store.active.splice(a,1),n.calculative.active=void 0,--a)}this.movingPens=deepClone(this.store.active,!0),this.movingPens=this.getAllFollowersByPens(this.movingPens);const t=this.getAllByPens(this.movingPens),i=deepClone(t,!0);t.forEach(a=>{this.changeIdsByMoving(a,i),this.store.pens[a.id]=a,a.calculative.canvas=this;const n={globalAlpha:.5};a.lineWidth===0&&(n.lineWidth=1),(a.name.endsWith("Dom")||isDomShapes.includes(a.name)||this.store.options.domShapes.includes(a.name)||a.image||a.isDom)&&(n.name="rectangle",n.onDestroy=void 0),this.updateValue(a,n),a.calculative.image=void 0})}moveLineAnchor(t,i){var c,l,u,h,v;if(!this.activeRect||this.store.data.locked)return;if(this.initPens||(this.initPens=deepClone(this.store.active,!0)),(c=this.store.activeAnchor)!=null&&c.connectTo){const f=this.store.pens[this.store.activeAnchor.connectTo];disconnectLine(f,getAnchor(f,this.store.activeAnchor.anchorId),this.store.pens[this.store.activeAnchor.penId],this.store.activeAnchor)}let s=(l=this.store.activeAnchor)==null?void 0:l.id,r=(h=(u=this.store.pens[this.store.activeAnchor.penId])==null?void 0:u.connectedLines)==null?void 0:h.filter(f=>f.anchor===s);r&&r.length>0&&r.forEach(f=>{const g=this.store.pens[f.lineId];disconnectLine(this.store.pens[this.store.activeAnchor.penId],this.store.activeAnchor,g,getAnchor(g,f.lineAnchor))});const a=this.store.active[0];getFromAnchor(a);const n=getToAnchor(a);if(a.lineName==="polyline"&&!i.shiftKey)translatePolylineAnchor(a,this.store.activeAnchor,t);else{let f=0,g=0;if(a.lineName==="line"){let y=a.calculative.worldAnchors.findIndex(m=>m.id===this.store.activeAnchor.id);y===0&&(y=2);let p=a.calculative.worldAnchors[y-1];if(i.ctrlKey&&i.shiftKey){let m=deepClone(t);this.getSpecialAngle(m,p),f=m.x-this.store.activeAnchor.x,g=m.y-this.store.activeAnchor.y}else if(!i.ctrlKey&&i.shiftKey){let m={x:t.x,y:p.y};f=m.x-this.store.activeAnchor.x,g=m.y-this.store.activeAnchor.y}else if(i.ctrlKey&&!i.shiftKey){let m={x:p.x,y:t.y};f=m.x-this.store.activeAnchor.x,g=m.y-this.store.activeAnchor.y}else f=t.x-this.store.activeAnchor.x,g=t.y-this.store.activeAnchor.y}else!i.ctrlKey&&i.shiftKey?(f=t.x-this.store.activeAnchor.x,g=0):i.ctrlKey&&!i.shiftKey?(f=0,g=t.y-this.store.activeAnchor.y):(f=t.x-this.store.activeAnchor.x,g=t.y-this.store.activeAnchor.y);translatePoint(this.store.activeAnchor,f,g),this.store.hover&&this.store.hoverAnchor&&this.store.hoverAnchor.penId!==this.store.activeAnchor.penId&&(this.store.hoverAnchor.type===PointType.Line?(f=t.x-this.store.activeAnchor.x,g=t.y-this.store.activeAnchor.y,getDistance(this.store.activeAnchor,this.store.hoverAnchor,this.store)):(f=this.store.hoverAnchor.x-this.store.activeAnchor.x,g=this.store.hoverAnchor.y-this.store.activeAnchor.y),translatePoint(this.store.activeAnchor,f,g),n.prev=void 0,a.lineName!=="polyline"&&((v=this[a.lineName])==null||v.call(this,this.store,a)))}this.patchFlagsLines.add(a),this.store.path2dMap.set(a,globalStore.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:EditType.Update,pens:deepClone(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=deepClone(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,rotatePoint(this.store.activeAnchor.next,180,this.store.activeAnchor);else if(this.store.activeAnchor.prevNextType===PrevNextType.Bilateral&&this.prevAnchor){const s=calcRotate(t,this.store.activeAnchor),r=calcRotate(this.prevAnchor,this.store.activeAnchor);this.store.activeAnchor.next.x=this.nextAnchor.x,this.store.activeAnchor.next.y=this.nextAnchor.y,rotatePoint(this.store.activeAnchor.next,s-r,this.store.activeAnchor)}}const i=this.store.active[0];this.patchFlagsLines.add(i),this.store.path2dMap.set(i,globalStore.path2dDraws[i.name](i)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.pushHistory({type:EditType.Update,pens:deepClone(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=deepClone(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,rotatePoint(this.store.activeAnchor.prev,180,this.store.activeAnchor);else if(this.store.activeAnchor.prevNextType===PrevNextType.Bilateral&&this.nextAnchor){const s=calcRotate(t,this.store.activeAnchor),r=calcRotate(this.nextAnchor,this.store.activeAnchor);this.store.activeAnchor.prev.x=this.prevAnchor.x,this.store.activeAnchor.prev.y=this.prevAnchor.y,rotatePoint(this.store.activeAnchor.prev,s-r,this.store.activeAnchor)}}const i=this.store.active[0];this.patchFlagsLines.add(i),this.store.path2dMap.set(i,globalStore.path2dDraws[i.name](i)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.pushHistory({type:EditType.Update,pens:deepClone(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0},200)}async setAnchor(t){var r;const i=[deepClone(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===PenType.Line&&((r=s.calculative.worldAnchors)==null?void 0:r.length)<=2?this.delete([s]):(removePenAnchor(s,this.store.hoverAnchor),s.type===PenType.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===PenType.Line){this.store.activeAnchor=addLineAnchor(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:s8(),x:t.x,y:t.y};this.store.activeAnchor=pushPenAnchor(s,a)}}this.hotkeyType=HotkeyType.None,this.render(),s&&this.pushHistory({type:EditType.Update,pens:[deepClone(s,!0)],initPens:i})}checkDisconnect(t,i){if(t.id.indexOf(movingSuffix)>0){const s=t.id;t=this.store.pens[s.replace(movingSuffix,"")]}t.anchors.forEach(s=>{if(s.connectTo&&!i.find(r=>r.id===s.connectTo||r.id===s.connectTo+movingSuffix)){const r=this.store.pens[s.connectTo];if(!r||r.type)return;disconnectLine(r,getAnchor(r,s.anchorId),t,s)}})}translatePens(t=this.store.active,i,s,r){if(!t||!t.length||t.some(l=>{if(l.locked>=LockState.DisableMove)return!0}))return;const n=!r&&deepClone(t,!0);this.activeRect&&translateRect(this.activeRect,i,s);const c=this.getAllByPens(t);t.forEach(l=>{var u,h;if(!(l.locked>=LockState.DisableMove)){if(l.type===PenType.Line){if(!this.store.options.moveConnectedLine&&!this.canMoveLine||l.isRuleLine)return;translateLine(l,i,s),this.checkDisconnect(l,c),this.store.path2dMap.set(l,globalStore.path2dDraws[l.name](l)),r||(this.initLineRect(l),(u=l.connectedLines)==null||u.forEach(v=>{const f=this.store.pens[v.lineId];this.initLineRect(f)}))}else translateRect(l.calculative.worldRect,i,s),this.updatePenRect(l,{worldRectIsReady:!0}),l.calculative.x=l.x,l.calculative.y=l.y,l.calculative.initRect&&(l.calculative.initRect.x=l.calculative.x,l.calculative.initRect.y=l.calculative.y,l.calculative.initRect.ex=l.calculative.x+l.calculative.width,l.calculative.initRect.ey=l.calculative.y+l.calculative.height);this.updateLines(l),(h=l.onMove)==null||h.call(l,l)}}),this.activeRect&&this.getSizeCPs(),this.render(),this.tooltip.translate(i,s),r||(this.pushHistory({type:EditType.Update,pens:deepClone(t,!0),initPens:n}),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 n;if(a.type===PenType.Line){if(!this.store.options.moveConnectedLine&&!this.canMoveLine)return;translateLine(a,i,s),this.checkDisconnect(a,r),this.store.path2dMap.set(a,globalStore.path2dDraws[a.name](a))}else translateRect(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);(n=a.onMove)==null||n.call(a,a)})}calcAutoAnchor(t,i,s,r){const a=getFromAnchor(t),n=getToAnchor(t),c=nearestAnchor(s,i===a?n:a);c&&(i.x=c.x,i.y=c.y,i.prev=void 0,i.next=void 0,r?r.anchor=c.id:connectLine(s,c,t,i),this[t.lineName]&&this[t.lineName](this.store,t),this.store.path2dMap.set(t,globalStore.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 n in t)n!=="x"&&n!=="y"&&n!=="width"&&n!=="height"&&n!=="initRect"&&n!=="rotate"&&(typeof t[n]!="object"||n==="lineDash")&&(t.calculative[n]=t[n]);(i=t.children)!=null&&i.length?r&&rotatePen(t,r,t.calculative.worldRect):t.calculative.rotate=t.rotate;const a=deepClone(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,calcTextLines(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 n=this.store.pens[r.lineId];if(!n||n.calculative.active)return;const c=getAnchor(n,r.lineAnchor);if(!c)return;if(!c.connectTo){t.connectedLines.splice(a,1);return}if(n.autoFrom){const f=getFromAnchor(n);f.id===c.id&&this.calcAutoAnchor(n,f,t,r)}if(n.autoTo){const f=getToAnchor(n);f.id===c.id&&this.calcAutoAnchor(n,f,t,r)}const l=getAnchor(t,r.anchor);if(!l)return;let u=t.rotate;t.flipX&&(u*=-1),t.flipY&&(u*=-1);let h=c.distance*this.store.data.scale*Math.cos((u+l.rotate)/180*Math.PI)||0,v=c.distance*this.store.data.scale*Math.sin((u+l.rotate)/180*Math.PI)||0;if(t.flipX&&(h=-h),t.flipY&&(v=-v),translatePoint(c,l.x-c.x+h,l.y-c.y+v),this.store.options.autoPolyline&&!this.autoPolylineFlag&&n.autoPolyline!==!1&&n.lineName==="polyline"){let f=getFromAnchor(n),g=getToAnchor(n),y=!1;f.id===c.id?(f=c,y=!0):g.id===c.id&&(g=c,y=!0),y&&(n.calculative.worldAnchors=[f,g],n.calculative.activeAnchor=f,this.polyline(this.store,n,g),this.initLineRect(n))}this.store.path2dMap.set(n,globalStore.path2dDraws[n.name](n)),this.patchFlagsLines.add(n),n.calculative.gradientSmooth&&(n.calculative.gradientAnimatePath=getGradientAnimatePath(n)),i&&getLineLength(n)})}calcActiveRect(){const t=this.store.active.filter(i=>(!i.locked||i.locked<LockState.DisableMove)&&i.visible!=!1);if(t.length)t.length===1?(this.activeRect=deepClone(t[0].calculative.worldRect),this.activeRect.rotate=t[0].calculative.rotate||0,calcCenter(this.activeRect)):(this.activeRect=getRect$1(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=>{rotatePoint(r,i,s.center)}),this.initLineRect(t),calcPenRect(t)):(t.calculative.rotate?t.calculative.rotate+=i:t.calculative.rotate=i,rotatePoint(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,n,c,l;if(s.calculative.pause){const u=Date.now()-s.calculative.pause;s.calculative.pause=void 0,s.calculative.frameStart+=u,s.calculative.frameEnd+=u}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||(n=s.frames)!=null&&n.length||s.animations&&s.animations.length){if(s.type){if((l=s.animations)!=null&&l.length){const u=deepClone(s.animations[0]);delete u.name,u.currentAnimation=0,this.parent.setValue({id:s.id,...u},{doEvent:!1,history:!1})}}else{if(!s.frames&&s.animations&&s.animations.length){let u=(c=s.animations)==null?void 0:c.findIndex(f=>f.autoPlay),h=u===-1?0:u;const v=deepClone(s.animations[h]);delete v.name,v.currentAnimation=h,!s.type&&v.frames&&(v.showDuration=this.parent.calcAnimateDuration(v)),this.parent.setValue({id:s.id,...v},{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)setNodeAnimate(r,t)?r.calculative.patchFlags&&(calcCenter(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(!setLineAnimate(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]);calcPenRect(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=s8(),{origin:r,scale:a}=this.store.data;this.store.clipboard=void 0,localStorage.removeItem(this.clipboardName),sessionStorage.setItem("page",s);let n=deepClone(t,!0);n||(n=deepClone(this.store.active,!0),n.length===1&&n[0].parentId&&(n[0].parentId=void 0,n[0].x=n[0].calculative.worldRect.x,n[0].y=n[0].calculative.worldRect.y,n[0].width=n[0].calculative.worldRect.width,n[0].height=n[0].calculative.worldRect.height));let c=this.getAllByPens(n);c.forEach(u=>{var h;u.copyIndex=this.store.data.pens.findIndex(v=>v.id===u.id),(h=u.followers)!=null&&h.length&&(u.followers=void 0),u.pathId&&(u.path=this.store.data.paths[u.pathId])}),c.sort((u,h)=>u.copyIndex-h.copyIndex);const l={meta2d:!0,pens:c,origin:deepClone(r),scale:a,page:s,initRect:deepClone(this.activeRect),offset:10,mousePos:deepClone(this.mousePos)};if(navigator.clipboard&&!this.store.options.disableClipboard&&!navigator.userAgent.includes("Firefox"))try{await navigator.clipboard.writeText(JSON.stringify(l))}catch{localStorage.setItem(this.clipboardName,JSON.stringify(l))}else localStorage.setItem(this.clipboardName,JSON.stringify(l));i&&this.store.emitter.emit("copy",l.pens)}cut(t){this.copy(t,!1),this.delete(t),this.store.emitter.emit("cut",t)}async paste(){var l,u;let t,i;if(navigator.clipboard&&!this.store.options.disableClipboard&&!navigator.userAgent.includes("Firefox"))try{t=await((l=navigator.clipboard)==null?void 0:l.readText())}catch{t=localStorage.getItem(this.clipboardName)}else t=localStorage.getItem(this.clipboardName);if(t){try{i=JSON.parse(t)}catch(h){console.warn("剪切板数据不是json",h.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=deepClone(i);const a=sessionStorage.getItem("page"),n=this.store.data.scale;if(this.store.clipboard.mousePos&&(Math.abs(this.store.clipboard.mousePos.x-this.mousePos.x)>100*n||Math.abs(this.store.clipboard.mousePos.y-this.mousePos.y)>100*n)){let h=-this.store.clipboard.initRect.width/this.store.clipboard.scale/10/n,v=-this.store.clipboard.initRect.height/this.store.clipboard.scale/10/n,f=(n-this.store.clipboard.scale)*this.store.clipboard.initRect.width/2+h,g=(n-this.store.clipboard.scale)*this.store.clipboard.initRect.height/2+v;n<this.store.clipboard.scale&&(f=(n-this.store.clipboard.scale)/((this.store.clipboard.scale-n)*100)*this.store.clipboard.initRect.width/2+h,g=(n-this.store.clipboard.scale)/((this.store.clipboard.scale-n)*100)*this.store.clipboard.initRect.height/2+v),this.store.clipboard.pens.length>1&&(f=(n-1)*this.store.clipboard.initRect.width/this.store.clipboard.scale/2,g=(n-1)*this.store.clipboard.initRect.height/this.store.clipboard.scale/2),this.store.clipboard.pos={x:this.mousePos.x-f,y:this.mousePos.y-g},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 c=this.store.clipboard.pens.filter(h=>!h.parentId);for(const h of c)this.pastePen(h,void 0);(u=this.keyOptions)!=null&&u.F||this.store.clipboard.pens.forEach(h=>{delete h.copyIndex}),sessionStorage.setItem("page",i.page),this.active(c),this.pushHistory({type:EditType.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(...deepClone(getAllChildren(s,this.store),!0));return i.concat(t)}getAllFollowersByPens(t,i=!0){const s=t;for(const r of t){let a=getAllFollowers(r,this.store);i&&(a=deepClone(a,!0));for(const n of a)s.find(c=>c.id===n.id)||s.push(n)}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],n=s.find(c=>c.id===a);if(n){const c=n.anchors[0],l=n.anchors[n.anchors.length-1];c.connectTo===t&&(c.connectTo=i.id),l.connectTo===t&&(l.connectTo=i.id)}else i.connectedLines.splice(r,1),r--}}changeNodeConnectedLine(t,i,s){var c;const r=i.anchors[0],a=i.anchors[i.anchors.length-1],n=[r,a];for(const l of n){const u=l.connectTo;if(u){const h=s.find(v=>v.id===u);h?(c=h.connectedLines)==null||c.forEach(v=>{v.lineId===t&&(v.lineId=i.id,v.lineAnchor=l.id)}):(l.connectTo=void 0,l.prev&&(l.prev.connectTo=void 0),l.next&&(l.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:EditType.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:EditType.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 n=getParent(r),c=n.children.indexOf(r.id);n.children.splice(c,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=getParent(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],n=this.store.pens[r];if(n){let c=n.anchors.find(l=>l.id===a);(c==null?void 0:c.connectTo)===t.id&&(c.connectTo=void 0,c.anchorId=void 0,c.prev&&(c.prev.connectTo=void 0),c.next&&(c.next.connectTo=void 0)),c=getAnchor(n,a),c&&(c.connectTo=void 0,c.anchorId=void 0,c.prev&&(c.prev.connectTo=void 0),c.next&&(c.next.connectTo=void 0))}}t.type&&((i=t.calculative.worldAnchors)==null||i.forEach((s,r)=>{var n;if(!s.connectTo)return;const a=this.store.pens[s.connectTo];a&&((n=a.calculative.worldAnchors)==null||n.forEach(c=>{disconnectLine(a,c,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(){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 i=0;i<document.styleSheets.length;i++)document.styleSheets[i].title==="le5le.com"&&(t=document.styleSheets[i]);if(!t){const i=document.createElement("style");i.title="le5le.com",document.head.appendChild(i),t=i.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;}"),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=i=>{if(navigator.userAgent.includes("Firefox")){if(!i.target.innerText){let s=this.inputDiv.offsetWidth/2;window.getComputedStyle(this.inputDiv,null).textAlign!=="center"&&(s=0),this.inputDiv.innerHTML=`<br style="margin-left:${s}px;margin-top:4px;" />`}}else if(i.target.innerText)this.inputDiv.style.paddingTop="";else{let s=window.getComputedStyle(this.inputDiv,null);s.justifyContent==="center"&&(this.inputDiv.style.paddingTop=` ${this.inputDiv.offsetHeight/2-parseFloat(s.lineHeight)/2}px`)}},this.inputDiv.oninput=i=>{const s=this.store.pens[this.inputDiv.dataset.penId];if(s&&s.inputType==="number"){const r=i.target.innerText,a=toNumber(r);r!==a&&(i.preventDefault(),i.target.innerText=a)}if(navigator.userAgent.includes("Firefox")){if(!i.target.innerText.trim()){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(i.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.store.emitter.emit("input",s)},this.inputDiv.onclick=i=>{i.stopPropagation();const s=this.store.pens[this.inputDiv.dataset.penId];this.dropdown.style.display==="block"?this.dropdown.style.display="none":s!=null&&s.dropdownList&&this.store.data.locked&&(this.dropdown.style.display="block"),this.store.emitter.emit("clickInput",s)},this.inputDiv.onkeyup=i=>{this.setDropdownList(!0);const s=this.store.pens[this.inputDiv.dataset.penId];this.store.emitter.emit("input",{pen:s,text:i.key}),i.stopPropagation()},this.inputDiv.onkeydown=i=>{if(i.key==="Enter"){const s=this.store.pens[this.inputDiv.dataset.penId];s.input&&s.whiteSpace==="nowrap"&&this.hideInput()}i.stopPropagation()},this.inputDiv.onmousedown=this.stopPropagation,this.inputDiv.onwheel=i=>{i.stopPropagation()},this.inputDiv.onpaste=i=>{i.preventDefault();let s="";i.clipboardData&&i.clipboardData.getData&&(s=i.clipboardData.getData("text/plain")),document.execCommand("insertHTML",!1,s)}}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,n,c,l,u,h;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 v=this.store.pens[s.parentId],f=(a=v.children)==null?void 0:a.findIndex(g=>g===t);f!==-1&&((n=v.children)==null||n.splice(f,1,i))}(c=s.children)==null||c.forEach(v=>{const f=this.store.pens[v];f.parentId=i}),s.formId&&s.followers.forEach(v=>{const f=this.store.pens[v];f.formId=i}),s.type===PenType.Line?this.changeNodeConnectedLine(t,s,this.store.data.pens):(this.changeLineAnchors(t,s,this.store.data.pens),(l=s.connectedLines)==null||l.forEach(({lineId:v})=>{const f=this.store.pens[v];calcWorldAnchors(f)})),(u=s.anchors)==null||u.forEach(v=>v.penId=i),(h=s.calculative.worldAnchors)==null||h.forEach(v=>v.penId=i)}}updateValue(t,i){var y,p;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 n=!1,c=!1,l=!1,u=!1,h=!1,v=!1,f,g=!1;for(const m in i)m.indexOf(".")===-1?(m==="rotate"?t.disableRotate?t.rotate=t.calculative.rotate||0:f=t.calculative.rotate||0:m==="canvasLayer"||m==="isBottom"||m==="showChild"?v=!0:m==="image"&&(g=!0),(typeof t[m]!="object"||m==="lineDash")&&(!t.disableRotate||m!=="rotate")&&(t.calculative[m]=i[m]),needCalcTextRectProps.includes(m)&&(c=!0),["name","borderRadius","lineSmooth","close"].includes(m)&&(n=!0),needSetPenProps.includes(m)&&(h=!0),needPatchFlagsPenRectProps.includes(m)&&(l=!0),needCalcIconRectProps.includes(m)&&(u=!0),t.image&&t.name!=="gif"&&needImgCanvasPatchFlagsProps.includes(m)&&(g=!0)):(delete t[m],setter(t,m,i[m])),m.split(".")[0]==="anchors"&&calcWorldAnchors(t);if(this.setCalculativeByScale(t),a&&((y=t.onDestroy)==null||y.call(t,t),clearLifeCycle(t)),h){const m={x:i.x??s.x,y:i.y??s.y,width:i.width??s.width,height:i.height??s.height};this.setPenRect(t,m,!1),this.updateLines(t,!0),this.store.active&&this.store.active.length&&t.id===this.store.active[0].id&&this.calcActiveRect()}else l?this.updatePenRect(t):(!t.hiddenText&&c&&calcTextRect(t),u&&calcIconRect(this.store.pens,t),n&&globalStore.path2dDraws[t.name]&&this.store.path2dMap.set(t,globalStore.path2dDraws[t.name](t)));if(f!==void 0){const m=t.calculative.rotate;t.calculative.rotate=f,this.rotatePen(t,m-f,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),v?(this.canvasImage.init(),this.canvasImageBottom.init()):g&&(t.canvasLayer===void 0&&(t.canvasLayer=CanvasLayer.CanvasImageBottom,t.calculative.canvasLayer=CanvasLayer.CanvasImageBottom),t.canvasLayer===CanvasLayer.CanvasImageBottom?this.canvasImageBottom.init():t.canvasLayer===CanvasLayer.CanvasImage&&this.canvasImage.init()),(i.canvasLayer!==void 0||t.canvasLayer===CanvasLayer.CanvasTemplate)&&this.initTemplateCanvas([t]),i.zIndex!==void 0&&(p=t.calculative.singleton)!=null&&p.div&&setElemPosition(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 n=this.store.pens[a];n&&this.execPenResize(n,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){const a=getRect$1(this.store.data.pens),n=this.store.data.scale;if(!isFinite(a.width))throw new Error("can not to png, because width is not finite");const c=deepClone(a),l=this.store.data,u=s&&this.store.bkImg;let h=!1,v=!1;if(u){if(a.x+=l.x,a.y+=l.y,calcRightBottom(a),rectInRect(a,this.canvasRect,!0))Object.assign(a,this.canvasRect);else{const I=getRectOfPoints([...rectToPoints(a),...rectToPoints(this.canvasRect)]);Object.assign(a,I)}h=a.x===0,v=a.y===0}const f=this.store.data.width||this.store.options.width,g=this.store.data.height||this.store.options.height;let y=!1;f&&g&&!this.store.data.component&&(y=!0),y&&(a.x=this.store.data.origin.x,a.y=this.store.data.origin.y,a.width=f*this.store.data.scale,a.height=g*this.store.data.scale);const p=deepClone(a),m=formatPadding(t);a.x-=m[3]*n,a.y-=m[0]*n,a.width+=(m[3]+m[1])*n,a.height+=(m[0]+m[2])*n;const x=(r||1920)/a.width;a.width*=x,a.height*=x,calcRightBottom(a);const k=document.createElement("canvas");if(k.width=a.width,k.height=a.height,k.width>32767||k.height>32767||!navigator.userAgent.includes("Firefox")&&k.height*k.width>268435456||navigator.userAgent.includes("Firefox")&&k.height*k.width>472907776)throw new Error("can not to png, because the size exceeds the browser limit");const w=k.getContext("2d");w.textBaseline="middle",w.scale(x,x);const C=this.store.options.downloadBgTransparent?void 0:this.store.data.background||this.store.styles.background;if(C&&y&&(w.save(),w.fillStyle=C,w.fillRect(0,0,p.width+(m[1]+m[3])*n,p.height+(m[0]+m[2])*n),w.restore()),u)if(y)w.drawImage(this.store.bkImg,m[3]*n||0,m[0]*n||0,p.width,p.height);else{const I=a.x<0?-a.x:0,_=a.y<0?-a.y:0;w.drawImage(this.store.bkImg,I,_,this.canvasRect.width,this.canvasRect.height)}if(C&&!y)if(u){const I=a.x<0?-a.x:0,_=a.y<0?-a.y:0;w.save(),w.fillStyle=C,w.fillRect(I,_,this.canvasRect.width,this.canvasRect.height),w.restore()}else w.save(),w.fillStyle=C,w.fillRect(0,0,c.width+(m[3]+m[1])*n,c.height+(m[0]+m[2])*n),w.restore();u?y?w.translate(-a.x,-a.y):w.translate((h?l.x:-c.x)+m[3]*n||0,(v?l.y:-c.y)+m[0]*n||0):w.translate(-a.x,-a.y);for(const I of this.store.data.pens){if(!isShowChild(I,this.store)||I.visible==!1)continue;const{active:_}=I.calculative;I.calculative.active=!1,I.calculative.img?renderPenRaw$1(w,I):renderPen(w,I,!0),I.calculative.active=_}if(i){k.toBlob(i);return}return k.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(g=>g.id);const n=getRect$1(r);if(!isFinite(n.width))throw new Error("can not to png, because width is not finite");const c=deepClone(n),l=formatPadding(i);n.x-=l[3],n.y-=l[0],n.width+=l[3]+l[1],n.height+=l[0]+l[2],calcRightBottom(n);const u=(s||n.width)/n.width;n.width*=u,n.height*=u;const h=document.createElement("canvas");if(h.width=n.width,h.height=n.height,h.width>32767||h.height>32767||!navigator.userAgent.includes("Firefox")&&h.height*h.width>268435456||navigator.userAgent.includes("Firefox")&&h.height*h.width>472907776)throw new Error("can not to png, because the size exceeds the browser limit");const v=h.getContext("2d");v.textBaseline="middle",v.scale(u,u);const f=this.store.options.downloadBgTransparent?void 0:this.store.data.background||this.store.styles.background;f&&(v.save(),v.fillStyle=f,v.fillRect(0,0,c.width+(l[3]+l[1]),c.height+(l[0]+l[2])),v.restore()),v.translate(-c.x+l[3],-c.y+l[0]);for(const g of this.store.data.pens)if(a.includes(g.id)){if(!isShowChild(g,this.store)||g.visible==!1)continue;const{active:y}=g.calculative;g.calculative.active=!1,g.calculative.img?renderPenRaw$1(v,g):renderPen(v,g),g.calculative.active=y}return h.toDataURL()}toggleAnchorMode(){var t;if(this.hotkeyType)this.hotkeyType===HotkeyType.AddAnchor&&(this.hotkeyType=HotkeyType.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=HotkeyType.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=[deepClone(this.store.active[0],!0)];this.store.activeAnchor.prev?this.store.activeAnchor.next||(this.store.activeAnchor.next={...this.store.activeAnchor.prev},rotatePoint(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},rotatePoint(this.store.activeAnchor.prev,180,this.store.activeAnchor),this.initLineRect(this.store.active[0]),this.patchFlags=!0),this.pushHistory({type:EditType.Update,pens:[deepClone(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=[deepClone(this.store.active[0],!0)];this.hoverType===HoverType.LineAnchorPrev?(this.store.activeAnchor.prev=void 0,this.initLineRect(this.store.active[0]),this.patchFlags=!0):this.hoverType===HoverType.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:EditType.Update,pens:[deepClone(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=PrevNextType.Mirror),this.store.activeAnchor.prevNextType=(this.store.activeAnchor.prevNextType+1)%3)}gotoView(t,i){let s=getRect$1(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(u=>{if(u.parentId||u.isRuleLine)return!1;if(rectInRect(u.calculative.worldRect,this.dragRect,!0))return u.type===PenType.Line&&!this.store.options.dragAllIn?lineInRect(u,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 n=(Math.floor(i.x)-this.store.data.origin.x)/s/r,c=(Math.floor(i.y)-this.store.data.origin.y)/s/a,l={x:n,y:c,width:(Math.ceil(i.width)+1)/s/r,height:(Math.ceil(i.height)+1)/s/a,children:t.map(u=>u.id),id:s8(),active:!0};l.x<-.1&&(l.x=-.1),l.y<-.1&&(l.y=-.1),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)),l.leftValue<.05&&(l.leftValue=0),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):(l.bottom=!0,l.bottomValue=1-(l.y+l.height)),l.topValue<.05&&(l.topValue=0),l.bottomValue<.05&&(l.bottomValue=0),this.store.data.fits||(this.store.data.fits=[]),this.store.data.fits.forEach(u=>{u.active=!1}),this.store.data.fits.push(l),this.canvasImage.activeFit=l,this.store.emitter.emit("fit",l),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,n=(t.y-this.store.data.origin.y)/i/r;if(this.canvasImage.currentFit){const c=this.canvasImage.activeFit;if(this.canvasImage.currentFit==="top"){n<-.1&&(n=-.1);let h=n-c.y;if(c.height-=h,c.height<.01){c.height=.01;return}c.y=n}if(this.canvasImage.currentFit==="bottom"&&(n>1.1&&(n=1.1),c.height=n-c.y,c.height<=.01&&(c.height=.01)),this.canvasImage.currentFit==="left"){a<-.1&&(a=-.1);let h=a-c.x;if(c.width-=h,c.width<.01){c.width=.01;return}c.x=a}this.canvasImage.currentFit==="right"&&(a>1.1&&(a=1.1),c.width=a-c.x,c.width<=.01&&(c.width=.01));let l={x:c.x*s*i+this.store.data.origin.x,y:c.y*r*i+this.store.data.origin.y,width:c.width*s*i,height:c.height*r*i};calcRightBottom(l);const u=this.store.data.pens.filter(h=>{if(h.parentId||h.isRuleLine)return!1;if(rectInRect(h.calculative.worldRect,l,!0))return h.type===PenType.Line&&!this.store.options.dragAllIn?lineInRect(h,l):!0});c.left=void 0,c.leftValue=void 0,c.right=void 0,c.rightValue=void 0,c.top=void 0,c.topValue=void 0,c.bottom=void 0,c.bottomValue=void 0,c.width>.5?(c.left=!0,c.right=!0,c.leftValue=c.x,c.rightValue=1-(c.x+c.width)):c.x<.5?(c.left=!0,c.leftValue=c.x,c.x>.2&&c.x+c.width>.5&&(c.right=!0,c.rightValue=1-(c.x+c.width))):(c.right=!0,c.rightValue=1-(c.x+c.width)),Math.abs(c.leftValue)<.05&&(c.leftValue=0),Math.abs(c.rightValue)<.05&&(c.rightValue=0),c.height>.5?(c.top=!0,c.bottom=!0,c.topValue=c.y,c.bottomValue=1-(c.y+c.height)):c.y<.5?(c.top=!0,c.topValue=c.y-0):(c.bottom=!0,c.bottomValue=1-(c.y+c.height)),Math.abs(c.topValue)<.05&&(c.topValue=0),Math.abs(c.bottomValue)<.05&&(c.bottomValue=0),c.children=u.map(h=>h.id),this.store.emitter.emit("fit",c),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 c;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,n=-1;(c=this.store.data.fits)==null||c.forEach((l,u)=>{l.ex=null,l.ey=null,pointInRect({x:s,y:r},l)&&(a=u),l.active&&(n=u)}),a!==-1&&a!==n?(this.canvasImage.activeFit=this.store.data.fits[a],this.store.data.fits[a].active=!0,n!==-1&&(this.store.data.fits[n].active=!1),this.store.emitter.emit("fit",this.store.data.fits[a])):a===-1&&n!==-1&&(this.store.data.fits[n].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 KeydownType.Document:document.removeEventListener("keydown",this.onkeydown),document.removeEventListener("keyup",this.onkeyup);break;case KeydownType.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 form(e,t){const i=t||new Path2D;e.onDestroy||(e.onDestroy=destory$3,e.onMouseLeave=mouseLeave,e.onMouseUp=mouseUp$1),e.formId=e.id;let s=e.calculative.borderRadius||0,r=s;const{x:a,y:n,width:c,height:l,ex:u,ey:h}=e.calculative.worldRect,{x:v}=e.calculative.worldTextRect;s<1&&(s=c*s,r=l*r);let f=s<r?s:r;if(c<2*f&&(f=c/2),l<2*f&&(f=l/2),i.moveTo(a+f,n),i.arcTo(u,n,u,h,f),i.arcTo(u,h,a,h,f),i.arcTo(a,h,a,n,f),i.arcTo(a,n,u,n,f),i instanceof Path2D)return i}function destory$3(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 mouseLeave(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+movingSuffix];r&&r.calculative&&(rectInRect(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 mouseUp$1(e){const t=e.calculative.canvas.store.active;t&&t.length&&t.forEach(i=>{let s=e.calculative.canvas.store.pens[i.id+movingSuffix];if(s||(s=e.calculative.canvas.store.pens[i.id]),s&&s.calculative){let r=deepClone(e.calculative.worldRect);r.x-=1,r.y-=1,r.width+=2,r.height+=2,rectInRect(s.calculative.worldRect,r,!0)&&(e.followers||(e.followers=[]),e.followers.includes(i.id)||e.followers.push(i.id),i.formId=e.id,predictFormValue(i))}})}function updateFormData(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 reset(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 n="";Array.isArray(a)&&(n=[]),e.calculative.canvas.parent.setValue({id:r.id,[r.formValue]:n},{render:!1,doEvent:!1,history:!1})}r||t.followers.splice(i,1)}t.formData={},e.calculative.canvas.parent.render()}const formValueMap={progress:"progress",cascadeFilterDom:"checked",treeFilterDom:"checked",dateRangePickerDom:"pickerTimes",datePickerDom:"pickerTimes",slider:"value",switch:"checked",inputDom:"text",checkbox:"selectedKeys",radio:"selectKey",rectangle:"text"};function predictFormValue(e){e.name==="rectangle"&&!e.input&&!e.dropdownList||(e.formValue=formValueMap[e.name])}function sceneContainer(e,t){e.onDestroy||(e.onAdd=add,e.onDestroy=destory$2,e.onMove=move$2,e.onBeforeValue=beforeValue$6,e.onMouseDown=onMousedown$2,e.onMouseUp=onMouseUp);const i=t||new Path2D;if(i instanceof Path2D)return i}async function add(e){e.sceneId||(e.sceneId=s8())}const getContainerPens=async(e,t)=>{var c;const i=e.calculative.canvas.store,s=i.data.origin,r=i.data.scale,a=t||e.vId,n=await getMeta2dData(i,a);if(n&&((c=n.pens)!=null&&c.length)){const l=n.scale,u=n.origin;n.pens.forEach(v=>{v.parentId||(v.width=v.width/l,v.height=v.height/l,v.x=(v.x-u.x)/l+(e.x-s.x)/r,v.y=(v.y-u.y)/l+(e.y-s.y)/r),v.p_sceneId||(v.p_sceneId=e.sceneId,v.name!=="sceneContainer"&&(v.p_vId=a))}),e.calculative.canvas.parent.addPens(n.pens,!1,!0)}moveToLast(e)},deleteContainerPens=e=>{const t=e.calculative.canvas.parent;collectContainerPens(e).forEach(s=>{t.canvas.delForce(s)}),t.canvas.canvasTemplate.init(),t.canvas.canvasImage.init(),t.canvas.canvasImageBottom.init(),t.render()},collectContainerPens=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},translateContainerPens=async e=>{e.calculative.drag&&e.calculative.active&&!(e.locked>1)&&(e.calculative.drag=!1,deleteContainerPens(e),getContainerPens(e))};function destory$2(e){deleteContainerPens(e)}function beforeValue$6(e,t){return t.vId&&(deleteContainerPens(e),getContainerPens(e,t.vId)),(t.x!==void 0||t.y!==void 0)&&(deleteContainerPens(e),getContainerPens(e)),t}function move$2(e){debounce(translateContainerPens,500,e)}function onMousedown$2(e,t){e.calculative.drag=!0}function onMouseUp(e,t){e.calculative.drag=!1}function moveToLast(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)}const gifsList={};function gif(e){e.onDestroy||(e.onDestroy=destory$1,e.onMove=move$1,e.onResize=resize$2,e.onRotate=move$1,e.onValue=value$2,e.onChangeId=changeId);const t=new Path2D;if(!e.image)return;const s=e.calculative.canvas.store.id+"-"+e.id;if(!gifsList[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),gifsList[s]=r,r.onload=()=>{var a;gifsList[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),setImagePosition(e,r))}}return e.calculative.patchFlags&&gifsList[s]&&setImagePosition(e,gifsList[s]),t}function destory$1(e){const i=e.calculative.canvas.store.id+"-"+e.id;gifsList[i]&&(gifsList[i].remove(),gifsList[i]=void 0)}function move$1(e){const i=e.calculative.canvas.store.id+"-"+e.id;gifsList[i]&&setImagePosition(e,gifsList[i])}function resize$2(e){const i=e.calculative.canvas.store.id+"-"+e.id;gifsList[i]&&setImagePosition(e,gifsList[i])}function value$2(e){const i=e.calculative.canvas.store.id+"-"+e.id;gifsList[i]&&(setImagePosition(e,gifsList[i]),gifsList[i].getAttribute("src")!==e.image&&(gifsList[i].src=e.image))}function changeId(e,t,i){const s=e.calculative.canvas.store.id;gifsList[s+"-"+t]&&(gifsList[s+"-"+i]=gifsList[s+"-"+t],delete gifsList[s+"-"+t])}function setImagePosition(e,t){t.style.objectFit=e.imageRatio?"contain":"fill",setElemPosition(e,t)}function mindNode(e,t){return e.onResize||(e.onResize=resize$1,e.onValue=value$1),rectangle(e,t)}function resize$1(e){const t=e.anchors.filter(i=>i.flag!==1);mindNodeAnchors(e),e.anchors=e.anchors.concat(...t)}function value$1(e){resize$1(e),calcWorldAnchors(e)}function mindNodeAnchors(e){const t=[],{x:i,y:s,width:r,height:a}=e,n=borderRadius(e),c=5;for(let v=0;v<c;v++){if(v===2)continue;let f=i+r*(v+1)/(c+1),g=s;f<i+n?g=getYByCircle(i+n,g+n,f,n,-1):f>i+r-n&&(g=getYByCircle(i+r-n,g+n,f,n,-1)),t.push({id:String(t.length),flag:1,penId:e.id,x:(f-i)/r,y:(g-s)/a})}const l=3;for(let v=0;v<l;v++){let f=s+a*(v+1)/(l+1),g=i+r;f<s+n?g=getXByCircle(g-n,s+n,f,n):f>s+a-n&&(g=getXByCircle(g-n,s+a-n,f,n)),t.push({id:String(t.length),flag:1,penId:e.id,x:(g-i)/r,y:(f-s)/a})}const u=5;for(let v=0;v<u;v++){if(v===2)continue;let f=i+r*(v+1)/(u+1),g=s+a;f<i+n?g=getYByCircle(i+n,g-n,f,n):f>i+r-n&&(g=getYByCircle(i+r-n,g-n,f,n)),t.push({id:String(t.length),flag:1,penId:e.id,x:(f-i)/r,y:(g-s)/a})}const h=3;for(let v=0;v<h;v++){let f=s+a*(v+1)/(h+1),g=i;f<s+n?g=getXByCircle(g+n,s+n,f,n,-1):f>s+a-n&&(g=getXByCircle(g+n,s+a-n,f,n,-1)),t.push({id:String(t.length),flag:1,penId:e.id,x:(g-i)/r,y:(f-s)/a})}e.anchors=t}function borderRadius(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 getXByCircle(e,t,i,s,r=1){return r*Math.sqrt(s**2-(i-t)**2)+e}function getYByCircle(e,t,i,s,r=1){return r*Math.sqrt(s**2-(i-e)**2)+t}function mindLine(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;if(i.moveTo(s,r+n),i.lineTo(s+a,r+n),i.closePath(),i instanceof Path2D)return i}function mindLineAnchors(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 commonPens(){return{rectangle,square,circle,svgPath,diamond,triangle,pentagon,pentagram,hexagon,leftArrow,rightArrow,twowayArrow,message,cloud,file,people,line,iframe,video,gif,mindNode,mindLine,mindNode2:rectangle,form,combine:rectangle,sceneContainer}}function commonAnchors(){return{triangle:triangleAnchors,pentagon:pentagonAnchors,pentagram:pentagramAnchors,mindNode:mindNodeAnchors,mindLine:mindLineAnchors}}var EventAction;(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"})(EventAction||(EventAction={}));class ViewMap{constructor(t){B(this,"parent");B(this,"box");B(this,"boxWidth",320);B(this,"boxHeight",180);B(this,"ratio",this.boxWidth/this.boxHeight);B(this,"padding",5);B(this,"img");B(this,"isShow");B(this,"isDown");B(this,"view");B(this,"timer");B(this,"onMouseDown",t=>{t.preventDefault(),t.stopPropagation(),this.isDown=!0});B(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}});B(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}});B(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 l=.2;t.deltaY.toString().indexOf(".")!==-1&&(l=.01),t.deltaY>0?i=-l:i=l}let{offsetX:s,offsetY:r}=t;const a=this.parent.store.data.width||this.parent.store.options.width,n=this.parent.store.data.height||this.parent.store.options.height;if(a&&n)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*n*this.parent.store.data.scale+this.parent.store.data.origin.y+this.parent.store.data.y;else{const c=this.parent.parent.getRect();s=s/this.boxWidth*c.width+c.x+this.parent.store.data.x,r=r/this.boxHeight*c.height+c.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=getRect$1(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)),translateRect(i,t.x,t.y),i.width/i.height>this.ratio){const v=i.width/this.ratio;i.y-=(v-i.height)/2,i.height=v,calcRightBottom(i)}else{const v=i.height*this.ratio;i.x-=(v-i.width)/2,i.width=v,calcRightBottom(i)}const n=this.parent.canvasRect;let c=0,l=0;if(i.x<0)c=-i.x/i.width;else if(i.x+i.width>n.width){let v=0;n.width>i.width&&(v=n.width-i.width),c=(-i.x+v)/i.width}if(i.y<0)l=-i.y/i.height;else if(i.y+i.height>n.height){let v=0;n.height>i.height&&(v=n.height-i.height),l=(-i.y+v)/i.height}const u=n.width>i.width?1:n.width/i.width,h=n.height>i.height?1:n.height/i.height;this.view.style.left=this.padding+c*this.boxWidth+"px",this.view.style.width=u*this.boxWidth+"px",this.view.style.top=this.padding+l*this.boxHeight+"px",this.view.style.height=h*this.boxHeight+"px"}}}function commonjsRequire(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 mqtt_min={exports:{}};(function(e,t){(function(i){e.exports=i()})(function(){return function(){return function i(s,r,a){function n(u,h){if(!r[u]){if(!s[u]){var v=typeof commonjsRequire=="function"&&commonjsRequire;if(!h&&v)return v(u,!0);if(c)return c(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var g=r[u]={exports:{}};s[u][0].call(g.exports,function(y){return n(s[u][1][y]||y)},g,g.exports,i,s,r,a)}return r[u].exports}for(var c=typeof commonjsRequire=="function"&&commonjsRequire,l=0;l<a.length;l++)n(a[l]);return n}}()({1:[function(i,s,r){(function(a,n){(function(){const c=i("events").EventEmitter,l=i("./store"),u=i("./topic-alias-recv"),h=i("./topic-alias-send"),v=i("mqtt-packet"),f=i("./default-message-id-provider"),g=i("readable-stream").Writable,y=i("inherits"),p=i("reinterval"),m=i("rfdc/default"),x=i("./validations"),k=i("xtend"),w=i("debug")("mqttjs:client"),C=a?a.nextTick:function(P){setTimeout(P,0)},I=n.setImmediate||function(P){C(P)},_={keepalive:60,reschedulePings:!0,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:1e3,connectTimeout:3e4,clean:!0,resubscribe:!0},L={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(P,M){let H;M.properties&&(H=M.properties.topicAlias);let $=M.topic.toString();if($.length===0){if(H===void 0)return new Error("Unregistered Topic Alias");if(($=P.topicAliasSend.getTopicByAlias(H))===void 0)return new Error("Unregistered Topic Alias");M.topic=$}H&&delete M.properties.topicAlias}function F(P,M,H){w("sendPacket :: packet: %O",M),w("sendPacket :: emitting `packetsend`"),P.emit("packetsend",M),w("sendPacket :: writing to stream");const $=v.writeToStream(M,P.stream,P.options);w("sendPacket :: writeToStream result %s",$),!$&&H&&H!==R?(w("sendPacket :: handle events on `drain` once through callback."),P.stream.once("drain",H)):H&&(w("sendPacket :: invoking cb"),H())}function q(P,M,H,$){w("storeAndSend :: store packet with cmd %s to outgoingStore",M.cmd);let X,j=M;if(j.cmd==="publish"&&(j=m(M),X=E(P,j)))return H&&H(X);P.outgoingStore.put(j,function(O){if(O)return H&&H(O);$(),F(P,M,H)})}function R(P){w("nop ::",P)}function A(P,M){let H;const $=this;if(!(this instanceof A))return new A(P,M);for(H in this.options=M||{},_)this.options[H]===void 0?this.options[H]=_[H]:this.options[H]=M[H];w("MqttClient :: options.protocol",M.protocol),w("MqttClient :: options.protocolVersion",M.protocolVersion),w("MqttClient :: options.username",M.username),w("MqttClient :: options.keepalive",M.keepalive),w("MqttClient :: options.reconnectPeriod",M.reconnectPeriod),w("MqttClient :: options.rejectUnauthorized",M.rejectUnauthorized),w("MqttClient :: options.topicAliasMaximum",M.topicAliasMaximum),this.options.clientId=typeof M.clientId=="string"?M.clientId:"mqttjs_"+Math.random().toString(16).substr(2,8),w("MqttClient :: clientId",this.options.clientId),this.options.customHandleAcks=M.protocolVersion===5&&M.customHandleAcks?M.customHandleAcks:function(){arguments[3](0)},this.streamBuilder=P,this.messageIdProvider=this.options.messageIdProvider===void 0?new f:this.options.messageIdProvider,this.outgoingStore=M.outgoingStore||new l,this.incomingStore=M.incomingStore||new l,this.queueQoSZero=M.queueQoSZero===void 0||M.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,M.topicAliasMaximum>0&&(M.topicAliasMaximum>65535?w("MqttClient :: options.topicAliasMaximum is out of range"):this.topicAliasRecv=new u(M.topicAliasMaximum)),this.on("connect",function(){const X=this.queue;w("connect :: sending queued packets"),function j(){const O=X.shift();w("deliver :: entry %o",O);let z=null;if(!O)return void $._resubscribe();z=O.packet,w("deliver :: call _sendPacket for %o",z);let V=!0;z.messageId&&z.messageId!==0&&($.messageIdProvider.register(z.messageId)||(V=!1)),V?$._sendPacket(z,function(N){O.cb&&O.cb(N),j()}):(w("messageId: %d has already used. The message is skipped and removed.",z.messageId),j())}()}),this.on("close",function(){w("close :: connected set to `false`"),this.connected=!1,w("close :: clearing connackTimer"),clearTimeout(this.connackTimer),w("close :: clearing ping timer"),$.pingTimer!==null&&($.pingTimer.clear(),$.pingTimer=null),this.topicAliasRecv&&this.topicAliasRecv.clear(),w("close :: calling _setupReconnect"),this._setupReconnect()}),c.call(this),w("MqttClient :: setting up stream"),this._setupStream()}y(A,c),A.prototype._setupStream=function(){const P=this,M=new g,H=v.parser(this.options);let $=null;const X=[];function j(){if(X.length)C(O);else{const V=$;$=null,V()}}function O(){w("work :: getting next packet in queue");const V=X.shift();if(V)w("work :: packet pulled from queue"),P._handlePacket(V,j);else{w("work :: no packets in queue");const N=$;$=null,w("work :: done flag is %s",!!N),N&&N()}}w("_setupStream :: calling method to clear reconnect"),this._clearReconnect(),w("_setupStream :: using streamBuilder provided to client to create stream"),this.stream=this.streamBuilder(this),H.on("packet",function(V){w("parser :: on packet push to packets array."),X.push(V)}),M._write=function(V,N,Y){$=Y,w("writable stream :: parsing buffer"),H.parse(V),O()},w("_setupStream :: pipe stream to writable stream"),this.stream.pipe(M),this.stream.on("error",function(V){w("streamErrorHandler :: error",V.message),V.code?(w("streamErrorHandler :: emitting error"),P.emit("error",V)):R(V)}),this.stream.on("close",function(){var V;w("(%s)stream :: on close",P.options.clientId),(V=P.outgoing)&&(w("flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"),Object.keys(V).forEach(function(N){V[N].volatile&&typeof V[N].cb=="function"&&(V[N].cb(new Error("Connection closed")),delete V[N])})),w("stream: emit close to MqttClient"),P.emit("close")}),w("_setupStream: sending packet `connect`");const z=Object.create(this.options);if(z.cmd="connect",this.topicAliasRecv&&(z.properties||(z.properties={}),this.topicAliasRecv&&(z.properties.topicAliasMaximum=this.topicAliasRecv.max)),F(this,z),H.on("error",this.emit.bind(this,"error")),this.options.properties){if(!this.options.properties.authenticationMethod&&this.options.properties.authenticationData)return P.end(()=>this.emit("error",new Error("Packet has no Authentication Method"))),this;this.options.properties.authenticationMethod&&this.options.authPacket&&typeof this.options.authPacket=="object"&&F(this,k({cmd:"auth",reasonCode:0},this.options.authPacket))}this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout(function(){w("!!connectTimeout hit!! Calling _cleanUp with force `true`"),P._cleanUp(!0)},this.options.connectTimeout)},A.prototype._handlePacket=function(P,M){const H=this.options;if(H.protocolVersion===5&&H.properties&&H.properties.maximumPacketSize&&H.properties.maximumPacketSize<P.length)return this.emit("error",new Error("exceeding packets size "+P.cmd)),this.end({reasonCode:149,properties:{reasonString:"Maximum packet size was exceeded"}}),this;switch(w("_handlePacket :: emitting packetreceive"),this.emit("packetreceive",P),P.cmd){case"publish":this._handlePublish(P,M);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":this._handleAck(P),M();break;case"pubrel":this._handlePubrel(P,M);break;case"connack":this._handleConnack(P),M();break;case"auth":this._handleAuth(P),M();break;case"pingresp":this._handlePingresp(P),M();break;case"disconnect":this._handleDisconnect(P),M()}},A.prototype._checkDisconnecting=function(P){return this.disconnecting&&(P&&P!==R?P(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting},A.prototype.publish=function(P,M,H,$){w("publish :: message `%s` to topic `%s`",M,P);const X=this.options;if(typeof H=="function"&&($=H,H=null),H=k({qos:0,retain:!1,dup:!1},H),this._checkDisconnecting($))return this;const j=this,O=function(){let z=0;if((H.qos===1||H.qos===2)&&(z=j._nextId())===null)return w("No messageId left"),!1;const V={cmd:"publish",topic:P,payload:M,qos:H.qos,retain:H.retain,messageId:z,dup:H.dup};switch(X.protocolVersion===5&&(V.properties=H.properties),w("publish :: qos",H.qos),H.qos){case 1:case 2:j.outgoing[V.messageId]={volatile:!1,cb:$||R},w("MqttClient:publish: packet cmd: %s",V.cmd),j._sendPacket(V,void 0,H.cbStorePut);break;default:w("MqttClient:publish: packet cmd: %s",V.cmd),j._sendPacket(V,$,H.cbStorePut)}return!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!O())&&this._storeProcessingQueue.push({invoke:O,cbStorePut:H.cbStorePut,callback:$}),this},A.prototype.subscribe=function(){const P=this,M=new Array(arguments.length);for(let K=0;K<arguments.length;K++)M[K]=arguments[K];const H=[];let $=M.shift();const X=$.resubscribe;let j=M.pop()||R,O=M.pop();const z=this.options.protocolVersion;delete $.resubscribe,typeof $=="string"&&($=[$]),typeof j!="function"&&(O=j,j=R);const V=x.validateTopics($);if(V!==null)return I(j,new Error("Invalid topic "+V)),this;if(this._checkDisconnecting(j))return w("subscribe: discconecting true"),this;const N={qos:0};if(z===5&&(N.nl=!1,N.rap=!1,N.rh=0),O=k(N,O),Array.isArray($)?$.forEach(function(K){if(w("subscribe: array topic %s",K),!Object.prototype.hasOwnProperty.call(P._resubscribeTopics,K)||P._resubscribeTopics[K].qos<O.qos||X){const G={topic:K,qos:O.qos};z===5&&(G.nl=O.nl,G.rap=O.rap,G.rh=O.rh,G.properties=O.properties),w("subscribe: pushing topic `%s` and qos `%s` to subs list",G.topic,G.qos),H.push(G)}}):Object.keys($).forEach(function(K){if(w("subscribe: object topic %s",K),!Object.prototype.hasOwnProperty.call(P._resubscribeTopics,K)||P._resubscribeTopics[K].qos<$[K].qos||X){const G={topic:K,qos:$[K].qos};z===5&&(G.nl=$[K].nl,G.rap=$[K].rap,G.rh=$[K].rh,G.properties=O.properties),w("subscribe: pushing `%s` to subs list",G),H.push(G)}}),!H.length)return j(null,[]),this;const Y=function(){const K=P._nextId();if(K===null)return w("No messageId left"),!1;const G={cmd:"subscribe",subscriptions:H,qos:1,retain:!1,dup:!1,messageId:K};if(O.properties&&(G.properties=O.properties),P.options.resubscribe){w("subscribe :: resubscribe true");const tt=[];H.forEach(function(Q){if(P.options.reconnectPeriod>0){const Z={qos:Q.qos};z===5&&(Z.nl=Q.nl||!1,Z.rap=Q.rap||!1,Z.rh=Q.rh||0,Z.properties=Q.properties),P._resubscribeTopics[Q.topic]=Z,tt.push(Q.topic)}}),P.messageIdToTopic[G.messageId]=tt}return P.outgoing[G.messageId]={volatile:!0,cb:function(tt,Q){if(!tt){const Z=Q.granted;for(let b=0;b<Z.length;b+=1)H[b].qos=Z[b]}j(tt,H)}},w("subscribe :: call _sendPacket"),P._sendPacket(G),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!Y())&&this._storeProcessingQueue.push({invoke:Y,callback:j}),this},A.prototype.unsubscribe=function(){const P=this,M=new Array(arguments.length);for(let z=0;z<arguments.length;z++)M[z]=arguments[z];let H=M.shift(),$=M.pop()||R,X=M.pop();typeof H=="string"&&(H=[H]),typeof $!="function"&&(X=$,$=R);const j=x.validateTopics(H);if(j!==null)return I($,new Error("Invalid topic "+j)),this;if(P._checkDisconnecting($))return this;const O=function(){const z=P._nextId();if(z===null)return w("No messageId left"),!1;const V={cmd:"unsubscribe",qos:1,messageId:z};return typeof H=="string"?V.unsubscriptions=[H]:Array.isArray(H)&&(V.unsubscriptions=H),P.options.resubscribe&&V.unsubscriptions.forEach(function(N){delete P._resubscribeTopics[N]}),typeof X=="object"&&X.properties&&(V.properties=X.properties),P.outgoing[V.messageId]={volatile:!0,cb:$},w("unsubscribe: call _sendPacket"),P._sendPacket(V),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!O())&&this._storeProcessingQueue.push({invoke:O,callback:$}),this},A.prototype.end=function(P,M,H){const $=this;function X(){w("end :: (%s) :: finish :: calling _cleanUp with force %s",$.options.clientId,P),$._cleanUp(P,()=>{w("end :: finish :: calling process.nextTick on closeStores"),C((function(){w("end :: closeStores: closing incoming and outgoing stores"),$.disconnected=!0,$.incomingStore.close(function(j){$.outgoingStore.close(function(O){if(w("end :: closeStores: emitting end"),$.emit("end"),H){const z=j||O;w("end :: closeStores: invoking callback with args"),H(z)}})}),$._deferredReconnect&&$._deferredReconnect()}).bind($))},M)}return w("end :: (%s)",this.options.clientId),P!=null&&typeof P=="boolean"||(H=M||R,M=P,P=!1,typeof M!="object"&&(H=M,M=null,typeof H!="function"&&(H=R))),typeof M!="object"&&(H=M,M=null),w("end :: cb? %s",!!H),H=H||R,this.disconnecting?(H(),this):(this._clearReconnect(),this.disconnecting=!0,!P&&Object.keys(this.outgoing).length>0?(w("end :: (%s) :: calling finish in 10ms once outgoing is empty",$.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,X,10))):(w("end :: (%s) :: immediately calling finish",$.options.clientId),X()),this)},A.prototype.removeOutgoingMessage=function(P){const M=this.outgoing[P]?this.outgoing[P].cb:null;return delete this.outgoing[P],this.outgoingStore.del({messageId:P},function(){M(new Error("Message removed"))}),this},A.prototype.reconnect=function(P){w("client reconnect");const M=this,H=function(){P?(M.options.incomingStore=P.incomingStore,M.options.outgoingStore=P.outgoingStore):(M.options.incomingStore=null,M.options.outgoingStore=null),M.incomingStore=M.options.incomingStore||new l,M.outgoingStore=M.options.outgoingStore||new l,M.disconnecting=!1,M.disconnected=!1,M._deferredReconnect=null,M._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=H:H(),this},A.prototype._reconnect=function(){w("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end(()=>{this._setupStream()}),w("client already connected. disconnecting first.")):(w("_reconnect: calling _setupStream"),this._setupStream())},A.prototype._setupReconnect=function(){const P=this;!P.disconnecting&&!P.reconnectTimer&&P.options.reconnectPeriod>0?(this.reconnecting||(w("_setupReconnect :: emit `offline` state"),this.emit("offline"),w("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),w("_setupReconnect :: setting reconnectTimer for %d ms",P.options.reconnectPeriod),P.reconnectTimer=setInterval(function(){w("reconnectTimer :: reconnect triggered!"),P._reconnect()},P.options.reconnectPeriod)):w("_setupReconnect :: doing nothing...")},A.prototype._clearReconnect=function(){w("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},A.prototype._cleanUp=function(P,M){const H=arguments[2];if(M&&(w("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",M)),w("_cleanUp :: forced? %s",P),P)this.options.reconnectPeriod===0&&this.options.clean&&($=this.outgoing)&&(w("flush: queue exists? %b",!!$),Object.keys($).forEach(function(X){typeof $[X].cb=="function"&&($[X].cb(new Error("Connection closed")),delete $[X])})),w("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{const X=k({cmd:"disconnect"},H);w("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(X,I.bind(null,this.stream.end.bind(this.stream)))}var $;this.disconnecting||(w("_cleanUp :: client not disconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),this.pingTimer!==null&&(w("_cleanUp :: clearing pingTimer"),this.pingTimer.clear(),this.pingTimer=null),M&&!this.connected&&(w("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",M),M())},A.prototype._sendPacket=function(P,M,H){w("_sendPacket :: (%s) :: start",this.options.clientId),H=H||R,M=M||R;const $=function(X,j){if(X.options.protocolVersion===5&&j.cmd==="publish"){let O;j.properties&&(O=j.properties.topicAlias);const z=j.topic.toString();if(X.topicAliasSend)if(O){if(z.length!==0&&(w("applyTopicAlias :: register topic: %s - alias: %d",z,O),!X.topicAliasSend.put(z,O)))return w("applyTopicAlias :: error out of range. topic: %s - alias: %d",z,O),new Error("Sending Topic Alias out of range")}else z.length!==0&&(X.options.autoAssignTopicAlias?(O=X.topicAliasSend.getAliasByTopic(z))?(j.topic="",j.properties={...j.properties,topicAlias:O},w("applyTopicAlias :: auto assign(use) topic: %s - alias: %d",z,O)):(O=X.topicAliasSend.getLruAlias(),X.topicAliasSend.put(z,O),j.properties={...j.properties,topicAlias:O},w("applyTopicAlias :: auto assign topic: %s - alias: %d",z,O)):X.options.autoUseTopicAlias&&(O=X.topicAliasSend.getAliasByTopic(z))&&(j.topic="",j.properties={...j.properties,topicAlias:O},w("applyTopicAlias :: auto use topic: %s - alias: %d",z,O)));else if(O)return w("applyTopicAlias :: error out of range. topic: %s - alias: %d",z,O),new Error("Sending Topic Alias out of range")}}(this,P);if($)M($);else{if(!this.connected)return P.cmd==="auth"?(this._shiftPingInterval(),void F(this,P,M)):(w("_sendPacket :: client not connected. Storing packet offline."),void this._storePacket(P,M,H));switch(this._shiftPingInterval(),P.cmd){case"publish":break;case"pubrel":return void q(this,P,M,H);default:return void F(this,P,M)}switch(P.qos){case 2:case 1:q(this,P,M,H);break;case 0:default:F(this,P,M)}w("_sendPacket :: (%s) :: end",this.options.clientId)}},A.prototype._storePacket=function(P,M,H){w("_storePacket :: packet: %o",P),w("_storePacket :: cb? %s",!!M),H=H||R;let $=P;if($.cmd==="publish"){const X=E(this,$=m(P));if(X)return M&&M(X)}($.qos||0)===0&&this.queueQoSZero||$.cmd!=="publish"?this.queue.push({packet:$,cb:M}):$.qos>0?(M=this.outgoing[$.messageId]?this.outgoing[$.messageId].cb:null,this.outgoingStore.put($,function(X){if(X)return M&&M(X);H()})):M&&M(new Error("No connection to broker"))},A.prototype._setupPingTimer=function(){w("_setupPingTimer :: keepalive %d (seconds)",this.options.keepalive);const P=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=p(function(){P._checkPing()},1e3*this.options.keepalive))},A.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},A.prototype._checkPing=function(){w("_checkPing :: checking ping..."),this.pingResp?(w("_checkPing :: ping response received. Clearing flag and sending `pingreq`"),this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):(w("_checkPing :: calling _cleanUp with force true"),this._cleanUp(!0))},A.prototype._handlePingresp=function(){this.pingResp=!0},A.prototype._handleConnack=function(P){w("_handleConnack");const M=this.options,H=M.protocolVersion===5?P.reasonCode:P.returnCode;if(clearTimeout(this.connackTimer),delete this.topicAliasSend,P.properties){if(P.properties.topicAliasMaximum){if(P.properties.topicAliasMaximum>65535)return void this.emit("error",new Error("topicAliasMaximum from broker is out of range"));P.properties.topicAliasMaximum>0&&(this.topicAliasSend=new h(P.properties.topicAliasMaximum))}P.properties.serverKeepAlive&&M.keepalive&&(M.keepalive=P.properties.serverKeepAlive,this._shiftPingInterval()),P.properties.maximumPacketSize&&(M.properties||(M.properties={}),M.properties.maximumPacketSize=P.properties.maximumPacketSize)}if(H===0)this.reconnecting=!1,this._onConnect(P);else if(H>0){const $=new Error("Connection refused: "+L[H]);$.code=H,this.emit("error",$)}},A.prototype._handleAuth=function(P){const M=this.options.protocolVersion,H=M===5?P.reasonCode:P.returnCode;if(M!==5){const X=new Error("Protocol error: Auth packets are only supported in MQTT 5. Your version:"+M);return X.code=H,void this.emit("error",X)}const $=this;this.handleAuth(P,function(X,j){if(X)$.emit("error",X);else if(H===24)$.reconnecting=!1,$._sendPacket(j);else{const O=new Error("Connection refused: "+L[H]);X.code=H,$.emit("error",O)}})},A.prototype.handleAuth=function(P,M){M()},A.prototype._handlePublish=function(P,M){w("_handlePublish: packet %o",P),M=M!==void 0?M:R;let H=P.topic.toString();const $=P.payload,X=P.qos,j=P.messageId,O=this,z=this.options,V=[0,16,128,131,135,144,145,151,153];if(this.options.protocolVersion===5){let N;if(P.properties&&(N=P.properties.topicAlias),N!==void 0)if(H.length===0){if(!(N>0&&N<=65535))return w("_handlePublish :: topic alias out of range. alias: %d",N),void this.emit("error",new Error("Received Topic Alias is out of range"));{const Y=this.topicAliasRecv.getTopicByAlias(N);if(!Y)return w("_handlePublish :: unregistered topic alias. alias: %d",N),void this.emit("error",new Error("Received unregistered Topic Alias"));w("_handlePublish :: topic complemented by alias. topic: %s - alias: %d",H=Y,N)}}else{if(!this.topicAliasRecv.put(H,N))return w("_handlePublish :: topic alias out of range. alias: %d",N),void this.emit("error",new Error("Received Topic Alias is out of range"));w("_handlePublish :: registered topic: %s - alias: %d",H,N)}}switch(w("_handlePublish: qos %d",X),X){case 2:z.customHandleAcks(H,$,P,function(N,Y){return N instanceof Error||(Y=N,N=null),N?O.emit("error",N):V.indexOf(Y)===-1?O.emit("error",new Error("Wrong reason code for pubrec")):void(Y?O._sendPacket({cmd:"pubrec",messageId:j,reasonCode:Y},M):O.incomingStore.put(P,function(){O._sendPacket({cmd:"pubrec",messageId:j},M)}))});break;case 1:z.customHandleAcks(H,$,P,function(N,Y){return N instanceof Error||(Y=N,N=null),N?O.emit("error",N):V.indexOf(Y)===-1?O.emit("error",new Error("Wrong reason code for puback")):(Y||O.emit("message",H,$,P),void O.handleMessage(P,function(K){if(K)return M&&M(K);O._sendPacket({cmd:"puback",messageId:j,reasonCode:Y},M)}))});break;case 0:this.emit("message",H,$,P),this.handleMessage(P,M);break;default:w("_handlePublish: unknown QoS. Doing nothing.")}},A.prototype.handleMessage=function(P,M){M()},A.prototype._handleAck=function(P){const M=P.messageId,H=P.cmd;let $=null;const X=this.outgoing[M]?this.outgoing[M].cb:null,j=this;let O;if(X){switch(w("_handleAck :: packet type",H),H){case"pubcomp":case"puback":{const z=P.reasonCode;z&&z>0&&z!==16&&((O=new Error("Publish error: "+L[z])).code=z,X(O,P)),delete this.outgoing[M],this.outgoingStore.del(P,X),this.messageIdProvider.deallocate(M),this._invokeStoreProcessingQueue();break}case"pubrec":{$={cmd:"pubrel",qos:2,messageId:M};const z=P.reasonCode;z&&z>0&&z!==16?((O=new Error("Publish error: "+L[z])).code=z,X(O,P)):this._sendPacket($);break}case"suback":delete this.outgoing[M],this.messageIdProvider.deallocate(M);for(let z=0;z<P.granted.length;z++)if(128&P.granted[z]){const V=this.messageIdToTopic[M];V&&V.forEach(function(N){delete j._resubscribeTopics[N]})}this._invokeStoreProcessingQueue(),X(null,P);break;case"unsuback":delete this.outgoing[M],this.messageIdProvider.deallocate(M),this._invokeStoreProcessingQueue(),X(null);break;default:j.emit("error",new Error("unrecognized packet type"))}this.disconnecting&&Object.keys(this.outgoing).length===0&&this.emit("outgoingEmpty")}else w("_handleAck :: Server sent an ack in error. Ignoring.")},A.prototype._handlePubrel=function(P,M){w("handling pubrel packet"),M=M!==void 0?M:R;const H=this,$={cmd:"pubcomp",messageId:P.messageId};H.incomingStore.get(P,function(X,j){X?H._sendPacket($,M):(H.emit("message",j.topic,j.payload,j),H.handleMessage(j,function(O){if(O)return M(O);H.incomingStore.del(j,R),H._sendPacket($,M)}))})},A.prototype._handleDisconnect=function(P){this.emit("disconnect",P)},A.prototype._nextId=function(){return this.messageIdProvider.allocate()},A.prototype.getLastMessageId=function(){return this.messageIdProvider.getLastAllocated()},A.prototype._resubscribe=function(){w("_resubscribe");const P=Object.keys(this._resubscribeTopics);if(!this._firstConnection&&(this.options.clean||this.options.protocolVersion===5&&!this.connackPacket.sessionPresent)&&P.length>0)if(this.options.resubscribe)if(this.options.protocolVersion===5){w("_resubscribe: protocolVersion 5");for(let M=0;M<P.length;M++){const H={};H[P[M]]=this._resubscribeTopics[P[M]],H.resubscribe=!0,this.subscribe(H,{properties:H[P[M]].properties})}}else this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics);else this._resubscribeTopics={};this._firstConnection=!1},A.prototype._onConnect=function(P){if(this.disconnected)return void this.emit("connect",P);const M=this;this.connackPacket=P,this.messageIdProvider.clear(),this._setupPingTimer(),this.connected=!0,function H(){let $=M.outgoingStore.createStream();function X(){M._storeProcessing=!1,M._packetIdsDuringStoreProcessing={}}function j(){$.destroy(),$=null,M._flushStoreProcessingQueue(),X()}M.once("close",j),$.on("error",function(O){X(),M._flushStoreProcessingQueue(),M.removeListener("close",j),M.emit("error",O)}),$.on("end",function(){let O=!0;for(const z in M._packetIdsDuringStoreProcessing)if(!M._packetIdsDuringStoreProcessing[z]){O=!1;break}O?(X(),M.removeListener("close",j),M._invokeAllStoreProcessingQueue(),M.emit("connect",P)):H()}),function O(){if(!$)return;M._storeProcessing=!0;const z=$.read(1);let V;z?M._packetIdsDuringStoreProcessing[z.messageId]?O():M.disconnecting||M.reconnectTimer?$.destroy&&$.destroy():(V=M.outgoing[z.messageId]?M.outgoing[z.messageId].cb:null,M.outgoing[z.messageId]={volatile:!1,cb:function(N,Y){V&&V(N,Y),O()}},M._packetIdsDuringStoreProcessing[z.messageId]=!0,M.messageIdProvider.register(z.messageId)?M._sendPacket(z):w("messageId: %d has already used.",z.messageId)):$.once("readable",O)}()}()},A.prototype._invokeStoreProcessingQueue=function(){if(this._storeProcessingQueue.length>0){const P=this._storeProcessingQueue[0];if(P&&P.invoke())return this._storeProcessingQueue.shift(),!0}return!1},A.prototype._invokeAllStoreProcessingQueue=function(){for(;this._invokeStoreProcessingQueue(););},A.prototype._flushStoreProcessingQueue=function(){for(const P of this._storeProcessingQueue)P.cbStorePut&&P.cbStorePut(new Error("Connection closed")),P.callback&&P.callback(new Error("Connection closed"));this._storeProcessingQueue.splice(0)},s.exports=A}).call(this)}).call(this,i("_process"),typeof commonjsGlobal<"u"?commonjsGlobal: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"),n=i("readable-stream").Transform,c=i("duplexify");let l,u,h,v=!1;s.exports=function(f,g){if(g.hostname=g.hostname||g.host,!g.hostname)throw new Error("Could not determine host. Specify host manually.");const y=g.protocolId==="MQIsdp"&&g.protocolVersion===3?"mqttv3.1":"mqtt";(function(m){m.hostname||(m.hostname="localhost"),m.path||(m.path="/"),m.wsOptions||(m.wsOptions={})})(g);const p=function(m,x){const k=m.protocol==="alis"?"wss":"ws";let w=k+"://"+m.hostname+m.path;return m.port&&m.port!==80&&m.port!==443&&(w=k+"://"+m.hostname+":"+m.port+m.path),typeof m.transformWsUrl=="function"&&(w=m.transformWsUrl(w,m,x)),w}(g,f);return(l=g.my).connectSocket({url:p,protocols:y}),u=function(){const m=new n;return m._write=function(x,k,w){l.sendSocketMessage({data:x.buffer,success:function(){w()},fail:function(){w(new Error)}})},m._flush=function(x){l.closeSocket({success:function(){x()}})},m}(),h=c.obj(),v||(v=!0,l.onSocketOpen(function(){h.setReadable(u),h.setWritable(u),h.emit("connect")}),l.onSocketMessage(function(m){if(typeof m.data=="string"){const x=a.from(m.data,"base64");u.push(x)}else{const x=new FileReader;x.addEventListener("load",function(){let k=x.result;k=k instanceof ArrayBuffer?a.from(k):a.from(k,"utf8"),u.push(k)}),x.readAsArrayBuffer(m.data)}}),l.onSocketClose(function(){h.end(),h.destroy()}),l.onSocketError(function(m){h.destroy(m)})),h}},{buffer:17,duplexify:20,"readable-stream":69}],3:[function(i,s,r){const a=i("net"),n=i("debug")("mqttjs:tcp");s.exports=function(c,l){l.port=l.port||1883,l.hostname=l.hostname||l.host||"localhost";const u=l.port,h=l.hostname;return n("port %d and host %s",u,h),a.createConnection(u,h)}},{debug:18,net:16}],4:[function(i,s,r){const a=i("tls"),n=i("net"),c=i("debug")("mqttjs:tls");s.exports=function(l,u){u.port=u.port||8883,u.host=u.hostname||u.host||"localhost",n.isIP(u.host)===0&&(u.servername=u.host),u.rejectUnauthorized=u.rejectUnauthorized!==!1,delete u.path,c("port %d host %s rejectUnauthorized %b",u.port,u.host,u.rejectUnauthorized);const h=a.connect(u);function v(f){u.rejectUnauthorized&&l.emit("error",f),h.end()}return h.on("secureConnect",function(){u.rejectUnauthorized&&!h.authorized?h.emit("error",new Error("TLS not authorized")):h.removeListener("error",v)}),h.on("error",v),h}},{debug:18,net:16,tls:16}],5:[function(i,s,r){(function(a){(function(){const{Buffer:n}=i("buffer"),c=i("ws"),l=i("debug")("mqttjs:ws"),u=i("duplexify"),h=i("readable-stream").Transform,v=["rejectUnauthorized","ca","cert","key","pfx","passphrase"],f=a!==void 0&&a.title==="browser"||typeof __webpack_require__=="function";function g(p,m){let x=p.protocol+"://"+p.hostname+":"+p.port+p.path;return typeof p.transformWsUrl=="function"&&(x=p.transformWsUrl(x,p,m)),x}function y(p){const m=p;return p.hostname||(m.hostname="localhost"),p.port||(p.protocol==="wss"?m.port=443:m.port=80),p.path||(m.path="/"),p.wsOptions||(m.wsOptions={}),f||p.protocol!=="wss"||v.forEach(function(x){Object.prototype.hasOwnProperty.call(p,x)&&!Object.prototype.hasOwnProperty.call(p.wsOptions,x)&&(m.wsOptions[x]=p[x])}),m}s.exports=f?function(p,m){let x;l("browserStreamBuilder");const k=function(P){const M=y(P);if(M.hostname||(M.hostname=M.host),!M.hostname){if(typeof document>"u")throw new Error("Could not determine host. Specify host manually.");const H=new URL(document.URL);M.hostname=H.hostname,M.port||(M.port=H.port)}return M.objectMode===void 0&&(M.objectMode=!(M.binary===!0||M.binary===void 0)),M}(m).browserBufferSize||524288,w=m.browserBufferTimeout||1e3,C=!m.objectMode,I=function(P,M){const H=M.protocolId==="MQIsdp"&&M.protocolVersion===3?"mqttv3.1":"mqtt",$=g(M,P),X=new WebSocket($,[H]);return X.binaryType="arraybuffer",X}(p,m),_=function(P,M,H){const $=new h({objectModeMode:P.objectMode});return $._write=M,$._flush=H,$}(m,function P(M,H,$){I.bufferedAmount>k&&setTimeout(P,w,M,H,$),C&&typeof M=="string"&&(M=n.from(M,"utf8"));try{I.send(M)}catch(X){return $(X)}$()},function(P){I.close(),P()});m.objectMode||(_._writev=A),_.on("close",()=>{I.close()});const L=I.addEventListener!==void 0;function E(){x.setReadable(_),x.setWritable(_),x.emit("connect")}function F(){x.end(),x.destroy()}function q(P){x.destroy(P)}function R(P){let M=P.data;M=M instanceof ArrayBuffer?n.from(M):n.from(M,"utf8"),_.push(M)}function A(P,M){const H=new Array(P.length);for(let $=0;$<P.length;$++)typeof P[$].chunk=="string"?H[$]=n.from(P[$],"utf8"):H[$]=P[$].chunk;this._write(n.concat(H),"binary",M)}return I.readyState===I.OPEN?x=_:(x=x=u(void 0,void 0,m),m.objectMode||(x._writev=A),L?I.addEventListener("open",E):I.onopen=E),x.socket=I,L?(I.addEventListener("close",F),I.addEventListener("error",q),I.addEventListener("message",R)):(I.onclose=F,I.onerror=q,I.onmessage=R),x}:function(p,m){l("streamBuilder");const x=y(m),k=g(x,p),w=function(I,_,L){l("createWebSocket"),l("protocol: "+L.protocolId+" "+L.protocolVersion);const E=L.protocolId==="MQIsdp"&&L.protocolVersion===3?"mqttv3.1":"mqtt";return l("creating new Websocket for url: "+_+" and protocol: "+E),new c(_,[E],L.wsOptions)}(0,k,x),C=c.createWebSocketStream(w,x.wsOptions);return C.url=k,w.on("close",()=>{C.destroy()}),C}}).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"),n=i("readable-stream").Transform,c=i("duplexify");let l,u,h;s.exports=function(v,f){if(f.hostname=f.hostname||f.host,!f.hostname)throw new Error("Could not determine host. Specify host manually.");const g=f.protocolId==="MQIsdp"&&f.protocolVersion===3?"mqttv3.1":"mqtt";(function(m){m.hostname||(m.hostname="localhost"),m.path||(m.path="/"),m.wsOptions||(m.wsOptions={})})(f);const y=function(m,x){const k=m.protocol==="wxs"?"wss":"ws";let w=k+"://"+m.hostname+m.path;return m.port&&m.port!==80&&m.port!==443&&(w=k+"://"+m.hostname+":"+m.port+m.path),typeof m.transformWsUrl=="function"&&(w=m.transformWsUrl(w,m,x)),w}(f,v);l=wx.connectSocket({url:y,protocols:[g]}),u=function(){const m=new n;return m._write=function(x,k,w){l.send({data:x.buffer,success:function(){w()},fail:function(C){w(new Error(C))}})},m._flush=function(x){l.close({success:function(){x()}})},m}(),(h=c.obj())._destroy=function(m,x){l.close({success:function(){x&&x(m)}})};const p=h.destroy;return h.destroy=(function(){h.destroy=p;const m=this;setTimeout(function(){l.close({fail:function(){m._destroy(new Error)}})},0)}).bind(h),l.onOpen(function(){h.setReadable(u),h.setWritable(u),h.emit("connect")}),l.onMessage(function(m){let x=m.data;x=x instanceof ArrayBuffer?a.from(x):a.from(x,"utf8"),u.push(x)}),l.onClose(function(){h.end(),h.destroy()}),l.onError(function(m){h.destroy(new Error(m.errMsg))}),h}},{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 n=this.nextId++;return this.nextId===65536&&(this.nextId=1),n},a.prototype.getLastAllocated=function(){return this.nextId===1?65535:this.nextId-1},a.prototype.register=function(n){return!0},a.prototype.deallocate=function(n){},a.prototype.clear=function(){},s.exports=a},{}],8:[function(i,s,r){const a=i("xtend"),n=i("readable-stream").Readable,c={objectMode:!0},l={clean:!0};function u(h){if(!(this instanceof u))return new u(h);this.options=h||{},this.options=a(l,h),this._inflights=new Map}u.prototype.put=function(h,v){return this._inflights.set(h.messageId,h),v&&v(),this},u.prototype.createStream=function(){const h=new n(c),v=[];let f=!1,g=0;return this._inflights.forEach(function(y,p){v.push(y)}),h._read=function(){!f&&g<v.length?this.push(v[g++]):this.push(null)},h.destroy=function(){if(f)return;const y=this;f=!0,setTimeout(function(){y.emit("close")},0)},h},u.prototype.del=function(h,v){return(h=this._inflights.get(h.messageId))?(this._inflights.delete(h.messageId),v(null,h)):v&&v(new Error("missing packet")),this},u.prototype.get=function(h,v){return(h=this._inflights.get(h.messageId))?v(null,h):v&&v(new Error("missing packet")),this},u.prototype.close=function(h){this.options.clean&&(this._inflights=null),h&&h()},s.exports=u},{"readable-stream":69,xtend:81}],9:[function(i,s,r){function a(n){if(!(this instanceof a))return new a(n);this.aliasToTopic={},this.max=n}a.prototype.put=function(n,c){return!(c===0||c>this.max)&&(this.aliasToTopic[c]=n,this.length=Object.keys(this.aliasToTopic).length,!0)},a.prototype.getTopicByAlias=function(n){return this.aliasToTopic[n]},a.prototype.clear=function(){this.aliasToTopic={}},s.exports=a},{}],10:[function(i,s,r){const a=i("lru-cache"),n=i("number-allocator").NumberAllocator;function c(l){if(!(this instanceof c))return new c(l);l>0&&(this.aliasToTopic=new a({max:l}),this.topicToAlias={},this.numberAllocator=new n(1,l),this.max=l,this.length=0)}c.prototype.put=function(l,u){if(u===0||u>this.max)return!1;const h=this.aliasToTopic.get(u);return h&&delete this.topicToAlias[h],this.aliasToTopic.set(u,l),this.topicToAlias[l]=u,this.numberAllocator.use(u),this.length=this.aliasToTopic.length,!0},c.prototype.getTopicByAlias=function(l){return this.aliasToTopic.get(l)},c.prototype.getAliasByTopic=function(l){const u=this.topicToAlias[l];return u!==void 0&&this.aliasToTopic.get(u),u},c.prototype.clear=function(){this.aliasToTopic.reset(),this.topicToAlias={},this.numberAllocator.clear(),this.length=0},c.prototype.getLruAlias=function(){return this.numberAllocator.firstVacant()||this.aliasToTopic.keys()[this.aliasToTopic.length-1]},s.exports=c},{"lru-cache":37,"number-allocator":46}],11:[function(i,s,r){function a(n){const c=n.split("/");for(let l=0;l<c.length;l++)if(c[l]!=="+"){if(c[l]==="#")return l===c.length-1;if(c[l].indexOf("+")!==-1||c[l].indexOf("#")!==-1)return!1}return!0}s.exports={validateTopics:function(n){if(n.length===0)return"empty_topic_list";for(let c=0;c<n.length;c++)if(!a(n[c]))return n[c];return null}}},{}],12:[function(i,s,r){(function(a){(function(){const n=i("../client"),c=i("../store"),l=i("url"),u=i("xtend"),h=i("debug")("mqttjs"),v={};function f(g,y){if(h("connecting to an MQTT broker..."),typeof g!="object"||y||(y=g,g=null),y=y||{},g){const m=l.parse(g,!0);if(m.port!=null&&(m.port=Number(m.port)),(y=u(m,y)).protocol===null)throw new Error("Missing protocol");y.protocol=y.protocol.replace(/:$/,"")}if(function(m){let x;m.auth&&((x=m.auth.match(/^(.+):(.+)$/))?(m.username=x[1],m.password=x[2]):m.username=m.auth)}(y),y.query&&typeof y.query.clientId=="string"&&(y.clientId=y.query.clientId),y.cert&&y.key){if(!y.protocol)throw new Error("Missing secure protocol key");if(["mqtts","wss","wxs","alis"].indexOf(y.protocol)===-1)switch(y.protocol){case"mqtt":y.protocol="mqtts";break;case"ws":y.protocol="wss";break;case"wx":y.protocol="wxs";break;case"ali":y.protocol="alis";break;default:throw new Error('Unknown protocol for secure connection: "'+y.protocol+'"!')}}if(!v[y.protocol]){const m=["mqtts","wss"].indexOf(y.protocol)!==-1;y.protocol=["mqtt","mqtts","ws","wss","wx","wxs","ali","alis"].filter(function(x,k){return(!m||k%2!=0)&&typeof v[x]=="function"})[0]}if(y.clean===!1&&!y.clientId)throw new Error("Missing clientId for unclean clients");y.protocol&&(y.defaultProtocol=y.protocol);const p=new n(function(m){return y.servers&&(m._reconnectCount&&m._reconnectCount!==y.servers.length||(m._reconnectCount=0),y.host=y.servers[m._reconnectCount].host,y.port=y.servers[m._reconnectCount].port,y.protocol=y.servers[m._reconnectCount].protocol?y.servers[m._reconnectCount].protocol:y.defaultProtocol,y.hostname=y.host,m._reconnectCount++),h("calling streambuilder for",y.protocol),v[y.protocol](m,y)},y);return p.on("error",function(){}),p}a!==void 0&&a.title!=="browser"||typeof __webpack_require__!="function"?(v.mqtt=i("./tcp"),v.tcp=i("./tcp"),v.ssl=i("./tls"),v.tls=i("./tls"),v.mqtts=i("./tls")):(v.wx=i("./wx"),v.wxs=i("./wx"),v.ali=i("./ali"),v.alis=i("./ali")),v.ws=i("./ws"),v.wss=i("./ws"),s.exports=f,s.exports.connect=f,s.exports.MqttClient=n,s.exports.Store=c}).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(g){var y=v(g),p=y[0],m=y[1];return 3*(p+m)/4-m},r.toByteArray=function(g){var y,p,m=v(g),x=m[0],k=m[1],w=new c(function(_,L,E){return 3*(L+E)/4-E}(0,x,k)),C=0,I=k>0?x-4:x;for(p=0;p<I;p+=4)y=n[g.charCodeAt(p)]<<18|n[g.charCodeAt(p+1)]<<12|n[g.charCodeAt(p+2)]<<6|n[g.charCodeAt(p+3)],w[C++]=y>>16&255,w[C++]=y>>8&255,w[C++]=255&y;return k===2&&(y=n[g.charCodeAt(p)]<<2|n[g.charCodeAt(p+1)]>>4,w[C++]=255&y),k===1&&(y=n[g.charCodeAt(p)]<<10|n[g.charCodeAt(p+1)]<<4|n[g.charCodeAt(p+2)]>>2,w[C++]=y>>8&255,w[C++]=255&y),w},r.fromByteArray=function(g){for(var y,p=g.length,m=p%3,x=[],k=0,w=p-m;k<w;k+=16383)x.push(f(g,k,k+16383>w?w:k+16383));return m===1?(y=g[p-1],x.push(a[y>>2]+a[y<<4&63]+"==")):m===2&&(y=(g[p-2]<<8)+g[p-1],x.push(a[y>>10]+a[y>>4&63]+a[y<<2&63]+"=")),x.join("")};for(var a=[],n=[],c=typeof Uint8Array<"u"?Uint8Array:Array,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0,h=l.length;u<h;++u)a[u]=l[u],n[l.charCodeAt(u)]=u;function v(g){var y=g.length;if(y%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var p=g.indexOf("=");return p===-1&&(p=y),[p,p===y?0:4-p%4]}function f(g,y,p){for(var m,x,k=[],w=y;w<p;w+=3)m=(g[w]<<16&16711680)+(g[w+1]<<8&65280)+(255&g[w+2]),k.push(a[(x=m)>>18&63]+a[x>>12&63]+a[x>>6&63]+a[63&x]);return k.join("")}n[45]=62,n[95]=63},{}],14:[function(i,s,r){const{Buffer:a}=i("buffer"),n=Symbol.for("BufferList");function c(l){if(!(this instanceof c))return new c(l);c._init.call(this,l)}c._init=function(l){Object.defineProperty(this,n,{value:!0}),this._bufs=[],this.length=0,l&&this.append(l)},c.prototype._new=function(l){return new c(l)},c.prototype._offset=function(l){if(l===0)return[0,0];let u=0;for(let h=0;h<this._bufs.length;h++){const v=u+this._bufs[h].length;if(l<v||h===this._bufs.length-1)return[h,l-u];u=v}},c.prototype._reverseOffset=function(l){const u=l[0];let h=l[1];for(let v=0;v<u;v++)h+=this._bufs[v].length;return h},c.prototype.get=function(l){if(l>this.length||l<0)return;const u=this._offset(l);return this._bufs[u[0]][u[1]]},c.prototype.slice=function(l,u){return typeof l=="number"&&l<0&&(l+=this.length),typeof u=="number"&&u<0&&(u+=this.length),this.copy(null,0,l,u)},c.prototype.copy=function(l,u,h,v){if((typeof h!="number"||h<0)&&(h=0),(typeof v!="number"||v>this.length)&&(v=this.length),h>=this.length||v<=0)return l||a.alloc(0);const f=!!l,g=this._offset(h),y=v-h;let p=y,m=f&&u||0,x=g[1];if(h===0&&v===this.length){if(!f)return this._bufs.length===1?this._bufs[0]:a.concat(this._bufs,this.length);for(let k=0;k<this._bufs.length;k++)this._bufs[k].copy(l,m),m+=this._bufs[k].length;return l}if(p<=this._bufs[g[0]].length-x)return f?this._bufs[g[0]].copy(l,u,x,x+p):this._bufs[g[0]].slice(x,x+p);f||(l=a.allocUnsafe(y));for(let k=g[0];k<this._bufs.length;k++){const w=this._bufs[k].length-x;if(!(p>w)){this._bufs[k].copy(l,m,x,x+p),m+=w;break}this._bufs[k].copy(l,m,x),m+=w,p-=w,x&&(x=0)}return l.length>m?l.slice(0,m):l},c.prototype.shallowSlice=function(l,u){if(l=l||0,u=typeof u!="number"?this.length:u,l<0&&(l+=this.length),u<0&&(u+=this.length),l===u)return this._new();const h=this._offset(l),v=this._offset(u),f=this._bufs.slice(h[0],v[0]+1);return v[1]===0?f.pop():f[f.length-1]=f[f.length-1].slice(0,v[1]),h[1]!==0&&(f[0]=f[0].slice(h[1])),this._new(f)},c.prototype.toString=function(l,u,h){return this.slice(u,h).toString(l)},c.prototype.consume=function(l){if(l=Math.trunc(l),Number.isNaN(l)||l<=0)return this;for(;this._bufs.length;){if(!(l>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(l),this.length-=l;break}l-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},c.prototype.duplicate=function(){const l=this._new();for(let u=0;u<this._bufs.length;u++)l.append(this._bufs[u]);return l},c.prototype.append=function(l){if(l==null)return this;if(l.buffer)this._appendBuffer(a.from(l.buffer,l.byteOffset,l.byteLength));else if(Array.isArray(l))for(let u=0;u<l.length;u++)this.append(l[u]);else if(this._isBufferList(l))for(let u=0;u<l._bufs.length;u++)this.append(l._bufs[u]);else typeof l=="number"&&(l=l.toString()),this._appendBuffer(a.from(l));return this},c.prototype._appendBuffer=function(l){this._bufs.push(l),this.length+=l.length},c.prototype.indexOf=function(l,u,h){if(h===void 0&&typeof u=="string"&&(h=u,u=void 0),typeof l=="function"||Array.isArray(l))throw new TypeError('The "value" argument must be one of type string, Buffer, BufferList, or Uint8Array.');if(typeof l=="number"?l=a.from([l]):typeof l=="string"?l=a.from(l,h):this._isBufferList(l)?l=l.slice():Array.isArray(l.buffer)?l=a.from(l.buffer,l.byteOffset,l.byteLength):a.isBuffer(l)||(l=a.from(l)),u=Number(u||0),isNaN(u)&&(u=0),u<0&&(u=this.length+u),u<0&&(u=0),l.length===0)return u>this.length?this.length:u;const v=this._offset(u);let f=v[0],g=v[1];for(;f<this._bufs.length;f++){const y=this._bufs[f];for(;g<y.length;)if(y.length-g>=l.length){const p=y.indexOf(l,g);if(p!==-1)return this._reverseOffset([f,p]);g=y.length-l.length+1}else{const p=this._reverseOffset([f,g]);if(this._match(p,l))return p;g++}g=0}return-1},c.prototype._match=function(l,u){if(this.length-l<u.length)return!1;for(let h=0;h<u.length;h++)if(this.get(l+h)!==u[h])return!1;return!0},function(){const l={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 u in l)(function(h){c.prototype[h]=l[h]===null?function(v,f){return this.slice(v,v+f)[h](0,f)}:function(v=0){return this.slice(v,v+l[h])[h](0)}})(u)}(),c.prototype._isBufferList=function(l){return l instanceof c||c.isBufferList(l)},c.isBufferList=function(l){return l!=null&&l[n]},s.exports=c},{buffer:17}],15:[function(i,s,r){const a=i("readable-stream").Duplex,n=i("inherits"),c=i("./BufferList");function l(u){if(!(this instanceof l))return new l(u);if(typeof u=="function"){this._callback=u;const h=(function(v){this._callback&&(this._callback(v),this._callback=null)}).bind(this);this.on("pipe",function(v){v.on("error",h)}),this.on("unpipe",function(v){v.removeListener("error",h)}),u=null}c._init.call(this,u),a.call(this)}n(l,a),Object.assign(l.prototype,c.prototype),l.prototype._new=function(u){return new l(u)},l.prototype._write=function(u,h,v){this._appendBuffer(u),typeof v=="function"&&v()},l.prototype._read=function(u){if(!this.length)return this.push(null);u=Math.min(u,this.length),this.push(this.slice(0,u)),this.consume(u)},l.prototype.end=function(u){a.prototype.end.call(this,u),this._callback&&(this._callback(null,this.slice()),this._callback=null)},l.prototype._destroy=function(u,h){this._bufs.length=0,this.length=0,h(u)},l.prototype._isBufferList=function(u){return u instanceof l||u instanceof c||l.isBufferList(u)},l.isBufferList=c.isBufferList,s.exports=l,s.exports.BufferListStream=l,s.exports.BufferList=c},{"./BufferList":14,inherits:24,"readable-stream":69}],16:[function(i,s,r){},{}],17:[function(i,s,r){(function(a){(function(){var n=i("base64-js"),c=i("ieee754");r.Buffer=h,r.SlowBuffer=function(b){return+b!=b&&(b=0),h.alloc(+b)},r.INSPECT_MAX_BYTES=50;var l=2147483647;function u(b){if(b>l)throw new RangeError('The value "'+b+'" is invalid for option "size"');var T=new Uint8Array(b);return T.__proto__=h.prototype,T}function h(b,T,S){if(typeof b=="number"){if(typeof T=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return g(b)}return v(b,T,S)}function v(b,T,S){if(typeof b=="string")return function(U,J){if(typeof J=="string"&&J!==""||(J="utf8"),!h.isEncoding(J))throw new TypeError("Unknown encoding: "+J);var it=0|m(U,J),et=u(it),st=et.write(U,J);return st!==it&&(et=et.slice(0,st)),et}(b,T);if(ArrayBuffer.isView(b))return y(b);if(b==null)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof b);if(Q(b,ArrayBuffer)||b&&Q(b.buffer,ArrayBuffer))return function(U,J,it){if(J<0||U.byteLength<J)throw new RangeError('"offset" is outside of buffer bounds');if(U.byteLength<J+(it||0))throw new RangeError('"length" is outside of buffer bounds');var et;return et=J===void 0&&it===void 0?new Uint8Array(U):it===void 0?new Uint8Array(U,J):new Uint8Array(U,J,it),et.__proto__=h.prototype,et}(b,T,S);if(typeof b=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var D=b.valueOf&&b.valueOf();if(D!=null&&D!==b)return h.from(D,T,S);var W=function(U){if(h.isBuffer(U)){var J=0|p(U.length),it=u(J);return it.length===0||U.copy(it,0,0,J),it}if(U.length!==void 0)return typeof U.length!="number"||Z(U.length)?u(0):y(U);if(U.type==="Buffer"&&Array.isArray(U.data))return y(U.data)}(b);if(W)return W;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof b[Symbol.toPrimitive]=="function")return h.from(b[Symbol.toPrimitive]("string"),T,S);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof b)}function f(b){if(typeof b!="number")throw new TypeError('"size" argument must be of type number');if(b<0)throw new RangeError('The value "'+b+'" is invalid for option "size"')}function g(b){return f(b),u(b<0?0:0|p(b))}function y(b){for(var T=b.length<0?0:0|p(b.length),S=u(T),D=0;D<T;D+=1)S[D]=255&b[D];return S}function p(b){if(b>=l)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+l.toString(16)+" bytes");return 0|b}function m(b,T){if(h.isBuffer(b))return b.length;if(ArrayBuffer.isView(b)||Q(b,ArrayBuffer))return b.byteLength;if(typeof b!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof b);var S=b.length,D=arguments.length>2&&arguments[2]===!0;if(!D&&S===0)return 0;for(var W=!1;;)switch(T){case"ascii":case"latin1":case"binary":return S;case"utf8":case"utf-8":return K(b).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*S;case"hex":return S>>>1;case"base64":return G(b).length;default:if(W)return D?-1:K(b).length;T=(""+T).toLowerCase(),W=!0}}function x(b,T,S){var D=b[T];b[T]=b[S],b[S]=D}function k(b,T,S,D,W){if(b.length===0)return-1;if(typeof S=="string"?(D=S,S=0):S>2147483647?S=2147483647:S<-2147483648&&(S=-2147483648),Z(S=+S)&&(S=W?0:b.length-1),S<0&&(S=b.length+S),S>=b.length){if(W)return-1;S=b.length-1}else if(S<0){if(!W)return-1;S=0}if(typeof T=="string"&&(T=h.from(T,D)),h.isBuffer(T))return T.length===0?-1:w(b,T,S,D,W);if(typeof T=="number")return T&=255,typeof Uint8Array.prototype.indexOf=="function"?W?Uint8Array.prototype.indexOf.call(b,T,S):Uint8Array.prototype.lastIndexOf.call(b,T,S):w(b,[T],S,D,W);throw new TypeError("val must be string, number or Buffer")}function w(b,T,S,D,W){var U,J=1,it=b.length,et=T.length;if(D!==void 0&&((D=String(D).toLowerCase())==="ucs2"||D==="ucs-2"||D==="utf16le"||D==="utf-16le")){if(b.length<2||T.length<2)return-1;J=2,it/=2,et/=2,S/=2}function st(ct,rt){return J===1?ct[rt]:ct.readUInt16BE(rt*J)}if(W){var ot=-1;for(U=S;U<it;U++)if(st(b,U)===st(T,ot===-1?0:U-ot)){if(ot===-1&&(ot=U),U-ot+1===et)return ot*J}else ot!==-1&&(U-=U-ot),ot=-1}else for(S+et>it&&(S=it-et),U=S;U>=0;U--){for(var lt=!0,nt=0;nt<et;nt++)if(st(b,U+nt)!==st(T,nt)){lt=!1;break}if(lt)return U}return-1}function C(b,T,S,D){S=Number(S)||0;var W=b.length-S;D?(D=Number(D))>W&&(D=W):D=W;var U=T.length;D>U/2&&(D=U/2);for(var J=0;J<D;++J){var it=parseInt(T.substr(2*J,2),16);if(Z(it))return J;b[S+J]=it}return J}function I(b,T,S,D){return tt(K(T,b.length-S),b,S,D)}function _(b,T,S,D){return tt(function(W){for(var U=[],J=0;J<W.length;++J)U.push(255&W.charCodeAt(J));return U}(T),b,S,D)}function L(b,T,S,D){return _(b,T,S,D)}function E(b,T,S,D){return tt(G(T),b,S,D)}function F(b,T,S,D){return tt(function(W,U){for(var J,it,et,st=[],ot=0;ot<W.length&&!((U-=2)<0);++ot)J=W.charCodeAt(ot),it=J>>8,et=J%256,st.push(et),st.push(it);return st}(T,b.length-S),b,S,D)}function q(b,T,S){return T===0&&S===b.length?n.fromByteArray(b):n.fromByteArray(b.slice(T,S))}function R(b,T,S){S=Math.min(b.length,S);for(var D=[],W=T;W<S;){var U,J,it,et,st=b[W],ot=null,lt=st>239?4:st>223?3:st>191?2:1;if(W+lt<=S)switch(lt){case 1:st<128&&(ot=st);break;case 2:(192&(U=b[W+1]))==128&&(et=(31&st)<<6|63&U)>127&&(ot=et);break;case 3:U=b[W+1],J=b[W+2],(192&U)==128&&(192&J)==128&&(et=(15&st)<<12|(63&U)<<6|63&J)>2047&&(et<55296||et>57343)&&(ot=et);break;case 4:U=b[W+1],J=b[W+2],it=b[W+3],(192&U)==128&&(192&J)==128&&(192&it)==128&&(et=(15&st)<<18|(63&U)<<12|(63&J)<<6|63&it)>65535&&et<1114112&&(ot=et)}ot===null?(ot=65533,lt=1):ot>65535&&(ot-=65536,D.push(ot>>>10&1023|55296),ot=56320|1023&ot),D.push(ot),W+=lt}return function(nt){var ct=nt.length;if(ct<=A)return String.fromCharCode.apply(String,nt);for(var rt="",at=0;at<ct;)rt+=String.fromCharCode.apply(String,nt.slice(at,at+=A));return rt}(D)}r.kMaxLength=l,h.TYPED_ARRAY_SUPPORT=function(){try{var b=new Uint8Array(1);return b.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},b.foo()===42}catch{return!1}}(),h.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(h.prototype,"parent",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.buffer}}),Object.defineProperty(h.prototype,"offset",{enumerable:!0,get:function(){if(h.isBuffer(this))return this.byteOffset}}),typeof Symbol<"u"&&Symbol.species!=null&&h[Symbol.species]===h&&Object.defineProperty(h,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),h.poolSize=8192,h.from=function(b,T,S){return v(b,T,S)},h.prototype.__proto__=Uint8Array.prototype,h.__proto__=Uint8Array,h.alloc=function(b,T,S){return function(D,W,U){return f(D),D<=0?u(D):W!==void 0?typeof U=="string"?u(D).fill(W,U):u(D).fill(W):u(D)}(b,T,S)},h.allocUnsafe=function(b){return g(b)},h.allocUnsafeSlow=function(b){return g(b)},h.isBuffer=function(b){return b!=null&&b._isBuffer===!0&&b!==h.prototype},h.compare=function(b,T){if(Q(b,Uint8Array)&&(b=h.from(b,b.offset,b.byteLength)),Q(T,Uint8Array)&&(T=h.from(T,T.offset,T.byteLength)),!h.isBuffer(b)||!h.isBuffer(T))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(b===T)return 0;for(var S=b.length,D=T.length,W=0,U=Math.min(S,D);W<U;++W)if(b[W]!==T[W]){S=b[W],D=T[W];break}return S<D?-1:D<S?1:0},h.isEncoding=function(b){switch(String(b).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}},h.concat=function(b,T){if(!Array.isArray(b))throw new TypeError('"list" argument must be an Array of Buffers');if(b.length===0)return h.alloc(0);var S;if(T===void 0)for(T=0,S=0;S<b.length;++S)T+=b[S].length;var D=h.allocUnsafe(T),W=0;for(S=0;S<b.length;++S){var U=b[S];if(Q(U,Uint8Array)&&(U=h.from(U)),!h.isBuffer(U))throw new TypeError('"list" argument must be an Array of Buffers');U.copy(D,W),W+=U.length}return D},h.byteLength=m,h.prototype._isBuffer=!0,h.prototype.swap16=function(){var b=this.length;if(b%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var T=0;T<b;T+=2)x(this,T,T+1);return this},h.prototype.swap32=function(){var b=this.length;if(b%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var T=0;T<b;T+=4)x(this,T,T+3),x(this,T+1,T+2);return this},h.prototype.swap64=function(){var b=this.length;if(b%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var T=0;T<b;T+=8)x(this,T,T+7),x(this,T+1,T+6),x(this,T+2,T+5),x(this,T+3,T+4);return this},h.prototype.toString=function(){var b=this.length;return b===0?"":arguments.length===0?R(this,0,b):(function(T,S,D){var W=!1;if((S===void 0||S<0)&&(S=0),S>this.length||((D===void 0||D>this.length)&&(D=this.length),D<=0)||(D>>>=0)<=(S>>>=0))return"";for(T||(T="utf8");;)switch(T){case"hex":return H(this,S,D);case"utf8":case"utf-8":return R(this,S,D);case"ascii":return P(this,S,D);case"latin1":case"binary":return M(this,S,D);case"base64":return q(this,S,D);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return $(this,S,D);default:if(W)throw new TypeError("Unknown encoding: "+T);T=(T+"").toLowerCase(),W=!0}}).apply(this,arguments)},h.prototype.toLocaleString=h.prototype.toString,h.prototype.equals=function(b){if(!h.isBuffer(b))throw new TypeError("Argument must be a Buffer");return this===b||h.compare(this,b)===0},h.prototype.inspect=function(){var b="",T=r.INSPECT_MAX_BYTES;return b=this.toString("hex",0,T).replace(/(.{2})/g,"$1 ").trim(),this.length>T&&(b+=" ... "),"<Buffer "+b+">"},h.prototype.compare=function(b,T,S,D,W){if(Q(b,Uint8Array)&&(b=h.from(b,b.offset,b.byteLength)),!h.isBuffer(b))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof b);if(T===void 0&&(T=0),S===void 0&&(S=b?b.length:0),D===void 0&&(D=0),W===void 0&&(W=this.length),T<0||S>b.length||D<0||W>this.length)throw new RangeError("out of range index");if(D>=W&&T>=S)return 0;if(D>=W)return-1;if(T>=S)return 1;if(T>>>=0,S>>>=0,D>>>=0,W>>>=0,this===b)return 0;for(var U=W-D,J=S-T,it=Math.min(U,J),et=this.slice(D,W),st=b.slice(T,S),ot=0;ot<it;++ot)if(et[ot]!==st[ot]){U=et[ot],J=st[ot];break}return U<J?-1:J<U?1:0},h.prototype.includes=function(b,T,S){return this.indexOf(b,T,S)!==-1},h.prototype.indexOf=function(b,T,S){return k(this,b,T,S,!0)},h.prototype.lastIndexOf=function(b,T,S){return k(this,b,T,S,!1)},h.prototype.write=function(b,T,S,D){if(T===void 0)D="utf8",S=this.length,T=0;else if(S===void 0&&typeof T=="string")D=T,S=this.length,T=0;else{if(!isFinite(T))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");T>>>=0,isFinite(S)?(S>>>=0,D===void 0&&(D="utf8")):(D=S,S=void 0)}var W=this.length-T;if((S===void 0||S>W)&&(S=W),b.length>0&&(S<0||T<0)||T>this.length)throw new RangeError("Attempt to write outside buffer bounds");D||(D="utf8");for(var U=!1;;)switch(D){case"hex":return C(this,b,T,S);case"utf8":case"utf-8":return I(this,b,T,S);case"ascii":return _(this,b,T,S);case"latin1":case"binary":return L(this,b,T,S);case"base64":return E(this,b,T,S);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return F(this,b,T,S);default:if(U)throw new TypeError("Unknown encoding: "+D);D=(""+D).toLowerCase(),U=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var A=4096;function P(b,T,S){var D="";S=Math.min(b.length,S);for(var W=T;W<S;++W)D+=String.fromCharCode(127&b[W]);return D}function M(b,T,S){var D="";S=Math.min(b.length,S);for(var W=T;W<S;++W)D+=String.fromCharCode(b[W]);return D}function H(b,T,S){var D=b.length;(!T||T<0)&&(T=0),(!S||S<0||S>D)&&(S=D);for(var W="",U=T;U<S;++U)W+=Y(b[U]);return W}function $(b,T,S){for(var D=b.slice(T,S),W="",U=0;U<D.length;U+=2)W+=String.fromCharCode(D[U]+256*D[U+1]);return W}function X(b,T,S){if(b%1!=0||b<0)throw new RangeError("offset is not uint");if(b+T>S)throw new RangeError("Trying to access beyond buffer length")}function j(b,T,S,D,W,U){if(!h.isBuffer(b))throw new TypeError('"buffer" argument must be a Buffer instance');if(T>W||T<U)throw new RangeError('"value" argument is out of bounds');if(S+D>b.length)throw new RangeError("Index out of range")}function O(b,T,S,D,W,U){if(S+D>b.length)throw new RangeError("Index out of range");if(S<0)throw new RangeError("Index out of range")}function z(b,T,S,D,W){return T=+T,S>>>=0,W||O(b,0,S,4),c.write(b,T,S,D,23,4),S+4}function V(b,T,S,D,W){return T=+T,S>>>=0,W||O(b,0,S,8),c.write(b,T,S,D,52,8),S+8}h.prototype.slice=function(b,T){var S=this.length;b=~~b,T=T===void 0?S:~~T,b<0?(b+=S)<0&&(b=0):b>S&&(b=S),T<0?(T+=S)<0&&(T=0):T>S&&(T=S),T<b&&(T=b);var D=this.subarray(b,T);return D.__proto__=h.prototype,D},h.prototype.readUIntLE=function(b,T,S){b>>>=0,T>>>=0,S||X(b,T,this.length);for(var D=this[b],W=1,U=0;++U<T&&(W*=256);)D+=this[b+U]*W;return D},h.prototype.readUIntBE=function(b,T,S){b>>>=0,T>>>=0,S||X(b,T,this.length);for(var D=this[b+--T],W=1;T>0&&(W*=256);)D+=this[b+--T]*W;return D},h.prototype.readUInt8=function(b,T){return b>>>=0,T||X(b,1,this.length),this[b]},h.prototype.readUInt16LE=function(b,T){return b>>>=0,T||X(b,2,this.length),this[b]|this[b+1]<<8},h.prototype.readUInt16BE=function(b,T){return b>>>=0,T||X(b,2,this.length),this[b]<<8|this[b+1]},h.prototype.readUInt32LE=function(b,T){return b>>>=0,T||X(b,4,this.length),(this[b]|this[b+1]<<8|this[b+2]<<16)+16777216*this[b+3]},h.prototype.readUInt32BE=function(b,T){return b>>>=0,T||X(b,4,this.length),16777216*this[b]+(this[b+1]<<16|this[b+2]<<8|this[b+3])},h.prototype.readIntLE=function(b,T,S){b>>>=0,T>>>=0,S||X(b,T,this.length);for(var D=this[b],W=1,U=0;++U<T&&(W*=256);)D+=this[b+U]*W;return D>=(W*=128)&&(D-=Math.pow(2,8*T)),D},h.prototype.readIntBE=function(b,T,S){b>>>=0,T>>>=0,S||X(b,T,this.length);for(var D=T,W=1,U=this[b+--D];D>0&&(W*=256);)U+=this[b+--D]*W;return U>=(W*=128)&&(U-=Math.pow(2,8*T)),U},h.prototype.readInt8=function(b,T){return b>>>=0,T||X(b,1,this.length),128&this[b]?-1*(255-this[b]+1):this[b]},h.prototype.readInt16LE=function(b,T){b>>>=0,T||X(b,2,this.length);var S=this[b]|this[b+1]<<8;return 32768&S?4294901760|S:S},h.prototype.readInt16BE=function(b,T){b>>>=0,T||X(b,2,this.length);var S=this[b+1]|this[b]<<8;return 32768&S?4294901760|S:S},h.prototype.readInt32LE=function(b,T){return b>>>=0,T||X(b,4,this.length),this[b]|this[b+1]<<8|this[b+2]<<16|this[b+3]<<24},h.prototype.readInt32BE=function(b,T){return b>>>=0,T||X(b,4,this.length),this[b]<<24|this[b+1]<<16|this[b+2]<<8|this[b+3]},h.prototype.readFloatLE=function(b,T){return b>>>=0,T||X(b,4,this.length),c.read(this,b,!0,23,4)},h.prototype.readFloatBE=function(b,T){return b>>>=0,T||X(b,4,this.length),c.read(this,b,!1,23,4)},h.prototype.readDoubleLE=function(b,T){return b>>>=0,T||X(b,8,this.length),c.read(this,b,!0,52,8)},h.prototype.readDoubleBE=function(b,T){return b>>>=0,T||X(b,8,this.length),c.read(this,b,!1,52,8)},h.prototype.writeUIntLE=function(b,T,S,D){b=+b,T>>>=0,S>>>=0,D||j(this,b,T,S,Math.pow(2,8*S)-1,0);var W=1,U=0;for(this[T]=255&b;++U<S&&(W*=256);)this[T+U]=b/W&255;return T+S},h.prototype.writeUIntBE=function(b,T,S,D){b=+b,T>>>=0,S>>>=0,D||j(this,b,T,S,Math.pow(2,8*S)-1,0);var W=S-1,U=1;for(this[T+W]=255&b;--W>=0&&(U*=256);)this[T+W]=b/U&255;return T+S},h.prototype.writeUInt8=function(b,T,S){return b=+b,T>>>=0,S||j(this,b,T,1,255,0),this[T]=255&b,T+1},h.prototype.writeUInt16LE=function(b,T,S){return b=+b,T>>>=0,S||j(this,b,T,2,65535,0),this[T]=255&b,this[T+1]=b>>>8,T+2},h.prototype.writeUInt16BE=function(b,T,S){return b=+b,T>>>=0,S||j(this,b,T,2,65535,0),this[T]=b>>>8,this[T+1]=255&b,T+2},h.prototype.writeUInt32LE=function(b,T,S){return b=+b,T>>>=0,S||j(this,b,T,4,4294967295,0),this[T+3]=b>>>24,this[T+2]=b>>>16,this[T+1]=b>>>8,this[T]=255&b,T+4},h.prototype.writeUInt32BE=function(b,T,S){return b=+b,T>>>=0,S||j(this,b,T,4,4294967295,0),this[T]=b>>>24,this[T+1]=b>>>16,this[T+2]=b>>>8,this[T+3]=255&b,T+4},h.prototype.writeIntLE=function(b,T,S,D){if(b=+b,T>>>=0,!D){var W=Math.pow(2,8*S-1);j(this,b,T,S,W-1,-W)}var U=0,J=1,it=0;for(this[T]=255&b;++U<S&&(J*=256);)b<0&&it===0&&this[T+U-1]!==0&&(it=1),this[T+U]=(b/J>>0)-it&255;return T+S},h.prototype.writeIntBE=function(b,T,S,D){if(b=+b,T>>>=0,!D){var W=Math.pow(2,8*S-1);j(this,b,T,S,W-1,-W)}var U=S-1,J=1,it=0;for(this[T+U]=255&b;--U>=0&&(J*=256);)b<0&&it===0&&this[T+U+1]!==0&&(it=1),this[T+U]=(b/J>>0)-it&255;return T+S},h.prototype.writeInt8=function(b,T,S){return b=+b,T>>>=0,S||j(this,b,T,1,127,-128),b<0&&(b=255+b+1),this[T]=255&b,T+1},h.prototype.writeInt16LE=function(b,T,S){return b=+b,T>>>=0,S||j(this,b,T,2,32767,-32768),this[T]=255&b,this[T+1]=b>>>8,T+2},h.prototype.writeInt16BE=function(b,T,S){return b=+b,T>>>=0,S||j(this,b,T,2,32767,-32768),this[T]=b>>>8,this[T+1]=255&b,T+2},h.prototype.writeInt32LE=function(b,T,S){return b=+b,T>>>=0,S||j(this,b,T,4,2147483647,-2147483648),this[T]=255&b,this[T+1]=b>>>8,this[T+2]=b>>>16,this[T+3]=b>>>24,T+4},h.prototype.writeInt32BE=function(b,T,S){return b=+b,T>>>=0,S||j(this,b,T,4,2147483647,-2147483648),b<0&&(b=4294967295+b+1),this[T]=b>>>24,this[T+1]=b>>>16,this[T+2]=b>>>8,this[T+3]=255&b,T+4},h.prototype.writeFloatLE=function(b,T,S){return z(this,b,T,!0,S)},h.prototype.writeFloatBE=function(b,T,S){return z(this,b,T,!1,S)},h.prototype.writeDoubleLE=function(b,T,S){return V(this,b,T,!0,S)},h.prototype.writeDoubleBE=function(b,T,S){return V(this,b,T,!1,S)},h.prototype.copy=function(b,T,S,D){if(!h.isBuffer(b))throw new TypeError("argument should be a Buffer");if(S||(S=0),D||D===0||(D=this.length),T>=b.length&&(T=b.length),T||(T=0),D>0&&D<S&&(D=S),D===S||b.length===0||this.length===0)return 0;if(T<0)throw new RangeError("targetStart out of bounds");if(S<0||S>=this.length)throw new RangeError("Index out of range");if(D<0)throw new RangeError("sourceEnd out of bounds");D>this.length&&(D=this.length),b.length-T<D-S&&(D=b.length-T+S);var W=D-S;if(this===b&&typeof Uint8Array.prototype.copyWithin=="function")this.copyWithin(T,S,D);else if(this===b&&S<T&&T<D)for(var U=W-1;U>=0;--U)b[U+T]=this[U+S];else Uint8Array.prototype.set.call(b,this.subarray(S,D),T);return W},h.prototype.fill=function(b,T,S,D){if(typeof b=="string"){if(typeof T=="string"?(D=T,T=0,S=this.length):typeof S=="string"&&(D=S,S=this.length),D!==void 0&&typeof D!="string")throw new TypeError("encoding must be a string");if(typeof D=="string"&&!h.isEncoding(D))throw new TypeError("Unknown encoding: "+D);if(b.length===1){var W=b.charCodeAt(0);(D==="utf8"&&W<128||D==="latin1")&&(b=W)}}else typeof b=="number"&&(b&=255);if(T<0||this.length<T||this.length<S)throw new RangeError("Out of range index");if(S<=T)return this;var U;if(T>>>=0,S=S===void 0?this.length:S>>>0,b||(b=0),typeof b=="number")for(U=T;U<S;++U)this[U]=b;else{var J=h.isBuffer(b)?b:h.from(b,D),it=J.length;if(it===0)throw new TypeError('The value "'+b+'" is invalid for argument "value"');for(U=0;U<S-T;++U)this[U+T]=J[U%it]}return this};var N=/[^+/0-9A-Za-z-_]/g;function Y(b){return b<16?"0"+b.toString(16):b.toString(16)}function K(b,T){var S;T=T||1/0;for(var D=b.length,W=null,U=[],J=0;J<D;++J){if((S=b.charCodeAt(J))>55295&&S<57344){if(!W){if(S>56319){(T-=3)>-1&&U.push(239,191,189);continue}if(J+1===D){(T-=3)>-1&&U.push(239,191,189);continue}W=S;continue}if(S<56320){(T-=3)>-1&&U.push(239,191,189),W=S;continue}S=65536+(W-55296<<10|S-56320)}else W&&(T-=3)>-1&&U.push(239,191,189);if(W=null,S<128){if((T-=1)<0)break;U.push(S)}else if(S<2048){if((T-=2)<0)break;U.push(S>>6|192,63&S|128)}else if(S<65536){if((T-=3)<0)break;U.push(S>>12|224,S>>6&63|128,63&S|128)}else{if(!(S<1114112))throw new Error("Invalid code point");if((T-=4)<0)break;U.push(S>>18|240,S>>12&63|128,S>>6&63|128,63&S|128)}}return U}function G(b){return n.toByteArray(function(T){if((T=(T=T.split("=")[0]).trim().replace(N,"")).length<2)return"";for(;T.length%4!=0;)T+="=";return T}(b))}function tt(b,T,S,D){for(var W=0;W<D&&!(W+S>=T.length||W>=b.length);++W)T[W+S]=b[W];return W}function Q(b,T){return b instanceof T||b!=null&&b.constructor!=null&&b.constructor.name!=null&&b.constructor.name===T.name}function Z(b){return b!=b}}).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(c){if(c[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+c[0]+(this.useColors?"%c ":" ")+"+"+s.exports.humanize(this.diff),!this.useColors)return;const l="color: "+this.color;c.splice(1,0,l,"color: inherit");let u=0,h=0;c[0].replace(/%[a-zA-Z%]/g,v=>{v!=="%%"&&v==="%c"&&(h=++u)}),c.splice(h,0,l)},r.save=function(c){try{c?r.storage.setItem("debug",c):r.storage.removeItem("debug")}catch{}},r.load=function(){let c;try{c=r.storage.getItem("debug")}catch{}return!c&&a!==void 0&&"env"in a&&(c=a.env.DEBUG),c},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 c=!1;return()=>{c||(c=!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:n}=s.exports;n.j=function(c){try{return JSON.stringify(c)}catch(l){return"[UnexpectedJSONParseError]: "+l.message}}}).call(this)}).call(this,i("_process"))},{"./common":19,_process:50}],19:[function(i,s,r){s.exports=function(a){function n(u){let h,v,f,g=null;function y(...p){if(!y.enabled)return;const m=y,x=Number(new Date),k=x-(h||x);m.diff=k,m.prev=h,m.curr=x,h=x,p[0]=n.coerce(p[0]),typeof p[0]!="string"&&p.unshift("%O");let w=0;p[0]=p[0].replace(/%([a-zA-Z%])/g,(C,I)=>{if(C==="%%")return"%";w++;const _=n.formatters[I];if(typeof _=="function"){const L=p[w];C=_.call(m,L),p.splice(w,1),w--}return C}),n.formatArgs.call(m,p),(m.log||n.log).apply(m,p)}return y.namespace=u,y.useColors=n.useColors(),y.color=n.selectColor(u),y.extend=c,y.destroy=n.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>g!==null?g:(v!==n.namespaces&&(v=n.namespaces,f=n.enabled(u)),f),set:p=>{g=p}}),typeof n.init=="function"&&n.init(y),y}function c(u,h){const v=n(this.namespace+(h===void 0?":":h)+u);return v.log=this.log,v}function l(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}return n.debug=n,n.default=n,n.coerce=function(u){return u instanceof Error?u.stack||u.message:u},n.disable=function(){const u=[...n.names.map(l),...n.skips.map(l).map(h=>"-"+h)].join(",");return n.enable(""),u},n.enable=function(u){let h;n.save(u),n.namespaces=u,n.names=[],n.skips=[];const v=(typeof u=="string"?u:"").split(/[\s,]+/),f=v.length;for(h=0;h<f;h++)v[h]&&((u=v[h].replace(/\*/g,".*?"))[0]==="-"?n.skips.push(new RegExp("^"+u.substr(1)+"$")):n.names.push(new RegExp("^"+u+"$")))},n.enabled=function(u){if(u[u.length-1]==="*")return!0;let h,v;for(h=0,v=n.skips.length;h<v;h++)if(n.skips[h].test(u))return!1;for(h=0,v=n.names.length;h<v;h++)if(n.names[h].test(u))return!0;return!1},n.humanize=i("ms"),n.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(u=>{n[u]=a[u]}),n.names=[],n.skips=[],n.formatters={},n.selectColor=function(u){let h=0;for(let v=0;v<u.length;v++)h=(h<<5)-h+u.charCodeAt(v),h|=0;return n.colors[Math.abs(h)%n.colors.length]},n.enable(n.load()),n}},{ms:45}],20:[function(i,s,r){(function(a,n){(function(){var c=i("readable-stream"),l=i("end-of-stream"),u=i("inherits"),h=i("stream-shift"),v=n.from&&n.from!==Uint8Array.from?n.from([0]):new n([0]),f=function(m,x){m._corked?m.once("uncork",x):x()},g=function(m,x){return function(k){k?function(w,C){w._autoDestroy&&w.destroy(C)}(m,k.message==="premature close"?null:k):x&&!m._ended&&m.end()}},y=function(){},p=function(m,x,k){if(!(this instanceof p))return new p(m,x,k);c.Duplex.call(this,k),this._writable=null,this._readable=null,this._readable2=null,this._autoDestroy=!k||k.autoDestroy!==!1,this._forwardDestroy=!k||k.destroy!==!1,this._forwardEnd=!k||k.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,m&&this.setWritable(m),x&&this.setReadable(x)};u(p,c.Duplex),p.obj=function(m,x,k){return k||(k={}),k.objectMode=!0,k.highWaterMark=16,new p(m,x,k)},p.prototype.cork=function(){++this._corked==1&&this.emit("cork")},p.prototype.uncork=function(){this._corked&&--this._corked==0&&this.emit("uncork")},p.prototype.setWritable=function(m){if(this._unwrite&&this._unwrite(),this.destroyed)m&&m.destroy&&m.destroy();else if(m!==null&&m!==!1){var x=this,k=l(m,{writable:!0,readable:!1},g(this,this._forwardEnd)),w=function(){var C=x._ondrain;x._ondrain=null,C&&C()};this._unwrite&&a.nextTick(w),this._writable=m,this._writable.on("drain",w),this._unwrite=function(){x._writable.removeListener("drain",w),k()},this.uncork()}else this.end()},p.prototype.setReadable=function(m){if(this._unread&&this._unread(),this.destroyed)m&&m.destroy&&m.destroy();else{if(m===null||m===!1)return this.push(null),void this.resume();var x,k=this,w=l(m,{writable:!1,readable:!0},g(this)),C=function(){k._forward()},I=function(){k.push(null)};this._drained=!0,this._readable=m,this._readable2=m._readableState?m:(x=m,new c.Readable({objectMode:!0,highWaterMark:16}).wrap(x)),this._readable2.on("readable",C),this._readable2.on("end",I),this._unread=function(){k._readable2.removeListener("readable",C),k._readable2.removeListener("end",I),w()},this._forward()}},p.prototype._read=function(){this._drained=!0,this._forward()},p.prototype._forward=function(){if(!this._forwarding&&this._readable2&&this._drained){var m;for(this._forwarding=!0;this._drained&&(m=h(this._readable2))!==null;)this.destroyed||(this._drained=this.push(m));this._forwarding=!1}},p.prototype.destroy=function(m,x){if(x||(x=y),this.destroyed)return x(null);this.destroyed=!0;var k=this;a.nextTick(function(){k._destroy(m),x(null)})},p.prototype._destroy=function(m){if(m){var x=this._ondrain;this._ondrain=null,x?x(m):this.emit("error",m)}this._forwardDestroy&&(this._readable&&this._readable.destroy&&this._readable.destroy(),this._writable&&this._writable.destroy&&this._writable.destroy()),this.emit("close")},p.prototype._write=function(m,x,k){if(!this.destroyed)return this._corked?f(this,this._write.bind(this,m,x,k)):m===v?this._finish(k):this._writable?void(this._writable.write(m)===!1?this._ondrain=k:this.destroyed||k()):k()},p.prototype._finish=function(m){var x=this;this.emit("preend"),f(this,function(){var k,w;k=x._forwardEnd&&x._writable,w=function(){x._writableState.prefinished===!1&&(x._writableState.prefinished=!0),x.emit("prefinish"),f(x,m)},k?k._writableState&&k._writableState.finished?w():k._writableState?k.end(w):(k.end(),w()):w()})},p.prototype.end=function(m,x,k){return typeof m=="function"?this.end(null,null,m):typeof x=="function"?this.end(m,null,x):(this._ended=!0,m&&this.write(m),this._writableState.ending||this._writableState.destroyed||this.write(v),c.Writable.prototype.end.call(this,k))},s.exports=p}).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 n=i("once"),c=function(){},l=function(u,h,v){if(typeof h=="function")return l(u,null,h);h||(h={}),v=n(v||c);var f=u._writableState,g=u._readableState,y=h.readable||h.readable!==!1&&u.readable,p=h.writable||h.writable!==!1&&u.writable,m=!1,x=function(){u.writable||k()},k=function(){p=!1,y||v.call(u)},w=function(){y=!1,p||v.call(u)},C=function(F){v.call(u,F?new Error("exited with error code: "+F):null)},I=function(F){v.call(u,F)},_=function(){a.nextTick(L)},L=function(){if(!m)return(!y||g&&g.ended&&!g.destroyed)&&(!p||f&&f.ended&&!f.destroyed)?void 0:v.call(u,new Error("premature close"))},E=function(){u.req.on("finish",k)};return function(F){return F.setHeader&&typeof F.abort=="function"}(u)?(u.on("complete",k),u.on("abort",_),u.req?E():u.on("request",E)):p&&!f&&(u.on("end",x),u.on("close",x)),function(F){return F.stdio&&Array.isArray(F.stdio)&&F.stdio.length===3}(u)&&u.on("exit",C),u.on("end",w),u.on("finish",k),h.error!==!1&&u.on("error",I),u.on("close",_),function(){m=!0,u.removeListener("complete",k),u.removeListener("abort",_),u.removeListener("request",E),u.req&&u.req.removeListener("finish",k),u.removeListener("end",x),u.removeListener("close",x),u.removeListener("finish",k),u.removeListener("exit",C),u.removeListener("end",w),u.removeListener("error",I),u.removeListener("close",_)}};s.exports=l}).call(this)}).call(this,i("_process"))},{_process:50,once:48}],22:[function(i,s,r){var a=Object.create||function(w){var C=function(){};return C.prototype=w,new C},n=Object.keys||function(w){var C=[];for(var I in w)Object.prototype.hasOwnProperty.call(w,I)&&C.push(I);return I},c=Function.prototype.bind||function(w){var C=this;return function(){return C.apply(w,arguments)}};function l(){this._events&&Object.prototype.hasOwnProperty.call(this,"_events")||(this._events=a(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0}s.exports=l,l.EventEmitter=l,l.prototype._events=void 0,l.prototype._maxListeners=void 0;var u,h=10;try{var v={};Object.defineProperty&&Object.defineProperty(v,"x",{value:0}),u=v.x===0}catch{u=!1}function f(w){return w._maxListeners===void 0?l.defaultMaxListeners:w._maxListeners}function g(w,C,I,_){var L,E,F;if(typeof I!="function")throw new TypeError('"listener" argument must be a function');if((E=w._events)?(E.newListener&&(w.emit("newListener",C,I.listener?I.listener:I),E=w._events),F=E[C]):(E=w._events=a(null),w._eventsCount=0),F){if(typeof F=="function"?F=E[C]=_?[I,F]:[F,I]:_?F.unshift(I):F.push(I),!F.warned&&(L=f(w))&&L>0&&F.length>L){F.warned=!0;var q=new Error("Possible EventEmitter memory leak detected. "+F.length+' "'+String(C)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');q.name="MaxListenersExceededWarning",q.emitter=w,q.type=C,q.count=F.length,typeof console=="object"&&console.warn&&console.warn("%s: %s",q.name,q.message)}}else F=E[C]=I,++w._eventsCount;return w}function y(){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 w=new Array(arguments.length),C=0;C<w.length;++C)w[C]=arguments[C];this.listener.apply(this.target,w)}}function p(w,C,I){var _={fired:!1,wrapFn:void 0,target:w,type:C,listener:I},L=c.call(y,_);return L.listener=I,_.wrapFn=L,L}function m(w,C,I){var _=w._events;if(!_)return[];var L=_[C];return L?typeof L=="function"?I?[L.listener||L]:[L]:I?function(E){for(var F=new Array(E.length),q=0;q<F.length;++q)F[q]=E[q].listener||E[q];return F}(L):k(L,L.length):[]}function x(w){var C=this._events;if(C){var I=C[w];if(typeof I=="function")return 1;if(I)return I.length}return 0}function k(w,C){for(var I=new Array(C),_=0;_<C;++_)I[_]=w[_];return I}u?Object.defineProperty(l,"defaultMaxListeners",{enumerable:!0,get:function(){return h},set:function(w){if(typeof w!="number"||w<0||w!=w)throw new TypeError('"defaultMaxListeners" must be a positive number');h=w}}):l.defaultMaxListeners=h,l.prototype.setMaxListeners=function(w){if(typeof w!="number"||w<0||isNaN(w))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=w,this},l.prototype.getMaxListeners=function(){return f(this)},l.prototype.emit=function(w){var C,I,_,L,E,F,q=w==="error";if(F=this._events)q=q&&F.error==null;else if(!q)return!1;if(q){if(arguments.length>1&&(C=arguments[1]),C instanceof Error)throw C;var R=new Error('Unhandled "error" event. ('+C+")");throw R.context=C,R}if(!(I=F[w]))return!1;var A=typeof I=="function";switch(_=arguments.length){case 1:(function(P,M,H){if(M)P.call(H);else for(var $=P.length,X=k(P,$),j=0;j<$;++j)X[j].call(H)})(I,A,this);break;case 2:(function(P,M,H,$){if(M)P.call(H,$);else for(var X=P.length,j=k(P,X),O=0;O<X;++O)j[O].call(H,$)})(I,A,this,arguments[1]);break;case 3:(function(P,M,H,$,X){if(M)P.call(H,$,X);else for(var j=P.length,O=k(P,j),z=0;z<j;++z)O[z].call(H,$,X)})(I,A,this,arguments[1],arguments[2]);break;case 4:(function(P,M,H,$,X,j){if(M)P.call(H,$,X,j);else for(var O=P.length,z=k(P,O),V=0;V<O;++V)z[V].call(H,$,X,j)})(I,A,this,arguments[1],arguments[2],arguments[3]);break;default:for(L=new Array(_-1),E=1;E<_;E++)L[E-1]=arguments[E];(function(P,M,H,$){if(M)P.apply(H,$);else for(var X=P.length,j=k(P,X),O=0;O<X;++O)j[O].apply(H,$)})(I,A,this,L)}return!0},l.prototype.addListener=function(w,C){return g(this,w,C,!1)},l.prototype.on=l.prototype.addListener,l.prototype.prependListener=function(w,C){return g(this,w,C,!0)},l.prototype.once=function(w,C){if(typeof C!="function")throw new TypeError('"listener" argument must be a function');return this.on(w,p(this,w,C)),this},l.prototype.prependOnceListener=function(w,C){if(typeof C!="function")throw new TypeError('"listener" argument must be a function');return this.prependListener(w,p(this,w,C)),this},l.prototype.removeListener=function(w,C){var I,_,L,E,F;if(typeof C!="function")throw new TypeError('"listener" argument must be a function');if(!(_=this._events))return this;if(!(I=_[w]))return this;if(I===C||I.listener===C)--this._eventsCount==0?this._events=a(null):(delete _[w],_.removeListener&&this.emit("removeListener",w,I.listener||C));else if(typeof I!="function"){for(L=-1,E=I.length-1;E>=0;E--)if(I[E]===C||I[E].listener===C){F=I[E].listener,L=E;break}if(L<0)return this;L===0?I.shift():function(q,R){for(var A=R,P=A+1,M=q.length;P<M;A+=1,P+=1)q[A]=q[P];q.pop()}(I,L),I.length===1&&(_[w]=I[0]),_.removeListener&&this.emit("removeListener",w,F||C)}return this},l.prototype.removeAllListeners=function(w){var C,I,_;if(!(I=this._events))return this;if(!I.removeListener)return arguments.length===0?(this._events=a(null),this._eventsCount=0):I[w]&&(--this._eventsCount==0?this._events=a(null):delete I[w]),this;if(arguments.length===0){var L,E=n(I);for(_=0;_<E.length;++_)(L=E[_])!=="removeListener"&&this.removeAllListeners(L);return this.removeAllListeners("removeListener"),this._events=a(null),this._eventsCount=0,this}if(typeof(C=I[w])=="function")this.removeListener(w,C);else if(C)for(_=C.length-1;_>=0;_--)this.removeListener(w,C[_]);return this},l.prototype.listeners=function(w){return m(this,w,!0)},l.prototype.rawListeners=function(w){return m(this,w,!1)},l.listenerCount=function(w,C){return typeof w.listenerCount=="function"?w.listenerCount(C):x.call(w,C)},l.prototype.listenerCount=x,l.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],23:[function(i,s,r){r.read=function(a,n,c,l,u){var h,v,f=8*u-l-1,g=(1<<f)-1,y=g>>1,p=-7,m=c?u-1:0,x=c?-1:1,k=a[n+m];for(m+=x,h=k&(1<<-p)-1,k>>=-p,p+=f;p>0;h=256*h+a[n+m],m+=x,p-=8);for(v=h&(1<<-p)-1,h>>=-p,p+=l;p>0;v=256*v+a[n+m],m+=x,p-=8);if(h===0)h=1-y;else{if(h===g)return v?NaN:1/0*(k?-1:1);v+=Math.pow(2,l),h-=y}return(k?-1:1)*v*Math.pow(2,h-l)},r.write=function(a,n,c,l,u,h){var v,f,g,y=8*h-u-1,p=(1<<y)-1,m=p>>1,x=u===23?Math.pow(2,-24)-Math.pow(2,-77):0,k=l?0:h-1,w=l?1:-1,C=n<0||n===0&&1/n<0?1:0;for(n=Math.abs(n),isNaN(n)||n===1/0?(f=isNaN(n)?1:0,v=p):(v=Math.floor(Math.log(n)/Math.LN2),n*(g=Math.pow(2,-v))<1&&(v--,g*=2),(n+=v+m>=1?x/g:x*Math.pow(2,1-m))*g>=2&&(v++,g/=2),v+m>=p?(f=0,v=p):v+m>=1?(f=(n*g-1)*Math.pow(2,u),v+=m):(f=n*Math.pow(2,m-1)*Math.pow(2,u),v=0));u>=8;a[c+k]=255&f,k+=w,f/=256,u-=8);for(v=v<<u|f,y+=u;y>0;a[c+k]=255&v,k+=w,v/=256,y-=8);a[c+k-w]|=128*C}},{}],24:[function(i,s,r){typeof Object.create=="function"?s.exports=function(a,n){n&&(a.super_=n,a.prototype=Object.create(n.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}))}:s.exports=function(a,n){if(n){a.super_=n;var c=function(){};c.prototype=n.prototype,a.prototype=new c,a.prototype.constructor=a}}},{}],25:[function(i,s,r){Object.defineProperty(r,"__esModule",{value:!0});var a=function(){function n(c,l){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=c,this.value=l}return n.prototype.rotateLeft=function(){var c=this.parent,l=this.brother,u=this.leftChild,h=this.rightChild;if(!h)throw new Error("unknown error");var v=h.leftChild,f=h.rightChild;return c&&(c.leftChild===this?c.leftChild=h:c.rightChild===this&&(c.rightChild=h)),h.parent=c,h.brother=l,h.leftChild=this,h.rightChild=f,l&&(l.brother=h),this.parent=h,this.brother=f,this.leftChild=u,this.rightChild=v,f&&(f.parent=h,f.brother=this),u&&(u.parent=this,u.brother=v),v&&(v.parent=this,v.brother=u),h},n.prototype.rotateRight=function(){var c=this.parent,l=this.brother,u=this.leftChild;if(!u)throw new Error("unknown error");var h=this.rightChild,v=u.leftChild,f=u.rightChild;return c&&(c.leftChild===this?c.leftChild=u:c.rightChild===this&&(c.rightChild=u)),u.parent=c,u.brother=l,u.leftChild=v,u.rightChild=this,l&&(l.brother=u),v&&(v.parent=u,v.brother=this),this.parent=u,this.brother=v,this.leftChild=f,this.rightChild=h,f&&(f.parent=this,f.brother=h),h&&(h.parent=this,h.brother=f),u},n.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},n.TreeNodeColorType={red:!0,black:!1},n}();Object.freeze(a),r.default=a},{}],26:[function(i,s,r){var a=this&&this.__generator||function(c,l){var u,h,v,f,g={label:0,sent:function(){if(1&v[0])throw v[1];return v[1]},trys:[],ops:[]};return f={next:y(0),throw:y(1),return:y(2)},typeof Symbol=="function"&&(f[Symbol.iterator]=function(){return this}),f;function y(p){return function(m){return function(x){if(u)throw new TypeError("Generator is already executing.");for(;g;)try{if(u=1,h&&(v=2&x[0]?h.return:x[0]?h.throw||((v=h.return)&&v.call(h),0):h.next)&&!(v=v.call(h,x[1])).done)return v;switch(h=0,v&&(x=[2&x[0],v.value]),x[0]){case 0:case 1:v=x;break;case 4:return g.label++,{value:x[1],done:!1};case 5:g.label++,h=x[1],x=[0];continue;case 7:x=g.ops.pop(),g.trys.pop();continue;default:if(!(v=(v=g.trys).length>0&&v[v.length-1])&&(x[0]===6||x[0]===2)){g=0;continue}if(x[0]===3&&(!v||x[1]>v[0]&&x[1]<v[3])){g.label=x[1];break}if(x[0]===6&&g.label<v[1]){g.label=v[1],v=x;break}if(v&&g.label<v[2]){g.label=v[2],g.ops.push(x);break}v[2]&&g.ops.pop(),g.trys.pop();continue}x=l.call(c,g)}catch(k){x=[6,k],h=0}finally{u=v=0}if(5&x[0])throw x[1];return{value:x[0]?x[1]:void 0,done:!0}}([p,m])}}};function n(c){var l=this;c===void 0&&(c=[]);var u=[],h=0,v=0,f=0,g=0,y=0,p=0;this.size=function(){return p},this.empty=function(){return p===0},this.clear=function(){h=f=v=g=y=p=0,x.call(this,n.bucketSize),p=0},this.front=function(){return u[h][v]},this.back=function(){return u[f][g]},this.forEach=function(k){if(!this.empty()){var w=0;if(h!==f){for(I=v;I<n.bucketSize;++I)k(u[h][I],w++);for(I=h+1;I<f;++I)for(var C=0;C<n.bucketSize;++C)k(u[I][C],w++);for(I=0;I<=g;++I)k(u[f][I],w++)}else for(var I=v;I<=g;++I)k(u[h][I],w++)}};var m=function(k){var w=h*n.bucketSize+v,C=w+k,I=f*n.bucketSize+g;if(C<w||C>I)throw new Error("pos should more than 0 and less than queue's size");return{curNodeBucketIndex:Math.floor(C/n.bucketSize),curNodePointerIndex:C%n.bucketSize}};this.getElementByPos=function(k){var w=m(k),C=w.curNodeBucketIndex,I=w.curNodePointerIndex;return u[C][I]},this.eraseElementByPos=function(k){var w=this;if(k<0||k>p)throw new Error("pos should more than 0 and less than queue's size");if(k===0)this.popFront();else if(k===this.size())this.popBack();else{for(var C=[],I=k+1;I<p;++I)C.push(this.getElementByPos(I));this.cut(k),this.popBack(),C.forEach(function(_){return w.pushBack(_)})}},this.eraseElementByValue=function(k){if(!this.empty()){var w=[];this.forEach(function(_){_!==k&&w.push(_)});for(var C=w.length,I=0;I<C;++I)this.setElementByPos(I,w[I]);this.cut(C-1)}};var x=function(k){for(var w=[],C=k*n.sigma,I=Math.max(Math.ceil(C/n.bucketSize),2),_=0;_<I;++_)w.push(new Array(n.bucketSize));var L=Math.ceil(k/n.bucketSize),E=Math.floor(I/2)-Math.floor(L/2),F=E,q=0;if(this.size())for(_=0;_<L;++_){for(var R=0;R<n.bucketSize;++R)if(w[E+_][R]=this.front(),this.popFront(),this.empty()){F=E+_,q=R;break}if(this.empty())break}u=w,h=E,v=0,f=F,g=q,y=I,p=k};this.pushBack=function(k){this.empty()||(f===y-1&&g===n.bucketSize-1&&x.call(this,this.size()),g<n.bucketSize-1?++g:f<y-1&&(++f,g=0)),++p,u[f][g]=k},this.popBack=function(){this.empty()||(this.size()!==1&&(g>0?--g:h<f&&(--f,g=n.bucketSize-1)),p>0&&--p)},this.setElementByPos=function(k,w){var C=m(k),I=C.curNodeBucketIndex,_=C.curNodePointerIndex;u[I][_]=w},this.insert=function(k,w,C){var I=this;if(C===void 0&&(C=1),k===0)for(;C--;)this.pushFront(w);else if(k===this.size())for(;C--;)this.pushBack(w);else{for(var _=[],L=k;L<p;++L)_.push(this.getElementByPos(L));for(this.cut(k-1),L=0;L<C;++L)this.pushBack(w);_.forEach(function(E){return I.pushBack(E)})}},this.find=function(k){if(h===f){for(var w=v;w<=g;++w)if(u[h][w]===k)return!0;return!1}for(w=v;w<n.bucketSize;++w)if(u[h][w]===k)return!0;for(w=h+1;w<f;++w)for(var C=0;C<n.bucketSize;++C)if(u[w][C]===k)return!0;for(w=0;w<=g;++w)if(u[f][w]===k)return!0;return!1},this.reverse=function(){for(var k=0,w=p-1;k<w;){var C=this.getElementByPos(k);this.setElementByPos(k,this.getElementByPos(w)),this.setElementByPos(w,C),++k,--w}},this.unique=function(){if(!this.empty()){var k=[],w=this.front();this.forEach(function(I,_){_!==0&&I===w||(k.push(I),w=I)});for(var C=0;C<p;++C)this.setElementByPos(C,k[C]);this.cut(k.length-1)}},this.sort=function(k){var w=[];this.forEach(function(I){w.push(I)}),w.sort(k);for(var C=0;C<p;++C)this.setElementByPos(C,w[C])},this.pushFront=function(k){this.empty()||(h===0&&v===0&&x.call(this,this.size()),v>0?--v:h>0&&(--h,v=n.bucketSize-1)),++p,u[h][v]=k},this.popFront=function(){this.empty()||(this.size()!==1&&(v<n.bucketSize-1?++v:h<f&&(++h,v=0)),p>0&&--p)},this.shrinkToFit=function(){var k=this,w=[];this.forEach(function(L){w.push(L)});var C=w.length;u=[];for(var I=Math.ceil(C/n.bucketSize),_=0;_<I;++_)u.push(new Array(n.bucketSize));this.clear(),w.forEach(function(L){return k.pushBack(L)})},this.cut=function(k){if(k<0)this.clear();else{var w=m(k),C=w.curNodeBucketIndex,I=w.curNodePointerIndex;f=C,g=I,p=k+1}},this[Symbol.iterator]=function(){return function(){var k,w;return a(this,function(C){switch(C.label){case 0:if(p===0)return[2];if(h!==f)return[3,5];w=v,C.label=1;case 1:return w<=g?[4,u[h][w]]:[3,4];case 2:C.sent(),C.label=3;case 3:return++w,[3,1];case 4:return[2];case 5:w=v,C.label=6;case 6:return w<n.bucketSize?[4,u[h][w]]:[3,9];case 7:C.sent(),C.label=8;case 8:return++w,[3,6];case 9:w=h+1,C.label=10;case 10:if(!(w<f))return[3,15];k=0,C.label=11;case 11:return k<n.bucketSize?[4,u[w][k]]:[3,14];case 12:C.sent(),C.label=13;case 13:return++k,[3,11];case 14:return++w,[3,10];case 15:w=0,C.label=16;case 16:return w<=g?[4,u[f][w]]:[3,19];case 17:C.sent(),C.label=18;case 18:return++w,[3,16];case 19:return[2]}})}()},function(){var k=n.bucketSize;c.size?k=c.size():c.length&&(k=c.length);var w=k*n.sigma;y=Math.ceil(w/n.bucketSize),y=Math.max(y,3);for(var C=0;C<y;++C)u.push(new Array(n.bucketSize));var I=Math.ceil(k/n.bucketSize);h=Math.floor(y/2)-Math.floor(I/2),f=h,c.forEach(function(_){return l.pushBack(_)})}(),Object.freeze(this)}Object.defineProperty(r,"__esModule",{value:!0}),n.sigma=3,n.bucketSize=5e3,Object.freeze(n),r.default=n},{}],27:[function(i,s,r){var a=this&&this.__generator||function(h,v){var f,g,y,p,m={label:0,sent:function(){if(1&y[0])throw y[1];return y[1]},trys:[],ops:[]};return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(k){return function(w){return function(C){if(f)throw new TypeError("Generator is already executing.");for(;m;)try{if(f=1,g&&(y=2&C[0]?g.return:C[0]?g.throw||((y=g.return)&&y.call(g),0):g.next)&&!(y=y.call(g,C[1])).done)return y;switch(g=0,y&&(C=[2&C[0],y.value]),C[0]){case 0:case 1:y=C;break;case 4:return m.label++,{value:C[1],done:!1};case 5:m.label++,g=C[1],C=[0];continue;case 7:C=m.ops.pop(),m.trys.pop();continue;default:if(!(y=(y=m.trys).length>0&&y[y.length-1])&&(C[0]===6||C[0]===2)){m=0;continue}if(C[0]===3&&(!y||C[1]>y[0]&&C[1]<y[3])){m.label=C[1];break}if(C[0]===6&&m.label<y[1]){m.label=y[1],y=C;break}if(y&&m.label<y[2]){m.label=y[2],m.ops.push(C);break}y[2]&&m.ops.pop(),m.trys.pop();continue}C=v.call(h,m)}catch(I){C=[6,I],g=0}finally{f=y=0}if(5&C[0])throw C[1];return{value:C[0]?C[1]:void 0,done:!0}}([k,w])}}},n=this&&this.__values||function(h){var v=typeof Symbol=="function"&&Symbol.iterator,f=v&&h[v],g=0;if(f)return f.call(h);if(h&&typeof h.length=="number")return{next:function(){return h&&g>=h.length&&(h=void 0),{value:h&&h[g++],done:!h}}};throw new TypeError(v?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var c=i("../LinkList/LinkList"),l=i("../Map/Map");function u(h,v,f){var g=this;if(h===void 0&&(h=[]),v===void 0&&(v=u.initSize),f=f||function(x){var k,w,C=0,I="";if(typeof x=="number")C=((C=Math.floor(x))<<5)-C,C&=C;else{I=typeof x!="string"?JSON.stringify(x):x;try{for(var _=n(I),L=_.next();!L.done;L=_.next())C=(C<<5)-C+L.value.charCodeAt(0),C&=C}catch(E){k={error:E}}finally{try{L&&!L.done&&(w=_.return)&&w.call(_)}finally{if(k)throw k.error}}}return C^=C>>>16},(v&v-1)!=0)throw new Error("initBucketNum must be 2 to the power of n");var y=0,p=[],m=Math.max(u.initSize,Math.min(u.maxSize,v));this.size=function(){return y},this.empty=function(){return y===0},this.clear=function(){y=0,m=v,p=[]},this.forEach=function(x){var k=0;p.forEach(function(w){w.forEach(function(C){x(C,k++)})})},this.setElement=function(x,k){var w,C;if(x==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(k!=null){var I=f(x)&m-1;if(p[I]){var _=p[I].size();if(p[I]instanceof c.default){try{for(var L=n(p[I]),E=L.next();!E.done;E=L.next()){var F=E.value;if(F.key===x)return void(F.value=k)}}catch(R){w={error:R}}finally{try{E&&!E.done&&(C=L.return)&&C.call(L)}finally{if(w)throw w.error}}p[I].pushBack({key:x,value:k}),p[I].size()>=u.treeifyThreshold&&(p[I]=new l.default(p[I]))}else p[I].setElement(x,k);var q=p[I].size();y+=q-_}else++y,p[I]=new c.default([{key:x,value:k}]);y>m*u.sigma&&(function(R){if(!(R>=u.maxSize)){m=2*R;var A=[];p.forEach(function(P,M){if(!P.empty()){if(P instanceof c.default&&P.size()===1){var H=P.front(),$=H.key,X=H.value;A[f($)&m-1]=new c.default([{key:$,value:X}])}else if(P instanceof l.default){var j=new c.default,O=new c.default;P.forEach(function(N){f(N.key)&R?O.pushBack(N):j.pushBack(N)}),j.size()>u.untreeifyThreshold?A[M]=new l.default(j):j.size()&&(A[M]=j),O.size()>u.untreeifyThreshold?A[M+R]=new l.default(O):O.size()&&(A[M+R]=O)}else{var z=new c.default,V=new c.default;P.forEach(function(N){f(N.key)&R?V.pushBack(N):z.pushBack(N)}),z.size()&&(A[M]=z),V.size()&&(A[M+R]=V)}p[M].clear()}}),p=A}}).call(this,m)}else this.eraseElementByKey(x)},this.getElementByKey=function(x){var k,w,C=f(x)&m-1;if(p[C]){if(p[C]instanceof l.default)return p[C].getElementByKey(x);try{for(var I=n(p[C]),_=I.next();!_.done;_=I.next()){var L=_.value;if(L.key===x)return L.value}}catch(E){k={error:E}}finally{try{_&&!_.done&&(w=I.return)&&w.call(I)}finally{if(k)throw k.error}}}},this.eraseElementByKey=function(x){var k,w,C=f(x)&m-1;if(p[C]){var I=p[C].size();if(p[C]instanceof l.default)p[C].eraseElementByKey(x),p[C].size()<=u.untreeifyThreshold&&(p[C]=new c.default(p[C]));else{var _=-1;try{for(var L=n(p[C]),E=L.next();!E.done;E=L.next())if(++_,E.value.key===x){p[C].eraseElementByPos(_);break}}catch(q){k={error:q}}finally{try{E&&!E.done&&(w=L.return)&&w.call(L)}finally{if(k)throw k.error}}}var F=p[C].size();y+=F-I}},this.find=function(x){var k,w,C=f(x)&m-1;if(!p[C])return!1;if(p[C]instanceof l.default)return p[C].find(x);try{for(var I=n(p[C]),_=I.next();!_.done;_=I.next())if(_.value.key===x)return!0}catch(L){k={error:L}}finally{try{_&&!_.done&&(w=I.return)&&w.call(I)}finally{if(k)throw k.error}}return!1},this[Symbol.iterator]=function(){return function(){var x,k,w,C,I,_;return a(this,function(L){switch(L.label){case 0:x=0,L.label=1;case 1:if(!(x<m))return[3,10];for(;x<m&&!p[x];)++x;if(x>=m)return[3,10];L.label=2;case 2:L.trys.push([2,7,8,9]),I=void 0,k=n(p[x]),w=k.next(),L.label=3;case 3:return w.done?[3,6]:[4,w.value];case 4:L.sent(),L.label=5;case 5:return w=k.next(),[3,3];case 6:return[3,9];case 7:return C=L.sent(),I={error:C},[3,9];case 8:try{w&&!w.done&&(_=k.return)&&_.call(k)}finally{if(I)throw I.error}return[7];case 9:return++x,[3,1];case 10:return[2]}})}()},h.forEach(function(x){var k=x.key,w=x.value;return g.setElement(k,w)}),Object.freeze(this)}u.initSize=16,u.maxSize=1<<30,u.sigma=.75,u.treeifyThreshold=8,u.untreeifyThreshold=6,u.minTreeifySize=64,Object.freeze(u),r.default=u},{"../LinkList/LinkList":29,"../Map/Map":30}],28:[function(i,s,r){var a=this&&this.__generator||function(h,v){var f,g,y,p,m={label:0,sent:function(){if(1&y[0])throw y[1];return y[1]},trys:[],ops:[]};return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(k){return function(w){return function(C){if(f)throw new TypeError("Generator is already executing.");for(;m;)try{if(f=1,g&&(y=2&C[0]?g.return:C[0]?g.throw||((y=g.return)&&y.call(g),0):g.next)&&!(y=y.call(g,C[1])).done)return y;switch(g=0,y&&(C=[2&C[0],y.value]),C[0]){case 0:case 1:y=C;break;case 4:return m.label++,{value:C[1],done:!1};case 5:m.label++,g=C[1],C=[0];continue;case 7:C=m.ops.pop(),m.trys.pop();continue;default:if(!(y=(y=m.trys).length>0&&y[y.length-1])&&(C[0]===6||C[0]===2)){m=0;continue}if(C[0]===3&&(!y||C[1]>y[0]&&C[1]<y[3])){m.label=C[1];break}if(C[0]===6&&m.label<y[1]){m.label=y[1],y=C;break}if(y&&m.label<y[2]){m.label=y[2],m.ops.push(C);break}y[2]&&m.ops.pop(),m.trys.pop();continue}C=v.call(h,m)}catch(I){C=[6,I],g=0}finally{f=y=0}if(5&C[0])throw C[1];return{value:C[0]?C[1]:void 0,done:!0}}([k,w])}}},n=this&&this.__values||function(h){var v=typeof Symbol=="function"&&Symbol.iterator,f=v&&h[v],g=0;if(f)return f.call(h);if(h&&typeof h.length=="number")return{next:function(){return h&&g>=h.length&&(h=void 0),{value:h&&h[g++],done:!h}}};throw new TypeError(v?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var c=i("../Set/Set"),l=i("../LinkList/LinkList");function u(h,v,f){var g=this;if(h===void 0&&(h=[]),v===void 0&&(v=u.initSize),f=f||function(x){var k=0,w="";if(typeof x=="number")k=((k=Math.floor(x))<<5)-k,k&=k;else{w=typeof x!="string"?JSON.stringify(x):x;for(var C=0;C<w.length;C++)k=(k<<5)-k+w.charCodeAt(C),k&=k}return k^=k>>>16},(v&v-1)!=0)throw new Error("initBucketNum must be 2 to the power of n");var y=0,p=[],m=Math.max(u.initSize,Math.min(u.maxSize,v));this.size=function(){return y},this.empty=function(){return y===0},this.clear=function(){y=0,m=v,p=[]},this.forEach=function(x){var k=0;p.forEach(function(w){w.forEach(function(C){x(C,k++)})})},this.insert=function(x){if(x==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");var k=f(x)&m-1;if(p[k]){var w=p[k].size();if(p[k]instanceof l.default){if(p[k].find(x))return;p[k].pushBack(x),p[k].size()>=u.treeifyThreshold&&(p[k]=new c.default(p[k]))}else p[k].insert(x);var C=p[k].size();y+=C-w}else p[k]=new l.default([x]),++y;y>m*u.sigma&&(function(I){if(!(I>=u.maxSize)){m=2*I;var _=[];p.forEach(function(L,E){if(!L.empty()){if(L instanceof l.default&&L.size()===1){var F=L.front();if(F===void 0)throw new Error("unknown error");_[f(F)&m-1]=new l.default([F])}else if(L instanceof c.default){var q=new l.default,R=new l.default;L.forEach(function(M){f(M)&I?R.pushBack(M):q.pushBack(M)}),q.size()>u.untreeifyThreshold?_[E]=new c.default(q):q.size()&&(_[E]=q),R.size()>u.untreeifyThreshold?_[E+I]=new c.default(R):R.size()&&(_[E+I]=R)}else{var A=new l.default,P=new l.default;L.forEach(function(M){f(M)&I?P.pushBack(M):A.pushBack(M)}),A.size()&&(_[E]=A),P.size()&&(_[E+I]=P)}p[E].clear()}}),p=_}}).call(this,m)},this.eraseElementByValue=function(x){var k=f(x)&m-1;if(p[k]){var w=p[k].size();p[k].eraseElementByValue(x),p[k]instanceof c.default&&p[k].size()<=u.untreeifyThreshold&&(p[k]=new l.default(p[k]));var C=p[k].size();y+=C-w}},this.find=function(x){var k=f(x)&m-1;return!!p[k]&&p[k].find(x)},this[Symbol.iterator]=function(){return function(){var x,k,w,C,I,_;return a(this,function(L){switch(L.label){case 0:x=0,L.label=1;case 1:if(!(x<m))return[3,10];for(;x<m&&!p[x];)++x;if(x>=m)return[3,10];L.label=2;case 2:L.trys.push([2,7,8,9]),I=void 0,k=n(p[x]),w=k.next(),L.label=3;case 3:return w.done?[3,6]:[4,w.value];case 4:L.sent(),L.label=5;case 5:return w=k.next(),[3,3];case 6:return[3,9];case 7:return C=L.sent(),I={error:C},[3,9];case 8:try{w&&!w.done&&(_=k.return)&&_.call(k)}finally{if(I)throw I.error}return[7];case 9:return++x,[3,1];case 10:return[2]}})}()},h.forEach(function(x){return g.insert(x)}),Object.freeze(this)}u.initSize=16,u.maxSize=1<<30,u.sigma=.75,u.treeifyThreshold=8,u.untreeifyThreshold=6,u.minTreeifySize=64,Object.freeze(u),r.default=u},{"../LinkList/LinkList":29,"../Set/Set":33}],29:[function(i,s,r){var a=this&&this.__generator||function(l,u){var h,v,f,g,y={label:0,sent:function(){if(1&f[0])throw f[1];return f[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(m){return function(x){return function(k){if(h)throw new TypeError("Generator is already executing.");for(;y;)try{if(h=1,v&&(f=2&k[0]?v.return:k[0]?v.throw||((f=v.return)&&f.call(v),0):v.next)&&!(f=f.call(v,k[1])).done)return f;switch(v=0,f&&(k=[2&k[0],f.value]),k[0]){case 0:case 1:f=k;break;case 4:return y.label++,{value:k[1],done:!1};case 5:y.label++,v=k[1],k=[0];continue;case 7:k=y.ops.pop(),y.trys.pop();continue;default:if(!(f=(f=y.trys).length>0&&f[f.length-1])&&(k[0]===6||k[0]===2)){y=0;continue}if(k[0]===3&&(!f||k[1]>f[0]&&k[1]<f[3])){y.label=k[1];break}if(k[0]===6&&y.label<f[1]){y.label=f[1],f=k;break}if(f&&y.label<f[2]){y.label=f[2],y.ops.push(k);break}f[2]&&y.ops.pop(),y.trys.pop();continue}k=u.call(l,y)}catch(w){k=[6,w],v=0}finally{h=f=0}if(5&k[0])throw k[1];return{value:k[0]?k[1]:void 0,done:!0}}([m,x])}}};Object.defineProperty(r,"__esModule",{value:!0});var n=function(){return function(l){this.value=void 0,this.pre=void 0,this.next=void 0,this.value=l}}();function c(l){var u=this;l===void 0&&(l=[]);var h=0,v=void 0,f=void 0;this.size=function(){return h},this.empty=function(){return h===0},this.clear=function(){v=f=void 0,h=0},this.front=function(){return v==null?void 0:v.value},this.back=function(){return f==null?void 0:f.value},this.forEach=function(g){for(var y=v,p=0;y;){if(y.value===void 0)throw new Error("unknown error");g(y.value,p++),y=y.next}},this.getElementByPos=function(g){if(g<0||g>=h)throw new Error("pos must more then 0 and less then the list length");for(var y=v;g--&&y;)y=y.next;if(!y||y.value===void 0)throw new Error("unknown error");return y.value},this.eraseElementByPos=function(g){if(g<0||g>=h)throw new Error("erase pos must more then 0 and less then the list length");if(g===0)this.popFront();else if(g===h-1)this.popBack();else{for(var y=v;g--;){if(!(y!=null&&y.next))throw new Error("unknown error");y=y.next}if(!y||!y.pre||!y.next)throw new Error("unknown error");var p=y.pre,m=y.next;m.pre=p,p.next=m,h>0&&--h}},this.eraseElementByValue=function(g){for(;v&&v.value===g;)this.popFront();for(;f&&f.value===g;)this.popBack();if(v)for(var y=v;y;){if(y.value===g){var p=y.pre,m=y.next;m&&(m.pre=p),p&&(p.next=m),h>0&&--h}y=y.next}},this.pushBack=function(g){if(g==null)throw new Error("you can't push null or undefined here");++h;var y=new n(g);f?(f.next=y,y.pre=f,f=y):v=f=y},this.popBack=function(){f&&(h>0&&--h,f&&(v===f?v=f=void 0:(f=f.pre)&&(f.next=void 0)))},this.setElementByPos=function(g,y){if(y==null)throw new Error("you can't set null or undefined here");if(g<0||g>=h)throw new Error("pos must more then 0 and less then the list length");for(var p=v;g--;){if(!p)throw new Error("unknown error");p=p.next}p&&(p.value=y)},this.insert=function(g,y,p){if(p===void 0&&(p=1),y==null)throw new Error("you can't insert null or undefined here");if(g<0||g>h)throw new Error("insert pos must more then 0 and less then or equal to the list length");if(p<0)throw new Error("insert size must more than 0");if(g===0)for(;p--;)this.pushFront(y);else if(g===h)for(;p--;)this.pushBack(y);else{for(var m=v,x=1;x<g;++x){if(!(m!=null&&m.next))throw new Error("unknown error");m=m==null?void 0:m.next}if(!m)throw new Error("unknown error");var k=m.next;for(h+=p;p--;)m.next=new n(y),m.next.pre=m,m=m.next;m.next=k,k&&(k.pre=m)}},this.find=function(g){for(var y=v;y;){if(y.value===g)return!0;y=y.next}return!1},this.reverse=function(){for(var g=v,y=f,p=0;g&&y&&2*p<h;){var m=g.value;g.value=y.value,y.value=m,g=g.next,y=y.pre,++p}},this.unique=function(){for(var g=v;g;){for(var y=g;y&&y.next&&y.value===y.next.value;)y=y.next,h>0&&--h;g.next=y.next,g.next&&(g.next.pre=g),g=g.next}},this.sort=function(g){var y=[];this.forEach(function(m){y.push(m)}),y.sort(g);var p=v;y.forEach(function(m){p&&(p.value=m,p=p.next)})},this.pushFront=function(g){if(g==null)throw new Error("you can't push null or undefined here");++h;var y=new n(g);v?(y.next=v,v.pre=y,v=y):v=f=y},this.popFront=function(){v&&(h>0&&--h,v&&(v===f?v=f=void 0:(v=v.next)&&(v.pre=void 0)))},this.merge=function(g){var y=this,p=v;g.forEach(function(m){for(;p&&p.value!==void 0&&p.value<=m;)p=p.next;if(p===void 0)y.pushBack(m),p=f;else if(p===v)y.pushFront(m),p=v;else{++h;var x=p.pre;x&&(x.next=new n(m),x.next.pre=x,x.next.next=p,p&&(p.pre=x.next))}})},this[Symbol.iterator]=function(){return function(){var g;return a(this,function(y){switch(y.label){case 0:g=v,y.label=1;case 1:if(g===void 0)return[3,3];if(!g.value)throw new Error("unknown error");return[4,g.value];case 2:return y.sent(),g=g.next,[3,1];case 3:return[2]}})}()},l.forEach(function(g){return u.pushBack(g)}),Object.freeze(this)}Object.freeze(c),r.default=c},{}],30:[function(i,s,r){var a=this&&this.__generator||function(u,h){var v,f,g,y,p={label:0,sent:function(){if(1&g[0])throw g[1];return g[1]},trys:[],ops:[]};return y={next:m(0),throw:m(1),return:m(2)},typeof Symbol=="function"&&(y[Symbol.iterator]=function(){return this}),y;function m(x){return function(k){return function(w){if(v)throw new TypeError("Generator is already executing.");for(;p;)try{if(v=1,f&&(g=2&w[0]?f.return:w[0]?f.throw||((g=f.return)&&g.call(f),0):f.next)&&!(g=g.call(f,w[1])).done)return g;switch(f=0,g&&(w=[2&w[0],g.value]),w[0]){case 0:case 1:g=w;break;case 4:return p.label++,{value:w[1],done:!1};case 5:p.label++,f=w[1],w=[0];continue;case 7:w=p.ops.pop(),p.trys.pop();continue;default:if(!(g=(g=p.trys).length>0&&g[g.length-1])&&(w[0]===6||w[0]===2)){p=0;continue}if(w[0]===3&&(!g||w[1]>g[0]&&w[1]<g[3])){p.label=w[1];break}if(w[0]===6&&p.label<g[1]){p.label=g[1],g=w;break}if(g&&p.label<g[2]){p.label=g[2],p.ops.push(w);break}g[2]&&p.ops.pop(),p.trys.pop();continue}w=h.call(u,p)}catch(C){w=[6,C],f=0}finally{v=g=0}if(5&w[0])throw w[1];return{value:w[0]?w[1]:void 0,done:!0}}([x,k])}}},n=this&&this.__values||function(u){var h=typeof Symbol=="function"&&Symbol.iterator,v=h&&u[h],f=0;if(v)return v.call(u);if(u&&typeof u.length=="number")return{next:function(){return u&&f>=u.length&&(u=void 0),{value:u&&u[f++],done:!u}}};throw new TypeError(h?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var c=i("../Base/TreeNode");function l(u,h){var v=this;u===void 0&&(u=[]),h=h||function(R,A){return R<A?-1:R>A?1:0};var f=0,g=new c.default;g.color=c.default.TreeNodeColorType.black,this.size=function(){return f},this.empty=function(){return f===0},this.clear=function(){f=0,g.key=g.value=void 0,g.leftChild=g.rightChild=g.brother=void 0};var y=function(R){if(!R||R.key===void 0)throw new Error("unknown error");return R.leftChild?y(R.leftChild):R},p=function(R){if(!R||R.key===void 0)throw new Error("unknown error");return R.rightChild?p(R.rightChild):R};this.front=function(){if(!this.empty()){var R=y(g);if(R.key===void 0||R.value===void 0)throw new Error("unknown error");return{key:R.key,value:R.value}}},this.back=function(){if(!this.empty()){var R=p(g);if(R.key===void 0||R.value===void 0)throw new Error("unknown error");return{key:R.key,value:R.value}}},this.forEach=function(R){var A,P,M=0;try{for(var H=n(this),$=H.next();!$.done;$=H.next())R($.value,M++)}catch(X){A={error:X}}finally{try{$&&!$.done&&(P=H.return)&&P.call(H)}finally{if(A)throw A.error}}},this.getElementByPos=function(R){var A,P;if(R<0||R>=this.size())throw new Error("pos must more than 0 and less than set's size");var M=0;try{for(var H=n(this),$=H.next();!$.done;$=H.next()){var X=$.value;if(M===R)return X;++M}}catch(j){A={error:j}}finally{try{$&&!$.done&&(P=H.return)&&P.call(H)}finally{if(A)throw A.error}}throw new Error("unknown Error")};var m=function(R,A){if(R&&R.key!==void 0&&R.value!==void 0){var P=h(R.key,A);return P===0?{key:R.key,value:R.value}:P<0?m(R.rightChild,A):m(R.leftChild,A)||{key:R.key,value:R.value}}};this.lowerBound=function(R){return m(g,R)};var x=function(R,A){if(R&&R.key!==void 0&&R.value!==void 0)return h(R.key,A)<=0?x(R.rightChild,A):x(R.leftChild,A)||{key:R.key,value:R.value}};this.upperBound=function(R){return x(g,R)};var k=function(R,A){if(R&&R.key!==void 0&&R.value!==void 0){var P=h(R.key,A);return P===0?{key:R.key,value:R.value}:P>0?k(R.leftChild,A):k(R.rightChild,A)||{key:R.key,value:R.value}}};this.reverseLowerBound=function(R){return k(g,R)};var w=function(R,A){if(R&&R.key!==void 0&&R.value!==void 0)return h(R.key,A)>=0?w(R.leftChild,A):w(R.rightChild,A)||{key:R.key,value:R.value}};this.reverseUpperBound=function(R){return w(g,R)};var C=function(R){var A=R.parent;if(!A){if(R===g)return;throw new Error("unknown error")}if(R.color!==c.default.TreeNodeColorType.red){var P=R.brother;if(!P)throw new Error("unknown error");if(R===A.leftChild)if(P.color===c.default.TreeNodeColorType.red){P.color=c.default.TreeNodeColorType.black,A.color=c.default.TreeNodeColorType.red;var M=A.rotateLeft();g===A&&(g=M),C(R)}else P.color===c.default.TreeNodeColorType.black&&(P.rightChild&&P.rightChild.color===c.default.TreeNodeColorType.red?(P.color=A.color,A.color=c.default.TreeNodeColorType.black,P.rightChild&&(P.rightChild.color=c.default.TreeNodeColorType.black),M=A.rotateLeft(),g===A&&(g=M),R.color=c.default.TreeNodeColorType.black):P.rightChild&&P.rightChild.color!==c.default.TreeNodeColorType.black||!P.leftChild||P.leftChild.color!==c.default.TreeNodeColorType.red?P.leftChild&&P.leftChild.color!==c.default.TreeNodeColorType.black||P.rightChild&&P.rightChild.color!==c.default.TreeNodeColorType.black||(P.color=c.default.TreeNodeColorType.red,C(A)):(P.color=c.default.TreeNodeColorType.red,P.leftChild&&(P.leftChild.color=c.default.TreeNodeColorType.black),M=P.rotateRight(),g===P&&(g=M),C(R)));else R===A.rightChild&&(P.color===c.default.TreeNodeColorType.red?(P.color=c.default.TreeNodeColorType.black,A.color=c.default.TreeNodeColorType.red,M=A.rotateRight(),g===A&&(g=M),C(R)):P.color===c.default.TreeNodeColorType.black&&(P.leftChild&&P.leftChild.color===c.default.TreeNodeColorType.red?(P.color=A.color,A.color=c.default.TreeNodeColorType.black,P.leftChild&&(P.leftChild.color=c.default.TreeNodeColorType.black),M=A.rotateRight(),g===A&&(g=M),R.color=c.default.TreeNodeColorType.black):P.leftChild&&P.leftChild.color!==c.default.TreeNodeColorType.black||!P.rightChild||P.rightChild.color!==c.default.TreeNodeColorType.red?P.leftChild&&P.leftChild.color!==c.default.TreeNodeColorType.black||P.rightChild&&P.rightChild.color!==c.default.TreeNodeColorType.black||(P.color=c.default.TreeNodeColorType.red,C(A)):(P.color=c.default.TreeNodeColorType.red,P.rightChild&&(P.rightChild.color=c.default.TreeNodeColorType.black),M=P.rotateLeft(),g===P&&(g=M),C(R))))}else R.color=c.default.TreeNodeColorType.black},I=function(R){for(var A=R;A.leftChild||A.rightChild;){if(A.rightChild){A=y(A.rightChild);var P=R.key;R.key=A.key,A.key=P;var M=R.value;R.value=A.value,A.value=M,R=A}A.leftChild&&(A=p(A.leftChild),P=R.key,R.key=A.key,A.key=P,M=R.value,R.value=A.value,A.value=M,R=A)}C(A),A&&A.remove(),--f,g.color=c.default.TreeNodeColorType.black},_=function(R,A){return!(!R||R.key===void 0)&&(!!_(R.leftChild,A)||!!A(R)||_(R.rightChild,A))};this.eraseElementByPos=function(R){if(R<0||R>=f)throw new Error("pos must more than 0 and less than set's size");var A=0;_(g,function(P){return R===A?(I(P),!0):(++A,!1)})},this.eraseElementByKey=function(R){if(!this.empty()){var A=F(g,R);A!==void 0&&A.key!==void 0&&h(A.key,R)===0&&I(A)}};var L=function(R,A){if(!R||R.key===void 0)throw new Error("unknown error");var P=h(A,R.key);return P<0?R.leftChild?L(R.leftChild,A):(R.leftChild=new c.default,R.leftChild.parent=R,R.leftChild.brother=R.rightChild,R.rightChild&&(R.rightChild.brother=R.leftChild),R.leftChild):P>0?R.rightChild?L(R.rightChild,A):(R.rightChild=new c.default,R.rightChild.parent=R,R.rightChild.brother=R.leftChild,R.leftChild&&(R.leftChild.brother=R.rightChild),R.rightChild):R},E=function(R){var A=R.parent;if(!A){if(R===g)return;throw new Error("unknown error")}if(A.color!==c.default.TreeNodeColorType.black&&A.color===c.default.TreeNodeColorType.red){var P=A.brother,M=A.parent;if(!M)throw new Error("unknown error");if(P&&P.color===c.default.TreeNodeColorType.red)P.color=A.color=c.default.TreeNodeColorType.black,M.color=c.default.TreeNodeColorType.red,E(M);else if(!P||P.color===c.default.TreeNodeColorType.black)if(A===M.leftChild)if(R===A.leftChild){A.color=c.default.TreeNodeColorType.black,M.color=c.default.TreeNodeColorType.red;var H=M.rotateRight();M===g&&(g=H)}else R===A.rightChild&&(H=A.rotateLeft(),M===g&&(g=H),E(A));else A===M.rightChild&&(R===A.leftChild?(H=A.rotateRight(),M===g&&(g=H),E(A)):R===A.rightChild&&(A.color=c.default.TreeNodeColorType.black,M.color=c.default.TreeNodeColorType.red,H=M.rotateLeft(),M===g&&(g=H)))}};this.setElement=function(R,A){if(R==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(A!=null){if(this.empty())return++f,g.key=R,g.value=A,void(g.color=c.default.TreeNodeColorType.black);var P=L(g,R);P.key===void 0||h(P.key,R)!==0?(++f,P.key=R,P.value=A,E(P),g.color=c.default.TreeNodeColorType.black):P.value=A}else this.eraseElementByKey(R)};var F=function(R,A){if(R&&R.key!==void 0){var P=h(A,R.key);return P<0?F(R.leftChild,A):P>0?F(R.rightChild,A):R}};this.find=function(R){return!!F(g,R)},this.getElementByKey=function(R){var A=F(g,R);if((A==null?void 0:A.key)===void 0||(A==null?void 0:A.value)===void 0)throw new Error("unknown error");return A.value},this.union=function(R){var A=this;R.forEach(function(P){var M=P.key,H=P.value;return A.setElement(M,H)})},this.getHeight=function(){if(this.empty())return 0;var R=function(A){return A?Math.max(R(A.leftChild),R(A.rightChild))+1:1};return R(g)};var q=function(R){return a(this,function(A){switch(A.label){case 0:return R&&R.key!==void 0&&R.value!==void 0?[5,n(q(R.leftChild))]:[2];case 1:return A.sent(),[4,{key:R.key,value:R.value}];case 2:return A.sent(),[5,n(q(R.rightChild))];case 3:return A.sent(),[2]}})};this[Symbol.iterator]=function(){return q(g)},u.forEach(function(R){var A=R.key,P=R.value;return v.setElement(A,P)}),Object.freeze(this)}Object.freeze(l),r.default=l},{"../Base/TreeNode":25}],31:[function(i,s,r){function a(n,c){n===void 0&&(n=[]),c=c||function(f,g){return f>g?-1:f<g?1:0};var l=[];n.forEach(function(f){return l.push(f)});var u=l.length,h=function(f,g){if(f<0||f>=u)throw new Error("unknown error");if(g<0||g>=u)throw new Error("unknown error");var y=l[f];l[f]=l[g],l[g]=y},v=function(f){if(f<0||f>=u)throw new Error("unknown error");var g=2*f+1,y=2*f+2;g<u&&c(l[f],l[g])>0&&h(f,g),y<u&&c(l[f],l[y])>0&&h(f,y)};(function(){for(var f=Math.floor((u-1)/2);f>=0;--f)for(var g=f,y=2*g+1;y<u;){var p=y+1,m=y;if(p<u&&c(l[y],l[p])>0&&(m=p),c(l[g],l[m])<=0)break;h(g,m),y=2*(g=m)+1}})(),this.size=function(){return u},this.empty=function(){return u===0},this.clear=function(){u=0,l.length=0},this.push=function(f){if(l.push(f),++u!==1)for(var g=u-1;g>0;){var y=Math.floor((g-1)/2);if(c(l[y],f)<=0)break;v(y),g=y}},this.pop=function(){if(!this.empty())if(this.size()!==1){var f=l[u-1];--u;for(var g=0;g<this.size();){var y=2*g+1,p=2*g+2;if(y>=this.size())break;var m=y;if(p<this.size()&&c(l[y],l[p])>0&&(m=p),c(l[m],f)>=0)break;l[g]=l[m],g=m}l[g]=f}else--u},this.top=function(){return l[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 n(c){c===void 0&&(c=[]);var l=new a.default(c);this.size=function(){return l.size()},this.empty=function(){return l.empty()},this.clear=function(){l.clear()},this.push=function(u){l.pushBack(u)},this.pop=function(){l.popFront()},this.front=function(){return l.front()},Object.freeze(this)}Object.freeze(n),r.default=n},{"../LinkList/LinkList":29}],33:[function(i,s,r){var a=this&&this.__generator||function(u,h){var v,f,g,y,p={label:0,sent:function(){if(1&g[0])throw g[1];return g[1]},trys:[],ops:[]};return y={next:m(0),throw:m(1),return:m(2)},typeof Symbol=="function"&&(y[Symbol.iterator]=function(){return this}),y;function m(x){return function(k){return function(w){if(v)throw new TypeError("Generator is already executing.");for(;p;)try{if(v=1,f&&(g=2&w[0]?f.return:w[0]?f.throw||((g=f.return)&&g.call(f),0):f.next)&&!(g=g.call(f,w[1])).done)return g;switch(f=0,g&&(w=[2&w[0],g.value]),w[0]){case 0:case 1:g=w;break;case 4:return p.label++,{value:w[1],done:!1};case 5:p.label++,f=w[1],w=[0];continue;case 7:w=p.ops.pop(),p.trys.pop();continue;default:if(!(g=(g=p.trys).length>0&&g[g.length-1])&&(w[0]===6||w[0]===2)){p=0;continue}if(w[0]===3&&(!g||w[1]>g[0]&&w[1]<g[3])){p.label=w[1];break}if(w[0]===6&&p.label<g[1]){p.label=g[1],g=w;break}if(g&&p.label<g[2]){p.label=g[2],p.ops.push(w);break}g[2]&&p.ops.pop(),p.trys.pop();continue}w=h.call(u,p)}catch(C){w=[6,C],f=0}finally{v=g=0}if(5&w[0])throw w[1];return{value:w[0]?w[1]:void 0,done:!0}}([x,k])}}},n=this&&this.__values||function(u){var h=typeof Symbol=="function"&&Symbol.iterator,v=h&&u[h],f=0;if(v)return v.call(u);if(u&&typeof u.length=="number")return{next:function(){return u&&f>=u.length&&(u=void 0),{value:u&&u[f++],done:!u}}};throw new TypeError(h?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var c=i("../Base/TreeNode");function l(u,h){var v=this;u===void 0&&(u=[]),h=h||function(R,A){return R<A?-1:R>A?1:0};var f=0,g=new c.default;g.color=c.default.TreeNodeColorType.black,this.size=function(){return f},this.empty=function(){return f===0},this.clear=function(){f=0,g.key=void 0,g.leftChild=g.rightChild=g.brother=g.parent=void 0,g.color=c.default.TreeNodeColorType.black};var y=function(R){if(!R||R.key===void 0)throw new Error("unknown error");return R.leftChild?y(R.leftChild):R},p=function(R){if(!R||R.key===void 0)throw new Error("unknown error");return R.rightChild?p(R.rightChild):R};this.front=function(){if(!this.empty())return y(g).key},this.back=function(){if(!this.empty())return p(g).key},this.forEach=function(R){var A,P,M=0;try{for(var H=n(this),$=H.next();!$.done;$=H.next())R($.value,M++)}catch(X){A={error:X}}finally{try{$&&!$.done&&(P=H.return)&&P.call(H)}finally{if(A)throw A.error}}},this.getElementByPos=function(R){var A,P;if(R<0||R>=this.size())throw new Error("pos must more than 0 and less than set's size");var M=0;try{for(var H=n(this),$=H.next();!$.done;$=H.next()){var X=$.value;if(M===R)return X;++M}}catch(j){A={error:j}}finally{try{$&&!$.done&&(P=H.return)&&P.call(H)}finally{if(A)throw A.error}}throw new Error("unknown error")};var m=function(R){var A=R.parent;if(!A){if(R===g)return;throw new Error("unknown error")}if(R.color!==c.default.TreeNodeColorType.red){var P=R.brother;if(!P)throw new Error("unknown error");if(R===A.leftChild)if(P.color===c.default.TreeNodeColorType.red){P.color=c.default.TreeNodeColorType.black,A.color=c.default.TreeNodeColorType.red;var M=A.rotateLeft();g===A&&(g=M),m(R)}else P.color===c.default.TreeNodeColorType.black&&(P.rightChild&&P.rightChild.color===c.default.TreeNodeColorType.red?(P.color=A.color,A.color=c.default.TreeNodeColorType.black,P.rightChild&&(P.rightChild.color=c.default.TreeNodeColorType.black),M=A.rotateLeft(),g===A&&(g=M),R.color=c.default.TreeNodeColorType.black):P.rightChild&&P.rightChild.color!==c.default.TreeNodeColorType.black||!P.leftChild||P.leftChild.color!==c.default.TreeNodeColorType.red?P.leftChild&&P.leftChild.color!==c.default.TreeNodeColorType.black||P.rightChild&&P.rightChild.color!==c.default.TreeNodeColorType.black||(P.color=c.default.TreeNodeColorType.red,m(A)):(P.color=c.default.TreeNodeColorType.red,P.leftChild&&(P.leftChild.color=c.default.TreeNodeColorType.black),M=P.rotateRight(),g===P&&(g=M),m(R)));else R===A.rightChild&&(P.color===c.default.TreeNodeColorType.red?(P.color=c.default.TreeNodeColorType.black,A.color=c.default.TreeNodeColorType.red,M=A.rotateRight(),g===A&&(g=M),m(R)):P.color===c.default.TreeNodeColorType.black&&(P.leftChild&&P.leftChild.color===c.default.TreeNodeColorType.red?(P.color=A.color,A.color=c.default.TreeNodeColorType.black,P.leftChild&&(P.leftChild.color=c.default.TreeNodeColorType.black),M=A.rotateRight(),g===A&&(g=M),R.color=c.default.TreeNodeColorType.black):P.leftChild&&P.leftChild.color!==c.default.TreeNodeColorType.black||!P.rightChild||P.rightChild.color!==c.default.TreeNodeColorType.red?P.leftChild&&P.leftChild.color!==c.default.TreeNodeColorType.black||P.rightChild&&P.rightChild.color!==c.default.TreeNodeColorType.black||(P.color=c.default.TreeNodeColorType.red,m(A)):(P.color=c.default.TreeNodeColorType.red,P.rightChild&&(P.rightChild.color=c.default.TreeNodeColorType.black),M=P.rotateLeft(),g===P&&(g=M),m(R))))}else R.color=c.default.TreeNodeColorType.black},x=function(R){for(var A=R;A.leftChild||A.rightChild;){if(A.rightChild){A=y(A.rightChild);var P=R.key;R.key=A.key,A.key=P,R=A}A.leftChild&&(A=p(A.leftChild),P=R.key,R.key=A.key,A.key=P,R=A)}m(A),A&&A.remove(),--f,g.color=c.default.TreeNodeColorType.black},k=function(R,A){return!(!R||R.key===void 0)&&(!!k(R.leftChild,A)||!!A(R)||k(R.rightChild,A))};this.eraseElementByPos=function(R){if(R<0||R>=f)throw new Error("pos must more than 0 and less than set's size");var A=0;k(g,function(P){return R===A?(x(P),!0):(++A,!1)})},this.eraseElementByValue=function(R){if(!this.empty()){var A=I(g,R);A!==void 0&&A.key!==void 0&&h(A.key,R)===0&&x(A)}};var w=function(R,A){if(!R||R.key===void 0)throw new Error("unknown error");var P=h(A,R.key);return P<0?R.leftChild?w(R.leftChild,A):(R.leftChild=new c.default,R.leftChild.parent=R,R.leftChild.brother=R.rightChild,R.rightChild&&(R.rightChild.brother=R.leftChild),R.leftChild):P>0?R.rightChild?w(R.rightChild,A):(R.rightChild=new c.default,R.rightChild.parent=R,R.rightChild.brother=R.leftChild,R.leftChild&&(R.leftChild.brother=R.rightChild),R.rightChild):R},C=function(R){var A=R.parent;if(!A){if(R===g)return;throw new Error("unknown error")}if(A.color!==c.default.TreeNodeColorType.black&&A.color===c.default.TreeNodeColorType.red){var P=A.brother,M=A.parent;if(!M)throw new Error("unknown error");if(P&&P.color===c.default.TreeNodeColorType.red)P.color=A.color=c.default.TreeNodeColorType.black,M.color=c.default.TreeNodeColorType.red,C(M);else if(!P||P.color===c.default.TreeNodeColorType.black)if(A===M.leftChild)if(R===A.leftChild){A.color=c.default.TreeNodeColorType.black,M.color=c.default.TreeNodeColorType.red;var H=M.rotateRight();M===g&&(g=H)}else R===A.rightChild&&(H=A.rotateLeft(),M===g&&(g=H),C(A));else A===M.rightChild&&(R===A.leftChild?(H=A.rotateRight(),M===g&&(g=H),C(A)):R===A.rightChild&&(A.color=c.default.TreeNodeColorType.black,M.color=c.default.TreeNodeColorType.red,H=M.rotateLeft(),M===g&&(g=H)))}};this.insert=function(R){if(R==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(this.empty())return++f,g.key=R,void(g.color=c.default.TreeNodeColorType.black);var A=w(g,R);A.key!==void 0&&h(A.key,R)===0||(++f,A.key=R,C(A),g.color=c.default.TreeNodeColorType.black)};var I=function(R,A){if(R&&R.key!==void 0){var P=h(A,R.key);return P<0?I(R.leftChild,A):P>0?I(R.rightChild,A):R}};this.find=function(R){var A=I(g,R);return A!==void 0&&A.key!==void 0&&h(A.key,R)===0};var _=function(R,A){if(R&&R.key!==void 0){var P=h(R.key,A);if(P===0)return R.key;if(P<0)return _(R.rightChild,A);var M=_(R.leftChild,A);return M!==void 0?M:R.key}};this.lowerBound=function(R){return _(g,R)};var L=function(R,A){if(R&&R.key!==void 0){if(h(R.key,A)<=0)return L(R.rightChild,A);var P=L(R.leftChild,A);return P!==void 0?P:R.key}};this.upperBound=function(R){return L(g,R)};var E=function(R,A){if(R&&R.key!==void 0){var P=h(R.key,A);if(P===0)return R.key;if(P>0)return E(R.leftChild,A);var M=E(R.rightChild,A);return M!==void 0?M:R.key}};this.reverseLowerBound=function(R){return E(g,R)};var F=function(R,A){if(R&&R.key!==void 0){if(h(R.key,A)>=0)return F(R.leftChild,A);var P=F(R.rightChild,A);return P!==void 0?P:R.key}};this.reverseUpperBound=function(R){return F(g,R)},this.union=function(R){var A=this;R.forEach(function(P){return A.insert(P)})},this.getHeight=function(){if(this.empty())return 0;var R=function(A){return A?Math.max(R(A.leftChild),R(A.rightChild))+1:1};return R(g)};var q=function(R){return a(this,function(A){switch(A.label){case 0:return R&&R.key!==void 0?[5,n(q(R.leftChild))]:[2];case 1:return A.sent(),[4,R.key];case 2:return A.sent(),[5,n(q(R.rightChild))];case 3:return A.sent(),[2]}})};this[Symbol.iterator]=function(){return q(g)},u.forEach(function(R){return v.insert(R)}),Object.freeze(this)}Object.freeze(l),r.default=l},{"../Base/TreeNode":25}],34:[function(i,s,r){function a(n){var c=this;n===void 0&&(n=[]);var l=0,u=[];this.size=function(){return l},this.empty=function(){return l===0},this.clear=function(){l=0,u.length=0},this.push=function(h){u.push(h),++l},this.pop=function(){u.pop(),l>0&&--l},this.top=function(){return u[l-1]},n.forEach(function(h){return c.push(h)}),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(h,v){var f,g,y,p,m={label:0,sent:function(){if(1&y[0])throw y[1];return y[1]},trys:[],ops:[]};return p={next:x(0),throw:x(1),return:x(2)},typeof Symbol=="function"&&(p[Symbol.iterator]=function(){return this}),p;function x(k){return function(w){return function(C){if(f)throw new TypeError("Generator is already executing.");for(;m;)try{if(f=1,g&&(y=2&C[0]?g.return:C[0]?g.throw||((y=g.return)&&y.call(g),0):g.next)&&!(y=y.call(g,C[1])).done)return y;switch(g=0,y&&(C=[2&C[0],y.value]),C[0]){case 0:case 1:y=C;break;case 4:return m.label++,{value:C[1],done:!1};case 5:m.label++,g=C[1],C=[0];continue;case 7:C=m.ops.pop(),m.trys.pop();continue;default:if(!(y=(y=m.trys).length>0&&y[y.length-1])&&(C[0]===6||C[0]===2)){m=0;continue}if(C[0]===3&&(!y||C[1]>y[0]&&C[1]<y[3])){m.label=C[1];break}if(C[0]===6&&m.label<y[1]){m.label=y[1],y=C;break}if(y&&m.label<y[2]){m.label=y[2],m.ops.push(C);break}y[2]&&m.ops.pop(),m.trys.pop();continue}C=v.call(h,m)}catch(I){C=[6,I],g=0}finally{f=y=0}if(5&C[0])throw C[1];return{value:C[0]?C[1]:void 0,done:!0}}([k,w])}}},n=this&&this.__read||function(h,v){var f=typeof Symbol=="function"&&h[Symbol.iterator];if(!f)return h;var g,y,p=f.call(h),m=[];try{for(;(v===void 0||v-- >0)&&!(g=p.next()).done;)m.push(g.value)}catch(x){y={error:x}}finally{try{g&&!g.done&&(f=p.return)&&f.call(p)}finally{if(y)throw y.error}}return m},c=this&&this.__spreadArray||function(h,v,f){if(f||arguments.length===2)for(var g,y=0,p=v.length;y<p;y++)!g&&y in v||(g||(g=Array.prototype.slice.call(v,0,y)),g[y]=v[y]);return h.concat(g||Array.prototype.slice.call(v))},l=this&&this.__values||function(h){var v=typeof Symbol=="function"&&Symbol.iterator,f=v&&h[v],g=0;if(f)return f.call(h);if(h&&typeof h.length=="number")return{next:function(){return h&&g>=h.length&&(h=void 0),{value:h&&h[g++],done:!h}}};throw new TypeError(v?"Object is not iterable.":"Symbol.iterator is not defined.")};function u(h){var v=this;h===void 0&&(h=[]);var f=0,g=[];this.size=function(){return f},this.empty=function(){return f===0},this.clear=function(){f=0,g.length=0},this.front=function(){if(!this.empty())return g[0]},this.back=function(){if(!this.empty())return g[f-1]},this.forEach=function(y){g.forEach(y)},this.getElementByPos=function(y){if(y<0||y>=f)throw new Error("pos must more than 0 and less than vector's size");return g[y]},this.eraseElementByPos=function(y){if(y<0||y>=f)throw new Error("pos must more than 0 and less than vector's size");for(var p=y;p<f-1;++p)g[p]=g[p+1];this.popBack()},this.eraseElementByValue=function(y){var p=[];this.forEach(function(x){x!==y&&p.push(x)}),p.forEach(function(x,k){g[k]=x});for(var m=p.length;f>m;)this.popBack()},this.pushBack=function(y){g.push(y),++f},this.popBack=function(){g.pop(),f>0&&--f},this.setElementByPos=function(y,p){if(y<0||y>=f)throw new Error("pos must more than 0 and less than vector's size");g[y]=p},this.insert=function(y,p,m){if(m===void 0&&(m=1),y<0||y>f)throw new Error("pos must more than 0 and less than or equal to vector's size");g.splice.apply(g,c([y,0],n(new Array(m).fill(p)),!1)),f+=m},this.find=function(y){return g.includes(y)},this.reverse=function(){g.reverse()},this.unique=function(){var y,p=[];this.forEach(function(x,k){k!==0&&x===y||(p.push(x),y=x)}),p.forEach(function(x,k){g[k]=x});for(var m=p.length;f>m;)this.popBack()},this.sort=function(y){g.sort(y)},this[Symbol.iterator]=function(){return function(){return a(this,function(y){switch(y.label){case 0:return[5,l(g)];case 1:return[2,y.sent()]}})}()},h.forEach(function(y){return v.pushBack(y)}),Object.freeze(this)}Object.defineProperty(r,"__esModule",{value:!0}),Object.freeze(u),r.default=u},{}],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 n=i("./Stack/Stack");r.Stack=n.default;var c=i("./Queue/Queue");r.Queue=c.default;var l=i("./LinkList/LinkList");r.LinkList=l.default;var u=i("./Deque/Deque");r.Deque=u.default;var h=i("./PriorityQueue/PriorityQueue");r.PriorityQueue=h.default;var v=i("./Set/Set");r.Set=v.default;var f=i("./Map/Map");r.Map=f.default;var g=i("./HashSet/HashSet");r.HashSet=g.default;var y=i("./HashMap/HashMap");r.HashMap=y.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"),n=Symbol("max"),c=Symbol("length"),l=Symbol("lengthCalculator"),u=Symbol("allowStale"),h=Symbol("maxAge"),v=Symbol("dispose"),f=Symbol("noDisposeOnSet"),g=Symbol("lruList"),y=Symbol("cache"),p=Symbol("updateAgeOnGet"),m=()=>1,x=(L,E,F)=>{const q=L[y].get(E);if(q){const R=q.value;if(k(L,R)){if(C(L,q),!L[u])return}else F&&(L[p]&&(q.value.now=Date.now()),L[g].unshiftNode(q));return R.value}},k=(L,E)=>{if(!E||!E.maxAge&&!L[h])return!1;const F=Date.now()-E.now;return E.maxAge?F>E.maxAge:L[h]&&F>L[h]},w=L=>{if(L[c]>L[n])for(let E=L[g].tail;L[c]>L[n]&&E!==null;){const F=E.prev;C(L,E),E=F}},C=(L,E)=>{if(E){const F=E.value;L[v]&&L[v](F.key,F.value),L[c]-=F.length,L[y].delete(F.key),L[g].removeNode(E)}};class I{constructor(E,F,q,R,A){this.key=E,this.value=F,this.length=q,this.now=R,this.maxAge=A||0}}const _=(L,E,F,q)=>{let R=F.value;k(L,R)&&(C(L,F),L[u]||(R=void 0)),R&&E.call(q,R.value,R.key,L)};s.exports=class{constructor(L){if(typeof L=="number"&&(L={max:L}),L||(L={}),L.max&&(typeof L.max!="number"||L.max<0))throw new TypeError("max must be a non-negative number");this[n]=L.max||1/0;const E=L.length||m;if(this[l]=typeof E!="function"?m:E,this[u]=L.stale||!1,L.maxAge&&typeof L.maxAge!="number")throw new TypeError("maxAge must be a number");this[h]=L.maxAge||0,this[v]=L.dispose,this[f]=L.noDisposeOnSet||!1,this[p]=L.updateAgeOnGet||!1,this.reset()}set max(L){if(typeof L!="number"||L<0)throw new TypeError("max must be a non-negative number");this[n]=L||1/0,w(this)}get max(){return this[n]}set allowStale(L){this[u]=!!L}get allowStale(){return this[u]}set maxAge(L){if(typeof L!="number")throw new TypeError("maxAge must be a non-negative number");this[h]=L,w(this)}get maxAge(){return this[h]}set lengthCalculator(L){typeof L!="function"&&(L=m),L!==this[l]&&(this[l]=L,this[c]=0,this[g].forEach(E=>{E.length=this[l](E.value,E.key),this[c]+=E.length})),w(this)}get lengthCalculator(){return this[l]}get length(){return this[c]}get itemCount(){return this[g].length}rforEach(L,E){E=E||this;for(let F=this[g].tail;F!==null;){const q=F.prev;_(this,L,F,E),F=q}}forEach(L,E){E=E||this;for(let F=this[g].head;F!==null;){const q=F.next;_(this,L,F,E),F=q}}keys(){return this[g].toArray().map(L=>L.key)}values(){return this[g].toArray().map(L=>L.value)}reset(){this[v]&&this[g]&&this[g].length&&this[g].forEach(L=>this[v](L.key,L.value)),this[y]=new Map,this[g]=new a,this[c]=0}dump(){return this[g].map(L=>!k(this,L)&&{k:L.key,v:L.value,e:L.now+(L.maxAge||0)}).toArray().filter(L=>L)}dumpLru(){return this[g]}set(L,E,F){if((F=F||this[h])&&typeof F!="number")throw new TypeError("maxAge must be a number");const q=F?Date.now():0,R=this[l](E,L);if(this[y].has(L)){if(R>this[n])return C(this,this[y].get(L)),!1;const P=this[y].get(L).value;return this[v]&&(this[f]||this[v](L,P.value)),P.now=q,P.maxAge=F,P.value=E,this[c]+=R-P.length,P.length=R,this.get(L),w(this),!0}const A=new I(L,E,R,q,F);return A.length>this[n]?(this[v]&&this[v](L,E),!1):(this[c]+=A.length,this[g].unshift(A),this[y].set(L,this[g].head),w(this),!0)}has(L){if(!this[y].has(L))return!1;const E=this[y].get(L).value;return!k(this,E)}get(L){return x(this,L,!0)}peek(L){return x(this,L,!1)}pop(){const L=this[g].tail;return L?(C(this,L),L.value):null}del(L){C(this,this[y].get(L))}load(L){this.reset();const E=Date.now();for(let F=L.length-1;F>=0;F--){const q=L[F],R=q.e||0;if(R===0)this.set(q.k,q.v);else{const A=R-E;A>0&&this.set(q.k,q.v,A)}}}prune(){this[y].forEach((L,E)=>x(this,E,!1))}}},{yallist:83}],38:[function(i,s,r){(function(a){(function(){const n=s.exports;n.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"},n.codes={};for(const l in n.types){const u=n.types[l];n.codes[u]=l}n.CMD_SHIFT=4,n.CMD_MASK=240,n.DUP_MASK=8,n.QOS_MASK=3,n.QOS_SHIFT=1,n.RETAIN_MASK=1,n.VARBYTEINT_MASK=127,n.VARBYTEINT_FIN_MASK=128,n.VARBYTEINT_MAX=268435455,n.SESSIONPRESENT_MASK=1,n.SESSIONPRESENT_HEADER=a.from([n.SESSIONPRESENT_MASK]),n.CONNACK_HEADER=a.from([n.codes.connack<<n.CMD_SHIFT]),n.USERNAME_MASK=128,n.PASSWORD_MASK=64,n.WILL_RETAIN_MASK=32,n.WILL_QOS_MASK=24,n.WILL_QOS_SHIFT=3,n.WILL_FLAG_MASK=4,n.CLEAN_SESSION_MASK=2,n.CONNECT_HEADER=a.from([n.codes.connect<<n.CMD_SHIFT]),n.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},n.propertiesCodes={};for(const l in n.properties){const u=n.properties[l];n.propertiesCodes[u]=l}function c(l){return[0,1,2].map(u=>[0,1].map(h=>[0,1].map(v=>{const f=a.alloc(1);return f.writeUInt8(n.codes[l]<<n.CMD_SHIFT|(h?n.DUP_MASK:0)|u<<n.QOS_SHIFT|v,0,!0),f})))}n.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"},n.PUBLISH_HEADER=c("publish"),n.SUBSCRIBE_HEADER=c("subscribe"),n.SUBSCRIBE_OPTIONS_QOS_MASK=3,n.SUBSCRIBE_OPTIONS_NL_MASK=1,n.SUBSCRIBE_OPTIONS_NL_SHIFT=2,n.SUBSCRIBE_OPTIONS_RAP_MASK=1,n.SUBSCRIBE_OPTIONS_RAP_SHIFT=3,n.SUBSCRIBE_OPTIONS_RH_MASK=3,n.SUBSCRIBE_OPTIONS_RH_SHIFT=4,n.SUBSCRIBE_OPTIONS_RH=[0,16,32],n.SUBSCRIBE_OPTIONS_NL=4,n.SUBSCRIBE_OPTIONS_RAP=8,n.SUBSCRIBE_OPTIONS_QOS=[0,1,2],n.UNSUBSCRIBE_HEADER=c("unsubscribe"),n.ACKS={unsuback:c("unsuback"),puback:c("puback"),pubcomp:c("pubcomp"),pubrel:c("pubrel"),pubrec:c("pubrec")},n.SUBACK_HEADER=a.from([n.codes.suback<<n.CMD_SHIFT]),n.VERSION3=a.from([3]),n.VERSION4=a.from([4]),n.VERSION5=a.from([5]),n.VERSION131=a.from([131]),n.VERSION132=a.from([132]),n.QOS=[0,1,2].map(l=>a.from([l])),n.EMPTY={pingreq:a.from([n.codes.pingreq<<4,0]),pingresp:a.from([n.codes.pingresp<<4,0]),disconnect:a.from([n.codes.disconnect<<4,0])}}).call(this)}).call(this,i("buffer").Buffer)},{buffer:17}],39:[function(i,s,r){(function(a){(function(){const n=i("./writeToStream"),c=i("events");class l extends c{constructor(){super(),this._array=new Array(20),this._i=0}write(h){return this._array[this._i++]=h,!0}concat(){let h=0;const v=new Array(this._array.length),f=this._array;let g,y=0;for(g=0;g<f.length&&f[g]!==void 0;g++)typeof f[g]!="string"?v[g]=f[g].length:v[g]=a.byteLength(f[g]),h+=v[g];const p=a.allocUnsafe(h);for(g=0;g<f.length&&f[g]!==void 0;g++)typeof f[g]!="string"?(f[g].copy(p,y),y+=v[g]):(p.write(f[g],y),y+=v[g]);return p}}s.exports=function(u,h){const v=new l;return n(u,v,h),v.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 c={},l=a.isBuffer(a.from([1,2]).subarray(0,1));function u(h){const v=a.allocUnsafe(2);return v.writeUInt8(h>>8,0),v.writeUInt8(255&h,1),v}s.exports={cache:c,generateCache:function(){for(let h=0;h<65536;h++)c[h]=u(h)},generateNumber:u,genBufVariableByteInt:function(h){let v=0,f=0;const g=a.allocUnsafe(4);do v=h%128|0,(h=h/128|0)>0&&(v|=128),g.writeUInt8(v,f++);while(h>0&&f<4);return h>0&&(f=0),l?g.subarray(0,f):g.slice(0,f)},generate4ByteBuffer:function(h){const v=a.allocUnsafe(4);return v.writeUInt32BE(h,0),v}}}).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"),n=i("events"),c=i("./packet"),l=i("./constants"),u=i("debug")("mqtt-packet:parser");class h extends n{constructor(){super(),this.parser=this.constructor.parser}static parser(f){return this instanceof h?(this.settings=f||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):new h().parser(f)}_resetState(){u("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new c,this.error=null,this._list=a(),this._stateCounter=0}parse(f){for(this.error&&this._resetState(),this._list.append(f),u("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++,u("parse: state complete. _stateCounter is now: %d",this._stateCounter),u("parse: packet.length: %d, buffer list length: %d",this.packet.length,this._list.length),this._stateCounter>=this._states.length&&(this._stateCounter=0);return u("parse: exited while loop. packet: %d, buffer list length: %d",this.packet.length,this._list.length),this._list.length}_parseHeader(){const f=this._list.readUInt8(0);return this.packet.cmd=l.types[f>>l.CMD_SHIFT],this.packet.retain=(f&l.RETAIN_MASK)!=0,this.packet.qos=f>>l.QOS_SHIFT&l.QOS_MASK,this.packet.dup=(f&l.DUP_MASK)!=0,u("_parseHeader: packet: %o",this.packet),this._list.consume(1),!0}_parseLength(){const f=this._parseVarByteNum(!0);return f&&(this.packet.length=f.value,this._list.consume(f.bytes)),u("_parseLength %d",f.value),!!f}_parsePayload(){u("_parsePayload: payload %O",this._list);let f=!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"))}f=!0}return u("_parsePayload complete result: %s",f),f}_parseConnect(){let f,g,y,p;u("_parseConnect");const m={},x=this.packet,k=this._parseString();if(k===null)return this._emitError(new Error("Cannot parse protocolId"));if(k!=="MQTT"&&k!=="MQIsdp")return this._emitError(new Error("Invalid protocolId"));if(x.protocolId=k,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(x.protocolVersion=this._list.readUInt8(this._pos),x.protocolVersion>=128&&(x.bridgeMode=!0,x.protocolVersion=x.protocolVersion-128),x.protocolVersion!==3&&x.protocolVersion!==4&&x.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(m.username=this._list.readUInt8(this._pos)&l.USERNAME_MASK,m.password=this._list.readUInt8(this._pos)&l.PASSWORD_MASK,m.will=this._list.readUInt8(this._pos)&l.WILL_FLAG_MASK,m.will&&(x.will={},x.will.retain=(this._list.readUInt8(this._pos)&l.WILL_RETAIN_MASK)!=0,x.will.qos=(this._list.readUInt8(this._pos)&l.WILL_QOS_MASK)>>l.WILL_QOS_SHIFT),x.clean=(this._list.readUInt8(this._pos)&l.CLEAN_SESSION_MASK)!=0,this._pos++,x.keepalive=this._parseNum(),x.keepalive===-1)return this._emitError(new Error("Packet too short"));if(x.protocolVersion===5){const C=this._parseProperties();Object.getOwnPropertyNames(C).length&&(x.properties=C)}const w=this._parseString();if(w===null)return this._emitError(new Error("Packet too short"));if(x.clientId=w,u("_parseConnect: packet.clientId: %s",x.clientId),m.will){if(x.protocolVersion===5){const C=this._parseProperties();Object.getOwnPropertyNames(C).length&&(x.will.properties=C)}if((f=this._parseString())===null)return this._emitError(new Error("Cannot parse will topic"));if(x.will.topic=f,u("_parseConnect: packet.will.topic: %s",x.will.topic),(g=this._parseBuffer())===null)return this._emitError(new Error("Cannot parse will payload"));x.will.payload=g,u("_parseConnect: packet.will.paylaod: %s",x.will.payload)}if(m.username){if((p=this._parseString())===null)return this._emitError(new Error("Cannot parse username"));x.username=p,u("_parseConnect: packet.username: %s",x.username)}if(m.password){if((y=this._parseBuffer())===null)return this._emitError(new Error("Cannot parse password"));x.password=y}return this.settings=x,u("_parseConnect: complete"),x}_parseConnack(){u("_parseConnack");const f=this.packet;if(this._list.length<1)return null;if(f.sessionPresent=!!(this._list.readUInt8(this._pos++)&l.SESSIONPRESENT_MASK),this.settings.protocolVersion===5)this._list.length>=2?f.reasonCode=this._list.readUInt8(this._pos++):f.reasonCode=0;else{if(this._list.length<2)return null;f.returnCode=this._list.readUInt8(this._pos++)}if(f.returnCode===-1||f.reasonCode===-1)return this._emitError(new Error("Cannot parse return code"));if(this.settings.protocolVersion===5){const g=this._parseProperties();Object.getOwnPropertyNames(g).length&&(f.properties=g)}u("_parseConnack: complete")}_parsePublish(){u("_parsePublish");const f=this.packet;if(f.topic=this._parseString(),f.topic===null)return this._emitError(new Error("Cannot parse topic"));if(!(f.qos>0)||this._parseMessageId()){if(this.settings.protocolVersion===5){const g=this._parseProperties();Object.getOwnPropertyNames(g).length&&(f.properties=g)}f.payload=this._list.slice(this._pos,f.length),u("_parsePublish: payload from buffer list: %o",f.payload)}}_parseSubscribe(){u("_parseSubscribe");const f=this.packet;let g,y,p,m,x,k,w;if(f.qos!==1)return this._emitError(new Error("Wrong subscribe header"));if(f.subscriptions=[],this._parseMessageId()){if(this.settings.protocolVersion===5){const C=this._parseProperties();Object.getOwnPropertyNames(C).length&&(f.properties=C)}for(;this._pos<f.length;){if((g=this._parseString())===null)return this._emitError(new Error("Cannot parse topic"));if(this._pos>=f.length)return this._emitError(new Error("Malformed Subscribe Payload"));p=(y=this._parseByte())&l.SUBSCRIBE_OPTIONS_QOS_MASK,k=(y>>l.SUBSCRIBE_OPTIONS_NL_SHIFT&l.SUBSCRIBE_OPTIONS_NL_MASK)!=0,x=(y>>l.SUBSCRIBE_OPTIONS_RAP_SHIFT&l.SUBSCRIBE_OPTIONS_RAP_MASK)!=0,m=y>>l.SUBSCRIBE_OPTIONS_RH_SHIFT&l.SUBSCRIBE_OPTIONS_RH_MASK,w={topic:g,qos:p},this.settings.protocolVersion===5?(w.nl=k,w.rap=x,w.rh=m):this.settings.bridgeMode&&(w.rh=0,w.rap=!0,w.nl=!0),u("_parseSubscribe: push subscription `%s` to subscription",w),f.subscriptions.push(w)}}}_parseSuback(){u("_parseSuback");const f=this.packet;if(this.packet.granted=[],this._parseMessageId()){if(this.settings.protocolVersion===5){const g=this._parseProperties();Object.getOwnPropertyNames(g).length&&(f.properties=g)}for(;this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseUnsubscribe(){u("_parseUnsubscribe");const f=this.packet;if(f.unsubscriptions=[],this._parseMessageId()){if(this.settings.protocolVersion===5){const g=this._parseProperties();Object.getOwnPropertyNames(g).length&&(f.properties=g)}for(;this._pos<f.length;){const g=this._parseString();if(g===null)return this._emitError(new Error("Cannot parse topic"));u("_parseUnsubscribe: push topic `%s` to unsubscriptions",g),f.unsubscriptions.push(g)}}}_parseUnsuback(){u("_parseUnsuback");const f=this.packet;if(!this._parseMessageId())return this._emitError(new Error("Cannot parse messageId"));if(this.settings.protocolVersion===5){const g=this._parseProperties();for(Object.getOwnPropertyNames(g).length&&(f.properties=g),f.granted=[];this._pos<this.packet.length;)this.packet.granted.push(this._list.readUInt8(this._pos++))}}_parseConfirmation(){u("_parseConfirmation: packet.cmd: `%s`",this.packet.cmd);const f=this.packet;if(this._parseMessageId(),this.settings.protocolVersion===5&&(f.length>2?(f.reasonCode=this._parseByte(),u("_parseConfirmation: packet.reasonCode `%d`",f.reasonCode)):f.reasonCode=0,f.length>3)){const g=this._parseProperties();Object.getOwnPropertyNames(g).length&&(f.properties=g)}return!0}_parseDisconnect(){const f=this.packet;if(u("_parseDisconnect"),this.settings.protocolVersion===5){this._list.length>0?f.reasonCode=this._parseByte():f.reasonCode=0;const g=this._parseProperties();Object.getOwnPropertyNames(g).length&&(f.properties=g)}return u("_parseDisconnect result: true"),!0}_parseAuth(){u("_parseAuth");const f=this.packet;if(this.settings.protocolVersion!==5)return this._emitError(new Error("Not supported auth packet for this version MQTT"));f.reasonCode=this._parseByte();const g=this._parseProperties();return Object.getOwnPropertyNames(g).length&&(f.properties=g),u("_parseAuth: result: true"),!0}_parseMessageId(){const f=this.packet;return f.messageId=this._parseNum(),f.messageId===null?(this._emitError(new Error("Cannot parse messageId")),!1):(u("_parseMessageId: packet.messageId %d",f.messageId),!0)}_parseString(f){const g=this._parseNum(),y=g+this._pos;if(g===-1||y>this._list.length||y>this.packet.length)return null;const p=this._list.toString("utf8",this._pos,y);return this._pos+=g,u("_parseString: result: %s",p),p}_parseStringPair(){return u("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){const f=this._parseNum(),g=f+this._pos;if(f===-1||g>this._list.length||g>this.packet.length)return null;const y=this._list.slice(this._pos,g);return this._pos+=f,u("_parseBuffer: result: %o",y),y}_parseNum(){if(this._list.length-this._pos<2)return-1;const f=this._list.readUInt16BE(this._pos);return this._pos+=2,u("_parseNum: result: %s",f),f}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;const f=this._list.readUInt32BE(this._pos);return this._pos+=4,u("_parse4ByteNum: result: %s",f),f}_parseVarByteNum(f){u("_parseVarByteNum");let g,y=0,p=1,m=0,x=!1;const k=this._pos?this._pos:0;for(;y<4&&k+y<this._list.length;){if(m+=p*((g=this._list.readUInt8(k+y++))&l.VARBYTEINT_MASK),p*=128,(g&l.VARBYTEINT_FIN_MASK)==0){x=!0;break}if(this._list.length<=y)break}return!x&&y===4&&this._list.length>=y&&this._emitError(new Error("Invalid variable byte integer")),k&&(this._pos+=y),u("_parseVarByteNum: result: %o",x=!!x&&(f?{bytes:y,value:m}:m)),x}_parseByte(){let f;return this._pos<this._list.length&&(f=this._list.readUInt8(this._pos),this._pos++),u("_parseByte: result: %o",f),f}_parseByType(f){switch(u("_parseByType: type: %s",f),f){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(){u("_parseProperties");const f=this._parseVarByteNum(),g=this._pos+f,y={};for(;this._pos<g;){const p=this._parseByte();if(!p)return this._emitError(new Error("Cannot parse property code type")),!1;const m=l.propertiesCodes[p];if(!m)return this._emitError(new Error("Unknown property")),!1;if(m!=="userProperties")y[m]?Array.isArray(y[m])?y[m].push(this._parseByType(l.propertiesTypes[m])):(y[m]=[y[m]],y[m].push(this._parseByType(l.propertiesTypes[m]))):y[m]=this._parseByType(l.propertiesTypes[m]);else{y[m]||(y[m]=Object.create(null));const x=this._parseByType(l.propertiesTypes[m]);if(y[m][x.name])if(Array.isArray(y[m][x.name]))y[m][x.name].push(x.value);else{const k=y[m][x.name];y[m][x.name]=[k],y[m][x.name].push(x.value)}else y[m][x.name]=x.value}}return y}_newPacket(){return u("_newPacket"),this.packet&&(this._list.consume(this.packet.length),u("_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)),u("_newPacket: new packet"),this.packet=new c,this._pos=0,!0}_emitError(f){u("_emitError"),this.error=f,this.emit("error",f)}}s.exports=h},{"./constants":38,"./packet":42,bl:15,debug:18,events:22}],44:[function(i,s,r){(function(a){(function(){const n=i("./constants"),c=a.allocUnsafe(0),l=a.from([0]),u=i("./numbers"),h=i("process-nextick-args").nextTick,v=i("debug")("mqtt-packet:writeToStream"),f=u.cache,g=u.generateNumber,y=u.generateCache,p=u.genBufVariableByteInt,m=u.generate4ByteBuffer;let x=F,k=!0;function w(j,O,z){switch(v("generate called"),O.cork&&(O.cork(),h(C,O)),k&&(k=!1,y()),v("generate: packet.cmd: %s",j.cmd),j.cmd){case"connect":return function(V,N,Y){const K=V||{},G=K.protocolId||"MQTT";let tt=K.protocolVersion||4;const Q=K.will;let Z=K.clean;const b=K.keepalive||0,T=K.clientId||"",S=K.username,D=K.password,W=K.properties;Z===void 0&&(Z=!0);let U=0;if(typeof G!="string"&&!a.isBuffer(G))return N.emit("error",new Error("Invalid protocolId")),!1;if(U+=G.length+2,tt!==3&&tt!==4&&tt!==5)return N.emit("error",new Error("Invalid protocol version")),!1;if(U+=1,(typeof T=="string"||a.isBuffer(T))&&(T||tt>=4)&&(T||Z))U+=a.byteLength(T)+2;else{if(tt<4)return N.emit("error",new Error("clientId must be supplied before 3.1.1")),!1;if(1*Z==0)return N.emit("error",new Error("clientId must be given if cleanSession set to 0")),!1}if(typeof b!="number"||b<0||b>65535||b%1!=0)return N.emit("error",new Error("Invalid keepalive")),!1;if(U+=2,U+=1,tt===5){var J=A(N,W);if(!J)return!1;U+=J.length}if(Q){if(typeof Q!="object")return N.emit("error",new Error("Invalid will")),!1;if(!Q.topic||typeof Q.topic!="string")return N.emit("error",new Error("Invalid will topic")),!1;if(U+=a.byteLength(Q.topic)+2,U+=2,Q.payload){if(!(Q.payload.length>=0))return N.emit("error",new Error("Invalid will payload")),!1;typeof Q.payload=="string"?U+=a.byteLength(Q.payload):U+=Q.payload.length}var it={};if(tt===5){if(!(it=A(N,Q.properties)))return!1;U+=it.length}}let et=!1;if(S!=null){if(!X(S))return N.emit("error",new Error("Invalid username")),!1;et=!0,U+=a.byteLength(S)+2}if(D!=null){if(!et)return N.emit("error",new Error("Username is required to use password")),!1;if(!X(D))return N.emit("error",new Error("Invalid password")),!1;U+=$(D)+2}N.write(n.CONNECT_HEADER),_(N,U),R(N,G),K.bridgeMode&&(tt+=128),N.write(tt===131?n.VERSION131:tt===132?n.VERSION132:tt===4?n.VERSION4:tt===5?n.VERSION5:n.VERSION3);let st=0;return st|=S!=null?n.USERNAME_MASK:0,st|=D!=null?n.PASSWORD_MASK:0,st|=Q&&Q.retain?n.WILL_RETAIN_MASK:0,st|=Q&&Q.qos?Q.qos<<n.WILL_QOS_SHIFT:0,st|=Q?n.WILL_FLAG_MASK:0,st|=Z?n.CLEAN_SESSION_MASK:0,N.write(a.from([st])),x(N,b),tt===5&&J.write(),R(N,T),Q&&(tt===5&&it.write(),L(N,Q.topic),R(N,Q.payload)),S!=null&&R(N,S),D!=null&&R(N,D),!0}(j,O);case"connack":return function(V,N,Y){const K=Y?Y.protocolVersion:4,G=V||{},tt=K===5?G.reasonCode:G.returnCode,Q=G.properties;let Z=2;if(typeof tt!="number")return N.emit("error",new Error("Invalid return code")),!1;let b=null;if(K===5){if(!(b=A(N,Q)))return!1;Z+=b.length}return N.write(n.CONNACK_HEADER),_(N,Z),N.write(G.sessionPresent?n.SESSIONPRESENT_HEADER:l),N.write(a.from([tt])),b!=null&&b.write(),!0}(j,O,z);case"publish":return function(V,N,Y){v("publish: packet: %o",V);const K=Y?Y.protocolVersion:4,G=V||{},tt=G.qos||0,Q=G.retain?n.RETAIN_MASK:0,Z=G.topic,b=G.payload||c,T=G.messageId,S=G.properties;let D=0;if(typeof Z=="string")D+=a.byteLength(Z)+2;else{if(!a.isBuffer(Z))return N.emit("error",new Error("Invalid topic")),!1;D+=Z.length+2}if(a.isBuffer(b)?D+=b.length:D+=a.byteLength(b),tt&&typeof T!="number")return N.emit("error",new Error("Invalid messageId")),!1;tt&&(D+=2);let W=null;if(K===5){if(!(W=A(N,S)))return!1;D+=W.length}return N.write(n.PUBLISH_HEADER[tt][G.dup?1:0][Q?1:0]),_(N,D),x(N,$(Z)),N.write(Z),tt>0&&x(N,T),W!=null&&W.write(),v("publish: payload: %o",b),N.write(b)}(j,O,z);case"puback":case"pubrec":case"pubrel":case"pubcomp":return function(V,N,Y){const K=Y?Y.protocolVersion:4,G=V||{},tt=G.cmd||"puback",Q=G.messageId,Z=G.dup&&tt==="pubrel"?n.DUP_MASK:0;let b=0;const T=G.reasonCode,S=G.properties;let D=K===5?3:2;if(tt==="pubrel"&&(b=1),typeof Q!="number")return N.emit("error",new Error("Invalid messageId")),!1;let W=null;if(K===5&&typeof S=="object"){if(!(W=P(N,S,Y,D)))return!1;D+=W.length}return N.write(n.ACKS[tt][b][Z][0]),_(N,D),x(N,Q),K===5&&N.write(a.from([T])),W!==null&&W.write(),!0}(j,O,z);case"subscribe":return function(V,N,Y){v("subscribe: packet: ");const K=Y?Y.protocolVersion:4,G=V||{},tt=G.dup?n.DUP_MASK:0,Q=G.messageId,Z=G.subscriptions,b=G.properties;let T=0;if(typeof Q!="number")return N.emit("error",new Error("Invalid messageId")),!1;T+=2;let S=null;if(K===5){if(!(S=A(N,b)))return!1;T+=S.length}if(typeof Z!="object"||!Z.length)return N.emit("error",new Error("Invalid subscriptions")),!1;for(let W=0;W<Z.length;W+=1){const U=Z[W].topic,J=Z[W].qos;if(typeof U!="string")return N.emit("error",new Error("Invalid subscriptions - invalid topic")),!1;if(typeof J!="number")return N.emit("error",new Error("Invalid subscriptions - invalid qos")),!1;if(K===5){if(typeof(Z[W].nl||!1)!="boolean")return N.emit("error",new Error("Invalid subscriptions - invalid No Local")),!1;if(typeof(Z[W].rap||!1)!="boolean")return N.emit("error",new Error("Invalid subscriptions - invalid Retain as Published")),!1;const st=Z[W].rh||0;if(typeof st!="number"||st>2)return N.emit("error",new Error("Invalid subscriptions - invalid Retain Handling")),!1}T+=a.byteLength(U)+2+1}v("subscribe: writing to stream: %o",n.SUBSCRIBE_HEADER),N.write(n.SUBSCRIBE_HEADER[1][tt?1:0][0]),_(N,T),x(N,Q),S!==null&&S.write();let D=!0;for(const W of Z){const U=W.topic,J=W.qos,it=+W.nl,et=+W.rap,st=W.rh;let ot;L(N,U),ot=n.SUBSCRIBE_OPTIONS_QOS[J],K===5&&(ot|=it?n.SUBSCRIBE_OPTIONS_NL:0,ot|=et?n.SUBSCRIBE_OPTIONS_RAP:0,ot|=st?n.SUBSCRIBE_OPTIONS_RH[st]:0),D=N.write(a.from([ot]))}return D}(j,O,z);case"suback":return function(V,N,Y){const K=Y?Y.protocolVersion:4,G=V||{},tt=G.messageId,Q=G.granted,Z=G.properties;let b=0;if(typeof tt!="number")return N.emit("error",new Error("Invalid messageId")),!1;if(b+=2,typeof Q!="object"||!Q.length)return N.emit("error",new Error("Invalid qos vector")),!1;for(let S=0;S<Q.length;S+=1){if(typeof Q[S]!="number")return N.emit("error",new Error("Invalid qos vector")),!1;b+=1}let T=null;if(K===5){if(!(T=P(N,Z,Y,b)))return!1;b+=T.length}return N.write(n.SUBACK_HEADER),_(N,b),x(N,tt),T!==null&&T.write(),N.write(a.from(Q))}(j,O,z);case"unsubscribe":return function(V,N,Y){const K=Y?Y.protocolVersion:4,G=V||{},tt=G.messageId,Q=G.dup?n.DUP_MASK:0,Z=G.unsubscriptions,b=G.properties;let T=0;if(typeof tt!="number")return N.emit("error",new Error("Invalid messageId")),!1;if(T+=2,typeof Z!="object"||!Z.length)return N.emit("error",new Error("Invalid unsubscriptions")),!1;for(let W=0;W<Z.length;W+=1){if(typeof Z[W]!="string")return N.emit("error",new Error("Invalid unsubscriptions")),!1;T+=a.byteLength(Z[W])+2}let S=null;if(K===5){if(!(S=A(N,b)))return!1;T+=S.length}N.write(n.UNSUBSCRIBE_HEADER[1][Q?1:0][0]),_(N,T),x(N,tt),S!==null&&S.write();let D=!0;for(let W=0;W<Z.length;W++)D=L(N,Z[W]);return D}(j,O,z);case"unsuback":return function(V,N,Y){const K=Y?Y.protocolVersion:4,G=V||{},tt=G.messageId,Q=G.dup?n.DUP_MASK:0,Z=G.granted,b=G.properties,T=G.cmd;let S=2;if(typeof tt!="number")return N.emit("error",new Error("Invalid messageId")),!1;if(K===5){if(typeof Z!="object"||!Z.length)return N.emit("error",new Error("Invalid qos vector")),!1;for(let W=0;W<Z.length;W+=1){if(typeof Z[W]!="number")return N.emit("error",new Error("Invalid qos vector")),!1;S+=1}}let D=null;if(K===5){if(!(D=P(N,b,Y,S)))return!1;S+=D.length}return N.write(n.ACKS[T][0][Q][0]),_(N,S),x(N,tt),D!==null&&D.write(),K===5&&N.write(a.from(Z)),!0}(j,O,z);case"pingreq":case"pingresp":return function(V,N,Y){return N.write(n.EMPTY[V.cmd])}(j,O);case"disconnect":return function(V,N,Y){const K=Y?Y.protocolVersion:4,G=V||{},tt=G.reasonCode,Q=G.properties;let Z=K===5?1:0,b=null;if(K===5){if(!(b=P(N,Q,Y,Z)))return!1;Z+=b.length}return N.write(a.from([n.codes.disconnect<<4])),_(N,Z),K===5&&N.write(a.from([tt])),b!==null&&b.write(),!0}(j,O,z);case"auth":return function(V,N,Y){const K=Y?Y.protocolVersion:4,G=V||{},tt=G.reasonCode,Q=G.properties;let Z=K===5?1:0;K!==5&&N.emit("error",new Error("Invalid mqtt version for auth packet"));const b=P(N,Q,Y,Z);return b?(Z+=b.length,N.write(a.from([n.codes.auth<<4])),_(N,Z),N.write(a.from([tt])),b!==null&&b.write(),!0):!1}(j,O,z);default:return O.emit("error",new Error("Unknown command")),!1}}function C(j){j.uncork()}Object.defineProperty(w,"cacheNumbers",{get:()=>x===F,set(j){j?(f&&Object.keys(f).length!==0||(k=!0),x=F):(k=!1,x=q)}});const I={};function _(j,O){if(O>n.VARBYTEINT_MAX)return j.emit("error",new Error(`Invalid variable byte integer: ${O}`)),!1;let z=I[O];return z||(z=p(O),O<16384&&(I[O]=z)),v("writeVarByteInt: writing to stream: %o",z),j.write(z)}function L(j,O){const z=a.byteLength(O);return x(j,z),v("writeString: %s",O),j.write(O,"utf8")}function E(j,O,z){L(j,O),L(j,z)}function F(j,O){return v("writeNumberCached: number: %d",O),v("writeNumberCached: %o",f[O]),j.write(f[O])}function q(j,O){const z=g(O);return v("writeNumberGenerated: %o",z),j.write(z)}function R(j,O){typeof O=="string"?L(j,O):O?(x(j,O.length),j.write(O)):x(j,0)}function A(j,O){if(typeof O!="object"||O.length!=null)return{length:1,write(){H(j,{},0)}};let z=0;function V(N,Y){let K=0;switch(n.propertiesTypes[N]){case"byte":if(typeof Y!="boolean")return j.emit("error",new Error(`Invalid ${N}: ${Y}`)),!1;K+=2;break;case"int8":if(typeof Y!="number"||Y<0||Y>255)return j.emit("error",new Error(`Invalid ${N}: ${Y}`)),!1;K+=2;break;case"binary":if(Y&&Y===null)return j.emit("error",new Error(`Invalid ${N}: ${Y}`)),!1;K+=1+a.byteLength(Y)+2;break;case"int16":if(typeof Y!="number"||Y<0||Y>65535)return j.emit("error",new Error(`Invalid ${N}: ${Y}`)),!1;K+=3;break;case"int32":if(typeof Y!="number"||Y<0||Y>4294967295)return j.emit("error",new Error(`Invalid ${N}: ${Y}`)),!1;K+=5;break;case"var":if(typeof Y!="number"||Y<0||Y>268435455)return j.emit("error",new Error(`Invalid ${N}: ${Y}`)),!1;K+=1+a.byteLength(p(Y));break;case"string":if(typeof Y!="string")return j.emit("error",new Error(`Invalid ${N}: ${Y}`)),!1;K+=3+a.byteLength(Y.toString());break;case"pair":if(typeof Y!="object")return j.emit("error",new Error(`Invalid ${N}: ${Y}`)),!1;K+=Object.getOwnPropertyNames(Y).reduce((G,tt)=>{const Q=Y[tt];return Array.isArray(Q)?G+=Q.reduce((Z,b)=>Z+=3+a.byteLength(tt.toString())+2+a.byteLength(b.toString()),0):G+=3+a.byteLength(tt.toString())+2+a.byteLength(Y[tt].toString()),G},0);break;default:return j.emit("error",new Error(`Invalid property ${N}: ${Y}`)),!1}return K}if(O)for(const N in O){let Y=0,K=0;const G=O[N];if(Array.isArray(G))for(let tt=0;tt<G.length;tt++){if(!(K=V(N,G[tt])))return!1;Y+=K}else{if(!(K=V(N,G)))return!1;Y=K}if(!Y)return!1;z+=Y}return{length:a.byteLength(p(z))+z,write(){H(j,O,z)}}}function P(j,O,z,V){const N=["reasonString","userProperties"],Y=z&&z.properties&&z.properties.maximumPacketSize?z.properties.maximumPacketSize:0;let K=A(j,O);if(Y)for(;V+K.length>Y;){const G=N.shift();if(!G||!O[G])return!1;delete O[G],K=A(j,O)}return K}function M(j,O,z){switch(n.propertiesTypes[O]){case"byte":j.write(a.from([n.properties[O]])),j.write(a.from([+z]));break;case"int8":j.write(a.from([n.properties[O]])),j.write(a.from([z]));break;case"binary":j.write(a.from([n.properties[O]])),R(j,z);break;case"int16":j.write(a.from([n.properties[O]])),x(j,z);break;case"int32":j.write(a.from([n.properties[O]])),function(V,N){const Y=m(N);v("write4ByteNumber: %o",Y),V.write(Y)}(j,z);break;case"var":j.write(a.from([n.properties[O]])),_(j,z);break;case"string":j.write(a.from([n.properties[O]])),L(j,z);break;case"pair":Object.getOwnPropertyNames(z).forEach(V=>{const N=z[V];Array.isArray(N)?N.forEach(Y=>{j.write(a.from([n.properties[O]])),E(j,V.toString(),Y.toString())}):(j.write(a.from([n.properties[O]])),E(j,V.toString(),N.toString()))});break;default:return j.emit("error",new Error(`Invalid property ${O} value: ${z}`)),!1}}function H(j,O,z){_(j,z);for(const V in O)if(Object.prototype.hasOwnProperty.call(O,V)&&O[V]!==null){const N=O[V];if(Array.isArray(N))for(let Y=0;Y<N.length;Y++)M(j,V,N[Y]);else M(j,V,N)}}function $(j){return j?j instanceof a?j.length:a.byteLength(j):0}function X(j){return typeof j=="string"||j instanceof a}s.exports=w}).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,n=60*a,c=60*n,l=24*c,u=7*l,h=365.25*l;function v(f,g,y,p){var m=g>=1.5*y;return Math.round(f/y)+" "+p+(m?"s":"")}s.exports=function(f,g){g=g||{};var y=typeof f;if(y==="string"&&f.length>0)return function(p){if(!((p=String(p)).length>100)){var m=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(p);if(m){var x=parseFloat(m[1]);switch((m[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return x*h;case"weeks":case"week":case"w":return x*u;case"days":case"day":case"d":return x*l;case"hours":case"hour":case"hrs":case"hr":case"h":return x*c;case"minutes":case"minute":case"mins":case"min":case"m":return x*n;case"seconds":case"second":case"secs":case"sec":case"s":return x*a;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return x;default:return}}}}(f);if(y==="number"&&isFinite(f))return g.long?function(p){var m=Math.abs(p);return m>=l?v(p,m,l,"day"):m>=c?v(p,m,c,"hour"):m>=n?v(p,m,n,"minute"):m>=a?v(p,m,a,"second"):p+" ms"}(f):function(p){var m=Math.abs(p);return m>=l?Math.round(p/l)+"d":m>=c?Math.round(p/c)+"h":m>=n?Math.round(p/n)+"m":m>=a?Math.round(p/a)+"s":p+"ms"}(f);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(f))}},{}],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,n=i("debug")("number-allocator:trace"),c=i("debug")("number-allocator:error");function l(h,v){this.low=h,this.high=v}function u(h,v){if(!(this instanceof u))return new u(h,v);this.min=h,this.max=v,this.ss=new a([],(f,g)=>f.compare(g)),n("Create"),this.clear()}l.prototype.equals=function(h){return this.low===h.low&&this.high===h.high},l.prototype.compare=function(h){return this.low<h.low&&this.high<h.low?-1:h.low<this.low&&h.high<this.low?1:0},u.prototype.firstVacant=function(){return this.ss.size()===0?null:this.ss.front().low},u.prototype.alloc=function(){if(this.ss.size()===0)return n("alloc():empty"),null;const h=this.ss.front(),v=h.low;return v+1<=h.high?++h.low:this.ss.eraseElementByPos(0),n("alloc():"+v),v},u.prototype.use=function(h){const v=new l(h,h),f=this.ss.lowerBound(v);if(f){if(f.equals(v))return this.ss.eraseElementByValue(f),n("use():"+h),!0;if(f.low>h)return!1;if(f.low===h)return++f.low,n("use():"+h),!0;if(f.high===h)return--f.high,n("use():"+h),!0;const g=f.low;return f.low=h+1,this.ss.insert(new l(g,h-1)),n("use():"+h),!0}return n("use():failed"),!1},u.prototype.free=function(h){if(h<this.min||h>this.max)return void c("free():"+h+" is out of range");const v=new l(h,h),f=this.ss.lowerBound(v);if(f){if(f.low<=h&&h<=f.high)return void c("free():"+h+" has already been vacant");if(f===this.ss.front())h+1===f.low?--f.low:this.ss.insert(v);else{const g=this.ss.reverseLowerBound(v);g.high+1===h?h+1===f.low?(this.ss.eraseElementByValue(g),f.low=g.low):g.high=h:h+1===f.low?f.low=h:this.ss.insert(v)}}else{if(f===this.ss.front())return void this.ss.insert(v);const g=this.ss.reverseLowerBound(v);g.high+1===h?g.high=h:this.ss.insert(v)}n("free():"+h)},u.prototype.clear=function(){n("clear()"),this.ss.clear(),this.ss.insert(new l(this.min,this.max))},u.prototype.intervalCount=function(){return this.ss.size()},u.prototype.dump=function(){console.log("length:"+this.ss.size());for(const h of this.ss)console.log(h)},s.exports=u},{debug:18,"js-sdsl":36}],48:[function(i,s,r){var a=i("wrappy");function n(l){var u=function(){return u.called?u.value:(u.called=!0,u.value=l.apply(this,arguments))};return u.called=!1,u}function c(l){var u=function(){if(u.called)throw new Error(u.onceError);return u.called=!0,u.value=l.apply(this,arguments)},h=l.name||"Function wrapped with `once`";return u.onceError=h+" shouldn't be called more than once",u.called=!1,u}s.exports=a(n),s.exports.strict=a(c),n.proto=n(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return n(this)},configurable:!0}),Object.defineProperty(Function.prototype,"onceStrict",{value:function(){return c(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(n,c,l,u){if(typeof n!="function")throw new TypeError('"callback" argument must be a function');var h,v,f=arguments.length;switch(f){case 0:case 1:return a.nextTick(n);case 2:return a.nextTick(function(){n.call(null,c)});case 3:return a.nextTick(function(){n.call(null,c,l)});case 4:return a.nextTick(function(){n.call(null,c,l,u)});default:for(h=new Array(f-1),v=0;v<h.length;)h[v++]=arguments[v];return a.nextTick(function(){n.apply(null,h)})}}}:s.exports=a}).call(this)}).call(this,i("_process"))},{_process:50}],50:[function(i,s,r){var a,n,c=s.exports={};function l(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}function h(w){if(a===setTimeout)return setTimeout(w,0);if((a===l||!a)&&setTimeout)return a=setTimeout,setTimeout(w,0);try{return a(w,0)}catch{try{return a.call(null,w,0)}catch{return a.call(this,w,0)}}}(function(){try{a=typeof setTimeout=="function"?setTimeout:l}catch{a=l}try{n=typeof clearTimeout=="function"?clearTimeout:u}catch{n=u}})();var v,f=[],g=!1,y=-1;function p(){g&&v&&(g=!1,v.length?f=v.concat(f):y=-1,f.length&&m())}function m(){if(!g){var w=h(p);g=!0;for(var C=f.length;C;){for(v=f,f=[];++y<C;)v&&v[y].run();y=-1,C=f.length}v=null,g=!1,function(I){if(n===clearTimeout)return clearTimeout(I);if((n===u||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(I);try{n(I)}catch{try{return n.call(null,I)}catch{return n.call(this,I)}}}(w)}}function x(w,C){this.fun=w,this.array=C}function k(){}c.nextTick=function(w){var C=new Array(arguments.length-1);if(arguments.length>1)for(var I=1;I<arguments.length;I++)C[I-1]=arguments[I];f.push(new x(w,C)),f.length!==1||g||h(m)},x.prototype.run=function(){this.fun.apply(null,this.array)},c.title="browser",c.browser=!0,c.env={},c.argv=[],c.version="",c.versions={},c.on=k,c.addListener=k,c.once=k,c.off=k,c.removeListener=k,c.removeAllListeners=k,c.emit=k,c.prependListener=k,c.prependOnceListener=k,c.listeners=function(w){return[]},c.binding=function(w){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(w){throw new Error("process.chdir is not supported")},c.umask=function(){return 0}},{}],51:[function(i,s,r){(function(a){(function(){(function(n){var c=typeof r=="object"&&r&&!r.nodeType&&r,l=typeof s=="object"&&s&&!s.nodeType&&s,u=typeof a=="object"&&a;u.global!==u&&u.window!==u&&u.self!==u||(n=u);var h,v,f=2147483647,g=36,y=1,p=26,m=38,x=700,k=72,w=128,C="-",I=/^xn--/,_=/[^\x20-\x7E]/,L=/[\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"},F=g-y,q=Math.floor,R=String.fromCharCode;function A(V){throw new RangeError(E[V])}function P(V,N){for(var Y=V.length,K=[];Y--;)K[Y]=N(V[Y]);return K}function M(V,N){var Y=V.split("@"),K="";return Y.length>1&&(K=Y[0]+"@",V=Y[1]),K+P((V=V.replace(L,".")).split("."),N).join(".")}function H(V){for(var N,Y,K=[],G=0,tt=V.length;G<tt;)(N=V.charCodeAt(G++))>=55296&&N<=56319&&G<tt?(64512&(Y=V.charCodeAt(G++)))==56320?K.push(((1023&N)<<10)+(1023&Y)+65536):(K.push(N),G--):K.push(N);return K}function $(V){return P(V,function(N){var Y="";return N>65535&&(Y+=R((N-=65536)>>>10&1023|55296),N=56320|1023&N),Y+=R(N)}).join("")}function X(V,N){return V+22+75*(V<26)-((N!=0)<<5)}function j(V,N,Y){var K=0;for(V=Y?q(V/x):V>>1,V+=q(V/N);V>F*p>>1;K+=g)V=q(V/F);return q(K+(F+1)*V/(V+m))}function O(V){var N,Y,K,G,tt,Q,Z,b,T,S,D,W=[],U=V.length,J=0,it=w,et=k;for((Y=V.lastIndexOf(C))<0&&(Y=0),K=0;K<Y;++K)V.charCodeAt(K)>=128&&A("not-basic"),W.push(V.charCodeAt(K));for(G=Y>0?Y+1:0;G<U;){for(tt=J,Q=1,Z=g;G>=U&&A("invalid-input"),((b=(D=V.charCodeAt(G++))-48<10?D-22:D-65<26?D-65:D-97<26?D-97:g)>=g||b>q((f-J)/Q))&&A("overflow"),J+=b*Q,!(b<(T=Z<=et?y:Z>=et+p?p:Z-et));Z+=g)Q>q(f/(S=g-T))&&A("overflow"),Q*=S;et=j(J-tt,N=W.length+1,tt==0),q(J/N)>f-it&&A("overflow"),it+=q(J/N),J%=N,W.splice(J++,0,it)}return $(W)}function z(V){var N,Y,K,G,tt,Q,Z,b,T,S,D,W,U,J,it,et=[];for(W=(V=H(V)).length,N=w,Y=0,tt=k,Q=0;Q<W;++Q)(D=V[Q])<128&&et.push(R(D));for(K=G=et.length,G&&et.push(C);K<W;){for(Z=f,Q=0;Q<W;++Q)(D=V[Q])>=N&&D<Z&&(Z=D);for(Z-N>q((f-Y)/(U=K+1))&&A("overflow"),Y+=(Z-N)*U,N=Z,Q=0;Q<W;++Q)if((D=V[Q])<N&&++Y>f&&A("overflow"),D==N){for(b=Y,T=g;!(b<(S=T<=tt?y:T>=tt+p?p:T-tt));T+=g)it=b-S,J=g-S,et.push(R(X(S+it%J,0))),b=q(it/J);et.push(R(X(b,0))),tt=j(Y,U,K==G),Y=0,++K}++Y,++N}return et.join("")}if(h={version:"1.4.1",ucs2:{decode:H,encode:$},decode:O,encode:z,toASCII:function(V){return M(V,function(N){return _.test(N)?"xn--"+z(N):N})},toUnicode:function(V){return M(V,function(N){return I.test(N)?O(N.slice(4).toLowerCase()):N})}},c&&l)if(s.exports==c)l.exports=h;else for(v in h)h.hasOwnProperty(v)&&(c[v]=h[v]);else n.punycode=h})(this)}).call(this)}).call(this,typeof commonjsGlobal<"u"?commonjsGlobal:typeof self<"u"?self:typeof window<"u"?window:{})},{}],52:[function(i,s,r){function a(c,l){return Object.prototype.hasOwnProperty.call(c,l)}s.exports=function(c,l,u,h){l=l||"&",u=u||"=";var v={};if(typeof c!="string"||c.length===0)return v;var f=/\+/g;c=c.split(l);var g=1e3;h&&typeof h.maxKeys=="number"&&(g=h.maxKeys);var y=c.length;g>0&&y>g&&(y=g);for(var p=0;p<y;++p){var m,x,k,w,C=c[p].replace(f,"%20"),I=C.indexOf(u);I>=0?(m=C.substr(0,I),x=C.substr(I+1)):(m=C,x=""),k=decodeURIComponent(m),w=decodeURIComponent(x),a(v,k)?n(v[k])?v[k].push(w):v[k]=[v[k],w]:v[k]=w}return v};var n=Array.isArray||function(c){return Object.prototype.toString.call(c)==="[object Array]"}},{}],53:[function(i,s,r){var a=function(u){switch(typeof u){case"string":return u;case"boolean":return u?"true":"false";case"number":return isFinite(u)?u:"";default:return""}};s.exports=function(u,h,v,f){return h=h||"&",v=v||"=",u===null&&(u=void 0),typeof u=="object"?c(l(u),function(g){var y=encodeURIComponent(a(g))+v;return n(u[g])?c(u[g],function(p){return y+encodeURIComponent(a(p))}).join(h):y+encodeURIComponent(a(u[g]))}).join(h):f?encodeURIComponent(a(f))+v+encodeURIComponent(a(u)):""};var n=Array.isArray||function(u){return Object.prototype.toString.call(u)==="[object Array]"};function c(u,h){if(u.map)return u.map(h);for(var v=[],f=0;f<u.length;f++)v.push(h(u[f],f));return v}var l=Object.keys||function(u){var h=[];for(var v in u)Object.prototype.hasOwnProperty.call(u,v)&&h.push(v);return h}},{}],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 n(l,u,h){h||(h=Error);var v=function(f){var g,y;function p(m,x,k){return f.call(this,function(w,C,I){return typeof u=="string"?u:u(w,C,I)}(m,x,k))||this}return y=f,(g=p).prototype=Object.create(y.prototype),g.prototype.constructor=g,g.__proto__=y,p}(h);v.prototype.name=h.name,v.prototype.code=l,a[l]=v}function c(l,u){if(Array.isArray(l)){var h=l.length;return l=l.map(function(v){return String(v)}),h>2?"one of ".concat(u," ").concat(l.slice(0,h-1).join(", "),", or ")+l[h-1]:h===2?"one of ".concat(u," ").concat(l[0]," or ").concat(l[1]):"of ".concat(u," ").concat(l[0])}return"of ".concat(u," ").concat(String(l))}n("ERR_INVALID_OPT_VALUE",function(l,u){return'The value "'+u+'" is invalid for option "'+l+'"'},TypeError),n("ERR_INVALID_ARG_TYPE",function(l,u,h){var v,f,g;if(typeof u=="string"&&(f="not ",u.substr(0,f.length)===f)?(v="must not be",u=u.replace(/^not /,"")):v="must be",function(p,m,x){return(x===void 0||x>p.length)&&(x=p.length),p.substring(x-m.length,x)===m}(l," argument"))g="The ".concat(l," ").concat(v," ").concat(c(u,"type"));else{var y=function(p,m,x){return typeof x!="number"&&(x=0),!(x+m.length>p.length)&&p.indexOf(m,x)!==-1}(l,".")?"property":"argument";g='The "'.concat(l,'" ').concat(y," ").concat(v," ").concat(c(u,"type"))}return g+=". Received type ".concat(typeof h)},TypeError),n("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),n("ERR_METHOD_NOT_IMPLEMENTED",function(l){return"The "+l+" method is not implemented"}),n("ERR_STREAM_PREMATURE_CLOSE","Premature close"),n("ERR_STREAM_DESTROYED",function(l){return"Cannot call "+l+" after a stream was destroyed"}),n("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),n("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),n("ERR_STREAM_WRITE_AFTER_END","write after end"),n("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),n("ERR_UNKNOWN_ENCODING",function(l){return"Unknown encoding: "+l},TypeError),n("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),s.exports.codes=a},{}],56:[function(i,s,r){(function(a){(function(){var n=Object.keys||function(p){var m=[];for(var x in p)m.push(x);return m};s.exports=f;var c=i("./_stream_readable"),l=i("./_stream_writable");i("inherits")(f,c);for(var u=n(l.prototype),h=0;h<u.length;h++){var v=u[h];f.prototype[v]||(f.prototype[v]=l.prototype[v])}function f(p){if(!(this instanceof f))return new f(p);c.call(this,p),l.call(this,p),this.allowHalfOpen=!0,p&&(p.readable===!1&&(this.readable=!1),p.writable===!1&&(this.writable=!1),p.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",g)))}function g(){this._writableState.ended||a.nextTick(y,this)}function y(p){p.end()}Object.defineProperty(f.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(f.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(f.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(f.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._writableState!==void 0&&this._readableState.destroyed&&this._writableState.destroyed},set:function(p){this._readableState!==void 0&&this._writableState!==void 0&&(this._readableState.destroyed=p,this._writableState.destroyed=p)}})}).call(this)}).call(this,i("_process"))},{"./_stream_readable":58,"./_stream_writable":60,_process:50,inherits:24}],57:[function(i,s,r){s.exports=n;var a=i("./_stream_transform");function n(c){if(!(this instanceof n))return new n(c);a.call(this,c)}i("inherits")(n,a),n.prototype._transform=function(c,l,u){u(null,c)}},{"./_stream_transform":59,inherits:24}],58:[function(i,s,r){(function(a,n){(function(){var c;s.exports=A,A.ReadableState=R,i("events").EventEmitter;var l=function(b,T){return b.listeners(T).length},u=i("./internal/streams/stream"),h=i("buffer").Buffer,v=n.Uint8Array||function(){},f,g=i("util");f=g&&g.debuglog?g.debuglog("stream"):function(){};var y,p,m,x=i("./internal/streams/buffer_list"),k=i("./internal/streams/destroy"),w=i("./internal/streams/state").getHighWaterMark,C=i("../errors").codes,I=C.ERR_INVALID_ARG_TYPE,_=C.ERR_STREAM_PUSH_AFTER_EOF,L=C.ERR_METHOD_NOT_IMPLEMENTED,E=C.ERR_STREAM_UNSHIFT_AFTER_END_EVENT;i("inherits")(A,u);var F=k.errorOrDestroy,q=["error","close","destroy","pause","resume"];function R(b,T,S){c=c||i("./_stream_duplex"),b=b||{},typeof S!="boolean"&&(S=T instanceof c),this.objectMode=!!b.objectMode,S&&(this.objectMode=this.objectMode||!!b.readableObjectMode),this.highWaterMark=w(this,b,"readableHighWaterMark",S),this.buffer=new x,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=b.emitClose!==!1,this.autoDestroy=!!b.autoDestroy,this.destroyed=!1,this.defaultEncoding=b.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,b.encoding&&(y||(y=i("string_decoder/").StringDecoder),this.decoder=new y(b.encoding),this.encoding=b.encoding)}function A(b){if(c=c||i("./_stream_duplex"),!(this instanceof A))return new A(b);var T=this instanceof c;this._readableState=new R(b,this,T),this.readable=!0,b&&(typeof b.read=="function"&&(this._read=b.read),typeof b.destroy=="function"&&(this._destroy=b.destroy)),u.call(this)}function P(b,T,S,D,W){f("readableAddChunk",T);var U,J=b._readableState;if(T===null)J.reading=!1,function(it,et){if(f("onEofChunk"),!et.ended){if(et.decoder){var st=et.decoder.end();st&&st.length&&(et.buffer.push(st),et.length+=et.objectMode?1:st.length)}et.ended=!0,et.sync?X(it):(et.needReadable=!1,et.emittedReadable||(et.emittedReadable=!0,j(it)))}}(b,J);else if(W||(U=function(it,et){var st;ot=et,h.isBuffer(ot)||ot instanceof v||typeof et=="string"||et===void 0||it.objectMode||(st=new I("chunk",["string","Buffer","Uint8Array"],et));var ot;return st}(J,T)),U)F(b,U);else if(J.objectMode||T&&T.length>0)if(typeof T=="string"||J.objectMode||Object.getPrototypeOf(T)===h.prototype||(T=function(it){return h.from(it)}(T)),D)J.endEmitted?F(b,new E):M(b,J,T,!0);else if(J.ended)F(b,new _);else{if(J.destroyed)return!1;J.reading=!1,J.decoder&&!S?(T=J.decoder.write(T),J.objectMode||T.length!==0?M(b,J,T,!1):O(b,J)):M(b,J,T,!1)}else D||(J.reading=!1,O(b,J));return!J.ended&&(J.length<J.highWaterMark||J.length===0)}function M(b,T,S,D){T.flowing&&T.length===0&&!T.sync?(T.awaitDrain=0,b.emit("data",S)):(T.length+=T.objectMode?1:S.length,D?T.buffer.unshift(S):T.buffer.push(S),T.needReadable&&X(b)),O(b,T)}Object.defineProperty(A.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._readableState.destroyed},set:function(b){this._readableState&&(this._readableState.destroyed=b)}}),A.prototype.destroy=k.destroy,A.prototype._undestroy=k.undestroy,A.prototype._destroy=function(b,T){T(b)},A.prototype.push=function(b,T){var S,D=this._readableState;return D.objectMode?S=!0:typeof b=="string"&&((T=T||D.defaultEncoding)!==D.encoding&&(b=h.from(b,T),T=""),S=!0),P(this,b,T,!1,S)},A.prototype.unshift=function(b){return P(this,b,null,!0,!1)},A.prototype.isPaused=function(){return this._readableState.flowing===!1},A.prototype.setEncoding=function(b){y||(y=i("string_decoder/").StringDecoder);var T=new y(b);this._readableState.decoder=T,this._readableState.encoding=this._readableState.decoder.encoding;for(var S=this._readableState.buffer.head,D="";S!==null;)D+=T.write(S.data),S=S.next;return this._readableState.buffer.clear(),D!==""&&this._readableState.buffer.push(D),this._readableState.length=D.length,this};var H=1073741824;function $(b,T){return b<=0||T.length===0&&T.ended?0:T.objectMode?1:b!=b?T.flowing&&T.length?T.buffer.head.data.length:T.length:(b>T.highWaterMark&&(T.highWaterMark=function(S){return S>=H?S=H:(S--,S|=S>>>1,S|=S>>>2,S|=S>>>4,S|=S>>>8,S|=S>>>16,S++),S}(b)),b<=T.length?b:T.ended?T.length:(T.needReadable=!0,0))}function X(b){var T=b._readableState;f("emitReadable",T.needReadable,T.emittedReadable),T.needReadable=!1,T.emittedReadable||(f("emitReadable",T.flowing),T.emittedReadable=!0,a.nextTick(j,b))}function j(b){var T=b._readableState;f("emitReadable_",T.destroyed,T.length,T.ended),T.destroyed||!T.length&&!T.ended||(b.emit("readable"),T.emittedReadable=!1),T.needReadable=!T.flowing&&!T.ended&&T.length<=T.highWaterMark,K(b)}function O(b,T){T.readingMore||(T.readingMore=!0,a.nextTick(z,b,T))}function z(b,T){for(;!T.reading&&!T.ended&&(T.length<T.highWaterMark||T.flowing&&T.length===0);){var S=T.length;if(f("maybeReadMore read 0"),b.read(0),S===T.length)break}T.readingMore=!1}function V(b){var T=b._readableState;T.readableListening=b.listenerCount("readable")>0,T.resumeScheduled&&!T.paused?T.flowing=!0:b.listenerCount("data")>0&&b.resume()}function N(b){f("readable nexttick read 0"),b.read(0)}function Y(b,T){f("resume",T.reading),T.reading||b.read(0),T.resumeScheduled=!1,b.emit("resume"),K(b),T.flowing&&!T.reading&&b.read(0)}function K(b){var T=b._readableState;for(f("flow",T.flowing);T.flowing&&b.read()!==null;);}function G(b,T){return T.length===0?null:(T.objectMode?S=T.buffer.shift():!b||b>=T.length?(S=T.decoder?T.buffer.join(""):T.buffer.length===1?T.buffer.first():T.buffer.concat(T.length),T.buffer.clear()):S=T.buffer.consume(b,T.decoder),S);var S}function tt(b){var T=b._readableState;f("endReadable",T.endEmitted),T.endEmitted||(T.ended=!0,a.nextTick(Q,T,b))}function Q(b,T){if(f("endReadableNT",b.endEmitted,b.length),!b.endEmitted&&b.length===0&&(b.endEmitted=!0,T.readable=!1,T.emit("end"),b.autoDestroy)){var S=T._writableState;(!S||S.autoDestroy&&S.finished)&&T.destroy()}}function Z(b,T){for(var S=0,D=b.length;S<D;S++)if(b[S]===T)return S;return-1}A.prototype.read=function(b){f("read",b),b=parseInt(b,10);var T=this._readableState,S=b;if(b!==0&&(T.emittedReadable=!1),b===0&&T.needReadable&&((T.highWaterMark!==0?T.length>=T.highWaterMark:T.length>0)||T.ended))return f("read: emitReadable",T.length,T.ended),T.length===0&&T.ended?tt(this):X(this),null;if((b=$(b,T))===0&&T.ended)return T.length===0&&tt(this),null;var D,W=T.needReadable;return f("need readable",W),(T.length===0||T.length-b<T.highWaterMark)&&f("length less than watermark",W=!0),T.ended||T.reading?f("reading or ended",W=!1):W&&(f("do read"),T.reading=!0,T.sync=!0,T.length===0&&(T.needReadable=!0),this._read(T.highWaterMark),T.sync=!1,T.reading||(b=$(S,T))),(D=b>0?G(b,T):null)===null?(T.needReadable=T.length<=T.highWaterMark,b=0):(T.length-=b,T.awaitDrain=0),T.length===0&&(T.ended||(T.needReadable=!0),S!==b&&T.ended&&tt(this)),D!==null&&this.emit("data",D),D},A.prototype._read=function(b){F(this,new L("_read()"))},A.prototype.pipe=function(b,T){var S=this,D=this._readableState;switch(D.pipesCount){case 0:D.pipes=b;break;case 1:D.pipes=[D.pipes,b];break;default:D.pipes.push(b)}D.pipesCount+=1,f("pipe count=%d opts=%j",D.pipesCount,T);var W=(!T||T.end!==!1)&&b!==a.stdout&&b!==a.stderr?J:ct;function U(rt,at){f("onunpipe"),rt===S&&at&&at.hasUnpiped===!1&&(at.hasUnpiped=!0,f("cleanup"),b.removeListener("close",lt),b.removeListener("finish",nt),b.removeListener("drain",it),b.removeListener("error",ot),b.removeListener("unpipe",U),S.removeListener("end",J),S.removeListener("end",ct),S.removeListener("data",st),et=!0,!D.awaitDrain||b._writableState&&!b._writableState.needDrain||it())}function J(){f("onend"),b.end()}D.endEmitted?a.nextTick(W):S.once("end",W),b.on("unpipe",U);var it=function(rt){return function(){var at=rt._readableState;f("pipeOnDrain",at.awaitDrain),at.awaitDrain&&at.awaitDrain--,at.awaitDrain===0&&l(rt,"data")&&(at.flowing=!0,K(rt))}}(S);b.on("drain",it);var et=!1;function st(rt){f("ondata");var at=b.write(rt);f("dest.write",at),at===!1&&((D.pipesCount===1&&D.pipes===b||D.pipesCount>1&&Z(D.pipes,b)!==-1)&&!et&&(f("false write response, pause",D.awaitDrain),D.awaitDrain++),S.pause())}function ot(rt){f("onerror",rt),ct(),b.removeListener("error",ot),l(b,"error")===0&&F(b,rt)}function lt(){b.removeListener("finish",nt),ct()}function nt(){f("onfinish"),b.removeListener("close",lt),ct()}function ct(){f("unpipe"),S.unpipe(b)}return S.on("data",st),function(rt,at,ht){if(typeof rt.prependListener=="function")return rt.prependListener(at,ht);rt._events&&rt._events[at]?Array.isArray(rt._events[at])?rt._events[at].unshift(ht):rt._events[at]=[ht,rt._events[at]]:rt.on(at,ht)}(b,"error",ot),b.once("close",lt),b.once("finish",nt),b.emit("pipe",S),D.flowing||(f("pipe resume"),S.resume()),b},A.prototype.unpipe=function(b){var T=this._readableState,S={hasUnpiped:!1};if(T.pipesCount===0)return this;if(T.pipesCount===1)return b&&b!==T.pipes?this:(b||(b=T.pipes),T.pipes=null,T.pipesCount=0,T.flowing=!1,b&&b.emit("unpipe",this,S),this);if(!b){var D=T.pipes,W=T.pipesCount;T.pipes=null,T.pipesCount=0,T.flowing=!1;for(var U=0;U<W;U++)D[U].emit("unpipe",this,{hasUnpiped:!1});return this}var J=Z(T.pipes,b);return J===-1?this:(T.pipes.splice(J,1),T.pipesCount-=1,T.pipesCount===1&&(T.pipes=T.pipes[0]),b.emit("unpipe",this,S),this)},A.prototype.on=function(b,T){var S=u.prototype.on.call(this,b,T),D=this._readableState;return b==="data"?(D.readableListening=this.listenerCount("readable")>0,D.flowing!==!1&&this.resume()):b==="readable"&&(D.endEmitted||D.readableListening||(D.readableListening=D.needReadable=!0,D.flowing=!1,D.emittedReadable=!1,f("on readable",D.length,D.reading),D.length?X(this):D.reading||a.nextTick(N,this))),S},A.prototype.addListener=A.prototype.on,A.prototype.removeListener=function(b,T){var S=u.prototype.removeListener.call(this,b,T);return b==="readable"&&a.nextTick(V,this),S},A.prototype.removeAllListeners=function(b){var T=u.prototype.removeAllListeners.apply(this,arguments);return b!=="readable"&&b!==void 0||a.nextTick(V,this),T},A.prototype.resume=function(){var b=this._readableState;return b.flowing||(f("resume"),b.flowing=!b.readableListening,function(T,S){S.resumeScheduled||(S.resumeScheduled=!0,a.nextTick(Y,T,S))}(this,b)),b.paused=!1,this},A.prototype.pause=function(){return f("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(f("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},A.prototype.wrap=function(b){var T=this,S=this._readableState,D=!1;for(var W in b.on("end",function(){if(f("wrapped end"),S.decoder&&!S.ended){var J=S.decoder.end();J&&J.length&&T.push(J)}T.push(null)}),b.on("data",function(J){f("wrapped data"),S.decoder&&(J=S.decoder.write(J)),(!S.objectMode||J!=null)&&(S.objectMode||J&&J.length)&&(T.push(J)||(D=!0,b.pause()))}),b)this[W]===void 0&&typeof b[W]=="function"&&(this[W]=function(J){return function(){return b[J].apply(b,arguments)}}(W));for(var U=0;U<q.length;U++)b.on(q[U],this.emit.bind(this,q[U]));return this._read=function(J){f("wrapped _read",J),D&&(D=!1,b.resume())},this},typeof Symbol=="function"&&(A.prototype[Symbol.asyncIterator]=function(){return p===void 0&&(p=i("./internal/streams/async_iterator")),p(this)}),Object.defineProperty(A.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(A.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(A.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(b){this._readableState&&(this._readableState.flowing=b)}}),A._fromList=G,Object.defineProperty(A.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}}),typeof Symbol=="function"&&(A.from=function(b,T){return m===void 0&&(m=i("./internal/streams/from")),m(A,b,T)})}).call(this)}).call(this,i("_process"),typeof commonjsGlobal<"u"?commonjsGlobal: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=v;var a=i("../errors").codes,n=a.ERR_METHOD_NOT_IMPLEMENTED,c=a.ERR_MULTIPLE_CALLBACK,l=a.ERR_TRANSFORM_ALREADY_TRANSFORMING,u=a.ERR_TRANSFORM_WITH_LENGTH_0,h=i("./_stream_duplex");function v(y){if(!(this instanceof v))return new v(y);h.call(this,y),this._transformState={afterTransform:(function(p,m){var x=this._transformState;x.transforming=!1;var k=x.writecb;if(k===null)return this.emit("error",new c);x.writechunk=null,x.writecb=null,m!=null&&this.push(m),k(p);var w=this._readableState;w.reading=!1,(w.needReadable||w.length<w.highWaterMark)&&this._read(w.highWaterMark)}).bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,y&&(typeof y.transform=="function"&&(this._transform=y.transform),typeof y.flush=="function"&&(this._flush=y.flush)),this.on("prefinish",f)}function f(){var y=this;typeof this._flush!="function"||this._readableState.destroyed?g(this,null,null):this._flush(function(p,m){g(y,p,m)})}function g(y,p,m){if(p)return y.emit("error",p);if(m!=null&&y.push(m),y._writableState.length)throw new u;if(y._transformState.transforming)throw new l;return y.push(null)}i("inherits")(v,h),v.prototype.push=function(y,p){return this._transformState.needTransform=!1,h.prototype.push.call(this,y,p)},v.prototype._transform=function(y,p,m){m(new n("_transform()"))},v.prototype._write=function(y,p,m){var x=this._transformState;if(x.writecb=m,x.writechunk=y,x.writeencoding=p,!x.transforming){var k=this._readableState;(x.needTransform||k.needReadable||k.length<k.highWaterMark)&&this._read(k.highWaterMark)}},v.prototype._read=function(y){var p=this._transformState;p.writechunk===null||p.transforming?p.needTransform=!0:(p.transforming=!0,this._transform(p.writechunk,p.writeencoding,p.afterTransform))},v.prototype._destroy=function(y,p){h.prototype._destroy.call(this,y,function(m){p(m)})}},{"../errors":55,"./_stream_duplex":56,inherits:24}],60:[function(i,s,r){(function(a,n){(function(){function c(O){var z=this;this.next=null,this.entry=null,this.finish=function(){(function(V,N,Y){var K=V.entry;for(V.entry=null;K;){var G=K.callback;N.pendingcb--,G(Y),K=K.next}N.corkedRequestsFree.next=V})(z,O)}}var l;s.exports=A,A.WritableState=R;var u={deprecate:i("util-deprecate")},h=i("./internal/streams/stream"),v=i("buffer").Buffer,f=n.Uint8Array||function(){},g,y=i("./internal/streams/destroy"),p=i("./internal/streams/state").getHighWaterMark,m=i("../errors").codes,x=m.ERR_INVALID_ARG_TYPE,k=m.ERR_METHOD_NOT_IMPLEMENTED,w=m.ERR_MULTIPLE_CALLBACK,C=m.ERR_STREAM_CANNOT_PIPE,I=m.ERR_STREAM_DESTROYED,_=m.ERR_STREAM_NULL_VALUES,L=m.ERR_STREAM_WRITE_AFTER_END,E=m.ERR_UNKNOWN_ENCODING,F=y.errorOrDestroy;function q(){}function R(O,z,V){l=l||i("./_stream_duplex"),O=O||{},typeof V!="boolean"&&(V=z instanceof l),this.objectMode=!!O.objectMode,V&&(this.objectMode=this.objectMode||!!O.writableObjectMode),this.highWaterMark=p(this,O,"writableHighWaterMark",V),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var N=O.decodeStrings===!1;this.decodeStrings=!N,this.defaultEncoding=O.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(Y){(function(K,G){var tt=K._writableState,Q=tt.sync,Z=tt.writecb;if(typeof Z!="function")throw new w;if(function(T){T.writing=!1,T.writecb=null,T.length-=T.writelen,T.writelen=0}(tt),G)(function(T,S,D,W,U){--S.pendingcb,D?(a.nextTick(U,W),a.nextTick(j,T,S),T._writableState.errorEmitted=!0,F(T,W)):(U(W),T._writableState.errorEmitted=!0,F(T,W),j(T,S))})(K,tt,Q,G,Z);else{var b=$(tt)||K.destroyed;b||tt.corked||tt.bufferProcessing||!tt.bufferedRequest||H(K,tt),Q?a.nextTick(M,K,tt,b,Z):M(K,tt,b,Z)}})(z,Y)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=O.emitClose!==!1,this.autoDestroy=!!O.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new c(this)}function A(O){var z=this instanceof(l=l||i("./_stream_duplex"));if(!z&&!g.call(A,this))return new A(O);this._writableState=new R(O,this,z),this.writable=!0,O&&(typeof O.write=="function"&&(this._write=O.write),typeof O.writev=="function"&&(this._writev=O.writev),typeof O.destroy=="function"&&(this._destroy=O.destroy),typeof O.final=="function"&&(this._final=O.final)),h.call(this)}function P(O,z,V,N,Y,K,G){z.writelen=N,z.writecb=G,z.writing=!0,z.sync=!0,z.destroyed?z.onwrite(new I("write")):V?O._writev(Y,z.onwrite):O._write(Y,K,z.onwrite),z.sync=!1}function M(O,z,V,N){V||function(Y,K){K.length===0&&K.needDrain&&(K.needDrain=!1,Y.emit("drain"))}(O,z),z.pendingcb--,N(),j(O,z)}function H(O,z){z.bufferProcessing=!0;var V=z.bufferedRequest;if(O._writev&&V&&V.next){var N=z.bufferedRequestCount,Y=new Array(N),K=z.corkedRequestsFree;K.entry=V;for(var G=0,tt=!0;V;)Y[G]=V,V.isBuf||(tt=!1),V=V.next,G+=1;Y.allBuffers=tt,P(O,z,!0,z.length,Y,"",K.finish),z.pendingcb++,z.lastBufferedRequest=null,K.next?(z.corkedRequestsFree=K.next,K.next=null):z.corkedRequestsFree=new c(z),z.bufferedRequestCount=0}else{for(;V;){var Q=V.chunk,Z=V.encoding,b=V.callback;if(P(O,z,!1,z.objectMode?1:Q.length,Q,Z,b),V=V.next,z.bufferedRequestCount--,z.writing)break}V===null&&(z.lastBufferedRequest=null)}z.bufferedRequest=V,z.bufferProcessing=!1}function $(O){return O.ending&&O.length===0&&O.bufferedRequest===null&&!O.finished&&!O.writing}function X(O,z){O._final(function(V){z.pendingcb--,V&&F(O,V),z.prefinished=!0,O.emit("prefinish"),j(O,z)})}function j(O,z){var V=$(z);if(V&&(function(Y,K){K.prefinished||K.finalCalled||(typeof Y._final!="function"||K.destroyed?(K.prefinished=!0,Y.emit("prefinish")):(K.pendingcb++,K.finalCalled=!0,a.nextTick(X,Y,K)))}(O,z),z.pendingcb===0&&(z.finished=!0,O.emit("finish"),z.autoDestroy))){var N=O._readableState;(!N||N.autoDestroy&&N.endEmitted)&&O.destroy()}return V}i("inherits")(A,h),R.prototype.getBuffer=function(){for(var O=this.bufferedRequest,z=[];O;)z.push(O),O=O.next;return z},function(){try{Object.defineProperty(R.prototype,"buffer",{get:u.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"?(g=Function.prototype[Symbol.hasInstance],Object.defineProperty(A,Symbol.hasInstance,{value:function(O){return!!g.call(this,O)||this===A&&O&&O._writableState instanceof R}})):g=function(O){return O instanceof this},A.prototype.pipe=function(){F(this,new C)},A.prototype.write=function(O,z,V){var N,Y=this._writableState,K=!1,G=!Y.objectMode&&(N=O,v.isBuffer(N)||N instanceof f);return G&&!v.isBuffer(O)&&(O=function(tt){return v.from(tt)}(O)),typeof z=="function"&&(V=z,z=null),G?z="buffer":z||(z=Y.defaultEncoding),typeof V!="function"&&(V=q),Y.ending?function(tt,Q){var Z=new L;F(tt,Z),a.nextTick(Q,Z)}(this,V):(G||function(tt,Q,Z,b){var T;return Z===null?T=new _:typeof Z=="string"||Q.objectMode||(T=new x("chunk",["string","Buffer"],Z)),!T||(F(tt,T),a.nextTick(b,T),!1)}(this,Y,O,V))&&(Y.pendingcb++,K=function(tt,Q,Z,b,T,S){if(!Z){var D=function(it,et,st){return it.objectMode||it.decodeStrings===!1||typeof et!="string"||(et=v.from(et,st)),et}(Q,b,T);b!==D&&(Z=!0,T="buffer",b=D)}var W=Q.objectMode?1:b.length;Q.length+=W;var U=Q.length<Q.highWaterMark;if(U||(Q.needDrain=!0),Q.writing||Q.corked){var J=Q.lastBufferedRequest;Q.lastBufferedRequest={chunk:b,encoding:T,isBuf:Z,callback:S,next:null},J?J.next=Q.lastBufferedRequest:Q.bufferedRequest=Q.lastBufferedRequest,Q.bufferedRequestCount+=1}else P(tt,Q,!1,W,b,T,S);return U}(this,Y,G,O,z,V)),K},A.prototype.cork=function(){this._writableState.corked++},A.prototype.uncork=function(){var O=this._writableState;O.corked&&(O.corked--,O.writing||O.corked||O.bufferProcessing||!O.bufferedRequest||H(this,O))},A.prototype.setDefaultEncoding=function(O){if(typeof O=="string"&&(O=O.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((O+"").toLowerCase())>-1))throw new E(O);return this._writableState.defaultEncoding=O,this},Object.defineProperty(A.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(A.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),A.prototype._write=function(O,z,V){V(new k("_write()"))},A.prototype._writev=null,A.prototype.end=function(O,z,V){var N=this._writableState;return typeof O=="function"?(V=O,O=null,z=null):typeof z=="function"&&(V=z,z=null),O!=null&&this.write(O,z),N.corked&&(N.corked=1,this.uncork()),N.ending||function(Y,K,G){K.ending=!0,j(Y,K),G&&(K.finished?a.nextTick(G):Y.once("finish",G)),K.ended=!0,Y.writable=!1}(this,N,V),this},Object.defineProperty(A.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(A.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState!==void 0&&this._writableState.destroyed},set:function(O){this._writableState&&(this._writableState.destroyed=O)}}),A.prototype.destroy=y.destroy,A.prototype._undestroy=y.undestroy,A.prototype._destroy=function(O,z){z(O)}}).call(this)}).call(this,i("_process"),typeof commonjsGlobal<"u"?commonjsGlobal: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 n;function c(C,I,_){return I in C?Object.defineProperty(C,I,{value:_,enumerable:!0,configurable:!0,writable:!0}):C[I]=_,C}var l=i("./end-of-stream"),u=Symbol("lastResolve"),h=Symbol("lastReject"),v=Symbol("error"),f=Symbol("ended"),g=Symbol("lastPromise"),y=Symbol("handlePromise"),p=Symbol("stream");function m(C,I){return{value:C,done:I}}function x(C){var I=C[u];if(I!==null){var _=C[p].read();_!==null&&(C[g]=null,C[u]=null,C[h]=null,I(m(_,!1)))}}var k=Object.getPrototypeOf(function(){}),w=Object.setPrototypeOf((c(n={get stream(){return this[p]},next:function(){var C=this,I=this[v];if(I!==null)return Promise.reject(I);if(this[f])return Promise.resolve(m(void 0,!0));if(this[p].destroyed)return new Promise(function(F,q){a.nextTick(function(){C[v]?q(C[v]):F(m(void 0,!0))})});var _,L=this[g];if(L)_=new Promise(function(F,q){return function(R,A){F.then(function(){q[f]?R(m(void 0,!0)):q[y](R,A)},A)}}(L,this));else{var E=this[p].read();if(E!==null)return Promise.resolve(m(E,!1));_=new Promise(this[y])}return this[g]=_,_}},Symbol.asyncIterator,function(){return this}),c(n,"return",function(){var C=this;return new Promise(function(I,_){C[p].destroy(null,function(L){L?_(L):I(m(void 0,!0))})})}),n),k);s.exports=function(C){var I,_=Object.create(w,(c(I={},p,{value:C,writable:!0}),c(I,u,{value:null,writable:!0}),c(I,h,{value:null,writable:!0}),c(I,v,{value:null,writable:!0}),c(I,f,{value:C._readableState.endEmitted,writable:!0}),c(I,y,{value:function(L,E){var F=_[p].read();F?(_[g]=null,_[u]=null,_[h]=null,L(m(F,!1))):(_[u]=L,_[h]=E)},writable:!0}),I));return _[g]=null,l(C,function(L){if(L&&L.code!=="ERR_STREAM_PREMATURE_CLOSE"){var E=_[h];return E!==null&&(_[g]=null,_[u]=null,_[h]=null,E(L)),void(_[v]=L)}var F=_[u];F!==null&&(_[g]=null,_[u]=null,_[h]=null,F(m(void 0,!0))),_[f]=!0}),C.on("readable",(function(L){a.nextTick(x,L)}).bind(null,_)),_}}).call(this)}).call(this,i("_process"))},{"./end-of-stream":64,_process:50}],62:[function(i,s,r){function a(v,f){var g=Object.keys(v);if(Object.getOwnPropertySymbols){var y=Object.getOwnPropertySymbols(v);f&&(y=y.filter(function(p){return Object.getOwnPropertyDescriptor(v,p).enumerable})),g.push.apply(g,y)}return g}function n(v,f,g){return f in v?Object.defineProperty(v,f,{value:g,enumerable:!0,configurable:!0,writable:!0}):v[f]=g,v}function c(v,f){for(var g=0;g<f.length;g++){var y=f[g];y.enumerable=y.enumerable||!1,y.configurable=!0,"value"in y&&(y.writable=!0),Object.defineProperty(v,y.key,y)}}var l=i("buffer").Buffer,u=i("util").inspect,h=u&&u.custom||"inspect";s.exports=function(){function v(){(function(y,p){if(!(y instanceof p))throw new TypeError("Cannot call a class as a function")})(this,v),this.head=null,this.tail=null,this.length=0}var f,g;return f=v,(g=[{key:"push",value:function(y){var p={data:y,next:null};this.length>0?this.tail.next=p:this.head=p,this.tail=p,++this.length}},{key:"unshift",value:function(y){var p={data:y,next:this.head};this.length===0&&(this.tail=p),this.head=p,++this.length}},{key:"shift",value:function(){if(this.length!==0){var y=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,y}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(y){if(this.length===0)return"";for(var p=this.head,m=""+p.data;p=p.next;)m+=y+p.data;return m}},{key:"concat",value:function(y){if(this.length===0)return l.alloc(0);for(var p,m,x,k=l.allocUnsafe(y>>>0),w=this.head,C=0;w;)p=w.data,m=k,x=C,l.prototype.copy.call(p,m,x),C+=w.data.length,w=w.next;return k}},{key:"consume",value:function(y,p){var m;return y<this.head.data.length?(m=this.head.data.slice(0,y),this.head.data=this.head.data.slice(y)):m=y===this.head.data.length?this.shift():p?this._getString(y):this._getBuffer(y),m}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(y){var p=this.head,m=1,x=p.data;for(y-=x.length;p=p.next;){var k=p.data,w=y>k.length?k.length:y;if(w===k.length?x+=k:x+=k.slice(0,y),(y-=w)===0){w===k.length?(++m,p.next?this.head=p.next:this.head=this.tail=null):(this.head=p,p.data=k.slice(w));break}++m}return this.length-=m,x}},{key:"_getBuffer",value:function(y){var p=l.allocUnsafe(y),m=this.head,x=1;for(m.data.copy(p),y-=m.data.length;m=m.next;){var k=m.data,w=y>k.length?k.length:y;if(k.copy(p,p.length-y,0,w),(y-=w)===0){w===k.length?(++x,m.next?this.head=m.next:this.head=this.tail=null):(this.head=m,m.data=k.slice(w));break}++x}return this.length-=x,p}},{key:h,value:function(y,p){return u(this,function(m){for(var x=1;x<arguments.length;x++){var k=arguments[x]!=null?arguments[x]:{};x%2?a(Object(k),!0).forEach(function(w){n(m,w,k[w])}):Object.getOwnPropertyDescriptors?Object.defineProperties(m,Object.getOwnPropertyDescriptors(k)):a(Object(k)).forEach(function(w){Object.defineProperty(m,w,Object.getOwnPropertyDescriptor(k,w))})}return m}({},p,{depth:0,customInspect:!1}))}}])&&c(f.prototype,g),v}()},{buffer:17,util:16}],63:[function(i,s,r){(function(a){(function(){function n(u,h){l(u,h),c(u)}function c(u){u._writableState&&!u._writableState.emitClose||u._readableState&&!u._readableState.emitClose||u.emit("close")}function l(u,h){u.emit("error",h)}s.exports={destroy:function(u,h){var v=this,f=this._readableState&&this._readableState.destroyed,g=this._writableState&&this._writableState.destroyed;return f||g?(h?h(u):u&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,a.nextTick(l,this,u)):a.nextTick(l,this,u)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(u||null,function(y){!h&&y?v._writableState?v._writableState.errorEmitted?a.nextTick(c,v):(v._writableState.errorEmitted=!0,a.nextTick(n,v,y)):a.nextTick(n,v,y):h?(a.nextTick(c,v),h(y)):a.nextTick(c,v)}),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(u,h){var v=u._readableState,f=u._writableState;v&&v.autoDestroy||f&&f.autoDestroy?u.destroy(h):u.emit("error",h)}}}).call(this)}).call(this,i("_process"))},{_process:50}],64:[function(i,s,r){var a=i("../../../errors").codes.ERR_STREAM_PREMATURE_CLOSE;function n(){}s.exports=function c(l,u,h){if(typeof u=="function")return c(l,null,u);u||(u={}),h=function(I){var _=!1;return function(){if(!_){_=!0;for(var L=arguments.length,E=new Array(L),F=0;F<L;F++)E[F]=arguments[F];I.apply(this,E)}}}(h||n);var v=u.readable||u.readable!==!1&&l.readable,f=u.writable||u.writable!==!1&&l.writable,g=function(){l.writable||p()},y=l._writableState&&l._writableState.finished,p=function(){f=!1,y=!0,v||h.call(l)},m=l._readableState&&l._readableState.endEmitted,x=function(){v=!1,m=!0,f||h.call(l)},k=function(I){h.call(l,I)},w=function(){var I;return v&&!m?(l._readableState&&l._readableState.ended||(I=new a),h.call(l,I)):f&&!y?(l._writableState&&l._writableState.ended||(I=new a),h.call(l,I)):void 0},C=function(){l.req.on("finish",p)};return function(I){return I.setHeader&&typeof I.abort=="function"}(l)?(l.on("complete",p),l.on("abort",w),l.req?C():l.on("request",C)):f&&!l._writableState&&(l.on("end",g),l.on("close",g)),l.on("end",x),l.on("finish",p),u.error!==!1&&l.on("error",k),l.on("close",w),function(){l.removeListener("complete",p),l.removeListener("abort",w),l.removeListener("request",C),l.req&&l.req.removeListener("finish",p),l.removeListener("end",g),l.removeListener("close",g),l.removeListener("finish",p),l.removeListener("end",x),l.removeListener("error",k),l.removeListener("close",w)}}},{"../../../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,n=i("../../../errors").codes,c=n.ERR_MISSING_ARGS,l=n.ERR_STREAM_DESTROYED;function u(f){if(f)throw f}function h(f){f()}function v(f,g){return f.pipe(g)}s.exports=function(){for(var f=arguments.length,g=new Array(f),y=0;y<f;y++)g[y]=arguments[y];var p,m=function(k){return k.length?typeof k[k.length-1]!="function"?u:k.pop():u}(g);if(Array.isArray(g[0])&&(g=g[0]),g.length<2)throw new c("streams");var x=g.map(function(k,w){var C=w<g.length-1;return function(I,_,L,E){E=function(R){var A=!1;return function(){A||(A=!0,R.apply(void 0,arguments))}}(E);var F=!1;I.on("close",function(){F=!0}),a===void 0&&(a=i("./end-of-stream")),a(I,{readable:_,writable:L},function(R){if(R)return E(R);F=!0,E()});var q=!1;return function(R){if(!F&&!q)return q=!0,function(A){return A.setHeader&&typeof A.abort=="function"}(I)?I.abort():typeof I.destroy=="function"?I.destroy():void E(R||new l("pipe"))}}(k,C,w>0,function(I){p||(p=I),I&&x.forEach(h),C||(x.forEach(h),m(p))})});return g.reduce(v)}},{"../../../errors":55,"./end-of-stream":64}],67:[function(i,s,r){var a=i("../../../errors").codes.ERR_INVALID_OPT_VALUE;s.exports={getHighWaterMark:function(n,c,l,u){var h=function(v,f,g){return v.highWaterMark!=null?v.highWaterMark:f?v[g]:null}(c,u,l);if(h!=null){if(!isFinite(h)||Math.floor(h)!==h||h<0)throw new a(u?l:"highWaterMark",h);return Math.floor(h)}return n.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 n=0;n<a.length;n++)a[n]=arguments[n+2]}return new function(c,l,u){var h=this;this._callback=c,this._args=u,this._interval=setInterval(c,l,this._args),this.reschedule=function(v){v||(v=h._interval),h._interval&&clearInterval(h._interval),h._interval=setInterval(h._callback,v,h._args)},this.clear=function(){h._interval&&(clearInterval(h._interval),h._interval=void 0)},this.destroy=function(){h._interval&&clearInterval(h._interval),h._callback=void 0,h._interval=void 0,h._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 n(c){return c instanceof a?a.from(c):new c.constructor(c.buffer.slice(),c.byteOffset,c.length)}s.exports=function(c){return(c=c||{}).circles?function(u){var h=[],v=[];return u.proto?function g(y){if(typeof y!="object"||y===null)return y;if(y instanceof Date)return new Date(y);if(Array.isArray(y))return f(y,g);if(y instanceof Map)return new Map(f(Array.from(y),g));if(y instanceof Set)return new Set(f(Array.from(y),g));var p={};for(var m in h.push(y),v.push(p),y){var x=y[m];if(typeof x!="object"||x===null)p[m]=x;else if(x instanceof Date)p[m]=new Date(x);else if(x instanceof Map)p[m]=new Map(f(Array.from(x),g));else if(x instanceof Set)p[m]=new Set(f(Array.from(x),g));else if(ArrayBuffer.isView(x))p[m]=n(x);else{var k=h.indexOf(x);p[m]=k!==-1?v[k]:g(x)}}return h.pop(),v.pop(),p}:function g(y){if(typeof y!="object"||y===null)return y;if(y instanceof Date)return new Date(y);if(Array.isArray(y))return f(y,g);if(y instanceof Map)return new Map(f(Array.from(y),g));if(y instanceof Set)return new Set(f(Array.from(y),g));var p={};for(var m in h.push(y),v.push(p),y)if(Object.hasOwnProperty.call(y,m)!==!1){var x=y[m];if(typeof x!="object"||x===null)p[m]=x;else if(x instanceof Date)p[m]=new Date(x);else if(x instanceof Map)p[m]=new Map(f(Array.from(x),g));else if(x instanceof Set)p[m]=new Set(f(Array.from(x),g));else if(ArrayBuffer.isView(x))p[m]=n(x);else{var k=h.indexOf(x);p[m]=k!==-1?v[k]:g(x)}}return h.pop(),v.pop(),p};function f(g,y){for(var p=Object.keys(g),m=new Array(p.length),x=0;x<p.length;x++){var k=p[x],w=g[k];if(typeof w!="object"||w===null)m[k]=w;else if(w instanceof Date)m[k]=new Date(w);else if(ArrayBuffer.isView(w))m[k]=n(w);else{var C=h.indexOf(w);m[k]=C!==-1?v[C]:y(w)}}return m}}(c):c.proto?function u(h){if(typeof h!="object"||h===null)return h;if(h instanceof Date)return new Date(h);if(Array.isArray(h))return l(h,u);if(h instanceof Map)return new Map(l(Array.from(h),u));if(h instanceof Set)return new Set(l(Array.from(h),u));var v={};for(var f in h){var g=h[f];typeof g!="object"||g===null?v[f]=g:g instanceof Date?v[f]=new Date(g):g instanceof Map?v[f]=new Map(l(Array.from(g),u)):g instanceof Set?v[f]=new Set(l(Array.from(g),u)):ArrayBuffer.isView(g)?v[f]=n(g):v[f]=u(g)}return v}:function u(h){if(typeof h!="object"||h===null)return h;if(h instanceof Date)return new Date(h);if(Array.isArray(h))return l(h,u);if(h instanceof Map)return new Map(l(Array.from(h),u));if(h instanceof Set)return new Set(l(Array.from(h),u));var v={};for(var f in h)if(Object.hasOwnProperty.call(h,f)!==!1){var g=h[f];typeof g!="object"||g===null?v[f]=g:g instanceof Date?v[f]=new Date(g):g instanceof Map?v[f]=new Map(l(Array.from(g),u)):g instanceof Set?v[f]=new Set(l(Array.from(g),u)):ArrayBuffer.isView(g)?v[f]=n(g):v[f]=u(g)}return v};function l(u,h){for(var v=Object.keys(u),f=new Array(v.length),g=0;g<v.length;g++){var y=v[g],p=u[y];typeof p!="object"||p===null?f[y]=p:p instanceof Date?f[y]=new Date(p):ArrayBuffer.isView(p)?f[y]=n(p):f[y]=h(p)}return f}}}).call(this)}).call(this,i("buffer").Buffer)},{buffer:17}],73:[function(i,s,r){var a=i("buffer"),n=a.Buffer;function c(u,h){for(var v in u)h[v]=u[v]}function l(u,h,v){return n(u,h,v)}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?s.exports=a:(c(a,r),r.Buffer=l),l.prototype=Object.create(n.prototype),c(n,l),l.from=function(u,h,v){if(typeof u=="number")throw new TypeError("Argument must not be a number");return n(u,h,v)},l.alloc=function(u,h,v){if(typeof u!="number")throw new TypeError("Argument must be a number");var f=n(u);return h!==void 0?typeof v=="string"?f.fill(h,v):f.fill(h):f.fill(0),f},l.allocUnsafe=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return n(u)},l.allocUnsafeSlow=function(u){if(typeof u!="number")throw new TypeError("Argument must be a number");return a.SlowBuffer(u)}},{buffer:17}],74:[function(i,s,r){s.exports=function(a){var n=a._readableState;return n?n.objectMode||typeof a._duplexState=="number"?a.read():a.read((c=n,c.buffer.length?c.buffer.head?c.buffer.head.data.length:c.buffer[0].length:c.length)):null;var c}},{}],75:[function(i,s,r){var a=i("safe-buffer").Buffer,n=a.isEncoding||function(m){switch((m=""+m)&&m.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 c(m){var x;switch(this.encoding=function(k){var w=function(C){if(!C)return"utf8";for(var I;;)switch(C){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 C;default:if(I)return;C=(""+C).toLowerCase(),I=!0}}(k);if(typeof w!="string"&&(a.isEncoding===n||!n(k)))throw new Error("Unknown encoding: "+k);return w||k}(m),this.encoding){case"utf16le":this.text=h,this.end=v,x=4;break;case"utf8":this.fillLast=u,x=4;break;case"base64":this.text=f,this.end=g,x=3;break;default:return this.write=y,void(this.end=p)}this.lastNeed=0,this.lastTotal=0,this.lastChar=a.allocUnsafe(x)}function l(m){return m<=127?0:m>>5==6?2:m>>4==14?3:m>>3==30?4:m>>6==2?-1:-2}function u(m){var x=this.lastTotal-this.lastNeed,k=function(w,C,I){if((192&C[0])!=128)return w.lastNeed=0,"�";if(w.lastNeed>1&&C.length>1){if((192&C[1])!=128)return w.lastNeed=1,"�";if(w.lastNeed>2&&C.length>2&&(192&C[2])!=128)return w.lastNeed=2,"�"}}(this,m);return k!==void 0?k:this.lastNeed<=m.length?(m.copy(this.lastChar,x,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(m.copy(this.lastChar,x,0,m.length),void(this.lastNeed-=m.length))}function h(m,x){if((m.length-x)%2==0){var k=m.toString("utf16le",x);if(k){var w=k.charCodeAt(k.length-1);if(w>=55296&&w<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=m[m.length-2],this.lastChar[1]=m[m.length-1],k.slice(0,-1)}return k}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=m[m.length-1],m.toString("utf16le",x,m.length-1)}function v(m){var x=m&&m.length?this.write(m):"";if(this.lastNeed){var k=this.lastTotal-this.lastNeed;return x+this.lastChar.toString("utf16le",0,k)}return x}function f(m,x){var k=(m.length-x)%3;return k===0?m.toString("base64",x):(this.lastNeed=3-k,this.lastTotal=3,k===1?this.lastChar[0]=m[m.length-1]:(this.lastChar[0]=m[m.length-2],this.lastChar[1]=m[m.length-1]),m.toString("base64",x,m.length-k))}function g(m){var x=m&&m.length?this.write(m):"";return this.lastNeed?x+this.lastChar.toString("base64",0,3-this.lastNeed):x}function y(m){return m.toString(this.encoding)}function p(m){return m&&m.length?this.write(m):""}r.StringDecoder=c,c.prototype.write=function(m){if(m.length===0)return"";var x,k;if(this.lastNeed){if((x=this.fillLast(m))===void 0)return"";k=this.lastNeed,this.lastNeed=0}else k=0;return k<m.length?x?x+this.text(m,k):this.text(m,k):x||""},c.prototype.end=function(m){var x=m&&m.length?this.write(m):"";return this.lastNeed?x+"�":x},c.prototype.text=function(m,x){var k=function(C,I,_){var L=I.length-1;if(L<_)return 0;var E=l(I[L]);return E>=0?(E>0&&(C.lastNeed=E-1),E):--L<_||E===-2?0:(E=l(I[L]))>=0?(E>0&&(C.lastNeed=E-2),E):--L<_||E===-2?0:(E=l(I[L]))>=0?(E>0&&(E===2?E=0:C.lastNeed=E-3),E):0}(this,m,x);if(!this.lastNeed)return m.toString("utf8",x);this.lastTotal=k;var w=m.length-(k-this.lastNeed);return m.copy(this.lastChar,0,w),m.toString("utf8",x,w)},c.prototype.fillLast=function(m){if(this.lastNeed<=m.length)return m.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);m.copy(this.lastChar,this.lastTotal-this.lastNeed,0,m.length),this.lastNeed-=m.length}},{"safe-buffer":73}],76:[function(i,s,r){var a=i("punycode"),n=i("./util");function c(){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=I,r.resolve=function(_,L){return I(_,!1,!0).resolve(L)},r.resolveObject=function(_,L){return _?I(_,!1,!0).resolveObject(L):L},r.format=function(_){return n.isString(_)&&(_=I(_)),_ instanceof c?_.format():c.prototype.format.call(_)},r.Url=c;var l=/^([a-z0-9.+-]+:)/i,u=/:[0-9]*$/,h=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,v=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r",`
|
|
67
|
-
`," "]),f=["'"].concat(v),g=["%","/","?",";","#"].concat(f),y=["/","?","#"],p=/^[+a-z0-9A-Z_-]{0,63}$/,m=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,x={javascript:!0,"javascript:":!0},k={javascript:!0,"javascript:":!0},w={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},C=i("querystring");function I(_,L,E){if(_&&n.isObject(_)&&_ instanceof c)return _;var F=new c;return F.parse(_,L,E),F}c.prototype.parse=function(_,L,E){if(!n.isString(_))throw new TypeError("Parameter 'url' must be a string, not "+typeof _);var F=_.indexOf("?"),q=F!==-1&&F<_.indexOf("#")?"?":"#",R=_.split(q);R[0]=R[0].replace(/\\/g,"/");var A=_=R.join(q);if(A=A.trim(),!E&&_.split("#").length===1){var P=h.exec(A);if(P)return this.path=A,this.href=A,this.pathname=P[1],P[2]?(this.search=P[2],this.query=L?C.parse(this.search.substr(1)):this.search.substr(1)):L&&(this.search="",this.query={}),this}var M=l.exec(A);if(M){var H=(M=M[0]).toLowerCase();this.protocol=H,A=A.substr(M.length)}if(E||M||A.match(/^\/\/[^@\/]+@[^@\/]+/)){var $=A.substr(0,2)==="//";!$||M&&k[M]||(A=A.substr(2),this.slashes=!0)}if(!k[M]&&($||M&&!w[M])){for(var X,j,O=-1,z=0;z<y.length;z++)(V=A.indexOf(y[z]))!==-1&&(O===-1||V<O)&&(O=V);for((j=O===-1?A.lastIndexOf("@"):A.lastIndexOf("@",O))!==-1&&(X=A.slice(0,j),A=A.slice(j+1),this.auth=decodeURIComponent(X)),O=-1,z=0;z<g.length;z++){var V;(V=A.indexOf(g[z]))!==-1&&(O===-1||V<O)&&(O=V)}O===-1&&(O=A.length),this.host=A.slice(0,O),A=A.slice(O),this.parseHost(),this.hostname=this.hostname||"";var N=this.hostname[0]==="["&&this.hostname[this.hostname.length-1]==="]";if(!N)for(var Y=this.hostname.split(/\./),K=(z=0,Y.length);z<K;z++){var G=Y[z];if(G&&!G.match(p)){for(var tt="",Q=0,Z=G.length;Q<Z;Q++)G.charCodeAt(Q)>127?tt+="x":tt+=G[Q];if(!tt.match(p)){var b=Y.slice(0,z),T=Y.slice(z+1),S=G.match(m);S&&(b.push(S[1]),T.unshift(S[2])),T.length&&(A="/"+T.join(".")+A),this.hostname=b.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),N||(this.hostname=a.toASCII(this.hostname));var D=this.port?":"+this.port:"",W=this.hostname||"";this.host=W+D,this.href+=this.host,N&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),A[0]!=="/"&&(A="/"+A))}if(!x[H])for(z=0,K=f.length;z<K;z++){var U=f[z];if(A.indexOf(U)!==-1){var J=encodeURIComponent(U);J===U&&(J=escape(U)),A=A.split(U).join(J)}}var it=A.indexOf("#");it!==-1&&(this.hash=A.substr(it),A=A.slice(0,it));var et=A.indexOf("?");if(et!==-1?(this.search=A.substr(et),this.query=A.substr(et+1),L&&(this.query=C.parse(this.query)),A=A.slice(0,et)):L&&(this.search="",this.query={}),A&&(this.pathname=A),w[H]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){D=this.pathname||"";var st=this.search||"";this.path=D+st}return this.href=this.format(),this},c.prototype.format=function(){var _=this.auth||"";_&&(_=(_=encodeURIComponent(_)).replace(/%3A/i,":"),_+="@");var L=this.protocol||"",E=this.pathname||"",F=this.hash||"",q=!1,R="";this.host?q=_+this.host:this.hostname&&(q=_+(this.hostname.indexOf(":")===-1?this.hostname:"["+this.hostname+"]"),this.port&&(q+=":"+this.port)),this.query&&n.isObject(this.query)&&Object.keys(this.query).length&&(R=C.stringify(this.query));var A=this.search||R&&"?"+R||"";return L&&L.substr(-1)!==":"&&(L+=":"),this.slashes||(!L||w[L])&&q!==!1?(q="//"+(q||""),E&&E.charAt(0)!=="/"&&(E="/"+E)):q||(q=""),F&&F.charAt(0)!=="#"&&(F="#"+F),A&&A.charAt(0)!=="?"&&(A="?"+A),L+q+(E=E.replace(/[?#]/g,function(P){return encodeURIComponent(P)}))+(A=A.replace("#","%23"))+F},c.prototype.resolve=function(_){return this.resolveObject(I(_,!1,!0)).format()},c.prototype.resolveObject=function(_){if(n.isString(_)){var L=new c;L.parse(_,!1,!0),_=L}for(var E=new c,F=Object.keys(this),q=0;q<F.length;q++){var R=F[q];E[R]=this[R]}if(E.hash=_.hash,_.href==="")return E.href=E.format(),E;if(_.slashes&&!_.protocol){for(var A=Object.keys(_),P=0;P<A.length;P++){var M=A[P];M!=="protocol"&&(E[M]=_[M])}return w[E.protocol]&&E.hostname&&!E.pathname&&(E.path=E.pathname="/"),E.href=E.format(),E}if(_.protocol&&_.protocol!==E.protocol){if(!w[_.protocol]){for(var H=Object.keys(_),$=0;$<H.length;$++){var X=H[$];E[X]=_[X]}return E.href=E.format(),E}if(E.protocol=_.protocol,_.host||k[_.protocol])E.pathname=_.pathname;else{for(var j=(_.pathname||"").split("/");j.length&&!(_.host=j.shift()););_.host||(_.host=""),_.hostname||(_.hostname=""),j[0]!==""&&j.unshift(""),j.length<2&&j.unshift(""),E.pathname=j.join("/")}if(E.search=_.search,E.query=_.query,E.host=_.host||"",E.auth=_.auth,E.hostname=_.hostname||_.host,E.port=_.port,E.pathname||E.search){var O=E.pathname||"",z=E.search||"";E.path=O+z}return E.slashes=E.slashes||_.slashes,E.href=E.format(),E}var V=E.pathname&&E.pathname.charAt(0)==="/",N=_.host||_.pathname&&_.pathname.charAt(0)==="/",Y=N||V||E.host&&_.pathname,K=Y,G=E.pathname&&E.pathname.split("/")||[],tt=(j=_.pathname&&_.pathname.split("/")||[],E.protocol&&!w[E.protocol]);if(tt&&(E.hostname="",E.port=null,E.host&&(G[0]===""?G[0]=E.host:G.unshift(E.host)),E.host="",_.protocol&&(_.hostname=null,_.port=null,_.host&&(j[0]===""?j[0]=_.host:j.unshift(_.host)),_.host=null),Y=Y&&(j[0]===""||G[0]==="")),N)E.host=_.host||_.host===""?_.host:E.host,E.hostname=_.hostname||_.hostname===""?_.hostname:E.hostname,E.search=_.search,E.query=_.query,G=j;else if(j.length)G||(G=[]),G.pop(),G=G.concat(j),E.search=_.search,E.query=_.query;else if(!n.isNullOrUndefined(_.search))return tt&&(E.hostname=E.host=G.shift(),(S=!!(E.host&&E.host.indexOf("@")>0)&&E.host.split("@"))&&(E.auth=S.shift(),E.host=E.hostname=S.shift())),E.search=_.search,E.query=_.query,n.isNull(E.pathname)&&n.isNull(E.search)||(E.path=(E.pathname?E.pathname:"")+(E.search?E.search:"")),E.href=E.format(),E;if(!G.length)return E.pathname=null,E.search?E.path="/"+E.search:E.path=null,E.href=E.format(),E;for(var Q=G.slice(-1)[0],Z=(E.host||_.host||G.length>1)&&(Q==="."||Q==="..")||Q==="",b=0,T=G.length;T>=0;T--)(Q=G[T])==="."?G.splice(T,1):Q===".."?(G.splice(T,1),b++):b&&(G.splice(T,1),b--);if(!Y&&!K)for(;b--;b)G.unshift("..");!Y||G[0]===""||G[0]&&G[0].charAt(0)==="/"||G.unshift(""),Z&&G.join("/").substr(-1)!=="/"&&G.push("");var S,D=G[0]===""||G[0]&&G[0].charAt(0)==="/";return tt&&(E.hostname=E.host=D?"":G.length?G.shift():"",(S=!!(E.host&&E.host.indexOf("@")>0)&&E.host.split("@"))&&(E.auth=S.shift(),E.host=E.hostname=S.shift())),(Y=Y||E.host&&G.length)&&!D&&G.unshift(""),G.length?E.pathname=G.join("/"):(E.pathname=null,E.path=null),n.isNull(E.pathname)&&n.isNull(E.search)||(E.path=(E.pathname?E.pathname:"")+(E.search?E.search:"")),E.auth=_.auth||E.auth,E.slashes=E.slashes||_.slashes,E.href=E.format(),E},c.prototype.parseHost=function(){var _=this.host,L=u.exec(_);L&&((L=L[0])!==":"&&(this.port=L.substr(1)),_=_.substr(0,_.length-L.length)),_&&(this.hostname=_)}},{"./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 n(c){try{if(!a.localStorage)return!1}catch{return!1}var l=a.localStorage[c];return l!=null&&String(l).toLowerCase()==="true"}s.exports=function(c,l){if(n("noDeprecation"))return c;var u=!1;return function(){if(!u){if(n("throwDeprecation"))throw new Error(l);n("traceDeprecation")?console.trace(l):console.warn(l),u=!0}return c.apply(this,arguments)}}}).call(this)}).call(this,typeof commonjsGlobal<"u"?commonjsGlobal:typeof self<"u"?self:typeof window<"u"?window:{})},{}],79:[function(i,s,r){s.exports=function a(n,c){if(n&&c)return a(n)(c);if(typeof n!="function")throw new TypeError("need wrapper function");return Object.keys(n).forEach(function(u){l[u]=n[u]}),l;function l(){for(var u=new Array(arguments.length),h=0;h<u.length;h++)u[h]=arguments[h];var v=n.apply(this,u),f=u[u.length-1];return typeof v=="function"&&v!==f&&Object.keys(f).forEach(function(g){v[g]=f[g]}),v}}},{}],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 n={},c=0;c<arguments.length;c++){var l=arguments[c];for(var u in l)a.call(l,u)&&(n[u]=l[u])}return n};var a=Object.prototype.hasOwnProperty},{}],82:[function(i,s,r){s.exports=function(a){a.prototype[Symbol.iterator]=function*(){for(let n=this.head;n;n=n.next)yield n.value}}},{}],83:[function(i,s,r){function a(h){var v=this;if(v instanceof a||(v=new a),v.tail=null,v.head=null,v.length=0,h&&typeof h.forEach=="function")h.forEach(function(y){v.push(y)});else if(arguments.length>0)for(var f=0,g=arguments.length;f<g;f++)v.push(arguments[f]);return v}function n(h,v,f){var g=v===h.head?new u(f,null,v,h):new u(f,v,v.next,h);return g.next===null&&(h.tail=g),g.prev===null&&(h.head=g),h.length++,g}function c(h,v){h.tail=new u(v,h.tail,null,h),h.head||(h.head=h.tail),h.length++}function l(h,v){h.head=new u(v,null,h.head,h),h.tail||(h.tail=h.head),h.length++}function u(h,v,f,g){if(!(this instanceof u))return new u(h,v,f,g);this.list=g,this.value=h,v?(v.next=this,this.prev=v):this.prev=null,f?(f.prev=this,this.next=f):this.next=null}s.exports=a,a.Node=u,a.create=a,a.prototype.removeNode=function(h){if(h.list!==this)throw new Error("removing node which does not belong to this list");var v=h.next,f=h.prev;return v&&(v.prev=f),f&&(f.next=v),h===this.head&&(this.head=v),h===this.tail&&(this.tail=f),h.list.length--,h.next=null,h.prev=null,h.list=null,v},a.prototype.unshiftNode=function(h){if(h!==this.head){h.list&&h.list.removeNode(h);var v=this.head;h.list=this,h.next=v,v&&(v.prev=h),this.head=h,this.tail||(this.tail=h),this.length++}},a.prototype.pushNode=function(h){if(h!==this.tail){h.list&&h.list.removeNode(h);var v=this.tail;h.list=this,h.prev=v,v&&(v.next=h),this.tail=h,this.head||(this.head=h),this.length++}},a.prototype.push=function(){for(var h=0,v=arguments.length;h<v;h++)c(this,arguments[h]);return this.length},a.prototype.unshift=function(){for(var h=0,v=arguments.length;h<v;h++)l(this,arguments[h]);return this.length},a.prototype.pop=function(){if(this.tail){var h=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,h}},a.prototype.shift=function(){if(this.head){var h=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,h}},a.prototype.forEach=function(h,v){v=v||this;for(var f=this.head,g=0;f!==null;g++)h.call(v,f.value,g,this),f=f.next},a.prototype.forEachReverse=function(h,v){v=v||this;for(var f=this.tail,g=this.length-1;f!==null;g--)h.call(v,f.value,g,this),f=f.prev},a.prototype.get=function(h){for(var v=0,f=this.head;f!==null&&v<h;v++)f=f.next;if(v===h&&f!==null)return f.value},a.prototype.getReverse=function(h){for(var v=0,f=this.tail;f!==null&&v<h;v++)f=f.prev;if(v===h&&f!==null)return f.value},a.prototype.map=function(h,v){v=v||this;for(var f=new a,g=this.head;g!==null;)f.push(h.call(v,g.value,this)),g=g.next;return f},a.prototype.mapReverse=function(h,v){v=v||this;for(var f=new a,g=this.tail;g!==null;)f.push(h.call(v,g.value,this)),g=g.prev;return f},a.prototype.reduce=function(h,v){var f,g=this.head;if(arguments.length>1)f=v;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");g=this.head.next,f=this.head.value}for(var y=0;g!==null;y++)f=h(f,g.value,y),g=g.next;return f},a.prototype.reduceReverse=function(h,v){var f,g=this.tail;if(arguments.length>1)f=v;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");g=this.tail.prev,f=this.tail.value}for(var y=this.length-1;g!==null;y--)f=h(f,g.value,y),g=g.prev;return f},a.prototype.toArray=function(){for(var h=new Array(this.length),v=0,f=this.head;f!==null;v++)h[v]=f.value,f=f.next;return h},a.prototype.toArrayReverse=function(){for(var h=new Array(this.length),v=0,f=this.tail;f!==null;v++)h[v]=f.value,f=f.prev;return h},a.prototype.slice=function(h,v){(v=v||this.length)<0&&(v+=this.length),(h=h||0)<0&&(h+=this.length);var f=new a;if(v<h||v<0)return f;h<0&&(h=0),v>this.length&&(v=this.length);for(var g=0,y=this.head;y!==null&&g<h;g++)y=y.next;for(;y!==null&&g<v;g++,y=y.next)f.push(y.value);return f},a.prototype.sliceReverse=function(h,v){(v=v||this.length)<0&&(v+=this.length),(h=h||0)<0&&(h+=this.length);var f=new a;if(v<h||v<0)return f;h<0&&(h=0),v>this.length&&(v=this.length);for(var g=this.length,y=this.tail;y!==null&&g>v;g--)y=y.prev;for(;y!==null&&g>h;g--,y=y.prev)f.push(y.value);return f},a.prototype.splice=function(h,v,...f){h>this.length&&(h=this.length-1),h<0&&(h=this.length+h);for(var g=0,y=this.head;y!==null&&g<h;g++)y=y.next;var p=[];for(g=0;y&&g<v;g++)p.push(y.value),y=this.removeNode(y);for(y===null&&(y=this.tail),y!==this.head&&y!==this.tail&&(y=y.prev),g=0;g<f.length;g++)y=n(this,y,f[g]);return p},a.prototype.reverse=function(){for(var h=this.head,v=this.tail,f=h;f!==null;f=f.prev){var g=f.prev;f.prev=f.next,f.next=g}return this.head=v,this.tail=h,this};try{i("./iterator.js")(a)}catch{}},{"./iterator.js":82}]},{},[12])(12)})})(mqtt_min);var mqtt_minExports=mqtt_min.exports;const status={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>'}},messageList={};class Message{constructor(t,i){B(this,"parentElement");B(this,"box");B(this,"icon");B(this,"text");B(this,"closeBtn");B(this,"duration");B(this,"content");B(this,"theme");B(this,"placement");B(this,"height");B(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=status[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||s8(),this.duration=i.duration??3e3,this.placement=i.placement||"top",this.theme=i.theme||"info",this.height=i.height}init(){messageList[this.id]=this,this.duration&&setTimeout(()=>{this.close()},this.duration);let t=-1;Object.keys(messageList).forEach(i=>{var s;((s=messageList[i])==null?void 0:s.placement)===this.placement&&t++}),this.setPosition(this.placement,t),this.icon.children[0].style.fill=status[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(messageList).forEach(t=>{var i;if(((i=messageList[t])==null?void 0:i.placement)===this.placement)switch(this.placement){case"top":case"left":case"right":messageList[t].box.style.top=parseInt(messageList[t].box.style.top)-60+"px";break;case"bottom":messageList[t].box.style.bottom=parseInt(messageList[t].box.style.bottom)-60+"px";break}}),messageList[this.id]=null,delete messageList[this.id],this.box.remove()}}function connectJetLinks(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")||getCookie("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 n=[];for(let c in r.payload.properties)n.push({id:`${r.payload.headers.productId}#${r.payload.deviceId}#${c}`,value:r.payload.properties[c]});e.setDatas(n,{history:!1})}else r.topic.startsWith("/notifications")&&doWarning(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+"-"+s8()}))}),t.notification&&e.jetLinksClient.send(JSON.stringify({type:"sub",topic:"/notifications",id:"notification",parameter:{}}))}}}function doWarning(e,t){var n,c;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;">${getTime(r)}</div>
|
|
90
|
-
</div>
|
|
91
|
-
<span>${s}</span>
|
|
92
|
-
</div>`;e.message({content:a,duration:0,closeBtn:!0,placement:"right",height:75}),(n=t.payload.detail)!=null&&n.alarmConfigId&&playMp3(e,(c=t.payload.detail)==null?void 0:c.alarmConfigId)}globalThis.doWarning=doWarning;function getTime(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"),n=(t.getMinutes()+"").padStart(2,"0"),c=(t.getSeconds()+"").padStart(2,"0");return i+"-"+s+"-"+r+" "+a+":"+n+":"+c}function closeJetLinks(e){e.jetLinksClient&&(e.jetLinksClient.close(),e.jetLinksClient=void 0)}function getSendData(e,t,i){const s=[];return i.list.forEach((r,a)=>{var c,l;const n=r.params?e.findOne(r.params):t;s[a]={deviceId:n.deviceId,productId:n.productId,properties:{}};for(let u in r.value)if(r.value[u]===void 0||r.value[u]===""){const h=(c=n.realTimes)==null?void 0:c.find(v=>v.propertyId===u);h&&(s[a].properties[u]=n[h.key])}else if(typeof r.value[u]=="string"&&((l=r.value[u])==null?void 0:l.indexOf("${"))>-1){let h=r.value[u].match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));h!=null&&h.length&&(s[a].properties[u]=n[h[0]]??e.getDynamicParam(h[0]))}else s[a].properties[u]=r.value[u]}),s}async function sendJetLinksData(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 playMp3(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&&createAudio(e,s.result.media,s.result.playTimes)}}function createAudio(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=createAudio;const echartReg=/^echarts/;class Meta2d{constructor(t,i={}){B(this,"store");B(this,"canvas");B(this,"websocket");B(this,"mqttClient");B(this,"websockets");B(this,"mqttClients");B(this,"eventSources");B(this,"penPluginMap",new Map);B(this,"socketFn");B(this,"events",{});B(this,"map");B(this,"mapTimer");B(this,"facePen",facePen);B(this,"getWords",getWords);B(this,"calcTextLines",calcTextLines);B(this,"calcTextRect",calcTextRect);B(this,"calcTextDrawRect",calcTextDrawRect);B(this,"jetLinksList",[]);B(this,"jetLinksClient");B(this,"register",register$1);B(this,"registerCanvasDraw",registerCanvasDraw);B(this,"registerAnchors",registerAnchors);B(this,"registerLineAnimateDraws",(t,i)=>{this.store.data.lineAnimateDraws[t]=i,globalStore.lineAnimateDraws[t]=new Function("ctx","pen","state","index",i)});B(this,"websocketTimes",0);B(this,"mqttTimes",0);B(this,"httpTimer");B(this,"httpTimerList",[]);B(this,"updateTimer");B(this,"updateTimerList",[]);B(this,"sqlTimerList",[]);B(this,"iotMqttClient");B(this,"iotTimer");B(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"&&(reset(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&&updateFormData(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?(updateFormData(i.pen),this.store.data.locked&&!i.pen.disabled&&this.doEvent(i.pen,t)):(updateFormData(i),this.store.data.locked&&i&&!i.disabled&&this.doEvent(i,t));break}this.doMessageEvent(t,i)});B(this,"doEvent",(t,i)=>{var a,n,c,l,u,h,v,f,g,y;if(!t)return;let s=!1,r=[];if((a=t.events)==null||a.forEach((p,m)=>{var x;if(p.actions&&p.actions.length){if(p.name===i){let k=!1;p.conditions&&p.conditions.length?p.conditionType==="and"?k=p.conditions.every(w=>this.judgeCondition(t,w.key,w)):p.conditionType==="or"&&(k=p.conditions.some(w=>this.judgeCondition(t,w.key,w))):k=!0,k&&r.push(m)}}else if(s=!0,this.events[p.action]&&p.name===i){let k=!((x=p.where)!=null&&x.type);if(p.where){const{fn:w,fnJs:C,comparison:I,key:_,value:L}=p.where;if(w)k=w(t,{meta2d:this});else if(C){try{p.where.fn=new Function("pen","context",C)}catch(E){console.error("Error: make function:",E,"code:",C)}p.where.fn&&(k=p.where.fn(t,{meta2d:this}))}else{let E=t[_];switch(["x","y","width","height"].includes(_)&&(E=this.getPenRect(t)[_]),I){case">":k=E>+L;break;case">=":k=E>=+L;break;case"<":k=E<+L;break;case"<=":k=E<=+L;break;case"=":case"==":k=E==L;break;case"!=":k=E!=L;break;case"[)":k=valueInRange(+E,L);break;case"![)":k=!valueInRange(+E,L);break;case"[]":k=valueInArray(E,L);break;case"![]":k=!valueInArray(E,L);break}}}k&&r.push(m)}}),s?(n=t.events)==null||n.forEach((p,m)=>{r.includes(m)&&this.events[p.action](t,p)}):(c=t.events)==null||c.forEach(async(p,m)=>{if(r.includes(m)){if(p.confirm&&!await this.canvas.popconfirm.showModal(t,this.canvas.mousePos,p.confirmTitle))return;p.actions.forEach(x=>{if(x.timeout){let k=setTimeout(()=>{this.events[x.action]&&(this.events[x.action](t,x),clearTimeout(k),k=null)},x.timeout)}else this.events[x.action]&&this.events[x.action](t,x)})}}),i==="valueUpdate"){(l=t.realTimes)==null||l.forEach(m=>{var k,w;let x=[];(k=m.triggers)==null||k.forEach((C,I)=>{var L;let _=!1;(L=C.conditions)!=null&&L.length?C.conditionType==="and"?_=C.conditions.every(E=>this.judgeCondition(t,m.key,E)):C.conditionType==="or"&&(_=C.conditions.some(E=>this.judgeCondition(t,m.key,E))):_=!0,_&&x.push(I)}),(w=m.triggers)==null||w.forEach((C,I)=>{var _;x.includes(I)&&((_=C.actions)==null||_.forEach(L=>{if(L.timeout){let E=setTimeout(()=>{this.events[L.action]&&(this.events[L.action](t,L),clearTimeout(E),E=null)},L.timeout)}else this.events[L.action](t,L)}))})});let p=[];if((u=this.store.globalTriggers[t.id])==null||u.forEach((m,x)=>{var w;let k=!1;(w=m.conditions)!=null&&w.length?m.conditionType==="and"?k=m.conditions.every(C=>this.judgeCondition(this.store.pens[C.source],C.key,C)):m.conditionType==="or"&&(k=m.conditions.some(C=>this.judgeCondition(this.store.pens[C.source],C.key,C))):k=!0,k&&p.push(x)}),(h=this.store.globalTriggers[t.id])==null||h.forEach((m,x)=>{var k;p.includes(x)&&((k=m.actions)==null||k.forEach(w=>{if(w.timeout){let C=setTimeout(()=>{this.events[w.action]&&(this.events[w.action](t,w),clearTimeout(C),C=null)},w.timeout)}else this.events[w.action](t,w)}))}),(v=t.triggers)!=null&&v.length){for(let m of t.triggers)if((f=m.status)!=null&&f.length)for(let x of m.status){let k=!1;if((g=x.conditions)!=null&&g.length?x.conditionType==="and"?k=x.conditions.every(w=>this.judgeCondition(t,w.key,w)):x.conditionType==="or"&&(k=x.conditions.some(w=>this.judgeCondition(t,w.key,w))):k=!0,k){(y=x.actions)==null||y.forEach(w=>{if(w.timeout){let C=setTimeout(()=>{this.events[w.action]&&(this.events[w.action](t,w),clearTimeout(C),C=null)},w.timeout)}else this.events[w.action](t,w)});break}}}}this.doEvent(this.store.pens[t.parentId],i)});B(this,"doDataEvent",t=>{var r,a,n;if(!((r=this.store.data.dataEvents)!=null&&r.length))return;const i=t.reduce((c,{dataId:l,id:u,value:h})=>(c[u||l]=h,c),{});let s=[];(a=this.store.data.dataEvents)==null||a.forEach((c,l)=>{let u=!1;c.conditions&&c.conditions.length?c.conditionType==="and"?u=c.conditions.every(h=>this.dataJudegeCondition(i,h.key,h)):c.conditionType==="or"&&(u=c.conditions.some(h=>this.dataJudegeCondition(i,h.key,h))):u=!0,u&&s.push(l)}),(n=this.store.data.dataEvents)==null||n.forEach((c,l)=>{var u;s.includes(l)&&((u=c.actions)==null||u.forEach(h=>{this.events[h.action](i,h)}))})});B(this,"renderPenRaw",renderPenRaw$1);B(this,"setElemPosition",setElemPosition);B(this,"setLifeCycleFunc",setLifeCycleFunc);this.store=useStore(s8()),this.setOptions(i),this.setDatabyOptions(i),this.init(t),this.register(commonPens()),this.registerCanvasDraw({cube}),this.registerAnchors(commonAnchors()),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=HotkeyType.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)calcInView(a);this.canvas&&t.scroll!==void 0&&(t.scroll?(!this.canvas.scroll&&(this.canvas.scroll=new Scroll(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(c=>s.test(c)))return;const a={},n=[];for(let c=0;c<i.length;c++){const u=i[c].split(":"),h=u[0].trim(),v=u[1].trim();n.push([h,v].join(":")),a[h]=v}le5leTheme.addTheme(t,n),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,le5leTheme.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:n,gridSize:c,fromArrow:l,toArrow:u,rule:h,ruleColor:v,textColor:f,x:g=0,y=0}=t;this.setRule({rule:h,ruleColor:v}),this.setGrid({grid:a,gridColor:n,gridSize:c}),this.store.data=Object.assign(this.store.data,{textColor:f,color:i,activeColor:s,activeBackground:r,fromArrow:l,toArrow:u,x:g,y})}init(t){typeof t=="string"?this.canvas=new Canvas(this,document.getElementById(t),this.store):this.canvas=new Canvas(this,t,this.store),this.canvas.initGlobalStyle(),this.resize(),this.canvas.listen(),le5leTheme.createThemeSheet(this.store.data.theme,this.store.id)}initEventFns(){this.events[EventAction.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(n=>n.slice(2,-1));a&&(a==null||a.forEach(n=>{r=r.replace(`\${${n}}`,getter(t,n)||this.getDynamicParam(n))}))}window.open(r,i.params??"_blank");return}console.warn("[meta2d] Link param is not a string")},this.events[EventAction.SetProps]=(t,i)=>{var r,a,n;const s=i.value;if(s&&typeof s=="object"){const c=i.params?this.find(i.params):this.find(t.id),l={};for(let u in s)if((r=s[u])!=null&&r.id)l[u]=(a=this.store.pens[s[u].id])==null?void 0:a[s[u].key];else if(typeof s[u]=="string"&&s[u].includes("${")){let h=s[u],v=(n=h.match(/\$\{([^}]+)\}/g))==null?void 0:n.map(f=>f.slice(2,-1));v&&v.forEach(f=>{h=h.replace(`\${${f}}`,getter(t,f)||this.getDynamicParam(f))}),l[u]=h}else if(typeof s[u]=="string"&&(s[u].startsWith("{")&&s[u].endsWith("}")||s[u].startsWith("[")&&s[u].endsWith("]")))try{l[u]=JSON.parse(s[u])}catch{l[u]=s[u]}else l[u]=s[u];c.forEach(u=>{l.hasOwnProperty("visible")&&u.visible!==l.visible&&this.setVisible(u,l.visible),this.setValue({id:u.id,...l},{render:!1,doEvent:!1})}),this.render();return}console.warn("[meta2d] SetProps value is not an object")},this.events[EventAction.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[EventAction.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[EventAction.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[EventAction.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[EventAction.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[EventAction.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[EventAction.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=new Function("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[EventAction.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[EventAction.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[EventAction.SendPropData]=(t,i)=>{const s=deepClone(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[EventAction.SendVarData]=(t,i)=>{const s=deepClone(i.value);if(s&&typeof s=="object"){const r=i.params?this.findOne(i.params):t;let a=[];for(let n in s){let c={dataId:n,value:s[n]};if(!c.value){let l=r.form.find(u=>u.dataIds&&u.dataIds.dataId===c.dataId);l&&(c.value=r[l.key])}a.push(c)}this.doSendDataEvent(a,i.extend);return}console.warn("[meta2d] SendVarData value is not an object")},this.events[EventAction.Navigator]=(t,i)=>{i.value&&typeof i.value=="string"&&this.navigatorTo(i.value)},this.events[EventAction.Dialog]=(t,i)=>{var s;if(i.params&&typeof i.params=="string"){let r=i.params;if(i.params.includes("${")){let n=(s=i.params.match(/\$\{([^}]+)\}/g))==null?void 0:s.map(c=>c.slice(2,-1));n&&(n==null||n.forEach(c=>{r=r.replace(`\${${c}}`,getter(t,c)||this.getDynamicParam(c))}))}Object.keys(i.extend).forEach(n=>{["x","y","width","height"].includes(n)||(r.indexOf("?")!==-1?r+=`&${n}=${i.extend[n]}`:r+=`?${n}=${i.extend[n]}`)});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[EventAction.SendData]=(t,i)=>{var r,a,n,c;if((r=i.data)!=null&&r.length){const l=this.getSendData(i.data,t);t.formId&&t.formData&&Object.assign(l,t.formData),this.sendDataToNetWork(l,t,i);return}if((a=i.list)!=null&&a.length){if(i.network&&i.network.protocol==="ADIIOT"){const u=getSendData(this,t,i);u.length&&sendJetLinksData(this,u);return}const l=this.getEventData(i.list,t);t.deviceId&&(l.deviceId=t.deviceId),t.formId&&t.formData&&Object.assign(l,t.formData),this.sendDataToNetWork(l,t,i);return}const s=deepClone(i.value);if(s&&typeof s=="object"&&i.targetType==="id"){const l=i.params?this.findOne(i.params):t;for(let u in s)if(s[u]===void 0||s[u]==="")s[u]=getter(l,u);else if(typeof s[u]=="string"&&((n=s[u])==null?void 0:n.indexOf("${"))>-1){let h=(c=s[u].match(/\$\{([^}]+)\}/g))==null?void 0:c.map(v=>v.slice(2,-1));h!=null&&h.length&&(s[u]=getter(l,u[0])??this.getDynamicParam(h[0]))}l.deviceId&&(s.deviceId=l.deviceId),this.sendDataToNetWork(s,t,i);return}},this.events[EventAction.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=queryURLParams(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[EventAction.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[EventAction.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 n=this.findOne(r.id);s[r.prop]=getter(n,r.key)}else if(typeof r.value=="string"&&r.value.includes("${")){let n=r.value,c=(a=n.match(/\$\{([^}]+)\}/g))==null?void 0:a.map(l=>l.slice(2,-1));c&&c.forEach(l=>{n=n.replace(`\${${l}}`,getter(i,l)||this.getDynamicParam(l))}),s[r.prop]=n}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(n=>n.slice(2,-1));if(a!=null&&a.length)for(let n=0;n<a.length;n++)r=r.replace(`\${${a[n]}}`,this.getDynamicParam(a[n]));return JSON.parse(r)}return t}getEventData(t,i){const s={};return t!=null&&t.length&&t.forEach(r=>{var n,c;const a=r.params?this.findOne(r.params):i;for(let l in r.value)if(r.value[l]===void 0||r.value[l]==="")s[l]=a[l];else if(typeof r.value[l]=="string"&&((n=r.value[l])==null?void 0:n.indexOf("${"))>-1){let u=(c=r.value[l].match(/\$\{([^}]+)\}/g))==null?void 0:c.map(h=>h.slice(2,-1));u!=null&&u.length&&(s[l]=a[u[0]]??this.getDynamicParam(u[0]))}else s[l]=r.value[l]}),Object.keys(s).length?s:{}}message(t){new Message(this.canvas.parentElement,t).init()}closeAll(){for(let t in messageList)messageList[t].close()}async navigatorTo(t){var r;if(!t)return;if((r=queryURLParams())==null?void 0:r.id){const a=new URL(window.location);a.searchParams.set("id",t),history.pushState({},"",a)}const s=await getMeta2dData(this.store,t);if(s){this.canvas.opening=!0,this.open(s),this.lock(1);const a=this.store.data.width||this.store.options.width,n=this.store.data.height||this.store.options.height;a&&n?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,n,c,l,u,h;const r=deepClone(s.network);if(r.data&&(Object.assign(r,r.data),delete r.data),r.protocol==="iot"){if(this.store.data.iot.room){let v={token:this.store.data.iot.token,data:t};if(t.name){const f=Object.keys(t).filter(g=>t[g]==="aggregate");if(f.length){const g=deepClone(t);f.forEach(p=>{delete g[p]}),delete g.name,g.start&&typeof g.start=="string"&&(g.start=Math.floor(new Date(g.start).getTime()/1e3)),g.end&&typeof g.end=="string"&&(g.end=Math.floor(new Date(g.end).getTime()/1e3));let y=[];f.forEach(p=>{let m=p.split("#");y.push({token:this.store.data.iot.token,deviceId:m[0],key:m[1],name:m[1]+"_"+t.name,...g})}),this.iotMqttClient&&this.iotMqttClient.publish(`le5le-iot/${this.store.data.iot.room}/property/aggregate`,JSON.stringify(y));return}}this.iotMqttClient&&this.iotMqttClient.publish(`le5le-iot/${this.store.data.iot.room}/properties/set`,JSON.stringify(v))}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 y=JSON.stringify(r.headers),p=(n=y.match(/\$\{([^}]+)\}/g))==null?void 0:n.map(m=>m.slice(2,-1));if(p!=null&&p.length)for(let m=0;m<p.length;m++)y=y.replace(`\${${p[m]}}`,this.getDynamicParam(p[m]));r.headers=JSON.parse(y)}let v,f=r.url;if(r.method==="GET"&&Object.keys(t).length!==0&&(f.includes("?")?v="&"+Object.keys(t).map(y=>y+"="+t[y]).join("&"):v="?"+Object.keys(t).map(y=>y+"="+t[y]).join("&")),f.indexOf("${")>-1){let y=(c=f.match(/\$\{([^}]+)\}/g))==null?void 0:c.map(p=>p.slice(2,-1));y&&y.forEach(p=>{f=f.replace(`\${${p}}`,getter(i,p)||this.getDynamicParam(p))})}const g=await fetch(f+(v||""),{headers:r.headers||{},method:r.method,body:r.method==="POST"?JSON.stringify(t):void 0});if(g.ok){if(s.callback){const y=await g.text();if(!s.fn)try{if(typeof s.callback!="string")throw new Error("[meta2d] Function callback must be string");const p=s.callback;s.fn=new Function("pen","data","context",p)}catch(p){console.error("[meta2d]: Error on make a function:",p,"code:",s.callback)}(l=s.fn)==null||l.call(s,i,y,{meta2d:this,e:s})}console.info("http消息发送成功")}else this.store.emitter.emit("error",{type:"http",error:g})}else if(r.protocol==="mqtt"){const v=(u=this.mqttClients)==null?void 0:u.filter(f=>f.options.href===r.url);if(v&&v.length)v[0].connected&&r.topics.split(",").forEach(f=>{v[0].publish(f,JSON.stringify(t))});else{let f=mqtt_minExports.connect(r.url,r.options);f.on("connect",()=>{console.info("mqtt连接成功"),r.topics.split(",").forEach(g=>{f.publish(g,JSON.stringify(t)),setTimeout(()=>{f==null||f.end()},1e3)})})}}else if(r.protocol==="websocket"){const v=(h=this.websockets)==null?void 0:h.filter(f=>f.url===r.url);if(v&&v.length)v[0].readyState===1&&v[0].send(JSON.stringify(t));else{let f=new WebSocket(r.url,r.protocols||void 0);f.onopen=function(){console.info("websocket连接成功"),f.send(JSON.stringify(t)),setTimeout(()=>{f.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=!1){return this.canvas.addPenSync(t,i,s,r)}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 c,l,u,h;let s=this;async function r(v){return new Promise(f=>{const g=new Image;g.src=v,s.store.options.cdn&&!(v.startsWith("http")||v.startsWith("//")||v.startsWith("data:image"))&&(g.src=s.store.options.cdn+v),g.crossOrigin=s.store.options.crossOrigin||"anonymous",g.onload=()=>{f(g)}})}this.store.data.bkImage=t;const a=(i==null?void 0:i.width)||((c=this.store.data)==null?void 0:c.width)||((l=this.store.options)==null?void 0:l.width),n=(i==null?void 0:i.height)||((u=this.store.data)==null?void 0:u.height)||((h=this.store.options)==null?void 0:h.height);if(a&&n?(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 v=await r(t);this.store.bkImg=v,a&&n&&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}={}){this.store.data.grid=t,this.store.data.gridColor=i,this.store.data.gridSize=s<0?0:s,this.store.data.gridRotate=r,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.canvas.autoPolylineFlag=!0,t){t.theme&&this.setTheme(t.theme),updateIframes(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=s8()),!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=s8()),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)loadCss(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 n=i.length-1;n>=0;n--){let c=i[n];if(c.parentId){const l=this.store.pens[c.parentId];(c.x>10||c.y>10||c.width>10||c.height>10||!l.children||!l.children.includes(c.id))&&a.push(c)}if(s&&r){let l=this.getPenRect(c);(l.x<-10||l.y<-10||l.x+l.width>s||l.y+l.height>r)&&a.push(c)}c.name==="line"&&c.anchors.length<2&&a.push(c)}return(!s||!r)&&findOutliersByZScore(i).forEach(c=>{a.filter(u=>u.id===c.id).length||a.push(c)}),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:deepClone(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,globalStore.path2dDraws[s.name]&&this.store.path2dMap.set(s,globalStore.path2dDraws[s.name](s)),s.type&&this.store.path2dMap.set(s,globalStore.path2dDraws[s.name](s)),s.image&&(s.calculative.imageDrawed=!1,this.canvas.loadImage(s))}),this.render())}loadLineAnimateDraws(){globalStore.lineAnimateDraws={},Object.entries(this.store.data.lineAnimateDraws).forEach(([t,i])=>{globalStore.lineAnimateDraws[t]=new Function("ctx","pen","state","index",i)})}statistics(){const t=this.store.data.pens.length,i=this.store.data.pens.filter(c=>c.image).length,s=this.store.data.pens.filter(c=>c.image&&c.calculative.inView).length,r=this.store.data.pens.filter(c=>c.name.endsWith("Dom")||isDomShapes.includes(c.name)||this.store.options.domShapes.includes(c.name)||c.externElement||c.isDom).length,a=this.store.animates.size;let n=0;return Object.keys(this.store.bind).forEach(c=>{n+=this.store.bind[c].length}),Object.keys(this.store.bindDatas).forEach(c=>{n+=this.store.bindDatas[c].length}),{图元总数量:t,图片图元数量:i,图片图元绘制数量:s,dom图元数量:r,正在执行的动画数量:a,数据点数量:n}}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,n;(a=r.realTimes)==null||a.forEach(c=>{var l;if(c.bind&&c.bind.id){const u=(l=this.store.data.networks)==null?void 0:l.some(y=>y.protocol==="ADIIOT");let h=c.productId||r.productId,v=c.deviceId||r.deviceId,f=c.propertyId,g=!1;if(u){if(h&&typeof h=="string"&&h.indexOf("${")>-1){let y=h.match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));y!=null&&y.length&&(h=this.getDynamicParam(y[0])||h),g=!0}if(v&&typeof v=="string"&&v.indexOf("${")>-1){let y=v.match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));y!=null&&y.length&&(v=this.getDynamicParam(y[0])||v),g=!0}if(f&&typeof f=="string"&&f.indexOf("${")>-1){let y=f.match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));y!=null&&y.length&&(f=this.getDynamicParam(y[0])||f),g=!0}g&&c.bind&&(c.bind.id=h+"#"+v+"#"+f)}if(this.store.bind[c.bind.id]||(this.store.bind[c.bind.id]=[]),this.store.bind[c.bind.id].push({id:r.id,key:c.key}),u&&h&&v&&f){const y=this.jetLinksList.findIndex(p=>p.topic.startsWith(`/${h}/${v}`));y>-1?this.jetLinksList[y].properties.includes(c.propertyId)||this.jetLinksList[y].properties.push(c.propertyId):this.jetLinksList.push({topic:`/${h}/${v}`,deviceId:v,properties:[c.propertyId]})}if(c.bind.class==="iot")if(c.bind.compute_name){s.findIndex(m=>m.id===c.bind.id)===-1&&s.push(deepClone(c.bind));let p=t.findIndex(m=>m.deviceId===c.bind.deviceId);p>-1?t[p].properties.includes(c.bind.key)||t[p].properties.push(c.bind.key):t.push({deviceId:c.bind.deviceId,properties:[c.bind.key],token:c.bind.token})}else{let y=c.bind.id.split("#"),p=t.findIndex(x=>x.deviceId===y[0]);p>-1?t[p].properties.includes(y[1])||t[p].properties.push(y[1]):t.push({deviceId:y[0],properties:[y[1]],token:c.bind.token}),i.findIndex(x=>x.key===c.bind.id)===-1&&i.push({key:c.bind.id,label:c.bind.label})}else if(c.bind.class==="sql"){let y=c.bind.id.split("#");const p=this.store.data.sqls.find(m=>m.bindId===y[0]);if(p){p.keys||(p.keys=[]),y.shift();const m=y.join("#");p.keys.includes(m)||p.keys.push(m)}}}}),(n=r.events)==null||n.forEach(c=>{var u;const l=(u=c.actions)==null?void 0:u.filter(h=>h.action===EventAction.SendData);l==null||l.forEach(h=>{var v;(v=h.data)==null||v.forEach(f=>{if(f.class==="iot"){let g=f.prop.split("#"),y=t.findIndex(p=>p.deviceId===g[0]);y>-1?t[y].properties.includes(g[1])||t[y].properties.push(g[1]):t.push({deviceId:g[0],properties:[g[1]],token:f.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=new Function("context",t);i({meta2d:this}),i=null}catch(i){console.warn("initJs error",i)}}doInitFn(){let t=queryURLParams(),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&&lockedError(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&&setElemPosition(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=getFromAnchor(t),r=getToAnchor(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);clearStore(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 globalStore.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,n;if(r.calculative.pause){const c=Date.now()-r.calculative.pause;r.calculative.pause=void 0,r.calculative.frameStart+=c,r.calculative.frameEnd+=c}else{let c=-1;if(i!==void 0&&r.animations){if(typeof i=="string"){if(c=r.animations.findIndex(l=>l.name===i),c===-1)return}else if(typeof i=="number")if(r.animations.length>i)c=i;else return}else i===void 0&&(c=(a=r.animations)==null?void 0:a.findIndex(l=>l.autoPlay),c===-1&&((n=r.animations)!=null&&n.length)&&(c=0));if(c!==-1&&c!==void 0){const l=deepClone(r.animations[c]);l.animateName=l.name,delete l.name,l.currentAnimation=c,!r.type&&l.frames&&(l.showDuration=this.calcAnimateDuration(l)),this.setValue({id:r.id,...l},{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===LockState.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=deepClone(t);if(t.length===1&&t[0].type){t[0].type=PenType.Node,this.canvas.active(t),this.pushHistory({type:EditType.Update,initPens:r,pens:deepClone(t,!0)}),this.render();return}const a=getRect$1(t);let n={id:s8(),name:"combine",...a,children:[],showChild:i};this.canvas.makePen(n);const c=deepClone(n);let l=1/0;return t.forEach(u=>{const h=this.store.data.pens.findIndex(f=>f.id===u.id);if(h<l&&(l=h),u===n||u.parentId===n.id||u.id===n.id)return;n.children.push(u.id),u.parentId=n.id;const v=calcRelativeRect(u.calculative.worldRect,a);Object.assign(u,v),u.locked=u.lockedOnCombine??LockState.None,u.locked=u.interaction||isInteraction.includes(u.name)?0:u.locked}),this.store.data.pens.splice(l,0,n),this.store.data.pens.pop(),s&&this.canvas.active([n]),this.pushHistory({type:EditType.Add,pens:[c],step:3}),this.pushHistory({type:EditType.Update,initPens:[c],pens:[n],step:3}),this.pushHistory({type:EditType.Update,initPens:r,pens:t,step:3}),i!=null&&(t.forEach(u=>{calcInView(u,!0)}),this.initImageCanvas([n])),this.store.emitter.emit("combine",[n]),this.render(),n}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=deepClone(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=LockState.None,a.calculative.active=void 0,a.calculative.hover=!1,this.setVisible(a,!0)});const r=this.isCombine(t)?3:2;this.pushHistory({type:EditType.Update,initPens:s,pens:i,step:r}),s=[deepClone(t)],this.inactive(),t.children=void 0,this.pushHistory({type:EditType.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=getAllChildren(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=LockState.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=getRect$1(t);Object.assign(s,r),Object.assign(s.calculative.worldRect,r),calcWorldAnchors(s),s.children.forEach(a=>{const n=this.store.pens[a],c=calcRelativeRect(n.calculative.worldRect,r);Object.assign(n,c)}),t.forEach(a=>{if(a.id!==s.id){s.children.push(a.id),a.parentId=s.id;const n=calcRelativeRect(a.calculative.worldRect,r);Object.assign(a,n),a.locked=a.lockedOnCombine??LockState.DisableMove,a.locked=a.interaction||isInteraction.includes(a.name)?0:a.locked,calcInView(a,!0)}}),this.initImageCanvas(t),this.render()}else console.warn("Invalid operation!")}updateRectbyChild(t,i,s){if(calcRightBottom(t),calcCenter(t),i.calculative.worldRect=t,s.container&&rectInRect(t,s.calculative.worldRect,!0)){const r=calcRelativeRect(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),n=Math.max(t.ex,s.calculative.worldRect.ex),c=Math.max(t.ey,s.calculative.worldRect.ey);s.calculative.worldRect={x:r,y:a,width:n-r,height:c-a,ex:n,ey:c},calcCenter(s.calculative.worldRect)}else{const r=s.children.map(a=>this.store.pens[a]);s.calculative.worldRect=getRect$1(r)}s.parentId||Object.assign(s,s.calculative.worldRect),s.children.forEach(r=>{const a=this.store.pens[r],n=calcRelativeRect(a.calculative.worldRect,s.calculative.worldRect);Object.assign(a,n)}),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!==LockState.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 getParent(t,i)}getAllChildren(t){return getAllChildren(t,this.store)}getAllFollowers(t){return getAllFollowers(t,this.store)}data(){this.initBinds();const t=deepClone(this.store.data),{pens:i,paths:s}=this.store.data;t.version=pkg.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=new Function("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){this.closeWebsocket(),t&&(this.store.data.websocket=t),this.store.data.websocket&&(this.websocket=new WebSocket(this.store.data.websocket,this.store.data.websocketProtocols||void 0),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=s8());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=mqtt_minExports.connect(this.store.data.mqtt,i),this.mqttClient.on("message",(a,n)=>{this.socketCallback(n.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 n=await a.text();this.socketCallback(n,{type:"http",url:i})}},s||1e3))}}async oldRequestHttp(t){let i=deepClone(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,n=0;this.mqttClients=[],this.websockets=[],this.eventSources=[],t.forEach(async c=>{c.protocol==="mqtt"?(c.index=s,this.connectNetMqtt(c),s+=1):c.protocol==="websocket"?(c.index=a,this.connectNetWebSocket(c),a+=1):c.protocol==="http"?(c.index=r,i.push({url:c.url,interval:c.interval,headers:c.headers||void 0,method:c.method,body:c.body,enable:c.enable,index:c.index,once:c.once}),r+=1):c.protocol==="ADIIOT"?connectJetLinks(this,c):c.protocol==="SSE"&&(c.index=n,this.connectSSE(c),n+=1)})}this.onNetworkConnect(i),this.connectIot(),this.connectSqls()}reconnectNetwork(t){var s,r;const i=this.store.data.networks[t];if(i.protocol==="mqtt")this.mqttClients&&((s=this.mqttClients[i.index])==null||s.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 a=deepClone(i);this.store.data.cancelFirstConnect||this.requestHttp(a),i.interval!==0&&(this.updateTimerList[i.index]=setInterval(async()=>{this.requestHttp(a)},a.interval||1e3))}else i.protocol==="SSE"&&(this.eventSources&&((r=this.eventSources[i.index])==null||r.close(),this.eventSources[i.index]=void 0),this.connectSSE(i))}async connectIot(){var u,h;const{iot:t}=this.store.data;if(!(t&&((u=t==null?void 0:t.devices)!=null&&u.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:n,data:c}=await this.getIotToken(t.devices,t.protocol==="websocket"?1:void 0,t.room);c&&this.socketCallback(JSON.stringify(c),{type:"iot",url:i,method:"mqtt"}),n&&(t.room=n),t.token=a;const l={username:r,password:s,clientId:"client-"+Math.random().toString(16).slice(2,8)};if(this.iotMqttClient=mqtt_minExports.connect(i,l),this.iotMqttClient.on("message",(v,f)=>{this.socketCallback(f.toString(),{topic:`le5le-iot/properties/${a}`,type:"iot",url:i,method:"mqtt"})}),this.iotMqttClient.on("error",v=>{this.store.emitter.emit("error",{type:"mqtt",error:v})}),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),(h=this.store.data.iot.computes)!=null&&h.length){let v=!1;this.store.data.iot.computes.forEach(f=>{f.times>0&&(v=!0)}),this.iotAggregatePublish(this.store.data.iot.computes),t.times=0,v&&(t.interval=setInterval(()=>{t.times+=1;let f=this.store.data.iot.computes.filter(g=>g.times&&t.times%g.times===0);f.length&&this.iotAggregatePublish(f)},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)))})}connectSSE(t){t.enable!==!1&&(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)})}connectNetMqtt(t){var r,a,n;if(t.enable===!1)return;t.options.clientId&&!t.options.customClientId&&(t.options.clientId=s8());let i=t.url;if(i.indexOf("${")>-1){let c=(r=i.match(/\$\{([^}]+)\}/g))==null?void 0:r.map(l=>l.slice(2,-1));c&&c.forEach(l=>{i=i.replace(`\${${l}}`,this.getDynamicParam(l))})}t.times=0;let s=deepClone(t.options);if(s!=null&&s.username&&s.username.includes("${")){let c=(a=s.username.match(/\$\{([^}]+)\}/g))==null?void 0:a.map(l=>l.slice(2,-1));c&&c.forEach(l=>{s.username=s.username.replace(`\${${l}}`,this.getDynamicParam(l))})}if(s!=null&&s.password&&s.password.includes("${")){let c=(n=s.password.match(/\$\{([^}]+)\}/g))==null?void 0:n.map(l=>l.slice(2,-1));c&&c.forEach(l=>{s.password=s.password.replace(`\${${l}}`,this.getDynamicParam(l))})}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]=mqtt_minExports.connect(i,s),this.mqttClients[t.index].on("message",(c,l)=>{this.socketCallback(l.toString(),{topic:c,type:"mqtt",url:t.url,name:t.name,net:t})}),this.mqttClients[t.index].on("error",c=>{this.store.emitter.emit("error",{type:"mqtt",error:c})}),this.mqttClients[t.index].on("connect",c=>{var l;if(!c.sessionPresent&&t.topics){let u=t.topics;if(u.indexOf("${")>-1){let h=(l=u.match(/\$\{([^}]+)\}/g))==null?void 0:l.map(v=>v.slice(2,-1));h&&h.forEach(v=>{u=u.replace(`\${${v}}`,this.getDynamicParam(v))})}this.mqttClients[t.index].subscribe(u.split(","),{qos:1},h=>{h&&console.error("订阅失败:",h)})}})}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;let i=t.url;if(i.indexOf("${")>-1){let a=(r=i.match(/\$\{([^}]+)\}/g))==null?void 0:r.map(n=>n.slice(2,-1));a&&a.forEach(n=>{i=i.replace(`\${${n}}`,this.getDynamicParam(n))})}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:getToken()}});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:getToken()},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:getToken()},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:getToken()},body:JSON.stringify({dbId:t.dbId||t.dbid,sql:s})});if(r.ok){let n=await r.text();if(n){const c=[];if(n=JSON.parse(n),n.error){this.store.emitter.emit("error",{type:"sql",error:n.error});return}(a=t.keys)==null||a.forEach(l=>{c.push({id:t.bindId+"#"+l,value:getter(n,l.split("#").join("."))})}),c.push({id:t.bindId,value:n}),this.socketCallback(JSON.stringify(c),{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,n=t.mock.split("-");if(t.mock.charAt(0)==="-"?n.length===4?(s=-parseFloat(n[3]),r=-parseFloat(n[1]),a=n[3]):(s=parseFloat(n[2]),r=-parseFloat(n[1]),a=n[2]):(s=parseFloat(n[1]),r=parseFloat(n[0]),a=n[1]),(a+"").indexOf(".")!==-1){let c=(a+"").split(".")[1].length;i=(Math.random()*(s-r)+r).toFixed(c)}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=deepClone(r);a.enableMock=!0;let n=this.mockValue(a);n!==void 0&&t.push({id:r.id,value:n})}))}),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){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=d(i)),queryURLParams()[t]||i||getCookie(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 s,r,a;let i=deepClone(t);if(i.url){if(i.url.indexOf("${")>-1){let c=(s=i.url.match(/\$\{([^}]+)\}/g))==null?void 0:s.map(l=>l.slice(2,-1));c&&c.forEach(l=>{i.url=i.url.replace(`\${${l}}`,this.getDynamicParam(l))})}if(typeof i.headers=="object"){let c=JSON.stringify(i.headers),l=(r=c.match(/\$\{([^}]+)\}/g))==null?void 0:r.map(u=>u.slice(2,-1));if(l!=null&&l.length)for(let u=0;u<l.length;u++)c=c.replace(`\${${l[u]}}`,this.getDynamicParam(l[u]));i.headers=JSON.parse(c)}if(typeof i.body=="object"){let c=JSON.stringify(i.body),l=(a=c.match(/\$\{([^}]+)\}/g))==null?void 0:a.map(u=>u.slice(2,-1));if(l!=null&&l.length)for(let u=0;u<l.length;u++)c=c.replace(`\${${l[u]}}`,this.getDynamicParam(l[u]));i.body=JSON.parse(c)}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 c=await n.text(),l=this.store.data.networks.filter(u=>u.protocol==="http")[i.index];this.socketCallback(c,{type:"http",method:i.method,url:i.url,name:i.name,net:l})}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(),closeJetLinks(this),this.closeSSE()}socketCallback(t,i){var a,n;this.store.emitter.emit("socket",{message:t,context:i});let s=t;if((a=i.net)!=null&&a.socketCbJs&&((n=i.net)!=null&&n.socketFn||(i.net.socketFn=new Function("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(c){console.warn("Invalid socket data:",r,c)}else return;r&&(Array.isArray(r)||(r=[r]),r.length&&(r[0].dataId?this.setDatas(r):r.forEach(c=>{this.setValue(c)})))}setDatas(t,{render:i=!0,doEvent:s=!0,history:r}={}){const a=new Map;t.forEach(l=>{var u,h;(u=this.store.bindDatas[l.dataId])==null||u.forEach(v=>{const f=this.store.pens[v.id];if(!f)return;let g=a.get(f);if(!f.noOnBinds&&typeof f.onBinds=="function"){if(g)return;a.set(f,f.onBinds(f,t,v.formItem));return}g?g[v.formItem.key]=l.value:(g={id:v.id,[v.formItem.key]:l.value},a.set(f,g))}),(h=this.store.bind[l.id||l.dataId])==null||h.forEach(v=>{const f=this.store.pens[v.id];if(!f)return;let g=a.get(f);g?g[v.key]=l.value:(g={id:v.id,[v.key]:l.value},a.set(f,g))})}),this.store.data.locked&&this.doDataEvent(t);let n,c;r&&(n=[]),a.forEach((l,u)=>{this.setValue(l,{render:!1,doEvent:s,history:!1}),r&&(n.push(deepClone(u,!0)),c.push(u))}),i&&this.render(),r&&this.pushHistory({type:EditType.Update,initPens:n,pens:c})}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 c=this.store.pens[t.id];if(c)a=[c];else{let l=this.store.bind[t.id];if(l&&l.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 c=[];for(let l in t)c.push({dataId:l,id:l,value:t[l]});c.length&&this.setDatas(c,{render:i,doEvent:s,history:r});return}r=r&&!this.store.data.locked;let n;if(r&&(n=deepClone(a)),a.forEach(c=>{var u;if(c.name==="echarts"&&!c.onBeforeValue&&Object.keys(t).some(v=>echartReg.test(v)))return;const l=c.onBeforeValue?c.onBeforeValue(c,t):t;t.frames&&(this.stopAnimate([c]),t.showDuration||(t.showDuration=t.frames.reduce((h,v)=>h+v.duration,0))),setChildValue(c,l),this.canvas.updateValue(c,l),(u=c.onValue)==null||u.call(c,c)}),!this.store.data.locked&&this.store.active.length&&!this.canvas.movingPens&&this.canvas.calcActiveRect(),r){let c=deepClone(a);this.pushHistory({type:EditType.Update,initPens:n,pens:c})}s&&a.forEach(c=>{this.store.emitter.emit("valueUpdate",c)}),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=>{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:n,fn:c,operator:l,valueType:u}=s;let h=!1;if(r==="fn"){if(c)h=c(t,{meta2d:this});else if(n){try{s.fn=new Function("data","context",n)}catch(v){console.error("Error: make function:",v)}s.fn&&(h=s.fn(t,{meta2d:this}))}}else{let v=s.value;u==="prop"&&(v=t[s.value]);let f=t[i];switch(l){case">":h=f>+v;break;case">=":h=f>=+v;break;case"<":h=f<+v;break;case"<=":h=f<=+v;break;case"=":case"==":h=f==v;break;case"!=":h=f!=v;break;case"[)":h=valueInRange(+f,v);break;case"![)":h=!valueInRange(+f,v);break;case"[]":h=valueInArray(f,v);break;case"![]":h=!valueInArray(f,v);break}}return h}judgeCondition(t,i,s){const{type:r,target:a,fnJs:n,fn:c,operator:l,valueType:u}=s;let h=!1;if(r==="fn"){if(c)h=c(t,{meta2d:this});else if(n){try{s.fn=new Function("pen","context",n)}catch(v){console.error("Error: make function:",v)}s.fn&&(h=s.fn(t,{meta2d:this}))}}else{let v=s.value;u==="prop"&&(v=this.store.pens[a][s.value]);let f=getter(t,i);switch(["x","y","width","height"].includes(i)&&(f=this.getPenRect(t)[i]),l){case">":h=f>+v;break;case">=":h=f>=+v;break;case"<":h=f<+v;break;case"<=":h=f<=+v;break;case"=":case"==":h=f==v;break;case"!=":h=f!=v;break;case"[)":h=valueInRange(+f,v);break;case"![)":h=!valueInRange(+f,v);break;case"[]":h=valueInArray(f,v);break;case"![]":h=!valueInArray(f,v);break}}return h}pushChildren(t,i){const s=[deepClone(t,!0)],r=[];t.children||(t.children=[]);const a=[];i.forEach(c=>{let l=deepClone(c,!0);if((!c.id||!this.store.pens[c.id])&&(this.canvas.makePen(c),l=null),c.parentId){const h=this.store.pens[c.parentId],v=h.children.findIndex(f=>f===c.id);s.push(deepClone(h,!0)),h.children.splice(v,1),a.push(deepClone(h,!0))}t.children.push(c.id),c.parentId=t.id;const u=calcRelativeRect(c.calculative.worldRect,t.calculative.worldRect);Object.assign(c,u),c.locked=c.lockedOnCombine??LockState.DisableMove,c.locked=c.interaction||isInteraction.includes(c.name)?0:c.locked,l?(s.push(l),a.push(deepClone(c,!0))):r.push(deepClone(c,!0))}),a.push(deepClone(t,!0));let n=1;r.length&&(n=2,this.pushHistory({type:EditType.Add,pens:r,step:n})),this.pushHistory({type:EditType.Update,initPens:s,pens:a,step:n})}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 n=document.createEvent("MouseEvents");n.initEvent("click",!0,!0),a.dispatchEvent(n)},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 n=new window.C2S(a.width+20,a.height+20);n.textBaseline="middle",n.strokeStyle=this.store.styles.color;const c=this.store.options.downloadBgTransparent?void 0:this.store.data.background||this.store.styles.background;c&&i&&(n.save(),n.fillStyle=c,n.fillRect(0,0,a.width,a.height),n.restore()),this.store.bkImg&&i&&n.drawImage(this.store.bkImg,0,0,a.width,a.height),c&&!i&&(n.save(),n.fillStyle=c,n.fillRect(0,0,a.width+20,a.height+20),n.restore());for(const y of this.store.data.pens)y.visible==!1||!isShowChild(y,this.store)||renderPenRaw$1(n,y,a,!0);let l=n.getSerializedSvg();t!=null&&t.length&&(l=l.replace("<defs/>",`<defs>
|
|
93
|
-
<style type="text/css">
|
|
94
|
-
${t.join(`
|
|
95
|
-
`)}
|
|
96
|
-
</style>
|
|
97
|
-
{{bk}}
|
|
98
|
-
</defs>
|
|
99
|
-
{{bkRect}}`)),c?(l=l.replace("{{bk}}",""),l=l.replace("{{bkRect}}",`<rect x="0" y="0" width="100%" height="100%" fill="${c}"></rect>`)):(l=l.replace("{{bk}}",""),l=l.replace("{{bkRect}}","")),l=l.replace(/--le5le--/g,"&#x");const u=window.URL,h=new Blob([l]),v=u.createObjectURL(h),f=document.createElement("a");f.setAttribute("download",`${this.store.data.name||"le5le.meta2d"}.svg`),f.setAttribute("href",v);const g=document.createEvent("MouseEvents");g.initEvent("click",!0,!0),f.dispatchEvent(g)}getRect(t=this.store.data.pens){return getRect$1(t)}hiddenTemplate(){this.canvas.canvasTemplate.hidden()}showTemplate(){this.canvas.canvasTemplate.show()}lockTemplate(t){this.store.data.pens.forEach(i=>{i.canvasLayer===CanvasLayer.CanvasTemplate&&(i.locked=t)})}fitView(t=!0,i=10,s=!0){var f,g;if(!this.hasView())return;const{canvas:r}=this.canvas,{offsetWidth:a,offsetHeight:n}=r;this.resize(a,n);const c=formatPadding(i),l=this.getRect(),u=(a-c[1]-c[3])/l.width,h=(n-c[0]-c[2])/l.height;let v=u;t?v=u>h?h:u:v=u>h?u:h,s&&((f=this.store.data.fits)!=null&&f.length)&&(this.canvas.opening=!0),this.scale(v*this.store.data.scale),this.centerView(),s&&((g=this.store.data.fits)!=null&&g.length)&&this.fillView()}fillView(){var r,a;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=this.canvas.width-t.width,s=this.canvas.height-t.height;if(Math.abs(i)>10){(r=this.store.data.fits)==null||r.forEach(l=>{let u=[];l.children.forEach(v=>{this.store.pens[v]&&(this.store.pens[v].locked=LockState.None,u.push(this.store.pens[v]))});let h=i/2;if(l.left&&l.right){let v=l.leftValue,f=l.rightValue;v?v=Math.abs(v)<1?v*t.width:v:v=0,f?f=Math.abs(f)<1?f*t.width:f:f=0;let g=(this.canvas.width-v-f)/(t.width-v-f);u.forEach(y=>{var p,m;y.image&&y.imageRatio&&y.calculative.worldRect.width/this.canvas.width>.1&&(y.imageRatio=!1,y.ratio=!1),y.name==="tablePlus"&&(y.colWidth=(y.colWidth??150)*g,y.styles.forEach(x=>{x.width&&(x.width=x.width*g)})),Math.abs(l.leftValue)<1?y.calculative.worldRect.x=t.x-i/2+v+(y.calculative.worldRect.x-t.x-v)*g:y.calculative.worldRect.x=t.x-i/2+v+(y.calculative.worldRect.x-t.x)*g,y.calculative.worldRect.width*=g,y.calculative.worldRect.ex=y.calculative.worldRect.x+y.calculative.worldRect.width,y.calculative.width=y.calculative.worldRect.width,y.calculative.x=y.calculative.worldRect.x,y.width=y.calculative.worldRect.width,y.x=y.calculative.worldRect.x,y.textWidth*=g,y.calculative.textWidth*=g,this.canvas.updatePenRect(y,{worldRectIsReady:!1}),y.externElement&&((p=y.onResize)==null||p.call(y,y)),(m=y.children)!=null&&m.length&&getAllChildren(y,this.store).forEach(k=>{var w;k.externElement&&((w=k.onResize)==null||w.call(k,k))})})}else l.left?(h=-h,l.leftValue&&(h+=Math.abs(l.leftValue)<1?l.leftValue*this.canvas.width:l.leftValue),this.translatePens(u,h,0)):l.right&&(l.rightValue&&(h=h-(Math.abs(l.rightValue)<1?l.rightValue*this.canvas.width:l.rightValue)),this.translatePens(u,h,0))});const n=this.store.data.pens.filter(l=>l.name==="iframe");n==null||n.forEach(l=>{var h,v;const u=l.calculative.worldRect;if(u.width/this.store.data.scale>t.width*.8){let f=u.width;l.calculative.worldRect.x=u.x-i/2,l.calculative.worldRect.width=u.width+i,l.calculative.worldRect.ex=u.ex+i,l.operationalRect.x=l.operationalRect.x*f/l.calculative.worldRect.width,l.operationalRect.width=(l.calculative.worldRect.width-(1-l.operationalRect.width)*f)/l.calculative.worldRect.width,(h=l.onBeforeValue)==null||h.call(l,l,{operationalRect:l.operationalRect}),(v=l.onResize)==null||v.call(l,l)}});const c=this.store.data.pens.filter(l=>l.name==="video");c==null||c.forEach(l=>{var h;const u=l.calculative.worldRect;u.width/this.store.data.scale>t.width*.8&&(l.calculative.worldRect.x=u.x-i/2,l.calculative.worldRect.width=u.width+i,l.calculative.worldRect.ex=u.ex+i,(h=l.onResize)==null||h.call(l,l))})}if(Math.abs(s)>10){(a=this.store.data.fits)==null||a.forEach(l=>{let u=[];l.children.forEach(v=>{this.store.pens[v]&&(this.store.pens[v].locked=LockState.None,u.push(this.store.pens[v]))});let h=s/2;if(l.top&&l.bottom){let v=l.topValue,f=l.bottomValue;v?v=Math.abs(v)<1?v*this.canvas.height:v:v=0,f?f=Math.abs(f)<1?f*this.canvas.height:f:f=0;let g=(this.canvas.height-v-f)/t.height;u.forEach(y=>{var p,m;y.image&&y.imageRatio&&y.calculative.worldRect.height/this.canvas.height>.1&&(y.imageRatio=!1,y.ratio=!1),y.calculative.worldRect.y=t.y-s/2+v+(y.calculative.worldRect.y-t.y)*g,y.calculative.worldRect.height*=g,y.calculative.worldRect.ey=y.calculative.worldRect.y+y.calculative.worldRect.height,y.calculative.height=y.calculative.worldRect.height,y.calculative.y=y.calculative.worldRect.y,y.height=y.calculative.worldRect.height,y.y=y.calculative.worldRect.y,this.canvas.updatePenRect(y,{worldRectIsReady:!1}),y.externElement&&((p=y.onResize)==null||p.call(y,y)),(m=y.children)!=null&&m.length&&getAllChildren(y,this.store).forEach(k=>{var w;k.externElement&&((w=k.onResize)==null||w.call(k,k))})})}else l.top?(h=-h,l.topValue&&(h+=Math.abs(l.topValue)<1?l.topValue*this.canvas.height:l.topValue),this.translatePens(u,0,h)):l.bottom&&(l.bottomValue&&(h=h-(Math.abs(l.bottomValue)<1?l.bottomValue*this.canvas.height:l.bottomValue)),this.translatePens(u,0,h))});const n=this.store.data.pens.filter(l=>l.name==="iframe");n==null||n.forEach(l=>{var h,v;const u=l.calculative.worldRect;if(u.height/this.store.data.scale>t.height*.8){let f=u.height;l.calculative.worldRect.y=u.y-s/2,l.calculative.worldRect.height=u.height+s,l.calculative.worldRect.ey=u.ey+s,l.operationalRect.y=l.operationalRect.y*f/l.calculative.worldRect.width,l.operationalRect.height=(l.calculative.worldRect.height-(1-l.operationalRect.height)*f)/l.calculative.worldRect.height,(h=l.onBeforeValue)==null||h.call(l,l,{operationalRect:l.operationalRect}),(v=l.onResize)==null||v.call(l,l)}});const c=this.store.data.pens.filter(l=>l.name==="video");c==null||c.forEach(l=>{var h;const u=l.calculative.worldRect;u.height/this.store.data.scale>t.height*.8&&(l.calculative.worldRect.y=u.y-s/2,l.calculative.worldRect.height=u.height+s,l.calculative.worldRect.ey=u.ey+s,(h=l.onResize)==null||h.call(l,l))})}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,n=formatPadding(i),c=this.getRect(),l=(r-n[1]-n[3])/c.width,u=(a-n[0]-n[2])/c.height;let h=l;t?h=l>u?u:l:h=l>u?l:u,this.canvas.templateScale(h*this.store.data.scale);let v=this.getRect(),f=this.store.data.pens.filter(g=>!g.parentId);this.canvas.templateTranslatePens(f,-v.x,-v.y),this.store.data.pens.forEach(g=>{g.type?this.canvas.initLineRect(g):this.canvas.updateLines(g)}),this.centerView()}fitSizeView(t=!0,i=10,s=!0){var g,y;const{canvas:r}=this.canvas,{offsetWidth:a,offsetHeight:n}=r;this.resize(a,n);const c=formatPadding(i),l=(this.store.data.width||this.store.options.width)*this.store.data.scale,u=(this.store.data.height||this.store.options.height)*this.store.data.scale,h=(a-c[1]-c[3])/l,v=(n-c[0]-c[2])/u;let f=h;t==="width"?f=h:t==="height"?f=v:t?f=h>v?v:h:f=h>v?h:v,s&&((g=this.store.data.fits)!=null&&g.length)&&(this.canvas.opening=!0),this.scale(f*this.store.data.scale),this.centerSizeView(),s&&((y=this.store.data.fits)!=null&&y.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};calcCenter(r);const{center:a}=r,{scale:n,origin:c,x:l,y:u}=this.store.data;this.translate((t.x-c.x)/n-a.x-l/n,(t.y-c.y)/n-a.y-u/n);const{canvas:h}=this.canvas,v=(h.scrollWidth-h.offsetWidth)/2,f=(h.scrollHeight-h.offsetHeight)/2;h.scrollTo(v,f)}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 n=formatPadding(t);let c=null;const l=this.store.data.width||this.store.options.width,u=this.store.data.height||this.store.options.height;l&&u?c={width:l*this.store.data.scale,height:u*this.store.data.scale}:c=this.getRect();const h=(r-n[1]-n[3])/c.width;this.scale(h*this.store.data.scale),this.topView(n[0]),i&&this.canvas.scroll.changeMode(n[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 n=formatPadding(t),c=this.getRect();let l=(r-n[1]-n[3])/c.width;i||(l=(a-n[0]-n[2])/c.height),this.scale(l*this.store.data.scale),this.topView(n[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 n=null;r&&a?n={x:0,y:0,width:r,height:a}:n=this.getPenRect(i),calcCenter(n);const{center:c}=n,{scale:l,origin:u,x:h,y:v}=this.store.data;this.translate((s.x-u.x)/l-c.x-h/l,(t-u.y)/l-n.y-v/l);const{canvas:f}=this.canvas,g=(f.scrollWidth-f.offsetWidth)/2,y=(f.scrollHeight-f.offsetHeight)/2;f.scrollTo(g,y)}centerView(){if(!this.hasView())return;const t=this.getRect(),i=this.getViewCenter(),s=this.getPenRect(t);calcCenter(s);const{center:r}=s,{scale:a,origin:n,x:c,y:l}=this.store.data;this.translate((i.x-n.x)/a-r.x-c/a,(i.y-n.y)/a-r.y-l/a);const{canvas:u}=this.canvas,h=(u.scrollWidth-u.offsetWidth)/2,v=(u.scrollHeight-u.offsetHeight)/2;u.scrollTo(h,v)}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=deepClone(t),r=t[0],{width:a,height:n}=this.getPenRect(r);for(let c=1;c<t.length;c++){const l=t[c];i==="width"?this.setValue({id:l.id,width:a},{render:!1,doEvent:!1}):i==="height"?this.setValue({id:l.id,height:n},{render:!1,doEvent:!1}):this.setValue({id:l.id,width:a,height:n},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:EditType.Update,initPens:s,pens:t})}beSameByLast(t=this.store.data.pens,i){const s=deepClone(t),r=t[t.length-1],{width:a,height:n}=this.getPenRect(r);for(let c=0;c<t.length-1;c++){const l=t[c];i==="width"?this.setValue({id:l.id,width:a},{render:!1,doEvent:!1}):i==="height"?this.setValue({id:l.id,height:n},{render:!1,doEvent:!1}):this.setValue({id:l.id,width:a,height:n},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:EditType.Update,initPens:s,pens:t})}formatPainterByFirst(t=this.store.data.pens){const i=deepClone(t),s=t[0],r={};formatAttrs.forEach(a=>{r[a]=s[a]});for(let a=1;a<t.length;a++){const n=t[a];this.setValue({id:n.id,...defaultFormat,...r},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:EditType.Update,initPens:i,pens:t})}formatPainterByLast(t=this.store.data.pens){const i=deepClone(t),s=t[t.length-1],r={};formatAttrs.forEach(a=>{r[a]=s[a]});for(let a=0;a<t.length-1;a++){const n=t[a];this.setValue({id:n.id,...defaultFormat,...r},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:EditType.Update,initPens:i,pens:t})}setFormatPainter(){const t=this.store.active,i={};if(t.length>0){const s=t[0];formatAttrs.forEach(r=>{i[r]=s[r]!==void 0?s[r]:this.store.options.defaultFormat[r]||this.store.data[r]||this.store.options[r]})}else formatAttrs.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=deepClone(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,...defaultFormat,...s},{render:!1,doEvent:!1})}this.render(),this.pushHistory({type:EditType.Update,initPens:i,pens:t})}clearFormatPainter(){const t=this.store.active,i=deepClone(t);formatAttrs.forEach(s=>{for(let r=0;r<t.length;r++){const a=t[r],{fontSize:n,lineHeight:c}=this.store.options;s==="lineWidth"?(a.lineWidth=1,a.calculative.lineWidth=1):s==="fontSize"?(a.fontSize=n,a.calculative.fontSize=n):s==="lineHeight"?(a.lineHeight=c,a.calculative.lineHeight=c):(delete a[s],delete a.calculative[s])}}),this.render(),this.pushHistory({type:EditType.Update,initPens:i,pens:t})}alignNodes(t,i=this.store.data.pens,s){!s&&(s=this.getPenRect(this.getRect(i)));const r=deepClone(i);for(const a of i)this.alignPen(t,a,s);this.initImageCanvas(i),this.initTemplateCanvas(i),this.render(),this.pushHistory({type:EditType.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 n={x:0,y:0,width:r,height:a};const c=deepClone(i);if(s){const l=this.store.data.scale,u=this.getRect(i),h=(u.x-this.store.data.origin.x)/l,v=(u.y-this.store.data.origin.y)/l,f=u.width/l,g=u.height/l;let y=0,p=0;switch(t){case"left":y=-h;break;case"right":y=r-(h+f);break;case"top":p=-v;break;case"bottom":p=a-(v+g);break;case"center":y=r/2-(h+f/2);break;case"middle":p=a/2-(v+g/2);break}this.translatePens(i,y*l,p*l)}else for(const l of i)this.alignPen(t,l,n);this.initImageCanvas(i),this.initTemplateCanvas(i),this.render(),this.pushHistory({type:EditType.Update,initPens:c,pens:i})}alignNodesByFirst(t,i=this.store.data.pens){const s=deepClone(i),r=i[0],a=this.getPenRect(r);for(let n=1;n<i.length;n++){const c=i[n];this.alignPen(t,c,a)}this.initImageCanvas(i),this.initTemplateCanvas(i),this.render(),this.pushHistory({type:EditType.Update,initPens:s,pens:i})}alignNodesByLast(t,i=this.store.data.pens){const s=deepClone(i),r=i[i.length-1],a=this.getPenRect(r);for(let n=0;n<i.length-1;n++){const c=i[n];this.alignPen(t,c,a)}this.initImageCanvas(i),this.initTemplateCanvas(i),this.render(),this.pushHistory({type:EditType.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 u=1/0,h=-1/0,v=t==="width"?"x":"y";i.forEach(f=>{u=Math.min(u,f.calculative.worldRect[v]),h=Math.max(h,f.calculative.worldRect["e"+v])}),s=(h-u)/this.store.data.scale}if(i=i.filter(u=>!u.parentId),i.length<=2)return;const r=deepClone(i),a=i.reduce((u,h)=>{const v=this.getPenRect(h);return u+v[t]},0),n=(s-a)/(i.length-1);i=i.sort((u,h)=>t==="width"?u.x-h.x:u.y-h.y);const c=this.getPenRect(i[0]);let l=t==="width"?c.x:c.y;for(const u of i){const h=this.getPenRect(u);t==="width"?h.x=l:h.y=l,l+=h[t]+n,this.setValue({id:u.id,...h},{render:!1,doEvent:!1})}this.initImageCanvas(i),this.initTemplateCanvas(i),this.render(),this.pushHistory({type:EditType.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(getRect$1(t));!i&&(i=r.width),t=t.filter(u=>!u.type&&!u.parentId);const a=deepClone(t);let n=0;t.forEach(u=>{const h=this.getPenRect(u);h.height>n&&(n=h.height)});let c=r.x,l=r.y;t.forEach((u,h)=>{const v=this.getPenRect(u);if(v.x=c,v.y=l+n/2-v.height/2,this.setValue({id:u.id,...v},{render:!1,doEvent:!1}),h===t.length-1)return;const f=c+v.width-r.x,g=this.getPenRect(t[h+1]);Math.round(i-f)>=Math.round(g.width+s)?c+=v.width+s:(c=r.x,l+=n+s)}),this.initImageCanvas(t),this.initTemplateCanvas(t),this.render(),this.pushHistory({type:EditType.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 n of this.store.data.pens)calcInView(n),(a=n.onMove)==null||a.call(n,n);this.canvas.canvasTemplate.init(),this.canvas.canvasImage.init(),this.canvas.canvasImageBottom.init(),this.render()}showMap(){this.map||(this.map=new ViewMap(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=[...getAllChildren(i,this.store),i].map(n=>n.id);s.filter(n=>r.includes(n.id)).forEach(n=>{const c=s.findIndex(l=>l.id===n.id);c>-1&&(s.push(s[c]),s.splice(c,1),this.initTemplateCanvas([n]),this.initImageCanvas([n])),this.specificLayerMove(n,"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=[...getAllChildren(i,this.store),i].map(n=>n.id),a=s.filter(n=>r.includes(n.id));for(let n=a.length-1;n>=0;n--){const c=a[n],l=s.findIndex(u=>u.id===c.id);l>-1&&(s.unshift(s[l]),s.splice(l+1,1),this.initTemplateCanvas([c]),this.initImageCanvas([c])),this.specificLayerMove(c,"bottom")}}this.store.emitter.emit("layer",{type:"bottom",pens:t})}upByArea(t){if(this.store.data.pens.findIndex(l=>l.id===t.id)===-1){console.warn("upByArea: pen not in canvas");return}const s=[t,...getAllChildren(t,this.store)];let r=s.map(l=>this.store.data.pens.findIndex(u=>u.id===l.id));r.includes(-1)&&(console.warn("upByArea: pen children not in canvas"),r=r.filter(l=>l!==-1));const a=Math.min(...r),n=t.calculative.worldRect,c=this.store.data.pens.findIndex((l,u)=>{if(u<=a||l.id===t.id||isAncestor(l,t))return!1;const h=l.calculative.worldRect;return rectInRect(n,h)});if(c===-1){this.up(t);return}this.store.data.pens.splice(c+1,0,...s);for(const l of s){const u=this.store.data.pens.findIndex(h=>h.id===l.id);u>-1&&this.store.data.pens.splice(u,1)}this.initImageCanvas([t])}specificLayerMove(t,i){var s;if(t.image&&t.name!=="gif"){let r=CanvasLayer.CanvasImageBottom;i==="top"?r=CanvasLayer.CanvasImage:(i==="up"||i==="down")&&(r=CanvasLayer.CanvasMain),this.setValue({id:t.id,canvasLayer:r},{render:!1,doEvent:!1,history:!1})}else if(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&&setElemPosition(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=[...getAllChildren(i,this.store),i],a=[];for(let l=0;l<s.length;l++){const u=s[l];r.findIndex(h=>h.id===u.id)!==-1&&(u.temIndex=l,a.push(u))}let n=-1,c=0;a.forEach(l=>{l.temIndex-=c,s.splice(l.temIndex,1),c+=1,n=l.temIndex,delete l.temIndex,this.specificLayerMove(l,"up")}),s.splice(n+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=[...getAllChildren(i,this.store),i],a=[];for(let l=0;l<s.length;l++){const u=s[l];r.findIndex(h=>h.id===u.id)!==-1&&(u.temIndex=l,a.push(u))}let n=-1,c=0;a.forEach((l,u)=>{l.temIndex-=c,s.splice(l.temIndex,1),c+=1,u===0&&(n=l.temIndex),delete l.temIndex,this.specificLayerMove(l,"down")}),s.splice(n-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===PenType.Line)return[];const s=[];return(r=t.connectedLines)==null||r.forEach(({lineId:a})=>{const n=this.store.pens[a];if(!n){console.warn(t,"node contain a error connectedLine");return}if(!s.find(c=>c.id===n.id))switch(i){case"all":s.push(n);break;case"in":getToAnchor(n).connectTo===t.id&&s.push(n);break;case"out":getFromAnchor(n).connectTo===t.id&&s.push(n);break}}),s}nextNode(t){if(t.type===PenType.Line){const i=this.store.pens[getToAnchor(t).connectTo];return i?[i]:[]}else{const i=this.getLines(t,"out"),s=[];return i.forEach(r=>{const a=this.nextNode(r);for(const n of a)!s.find(l=>l.id===n.id)&&s.push(n)}),s}}previousNode(t){if(t.type===PenType.Line){const i=this.store.pens[getFromAnchor(t).connectTo];return i?[i]:[]}else{const i=this.getLines(t,"in"),s=[];return i.forEach(r=>{const a=this.previousNode(r);for(const n of a)!s.find(l=>l.id===n.id)&&s.push(n)}),s}}getNext(t){var s;if(t.type===PenType.Line){console.warn("非连线节点");return}const i=[];return(s=t.connectedLines)==null||s.forEach(({lineId:r,anchor:a})=>{var l,u;const n=(l=t.anchors)==null?void 0:l.filter(h=>h.id===a)[0],c=this.findOne(r);if(c.anchors[0].connectTo==t.id){const h=c.anchors[c.anchors.length-1].connectTo;if(h){const v=this.findOne(h),f=(u=v.connectedLines)==null?void 0:u.filter(y=>y.lineId===c.id)[0],g=v.anchors.filter(y=>y.id===f.anchor)[0];i.push({from:t,fromAnchor:n,line:c,to:v,toAnchor:g})}}}),i}addAnchor(t,i,s){if(!t)return;if(t.anchors||(t.anchors=[]),t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),t.type===PenType.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||s8(),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&&rotatePoint(a,t.rotate,t.calculative.worldRect.center),r={id:a.id,penId:t.id,x:i.x,y:i.y}):(a={id:i.id||s8(),penId:t.id,x:i.x,y:i.y},t.calculative.worldRect&&(t.rotate%360&&rotatePoint(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===PenType.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 u=i.calculative.worldRect;s=nearestAnchor(t,{x:u.x+u.width/2,y:u.y+u.height/2})}if(!r){const u=t.calculative.worldRect;r=nearestAnchor(i,{x:u.x+u.width/2,y:u.y+u.height/2})}const n=Math.abs(s.x-r.x),l={height:Math.abs(s.y-r.y),lineName:"line",lineWidth:1,name:"line",type:1,width:n,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:s8()},{x:s.x>r.x?0:1,y:s.x>r.x?0:1,id:s8()}]};return this.addPens([l]),connectLine(t,s,l,l.calculative.worldAnchors[0]),connectLine(i,r,l,l.calculative.worldAnchors[1]),l.calculative.active=!1,this.canvas.updateLines(l),this.canvas.updateLines(t),this.canvas.updateLines(i),this.canvas.initLineRect(l),a&&this.render(),l}toComponent(t=this.store.data.pens,i,s){if(t.length===1){const h=deepClone(t[0]);return h.type=PenType.Node,h.id=void 0,[h]}const r=deepClone(t,!0),a=getRect$1(r);let n={id:s8(),name:"combine",...a,children:[],showChild:i};s&&(n.anchors=[{id:"0",penId:n.id,x:.5,y:0},{id:"1",penId:n.id,x:1,y:.5},{id:"2",penId:n.id,x:.5,y:1},{id:"3",penId:n.id,x:0,y:.5}]);const c=r.filter(h=>!h.parentId),l=r.find(h=>h.width===a.width&&h.height===a.height),u=l&&i===void 0;return c.length===1?n=c[0]:u&&(l.children||(l.children=[]),n=l),r.forEach(h=>{if(h===n||h.parentId===n.id||h.parentId)return;n.children.push(h.id),h.parentId=n.id;const v=calcRelativeRect(h.calculative.worldRect,a);Object.assign(h,v),h.locked=h.lockedOnCombine??LockState.DisableMove}),u||c.length===1?deepClone(r):deepClone([n,...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,n=r.options;if(a&&validationPlugin(a)&&s)if(a.install(t,n),!this.penPluginMap.has(a))this.penPluginMap.set(a,[{[s]:t[s],option:n}]);else{let c=this.penPluginMap.get(a).find(l=>l[s]===t[s]);c?c.option=n:this.penPluginMap.get(a).push({[s]:t[s],option:n})}})}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 n=this.penPluginMap.get(a),c=n.findIndex(l=>l[s]===t[s]);c!==-1&&(n.splice(c,1),n.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 n=this.store.pens[a];n&&this.setVisible(n,i,!1)}let r=getAllChildren(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),clearIframes(),this.stopDataMock(),this.closeSocket(),this.closeNetwork(),this.closeAll(),le5leTheme.destroyThemeSheet(this.store.id),this.store.emitter.all.clear(),this.canvas.destroy(),this.canvas=void 0,globalStore[this.store.id]=void 0,!t){for(const i in globalStore)delete globalStore[i];globalStore.path2dDraws={},globalStore.canvasDraws={},globalStore.anchors={},globalStore.htmlElements={},globalStore.lineAnimateDraws={}}}}var canvas2svg={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 n(f,g){var y=Object.keys(g),p;for(p=0;p<y.length;p++)f=f.replace(new RegExp("\\{"+y[p]+"\\}","gi"),g[y[p]]);return f}function c(f){var g,y,p;if(!f)throw new Error("cannot create a random attribute name for an undefined object");g="ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",y="";do for(y="",p=0;p<12;p++)y+=g[Math.floor(Math.random()*g.length)];while(f[y]);return y}function l(f,g){var y,p,m={},x;for(f=f.split(","),g=g||10,y=0;y<f.length;y+=2)p="&"+f[y+1]+";",x=parseInt(f[y],g),m[p]="&#"+x+";";return m["\\xa0"]=" ",m}function u(f){var g={left:"start",right:"end",center:"middle",start:"start",end:"end"};return g[f]||g.start}function h(f){var g={alphabetic:"alphabetic",hanging:"hanging",top:"text-before-edge",bottom:"text-after-edge",middle:"central"};return g[f]||g.alphabetic}a=l("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(f,g){this.__root=f,this.__ctx=g},s.prototype.addColorStop=function(f,g){var y=this.__ctx.__createElement("stop"),p,m;y.setAttribute("offset",f),g.indexOf("rgba")!==-1?(p=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi,m=p.exec(g),y.setAttribute("stop-color",n("rgb({r},{g},{b})",{r:m[1],g:m[2],b:m[3]})),y.setAttribute("stop-opacity",m[4])):y.setAttribute("stop-color",g),this.__root.appendChild(y)},r=function(f,g){this.__root=f,this.__ctx=g},i=function(f){var g={width:500,height:500,enableMirroring:!1},y;if(arguments.length>1?(y=g,y.width=arguments[0],y.height=arguments[1]):f?y=f:y=g,!(this instanceof i))return new i(y);this.width=y.width||g.width,this.height=y.height||g.height,this.enableMirroring=y.enableMirroring!==void 0?y.enableMirroring:g.enableMirroring,this.canvas=this,this.__document=y.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(f,g,y){typeof g>"u"&&(g={});var p=this.__document.createElementNS("http://www.w3.org/2000/svg",f),m=Object.keys(g),x,k;for(y&&(p.setAttribute("fill","none"),p.setAttribute("stroke","none")),x=0;x<m.length;x++)k=m[x],p.setAttribute(k,g[k]);return p},i.prototype.__setDefaultStyles=function(){var f=Object.keys(t),g,y;for(g=0;g<f.length;g++)y=f[g],this[y]=t[y].canvas},i.prototype.__applyStyleState=function(f){var g=Object.keys(f),y,p;for(y=0;y<g.length;y++)p=g[y],this[p]=f[p]},i.prototype.__getStyleState=function(){var f,g={},y=Object.keys(t),p;for(f=0;f<y.length;f++)p=y[f],g[p]=this[p];return g},i.prototype.__applyStyleToCurrentElement=function(f){var g=Object.keys(t),y,p,m,x,k,w;for(y=0;y<g.length;y++)if(p=t[g[y]],m=this[g[y]],p.apply)if(p.apply.indexOf("fill")!==-1&&m instanceof r){if(m.__ctx)for(;m.__ctx.__defs.childNodes.length;)x=m.__ctx.__defs.childNodes[0].getAttribute("id"),this.__ids[x]=x,this.__defs.appendChild(m.__ctx.__defs.childNodes[0]);this.__currentElement.setAttribute("fill",n("url(#{id})",{id:m.__root.getAttribute("id")}))}else p.apply.indexOf("fill")!==-1&&m instanceof s?this.__currentElement.setAttribute("fill",n("url(#{id})",{id:m.__root.getAttribute("id")})):p.apply.indexOf(f)!==-1&&p.svg!==m&&((p.svgAttr==="stroke"||p.svgAttr==="fill")&&m.indexOf("rgba")!==-1?(k=/rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d?\.?\d*)\s*\)/gi,w=k.exec(m),this.__currentElement.setAttribute(p.svgAttr,n("rgb({r},{g},{b})",{r:w[1],g:w[2],b:w[3]})),this.__currentElement.setAttribute(p.svgAttr+"-opacity",w[4])):this.__currentElement.setAttribute(p.svgAttr,m))},i.prototype.__closestGroupOrSvg=function(f){return f=f||this.__currentElement,f.nodeName==="g"||f.nodeName==="svg"?f:this.__closestGroupOrSvg(f.parentNode)},i.prototype.getSerializedSvg=function(f){var g=new XMLSerializer().serializeToString(this.__root),y,p,m,x,k,w;if(w=/xmlns="http:\/\/www\.w3\.org\/2000\/svg".+xmlns="http:\/\/www\.w3\.org\/2000\/svg/gi,w.test(g)&&(g=g.replace('xmlns="http://www.w3.org/2000/svg','xmlns:xlink="http://www.w3.org/1999/xlink')),f)for(y=Object.keys(a),p=0;p<y.length;p++)m=y[p],x=a[m],k=new RegExp(m,"gi"),k.test(g)&&(g=g.replace(k,x));return g},i.prototype.getSvg=function(){return this.__root},i.prototype.save=function(){var f=this.__createElement("g"),g=this.__closestGroupOrSvg();this.__groupStack.push(g),g.appendChild(f),this.__currentElement=f,this.__stack.push(this.__getStyleState())},i.prototype.restore=function(){this.__currentElement=this.__groupStack.pop();var f=this.__stack.pop();this.__applyStyleState(f)},i.prototype.__addTransform=function(f){var g=this.__closestGroupOrSvg();if(g.childNodes.length>0){var y=this.__createElement("g");g.appendChild(y),this.__currentElement=y}var p=this.__currentElement.getAttribute("transform");p?p+=" ":p="",p+=f,this.__currentElement.setAttribute("transform",p)},i.prototype.scale=function(f,g){g===void 0&&(g=f),this.__addTransform(n("scale({x},{y})",{x:f,y:g}))},i.prototype.rotate=function(f){var g=f*180/Math.PI;this.__addTransform(n("rotate({angle},{cx},{cy})",{angle:g,cx:0,cy:0}))},i.prototype.translate=function(f,g){this.__addTransform(n("translate({x},{y})",{x:f,y:g}))},i.prototype.transform=function(f,g,y,p,m,x){this.__addTransform(n("matrix({a},{b},{c},{d},{e},{f})",{a:f,b:g,c:y,d:p,e:m,f:x}))},i.prototype.beginPath=function(){var f,g;this.__currentDefaultPath="",this.__currentPosition={},f=this.__createElement("path",{},!0),g=this.__closestGroupOrSvg(),g.appendChild(f),this.__currentElement=f},i.prototype.__applyCurrentDefaultPath=function(){if(this.__currentElement.nodeName==="path"){var f=this.__currentDefaultPath;this.__currentElement.setAttribute("d",f)}else throw new Error("Attempted to apply path command to node "+this.__currentElement.nodeName)},i.prototype.__addPathCommand=function(f){this.__currentDefaultPath+=" ",this.__currentDefaultPath+=f},i.prototype.moveTo=function(f,g){this.__currentElement.nodeName!=="path"&&this.beginPath(),this.__currentPosition={x:f,y:g},this.__addPathCommand(n("M {x} {y}",{x:f,y:g}))},i.prototype.closePath=function(){this.__addPathCommand("Z")},i.prototype.lineTo=function(f,g){this.__currentPosition={x:f,y:g},this.__currentDefaultPath.indexOf("M")>-1?this.__addPathCommand(n("L {x} {y}",{x:f,y:g})):this.__addPathCommand(n("M {x} {y}",{x:f,y:g}))},i.prototype.bezierCurveTo=function(f,g,y,p,m,x){this.__currentPosition={x:m,y:x},this.__addPathCommand(n("C {cp1x} {cp1y} {cp2x} {cp2y} {x} {y}",{cp1x:f,cp1y:g,cp2x:y,cp2y:p,x:m,y:x}))},i.prototype.quadraticCurveTo=function(f,g,y,p){this.__currentPosition={x:y,y:p},this.__addPathCommand(n("Q {cpx} {cpy} {x} {y}",{cpx:f,cpy:g,x:y,y:p}))};var v=function(f){var g=Math.sqrt(f[0]*f[0]+f[1]*f[1]);return[f[0]/g,f[1]/g]};i.prototype.arcTo=function(f,g,y,p,m){var x=this.__currentPosition&&this.__currentPosition.x,k=this.__currentPosition&&this.__currentPosition.y;if(!(typeof x>"u"||typeof k>"u")){if(m<0)throw new Error("IndexSizeError: The radius provided ("+m+") is negative.");if(x===f&&k===g||f===y&&g===p||m===0){this.lineTo(f,g);return}var w=v([x-f,k-g]),C=v([y-f,p-g]);if(w[0]*C[1]===w[1]*C[0]){this.lineTo(f,g);return}var I=w[0]*C[0]+w[1]*C[1],_=Math.acos(Math.abs(I)),L=v([w[0]+C[0],w[1]+C[1]]),E=m/Math.sin(_/2),F=f+E*L[0],q=g+E*L[1],R=[-w[1],w[0]],A=[C[1],-C[0]],P=function($){var X=$[0],j=$[1];return j>=0?Math.acos(X):-Math.acos(X)},M=P(R),H=P(A);this.lineTo(F+R[0]*m,q+R[1]*m),this.arc(F,q,m,M,H)}},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(f,g,y,p){this.__currentElement.nodeName!=="path"&&this.beginPath(),this.moveTo(f,g),this.lineTo(f+y,g),this.lineTo(f+y,g+p),this.lineTo(f,g+p),this.lineTo(f,g),this.closePath()},i.prototype.fillRect=function(f,g,y,p){var m,x;m=this.__createElement("rect",{x:f,y:g,width:y,height:p},!0),x=this.__closestGroupOrSvg(),x.appendChild(m),this.__currentElement=m,this.__applyStyleToCurrentElement("fill")},i.prototype.strokeRect=function(f,g,y,p){var m,x;m=this.__createElement("rect",{x:f,y:g,width:y,height:p},!0),x=this.__closestGroupOrSvg(),x.appendChild(m),this.__currentElement=m,this.__applyStyleToCurrentElement("stroke")},i.prototype.clearRect=function(f,g,y,p){var m,x=this.__closestGroupOrSvg();m=this.__createElement("rect",{x:f,y:g,width:y,height:p,fill:"#FFFFFF"},!0),x.appendChild(m)},i.prototype.createLinearGradient=function(f,g,y,p){var m=this.__createElement("linearGradient",{id:c(this.__ids),x1:f+"px",x2:y+"px",y1:g+"px",y2:p+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(m),new s(m,this)},i.prototype.createRadialGradient=function(f,g,y,p,m,x){var k=this.__createElement("radialGradient",{id:c(this.__ids),cx:p+"px",cy:m+"px",r:x+"px",fx:f+"px",fy:g+"px",gradientUnits:"userSpaceOnUse"},!1);return this.__defs.appendChild(k),new s(k,this)},i.prototype.__parseFont=function(){var f=/^\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,g=f.exec(this.font),y={style:g[1]||"normal",size:g[4]||"10px",family:g[6]||"sans-serif",weight:g[3]||"normal",decoration:g[2]||"normal",href:null};return this.__fontUnderline==="underline"&&(y.decoration="underline"),this.__fontHref&&(y.href=this.__fontHref),y},i.prototype.__wrapTextLink=function(f,g){if(f.href){var y=this.__createElement("a");return y.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",f.href),y.appendChild(g),y}return g},i.prototype.__applyText=function(f,g,y,p){var m=this.__parseFont(),x=this.__closestGroupOrSvg(),k=this.__createElement("text",{"font-family":m.family,"font-size":m.size,"font-style":m.style,"font-weight":m.weight,"text-decoration":m.decoration,x:g,y,"text-anchor":u(this.textAlign),"dominant-baseline":h(this.textBaseline)},!0);k.appendChild(this.__document.createTextNode(f)),this.__currentElement=k,this.__applyStyleToCurrentElement(p),x.appendChild(this.__wrapTextLink(m,k))},i.prototype.fillText=function(f,g,y){this.__applyText(f,g,y,"fill")},i.prototype.strokeText=function(f,g,y){this.__applyText(f,g,y,"stroke")},i.prototype.measureText=function(f){return this.__ctx.font=this.font,this.__ctx.measureText(f)},i.prototype.arc=function(f,g,y,p,m,x){if(p!==m){p=p%(2*Math.PI),m=m%(2*Math.PI),p===m&&(m=(m+2*Math.PI-.001*(x?-1:1))%(2*Math.PI));var k=f+y*Math.cos(m),w=g+y*Math.sin(m),C=f+y*Math.cos(p),I=g+y*Math.sin(p),_=x?0:1,L=0,E=m-p;E<0&&(E+=2*Math.PI),x?L=E>Math.PI?0:1:L=E>Math.PI?1:0,this.lineTo(C,I),this.__addPathCommand(n("A {rx} {ry} {xAxisRotation} {largeArcFlag} {sweepFlag} {endX} {endY}",{rx:y,ry:y,xAxisRotation:0,largeArcFlag:L,sweepFlag:_,endX:k,endY:w})),this.__currentPosition={x:k,y:w}}},i.prototype.clip=function(){var f=this.__closestGroupOrSvg(),g=this.__createElement("clipPath"),y=c(this.__ids),p=this.__createElement("g");f.removeChild(this.__currentElement),g.setAttribute("id",y),g.appendChild(this.__currentElement),this.__defs.appendChild(g),f.setAttribute("clip-path",n("url(#{id})",{id:y})),f.appendChild(p),this.__currentElement=p},i.prototype.drawImage=function(){var f=Array.prototype.slice.call(arguments),g=f[0],y,p,m,x,k=0,w=0,C,I,_,L,E,F,q,R,A,P,M;if(f.length===3)y=f[1],p=f[2],C=g.width,I=g.height,m=C,x=I;else if(f.length===5)y=f[1],p=f[2],m=f[3],x=f[4],C=g.width,I=g.height;else if(f.length===9)k=f[1],w=f[2],C=f[3],I=f[4],y=f[5],p=f[6],m=f[7],x=f[8];else throw new Error("Inavlid number of arguments passed to drawImage: "+arguments.length);if(_=this.__closestGroupOrSvg(),q=this.__currentElement,g instanceof i){for(L=g.getSvg(),E=L.childNodes[0];E.childNodes.length;)M=E.childNodes[0].getAttribute("id"),this.__ids[M]=M,this.__defs.appendChild(E.childNodes[0]);F=L.childNodes[1],_.appendChild(F),this.__currentElement=F,this.translate(y,p),this.__currentElement=q}else(g.nodeName==="CANVAS"||g.nodeName==="IMG")&&(R=this.__createElement("image"),R.setAttribute("width",m),R.setAttribute("height",x),R.setAttribute("preserveAspectRatio","none"),(k||w||C!==g.width||I!==g.height)&&(A=this.__document.createElement("canvas"),A.width=m,A.height=x,P=A.getContext("2d"),P.drawImage(g,k,w,C,I,0,0,m,x),g=A),R.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",g.nodeName==="CANVAS"?g.toDataURL():g.getAttribute("src")),_.appendChild(R),this.__currentElement=R,this.translate(y,p),this.__currentElement=q)},i.prototype.createPattern=function(f,g){var y=this.__document.createElementNS("http://www.w3.org/2000/svg","pattern"),p=c(this.__ids),m;return y.setAttribute("id",p),y.setAttribute("width",f.width),y.setAttribute("height",f.height),f.nodeName==="CANVAS"||f.nodeName==="IMG"?(m=this.__document.createElementNS("http://www.w3.org/2000/svg","image"),m.setAttribute("width",f.width),m.setAttribute("height",f.height),m.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",f.nodeName==="CANVAS"?f.toDataURL():f.getAttribute("src")),y.appendChild(m),this.__defs.appendChild(y)):f instanceof i&&(y.appendChild(f.__root.childNodes[1]),this.__defs.appendChild(y)),new r(y,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})()})(canvas2svg);var canvas2svgExports=canvas2svg.exports;const C2S=getDefaultExportFromCjs(canvas2svgExports);function activityFinal(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 swimlaneH(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n,ey:c}=e.calculative.worldRect,l=e.calculative.lineLeft||.08;let u=e.calculative.borderRadius||0,h=u;u<1&&(u=a*u,h=n*u);let v=u<h?u:h;if(a<2*v&&(v=a/2),n<2*v&&(v=n/2),i.moveTo(s+v,r),i.arcTo(s+a,r,s+a,r+n,v),i.arcTo(s+a,r+n,s,r+n,v),i.arcTo(s,r+n,s,r,v),i.arcTo(s,r,s+a,r,v),i.closePath(),i.moveTo(s+l*a,r),i.lineTo(s+l*a,c),i instanceof Path2D)return i}function swimlaneV(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n,ex:c}=e.calculative.worldRect,l=e.calculative.lineTop||.08;let u=e.calculative.borderRadius||0,h=u;u<1&&(u=a*u,h=n*h);let v=u<h?u:h;if(a<2*v&&(v=a/2),n<2*v&&(v=n/2),i.moveTo(s+v,r),i.arcTo(s+a,r,s+a,r+n,v),i.arcTo(s+a,r+n,s,r+n,v),i.arcTo(s,r+n,s,r,v),i.arcTo(s,r,s+a,r,v),i.closePath(),i.moveTo(s,r+l*n),i.lineTo(c,r+l*n),i instanceof Path2D)return i}function activityDiagram(){return{forkV:rectangle,forkH:rectangle,swimlaneH,swimlaneV}}function activityDiagramByCtx(){return{activityFinal}}const eventNameMap={enter:"mouseover",leave:"mouseout"};var ReplaceMode$2;(function(e){e[e.Add=0]="Add",e[e.Replace=1]="Replace",e[e.ReplaceAll=2]="ReplaceAll"})(ReplaceMode$2||(ReplaceMode$2={}));let keyWords=["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 funKeyWords=["formatter","color"];function echarts(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{}keyWords=((r=e.calculative.canvas.store.options.diagramOptions.chart)==null?void 0:r.keyWords)||keyWords,e.onDestroy||(e.onDestroy=destory,e.onMove=move,e.onResize=resize,e.onRotate=move,e.onValue=value,e.onBeforeValue=beforeValue$5,e.onBinds=binds,e.onMouseEnter=move,e.onRenderPenRaw=onRenderPenRaw,e.onScale=scale),e.calculative.singleton||(e.calculative.singleton={});const i=new Path2D,s=e.calculative.worldRect;if(!e.calculative.singleton.div){const n=document.createElement("div");n.style.position="absolute",n.style.outline="none",n.style.left="-9999px",n.style.top="-9999px",n.style.width=s.width+"px",n.style.height=s.height+"px",document.body.appendChild(n),(a=e.calculative.canvas.externalElements)==null||a.parentElement.appendChild(n),setElemPosition(e,n),e.calculative.singleton.div=n,e.calculative.singleton.echart=t.init(n,e.echarts.theme),initEvent(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(c=>{c.text().then(l=>{if(typeof l=="string")try{l=JSON.parse(l)}catch{}if(l.constructor!==Object&&l.constructor!==Array){console.warn("Invalid data:",l);return}t.registerMap(e.echarts.geoName,l),e.calculative.singleton.echartsReady=!0,e.calculative.singleton.echart.setOption(updateOption(e.echarts.option,e.calculative.canvas.store.data.scale),!0),e.calculative.singleton.echart.resize(),setTimeout(()=>{onRenderPenRaw(e)},300)})}))),e.calculative.singleton.echartsReady&&setTimeout(()=>{var c;e.echarts.initJs?new Function("myChart","context",`return async function () { ${e.echarts.initJs}}`)(e.calculative.singleton.echart,{meta2d:this,pen:e})().then(u=>{if(u){e.calculative.singleton.echart.setOption(u,!0);let h=e.calculative.singleton.echart.getOption();e.echarts.option=h}}):(c=e.calculative.singleton.echart)==null||c.setOption(updateOption(e.echarts.option,e.calculative.canvas.store.data.scale),!0),setTimeout(()=>onRenderPenRaw(e),300)})}return i}function initEvent(e){var s;const t=e.calculative.singleton.echart,i=["click","dblclick","mousedown","mousemove","mouseup","mouseover","mouseout","globalout","contextmenu"];i.forEach(r=>{let a=eventNameMap[r]||r;t.getZr().off(a)}),(s=e.events)==null||s.forEach(r=>{r.actions&&r.actions.length&&i.includes(eventNameMap[r.name]||r.name)&&t.getZr().on(eventNameMap[r.name]||r.name,a=>{let n=!1;r.conditions&&r.conditions.length?r.conditionType==="and"?n=r.conditions.every(c=>e.calculative.canvas.parent.judgeCondition(e,c.key,c)):r.conditionType==="or"&&(n=r.conditions.some(c=>e.calculative.canvas.parent.judgeCondition(e,c.key,c))):n=!0,n&&r.actions.forEach(c=>{if(c.timeout){let l=setTimeout(()=>{e.calculative.canvas.parent.events[c.action]&&(e.calculative.canvas.parent.events[c.action](e,c,a),clearTimeout(l),l=null)},c.timeout)}else e.calculative.canvas.parent.events[c.action]&&e.calculative.canvas.parent.events[c.action](e,c,a)})})})}function destory(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 move(e){e.calculative.singleton.div&&setElemPosition(e,e.calculative.singleton.div)}function resize(e){e.debounceTime?(e.resizeFn||(e.resizeFn=resizeFn,e.debounceResize=InstanceDebouncer.debounce(e,"resizeFn",e.debounceTime)),e.debounceResize(e)):resizeFn(e)}function resizeFn(e){var t;move(e),(t=e.calculative.singleton)!=null&&t.echart&&e.calculative.singleton.echart.resize()}function scale(e){e.debounceTime?(e.scaleFn||(e.scaleFn=scaleFn,e.debounceScale=InstanceDebouncer.debounce(e,"scaleFn",e.debounceTime)),e.debounceScale(e)):scaleFn(e)}function scaleFn(e){var i,s;if(!e.calculative.singleton.echart)return;let t=globalThis.echarts;if(setElemPosition(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((n,c)=>{a[c]&&(n.start=a[c].start,n.end=a[c].end)})}}e.calculative.singleton.echart.setOption(updateOption(e.echarts.option,e.calculative.canvas.store.data.scale),!0)}e.calculative.singleton.echart.resize()}}function value(e){var t,i;if(e.calculative.singleton.echart&&(setElemPosition(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)?e.calculative.singleton.echart.setOption(deepClone(s),{replaceMerge:e.echarts.replaceMerge}):e.calculative.singleton.echart.setOption(deepClone(s))}else e.calculative.singleton.echart.setOption(updateOption(e.echarts.option,e.calculative.canvas.store.data.scale),!0)}function beforeValue$5(e,t){if(e.calculative.partialOption=null,t.echarts){let y=globalThis.echarts;return t.echarts.geoName&&!y.getMap(t.echarts.geoName)&&(t.echarts.geoJson?y.registerMap(t.echarts.geoName,t.echarts.geoJson):t.echarts.geoUrl&&(e.calculative.singleton.echartsReady=!1,fetch(t.echarts.geoUrl).then(p=>{p.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 y.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=formatData(e,t));let y=Object.keys(t);const{xAxis:p,yAxis:m}=e.echarts.option,{max:x,replaceMode:k,timeFormat:w,autoGetTime:C=!0}=e.echarts;let I=[],_=!1,L=e.realTimes.filter(E=>E.bind&&E.bind.class==="iot"&&E.bind.compute_name);if(L.length&&L.find(F=>y.includes(F.key))){let F={},q=[];for(let R in t)R.includes("echarts.option.series")&&(F[R]=Object.fromEntries(t[R]),q.push(...Object.keys(F[R])));q=[...new Set(q)].sort((R,A)=>R-A);for(let R in t)R.includes("echarts.option.series")&&(F[R]=q.map(A=>F[R][A]));return(q[0]+"").length===19&&(q=q.map(R=>R/1e6)),q=q.map(R=>formatTime(w||"`${year}:${month}:${day} ${hours}:${minutes}:${seconds}`",R)),F["echarts.option.xAxis.data"]=q,F}for(let E in t)if(E.includes("echarts.option")){_=!0,E.includes("series.links.")&&(_=!1);let F=getter(e,E);if(Array.isArray(F)&&k===ReplaceMode$2.Add&&(F.push(t[E]),x&&F.splice(0,F.length-x),t[E]=F,C&&!y.includes("echarts.option.xAxis.data"))){let q="echarts.option.xAxis.data";if(!t[q]){Array.isArray(p)&&p.length&&(q="echarts.option.xAxis.0.data");let R=getter(e,q),A=formatTime(w||"`${hours}:${minutes}:${seconds}`");R.push(A),x&&R.splice(0,R.length-x),t[q]=R}}if(E.includes(".data.")){let q=E.substring(0,E.indexOf(".data.")+5);I.includes(q)||I.push(q)}}if(_){const E=deepClone(t);e.calculative.partialOption=dotNotationToObject(E,e),I.forEach(F=>{let q=getter(e,F);setter(e.calculative.partialOption,F,q)})}return t}if(!t.dataX&&!t.dataY)return t;const i=e.echarts,{max:s,replaceMode:r}=i;let a=t.dataX,n=t.dataY,c=[];n&&c.push("echarts.option.series");const l=i.option.series,u=l.length,{xAxis:h,yAxis:v}=i.option;Array.isArray(h)&&h.length>1&&console.warn("echarts 只支持单 x 轴,多 x 轴将被忽略");const f=Array.isArray(h)?h[0]:h,g=Array.isArray(v)?v[0]:v;if(r)if(r===ReplaceMode$2.Replace){if(!f&&!g)n&&(u===1?(!Array.isArray(n)&&(n=[n]),n.forEach((y,p)=>{const m=l[0].data.find(x=>x.name===y.name);m&&(m.value=y.value)})):l.forEach((y,p)=>{Array.isArray(n[p])||(n[p]=[n[p]]),n[p].forEach((m,x)=>{const k=y.data.find(w=>w.name===m.name);k&&(k.value=m.value)})}));else if((f.type==="category"||g.type==="category")&&a&&n){const y=f.type==="category"?f.data:g.data;!Array.isArray(a)&&(a=[a]),!Array.isArray(n)&&(n=[n]),f.type==="category"?c.push("echarts.option.xAxis"):c.push("echarts.option.yAxis"),u===1?n.forEach((p,m)=>{const x=y.indexOf(a[m]);l[0].data[x]=p}):l.forEach((p,m)=>{n[m].forEach((x,k)=>{const w=y.indexOf(a[k]);p.data[w]=x})})}}else r===ReplaceMode$2.ReplaceAll&&(a&&(f.data=a,f.data.splice(0,f.data.length-s),c.push("echarts.option.xAxis")),n&&(u===1?(l[0].data=n,l[0].data.splice(0,l[0].data.length-s)):l.forEach((y,p)=>{y.data=n[p],y.data.splice(0,y.data.length-s)})));else{if(a){!Array.isArray(a)&&(a=[a]);const y=f.data;y.push(...a),y.splice(0,y.length-s),c.push("echarts.option.xAxis")}if(n)if(u===1){!Array.isArray(n)&&(n=[n]);const y=l[0].data;y.push(...n),y.splice(0,y.length-s)}else l.forEach((y,p)=>{Array.isArray(n[p])||(n[p]=[n[p]]);const m=y.data;m.push(...n[p]),m.splice(0,m.length-s)})}return e.calculative.partialOption={},c.forEach(y=>{let p=getter(e,y);setter(e.calculative.partialOption,y,p)}),delete t.dataX,delete t.dataY,Object.assign(t,{echarts:i})}function formatData(e,t){var i,s;if(!e.echarts.dataMap||!t.data)return t;if(t.data){let r={};if(Array.isArray(t.data))for(const a in e.echarts.dataMap)e.echarts.dataMap.hasOwnProperty(a)&&((i=e.echarts.timeKeys)!=null&&i.length&&e.echarts.timeKeys.includes(e.echarts.dataMap[a])?r[a]=t.data.map(n=>formatTime(e.echarts.timeFormat,n[e.echarts.dataMap[a]])):r[a]=t.data.map(n=>n[e.echarts.dataMap[a]]));else for(const a in e.echarts.dataMap)e.echarts.dataMap.hasOwnProperty(a)&&((s=e.echarts.timeKeys)!=null&&s.length&&e.echarts.timeKeys.includes(e.echarts.dataMap[a])?r[a]=formatTime(e.echarts.timeFormat,t.data[e.echarts.dataMap[a]]):r[a]=t.data[e.echarts.dataMap[a]]);return delete t.data,Object.assign(t,r),t}}function binds(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 n=Array.isArray(r)?r[0]:r,c=Array.isArray(a)?a[0]:a,l=s.option.series;if(!n&&!c){const u=[];if(Array.isArray(l)&&l.length===1)return l[0].data.forEach(h=>{const{dataId:v}=i.dataIds.find(f=>f.name===h.name);if(v){const f=t.find(g=>g.dataId===v);f&&u.push({name:h.name,value:f.value})}}),{id:e.id,dataY:u}}else if(n.type==="category"||c.type==="category"){const u=[],h=[],v=n.type==="category"?n.data:c.data;return v==null||v.forEach(f=>{const{dataId:g}=i.dataIds.find(y=>y.name===f);if(g){const y=t.find(p=>p.dataId===g);y&&(h.push(f),u.push(y.value))}}),{id:e.id,dataY:u,dataX:h}}else if(n.type==="time"){const u=[],h=+new Date;let v=!1;if(l.forEach((f,g)=>{const y=[],{dataId:p}=i.dataIds.find(m=>m.name===f.name);if(p){const m=t.find(x=>x.dataId===p);m&&(y.push([h,m.value]),v=!0)}u[g]=y}),v)u.forEach((f,g)=>{if(!f||f.length===0){const y=l[g].data[l[g].data.length-1];u[g]=[[h,y[1]]]}});else return;return{id:e.id,dataY:u.length===1?u[0]:u}}}function onRenderPenRaw(e){var i,s;const t=new Image;t.src=(s=(i=e.calculative.singleton)==null?void 0:i.echart)==null?void 0:s.getDataURL({pixelRatio:2}),e.calculative.img=t}function updateOption(e,t){const i=deepClone(e);if(i.dataZoom){let s=["right","top","width","height","left","bottom"];for(let r=0;r<s.length;r++)i.dataZoom.forEach(a=>{isNaN(a[s[r]])||(a[s[r]]*=t)})}return deepSetValue(i,keyWords,t),deepNewFunction(i,funKeyWords),i}function dotNotationToObject(e,t){const i={};return Object.keys(e).forEach(s=>{const r=s.split(".");let a=i;r.forEach((n,c)=>{const l=!isNaN(parseInt(n));if(c===6){let u=r.slice(0,7).join(".");setter(t,s,e[s]);let h=getter(t,u);a[r[c]]=h}else{if(c>6)return;if(c===r.length-1)l?(Array.isArray(a)||(a=[]),a[parseInt(n)]=e[s]):a[n]=e[s];else if(l){const u=parseInt(n);if(Array.isArray(a)||a[r[c-1]],a[u]||(a[u]={}),Array.isArray(a))for(let h=0;h<parseInt(n);h++)a[h]||(a[h]={});a=a[u]}else a[n]||(["series","yAxis","xAxis"].includes(n)&&!isNaN(parseInt(r[c+1]))?a[n]=[]:a[n]={}),a=a[n]}})}),i}function isFunctionString(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 deepNewFunction(o,keyWords){if(Array.isArray(o)){const e=[];return o.forEach(t=>{e.push(deepNewFunction(t,keyWords))}),e}else if(typeof o=="object"){if(o===null)return null;for(const key in o)keyWords.includes(key)?isFunctionString(o[key])&&(o[key]=eval("("+o[key]+")")):o[key]=deepNewFunction(o[key],keyWords);return o}return o}function register(e){register$1({echarts})}function interfaceClass(e,t){e.onDestroy||(e.onDestroy=onDestroy$3,e.onAdd=onAdd$4);const i=t||new Path2D,{x:s,y:r,width:a,height:n,ex:c}=e.calculative.worldRect;let l=e.calculative.borderRadius||0,u=l;l<1&&(l*=a,u*=n);let h=l<u?l:u;a<2*h&&(h=a/2),n<2*h&&(h=n/2),i.moveTo(s+h,r),i.arcTo(s+a,r,s+a,r+n,h),i.arcTo(s+a,r+n,s,r+n,h),i.arcTo(s,r+n,s,r,h),i.arcTo(s,r,s+a,r,h);const v=.2*n;i.moveTo(s,r+v),i.lineTo(c,r+v);const f=r+v+(n-v)/2;if(i.moveTo(s,f),i.lineTo(c,f),i.closePath(),i instanceof Path2D)return i}function onAdd$4(e){const{x:t,y:i,width:s,height:r}=e.calculative.worldRect,a=e.list,n={name:"text",x:t,y:i+.2*r,width:s,height:.4*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10},c={name:"text",x:t,y:i+.6*r,width:s,height:.4*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10};Object.assign(n,a[0]),Object.assign(c,a[1]),e.calculative.canvas.makePen(n),e.calculative.canvas.makePen(c),e.calculative.canvas.parent.pushChildren(e,[n]),e.calculative.canvas.parent.pushChildren(e,[c])}function onDestroy$3(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 simpleClass(e,t){e.onDestroy||(e.onDestroy=onDestroy$2,e.onAdd=onAdd$3);const i=t||new Path2D,{x:s,y:r,width:a,height:n,ex:c}=e.calculative.worldRect;let l=e.calculative.borderRadius||0,u=l;l<1&&(l=a*l,u=n*u);let h=l<u?l:u;a<2*h&&(h=a/2),n<2*h&&(h=n/2),i.moveTo(s+h,r),i.arcTo(s+a,r,s+a,r+n,h),i.lineTo(s+a,r+n-h),i.arcTo(s+a,r+n,s,r+n,h),i.arcTo(s,r+n,s,r,h),i.arcTo(s,r,s+a,r,h);const v=.2*n;if(i.moveTo(s,r+v),i.lineTo(c,r+v),i.closePath(),i instanceof Path2D)return i}function onAdd$3(e){const{x:t,y:i,width:s,height:r}=e.calculative.worldRect,a=e.list;let n={name:"text",x:t,y:i+.2*r,width:s,height:.8*r,textAlign:"left",textBaseline:"top",textLeft:10,textTop:10};Object.assign(n,a[0]),e.calculative.canvas.makePen(n),e.calculative.canvas.parent.pushChildren(e,[n])}function onDestroy$2(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 classPens(){return{interfaceClass,simpleClass}}function flowComment(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ey:n}=e.calculative.worldRect,c=a/4;if(i.moveTo(s+c,r),i.lineTo(s,r),i.lineTo(s,n),i.lineTo(s+c,n),i instanceof Path2D)return i}function flowCommentAnchors(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 flowData(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:n,ey:c}=e.calculative.worldRect,l=e.offsetX;let u=a/7;if(l>1?u=l:l>0&&(u=a*l),i.moveTo(s+u,r),i.lineTo(n,r),i.lineTo(s+a-u,c),i.lineTo(s,c),i.closePath(),i instanceof Path2D)return i}function flowDataAnchors(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 flowDisplay(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n,ex:c,ey:l}=e.calculative.worldRect,u=a/8;if(i.moveTo(s+u,r),i.lineTo(c-u,r),i.bezierCurveTo(c+u/3,r,c+u/3,l,c-u,l),i.lineTo(s+u,l),i.lineTo(s,r+n/2),i.closePath(),i instanceof Path2D)return i}function flowDocument(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n,ex:c,center:l}=e.calculative.worldRect,u=l.x,h=r+n*6/7,v=n/6;if(i.moveTo(s,r),i.lineTo(c,r),i.lineTo(c,h),i.bezierCurveTo(c-20,h-v,u+a/5,h-v,u,h),i.bezierCurveTo(u-a/5,h+v,s,h+v,s,h),i.closePath(),i instanceof Path2D)return i}function flowDocumentAnchors(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 flowExternStorage(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:n,ey:c}=e.calculative.worldRect,l=a/10;if(i.moveTo(s+l*2,r),i.bezierCurveTo(s-l*2/3,r,s-l*2/3,c,s+l*2,c),i.lineTo(n,c),i.bezierCurveTo(n-l,c,n-l,r,n,r),i.closePath(),i instanceof Path2D)return i}function flowInternalStorage(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:n,ey:c}=e.calculative.worldRect;i.moveTo(s,r),i.lineTo(n,r),i.lineTo(n,c),i.lineTo(s,c),i.closePath();const l=a/7;if(i.moveTo(s,r+l),i.lineTo(n,r+l),i.moveTo(s+l,r),i.lineTo(s+l,c),i instanceof Path2D)return i}function flowManually(e,t){const i=t||new Path2D,{x:s,y:r,height:a,ex:n,ey:c}=e.calculative.worldRect,l=a/4;if(i.moveTo(s,r+l),i.lineTo(n,r),i.lineTo(n,c),i.lineTo(s,c),i.closePath(),i instanceof Path2D)return i}function flowManuallyAnchors(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 flowParallel(e,t){const i=t||new Path2D,{x:s,y:r,ex:a,ey:n}=e.calculative.worldRect;if(i.moveTo(s,r),i.lineTo(a,r),i.moveTo(s,n),i.lineTo(a,n),i instanceof Path2D)return i}function flowParallelAnchors(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 flowQueue(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n,ex:c,ey:l}=e.calculative.worldRect;if(i.ellipse(s+a/2,r+n/2,a/2,n/2,0,0,Math.PI*2),i.moveTo(s+a/2,l),i.lineTo(c,l),i.closePath(),i instanceof Path2D)return i}function flowSubprocess(e,t){const i=t||new Path2D,{x:s,y:r,width:a,ex:n,ey:c}=e.calculative.worldRect,l=a/7;if(i.moveTo(s,r),i.lineTo(n,r),i.lineTo(n,c),i.lineTo(s,c),i.closePath(),i.moveTo(s+l,r),i.lineTo(s+l,c),i.moveTo(n-l,r),i.lineTo(n-l,c),i instanceof Path2D)return i}function flowDb(e,t){const i=t||new Path2D,{x:s,y:r,height:a,ex:n,ey:c}=e.calculative.worldRect,l=a/7;if(i.moveTo(s,r+l),i.bezierCurveTo(s,r-l/2|0,n,r-l/2|0,n,r+l),i.lineTo(n,c-l),i.bezierCurveTo(n,c+l/2|0,s,c+l/2|0,s,c-l),i.closePath(),i.moveTo(s,c-l),i.bezierCurveTo(s,c-l*2|0,n,c-l*2|0,n,c-l),i instanceof Path2D)return i}function flowPens(){return{flowComment,flowData,flowDb,flowDisplay,flowDocument,flowExternStorage,flowInternalStorage,flowManually,flowParallel,flowQueue,flowSubprocess}}function flowAnchors(){return{flowDocument:flowDocumentAnchors,flowManually:flowManuallyAnchors,flowParallel:flowParallelAnchors,flowComment:flowCommentAnchors,flowData:flowDataAnchors}}var ReplaceMode$1;(function(e){e[e.Add=0]="Add",e[e.Replace=1]="Replace",e[e.ReplaceAll=2]="ReplaceAll"})(ReplaceMode$1||(ReplaceMode$1={}));function getTextLength(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 initOptions(e){if(e.direction=="horizontal"){const t=[];let i=0;const s=e.height;e.checkboxHeight=s,e.options.forEach((a,n)=>{t.push(n*(40+s)+i),i+=getTextLength(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}},calcRightBottom(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}},calcRightBottom(e.calculative.worldRect))}}function table2(e,t){t.onAdd||(t.onAdd=onAdd$2,(!t.rowPos||!t.colPos||!t.calculative.maxOffsetY)&&t.onAdd(t),t.onMouseMove=onMouseMove,t.onMouseLeave=onMouseLeave,t.onMouseDown=onMouseDown,t.onShowInput=onShowInput,t.onInput=onInput,t.onValue=onValue$2,t.onBeforeValue=beforeValue$4,t.onMouseEnter=onMouseEnter,t.onWheel=onWheel,t.onDestroy=onDestroy$1),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:n}=t.calculative.worldRect;e.fillStyle="#fff0",e.rect(s-1,r-1,a+2,n+2),e.fill(),e.clip()}drawGridLine(e,t),drawCell(e,t),drawNote(e,t),e.restore(),t.isFirstTime=!1}function drawNote(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:n,y:c}=t.calculative.canvas.mousePos;if(!t.data[r])return;let l=t.data[r][a];if(typeof l=="object"||!l)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 u=e.measureText(l).width;e.beginPath(),e.fillStyle="#fff",e.strokeStyle="#000",e.moveTo(n,c),e.rect(n-10,c,u+20,20),e.fill(),e.stroke(),e.beginPath(),e.fillStyle="#000",e.fillText(l,n,c+10),e.restore()}function initRect$1(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(m=>m.col!==void 0&&m.row===void 0&&m.width);let n={};a&&a.forEach(m=>{n[m.col]=m.width});for(let m=0;m<e.data[0].length;m++){r+=(n[m]||e.colWidth)*e.calculative.canvas.store.data.scale,t.push(r);let x=e.styles&&e.styles.filter(k=>k.col===m&&k.row===void 0);x&&(s[m]=x[0])}let c=0;const l=e.styles&&e.styles.filter(m=>m.col===void 0&&m.row!==void 0&&m.height);let u={};l&&l.forEach(m=>{u[m.row]=m.height});let h=c;for(let m=0;m<e.data.length;m++)c+=(u[m]||e.rowHeight)*e.calculative.canvas.store.data.scale,i.push(c),m<e.maxNum&&(h=c);if(e.calculative.maxOffsetY=(c-h)/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=h||c;let v=h||c,f=r,g=v;e.parentId&&(r=f/e.calculative.canvas.parent.store.pens[e.parentId].calculative.worldRect.width,g=v/e.calculative.canvas.parent.store.pens[e.parentId].calculative.worldRect.height),e.calculative.width=r,e.calculative.height=g,e.calculative.width=r,e.calculative.height=g,e.height||(e.height=e.calculative.height),e.width||(e.width=e.calculative.width);let y=e.x,p=e.y;if(e.parentId){let m=e.calculative.canvas.store.pens[e.parentId];y=m.calculative.worldRect.x+m.calculative.worldRect.width*e.x,p=m.calculative.worldRect.y+m.calculative.worldRect.height*e.y}e.calculative.worldRect={x:y,y:p,height:v,width:f},e.width=e.calculative.width,e.height=e.calculative.height,e.initWorldRect||(e.initWorldRect={width:e.calculative.worldRect.width,height:e.calculative.worldRect.height}),calcRightBottom(e.calculative.worldRect)}function drawGridLine(e,t){if(!t.colPos)return;const{x:i,y:s,width:r,height:a,ex:n,ey:c}=t.calculative.worldRect;e.save(),e.beginPath(),e.strokeStyle=t.color;let l=t.calculative.borderRadius||0,u=l;l<1&&(l=r*l,u=a*u);let h=l<u?l:u;if(r<2*h&&(h=r/2),a<2*h&&(h=a/2),e.moveTo(i+h,s),e.arcTo(n,s,n,c,h),e.arcTo(n,c,i,c,h),e.arcTo(i,c,i,s,h),e.arcTo(i,s,n,s,h),t.background&&(e.fillStyle=t.background,e.fill()),t.bordered!==!1&&(e.strokeStyle=t.borderColor||t.color||"#424B61",e.stroke()),t.hLine!==!1){let v=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 f of t.rowPos){if(f===v)continue;const g=f*t.calculative.worldRect.height/t.tableHeight-t.offsetY*t.calculative.canvas.store.data.scale;if(t.hasHeader){if(g<0+t.rowPos[0]||g>t.calculative.worldRect.height)continue}else if(g<0||g>t.calculative.worldRect.height)continue;e.beginPath(),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y+g),e.lineTo(t.calculative.worldRect.ex,t.calculative.worldRect.y+g),e.strokeStyle=t.borderColor||t.color||"#424B61",e.stroke()}}if(t.vLine!==!1){let v=t.colPos[t.colPos.length-1];t.colPos.forEach((f,g)=>{if(f===v)return;const y=f*t.calculative.worldRect.width/t.tableWidth;e.beginPath(),e.moveTo(t.calculative.worldRect.x+y,t.calculative.worldRect.y),e.lineTo(t.calculative.worldRect.x+y,t.calculative.worldRect.ey),e.strokeStyle=t.borderColor||t.color||"#424B61",e.stroke()})}e.restore()}function drawCell(e,t){var s,r,a,n,c;if(!t.colPos)return;t.calculative.texts||(t.calculative.texts=[]);const i=1;for(let l=0;l<t.rowPos.length;l++){if(t.hasHeader&&l===1){e.save(),e.beginPath();const{x:h,y:v,width:f,height:g}=t.calculative.worldRect;e.fillStyle="#fff0",e.rect(h-1,v+t.rowPos[0]*t.calculative.worldRect.height/t.tableHeight-1,f+2,g-t.rowPos[0]*t.calculative.worldRect.height/t.tableHeight+2),e.fill(),e.clip()}let{style:u}=getRow(t,l);for(let h=0;h<t.colPos.length;h++){let{value:v,style:f}=getCell(t,l,h),g=!0;if(Array.isArray(f)&&f.length>0){let E=0;f.forEach((F,q)=>{F.wheres&&F.wheres.every(A=>{let P=new Function("attr",`return attr ${A.comparison} ${A.value}`);const M=P(v);return P=null,M})&&(E=q)}),f=f[E]}else f.wheres&&Array.isArray(f.wheres)&&(g=!1,g=f.wheres.every(function(E){let F=new Function("attr",`return attr ${E.comparison} ${E.value}`);const q=F(v);return F=null,q}));let y=t.color,p=t.textColor||t.color,m=null,x=null,k=null,w=null;g&&(y=f.color||u.color||t.color,p=f.textColor||u.textColor||t.textColor,m=f.background||u.background,x=(f.fontSize||u.fontSize||0)*t.calculative.canvas.store.data.scale,k=f.fontWeight||u.fontWeight,w=f.fontStyle||u.fontStyle);let C;t.stripe&&(t.hasHeader!==!1?l%2===1&&(m=m||t.stripeColor||"#407FFF1F"):l%2===0&&(m=m||t.stripeColor||"#407FFF1F")),t.calculative.active&&((s=t.calculative.activeCell)==null?void 0:s.row)===l&&((r=t.calculative.activeCell)==null?void 0:r.col)===h&&(y=t.activeColor,m=t.activeBackground,C=y,p=t.activeTextColor||t.activeColor),t.calculative.hover&&((a=t.calculative.hoverCell)==null?void 0:a.row)===l&&((n=t.calculative.hoverCell)==null?void 0:n.col)===h&&(y=t.hoverColor,m=t.hoverBackground,p=t.hoverTextColor||t.hoverColor,C=y);const I=getCellRect(t,l,h);if(I.y+I.height<t.calculative.worldRect.y||I.y>t.calculative.worldRect.height+t.calculative.worldRect.y)continue;m&&(e.save(),e.beginPath(),e.fillStyle=m,e.fillRect(I.x,I.y,I.width+.25*t.calculative.canvas.store.data.scale,I.height),e.restore()),C&&(e.save(),e.beginPath(),e.strokeStyle=C,e.strokeRect(I.x,I.y,I.width,I.height),e.restore()),t.calculative.worldTextRect=I;let _=t.calculative.texts[l];if(t.calculative.texts[l]||(_=[],t.calculative.texts.push(_)),_[h]==null){if(typeof v=="object"){const E=t.styles&&t.styles.filter(F=>F.col===h&&F.row===void 0&&F.pens);if(E.length>0){if(_[h]="",t.isFirstTime){t.maxNum&&t.hasHeader&&l>=t.maxNum&&(v.visible=!1);let F=JSON.parse(JSON.stringify(E[0].pens));F.forEach(q=>{Object.assign(q,{row:l,col:h},v),q.activeBackground=q.background,q.hoverBackground=q.background,q.activeColor=q.color,q.hoverColor=q.color,q.activeTextColor=q.textColor,q.hoverTextColor=q.textColor,q.height*=t.calculative.canvas.store.data.scale,q.width*=t.calculative.canvas.store.data.scale}),calcChildrenRect(t,I,F),t.calculative.canvas.parent.pushChildren(t,F)}continue}}else v===void 0?_[h]="":_[h]=v.text||v+"";if(!_[h])continue;_[h]=calcTextLines(t,_[h])}if(!_[h])continue;e.save(),e.beginPath(),e.fillStyle=p,e.textAlign="center",e.textBaseline="middle",e.font=(w||t.calculative.fontStyle||"")+" normal "+(k||t.calculative.fontWeight||"")+" "+(x||t.calculative.fontSize||12)*i+"px "+t.calculative.fontFamily;let L=t.colStyle&&((c=t.colStyle[h])==null?void 0:c.textAlign);if(L&&(e.textAlign=L),_[h].length===1)L==="left"?e.fillText(_[h][0],I.x,I.y+I.height/2):L==="right"?e.fillText(_[h][0],I.x+I.width,I.y+I.height/2):e.fillText(_[h][0],I.x+I.width/2,I.y+I.height/2);else{const F=(x||t.calculative.fontSize)*t.calculative.lineHeight*i,q=_[h].length*F;let R=(I.height-q)/2;L==="left"?_[h].forEach((A,P)=>{e.fillText(A,I.x,I.y+R+(P+.55)*F)}):L==="right"?_[h].forEach((A,P)=>{e.fillText(A,I.x+I.width,I.y+R+(P+.55)*F)}):_[h].forEach((A,P)=>{e.fillText(A,I.x+I.width/2,I.y+R+(P+.55)*F)})}e.restore()}}}function onAdd$2(e){var t;createInterval(e),(t=e.children)!=null&&t.length||(e.isFirstTime=!0),e.offsetY||(e.offsetY=0),initRect$1(e)}function onShowInput(e,t){if(!e.calculative.hoverCell)return;const{value:i}=getCell(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=getCellRect(e,e.calculative.hoverCell.row,e.calculative.hoverCell.col);e.calculative.tempText=i.text||i+"",e.calculative.canvas.showInput(e,s,"#ffffff")}function onInput(e,t){e.calculative.inputCell&&(setCellText(e,e.calculative.inputCell.row,e.calculative.inputCell.col,t),e.calculative.isInput=!1,e.calculative.isHover=!0,e.calculative.canvas.render())}function onMouseMove(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=getCellIndex(e,t),e.calculative.canvas.render()}function onMouseLeave(e,t){createInterval(e),e.calculative.hoverCell=void 0,e.calculative.canvas.render()}function onMouseDown(e,t){e.calculative.activeCell=getCellIndex(e,t),e.calculative.canvas.render()}function getCellIndex(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 getCell(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 getRow(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 setCellText(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 getCellRect(e,t,i){const s=e.calculative.worldRect.width/e.tableWidth,r=e.calculative.worldRect.height/e.tableHeight;let a=0,n=e.colPos[i]*s;i>0&&(a=e.colPos[i-1]*s);let c=0,l=e.rowPos[t]*r;t>0&&(c=e.rowPos[t-1]*r);let u=e.offsetY*e.calculative.canvas.store.data.scale;return t===0&&e.hasHeader&&(u=0),{x:e.calculative.worldRect.x+a,y:e.calculative.worldRect.y+c-u,ex:e.calculative.worldRect.x+n,ey:e.calculative.worldRect.y+l-u,width:n-a,height:l-c}}function calcChildrenRect(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,n=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&&(n=e.calculative.worldRect.height/e.initWorldRect.height));let c=0,l=0,u=0;const h=e.calculative.canvas.store.data.scale;if(i.length>1){for(const v of i)l+v.width*s+20*h*s<t.width?(v.x=t.x+l+10*h*s,v.y=t.y+u+10*h*r,l+=(v.width+10*h)*s,c=Math.max(c,u+(v.height+10*h)*r)):(l=0,u=c,v.x=t.x+l+10*h*s,v.y=t.y+u+10*h*r,c+=(v.height+10*h)*r);if(c+20*h*r<t.height){const v=(t.height-c-10*h*r)/2;for(const f of i)f.y+=v}}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(v=>{v.width=v.width*a,v.height=v.height*n})}function onValue$2(e){if(e.calculative.isUpdateData){delete e.calculative.isUpdateData;let t=deepClone(e.children);e.children=[],onAdd$2(e),t&&t.forEach(i=>{e.calculative.canvas.delForce(e.calculative.canvas.findOne(i))}),e.calculative.texts=void 0}}function beforeValue$4(e,t){if(e.calculative.isUpdateData=!1,e.swiper!==void 0&&(e.swiper?createInterval(e):delInterval(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===ReplaceMode$1.Replace?(r=e.data,t.dataX&&t.dataX.forEach((a,n)=>{r[a]=t.dataY[n]})):s===ReplaceMode$1.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),setCellText(e,t.row,t.col,t.value),e.calculative.canvas.render(),delete t.col,delete t.row),t}function onWheel(e,t){if(!e.locked&&!e.calculative.canvas.store.data.locked||!e.maxNum)return;let i=0;t.deltaY>0?i=4:i=-4,scroll(e,i)}function scroll(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];changeChildVisible(e,r)}),e.calculative.canvas.render()}function changeChildVisible(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,n=e.calculative.canvas.store.data.scale;e.calculative.worldRect.height/e.tableHeight;const c=e.rowHeight;t.y=t.oldY-e.offsetY*n/e.calculative.worldRect.height;const l=c*(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+=l;let u=t.row+e.maxNum;if(!e.data[u])return;let h=deepClone(e.data[u][t.col]);h.background&&(h.activeBackground=h.background,h.hoverBackground=h.background),h.color&&(h.hoverColor=h.color,h.activeColor=h.color),h.textColor&&(h.activeTextColor=h.textColor,h.hoverTextColor=h.textColor),Object.assign(t,h,{row:u}),Object.assign(t.calculative,h,{row:u})}}else if(t.y+t.height>1){if(t.calculative.visible=!1,t.visible=!1,t.y+t.height/2>1){t.oldY-=l;let u=t.row-e.maxNum;if(!e.data[u])return;let h=deepClone(e.data[u][t.col]);h.background&&(h.activeBackground=h.background,h.hoverBackground=h.background),h.color&&(h.hoverColor=h.color,h.activeColor=h.color),h.textColor&&(h.activeTextColor=h.textColor,h.hoverTextColor=h.textColor),Object.assign(t,h,{row:u}),Object.assign(t.calculative,h,{row:u})}}else t.visible=!0,t.calculative.visible=!0;else if(t.y<0){if(t.calculative.visible=!1,t.visible=!1,t.y<-c/e.tableHeight/2){t.oldY+=l;let u=t.row+e.maxNum;if(!e.data[u])return;let h=deepClone(e.data[u][t.col]);h.background&&(h.activeBackground=h.background,h.hoverBackground=h.background),h.color&&(h.hoverColor=h.color,h.activeColor=h.color),h.textColor&&(h.activeTextColor=h.textColor,h.hoverTextColor=h.textColor),Object.assign(t,h,{row:u}),Object.assign(t.calculative,h,{row:u})}}else if(t.y+t.height>1){if(t.calculative.visible=!1,t.visible=!1,t.y+t.height/2>1){t.oldY-=l;let u=t.row-e.maxNum;if(!e.data[u])return;let h=deepClone(e.data[u][t.col]);h.background&&(h.activeBackground=h.background,h.hoverBackground=h.background),h.color&&(h.hoverColor=h.color,h.activeColor=h.color),h.textColor&&(h.activeTextColor=h.textColor,h.hoverTextColor=h.textColor),Object.assign(t,h,{row:u}),Object.assign(t.calculative,h,{row:u})}}else t.calculative.visible=!0,t.visible=!0}function onDestroy$1(e){delInterval(e)}function delInterval(e){e.interval&&(globalThis.clearInterval(e.interval),e.interval=null)}function createInterval(e){if(e.maxNum&&e.swiper){if(e.interval)return;e.interval=globalThis.setInterval(()=>{e.offsetY>=e.calculative.maxOffsetY?(e.offsetY=0,initChildrenStyle(e)):e.offsetY%e.rowHeight?scroll(e,1):(e.calculative.stap||(e.calculative.stap=0),e.calculative.stap+=1,e.calculative.stap==12&&(e.calculative.stap=0,scroll(e,1)))},50)}}function initChildrenStyle(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 n=r.row-e.maxNum;if(!e.data[n])return;let c=deepClone(e.data[n][r.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),r.calculative.visible=!0,r.visible=!0,Object.assign(r,c,{row:n}),Object.assign(r.calculative,c,{row:n})}),e.calculative.canvas.render()}function onMouseEnter(e){delInterval(e)}function le5leSwitch(e,t){t.onClick||(t.onClick=click,t.setTheme=setTheme$1);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||pSBC(.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||pSBC(.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 click(e){e.disableDefaultClick||e.disabled||e.disable||(e.checked=!e.checked,e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render())}function setTheme$1(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 slider(e,t){t.onAdd||(t.onAdd=initRect,t.onResize=initRect,t.onMove=initRect,t.onMouseMove=mouseMove,t.onMouseDown=mouseDown,t.onValue=onValue$1,t.onBeforeValue=beforeValue$3,t.onMouseUp=mouseUp,t.setTheme=setTheme),t.calculative.barRect||initRect(t);const i=t.calculative.canvas.store;t.calculative.canvas.store.options;let s=t.background;t.disabled&&(s=t.disabledBackground||pSBC(.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,n=t.calculative.barRect.width,c=t.calculative.barRect.height,l=c/2;e.moveTo(r+l,a),e.arcTo(r+n,a,r+n,a+c,l),e.arcTo(r+n,a+c,r,a+c,l),e.arcTo(r,a+c,r,a,l),e.arcTo(r,a,r+n,a,l),e.fill();let u=t.activeColor||i.styles.activeColor;t.disabled&&(u=t.disabledColor||pSBC(.6,u)),e.fillStyle=u,e.beginPath(),n=t.calculative.ballRect.x,e.moveTo(r+l,a),e.arcTo(r+n,a,r+n,a+c,l),e.arcTo(r+n,a+c,r,a+c,l),e.arcTo(r,a+c,r,a,l),e.arcTo(r,a,r+n,a,l),e.fill(),e.fillStyle=t.btnBackground||"#fff",e.strokeStyle=u,e.lineWidth=2,e.beginPath();const h=t.calculative.canvas.store.data.scale;r=t.calculative.worldRect.x+t.calculative.ballRect.x+20*h,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 initRect(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},calcRightBottom(e.calculative.barRect),calcBallRect(e)}function calcBallRect(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},calcRightBottom(e.calculative.ballRect),e.calculative.text=e.value+e.unit,calcTextRect(e)}function mouseDown(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,calcBallRect(e),e.calculative.text=e.value+e.unit,calcTextRect(e),e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render()}function mouseMove(e,t){e.calculative.canvas.mouseDown&&mouseDown(e,t)}function onValue$1(e){e.calculative.isUpdateData&&(delete e.calculative.isUpdateData,initRect(e)),calcBallRect(e)}function beforeValue$3(e,t){return e.calculative.isUpdateData=!1,(t.textWidth||t.barHeight)&&(t.textWidth&&(e._textWidth=0),e.calculative.isUpdateData=!0),t}function setTheme(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 mouseUp(e,t){e.calculative.canvas.store.emitter.emit("change",e)}function checkbox(e,t){t.onMouseDown||(t.onMouseDown=onMousedown$1),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:n,fontSize:c,fontFamily:l,lineHeight:u}=t.calculative;let h=2;e.beginPath(),e.moveTo(i,s),e.arcTo(i+r,s,i+r,s+r,h),e.arcTo(i+r,s+r,i,s+r,h),e.arcTo(i,s+r,i,s,h),e.arcTo(i,s,i+r,s,h),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||pSBC(.6,t.background)||"#ebebeb",e.strokeStyle=t.disabledColor||pSBC(.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||pSBC(.6,t.textColor||t.color)||"#00000040":getTextColor(t,t.calculative.canvas.parent.store)||"#000000d9",e.textAlign="start",e.textBaseline="middle",e.font=getFont({fontStyle:a,fontWeight:n,fontFamily:l||t.calculative.canvas.parent.store.options.fontFamily,fontSize:c,lineHeight:u}),e.fillText(t.value+"",i+r+10,s+r/2),e.restore()}function onMousedown$1(e,t){e.isForbidden||(e.checked=!e.checked,e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render())}function radio(e,t){t.options||(t.options=t.data),t.onAdd||(t.onAdd=onAdd$1,t.optionPos||(t.onAdd(t),t.calculative.canvas.parent.active([t])),t.onMouseDown=onMousedown,t.onValue=onValue,t.onBeforeValue=beforeValue$2);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:n,fontWeight:c,fontSize:l,fontFamily:u,lineHeight:h}=t.calculative;if(t.direction=="horizontal")for(let v=0;v<t.optionPos.length;v++){const f=t.optionPos[v]*a/t.checkboxWidth,g=t.options[v].isForbidden||t.disabled;e.beginPath(),e.arc(i+f+r/2,s+r/2,r/2,0,Math.PI*2),e.strokeStyle="#d9d9d9",e.fillStyle="#ffffff00",t.options[v].text===t.checked&&(e.strokeStyle=t.options[v].background||t.background||"#1890ff"),g&&(e.fillStyle=t.disabledBackground||pSBC(.6,t.background)||"#ebebeb",e.strokeStyle=t.disabledColor||pSBC(.6,t.color)||"#d9d9d9",t.options[v].text===t.checked&&(e.fillStyle="#ffffff00")),e.closePath(),e.fill(),e.stroke(),e.save(),t.options[v].text===t.checked&&(e.beginPath(),e.strokeStyle=t.options[v].background?t.options[v].background+"20":t.background||"#1890ff20",g&&(e.strokeStyle=t.disabledBackground||pSBC(.6,t.background)||"#ebebeb"),e.arc(i+r/2+f,s+r/2,r/2+1.5,0,Math.PI*2),e.stroke(),e.closePath(),e.beginPath(),e.fillStyle=t.options[v].background||t.background||"#1890ff",g&&(e.fillStyle=t.disabledBackground||pSBC(.6,t.background)||"#ebebeb"),e.arc(i+r/2+f,s+r/2,r/4,0,Math.PI*2),e.fill(),e.closePath()),e.restore(),e.save(),e.fillStyle=g?t.disabledTextColor||"#00000040":getTextColor(t,t.calculative.canvas.parent.store)||"#000000d9";const y=t.calculative.worldRect.height*14/16;e.textAlign="start",e.textBaseline="middle",e.font=getFont({fontStyle:n,fontWeight:c,fontFamily:u||t.calculative.canvas.parent.store.options.fontFamily,fontSize:y,lineHeight:h}),e.fillText(t.options[v].text,i+r+f+10/t.checkboxWidth*a,s+r/2),e.restore()}else if(t.direction=="vertical"){const v=t.optionHeight*r/t.checkboxHeight;for(let f=0;f<t.optionPos.length;f++){const g=t.optionPos[f]*r/t.checkboxHeight,y=t.options[f].isForbidden;e.beginPath(),e.arc(i+v/2,s+v/2+g,v/2,0,Math.PI*2),e.strokeStyle="#d9d9d9",e.fillStyle="#ffffff00",t.options[f].text===t.checked&&(e.strokeStyle=t.options[f].background||"#1890ff"),y&&(e.fillStyle="#ebebeb",e.strokeStyle="#d9d9d9"),e.closePath(),e.fill(),e.stroke(),e.save(),!y&&t.options[f].text===t.checked&&(e.beginPath(),e.strokeStyle=t.options[f].background?t.options[f].background+"20":"#1890ff20",e.arc(i+v/2,s+v/2+g,v/2+1.5,0,Math.PI*2),e.stroke(),e.closePath(),e.beginPath(),e.fillStyle=t.options[f].background||"#1890ff",e.arc(i+v/2,s+v/2+g,v/4,0,Math.PI*2),e.fill(),e.closePath()),e.restore(),e.save(),e.fillStyle=y?"#00000040":getTextColor(t,t.calculative.canvas.parent.store)||"#000000d9";const p=14*t.calculative.worldRect.height/t.checkboxHeight;e.textAlign="start",e.textBaseline="middle",e.font=getFont({fontStyle:n,fontWeight:c,fontFamily:u||t.calculative.canvas.parent.store.options.fontFamily,fontSize:p,lineHeight:h}),e.fillText(t.options[f].text,i+v+10,s+v/2+g),e.restore()}}}function onAdd$1(e){initOptions(e)}function onMousedown(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+getTextLength(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 onValue(e){e.calculative.flag&&initOptions(e)}function beforeValue$2(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 formPens(){return{radio,switch:le5leSwitch,slider,checkbox,table:table2,table2}}function andGate(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect,c=n/6,l=a/4;if(i.moveTo(s+l*2,r+0),i.lineTo(s+l*2,r+c),i.moveTo(s,r+c+l*2),i.arc(s+l*2,r+c+l*2,l*2,Math.PI*1,Math.PI*2,!1),i.lineTo(s+l*4,r+c*5),i.lineTo(s,r+c*5),i.lineTo(s,r+c+l*2),i.moveTo(s+l,r+c*5),i.lineTo(s+l,r+c*6),i.moveTo(s+l*2,r+c*5),i.lineTo(s+l*2,r+c*6),i.moveTo(s+l*3,r+c*5),i.lineTo(s+l*3,r+c*6),i.closePath(),i instanceof Path2D)return i}function andGateAnchors(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 basicEvent(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect,c=n-a,l=.5*a;if(i.moveTo(s+a/2,r),i.lineTo(s+a/2,r+c),i.moveTo(s+a,r+l+c),i.arc(s+a/2,r+l+c,l,0,Math.PI*2,!1),i.closePath(),i instanceof Path2D)return i}function basicEventAnchors(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 conditionalEvent(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect,c=n/2,l=a/5;if(i.moveTo(s,r+c),i.lineTo(s+l,r+c),i.moveTo(s+l*5,r+c),i.ellipse(s+l*3,r+c,2*l,c,0,0,Math.PI*2),i.closePath(),i instanceof Path2D)return i}function conditionalEventAnchors(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 event(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect,c=n/4,l=.5*a;if(i.moveTo(s+l,r),i.lineTo(s+l,r+c),i.moveTo(s,r+c),i.rect(s,r+c,l*2,c*2),i.moveTo(s+l,r+3*c),i.lineTo(s+l,r+4*c),i.closePath(),i instanceof Path2D)return i}function forbiddenGate(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect,c=n/8,l=.25*a;if(i.moveTo(s+l*2,r),i.lineTo(s+l*2,r+c*2),i.lineTo(s+l*3,r+c*3),i.lineTo(s+l*3,r+c*5),i.lineTo(s+l*2,r+c*6),i.lineTo(s+l*1,r+c*5),i.lineTo(s+l*1,r+c*3),i.lineTo(s+l*2,r+c*2),i.moveTo(s+l*3,r+c*4),i.lineTo(s+l*4,r+c*4),i.moveTo(s+l*2,r+c*6),i.lineTo(s+l*2,r+c*8),i.closePath(),i instanceof Path2D)return i}function forbiddenGateAnchors(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 orGate(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect,c=a/2,l=n/10;if(i.moveTo(s+c,r),i.lineTo(s+c,r+l),i.moveTo(s+c,r+l),i.quadraticCurveTo(s+c*2,r+l,s+c*2,r+l*9),i.moveTo(s+c,r+l),i.quadraticCurveTo(s,r+l,s,r+l*9),i.quadraticCurveTo(s+c,r+l*6,s+c*2,r+l*9),i.moveTo(s+c,r+n*3/4),i.lineTo(s+c,r+n),i.moveTo(s+c*2/5,r+n*201/250),i.lineTo(s+c*2/5,r+n),i.moveTo(s+c*8/5,r+n*201/250),i.lineTo(s+c*8/5,r+n),i.closePath(),i instanceof Path2D)return i}function orGateAnchors(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 priorityAndGate(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect,c=n/6,l=a/4;if(i.moveTo(s+l*2,r+0),i.lineTo(s+l*2,r+c),i.moveTo(s,r+c+l*2),i.arc(s+l*2,r+c+l*2,l*2,Math.PI*1,Math.PI*2,!1),i.lineTo(s+l*4,r+c*5),i.lineTo(s,r+c*5),i.lineTo(s,r+c+l*2),i.moveTo(s,r+c*5-c/3),i.lineTo(s+l*4,r+c*5-c/3),i.moveTo(s+l,r+c*5),i.lineTo(s+l,r+c*6),i.moveTo(s+l*2,r+c*5),i.lineTo(s+l*2,r+c*6),i.moveTo(s+l*3,r+c*5),i.lineTo(s+l*3,r+c*6),i.closePath(),i instanceof Path2D)return i}function switchEvent(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect,c=n/4,l=.5*a;if(i.moveTo(s+l,r),i.lineTo(s+l,r+c),i.lineTo(s+l*2,r+c*2),i.lineTo(s+l*2,r+c*4),i.lineTo(s,r+c*4),i.lineTo(s,r+c*2),i.lineTo(s+l,r+c),i.closePath(),i instanceof Path2D)return i}function transferSymbol(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect,c=n/4,l=a/2;if(i.moveTo(s+l,r),i.lineTo(s+l,r+c),i.lineTo(s+l*2,r+c*4),i.lineTo(s,r+c*4),i.lineTo(s+l,r+c),i.closePath(),i instanceof Path2D)return i}function unexpandedEvent(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect,c=n/3,l=.5*a;if(i.moveTo(s+l,r),i.lineTo(s+l,r+c),i.lineTo(s+a,r+2*c),i.lineTo(s+l,r+n),i.lineTo(s,r+2*c),i.lineTo(s+l,r+c),i.closePath(),i instanceof Path2D)return i}function unexpandedEventAnchors(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 xorGate(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;let c=a/2,l=n/10;if(i.moveTo(s+c,r),i.lineTo(s+c,r+l),i.moveTo(s+c,r+l),i.quadraticCurveTo(s+c*2,r+l,s+c*2,r+l*9),i.moveTo(s+c,r+l),i.quadraticCurveTo(s,r+l,s,r+l*9),i.quadraticCurveTo(s+c,r+l*6,s+c*2,r+l*9),i.moveTo(s,r+l*10),i.quadraticCurveTo(s+c,r+l*7,s+c*2,r+l*10),i.moveTo(s+c*2/5,r+n*201/250+l),i.lineTo(s+c*2/5,r+n),i.moveTo(s+c*8/5,r+n*201/250+l),i.lineTo(s+c*8/5,r+n),i.closePath(),i instanceof Path2D)return i}function xorGateAnchors(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 votingGate(e,t){const{x:i,y:s,width:r,height:a}=t.calculative.worldRect,n=r/2,c=a/10;e.beginPath(),e.moveTo(i+n,s),e.lineTo(i+n,s+c),e.moveTo(i+n,s+c),e.quadraticCurveTo(i+n*2,s+c,i+n*2,s+c*9),e.moveTo(i+n,s+c),e.quadraticCurveTo(i,s+c,i,s+c*9),e.quadraticCurveTo(i+n,s+c*6,i+n*2,s+c*9),e.moveTo(i+n,s+a*3/4),e.lineTo(i+n,s+a*9/10),e.moveTo(i+n*2/5,s+a*201/250),e.lineTo(i+n*2/5,s+a*9/10),e.moveTo(i+n*8/5,s+a*201/250),e.lineTo(i+n*8/5,s+a*9/10),e.stroke(),e.closePath(),e.beginPath();const l=n*2>c*10?c:n/5;e.fillStyle="#333333",e.font=l+"px Arial",e.textBaseline="bottom",e.textAlign="center",e.fillText("o",i+n,s+a),e.fillText("m",i+n*2/5,s+a),e.fillText("o",i+n*8/5,s+a),e.closePath()}function ftaPens(){return{andGate,basicEvent,conditionalEvent,event,forbiddenGate,orGate,priorityAndGate,switchEvent,transferSymbol,unexpandedEvent,xorGate}}function ftaPensbyCtx(){return{votingGate}}function ftaAnchors(){return{andGate:andGateAnchors,orGate:orGateAnchors,priorityAndGate:andGateAnchors,votingGate:orGateAnchors,xorGate:xorGateAnchors,forbiddenGate:forbiddenGateAnchors,basicEvent:basicEventAnchors,unexpandedEvent:unexpandedEventAnchors,conditionalEvent:conditionalEventAnchors,transferSymbol:basicEventAnchors}}const maxDecimal=15;function fixedNum(e,t=maxDecimal){let i=""+e;return i.indexOf(".")>=0&&(i=Number.parseFloat(i).toFixed(t)),Number.parseFloat(i)}function numberValid(e){return typeof e=="number"&&Number.isFinite(e)}function scaleCompute(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:n,preferZero:c}=e;if(!numberValid(i)||!numberValid(s)||i<s)return{splitNumber:r};if(i===s&&i===0)return{max:fixedNum(t[0]*r),min:s,interval:t[0],splitNumber:r};i===s&&(c=!0),(!numberValid(r)||r<=0)&&(r=4),c&&i*s>0&&(i<0?i=0:s=0);const l=(i-s)/r;let u=Math.floor(Math.log10(l)-1);u=Math.pow(10,u);const h=l/u;let v=t[0]*u,f=-1,g;for(g=0;g<t.length;g++)if(t[g]>h){v=t[g]*u;break}let y=i,p=s;function m(k){if(y=parseInt(""+(i/k+1))*k,p=parseInt(""+(s/k-1))*k,i===0&&(y=0),s===0&&(p=0),a&&y*p<0){const w=Math.max(Math.abs(y),Math.abs(p));y=w,p=-w}}if(m(v),n)return{max:fixedNum(y),min:fixedNum(p),interval:fixedNum(v),splitNumber:Math.round((y-p)/v)};if(!a||y*p>0){let k;t:do{if(k=Math.round((y-p)/v),(g-f)*(k-r)<0){for(;k<r;)if(p-s<=y-i&&p!==0||y===0?p-=v:y+=v,k++,k===r)break t}if(g>=t.length-1||g<=0||k===r)break;f=g,k>r?v=t[++g]*u:v=t[--g]*u,m(v)}while(k!==r)}y=fixedNum(y),p=fixedNum(p);const x=fixedNum((y-p)/r);return{max:y,min:p,interval:x,splitNumber:r}}function coordinateAxis(e,t){var m,x,k,w,C,I,_,L,E,F,q,R,A,P,M,H,$,X,j,O,z,V,N,Y,K,G,tt,Q;const i=t.calculative.worldRect.x,s=t.calculative.worldRect.y,r=t.calculative.worldRect.width,a=t.calculative.worldRect.height;let n=t.calculative.canvas.store.data.scale,c=[];if(t.echarts)for(let Z=0;Z<t.echarts.option.series.length;Z++)c.push(t.echarts.option.series[Z].data);else c=t.data;let l=[];for(let Z=0;Z<c.length;Z++)l=l.concat(c[Z]);let u={max:Math.max.apply(null,l),min:Math.min.apply(null,l),splitNumber:5},h=scaleCompute(u),v=t.echarts?t.echarts.option.xAxis.data.length:t.xAxisData.length;e.beginPath(),e.strokeStyle="#BFBFBF",e.lineWidth=6*n,e.lineCap="butt";let f=(r-1*(v+1))/v;e.setLineDash([1,f]),e.moveTo(i,s+a+3*n),e.lineTo(i+r,s+a+3*n),e.stroke(),e.closePath(),e.beginPath(),e.lineWidth=1*n,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 g={fontStyle:((x=(m=t.yAxis)==null?void 0:m.axisLabel)==null?void 0:x.fontStyle)||t.fontStyle,textDecoration:(w=(k=t.yAxis)==null?void 0:k.axisLabel)==null?void 0:w.textDecoration,fontWeight:((I=(C=t.yAxis)==null?void 0:C.axisLabel)==null?void 0:I.fontWeight)||t.fontWeight,fontFamily:((L=(_=t.yAxis)==null?void 0:_.axisLabel)==null?void 0:L.fontFamily)||t.fontFamily,fontSize:((F=(E=t.yAxis)==null?void 0:E.axisLabel)==null?void 0:F.fontSize)||t.fontSize,lineHeight:((R=(q=t.yAxis)==null?void 0:q.axisLabel)==null?void 0:R.lineHeight)||t.lineHeight};e.fillStyle=((P=(A=t.yAxis)==null?void 0:A.axisLabel)==null?void 0:P.fontColor)||t.color;for(let Z=0;Z<h.splitNumber+1;Z++){let b=Z*a/h.splitNumber;e.textAlign="right",e.textBaseline="middle",e.font=getFont(g),e.fillText(h.max-Z*h.interval+"",i-10*n,s+b),e.fill(),Z<h.splitNumber&&(e.beginPath(),e.moveTo(i,s+b),e.lineTo(i+r,s+b),e.stroke())}e.closePath(),e.beginPath(),e.strokeStyle="#BFBFBF";let y=t.echarts?t.echarts.option.xAxis.data:t.xAxisData,p=0;for(let Z=0;Z<y.length;Z++){p=i+(1+f/2)+(f+1)*Z,e.textAlign="center",e.textBaseline="top";let b={fontStyle:((H=(M=t.xAxis)==null?void 0:M.axisLabel)==null?void 0:H.fontStyle)||t.calculative.fontStyle,textDecoration:(X=($=t.xAxis)==null?void 0:$.axisLabel)==null?void 0:X.textDecoration,fontWeight:((O=(j=t.xAxis)==null?void 0:j.axisLabel)==null?void 0:O.fontWeight)||t.calculative.fontWeight,fontFamily:((V=(z=t.xAxis)==null?void 0:z.axisLabel)==null?void 0:V.fontFamily)||t.calculative.fontFamily,fontSize:((Y=(N=t.xAxis)==null?void 0:N.axisLabel)==null?void 0:Y.fontSize)||t.calculative.fontSize,lineHeight:((G=(K=t.xAxis)==null?void 0:K.axisLabel)==null?void 0:G.lineHeight)||t.calculative.lineHeight};e.font=getFont(b),e.fillStyle=((Q=(tt=t.xAxis)==null?void 0:tt.axisLabel)==null?void 0:Q.fontColor)||t.calculative.color,e.fillText(y[Z],p,s+a+10*n),e.fill()}return e.closePath(),e.setLineDash([]),{dash:f,normalizedOption:h}}function getValidValue(e,t){if(!isNaN(e))return Math.round(Number(e)*1e3)/1e3}var ReplaceMode;(function(e){e[e.Add=0]="Add",e[e.Replace=1]="Replace",e[e.ReplaceAll=2]="ReplaceAll"})(ReplaceMode||(ReplaceMode={}));function lineChart(e,t){t.onBeforeValue||(t.onBeforeValue=beforeValue$1);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,n=[];t.echarts&&!t.echarts.option.color&&(t.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]);let c=coordinateAxis(e,t),l=c.dash,u=c.normalizedOption;const h=!!(t.echarts?t.echarts.option.series[0].smooth:t.smooth);let v=[];if(t.echarts)for(let f=0;f<t.echarts.option.series.length;f++)n.push(t.echarts.option.series[f].data);else n=t.data;for(let f=0;f<n.length;f++){e.beginPath();let g=n[f];e.strokeStyle=t.echarts?t.echarts.option.color[f]:t.chartsColor[f],e.fillStyle=t.echarts?t.echarts.option.color[f]:t.chartsColor[f];let y=i+(1+l/2),p=s+r-(g[0]-u.min)/(u.max-u.min)*r;if(e.moveTo(y,p),v.push({x:y,y:p}),h)if(g.length<=2)for(let m=1;m<g.length;m++)y=i+(1+l/2)+(l+1)*m,p=s+r-(g[m]-u.min)/(u.max-u.min)*r,e.lineTo(y,p),v.push({x:y,y:p});else{let m,x,k,w;g.forEach((C,I)=>{y=i+(1+l/2)+(l+1)*I,p=s+r-(g[I]-u.min)/(u.max-u.min)*r;let _=i+(1+l/2)+(l+1)*(I+1),L=s+r-(g[I+1]-u.min)/(u.max-u.min)*r,E=i+(1+l/2)+(l+1)*(I-1),F=s+r-(g[I-1]-u.min)/(u.max-u.min)*r,q=i+(1+l/2)+(l+1)*(I+2),R=s+r-(g[I+2]-u.min)/(u.max-u.min)*r;I===0?(E=i+(1+l/2)+(l+1)*I,F=s+r-(g[I]-u.min)/(u.max-u.min)*r):I===g.length-2&&(q=i+(1+l/2)+(l+1)*(I+1),R=s+r-(g[I+1]-u.min)/(u.max-u.min)*r),v.push({x:y,y:p}),m=y+(_-E)/4,x=p+(L-F)/4,k=_-(q-y)/4,w=L-(R-p)/4,e.bezierCurveTo(m,x,k,w,_,L)})}else for(let m=1;m<g.length;m++)y=i+(1+l/2)+(l+1)*m,p=s+r-(g[m]-u.min)/(u.max-u.min)*r,e.lineTo(y,p),v.push({x:y,y:p});e.stroke(),e.closePath(),e.save(),v.forEach((m,x)=>{e.beginPath(),e.strokeStyle="#fff",e.lineWidth=2*a,e.arc(m.x,m.y,4*a,0,Math.PI*2),e.stroke(),e.fill(),e.closePath()}),e.restore(),v=[]}}function beforeValue$1(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=[],n=[];return r?r===ReplaceMode.Replace?(t.dataX.forEach((c,l)=>{let u=i.indexOf(c);s.forEach((h,v)=>{h[u]=t.dataY[v][l]})}),a=i,n=s):r===ReplaceMode.ReplaceAll&&(a=t.dataX,n=t.dataY):(a=[...i,...t.dataX],s.forEach((c,l)=>{let u=[...c,...t.dataY[l]];n.push(u)})),delete t.dataX,delete t.dataY,Object.assign(t,{xAxisData:a,data:n})}function pieChart(e,t){var h,v;t.onBeforeValue||(t.onBeforeValue=beforeValue);let i=t.calculative.canvas.store.data.scale;const s=t.calculative.worldRect.x,r=t.calculative.worldRect.y,a=t.calculative.worldRect.width,n=t.calculative.worldRect.height,c=!!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 l=c?t.echarts.option.series:t.data;let u=0;for(let f=0;f<l.length;f++){let g=l[f],y=a/2;n<a&&(y=n/2);const p=s+a/2,m=r+n/2;let x=0;c?x=g.data.reduce((L,E)=>L+E.value,0):x=g.reduce((L,E)=>L+E.value,0);const k=y*parseFloat(c?g.radius[0]:t.chartsRadius[f][0])/100,w=y*parseFloat(c?g.radius[1]:t.chartsRadius[f][1])/100;if(k>w)return;let C=0,I=0;e.strokeStyle=c&&((h=g.itemStyle)==null?void 0:h.borderColor)||"#fff",e.lineWidth=(c&&((v=g.itemStyle)==null?void 0:v.borderWidth)||2)*i;const _=c?g.data:g;_.forEach((L,E)=>{var H,$,X,j,O,z,V,N,Y,K;I+=Math.PI*2*L.value/x,e.beginPath();let F=u+E;F>=t.chartsColor.length&&(F=F%t.chartsColor.length),e.fillStyle=c?t.echarts.option.color[F]:t.chartsColor[F],e.moveTo(p+k*Math.sin(I),m-k*Math.cos(I)),e.arc(p,m,k,-Math.PI/2+I,-Math.PI/2+C,!0),e.lineTo(p+w*Math.sin(C),m-w*Math.cos(C)),e.arc(p,m,w,-Math.PI/2+C,-Math.PI/2+I),e.lineTo(p+k*Math.sin(I),m-k*Math.cos(I)),e.stroke(),e.fill(),e.closePath();let q=(C+I)/2,R=p+(w+10*i)*Math.sin(q),A=m-(w+10*i)*Math.cos(q),P=e.fillStyle;g.label||(g.label={position:"outside",show:!0}),c&&["inner","inside"].includes(g.label.position)?(e.fillStyle="#ffffff",R=p+(w-k)/2*Math.sin(q),A=m-(w-k)/2*Math.cos(q)):c&&g.label.position=="outside",g.labelLine||(g.labelLine={show:!0}),(c&&g.labelLine.show!==!1||!c)&&(e.beginPath(),e.strokeStyle=c?t.echarts.option.color[u+E]:t.chartsColor[u+E],e.moveTo(p+w*Math.sin(q),m-w*Math.cos(q)),e.lineTo(R,A));let M={fontStyle:((H=t.tickLabel)==null?void 0:H.fontStyle)||t.calculative.fontStyle,fontWeight:(($=t.tickLabel)==null?void 0:$.fontWeight)||t.calculative.fontWeight,fontFamily:((X=t.tickLabel)==null?void 0:X.fontFamily)||t.calculative.fontFamily,lineHeight:((j=t.tickLabel)==null?void 0:j.lineHeight)||t.calculative.lineHeight,fontSize:(((O=t.tickLabel)==null?void 0:O.fontSize)||t.calculative.fontSize)*i};e.font=getFont(M),e.textBaseline="middle",e.textAlign="center",q>Math.PI?((c&&g.label.position==="outside"||!c)&&(e.textAlign="end"),(c&&g.labelLine.show!==!1||!c&&(((V=(z=t.tickLabel)==null?void 0:z.labelLine)==null?void 0:V.show)??!0))&&e.lineTo(R-5*i,A),(c&&g.label.show!==!1||!c&&(((N=t.tickLabel)==null?void 0:N.show)??!0))&&e.fillText(L.name,R-5*i,A)):((c&&g.label.position==="outside"||!c)&&(e.textAlign="start"),(c&&g.labelLine.show!==!1||!c)&&e.lineTo(R+5*i,A),(c&&g.label.show!==!1||!c&&(((Y=t.tickLabel)==null?void 0:Y.show)??!0))&&e.fillText(L.name,R+5*i,A)),e.stroke(),e.closePath(),e.fillStyle=P,e.strokeStyle=c&&((K=g.itemStyle)==null?void 0:K.borderColor)||"#fff",C=I}),u+=_.length}}function beforeValue(e,t){if(t.data||!t.dataX&&!t.dataY)return t;const i=e.data,s=e.replaceMode;let r=[];return s?s===ReplaceMode.Replace?(t.dataY.forEach((a,n)=>{a.forEach((c,l)=>{let u=i[n].filter(h=>h.name===c.name);u.length>0&&(u[0].value=c.value)})}),r=i):s===ReplaceMode.ReplaceAll&&(r=t.dataY):i.forEach((a,n)=>{let c=[...a,...t.dataY[n]];r.push(c)}),delete t.dataX,delete t.dataY,Object.assign(t,{data:r})}function histogram(e,t){t.onBeforeValue||(t.onBeforeValue=beforeValue$1);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 n=[];if(t.echarts&&!t.echarts.option.color&&(t.echarts.option.color=["#1890ff","#2FC25B","#FACC14","#c23531","#2f4554","#61a0a8","#d48265"]),t.echarts)for(let v=0;v<t.echarts.option.series.length;v++)n.push(t.echarts.option.series[v].data);else n=t.data;let c=coordinateAxis(e,t),l=c.dash,u=c.normalizedOption,h=l*4/5/n.length;for(let v=0;v<n.length;v++){e.beginPath();let f=n[v];e.fillStyle=t.echarts?t.echarts.option.color[v]:t.chartsColor[v],e.strokeStyle="#ffffff",e.lineWidth=1*i;let g=0,y=0,p=0;for(let m=0;m<f.length;m++)g=s+(1+.1*l)+(l+1)*m+h*v,p=(f[m]-u.min)/(u.max-u.min)*a,y=r+a-p,e.rect(g,y,h-1,p-1),e.stroke(),e.fill();e.closePath()}}function gauge(e,t){var j,O,z,V,N,Y,K,G,tt,Q,Z,b,T,S;t.onAdd||(t.onAdd=onAdd,t.onDestroy=onDestroy,t.onClick=onclick,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 n=t.calculative.canvas.store.data.scale,c={startAngle:225,endAngle:-45,min:0,max:100,splitNumber:10};if(t.echarts&&t.echarts.option){let D=t.echarts.option.series[0];t.startAngle=D.startAngle||c.startAngle,t.endAngle=D.endAngle||c.endAngle,t.min=D.min||c.min,t.max=D.max||c.max,t.axisLine=D.axisLine.lineStyle.color,t.unit=D.detail.formatter.replace("{value}",""),t.value=D.data[0].value,t.splitNumber=D.splitNumber||c.splitNumber}t={...c,...t};let l=r>a?a/2*9/10:r/2*9/10,u=i+r/2,h=s+a/2,v=t.echarts?t.echarts.option.series[0].data[0].value:t.value,f,g=t.startAngle-t.endAngle,y=t.background||"#E6EBF8";e.strokeStyle=y;let p=l/10;e.lineWidth=p,e.beginPath(),e.lineCap="round",e.arc(u,h,l,-t.startAngle/180*Math.PI,-t.endAngle/180*Math.PI),e.stroke(),e.closePath();let m=0;if(t.axisLine&&!t.isClock)for(let D=t.axisLine.length-1;D>=0;D--)t.axisLine[D][0]*(t.max-t.min)<v?m=t.axisLine[D][0]:(m=(v-t.min)/(t.max-t.min),f=t.axisLine[D][1]),e.beginPath(),e.strokeStyle=t.axisLine[D][1],e.arc(u,h,l,-t.startAngle/180*Math.PI,(-t.startAngle+m*g)/180*Math.PI),e.stroke(),e.closePath();e.lineCap="butt";let x=2*n,k=l-p;k<0&&(k=0);let w=g/180*Math.PI*k,C=(w-x*t.splitNumber)/t.splitNumber,I=g/180*Math.PI*x/2/w;e.beginPath(),e.strokeStyle=t.color||"#999999",e.lineWidth=l/20,e.setLineDash([x,C]),e.arc(u,h,k,-t.startAngle/180*Math.PI-I,-t.endAngle/180*Math.PI+I),e.stroke(),e.closePath();let _=1*n,L=l-p;L<0&&(L=0);let E=g/180*Math.PI*L,F=(E-_*5*t.splitNumber)/5/t.splitNumber,q=g/180*Math.PI*_/2/E;e.beginPath(),e.strokeStyle=t.color||"#999999",e.lineWidth=l/40,e.setLineDash([_,F]),e.arc(u,h,L,-t.startAngle/180*Math.PI-q,-t.endAngle/180*Math.PI+q),e.stroke(),e.closePath(),e.beginPath();let R=t.max-t.min,A=R/t.splitNumber,P={fontStyle:((j=t.tickLabel)==null?void 0:j.fontStyle)||t.calculative.fontStyle,textDecoration:((O=t.tickLabel)==null?void 0:O.textDecoration)||t.textDecoration,fontWeight:((z=t.tickLabel)==null?void 0:z.fontWeight)||t.calculative.fontWeight,fontFamily:((V=t.tickLabel)==null?void 0:V.fontFamily)||t.calculative.fontFamily,fontSize:(((N=t.tickLabel)==null?void 0:N.fontSize)||t.calculative.fontSize)*n,lineHeight:((Y=t.tickLabel)==null?void 0:Y.lineHeight)||t.calculative.lineHeight};e.font=getFont(P);let M=l-p-l/20;for(let D=0;D<=t.splitNumber;D++){if(Math.abs(t.startAngle)+Math.abs(t.endAngle)===360&&D==0)continue;let W=t.startAngle-A*D/R*g,U=Math.cos(W/180*Math.PI),J=Math.sin(W/180*Math.PI);e.fillStyle=((K=t.tickLabel)==null?void 0:K.color)||"#999999",U>.02?e.textAlign="end":U<-.02?e.textAlign="start":e.textAlign="center",J>.02?e.textBaseline="top":J<-.02?e.textBaseline="bottom":e.textBaseline="middle",e.fillText(getValidValue(A*D+t.min),u+M*U,h-M*J),e.fill()}e.closePath();let H=1,$=["value"];if(t.isClock&&(H=3,$=["hourvalue","minutevalue","secondvalue"]),t.isClock)for(let D=0;D<H;D++){let W=(t.startAngle-(t[$[D]]-t.min)/(t.max-t.min)*g)/180*Math.PI;D>0&&(W=(t.startAngle-(t[$[D]]-t.min)/(t.max*5-t.min)*g)/180*Math.PI);let U=4/5*l;$[D]==="hourvalue"&&(U=3/5*l),$[D]==="minutevalue"&&(U=3.5/5*l);let J=l*1/40;e.beginPath(),e.setLineDash([]),e.lineWidth=l/(D+1)/20,e.strokeStyle=t.color||"#999999",e.moveTo(u-J*3*Math.cos(W),h+J*3*Math.sin(W)),e.lineTo(u+U*Math.cos(W),h-U*Math.sin(W)),e.stroke()}else{let D=(t.startAngle-(v-t.min)/(t.max-t.min)*g)/180*Math.PI,W=4/5*l,U=l*1/40;e.beginPath(),e.setLineDash([]),e.lineWidth=2,e.fillStyle=f,e.moveTo(u-U*3*Math.cos(D),h+U*3*Math.sin(D)),e.lineTo(u+U*Math.cos(D-Math.PI/2),h-U*Math.sin(D-Math.PI/2)),e.lineTo(u+W*Math.cos(D),h-W*Math.sin(D)),e.lineTo(u+U*Math.cos(D+Math.PI/2),h-U*Math.sin(D+Math.PI/2)),e.lineTo(u-U*3*Math.cos(D),h+U*3*Math.sin(D)),e.fill()}e.beginPath(),e.textAlign="center",e.textBaseline="middle";let X={fontStyle:((G=t.titleLabel)==null?void 0:G.fontStyle)||t.calculative.fontStyle,textDecoration:((tt=t.titleLabel)==null?void 0:tt.textDecoration)||t.textDecoration,fontWeight:((Q=t.titleLabel)==null?void 0:Q.fontWeight)||t.calculative.fontWeight,fontFamily:((Z=t.titleLabel)==null?void 0:Z.fontFamily)||t.calculative.fontFamily,fontSize:(((b=t.titleLabel)==null?void 0:b.fontSize)||t.calculative.fontSize)*n,lineHeight:((T=t.titleLabel)==null?void 0:T.lineHeight)||t.calculative.lineHeight};e.font=getFont(X),e.fillStyle=((S=t.titleLabel)==null?void 0:S.color)||f,t.isClock?e.fillText(("0"+parseInt(t.hourvalue)).slice(-2)+":"+("0"+parseInt(t.minutevalue)).slice(-2)+":"+("0"+parseInt(t.secondvalue)).slice(-2),u,h+l/2):e.fillText(v+" "+(t.unit||""),u,h+l/2),e.fill(),t.isClock&&(e.beginPath(),e.fillStyle=t.color||"#999999",e.strokeStyle="#ffffff",e.arc(u,h,l/20,0,Math.PI*2),e.stroke(),e.fill(),e.closePath())}function onAdd(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 onDestroy(e){e.clockInterval&&(clearInterval(e.clockInterval),e.clockInterval=void 0)}function onclick(e){e.isClock&&(e.onDestroy(e),e.onAdd(e))}function chartsPens(){return{lineChart,histogram,pieChart,gauge}}function focus(e,t){const i=t||new Path2D,{x:s,y:r,width:a,height:n}=e.calculative.worldRect;if(i.rect(s,r,a,n),i.closePath(),i instanceof Path2D)return i}function lifeline(e,t){const i=t.headHeight??50,{x:s,y:r,width:a,height:n,ey:c}=t.calculative.worldRect;let l=t.calculative.borderRadius||0,u=l;t.calculative.borderRadius<1&&(l*=a,u*=n);let h=l<u?l:u;a<2*h&&(h=a/2),i<2*h&&(h=i/2),e.beginPath(),e.moveTo(s+h,r),e.arcTo(s+a,r,s+a,r+i,h),e.arcTo(s+a,r+i,s,r+i,h),e.arcTo(s,r+i,s,r,h),e.arcTo(s,r,s+a,r,h),e.closePath(),e.stroke(),e.save(),e.beginPath(),e.lineWidth=1,e.setLineDash([7,7]);const v=s+a/2;e.moveTo(v,r+i+1),e.lineTo(v,c),e.stroke(),e.restore()}function sequencePens(){return{sequenceFocus:focus}}function sequencePensbyCtx(){return{lifeline}}export{C2S as C,Meta2d as M,registerAnchors as a,registerCanvasDraw as b,register as c,flowAnchors as d,activityDiagram as e,flowPens as f,activityDiagramByCtx as g,classPens as h,isShowChild as i,sequencePensbyCtx as j,formPens as k,chartsPens as l,ftaPens as m,ftaPensbyCtx as n,ftaAnchors as o,register$1 as r,sequencePens as s};
|