var Gx=Object.defineProperty;var Zx=(e,t,i)=>t in e?Gx(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var W=(e,t,i)=>(Zx(e,typeof t!="symbol"?t+"":t,i),i);import{G as Le,I as Jx,E as mr}from"./index.254cdd50.js";function qn(e,t){const i=t||new Path2D;let n=e.calculative.borderRadius||0,r=n;const{x:s,y:a,width:l,height:c,ex:u,ey:h}=e.calculative.worldRect;n<1&&(n=l*n,r=c*r);let d=nt.x-i&&e.xt.y-i&&e.y0&&n>0?r=180-r:i<0&&n>0?r+=180:i<0&&n<0&&(r=360-r),r}function Za(e,t){const i=e.x-t.x,n=e.y-t.y;return Math.sqrt(i*i+n*n)}function l_(e,t){let i=Lt.None;if(!t)return i;const n=e.x-t.x,r=e.y-t.y;return Math.abs(n)>Math.abs(r)?n>0?i=Lt.Right:i=Lt.Left:r>0?i=Lt.Bottom:i=Lt.Up,i}function ls(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 Bf(e,t){return e.anchorId===t.anchorId&&e.connectTo===t.connectTo}function wa(e,t,i){let n=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>>0,1)},emit:function(t,i){(e.get(t)||[]).slice().map(function(n){n(i)}),(e.get("*")||[]).slice().map(function(n){n(t,i)})}}}var zn;(function(e){e[e.None=-1]="None",e[e.Document=0]="Document",e[e.Canvas=1]="Canvas"})(zn||(zn={}));const S_={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:zn.Document,gridSize:20,gridColor:"#e2e2e2",ruleColor:"#888888",drawingLineName:"curve",interval:30,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,cdn:"",polylineSpace:10,domShapes:[],containerShapes:["tablePlus"],textFlip:!0,textRotate:!0,unavailableKeys:[],diagramOptions:{},svgPathStroke:!0},P_={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"}}};var bt;(function(e){e[e.Add=0]="Add",e[e.Update=1]="Update",e[e.Delete=2]="Delete",e[e.Replace=3]="Replace"})(bt||(bt={}));const I_=()=>({data:{x:0,y:0,scale:1,pens:[],origin:{x:0,y:0},center:{x:0,y:0},paths:{},theme:"light"},histories:[],pens:{},path2dMap:new WeakMap,animateMap:new WeakMap,active:[],animates:new Set,options:{...S_},theme:{...P_},emitter:T_(),bindDatas:{},bind:{},pensNetwork:{},cacheDatas:[],messageEvents:{},templatePens:{},globalTriggers:{}}),L_=(e="default")=>(At[e]||(At[e]=I_(),At[e].id=e),At[e]),D_=(e,t)=>{const i=e.data.template===t;if(i)for(const n of e.data.pens)n.canvasLayer===zt.CanvasTemplate&&(e.templatePens[n.id]=n);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},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 Ti(e){const{paddingTop:t,paddingBottom:i,paddingLeft:n,paddingRight:r,worldRect:s,canvas:a}=e.calculative;let{textLeft:l,textTop:c,textWidth:u,textHeight:h}=e.calculative,d=n,g=t;const v=s.width-n-r,y=s.height-t-i;u&&u<1&&(u*=s.width),h&&h<1&&(h*=s.height),u1?s:1;switch(e.whiteSpace){case"nowrap":if(e.ellipsis!==!1){const h=Of(t.split(""),e);h[0]&&(i.push(h[0]),h.length>1&&Sl(i))}else i.push(t);break;case"pre-line":i=t.split(/[\n]/g),e.ellipsis!==!1&&i.length>a&&(i=i.slice(0,a),Sl(i));break;case"break-all":default:const c=t.split(/[\n]/g);let u=0;t:for(const h of c){const d=e.whiteSpace==="break-all"?h.split(""):Av(h);let g=Of(d,e);if(g.length===0&&(g=[""]),e.ellipsis!=!1)for(const v of g)if(u++,u>a){Sl(i);break t}else i.push(v);else i.push(...g)}break}const l=e.calculative.keepDecimal;return l!=null&&i.forEach((c,u)=>{const h=Number(c);isNaN(h)||(i[u]=h.toFixed(l))}),e.calculative.textLines=i,i}function Av(e=""){const t=[];let i="";for(let n=0;n126?(i&&(t.push(i),i=""),t.push(e[n])):i+=e[n]}return i&&t.push(i),t}function Of(e,t){const i=t.calculative.canvas,n=i.offscreen.getContext("2d"),{fontStyle:r,fontWeight:s,fontSize:a,fontFamily:l,lineHeight:c}=t.calculative;n.save();const u=[];let h=e[0]||"";for(let d=1;d{const r=e.measureText(n).width;t.calculative.textLineWidths.push(r),iu&&(u=h)}n.restore();let d=t.length*a*c;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-(d-e.height):e.y=e.y-(d-e.height)/2),e.height=d+2,e.width=u+2,e.calculative.canvas.updatePenRect(e),e.calculative.canvas.calcActiveRect()}function ct(e,t=!1){if(Array.isArray(e)){const i=[];return e.forEach(n=>{i.push(ct(n,t))}),i}else if(typeof e=="object"){if(e===null)return null;if(e.constructor===RegExp)return e;const i={};for(const n in e)if(!(["canvas","lastFrame"].includes(n)||e[n]instanceof HTMLImageElement||e[n]instanceof HTMLMediaElement)){{if(n==="calculative"&&!t)continue;if(n==="singleton"){t?i[n]={}:i[n]=e[n];continue}}i[n]=ct(e[n],t)}return i}return e}const ei={};function Rv(e,t,i){if(!ei[t.fromArrow])return;const n=le(t),{x:r,y:s}=n,a={x:r,y:s};if(a.step=(t.fromArrowSize||10)*i.data.scale,n.next)a.rotate=hi(n.next,n)+90;else{const c=t.calculative.worldAnchors[1];if(!c)return;c.prev?a.rotate=hi(c.prev,n)+90:a.rotate=hi(c,n)+90}e.save(),e.beginPath(),e.setLineDash([]);const l=t.fromArrowColor||t.calculative.color;l&&(e.strokeStyle=l),ei[t.fromArrow](e,t,i,a),e.restore()}function Cv(e,t,i){if(!ei[t.toArrow]||t.calculative.worldAnchors.length<2)return;e.save();const n=qt(t),{x:r,y:s}=n,a={x:r,y:s};if(a.step=(t.toArrowSize||10)*i.data.scale,n.prev)a.rotate=hi(n.prev,n)+90;else{const c=t.calculative.worldAnchors[t.calculative.worldAnchors.length-2];c.next?a.rotate=hi(c.next,n)+90:a.rotate=hi(c,n)+90}e.beginPath(),e.setLineDash([]);const l=t.toArrowColor||t.calculative.color;l&&(e.strokeStyle=l),ei[t.toArrow](e,t,i,a),e.restore()}ei.triangleSolid=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step;e.moveTo(r,n.y-n.step/4),e.lineTo(n.x,n.y),e.lineTo(r,n.y+n.step/4),e.closePath(),e.stroke(),e.fillStyle=e.strokeStyle,e.fill(),e.restore()};ei.triangle=(e,t,i,n)=>{e.save(),e.lineWidth<2&&(e.lineWidth=2),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step;e.moveTo(r,n.y-n.step/4),e.lineTo(n.x,n.y),e.lineTo(r,n.y+n.step/4),e.closePath(),e.stroke(),e.fillStyle=i.data.background||"#ffffff",e.fill(),e.restore()};ei.circleSolid=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.step/2;e.arc(n.x-r,n.y,r,0,2*Math.PI),e.stroke(),e.fillStyle=e.strokeStyle,e.fill(),e.restore()};ei.circle=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.step/2;e.arc(n.x-r,n.y,r,0,2*Math.PI),e.stroke(),e.fillStyle=i.data.background||"#ffffff",e.fill(),e.restore()};ei.diamondSolid=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step,s=n.step/2;e.moveTo(r,n.y),e.lineTo(r+s,n.y-s/2),e.lineTo(n.x,n.y),e.lineTo(r+s,n.y+s/2),e.closePath(),e.stroke(),e.fillStyle=e.strokeStyle,e.fill(),e.restore()};ei.diamond=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step,s=n.step/2;e.moveTo(r,n.y),e.lineTo(r+s,n.y-s/2),e.lineTo(n.x,n.y),e.lineTo(r+s,n.y+s/2),e.closePath(),e.stroke(),e.fillStyle=i.data.background||"#ffffff",e.fill(),e.restore()};ei.line=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step;e.moveTo(r,n.y-n.step/3),e.lineTo(n.x,n.y),e.lineTo(r,n.y+n.step/3),e.stroke(),e.restore()};ei.lineUp=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step;e.moveTo(r,n.y-n.step/3),e.lineTo(n.x,n.y),e.stroke(),e.restore()};ei.lineDown=(e,t,i,n)=>{e.save(),e.translate(n.x,n.y),e.rotate(n.rotate*Math.PI/180),e.translate(-n.x,-n.y);const r=n.x-n.step;e.moveTo(r,n.y+n.step/3),e.lineTo(n.x,n.y),e.stroke(),e.restore()};function gc(e){const t=parseInt,i=Math.round;let n=e.length,r={};if(n>9){const[s,a,l,c]=e=e.split(",");if(n=e.length,n<3||n>4)return null;r.r=t(s[3]=="a"?s.slice(5):s.slice(4)),r.g=t(a),r.b=t(l),r.a=c?parseFloat(c):-1}else{if(n==8||n==6||n<4)return null;n<6&&(e="#"+e[1]+e[1]+e[2]+e[2]+e[3]+e[3]+(n>4?e[4]+e[4]:"")),e=t(e.slice(1),16),n==9||n==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 Ae(e,t,i,n){let r,s,a,l,c,u,h,d=Math.round,g=typeof i=="string";return typeof e!="number"||e<-1||e>1||typeof t!="string"||t[0]!="r"&&t[0]!="#"||i&&!g||(h=t.length>9,h=g?i.length>9?!0:i=="c"?!h:!1:h,c=gc(t),l=e<0,u=i&&i!="c"?gc(i):l?{r:0,g:0,b:0,a:-1}:{r:255,g:255,b:255,a:-1},e=l?e*-1:e,l=1-e,!c||!u)?null:(n?(r=d(l*c.r+e*u.r),s=d(l*c.g+e*u.g),a=d(l*c.b+e*u.b)):(r=d((l*c.r**2+e*u.r**2)**.5),s=d((l*c.g**2+e*u.g**2)**.5),a=d((l*c.b**2+e*u.b**2)**.5)),g=c.a,u=u.a,c=g>=0||u>=0,g=c?g<0?u:u<0?g:g*l+u*e:0,h?"rgb"+(c?"a(":"(")+r+","+s+","+a+(c?","+d(g*1e3)/1e3:"")+")":"#"+(4294967296+r*16777216+s*65536+a*256+(c?d(g*255):0)).toString(16).slice(1,c?void 0:-2))}globalThis.pSBC=Ae;function qa(e,t){const i=gc(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 pr(e,t){if(isNaN(e)){console.warn("realValue not number");return}if(typeof t!="string"){console.warn("collection must be string");return}const[i,n]=[t[0],t[t.length-1]];if(!["[","("].includes(i)){console.warn('collection must start with "[" or "("');return}if(!["]",")"].includes(n)){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[s,a]=[+r[0],+r[1]];if(s>=a){console.warn("startNum must less than endNum");return}return e>s||i==="["&&e===s?e=u){console.warn("startNum must less than endNum");return}if(e>=c&&e<=u)return!0}else if(e==s)return!0;return!1}function It(){return((1+Math.random())*4294967296|0).toString(16).substring(1)}const Xi=e=>{let t=0,i=0,n=0,r=0;return typeof e=="number"?t=i=n=r=e:typeof e=="string"?t=i=n=r=parseInt(e,10):Array.isArray(e)&&(t=e[0],n=Pl(e[1])?e[0]:e[1],r=Pl(e[2])?e[0]:e[2],i=Pl(e[3])?n:e[3]),[t,n,r,i]};function Pl(e){return e==null}async function O_(e){return new Promise((t,i)=>{const n=new FileReader;n.onload=r=>{t(r.target.result)},n.onerror=r=>{i(r)},n.readAsDataURL(e)})}async function N_(e,t,i,n){const r=new FormData;if(r.append("file",e),i)for(const a in i)i.hasOwnProperty(a)&&r.append(a,i[a]);return(await(await fetch(t,{method:"POST",headers:n,body:r})).json()).url}function F_(e,t,i){var n=document.createElement("link");n.href=e,n.rel="stylesheet",t&&(n.onload=t),i&&(n.onerror=i),document.head.appendChild(n)}function Il(e){let t=e||window.location.search.split("?")[1];const i=new URLSearchParams(t);return Object.fromEntries(i.entries())}function Nf(e,t){if(t==null)return e;const i=t.split(".");for(;i.length&&(e=e[i.shift()]););return e}function z_(e,t,i){t!=null&&t.split(".").reduce((n,r,s)=>n[r]=t.split(".").length===++s?i:n[r]||{},e)}function H_(e,t){if(!e||!t)return!1;let i=Ze(e);for(;i;){if(i.id===t.id)return!0;i=Ze(i)}return!1}function Ze(e,t){if(!e||!e.parentId||!e.calculative)return;const n=e.calculative.canvas.store.pens[e.parentId];return t&&Ze(n,t)||n}function Ci(e,t){if(!e||!e.children)return[];const i=[];return e.children.forEach(n=>{const r=t.pens[n];r&&(i.push(r),i.push(...Ci(r,t)))}),i}function Bc(e,t){if(!e||!e.followers)return[];const i=[];return e.followers.forEach(n=>{const r=t.pens[n];r&&!r.parentId&&(i.push(r),i.push(...Bc(r,t)))}),i}function U_(e,t){const{worldRect:i,gradientFromColor:n,gradientToColor:r,gradientAngle:s}=t.calculative;return Sv(e,i,n,r,s)}function W_(e,t){const{worldRect:i,gradientFromColor:n,gradientToColor:r,gradientRadius:s}=t.calculative;if(!n||!r)return;const{width:a,height:l,center:c}=i,{x:u,y:h}=c;let d=a;d{v.addColorStop(y.i,y.color)}),v}function V_(e,t){const{x:i,y:n,ex:r,width:s,height:a,center:l}=t.calculative.worldRect;let c=[{x:r,y:n+a/2},{x:i,y:n+a/2}],u=t.calculative.gradientColors;t.calculative.checked&&(u=t.calculative.onGradientColors);const{angle:h,colors:d}=Qn(u);let g=Oc(h,s,a);return c.forEach(v=>{Gt(v,h,l)}),Ja(e,c,d,g)}function $_(e,t){const{worldRect:i,textGradientColors:n}=t.calculative;if(!n)return;const{width:r,height:s,center:a}=i,{x:l,y:c}=a;let u=r;u{d.addColorStop(g.i,g.color)}),d}function K_(e,t){const{x:i,y:n,ex:r,width:s,height:a,center:l}=t.calculative.worldRect;let c=[{x:r,y:n+a/2},{x:i,y:n+a/2}];const{angle:u,colors:h}=Qn(t.calculative.textGradientColors);let d=Oc(u,s,a);return c.forEach(g=>{Gt(g,u,l)}),Ja(e,c,h,d)}function Oc(e,t,i){const n=Math.atan(i/t)/Math.PI*180;let r=(e-90)%360,s=0;return r>n&&r<180-n||r>180+n&&r<360-n||r<0?(r>270?r=360-r:r>180?r=r-180:r>90&&(r=180-r),s=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),s=Math.abs(t/Math.cos(r/180*Math.PI)/2)),s}function Qn(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 n=[];return i.forEach(r=>{if(/rgba?/.test(r)){let s=r.split(") ");n.push({color:Y_(s[0]+")"),i:parseFloat(s[1])/100})}else{let s=r.split(" ");s.length>2?n.push({color:s[1],i:parseFloat(s[2])/100}):n.push({color:s[0],i:parseFloat(s[1])/100})}}),{angle:parseFloat(t[0]),colors:n}}else return{angle:parseFloat(t[0]),colors:[]}}else return{angle:0,colors:[]}}function Y_(e){if(/rgba?/.test(e)){let t=e.split(",");if(t.length<3)return"";e="#";for(let i=0,n;n=t[i++];)if(i<4)n=parseInt(n.replace(/[^\d]/gi,""),10).toString(16),e+=n.length==1?"0"+n:n;else{n=n.replace(")","");let s=parseInt(n*255+"").toString(16);s=s.length===2?s:"0"+s,e+=s}e=e.toUpperCase()}return e}function X_(e,t){const{x:i,y:n,ex:r,width:s,height:a,center:l}=t.calculative.worldRect;let c=[{x:r,y:n+a/2},{x:i,y:n+a/2}];const{angle:u,colors:h}=Qn(t.calculative.lineGradientColors);let d=Oc(u,s,a);return c.forEach(g=>{Gt(g,u,l)}),Ja(e,c,h,d)}function Ja(e,t,i,n){let r=q_(t[0].x,t[0].y,t[1].x,t[1].y,n),s=e.createLinearGradient(r[0],r[1],r[2],r[3]);return i.forEach(a=>{s.addColorStop(a.i,a.color)}),s}function gn(e,t,i){let n=[];t.calculative.gradientColorStop?n=t.calculative.gradientColorStop:(n=Qn(t.calculative.lineGradientColors).colors,t.calculative.gradientColorStop=n),e.strokeStyle=Ja(e,i,n,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 Tv(e,t){const i=t.calculative.worldAnchors;let n=t.calculative.lineWidth*(t.calculative.gradientSmooth||t.calculative.lineSmooth||0);for(let r=0;r0){let l=i[r-1].curvePoints;l?ba(e,t,n,l[l.length-1],i[r],i[r].curvePoints[0]):ba(e,t,n,i[r-1],i[r],i[r].curvePoints[0]);let c=Zi(n,i[r],i[r].curvePoints[0]);gn(e,t,[c,i[r].curvePoints[1]])}else gn(e,t,[i[r],i[r].curvePoints[0]]),gn(e,t,[i[r].curvePoints[0],i[r].curvePoints[1]]);let s=i[r].curvePoints.length-1;for(let l=1;l0&&r0&&r0&&r0&&r{const q=t.calculative.textLineWidths[D];let Q=0;I==="center"?Q=(A-q)/2:I==="right"&&(Q=A-q),e.fillText(B,p+Q,_+(D+E)*M);const{textDecorationColor:C,textDecorationDash:T,textDecoration:S}=t;S&&i2(e,{x:p+Q,y:_+(D+E)*M,width:q},{textDecorationColor:C,textDecorationDash:T,fontSize:r});const{textStrickoutColor:O,textStrickoutDash:K,textStrickout:Z}=t;Z&&n2(e,{x:p+Q,y:_+(D+E)*M,width:q},{textStrickoutColor:O,textStrickoutDash:K,fontSize:r})}),e.restore()}function i2(e,t,i){const{textDecorationColor:n,textDecorationDash:r,fontSize:s}=i;let{x:a,y:l,width:c}=t;switch(e.textBaseline){case"top":l+=s;break;case"middle":l+=s/2;break}e.save(),e.beginPath(),e.strokeStyle=n||e.fillStyle,e.lineWidth=1,e.moveTo(a,l),e.setLineDash(r||[]),e.lineTo(a+c,l),e.stroke(),e.restore()}function n2(e,t,i){const{textStrickoutColor:n,textStrickoutDash:r,fontSize:s}=i;let{x:a,y:l,width:c}=t;switch(e.textBaseline){case"top":l+=s/2;break;case"bottom":l-=s/2;break}e.save(),e.beginPath(),e.strokeStyle=n||e.fillStyle,e.lineWidth=1,e.moveTo(a,l),e.setLineDash(r||[]),e.lineTo(a+c,l),e.stroke(),e.restore()}function Iv(e,t,i){if(i==null)return;const{fontStyle:n,fontWeight:r,fontSize:s,fontFamily:a,lineHeight:l,canvas:c}=t.calculative,u=c.store;e.save();let h;t.calculative.hover?h=t.hoverTextColor||t.hoverColor||u.options.hoverColor:t.calculative.active&&(h=t.activeTextColor||t.activeColor||u.options.activeColor),e.fillStyle=h||An(t,u),e.font=Rn({fontStyle:n,fontWeight:r,fontFamily:a||u.options.fontFamily,fontSize:s,lineHeight:l});const d=e.measureText(i).width;let g,v;for(const y of t.calculative.worldAnchors){if(!v){v=y;continue}const w=Za(v,y),p=Math.floor(w/d);g="";for(let A=0;A0?l=t.calculative.iconSize:n.width>n.height?l=n.height:l=n.width,e.font=Rn({fontSize:l,fontWeight:a,fontFamily:c}),e.fillStyle=t.calculative.iconColor||An(t,i),t.calculative.iconRotate&&(e.translate(n.center.x,n.center.y),e.rotate(t.calculative.iconRotate*Math.PI/180),e.translate(-n.center.x,-n.center.y)),e.beginPath(),e.fillText(t.calculative.icon,r,s),e.restore()}function Dv(e,t){const i=t.calculative.canvas.store.data.scale,n=t.calculative.canvas.inputDiv.dataset.penId,{x:r,y:s,width:a,height:l}=t.calculative.worldRect;e.save(),e.beginPath(),t.id===n?(e.moveTo(r+a-20*i,s+l/2+2*i),e.lineTo(r+a-14*i,s+l/2-4*i),e.lineTo(r+a-8*i,s+l/2+2*i)):(e.moveTo(r+a-20*i,s+l/2-4*i),e.lineTo(r+a-14*i,s+l/2+2*i),e.lineTo(r+a-8*i,s+l/2-4*i)),e.stroke(),e.restore()}function Rn({fontStyle:e="normal",textDecoration:t="normal",fontWeight:i="normal",fontSize:n=12,fontFamily:r="Arial",lineHeight:s=1}={}){return`${e} ${t} ${i} ${n}px/${s} ${r}`}function Vn(e,t){const{x:i,ex:n,y:r,ey:s}=t.calculative.worldRect||{};t.calculative.flipX&&(e.translate(i+n+.5,.5),e.scale(-1,1)),t.calculative.flipY&&(e.translate(.5,r+s+.5),e.scale(1,-1))}function Qi(e,t,i=!1){const{x:n,y:r}=t.calculative.worldRect.pivot||t.calculative.worldRect.center;e.translate(n,r);let s=t.calculative.rotate*Math.PI/180;i||(t.calculative.flipX&&(s*=-1),t.calculative.flipY&&(s*=-1)),e.rotate(s),e.translate(-n,-r)}function Nn(e,t,i){e.save(),e.translate(.5,.5),e.beginPath();const n=t.calculative.canvas.store,r=t.textFlip||n.options.textFlip,s=t.textRotate||n.options.textRotate;(!r||!s)&&e.save(),Vn(e,t),t.calculative.rotate&&t.name!=="line"&&Qi(e,t),(t.calculative.lineWidth>1||i)&&(e.lineWidth=t.calculative.lineWidth),d2(e,n,t);let a,l=!1,c;t.calculative.disabled?(c=t.disabledColor||n.options.disabledColor||Ae(.4,t.calculative.color||cs(n)),a=t.disabledBackground||n.options.disabledBackground||Ae(.4,t.calculative.background||n.data.penBackground)):t.mouseDownValid&&t.calculative.mouseDown?(c=t.mouseDownColor||Ae(-.4,t.calculative.color||cs(n)),a=t.mouseDownBackground||Ae(-.4,t.calculative.background||n.data.penBackground)):t.switch&&t.calculative.checked?t.calculative.bkType||(a=t.onBackground):t.calculative.hover?(c=t.hoverColor||n.options.hoverColor,a=t.hoverBackground||n.options.hoverBackground):t.calculative.active?(c=t.activeColor||n.options.activeColor,a=t.activeBackground||n.options.activeBackground):t.calculative.isDock&&(t.type===jt.Line?c=n.options.dockPenColor:a=qa(n.options.dockPenColor,.2));const u=t.calculative.strokeImg;if(t.calculative.strokeImage&&u)e.strokeStyle=c||e.createPattern(u,"repeat");else{let d;t.calculative.strokeType?t.calculative.lineGradientColors?t.name==="line"?l=!0:t.calculative.lineGradient?d=t.calculative.lineGradient:(d=X_(e,t),t.calculative.lineGradient=d):d=t2(e,t):d=t.calculative.color||(t.type?n.data.lineColor:"")||cs(n),e.strokeStyle=c||d}const h=t.calculative.backgroundImg;if(t.calculative.backgroundImage&&h)e.fillStyle=a||e.createPattern(h,"repeat"),a=!0;else{let d;t.calculative.bkType===Br.Linear?t.calculative.gradientColors?t.calculative.gradient?d=t.calculative.gradient:(d=V_(e,t),t.calculative.gradient=d):d=U_(e,t):t.calculative.bkType===Br.Radial?t.calculative.gradientColors?t.calculative.radialGradient?d=t.calculative.radialGradient:(d=j_(e,t),t.calculative.radialGradient=d):d=W_(e,t):d=t.calculative.background||n.data.penBackground,e.fillStyle=a||d,a=!!d}if(Mv(e,t),Bv(e,t),$n(e,t),t.calculative.lineDash&&e.setLineDash(t.calculative.lineDash.map(d=>d*t.calculative.canvas.store.data.scale)),t.calculative.lineDashOffset&&(e.lineDashOffset=t.calculative.lineDashOffset),t.calculative.shadowColor&&(e.shadowColor=t.calculative.shadowColor,e.shadowOffsetX=t.calculative.shadowOffsetX,e.shadowOffsetY=t.calculative.shadowOffsetY,e.shadowBlur=t.calculative.shadowBlur),l?(Tv(e,t),Nv(!0,e,t,n)):(Ov(!0,e,t,n,a),jv(e,t)),!(t.image&&t.calculative.img)&&t.calculative.icon&&Lv(e,t),t.dropdownList&&Dv(e,t),(!r||!s)&&e.restore(),r&&!s&&Vn(e,t),!r&&s&&t.calculative.rotate&&t.name!=="line"&&Qi(e,t,!0),Pv(e,t),t.type===jt.Line&&t.fillTexts)for(const d of t.fillTexts)Iv(e,t,d);e.restore()}function Mv(e,t){const i=t.lineCap||(t.type?"round":"square");i?e.lineCap=i:t.type&&(e.lineCap="round")}function Bv(e,t){const i=t.lineJoin;i?e.lineJoin=i:t.type&&(e.lineJoin="round")}function ja(e,t,i,n){var u;e.save(),i&&e.translate(-i.x,-i.y),(u=e.setAttrs)==null||u.call(e,t);let r=!1;const s=t.calculative.canvas.store,a=t.textFlip||s.options.textFlip,l=t.textRotate||s.options.textRotate;e.beginPath(),(!a||!l)&&e.save(),t.calculative.flipX&&(e.translate(t.calculative.worldRect.x+t.calculative.worldRect.ex,0),e.scale(-1,1)),t.calculative.flipY&&(e.translate(0,t.calculative.worldRect.y+t.calculative.worldRect.ey),e.scale(1,-1)),t.calculative.rotate&&t.name!=="line"&&Qi(e,t),(t.calculative.lineWidth>1||n)&&(e.lineWidth=t.calculative.lineWidth);let c;if(t.calculative.hover)e.strokeStyle=t.hoverColor||s.options.hoverColor,e.fillStyle=t.hoverBackground||s.options.hoverBackground,c=t.hoverBackground||s.options.hoverBackground;else if(t.calculative.active)e.strokeStyle=t.activeColor||s.options.activeColor,e.fillStyle=t.activeBackground||s.options.activeBackground,c=t.activeBackground||s.options.activeBackground;else{if(t.strokeImage)t.calculative.strokeImg&&(e.strokeStyle=e.createPattern(t.calculative.strokeImg,"repeat"),c=!0);else{let h;t.calculative.strokeType&&t.calculative.lineGradientColors&&t.name==="line"?r=!0:h=t.calculative.color||cs(s),e.strokeStyle=h}t.backgroundImage?t.calculative.backgroundImg&&(e.fillStyle=e.createPattern(t.calculative.backgroundImg,"repeat"),c=!0):(e.fillStyle=t.background,c=!!t.background)}if(Mv(e,t),Bv(e,t),$n(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?(Tv(e,t),Nv(!0,e,t,s)):(Ov(!1,e,t,s,c),jv(e,t)),t.calculative.img?(e.save(),e.shadowColor="",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0,Pr(e,t),e.restore()):t.calculative.icon&&Lv(e,t),t.dropdownList&&Dv(e,t),(!a||!l)&&e.restore(),a&&!l&&(t.calculative.flipX&&(e.translate(t.calculative.worldRect.x+t.calculative.worldRect.ex,0),e.scale(-1,1)),t.calculative.flipY&&(e.translate(0,t.calculative.worldRect.y+t.calculative.worldRect.ey),e.scale(1,-1))),!a&&l&&t.calculative.rotate&&t.name!=="line"&&Qi(e,t,!0),Pv(e,t),t.type===jt.Line&&t.fillTexts)for(const h of t.fillTexts)Iv(e,t,h);e.restore()}function Ov(e=!0,t,i,n,r){if(i.name==="drawCommand")return;const s=e?n.path2dMap.get(i):At.path2dDraws[i.name];let a=null,l=null;if(i.type===jt.Line&&(i.fromLineCap&&i.fromLineCap!=="butt"&&(t.lineCap="butt",a=new Path2D,a.moveTo(i.calculative.worldAnchors[0].x,i.calculative.worldAnchors[0].y),a.lineTo(i.calculative.worldAnchors[0].x,i.calculative.worldAnchors[0].y)),i.toLineCap&&i.toLineCap!=="butt"&&(t.lineCap="butt",l=new Path2D,l.moveTo(i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].x,i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].y),l.lineTo(i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].x,i.calculative.worldAnchors[i.calculative.worldAnchors.length-1].y))),s){if(i.type===jt.Line&&i.borderWidth){t.save(),t.beginPath();const u=i.calculative.lineWidth+i.calculative.borderWidth;t.lineWidth=u,t.strokeStyle=i.borderColor,a&&(t.save(),t.lineCap=i.fromLineCap,t.stroke(a),t.restore()),s instanceof Path2D?(r&&t.fill(s),u&&t.stroke(s)):(s(i,t),r&&t.fill(),u&&t.stroke()),l&&(t.save(),t.lineCap=i.toLineCap,t.stroke(l),t.restore()),t.restore()}s instanceof Path2D?i.type?i.close&&r&&t.fill(s):r&&t.fill(s):(t.save(),s(i,t),r&&t.fill(),t.restore());const c=i.calculative.progress;if(c!=null){t.save();const{ex:u,x:h,y:d,width:g,height:v,ey:y}=i.calculative.worldRect;let w=null;if(i.calculative.verticalProgress?w=i.reverseProgress?t.createLinearGradient(h,d,h,d+v*c):t.createLinearGradient(h,y,h,d+v*(1-c)):w=i.reverseProgress?t.createLinearGradient(u,d,h+g*(1-c),d):t.createLinearGradient(h,d,h+g*c,d),i.calculative.progressGradientColors){const{colors:p}=Qn(i.calculative.progressGradientColors);p.forEach(_=>{w.addColorStop(_.i,_.color)})}else{const p=i.calculative.progressColor||i.calculative.color||n.options.activeColor;w.addColorStop(0,p),w.addColorStop(1,p)}w.addColorStop(1,"transparent"),t.fillStyle=w,s instanceof Path2D?t.fill(s):(s(i,t),t.fill()),t.restore()}if(i.calculative.lineWidth&&(s instanceof Path2D?(n.options.svgPathStroke||i.name!=="svgPath")&&(a&&(t.save(),t.lineCap=i.fromLineCap,t.stroke(a),t.restore()),t.stroke(s),l&&(t.save(),t.lineCap=i.toLineCap,t.stroke(l),t.restore())):(s(i,t),t.stroke())),i.type){if(i.calculative.animatePos){if(t.save(),Fv(t,i,n),i.lineAnimateType===Je.Arrow||i.lineAnimateType===Je.WaterDrop){let u=Zv(i,t);u instanceof Path2D?(t.stroke(u),t.fill(u)):(t.stroke(),t.fill())}else s instanceof Path2D?(a&&!i.lineAnimateType&&(t.save(),t.lineCap=i.fromLineCap,t.stroke(a),t.restore()),t.lineCap=i.lineCap,t.stroke(s)):(s(i,t),t.stroke());t.restore()}i.fromArrow&&Rv(t,i,n),i.toArrow&&Cv(t,i,n),i.calculative.active&&!i.calculative.pencil&&!n.options.disableAnchor&&!n.data.locked&&zv(t,i)}}}function Nv(e=!0,t,i,n){const r=e?n.path2dMap.get(i):At.path2dDraws[i.name];if(r&&i.type){if(i.calculative.animatePos){if(t.save(),Fv(t,i,n),t.beginPath(),r instanceof Path2D)if(i.lineName==="polyline"||i.lineName==="line")if(i.lineAnimateType===Je.Arrow||i.lineAnimateType===Je.WaterDrop){const s=Zv(i);t.stroke(s),t.fill(s)}else i.calculative.gradientSmooth||i.calculative.lineSmooth?(i.calculative.gradientAnimatePath||(i.calculative.gradientAnimatePath=Nc(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&&Rv(t,i,n),i.toArrow&&Cv(t,i,n),i.calculative.active&&!i.calculative.pencil&&!n.options.disableAnchor&&!n.data.locked&&zv(t,i)}}function Fv(e,t,i){e.strokeStyle=t.animateColor||i.options.animateColor,t.animateShadow&&(e.shadowBlur=t.animateShadowBlur||t.animateLineWidth||6,e.shadowColor=t.animateShadowColor||t.animateColor||i.options.animateColor),t.calculative.animateLineWidth&&(e.lineWidth=t.calculative.animateLineWidth*i.data.scale);let n=0;switch(t.lineAnimateType){case Je.Beads:t.animateReverse?e.lineDashOffset=t.calculative.animatePos:e.lineDashOffset=t.length-t.calculative.animatePos,n=t.calculative.lineWidth||5,n<5&&(n=5);const r=t.animateLineDash&&t.animateLineDash.map(s=>s*n/5);e.setLineDash(r||[n,n*2]);break;case Je.Dot:t.animateReverse?e.lineDashOffset=t.calculative.animatePos:e.lineDashOffset=t.length-t.calculative.animatePos,n=t.calculative.animateDotSize||t.calculative.lineWidth*2||6,n<6&&(n=6),n>40&&(n=40),e.lineWidth=(t.calculative.animateLineWidth||n)*i.data.scale,e.setLineDash([.1,t.length]);break;case Je.Arrow:e.fillStyle=t.animateColor||i.options.animateColor,e.lineWidth=1;break;case Je.WaterDrop:e.fillStyle=t.animateColor||i.options.animateColor,e.lineWidth=1;break;default:t.animateReverse?(e.lineDashOffset=Number.EPSILON,e.setLineDash([0,t.length-t.calculative.animatePos+1,t.calculative.animatePos])):e.setLineDash([t.calculative.animatePos,t.length+.01-t.calculative.animatePos]);break}}function cs(e){const{data:t,options:i}=e;return t.color||i.color}function zv(e,t){const i=t.calculative.canvas.store;e.save(),e.lineWidth=1,e.fillStyle=t.activeColor||i.options.activeColor,t.calculative.worldAnchors.forEach(n=>{!n.hidden&&!n.isTemp&&r2(e,n,t)}),e.restore()}function r2(e,t,i){if(!t)return;const n=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),n?(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 Hv(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,ae(i),ee(i),e.pivot&&mc(i,e.pivot);else{const n=t.pens[e.parentId];let r=n.calculative.worldRect;r||(r=Hv(n)),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,n.flipX&&(i.x=r.width-(i.x-r.x+i.width)+r.x),n.flipY&&(i.y=r.height-(i.y-r.y+i.height)+r.y),ae(i),i.rotate=r.rotate+e.rotate,ee(i),e.pivot&&mc(i,e.pivot)}return e.calculative.worldRect=i,Fc(e,i),i}function Fc(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 Da(e){const t=ct(e.calculative.worldRect);if(delete t.pivot,!e.parentId){Object.assign(e,t);return}const n=e.calculative.canvas.store.pens[e.parentId].calculative.worldRect;Object.assign(e,mn(t,n))}function Ir(e){const t=e.calculative.canvas.store;let i=[];if(e.anchors){let n=ct(e.anchors);e.flipX&&n.forEach(r=>{r.x=.5-(r.x-.5)}),e.flipY&&n.forEach(r=>{r.y=.5-(r.y-.5)}),n.forEach(r=>{i.push(s2(e,r))})}if(!i.length&&!e.type&&!e.calculative.canvas.parent.isCombine(e)){const{x:n,y:r,width:s,height:a}=e.calculative.worldRect;i=t.options.defaultAnchors.map((l,c)=>({id:`${c}`,penId:e.id,x:n+s*l.x,y:r+a*l.y}))}e.calculative.rotate&&i.forEach(n=>{Gt(n,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(n=>{n.id,e.calculative.activeAnchor.id})),e.calculative.gradientAnimatePath=void 0}function Uv(e){var t;if((t=e.children)!=null&&t.length){let i=e.calculative.worldRect;e.children.forEach(n=>{const r=e.calculative.canvas.store.pens[n];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,ee(r.calculative.initRect)),Uv(r)})}}function s2(e,t){const i={...t},{x:n,y:r,width:s,height:a}=e.calculative.worldRect;return i.x=n+s*t.x,i.y=r+a*t.y,t.prev&&(i.prev={penId:e.id,connectTo:t.prev.connectTo,x:n+s*t.prev.x,y:r+a*t.prev.y}),t.next&&(i.next={penId:e.id,connectTo:t.next.connectTo,x:n+s*t.next.x,y:r+a*t.next.y}),i}function zf(e,t){const{paddingTop:i,paddingBottom:n,paddingLeft:r,paddingRight:s}=t.calculative;let a=r,l=i,c=t.calculative.worldRect.width-r-s,u=t.calculative.worldRect.height-i-n,h=t.calculative.iconLeft,d=t.calculative.iconTop;h&&Math.abs(h)<1&&(h=t.calculative.worldRect.width*h),d&&Math.abs(d)<1&&(d=t.calculative.worldRect.height*d),a+=h||0,l+=d||0,c-=h||0,u-=d||0;let g=t.calculative.iconRotate||0;if(t.parentId){const v=e[t.parentId].calculative;v&&(g+=v.rotate,g%=360)}a=t.calculative.worldRect.x+a,l=t.calculative.worldRect.y+l,t.calculative.worldIconRect={x:a,y:l,width:c,height:u,rotate:g},ae(t.calculative.worldIconRect),ee(t.calculative.worldIconRect)}function br(e,t,i){ms(e.calculative.worldRect,t,i,e.pivot),e.calculative.initRect&&ms(e.calculative.initRect,t,i,e.pivot),Wv(e,t,i),e.calculative.x&&Wa(e.calculative,t,i),e.type&&Ir(e)}function Wv(e,t,i){var n;!e||(n=e.children)!=null&&n.length&&e.children.forEach(r=>{const s=e.calculative.canvas.store.pens[r];s&&(s.calculative.initRect&&ms(s.calculative.initRect,t,i),Wv(s,t,i))})}function a2(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&&Gt(t,-e.rotate,e.calculative.worldRect.center);const n={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(n)}return i}function o2(e,t,i){e.anchors||(e.anchors=[]),e.calculative.worldAnchors||(e.calculative.worldAnchors=[]);const n=nk(e,t,i);return e.calculative.worldAnchors.splice(i+1,0,n),e.anchors.splice(i+1,0,hs(n,e.calculative.worldRect)),e.calculative.activeAnchor=n,n}function l2(e,t){if(!e||!e.calculative.worldAnchors)return;let i=e.calculative.worldAnchors.findIndex(n=>n.id===t.id);i>-1&&e.calculative.worldAnchors.splice(i,1),i=e.anchors.findIndex(n=>n.id===t.id),i>-1&&e.anchors.splice(i,1)}function Or(e,t){if(!t||!t.calculative||!t.calculative.worldRect.center)return Lt.None;if(e.anchorId){let i=t.anchors.filter(n=>n.id===e.anchorId);if(i.length&&i[0].direction>-1)return i[0].direction}return l_(e,t.calculative.worldRect.center)}function Cr(e,t){let i=1/0,n;return e.calculative.worldAnchors.forEach(r=>{const s=Za(t,r);i>s&&(i=s,n=r)}),n}function Hf(e,t,i){e.x+=t,e.y+=i,e.anchors&&e.anchors.forEach(n=>{ls(n,t,i)}),e.calculative.worldAnchors&&e.calculative.worldAnchors.forEach(n=>{ls(n,t,i)})}function zc(e){if(e&&e.calculative&&e.calculative.worldAnchors.length){let t=qt(e);if(!e.anchors||!e.anchors.length)for(;e.calculative.worldAnchors.length&&t!==e.calculative.activeAnchor;)e.calculative.worldAnchors.pop(),t=qt(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 we(e,t,i,n){var l,c,u,h,d,g;if(!e||!t||!i||!n||t.twoWay===Ee.DisableConnected||t.twoWay===Ee.Disable||n.twoWay===Ee.DisableConnectTo||n.twoWay===Ee.Disable)return;if(t.twoWay===Ee.In){if(i.calculative.worldAnchors.length===1)return;const v=qt(i);if(n.id!==v.id)return}if(t.twoWay===Ee.Out){const v=le(i);if(n.id!==v.id)return}if(n.connectTo===e.id&&n.anchorId===t.id)return;if(n.connectTo){const v=e.calculative.canvas.store.pens[n.connectTo];Tr(v,Fn(v,n.anchorId),i,n)}e.connectedLines||(e.connectedLines=[]),e.connectedLines.findIndex(v=>v.lineId===i.id&&v.lineAnchor===n.id&&v.anchor===t.id)<0&&e.connectedLines.push({lineId:i.id,lineAnchor:n.id,anchor:t.id}),n.connectTo=e.id,n.anchorId=t.id,e.type&&we(i,n,e,t),e.calculative.canvas.store.emitter.emit("connectLine",{line:i,lineAnchor:n,pen:e,anchor:t});let s=((l=i.calculative.worldAnchors)==null?void 0:l.length)>=2?(c=i.calculative.worldAnchors)==null?void 0:c[0].connectTo:void 0,a=((u=i.calculative.worldAnchors)==null?void 0:u.length)>=2?(d=i.calculative.canvas.store.pens[(h=i.calculative.worldAnchors)==null?void 0:h[0].connectTo])==null?void 0:d.anchors.find(v=>{var y;return v.id===((y=i.calculative.worldAnchors)==null?void 0:y[0].anchorId)}):void 0;return(g=e.onConnectLine)==null||g.call(e,e,{line:i,lineAnchor:n,pen:e,anchor:t,fromPen:s,fromAnchor:a}),!0}function Tr(e,t,i,n){if(!(!e||!t||!i||!n)&&!(!e.connectedLines||!e.connectedLines.length))return i.lastConnected||(i.lastConnected={}),i.lastConnected[e.id]||(i.lastConnected[e.id]=ct(e.connectedLines)),e.connectedLines.forEach((r,s,a)=>{(r.lineId===i.id||r.lineId===i.id)&&r.lineAnchor===n.id&&r.anchor===t.id&&a.splice(s,1)}),n.connectTo=void 0,n.anchorId=void 0,e.type&&t.connectTo===i.id&&t.anchorId===n.id&&Tr(i,n,e,t),e.calculative.canvas.store.emitter.emit("disconnectLine",{line:i,lineAnchor:n,pen:e,anchor:t}),!0}function Fn(e,t){var i;if(!(!e||!t))return(i=e.calculative.worldAnchors)==null?void 0:i.find(n=>n.id===t)}function le(e){if(!(!e||!e.calculative.worldAnchors))return e.calculative.worldAnchors[0]}function qt(e){if(!(!e||!e.calculative.worldAnchors))return e.calculative.worldAnchors[e.calculative.worldAnchors.length-1]}function c2(e,t){var n,r;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 s of e.frames){e.calculative.duration+=s.duration;for(const a in s)a!=="duration"&&!e[a]&&a==="scale"&&(e[a]=1)}}if(e.animateCycle||(e.animateCycle=1/0),e.calculative.start){let s=0;const a=Math.ceil((t-e.calculative.start)/e.calculative.duration);if(a>e.animateCycle)return e.currentAnimation=void 0,e.calculative.start=void 0,Wf(e,1),0;const l=(t-e.calculative.start)%e.calculative.duration;let c=0;for(const d of e.frames)if(c+=d.duration,l>c)++s;else break;if(!e.frames[s])return!0;e.calculative.frameDuration=e.frames[s].duration,e.calculative.frameStart=e.calculative.start+e.calculative.duration*(a-1),e.calculative.frameEnd=e.calculative.frameStart+e.calculative.frameDuration;const u=s!==e.calculative.frameIndex,h=a>e.calculative.cycleIndex;if(u&&(e.calculative.frameIndex=s),h&&(e.calculative.cycleIndex=a),u||h)if(e.calculative.x=e.calculative.initRect.x,e.calculative.y=e.calculative.initRect.y,((r=e.children)==null?void 0:r.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,s>0){e.prevFrame={};const d=e.frames[s-1];for(const g in d)e.prevFrame[g]=d[g];Object.assign(e.prevFrame,{rotate:d.rotate||0,x:d.x||0,y:d.y||0,scale:d.scale||1})}else Uf(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=ct(e.calculative.worldRect),e.parentId&&(e.calculative.initRelativeRect={x:e.x,y:e.y,width:e.width,height:e.height}),(n=e.children)!=null&&n.length){const s=e.calculative.canvas.store;e.calculative.childrenVisible={},e.children.forEach(a=>{e.calculative.childrenVisible[a]=s.pens[a].visible})}e.calculative.initRect.rotate=e.calculative.rotate||0,Uf(e)}const i=(t-e.calculative.frameStart)/e.calculative.frameDuration%1;return Wf(e,i),!0}function Uf(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 Wf(e,t){var n,r;if(t<0)return;t>1&&(t=1);const i=e.frames[e.calculative.frameIndex];for(const s in i)if(s!=="duration"){if(s==="scale"){e.calculative.worldRect=ct(e.calculative.initRect),ms(e.calculative.worldRect,e.prevFrame.scale,e.calculative.worldRect.center);const a=e.prevFrame.scale+(i[s]-e.prevFrame.scale)*t;ms(e.calculative.worldRect,a/e.prevFrame.scale,e.calculative.worldRect.center),e.calculative.patchFlags=!0}else if(s==="x"){const a=Dl(e,s,e.calculative.frameIndex);e.calculative.worldRect.x=e.calculative.initRect.x+a,e.calculative.worldRect.ex=e.calculative.initRect.ex+a,Hn(e.calculative.worldRect,i[s]*t*e.calculative.canvas.store.data.scale,0),e.calculative.patchFlags=!0}else if(s==="y"){const a=Dl(e,s,e.calculative.frameIndex);e.calculative.worldRect.y=e.calculative.initRect.y+a,e.calculative.worldRect.ey=e.calculative.initRect.ey+a,Hn(e.calculative.worldRect,0,i[s]*t*e.calculative.canvas.store.data.scale),e.calculative.patchFlags=!0}else if(s==="rotate"){e.prevFrame[s]>=360&&(e.prevFrame[s]%=360);const a=Dl(e,s,e.calculative.frameIndex),l=(e.calculative.initRect.rotate+a+i[s]*t)%360-(e.calculative.rotate||0);(n=e.children)!=null&&n.length?e.calculative.canvas.rotatePen(e,l,e.calculative.initRect):e.calculative.rotate=(e.calculative.initRect.rotate+a+i[s]*t)%360,e.calculative.patchFlags=!0}else if(s==="image")e.image=i.image,e.calculative.image=void 0,e.calculative.canvas.loadImage(e),e.canvasLayer===zt.CanvasImageBottom?e.calculative.canvas.canvasImageBottom.init():e.canvasLayer===zt.CanvasImage&&e.calculative.canvas.canvasImage.init();else if(h2(i[s],s,e)){e.prevFrame[s]==null&&(s==="globalAlpha"?e.prevFrame[s]=1:e.prevFrame[s]=0);const a=e.prevFrame[s]+(i[s]-e.prevFrame[s])*t;e.calculative[s]=Math.round(a*100)/100}else{if(s==="visible"){if(e.calculative.image)e.canvasLayer===zt.CanvasImageBottom?e.calculative.canvas.canvasImageBottom.init():e.canvasLayer===zt.CanvasImage&&e.calculative.canvas.canvasImage.init();else if((r=e.children)!=null&&r.length){const l=Ci(e,e.calculative.canvas.store);e.calculative.canvas.initImageCanvas(l)}}e.calculative[s]=i[s];const a={};a[s]=i[s],Hc(e,a)}s==="text"&&Es(e)}}function h2(e,t,i){const n=["strokeType","bkType","showChild"];return typeof e=="number"&&i.linear!==!1&&!n.includes(t)}function u2(e,t){if(e.calculative.start===0)return e.calculative.start=void 0,0;if(e.animateCycle||(e.animateCycle=1/0),e.animateSpan||(e.animateSpan=1),e.calculative.animatePos+=e.animateSpan*(e.calculative.canvas.store.data.scale||1),!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){if(++e.calculative.cycleIndex,e.calculative.cycleIndex>e.animateCycle)return e.currentAnimation=void 0,e.calculative.start=void 0,0;e.calculative.animatePos=e.animateSpan}return!0}function Rr(e,t=!0){if(!e.children||e.childActive===!1)return;const i=e.calculative.canvas.store;e.children.forEach(n=>{const r=i.pens[n];r&&(r.calculative.active=t,Rr(r,t))})}function rs(e,t=!0){if(!e)return;const i=e.calculative.canvas.store;e.calculative.hover=t,e.childHover!==!1&&e.children&&e.children.forEach(n=>{var r,s;((r=i.pens[n])==null?void 0:r.hoverColor)==null&&((s=i.pens[n])==null?void 0:s.hoverBackground)==null&&rs(i.pens[n],t)})}function ti(e,t){if(!t)return;const i=e.calculative.canvas.store,n=e.calculative.worldRect;t.style.opacity=e.globalAlpha+"",t.style.position="absolute",t.style.outline="none",t.style.left=n.x+i.data.x+"px",t.style.top=n.y+i.data.y+"px",t.style.width=n.width+"px",t.style.height=n.height+"px",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===Ot.DisableEdit||e.locked===Ot.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")}function Ll(e){return e.every(t=>t.locked)}function qf(e){return e.every(t=>t.disableRotate)}function qv(e,t,i){var n;e.type?(e.calculative.worldAnchors.forEach(r=>{Gt(r,t,i.center)}),f2(e),Da(e)):(e.calculative.rotate?e.calculative.rotate+=t:e.calculative.rotate=t,Gt(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)),(n=e.children)==null||n.forEach(r=>{const s=e.calculative.canvas.store.pens[r];qv(s,t,i)})}function f2(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=bc(e);e.parentId||Object.assign(e,t);const{fontSize:i,lineHeight:n}=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=n,e.calculative.lineHeight=e.lineHeight),ee(t),e.calculative.worldRect=t,Fc(e,t),Ti(e),e.calculative.worldAnchors&&(e.anchors=e.calculative.worldAnchors.map(s=>hs(s,e.calculative.worldRect)))}function jf(e){return e.every(t=>t.disableSize||t.pivot)}function Dl(e,t,i){if(!e.frames||!t)return 0;let n=0;for(let r=0;r{const l=i.pens[a];l&&Gi(l,!0)})),e.calculative.inView=!0,!Va(e,i)||e.visible==!1||e.calculative.visible==!1)e.calculative.inView=!1;else{const{x:a,y:l,width:c,height:u,rotate:h}=e.calculative.worldRect,d={x:a+i.data.x,y:l+i.data.y,width:c,height:u,rotate:h};ae(d),Ji(d,n)||(e.calculative.inView=!1)}(s=e.calculative.singleton)!=null&&s.div&&ti(e,e.calculative.singleton.div)}function d2(e,t,i){if(t.fillWorldTextRect){e.save(),e.fillStyle="#c3deb7";const{x:n,y:r,width:s,height:a}=i.calculative.worldTextRect;e.fillRect(n,r,s,a),e.restore()}}function $n(e,t){const i=t.calculative.globalAlpha;typeof i=="number"&&i<1&&!isNaN(i)&&(e.globalAlpha=i)}function jv(e,t){const i=v2(e,t)||At.canvasDraws[t.name];i&&(e.save(),i(e,t),e.restore())}function v2(e,t){const i=t.drawCommand;if(!(!i||t.name==="line"))return(n,r)=>{i.forEach(s=>{try{s.steps=s.steps.flat(1/0),s.steps.reduce((a,l)=>{const c=g2(l,r,a.x,a.y);try{if(c.c){if(c.c.startsWith("_")){const h=c.c.split("_")[1];return typeof c.v.value=="number"&&(c.v.value*=r.calculative.canvas.store.data.scale),(c.p||n)[h]=c.v.value,{x:a.x,y:a.y}}let u=[];for(const h in c.v)u.push(c.v[h]);return(c.p||n)[c.c](...u),{x:c.startX||c.v.x,y:c.startY||c.v.y}}return{x:a.x,y:a.y}}catch{}},{})}catch{}}),n.stroke()}}function g2(e,t,i,n){return{visio:m2,dxf:y2}[t.parseType](e,t,i,n)}function y2(e,t,i,n){var h,d;const{x:r,y:s,width:a,height:l}=t.calculative.worldRect,{originWidth:c,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*(a/c)+r,y:e.v.y*(l/u)+s}};case"lineTo":return{c:"lineTo",v:{x:e.v.x*(a/c)+r,y:e.v.y*(l/u)+s}};case"arc":return{c:"ellipse",v:{x:e.v.x*(a/c)+r,y:e.v.y*(l/u)+s,rx:e.v.xr*(a/c),ry:e.v.yr*(l/u),rotation:e.v.rotation||0,startAngle:e.v.startAngle,endAngle:e.v.endAngle,a:(h=e.v.aclockwise)!=null?h:!0}};case"ellipse":return{c:"ellipse",v:{x:e.v.x*(a/c)+r,y:e.v.y*(l/u)+s,rx:e.v.xr*(a/c),ry:e.v.yr*(l/u),rotation:e.v.rotation||0,startAngle:e.v.startAngle,endAngle:e.v.endAngle,a:(d=e.v.aclockwise)!=null?d:!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 g={c:e.c,v:{...e.v}};return g.v.x!==void 0&&(g.v.x=e.v.x*(a/c)+r),g.v.y!==void 0&&(g.v.y=e.v.y*(l/u)+s),g}}function m2(e,t,i,n){const{x:r,y:s,width:a,height:l}=t.calculative.worldRect,{width:c,height:u}=t.origin;switch(e.c){case"MoveTo":return{c:"moveTo",v:{x:+e.v.X*100*(a/c)+r,y:+e.v.Y*100*(l/u)+s}};case"RelMoveTo":return{c:"moveTo",v:{x:+e.v.X*c*(a/c)+r,y:+e.v.Y*u*(l/u)+s}};case"LineTo":return{c:"lineTo",v:{x:+e.v.X*100*(a/c)+r,y:+e.v.Y*100*(l/u)+s}};case"RelLineTo":return{c:"lineTo",v:{x:+e.v.X*c*(a/c)+r,y:+e.v.Y*u*(l/u)+s}};case"Ellipse":let h=e.v.X,d=e.v.Y,g=Math.abs(e.v.A-e.v.C),v=Math.abs(e.v.B-e.v.D);return{c:"ellipse",v:{x:h*100*(a/c)+r,y:d*100*(l/u)+s,radiuX:g*100*(a/c),radiuY:v*100*(l/u),rotation:0,startAngle:0,endAngle:Math.PI*2,anticlockwise:!0}};case"EllipticalArcTo":const y=e.v.X*100*(a/c)+r,w=e.v.Y*100*(l/u)+s,p=e.v.A*100*(a/c)+r,_=e.v.B*100*(l/u)+s;e.v.C;const A=e.v.D*(a/l)*(u/c),x=(y-i)*(_-n)-(w-n)*(p-i)>0,E=Vf(i,n,y,w,p,_,A);return!e.orign&&(e.orign={}),!e.orign.startA&&(e.orign.startA=xa(E.x0,E.y0,i,n)),!e.orign.endA&&(e.orign.endA=xa(E.x0,E.y0,y,w)),{c:"ellipse",v:{centerX:E.x0,centerY:E.y0,radiuX:E.a,radiuY:E.b,rotation:0,startAngle:e.orign.startA,endAngle:e.orign.endA,anticlockwise:x},startX:y,startY:w};case"RelEllipticalArcTo":const I=e.v.X*c*(a/c)+r,M=e.v.Y*u*(l/u)+s,B=e.v.A*c*(a/c)+r,D=e.v.B*u*(l/u)+s;e.v.C;const q=e.v.D*(a/l)*(u/c),Q=(I-i)*(D-n)-(M-n)*(B-i)>0,C=Vf(i,n,I,M,B,D,q);return!e.orign&&(e.orign={}),!e.orign.startA&&(e.orign.startA=xa(C.x0,C.y0,i,n)),!e.orign.endA&&(e.orign.endA=xa(C.x0,C.y0,I,M)),{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:Q},startX:I,startY:M};case"ArcTo":let T=e.v.X*100*a/c+r,S=e.v.Y*100*l/u+s,O=e.v.A*100*(a/l)*(u/c),K=(i+T)/2,Z=(n+S)/2,st=Math.sqrt((T-i)**2+(S-n)**2),$=st**2/(8*O)+O/2,z=-(S-n)/st,V=(T-i)/st,Y=K+z*$,U=Z+V*$,tt=Y,rt=U,nt=Math.atan2(n-rt,i-tt),ft=Math.atan2(S-rt,T-tt);return{c:"arc",v:{x:tt,y:rt,radius:$,startAngle:nt,endAngle:ft,aclockwise:!0}};default:const lt=ct(e);return Object.entries(lt.v).forEach(([ut,b])=>{var k,P;(k=ut.endsWith)!=null&&k.call(ut,"_x")?typeof b=="number"&&(lt.v[ut]=b*(a/c)+r):(P=ut.endsWith)!=null&&P.call(ut,"_y")?typeof b=="number"&&(lt.v[ut]=b*(l/u)+s):typeof b=="number"&&(lt.v[ut]=b)}),lt}}function Hc(e,t){for(const i in t)_v.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,Ti(e)):e.calculative[i]=t[i]);if(e.calculative.canvas.parent.isCombine(e)){const i=e.children;i==null||i.forEach(n=>{let r=ct(t);e.calculative.childrenVisible&&e.calculative.childrenVisible[n]===!1&&delete r.visible;const s=e.calculative.canvas.store.pens[n];s&&Hc(s,r)})}}function Vf(e,t,i,n,r,s,a){let l=(e-i)*(e+i)*(n-s)-(i-r)*(i+r)*(t-n)+a*a*(t-n)*(n-s)*(t-s),c=2*((e-i)*(n-s)-(i-r)*(t-n)),u=l/c,h=(e-i)*(i-r)*(e-r)+a*a*((i-r)*(t-n)*(t+n)-(e-i)*(n-s)*(n+s)),d=2*a*a*((i-r)*(t-n)-(e-i)*(n-s)),g=h/d,v=Math.sqrt(Math.pow(e-u,2)+Math.pow(a*(t-g),2)),y=v/a;return{x0:u,y0:g,a:v,b:y}}function xa(e,t,i,n){let r=i-e,s=n-t,a=Math.atan2(s,r);return a<0&&(a+=2*Math.PI),a}function $f(e,t,i){let n,r,s=1/0,a=1/0;const l=8;for(const c of e.data.pens){if(c.calculative.inView===!1)continue;Uc(c).forEach(h=>{if(h===t||h===i)return;let d=(c.calculative.worldRect.center.x-t.x)*(c.calculative.worldRect.center.x-t.x)+(c.calculative.worldRect.center.y-t.y)*(c.calculative.worldRect.center.y-t.y);const g=Math.abs(h.x-t.x);g>0&&g0&&v{s.x+=n.x,s.y+=n.y})):(ee(t),r=[t.center,...tn(t)]),Vv(e,r,t,!0)}function Uc(e){if(e.type){if(e.type===jt.Line)return e.calculative.worldAnchors}else{const t=tn(e.calculative.worldRect);return ee(e.calculative.worldRect),[...e.calculative.worldAnchors,...t,e.calculative.worldRect.center]}}function w2(e,t,i,n){const r=tn(t);return Vv(e,r,t)}function Vv(e,t,i,n=!1){let r,s,a=1/0,l=1/0;const c=10,u=A2(i,c);return e.data.pens.forEach(h=>{const{inView:d,worldRect:g,active:v}=h.calculative;if(d===!1||!n&&v||E2(u,g)||h.type&&e.active.some(w=>$v(e,w,h)))return;const y=Uc(h);if(!!y)for(const w of y)for(const p of t){const _=w.x-p.x,A=w.y-p.y,x=Math.abs(_),E=Math.abs(A);i.center||(i.center={x:i.x+i.width/2,y:i.y+i.height/2}),x{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 a=new Set,l=new Map;e.has(n)&&e.get(n)?a=e.get(n):(l.set(n,i[n]),e.set(n,a)),s?a.delete(r):a.add(r);let c=l.get(n),u=(...h)=>{c==null||c(...h),a.forEach(d=>{d(...h)})};i[n]=u}}let x2=b2();function _2(e){return!e.name&&!e.install?(console.error("installPenPlugin Error: Validation Failed"),!1):!0}function yn(e,t){if(!t)return;if(t.ex==null&&ae(t),!t.rotate||t.rotate%360===0)return e.x>t.x&&e.xt.y&&e.y{Gt(n,t.rotate,t.pivot||t.center)}),k2(e,i)}function Kn(e,t,i=0){const{x:n,y:r,ex:s,ey:a}=t;return e.x>=n-i&&e.x<=s+i&&e.y>=r-i&&e.y<=a+i}function ee(e){e.center||(e.center={}),e.center.x=e.x+e.width/2,e.center.y=e.y+e.height/2}function ae(e){e.ex=e.x+e.width,e.ey=e.y+e.height}function mc(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 k2(e,t){if(t.length<3)return!1;let i=!1,n=t[t.length-1];for(const r of t)n.y>e.y!=r.y>e.y&&r.x+(e.y-r.y)*(n.x-r.x)/(n.y-r.y)>e.x&&(i=!i),n=r;return i}function pi(e){const t=[];e.forEach(n=>{if(n.isRuleLine)return;const r=n.calculative.worldRect;if(r){const s=tn(r);t.push(...s)}});const i=As(t);return ee(i),i}function tn(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||ee(e),t.forEach(i=>{Gt(i,e.rotate,e.pivot||e.center)})),t}function As(e){let t=1/0,i=1/0,n=-1/0,r=-1/0;return e==null||e.forEach(s=>{!isFinite(s.x)||!isFinite(s.y)||(t=Math.min(t,s.x),i=Math.min(i,s.y),n=Math.max(n,s.x),r=Math.max(r,s.y))}),{x:t,y:i,ex:n,ey:r,width:n-t,height:r-i}}function Ji(e,t,i){return e.rotate&&(e=As(tn(e))),i?e.x>t.x&&e.ext.y&&e.eyt.ex||e.ext.ey)}function E2(e,t){return(t.x>e.ex||t.exe.ey||t.eye.y!=c>e.y&&e.x<(l-s)*(e.y-a)/(c-a)+s&&(i=!i)}return i}const S2=/^[\t\n\f\r ]*([MLHVZCSQTAmlhvzcsqta])[\t\n\f\r ]*/,Xf=/^[01]/,Jt=/^[+-]?(([0-9]*\.[0-9]+)|([0-9]+\.)|([0-9]+))([eE][+-]?[0-9]+)?/,P2=/^(([\t\n\f\r ]+,?[\t\n\f\r ]*)|(,[\t\n\f\r ]*))/,I2={M:[Jt,Jt],L:[Jt,Jt],H:[Jt],V:[Jt],Z:[],C:[Jt,Jt,Jt,Jt,Jt,Jt],S:[Jt,Jt,Jt,Jt],Q:[Jt,Jt,Jt,Jt],T:[Jt,Jt],A:[Jt,Jt,Jt,Xf,Xf,Jt,Jt]};function L2(e){let t=0;const i=[];for(;t{s.worldPoints.forEach((a,l)=>{l%2===0?(an&&(n=a)):(ar&&(r=a))})}),--t,--i,{x:t,y:i,ex:n,ey:r,width:n-t+1,height:r-i+1}}function D2(e,t,i){i==null&&(i=t),e.commands.forEach((n,r)=>{if(!(n.relative&&r))switch(n.key){case"A":case"a":n.values[5]+=t,n.values[6]+=i;break;case"V":case"v":n.values[0]+=i;break;default:n.values.forEach((s,a)=>{n.values[a]=s+(a%2===0?t:i)});break}})}function M2(e,t,i){i==null&&(i=t),e.commands.forEach(n=>{switch(n.key){case"A":case"a":const r=n.values[0],s=n.values[1],a=Math.PI*n.values[2]/180,l=Math.cos(a),c=Math.sin(a),u=s*s*i*i*l*l+r*r*i*i*c*c,h=2*t*i*l*c*(s*s-r*r),d=r*r*t*t*l*l+s*s*t*t*c*c,g=-(r*r*s*s*t*t*i*i),v=h*h-4*u*d,y=Math.sqrt((u-d)*(u-d)+h*h);n.values[2]=h!==0?Math.atan((d-u-y)/h)*180/Math.PI:u=0?n.values[4]:1-n.values[4];break;case"V":case"v":n.values[0]*=i;break;default:n.values.forEach((w,p)=>{n.values[p]=w*(p%2===0?t:i)});break}})}function B2(e){let t="";return e.commands.forEach(i=>{t+=i.key+" ",i.values.forEach(n=>{t+=n+" "})}),t}function O2(e,t,i){const n=I2[e.toUpperCase()],r=[];for(;i<=t.length;){const s={key:e,values:[]};for(const a of n){const l=t.slice(i).match(a);if(l!==null){s.values.push(+l[0]),i+=l[0].length;const c=t.slice(i).match(P2);c!==null&&(i+=c[0].length)}else{if(s.values.length===0)return{cursor:i,commands:r};throw new Error("malformed path (first error at "+i+")")}}if(s.relative=s.key.toUpperCase()!==s.key,r.push(s),n.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 N2(e,t){const i=[];let n=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{switch(r.key){case"Z":case"z":r.worldPoints=[i,n];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:N2(r,t);break}(r.key==="M"||r.key==="m"||r.key==="Z"||r.key==="z")&&(i=r.worldPoints[r.worldPoints.length-2],n=r.worldPoints[r.worldPoints.length-1]),t=r})}function z2(e,t){var c;const n=e.calculative.canvas.store.data.paths[e.pathId];if(!n)return new Path2D;const r=L2(n);e.calculative.svgRect=Gf(r),ee(e.calculative.svgRect),(e.calculative.svgRect.width!==e.calculative.worldRect.width||e.calculative.svgRect.height!==e.calculative.worldRect.height)&&M2(r,e.calculative.worldRect.width/e.calculative.svgRect.width,e.calculative.worldRect.height/e.calculative.svgRect.height);const s=Gf(r);ee(s),D2(r,e.calculative.worldRect.x-s.x,e.calculative.worldRect.y-s.y);const a=B2(r);if(t){(c=t.svgPath)==null||c.call(t,a);return}return new Path2D(a)}function H2(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a}=e.calculative.worldRect;if(i.moveTo(n+s/2,r),i.lineTo(n+s,r+a/2),i.lineTo(n+s/2,r+a),i.lineTo(n,r+a/2),i.lineTo(n+s/2,r),i.closePath(),i instanceof Path2D)return i}function U2(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a}=e.calculative.worldRect;if(i.moveTo(n+s/2,r),i.lineTo(n+s,r+a),i.lineTo(n,r+a),i.lineTo(n+s/2,r),i.closePath(),i instanceof Path2D)return i}function W2(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:n},r)=>({id:`${r}`,penId:e.id,x:i,y:n}))}function q2(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a}=e.calculative.worldRect;if(i.moveTo(n+s/2,r),i.lineTo(n+s,r+a*2/5),i.lineTo(n+s*4/5,r+a),i.lineTo(n+s/5,r+a),i.lineTo(n,r+a*2/5),i.closePath(),i instanceof Path2D)return i}function j2(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:n},r)=>({id:`${r}`,penId:e.id,x:i,y:n}))}function V2(e,t){e.onResize||(e.onResize=$2);const i=t||new Path2D,{width:n,height:r,center:s}=e.calculative.worldRect,a=n>r?r:n,l=s.x,c=s.y,u=c-a/2,h=c-a/4,d=-(h-c)*Math.sin(Math.PI/180*324)+l,g=(h-c)*Math.cos(Math.PI/180*324)+c;i.moveTo(d,g);for(let v=0;v<5;++v)i.lineTo(-(u-c)*Math.sin(Math.PI/180*72*v)+l,(u-c)*Math.cos(Math.PI/180*72*v)+c),i.lineTo((d-l)*Math.cos(Math.PI/180*72*(v+1))-(g-c)*Math.sin(Math.PI/180*72*(v+1))+l,(d-l)*Math.sin(Math.PI/180*72*(v+1))+(g-c)*Math.cos(Math.PI/180*72*(v+1))+c);if(i.closePath(),i instanceof Path2D)return i}function Kv(e){const{width:t,height:i}=e,n=t>i?i:t,r=[];for(let s=0;s<5;++s)r.push({flag:1,id:String(s),penId:e.id,x:.5+n/2*Math.sin(Math.PI/180*72*s)/t,y:-n/2*Math.cos(Math.PI/180*72*s)/i+.5});e.anchors=r}function $2(e){const t=e.anchors.filter(i=>i.flag!==1);Kv(e),e.anchors=e.anchors.concat(...t)}function K2(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a}=e.calculative.worldRect;if(i.moveTo(n+s/4,r),i.lineTo(n+s*3/4,r),i.lineTo(n+s,r+a/2),i.lineTo(n+s*3/4,r+a),i.lineTo(n+s*1/4,r+a),i.lineTo(n,r+a/2),i.lineTo(n+s/4,r),i.closePath(),i instanceof Path2D)return i}function Y2(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a}=e.calculative.worldRect;if(i.moveTo(n,r+a/2),i.lineTo(n+a/2,r),i.lineTo(n+a/2,r+a/3),i.lineTo(n+s,r+a/3),i.lineTo(n+s,r+a*2/3),i.lineTo(n+a/2,r+a*2/3),i.lineTo(n+a/2,r+a*2/3),i.lineTo(n+a/2,r+a),i.closePath(),i instanceof Path2D)return i}function X2(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a}=e.calculative.worldRect;if(i.moveTo(n,r+a/3),i.lineTo(n+(s-a/2),r+a/3),i.lineTo(n+(s-a/2),r),i.lineTo(n+s,r+a/2),i.lineTo(n+(s-a/2),r+a),i.lineTo(n+(s-a/2),r+a*2/3),i.lineTo(n,r+a*2/3),i.closePath(),i instanceof Path2D)return i}function G2(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a}=e.calculative.worldRect;if(i.moveTo(n,r+a/2),i.lineTo(n+a/2,r),i.lineTo(n+a/2,r+a/3),i.lineTo(n+(s-a/2),r+a/3),i.lineTo(n+(s-a/2),r),i.lineTo(n+s,r+a/2),i.lineTo(n+(s-a/2),r+a),i.lineTo(n+(s-a/2),r+a*2/3),i.lineTo(n+a/2,r+a*2/3),i.lineTo(n+a/2,r+a),i.closePath(),i instanceof Path2D)return i}function Z2(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a,ey:l}=e.calculative.worldRect;if(i.moveTo(n,r),i.lineTo(n+s,r),i.lineTo(n+s,r+a*3/4),i.lineTo(n+s*8/16,r+a*3/4),i.lineTo(n+s/4,l),i.lineTo(n+s*5/16,r+a*3/4),i.lineTo(n,r+a*3/4),i.closePath(),i instanceof Path2D)return i}function J2(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a}=e.calculative.worldRect;if(i.moveTo(n+s/5,r+a*13/16),i.bezierCurveTo(n-s/15,r+a*13/16,n-s/15,r+a*7/16,n+s/5,r+a*7/16),i.bezierCurveTo(n+s/5,r,n+s*4/5,r,n+s*4/5,r+a*7/16),i.bezierCurveTo(n+s*16/15,r+a*7/16,n+s*16/15,r+a*13/16,n+s*4/5,r+a*13/16),i.closePath(),i instanceof Path2D)return i}function Q2(e,t){const i=t||new Path2D,{x:n,y:r,width:s,ex:a,ey:l}=e.calculative.worldRect,c=s/6;if(i.moveTo(n,r),i.lineTo(a-c,r),i.lineTo(a,r+c),i.lineTo(a,l),i.lineTo(n,l),i.closePath(),i.moveTo(a-c,r),i.lineTo(a-c,r+c),i.lineTo(a,r+c),i.closePath(),i instanceof Path2D)return i}function tk(e,t){const{x:i,y:n,width:r,ex:s,ey:a}=t.calculative.worldRect;let l=r*.25;const c=t.z;c>1?l=c:c>0&&(l=r*c);const u={x:i,y:n+l},h={x:s-l,y:n+l},d={x:s-l,y:a};Ml(e,[u,h,d,{x:i,y:a}],t.backgroundFront||t.background,t.color),Ml(e,[u,{x:i+l,y:n},{x:s,y:n},h],t.backgroundUp||t.background,t.color),Ml(e,[h,{x:s,y:n},{x:s,y:a-l},d],t.backgroundRight||t.background,t.color)}function Ml(e,t,i="",n=""){e.save(),i&&(e.fillStyle=i),n&&(e.strokeStyle=n),e.beginPath();for(let r=0;rn.x?l=Lt.Right:l=Lt.Left),n.next={id:It(),penId:t.id,x:n.x,y:n.y,prevNextType:2},r.prev={id:It(),penId:t.id,x:r.x,y:r.y,prevNextType:2},l){case Lt.Up:n.next.y-=s,r.prev.y=n.y;break;case Lt.Bottom:n.next.y+=s,r.prev.y=n.y;break;case Lt.Left:n.next.x-=s,r.prev.x=n.x;break;default:n.next.x+=s,r.prev.x=n.x;break}}function sk(e,t){const i=t||new Path2D;if((e.lineName==="line"||e.lineName==="polyline")&&e.calculative.lineSmooth){let r=Nc(e);if(i.addPath(r),i instanceof Path2D)return i}const n=e.calculative.worldAnchors;if(n.length>1){let r;n.forEach(s=>{r?Jf(i,r,s):s.start=!0,r=s}),e.close&&(e.lineName==="curve"?Jf(i,r,n[0]):i.closePath())}if(i instanceof Path2D)return i}function ak(e,t,i){var s;if(t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),t.calculative.worldAnchors.length<2||((s=t.anchors)==null?void 0:s.length)>1)return;const n=le(t),r=qt(t);!n||!r||!r.id||n===r||(n.next=void 0,zc(t),r.prev=void 0,t.calculative.worldAnchors.push(r))}function Jf(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 bc(e){return xc(e),As(Xv(e))}function Xv(e){const t=[];let i;return e.calculative.worldAnchors.forEach(n=>{t.push(n),i&&t.push(...Qf(i,n,e)),i=n}),e.close&&e.calculative.worldAnchors.length>1&&t.push(...Qf(i,e.calculative.worldAnchors[0],e)),t}function $a(e){return e!=null&&e.lineWidth?e.lineWidth/2+4:4}function Qf(e,t,i){const n=[];if(!t)return n;let r=.02;if(e.lineLength&&(r=$a(i)/e.lineLength),e.next)if(t.prev)for(let s=r;s<1;s+=r)n.push(Yv(s,e,e.next,t.prev,t));else for(let s=r;s<1;s+=r)n.push(wc(s,e,e.next,t));else if(t.prev)for(let s=r;s<1;s+=r)n.push(wc(s,e,t.prev,t));else n.push({x:t.x,y:t.y});return n.length>1&&(e.curvePoints=n),n}function ok(e,t){const i=$a(t);let n=0,r,s;for(const a of t.calculative.worldAnchors){if(r){if(s=td(e,r,a,i),s)return{i:n,point:s};++n}r=a}if(t.close&&t.calculative.worldAnchors.length>1&&(s=td(e,r,t.calculative.worldAnchors[0],i)))return{i:n,point:s}}function td(e,t,i,n=4){if(!t.next&&!i.prev){const{x:r,y:s}=t,{x:a,y:l}=i,c=Math.min(r,a),u=Math.max(r,a),h=Math.min(s,l),d=Math.max(s,l);return e.x>=c-n&&e.x<=u+n&&e.y>=h-n&&e.y<=d+n?lk(e,t,i,n):void 0}else if(t.curvePoints){for(const r of t.curvePoints)if(Ar(e,r,n))return r}}function lk(e,t,i,n=4){if(t.x===i.x){if(Math.abs(e.x-t.x)<=n)return{x:t.x,y:e.y}}else{const r=(t.y-i.y)/(t.x-i.x),s=t.y-r*t.x;if(Math.abs((r*e.x+s-e.y)/Math.sqrt(r*r+1))<=n){const c=(e.x+r*e.y-r*s)/(r*r+1);return{x:c,y:r*c+s}}}}function ed(e,t,i,n){if(!t&&!i)return Math.sqrt(Math.pow(Math.abs(e.x-n.x),2)+Math.pow(Math.abs(e.y-n.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} ${n.x} ${n.y}`):t?r.setAttribute("d",`M${e.x} ${e.y} Q${t.x} ${t.y} ${n.x} ${n.y}`):r.setAttribute("d",`M${e.x} ${e.y} Q${i.x} ${i.y} ${n.x} ${n.y}`),r.getTotalLength()||0}function xc(e){if(e.calculative.worldAnchors.length<2)return 0;let t=0,i;if(e.calculative.worldAnchors.forEach(n=>{i&&(i.lineLength=ed(i,i.next,n.prev,n),t+=i.lineLength),i=n}),e.close){const n=le(e);i.lineLength=ed(i,i.next,n.prev,n),t+=i.lineLength}return e.calculative.animatePos&&(e.calculative.animatePos=t/e.length*e.calculative.animatePos),e.length=t,t}function Bl(e,t){const i=e.calculative.worldAnchors;for(let n=0;n=0&&d*u+g*h+v<=0||d*l+g*c+v<=0&&d*u+g*h+v>=0||d*l+g*h+v>=0&&d*u+g*c+v<=0||d*l+g*h+v<=0&&d*u+g*c+v>=0){if(l>u){const y=l;l=u,u=y}if(cu&&s>u||r>c&&a>c||rv.y&&n.yv.y))){y=g;let p=ze;n.x{p.id=It(),p.penId=t.id,t.calculative.worldAnchors.push(p)}),t.calculative.worldAnchors.push(r),y&&t.calculative.worldAnchors.push(y),g&&t.calculative.worldAnchors.push(v),s&&t.calculative.worldAnchors.reverse(),a){const p=t.calculative.worldAnchors.length-2;t.calculative.worldAnchors[p].isTemp=!1,t.calculative.worldAnchors[1].isTemp=!1}}function id(e,t,i){const n={x:e.x,y:e.y,id:It()};switch(t){case Lt.Up:n.y-=i;break;case Lt.Right:n.x+=i;break;case Lt.Bottom:n.y+=i;break;case Lt.Left:n.x-=i;break;default:return}return n}function uk(e,t,i){if(e.x===t.x||e.y===t.y)return[];const n=[];let r,s;switch(i){case Lt.Up:e.ye.y)r=e.x+(t.x-e.x)/2,n.push({x:r,y:e.y},{x:r,y:t.y});else{const a=(e.y+t.y)/2;n.push({x:e.x,y:a},{x:t.x,y:a})}break;case Lt.Right:r=t.x,s=e.y,t.xe.x&&t.ye.y-ze)r=e.x+(t.x-e.x)/2,n.push({x:r,y:e.y},{x:r,y:t.y});else{const a=(e.y+t.y+ze)/2;n.push({x:e.x,y:a},{x:t.x,y:a})}break}return n}function fk(e,t,i){if(e.x===t.x||e.y===t.y)return[];const n=[];let r,s;switch(i){case Lt.Up:r=e.x,s=t.y,t.x>e.x&&t.y>e.y&&(r=t.x,s=e.y),n.push({x:r,y:s});break;case Lt.Bottom:r=e.x,s=t.y,t.x>e.x&&t.ye.y&&(r=e.x,s=t.y),n.push({x:r,y:s});break;case Lt.Bottom:e.y>t.y?(r=t.x,s=e.y):(r=e.x,s=t.y),n.push({x:r,y:s});break;case Lt.Left:r=t.x,s=e.y,t.x>e.x&&t.y>e.y&&(r=e.x,s=t.y),n.push({x:r,y:s});break;default:if(r=e.x,t.ye.y&&(r=t.x,s=e.y),n.push({x:r,y:s});break;case Lt.Bottom:r=e.x,s=t.y,t.xe.x)r=t.x,s=e.y+(t.y-e.y)/2,n.push({x:e.x,y:s},{x:t.x,y:s});else{const a=(e.x+t.x)/2;n.push({x:a,y:e.y},{x:a,y:t.y})}break;case Lt.Left:t.x>e.x?n.push({x:e.x,y:t.y}):n.push({x:t.x,y:e.y});break;default:if(r=e.x,s=t.y,t.xMath.abs(i.y-t.y));let r=e.calculative.worldAnchors.findIndex(s=>s.id==t.id);if(r>1){let s=e.calculative.worldAnchors[r-1];if(s.x===t.x&&s.y!==t.y)return n.push({x:i.x,y:t.y}),n;if(s.y===t.y&&s.x!==t.x)return n.push({x:t.x,y:i.y}),n}return e.calculative.worldAnchors.length&&(i.isTemp=void 0,e.calculative.drawlineH?(n.push({x:i.x,y:t.y}),Math.abs(i.y-t.y){n.unshift(a)}));for(let a=0;a{n.unshift(a)}));for(let a=0;ac.id===t.id),r=le(e),s=qt(e);let a=e.calculative.worldAnchors[n-1],l=e.calculative.worldAnchors[n+1];if(e.calculative.h==null&&(r.connectTo&&(_a(e,t,!0)?e.calculative.h=!0:ka(e,t,!0)&&(e.calculative.h=!1)),e.calculative.h==null&&s.connectTo&&(_a(e,t,!1)?e.calculative.h=!0:ka(e,t,!1)&&(e.calculative.h=!1)),e.calculative.h==null&&(a?e.calculative.h=a.y===t.y:l&&(e.calculative.h=l.y===t.y))),e.calculative.h){if(t.x=i.x,r.connectTo&&_a(e,t,!0)){l&&l.y!==t.y&&(l.x=t.x);return}if(s.connectTo&&_a(e,t,!1)){a&&a.y!==t.y&&(a.x=t.x);return}const c=e.anchors[n];let u;for(let h=n-1;h>-1;h--)if(a=e.anchors[h],u==null&&(u=a.y===c.y),u===!0)if(a.y===c.y)e.calculative.worldAnchors[h].y=i.y;else break;else if(a.x===c.x)e.calculative.worldAnchors[h].x=i.x;else break;u=void 0;for(let h=n+1;h-1;h--)if(a=e.anchors[h],u==null&&(u=a.x===c.x),u===!0)if(a.x===c.x)e.calculative.worldAnchors[h].x=i.x;else break;else if(a.y===c.y)e.calculative.worldAnchors[h].y=i.y;else break;u=void 0;for(let h=n+1;h1?(u=w.x-y.x,h=w.y-y.y):p>0?(u=w.x-(l+d*p),h=w.y-(c+g*p)):(u=w.x-l,h=w.y-c)):(u=w.x-l,h=w.y-c),_=u*u+h*h,_>s&&(a=x,s=_);return s>t&&(a-i>1&&r.push(..._c(e,t,i,a)),r.push({id:e[a].id,penId:e[a].penId,x:e[a].x,y:e[a].y}),n-a>1&&r.push(..._c(e,t,a,n))),r}function mk(e,t=.8,i=!1){if(e.length<3)return e;let n,r,s,a,l,c,u,h,d,g,v,y,w,p,_;const A=(x,E,I,M)=>(a=Math.sqrt(x*x+E*E),a>0?(y=x/a,p=E/a):(y=1,p=0),l=Math.sqrt(I*I+M*M),l>0?(w=I/l,_=M/l):(w=1,_=0),Math.acos(y*w+p*_));g=[],v=e.length,n=e[0],e[v-1],g.push({...e[0]});for(let x=0;x1){let h,d=0;for(let g=0;ga)&&p>c+a&&_-p>c&&(e.lineAnimateType===Je.Arrow?wk(i,w,s,y,u,a):e.lineAnimateType===Je.WaterDrop&&bk(i,w,e.animateReverse,y,u,a)),w.x+=l*Math.cos(y*Math.PI/180),w.y-=l*Math.sin(y*Math.PI/180),p=Math.sqrt((w.x-h.x)**2+(w.y-h.y)**2)}h=v}}if(i instanceof Path2D)return i}function pk(e,t){let i=t.x-e.x,n=t.y-e.y,r=Math.atan(n/i)*180/Math.PI;return t.x>=e.x?r=-r:r=180-r,r}function bn(e,t,i){let n=(180-i)*Math.PI/180;return{x:(e.x-t.x)*Math.cos(n)-(e.y-t.y)*Math.sin(n)+t.x,y:(e.x-t.x)*Math.sin(n)+(e.y-t.y)*Math.cos(n)+t.y}}function wk(e,t,i,n,r,s){let a=bn({x:t.x+i,y:t.y+.57*i},{x:t.x,y:t.y},n),l=bn({x:t.x+i,y:t.y-.57*i},{x:t.x,y:t.y},n),c=bn({x:t.x+i,y:t.y+r/2},{x:t.x,y:t.y},n),u=bn({x:t.x+s,y:t.y+r/2},{x:t.x,y:t.y},n),h=bn({x:t.x+i,y:t.y-r/2},{x:t.x,y:t.y},n),d=bn({x:t.x+s,y:t.y-r/2},{x:t.x,y:t.y},n);e.moveTo(a.x,a.y),e.lineTo(t.x,t.y),e.lineTo(l.x,l.y),e.lineTo(h.x,h.y),e.lineTo(d.x,d.y),e.lineTo(u.x,u.y),e.lineTo(c.x,c.y),e.lineTo(a.x,a.y)}function bk(e,t,i,n,r,s){let a=r/2;i&&(a=-r/2);let l=bn({x:t.x,y:t.y+a},{x:t.x,y:t.y},n),c=bn({x:t.x+s,y:t.y},{x:t.x,y:t.y},n),u=Math.PI/2;i&&(u=-Math.PI/2),e.moveTo(t.x,t.y),e.arc(t.x,t.y,r/2,-u-n/180*Math.PI,u-n/180*Math.PI,!1),e.lineTo(c.x,c.y),e.lineTo(l.x,l.y)}function xk(e){var i;e.onDestroy||(e.onDestroy=_k,e.onMove=Ea,e.onResize=Ea,e.onRotate=Ea,e.onValue=Ea,e.onMouseMove=Ek,e.onBeforeValue=kk,e.onRenderPenRaw=Ak),e.calculative.singleton||(e.calculative.singleton={});const t=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=t.width+"px",n.style.height=t.height+"px",document.body.appendChild(n),(i=e.calculative.canvas.externalElements)==null||i.parentElement.appendChild(n),ti(e,n),e.calculative.singleton.div=n;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,e.calculative.iframe=e.iframe,n.appendChild(r),Qv(e),r.onload=()=>{r.setAttribute("document.domain","")}}return e.calculative.patchFlags&&ti(e,e.calculative.singleton.div),e.onRenderPenRaw(e),new Path2D}function _k(e){tg(e),e.calculative.singleton&&e.calculative.singleton.div&&(e.calculative.singleton.div.remove(),delete e.calculative.singleton.div)}function Ea(e){e.calculative.singleton.div&&ti(e,e.calculative.singleton.div)}function kk(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=ct(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?Qv(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].style["backdrop-filter"]=`blur(${t.blur||2}px)`;if(t.blurBackground!==void 0)for(let i=1;i<5;i++)e.calculative.singleton.div.children[i].style.backgroundColor=t.blurBackground;return t}function Ek(e,t){if(!(!e.calculative.canvas.store.data.locked&&!e.locked)&&Jv(e.operationalRect)&&e.calculative.zIndex<5&&t.x>e.x+e.width*e.operationalRect.x&&t.xe.y+e.height*e.operationalRect.y&&t.y{tg(e)};i.onmouseenter=a,r.onmouseenter=a,n.onmouseenter=a,s.onmouseenter=a,t.onmouseleave=a}function tg(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 Ak(e){if(e.thumbImg&&!e.calculative.img){const t=new Image;t.crossOrigin=e.crossOrigin==="undefined"?void 0:e.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 He={},Ma=['',''];function Rk(e){var t;if(e.onDestroy||(e.onDestroy=Ck,e.onMove=Ol,e.onResize=Ol,e.onRotate=Ol,e.onClick=nd,e.onValue=Sk,e.onChangeId=Tk),He[e.id])e.video&&e.calculative.media&&e.video!==e.calculative.video?(console.warn("video \u66F4\u6539, \u6B64\u5904\u662F\u5426\u6267\u884C\uFF1F"),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"),n=document.createElement("div");n.style.position="absolute",n.style.outline="none",n.style.left="0",n.style.bottom="0",n.style.width="0",n.style.height="2px",n.style.background="#52c41a",n.style.zIndex="1",e.hideProgress&&(n.style.display="none");const r=document.createElement("div");r.innerHTML=Ma[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(n),i.appendChild(r),r.onclick=a=>{a.stopPropagation(),e.calculative.media.muted?(r.innerHTML=Ma[0],e.calculative.media.muted=!1):(r.innerHTML=Ma[1],e.calculative.media.muted=!0)},e.calculative.singleton||(e.calculative.singleton={}),e.calculative.singleton.muted=r,i.onmouseenter=a=>{r.style.display="block"},i.onmouseleave=a=>{r.style.display="none"},i.onclick=a=>{a.stopPropagation(),nd(e)};let s;e.video?(s=document.createElement("video"),s.src=e.video):e.audio&&(s=document.createElement("audio"),s.src=e.audio),s.loop=e.playLoop,s.ontimeupdate=()=>{eg(n,s,e.calculative.worldRect.width)},s.onended=()=>{e.calculative.onended&&e.calculative.onended(e)},e.calculative.media=s,s.style.position="absolute",s.style.outline="none",s.style.left="0",s.style.top="0",s.style.width="100%",s.style.height="100%",i.appendChild(s),He[e.id]=i,(t=e.calculative.canvas.externalElements)==null||t.parentElement.appendChild(i),ti(e,i),e.autoPlay&&(s.autoplay=!0,s.muted=!0)}return e.calculative.patchFlags&&ti(e,He[e.id]),new Path2D}function Ck(e){He[e.id].onclick=null,He[e.id].remove(),He[e.id]=void 0}function Ol(e){ti(e,He[e.id]);const t=He[e.id].children[0],i=He[e.id].children[1];eg(t,i,e.calculative.worldRect.width)}function nd(e){e.calculative.media&&(e.calculative.media.muted=!1,e.calculative.singleton.muted.innerHTML=Ma[0],e.calculative.media.paused?e.calculative.media.play():e.calculative.media.pause())}function eg(e,t,i){e.style.width=t.currentTime/t.duration*i+"px"}function Tk(e,t,i){!He[t]||(He[i]=He[t],delete He[t])}function Sk(e){const t=He[e.id];if(!t)return;ti(e,t);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 Ii(){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 us{constructor(t,i){W(this,"parentElement");W(this,"store");W(this,"box");W(this,"text");W(this,"arrowUp");W(this,"arrowDown");W(this,"x");W(this,"y");W(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 n;for(let r=0;r0?(this.arrowUp.style.borderBottomColor="transparent",this.arrowDown.style.borderTopColor="#777777"):(a+=n.height+r.height+5,this.arrowUp.style.borderBottomColor="#777777",this.arrowDown.style.borderTopColor="transparent"),this.x=s,this.y=a,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px"}hide(){this.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 ig{constructor(t){W(this,"parent");W(this,"h");W(this,"v");W(this,"isDownH");W(this,"isDownV");W(this,"x");W(this,"y");W(this,"hSize");W(this,"vSize");W(this,"scrollX");W(this,"scrollY");W(this,"lastScrollX");W(this,"lastScrollY");W(this,"rect");W(this,"isShow");W(this,"pageMode");W(this,"onMouseDownH",t=>{t.preventDefault(),t.stopPropagation(),this.isDownH=t.x,this.x=this.parent.store.data.x||0,this.lastScrollX=this.scrollX});W(this,"onMouseDownV",t=>{t.preventDefault(),t.stopPropagation(),this.isDownV=t.y,this.y=this.parent.store.data.y||0,this.lastScrollY=this.scrollY});W(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.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())});W(this,"onMouseUp",t=>{!this.isDownH&&!this.isDownV||(this.isDownH=void 0,this.isDownV=void 0,this.scrollX<20?(this.scrollX=20,this.h.style.left=`${this.scrollX}px`):this.scrollX>this.parent.parentElement.clientWidth-this.hSize-20&&(this.scrollX=this.parent.parentElement.clientWidth-this.hSize-20,this.h.style.left=`${this.scrollX}px`),this.scrollY<20?(this.scrollY=20,this.v.style.top=`${this.scrollY}px`):this.scrollY>this.parent.parentElement.clientHeight-this.vSize-20&&(this.scrollY=this.parent.parentElement.clientHeight-this.vSize-20,this.v.style.top=`${this.scrollY}px`),this.resize())});this.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 n=0;n=0||t>0&&i.ey-this.parent.height+this.parent.store.data.y<=0}changeMode(){this.pageMode=!0,this.h.style.display="none",this.parent.parent.getRect().height0?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;t&&(i=-10),!(this.pageMode&&this.canMouseMove(i))&&(this.scrollY+=i,this.v.style.top=`${this.scrollY}px`,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 rd{constructor(t,i,n){W(this,"parentElement");W(this,"store");W(this,"isBottom");W(this,"canvas",document.createElement("canvas"));W(this,"otherOffsreen",Ii());W(this,"offscreen",Ii());W(this,"animateOffsScreen",Ii());W(this,"fitOffscreen",Ii());W(this,"fitFlag",!1);W(this,"currentFit");W(this,"activeFit");this.parentElement=t,this.store=i,this.isBottom=n,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===zt.CanvasImageBottom||!this.isBottom&&t.canvasLayer===zt.CanvasImage)&&t.image&&t.calculative.img&&t.name!=="gif",t.calculative.hasImage}render(){var a;let t=!1,i=!1;for(const l of this.store.data.pens)this.hasImage(l)&&(this.store.animates.has(l)?i=!0:l.calculative.imageDrawed||(t=!0),l.parentId&&this.store.animates.has(Ze(l,!0))&&(i=!0));const n=this.store.patchFlagsBackground,r=this.store.patchFlagsTop;if(r&&!this.isBottom){const l=this.otherOffsreen.getContext("2d");l.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderRule(l)}if(this.store.patchFlagsLast&&this.offscreen.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),t){const l=this.offscreen.getContext("2d");l.save(),l.clearRect(0,0,this.canvas.width,this.canvas.height),l.translate(this.store.data.x,this.store.data.y);for(const c of this.store.data.pens)!c.calculative.hasImage||this.store.animates.has(c)||this.store.animates.has(Ze(c,!0))||c.canvasLayer!==zt.CanvasTemplate&&(c.name==="combine"&&!c.draw||(c.calculative.imageDrawed=!0,l.save(),Vn(l,c),c.calculative.rotate&&Qi(l,c),$n(l,c),Pr(l,c),l.restore()));l.restore()}if(i){const l=this.animateOffsScreen.getContext("2d");l.save(),l.clearRect(0,0,this.canvas.width,this.canvas.height),l.translate(this.store.data.x,this.store.data.y);for(const c of this.store.animates)!c.calculative.hasImage||c.canvasLayer!==zt.CanvasTemplate&&(c.calculative.imageDrawed=!0,l.save(),Vn(l,c),c.calculative.rotate&&Qi(l,c),$n(l,c),Pr(l,c),l.restore());for(const c of this.store.data.pens)!c.calculative.hasImage||!c.parentId||c.canvasLayer!==zt.CanvasTemplate&&this.store.animates.has(Ze(c,!0))&&(c.calculative.imageDrawed=!0,l.save(),Vn(l,c),c.calculative.rotate&&Qi(l,c),$n(l,c),Pr(l,c),l.restore());l.restore()}if(!this.isBottom&&!this.store.data.locked&&this.fitFlag){const l=(this.store.data.width||this.store.options.width)*this.store.data.scale,c=(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,d=this.fitOffscreen.getContext("2d");d.save(),d.clearRect(0,0,this.canvas.width,this.canvas.height),d.fillStyle="#ffffff66",d.strokeStyle=this.store.options.activeColor,(a=this.store.data.fits)==null||a.forEach((g,v)=>{d.fillRect(u+l*g.x,h+c*g.y,l*g.width,c*g.height),g.active&&d.strokeRect(u+l*g.x,h+c*g.y,l*g.width,c*g.height)}),d.restore()}if(t||i||n&&this.isBottom||r&&!this.isBottom){const l=this.canvas.getContext("2d");l.clearRect(0,0,this.canvas.width,this.canvas.height),this.isBottom&&(this.store.patchFlagsBackground=!1),l.drawImage(this.offscreen,0,0,this.canvas.width,this.canvas.height),l.drawImage(this.animateOffsScreen,0,0,this.canvas.width,this.canvas.height),this.isBottom||(l.drawImage(this.otherOffsreen,0,0,this.canvas.width,this.canvas.height),this.store.patchFlagsTop=!1,!this.store.data.locked&&this.fitFlag&&l.drawImage(this.fitOffscreen,0,0,this.canvas.width,this.canvas.height))}}renderRule(t){var x,E,I,M,B,D,q,Q;const{data:i,options:n}=this.store,{rule:r,ruleColor:s,scale:a,origin:l}=i;if(!(r!=null?r:n.rule))return;const c=a*10;t.save();const u=s||n.ruleColor;t.strokeStyle=qa(u,.7);const h=l.x+i.x,d=l.y+i.y,{width:g,height:v}=this.canvas;let y=((x=n.ruleOptions)==null?void 0:x.height)||20;(E=n.ruleOptions)!=null&&E.background&&(t.beginPath(),t.fillStyle=(I=n.ruleOptions)==null?void 0:I.background,t.rect(0,0,g,y),t.fill(),t.rect(0,0,y,v),t.fill()),(M=n.ruleOptions)!=null&&M.underline&&(t.beginPath(),t.fillStyle=qa(u,.7),t.moveTo(0,y),t.lineTo(g,y),t.stroke(),t.moveTo(y,0),t.lineTo(y,v),t.stroke());let w=y/4;((B=n.ruleOptions)==null?void 0:B.baseline)==="bottom"&&(w=y*3/4),t.beginPath(),t.lineWidth=y/2,t.lineDashOffset=-h%c,t.setLineDash([1,c-1]),t.moveTo(0,w),t.lineTo(g,w),t.stroke(),t.beginPath(),t.lineDashOffset=-d%c,t.moveTo(w,0),t.lineTo(w,v),t.stroke(),t.strokeStyle=u,t.beginPath(),t.lineWidth=y,t.lineDashOffset=-h%(c*10),t.setLineDash([1,c*10-1]),t.moveTo(0,y/2),t.lineTo(g,y/2),t.stroke(),t.beginPath(),t.lineDashOffset=-d%(c*10),t.moveTo(y/2,0),t.lineTo(y/2,v),t.stroke(),t.beginPath(),t.fillStyle=((D=n.ruleOptions)==null?void 0:D.textColor)||t.strokeStyle;let p=0-Math.floor(h/c/10)*100,_=((q=n.ruleOptions)==null?void 0:q.textTop)||16,A=((Q=n.ruleOptions)==null?void 0:Q.textLeft)||4;h<0&&(p-=100);for(let C=h%(c*10);C{n.drawImage(c,r.x-t,r.y-t,this.magnifierSize,this.magnifierSize,0,0,this.magnifierSize,this.magnifierSize)}),n.restore(),n.beginPath();const a=n.createRadialGradient(t,t,t-5,t,t,t);a.addColorStop(0,"rgba(0,0,0,0.2)"),a.addColorStop(.8,"rgb(200,200,200)"),a.addColorStop(.9,"rgb(200,200,200)"),a.addColorStop(1,"rgba(200,200,200,0.9)"),n.strokeStyle=a,n.arc(t,t,t,0,Math.PI*2,!1),n.stroke(),n.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:n,y:r,width:s,height:a}=i.calculative.worldRect;t.drawImage(i.calculative.img,n,r,s,a),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 ng(e){if(e.data.locked)throw new Error("canvas is locked")}class Ik{constructor(t){W(this,"parentElement");W(this,"box");W(this,"iframe");W(this,"dialog");W(this,"close");W(this,"title");W(this,"body");W(this,"x");W(this,"y");W(this,"url");this.parentElement=t,this.box=document.createElement("div"),this.dialog=document.createElement("div");let i=document.createElement("div");this.title=document.createElement("div"),this.close=document.createElement("span"),this.close.innerHTML=` `,this.body=document.createElement("div"),this.iframe=document.createElement("iframe"),this.iframe.setAttribute("frameborder","0"),this.box.className="meta2d-dialog_mask",this.dialog.className="meta2d-dialog",this.body.className="meta2d-dialog_body",i.className="meta2d-dialog_header",this.title.className="meta2d-dialog-content",this.close.className="meta2d-dialog-close",i.appendChild(this.title),i.appendChild(this.close),this.body.appendChild(this.iframe),this.dialog.appendChild(i),this.dialog.appendChild(this.body),this.box.appendChild(this.dialog),t.appendChild(this.box),this.dialog.onclick=r=>{r.stopPropagation()},this.box.onclick=()=>{this.hide()},this.close.onclick=()=>{this.hide()};let n;for(let r=0;r'},warning:{},error:{}};class Mk{constructor(t,i){W(this,"parentElement");W(this,"store");W(this,"box");W(this,"text");W(this,"arrowUp");W(this,"arrowDown");W(this,"icon");W(this,"confirm");W(this,"cancel");W(this,"x");W(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="\u786E\u5B9A",this.cancel.innerHTML="\u53D6\u6D88",this.icon.innerHTML=Dk.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 n;for(let r=0;r0?(this.arrowUp.style.borderBottomColor="transparent",this.arrowDown.style.borderTopColor="#fff",a-=10):(a+=n.height+r.height+5,a+=10,this.arrowUp.style.borderBottomColor="#fff",this.arrowDown.style.borderTopColor="transparent"),this.x=s,this.y=a,this.box.style.left=this.x+"px",this.box.style.top=this.y+"px"}hide(){this.x=-9999,this.box.style.left="-9999px"}showModal(t,i,n){return new Promise(r=>{this.text.innerHTML=n||"\u786E\u8BA4\u6267\u884C\u64CD\u4F5C\u5417\uFF1F",this.show(t,i),this.confirm.onclick=()=>{r(!0),this.hide()},this.cancel.onclick=()=>{r(!1),this.hide()}})}destroy(){this.box=null}}const Fe="-moving";class sd{constructor(t,i,n){W(this,"parent");W(this,"parentElement");W(this,"store");W(this,"canvas",document.createElement("canvas"));W(this,"offscreen",Ii());W(this,"width");W(this,"height");W(this,"externalElements",document.createElement("div"));W(this,"clientRect");W(this,"canvasRect");W(this,"activeRect");W(this,"initActiveRect");W(this,"dragRect");W(this,"lastRotate",0);W(this,"sizeCPs");W(this,"activeInitPos");W(this,"hoverType",xt.None);W(this,"resizeIndex",0);W(this,"mouseDown");W(this,"hotkeyType");W(this,"mouseRight");W(this,"addCaches");W(this,"touchCenter");W(this,"initTouchDis");W(this,"initScale");W(this,"touchScaling");W(this,"touchMoving");W(this,"startTouches");W(this,"lastOffsetX",0);W(this,"lastOffsetY",0);W(this,"drawingLineName");W(this,"drawLineFns",[...o_]);W(this,"drawingLine");W(this,"pencil");W(this,"pencilLine");W(this,"movingPens");W(this,"patchFlagsLines",new Set);W(this,"dock");W(this,"prevAnchor");W(this,"nextAnchor");W(this,"lastMouseTime",0);W(this,"hoverTimer",0);W(this,"fitTimer",0);W(this,"willInactivePen");W(this,"patchFlags",!1);W(this,"lastRender",0);W(this,"touchStart",0);W(this,"touchStartTimer");W(this,"timer");W(this,"lastAnimateRender",0);W(this,"animateRendering",!1);W(this,"renderTimer");W(this,"initPens");W(this,"pointSize",8);W(this,"pasteOffset",!0);W(this,"opening",!1);W(this,"maxZindex",5);W(this,"canMoveLine",!1);W(this,"randomIdObj");W(this,"keyOptions");W(this,"beforeAddPen");W(this,"beforeAddPens");W(this,"beforeAddAnchor");W(this,"beforeRemovePens");W(this,"beforeRemoveAnchor");W(this,"customResizeDock");W(this,"customMoveDock");W(this,"inputParent",document.createElement("div"));W(this,"inputDiv",document.createElement("div"));W(this,"dropdown",document.createElement("ul"));W(this,"tooltip");W(this,"popconfirm");W(this,"title");W(this,"mousePos",{x:0,y:0});W(this,"scroll");W(this,"movingAnchor");W(this,"canvasTemplate");W(this,"canvasImage");W(this,"canvasImageBottom");W(this,"magnifierCanvas");W(this,"dialog");W(this,"autoPolylineFlag",!1);W(this,"stopPropagation",t=>{t.stopPropagation()});W(this,"curve",ik);W(this,"polyline",hk);W(this,"mind",rk);W(this,"line",ak);W(this,"onCopy",t=>{this.store.options.disableClipboard||t.target!==this.externalElements&&t.target!==document.body&&t.target.offsetParent!==this.externalElements||this.copy()});W(this,"onCut",t=>{this.store.options.disableClipboard||t.target!==this.externalElements&&t.target!==document.body&&t.target.offsetParent!==this.externalElements||this.cut()});W(this,"onPaste",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 n=t.clipboardData.items;if(n){for(let r=0;r{u=d.target.result;const g=new Image;g.src=u,g.onload=()=>{const{width:v,height:y}=g,w={name:c,x:s-50/2,y:a-y/v*50,externElement:c==="gif",width:100,height:y/v*100,image:u};this.addPens([w]),this.active([w]),this.copy([w])}},h.readAsDataURL(l)}}}}else this.paste()});W(this,"onMessage",t=>{if(typeof t.data!="string"||!t.data||t.data.startsWith("setImmediate"))return;let i=JSON.parse(t.data);typeof i=="object"?this.parent.doMessageEvent(i.name,i.value):this.parent.doMessageEvent(i)});W(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===xt.Node||this.hoverType===xt.Line))||this.store.data.locked===Ot.Disable||this.store.data.locked===Ot.DisableScale||this.store.data.locked===Ot.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 s=this.store.data.scale||1;this.translate(-t.deltaX/s,-t.deltaY/s);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 a=.2;t.deltaY.toString().indexOf(".")!==-1&&(a=.01),t.deltaY>0?i=-a:i=a}let{offsetX:n,offsetY:r}=t;this.scale(this.store.data.scale+i,{x:n,y:r}),this.externalElements.focus()});W(this,"onkeydown",t=>{var s,a,l;if(this.store.data.locked>=Ot.DisableEdit&&t.target.tagName!=="INPUT"&&t.target.tagName!=="TEXTAREA"&&!t.target.dataset.meta2dIgnore&&this.store.active.forEach(c=>{var u;(u=c.onKeyDown)==null||u.call(c,c,t.key)}),this.store.data.locked>=Ot.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;let i=10,n=10,r=null;if(this.store.options.strictScope){const c=this.store.data.width||this.store.options.width,u=this.store.data.height||this.store.options.height;c&&u&&(r={x:this.store.data.origin.x,y:this.store.data.origin.y,width:c*this.store.data.scale,height:u*this.store.data.scale})}switch(t.key){case" ":this.hotkeyType=Kt.Translate;break;case"Control":this.drawingLine?this.drawingLine.calculative.drawlineH=!this.drawingLine.calculative.drawlineH:this.hotkeyType||(this.patchFlags=!0,this.hotkeyType=Kt.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=Kt.Resize));break;case"Alt":if(!t.ctrlKey&&!t.shiftKey&&this.drawingLine){const c=qt(this.drawingLine);c!==this.drawingLine.calculative.activeAnchor?(zc(this.drawingLine),this.drawingLine.calculative.worldAnchors.push(c)):this.drawingLine.calculative.worldAnchors.push({x:c.x,y:c.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(c=>!c.parentId&&c.locked!==Ot.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+ir.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(n=1,t.shiftKey&&(n=5),(t.ctrlKey||t.metaKey)&&(n=10),n=n*this.store.data.scale,r&&this.activeRect.y+this.activeRect.height+n>r.y+r.height&&(n=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+n},{});break}this.translatePens(this.store.active,0,n);break;case"d":case"D":(s=this.store.active[0])!=null&&s.locked||this.removeAnchorHand();break;case"h":case"H":(a=this.store.active[0])!=null&&a.locked||this.addAnchorHand();break;case"m":case"M":this.toggleMagnifier();break;case"g":case"G":this.hoverType===xt.NodeAnchor&&(this.movingAnchor=this.store.hoverAnchor,this.externalElements.style.cursor="move");break;case"s":case"S":!this.store.data.locked&&this.hoverType===xt.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"\u221A":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?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(c=>{c.type?(c.close=!c.close,c.close&&Xv(c),this.store.path2dMap.set(c,At.path2dDraws.line(c)),xc(c)):c.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(c=>{c.type||(c.calculative.focus=!1)}),this.movingPens&&(this.getAllByPens(this.movingPens).forEach(c=>{this.store.pens[c.id]=void 0}),this.movingPens=void 0,this.mouseDown=void 0,this.clearDock(),(l=this.store.active)==null||l.forEach(c=>{this.updateLines(c)}),this.calcActiveRect(),this.patchFlags=!0),this.hotkeyType=Kt.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.setFollowers();break}this.render(!1)});W(this,"onkeyup",t=>{switch(t.key){case"l":case"L":this.canMoveLine=!1;break}this.hotkeyType&&this.render(),this.hotkeyType{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 n=null;try{i&&(n=JSON.parse(i))}catch{}if(!n){const{files:r}=t.dataTransfer;if(r.length&&r[0].type.match("image.*")&&!(this.addCaches&&this.addCaches.length)){const s=r[0].type==="image/gif";n=await this.fileToPen(r[0],s)}else if(this.addCaches&&this.addCaches.length)n=this.addCaches,this.addCaches=[];else{this.store.emitter.emit("drop",void 0);return}}if(n=Array.isArray(n)?n:[n],n[0]&&n[0].draggable!==!1){const r={x:t.offsetX,y:t.offsetY};this.calibrateMouse(r),this.dropPens(n,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",n||i)});W(this,"ontouchstart",t=>{this.store.data.locked!==Ot.Disable&&(this.touchStartTimer&&clearTimeout(this.touchStartTimer),this.touchStartTimer=setTimeout(()=>{this.touchStart=performance.now();const i=t.touches[0].pageX-this.clientRect.x,n=t.touches[0].pageY-this.clientRect.y,r={x:i,y:n};if(this.calibrateMouse(r),this.getHover(r),this.onMouseDown({x:i,y:n,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.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};return}else t.touches.length===3&&(this.store.emitter.emit("contextmenu",{e:{x:i,y:n,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))});W(this,"ontouchmove",t=>{var l;if(this.store.data.locked===Ot.Disable)return;t.stopPropagation(),t.preventDefault();const i=performance.now();if(i-this.touchStart<50)return;this.touchStart=i;const n=t.touches,r=n.length,s=t.touches[0].pageX-this.clientRect.x,a=t.touches[0].pageY-this.clientRect.y;if(r===1)this.onMouseMove({x:s,y:a,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&&((l=this.startTouches)==null?void 0:l.length)===2){if(!this.touchMoving&&!this.touchScaling){const c=this.startTouches[0].pageX-n[0].pageX,u=this.startTouches[1].pageX-n[1].pageX,h=this.startTouches[0].pageY-n[0].pageY,d=this.startTouches[1].pageY-n[1].pageY;(c>=0&&u<0||c<=0&&u>0)&&(h>=0&&d<0||h<=0&&d>0)?this.touchScaling=!0:this.touchMoving=!0}if(this.touchScaling){if(this.store.data.disableScale||this.store.options.disableScale)return;const c=Math.hypot(n[0].pageX-n[1].pageX,n[0].pageY-n[1].pageY)/this.initTouchDis;this.scale(this.initScale*c,ct(this.touchCenter))}if(this.touchMoving){if(this.store.data.locked>=Ot.DisableMove&&this.store.data.locked!==Ot.DisableScale||this.store.data.disableScale||this.store.options.disableScale)return;if(this.lastOffsetX){const{scale:c}=this.store.data;this.translate((s-this.lastOffsetX)/c,(a-this.lastOffsetY)/c)}this.lastOffsetX=s,this.lastOffsetY=a}}});W(this,"ontouchend",t=>{if(this.store.data.locked===Ot.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,n=t.changedTouches[0].pageY-this.clientRect.y;this.onMouseUp({x:i,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}),setTimeout(()=>{this.render()},20)});W(this,"onGesturestart",t=>{t.preventDefault()});W(this,"onMouseDown",t=>{var i,n,r,s,a;if(t.buttons===2&&!this.drawingLine&&(this.mouseRight=$i.Down),this.hideInput(),this.popconfirm.hide(),this.store.data.locked===Ot.Disable||t.buttons!==1&&t.buttons!==2){this.hoverType=xt.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===Kt.AddAnchor){this.setAnchor(this.store.pointAt);return}if(!this.store.options.autoAnchor&&!this.drawingLine&&t.shiftKey&&t.ctrlKey&&t.altKey){this.setAnchor(this.store.pointAt),this.drawingLineName=this.store.options.drawingLineName;const l=this.store.activeAnchor;if(!l)return;const c={id:It(),x:l.x,y:l.y};this.drawingLine=this.createDrawingLine(c);let u=le(this.drawingLine);this.drawingLine.calculative.activeAnchor=u,we(this.store.hover,l,this.drawingLine,c),this.drawline();return}if(!(this.hotkeyType===Kt.Translate||this.mouseRight===$i.Down&&!this.store.options.mouseRightActive)){if(this.drawingLine){if(this.store.hoverAnchor){const c=qt(this.drawingLine);this.store.hoverAnchor.type===Ki.Line?wa(c,this.store.hoverAnchor,this.store):(c.x=this.store.hoverAnchor.x,c.y=this.store.hoverAnchor.y),we(this.store.hover,this.store.hoverAnchor,this.drawingLine,c),this.drawline(),this.finishDrawline(!0);return}if(!this.store.options.autoAnchor&&t.shiftKey&&t.altKey&&t.ctrlKey){this.setAnchor(this.store.pointAt);const c=qt(this.drawingLine),u=this.store.activeAnchor;if(!u)return;c.x=u.x,c.y=u.y,we(this.store.hover,u,this.drawingLine,c),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&&((n=this.drawingLine)==null?void 0:n.calculative.worldAnchors.length)>this.store.options.drawingLineLength){this.finishDrawline(!0),((r=this.store.active[0])==null?void 0: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===xt.Node){const c=qt(this.drawingLine),u=Cr(this.store.hover,t);c.x=u.x,c.y=u.y,this.drawingLine.autoTo=!0,we(this.store.hover,u,this.drawingLine,c),this.drawline(),this.finishDrawline(!0);return}const l=qt(this.drawingLine);l.isTemp?(this.drawingLine.calculative.activeAnchor=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2],l.isTemp=void 0):(this.drawingLine.calculative.activeAnchor=l,this.drawingLine.calculative.worldAnchors.push({x:l.x,y:l.y,penId:l.penId})),this.drawingLine.calculative.drawlineH=void 0,this.drawingLineName!=="polyline"&&this.drawline()}if(this.drawingLineName){if(this.hoverType===xt.Node)if(this.store.options.autoAnchor){this.inactive(!0);const l=Cr(this.store.hover,t);this.store.hoverAnchor=l;const c={id:It(),x:l.x,y:l.y};this.drawingLine=this.createDrawingLine(c),this.drawingLine.autoFrom=!0,we(this.store.hover,l,this.drawingLine,c)}else this.inactive(),this.hoverType=xt.None;else if(this.hoverType===xt.NodeAnchor){this.drawingLineName=this.store.options.drawingLineName;const l={id:It(),x:this.store.hoverAnchor.x,y:this.store.hoverAnchor.y};this.drawingLine=this.createDrawingLine(l),this.drawingLine.calculative.activeAnchor=l,we(this.store.hover,this.store.hoverAnchor,this.drawingLine,l)}else if(!this.drawingLine&&this.drawingLineName!=="curve"){this.inactive(!0);const l={id:It(),x:t.x,y:t.y};this.drawingLine=this.createDrawingLine(l),this.drawingLine.calculative.activeAnchor=l}}else if(this.pencil){this.inactive(!0);const l=It(),c={x:t.x,y:t.y,id:It(),penId:l};this.pencilLine=this.getInitPencilLine(c)}else{switch(this.hoverType){case xt.None:(this.store.data.rule||this.store.options.rule)&&!this.store.options.disableRuleLine&&this.addRuleLine(t),this.store.options.resizeMode&&(this.hotkeyType=Kt.None),this.inactive();break;case xt.Node:case xt.Line:if(this.store.hover){if(((s=this.store.active)==null?void 0:s.length)&&this.store.active.length===1&&this.store.hover.id===this.store.active[0].id){this.calcActiveRect();break}const l=Ze(this.store.hover,!0);let c=l||this.store.hover;l&&(l.container||((a=this.store.options.containerShapes)==null?void 0:a.includes(l.name)))&&(c=this.store.hover),t.ctrlKey&&!t.shiftKey?(c.calculative.active?this.willInactivePen=c:this.store.active.length>0&&(c.calculative.active=!0,Rr(c),this.store.active.push(c),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&&yn({x:t.x,y:t.y},this.activeRect))||this.store.active.length==1)&&(c.calculative.active||(this.active([c]),this.store.options.resizeMode&&(this.hotkeyType=Kt.Resize))),this.calcActiveRect()}break;case xt.LineAnchor:this.store.activeAnchor=this.store.hoverAnchor,this.store.hover.calculative.activeAnchor=this.store.hoverAnchor,this.active([this.store.hover]);break;case xt.LineAnchorPrev:case xt.LineAnchorNext:this.store.activeAnchor&&(this.prevAnchor={...this.store.activeAnchor.prev},this.nextAnchor={...this.store.activeAnchor.next});break;case xt.Resize:this.activeInitPos=[],this.store.active.forEach(l=>{this.activeInitPos.push({x:(l.calculative.worldRect.x-this.activeRect.x)/this.activeRect.width,y:(l.calculative.worldRect.y-this.activeRect.y)/this.activeRect.height})});break}this.store.hover&&(this.store.hover.calculative.mouseDown=!0),this.store.emitter.emit("mousedown",{x:t.x,y:t.y,pen:this.store.hover})}this.render()}}});W(this,"onMouseMove",t=>{var n,r,s,a,l,c,u,h;if(this.store.data.locked===Ot.Disable){this.hoverType=xt.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 d=performance.now();d-this.fitTimer>100&&(this.mouseDown?this.updateFit(t):this.inFitBorder(this.mousePos),this.fitTimer=d);return}if(this.mouseDown&&!this.store.options.disableTranslate&&!this.store.data.disableTranslate){if(this.mouseRight===$i.Down&&(this.mouseRight=$i.Translate),this.store.data.locked===Ot.DisableEdit||this.store.data.locked===Ot.DisableScale||this.hotkeyType===Kt.Translate||this.mouseRight===$i.Translate){const{scale:d}=this.store.data;let g=(t.x-this.mouseDown.x)/d,v=(t.y-this.mouseDown.y)/d;t.shiftKey&&!t.ctrlKey&&(v=0),t.ctrlKey&&(g=0),this.translate(g,v);return}if(this.store.data.locked)return;if(!this.drawingLine&&!this.pencil){if(!this.drawingLineName&&!this.movingAnchor){if(this.hoverType===xt.NodeAnchor){if(!this.store.hoverAnchor)return;this.drawingLineName=this.store.options.drawingLineName;const d={id:It(),x:this.store.hoverAnchor.x,y:this.store.hoverAnchor.y};this.drawingLine=this.createDrawingLine(d),this.drawingLine.calculative.activeAnchor=d,we(this.store.hover,this.store.hoverAnchor,this.drawingLine,d),this.drawline();return}}else if(this.drawingLineName&&this.hoverType===xt.None){const d={id:It(),x:t.x,y:t.y};this.drawingLine=this.createDrawingLine(d),this.drawingLine.calculative.activeAnchor=d,this.drawline();return}if(t.buttons===1&&(t.ctrlKey||!this.hoverType&&!this.hotkeyType)&&!(t.ctrlKey&&(this.store.activeAnchor||((n=this.store.active)==null?void 0:n.length)))){this.dragRect={x:Math.min(this.mouseDown.x,t.x),y:Math.min(this.mouseDown.y,t.y),ex:Math.max(this.mouseDown.x,t.x),ey:Math.max(this.mouseDown.y,t.y),width:Math.abs(t.x-this.mouseDown.x),height:Math.abs(t.y-this.mouseDown.y)},this.render();return}if(this.movingAnchor){const d=t.x-this.movingAnchor.x,g=t.y-this.movingAnchor.y;this.translateAnchor(d,g),this.render();return}else if(!((r=this.store.active[0])!=null&&r.locked)){const d={x:t.x,y:t.y};if(this.hoverType===xt.LineAnchor){(this.dockInAnchor(t)||((s=this.store.active[0])==null?void 0:s.lineName)==="line")&&!this.store.options.disableDock&&!this.store.options.disableLineDock&&(this.clearDock(),this.dock=$f(this.store,d,this.store.activeAnchor),(a=this.dock)!=null&&a.xDock&&(d.x+=this.dock.xDock.step),(l=this.dock)!=null&&l.yDock&&(d.y+=this.dock.yDock.step)),this.moveLineAnchor(d,t);return}if(this.hoverType===xt.LineAnchorPrev){this.moveLineAnchorPrev(t);return}if(this.hoverType===xt.LineAnchorNext){this.moveLineAnchorNext(t);return}}if(this.hoverType===xt.Rotate){this.rotatePens({x:t.x,y:t.y});return}if(this.hoverType===xt.Resize){this.resizePens(t);return}if(this.hoverType===xt.Node||this.hoverType===xt.Line){const d=t.x-this.mouseDown.x,g=t.y-this.mouseDown.y,v=20;if(t.ctrlKey&&!t.shiftKey&&(Math.abs(d)>=v||Math.abs(g)>=v)&&(this.willInactivePen=void 0),this.store.active.length===1){const y=this.store.active[0];if((y.locked===void 0||y.locked1&&(y=qt(this.drawingLine)),y?(y.prev=void 0,y.next=void 0,y.id||(y.id=It()),y.x=v.x,y.y=v.y,y.connectTo=void 0):(y={...v},this.drawingLine.calculative.worldAnchors.push(y)),(this.hoverType===xt.NodeAnchor||this.hoverType===xt.LineAnchor)&&(this.store.hoverAnchor.type!==Ki.Line&&(y.x=this.store.hoverAnchor.x,y.y=this.store.hoverAnchor.y),y.connectTo=this.store.hoverAnchor.penId,this.drawingLineName==="polyline"&&(y.isTemp=!1)),this.drawingLineName==="line"){if(t.ctrlKey&&!t.shiftKey)y.x=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].x;else if(t.shiftKey&&!t.ctrlKey)y.y=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2].y;else if(t.shiftKey&&t.ctrlKey){let w=this.drawingLine.calculative.worldAnchors[this.drawingLine.calculative.worldAnchors.length-2];this.getSpecialAngle(y,w)}}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===Kt.AddAnchor&&(this.patchFlags=!0),this.render(!1)});W(this,"onMouseUp",t=>{if(this.store.data.locked===Ot.Disable){this.hoverType=xt.None;return}if(!!this.mouseDown){if(this.mouseRight===$i.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=$i.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=qt(this.drawingLine);this.store.hoverAnchor.type===Ki.Line?wa(i,this.store.hoverAnchor,this.store):(i.x=this.store.hoverAnchor.x,i.y=this.store.hoverAnchor.y),we(this.store.hover,this.store.hoverAnchor,this.drawingLine,i),this.drawline(),this.finishDrawline(!0);return}if(this.store.options.autoAnchor&&this.hoverType===xt.Node){const i=qt(this.drawingLine),n=Cr(this.store.hover,t);i.x=n.x,i.y=n.y,this.drawingLine.autoTo=!0,we(this.store.hover,n,this.drawingLine,i),this.drawline(),this.finishDrawline(!0);return}}if(this.hoverType===xt.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],n=le(i),r=qt(i);if(this.store.hoverAnchor){const s=this.store.hover,a=le(s)===this.store.hoverAnchor,l=qt(s)===this.store.hoverAnchor,c=n===this.store.activeAnchor,u=r===this.store.activeAnchor;if((t.ctrlKey||t.altKey)&&s.type===jt.Line&&(a||l)&&(c||u)){const h=s.calculative.worldAnchors.map(d=>({...d,penId:i.id}));a?h.shift():l&&h.pop(),(a&&c||l&&u)&&h.reverse(),c?(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([s]),this.render()}else this.store.activeAnchor&&(this.store.hoverAnchor.type===Ki.Line?wa(this.store.activeAnchor,this.store.hoverAnchor,this.store):(this.store.activeAnchor.x=this.store.hoverAnchor.x,this.store.activeAnchor.y=this.store.hoverAnchor.y),we(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,At.path2dDraws.line(i)),this.initLineRect(i)}else n===this.store.activeAnchor&&i.autoFrom?this.calcAutoAnchor(i,n,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===xt.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(n=>{if(n.visible===!1||n.locked>=Ot.DisableMove||n.parentId||n.isRuleLine)return!1;if(Ji(n.calculative.worldRect,this.dragRect,t.ctrlKey||this.store.options.dragAllIn))return n.type===jt.Line&&!this.store.options.dragAllIn?Bl(n,this.dragRect):!0});this.active(i)}if(t.button!==2&&(Za(this.mouseDown,t)<2&&(this.store.hover&&this.store.hover.input&&this.showInput(this.store.hover),this.store.emitter.emit("click",{x:t.x,y:t.y,pen:this.store.hover})),this.store.hover&&(this.store.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,Rr(this.willInactivePen,!1);const i=this.store.active.findIndex(n=>n===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()}});W(this,"clearDock",()=>{var s,a,l,c;const t=(a=(s=this.dock)==null?void 0:s.xDock)==null?void 0:a.penId,i=(c=(l=this.dock)==null?void 0:l.yDock)==null?void 0:c.penId,n=this.store.pens[t];n&&(n.calculative.isDock=!1);const r=this.store.pens[i];r&&(r.calculative.isDock=!1),this.dock=void 0});W(this,"onResize",()=>{this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.resize(),this.timer=void 0},100)});W(this,"onScroll",()=>{this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.clientRect=this.canvas.getBoundingClientRect(),this.timer=void 0},100)});W(this,"calibrateMouse",t=>(t.x-=this.store.data.x,t.y-=this.store.data.y,t));W(this,"getContainerHover",t=>{var n;if(this.dragRect)return;this.store.hoverContainer=void 0;const i=this.store.data.pens.filter(r=>{var s;return r.container||((s=this.store.options.containerShapes)==null?void 0:s.includes(r.name))});if(i.length)for(let r=i.length-1;r>=0;--r){const s=i[r];if(!(s.visible==!1||s.calculative.inView==!1||s.locked===Ot.Disable)){if(yn(t,s.calculative.worldRect))this.store.hoverContainer=s,(n=s==null?void 0:s.onMouseMove)==null||n.call(s,s,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(s===this.store.hoverContainer&&(this.store.hoverContainer=void 0,this.store.lastHoverContainer!==this.store.hoverContainer)){this.patchFlags=!0;const a=this.store.lastHoverContainer.calculative.canvas.store.pens[this.store.lastHoverContainer.id+Fe];this.store.lastHoverContainer&&!a&&(this.store.lastHoverContainer.calculative.containerHover=!1,this.store.emitter.emit("leave",this.store.lastHoverContainer)),this.store.lastHoverContainer=this.store.hoverContainer}}}});W(this,"getHover",t=>{var r,s;if(this.dragRect||this.canvasImage.fitFlag)return;let i=xt.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 n=this.store.active.length===1&&this.store.active[0].type;if(!this.drawingLineName&&this.hotkeyType!==Kt.AddAnchor&&this.activeRect&&!n&&!this.store.data.locked){const a=Ll(this.store.active),l=qf(this.store.active)||this.store.options.disableRotate,c=jf(this.store.active)||this.store.options.disableSize;if(!a&&!l){const u={x:this.activeRect.center.x,y:this.activeRect.y-30};this.activeRect.rotate&&Gt(u,this.activeRect.rotate,this.activeRect.pivot||this.activeRect.center),!this.hotkeyType&&Ar(t,u,this.pointSize)&&(i=xt.Rotate,this.externalElements.style.cursor=`url("${this.store.options.rotateCursor}"), auto`)}if(!a&&!c)for(let u=0;u<8;u++){const h=u<4;if((this.hotkeyType===Kt.Resize||h&&!this.hotkeyType)&&Ar(t,this.sizeCPs[u],this.pointSize)){let g=h?Df:Mf,v=0;Math.abs(this.activeRect.rotate%90-45)<25?(g=h?Mf:Df,v=Math.round((this.activeRect.rotate-45)/90)+(h?0:1)):v=Math.round(this.activeRect.rotate/90),i=xt.Resize,this.resizeIndex=u,this.externalElements.style.cursor=g[(u+v)%4];break}}}i===xt.None&&(i=this.inPens(t,this.store.data.pens)),!i&&!n&&yn(t,this.activeRect)&&(i=xt.Node,this.externalElements.style.cursor="move"),this.hoverType=i,i===xt.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,rs(Ze(this.store.lastHover,!0)||this.store.lastHover,!1),this.store.emitter.emit("leave",this.store.lastHover),this.tooltip.hide()),this.store.hover&&(this.store.hover.calculative.hover=!0,rs(Ze(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),(s=(r=this.store.hover)==null?void 0:r.onMouseMove)==null||s.call(r,this.store.hover,this.mousePos)});W(this,"inPens",(t,i)=>{var r;let n=xt.None;t:for(let s=i.length-1;s>=0;--s){const a=i[s];if(a.visible==!1||a.calculative.inView==!1||a.locked===Ot.Disable)continue;const l=$a(a);if(!(!a.calculative.active&&!Kn(t,a.calculative.worldRect,l)&&!yn(t,a.calculative.worldRect))){if(!this.store.data.locked&&this.hotkeyType!==Kt.Resize&&a.calculative.worldAnchors){for(const c of a.calculative.worldAnchors)if(n=this.inAnchor(t,a,c),n){let u=ct(c);Object.assign(u,t),this.title.show(u,a);break t}}if(a.type){if(a.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 c=ok(t,a);if(c){!this.store.data.locked&&!a.locked?this.hotkeyType===Kt.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move":this.externalElements.style.cursor=this.store.options.hoverCursor,a.calculative.disabled&&(this.externalElements.style.cursor="not-allowed"),this.store.hover=a,this.store.pointAt=c.point,this.store.pointAtIndex=c.i,this.initTemplateCanvas([this.store.hover]),n=xt.Line;break}}else{if(a.children){const u=[];if(a.children.forEach(h=>{this.store.pens[h]&&u.push(this.store.pens[h])}),n=this.inPens(t,u),n)break}let c=!1;if(a.name==="line"?c=Kn(t,a.calculative.worldRect,a.lineWidth):c=yn(t,a.calculative.worldRect),c){if(a.type===jt.Node&&a.name==="line"&&!T2(t,a.calculative.worldAnchors))continue;if(!this.store.data.locked&&!a.locked?this.hotkeyType===Kt.AddAnchor?this.externalElements.style.cursor="pointer":this.externalElements.style.cursor="move":this.externalElements.style.cursor=this.store.options.hoverCursor,a.calculative.disabled&&(this.externalElements.style.cursor="not-allowed"),this.store.hover=a,this.initTemplateCanvas([this.store.hover]),n=xt.Node,this.store.pointAt=t,!t.ctrlKey){let{x:u,y:h,ex:d,ey:g,rotate:v,center:y}=this.store.hover.calculative.worldRect;if(v){const w=[{x:u,y:h},{x:d,y:h},{x:d,y:g},{x:u,y:g}];w.forEach(_=>{Gt(_,v,y)});let p=w[w.length-1];for(const _ of w){if(p.y>t.y!=_.y>t.y){const A=_.x+(t.y-_.y)*(p.x-_.x)/(p.y-_.y);Math.abs(A-this.store.pointAt.x)<10&&(this.store.pointAt.x=A)}p=_}}else this.store.pointAt.x-10d&&(this.store.pointAt.x=d),this.store.pointAt.y-10g&&(this.store.pointAt.y=g)}break}}}}return n});W(this,"dockInAnchor",t=>{var i,n;this.store.hover=void 0;for(let r=this.store.data.pens.length-1;r>=0;--r){const s=this.store.data.pens[r];if(s.visible==!1||s.locked===Ot.Disable||s===this.store.active[0])continue;let a=$a(s);if(a+=2*this.store.options.anchorRadius,!!Kn(t,s.calculative.worldRect,a)&&(this.store.hover=s,this.hotkeyType!==Kt.Resize&&s.calculative.worldAnchors))for(const l of s.calculative.worldAnchors){if(l.twoWay===Ee.In){const c=qt(this.store.active[0]);if(this.store.activeAnchor.id!==c.id)continue}if(l.twoWay===Ee.Out){const c=le(this.store.active[0]);if(this.store.activeAnchor.id!==c.id)continue}if(!(l.twoWay===Ee.DisableConnected||l.twoWay===Ee.Disable||((i=this.store.activeAnchor)==null?void 0:i.twoWay)===Ee.DisableConnectTo||((n=this.store.activeAnchor)==null?void 0:n.twoWay)===Ee.Disable)&&(this.title.hide(),this.inAnchor(t,s,l))){let c=ct(l);return Object.assign(c,t),this.title.show(c,s),!0}}}});W(this,"imageTimer");W(this,"templateImageTimer");W(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{const t=this.offscreen.getContext("2d");t.strokeStyle=cs(this.store);for(const i of this.store.data.pens)!isFinite(i.x)||i.canvasLayer!==zt.CanvasTemplate&&(i.name==="combine"&&!i.draw||i.calculative.inView&&(i.canvasLayer===zt.CanvasMain&&i.name!=="gif"&&i.image&&i.calculative.img&&(t.save(),Vn(t,i),i.calculative.rotate&&Qi(t,i),$n(t,i),Pr(t,i),t.restore()),Nn(t,i)));this.drawingLine&&Nn(t,this.drawingLine),this.pencilLine&&Nn(t,this.pencilLine),this.movingPens&&this.movingPens.forEach(i=>{this.renderPenContainChild(t,i)})});W(this,"renderPenContainChild",(t,i)=>{var n;i.calculative.inView&&Nn(t,i),(n=i.children)==null||n.forEach(r=>{const s=this.store.pens[r];s&&this.renderPenContainChild(t,s)})});W(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.options.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,Ll(this.store.active)||qf(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.options.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()}});W(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!==Kt.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===Kt.AddAnchor&&i.push(this.store.pointAt),i&&(t.strokeStyle=this.store.hover.anchorColor||this.store.options.anchorColor,t.fillStyle=this.store.hover.anchorBackground||this.store.options.anchorBackground,i.forEach(n=>{if(n.hidden&&n.locked>Ot.DisableEdit)return;if(n===this.store.hoverAnchor){t.save();const s=this.store.hover.hoverAnchorColor||this.store.options.hoverAnchorColor;t.strokeStyle=s,t.fillStyle=s}t.beginPath();let r=n.radius||this.store.hover.anchorRadius||this.store.options.anchorRadius;if(this.store.hover.type&&!n.radius&&!this.store.hover.anchorRadius&&(r=3,this.store.hover.calculative.lineWidth>3&&(r=this.store.hover.calculative.lineWidth)),n.type===Ki.Line){let s=this.store.pens[n.penId].rotate||0;this.store.pens[n.penId].calculative.flipX&&(s*=-1),this.store.pens[n.penId].calculative.flipY&&(s*=-1);let a=n.rotate+s;this.store.pens[n.penId].calculative.flipX&&(a*=-1),this.store.pens[n.penId].calculative.flipY&&(a*=-1),t.save(),t.translate(n.x,n.y),t.rotate(a*Math.PI/180),t.translate(-n.x,-n.y),t.rect(n.x-n.length*this.store.data.scale/2,n.y-r,n.length*this.store.data.scale,r*2),t.restore()}else t.arc(n.x,n.y,r,0,Math.PI*2);if(this.store.hover.type&&this.store.hoverAnchor===n?(t.save(),t.strokeStyle=this.store.hover.activeColor||this.store.options.activeColor,t.fillStyle=t.strokeStyle):(n.color||n.background)&&(t.save(),t.strokeStyle=n.color,t.fillStyle=n.background),t.fill(),t.stroke(),n===this.store.hoverAnchor&&t.restore(),(this.store.hover.type&&this.store.hoverAnchor===n||n.color||n.background)&&t.restore(),!this.store.hover.parentId&&this.store.hover.children&&this.store.hover.children.length>0&&n===this.store.hoverAnchor){t.save(),t.beginPath(),t.lineWidth=3;const s=this.store.hover.hoverAnchorColor||this.store.options.hoverAnchorColor;globalThis.pSBC&&(t.strokeStyle=globalThis.pSBC(.5,s)),t.arc(n.x,n.y,r+1.5,0,Math.PI*2),t.stroke(),t.restore()}}))}this.hotkeyType!==Kt.AddAnchor&&!this.movingPens&&this.activeRect&&!(this.store.active.length===1&&this.store.active[0].type)&&!Ll(this.store.active)&&!jf(this.store.active)&&!this.store.options.disableSize&&(t.strokeStyle=this.store.options.activeColor,t.fillStyle="#ffffff",this.sizeCPs.forEach((i,n)=>{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)),(n<4||this.hotkeyType===Kt.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=qa(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()});W(this,"pastePen",(t,i)=>{const n=t.id;if(Kf(t),t.parentId=i,t.type===jt.Line?this.changeNodeConnectedLine(n,t,this.store.clipboard.pens):this.changeLineAnchors(n,t,this.store.clipboard.pens),!t.parentId){const s=this.getPenRect(t,this.store.clipboard.origin,this.store.clipboard.scale),a=this.getPenRect(this.store.clipboard.initRect,this.store.clipboard.origin,this.store.clipboard.scale),{origin:l,scale:c}=this.store.data;t.x=l.x+s.x*c,t.y=l.y+s.y*c,t.width=s.width*c,t.height=s.height*c,a.x=l.x+a.x*c,a.y=l.y+a.y*c,ee(a),this.store.clipboard.pos&&(t.x-=a.center.x-this.store.clipboard.pos.x,t.y-=a.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)||(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 s of t.children){const a=this.store.clipboard.pens.find(l=>l.id===s);a&&r.push(this.pastePen(a,t.id).id)}return t.children=r,Gi(t,!0),t});W(this,"ondblclick",t=>{var i;this.store.hover&&(!this.store.data.locked||this.store.hover.dbInput)&&!this.store.options.disableInput&&(this.store.hover.onShowInput?this.store.hover.onShowInput(this.store.hover,t):this.store.hover&&this.store.hover.parentId?((i=this.store.active)==null?void 0:i.length)===1&&this.store.active[0].id===this.store.hover.id?this.showInput(this.store.hover):(this.store.pens[this.store.hover.parentId].children.forEach(n=>{this.store.pens[n].calculative.active=!1,this.store.pens[n].calculative.hover=!1}),this.active([this.store.hover])):this.showInput(this.store.hover)),this.store.emitter.emit("dblclick",{x:t.x,y:t.y,pen:this.store.hover})});W(this,"showInput",(t,i,n="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,l=`${(t.calculative.tempText===void 0?t.text+""||"":t.calculative.tempText).replace(/\x20/g," ").split(/[\s\n]/).join("
")}
`.replace("","").replace(/\\<\/div\>/g,"

");this.inputDiv.innerHTML=l,this.inputParent.style.left=r.x+this.store.data.x-(t.textLeft||0)+"px",this.inputParent.style.top=r.y+this.store.data.y-(t.textTop||0)+"px";let c=r.width;this.inputParent.style.width=(c<0?12:c)+"px",this.inputParent.style.height=r.height+(t.textTop||0)+"px",this.inputParent.style.zIndex="9999",this.inputParent.style.background=n,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||"#fff",this.dropdown.style.color=t.dropdownColor||"#bdc7db",this.setDropdownList()),this.inputDiv.contentEditable="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()});W(this,"setInputStyle",t=>{t.text||(t.text="");let i;for(let c=0;c1?t.textLeft*s:t.textLeft*s/a}px;`),t.textTop&&(n+=`margin-top:${a>1?t.textTop*s:t.textTop*s/a}px;`),t.lineHeight&&(n+=`line-height:${a>1?t.fontSize*t.lineHeight*a:t.fontSize*t.lineHeight*s}px;`),t.textHeight)n+=`height:${a>1?t.textHeight*s*a:t.textHeight*s}px;`;else{let c=t.calculative.worldRect.height/a;c<0&&(c=0);let u=t.fontSize*a<12?c*s:c*a*s;u-1?t.textWidth*t.calculative.worldRect.width:t.textWidth,t.whiteSpace!=="pre-line"&&(l1?l*s*a:l*s}px;`);else if(t.whiteSpace===void 0||t.whiteSpace==="break-all"){let c=(t.calculative.worldTextRect.width||12)/a;c<0&&(c=0),n+=`width:${t.fontSize*a<12?c*s:c*a}px;`}if(t.whiteSpace&&(t.whiteSpace==="pre-line"?n+="white-space:pre;":(n+=`white-space:${t.whiteSpace};`,t.whiteSpace==="nowrap"&&(r+="display:contents;"))),t.whiteSpace!=="nowrap"){let c=t.fontSize*1.2*t.text.length,u=(l||t.calculative.worldRect.width/a)*Math.floor(t.calculative.worldRect.height/a/(t.lineHeight*t.fontSize));c>u&&(n+="justify-content: start;")}i.deleteRule(0),i.deleteRule(0),i.insertRule(`.meta2d-input .input-div{ 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;${n}}`),i.insertRule(`.input-div div{${r}}`)});W(this,"hideInput",()=>{if(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(/\/g,` `).replace(/\<\/div\>/g,"").replace(/\/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=[ct(t,!0)];t.text=this.inputDiv.dataset.value,t.calculative.text=t.text,this.inputDiv.dataset.penId=void 0,t.text&&t.textAutoAdjust&&B_(t),Ti(t),this.patchFlags=!0,this.pushHistory({type:bt.Update,pens:[ct(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.length==0&&Ti(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()});W(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 s=document.createElement("div");s.innerText="None",s.style.padding="5px 12px",s.style.color="#ddd",this.dropdown.appendChild(s);return}const n=this.inputDiv.innerHTML.replace(/\/g,` `).replace(/\<\/div\>/g,"").replace(/\/g,"");let r=0;for(const s of i.dropdownList){const a=typeof s=="string"?s:s.text;t&&n?a.includes(n)&&this.dropdownAppendOption(a,r):this.dropdownAppendOption(a,r),++r}if(!this.dropdown.hasChildNodes()){const s=document.createElement("div");s.innerText="None",s.style.padding="5px 12px",s.style.color="#ddd",this.dropdown.appendChild(s)}});W(this,"selectDropdown",t=>{const i=t.target,n=this.store.pens[this.inputDiv.dataset.penId];if(!i||!n||!n.dropdownList)return;const r=+i.dataset.i,s=n.dropdownList[r];if(!s)return;const a=[ct(n,!0)];typeof s=="object"?(this.updateValue(n,{...s}),n.calculative.text=void 0,this.calcActiveRect()):n.text=s+"",this.inputDiv.innerText=n.text,this.hideInput(),this.pushHistory({type:bt.Update,pens:[ct(n,!0)],initPens:a}),this.render(),this.store.emitter.emit("change",n),this.store.emitter.emit("valueUpdate",n)});W(this,"inFitBorder",t=>{let i;const n=this.store.data.width||this.store.options.width,r=this.store.data.height||this.store.options.height;let s={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 a=this.canvasImage.activeFit;this.externalElements.style.cursor="default",s.y>r*a.y-10&&s.yr*(a.y+a.height)-10&&s.yn*a.x-10&&s.xn*(a.x+a.width)-10&&s.x{this.patchFlags=!0,this.store.lastHover&&(this.store.lastHover.calculative.hover=!1);let s=this.store.data.pens.find(a=>a.calculative.hover===!0);rs(s,!1)},this.popconfirm=new Mk(i,n),this.dialog=new Ik(i),this.title=new Ka(i),this.store.options.scroll&&(this.scroll=new ig(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.externalElements.ontouchstart=this.ontouchstart,this.externalElements.ontouchmove=this.ontouchmove,this.externalElements.ontouchend=this.ontouchend,this.externalElements.onmousedown=t=>{this.onMouseDown({x:t.offsetX,y:t.offsetY,clientX:t.clientX,clientY:t.clientY,pageX:t.pageX,pageY:t.pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons})},this.externalElements.onmousemove=t=>{t.target===this.externalElements&&this.onMouseMove({x:t.offsetX,y:t.offsetY,clientX:t.clientX,clientY:t.clientY,pageX:t.pageX,pageY:t.pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons})},this.externalElements.onmouseup=t=>{this.onMouseUp({x:t.offsetX,y:t.offsetY,clientX:t.clientX,clientY:t.clientY,pageX:t.pageX,pageY:t.pageY,ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey,altKey:t.altKey,buttons:t.buttons,button:t.button})},this.externalElements.onmouseleave=t=>{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=this.ondblclick,this.externalElements.tabIndex=0,this.externalElements.onblur=()=>{this.mouseDown=void 0},this.externalElements.onwheel=this.onwheel,document.addEventListener("copy",this.onCopy),document.addEventListener("cut",this.onCut),document.addEventListener("paste",this.onPaste),this.store.options.keydown){case zn.Document:document.addEventListener("keydown",this.onkeydown),document.addEventListener("keyup",this.onkeyup);break;case zn.Canvas:this.externalElements.addEventListener("keydown",this.onkeydown),this.externalElements.addEventListener("keyup",this.onkeyup);break}}splitLine(t,i){const n=t.calculative.worldAnchors,r=n.findIndex(h=>h===i);if([-1,0,n.length-1].includes(r))return;const s=ct(t,!0),a=ct(t,!0),l=It();a.id=l,a.calculative.canvas=this,a.calculative.active=!1,a.calculative.hover=!1;const c=ct(n.slice(0,r+1)),u=ct(n.slice(r)).map(h=>(h.penId=l,h));t.calculative.worldAnchors=c,a.calculative.worldAnchors=u,this.initLineRect(t),this.initLineRect(a),this.store.data.pens.push(a),this.store.pens[l]=a,this.pushHistory({type:bt.Add,pens:[ct(a,!0)],step:2}),this.pushHistory({type:bt.Update,initPens:[s],pens:[ct(t,!0)],step:2})}translateAnchor(t,i){this.movingAnchor.x+=t,this.movingAnchor.y+=i;const n=this.movingAnchor.penId;if(n){const r=this.store.pens[n],s=r.calculative.worldRect;this.movingAnchor.xs.ex&&(this.movingAnchor.x=s.ex),this.movingAnchor.ys.ey&&(this.movingAnchor.y=s.ey);const a=hs(this.movingAnchor,s),l=r.anchors.findIndex(c=>c.id===this.movingAnchor.id);r.anchors[l]=a,this.patchFlags=!0}}async fileToPen(t,i){let n="";return this.store.options.uploadFn?n=await this.store.options.uploadFn(t):this.store.options.uploadUrl?n=await N_(t,this.store.options.uploadUrl,this.store.options.uploadParams,this.store.options.uploadHeaders):n=await O_(t),new Promise((r,s)=>{const a=new Image;a.onload=()=>{At.htmlElements[n]=a,r({width:a.width,height:a.height,name:i?"gif":"image",image:n})},a.onerror=l=>{s(l)},a.crossOrigin="anonymous",a.src=n})}async dropPens(t,i){var c;this.randomIdObj={};for(const u of t)!u.parentId&&this.randomCombineId(u,t);if(Object.keys(this.randomIdObj).length!==0)for(const u of t)u.type?(u.anchors[0].connectTo=this.randomIdObj[u.anchors[0].connectTo],u.anchors[u.anchors.length-1].connectTo=this.randomIdObj[u.anchors[u.anchors.length-1].connectTo]):(c=u.connectedLines)==null||c.forEach(h=>{h.lineAnchor=this.randomIdObj[h.lineAnchor],h.lineId=this.randomIdObj[h.lineId]});for(const u of t)u.id||(u.id=It()),!u.calculative&&(u.calculative={canvas:this}),this.store.pens[u.id]=u;let n=0,r=0,s=0;for(const u of t)u.parentId||(u.width*=this.store.data.scale,u.height*=this.store.data.scale,u.x=i.x-u.width/2+s,u.y=i.y-u.height/2+r,u.tags&&u.tags.includes("meta3d")&&(u.x=this.store.data.origin.x,u.y=this.store.data.origin.y),u.dataset&&(n%2===0?s=u.width-40*this.store.data.scale:s=0,n++,n%2===0&&(r+=u.height+10*this.store.data.scale)));const a=this.store.data.width||this.store.options.width,l=this.store.data.height||this.store.options.height;if(a&&l){let u={x:this.store.data.origin.x,y:this.store.data.origin.y,width:a*this.store.data.scale,height:l*this.store.data.scale},h=!0;for(const d of t)if(!d.parentId){let g=[{x:d.x,y:d.y},{x:d.x+d.width,y:d.y},{x:d.x,y:d.y+d.height},{x:d.x+d.width,y:d.y+d.height},{x:d.x+d.width/2,y:d.y+d.height/2}];if(d.x===u.x&&d.y===u.y&&d.width===u.width&&d.height===u.height||g.some(v=>yn(v,u))){h=!1,this.store.options.strictScope&&(d.xu.x+u.width&&(d.x=u.x+u.width-d.width),d.y+d.height>u.y+u.height&&(d.y=u.y+u.height-d.height));break}}if(h){console.info("\u753B\u7B14\u5728\u5927\u5C4F\u8303\u56F4\u5916");return}}await this.addPens(t,!0),this.active(t.filter(u=>!u.parentId)),this.render(),this.externalElements.focus()}randomCombineId(t,i,n){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]):t.connectedLines&&t.connectedLines.length&&(r=[t.id]),Kf(t),r&&(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=n;const s=[];if(Array.isArray(t.children))for(const a of t.children){const l=i.find(c=>c.id===a);l&&s.push(this.randomCombineId(l,i,t.id).id)}return t.children=s,t}async addPens(t,i,n){if(this.beforeAddPens&&await this.beforeAddPens(t)!=!0)return[];const r=[];for(const s of t)this.beforeAddPen&&this.beforeAddPen(s)!=!0||(n&&(s.x=s.x*this.store.data.scale+this.store.data.origin.x,s.y=s.y*this.store.data.scale+this.store.data.origin.y,s.width=s.width*this.store.data.scale,s.height=s.height*this.store.data.scale),this.makePen(s),r.push(s));return this.render(),this.store.emitter.emit("add",r),i&&this.pushHistory({type:bt.Add,pens:ct(r,!0)}),r}getInitPencilLine(t){const{data:i,options:n}=this.store,r=i.scale,s=i.lineWidth||1;return{id:t.penId,name:"line",x:t.x,y:t.y,type:jt.Line,calculative:{canvas:this,pencil:!0,active:!0,worldAnchors:[t],lineWidth:s*r},fromArrow:i.fromArrow||n.fromArrow,toArrow:i.toArrow||n.toArrow,lineWidth:s}}createDrawingLine(t){this.inactive();const{data:i,options:n}=this.store,r=i.scale,s=i.lineWidth||1;return t.penId=It(),{id:t.penId,name:"line",lineName:this.drawingLineName,x:t.x,y:t.y,type:jt.Line,calculative:{canvas:this,active:!0,worldAnchors:[t],lineWidth:s*r},fromArrow:i.fromArrow||n.fromArrow,toArrow:i.toArrow||n.toArrow,lineWidth:s}}addRuleLine(t){const{x:i,y:n,scale:r,origin:s}=this.store.data,a=t.x+i,l=t.y+n;let c=t.x,u=t.y,h=0,d=0,g=0,v=0;if(a<=l&&a<20)c=-i,h=this.width,g=1,t.ctrlKey||(u=Math.round((u-s.y)/(r*10))*(r*10)+s.y);else if(lt.isRuleLine)}alignPenToGrid(t){var n;if(this.store.options.autoAlignGrid&&this.store.data.grid&&!t.type){const r=this.store.data.gridSize||this.store.options.gridSize,{origin:s,scale:a}=this.store.data,{x:l,y:c}=t,u={x:l,y:c},h=this.getPenRect(t),d=parseInt((h.x/r).toFixed()),g=parseInt((h.y/r).toFixed()),v=d*r,y=g*r;u.x=s.x+v*a,u.y=s.y+y*a,Object.assign(t,u),(n=t.onMove)==null||n.call(t,t),this.updatePenRect(t),this.calcActiveRect(),this.getSizeCPs()}}movedActivePens(t){let i=this.getAllFollowersByPens(this.store.active,!1);const n=ct(i,!0),r=this.store.data.gridSize||this.store.options.gridSize,{origin:s,scale:a}=this.store.data,l=this.store.options.autoAlignGrid&&this.store.data.grid;if(i.forEach(g=>{var _;const v=this.movingPens.findIndex(A=>A.id===g.id+Fe);if(v<0)return;const{x:y,y:w}=this.movingPens[v],p={x:y,y:w};if(l&&!this.movingPens[v].type){const A=this.getPenRect(this.movingPens[v]),x=parseInt((A.x/r).toFixed()),E=parseInt((A.y/r).toFixed()),I=x*r,M=E*r;p.x=s.x+I*a,p.y=s.y+M*a}Object.assign(g,p),(_=g.onMove)==null||_.call(g,g),this.updatePenRect(g),this.updateLines(g),this.store.emitter.emit("updateLines",g),this.patchFlagsLines.forEach(A=>{A.type&&this.initLineRect(A)}),this.patchFlagsLines.clear(),g.calculative.x=g.x,g.calculative.y=g.y,g.calculative.initRect&&(g.calculative.initRect.x=g.calculative.x,g.calculative.initRect.y=g.calculative.y,g.calculative.initRect.ex=g.calculative.x+g.calculative.width,g.calculative.initRect.ey=g.calculative.y+g.calculative.height),Uv(g),g.parentId&&this.parent.updateRectbyChild(g.calculative.worldRect,g,this.store.pens[g.parentId])}),this.initImageCanvas(this.store.active),this.initTemplateCanvas(this.store.active),!this.dock)return;const{xDock:c,yDock:u}=this.dock;let h;c&&(h=this.store.pens[c.penId]),!h&&u&&(h=this.store.pens[u.penId]);const d=ct(this.store.active,!0);if(t&&this.store.active.length===1&&(h==null?void 0:h.type)===1&&((c==null?void 0:c.anchorId)||(u==null?void 0:u.anchorId))){const g=le(h),v=qt(h);if(c!=null&&c.anchorId){const y=this.store.pens[this.store.active[0].id+Fe].calculative.worldAnchors.find(w=>w.id===c.anchorId);y.x===g.x&&y.y===g.y?(n.push(ct(h,!0)),we(this.store.active[0],y,h,g),d.push(ct(h,!0))):y.x===v.x&&y.y===v.y&&(n.push(ct(h,!0)),we(this.store.active[0],y,h,v),d.push(ct(h,!0)))}else if(u!=null&&u.anchorId){const y=this.store.pens[this.store.active[0].id+Fe].calculative.worldAnchors.find(w=>w.id===u.anchorId);y.x===g.x&&y.y===g.y?(n.push(ct(h,!0)),we(this.store.active[0],y,h,g),d.push(ct(h,!0))):y.x===v.x&&y.y===v.y&&(n.push(ct(h,!0)),we(this.store.active[0],y,h,v),d.push(ct(h,!0)))}}l&&(this.calcActiveRect(),this.getSizeCPs()),this.pushHistory({type:bt.Update,pens:d,initPens:n}),this.store.emitter.emit("translatePens",d)}copyMovedPens(){this.copy(this.store.active.map((t,i)=>{const{x:n,y:r}=this.movingPens[i];return this.updateLines(t),{...t,x:n,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===zt.CanvasTemplate)&&this.canvasTemplate.init()}hasImage(t,i){var n;return t.image&&t.name!=="gif"?i?t.canvasLayer===zt.CanvasImageBottom:t.canvasLayer===zt.CanvasImage:(n=t.children)==null?void 0:n.some(r=>{const s=this.store.pens[r];return s&&this.hasImage(s,i)})}inactive(t){!this.store.active.length||(this.initTemplateCanvas(this.store.active),this.store.active.forEach(i=>{i.calculative.active=void 0,i.calculative.activeAnchor=void 0,i.calculative.hover=!1,Rr(i,!1)}),!t&&this.store.emitter.emit("inactive",this.store.active),this.store.active=[],this.activeRect=void 0,this.sizeCPs=void 0,this.store.activeAnchor=void 0,this.patchFlags=!0)}active(t,i=!0){if(this.store.active){i&&this.store.emitter.emit("inactive",this.store.active);for(const n of this.store.active)n.calculative.active=void 0,n.calculative.hover=!1,Rr(n,!1)}this.store.active=[],t.forEach(n=>{n.calculative.active=!0,Rr(n)}),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=tn(this.activeRect);const t=[{x:.5,y:0},{x:1,y:.5},{x:.5,y:1},{x:0,y:.5}],{x:i,y:n,width:r,height:s,rotate:a,center:l}=this.activeRect;t.forEach(c=>{const u={x:c.x*r+i,y:c.y*s+n};Gt(u,a,l),this.sizeCPs.push(u)})}getSpecialAngle(t,i){let n=0;t.x-i.x!==0?(n=Math.atan((i.y-t.y)/(t.x-i.x))*180/Math.PI,t.x0?n-=180:n+=180)):i.y>t.y?n=90:i.yOt.DisableEdit||!(i.type&&i.calculative.active)&&this.store.options.disableAnchor||i.disableAnchor)return xt.None;if((this.mouseDown||this.drawingLine)&&i.name==="line"&&n.connectTo){const s=this.findOne(n.connectTo);if((s==null?void 0:s.calculative)&&!(s!=null&&s.calculative.active)){i=s;const a=s.calculative.worldAnchors.find(l=>l.id===n.anchorId);a&&(n=a)}}if(n.twoWay===Ee.Disable&&i.name!=="line")return xt.None;if(i.name==="line"&&n.connectTo){let s=(r=this.findOne(n.connectTo))==null?void 0:r.anchors.find(a=>a.id===n.anchorId);if(s&&s.twoWay)return xt.None}if(this.drawingLine){if(n.twoWay===Ee.Out)return xt.None}else if(!(this.mouseDown&&this.hoverType===xt.LineAnchor)){if(n.twoWay===Ee.In)return xt.None}if(Ar(t,n,this.pointSize,n.penId?this.store.pens[n.penId]:void 0))return n!==this.store.hoverAnchor&&(this.patchFlags=!0),this.store.hoverAnchor=n,this.store.hover=i,i.type?n.connectTo&&!i.calculative.active&&(this.store.hover=this.store.pens[n.connectTo],this.store.hover)?(this.store.hoverAnchor=this.store.hover.calculative.worldAnchors.find(s=>s.id===n.anchorId),this.store.hoverAnchor?(this.externalElements.style.cursor="crosshair",xt.NodeAnchor):xt.None):(this.hotkeyType===Kt.AddAnchor?this.externalElements.style.cursor="vertical-text":this.externalElements.style.cursor="pointer",xt.LineAnchor):(this.hotkeyType===Kt.AddAnchor?this.externalElements.style.cursor="vertical-text":this.externalElements.style.cursor="crosshair",xt.NodeAnchor);if(!this.mouseDown&&i.type){if(i.calculative.active&&n.prev&&Ar(t,n.prev,this.pointSize))return this.store.hoverAnchor=n,this.store.hover=i,this.externalElements.style.cursor="pointer",xt.LineAnchorPrev;if(i.calculative.active&&n.next&&Ar(t,n.next,this.pointSize))return this.store.hoverAnchor=n,this.store.hover=i,this.externalElements.style.cursor="pointer",xt.LineAnchorNext}return xt.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},ae(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 n of this.store.data.pens)n.isRuleLine&&(n.width?n.height||(n.width=this.width):n.height=this.height),Gi(n);this.render()}clearCanvas(){this.activeRect=void 0,this.sizeCPs=void 0,this.canvas.getContext("2d").clearRect(0,0,this.canvas.width,this.canvas.height),this.offscreen.getContext("2d").clearRect(0,0,this.offscreen.width,this.offscreen.height),this.store.data.template||this.canvasTemplate.clear(),this.canvasImage.clear(),this.canvasImageBottom.clear()}async addPen(t,i,n,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(),n&&this.store.emitter.emit("add",[t]),i&&this.pushHistory({type:bt.Add,pens:[t]}),t}pushHistory(t){var r;if(this.store.data.locked)return;const{origin:i,scale:n}=this.store.data;t.origin=ct(i),t.scale=n,t.type!==bt.Update&&t.pens&&t.pens.forEach(s=>{s.calculative&&(s.calculative.layer=this.store.data.pens.findIndex(a=>a.id===s.id))}),this.store.historyIndex{let a;if(t.initPens)for(const l of t.initPens)l.id===s.id&&(a=l);if(a)for(const l in s)a[l]==null&&(a[l]=void 0)}),this.store.histories.push(t),this.store.historyIndex=this.store.histories.length-1,this.store.emitter.emit("update",{previous:t.initPens,current:t.pens})}undo(){if(this.store.data.locked||this.store.historyIndex==null||this.store.historyIndex<0)return;const t=this.store.histories[this.store.historyIndex--];this.doEditAction(t,!0);let i=t.step;for(;i>1;){const n=this.store.histories[this.store.historyIndex--];this.doEditAction(n,!0),i--}(t.type==bt.Add||t.type==bt.Delete||t.type==bt.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 n=this.store.histories[++this.store.historyIndex];this.doEditAction(n,!1),i--}(t.type==bt.Add||t.type==bt.Delete||t.type==bt.Update)&&this.activeHistory()}activeHistory(){let t=this.store.histories[this.store.historyIndex+1];const i=[];if(t&&t.type===bt.Update){t.pens.forEach(r=>{i.push(this.store.pens[r.id])}),this.active(i);return}let n=this.store.histories[this.store.historyIndex];n&&(n.type===bt.Add||n.type===bt.Delete)&&(n.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 bt.Add:t.pens.forEach(s=>{var c;const a=ct(s,!0),l=this.store.data.pens.findIndex(u=>u.id===a.id);l>-1&&((c=a.onDestroy)==null||c.call(a,this.store.pens[a.id]),this.store.data.pens.splice(l,1),this.store.pens[a.id]=void 0,a.calculative||(a.calculative={}),a.calculative.canvas=this,this.store.animates.delete(a),this.store.animateMap.delete(a))}),t.type=bt.Delete;break;case bt.Update:const n=i?t.initPens:t.pens,r=i?t.pens:t.initPens;n.forEach(s=>{const a=ct(s,!0),l=this.store.data.pens.findIndex(c=>c.id===a.id);if(l>-1){if(a.calculative=this.store.data.pens[l].calculative,this.store.data.pens[l].type&&this.store.data.pens[l].lastConnected){for(let u in this.store.data.pens[l].lastConnected)if(this.store.pens[u]){let h=ct(this.store.data.pens[l].lastConnected[u]);this.store.pens[u].connectedLines=h,a.anchors.forEach(d=>{h.forEach(g=>{d.id===g.lineAnchor&&(d.connectTo=u)})})}}this.store.data.pens[l]=a,this.store.pens[a.id]=a;for(const u in a)(typeof a[u]!="object"||u==="lineDash")&&(a.calculative[u]=a[u]);a.calculative.image=void 0;const c=this.getPenRect(a,t.origin,t.scale);if(this.setPenRect(a,c,!1),this.updateLines(a,!0),a.calculative.canvas.parent.isCombine(a)){let u=r.find(h=>h.id===a.id);_v.forEach(h=>{a[h]!==u[h]&&this.parent.setValue({id:a.id,[h]:a[h]},{render:!0,doEvent:!1})})}}});break;case bt.Delete:t.pens.reverse().forEach(s=>{var l,c;const a=ct(s,!0);if(a.calculative||(a.calculative={}),this.store.data.pens.splice(((l=a.calculative)==null?void 0:l.layer)!==-1?(c=a.calculative)==null?void 0:c.layer:this.store.data.pens.length,0,a),this.store.pens[a.id]=a,a.type&&a.lastConnected)for(let u in a.lastConnected)this.store.pens[u]&&(this.store.pens[u].connectedLines=a.lastConnected[u]);a.calculative.canvas=this}),t.pens.reverse().forEach(s=>{const a=this.store.pens[s.id],l=this.getPenRect(a,t.origin,t.scale);this.setPenRect(a,l,!1),a.calculative.image=void 0,a.calculative.backgroundImage=void 0,a.calculative.strokeImage=void 0,this.loadImage(a)}),t.type=bt.Add;break;case bt.Replace:{const s=i?t.initPens:t.pens;(i?t.pens:t.initPens).forEach(l=>{var h;const c=ct(l,!0);if(this.store.data.pens.findIndex(d=>d.id===c.id)>-1){(h=c.onDestroy)==null||h.call(c,this.store.data.pens.find(g=>g.id===c.id));const d=this.store.data.pens.findIndex(g=>g.id===c.id);this.store.data.pens.splice(d,1),this.store.pens[c.id]=void 0,c.calculative||(c.calculative={}),c.calculative.canvas=this,this.store.animates.delete(c),this.store.animateMap.delete(c)}}),s.reverse().forEach(l=>{var u,h;const c=ct(l,!0);if(c.calculative||(c.calculative={}),this.store.data.pens.splice(((u=c.calculative)==null?void 0:u.layer)!==-1?(h=c.calculative)==null?void 0:h.layer:this.store.data.pens.length,0,c),this.store.pens[c.id]=c,c.type&&c.lastConnected)for(let d in c.lastConnected)this.store.pens[d]&&(this.store.pens[d].connectedLines=c.lastConnected[d]);c.calculative.canvas=this}),s.reverse().forEach(l=>{const c=this.store.data.pens.find(h=>h.id===l.id),u=this.getPenRect(c,t.origin,t.scale);this.setPenRect(c,u,!1),c.calculative.image=void 0,c.calculative.backgroundImage=void 0,c.calculative.strokeImage=void 0,this.loadImage(c)}),t.type=bt.Replace;break}}if(t.type===bt.Update){let n=[...t.pens,...t.initPens];this.initImageCanvas(n),this.initTemplateCanvas(n)}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=It()),Math.abs(this.store.lastScale-this.store.data.scale)<1e-4&&this.store.sameTemplate&&this.store.templatePens[t.id]&&t.canvasLayer===zt.CanvasTemplate){t=this.store.templatePens[t.id],this.store.data.pens.push(t),this.updatePenRect(t);return}if(this.store.data.pens.push(t),this.store.pens[t.id]=t,t.path){!t.pathId&&(t.pathId=It());const s=this.store.data.paths;!s[t.pathId]&&(s[t.pathId]=t.path),t.path=void 0}t.lineWidth==null&&(t.lineWidth=1);const{fontSize:i,lineHeight:n}=this.store.options;t.fontSize?t.fontSize<0&&(t.fontSize=0):t.fontSize=i>=0?i:12,t.lineHeight||(t.lineHeight=n),t.image&&t.name!=="gif"&&t.canvasLayer===void 0&&(t.isBottom?t.canvasLayer=zt.CanvasImageBottom:t.canvasLayer=zt.CanvasImage,delete t.isBottom),t.template&&(t.canvasLayer=zt.CanvasTemplate),t.calculative={canvas:this,singleton:(r=t.calculative)==null?void 0:r.singleton},(t.video||t.audio)&&(t.calculative.onended=s=>{this.nextAnimate(s)});for(const s in t)(typeof t[s]!="object"||s==="lineDash")&&(t.calculative[s]=t[s]);if(t.calculative.image=void 0,t.calculative.backgroundImage=void 0,t.calculative.strokeImage=void 0,!t.anchors&&At.anchors[t.name]&&(t.anchors||(t.anchors=[]),At.anchors[t.name](t)),!t.anchors){const s=ct(this.store.options.defaultAnchors);s.forEach((a,l)=>{a.id=`${l}`,a.penId=t.id}),t.anchors=s}this.updatePenRect(t),!t.anchors&&t.calculative.worldAnchors&&(t.anchors=t.calculative.worldAnchors.map(s=>hs(s,t.calculative.worldRect))),!t.rotate&&(t.rotate=0),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,At.path2dDraws.line(this.drawingLine)),this.patchFlags=!0)}initLineRect(t){var s;if(!t)return;if(!((s=t.calculative.worldAnchors)!=null&&s.length)){this._del([t]);return}if(!isFinite(t.x)||!isFinite(t.x)||t.x==null||t.y==null)return;const i=bc(t);t.parentId||Object.assign(t,i);const{fontSize:n,lineHeight:r}=this.store.options;t.fontSize||(t.fontSize=n>=0?n:12,t.calculative.fontSize=t.fontSize*this.store.data.scale),t.lineHeight||(t.lineHeight=r,t.calculative.lineHeight=t.lineHeight),ee(i),t.calculative.worldRect=i,Fc(t,i),Ti(t),Gi(t),t.calculative&&(t.calculative.gradientAnimatePath=void 0),this.store.path2dMap.set(t,At.path2dDraws[t.name](t)),t.calculative.worldAnchors&&(t.anchors=t.calculative.worldAnchors.map(a=>hs(a,t.calculative.worldRect)))}drawingPencil(){ng(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=le(this.drawingLine);let n=qt(this.drawingLine);if(n.isTemp&&(this.drawingLine.calculative.worldAnchors.pop(),n=qt(this.drawingLine)),!t&&(!n.connectTo&&this.drawingLine.calculative.worldAnchors.pop(),le(this.drawingLine)===this.drawingLine.calculative.activeAnchor)){this.drawingLine=void 0,this.render();return}if(!i.connectTo||!n.connectTo){if(this.store.options.disableEmptyLine){i.connectTo&&(this.store.pens[i.connectTo].connectedLines=this.store.pens[i.connectTo].connectedLines.filter(a=>a.lineId!==this.drawingLine.id)),this.drawingLine=void 0,this.render();return}}else if(this.store.options.disableRepeatLine&&this.store.data.pens.find(l=>{if(l.type){const c=le(l),u=qt(l);return Bf(c,i)&&Bf(u,n)}})){this.drawingLine=void 0,this.render();return}const r=bc(this.drawingLine);Object.assign(this.drawingLine,r),this.drawingLine.calculative.worldRect=r,this.drawingLine.calculative.activeAnchor=qt(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:bt.Add,pens:ct([this.drawingLine],!0)})),this.store.path2dMap.set(this.drawingLine,At.path2dDraws[this.drawingLine.name](this.drawingLine)),this.drawingLine=void 0,this.drawingLineName=void 0,this.render()}async finishPencil(){if(this.pencilLine){const t=_c(this.pencilLine.calculative.worldAnchors,10,0,this.pencilLine.calculative.worldAnchors.length-1);let i=le(this.pencilLine);t.unshift({id:i.id,penId:i.penId,x:i.x,y:i.y}),i=qt(this.pencilLine),t.push({id:i.id,penId:i.penId,x:i.x,y:i.y}),this.pencilLine.calculative.worldAnchors=mk(t),this.pencilLine.calculative.worldAnchors.length>1&&(this.pencilLine.calculative.pencil=!1,this.store.path2dMap.set(this.pencilLine,At.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:bt.Add,pens:ct([this.pencilLine],!0)}))),this.pencilLine=void 0,this.render()}}firefoxLoadSvg(t){const i=new Image,n=new XMLHttpRequest;n.open("GET",t.image,!0),n.onload=()=>{const a=new DOMParser().parseFromString(n.responseText,"text/xml").getElementsByTagName("svg")[0],{width:l,height:c}=t.calculative.worldRect;a.setAttribute("width",`${l}px`),a.setAttribute("height",`${c}px`);const h="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(new XMLSerializer().serializeToString(a))));i.src=h,i.onload=()=>{t.calculative.img=i,t.calculative.imgNaturalWidth=i.naturalWidth||t.iconWidth,t.calculative.imgNaturalHeight=i.naturalHeight||t.iconHeight,At.htmlElements[t.image]=i,this.imageLoaded(),t.canvasLayer===zt.CanvasTemplate&&this.templateImageLoaded()}},n.send()}loadImage(t){if(t.image!==t.calculative.image||!t.calculative.img){if(t.calculative.img=void 0,t.image)if(At.htmlElements[t.image]){const i=At.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===zt.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||"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,At.htmlElements[t.image]=i,this.imageLoaded(),t.canvasLayer===zt.CanvasTemplate&&this.templateImageLoaded()}}t.calculative.image=t.image}if(t.backgroundImage!==t.calculative.backgroundImage){if(t.calculative.backgroundImg=void 0,t.backgroundImage)if(At.htmlElements[t.backgroundImage]){const i=At.htmlElements[t.backgroundImage];t.calculative.backgroundImg=i}else{const i=new Image;i.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,At.htmlElements[t.backgroundImage]=i,this.imageLoaded(),t.canvasLayer===zt.CanvasTemplate&&this.templateImageLoaded()}}t.calculative.backgroundImage=t.backgroundImage}if(t.strokeImage!==t.calculative.strokeImage){if(t.calculative.strokeImg=void 0,t.strokeImage)if(At.htmlElements[t.strokeImage]){const i=At.htmlElements[t.strokeImage];t.calculative.strokeImg=i}else{const i=new Image;i.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,At.htmlElements[t.strokeImage]=i,this.imageLoaded(),t.canvasLayer===zt.CanvasTemplate&&t.name!=="gif"&&this.templateImageLoaded()}}t.calculative.strokeImage=t.strokeImage}}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.fontSize<1&&t.fontSize>0&&(t.calculative.fontSize=t.fontSize*t.calculative.worldRect.height),t.calculative.iconSize=t.iconSize*i,t.calculative.iconWidth=t.iconWidth*i,t.calculative.iconHeight=t.iconHeight*i,t.calculative.iconLeft=t.iconLeft<1&&t.iconLeft>-1?t.iconLeft:t.iconLeft*i,t.calculative.iconTop=t.iconTop<1&&t.iconTop>-1?t.iconTop:t.iconTop*i,t.calculative.textWidth=t.textWidth<1&&t.textWidth>-1?t.textWidth:t.textWidth*i,t.calculative.textHeight=t.textHeight<1&&t.textHeight>-1?t.textHeight:t.textHeight*i,t.calculative.textLeft=t.textLeft<1&&t.textLeft>-1?t.textLeft*t.calculative.worldRect.width:t.textLeft*i,t.calculative.textTop=t.textTop<1&&t.textTop>-1?t.textTop*t.calculative.worldRect.height:t.textTop*i,t.type===jt.Line&&t.borderWidth&&(t.calculative.borderWidth=t.borderWidth*i)}updatePenRect(t,{worldRectIsReady:i,playingAnimate:n}={}){i?Da(t):Hv(t),n||this.setCalculativeByScale(t),Ir(t),zf(this.store.pens,t),Ti(t),Gi(t),At.path2dDraws[t.name]&&this.store.path2dMap.set(t,At.path2dDraws[t.name](t)),t.calculative.patchFlags=!0,this.patchFlags=!0,t.children&&t.children.forEach(r=>{const s=this.store.pens[r];s&&this.updatePenRect(s,{worldRectIsReady:!1})}),t.type&&this.initLineRect(t),t.calculative.gradientTimer&&clearTimeout(t.calculative.gradientTimer),t.calculative.gradientTimer=setTimeout(()=>{t.calculative.lineGradient&&(t.calculative.lineGradient=null),t.calculative.gradient&&(t.calculative.gradient=null),t.calculative.radialGradient&&(t.calculative.radialGradient=null),this.patchFlags=!0,t.calculative.gradientTimer=void 0},50)}translate(t=0,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 n=Xi(this.store.options.padding);const r=this.store.data.width||this.store.options.width,s=this.store.data.height||this.store.options.height;this.width<(r+n[1]+n[3])*this.store.data.scale&&(this.store.data.x+this.store.data.origin.x>n[3]*this.store.data.scale&&(this.store.data.x=n[3]*this.store.data.scale-this.store.data.origin.x),this.store.data.x+this.store.data.origin.x+r*this.store.data.scalen[0]*this.store.data.scale&&(this.store.data.y=n[0]*this.store.data.scale-this.store.data.origin.y),this.store.data.y+this.store.data.origin.y+s*this.store.data.scale=n&&t<=r))return;this.calibrateMouse(i);const s=t/this.store.data.scale;this.store.data.scale=t,this.store.data.center=i,(l=this.store.clipboard)!=null&&l.pos&&Wa(this.store.clipboard.pos,s,i),Wa(this.store.data.origin,s,i),this.store.data.pens.forEach(c=>{if(!c.parentId){if(br(c,s,i),c.onScale&&c.onScale(c),c.isRuleLine){const u=1/s,h=c.calculative.worldRect.center;c.width&&c.height||br(c,u,h)}this.updatePenRect(c,{worldRectIsReady:!0}),this.execPenResize(c)}}),this.onMovePens(),this.calcActiveRect(),this.canvasTemplate.init(),this.canvasImage.init(),this.canvasImageBottom.init();const a=this.parent.map;a&&a.isShow&&a.setView(),this.render(),this.store.emitter.emit("scale",this.store.data.scale)}templateScale(t,i={x:0,y:0}){const{minScale:n,maxScale:r}=this.store.options;if(!(t>=n&&t<=r))return;const s=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(a=>{if(!a.parentId){if(br(a,s,i),a.onScale&&a.onScale(a),a.isRuleLine){const l=s>1?1:1/s/s,c=a.calculative.worldRect.center;a.width&&a.height||br(a,l,c)}this.execPenResize(a)}}),this.calcActiveRect()}rotatePens(t){this.initPens||(this.initPens=ct(this.getAllByPens(this.store.active))),this.activeRect.rotate=hi(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 n of this.store.active){if(n.parentId)return;this.rotatePen(n,i,this.activeRect),n.onRotate&&n.onRotate(n),this.updateLines(n)}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:bt.Update,pens:ct(this.getAllByPens(this.store.active)),initPens:this.initPens}),this.initPens=void 0},200)}resizePens(t){if(this.initPens||(this.initPens=ct(this.store.active,!0)),!this.initActiveRect){this.initActiveRect=ct(this.activeRect);return}const i={x:this.mouseDown.x,y:this.mouseDown.y},n={x:t.x,y:t.y};let r=n.x-i.x,s=n.y-i.y;const a=ct(this.initActiveRect);if(Yf(a,r,s,this.resizeIndex),ee(a),!this.store.options.disableDock){this.clearDock();const v=this.customResizeDock||w2;this.dock=v(this.store,a,this.store.active,this.resizeIndex);const{xDock:y,yDock:w}=this.dock;if(y){r+=y.step;const p=this.store.pens[y.penId];p.calculative.isDock=!0}if(w){s+=w.step;const p=this.store.pens[w.penId];p.calculative.isDock=!0}}const l=this.activeRect.width,c=this.activeRect.height;let u=r-this.lastOffsetX,h=s-this.lastOffsetY;if(this.lastOffsetX=r,this.lastOffsetY=s,(t.ctrlKey||this.initPens.length===1&&this.initPens[0].ratio)&&(h=([1,3].includes(this.resizeIndex)?-1:1)*(u*c)/l),this.activeRect.ratio=this.initPens[0].ratio,Yf(this.activeRect,u,h,this.resizeIndex),this.store.options.strictScope){const v=this.store.data.width||this.store.options.width,y=this.store.data.height||this.store.options.height;if(v&&y){let w={x:this.store.data.origin.x,y:this.store.data.origin.y,width:v*this.store.data.scale,height:y*this.store.data.scale};this.activeRect.xw.x+w.width&&(this.activeRect.width=this.activeRect.width-(this.activeRect.x+this.activeRect.width-(w.x+w.width)),this.activeRect.x=w.x+w.width-this.activeRect.width,this.activeRect.ex=this.activeRect.x+this.activeRect.width),this.activeRect.y+this.activeRect.height>w.y+w.height&&(this.activeRect.height=this.activeRect.height-(this.activeRect.y+this.activeRect.height-(w.y+w.height)),this.activeRect.y=w.y+w.height-this.activeRect.height,this.activeRect.ey=this.activeRect.y+this.activeRect.height)}}ee(this.activeRect);const d=this.activeRect.width/l,g=this.activeRect.height/c;this.store.active.forEach((v,y)=>{v.calculative.worldRect.x=this.activeInitPos[y].x*this.activeRect.width+this.activeRect.x,v.calculative.worldRect.y=this.activeInitPos[y].y*this.activeRect.height+this.activeRect.y,v.calculative.worldRect.width*=d,v.calculative.iconWidth&&(v.calculative.iconWidth*=d),v.calculative.worldRect.height*=g,v.calculative.iconHeight&&(v.calculative.iconHeight*=g),ae(v.calculative.worldRect),ee(v.calculative.worldRect),this.updatePenRect(v,{worldRectIsReady:!0}),this.execPenResize(v),this.updateLines(v)}),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:bt.Update,pens:ct(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0},200)}movePens(t){var l,c;if(!this.activeRect||this.store.data.locked)return;if(!this.initActiveRect){this.initActiveRect=ct(this.activeRect);return}if(!this.store.options.moveConnectedLine&&!this.canMoveLine&&this.store.active.length===1&&(((l=this.store.active[0].anchors[0])==null?void 0:l.connectTo)||((c=this.store.active[0].anchors[this.store.active[0].anchors.length-1])==null?void 0:c.connectTo))||(this.movingPens||(this.initMovingPens(),this.store.active.forEach(u=>{rs(u,!1)}),this.store.hover=void 0),!this.mouseDown))return;let i=t.x-this.mouseDown.x,n=t.y-this.mouseDown.y;t.shiftKey&&!t.ctrlKey&&(n=0),t.ctrlKey&&(i=0);const r=ct(this.initActiveRect);Hn(r,i,n);let s=!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 d={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.xd.x+d.width&&(r.x=d.x+d.width-r.width,s=!0),r.y+r.height>d.y+d.height&&(r.y=d.y+d.height-r.height,s=!0)}}const a={x:r.x-this.activeRect.x,y:r.y-this.activeRect.y};if(!this.store.options.disableDock&&!s){this.clearDock();const u=this.customMoveDock||p2;this.dock=u(this.store,r,this.movingPens,a);const{xDock:h,yDock:d}=this.dock;let g;h&&(a.x+=h.step,g=this.store.pens[h.penId],g.calculative.isDock=!0),d&&(a.y+=d.step,g=this.store.pens[d.penId],g.calculative.isDock=!0)}this.translatePens(this.movingPens,a.x,a.y,!0)}changeIdsByMoving(t,i){t.id+=Fe,t.parentId&&i.find(n=>n.id===t.parentId)&&(t.parentId+=Fe),t.children&&(t.children=t.children.map(n=>n+Fe)),t.connectedLines&&(t.connectedLines=t.connectedLines.map(n=>(i.find(r=>r.id===n.lineId)&&(n.lineId+=Fe),n))),t.type&&t.calculative.worldAnchors&&(t.calculative.worldAnchors=t.calculative.worldAnchors.map(n=>(n.connectTo&&i.find(r=>r.id===n.connectTo)&&(n.connectTo+=Fe),n)))}initMovingPens(){var n,r;if(!this.store.options.moveConnectedLine&&!this.canMoveLine)for(let s=0;s{this.changeIdsByMoving(s,i),this.store.pens[s.id]=s,s.calculative.canvas=this;const a={globalAlpha:.5};s.lineWidth===0&&(a.lineWidth=1),(s.name.endsWith("Dom")||s_.includes(s.name)||this.store.options.domShapes.includes(s.name)||s.image)&&(a.name="rectangle",a.onDestroy=void 0),this.updateValue(s,a),s.calculative.image=void 0})}moveLineAnchor(t,i){var l,c,u,h,d;if(!this.activeRect||this.store.data.locked)return;if(this.initPens||(this.initPens=ct(this.store.active,!0)),(l=this.store.activeAnchor)!=null&&l.connectTo){const g=this.store.pens[this.store.activeAnchor.connectTo];Tr(g,Fn(g,this.store.activeAnchor.anchorId),this.store.pens[this.store.activeAnchor.penId],this.store.activeAnchor)}let n=(c=this.store.activeAnchor)==null?void 0:c.id,r=(h=(u=this.store.pens[this.store.activeAnchor.penId])==null?void 0:u.connectedLines)==null?void 0:h.filter(g=>g.anchor===n);r&&r.length>0&&r.forEach(g=>{const v=this.store.pens[g.lineId];Tr(this.store.pens[this.store.activeAnchor.penId],this.store.activeAnchor,v,Fn(v,g.lineAnchor))});const s=this.store.active[0];le(s);const a=qt(s);if(s.lineName==="polyline"&&!i.shiftKey)yk(s,this.store.activeAnchor,t);else{let g=0,v=0;if(s.lineName==="line"){let y=s.calculative.worldAnchors.findIndex(p=>p.id===this.store.activeAnchor.id);y===0&&(y=2);let w=s.calculative.worldAnchors[y-1];if(i.ctrlKey&&i.shiftKey){let p=ct(t);this.getSpecialAngle(p,w),g=p.x-this.store.activeAnchor.x,v=p.y-this.store.activeAnchor.y}else if(!i.ctrlKey&&i.shiftKey){let p={x:t.x,y:w.y};g=p.x-this.store.activeAnchor.x,v=p.y-this.store.activeAnchor.y}else if(i.ctrlKey&&!i.shiftKey){let p={x:w.x,y:t.y};g=p.x-this.store.activeAnchor.x,v=p.y-this.store.activeAnchor.y}else g=t.x-this.store.activeAnchor.x,v=t.y-this.store.activeAnchor.y}else!i.ctrlKey&&i.shiftKey?(g=t.x-this.store.activeAnchor.x,v=0):i.ctrlKey&&!i.shiftKey?(g=0,v=t.y-this.store.activeAnchor.y):(g=t.x-this.store.activeAnchor.x,v=t.y-this.store.activeAnchor.y);ls(this.store.activeAnchor,g,v),this.store.hover&&this.store.hoverAnchor&&this.store.hoverAnchor.penId!==this.store.activeAnchor.penId&&(this.store.hoverAnchor.type===Ki.Line?(g=t.x-this.store.activeAnchor.x,v=t.y-this.store.activeAnchor.y,wa(this.store.activeAnchor,this.store.hoverAnchor,this.store)):(g=this.store.hoverAnchor.x-this.store.activeAnchor.x,v=this.store.hoverAnchor.y-this.store.activeAnchor.y),ls(this.store.activeAnchor,g,v),a.prev=void 0,s.lineName!=="polyline"&&((d=this[s.lineName])==null||d.call(this,this.store,s)))}this.patchFlagsLines.add(s),this.store.path2dMap.set(s,At.path2dDraws[s.name](s)),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:bt.Update,pens:ct(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=ct(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,Gt(this.store.activeAnchor.next,180,this.store.activeAnchor);else if(this.store.activeAnchor.prevNextType===jn.Bilateral&&this.prevAnchor){const n=hi(t,this.store.activeAnchor),r=hi(this.prevAnchor,this.store.activeAnchor);this.store.activeAnchor.next.x=this.nextAnchor.x,this.store.activeAnchor.next.y=this.nextAnchor.y,Gt(this.store.activeAnchor.next,n-r,this.store.activeAnchor)}}const i=this.store.active[0];this.patchFlagsLines.add(i),this.store.path2dMap.set(i,At.path2dDraws[i.name](i)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.pushHistory({type:bt.Update,pens:ct(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=ct(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,Gt(this.store.activeAnchor.prev,180,this.store.activeAnchor);else if(this.store.activeAnchor.prevNextType===jn.Bilateral&&this.nextAnchor){const n=hi(t,this.store.activeAnchor),r=hi(this.nextAnchor,this.store.activeAnchor);this.store.activeAnchor.prev.x=this.prevAnchor.x,this.store.activeAnchor.prev.y=this.prevAnchor.y,Gt(this.store.activeAnchor.prev,n-r,this.store.activeAnchor)}}const i=this.store.active[0];this.patchFlagsLines.add(i),this.store.path2dMap.set(i,At.path2dDraws[i.name](i)),this.render(),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.pushHistory({type:bt.Update,pens:ct(this.store.active,!0),initPens:this.initPens}),this.initPens=void 0},200)}async setAnchor(t){var r;const i=[ct(this.store.hover,!0)],n=this.store.hover;if(this.store.hoverAnchor){if(this.beforeRemoveAnchor&&!await this.beforeRemoveAnchor(n,this.store.hoverAnchor))return;n.type===jt.Line&&((r=n.calculative.worldAnchors)==null?void 0:r.length)<=2?this.delete([n]):(l2(n,this.store.hoverAnchor),n.type===jt.Line&&this.initLineRect(n)),this.store.hoverAnchor=void 0,this.store.activeAnchor=void 0,this.externalElements.style.cursor="default"}else if(n){if(this.beforeAddAnchor&&!await this.beforeAddAnchor(n,this.store.pointAt))return;if(n.type===jt.Line){this.store.activeAnchor=o2(n,this.store.pointAt,this.store.pointAtIndex),this.initLineRect(n);const s={x:t.x,y:t.y};this.getHover(s)}else{const s={id:It(),x:t.x,y:t.y};this.store.activeAnchor=a2(n,s)}}this.hotkeyType=Kt.None,this.render(),n&&this.pushHistory({type:bt.Update,pens:[ct(n,!0)],initPens:i})}checkDisconnect(t,i){if(t.id.indexOf(Fe)>0){const n=t.id;t=this.store.pens[n.replace(Fe,"")]}t.anchors.forEach(n=>{if(n.connectTo&&!i.find(r=>r.id===n.connectTo||r.id===n.connectTo+Fe)){const r=this.store.pens[n.connectTo];if(!r||r.type)return;Tr(r,Fn(r,n.anchorId),t,n)}})}translatePens(t=this.store.active,i,n,r){if(!t||!t.length||t.some(c=>{if(c.locked>=Ot.DisableMove)return!0}))return;const a=!r&&ct(t,!0);this.activeRect&&Hn(this.activeRect,i,n);const l=this.getAllByPens(t);t.forEach(c=>{var u,h;if(!(c.locked>=Ot.DisableMove)){if(c.type===jt.Line){if(!this.store.options.moveConnectedLine&&!this.canMoveLine||c.isRuleLine)return;Hf(c,i,n),this.checkDisconnect(c,l),this.store.path2dMap.set(c,At.path2dDraws[c.name](c)),r||(this.initLineRect(c),(u=c.connectedLines)==null||u.forEach(d=>{const g=this.store.pens[d.lineId];this.initLineRect(g)}))}else Hn(c.calculative.worldRect,i,n),this.updatePenRect(c,{worldRectIsReady:!0}),c.calculative.x=c.x,c.calculative.y=c.y,c.calculative.initRect&&(c.calculative.initRect.x=c.calculative.x,c.calculative.initRect.y=c.calculative.y,c.calculative.initRect.ex=c.calculative.x+c.calculative.width,c.calculative.initRect.ey=c.calculative.y+c.calculative.height);this.updateLines(c),(h=c.onMove)==null||h.call(c,c)}}),this.activeRect&&this.getSizeCPs(),this.render(),this.tooltip.translate(i,n),r||(this.pushHistory({type:bt.Update,pens:ct(t,!0),initPens:a}),this.initImageCanvas(t),this.initTemplateCanvas(t),this.store.emitter.emit("translatePens",t)),this.store.emitter.emit("translatingPens",t)}templateTranslatePens(t=this.store.active,i,n){if(!t||!t.length)return;const r=this.getAllByPens(t);t.forEach(s=>{var a;if(s.type===jt.Line){if(!this.store.options.moveConnectedLine&&!this.canMoveLine)return;Hf(s,i,n),this.checkDisconnect(s,r),this.store.path2dMap.set(s,At.path2dDraws[s.name](s))}else Hn(s.calculative.worldRect,i,n),this.updatePenRect(s,{worldRectIsReady:!0}),s.calculative.x=s.x,s.calculative.y=s.y,s.calculative.initRect&&(s.calculative.initRect.x=s.calculative.x,s.calculative.initRect.y=s.calculative.y,s.calculative.initRect.ex=s.calculative.x+s.calculative.width,s.calculative.initRect.ey=s.calculative.y+s.calculative.height);(a=s.onMove)==null||a.call(s,s)})}calcAutoAnchor(t,i,n,r){const s=le(t),a=qt(t),l=Cr(n,i===s?a:s);!l||(i.x=l.x,i.y=l.y,i.prev=void 0,i.next=void 0,r?r.anchor=l.id:we(n,l,t,i),this[t.lineName]&&this[t.lineName](this.store,t),this.store.path2dMap.set(t,At.path2dDraws.line(t)),this.initLineRect(t))}restoreNodeAnimate(t){var i,n;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 a in t)a!=="x"&&a!=="y"&&a!=="width"&&a!=="height"&&a!=="initRect"&&a!=="rotate"&&(typeof t[a]!="object"||a==="lineDash")&&(t.calculative[a]=t[a]);(i=t.children)!=null&&i.length?r&&qv(t,r,t.calculative.worldRect):t.calculative.rotate=t.rotate;const s=ct(this.store.animateMap.get(t));s&&(s.id=t.id,this.parent.setValue(s,{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,Es(t)),(n=this.store.active)!=null&&n.length&&this.calcActiveRect(),t.calculative.initRect=void 0}}updateLines(t,i){var n;(n=t.children)==null||n.forEach(r=>{const s=this.store.pens[r];s&&this.updateLines(s,i)}),t.connectedLines&&t.connectedLines.forEach((r,s)=>{const a=this.store.pens[r.lineId];if(!a||a.calculative.active)return;const l=Fn(a,r.lineAnchor);if(!l)return;if(!l.connectTo){t.connectedLines.splice(s,1);return}if(a.autoFrom){const g=le(a);g.id===l.id&&this.calcAutoAnchor(a,g,t,r)}if(a.autoTo){const g=qt(a);g.id===l.id&&this.calcAutoAnchor(a,g,t,r)}const c=Fn(t,r.anchor);if(!c)return;let u=t.rotate;t.flipX&&(u*=-1),t.flipY&&(u*=-1);let h=l.distance*this.store.data.scale*Math.cos((u+c.rotate)/180*Math.PI)||0,d=l.distance*this.store.data.scale*Math.sin((u+c.rotate)/180*Math.PI)||0;if(t.flipX&&(h=-h),t.flipY&&(d=-d),ls(l,c.x-l.x+h,c.y-l.y+d),this.store.options.autoPolyline&&!this.autoPolylineFlag&&a.autoPolyline!==!1&&a.lineName==="polyline"){let g=le(a),v=qt(a),y=!1;g.id===l.id?(g=l,y=!0):v.id===l.id&&(v=l,y=!0),y&&(a.calculative.worldAnchors=[g,v],a.calculative.activeAnchor=g,this.polyline(this.store,a,v),this.initLineRect(a))}this.store.path2dMap.set(a,At.path2dDraws[a.name](a)),this.patchFlagsLines.add(a),a.calculative.gradientSmooth&&(a.calculative.gradientAnimatePath=Nc(a)),i&&xc(a)})}calcActiveRect(){const t=this.store.active.filter(i=>(!i.locked||i.locked{Gt(r,i,n.center)}),this.initLineRect(t),Da(t)):(t.calculative.rotate?t.calculative.rotate+=i:t.calculative.rotate=i,Gt(t.calculative.worldRect.center,i,n.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-n.x)/n.width,t.y=(t.calculative.worldRect.y-n.y)/n.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 s=this.store.pens[r];this.rotatePen(s,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(n=>n.id===t.nextAnimate||n.tags&&n.tags.indexOf(t.nextAnimate)>-1)),i&&(i.forEach(n=>{var r,s,a,l,c;if(n.calculative.pause){const u=Date.now()-n.calculative.pause;n.calculative.pause=void 0,n.calculative.frameStart+=u,n.calculative.frameEnd+=u}else if(n.name==="video")n.calculative.media.currentTime=0,(r=n.calculative.media)==null||r.play(),(s=n.onStartVideo)==null||s.call(n,n);else if(n.type||((a=n.frames)==null?void 0:a.length)||n.animations&&n.animations.length){if(n.type){if((c=n.animations)!=null&&c.length){const u=ct(n.animations[0]);delete u.name,u.currentAnimation=0,this.parent.setValue({id:n.id,...u},{doEvent:!1,history:!1})}}else{if(!n.frames&&n.animations&&n.animations.length){let u=(l=n.animations)==null?void 0:l.findIndex(g=>g.autoPlay),h=u===-1?0:u;const d=ct(n.animations[h]);delete d.name,d.currentAnimation=h,!n.type&&d.frames&&(d.showDuration=this.parent.calcAnimateDuration(d)),this.parent.setValue({id:n.id,...d},{doEvent:!1,history:!1})}this.store.animateMap.set(n,this.getFrameProps(n))}this.store.animates.add(n)}}),this.animate())}getFrameProps(t){let i={};return t.frames&&t.frames.forEach(n=>{for(let r in n)!["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.lastAnimateRender0&&this.animate();return}this.lastAnimateRender=t,this.animateRendering=!0;const i=[];let n=!1;for(const r of this.store.animates)if(!r.calculative.pause){if(r.calculative.active&&!r.type&&!this.movingPens&&(n=!0),!r.type)c2(r,t)?r.calculative.patchFlags&&(ee(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(!u2(r)){if(r.keepAnimateState){for(const s in r)r.calculative[s]!==void 0&&s!=="length"&&(typeof r[s]!="object"||s==="lineDash")&&(s==="lineWidth"?r[s]=r.calculative[s]/r.calculative.canvas.store.data.scale:r[s]=r.calculative[s]);Da(r)}else for(const s in r)(typeof r[s]!="object"||s==="lineDash")&&(s==="lineWidth"?r.calculative[s]=r[s]*r.calculative.canvas.store.data.scale:r.calculative[s]=r[s]);i.push(r),this.nextAnimate(r)}this.patchFlags=!0}n&&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 n=It(),{origin:r,scale:s}=this.store.data;this.store.clipboard=void 0,localStorage.removeItem(this.clipboardName),sessionStorage.setItem("page",n);let a=this.getAllByPens(ct(t||this.store.active,!0));a.forEach(c=>{c.copyIndex=this.store.data.pens.findIndex(u=>u.id===c.id),c.pathId&&(c.path=this.store.data.paths[c.pathId])}),a.sort((c,u)=>c.copyIndex-u.copyIndex),a.forEach(c=>{delete c.copyIndex});const l={meta2d:!0,pens:a,origin:ct(r),scale:s,page:n,initRect:ct(this.activeRect),offset:10};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;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(c){console.warn("\u526A\u5207\u677F\u6570\u636E\u4E0D\u662Fjson",c.message);return}if(!i||!i.meta2d)return}else return;if(this.beforeAddPens&&await this.beforeAddPens(i.pens)!=!0)return;let n,r;this.store.clipboard&&(n=this.store.clipboard.offset+10,r=this.store.clipboard.pos),this.store.clipboard=ct(i),sessionStorage.getItem("page")!==i.page?(this.store.clipboard.pos={x:this.mousePos.x,y:this.mousePos.y},this.store.clipboard.offset=0):this.pasteOffset?(n&&(this.store.clipboard.offset=n),r&&(this.store.clipboard.pos=r)):(this.store.clipboard.offset=0,this.pasteOffset=!0);const a=this.store.clipboard.pens.filter(c=>!c.parentId);for(const c of a)this.pastePen(c,void 0);sessionStorage.setItem("page",i.page),this.active(a),this.pushHistory({type:bt.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 n of t)i.push(...ct(Ci(n,this.store),!0));return i.concat(t)}getAllFollowersByPens(t,i=!0){const n=t;for(const r of t){let s=Bc(r,this.store);i&&(s=ct(s,!0));for(const a of s)n.find(l=>l.id===a.id)||n.push(a)}return n}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 n=t[t.length-1];n.followers?i.forEach(r=>{n.followers.includes(r)||n.followers.push(r)}):n.followers=i}}changeLineAnchors(t,i,n){if(!!Array.isArray(i.connectedLines))for(let r=0;rl.id===s);if(a){const l=a.anchors[0],c=a.anchors[a.anchors.length-1];l.connectTo===t&&(l.connectTo=i.id),c.connectTo===t&&(c.connectTo=i.id)}else i.connectedLines.splice(r,1),r--}}changeNodeConnectedLine(t,i,n){var l;const r=i.anchors[0],s=i.anchors[i.anchors.length-1],a=[r,s];for(const c of a){const u=c.connectTo;if(u){const h=n.find(d=>d.id===u);h?(l=h.connectedLines)==null||l.forEach(d=>{d.lineId===t&&(d.lineId=i.id,d.lineAnchor=c.id)}):(c.connectTo=void 0,c.prev&&(c.prev.connectTo=void 0),c.next&&(c.next.connectTo=void 0))}}}async delete(t=this.store.active,i=!1,n=!0){if(!t||!t.length||this.beforeRemovePens&&await this.beforeRemovePens(t)!=!0||(i||(t=t.filter(s=>!s.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(),n){if(r.length===0)return;this.pushHistory({type:bt.Delete,pens:r})}this.store.emitter.emit("delete",t)}_del(t,i,n){!t||t.forEach(r=>{if(r.type&&(r.lastConnected={}),r.parentId)if(this.getLockedParent(r)){console.warn("\u7236\u8282\u70B9\u9501\u5B9A");return}else{const a=Ze(r),l=a.children.indexOf(r.id);a.children.splice(l,1),i&&this.getDelPens(r,i),this.delForce(r)}else{if(!n&&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.calculative.active=void 0,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=Ze(t);if(i.locked)return i;this.getLockedParent(i)}delForce(t){var n;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&&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])}),(n=t.onDestroy)==null||n.call(t,t)}delConnectedLines(t){var i;if(t.connectedLines)for(let n=0;nc.id===s);(l==null?void 0:l.connectTo)===t.id&&(l.connectTo=void 0,l.anchorId=void 0,l.prev&&(l.prev.connectTo=void 0),l.next&&(l.next.connectTo=void 0)),l=Fn(a,s),l&&(l.connectTo=void 0,l.anchorId=void 0,l.prev&&(l.prev.connectTo=void 0),l.next&&(l.next.connectTo=void 0))}}!t.type||(i=t.calculative.worldAnchors)==null||i.forEach((n,r)=>{var a;if(!n.connectTo)return;const s=this.store.pens[n.connectTo];s&&((a=s.calculative.worldAnchors)==null||a.forEach(l=>{Tr(s,l,t,n)}))})}convertSpecialCharacter(t){var i={lt:"<",gt:">",nbsp:" ",amp:"&",quot:'"'};return t.replace(/&(lt|gt|nbsp|amp|quot);/gi,function(n,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{if(navigator.userAgent.includes("Firefox")){if(!i.target.innerText){let n=this.inputDiv.offsetWidth/2;window.getComputedStyle(this.inputDiv,null).textAlign!=="center"&&(n=0),this.inputDiv.innerHTML=`
`}}else if(i.target.innerText)this.inputDiv.style.paddingTop="";else{let n=window.getComputedStyle(this.inputDiv,null);n.justifyContent==="center"&&(this.inputDiv.style.paddingTop=` ${this.inputDiv.offsetHeight/2-parseFloat(n.lineHeight)/2}px`)}},this.inputDiv.onblur=()=>{setTimeout(()=>{this.hideInput()},300)},this.inputDiv.oninput=i=>{const n=this.store.pens[this.inputDiv.dataset.penId];if(n&&n.inputType==="number"){const r=i.target.innerText,s=r.replace(/[^0-9]/g,"");r!==s&&(i.preventDefault(),i.target.innerText=s)}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=`
`}}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",n)},this.inputDiv.onclick=i=>{i.stopPropagation();const n=this.store.pens[this.inputDiv.dataset.penId];this.dropdown.style.display==="block"?this.dropdown.style.display="none":(n==null?void 0:n.dropdownList)&&this.store.data.locked&&(this.dropdown.style.display="block"),this.store.emitter.emit("clickInput",n)},this.inputDiv.onkeyup=i=>{this.setDropdownList(!0);const n=this.store.pens[this.inputDiv.dataset.penId];this.store.emitter.emit("input",{pen:n,text:i.key}),i.stopPropagation()},this.inputDiv.onkeydown=i=>{i.stopPropagation()},this.inputDiv.onmousedown=this.stopPropagation,this.inputDiv.onwheel=i=>{i.stopPropagation()},this.inputDiv.onpaste=i=>{i.preventDefault();let n="";i.clipboardData&&i.clipboardData.getData&&(n=i.clipboardData.getData("text/plain")),document.execCommand("insertHTML",!1,n)}}clearDropdownList(){if(this.dropdown.hasChildNodes())for(let t=0;t{n.style.background=r.dropdownHoverBackground||"#eee",n.style.color=r.dropdownHoverColor||"#bdc7db"},n.onmouseleave=()=>{n.style.background=r.dropdownBackground||"#fff",n.style.color=r.dropdownColor||"#bdc7db"},this.dropdown.appendChild(n)}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,s,a,l,c,u,h;if(t===i)return;const n=this.store.pens[t];if(!!n&&!this.store.pens[i]){if(n.id=i,this.store.pens[i]=this.store.pens[t],(r=n.onChangeId)==null||r.call(n,n,t,i),delete this.store.pens[t],n.parentId){const d=this.store.pens[n.parentId],g=(s=d.children)==null?void 0:s.findIndex(v=>v===t);g!==-1&&((a=d.children)==null||a.splice(g,1,i))}(l=n.children)==null||l.forEach(d=>{const g=this.store.pens[d];g.parentId=i}),n.type===jt.Line?this.changeNodeConnectedLine(t,n,this.store.data.pens):(this.changeLineAnchors(t,n,this.store.data.pens),(c=n.connectedLines)==null||c.forEach(({lineId:d})=>{const g=this.store.pens[d];Ir(g)})),(u=n.anchors)==null||u.forEach(d=>d.penId=i),(h=n.calculative.worldAnchors)==null||h.forEach(d=>d.penId=i)}}updateValue(t,i){var y,w,p,_,A,x;const n=this.getPenRect(t),r=t.name;Object.assign(t,i);const s=r!==t.name;i.newId&&this.changePenId(t.id,i.newId);let a=!1,l=!1,c=!1,u=!1,h=!1,d=!1,g,v=!1;for(const E in i)E.indexOf(".")===-1?(E==="rotate"?t.disableRotate?t.rotate=t.calculative.rotate||0:g=t.calculative.rotate||0:E==="canvasLayer"||E==="isBottom"||E==="showChild"?d=!0:E==="image"&&(v=!0),(typeof t[E]!="object"||E==="lineDash")&&(!t.disableRotate||E!=="rotate")&&(t.calculative[E]=i[E]),e_.includes(E)&&(l=!0),["name","borderRadius","lineSmooth","close"].includes(E)&&(a=!0),i_.includes(E)&&(h=!0),n_.includes(E)&&(c=!0),r_.includes(E)&&(u=!0),t.image&&t.name!=="gif"&&["globalAlpha","flipY","flipX","x","y","width","height","iconWidth","iconHeight","imageRatio","iconLeft","iconTop","iconAlign","rotate"].includes(E)&&(v=!0)):(delete t[E],z_(t,E,i[E])),E.split(".")[0]==="anchors"&&Ir(t);if(this.setCalculativeByScale(t),s&&((y=t.onDestroy)==null||y.call(t,t),a_(t)),h){const E={x:(w=i.x)!=null?w:n.x,y:(p=i.y)!=null?p:n.y,width:(_=i.width)!=null?_:n.width,height:(A=i.height)!=null?A:n.height};this.setPenRect(t,E,!1),this.updateLines(t,!0),this.store.active&&this.store.active.length&&t.id===this.store.active[0].id&&this.calcActiveRect()}else c?this.updatePenRect(t):(l&&Ti(t),u&&zf(this.store.pens,t),a&&At.path2dDraws[t.name]&&this.store.path2dMap.set(t,At.path2dDraws[t.name](t)));if(g!==void 0){const E=t.calculative.rotate;t.calculative.rotate=g,this.rotatePen(t,E-g,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),d?(this.canvasImage.init(),this.canvasImageBottom.init()):v&&(t.canvasLayer===void 0&&(t.canvasLayer=zt.CanvasImageBottom,t.calculative.canvasLayer=zt.CanvasImageBottom),t.canvasLayer===zt.CanvasImageBottom?this.canvasImageBottom.init():t.canvasLayer===zt.CanvasImage&&this.canvasImage.init()),(i.canvasLayer!==void 0||t.canvasLayer===zt.CanvasTemplate)&&this.initTemplateCanvas([t]),i.zIndex!==void 0&&(x=t.calculative.singleton)!=null&&x.div&&ti(t,t.calculative.singleton.div)}execPenResize(t){var i,n;(i=t.onResize)==null||i.call(t,t),(n=t.children)==null||n.forEach(r=>{const s=this.store.pens[r];s&&this.execPenResize(s)})}setPenRect(t,i,n=!0){if(t.parentId)Object.assign(t,i);else{const{origin:r,scale:s}=this.store.data;t.x=r.x+i.x*s,t.y=r.y+i.y*s,t.width=i.width*s,t.height=i.height*s}this.updatePenRect(t),this.execPenResize(t),n&&this.render()}getPenRect(t,i=this.store.data.origin,n=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)/n,y:(t.y-i.y)/n,width:t.width/n,height:t.height/n}}toPng(t=2,i,n=!1,r){const s=pi(this.store.data.pens),a=this.store.data.scale;if(!isFinite(s.width))throw new Error("can not to png, because width is not finite");const l=ct(s),c=this.store.data,u=n&&!c.background&&this.store.bkImg;let h=!1,d=!1;if(u){if(s.x+=c.x,s.y+=c.y,ae(s),Ji(s,this.canvasRect,!0))Object.assign(s,this.canvasRect);else{const I=As([...tn(s),...tn(this.canvasRect)]);Object.assign(s,I)}h=s.x===0,d=s.y===0}const g=this.store.data.width||this.store.options.width,v=this.store.data.height||this.store.options.height;let y=!1;g&&v&&!this.store.data.component&&(y=!0),y&&(s.x=this.store.data.origin.x,s.y=this.store.data.origin.y,s.width=g*this.store.data.scale,s.height=v*this.store.data.scale);const w=ct(s),p=Xi(t);s.x-=p[3]*a,s.y-=p[0]*a,s.width+=(p[3]+p[1])*a,s.height+=(p[0]+p[2])*a;const _=(r||1920)/s.width;s.width*=_,s.height*=_,ae(s);const A=document.createElement("canvas");if(A.width=s.width,A.height=s.height,A.width>32767||A.height>32767||!navigator.userAgent.includes("Firefox")&&A.height*A.width>268435456||navigator.userAgent.includes("Firefox")&&A.height*A.width>472907776)throw new Error("can not to png, because the size exceeds the browser limit");const x=A.getContext("2d");x.textBaseline="middle",x.scale(_,_);const E=this.store.data.background||this.store.options.background;if(E&&(x.save(),x.fillStyle=E,y?x.fillRect(0,0,w.width+(p[1]+p[3])*a,w.height+(p[0]+p[2])*a):x.fillRect(0,0,l.width+(p[3]+p[1])*a,l.height+(p[0]+p[2])*a),x.restore()),u)if(y)x.drawImage(this.store.bkImg,p[3]*a||0,p[0]*a||0,w.width,w.height);else{const I=s.x<0?-s.x:0,M=s.y<0?-s.y:0;x.drawImage(this.store.bkImg,I,M,this.canvasRect.width,this.canvasRect.height)}u?y?x.translate(-l.x+p[3]*a||0,-l.y+p[0]*a||0):x.translate((h?c.x:-l.x)+p[3]*a||0,(d?c.y:-l.y)+p[0]*a||0):x.translate(-s.x,-s.y);for(const I of this.store.data.pens){if(!Va(I,this.store)||I.visible==!1)continue;const{active:M}=I.calculative;I.calculative.active=!1,I.calculative.img?ja(x,I):Nn(x,I,!0),I.calculative.active=M}if(i){A.toBlob(i);return}return A.toDataURL()}activeToPng(t=2,i){return this.pensToPng(this.store.active,t,i)}pensToPng(t=this.store.active,i=2,n){if(t.length===0)return;const r=this.getAllByPens(t);let s=r.map(v=>v.id);const a=pi(r);if(!isFinite(a.width))throw new Error("can not to png, because width is not finite");const l=ct(a),c=Xi(i);a.x-=c[3],a.y-=c[0],a.width+=c[3]+c[1],a.height+=c[0]+c[2],ae(a);const u=(n||a.width)/a.width;a.width*=u,a.height*=u;const h=document.createElement("canvas");if(h.width=a.width,h.height=a.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 d=h.getContext("2d");d.textBaseline="middle",d.scale(u,u);const g=this.store.data.background||this.store.options.background;g&&(d.save(),d.fillStyle=g,d.fillRect(0,0,l.width+(c[3]+c[1]),l.height+(c[0]+c[2])),d.restore()),d.translate(-l.x+c[3],-l.y+c[0]);for(const v of this.store.data.pens)if(s.includes(v.id)){if(!Va(v,this.store)||v.visible==!1)continue;const{active:y}=v.calculative;v.calculative.active=!1,v.calculative.img?ja(d,v):Nn(d,v),v.calculative.active=y}return h.toDataURL()}toggleAnchorMode(){var t;if(this.hotkeyType)this.hotkeyType===Kt.AddAnchor&&(this.hotkeyType=Kt.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?void 0:t.disableAnchor))return;this.hotkeyType=Kt.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=[ct(this.store.active[0],!0)];this.store.activeAnchor.prev?this.store.activeAnchor.next||(this.store.activeAnchor.next={...this.store.activeAnchor.prev},Gt(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},Gt(this.store.activeAnchor.prev,180,this.store.activeAnchor),this.initLineRect(this.store.active[0]),this.patchFlags=!0),this.pushHistory({type:bt.Update,pens:[ct(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=[ct(this.store.active[0],!0)];this.hoverType===xt.LineAnchorPrev?(this.store.activeAnchor.prev=void 0,this.initLineRect(this.store.active[0]),this.patchFlags=!0):this.hoverType===xt.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:bt.Update,pens:[ct(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=jn.Mirror),this.store.activeAnchor.prevNextType=(this.store.activeAnchor.prevNextType+1)%3)}gotoView(t,i){let n=pi(this.store.data.pens);if(!isFinite(n.width))throw new Error("can not move view, because width is not finite");const r=this.store.data.width||this.store.options.width,s=this.store.data.height||this.store.options.height;r&&s&&(n={x:this.store.data.origin.x,y:this.store.data.origin.y,width:r*this.store.data.scale,height:s*this.store.data.scale}),this.store.data.x=this.canvas.clientWidth/2-t*n.width-n.x,this.store.data.y=this.canvas.clientHeight/2-i*n.height-n.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.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(Ji(u.calculative.worldRect,this.dragRect,!0))return u.type===jt.Line&&!this.store.options.dragAllIn?Bl(u,this.dragRect):!0});if(!t.length)return;const i=this.parent.getRect(t),n=this.store.data.scale,r=this.store.data.width||this.store.options.width,s=this.store.data.height||this.store.options.height;let a=(Math.floor(i.x)-this.store.data.origin.x)/n/r,l=(Math.floor(i.y)-this.store.data.origin.y)/n/s,c={x:a,y:l,width:(Math.ceil(i.width)+1)/n/r,height:(Math.ceil(i.height)+1)/n/s,children:t.map(u=>u.id),id:It(),active:!0};c.x<-.1&&(c.x=-.1),c.y<-.1&&(c.y=-.1),c.width>.5?(c.left=!0,c.right=!0,c.leftValue=(c.x-0)*n*r,c.rightValue=(1-(c.x+c.width))*n*r):c.x<.5?(c.left=!0,c.leftValue=(c.x-0)*n*r):(c.right=!0,c.rightValue=(1-(c.x+c.width))*n*r),c.leftValue<1&&(c.leftValue=0),c.rightValue<1&&(c.rightValue=0),c.height>.5?(c.top=!0,c.bottom=!0,c.topValue=(c.y-0)*n*s,c.bottomValue=(1-(c.y+c.height))*n*s):c.y<.5?(c.top=!0,c.topValue=(c.y-0)*n*s):(c.bottom=!0,c.bottomValue=(1-(c.y+c.height))*n*s),c.topValue<1&&(c.topValue=0),c.bottomValue<1&&(c.bottomValue=0),this.store.data.fits||(this.store.data.fits=[]),this.store.data.fits.forEach(u=>{u.active=!1}),this.store.data.fits.push(c),this.canvasImage.activeFit=c,this.store.emitter.emit("fit",c),this.canvasImage.init(),this.canvasImage.render()}updateFit(t){const i=this.store.data.scale,n=this.store.data.width||this.store.options.width,r=this.store.data.height||this.store.options.height;let s=(t.x-this.store.data.origin.x)/i/n,a=(t.y-this.store.data.origin.y)/i/r;if(this.canvasImage.currentFit){const l=this.canvasImage.activeFit;if(this.canvasImage.currentFit==="top"){a<-.1&&(a=-.1);let h=a-l.y;if(l.height-=h,l.height<.01){l.height=.01;return}l.y=a}if(this.canvasImage.currentFit==="bottom"&&(a>1.1&&(a=1.1),l.height=a-l.y,l.height<=.01&&(l.height=.01)),this.canvasImage.currentFit==="left"){s<-.1&&(s=-.1);let h=s-l.x;if(l.width-=h,l.width<.01){l.width=.01;return}l.x=s}this.canvasImage.currentFit==="right"&&(s>1.1&&(s=1.1),l.width=s-l.x,l.width<=.01&&(l.width=.01));let c={x:l.x*n*i+this.store.data.origin.x,y:l.y*r*i+this.store.data.origin.y,width:l.width*n*i,height:l.height*r*i};ae(c);const u=this.store.data.pens.filter(h=>{if(h.parentId||h.isRuleLine)return!1;if(Ji(h.calculative.worldRect,c,!0))return h.type===jt.Line&&!this.store.options.dragAllIn?Bl(h,c):!0});l.left=void 0,l.leftValue=void 0,l.right=void 0,l.rightValue=void 0,l.top=void 0,l.topValue=void 0,l.bottom=void 0,l.bottomValue=void 0,l.width>.5?(l.left=!0,l.right=!0,l.leftValue=(l.x-0)*i*n,l.rightValue=(1-(l.x+l.width))*i*n):l.x<.5?(l.left=!0,l.leftValue=(l.x-0)*i*n):(l.right=!0,l.rightValue=(1-(l.x+l.width))*i*n),Math.abs(l.leftValue)<1&&(l.leftValue=0),Math.abs(l.rightValue)<1&&(l.rightValue=0),l.height>.5?(l.top=!0,l.bottom=!0,l.topValue=(l.y-0)*i*r,l.bottomValue=(1-(l.y+l.height))*i*r):l.y<.5?(l.top=!0,l.topValue=(l.y-0)*i*r):(l.bottom=!0,l.bottomValue=(1-(l.y+l.height))*i*r),Math.abs(l.topValue)<1&&(l.topValue=0),Math.abs(l.bottomValue)<1&&(l.bottomValue=0),l.children=u.map(h=>h.id),this.store.emitter.emit("fit",l),this.mouseDown.x=t.x,this.mouseDown.y=t.y,this.canvasImage.init(),this.canvasImage.render()}}updateFitRect(t=this.canvasImage.activeFit){const i=this.store.data.width||this.store.options.width,n=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/n:t.y=0),t.bottom&&(t.bottomValue?t.height=1-(Math.abs(t.bottomValue)<1?t.bottomValue:t.bottomValue/n)-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(n=>n.id===t.id);this.store.data.fits.splice(i,1),this.canvasImage.activeFit=void 0,this.canvasImage.init(),this.canvasImage.render(),this.store.emitter.emit("fit",void 0)}calcuActiveFit(){var l;const t=this.store.data.width||this.store.options.width,i=this.store.data.height||this.store.options.height;let n=(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,s=-1,a=-1;(l=this.store.data.fits)==null||l.forEach((c,u)=>{c.ex=null,c.ey=null,yn({x:n,y:r},c)&&(s=u),c.active&&(a=u)}),s!==-1&&s!==a?(this.canvasImage.activeFit=this.store.data.fits[s],this.store.data.fits[s].active=!0,a!==-1&&(this.store.data.fits[a].active=!1),this.store.emitter.emit("fit",this.store.data.fits[s])):s===-1&&a!==-1&&(this.store.data.fits[a].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.render()}destroy(){var t,i,n,r;switch(this.scroll&&this.scroll.destroy(),(t=this.tooltip)==null||t.destroy(),(i=this.dialog)==null||i.destroy(),(n=this.title)==null||n.destroy(),(r=this.popconfirm)==null||r.destroy(),this.externalElements.removeEventListener("gesturestart",this.onGesturestart),this.externalElements.ondragover=s=>s.preventDefault(),this.externalElements.ondrop=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 zn.Document:document.removeEventListener("keydown",this.onkeydown),document.removeEventListener("keyup",this.onkeyup);break;case zn.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 Bk(e,t){const i=t||new Path2D;e.onDestroy||(e.onDestroy=Fk,e.onMove=ad,e.onRotate=ad,e.onMouseEnter=zk,e.onMouseLeave=Hk,e.onMouseMove=Wk,e.onMouseUp=Uk,e.onInput=Nk);let n=e.calculative.borderRadius||0,r=n;const{x:s,y:a,width:l,height:c,ex:u,ey:h}=e.calculative.worldRect,{x:d}=e.calculative.worldTextRect;n<1&&(n=l*n,r=c*r);let g=n{if(e.followers){let n=e.followers.findIndex(r=>r===i.id);if(n!==-1){const r=e.calculative.canvas.store.pens[i.id+Fe];r&&r.calculative&&(Ji(r.calculative.worldRect,e.calculative.worldRect,!0)||e.followers.splice(n,1))}}})}function Uk(e){const t=e.calculative.canvas.store.active;t&&t.length&&t.forEach(i=>{const n=e.calculative.canvas.store.pens[i.id+Fe];if(n&&n.calculative){let r=ct(e.calculative.worldRect);r.x-=1,r.y-=1,r.width+=2,r.height+=2,Ji(n.calculative.worldRect,r,!0)&&(e.followers||(e.followers=[]),e.followers.includes(i.id)||e.followers.push(i.id))}})}function Wk(e,t){}const ve={};function qk(e){e.onDestroy||(e.onDestroy=jk,e.onMove=od,e.onResize=Vk,e.onRotate=od,e.onValue=$k,e.onChangeId=Kk);const t=new Path2D;if(!!e.image){if(!ve[e.id]){const i=new Image;i.crossOrigin="anonymous",i.src=e.image,e.calculative.canvas.parent.store.options.cdn&&!(e.image.startsWith("http")||e.image.startsWith("//")||e.image.startsWith("data:image"))&&(i.src=e.calculative.canvas.parent.store.options.cdn+e.image),ve[e.id]=i,i.onload=()=>{var n;ve[e.id]===i&&(e.calculative.img=i,e.calculative.imgNaturalWidth=i.naturalWidth||e.iconWidth,e.calculative.imgNaturalHeight=i.naturalHeight||e.iconHeight,(n=e.calculative.canvas.externalElements)==null||n.parentElement.appendChild(i),ps(e,i))}}return e.calculative.patchFlags&&ve[e.id]&&ps(e,ve[e.id]),t}}function jk(e){ve[e.id]&&(ve[e.id].remove(),ve[e.id]=void 0)}function od(e){!ve[e.id]||ps(e,ve[e.id])}function Vk(e){!ve[e.id]||ps(e,ve[e.id])}function $k(e){!ve[e.id]||(ps(e,ve[e.id]),ve[e.id].getAttribute("src")!==e.image&&(ve[e.id].src=e.image))}function Kk(e,t,i){!ve[t]||(ve[i]=ve[t],delete ve[t])}function ps(e,t){t.style.objectFit=e.imageRatio?"contain":"fill",ti(e,t)}function Yk(e,t){return e.onResize||(e.onResize=rg,e.onValue=Xk),qn(e,t)}function rg(e){const t=e.anchors.filter(i=>i.flag!==1);sg(e),e.anchors=e.anchors.concat(...t)}function Xk(e){rg(e),Ir(e)}function sg(e){const t=[],{x:i,y:n,width:r,height:s}=e,a=Gk(e),l=5;for(let d=0;di+r-a&&(v=Ra(i+r-a,v+a,g,a,-1)),t.push({id:String(t.length),flag:1,penId:e.id,x:(g-i)/r,y:(v-n)/s})}const c=3;for(let d=0;dn+s-a&&(v=Aa(v-a,n+s-a,g,a)),t.push({id:String(t.length),flag:1,penId:e.id,x:(v-i)/r,y:(g-n)/s})}const u=5;for(let d=0;di+r-a&&(v=Ra(i+r-a,v-a,g,a)),t.push({id:String(t.length),flag:1,penId:e.id,x:(g-i)/r,y:(v-n)/s})}const h=3;for(let d=0;dn+s-a&&(v=Aa(v+a,n+s-a,g,a,-1)),t.push({id:String(t.length),flag:1,penId:e.id,x:(v-i)/r,y:(g-n)/s})}e.anchors=t}function Gk(e){let t=e.calculative.borderRadius||0,i=e.calculative.borderRadius||0;const{width:n,height:r}=e;e.calculative.borderRadius<1&&(t=n*e.calculative.borderRadius,i=r*e.calculative.borderRadius);let s=t({id:r+"",x:i,y:n,penId:e.id}))}function Qk(){return{rectangle:qn,square:Qx,circle:t_,svgPath:z2,diamond:H2,triangle:U2,pentagon:q2,pentagram:V2,hexagon:K2,leftArrow:Y2,rightArrow:X2,twowayArrow:G2,message:Z2,cloud:J2,file:Q2,people:ek,line:sk,iframe:xk,video:Rk,gif:qk,mindNode:Yk,mindLine:Zk,mindNode2:qn,panel:Bk,combine:qn}}function tE(){return{triangle:W2,pentagon:j2,pentagram:Kv,mindNode:sg,mindLine:Jk}}var fe;(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"})(fe||(fe={}));class eE{constructor(t){W(this,"parent");W(this,"box");W(this,"boxWidth",320);W(this,"boxHeight",180);W(this,"ratio",this.boxWidth/this.boxHeight);W(this,"padding",5);W(this,"img");W(this,"isShow");W(this,"isDown");W(this,"view");W(this,"onMouseDown",t=>{t.preventDefault(),t.stopPropagation(),this.isDown=!0});W(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}});W(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}});W(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 c=.2;t.deltaY.toString().indexOf(".")!==-1&&(c=.01),t.deltaY>0?i=-c:i=c}let{offsetX:n,offsetY:r}=t;const s=this.parent.store.data.width||this.parent.store.options.width,a=this.parent.store.data.height||this.parent.store.options.height;if(s&&a)n=n/this.boxWidth*s*this.parent.store.data.scale+this.parent.store.data.origin.x+this.parent.store.data.x,r=r/this.boxHeight*a*this.parent.store.data.scale+this.parent.store.data.origin.y+this.parent.store.data.y;else{const l=this.parent.parent.getRect();n=n/this.boxWidth*l.width+l.x+this.parent.store.data.x,r=r/this.boxHeight*l.height+l.y+this.parent.store.data.y}this.parent.scale(this.parent.store.data.scale+i,{x:n,y:r})});var n;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),(n=this.parent.externalElements)==null||n.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;rthis.ratio){const d=i.width/this.ratio;i.y-=(d-i.height)/2,i.height=d,ae(i)}else{const d=i.height*this.ratio;i.x-=(d-i.width)/2,i.width=d,ae(i)}const a=this.parent.canvasRect;let l=0,c=0;if(i.x<0)l=-i.x/i.width;else if(i.x+i.width>a.width){let d=0;a.width>i.width&&(d=a.width-i.width),l=(-i.x+d)/i.width}if(i.y<0)c=-i.y/i.height;else if(i.y+i.height>a.height){let d=0;a.height>i.height&&(d=a.height-i.height),c=(-i.y+d)/i.height}const u=a.width>i.width?1:a.width/i.width,h=a.height>i.height?1:a.height/i.height;this.view.style.left=this.padding+l*this.boxWidth+"px",this.view.style.width=u*this.boxWidth+"px",this.view.style.top=this.padding+c*this.boxHeight+"px",this.view.style.height=h*this.boxHeight+"px"}}}function Ca(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 ss={exports:{}};(function(e,t){(function(i){e.exports=i()})(function(){return function(){return function i(n,r,s){function a(u,h){if(!r[u]){if(!n[u]){var d=typeof Ca=="function"&&Ca;if(!h&&d)return d(u,!0);if(l)return l(u,!0);var g=new Error("Cannot find module '"+u+"'");throw g.code="MODULE_NOT_FOUND",g}var v=r[u]={exports:{}};n[u][0].call(v.exports,function(y){return a(n[u][1][y]||y)},v,v.exports,i,n,r,s)}return r[u].exports}for(var l=typeof Ca=="function"&&Ca,c=0;c0&&(O.topicAliasMaximum>65535?x("MqttClient :: options.topicAliasMaximum is out of range"):this.topicAliasRecv=new u(O.topicAliasMaximum)),this.on("connect",function(){const st=this.queue;x("connect :: sending queued packets"),function $(){const z=st.shift();x("deliver :: entry %o",z);let V=null;if(!z)return void Z._resubscribe();V=z.packet,x("deliver :: call _sendPacket for %o",V);let Y=!0;V.messageId&&V.messageId!==0&&(Z.messageIdProvider.register(V.messageId)||(Y=!1)),Y?Z._sendPacket(V,function(U){z.cb&&z.cb(U),$()}):(x("messageId: %d has already used. The message is skipped and removed.",V.messageId),$())}()}),this.on("close",function(){x("close :: connected set to `false`"),this.connected=!1,x("close :: clearing connackTimer"),clearTimeout(this.connackTimer),x("close :: clearing ping timer"),Z.pingTimer!==null&&(Z.pingTimer.clear(),Z.pingTimer=null),this.topicAliasRecv&&this.topicAliasRecv.clear(),x("close :: calling _setupReconnect"),this._setupReconnect()}),l.call(this),x("MqttClient :: setting up stream"),this._setupStream()}y(T,l),T.prototype._setupStream=function(){const S=this,O=new v,K=d.parser(this.options);let Z=null;const st=[];function $(){if(st.length)E(z);else{const Y=Z;Z=null,Y()}}function z(){x("work :: getting next packet in queue");const Y=st.shift();if(Y)x("work :: packet pulled from queue"),S._handlePacket(Y,$);else{x("work :: no packets in queue");const U=Z;Z=null,x("work :: done flag is %s",!!U),U&&U()}}x("_setupStream :: calling method to clear reconnect"),this._clearReconnect(),x("_setupStream :: using streamBuilder provided to client to create stream"),this.stream=this.streamBuilder(this),K.on("packet",function(Y){x("parser :: on packet push to packets array."),st.push(Y)}),O._write=function(Y,U,tt){Z=tt,x("writable stream :: parsing buffer"),K.parse(Y),z()},x("_setupStream :: pipe stream to writable stream"),this.stream.pipe(O),this.stream.on("error",function(Y){x("streamErrorHandler :: error",Y.message),Y.code?(x("streamErrorHandler :: emitting error"),S.emit("error",Y)):C(Y)}),this.stream.on("close",function(){var Y;x("(%s)stream :: on close",S.options.clientId),(Y=S.outgoing)&&(x("flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"),Object.keys(Y).forEach(function(U){Y[U].volatile&&typeof Y[U].cb=="function"&&(Y[U].cb(new Error("Connection closed")),delete Y[U])})),x("stream: emit close to MqttClient"),S.emit("close")}),x("_setupStream: sending packet `connect`");const V=Object.create(this.options);if(V.cmd="connect",this.topicAliasRecv&&(V.properties||(V.properties={}),this.topicAliasRecv&&(V.properties.topicAliasMaximum=this.topicAliasRecv.max)),q(this,V),K.on("error",this.emit.bind(this,"error")),this.options.properties){if(!this.options.properties.authenticationMethod&&this.options.properties.authenticationData)return S.end(()=>this.emit("error",new Error("Packet has no Authentication Method"))),this;this.options.properties.authenticationMethod&&this.options.authPacket&&typeof this.options.authPacket=="object"&&q(this,A({cmd:"auth",reasonCode:0},this.options.authPacket))}this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout(function(){x("!!connectTimeout hit!! Calling _cleanUp with force `true`"),S._cleanUp(!0)},this.options.connectTimeout)},T.prototype._handlePacket=function(S,O){const K=this.options;if(K.protocolVersion===5&&K.properties&&K.properties.maximumPacketSize&&K.properties.maximumPacketSize0||!z())&&this._storeProcessingQueue.push({invoke:z,cbStorePut:K.cbStorePut,callback:Z}),this},T.prototype.subscribe=function(){const S=this,O=new Array(arguments.length);for(let rt=0;rt0){const ut={qos:lt.qos};V===5&&(ut.nl=lt.nl||!1,ut.rap=lt.rap||!1,ut.rh=lt.rh||0,ut.properties=lt.properties),S._resubscribeTopics[lt.topic]=ut,ft.push(lt.topic)}}),S.messageIdToTopic[nt.messageId]=ft}return S.outgoing[nt.messageId]={volatile:!0,cb:function(ft,lt){if(!ft){const ut=lt.granted;for(let b=0;b0||!tt())&&this._storeProcessingQueue.push({invoke:tt,callback:$}),this},T.prototype.unsubscribe=function(){const S=this,O=new Array(arguments.length);for(let V=0;V0||!z())&&this._storeProcessingQueue.push({invoke:z,callback:Z}),this},T.prototype.end=function(S,O,K){const Z=this;function st(){x("end :: (%s) :: finish :: calling _cleanUp with force %s",Z.options.clientId,S),Z._cleanUp(S,()=>{x("end :: finish :: calling process.nextTick on closeStores"),E(function(){x("end :: closeStores: closing incoming and outgoing stores"),Z.disconnected=!0,Z.incomingStore.close(function($){Z.outgoingStore.close(function(z){if(x("end :: closeStores: emitting end"),Z.emit("end"),K){const V=$||z;x("end :: closeStores: invoking callback with args"),K(V)}})}),Z._deferredReconnect&&Z._deferredReconnect()}.bind(Z))},O)}return x("end :: (%s)",this.options.clientId),S!=null&&typeof S=="boolean"||(K=O||C,O=S,S=!1,typeof O!="object"&&(K=O,O=null,typeof K!="function"&&(K=C))),typeof O!="object"&&(K=O,O=null),x("end :: cb? %s",!!K),K=K||C,this.disconnecting?(K(),this):(this._clearReconnect(),this.disconnecting=!0,!S&&Object.keys(this.outgoing).length>0?(x("end :: (%s) :: calling finish in 10ms once outgoing is empty",Z.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,st,10))):(x("end :: (%s) :: immediately calling finish",Z.options.clientId),st()),this)},T.prototype.removeOutgoingMessage=function(S){const O=this.outgoing[S]?this.outgoing[S].cb:null;return delete this.outgoing[S],this.outgoingStore.del({messageId:S},function(){O(new Error("Message removed"))}),this},T.prototype.reconnect=function(S){x("client reconnect");const O=this,K=function(){S?(O.options.incomingStore=S.incomingStore,O.options.outgoingStore=S.outgoingStore):(O.options.incomingStore=null,O.options.outgoingStore=null),O.incomingStore=O.options.incomingStore||new c,O.outgoingStore=O.options.outgoingStore||new c,O.disconnecting=!1,O.disconnected=!1,O._deferredReconnect=null,O._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=K:K(),this},T.prototype._reconnect=function(){x("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end(()=>{this._setupStream()}),x("client already connected. disconnecting first.")):(x("_reconnect: calling _setupStream"),this._setupStream())},T.prototype._setupReconnect=function(){const S=this;!S.disconnecting&&!S.reconnectTimer&&S.options.reconnectPeriod>0?(this.reconnecting||(x("_setupReconnect :: emit `offline` state"),this.emit("offline"),x("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),x("_setupReconnect :: setting reconnectTimer for %d ms",S.options.reconnectPeriod),S.reconnectTimer=setInterval(function(){x("reconnectTimer :: reconnect triggered!"),S._reconnect()},S.options.reconnectPeriod)):x("_setupReconnect :: doing nothing...")},T.prototype._clearReconnect=function(){x("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},T.prototype._cleanUp=function(S,O){const K=arguments[2];if(O&&(x("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",O)),x("_cleanUp :: forced? %s",S),S)this.options.reconnectPeriod===0&&this.options.clean&&(Z=this.outgoing)&&(x("flush: queue exists? %b",!!Z),Object.keys(Z).forEach(function(st){typeof Z[st].cb=="function"&&(Z[st].cb(new Error("Connection closed")),delete Z[st])})),x("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{const st=A({cmd:"disconnect"},K);x("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(st,I.bind(null,this.stream.end.bind(this.stream)))}var Z;this.disconnecting||(x("_cleanUp :: client not disconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),this.pingTimer!==null&&(x("_cleanUp :: clearing pingTimer"),this.pingTimer.clear(),this.pingTimer=null),O&&!this.connected&&(x("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",O),O())},T.prototype._sendPacket=function(S,O,K){x("_sendPacket :: (%s) :: start",this.options.clientId),K=K||C,O=O||C;const Z=function(st,$){if(st.options.protocolVersion===5&&$.cmd==="publish"){let z;$.properties&&(z=$.properties.topicAlias);const V=$.topic.toString();if(st.topicAliasSend)if(z){if(V.length!==0&&(x("applyTopicAlias :: register topic: %s - alias: %d",V,z),!st.topicAliasSend.put(V,z)))return x("applyTopicAlias :: error out of range. topic: %s - alias: %d",V,z),new Error("Sending Topic Alias out of range")}else V.length!==0&&(st.options.autoAssignTopicAlias?(z=st.topicAliasSend.getAliasByTopic(V))?($.topic="",$.properties={...$.properties,topicAlias:z},x("applyTopicAlias :: auto assign(use) topic: %s - alias: %d",V,z)):(z=st.topicAliasSend.getLruAlias(),st.topicAliasSend.put(V,z),$.properties={...$.properties,topicAlias:z},x("applyTopicAlias :: auto assign topic: %s - alias: %d",V,z)):st.options.autoUseTopicAlias&&(z=st.topicAliasSend.getAliasByTopic(V))&&($.topic="",$.properties={...$.properties,topicAlias:z},x("applyTopicAlias :: auto use topic: %s - alias: %d",V,z)));else if(z)return x("applyTopicAlias :: error out of range. topic: %s - alias: %d",V,z),new Error("Sending Topic Alias out of range")}}(this,S);if(Z)O(Z);else{if(!this.connected)return S.cmd==="auth"?(this._shiftPingInterval(),void q(this,S,O)):(x("_sendPacket :: client not connected. Storing packet offline."),void this._storePacket(S,O,K));switch(this._shiftPingInterval(),S.cmd){case"publish":break;case"pubrel":return void Q(this,S,O,K);default:return void q(this,S,O)}switch(S.qos){case 2:case 1:Q(this,S,O,K);break;case 0:default:q(this,S,O)}x("_sendPacket :: (%s) :: end",this.options.clientId)}},T.prototype._storePacket=function(S,O,K){x("_storePacket :: packet: %o",S),x("_storePacket :: cb? %s",!!O),K=K||C;let Z=S;if(Z.cmd==="publish"){const st=D(this,Z=p(S));if(st)return O&&O(st)}(Z.qos||0)===0&&this.queueQoSZero||Z.cmd!=="publish"?this.queue.push({packet:Z,cb:O}):Z.qos>0?(O=this.outgoing[Z.messageId]?this.outgoing[Z.messageId].cb:null,this.outgoingStore.put(Z,function(st){if(st)return O&&O(st);K()})):O&&O(new Error("No connection to broker"))},T.prototype._setupPingTimer=function(){x("_setupPingTimer :: keepalive %d (seconds)",this.options.keepalive);const S=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=w(function(){S._checkPing()},1e3*this.options.keepalive))},T.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},T.prototype._checkPing=function(){x("_checkPing :: checking ping..."),this.pingResp?(x("_checkPing :: ping response received. Clearing flag and sending `pingreq`"),this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):(x("_checkPing :: calling _cleanUp with force true"),this._cleanUp(!0))},T.prototype._handlePingresp=function(){this.pingResp=!0},T.prototype._handleConnack=function(S){x("_handleConnack");const O=this.options,K=O.protocolVersion===5?S.reasonCode:S.returnCode;if(clearTimeout(this.connackTimer),delete this.topicAliasSend,S.properties){if(S.properties.topicAliasMaximum){if(S.properties.topicAliasMaximum>65535)return void this.emit("error",new Error("topicAliasMaximum from broker is out of range"));S.properties.topicAliasMaximum>0&&(this.topicAliasSend=new h(S.properties.topicAliasMaximum))}S.properties.serverKeepAlive&&O.keepalive&&(O.keepalive=S.properties.serverKeepAlive,this._shiftPingInterval()),S.properties.maximumPacketSize&&(O.properties||(O.properties={}),O.properties.maximumPacketSize=S.properties.maximumPacketSize)}if(K===0)this.reconnecting=!1,this._onConnect(S);else if(K>0){const Z=new Error("Connection refused: "+B[K]);Z.code=K,this.emit("error",Z)}},T.prototype._handleAuth=function(S){const O=this.options.protocolVersion,K=O===5?S.reasonCode:S.returnCode;if(O!==5){const st=new Error("Protocol error: Auth packets are only supported in MQTT 5. Your version:"+O);return st.code=K,void this.emit("error",st)}const Z=this;this.handleAuth(S,function(st,$){if(st)Z.emit("error",st);else if(K===24)Z.reconnecting=!1,Z._sendPacket($);else{const z=new Error("Connection refused: "+B[K]);st.code=K,Z.emit("error",z)}})},T.prototype.handleAuth=function(S,O){O()},T.prototype._handlePublish=function(S,O){x("_handlePublish: packet %o",S),O=O!==void 0?O:C;let K=S.topic.toString();const Z=S.payload,st=S.qos,$=S.messageId,z=this,V=this.options,Y=[0,16,128,131,135,144,145,151,153];if(this.options.protocolVersion===5){let U;if(S.properties&&(U=S.properties.topicAlias),U!==void 0)if(K.length===0){if(!(U>0&&U<=65535))return x("_handlePublish :: topic alias out of range. alias: %d",U),void this.emit("error",new Error("Received Topic Alias is out of range"));{const tt=this.topicAliasRecv.getTopicByAlias(U);if(!tt)return x("_handlePublish :: unregistered topic alias. alias: %d",U),void this.emit("error",new Error("Received unregistered Topic Alias"));x("_handlePublish :: topic complemented by alias. topic: %s - alias: %d",K=tt,U)}}else{if(!this.topicAliasRecv.put(K,U))return x("_handlePublish :: topic alias out of range. alias: %d",U),void this.emit("error",new Error("Received Topic Alias is out of range"));x("_handlePublish :: registered topic: %s - alias: %d",K,U)}}switch(x("_handlePublish: qos %d",st),st){case 2:V.customHandleAcks(K,Z,S,function(U,tt){return U instanceof Error||(tt=U,U=null),U?z.emit("error",U):Y.indexOf(tt)===-1?z.emit("error",new Error("Wrong reason code for pubrec")):void(tt?z._sendPacket({cmd:"pubrec",messageId:$,reasonCode:tt},O):z.incomingStore.put(S,function(){z._sendPacket({cmd:"pubrec",messageId:$},O)}))});break;case 1:V.customHandleAcks(K,Z,S,function(U,tt){return U instanceof Error||(tt=U,U=null),U?z.emit("error",U):Y.indexOf(tt)===-1?z.emit("error",new Error("Wrong reason code for puback")):(tt||z.emit("message",K,Z,S),void z.handleMessage(S,function(rt){if(rt)return O&&O(rt);z._sendPacket({cmd:"puback",messageId:$,reasonCode:tt},O)}))});break;case 0:this.emit("message",K,Z,S),this.handleMessage(S,O);break;default:x("_handlePublish: unknown QoS. Doing nothing.")}},T.prototype.handleMessage=function(S,O){O()},T.prototype._handleAck=function(S){const O=S.messageId,K=S.cmd;let Z=null;const st=this.outgoing[O]?this.outgoing[O].cb:null,$=this;let z;if(st){switch(x("_handleAck :: packet type",K),K){case"pubcomp":case"puback":{const V=S.reasonCode;V&&V>0&&V!==16&&((z=new Error("Publish error: "+B[V])).code=V,st(z,S)),delete this.outgoing[O],this.outgoingStore.del(S,st),this.messageIdProvider.deallocate(O),this._invokeStoreProcessingQueue();break}case"pubrec":{Z={cmd:"pubrel",qos:2,messageId:O};const V=S.reasonCode;V&&V>0&&V!==16?((z=new Error("Publish error: "+B[V])).code=V,st(z,S)):this._sendPacket(Z);break}case"suback":delete this.outgoing[O],this.messageIdProvider.deallocate(O);for(let V=0;V0)if(this.options.resubscribe)if(this.options.protocolVersion===5){x("_resubscribe: protocolVersion 5");for(let O=0;O0){const S=this._storeProcessingQueue[0];if(S&&S.invoke())return this._storeProcessingQueue.shift(),!0}return!1},T.prototype._invokeAllStoreProcessingQueue=function(){for(;this._invokeStoreProcessingQueue(););},T.prototype._flushStoreProcessingQueue=function(){for(const S of this._storeProcessingQueue)S.cbStorePut&&S.cbStorePut(new Error("Connection closed")),S.callback&&S.callback(new Error("Connection closed"));this._storeProcessingQueue.splice(0)},n.exports=T}).call(this)}).call(this,i("_process"),typeof Le<"u"?Le: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,n,r){const{Buffer:s}=i("buffer"),a=i("readable-stream").Transform,l=i("duplexify");let c,u,h,d=!1;n.exports=function(g,v){if(v.hostname=v.hostname||v.host,!v.hostname)throw new Error("Could not determine host. Specify host manually.");const y=v.protocolId==="MQIsdp"&&v.protocolVersion===3?"mqttv3.1":"mqtt";(function(p){p.hostname||(p.hostname="localhost"),p.path||(p.path="/"),p.wsOptions||(p.wsOptions={})})(v);const w=function(p,_){const A=p.protocol==="alis"?"wss":"ws";let x=A+"://"+p.hostname+p.path;return p.port&&p.port!==80&&p.port!==443&&(x=A+"://"+p.hostname+":"+p.port+p.path),typeof p.transformWsUrl=="function"&&(x=p.transformWsUrl(x,p,_)),x}(v,g);return(c=v.my).connectSocket({url:w,protocols:y}),u=function(){const p=new a;return p._write=function(_,A,x){c.sendSocketMessage({data:_.buffer,success:function(){x()},fail:function(){x(new Error)}})},p._flush=function(_){c.closeSocket({success:function(){_()}})},p}(),h=l.obj(),d||(d=!0,c.onSocketOpen(function(){h.setReadable(u),h.setWritable(u),h.emit("connect")}),c.onSocketMessage(function(p){if(typeof p.data=="string"){const _=s.from(p.data,"base64");u.push(_)}else{const _=new FileReader;_.addEventListener("load",function(){let A=_.result;A=A instanceof ArrayBuffer?s.from(A):s.from(A,"utf8"),u.push(A)}),_.readAsArrayBuffer(p.data)}}),c.onSocketClose(function(){h.end(),h.destroy()}),c.onSocketError(function(p){h.destroy(p)})),h}},{buffer:17,duplexify:20,"readable-stream":69}],3:[function(i,n,r){const s=i("net"),a=i("debug")("mqttjs:tcp");n.exports=function(l,c){c.port=c.port||1883,c.hostname=c.hostname||c.host||"localhost";const u=c.port,h=c.hostname;return a("port %d and host %s",u,h),s.createConnection(u,h)}},{debug:18,net:16}],4:[function(i,n,r){const s=i("tls"),a=i("net"),l=i("debug")("mqttjs:tls");n.exports=function(c,u){u.port=u.port||8883,u.host=u.hostname||u.host||"localhost",a.isIP(u.host)===0&&(u.servername=u.host),u.rejectUnauthorized=u.rejectUnauthorized!==!1,delete u.path,l("port %d host %s rejectUnauthorized %b",u.port,u.host,u.rejectUnauthorized);const h=s.connect(u);function d(g){u.rejectUnauthorized&&c.emit("error",g),h.end()}return h.on("secureConnect",function(){u.rejectUnauthorized&&!h.authorized?h.emit("error",new Error("TLS not authorized")):h.removeListener("error",d)}),h.on("error",d),h}},{debug:18,net:16,tls:16}],5:[function(i,n,r){(function(s){(function(){const{Buffer:a}=i("buffer"),l=i("ws"),c=i("debug")("mqttjs:ws"),u=i("duplexify"),h=i("readable-stream").Transform,d=["rejectUnauthorized","ca","cert","key","pfx","passphrase"],g=s!==void 0&&s.title==="browser"||typeof __webpack_require__=="function";function v(w,p){let _=w.protocol+"://"+w.hostname+":"+w.port+w.path;return typeof w.transformWsUrl=="function"&&(_=w.transformWsUrl(_,w,p)),_}function y(w){const p=w;return w.hostname||(p.hostname="localhost"),w.port||(w.protocol==="wss"?p.port=443:p.port=80),w.path||(p.path="/"),w.wsOptions||(p.wsOptions={}),g||w.protocol!=="wss"||d.forEach(function(_){Object.prototype.hasOwnProperty.call(w,_)&&!Object.prototype.hasOwnProperty.call(w.wsOptions,_)&&(p.wsOptions[_]=w[_])}),p}n.exports=g?function(w,p){let _;c("browserStreamBuilder");const A=function(S){const O=y(S);if(O.hostname||(O.hostname=O.host),!O.hostname){if(typeof document>"u")throw new Error("Could not determine host. Specify host manually.");const K=new URL(document.URL);O.hostname=K.hostname,O.port||(O.port=K.port)}return O.objectMode===void 0&&(O.objectMode=!(O.binary===!0||O.binary===void 0)),O}(p).browserBufferSize||524288,x=p.browserBufferTimeout||1e3,E=!p.objectMode,I=function(S,O){const K=O.protocolId==="MQIsdp"&&O.protocolVersion===3?"mqttv3.1":"mqtt",Z=v(O,S),st=new WebSocket(Z,[K]);return st.binaryType="arraybuffer",st}(w,p),M=function(S,O,K){const Z=new h({objectModeMode:S.objectMode});return Z._write=O,Z._flush=K,Z}(p,function S(O,K,Z){I.bufferedAmount>A&&setTimeout(S,x,O,K,Z),E&&typeof O=="string"&&(O=a.from(O,"utf8"));try{I.send(O)}catch(st){return Z(st)}Z()},function(S){I.close(),S()});p.objectMode||(M._writev=T),M.on("close",()=>{I.close()});const B=I.addEventListener!==void 0;function D(){_.setReadable(M),_.setWritable(M),_.emit("connect")}function q(){_.end(),_.destroy()}function Q(S){_.destroy(S)}function C(S){let O=S.data;O=O instanceof ArrayBuffer?a.from(O):a.from(O,"utf8"),M.push(O)}function T(S,O){const K=new Array(S.length);for(let Z=0;Z{E.destroy()}),E}}).call(this)}).call(this,i("_process"))},{_process:50,buffer:17,debug:18,duplexify:20,"readable-stream":69,ws:80}],6:[function(i,n,r){const{Buffer:s}=i("buffer"),a=i("readable-stream").Transform,l=i("duplexify");let c,u,h;n.exports=function(d,g){if(g.hostname=g.hostname||g.host,!g.hostname)throw new Error("Could not determine host. Specify host manually.");const v=g.protocolId==="MQIsdp"&&g.protocolVersion===3?"mqttv3.1":"mqtt";(function(p){p.hostname||(p.hostname="localhost"),p.path||(p.path="/"),p.wsOptions||(p.wsOptions={})})(g);const y=function(p,_){const A=p.protocol==="wxs"?"wss":"ws";let x=A+"://"+p.hostname+p.path;return p.port&&p.port!==80&&p.port!==443&&(x=A+"://"+p.hostname+":"+p.port+p.path),typeof p.transformWsUrl=="function"&&(x=p.transformWsUrl(x,p,_)),x}(g,d);c=wx.connectSocket({url:y,protocols:[v]}),u=function(){const p=new a;return p._write=function(_,A,x){c.send({data:_.buffer,success:function(){x()},fail:function(E){x(new Error(E))}})},p._flush=function(_){c.close({success:function(){_()}})},p}(),(h=l.obj())._destroy=function(p,_){c.close({success:function(){_&&_(p)}})};const w=h.destroy;return h.destroy=function(){h.destroy=w;const p=this;setTimeout(function(){c.close({fail:function(){p._destroy(new Error)}})},0)}.bind(h),c.onOpen(function(){h.setReadable(u),h.setWritable(u),h.emit("connect")}),c.onMessage(function(p){let _=p.data;_=_ instanceof ArrayBuffer?s.from(_):s.from(_,"utf8"),u.push(_)}),c.onClose(function(){h.end(),h.destroy()}),c.onError(function(p){h.destroy(new Error(p.errMsg))}),h}},{buffer:17,duplexify:20,"readable-stream":69}],7:[function(i,n,r){function s(){if(!(this instanceof s))return new s;this.nextId=Math.max(1,Math.floor(65535*Math.random()))}s.prototype.allocate=function(){const a=this.nextId++;return this.nextId===65536&&(this.nextId=1),a},s.prototype.getLastAllocated=function(){return this.nextId===1?65535:this.nextId-1},s.prototype.register=function(a){return!0},s.prototype.deallocate=function(a){},s.prototype.clear=function(){},n.exports=s},{}],8:[function(i,n,r){const s=i("xtend"),a=i("readable-stream").Readable,l={objectMode:!0},c={clean:!0};function u(h){if(!(this instanceof u))return new u(h);this.options=h||{},this.options=s(c,h),this._inflights=new Map}u.prototype.put=function(h,d){return this._inflights.set(h.messageId,h),d&&d(),this},u.prototype.createStream=function(){const h=new a(l),d=[];let g=!1,v=0;return this._inflights.forEach(function(y,w){d.push(y)}),h._read=function(){!g&&vthis.max)&&(this.aliasToTopic[l]=a,this.length=Object.keys(this.aliasToTopic).length,!0)},s.prototype.getTopicByAlias=function(a){return this.aliasToTopic[a]},s.prototype.clear=function(){this.aliasToTopic={}},n.exports=s},{}],10:[function(i,n,r){const s=i("lru-cache"),a=i("number-allocator").NumberAllocator;function l(c){if(!(this instanceof l))return new l(c);c>0&&(this.aliasToTopic=new s({max:c}),this.topicToAlias={},this.numberAllocator=new a(1,c),this.max=c,this.length=0)}l.prototype.put=function(c,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,c),this.topicToAlias[c]=u,this.numberAllocator.use(u),this.length=this.aliasToTopic.length,!0},l.prototype.getTopicByAlias=function(c){return this.aliasToTopic.get(c)},l.prototype.getAliasByTopic=function(c){const u=this.topicToAlias[c];return u!==void 0&&this.aliasToTopic.get(u),u},l.prototype.clear=function(){this.aliasToTopic.reset(),this.topicToAlias={},this.numberAllocator.clear(),this.length=0},l.prototype.getLruAlias=function(){return this.numberAllocator.firstVacant()||this.aliasToTopic.keys()[this.aliasToTopic.length-1]},n.exports=l},{"lru-cache":37,"number-allocator":46}],11:[function(i,n,r){function s(a){const l=a.split("/");for(let c=0;c0?_-4:_;for(w=0;w>16&255,x[E++]=y>>8&255,x[E++]=255&y;return A===2&&(y=a[v.charCodeAt(w)]<<2|a[v.charCodeAt(w+1)]>>4,x[E++]=255&y),A===1&&(y=a[v.charCodeAt(w)]<<10|a[v.charCodeAt(w+1)]<<4|a[v.charCodeAt(w+2)]>>2,x[E++]=y>>8&255,x[E++]=255&y),x},r.fromByteArray=function(v){for(var y,w=v.length,p=w%3,_=[],A=0,x=w-p;Ax?x:A+16383));return p===1?(y=v[w-1],_.push(s[y>>2]+s[y<<4&63]+"==")):p===2&&(y=(v[w-2]<<8)+v[w-1],_.push(s[y>>10]+s[y>>4&63]+s[y<<2&63]+"=")),_.join("")};for(var s=[],a=[],l=typeof Uint8Array<"u"?Uint8Array:Array,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0,h=c.length;u0)throw new Error("Invalid string. Length must be a multiple of 4");var w=v.indexOf("=");return w===-1&&(w=y),[w,w===y?0:4-w%4]}function g(v,y,w){for(var p,_,A=[],x=y;x>18&63]+s[_>>12&63]+s[_>>6&63]+s[63&_]);return A.join("")}a["-".charCodeAt(0)]=62,a["_".charCodeAt(0)]=63},{}],14:[function(i,n,r){const{Buffer:s}=i("buffer"),a=Symbol.for("BufferList");function l(c){if(!(this instanceof l))return new l(c);l._init.call(this,c)}l._init=function(c){Object.defineProperty(this,a,{value:!0}),this._bufs=[],this.length=0,c&&this.append(c)},l.prototype._new=function(c){return new l(c)},l.prototype._offset=function(c){if(c===0)return[0,0];let u=0;for(let h=0;hthis.length||c<0)return;const u=this._offset(c);return this._bufs[u[0]][u[1]]},l.prototype.slice=function(c,u){return typeof c=="number"&&c<0&&(c+=this.length),typeof u=="number"&&u<0&&(u+=this.length),this.copy(null,0,c,u)},l.prototype.copy=function(c,u,h,d){if((typeof h!="number"||h<0)&&(h=0),(typeof d!="number"||d>this.length)&&(d=this.length),h>=this.length||d<=0)return c||s.alloc(0);const g=!!c,v=this._offset(h),y=d-h;let w=y,p=g&&u||0,_=v[1];if(h===0&&d===this.length){if(!g)return this._bufs.length===1?this._bufs[0]:s.concat(this._bufs,this.length);for(let A=0;Ax)){this._bufs[A].copy(c,p,_,_+w),p+=x;break}this._bufs[A].copy(c,p,_),p+=x,w-=x,_&&(_=0)}return c.length>p?c.slice(0,p):c},l.prototype.shallowSlice=function(c,u){if(c=c||0,u=typeof u!="number"?this.length:u,c<0&&(c+=this.length),u<0&&(u+=this.length),c===u)return this._new();const h=this._offset(c),d=this._offset(u),g=this._bufs.slice(h[0],d[0]+1);return d[1]===0?g.pop():g[g.length-1]=g[g.length-1].slice(0,d[1]),h[1]!==0&&(g[0]=g[0].slice(h[1])),this._new(g)},l.prototype.toString=function(c,u,h){return this.slice(u,h).toString(c)},l.prototype.consume=function(c){if(c=Math.trunc(c),Number.isNaN(c)||c<=0)return this;for(;this._bufs.length;){if(!(c>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(c),this.length-=c;break}c-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},l.prototype.duplicate=function(){const c=this._new();for(let u=0;uthis.length?this.length:u;const d=this._offset(u);let g=d[0],v=d[1];for(;g=c.length){const w=y.indexOf(c,v);if(w!==-1)return this._reverseOffset([g,w]);v=y.length-c.length+1}else{const w=this._reverseOffset([g,v]);if(this._match(w,c))return w;v++}v=0}return-1},l.prototype._match=function(c,u){if(this.length-cc)throw new RangeError('The value "'+b+'" is invalid for option "size"');var k=new Uint8Array(b);return k.__proto__=h.prototype,k}function h(b,k,P){if(typeof b=="number"){if(typeof k=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return v(b)}return d(b,k,P)}function d(b,k,P){if(typeof b=="string")return function(J,at){if(typeof at=="string"&&at!==""||(at="utf8"),!h.isEncoding(at))throw new TypeError("Unknown encoding: "+at);var mt=0|p(J,at),yt=u(mt),kt=yt.write(J,at);return kt!==mt&&(yt=yt.slice(0,kt)),yt}(b,k);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(lt(b,ArrayBuffer)||b&<(b.buffer,ArrayBuffer))return function(J,at,mt){if(at<0||J.byteLength=c)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+c.toString(16)+" bytes");return 0|b}function p(b,k){if(h.isBuffer(b))return b.length;if(ArrayBuffer.isView(b)||lt(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 P=b.length,H=arguments.length>2&&arguments[2]===!0;if(!H&&P===0)return 0;for(var X=!1;;)switch(k){case"ascii":case"latin1":case"binary":return P;case"utf8":case"utf-8":return rt(b).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*P;case"hex":return P>>>1;case"base64":return nt(b).length;default:if(X)return H?-1:rt(b).length;k=(""+k).toLowerCase(),X=!0}}function _(b,k,P){var H=b[k];b[k]=b[P],b[P]=H}function A(b,k,P,H,X){if(b.length===0)return-1;if(typeof P=="string"?(H=P,P=0):P>2147483647?P=2147483647:P<-2147483648&&(P=-2147483648),ut(P=+P)&&(P=X?0:b.length-1),P<0&&(P=b.length+P),P>=b.length){if(X)return-1;P=b.length-1}else if(P<0){if(!X)return-1;P=0}if(typeof k=="string"&&(k=h.from(k,H)),h.isBuffer(k))return k.length===0?-1:x(b,k,P,H,X);if(typeof k=="number")return k&=255,typeof Uint8Array.prototype.indexOf=="function"?X?Uint8Array.prototype.indexOf.call(b,k,P):Uint8Array.prototype.lastIndexOf.call(b,k,P):x(b,[k],P,H,X);throw new TypeError("val must be string, number or Buffer")}function x(b,k,P,H,X){var J,at=1,mt=b.length,yt=k.length;if(H!==void 0&&((H=String(H).toLowerCase())==="ucs2"||H==="ucs-2"||H==="utf16le"||H==="utf-16le")){if(b.length<2||k.length<2)return-1;at=2,mt/=2,yt/=2,P/=2}function kt(xe,Vt){return at===1?xe[Vt]:xe.readUInt16BE(Vt*at)}if(X){var Tt=-1;for(J=P;Jmt&&(P=mt-yt),J=P;J>=0;J--){for(var be=!0,ne=0;neX&&(H=X):H=X;var J=k.length;H>J/2&&(H=J/2);for(var at=0;at>8,yt=at%256,kt.push(yt),kt.push(mt);return kt}(k,b.length-P),b,P,H)}function Q(b,k,P){return k===0&&P===b.length?a.fromByteArray(b):a.fromByteArray(b.slice(k,P))}function C(b,k,P){P=Math.min(b.length,P);for(var H=[],X=k;X239?4:kt>223?3:kt>191?2:1;if(X+be<=P)switch(be){case 1:kt<128&&(Tt=kt);break;case 2:(192&(J=b[X+1]))==128&&(yt=(31&kt)<<6|63&J)>127&&(Tt=yt);break;case 3:J=b[X+1],at=b[X+2],(192&J)==128&&(192&at)==128&&(yt=(15&kt)<<12|(63&J)<<6|63&at)>2047&&(yt<55296||yt>57343)&&(Tt=yt);break;case 4:J=b[X+1],at=b[X+2],mt=b[X+3],(192&J)==128&&(192&at)==128&&(192&mt)==128&&(yt=(15&kt)<<18|(63&J)<<12|(63&at)<<6|63&mt)>65535&&yt<1114112&&(Tt=yt)}Tt===null?(Tt=65533,be=1):Tt>65535&&(Tt-=65536,H.push(Tt>>>10&1023|55296),Tt=56320|1023&Tt),H.push(Tt),X+=be}return function(ne){var xe=ne.length;if(xe<=T)return String.fromCharCode.apply(String,ne);for(var Vt="",Qt=0;Qt"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,k,P){return d(b,k,P)},h.prototype.__proto__=Uint8Array.prototype,h.__proto__=Uint8Array,h.alloc=function(b,k,P){return function(H,X,J){return g(H),H<=0?u(H):X!==void 0?typeof J=="string"?u(H).fill(X,J):u(H).fill(X):u(H)}(b,k,P)},h.allocUnsafe=function(b){return v(b)},h.allocUnsafeSlow=function(b){return v(b)},h.isBuffer=function(b){return b!=null&&b._isBuffer===!0&&b!==h.prototype},h.compare=function(b,k){if(lt(b,Uint8Array)&&(b=h.from(b,b.offset,b.byteLength)),lt(k,Uint8Array)&&(k=h.from(k,k.offset,k.byteLength)),!h.isBuffer(b)||!h.isBuffer(k))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(b===k)return 0;for(var P=b.length,H=k.length,X=0,J=Math.min(P,H);Xthis.length||((H===void 0||H>this.length)&&(H=this.length),H<=0)||(H>>>=0)<=(P>>>=0))return"";for(k||(k="utf8");;)switch(k){case"hex":return K(this,P,H);case"utf8":case"utf-8":return C(this,P,H);case"ascii":return S(this,P,H);case"latin1":case"binary":return O(this,P,H);case"base64":return Q(this,P,H);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Z(this,P,H);default:if(X)throw new TypeError("Unknown encoding: "+k);k=(k+"").toLowerCase(),X=!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="",k=r.INSPECT_MAX_BYTES;return b=this.toString("hex",0,k).replace(/(.{2})/g,"$1 ").trim(),this.length>k&&(b+=" ... "),""},h.prototype.compare=function(b,k,P,H,X){if(lt(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(k===void 0&&(k=0),P===void 0&&(P=b?b.length:0),H===void 0&&(H=0),X===void 0&&(X=this.length),k<0||P>b.length||H<0||X>this.length)throw new RangeError("out of range index");if(H>=X&&k>=P)return 0;if(H>=X)return-1;if(k>=P)return 1;if(k>>>=0,P>>>=0,H>>>=0,X>>>=0,this===b)return 0;for(var J=X-H,at=P-k,mt=Math.min(J,at),yt=this.slice(H,X),kt=b.slice(k,P),Tt=0;Tt>>=0,isFinite(P)?(P>>>=0,H===void 0&&(H="utf8")):(H=P,P=void 0)}var X=this.length-k;if((P===void 0||P>X)&&(P=X),b.length>0&&(P<0||k<0)||k>this.length)throw new RangeError("Attempt to write outside buffer bounds");H||(H="utf8");for(var J=!1;;)switch(H){case"hex":return E(this,b,k,P);case"utf8":case"utf-8":return I(this,b,k,P);case"ascii":return M(this,b,k,P);case"latin1":case"binary":return B(this,b,k,P);case"base64":return D(this,b,k,P);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return q(this,b,k,P);default:if(J)throw new TypeError("Unknown encoding: "+H);H=(""+H).toLowerCase(),J=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var T=4096;function S(b,k,P){var H="";P=Math.min(b.length,P);for(var X=k;XH)&&(P=H);for(var X="",J=k;JP)throw new RangeError("Trying to access beyond buffer length")}function $(b,k,P,H,X,J){if(!h.isBuffer(b))throw new TypeError('"buffer" argument must be a Buffer instance');if(k>X||kb.length)throw new RangeError("Index out of range")}function z(b,k,P,H,X,J){if(P+H>b.length)throw new RangeError("Index out of range");if(P<0)throw new RangeError("Index out of range")}function V(b,k,P,H,X){return k=+k,P>>>=0,X||z(b,0,P,4),l.write(b,k,P,H,23,4),P+4}function Y(b,k,P,H,X){return k=+k,P>>>=0,X||z(b,0,P,8),l.write(b,k,P,H,52,8),P+8}h.prototype.slice=function(b,k){var P=this.length;b=~~b,k=k===void 0?P:~~k,b<0?(b+=P)<0&&(b=0):b>P&&(b=P),k<0?(k+=P)<0&&(k=0):k>P&&(k=P),k>>=0,k>>>=0,P||st(b,k,this.length);for(var H=this[b],X=1,J=0;++J>>=0,k>>>=0,P||st(b,k,this.length);for(var H=this[b+--k],X=1;k>0&&(X*=256);)H+=this[b+--k]*X;return H},h.prototype.readUInt8=function(b,k){return b>>>=0,k||st(b,1,this.length),this[b]},h.prototype.readUInt16LE=function(b,k){return b>>>=0,k||st(b,2,this.length),this[b]|this[b+1]<<8},h.prototype.readUInt16BE=function(b,k){return b>>>=0,k||st(b,2,this.length),this[b]<<8|this[b+1]},h.prototype.readUInt32LE=function(b,k){return b>>>=0,k||st(b,4,this.length),(this[b]|this[b+1]<<8|this[b+2]<<16)+16777216*this[b+3]},h.prototype.readUInt32BE=function(b,k){return b>>>=0,k||st(b,4,this.length),16777216*this[b]+(this[b+1]<<16|this[b+2]<<8|this[b+3])},h.prototype.readIntLE=function(b,k,P){b>>>=0,k>>>=0,P||st(b,k,this.length);for(var H=this[b],X=1,J=0;++J=(X*=128)&&(H-=Math.pow(2,8*k)),H},h.prototype.readIntBE=function(b,k,P){b>>>=0,k>>>=0,P||st(b,k,this.length);for(var H=k,X=1,J=this[b+--H];H>0&&(X*=256);)J+=this[b+--H]*X;return J>=(X*=128)&&(J-=Math.pow(2,8*k)),J},h.prototype.readInt8=function(b,k){return b>>>=0,k||st(b,1,this.length),128&this[b]?-1*(255-this[b]+1):this[b]},h.prototype.readInt16LE=function(b,k){b>>>=0,k||st(b,2,this.length);var P=this[b]|this[b+1]<<8;return 32768&P?4294901760|P:P},h.prototype.readInt16BE=function(b,k){b>>>=0,k||st(b,2,this.length);var P=this[b+1]|this[b]<<8;return 32768&P?4294901760|P:P},h.prototype.readInt32LE=function(b,k){return b>>>=0,k||st(b,4,this.length),this[b]|this[b+1]<<8|this[b+2]<<16|this[b+3]<<24},h.prototype.readInt32BE=function(b,k){return b>>>=0,k||st(b,4,this.length),this[b]<<24|this[b+1]<<16|this[b+2]<<8|this[b+3]},h.prototype.readFloatLE=function(b,k){return b>>>=0,k||st(b,4,this.length),l.read(this,b,!0,23,4)},h.prototype.readFloatBE=function(b,k){return b>>>=0,k||st(b,4,this.length),l.read(this,b,!1,23,4)},h.prototype.readDoubleLE=function(b,k){return b>>>=0,k||st(b,8,this.length),l.read(this,b,!0,52,8)},h.prototype.readDoubleBE=function(b,k){return b>>>=0,k||st(b,8,this.length),l.read(this,b,!1,52,8)},h.prototype.writeUIntLE=function(b,k,P,H){b=+b,k>>>=0,P>>>=0,H||$(this,b,k,P,Math.pow(2,8*P)-1,0);var X=1,J=0;for(this[k]=255&b;++J>>=0,P>>>=0,H||$(this,b,k,P,Math.pow(2,8*P)-1,0);var X=P-1,J=1;for(this[k+X]=255&b;--X>=0&&(J*=256);)this[k+X]=b/J&255;return k+P},h.prototype.writeUInt8=function(b,k,P){return b=+b,k>>>=0,P||$(this,b,k,1,255,0),this[k]=255&b,k+1},h.prototype.writeUInt16LE=function(b,k,P){return b=+b,k>>>=0,P||$(this,b,k,2,65535,0),this[k]=255&b,this[k+1]=b>>>8,k+2},h.prototype.writeUInt16BE=function(b,k,P){return b=+b,k>>>=0,P||$(this,b,k,2,65535,0),this[k]=b>>>8,this[k+1]=255&b,k+2},h.prototype.writeUInt32LE=function(b,k,P){return b=+b,k>>>=0,P||$(this,b,k,4,4294967295,0),this[k+3]=b>>>24,this[k+2]=b>>>16,this[k+1]=b>>>8,this[k]=255&b,k+4},h.prototype.writeUInt32BE=function(b,k,P){return b=+b,k>>>=0,P||$(this,b,k,4,4294967295,0),this[k]=b>>>24,this[k+1]=b>>>16,this[k+2]=b>>>8,this[k+3]=255&b,k+4},h.prototype.writeIntLE=function(b,k,P,H){if(b=+b,k>>>=0,!H){var X=Math.pow(2,8*P-1);$(this,b,k,P,X-1,-X)}var J=0,at=1,mt=0;for(this[k]=255&b;++J>0)-mt&255;return k+P},h.prototype.writeIntBE=function(b,k,P,H){if(b=+b,k>>>=0,!H){var X=Math.pow(2,8*P-1);$(this,b,k,P,X-1,-X)}var J=P-1,at=1,mt=0;for(this[k+J]=255&b;--J>=0&&(at*=256);)b<0&&mt===0&&this[k+J+1]!==0&&(mt=1),this[k+J]=(b/at>>0)-mt&255;return k+P},h.prototype.writeInt8=function(b,k,P){return b=+b,k>>>=0,P||$(this,b,k,1,127,-128),b<0&&(b=255+b+1),this[k]=255&b,k+1},h.prototype.writeInt16LE=function(b,k,P){return b=+b,k>>>=0,P||$(this,b,k,2,32767,-32768),this[k]=255&b,this[k+1]=b>>>8,k+2},h.prototype.writeInt16BE=function(b,k,P){return b=+b,k>>>=0,P||$(this,b,k,2,32767,-32768),this[k]=b>>>8,this[k+1]=255&b,k+2},h.prototype.writeInt32LE=function(b,k,P){return b=+b,k>>>=0,P||$(this,b,k,4,2147483647,-2147483648),this[k]=255&b,this[k+1]=b>>>8,this[k+2]=b>>>16,this[k+3]=b>>>24,k+4},h.prototype.writeInt32BE=function(b,k,P){return b=+b,k>>>=0,P||$(this,b,k,4,2147483647,-2147483648),b<0&&(b=4294967295+b+1),this[k]=b>>>24,this[k+1]=b>>>16,this[k+2]=b>>>8,this[k+3]=255&b,k+4},h.prototype.writeFloatLE=function(b,k,P){return V(this,b,k,!0,P)},h.prototype.writeFloatBE=function(b,k,P){return V(this,b,k,!1,P)},h.prototype.writeDoubleLE=function(b,k,P){return Y(this,b,k,!0,P)},h.prototype.writeDoubleBE=function(b,k,P){return Y(this,b,k,!1,P)},h.prototype.copy=function(b,k,P,H){if(!h.isBuffer(b))throw new TypeError("argument should be a Buffer");if(P||(P=0),H||H===0||(H=this.length),k>=b.length&&(k=b.length),k||(k=0),H>0&&H=this.length)throw new RangeError("Index out of range");if(H<0)throw new RangeError("sourceEnd out of bounds");H>this.length&&(H=this.length),b.length-k=0;--J)b[J+k]=this[J+P];else Uint8Array.prototype.set.call(b,this.subarray(P,H),k);return X},h.prototype.fill=function(b,k,P,H){if(typeof b=="string"){if(typeof k=="string"?(H=k,k=0,P=this.length):typeof P=="string"&&(H=P,P=this.length),H!==void 0&&typeof H!="string")throw new TypeError("encoding must be a string");if(typeof H=="string"&&!h.isEncoding(H))throw new TypeError("Unknown encoding: "+H);if(b.length===1){var X=b.charCodeAt(0);(H==="utf8"&&X<128||H==="latin1")&&(b=X)}}else typeof b=="number"&&(b&=255);if(k<0||this.length>>=0,P=P===void 0?this.length:P>>>0,b||(b=0),typeof b=="number")for(J=k;J55295&&P<57344){if(!X){if(P>56319){(k-=3)>-1&&J.push(239,191,189);continue}if(at+1===H){(k-=3)>-1&&J.push(239,191,189);continue}X=P;continue}if(P<56320){(k-=3)>-1&&J.push(239,191,189),X=P;continue}P=65536+(X-55296<<10|P-56320)}else X&&(k-=3)>-1&&J.push(239,191,189);if(X=null,P<128){if((k-=1)<0)break;J.push(P)}else if(P<2048){if((k-=2)<0)break;J.push(P>>6|192,63&P|128)}else if(P<65536){if((k-=3)<0)break;J.push(P>>12|224,P>>6&63|128,63&P|128)}else{if(!(P<1114112))throw new Error("Invalid code point");if((k-=4)<0)break;J.push(P>>18|240,P>>12&63|128,P>>6&63|128,63&P|128)}}return J}function nt(b){return a.toByteArray(function(k){if((k=(k=k.split("=")[0]).trim().replace(U,"")).length<2)return"";for(;k.length%4!=0;)k+="=";return k}(b))}function ft(b,k,P,H){for(var X=0;X=k.length||X>=b.length);++X)k[X+P]=b[X];return X}function lt(b,k){return b instanceof k||b!=null&&b.constructor!=null&&b.constructor.name!=null&&b.constructor.name===k.name}function ut(b){return b!=b}}).call(this)}).call(this,i("buffer").Buffer)},{"base64-js":13,buffer:17,ieee754:23}],18:[function(i,n,r){(function(s){(function(){r.formatArgs=function(l){if(l[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+l[0]+(this.useColors?"%c ":" ")+"+"+n.exports.humanize(this.diff),!this.useColors)return;const c="color: "+this.color;l.splice(1,0,c,"color: inherit");let u=0,h=0;l[0].replace(/%[a-zA-Z%]/g,d=>{d!=="%%"&&d==="%c"&&(h=++u)}),l.splice(h,0,c)},r.save=function(l){try{l?r.storage.setItem("debug",l):r.storage.removeItem("debug")}catch{}},r.load=function(){let l;try{l=r.storage.getItem("debug")}catch{}return!l&&s!==void 0&&"env"in s&&(l=s.env.DEBUG),l},r.useColors=function(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},r.storage=function(){try{return localStorage}catch{}}(),r.destroy=(()=>{let l=!1;return()=>{l||(l=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),r.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],r.log=console.debug||console.log||(()=>{}),n.exports=i("./common")(r);const{formatters:a}=n.exports;a.j=function(l){try{return JSON.stringify(l)}catch(c){return"[UnexpectedJSONParseError]: "+c.message}}}).call(this)}).call(this,i("_process"))},{"./common":19,_process:50}],19:[function(i,n,r){n.exports=function(s){function a(u){let h,d,g,v=null;function y(...w){if(!y.enabled)return;const p=y,_=Number(new Date),A=_-(h||_);p.diff=A,p.prev=h,p.curr=_,h=_,w[0]=a.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let x=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,(E,I)=>{if(E==="%%")return"%";x++;const M=a.formatters[I];if(typeof M=="function"){const B=w[x];E=M.call(p,B),w.splice(x,1),x--}return E}),a.formatArgs.call(p,w),(p.log||a.log).apply(p,w)}return y.namespace=u,y.useColors=a.useColors(),y.color=a.selectColor(u),y.extend=l,y.destroy=a.destroy,Object.defineProperty(y,"enabled",{enumerable:!0,configurable:!1,get:()=>v!==null?v:(d!==a.namespaces&&(d=a.namespaces,g=a.enabled(u)),g),set:w=>{v=w}}),typeof a.init=="function"&&a.init(y),y}function l(u,h){const d=a(this.namespace+(h===void 0?":":h)+u);return d.log=this.log,d}function c(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}return a.debug=a,a.default=a,a.coerce=function(u){return u instanceof Error?u.stack||u.message:u},a.disable=function(){const u=[...a.names.map(c),...a.skips.map(c).map(h=>"-"+h)].join(",");return a.enable(""),u},a.enable=function(u){let h;a.save(u),a.namespaces=u,a.names=[],a.skips=[];const d=(typeof u=="string"?u:"").split(/[\s,]+/),g=d.length;for(h=0;h{a[u]=s[u]}),a.names=[],a.skips=[],a.formatters={},a.selectColor=function(u){let h=0;for(let d=0;d0&&q.length>B){q.warned=!0;var Q=new Error("Possible EventEmitter memory leak detected. "+q.length+' "'+String(E)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');Q.name="MaxListenersExceededWarning",Q.emitter=x,Q.type=E,Q.count=q.length,typeof console=="object"&&console.warn&&console.warn("%s: %s",Q.name,Q.message)}}else q=D[E]=I,++x._eventsCount;return x}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 x=new Array(arguments.length),E=0;E1&&(E=arguments[1]),E instanceof Error)throw E;var C=new Error('Unhandled "error" event. ('+E+")");throw C.context=E,C}if(!(I=q[x]))return!1;var T=typeof I=="function";switch(M=arguments.length){case 1:(function(S,O,K){if(O)S.call(K);else for(var Z=S.length,st=A(S,Z),$=0;$=0;D--)if(I[D]===E||I[D].listener===E){q=I[D].listener,B=D;break}if(B<0)return this;B===0?I.shift():function(Q,C){for(var T=C,S=T+1,O=Q.length;S=0;M--)this.removeListener(x,E[M]);return this},c.prototype.listeners=function(x){return p(this,x,!0)},c.prototype.rawListeners=function(x){return p(this,x,!1)},c.listenerCount=function(x,E){return typeof x.listenerCount=="function"?x.listenerCount(E):_.call(x,E)},c.prototype.listenerCount=_,c.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],23:[function(i,n,r){r.read=function(s,a,l,c,u){var h,d,g=8*u-c-1,v=(1<>1,w=-7,p=l?u-1:0,_=l?-1:1,A=s[a+p];for(p+=_,h=A&(1<<-w)-1,A>>=-w,w+=g;w>0;h=256*h+s[a+p],p+=_,w-=8);for(d=h&(1<<-w)-1,h>>=-w,w+=c;w>0;d=256*d+s[a+p],p+=_,w-=8);if(h===0)h=1-y;else{if(h===v)return d?NaN:1/0*(A?-1:1);d+=Math.pow(2,c),h-=y}return(A?-1:1)*d*Math.pow(2,h-c)},r.write=function(s,a,l,c,u,h){var d,g,v,y=8*h-u-1,w=(1<>1,_=u===23?Math.pow(2,-24)-Math.pow(2,-77):0,A=c?0:h-1,x=c?1:-1,E=a<0||a===0&&1/a<0?1:0;for(a=Math.abs(a),isNaN(a)||a===1/0?(g=isNaN(a)?1:0,d=w):(d=Math.floor(Math.log(a)/Math.LN2),a*(v=Math.pow(2,-d))<1&&(d--,v*=2),(a+=d+p>=1?_/v:_*Math.pow(2,1-p))*v>=2&&(d++,v/=2),d+p>=w?(g=0,d=w):d+p>=1?(g=(a*v-1)*Math.pow(2,u),d+=p):(g=a*Math.pow(2,p-1)*Math.pow(2,u),d=0));u>=8;s[l+A]=255&g,A+=x,g/=256,u-=8);for(d=d<0;s[l+A]=255&d,A+=x,d/=256,y-=8);s[l+A-x]|=128*E}},{}],24:[function(i,n,r){typeof Object.create=="function"?n.exports=function(s,a){a&&(s.super_=a,s.prototype=Object.create(a.prototype,{constructor:{value:s,enumerable:!1,writable:!0,configurable:!0}}))}:n.exports=function(s,a){if(a){s.super_=a;var l=function(){};l.prototype=a.prototype,s.prototype=new l,s.prototype.constructor=s}}},{}],25:[function(i,n,r){Object.defineProperty(r,"__esModule",{value:!0});var s=function(){function a(l,c){this.color=!0,this.key=void 0,this.value=void 0,this.parent=void 0,this.brother=void 0,this.leftChild=void 0,this.rightChild=void 0,this.key=l,this.value=c}return a.prototype.rotateLeft=function(){var l=this.parent,c=this.brother,u=this.leftChild,h=this.rightChild;if(!h)throw new Error("unknown error");var d=h.leftChild,g=h.rightChild;return l&&(l.leftChild===this?l.leftChild=h:l.rightChild===this&&(l.rightChild=h)),h.parent=l,h.brother=c,h.leftChild=this,h.rightChild=g,c&&(c.brother=h),this.parent=h,this.brother=g,this.leftChild=u,this.rightChild=d,g&&(g.parent=h,g.brother=this),u&&(u.parent=this,u.brother=d),d&&(d.parent=this,d.brother=u),h},a.prototype.rotateRight=function(){var l=this.parent,c=this.brother,u=this.leftChild;if(!u)throw new Error("unknown error");var h=this.rightChild,d=u.leftChild,g=u.rightChild;return l&&(l.leftChild===this?l.leftChild=u:l.rightChild===this&&(l.rightChild=u)),u.parent=l,u.brother=c,u.leftChild=d,u.rightChild=this,c&&(c.brother=u),d&&(d.parent=u,d.brother=this),this.parent=u,this.brother=d,this.leftChild=g,this.rightChild=h,g&&(g.parent=this,g.brother=h),h&&(h.parent=this,h.brother=g),u},a.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},a.TreeNodeColorType={red:!0,black:!1},a}();Object.freeze(s),r.default=s},{}],26:[function(i,n,r){var s=this&&this.__generator||function(l,c){var u,h,d,g,v={label:0,sent:function(){if(1&d[0])throw d[1];return d[1]},trys:[],ops:[]};return g={next:y(0),throw:y(1),return:y(2)},typeof Symbol=="function"&&(g[Symbol.iterator]=function(){return this}),g;function y(w){return function(p){return function(_){if(u)throw new TypeError("Generator is already executing.");for(;v;)try{if(u=1,h&&(d=2&_[0]?h.return:_[0]?h.throw||((d=h.return)&&d.call(h),0):h.next)&&!(d=d.call(h,_[1])).done)return d;switch(h=0,d&&(_=[2&_[0],d.value]),_[0]){case 0:case 1:d=_;break;case 4:return v.label++,{value:_[1],done:!1};case 5:v.label++,h=_[1],_=[0];continue;case 7:_=v.ops.pop(),v.trys.pop();continue;default:if(!(d=(d=v.trys).length>0&&d[d.length-1])&&(_[0]===6||_[0]===2)){v=0;continue}if(_[0]===3&&(!d||_[1]>d[0]&&_[1]I)throw new Error("pos should more than 0 and less than queue's size");return{curNodeBucketIndex:Math.floor(E/a.bucketSize),curNodePointerIndex:E%a.bucketSize}};this.getElementByPos=function(A){var x=p(A),E=x.curNodeBucketIndex,I=x.curNodePointerIndex;return u[E][I]},this.eraseElementByPos=function(A){var x=this;if(A<0||A>w)throw new Error("pos should more than 0 and less than queue's size");if(A===0)this.popFront();else if(A===this.size())this.popBack();else{for(var E=[],I=A+1;I0?--v:h0&&--w)},this.setElementByPos=function(A,x){var E=p(A),I=E.curNodeBucketIndex,M=E.curNodePointerIndex;u[I][M]=x},this.insert=function(A,x,E){var I=this;if(E===void 0&&(E=1),A===0)for(;E--;)this.pushFront(x);else if(A===this.size())for(;E--;)this.pushBack(x);else{for(var M=[],B=A;B0?--d:h>0&&(--h,d=a.bucketSize-1)),++w,u[h][d]=A},this.popFront=function(){this.empty()||(this.size()!==1&&(d0&&--w)},this.shrinkToFit=function(){var A=this,x=[];this.forEach(function(B){x.push(B)});var E=x.length;u=[];for(var I=Math.ceil(E/a.bucketSize),M=0;M0&&y[y.length-1])&&(E[0]===6||E[0]===2)){p=0;continue}if(E[0]===3&&(!y||E[1]>y[0]&&E[1]=h.length&&(h=void 0),{value:h&&h[v++],done:!h}}};throw new TypeError(d?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var l=i("../LinkList/LinkList"),c=i("../Map/Map");function u(h,d,g){var v=this;if(h===void 0&&(h=[]),d===void 0&&(d=u.initSize),g=g||function(_){var A,x,E=0,I="";if(typeof _=="number")E=((E=Math.floor(_))<<5)-E,E&=E;else{I=typeof _!="string"?JSON.stringify(_):_;try{for(var M=a(I),B=M.next();!B.done;B=M.next())E=(E<<5)-E+B.value.charCodeAt(0),E&=E}catch(D){A={error:D}}finally{try{B&&!B.done&&(x=M.return)&&x.call(M)}finally{if(A)throw A.error}}}return E^=E>>>16},(d&d-1)!=0)throw new Error("initBucketNum must be 2 to the power of n");var y=0,w=[],p=Math.max(u.initSize,Math.min(u.maxSize,d));this.size=function(){return y},this.empty=function(){return y===0},this.clear=function(){y=0,p=d,w=[]},this.forEach=function(_){var A=0;w.forEach(function(x){x.forEach(function(E){_(E,A++)})})},this.setElement=function(_,A){var x,E;if(_==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(A!=null){var I=g(_)&p-1;if(w[I]){var M=w[I].size();if(w[I]instanceof l.default){try{for(var B=a(w[I]),D=B.next();!D.done;D=B.next()){var q=D.value;if(q.key===_)return void(q.value=A)}}catch(C){x={error:C}}finally{try{D&&!D.done&&(E=B.return)&&E.call(B)}finally{if(x)throw x.error}}w[I].pushBack({key:_,value:A}),w[I].size()>=u.treeifyThreshold&&(w[I]=new c.default(w[I]))}else w[I].setElement(_,A);var Q=w[I].size();y+=Q-M}else++y,w[I]=new l.default([{key:_,value:A}]);y>p*u.sigma&&function(C){if(!(C>=u.maxSize)){p=2*C;var T=[];w.forEach(function(S,O){if(!S.empty()){if(S instanceof l.default&&S.size()===1){var K=S.front(),Z=K.key,st=K.value;T[g(Z)&p-1]=new l.default([{key:Z,value:st}])}else if(S instanceof c.default){var $=new l.default,z=new l.default;S.forEach(function(U){(g(U.key)&C)==0?$.pushBack(U):z.pushBack(U)}),$.size()>u.untreeifyThreshold?T[O]=new c.default($):$.size()&&(T[O]=$),z.size()>u.untreeifyThreshold?T[O+C]=new c.default(z):z.size()&&(T[O+C]=z)}else{var V=new l.default,Y=new l.default;S.forEach(function(U){(g(U.key)&C)==0?V.pushBack(U):Y.pushBack(U)}),V.size()&&(T[O]=V),Y.size()&&(T[O+C]=Y)}w[O].clear()}}),w=T}}.call(this,p)}else this.eraseElementByKey(_)},this.getElementByKey=function(_){var A,x,E=g(_)&p-1;if(w[E]){if(w[E]instanceof c.default)return w[E].getElementByKey(_);try{for(var I=a(w[E]),M=I.next();!M.done;M=I.next()){var B=M.value;if(B.key===_)return B.value}}catch(D){A={error:D}}finally{try{M&&!M.done&&(x=I.return)&&x.call(I)}finally{if(A)throw A.error}}}},this.eraseElementByKey=function(_){var A,x,E=g(_)&p-1;if(w[E]){var I=w[E].size();if(w[E]instanceof c.default)w[E].eraseElementByKey(_),w[E].size()<=u.untreeifyThreshold&&(w[E]=new l.default(w[E]));else{var M=-1;try{for(var B=a(w[E]),D=B.next();!D.done;D=B.next())if(++M,D.value.key===_){w[E].eraseElementByPos(M);break}}catch(Q){A={error:Q}}finally{try{D&&!D.done&&(x=B.return)&&x.call(B)}finally{if(A)throw A.error}}}var q=w[E].size();y+=q-I}},this.find=function(_){var A,x,E=g(_)&p-1;if(!w[E])return!1;if(w[E]instanceof c.default)return w[E].find(_);try{for(var I=a(w[E]),M=I.next();!M.done;M=I.next())if(M.value.key===_)return!0}catch(B){A={error:B}}finally{try{M&&!M.done&&(x=I.return)&&x.call(I)}finally{if(A)throw A.error}}return!1},this[Symbol.iterator]=function(){return function(){var _,A,x,E,I,M;return s(this,function(B){switch(B.label){case 0:_=0,B.label=1;case 1:if(!(_=p)return[3,10];B.label=2;case 2:B.trys.push([2,7,8,9]),I=void 0,A=a(w[_]),x=A.next(),B.label=3;case 3:return x.done?[3,6]:[4,x.value];case 4:B.sent(),B.label=5;case 5:return x=A.next(),[3,3];case 6:return[3,9];case 7:return E=B.sent(),I={error:E},[3,9];case 8:try{x&&!x.done&&(M=A.return)&&M.call(A)}finally{if(I)throw I.error}return[7];case 9:return++_,[3,1];case 10:return[2]}})}()},h.forEach(function(_){var A=_.key,x=_.value;return v.setElement(A,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,"../Map/Map":30}],28:[function(i,n,r){var s=this&&this.__generator||function(h,d){var g,v,y,w,p={label:0,sent:function(){if(1&y[0])throw y[1];return y[1]},trys:[],ops:[]};return w={next:_(0),throw:_(1),return:_(2)},typeof Symbol=="function"&&(w[Symbol.iterator]=function(){return this}),w;function _(A){return function(x){return function(E){if(g)throw new TypeError("Generator is already executing.");for(;p;)try{if(g=1,v&&(y=2&E[0]?v.return:E[0]?v.throw||((y=v.return)&&y.call(v),0):v.next)&&!(y=y.call(v,E[1])).done)return y;switch(v=0,y&&(E=[2&E[0],y.value]),E[0]){case 0:case 1:y=E;break;case 4:return p.label++,{value:E[1],done:!1};case 5:p.label++,v=E[1],E=[0];continue;case 7:E=p.ops.pop(),p.trys.pop();continue;default:if(!(y=(y=p.trys).length>0&&y[y.length-1])&&(E[0]===6||E[0]===2)){p=0;continue}if(E[0]===3&&(!y||E[1]>y[0]&&E[1]=h.length&&(h=void 0),{value:h&&h[v++],done:!h}}};throw new TypeError(d?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var l=i("../Set/Set"),c=i("../LinkList/LinkList");function u(h,d,g){var v=this;if(h===void 0&&(h=[]),d===void 0&&(d=u.initSize),g=g||function(_){var A=0,x="";if(typeof _=="number")A=((A=Math.floor(_))<<5)-A,A&=A;else{x=typeof _!="string"?JSON.stringify(_):_;for(var E=0;E>>16},(d&d-1)!=0)throw new Error("initBucketNum must be 2 to the power of n");var y=0,w=[],p=Math.max(u.initSize,Math.min(u.maxSize,d));this.size=function(){return y},this.empty=function(){return y===0},this.clear=function(){y=0,p=d,w=[]},this.forEach=function(_){var A=0;w.forEach(function(x){x.forEach(function(E){_(E,A++)})})},this.insert=function(_){if(_==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");var A=g(_)&p-1;if(w[A]){var x=w[A].size();if(w[A]instanceof c.default){if(w[A].find(_))return;w[A].pushBack(_),w[A].size()>=u.treeifyThreshold&&(w[A]=new l.default(w[A]))}else w[A].insert(_);var E=w[A].size();y+=E-x}else w[A]=new c.default([_]),++y;y>p*u.sigma&&function(I){if(!(I>=u.maxSize)){p=2*I;var M=[];w.forEach(function(B,D){if(!B.empty()){if(B instanceof c.default&&B.size()===1){var q=B.front();if(q===void 0)throw new Error("unknown error");M[g(q)&p-1]=new c.default([q])}else if(B instanceof l.default){var Q=new c.default,C=new c.default;B.forEach(function(O){(g(O)&I)==0?Q.pushBack(O):C.pushBack(O)}),Q.size()>u.untreeifyThreshold?M[D]=new l.default(Q):Q.size()&&(M[D]=Q),C.size()>u.untreeifyThreshold?M[D+I]=new l.default(C):C.size()&&(M[D+I]=C)}else{var T=new c.default,S=new c.default;B.forEach(function(O){(g(O)&I)==0?T.pushBack(O):S.pushBack(O)}),T.size()&&(M[D]=T),S.size()&&(M[D+I]=S)}w[D].clear()}}),w=M}}.call(this,p)},this.eraseElementByValue=function(_){var A=g(_)&p-1;if(w[A]){var x=w[A].size();w[A].eraseElementByValue(_),w[A]instanceof l.default&&w[A].size()<=u.untreeifyThreshold&&(w[A]=new c.default(w[A]));var E=w[A].size();y+=E-x}},this.find=function(_){var A=g(_)&p-1;return!!w[A]&&w[A].find(_)},this[Symbol.iterator]=function(){return function(){var _,A,x,E,I,M;return s(this,function(B){switch(B.label){case 0:_=0,B.label=1;case 1:if(!(_=p)return[3,10];B.label=2;case 2:B.trys.push([2,7,8,9]),I=void 0,A=a(w[_]),x=A.next(),B.label=3;case 3:return x.done?[3,6]:[4,x.value];case 4:B.sent(),B.label=5;case 5:return x=A.next(),[3,3];case 6:return[3,9];case 7:return E=B.sent(),I={error:E},[3,9];case 8:try{x&&!x.done&&(M=A.return)&&M.call(A)}finally{if(I)throw I.error}return[7];case 9:return++_,[3,1];case 10:return[2]}})}()},h.forEach(function(_){return v.insert(_)}),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,n,r){var s=this&&this.__generator||function(c,u){var h,d,g,v,y={label:0,sent:function(){if(1&g[0])throw g[1];return g[1]},trys:[],ops:[]};return v={next:w(0),throw:w(1),return:w(2)},typeof Symbol=="function"&&(v[Symbol.iterator]=function(){return this}),v;function w(p){return function(_){return function(A){if(h)throw new TypeError("Generator is already executing.");for(;y;)try{if(h=1,d&&(g=2&A[0]?d.return:A[0]?d.throw||((g=d.return)&&g.call(d),0):d.next)&&!(g=g.call(d,A[1])).done)return g;switch(d=0,g&&(A=[2&A[0],g.value]),A[0]){case 0:case 1:g=A;break;case 4:return y.label++,{value:A[1],done:!1};case 5:y.label++,d=A[1],A=[0];continue;case 7:A=y.ops.pop(),y.trys.pop();continue;default:if(!(g=(g=y.trys).length>0&&g[g.length-1])&&(A[0]===6||A[0]===2)){y=0;continue}if(A[0]===3&&(!g||A[1]>g[0]&&A[1]=h)throw new Error("pos must more then 0 and less then the list length");for(var y=d;v--&&y;)y=y.next;if(!y||y.value===void 0)throw new Error("unknown error");return y.value},this.eraseElementByPos=function(v){if(v<0||v>=h)throw new Error("erase pos must more then 0 and less then the list length");if(v===0)this.popFront();else if(v===h-1)this.popBack();else{for(var y=d;v--;){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 w=y.pre,p=y.next;p.pre=w,w.next=p,h>0&&--h}},this.eraseElementByValue=function(v){for(;d&&d.value===v;)this.popFront();for(;g&&g.value===v;)this.popBack();if(d)for(var y=d;y;){if(y.value===v){var w=y.pre,p=y.next;p&&(p.pre=w),w&&(w.next=p),h>0&&--h}y=y.next}},this.pushBack=function(v){if(v==null)throw new Error("you can't push null or undefined here");++h;var y=new a(v);g?(g.next=y,y.pre=g,g=y):d=g=y},this.popBack=function(){g&&(h>0&&--h,g&&(d===g?d=g=void 0:(g=g.pre)&&(g.next=void 0)))},this.setElementByPos=function(v,y){if(y==null)throw new Error("you can't set null or undefined here");if(v<0||v>=h)throw new Error("pos must more then 0 and less then the list length");for(var w=d;v--;){if(!w)throw new Error("unknown error");w=w.next}w&&(w.value=y)},this.insert=function(v,y,w){if(w===void 0&&(w=1),y==null)throw new Error("you can't insert null or undefined here");if(v<0||v>h)throw new Error("insert pos must more then 0 and less then or equal to the list length");if(w<0)throw new Error("insert size must more than 0");if(v===0)for(;w--;)this.pushFront(y);else if(v===h)for(;w--;)this.pushBack(y);else{for(var p=d,_=1;_0&&--h;v.next=y.next,v.next&&(v.next.pre=v),v=v.next}},this.sort=function(v){var y=[];this.forEach(function(p){y.push(p)}),y.sort(v);var w=d;y.forEach(function(p){w&&(w.value=p,w=w.next)})},this.pushFront=function(v){if(v==null)throw new Error("you can't push null or undefined here");++h;var y=new a(v);d?(y.next=d,d.pre=y,d=y):d=g=y},this.popFront=function(){d&&(h>0&&--h,d&&(d===g?d=g=void 0:(d=d.next)&&(d.pre=void 0)))},this.merge=function(v){var y=this,w=d;v.forEach(function(p){for(;w&&w.value!==void 0&&w.value<=p;)w=w.next;if(w===void 0)y.pushBack(p),w=g;else if(w===d)y.pushFront(p),w=d;else{++h;var _=w.pre;_&&(_.next=new a(p),_.next.pre=_,_.next.next=w,w&&(w.pre=_.next))}})},this[Symbol.iterator]=function(){return function(){var v;return s(this,function(y){switch(y.label){case 0:v=d,y.label=1;case 1:if(v===void 0)return[3,3];if(!v.value)throw new Error("unknown error");return[4,v.value];case 2:return y.sent(),v=v.next,[3,1];case 3:return[2]}})}()},c.forEach(function(v){return u.pushBack(v)}),Object.freeze(this)}Object.freeze(l),r.default=l},{}],30:[function(i,n,r){var s=this&&this.__generator||function(u,h){var d,g,v,y,w={label:0,sent:function(){if(1&v[0])throw v[1];return v[1]},trys:[],ops:[]};return y={next:p(0),throw:p(1),return:p(2)},typeof Symbol=="function"&&(y[Symbol.iterator]=function(){return this}),y;function p(_){return function(A){return function(x){if(d)throw new TypeError("Generator is already executing.");for(;w;)try{if(d=1,g&&(v=2&x[0]?g.return:x[0]?g.throw||((v=g.return)&&v.call(g),0):g.next)&&!(v=v.call(g,x[1])).done)return v;switch(g=0,v&&(x=[2&x[0],v.value]),x[0]){case 0:case 1:v=x;break;case 4:return w.label++,{value:x[1],done:!1};case 5:w.label++,g=x[1],x=[0];continue;case 7:x=w.ops.pop(),w.trys.pop();continue;default:if(!(v=(v=w.trys).length>0&&v[v.length-1])&&(x[0]===6||x[0]===2)){w=0;continue}if(x[0]===3&&(!v||x[1]>v[0]&&x[1]=u.length&&(u=void 0),{value:u&&u[g++],done:!u}}};throw new TypeError(h?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var l=i("../Base/TreeNode");function c(u,h){var d=this;u===void 0&&(u=[]),h=h||function(C,T){return CT?1:0};var g=0,v=new l.default;v.color=l.default.TreeNodeColorType.black,this.size=function(){return g},this.empty=function(){return g===0},this.clear=function(){g=0,v.key=v.value=void 0,v.leftChild=v.rightChild=v.brother=void 0};var y=function(C){if(!C||C.key===void 0)throw new Error("unknown error");return C.leftChild?y(C.leftChild):C},w=function(C){if(!C||C.key===void 0)throw new Error("unknown error");return C.rightChild?w(C.rightChild):C};this.front=function(){if(!this.empty()){var C=y(v);if(C.key===void 0||C.value===void 0)throw new Error("unknown error");return{key:C.key,value:C.value}}},this.back=function(){if(!this.empty()){var C=w(v);if(C.key===void 0||C.value===void 0)throw new Error("unknown error");return{key:C.key,value:C.value}}},this.forEach=function(C){var T,S,O=0;try{for(var K=a(this),Z=K.next();!Z.done;Z=K.next())C(Z.value,O++)}catch(st){T={error:st}}finally{try{Z&&!Z.done&&(S=K.return)&&S.call(K)}finally{if(T)throw T.error}}},this.getElementByPos=function(C){var T,S;if(C<0||C>=this.size())throw new Error("pos must more than 0 and less than set's size");var O=0;try{for(var K=a(this),Z=K.next();!Z.done;Z=K.next()){var st=Z.value;if(O===C)return st;++O}}catch($){T={error:$}}finally{try{Z&&!Z.done&&(S=K.return)&&S.call(K)}finally{if(T)throw T.error}}throw new Error("unknown Error")};var p=function(C,T){if(C&&C.key!==void 0&&C.value!==void 0){var S=h(C.key,T);return S===0?{key:C.key,value:C.value}:S<0?p(C.rightChild,T):p(C.leftChild,T)||{key:C.key,value:C.value}}};this.lowerBound=function(C){return p(v,C)};var _=function(C,T){if(C&&C.key!==void 0&&C.value!==void 0)return h(C.key,T)<=0?_(C.rightChild,T):_(C.leftChild,T)||{key:C.key,value:C.value}};this.upperBound=function(C){return _(v,C)};var A=function(C,T){if(C&&C.key!==void 0&&C.value!==void 0){var S=h(C.key,T);return S===0?{key:C.key,value:C.value}:S>0?A(C.leftChild,T):A(C.rightChild,T)||{key:C.key,value:C.value}}};this.reverseLowerBound=function(C){return A(v,C)};var x=function(C,T){if(C&&C.key!==void 0&&C.value!==void 0)return h(C.key,T)>=0?x(C.leftChild,T):x(C.rightChild,T)||{key:C.key,value:C.value}};this.reverseUpperBound=function(C){return x(v,C)};var E=function(C){var T=C.parent;if(!T){if(C===v)return;throw new Error("unknown error")}if(C.color!==l.default.TreeNodeColorType.red){var S=C.brother;if(!S)throw new Error("unknown error");if(C===T.leftChild)if(S.color===l.default.TreeNodeColorType.red){S.color=l.default.TreeNodeColorType.black,T.color=l.default.TreeNodeColorType.red;var O=T.rotateLeft();v===T&&(v=O),E(C)}else S.color===l.default.TreeNodeColorType.black&&(S.rightChild&&S.rightChild.color===l.default.TreeNodeColorType.red?(S.color=T.color,T.color=l.default.TreeNodeColorType.black,S.rightChild&&(S.rightChild.color=l.default.TreeNodeColorType.black),O=T.rotateLeft(),v===T&&(v=O),C.color=l.default.TreeNodeColorType.black):S.rightChild&&S.rightChild.color!==l.default.TreeNodeColorType.black||!S.leftChild||S.leftChild.color!==l.default.TreeNodeColorType.red?S.leftChild&&S.leftChild.color!==l.default.TreeNodeColorType.black||S.rightChild&&S.rightChild.color!==l.default.TreeNodeColorType.black||(S.color=l.default.TreeNodeColorType.red,E(T)):(S.color=l.default.TreeNodeColorType.red,S.leftChild&&(S.leftChild.color=l.default.TreeNodeColorType.black),O=S.rotateRight(),v===S&&(v=O),E(C)));else C===T.rightChild&&(S.color===l.default.TreeNodeColorType.red?(S.color=l.default.TreeNodeColorType.black,T.color=l.default.TreeNodeColorType.red,O=T.rotateRight(),v===T&&(v=O),E(C)):S.color===l.default.TreeNodeColorType.black&&(S.leftChild&&S.leftChild.color===l.default.TreeNodeColorType.red?(S.color=T.color,T.color=l.default.TreeNodeColorType.black,S.leftChild&&(S.leftChild.color=l.default.TreeNodeColorType.black),O=T.rotateRight(),v===T&&(v=O),C.color=l.default.TreeNodeColorType.black):S.leftChild&&S.leftChild.color!==l.default.TreeNodeColorType.black||!S.rightChild||S.rightChild.color!==l.default.TreeNodeColorType.red?S.leftChild&&S.leftChild.color!==l.default.TreeNodeColorType.black||S.rightChild&&S.rightChild.color!==l.default.TreeNodeColorType.black||(S.color=l.default.TreeNodeColorType.red,E(T)):(S.color=l.default.TreeNodeColorType.red,S.rightChild&&(S.rightChild.color=l.default.TreeNodeColorType.black),O=S.rotateLeft(),v===S&&(v=O),E(C))))}else C.color=l.default.TreeNodeColorType.black},I=function(C){for(var T=C;T.leftChild||T.rightChild;){if(T.rightChild){T=y(T.rightChild);var S=C.key;C.key=T.key,T.key=S;var O=C.value;C.value=T.value,T.value=O,C=T}T.leftChild&&(T=w(T.leftChild),S=C.key,C.key=T.key,T.key=S,O=C.value,C.value=T.value,T.value=O,C=T)}E(T),T&&T.remove(),--g,v.color=l.default.TreeNodeColorType.black},M=function(C,T){return!(!C||C.key===void 0)&&(!!M(C.leftChild,T)||!!T(C)||M(C.rightChild,T))};this.eraseElementByPos=function(C){if(C<0||C>=g)throw new Error("pos must more than 0 and less than set's size");var T=0;M(v,function(S){return C===T?(I(S),!0):(++T,!1)})},this.eraseElementByKey=function(C){if(!this.empty()){var T=q(v,C);T!==void 0&&T.key!==void 0&&h(T.key,C)===0&&I(T)}};var B=function(C,T){if(!C||C.key===void 0)throw new Error("unknown error");var S=h(T,C.key);return S<0?C.leftChild?B(C.leftChild,T):(C.leftChild=new l.default,C.leftChild.parent=C,C.leftChild.brother=C.rightChild,C.rightChild&&(C.rightChild.brother=C.leftChild),C.leftChild):S>0?C.rightChild?B(C.rightChild,T):(C.rightChild=new l.default,C.rightChild.parent=C,C.rightChild.brother=C.leftChild,C.leftChild&&(C.leftChild.brother=C.rightChild),C.rightChild):C},D=function(C){var T=C.parent;if(!T){if(C===v)return;throw new Error("unknown error")}if(T.color!==l.default.TreeNodeColorType.black&&T.color===l.default.TreeNodeColorType.red){var S=T.brother,O=T.parent;if(!O)throw new Error("unknown error");if(S&&S.color===l.default.TreeNodeColorType.red)S.color=T.color=l.default.TreeNodeColorType.black,O.color=l.default.TreeNodeColorType.red,D(O);else if(!S||S.color===l.default.TreeNodeColorType.black)if(T===O.leftChild)if(C===T.leftChild){T.color=l.default.TreeNodeColorType.black,O.color=l.default.TreeNodeColorType.red;var K=O.rotateRight();O===v&&(v=K)}else C===T.rightChild&&(K=T.rotateLeft(),O===v&&(v=K),D(T));else T===O.rightChild&&(C===T.leftChild?(K=T.rotateRight(),O===v&&(v=K),D(T)):C===T.rightChild&&(T.color=l.default.TreeNodeColorType.black,O.color=l.default.TreeNodeColorType.red,K=O.rotateLeft(),O===v&&(v=K)))}};this.setElement=function(C,T){if(C==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(T!=null){if(this.empty())return++g,v.key=C,v.value=T,void(v.color=l.default.TreeNodeColorType.black);var S=B(v,C);S.key===void 0||h(S.key,C)!==0?(++g,S.key=C,S.value=T,D(S),v.color=l.default.TreeNodeColorType.black):S.value=T}else this.eraseElementByKey(C)};var q=function(C,T){if(C&&C.key!==void 0){var S=h(T,C.key);return S<0?q(C.leftChild,T):S>0?q(C.rightChild,T):C}};this.find=function(C){return!!q(v,C)},this.getElementByKey=function(C){var T=q(v,C);if((T==null?void 0:T.key)===void 0||(T==null?void 0:T.value)===void 0)throw new Error("unknown error");return T.value},this.union=function(C){var T=this;C.forEach(function(S){var O=S.key,K=S.value;return T.setElement(O,K)})},this.getHeight=function(){if(this.empty())return 0;var C=function(T){return T?Math.max(C(T.leftChild),C(T.rightChild))+1:1};return C(v)};var Q=function(C){return s(this,function(T){switch(T.label){case 0:return C&&C.key!==void 0&&C.value!==void 0?[5,a(Q(C.leftChild))]:[2];case 1:return T.sent(),[4,{key:C.key,value:C.value}];case 2:return T.sent(),[5,a(Q(C.rightChild))];case 3:return T.sent(),[2]}})};this[Symbol.iterator]=function(){return Q(v)},u.forEach(function(C){var T=C.key,S=C.value;return d.setElement(T,S)}),Object.freeze(this)}Object.freeze(c),r.default=c},{"../Base/TreeNode":25}],31:[function(i,n,r){function s(a,l){a===void 0&&(a=[]),l=l||function(g,v){return g>v?-1:g=u)throw new Error("unknown error");if(v<0||v>=u)throw new Error("unknown error");var y=c[g];c[g]=c[v],c[v]=y},d=function(g){if(g<0||g>=u)throw new Error("unknown error");var v=2*g+1,y=2*g+2;v0&&h(g,v),y0&&h(g,y)};(function(){for(var g=Math.floor((u-1)/2);g>=0;--g)for(var v=g,y=2*v+1;y0&&(p=w),l(c[v],c[p])<=0)break;h(v,p),y=2*(v=p)+1}})(),this.size=function(){return u},this.empty=function(){return u===0},this.clear=function(){u=0,c.length=0},this.push=function(g){if(c.push(g),++u!==1)for(var v=u-1;v>0;){var y=Math.floor((v-1)/2);if(l(c[y],g)<=0)break;d(y),v=y}},this.pop=function(){if(!this.empty())if(this.size()!==1){var g=c[u-1];--u;for(var v=0;v=this.size())break;var p=y;if(w0&&(p=w),l(c[p],g)>=0)break;c[v]=c[p],v=p}c[v]=g}else--u},this.top=function(){return c[0]},Object.freeze(this)}Object.defineProperty(r,"__esModule",{value:!0}),Object.freeze(s),r.default=s},{}],32:[function(i,n,r){Object.defineProperty(r,"__esModule",{value:!0});var s=i("../LinkList/LinkList");function a(l){l===void 0&&(l=[]);var c=new s.default(l);this.size=function(){return c.size()},this.empty=function(){return c.empty()},this.clear=function(){c.clear()},this.push=function(u){c.pushBack(u)},this.pop=function(){c.popFront()},this.front=function(){return c.front()},Object.freeze(this)}Object.freeze(a),r.default=a},{"../LinkList/LinkList":29}],33:[function(i,n,r){var s=this&&this.__generator||function(u,h){var d,g,v,y,w={label:0,sent:function(){if(1&v[0])throw v[1];return v[1]},trys:[],ops:[]};return y={next:p(0),throw:p(1),return:p(2)},typeof Symbol=="function"&&(y[Symbol.iterator]=function(){return this}),y;function p(_){return function(A){return function(x){if(d)throw new TypeError("Generator is already executing.");for(;w;)try{if(d=1,g&&(v=2&x[0]?g.return:x[0]?g.throw||((v=g.return)&&v.call(g),0):g.next)&&!(v=v.call(g,x[1])).done)return v;switch(g=0,v&&(x=[2&x[0],v.value]),x[0]){case 0:case 1:v=x;break;case 4:return w.label++,{value:x[1],done:!1};case 5:w.label++,g=x[1],x=[0];continue;case 7:x=w.ops.pop(),w.trys.pop();continue;default:if(!(v=(v=w.trys).length>0&&v[v.length-1])&&(x[0]===6||x[0]===2)){w=0;continue}if(x[0]===3&&(!v||x[1]>v[0]&&x[1]=u.length&&(u=void 0),{value:u&&u[g++],done:!u}}};throw new TypeError(h?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(r,"__esModule",{value:!0});var l=i("../Base/TreeNode");function c(u,h){var d=this;u===void 0&&(u=[]),h=h||function(C,T){return CT?1:0};var g=0,v=new l.default;v.color=l.default.TreeNodeColorType.black,this.size=function(){return g},this.empty=function(){return g===0},this.clear=function(){g=0,v.key=void 0,v.leftChild=v.rightChild=v.brother=v.parent=void 0,v.color=l.default.TreeNodeColorType.black};var y=function(C){if(!C||C.key===void 0)throw new Error("unknown error");return C.leftChild?y(C.leftChild):C},w=function(C){if(!C||C.key===void 0)throw new Error("unknown error");return C.rightChild?w(C.rightChild):C};this.front=function(){if(!this.empty())return y(v).key},this.back=function(){if(!this.empty())return w(v).key},this.forEach=function(C){var T,S,O=0;try{for(var K=a(this),Z=K.next();!Z.done;Z=K.next())C(Z.value,O++)}catch(st){T={error:st}}finally{try{Z&&!Z.done&&(S=K.return)&&S.call(K)}finally{if(T)throw T.error}}},this.getElementByPos=function(C){var T,S;if(C<0||C>=this.size())throw new Error("pos must more than 0 and less than set's size");var O=0;try{for(var K=a(this),Z=K.next();!Z.done;Z=K.next()){var st=Z.value;if(O===C)return st;++O}}catch($){T={error:$}}finally{try{Z&&!Z.done&&(S=K.return)&&S.call(K)}finally{if(T)throw T.error}}throw new Error("unknown error")};var p=function(C){var T=C.parent;if(!T){if(C===v)return;throw new Error("unknown error")}if(C.color!==l.default.TreeNodeColorType.red){var S=C.brother;if(!S)throw new Error("unknown error");if(C===T.leftChild)if(S.color===l.default.TreeNodeColorType.red){S.color=l.default.TreeNodeColorType.black,T.color=l.default.TreeNodeColorType.red;var O=T.rotateLeft();v===T&&(v=O),p(C)}else S.color===l.default.TreeNodeColorType.black&&(S.rightChild&&S.rightChild.color===l.default.TreeNodeColorType.red?(S.color=T.color,T.color=l.default.TreeNodeColorType.black,S.rightChild&&(S.rightChild.color=l.default.TreeNodeColorType.black),O=T.rotateLeft(),v===T&&(v=O),C.color=l.default.TreeNodeColorType.black):S.rightChild&&S.rightChild.color!==l.default.TreeNodeColorType.black||!S.leftChild||S.leftChild.color!==l.default.TreeNodeColorType.red?S.leftChild&&S.leftChild.color!==l.default.TreeNodeColorType.black||S.rightChild&&S.rightChild.color!==l.default.TreeNodeColorType.black||(S.color=l.default.TreeNodeColorType.red,p(T)):(S.color=l.default.TreeNodeColorType.red,S.leftChild&&(S.leftChild.color=l.default.TreeNodeColorType.black),O=S.rotateRight(),v===S&&(v=O),p(C)));else C===T.rightChild&&(S.color===l.default.TreeNodeColorType.red?(S.color=l.default.TreeNodeColorType.black,T.color=l.default.TreeNodeColorType.red,O=T.rotateRight(),v===T&&(v=O),p(C)):S.color===l.default.TreeNodeColorType.black&&(S.leftChild&&S.leftChild.color===l.default.TreeNodeColorType.red?(S.color=T.color,T.color=l.default.TreeNodeColorType.black,S.leftChild&&(S.leftChild.color=l.default.TreeNodeColorType.black),O=T.rotateRight(),v===T&&(v=O),C.color=l.default.TreeNodeColorType.black):S.leftChild&&S.leftChild.color!==l.default.TreeNodeColorType.black||!S.rightChild||S.rightChild.color!==l.default.TreeNodeColorType.red?S.leftChild&&S.leftChild.color!==l.default.TreeNodeColorType.black||S.rightChild&&S.rightChild.color!==l.default.TreeNodeColorType.black||(S.color=l.default.TreeNodeColorType.red,p(T)):(S.color=l.default.TreeNodeColorType.red,S.rightChild&&(S.rightChild.color=l.default.TreeNodeColorType.black),O=S.rotateLeft(),v===S&&(v=O),p(C))))}else C.color=l.default.TreeNodeColorType.black},_=function(C){for(var T=C;T.leftChild||T.rightChild;){if(T.rightChild){T=y(T.rightChild);var S=C.key;C.key=T.key,T.key=S,C=T}T.leftChild&&(T=w(T.leftChild),S=C.key,C.key=T.key,T.key=S,C=T)}p(T),T&&T.remove(),--g,v.color=l.default.TreeNodeColorType.black},A=function(C,T){return!(!C||C.key===void 0)&&(!!A(C.leftChild,T)||!!T(C)||A(C.rightChild,T))};this.eraseElementByPos=function(C){if(C<0||C>=g)throw new Error("pos must more than 0 and less than set's size");var T=0;A(v,function(S){return C===T?(_(S),!0):(++T,!1)})},this.eraseElementByValue=function(C){if(!this.empty()){var T=I(v,C);T!==void 0&&T.key!==void 0&&h(T.key,C)===0&&_(T)}};var x=function(C,T){if(!C||C.key===void 0)throw new Error("unknown error");var S=h(T,C.key);return S<0?C.leftChild?x(C.leftChild,T):(C.leftChild=new l.default,C.leftChild.parent=C,C.leftChild.brother=C.rightChild,C.rightChild&&(C.rightChild.brother=C.leftChild),C.leftChild):S>0?C.rightChild?x(C.rightChild,T):(C.rightChild=new l.default,C.rightChild.parent=C,C.rightChild.brother=C.leftChild,C.leftChild&&(C.leftChild.brother=C.rightChild),C.rightChild):C},E=function(C){var T=C.parent;if(!T){if(C===v)return;throw new Error("unknown error")}if(T.color!==l.default.TreeNodeColorType.black&&T.color===l.default.TreeNodeColorType.red){var S=T.brother,O=T.parent;if(!O)throw new Error("unknown error");if(S&&S.color===l.default.TreeNodeColorType.red)S.color=T.color=l.default.TreeNodeColorType.black,O.color=l.default.TreeNodeColorType.red,E(O);else if(!S||S.color===l.default.TreeNodeColorType.black)if(T===O.leftChild)if(C===T.leftChild){T.color=l.default.TreeNodeColorType.black,O.color=l.default.TreeNodeColorType.red;var K=O.rotateRight();O===v&&(v=K)}else C===T.rightChild&&(K=T.rotateLeft(),O===v&&(v=K),E(T));else T===O.rightChild&&(C===T.leftChild?(K=T.rotateRight(),O===v&&(v=K),E(T)):C===T.rightChild&&(T.color=l.default.TreeNodeColorType.black,O.color=l.default.TreeNodeColorType.red,K=O.rotateLeft(),O===v&&(v=K)))}};this.insert=function(C){if(C==null)throw new Error("to avoid some unnecessary errors, we don't suggest you insert null or undefined here");if(this.empty())return++g,v.key=C,void(v.color=l.default.TreeNodeColorType.black);var T=x(v,C);T.key!==void 0&&h(T.key,C)===0||(++g,T.key=C,E(T),v.color=l.default.TreeNodeColorType.black)};var I=function(C,T){if(C&&C.key!==void 0){var S=h(T,C.key);return S<0?I(C.leftChild,T):S>0?I(C.rightChild,T):C}};this.find=function(C){var T=I(v,C);return T!==void 0&&T.key!==void 0&&h(T.key,C)===0};var M=function(C,T){if(C&&C.key!==void 0){var S=h(C.key,T);if(S===0)return C.key;if(S<0)return M(C.rightChild,T);var O=M(C.leftChild,T);return O!==void 0?O:C.key}};this.lowerBound=function(C){return M(v,C)};var B=function(C,T){if(C&&C.key!==void 0){if(h(C.key,T)<=0)return B(C.rightChild,T);var S=B(C.leftChild,T);return S!==void 0?S:C.key}};this.upperBound=function(C){return B(v,C)};var D=function(C,T){if(C&&C.key!==void 0){var S=h(C.key,T);if(S===0)return C.key;if(S>0)return D(C.leftChild,T);var O=D(C.rightChild,T);return O!==void 0?O:C.key}};this.reverseLowerBound=function(C){return D(v,C)};var q=function(C,T){if(C&&C.key!==void 0){if(h(C.key,T)>=0)return q(C.leftChild,T);var S=q(C.rightChild,T);return S!==void 0?S:C.key}};this.reverseUpperBound=function(C){return q(v,C)},this.union=function(C){var T=this;C.forEach(function(S){return T.insert(S)})},this.getHeight=function(){if(this.empty())return 0;var C=function(T){return T?Math.max(C(T.leftChild),C(T.rightChild))+1:1};return C(v)};var Q=function(C){return s(this,function(T){switch(T.label){case 0:return C&&C.key!==void 0?[5,a(Q(C.leftChild))]:[2];case 1:return T.sent(),[4,C.key];case 2:return T.sent(),[5,a(Q(C.rightChild))];case 3:return T.sent(),[2]}})};this[Symbol.iterator]=function(){return Q(v)},u.forEach(function(C){return d.insert(C)}),Object.freeze(this)}Object.freeze(c),r.default=c},{"../Base/TreeNode":25}],34:[function(i,n,r){function s(a){var l=this;a===void 0&&(a=[]);var c=0,u=[];this.size=function(){return c},this.empty=function(){return c===0},this.clear=function(){c=0,u.length=0},this.push=function(h){u.push(h),++c},this.pop=function(){u.pop(),c>0&&--c},this.top=function(){return u[c-1]},a.forEach(function(h){return l.push(h)}),Object.freeze(this)}Object.defineProperty(r,"__esModule",{value:!0}),Object.freeze(s),r.default=s},{}],35:[function(i,n,r){var s=this&&this.__generator||function(h,d){var g,v,y,w,p={label:0,sent:function(){if(1&y[0])throw y[1];return y[1]},trys:[],ops:[]};return w={next:_(0),throw:_(1),return:_(2)},typeof Symbol=="function"&&(w[Symbol.iterator]=function(){return this}),w;function _(A){return function(x){return function(E){if(g)throw new TypeError("Generator is already executing.");for(;p;)try{if(g=1,v&&(y=2&E[0]?v.return:E[0]?v.throw||((y=v.return)&&y.call(v),0):v.next)&&!(y=y.call(v,E[1])).done)return y;switch(v=0,y&&(E=[2&E[0],y.value]),E[0]){case 0:case 1:y=E;break;case 4:return p.label++,{value:E[1],done:!1};case 5:p.label++,v=E[1],E=[0];continue;case 7:E=p.ops.pop(),p.trys.pop();continue;default:if(!(y=(y=p.trys).length>0&&y[y.length-1])&&(E[0]===6||E[0]===2)){p=0;continue}if(E[0]===3&&(!y||E[1]>y[0]&&E[1]0)&&!(v=w.next()).done;)p.push(v.value)}catch(_){y={error:_}}finally{try{v&&!v.done&&(g=w.return)&&g.call(w)}finally{if(y)throw y.error}}return p},l=this&&this.__spreadArray||function(h,d,g){if(g||arguments.length===2)for(var v,y=0,w=d.length;y=h.length&&(h=void 0),{value:h&&h[v++],done:!h}}};throw new TypeError(d?"Object is not iterable.":"Symbol.iterator is not defined.")};function u(h){var d=this;h===void 0&&(h=[]);var g=0,v=[];this.size=function(){return g},this.empty=function(){return g===0},this.clear=function(){g=0,v.length=0},this.front=function(){if(!this.empty())return v[0]},this.back=function(){if(!this.empty())return v[g-1]},this.forEach=function(y){v.forEach(y)},this.getElementByPos=function(y){if(y<0||y>=g)throw new Error("pos must more than 0 and less than vector's size");return v[y]},this.eraseElementByPos=function(y){if(y<0||y>=g)throw new Error("pos must more than 0 and less than vector's size");for(var w=y;wp;)this.popBack()},this.pushBack=function(y){v.push(y),++g},this.popBack=function(){v.pop(),g>0&&--g},this.setElementByPos=function(y,w){if(y<0||y>=g)throw new Error("pos must more than 0 and less than vector's size");v[y]=w},this.insert=function(y,w,p){if(p===void 0&&(p=1),y<0||y>g)throw new Error("pos must more than 0 and less than or equal to vector's size");v.splice.apply(v,l([y,0],a(new Array(p).fill(w)),!1)),g+=p},this.find=function(y){return v.includes(y)},this.reverse=function(){v.reverse()},this.unique=function(){var y,w=[];this.forEach(function(_,A){A!==0&&_===y||(w.push(_),y=_)}),w.forEach(function(_,A){v[A]=_});for(var p=w.length;g>p;)this.popBack()},this.sort=function(y){v.sort(y)},this[Symbol.iterator]=function(){return function(){return s(this,function(y){switch(y.label){case 0:return[5,c(v)];case 1:return[2,y.sent()]}})}()},h.forEach(function(y){return d.pushBack(y)}),Object.freeze(this)}Object.defineProperty(r,"__esModule",{value:!0}),Object.freeze(u),r.default=u},{}],36:[function(i,n,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 s=i("./Vector/Vector");r.Vector=s.default;var a=i("./Stack/Stack");r.Stack=a.default;var l=i("./Queue/Queue");r.Queue=l.default;var c=i("./LinkList/LinkList");r.LinkList=c.default;var u=i("./Deque/Deque");r.Deque=u.default;var h=i("./PriorityQueue/PriorityQueue");r.PriorityQueue=h.default;var d=i("./Set/Set");r.Set=d.default;var g=i("./Map/Map");r.Map=g.default;var v=i("./HashSet/HashSet");r.HashSet=v.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,n,r){const s=i("yallist"),a=Symbol("max"),l=Symbol("length"),c=Symbol("lengthCalculator"),u=Symbol("allowStale"),h=Symbol("maxAge"),d=Symbol("dispose"),g=Symbol("noDisposeOnSet"),v=Symbol("lruList"),y=Symbol("cache"),w=Symbol("updateAgeOnGet"),p=()=>1,_=(B,D,q)=>{const Q=B[y].get(D);if(Q){const C=Q.value;if(A(B,C)){if(E(B,Q),!B[u])return}else q&&(B[w]&&(Q.value.now=Date.now()),B[v].unshiftNode(Q));return C.value}},A=(B,D)=>{if(!D||!D.maxAge&&!B[h])return!1;const q=Date.now()-D.now;return D.maxAge?q>D.maxAge:B[h]&&q>B[h]},x=B=>{if(B[l]>B[a])for(let D=B[v].tail;B[l]>B[a]&&D!==null;){const q=D.prev;E(B,D),D=q}},E=(B,D)=>{if(D){const q=D.value;B[d]&&B[d](q.key,q.value),B[l]-=q.length,B[y].delete(q.key),B[v].removeNode(D)}};class I{constructor(D,q,Q,C,T){this.key=D,this.value=q,this.length=Q,this.now=C,this.maxAge=T||0}}const M=(B,D,q,Q)=>{let C=q.value;A(B,C)&&(E(B,q),B[u]||(C=void 0)),C&&D.call(Q,C.value,C.key,B)};n.exports=class{constructor(B){if(typeof B=="number"&&(B={max:B}),B||(B={}),B.max&&(typeof B.max!="number"||B.max<0))throw new TypeError("max must be a non-negative number");this[a]=B.max||1/0;const D=B.length||p;if(this[c]=typeof D!="function"?p:D,this[u]=B.stale||!1,B.maxAge&&typeof B.maxAge!="number")throw new TypeError("maxAge must be a number");this[h]=B.maxAge||0,this[d]=B.dispose,this[g]=B.noDisposeOnSet||!1,this[w]=B.updateAgeOnGet||!1,this.reset()}set max(B){if(typeof B!="number"||B<0)throw new TypeError("max must be a non-negative number");this[a]=B||1/0,x(this)}get max(){return this[a]}set allowStale(B){this[u]=!!B}get allowStale(){return this[u]}set maxAge(B){if(typeof B!="number")throw new TypeError("maxAge must be a non-negative number");this[h]=B,x(this)}get maxAge(){return this[h]}set lengthCalculator(B){typeof B!="function"&&(B=p),B!==this[c]&&(this[c]=B,this[l]=0,this[v].forEach(D=>{D.length=this[c](D.value,D.key),this[l]+=D.length})),x(this)}get lengthCalculator(){return this[c]}get length(){return this[l]}get itemCount(){return this[v].length}rforEach(B,D){D=D||this;for(let q=this[v].tail;q!==null;){const Q=q.prev;M(this,B,q,D),q=Q}}forEach(B,D){D=D||this;for(let q=this[v].head;q!==null;){const Q=q.next;M(this,B,q,D),q=Q}}keys(){return this[v].toArray().map(B=>B.key)}values(){return this[v].toArray().map(B=>B.value)}reset(){this[d]&&this[v]&&this[v].length&&this[v].forEach(B=>this[d](B.key,B.value)),this[y]=new Map,this[v]=new s,this[l]=0}dump(){return this[v].map(B=>!A(this,B)&&{k:B.key,v:B.value,e:B.now+(B.maxAge||0)}).toArray().filter(B=>B)}dumpLru(){return this[v]}set(B,D,q){if((q=q||this[h])&&typeof q!="number")throw new TypeError("maxAge must be a number");const Q=q?Date.now():0,C=this[c](D,B);if(this[y].has(B)){if(C>this[a])return E(this,this[y].get(B)),!1;const S=this[y].get(B).value;return this[d]&&(this[g]||this[d](B,S.value)),S.now=Q,S.maxAge=q,S.value=D,this[l]+=C-S.length,S.length=C,this.get(B),x(this),!0}const T=new I(B,D,C,Q,q);return T.length>this[a]?(this[d]&&this[d](B,D),!1):(this[l]+=T.length,this[v].unshift(T),this[y].set(B,this[v].head),x(this),!0)}has(B){if(!this[y].has(B))return!1;const D=this[y].get(B).value;return!A(this,D)}get(B){return _(this,B,!0)}peek(B){return _(this,B,!1)}pop(){const B=this[v].tail;return B?(E(this,B),B.value):null}del(B){E(this,this[y].get(B))}load(B){this.reset();const D=Date.now();for(let q=B.length-1;q>=0;q--){const Q=B[q],C=Q.e||0;if(C===0)this.set(Q.k,Q.v);else{const T=C-D;T>0&&this.set(Q.k,Q.v,T)}}}prune(){this[y].forEach((B,D)=>_(this,D,!1))}}},{yallist:83}],38:[function(i,n,r){(function(s){(function(){const a=n.exports;a.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"},a.codes={};for(const c in a.types){const u=a.types[c];a.codes[u]=c}a.CMD_SHIFT=4,a.CMD_MASK=240,a.DUP_MASK=8,a.QOS_MASK=3,a.QOS_SHIFT=1,a.RETAIN_MASK=1,a.VARBYTEINT_MASK=127,a.VARBYTEINT_FIN_MASK=128,a.VARBYTEINT_MAX=268435455,a.SESSIONPRESENT_MASK=1,a.SESSIONPRESENT_HEADER=s.from([a.SESSIONPRESENT_MASK]),a.CONNACK_HEADER=s.from([a.codes.connack<[0,1].map(h=>[0,1].map(d=>{const g=s.alloc(1);return g.writeUInt8(a.codes[c]<s.from([c])),a.EMPTY={pingreq:s.from([a.codes.pingreq<<4,0]),pingresp:s.from([a.codes.pingresp<<4,0]),disconnect:s.from([a.codes.disconnect<<4,0])}}).call(this)}).call(this,i("buffer").Buffer)},{buffer:17}],39:[function(i,n,r){(function(s){(function(){const a=i("./writeToStream"),l=i("events");class c extends l{constructor(){super(),this._array=new Array(20),this._i=0}write(h){return this._array[this._i++]=h,!0}concat(){let h=0;const d=new Array(this._array.length),g=this._array;let v,y=0;for(v=0;v>8,0),d.writeUInt8(255&h,1),d}n.exports={cache:l,generateCache:function(){for(let h=0;h<65536;h++)l[h]=u(h)},generateNumber:u,genBufVariableByteInt:function(h){let d=0,g=0;const v=s.allocUnsafe(4);do d=h%128|0,(h=h/128|0)>0&&(d|=128),v.writeUInt8(d,g++);while(h>0&&g<4);return h>0&&(g=0),c?v.subarray(0,g):v.slice(0,g)},generate4ByteBuffer:function(h){const d=s.allocUnsafe(4);return d.writeUInt32BE(h,0),d}}}).call(this)}).call(this,i("buffer").Buffer)},{buffer:17}],42:[function(i,n,r){n.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,n,r){const s=i("bl"),a=i("events"),l=i("./packet"),c=i("./constants"),u=i("debug")("mqtt-packet:parser");class h extends a{constructor(){super(),this.parser=this.constructor.parser}static parser(g){return this instanceof h?(this.settings=g||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):new h().parser(g)}_resetState(){u("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new l,this.error=null,this._list=s(),this._stateCounter=0}parse(g){for(this.error&&this._resetState(),this._list.append(g),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 g=this._list.readUInt8(0);return this.packet.cmd=c.types[g>>c.CMD_SHIFT],this.packet.retain=(g&c.RETAIN_MASK)!=0,this.packet.qos=g>>c.QOS_SHIFT&c.QOS_MASK,this.packet.dup=(g&c.DUP_MASK)!=0,u("_parseHeader: packet: %o",this.packet),this._list.consume(1),!0}_parseLength(){const g=this._parseVarByteNum(!0);return g&&(this.packet.length=g.value,this._list.consume(g.bytes)),u("_parseLength %d",g.value),!!g}_parsePayload(){u("_parsePayload: payload %O",this._list);let g=!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"))}g=!0}return u("_parsePayload complete result: %s",g),g}_parseConnect(){let g,v,y,w;u("_parseConnect");const p={},_=this.packet,A=this._parseString();if(A===null)return this._emitError(new Error("Cannot parse protocolId"));if(A!=="MQTT"&&A!=="MQIsdp")return this._emitError(new Error("Invalid protocolId"));if(_.protocolId=A,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(_.protocolVersion=this._list.readUInt8(this._pos),_.protocolVersion>=128&&(_.bridgeMode=!0,_.protocolVersion=_.protocolVersion-128),_.protocolVersion!==3&&_.protocolVersion!==4&&_.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(p.username=this._list.readUInt8(this._pos)&c.USERNAME_MASK,p.password=this._list.readUInt8(this._pos)&c.PASSWORD_MASK,p.will=this._list.readUInt8(this._pos)&c.WILL_FLAG_MASK,p.will&&(_.will={},_.will.retain=(this._list.readUInt8(this._pos)&c.WILL_RETAIN_MASK)!=0,_.will.qos=(this._list.readUInt8(this._pos)&c.WILL_QOS_MASK)>>c.WILL_QOS_SHIFT),_.clean=(this._list.readUInt8(this._pos)&c.CLEAN_SESSION_MASK)!=0,this._pos++,_.keepalive=this._parseNum(),_.keepalive===-1)return this._emitError(new Error("Packet too short"));if(_.protocolVersion===5){const E=this._parseProperties();Object.getOwnPropertyNames(E).length&&(_.properties=E)}const x=this._parseString();if(x===null)return this._emitError(new Error("Packet too short"));if(_.clientId=x,u("_parseConnect: packet.clientId: %s",_.clientId),p.will){if(_.protocolVersion===5){const E=this._parseProperties();Object.getOwnPropertyNames(E).length&&(_.will.properties=E)}if((g=this._parseString())===null)return this._emitError(new Error("Cannot parse will topic"));if(_.will.topic=g,u("_parseConnect: packet.will.topic: %s",_.will.topic),(v=this._parseBuffer())===null)return this._emitError(new Error("Cannot parse will payload"));_.will.payload=v,u("_parseConnect: packet.will.paylaod: %s",_.will.payload)}if(p.username){if((w=this._parseString())===null)return this._emitError(new Error("Cannot parse username"));_.username=w,u("_parseConnect: packet.username: %s",_.username)}if(p.password){if((y=this._parseBuffer())===null)return this._emitError(new Error("Cannot parse password"));_.password=y}return this.settings=_,u("_parseConnect: complete"),_}_parseConnack(){u("_parseConnack");const g=this.packet;if(this._list.length<1)return null;if(g.sessionPresent=!!(this._list.readUInt8(this._pos++)&c.SESSIONPRESENT_MASK),this.settings.protocolVersion===5)this._list.length>=2?g.reasonCode=this._list.readUInt8(this._pos++):g.reasonCode=0;else{if(this._list.length<2)return null;g.returnCode=this._list.readUInt8(this._pos++)}if(g.returnCode===-1||g.reasonCode===-1)return this._emitError(new Error("Cannot parse return code"));if(this.settings.protocolVersion===5){const v=this._parseProperties();Object.getOwnPropertyNames(v).length&&(g.properties=v)}u("_parseConnack: complete")}_parsePublish(){u("_parsePublish");const g=this.packet;if(g.topic=this._parseString(),g.topic===null)return this._emitError(new Error("Cannot parse topic"));if(!(g.qos>0)||this._parseMessageId()){if(this.settings.protocolVersion===5){const v=this._parseProperties();Object.getOwnPropertyNames(v).length&&(g.properties=v)}g.payload=this._list.slice(this._pos,g.length),u("_parsePublish: payload from buffer list: %o",g.payload)}}_parseSubscribe(){u("_parseSubscribe");const g=this.packet;let v,y,w,p,_,A,x;if(g.qos!==1)return this._emitError(new Error("Wrong subscribe header"));if(g.subscriptions=[],this._parseMessageId()){if(this.settings.protocolVersion===5){const E=this._parseProperties();Object.getOwnPropertyNames(E).length&&(g.properties=E)}for(;this._pos=g.length)return this._emitError(new Error("Malformed Subscribe Payload"));w=(y=this._parseByte())&c.SUBSCRIBE_OPTIONS_QOS_MASK,A=(y>>c.SUBSCRIBE_OPTIONS_NL_SHIFT&c.SUBSCRIBE_OPTIONS_NL_MASK)!=0,_=(y>>c.SUBSCRIBE_OPTIONS_RAP_SHIFT&c.SUBSCRIBE_OPTIONS_RAP_MASK)!=0,p=y>>c.SUBSCRIBE_OPTIONS_RH_SHIFT&c.SUBSCRIBE_OPTIONS_RH_MASK,x={topic:v,qos:w},this.settings.protocolVersion===5?(x.nl=A,x.rap=_,x.rh=p):this.settings.bridgeMode&&(x.rh=0,x.rap=!0,x.nl=!0),u("_parseSubscribe: push subscription `%s` to subscription",x),g.subscriptions.push(x)}}}_parseSuback(){u("_parseSuback");const g=this.packet;if(this.packet.granted=[],this._parseMessageId()){if(this.settings.protocolVersion===5){const v=this._parseProperties();Object.getOwnPropertyNames(v).length&&(g.properties=v)}for(;this._pos2?(g.reasonCode=this._parseByte(),u("_parseConfirmation: packet.reasonCode `%d`",g.reasonCode)):g.reasonCode=0,g.length>3)){const v=this._parseProperties();Object.getOwnPropertyNames(v).length&&(g.properties=v)}return!0}_parseDisconnect(){const g=this.packet;if(u("_parseDisconnect"),this.settings.protocolVersion===5){this._list.length>0?g.reasonCode=this._parseByte():g.reasonCode=0;const v=this._parseProperties();Object.getOwnPropertyNames(v).length&&(g.properties=v)}return u("_parseDisconnect result: true"),!0}_parseAuth(){u("_parseAuth");const g=this.packet;if(this.settings.protocolVersion!==5)return this._emitError(new Error("Not supported auth packet for this version MQTT"));g.reasonCode=this._parseByte();const v=this._parseProperties();return Object.getOwnPropertyNames(v).length&&(g.properties=v),u("_parseAuth: result: true"),!0}_parseMessageId(){const g=this.packet;return g.messageId=this._parseNum(),g.messageId===null?(this._emitError(new Error("Cannot parse messageId")),!1):(u("_parseMessageId: packet.messageId %d",g.messageId),!0)}_parseString(g){const v=this._parseNum(),y=v+this._pos;if(v===-1||y>this._list.length||y>this.packet.length)return null;const w=this._list.toString("utf8",this._pos,y);return this._pos+=v,u("_parseString: result: %s",w),w}_parseStringPair(){return u("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){const g=this._parseNum(),v=g+this._pos;if(g===-1||v>this._list.length||v>this.packet.length)return null;const y=this._list.slice(this._pos,v);return this._pos+=g,u("_parseBuffer: result: %o",y),y}_parseNum(){if(this._list.length-this._pos<2)return-1;const g=this._list.readUInt16BE(this._pos);return this._pos+=2,u("_parseNum: result: %s",g),g}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;const g=this._list.readUInt32BE(this._pos);return this._pos+=4,u("_parse4ByteNum: result: %s",g),g}_parseVarByteNum(g){u("_parseVarByteNum");let v,y=0,w=1,p=0,_=!1;const A=this._pos?this._pos:0;for(;y<4&&A+y=y&&this._emitError(new Error("Invalid variable byte integer")),A&&(this._pos+=y),u("_parseVarByteNum: result: %o",_=!!_&&(g?{bytes:y,value:p}:p)),_}_parseByte(){let g;return this._pos=4)&&(k||ut))J+=s.byteLength(k)+2;else{if(ft<4)return U.emit("error",new Error("clientId must be supplied before 3.1.1")),!1;if(1*ut==0)return U.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 U.emit("error",new Error("Invalid keepalive")),!1;if(J+=2,J+=1,ft===5){var at=T(U,X);if(!at)return!1;J+=at.length}if(lt){if(typeof lt!="object")return U.emit("error",new Error("Invalid will")),!1;if(!lt.topic||typeof lt.topic!="string")return U.emit("error",new Error("Invalid will topic")),!1;if(J+=s.byteLength(lt.topic)+2,J+=2,lt.payload){if(!(lt.payload.length>=0))return U.emit("error",new Error("Invalid will payload")),!1;typeof lt.payload=="string"?J+=s.byteLength(lt.payload):J+=lt.payload.length}var mt={};if(ft===5){if(!(mt=T(U,lt.properties)))return!1;J+=mt.length}}let yt=!1;if(P!=null){if(!st(P))return U.emit("error",new Error("Invalid username")),!1;yt=!0,J+=s.byteLength(P)+2}if(H!=null){if(!yt)return U.emit("error",new Error("Username is required to use password")),!1;if(!st(H))return U.emit("error",new Error("Invalid password")),!1;J+=Z(H)+2}U.write(a.CONNECT_HEADER),M(U,J),C(U,nt),rt.bridgeMode&&(ft+=128),U.write(ft===131?a.VERSION131:ft===132?a.VERSION132:ft===4?a.VERSION4:ft===5?a.VERSION5:a.VERSION3);let kt=0;return kt|=P!=null?a.USERNAME_MASK:0,kt|=H!=null?a.PASSWORD_MASK:0,kt|=lt&<.retain?a.WILL_RETAIN_MASK:0,kt|=lt&<.qos?lt.qos<0&&_(U,k),X!=null&&X.write(),d("publish: payload: %o",b),U.write(b)}($,z,V);case"puback":case"pubrec":case"pubrel":case"pubcomp":return function(Y,U,tt){const rt=tt?tt.protocolVersion:4,nt=Y||{},ft=nt.cmd||"puback",lt=nt.messageId,ut=nt.dup&&ft==="pubrel"?a.DUP_MASK:0;let b=0;const k=nt.reasonCode,P=nt.properties;let H=rt===5?3:2;if(ft==="pubrel"&&(b=1),typeof lt!="number")return U.emit("error",new Error("Invalid messageId")),!1;let X=null;if(rt===5&&typeof P=="object"){if(!(X=S(U,P,tt,H)))return!1;H+=X.length}return U.write(a.ACKS[ft][b][ut][0]),M(U,H),_(U,lt),rt===5&&U.write(s.from([k])),X!==null&&X.write(),!0}($,z,V);case"subscribe":return function(Y,U,tt){d("subscribe: packet: ");const rt=tt?tt.protocolVersion:4,nt=Y||{},ft=nt.dup?a.DUP_MASK:0,lt=nt.messageId,ut=nt.subscriptions,b=nt.properties;let k=0;if(typeof lt!="number")return U.emit("error",new Error("Invalid messageId")),!1;k+=2;let P=null;if(rt===5){if(!(P=T(U,b)))return!1;k+=P.length}if(typeof ut!="object"||!ut.length)return U.emit("error",new Error("Invalid subscriptions")),!1;for(let X=0;X2)return U.emit("error",new Error("Invalid subscriptions - invalid Retain Handling")),!1}k+=s.byteLength(J)+2+1}d("subscribe: writing to stream: %o",a.SUBSCRIBE_HEADER),U.write(a.SUBSCRIBE_HEADER[1][ft?1:0][0]),M(U,k),_(U,lt),P!==null&&P.write();let H=!0;for(const X of ut){const J=X.topic,at=X.qos,mt=+X.nl,yt=+X.rap,kt=X.rh;let Tt;B(U,J),Tt=a.SUBSCRIBE_OPTIONS_QOS[at],rt===5&&(Tt|=mt?a.SUBSCRIBE_OPTIONS_NL:0,Tt|=yt?a.SUBSCRIBE_OPTIONS_RAP:0,Tt|=kt?a.SUBSCRIBE_OPTIONS_RH[kt]:0),H=U.write(s.from([Tt]))}return H}($,z,V);case"suback":return function(Y,U,tt){const rt=tt?tt.protocolVersion:4,nt=Y||{},ft=nt.messageId,lt=nt.granted,ut=nt.properties;let b=0;if(typeof ft!="number")return U.emit("error",new Error("Invalid messageId")),!1;if(b+=2,typeof lt!="object"||!lt.length)return U.emit("error",new Error("Invalid qos vector")),!1;for(let P=0;P_===q,set($){$?(g&&Object.keys(g).length!==0||(A=!0),_=q):(A=!1,_=Q)}});const I={};function M($,z){if(z>a.VARBYTEINT_MAX)return $.emit("error",new Error(`Invalid variable byte integer: ${z}`)),!1;let V=I[z];return V||(V=w(z),z<16384&&(I[z]=V)),d("writeVarByteInt: writing to stream: %o",V),$.write(V)}function B($,z){const V=s.byteLength(z);return _($,V),d("writeString: %s",z),$.write(z,"utf8")}function D($,z,V){B($,z),B($,V)}function q($,z){return d("writeNumberCached: number: %d",z),d("writeNumberCached: %o",g[z]),$.write(g[z])}function Q($,z){const V=v(z);return d("writeNumberGenerated: %o",V),$.write(V)}function C($,z){typeof z=="string"?B($,z):z?(_($,z.length),$.write(z)):_($,0)}function T($,z){if(typeof z!="object"||z.length!=null)return{length:1,write(){K($,{},0)}};let V=0;function Y(U,tt){let rt=0;switch(a.propertiesTypes[U]){case"byte":if(typeof tt!="boolean")return $.emit("error",new Error(`Invalid ${U}: ${tt}`)),!1;rt+=2;break;case"int8":if(typeof tt!="number"||tt<0||tt>255)return $.emit("error",new Error(`Invalid ${U}: ${tt}`)),!1;rt+=2;break;case"binary":if(tt&&tt===null)return $.emit("error",new Error(`Invalid ${U}: ${tt}`)),!1;rt+=1+s.byteLength(tt)+2;break;case"int16":if(typeof tt!="number"||tt<0||tt>65535)return $.emit("error",new Error(`Invalid ${U}: ${tt}`)),!1;rt+=3;break;case"int32":if(typeof tt!="number"||tt<0||tt>4294967295)return $.emit("error",new Error(`Invalid ${U}: ${tt}`)),!1;rt+=5;break;case"var":if(typeof tt!="number"||tt<0||tt>268435455)return $.emit("error",new Error(`Invalid ${U}: ${tt}`)),!1;rt+=1+s.byteLength(w(tt));break;case"string":if(typeof tt!="string")return $.emit("error",new Error(`Invalid ${U}: ${tt}`)),!1;rt+=3+s.byteLength(tt.toString());break;case"pair":if(typeof tt!="object")return $.emit("error",new Error(`Invalid ${U}: ${tt}`)),!1;rt+=Object.getOwnPropertyNames(tt).reduce((nt,ft)=>{const lt=tt[ft];return Array.isArray(lt)?nt+=lt.reduce((ut,b)=>ut+=3+s.byteLength(ft.toString())+2+s.byteLength(b.toString()),0):nt+=3+s.byteLength(ft.toString())+2+s.byteLength(tt[ft].toString()),nt},0);break;default:return $.emit("error",new Error(`Invalid property ${U}: ${tt}`)),!1}return rt}if(z)for(const U in z){let tt=0,rt=0;const nt=z[U];if(Array.isArray(nt))for(let ft=0;fttt;){const nt=U.shift();if(!nt||!z[nt])return!1;delete z[nt],rt=T($,z)}return rt}function O($,z,V){switch(a.propertiesTypes[z]){case"byte":$.write(s.from([a.properties[z]])),$.write(s.from([+V]));break;case"int8":$.write(s.from([a.properties[z]])),$.write(s.from([V]));break;case"binary":$.write(s.from([a.properties[z]])),C($,V);break;case"int16":$.write(s.from([a.properties[z]])),_($,V);break;case"int32":$.write(s.from([a.properties[z]])),function(Y,U){const tt=p(U);d("write4ByteNumber: %o",tt),Y.write(tt)}($,V);break;case"var":$.write(s.from([a.properties[z]])),M($,V);break;case"string":$.write(s.from([a.properties[z]])),B($,V);break;case"pair":Object.getOwnPropertyNames(V).forEach(Y=>{const U=V[Y];Array.isArray(U)?U.forEach(tt=>{$.write(s.from([a.properties[z]])),D($,Y.toString(),tt.toString())}):($.write(s.from([a.properties[z]])),D($,Y.toString(),U.toString()))});break;default:return $.emit("error",new Error(`Invalid property ${z} value: ${V}`)),!1}}function K($,z,V){M($,V);for(const Y in z)if(Object.prototype.hasOwnProperty.call(z,Y)&&z[Y]!==null){const U=z[Y];if(Array.isArray(U))for(let tt=0;tt=1.5*y;return Math.round(g/y)+" "+w+(p?"s":"")}n.exports=function(g,v){v=v||{};var y=typeof g;if(y==="string"&&g.length>0)return function(w){if(!((w=String(w)).length>100)){var p=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(w);if(!!p){var _=parseFloat(p[1]);switch((p[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return _*h;case"weeks":case"week":case"w":return _*u;case"days":case"day":case"d":return _*c;case"hours":case"hour":case"hrs":case"hr":case"h":return _*l;case"minutes":case"minute":case"mins":case"min":case"m":return _*a;case"seconds":case"second":case"secs":case"sec":case"s":return _*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return _;default:return}}}}(g);if(y==="number"&&isFinite(g))return v.long?function(w){var p=Math.abs(w);return p>=c?d(w,p,c,"day"):p>=l?d(w,p,l,"hour"):p>=a?d(w,p,a,"minute"):p>=s?d(w,p,s,"second"):w+" ms"}(g):function(w){var p=Math.abs(w);return p>=c?Math.round(w/c)+"d":p>=l?Math.round(w/l)+"h":p>=a?Math.round(w/a)+"m":p>=s?Math.round(w/s)+"s":w+"ms"}(g);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(g))}},{}],46:[function(i,n,r){const s=i("./lib/number-allocator.js");n.exports.NumberAllocator=s},{"./lib/number-allocator.js":47}],47:[function(i,n,r){const s=i("js-sdsl").Set,a=i("debug")("number-allocator:trace"),l=i("debug")("number-allocator:error");function c(h,d){this.low=h,this.high=d}function u(h,d){if(!(this instanceof u))return new u(h,d);this.min=h,this.max=d,this.ss=new s([],(g,v)=>g.compare(v)),a("Create"),this.clear()}c.prototype.equals=function(h){return this.low===h.low&&this.high===h.high},c.prototype.compare=function(h){return this.lowh)return!1;if(g.low===h)return++g.low,a("use():"+h),!0;if(g.high===h)return--g.high,a("use():"+h),!0;const v=g.low;return g.low=h+1,this.ss.insert(new c(v,h-1)),a("use():"+h),!0}return a("use():failed"),!1},u.prototype.free=function(h){if(hthis.max)return void l("free():"+h+" is out of range");const d=new c(h,h),g=this.ss.lowerBound(d);if(g){if(g.low<=h&&h<=g.high)return void l("free():"+h+" has already been vacant");if(g===this.ss.front())h+1===g.low?--g.low:this.ss.insert(d);else{const v=this.ss.reverseLowerBound(d);v.high+1===h?h+1===g.low?(this.ss.eraseElementByValue(v),g.low=v.low):v.high=h:h+1===g.low?g.low=h:this.ss.insert(d)}}else{if(g===this.ss.front())return void this.ss.insert(d);const v=this.ss.reverseLowerBound(d);v.high+1===h?v.high=h:this.ss.insert(d)}a("free():"+h)},u.prototype.clear=function(){a("clear()"),this.ss.clear(),this.ss.insert(new c(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)},n.exports=u},{debug:18,"js-sdsl":36}],48:[function(i,n,r){var s=i("wrappy");function a(c){var u=function(){return u.called?u.value:(u.called=!0,u.value=c.apply(this,arguments))};return u.called=!1,u}function l(c){var u=function(){if(u.called)throw new Error(u.onceError);return u.called=!0,u.value=c.apply(this,arguments)},h=c.name||"Function wrapped with `once`";return u.onceError=h+" shouldn't be called more than once",u.called=!1,u}n.exports=s(a),n.exports.strict=s(l),a.proto=a(function(){Object.defineProperty(Function.prototype,"once",{value:function(){return a(this)},configurable:!0}),Object.defineProperty(Function.prototype,"onceStrict",{value:function(){return l(this)},configurable:!0})})},{wrappy:79}],49:[function(i,n,r){(function(s){(function(){s===void 0||!s.version||s.version.indexOf("v0.")===0||s.version.indexOf("v1.")===0&&s.version.indexOf("v1.8.")!==0?n.exports={nextTick:function(a,l,c,u){if(typeof a!="function")throw new TypeError('"callback" argument must be a function');var h,d,g=arguments.length;switch(g){case 0:case 1:return s.nextTick(a);case 2:return s.nextTick(function(){a.call(null,l)});case 3:return s.nextTick(function(){a.call(null,l,c)});case 4:return s.nextTick(function(){a.call(null,l,c,u)});default:for(h=new Array(g-1),d=0;d1)for(var I=1;I= 0x80 (not a basic code point)","invalid-input":"Invalid input"},q=v-y,Q=Math.floor,C=String.fromCharCode;function T(Y){throw new RangeError(D[Y])}function S(Y,U){for(var tt=Y.length,rt=[];tt--;)rt[tt]=U(Y[tt]);return rt}function O(Y,U){var tt=Y.split("@"),rt="";return tt.length>1&&(rt=tt[0]+"@",Y=tt[1]),rt+S((Y=Y.replace(B,".")).split("."),U).join(".")}function K(Y){for(var U,tt,rt=[],nt=0,ft=Y.length;nt=55296&&U<=56319&&nt65535&&(tt+=C((U-=65536)>>>10&1023|55296),U=56320|1023&U),tt+=C(U)}).join("")}function st(Y,U){return Y+22+75*(Y<26)-((U!=0)<<5)}function $(Y,U,tt){var rt=0;for(Y=tt?Q(Y/_):Y>>1,Y+=Q(Y/U);Y>q*w>>1;rt+=v)Y=Q(Y/q);return Q(rt+(q+1)*Y/(Y+p))}function z(Y){var U,tt,rt,nt,ft,lt,ut,b,k,P,H,X=[],J=Y.length,at=0,mt=x,yt=A;for((tt=Y.lastIndexOf(E))<0&&(tt=0),rt=0;rt=128&&T("not-basic"),X.push(Y.charCodeAt(rt));for(nt=tt>0?tt+1:0;nt=J&&T("invalid-input"),((b=(H=Y.charCodeAt(nt++))-48<10?H-22:H-65<26?H-65:H-97<26?H-97:v)>=v||b>Q((g-at)/lt))&&T("overflow"),at+=b*lt,!(b<(k=ut<=yt?y:ut>=yt+w?w:ut-yt));ut+=v)lt>Q(g/(P=v-k))&&T("overflow"),lt*=P;yt=$(at-ft,U=X.length+1,ft==0),Q(at/U)>g-mt&&T("overflow"),mt+=Q(at/U),at%=U,X.splice(at++,0,mt)}return Z(X)}function V(Y){var U,tt,rt,nt,ft,lt,ut,b,k,P,H,X,J,at,mt,yt=[];for(X=(Y=K(Y)).length,U=x,tt=0,ft=A,lt=0;lt=U&&HQ((g-tt)/(J=rt+1))&&T("overflow"),tt+=(ut-U)*J,U=ut,lt=0;ltg&&T("overflow"),H==U){for(b=tt,k=v;!(b<(P=k<=ft?y:k>=ft+w?w:k-ft));k+=v)mt=b-P,at=v-P,yt.push(C(st(P+mt%at,0))),b=Q(mt/at);yt.push(C(st(b,0))),ft=$(tt,J,rt==nt),tt=0,++rt}++tt,++U}return yt.join("")}if(h={version:"1.4.1",ucs2:{decode:K,encode:Z},decode:z,encode:V,toASCII:function(Y){return O(Y,function(U){return M.test(U)?"xn--"+V(U):U})},toUnicode:function(Y){return O(Y,function(U){return I.test(U)?z(U.slice(4).toLowerCase()):U})}},l&&c)if(n.exports==l)c.exports=h;else for(d in h)h.hasOwnProperty(d)&&(l[d]=h[d]);else a.punycode=h})(this)}).call(this)}).call(this,typeof Le<"u"?Le:typeof self<"u"?self:typeof window<"u"?window:{})},{}],52:[function(i,n,r){function s(l,c){return Object.prototype.hasOwnProperty.call(l,c)}n.exports=function(l,c,u,h){c=c||"&",u=u||"=";var d={};if(typeof l!="string"||l.length===0)return d;var g=/\+/g;l=l.split(c);var v=1e3;h&&typeof h.maxKeys=="number"&&(v=h.maxKeys);var y=l.length;v>0&&y>v&&(y=v);for(var w=0;w=0?(p=E.substr(0,I),_=E.substr(I+1)):(p=E,_=""),A=decodeURIComponent(p),x=decodeURIComponent(_),s(d,A)?a(d[A])?d[A].push(x):d[A]=[d[A],x]:d[A]=x}return d};var a=Array.isArray||function(l){return Object.prototype.toString.call(l)==="[object Array]"}},{}],53:[function(i,n,r){var s=function(u){switch(typeof u){case"string":return u;case"boolean":return u?"true":"false";case"number":return isFinite(u)?u:"";default:return""}};n.exports=function(u,h,d,g){return h=h||"&",d=d||"=",u===null&&(u=void 0),typeof u=="object"?l(c(u),function(v){var y=encodeURIComponent(s(v))+d;return a(u[v])?l(u[v],function(w){return y+encodeURIComponent(s(w))}).join(h):y+encodeURIComponent(s(u[v]))}).join(h):g?encodeURIComponent(s(g))+d+encodeURIComponent(s(u)):""};var a=Array.isArray||function(u){return Object.prototype.toString.call(u)==="[object Array]"};function l(u,h){if(u.map)return u.map(h);for(var d=[],g=0;g2?"one of ".concat(u," ").concat(c.slice(0,h-1).join(", "),", or ")+c[h-1]:h===2?"one of ".concat(u," ").concat(c[0]," or ").concat(c[1]):"of ".concat(u," ").concat(c[0])}return"of ".concat(u," ").concat(String(c))}a("ERR_INVALID_OPT_VALUE",function(c,u){return'The value "'+u+'" is invalid for option "'+c+'"'},TypeError),a("ERR_INVALID_ARG_TYPE",function(c,u,h){var d,g,v;if(typeof u=="string"&&(g="not ",u.substr(0,g.length)===g)?(d="must not be",u=u.replace(/^not /,"")):d="must be",function(w,p,_){return(_===void 0||_>w.length)&&(_=w.length),w.substring(_-p.length,_)===p}(c," argument"))v="The ".concat(c," ").concat(d," ").concat(l(u,"type"));else{var y=function(w,p,_){return typeof _!="number"&&(_=0),!(_+p.length>w.length)&&w.indexOf(p,_)!==-1}(c,".")?"property":"argument";v='The "'.concat(c,'" ').concat(y," ").concat(d," ").concat(l(u,"type"))}return v+=". Received type ".concat(typeof h)},TypeError),a("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),a("ERR_METHOD_NOT_IMPLEMENTED",function(c){return"The "+c+" method is not implemented"}),a("ERR_STREAM_PREMATURE_CLOSE","Premature close"),a("ERR_STREAM_DESTROYED",function(c){return"Cannot call "+c+" after a stream was destroyed"}),a("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),a("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),a("ERR_STREAM_WRITE_AFTER_END","write after end"),a("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),a("ERR_UNKNOWN_ENCODING",function(c){return"Unknown encoding: "+c},TypeError),a("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),n.exports.codes=s},{}],56:[function(i,n,r){(function(s){(function(){var a=Object.keys||function(w){var p=[];for(var _ in w)p.push(_);return p};n.exports=g;var l=i("./_stream_readable"),c=i("./_stream_writable");i("inherits")(g,l);for(var u=a(c.prototype),h=0;h0)if(typeof k=="string"||at.objectMode||Object.getPrototypeOf(k)===h.prototype||(k=function(mt){return h.from(mt)}(k)),H)at.endEmitted?q(b,new D):O(b,at,k,!0);else if(at.ended)q(b,new M);else{if(at.destroyed)return!1;at.reading=!1,at.decoder&&!P?(k=at.decoder.write(k),at.objectMode||k.length!==0?O(b,at,k,!1):z(b,at)):O(b,at,k,!1)}else H||(at.reading=!1,z(b,at));return!at.ended&&(at.lengthk.highWaterMark&&(k.highWaterMark=function(P){return P>=K?P=K:(P--,P|=P>>>1,P|=P>>>2,P|=P>>>4,P|=P>>>8,P|=P>>>16,P++),P}(b)),b<=k.length?b:k.ended?k.length:(k.needReadable=!0,0))}function st(b){var k=b._readableState;g("emitReadable",k.needReadable,k.emittedReadable),k.needReadable=!1,k.emittedReadable||(g("emitReadable",k.flowing),k.emittedReadable=!0,s.nextTick($,b))}function $(b){var k=b._readableState;g("emitReadable_",k.destroyed,k.length,k.ended),k.destroyed||!k.length&&!k.ended||(b.emit("readable"),k.emittedReadable=!1),k.needReadable=!k.flowing&&!k.ended&&k.length<=k.highWaterMark,rt(b)}function z(b,k){k.readingMore||(k.readingMore=!0,s.nextTick(V,b,k))}function V(b,k){for(;!k.reading&&!k.ended&&(k.length0,k.resumeScheduled&&!k.paused?k.flowing=!0:b.listenerCount("data")>0&&b.resume()}function U(b){g("readable nexttick read 0"),b.read(0)}function tt(b,k){g("resume",k.reading),k.reading||b.read(0),k.resumeScheduled=!1,b.emit("resume"),rt(b),k.flowing&&!k.reading&&b.read(0)}function rt(b){var k=b._readableState;for(g("flow",k.flowing);k.flowing&&b.read()!==null;);}function nt(b,k){return k.length===0?null:(k.objectMode?P=k.buffer.shift():!b||b>=k.length?(P=k.decoder?k.buffer.join(""):k.buffer.length===1?k.buffer.first():k.buffer.concat(k.length),k.buffer.clear()):P=k.buffer.consume(b,k.decoder),P);var P}function ft(b){var k=b._readableState;g("endReadable",k.endEmitted),k.endEmitted||(k.ended=!0,s.nextTick(lt,k,b))}function lt(b,k){if(g("endReadableNT",b.endEmitted,b.length),!b.endEmitted&&b.length===0&&(b.endEmitted=!0,k.readable=!1,k.emit("end"),b.autoDestroy)){var P=k._writableState;(!P||P.autoDestroy&&P.finished)&&k.destroy()}}function ut(b,k){for(var P=0,H=b.length;P=k.highWaterMark:k.length>0)||k.ended))return g("read: emitReadable",k.length,k.ended),k.length===0&&k.ended?ft(this):st(this),null;if((b=Z(b,k))===0&&k.ended)return k.length===0&&ft(this),null;var H,X=k.needReadable;return g("need readable",X),(k.length===0||k.length-b0?nt(b,k):null)===null?(k.needReadable=k.length<=k.highWaterMark,b=0):(k.length-=b,k.awaitDrain=0),k.length===0&&(k.ended||(k.needReadable=!0),P!==b&&k.ended&&ft(this)),H!==null&&this.emit("data",H),H},T.prototype._read=function(b){q(this,new B("_read()"))},T.prototype.pipe=function(b,k){var P=this,H=this._readableState;switch(H.pipesCount){case 0:H.pipes=b;break;case 1:H.pipes=[H.pipes,b];break;default:H.pipes.push(b)}H.pipesCount+=1,g("pipe count=%d opts=%j",H.pipesCount,k);var X=(!k||k.end!==!1)&&b!==s.stdout&&b!==s.stderr?at:xe;function J(Vt,Qt){g("onunpipe"),Vt===P&&Qt&&Qt.hasUnpiped===!1&&(Qt.hasUnpiped=!0,g("cleanup"),b.removeListener("close",be),b.removeListener("finish",ne),b.removeListener("drain",mt),b.removeListener("error",Tt),b.removeListener("unpipe",J),P.removeListener("end",at),P.removeListener("end",xe),P.removeListener("data",kt),yt=!0,!H.awaitDrain||b._writableState&&!b._writableState.needDrain||mt())}function at(){g("onend"),b.end()}H.endEmitted?s.nextTick(X):P.once("end",X),b.on("unpipe",J);var mt=function(Vt){return function(){var Qt=Vt._readableState;g("pipeOnDrain",Qt.awaitDrain),Qt.awaitDrain&&Qt.awaitDrain--,Qt.awaitDrain===0&&c(Vt,"data")&&(Qt.flowing=!0,rt(Vt))}}(P);b.on("drain",mt);var yt=!1;function kt(Vt){g("ondata");var Qt=b.write(Vt);g("dest.write",Qt),Qt===!1&&((H.pipesCount===1&&H.pipes===b||H.pipesCount>1&&ut(H.pipes,b)!==-1)&&!yt&&(g("false write response, pause",H.awaitDrain),H.awaitDrain++),P.pause())}function Tt(Vt){g("onerror",Vt),xe(),b.removeListener("error",Tt),c(b,"error")===0&&q(b,Vt)}function be(){b.removeListener("finish",ne),xe()}function ne(){g("onfinish"),b.removeListener("close",be),xe()}function xe(){g("unpipe"),P.unpipe(b)}return P.on("data",kt),function(Vt,Qt,xi){if(typeof Vt.prependListener=="function")return Vt.prependListener(Qt,xi);Vt._events&&Vt._events[Qt]?Array.isArray(Vt._events[Qt])?Vt._events[Qt].unshift(xi):Vt._events[Qt]=[xi,Vt._events[Qt]]:Vt.on(Qt,xi)}(b,"error",Tt),b.once("close",be),b.once("finish",ne),b.emit("pipe",P),H.flowing||(g("pipe resume"),P.resume()),b},T.prototype.unpipe=function(b){var k=this._readableState,P={hasUnpiped:!1};if(k.pipesCount===0)return this;if(k.pipesCount===1)return b&&b!==k.pipes?this:(b||(b=k.pipes),k.pipes=null,k.pipesCount=0,k.flowing=!1,b&&b.emit("unpipe",this,P),this);if(!b){var H=k.pipes,X=k.pipesCount;k.pipes=null,k.pipesCount=0,k.flowing=!1;for(var J=0;J0,H.flowing!==!1&&this.resume()):b==="readable"&&(H.endEmitted||H.readableListening||(H.readableListening=H.needReadable=!0,H.flowing=!1,H.emittedReadable=!1,g("on readable",H.length,H.reading),H.length?st(this):H.reading||s.nextTick(U,this))),P},T.prototype.addListener=T.prototype.on,T.prototype.removeListener=function(b,k){var P=u.prototype.removeListener.call(this,b,k);return b==="readable"&&s.nextTick(Y,this),P},T.prototype.removeAllListeners=function(b){var k=u.prototype.removeAllListeners.apply(this,arguments);return b!=="readable"&&b!==void 0||s.nextTick(Y,this),k},T.prototype.resume=function(){var b=this._readableState;return b.flowing||(g("resume"),b.flowing=!b.readableListening,function(k,P){P.resumeScheduled||(P.resumeScheduled=!0,s.nextTick(tt,k,P))}(this,b)),b.paused=!1,this},T.prototype.pause=function(){return g("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(g("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},T.prototype.wrap=function(b){var k=this,P=this._readableState,H=!1;for(var X in b.on("end",function(){if(g("wrapped end"),P.decoder&&!P.ended){var at=P.decoder.end();at&&at.length&&k.push(at)}k.push(null)}),b.on("data",function(at){g("wrapped data"),P.decoder&&(at=P.decoder.write(at)),(!P.objectMode||at!=null)&&(P.objectMode||at&&at.length)&&(k.push(at)||(H=!0,b.pause()))}),b)this[X]===void 0&&typeof b[X]=="function"&&(this[X]=function(at){return function(){return b[at].apply(b,arguments)}}(X));for(var J=0;J-1))throw new D(z);return this._writableState.defaultEncoding=z,this},Object.defineProperty(T.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(T.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),T.prototype._write=function(z,V,Y){Y(new A("_write()"))},T.prototype._writev=null,T.prototype.end=function(z,V,Y){var U=this._writableState;return typeof z=="function"?(Y=z,z=null,V=null):typeof V=="function"&&(Y=V,V=null),z!=null&&this.write(z,V),U.corked&&(U.corked=1,this.uncork()),U.ending||function(tt,rt,nt){rt.ending=!0,$(tt,rt),nt&&(rt.finished?s.nextTick(nt):tt.once("finish",nt)),rt.ended=!0,tt.writable=!1}(this,U,Y),this},Object.defineProperty(T.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(T.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState!==void 0&&this._writableState.destroyed},set:function(z){this._writableState&&(this._writableState.destroyed=z)}}),T.prototype.destroy=y.destroy,T.prototype._undestroy=y.undestroy,T.prototype._destroy=function(z,V){V(z)}}).call(this)}).call(this,i("_process"),typeof Le<"u"?Le: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,n,r){(function(s){(function(){var a;function l(E,I,M){return I in E?Object.defineProperty(E,I,{value:M,enumerable:!0,configurable:!0,writable:!0}):E[I]=M,E}var c=i("./end-of-stream"),u=Symbol("lastResolve"),h=Symbol("lastReject"),d=Symbol("error"),g=Symbol("ended"),v=Symbol("lastPromise"),y=Symbol("handlePromise"),w=Symbol("stream");function p(E,I){return{value:E,done:I}}function _(E){var I=E[u];if(I!==null){var M=E[w].read();M!==null&&(E[v]=null,E[u]=null,E[h]=null,I(p(M,!1)))}}var A=Object.getPrototypeOf(function(){}),x=Object.setPrototypeOf((l(a={get stream(){return this[w]},next:function(){var E=this,I=this[d];if(I!==null)return Promise.reject(I);if(this[g])return Promise.resolve(p(void 0,!0));if(this[w].destroyed)return new Promise(function(q,Q){s.nextTick(function(){E[d]?Q(E[d]):q(p(void 0,!0))})});var M,B=this[v];if(B)M=new Promise(function(q,Q){return function(C,T){q.then(function(){Q[g]?C(p(void 0,!0)):Q[y](C,T)},T)}}(B,this));else{var D=this[w].read();if(D!==null)return Promise.resolve(p(D,!1));M=new Promise(this[y])}return this[v]=M,M}},Symbol.asyncIterator,function(){return this}),l(a,"return",function(){var E=this;return new Promise(function(I,M){E[w].destroy(null,function(B){B?M(B):I(p(void 0,!0))})})}),a),A);n.exports=function(E){var I,M=Object.create(x,(l(I={},w,{value:E,writable:!0}),l(I,u,{value:null,writable:!0}),l(I,h,{value:null,writable:!0}),l(I,d,{value:null,writable:!0}),l(I,g,{value:E._readableState.endEmitted,writable:!0}),l(I,y,{value:function(B,D){var q=M[w].read();q?(M[v]=null,M[u]=null,M[h]=null,B(p(q,!1))):(M[u]=B,M[h]=D)},writable:!0}),I));return M[v]=null,c(E,function(B){if(B&&B.code!=="ERR_STREAM_PREMATURE_CLOSE"){var D=M[h];return D!==null&&(M[v]=null,M[u]=null,M[h]=null,D(B)),void(M[d]=B)}var q=M[u];q!==null&&(M[v]=null,M[u]=null,M[h]=null,q(p(void 0,!0))),M[g]=!0}),E.on("readable",function(B){s.nextTick(_,B)}.bind(null,M)),M}}).call(this)}).call(this,i("_process"))},{"./end-of-stream":64,_process:50}],62:[function(i,n,r){function s(d,g){var v=Object.keys(d);if(Object.getOwnPropertySymbols){var y=Object.getOwnPropertySymbols(d);g&&(y=y.filter(function(w){return Object.getOwnPropertyDescriptor(d,w).enumerable})),v.push.apply(v,y)}return v}function a(d,g,v){return g in d?Object.defineProperty(d,g,{value:v,enumerable:!0,configurable:!0,writable:!0}):d[g]=v,d}function l(d,g){for(var v=0;v0?this.tail.next=w:this.head=w,this.tail=w,++this.length}},{key:"unshift",value:function(y){var w={data:y,next:this.head};this.length===0&&(this.tail=w),this.head=w,++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 w=this.head,p=""+w.data;w=w.next;)p+=y+w.data;return p}},{key:"concat",value:function(y){if(this.length===0)return c.alloc(0);for(var w,p,_,A=c.allocUnsafe(y>>>0),x=this.head,E=0;x;)w=x.data,p=A,_=E,c.prototype.copy.call(w,p,_),E+=x.data.length,x=x.next;return A}},{key:"consume",value:function(y,w){var p;return yA.length?A.length:y;if(x===A.length?_+=A:_+=A.slice(0,y),(y-=x)===0){x===A.length?(++p,w.next?this.head=w.next:this.head=this.tail=null):(this.head=w,w.data=A.slice(x));break}++p}return this.length-=p,_}},{key:"_getBuffer",value:function(y){var w=c.allocUnsafe(y),p=this.head,_=1;for(p.data.copy(w),y-=p.data.length;p=p.next;){var A=p.data,x=y>A.length?A.length:y;if(A.copy(w,w.length-y,0,x),(y-=x)===0){x===A.length?(++_,p.next?this.head=p.next:this.head=this.tail=null):(this.head=p,p.data=A.slice(x));break}++_}return this.length-=_,w}},{key:h,value:function(y,w){return u(this,function(p){for(var _=1;_0,function(I){w||(w=I),I&&_.forEach(h),E||(_.forEach(h),p(w))})});return v.reduce(d)}},{"../../../errors":55,"./end-of-stream":64}],67:[function(i,n,r){var s=i("../../../errors").codes.ERR_INVALID_OPT_VALUE;n.exports={getHighWaterMark:function(a,l,c,u){var h=function(d,g,v){return d.highWaterMark!=null?d.highWaterMark:g?d[v]:null}(l,u,c);if(h!=null){if(!isFinite(h)||Math.floor(h)!==h||h<0)throw new s(u?c:"highWaterMark",h);return Math.floor(h)}return a.objectMode?16:16384}}},{"../../../errors":55}],68:[function(i,n,r){n.exports=i("events").EventEmitter},{events:22}],69:[function(i,n,r){(r=n.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,n,r){n.exports=function(){if(typeof arguments[0]!="function")throw new Error("callback needed");if(typeof arguments[1]!="number")throw new Error("interval needed");var s;if(arguments.length>0){s=new Array(arguments.length-2);for(var a=0;a>5==6?2:p>>4==14?3:p>>3==30?4:p>>6==2?-1:-2}function u(p){var _=this.lastTotal-this.lastNeed,A=function(x,E,I){if((192&E[0])!=128)return x.lastNeed=0,"\uFFFD";if(x.lastNeed>1&&E.length>1){if((192&E[1])!=128)return x.lastNeed=1,"\uFFFD";if(x.lastNeed>2&&E.length>2&&(192&E[2])!=128)return x.lastNeed=2,"\uFFFD"}}(this,p);return A!==void 0?A:this.lastNeed<=p.length?(p.copy(this.lastChar,_,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(p.copy(this.lastChar,_,0,p.length),void(this.lastNeed-=p.length))}function h(p,_){if((p.length-_)%2==0){var A=p.toString("utf16le",_);if(A){var x=A.charCodeAt(A.length-1);if(x>=55296&&x<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=p[p.length-2],this.lastChar[1]=p[p.length-1],A.slice(0,-1)}return A}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=p[p.length-1],p.toString("utf16le",_,p.length-1)}function d(p){var _=p&&p.length?this.write(p):"";if(this.lastNeed){var A=this.lastTotal-this.lastNeed;return _+this.lastChar.toString("utf16le",0,A)}return _}function g(p,_){var A=(p.length-_)%3;return A===0?p.toString("base64",_):(this.lastNeed=3-A,this.lastTotal=3,A===1?this.lastChar[0]=p[p.length-1]:(this.lastChar[0]=p[p.length-2],this.lastChar[1]=p[p.length-1]),p.toString("base64",_,p.length-A))}function v(p){var _=p&&p.length?this.write(p):"";return this.lastNeed?_+this.lastChar.toString("base64",0,3-this.lastNeed):_}function y(p){return p.toString(this.encoding)}function w(p){return p&&p.length?this.write(p):""}r.StringDecoder=l,l.prototype.write=function(p){if(p.length===0)return"";var _,A;if(this.lastNeed){if((_=this.fillLast(p))===void 0)return"";A=this.lastNeed,this.lastNeed=0}else A=0;return A=0?(D>0&&(E.lastNeed=D-1),D):--B=0?(D>0&&(E.lastNeed=D-2),D):--B=0?(D>0&&(D===2?D=0:E.lastNeed=D-3),D):0}(this,p,_);if(!this.lastNeed)return p.toString("utf8",_);this.lastTotal=A;var x=p.length-(A-this.lastNeed);return p.copy(this.lastChar,0,x),p.toString("utf8",_,x)},l.prototype.fillLast=function(p){if(this.lastNeed<=p.length)return p.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);p.copy(this.lastChar,this.lastTotal-this.lastNeed,0,p.length),this.lastNeed-=p.length}},{"safe-buffer":73}],76:[function(i,n,r){var s=i("punycode"),a=i("./util");function l(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}r.parse=I,r.resolve=function(M,B){return I(M,!1,!0).resolve(B)},r.resolveObject=function(M,B){return M?I(M,!1,!0).resolveObject(B):B},r.format=function(M){return a.isString(M)&&(M=I(M)),M instanceof l?M.format():l.prototype.format.call(M)},r.Url=l;var c=/^([a-z0-9.+-]+:)/i,u=/:[0-9]*$/,h=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,d=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r",` `," "]),g=["'"].concat(d),v=["%","/","?",";","#"].concat(g),y=["/","?","#"],w=/^[+a-z0-9A-Z_-]{0,63}$/,p=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,_={javascript:!0,"javascript:":!0},A={javascript:!0,"javascript:":!0},x={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},E=i("querystring");function I(M,B,D){if(M&&a.isObject(M)&&M instanceof l)return M;var q=new l;return q.parse(M,B,D),q}l.prototype.parse=function(M,B,D){if(!a.isString(M))throw new TypeError("Parameter 'url' must be a string, not "+typeof M);var q=M.indexOf("?"),Q=q!==-1&&q127?ft+="x":ft+=nt[lt];if(!ft.match(w)){var b=tt.slice(0,V),k=tt.slice(V+1),P=nt.match(p);P&&(b.push(P[1]),k.unshift(P[2])),k.length&&(T="/"+k.join(".")+T),this.hostname=b.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),U||(this.hostname=s.toASCII(this.hostname));var H=this.port?":"+this.port:"",X=this.hostname||"";this.host=X+H,this.href+=this.host,U&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),T[0]!=="/"&&(T="/"+T))}if(!_[K])for(V=0,rt=g.length;V0)&&D.host.split("@"))&&(D.auth=P.shift(),D.host=D.hostname=P.shift())),D.search=M.search,D.query=M.query,a.isNull(D.pathname)&&a.isNull(D.search)||(D.path=(D.pathname?D.pathname:"")+(D.search?D.search:"")),D.href=D.format(),D;if(!nt.length)return D.pathname=null,D.search?D.path="/"+D.search:D.path=null,D.href=D.format(),D;for(var lt=nt.slice(-1)[0],ut=(D.host||M.host||nt.length>1)&&(lt==="."||lt==="..")||lt==="",b=0,k=nt.length;k>=0;k--)(lt=nt[k])==="."?nt.splice(k,1):lt===".."?(nt.splice(k,1),b++):b&&(nt.splice(k,1),b--);if(!tt&&!rt)for(;b--;b)nt.unshift("..");!tt||nt[0]===""||nt[0]&&nt[0].charAt(0)==="/"||nt.unshift(""),ut&&nt.join("/").substr(-1)!=="/"&&nt.push("");var P,H=nt[0]===""||nt[0]&&nt[0].charAt(0)==="/";return ft&&(D.hostname=D.host=H?"":nt.length?nt.shift():"",(P=!!(D.host&&D.host.indexOf("@")>0)&&D.host.split("@"))&&(D.auth=P.shift(),D.host=D.hostname=P.shift())),(tt=tt||D.host&&nt.length)&&!H&&nt.unshift(""),nt.length?D.pathname=nt.join("/"):(D.pathname=null,D.path=null),a.isNull(D.pathname)&&a.isNull(D.search)||(D.path=(D.pathname?D.pathname:"")+(D.search?D.search:"")),D.auth=M.auth||D.auth,D.slashes=D.slashes||M.slashes,D.href=D.format(),D},l.prototype.parseHost=function(){var M=this.host,B=u.exec(M);B&&((B=B[0])!==":"&&(this.port=B.substr(1)),M=M.substr(0,M.length-B.length)),M&&(this.hostname=M)}},{"./util":77,punycode:51,querystring:54}],77:[function(i,n,r){n.exports={isString:function(s){return typeof s=="string"},isObject:function(s){return typeof s=="object"&&s!==null},isNull:function(s){return s===null},isNullOrUndefined:function(s){return s==null}}},{}],78:[function(i,n,r){(function(s){(function(){function a(l){try{if(!s.localStorage)return!1}catch{return!1}var c=s.localStorage[l];return c!=null&&String(c).toLowerCase()==="true"}n.exports=function(l,c){if(a("noDeprecation"))return l;var u=!1;return function(){if(!u){if(a("throwDeprecation"))throw new Error(c);a("traceDeprecation")?console.trace(c):console.warn(c),u=!0}return l.apply(this,arguments)}}}).call(this)}).call(this,typeof Le<"u"?Le:typeof self<"u"?self:typeof window<"u"?window:{})},{}],79:[function(i,n,r){n.exports=function s(a,l){if(a&&l)return s(a)(l);if(typeof a!="function")throw new TypeError("need wrapper function");return Object.keys(a).forEach(function(u){c[u]=a[u]}),c;function c(){for(var u=new Array(arguments.length),h=0;h0)for(var g=0,v=arguments.length;g1)g=d;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");v=this.head.next,g=this.head.value}for(var y=0;v!==null;y++)g=h(g,v.value,y),v=v.next;return g},s.prototype.reduceReverse=function(h,d){var g,v=this.tail;if(arguments.length>1)g=d;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");v=this.tail.prev,g=this.tail.value}for(var y=this.length-1;v!==null;y--)g=h(g,v.value,y),v=v.prev;return g},s.prototype.toArray=function(){for(var h=new Array(this.length),d=0,g=this.head;g!==null;d++)h[d]=g.value,g=g.next;return h},s.prototype.toArrayReverse=function(){for(var h=new Array(this.length),d=0,g=this.tail;g!==null;d++)h[d]=g.value,g=g.prev;return h},s.prototype.slice=function(h,d){(d=d||this.length)<0&&(d+=this.length),(h=h||0)<0&&(h+=this.length);var g=new s;if(dthis.length&&(d=this.length);for(var v=0,y=this.head;y!==null&&vthis.length&&(d=this.length);for(var v=this.length,y=this.tail;y!==null&&v>d;v--)y=y.prev;for(;y!==null&&v>h;v--,y=y.prev)g.push(y.value);return g},s.prototype.splice=function(h,d,...g){h>this.length&&(h=this.length-1),h<0&&(h=this.length+h);for(var v=0,y=this.head;y!==null&&v'},info:{color:"#0052d9",icon:''},warning:{color:"#e37318",icon:''},error:{color:"#d54941",icon:''},question:{color:"#0052d9",icon:''}},Ge={};class iE{constructor(t,i){W(this,"parentElement");W(this,"box");W(this,"icon");W(this,"text");W(this,"closeBtn");W(this,"duration");W(this,"content");W(this,"theme");W(this,"placement");W(this,"id");var r;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=ld[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 n;for(let s=0;s{this.close()},this.duration);let t=-1;Object.keys(Ge).forEach(i=>{var n;((n=Ge[i])==null?void 0:n.placement)===this.placement&&t++}),this.setPosition(this.placement,t),this.icon.children[0].style.fill=ld[this.theme].color}setPosition(t,i=0){switch(t){case"top":this.box.style.top=`${30+i*60}px`,this.box.style.left="50%";break;case"bottom":this.box.style.bottom=`${30+i*60}px`,this.box.style.left="50%";break;case"left":this.box.style.top=`${30+i*60}px`,this.box.style.left="30px";break;case"right":this.box.style.top=`${30+i*60}px`,this.box.style.right="30px";break}}close(){Object.keys(Ge).forEach(t=>{var i;if(((i=Ge[t])==null?void 0:i.placement)===this.placement)switch(this.placement){case"top":case"left":case"right":Ge[t].box.style.top=parseInt(Ge[t].box.style.top)-60+"px";break;case"bottom":Ge[t].box.style.bottom=parseInt(Ge[t].box.style.bottom)-60+"px";break}}),Ge[this.id]=null,delete Ge[this.id],this.box.remove()}}class UC{constructor(t,i={}){W(this,"store");W(this,"canvas");W(this,"websocket");W(this,"mqttClient");W(this,"websockets");W(this,"mqttClients");W(this,"penPluginMap",new Map);W(this,"socketFn");W(this,"events",{});W(this,"map");W(this,"mapTimer");W(this,"facePen",Or);W(this,"getWords",Av);W(this,"calcTextLines",Es);W(this,"calcTextRect",Ti);W(this,"calcTextDrawRect",Ev);W(this,"jetLinksList",[]);W(this,"jetLinksClient");W(this,"register",A_);W(this,"registerCanvasDraw",R_);W(this,"registerAnchors",C_);W(this,"websocketTimes",0);W(this,"mqttTimes",0);W(this,"httpTimer");W(this,"httpTimerList",[]);W(this,"updateTimer");W(this,"updateTimerList",[]);W(this,"sqlTimerList",[]);W(this,"onEvent",(t,i)=>{switch(t){case"add":i.forEach(n=>{var r;(r=n.onAdd)==null||r.call(n,n)}),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(n=>{this.doEvent(n,t)});break;case"click":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.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":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("\u8BF7\u5148\u4FDD\u5B58\u5F53\u524D\u56FE\u7EB8"),this.navigatorTo(i.params);break;case"input":this.store.data.locked&&i&&!i.disabled&&this.doEvent(i,t);break;case"change":this.store.data.locked&&i&&!i.disabled&&this.doEvent(i,t);break}this.doMessageEvent(t)});W(this,"doEvent",(t,i)=>{var s,a,l,c,u,h,d,g,v,y;if(!t)return;let n=!1,r=[];if((s=t.events)==null||s.forEach((w,p)=>{var _;if(w.actions&&w.actions.length){if(w.name===i){let A=!1;w.conditions&&w.conditions.length?w.conditionType==="and"?A=w.conditions.every(x=>this.judgeCondition(t,x.key,x)):w.conditionType==="or"&&(A=w.conditions.some(x=>this.judgeCondition(t,x.key,x))):A=!0,A&&r.push(p)}}else if(n=!0,this.events[w.action]&&w.name===i){let A=!((_=w.where)!=null&&_.type);if(w.where){const{fn:x,fnJs:E,comparison:I,key:M,value:B}=w.where;if(x)A=x(t,{meta2d:this});else if(E){try{w.where.fn=new Function("pen","context",E)}catch(D){console.error("Error: make function:",D)}w.where.fn&&(A=w.where.fn(t,{meta2d:this}))}else{let D=t[M];switch(["x","y","width","height"].includes(M)&&(D=this.getPenRect(t)[M]),I){case">":A=D>+B;break;case">=":A=D>=+B;break;case"<":A=D<+B;break;case"<=":A=D<=+B;break;case"=":case"==":A=D==B;break;case"!=":A=D!=B;break;case"[)":A=pr(+D,B);break;case"![)":A=!pr(+D,B);break;case"[]":A=wr(D,B);break;case"![]":A=!wr(D,B);break}}}A&&r.push(p)}}),n?(a=t.events)==null||a.forEach((w,p)=>{r.includes(p)&&this.events[w.action](t,w)}):(l=t.events)==null||l.forEach(async(w,p)=>{if(r.includes(p)){if(w.confirm&&!await this.canvas.popconfirm.showModal(t,this.canvas.mousePos,w.confirmTitle))return;w.actions.forEach(_=>{if(_.timeout){let A=setTimeout(()=>{this.events[_.action]&&(this.events[_.action](t,_),clearTimeout(A),A=null)},_.timeout)}else this.events[_.action]&&this.events[_.action](t,_)})}}),i==="valueUpdate"){(c=t.realTimes)==null||c.forEach(p=>{var A,x;let _=[];(A=p.triggers)==null||A.forEach((E,I)=>{var B;let M=!1;(B=E.conditions)!=null&&B.length?E.conditionType==="and"?M=E.conditions.every(D=>this.judgeCondition(t,p.key,D)):E.conditionType==="or"&&(M=E.conditions.some(D=>this.judgeCondition(t,p.key,D))):M=!0,M&&_.push(I)}),(x=p.triggers)==null||x.forEach((E,I)=>{var M;_.includes(I)&&((M=E.actions)==null||M.forEach(B=>{if(B.timeout){let D=setTimeout(()=>{this.events[B.action]&&(this.events[B.action](t,B),clearTimeout(D),D=null)},B.timeout)}else this.events[B.action](t,B)}))})});let w=[];if((u=this.store.globalTriggers[t.id])==null||u.forEach((p,_)=>{var x;let A=!1;(x=p.conditions)!=null&&x.length?p.conditionType==="and"?A=p.conditions.every(E=>this.judgeCondition(this.store.pens[E.source],E.key,E)):p.conditionType==="or"&&(A=p.conditions.some(E=>this.judgeCondition(this.store.pens[E.source],E.key,E))):A=!0,A&&w.push(_)}),(h=this.store.globalTriggers[t.id])==null||h.forEach((p,_)=>{var A;w.includes(_)&&((A=p.actions)==null||A.forEach(x=>{if(x.timeout){let E=setTimeout(()=>{this.events[x.action]&&(this.events[x.action](t,x),clearTimeout(E),E=null)},x.timeout)}else this.events[x.action](t,x)}))}),(d=t.triggers)!=null&&d.length){for(let p of t.triggers)if((g=p.status)!=null&&g.length)for(let _ of p.status){let A=!1;if((v=_.conditions)!=null&&v.length?_.conditionType==="and"?A=_.conditions.every(x=>this.judgeCondition(t,x.key,x)):_.conditionType==="or"&&(A=_.conditions.some(x=>this.judgeCondition(t,x.key,x))):A=!0,A){(y=_.actions)==null||y.forEach(x=>{if(x.timeout){let E=setTimeout(()=>{this.events[x.action]&&(this.events[x.action](t,x),clearTimeout(E),E=null)},x.timeout)}else this.events[x.action](t,x)});break}}}}this.doEvent(this.store.pens[t.parentId],i)});W(this,"doDataEvent",t=>{var r,s,a;if(!((r=this.store.data.dataEvents)!=null&&r.length))return;const i=t.reduce((l,{dataId:c,id:u,value:h})=>(l[u||c]=h,l),{});let n=[];(s=this.store.data.dataEvents)==null||s.forEach((l,c)=>{let u=!1;l.conditions&&l.conditions.length?l.conditionType==="and"?u=l.conditions.every(h=>this.dataJudegeCondition(i,h.key,h)):l.conditionType==="or"&&(u=l.conditions.some(h=>this.dataJudegeCondition(i,h.key,h))):u=!0,u&&n.push(c)}),(a=this.store.data.dataEvents)==null||a.forEach((l,c)=>{var u;n.includes(c)&&((u=l.actions)==null||u.forEach(h=>{this.events[h.action](i,h)}))})});W(this,"renderPenRaw",ja);W(this,"setElemPosition",ti);W(this,"setLifeCycleFunc",x2);this.store=L_(It()),this.setOptions(i),this.setDatabyOptions(i),this.init(t),this.register(Qk()),this.registerCanvasDraw({cube:tk}),this.registerAnchors(tE()),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;(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=Kt.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),this.canvas&&t.scroll!==void 0&&(t.scroll?(!this.canvas.scroll&&(this.canvas.scroll=new ig(this.canvas)),this.canvas.scroll.show()):this.canvas.scroll&&this.canvas.scroll.hide())}getOptions(){return this.store.options}setTheme(t){this.store.data.theme=t,this.setBackgroundColor(this.store.theme[t].background),this.canvas.parentElement.style.background=this.store.theme[t].parentBackground,this.store.data.color=this.store.theme[t].color,this.setOptions({ruleColor:this.store.theme[t].ruleColor,ruleOptions:this.store.theme[t].ruleOptions}),this.render()}setDatabyOptions(t={}){const{color:i,activeColor:n,activeBackground:r,grid:s,gridColor:a,gridSize:l,fromArrow:c,toArrow:u,rule:h,ruleColor:d,textColor:g,x:v=0,y=0}=t;this.setRule({rule:h,ruleColor:d}),this.setGrid({grid:s,gridColor:a,gridSize:l}),this.store.data=Object.assign(this.store.data,{textColor:g,color:i,activeColor:n,activeBackground:r,fromArrow:c,toArrow:u,x:v,y})}init(t){typeof t=="string"?this.canvas=new sd(this,document.getElementById(t),this.store):this.canvas=new sd(this,t,this.store),this.resize(),this.canvas.listen()}initEventFns(){this.events[fe.Link]=(t,i)=>{var n;if(window&&i.value&&typeof i.value=="string"){window.open(i.value,(n=i.params)!=null?n:"_blank");return}console.warn("[meta2d] Link param is not a string")},this.events[fe.SetProps]=(t,i)=>{const n=i.value;if(n&&typeof n=="object"){(i.params?this.find(i.params):this.find(t.id)).forEach(s=>{n.hasOwnProperty("visible")&&s.visible!==n.visible&&this.setVisible(s,n.visible),this.setValue({id:s.id,...n},{render:!1,doEvent:!1})}),this.render();return}console.warn("[meta2d] SetProps value is not an object")},this.events[fe.StartAnimate]=(t,i)=>{let n=t;if(i.value&&(n=this.findOne(i.value)),!(this.store.animates.has(n)&&!n.calculative.pause&&n.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[fe.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[fe.StopAnimate]=(t,i)=>{if(!i.value||typeof i.value=="string"){if(i.value){let n=this.findOne(i.value);if(!this.store.animates.has(n))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[fe.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[fe.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[fe.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[fe.JS]=(t,i,n)=>{var r;if(i.value&&!i.fn)try{if(typeof i.value!="string")throw new Error("[meta2d] Function value must be string");const s=i.value;i.fn=new Function("pen","params","context",s)}catch(s){console.error("[meta2d]: Error on make a function:",s)}(r=i.fn)==null||r.call(i,t,n||i.params,{meta2d:this,eventName:i.name})},this.events[fe.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[fe.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[fe.SendPropData]=(t,i)=>{const n=ct(i.value);if(n&&typeof n=="object"){const r=i.params?this.findOne(i.params):t;for(let s in n)(n[s]===void 0||n[s]==="")&&(n[s]=r[s]);n.id=r.id,this.doSendDataEvent(n,i.extend);return}console.warn("[meta2d] SendPropData value is not an object")},this.events[fe.SendVarData]=(t,i)=>{const n=ct(i.value);if(n&&typeof n=="object"){const r=i.params?this.findOne(i.params):t;let s=[];for(let a in n){let l={dataId:a,value:n[a]};if(!l.value){let c=r.form.find(u=>u.dataIds&&u.dataIds.dataId===l.dataId);c&&(l.value=r[c.key])}s.push(l)}this.doSendDataEvent(s,i.extend);return}console.warn("[meta2d] SendVarData value is not an object")},this.events[fe.Navigator]=(t,i)=>{i.value&&typeof i.value=="string"&&this.navigatorTo(i.value)},this.events[fe.Dialog]=(t,i)=>{if(i.params&&typeof i.params=="string"){let n=i.params;if(i.params.includes("${")){let r=i.params.match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));r&&(r==null||r.forEach(s=>{n=n.replace(`\${${s}}`,t[s])}))}this.canvas.dialog.show(i.value,n,i.extend)}},this.events[fe.SendData]=(t,i)=>{var r,s;if((r=i.list)!=null&&r.length){if(i.network&&i.network.protocol==="jetLinks"){const l=[];i.list.forEach((c,u)=>{var d,g;const h=c.params?this.findOne(c.params):t;l[u]={deviceId:h.deviceId,productId:h.productId,properties:{}};for(let v in c.value)if(c.value[v]===void 0||c.value[v]===""){const y=(d=h.realTimes)==null?void 0:d.find(w=>w.propertyId===v);y&&(l[u].properties[v]=h[y.key])}else if(typeof c.value[v]=="string"&&((g=c.value[v])==null?void 0:g.indexOf("${"))>-1){let y=c.value[v].match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));y!=null&&y.length&&(l[u].properties[v]=h[y[0]])}else l[u].properties[v]=c.value[v]}),this.jetLinksClient&&l.length&&l.forEach(c=>{this.jetLinksClient.send(JSON.stringify({type:"sub",topic:`/device-message-sender/${c.productId}/${c.deviceId}`,parameter:{messageType:"WRITE_PROPERTY",properties:c.properties,headers:{async:!1}},id:c.productId+"/"+c.deviceId+"-"+It()}))});return}const a={};i.list.forEach(l=>{var u;const c=l.params?this.findOne(l.params):t;for(let h in l.value)if(l.value[h]===void 0||l.value[h]==="")a[h]=c[h];else if(typeof l.value[h]=="string"&&((u=l.value[h])==null?void 0:u.indexOf("${"))>-1){let d=l.value[h].match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));d!=null&&d.length&&(a[h]=c[d[0]])}else a[h]=l.value[h]}),t.deviceId&&(a.deviceId=t.deviceId),this.sendDataToNetWork(a,t,i);return}const n=ct(i.value);if(n&&typeof n=="object"&&i.targetType==="id"){const a=i.params?this.findOne(i.params):t;for(let l in n)if(n[l]===void 0||n[l]==="")n[l]=a[l];else if(typeof n[l]=="string"&&((s=n[l])==null?void 0:s.indexOf("${"))>-1){let c=n[l].match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));c!=null&&c.length&&(n[l]=a[c[0]])}a.deviceId&&(n.deviceId=a.deviceId),this.sendDataToNetWork(n,t,i);return}},this.events[fe.PostMessage]=(t,i)=>{var a;if(typeof i.value!="string"){console.warn("[meta2d] Emit value must be a string");return}const n=i.params?this.findOne(i.params):t;if(n.name!=="iframe"||!n.iframe){console.warn("\u4E0D\u662F\u5D4C\u5165\u9875\u9762");return}let r=Il(n.iframe.split("?")[1]);const s={};(a=i.list)!=null&&a.length&&i.list.forEach(l=>{var u;const c=l.params?this.findOne(l.params):t;for(let h in l.value)if(l.value[h]===void 0||l.value[h]==="")s[h]=c[h];else if(typeof l.value[h]=="string"&&((u=l.value[h])==null?void 0:u.indexOf("${"))>-1){let d=l.value[h].match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));d!=null&&d.length&&(s[h]=c[d[0]])}else s[h]=l.value[h]}),n.calculative.singleton.div.children[0].contentWindow.postMessage(JSON.stringify({name:i.value,id:r.id,value:s}),"*")},this.events[fe.PostMessageToParent]=(t,i)=>{var r;if(typeof i.value!="string"){console.warn("[meta2d] Emit value must be a string");return}const n={};(r=i.list)!=null&&r.length&&i.list.forEach(s=>{var l;const a=s.params?this.findOne(s.params):t;for(let c in s.value)if(s.value[c]===void 0||s.value[c]==="")n[c]=a[c];else if(typeof s.value[c]=="string"&&((l=s.value[c])==null?void 0:l.indexOf("${"))>-1){let u=s.value[c].match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));u!=null&&u.length&&(n[c]=a[u[0]])}else n[c]=s.value[c]}),window.parent.postMessage(JSON.stringify({name:i.value,value:n}),"*")},this.events[fe.Message]=(t,i)=>{this.message({theme:i.params,content:i.value,...i.extend})}}message(t){new iE(this.canvas.parentElement,t).init()}closeAll(){for(let t in Ge)Ge[t].close()}async navigatorTo(t){if(!t)return;const i=new URL(window.location);i.searchParams.set("id",t),history.pushState({},"",i);const n=this.store.options.navigatorNetWork,r=location.href.includes("2d.")||location.href.includes("/2d")?"2d":"v",s=await fetch(((n==null?void 0:n.url)||`/api/data/${r}/get`)+((n==null?void 0:n.method)==="GET"?`?id=${t}`:""),{headers:{Authorization:`Bearer ${this.getCookie("token")||localStorage.getItem("token")||new URLSearchParams(location.search).get("token")||""}`},method:(n==null?void 0:n.method)||"POST",body:(n==null?void 0:n.method)==="GET"?void 0:JSON.stringify({id:t})});if(s.ok){let a=await s.text();a.constructor===Object||a.constructor===Array?a=JSON.parse(JSON.stringify(a)):typeof a=="string"&&(a=JSON.parse(a)),a.data&&(a=a.data),this.open(a)}else this.store.emitter.emit("error",{type:"http",error:s})}doSendDataEvent(t,i){let n=JSON.stringify(t);this.mqttClient&&this.mqttClient.connected&&(i?i.split(",").forEach(r=>{this.mqttClient.publish(r,n)}):this.store.data.mqttTopics&&this.store.data.mqttTopics.split(",").forEach(r=>{this.mqttClient.publish(r,n)})),this.websocket&&this.websocket.readyState===1&&this.websocket.send(n),(this.store.data.https||this.store.data.http)&&this.sendDatabyHttp(n),this.store.emitter.emit("sendData",n)}async sendDataToNetWork(t,i,n){var s;const r=ct(n.network);if(r.data&&(Object.assign(r,r.data),delete r.data),!!r.url){if(r.protocol==="http"){if(typeof r.headers=="object"){for(let u in r.headers)if(typeof r.headers[u]=="string"){let h=r.headers[u].match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));h&&(r.headers[u]=r.headers[u].replace(`\${${h[0]}}`,this.getDynamicParam(h[0])))}}let a,l=r.url;if(r.method==="GET"&&(a="?"+Object.keys(t).map(u=>u+"="+t[u]).join("&")),r.method==="POST"&&l.indexOf("${")>-1){let u=l.match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));u&&u.forEach(h=>{l=l.replace(`\${${h}}`,Nf(i,h)||this.getDynamicParam(h))})}const c=await fetch(l+(a||""),{headers:r.headers||{},method:r.method,body:r.method==="POST"?JSON.stringify(t):void 0});if(c.ok){if(n.callback){const u=await c.text();if(!n.fn)try{if(typeof n.callback!="string")throw new Error("[meta2d] Function callback must be string");const h=n.callback;n.fn=new Function("pen","data","context",h)}catch(h){console.error("[meta2d]: Error on make a function:",h)}(s=n.fn)==null||s.call(n,i,u,{meta2d:this,e:n})}console.info("http\u6D88\u606F\u53D1\u9001\u6210\u529F")}}else if(r.protocol==="mqtt"){const a=this.mqttClients.filter(l=>l.options.href===r.url);if(a&&a.length)a[0].connected&&r.topics.split(",").forEach(l=>{a[0].publish(l,t)});else{let l=ss.exports.connect(r.url,r.options);l.on("connect",()=>{console.info("mqtt\u8FDE\u63A5\u6210\u529F"),r.topics.split(",").forEach(c=>{l.publish(c,t),l==null||l.end()})})}}else if(r.protocol==="websocket"){const a=this.websockets.filter(l=>l.url===r.url);if(a&&a.length)a[0].readyState===1&&a[0].send(t);else{let l=new WebSocket(r.url,r.protocols||void 0);l.onopen=function(){console.info("websocket\u8FDE\u63A5\u6210\u529F"),l.send(t),setTimeout(()=>{l.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,n=!0,r=!1){return await this.canvas.addPen(t,i,n,r)}async addPens(t,i,n=!1){return await this.canvas.addPens(t,i,n)}render(t){var i;(i=this.canvas)==null||i.render(t)}async setBackgroundImage(t,i){var l,c,u,h;let n=this;async function r(d){return new Promise(g=>{const v=new Image;v.src=d,n.store.options.cdn&&!(d.startsWith("http")||d.startsWith("//")||d.startsWith("data:image"))&&(v.src=n.store.options.cdn+d),v.crossOrigin="anonymous",v.onload=()=>{g(v)}})}this.store.data.bkImage=t;const s=(i==null?void 0:i.width)||((l=this.store.data)==null?void 0:l.width)||((c=this.store.options)==null?void 0:c.width),a=(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(s&&a?(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 d=await r(t);this.store.bkImg=d,s&&a&&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:n=this.store.data.gridSize,gridRotate:r=this.store.data.gridRotate}={}){this.store.data.grid=t,this.store.data.gridColor=i,this.store.data.gridSize=n<0?0:n,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){this.setBackgroundImage(t.bkImage,t),Object.assign(this.store.data,t),this.store.data.pens=[];for(const n of t.pens)n.id||(n.id=It()),!n.calculative&&(n.calculative={canvas:this.canvas}),this.store.pens[n.id]=n;for(const n of t.pens)this.canvas.makePen(n)}if(this.canvas.patchFlagsLines.forEach(n=>{n.type&&this.canvas.initLineRect(n)}),this.store.data.template||(this.store.data.template=It()),i||(this.canvas.opening=!0),this.initBindDatas(),this.initBinds(),this.initMessageEvents(),this.initGlobalTriggers(),this.render(),this.listenSocket(),this.connectSocket(),this.connectNetwork(),this.startDataMock(),this.startAnimate(),this.startVideo(),this.doInitJS(),this.doInitFn(),setTimeout(()=>{const n=this.store.data.pens.find(r=>r.autofocus);n&&this.focus(n.id)},100),this.store.data.iconUrls)for(const n of this.store.data.iconUrls)F_(n,()=>{this.render()});this.canvas.autoPolylineFlag=!1,this.store.emitter.emit("opened"),this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.init()}cacheData(t){if(t&&this.store.options.cacheLength){let i=this.store.cacheDatas.findIndex(n=>n.data&&n.data._id===t);if(i===-1)this.store.cacheDatas.push({data:ct(this.store.data,!0)}),this.store.cacheDatas.length>this.store.options.cacheLength&&this.store.cacheDatas.shift();else{let n=this.store.cacheDatas.splice(i,1)[0];this.store.cacheDatas.push(n)}}}loadCacheData(t){let i=this.store.cacheDatas.findIndex(n=>n.data&&n.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(n=>{n.calculative.canvas=this.canvas,this.store.pens[n.id]=n,At.path2dDraws[n.name]&&this.store.path2dMap.set(n,At.path2dDraws[n.name](n)),n.type&&this.store.path2dMap.set(n,At.path2dDraws[n.name](n)),n.image&&(n.calculative.imageDrawed=!1,this.canvas.loadImage(n))}),this.render())}initBindDatas(){this.store.bindDatas={},this.store.data.pens.forEach(t=>{var i;(i=t.form)==null||i.forEach(n=>{let r;n.dataIds&&(Array.isArray(n.dataIds)?r=n.dataIds:r=[n.dataIds]),r==null||r.forEach(s=>{this.store.bindDatas[s.dataId]||(this.store.bindDatas[s.dataId]=[]),this.store.bindDatas[s.dataId].push({id:t.id,formItem:n})})})})}initBinds(){this.jetLinksList=[],this.store.bind={},this.store.data.pens.forEach(t=>{var i;(i=t.realTimes)==null||i.forEach(n=>{if(n.bind&&n.bind.id){this.store.bind[n.bind.id]||(this.store.bind[n.bind.id]=[]),this.store.bind[n.bind.id].push({id:t.id,key:n.key});const r=n.productId||t.productId,s=n.deviceId||t.deviceId,a=n.propertyId;if(r&&s&&a){const l=this.jetLinksList.findIndex(c=>c.topic.startsWith(`/${r}/${s}`));l>-1?this.jetLinksList[l].properties.includes(n.propertyId)||this.jetLinksList[l].properties.push(n.propertyId):this.jetLinksList.push({topic:`/${r}/${s}`,deviceId:s,properties:[n.propertyId]})}}})})}connectSocket(){this.connectWebsocket(),this.connectMqtt(),this.connectHttp()}doInitJS(){const t=this.store.data.initJs;if(t&&t.trim())try{new Function("context",t)({meta2d:this})}catch(i){console.warn("initJs error",i)}}doInitFn(){let t=Il(),i=[];for(let n in t)t.hasOwnProperty(n)&&n.startsWith("bind-")&&i.push({id:n.replace("bind-",""),dataId:n.replace("bind-",""),value:t[n]});i.length&&this.setDatas(i,{history:!1})}drawLine(t){t&&ng(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 n;i.externElement===!0&&(n=i.calculative.singleton)!=null&&n.div&&ti(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 n=le(t),r=qt(t);n.prev=void 0,n.next=void 0,r.prev=void 0,r.next=void 0,t.calculative.worldAnchors=[n,r],t.calculative.activeAnchor=n,this.canvas[i](this.store,t,r),t.lineName==="curve"&&(n.prev={penId:n.penId,x:n.x-50,y:n.y},n.next={penId:n.penId,x:n.x+50,y:n.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 n;for(const r of this.store.data.pens)(n=r.onDestroy)==null||n.call(r,r);D_(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}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,n=!0){this.canvas.setPenRect(t,i,n)}startAnimate(t,i){this.stopAnimate(t);let n;t?typeof t=="string"?n=this.find(t):n=t:n=this.store.data.pens.filter(r=>(r.type||r.frames)&&r.autoPlay||r.animations&&r.animations.length&&r.animations.findIndex(s=>s.autoPlay)!==-1),n.length&&(n.forEach(r=>{var s,a;if(r.calculative.pause){const l=Date.now()-r.calculative.pause;r.calculative.pause=void 0,r.calculative.frameStart+=l,r.calculative.frameEnd+=l}else{let l=-1;if(i!==void 0&&r.animations){if(typeof i=="string"){if(l=r.animations.findIndex(c=>c.name===i),l===-1)return}else if(typeof i=="number")if(r.animations.length>i)l=i;else return}else i===void 0&&(l=(s=r.animations)==null?void 0:s.findIndex(c=>c.autoPlay),l===-1&&((a=r.animations)==null?void 0:a.length)&&(l=0));if(l!==-1&&l!==void 0){const c=ct(r.animations[l]);c.animateName=c.name,delete c.name,c.currentAnimation=l,!r.type&&c.frames&&(c.showDuration=this.calcAnimateDuration(c)),this.setValue({id:r.id,...c},{doEvent:!1,history:!1})}this.store.animates.add(r),r.type||this.store.animateMap.set(r,r.calculative.canvas.getFrameProps(r))}}),this.initImageCanvas(n),this.canvas.animate())}pauseAnimate(t){let i=[];t?typeof t=="string"?i=this.find(t):i=t:this.store.animates.forEach(n=>{i.push(n)}),i.forEach(n=>{n.calculative.pause||(n.calculative.pause=Date.now())})}stopAnimate(t){let i=[];t?typeof t=="string"?i=this.find(t):i=t:this.store.animates.forEach(n=>{i.push(n)}),i.forEach(n=>{n.currentAnimation=void 0,n.calculative.pause=void 0,n.calculative.start=void 0,n.calculative.duration=void 0,n.calculative.animatePos=0,this.store.animates.delete(n),this.canvas.restoreNodeAnimate(n),this.canvas.updateLines(n),this.store.animateMap.delete(n)}),this.initImageCanvas(i),setTimeout(()=>{var n;(n=this.canvas)==null||n.calcActiveRect(),this.render()},20)}startVideo(t){let i;t?typeof t=="string"?i=this.find(t):i=t:i=this.store.data.pens.filter(n=>(n.video||n.audio)&&n.autoPlay),i.forEach(n=>{var r,s;(r=n.calculative.media)==null||r.play(),(s=n.onStartVideo)==null||s.call(n,n)})}pauseVideo(t){let i=[];t?typeof t=="string"?i=this.find(t):i=t:i=this.store.data.pens.filter(n=>(n.video||n.audio)&&n.autoPlay),i.forEach(n=>{var r,s;(r=n.calculative.media)==null||r.pause(),(s=n.onPauseVideo)==null||s.call(n,n)})}stopVideo(t){let i=[];t?typeof t=="string"?i=this.find(t):i=t:i=this.store.data.pens.filter(n=>(n.video||n.audio)&&n.autoPlay),i.forEach(n=>{var r;n.calculative.media&&(n.calculative.media.currentTime=0,n.calculative.media.pause()),(r=n.onStopVideo)==null||r.call(n,n)})}calcAnimateDuration(t){return t.frames.reduce((i,n)=>i+n.duration,0)}combine(t=this.store.active,i){if(!t||!t.length)return;const n=ct(t);if(t.length===1&&t[0].type){t[0].type=jt.Node,this.canvas.active(t),this.pushHistory({type:bt.Update,initPens:n,pens:ct(t,!0)}),this.render();return}const r=pi(t);let s={id:It(),name:"combine",...r,children:[],showChild:i};this.canvas.makePen(s);const a=ct(s);let l=1/0;return t.forEach(c=>{var d;const u=this.store.data.pens.findIndex(g=>g.id===c.id);if(u{Gi(c,!0)}),this.initImageCanvas([s])),this.store.emitter.emit("combine",[s]),this.render(),s}uncombine(t){if(!t&&this.store.active&&(t=this.store.active[0]),!t||!t.children)return;const i=t.children.map(s=>this.store.pens[s]);let n=ct(i);i.forEach(s=>{s.parentId=void 0,s.x=s.calculative.worldRect.x,s.y=s.calculative.worldRect.y,s.width=s.calculative.worldRect.width,s.height=s.calculative.worldRect.height,s.locked=Ot.None,s.calculative.active=void 0,s.calculative.hover=!1,this.setVisible(s,!0)});const r=this.isCombine(t)?3:2;this.pushHistory({type:bt.Update,initPens:n,pens:i,step:r}),n=[ct(t)],t.children=void 0,this.pushHistory({type:bt.Update,initPens:n,pens:[t],step:r}),this.isCombine(t)&&(this.delete([t]),this.store.histories[this.store.histories.length-1].step=r),this.inactive()}appendChild(t=this.store.active){if(!t||t.length<2)return;const i=t.findIndex(n=>n.name==="combine"&&n.showChild!==void 0);if(i!==-1){let n=t[i];const r=pi(t);Object.assign(n,r),Object.assign(n.calculative.worldRect,r),Ir(n),n.children.forEach(s=>{const a=this.store.pens[s],l=mn(a.calculative.worldRect,r);Object.assign(a,l)}),t.forEach(s=>{var a;if(s.id!==n.id){n.children.push(s.id),s.parentId=n.id;const l=mn(s.calculative.worldRect,r);Object.assign(s,l),s.locked=(a=s.lockedOnCombine)!=null?a:Ot.DisableMove,s.locked=s.interaction||Tl.includes(s.name)?0:s.locked,Gi(s,!0)}}),this.initImageCanvas(t),this.render()}else console.warn("Invalid operation!")}updateRectbyChild(t,i,n){if(ae(t),ee(t),i.calculative.worldRect=t,Ji(t,n.calculative.worldRect,!0)){const r=mn(t,n.calculative.worldRect);Object.assign(i,r)}else{let r=Math.min(t.x,n.calculative.worldRect.x),s=Math.min(t.y,n.calculative.worldRect.y),a=Math.max(t.ex,n.calculative.worldRect.ex),l=Math.max(t.ey,n.calculative.worldRect.ey);n.calculative.worldRect={x:r,y:s,width:a-r,height:l-s,ex:a,ey:l},n.parentId||Object.assign(n,n.calculative.worldRect),ee(n.calculative.worldRect),n.children.forEach(c=>{const u=this.store.pens[c],h=mn(u.calculative.worldRect,n.calculative.worldRect);Object.assign(u,h)}),n.parentId&&this.updateRectbyChild(n.calculative.worldRect,n,this.store.pens[n.parentId])}this.canvas.updatePenRect(n),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!==Ot.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,n=!0){this.canvas.delete(t,i,n)}scale(t,i={x:0,y:0}){this.canvas.scale(t,i)}translate(t,i){this.canvas.translate(t,i)}translatePens(t,i,n){this.canvas.translatePens(t,i,n)}getParent(t,i){return Ze(t,i)}getAllChildren(t){return Ci(t,this.store)}getAllFollowers(t){return Bc(t,this.store)}data(){const t=ct(this.store.data),{pens:i,paths:n}=this.store.data;t.version=kv.version,t.paths={};for(const r in n)Object.prototype.hasOwnProperty.call(n,r)&&i.find(s=>s.pathId===r)&&(t.paths[r]=n[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=It());const i={...this.store.data.mqttOptions};i.username||delete i.username,i.password||delete i.password;const{username:n,password:r}=i;n&&r||!n&&!r?(this.mqttClient=ss.exports.connect(this.store.data.mqtt,i),this.mqttClient.on("message",(s,a)=>{this.socketCallback(a.toString(),{topic:s,type:"mqtt",url:this.store.data.mqtt})}),this.mqttClient.on("error",s=>{this.store.emitter.emit("error",{type:"mqtt",error:s})}),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("\u7F3A\u5C11\u7528\u6237\u540D\u6216\u5BC6\u7801")}}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,n)=>{i.http&&(i.times=0,this.httpTimerList[n]=setInterval(async()=>{this.oldRequestHttp(i),this.store.options.reconnetTimes&&(i.times++,i.times>=this.store.options.reconnetTimes&&(i.times=0,clearInterval(this.httpTimerList[n]),this.httpTimerList[n]=void 0))},i.httpTimeInterval||1e3))});else{const{http:i,httpTimeInterval:n,httpHeaders:r}=this.store.data;i&&(this.httpTimer=setInterval(async()=>{const s=await fetch(i,{headers:r});if(s.ok){const a=await s.text();this.socketCallback(a,{type:"http",url:i})}},n||1e3))}}async oldRequestHttp(t){let i=ct(t);if(i.http){const n=await fetch(i.http,{headers:i.httpHeaders,method:i.method||"GET",body:i.method==="POST"?JSON.stringify(i.body):void 0});if(n.ok){const r=await n.text();this.socketCallback(r,{type:"http",url:i.http})}else this.store.emitter.emit("error",{type:"http",error:n})}}async sendDatabyHttp(t){const{https:i}=this.store.data;if(i)i.forEach(async n=>{n.http&&(await fetch(n.http,{method:"post",body:t,headers:n.httpHeaders})).ok&&console.info("http\u6D88\u606F\u53D1\u9001\u6210\u529F")});else{const{http:n,httpHeaders:r}=this.store.data;n&&(await fetch(n,{method:"post",body:t,headers:r})).ok&&console.info("http\u6D88\u606F\u53D1\u9001\u6210\u529F")}}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 n=0;this.mqttClients=[];let r=0,s=0;this.websockets=[],t.forEach(async a=>{if(a.protocol==="mqtt")a.index=n,a.options.clientId&&!a.options.customClientId&&(a.options.clientId=It()),a.times=0,this.mqttClients[n]=ss.exports.connect(a.url,a.options),this.mqttClients[n].on("message",(l,c)=>{this.socketCallback(c.toString(),{topic:l,type:"mqtt",url:a.url})}),this.mqttClients[n].on("error",l=>{this.store.emitter.emit("error",{type:"mqtt",error:l})}),this.mqttClients[n].on("close",()=>{var l;this.store.options.reconnetTimes&&(a.times++,a.times>=this.store.options.reconnetTimes&&(a.times=0,this.mqttClients&&((l=this.mqttClients[a.index])==null||l.end())))}),a.topics&&this.mqttClients[n].subscribe(a.topics.split(",")),n+=1;else if(a.protocol==="websocket")a.index=r,this.connectNetWebSocket(a),r+=1;else if(a.protocol==="http")i.push({url:a.url,interval:a.interval,headers:a.headers||void 0,method:a.method,body:a.body});else if(a.protocol==="iot"){const l=await this.getIotToken(a.devices);a.method==="mqtt"?(a.index=n,this.mqttClients[n]=ss.exports.connect(a.url),this.mqttClients[n].on("message",(c,u)=>{this.socketCallback(u.toString(),{topic:`le5le-iot/properties/${l}`,type:"iot",url:a.url,method:"mqtt"})}),this.mqttClients[n].on("error",c=>{this.store.emitter.emit("error",{type:"mqtt",error:c})}),this.mqttClients[n].subscribe(`le5le-iot/properties/${l}`),n+=1):a.method==="websocket"&&(a.index=r,this.websockets[r]=new WebSocket(`${location.protocol==="https:"?"wss":"ws"}://${location.host}/api/ws/iot/properties`,l),this.websockets[r].onmessage=c=>{this.socketCallback(c.data,{type:"iot",method:"websocket"})},this.websockets[r].onerror=c=>{this.store.emitter.emit("error",{type:"websocket",error:c})},r+=1)}else a.protocol==="sql"?(await this.doSqlCode("list",a.dbId,a.sql),a.interval&&(a.index=s,this.sqlTimerList[s]=setInterval(async()=>{await this.doSqlCode("list",a.dbId,a.sql)},a.interval),s+=1)):a.protocol==="jetLinks"&&this.jetLinksList.length&&(this.jetLinksClient=new WebSocket(`${a.url}/${localStorage.getItem("X-Access-Token")||this.getCookie("X-Access-Token")||new URLSearchParams(location.search).get("X-Access-Token")||""}`),this.jetLinksClient.onmessage=l=>{var u;const c=JSON.parse(l.data);if(c.payload&&c.payload.success&&((u=c.payload)==null?void 0:u.properties)){const h=[];for(let d in c.payload.properties)d.startsWith("_")||h.push({id:`${c.payload.headers.productId}#${c.payload.deviceId}#${d}`,value:c.payload.properties[d]});this.setDatas(h,{history:!1})}},this.jetLinksClient.onopen=()=>{this.jetLinksList.forEach(l=>{this.jetLinksClient.send(JSON.stringify({type:"sub",topic:`/device${l.topic}/message/property/report`,parameter:{deviceId:l.deviceId,properties:l.properties,history:1},id:l.topic+"-"+It()}))})})})}this.onNetworkConnect(i)}connectNetWebSocket(t){var i;this.websockets[t.index]&&(this.websockets[t.index].onclose=void 0,(i=this.websockets[t.index])==null||i.close(),this.websockets[t.index]=void 0),this.websockets[t.index]=new WebSocket(t.url,t.protocols||void 0),this.websockets[t.index].onmessage=n=>{this.socketCallback(n.data,{type:"websocket",url:t.url})},this.websockets[t.index].onerror=n=>{this.store.emitter.emit("error",{type:"websocket",error:n})},this.websockets[t.index].onclose=()=>{var n;if(this.store.options.reconnetTimes&&(t.times++,t.times>=this.store.options.reconnetTimes)){t.times=0,this.websockets[t.index].onclose=void 0,(n=this.websockets[t.index])==null||n.close(),this.websockets[t.index]=void 0;return}setTimeout(()=>{console.info("Canvas websocket closed and reconneting..."),this.connectNetWebSocket(t)},2e3)}}async getIotToken(t){const i=await fetch("/api/iot/subscribe/properties",{method:"POST",body:JSON.stringify({devices:t})});if(i.ok){const n=await i.text();return JSON.parse(n).token}}async doSqlCode(t,i,n){const r=await fetch(`/api/iot/data/sql/${t}`,{method:"POST",body:JSON.stringify({dbid:i,sql:n})});if(r.ok){const s=await r.text();s&&this.socketCallback(s,{type:"sql",url:`/api/iot/data/sql/${t}`})}}randomString(t){t=t||32;let i="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",n=i.length,r="";for(let s=0;s{let s=this.mockValue(r);s!==void 0&&t.push({id:r.id,value:s})}),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.dataMock(),this.render()},this.store.data.networkInterval||1e3))}stopDataMock(){clearInterval(this.updateTimer),this.updateTimer=void 0}penMock(t){var i;if(t.realTimes){let n={};if(t.realTimes.forEach(r=>{let s=this.mockValue(r);s!==void 0&&(n[r.key]=s)}),Object.keys(n).length){let r=t.onBeforeValue?t.onBeforeValue(t,n):n;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]}getCookie(t){let i;const n=new RegExp("(^| )"+t+"=([^;]*)(;|$)");return(i=document.cookie.match(n))?decodeURIComponent(i[2]):""}getDynamicParam(t){return Il()[t]||localStorage[t]||this.getCookie(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=>{this.requestHttp(i)}),t.forEach((i,n)=>{i.times=0,this.updateTimerList[n]=setInterval(async()=>{this.requestHttp(i),this.store.options.reconnetTimes&&(i.times++,i.times>=this.store.options.reconnetTimes&&(i.times=0,clearInterval(this.updateTimerList[n]),this.updateTimerList[n]=void 0))},i.interval||1e3)})}}async requestHttp(t){let i=ct(t);if(i.url){if(typeof i.headers=="object"){for(let r in i.headers)if(typeof i.headers[r]=="string"){let s=i.headers[r].match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));s&&(i.headers[r]=i.headers[r].replace(`\${${s[0]}}`,this.getDynamicParam(s[0])))}}if(typeof i.body=="object"){for(let r in i.body)if(typeof i.body[r]=="string"){let s=i.body[r].match(new RegExp("(?<=\\$\\{).*?(?=\\})","g"));s&&(i.body[r]=i.body[r].replace(`\${${s[0]}}`,this.getDynamicParam(s[0])))}}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 r=await n.text();this.socketCallback(r,{type:"http",url:i.url})}else 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})}socketCallback(t,i){this.store.emitter.emit("socket",{message:t,context:i});let n=t;if(this.socketFn&&(n=this.socketFn(t,{meta2d:this,type:i.type,topic:i.topic,url:i.url,method:i.method}),!n))return;n===!0&&(n=t);let r;if(n.constructor===Object||n.constructor===Array)r=n;else if(typeof n=="string")try{r=JSON.parse(n)}catch(s){console.warn("Invalid socket data:",r,s)}else return;!r||(Array.isArray(r)||(r=[r]),r.length&&(r[0].dataId?this.setDatas(r):r.forEach(s=>{this.setValue(s)})))}setDatas(t,{render:i=!0,doEvent:n=!0,history:r}={}){const s=new Map;t.forEach(c=>{var u,h;(u=this.store.bindDatas[c.dataId])==null||u.forEach(d=>{const g=this.store.pens[d.id];if(!g)return;let v=s.get(g);if(!g.noOnBinds&&typeof g.onBinds=="function"){if(v)return;s.set(g,g.onBinds(g,t,d.formItem));return}v?v[d.formItem.key]=c.value:(v={id:d.id,[d.formItem.key]:c.value},s.set(g,v))}),(h=this.store.bind[c.id||c.dataId])==null||h.forEach(d=>{const g=this.store.pens[d.id];if(!g)return;let v=s.get(g);v?v[d.key]=c.value:(v={id:d.id,[d.key]:c.value},s.set(g,v))})}),this.store.data.locked&&this.doDataEvent(t);let a,l;r&&(a=[]),s.forEach((c,u)=>{this.setValue(c,{render:!1,doEvent:n,history:!1}),r&&(a.push(ct(u,!0)),l.push(u))}),i&&this.render(),r&&this.pushHistory({type:bt.Update,initPens:a,pens:l})}setValue(t,{render:i=!0,doEvent:n=!0,history:r}={}){let s=[];if(!t)return;if(t.id){if(t.id===this.store.data.id){this.setDatabyOptions(t),t.bkImage&&this.setBackgroundImage(t.bkImage),t.background&&this.setBackgroundColor(t.background),this.render();return}const l=this.store.pens[t.id];if(l)s=[l];else{let c=this.store.bind[t.id];if(c&&c.length){s=[],this.setDatas([t],{render:i,doEvent:n,history:r});return}}}else if(t.dataId){s=[],this.setDatas([t],{render:i,doEvent:n,history:r});return}else if(t.tag)s=this.find(t.tag);else{let l=[];for(let c in t)l.push({dataId:c,id:c,value:t[c]});l.length&&this.setDatas(l,{render:i,doEvent:n,history:r});return}r=r&&!this.store.data.locked;let a;if(r&&(a=ct(s)),s.forEach(l=>{var u;const c=l.onBeforeValue?l.onBeforeValue(l,t):t;t.frames&&(this.stopAnimate([l]),t.showDuration||(t.showDuration=t.frames.reduce((h,d)=>h+d.duration,0))),Hc(l,c),this.canvas.updateValue(l,c),(u=l.onValue)==null||u.call(l,l)}),!this.store.data.locked&&this.store.active.length&&!this.canvas.movingPens&&this.canvas.calcActiveRect(),r){let l=ct(s);this.pushHistory({type:bt.Update,initPens:a,pens:l})}n&&s.forEach(l=>{this.store.emitter.emit("valueUpdate",l)}),i&&this.render()}_setValue(t,i=!1){this.setValue(t,{history:i,render:!1,doEvent:!1})}pushHistory(t){this.canvas.pushHistory(t)}showInput(t,i){this.canvas.showInput(t,i)}hideInput(){this.canvas.hideInput()}clearDropdownList(){this.canvas.clearDropdownList()}clearRuleLines(){this.canvas.clearRuleLines()}doMessageEvent(t,i){this.store.messageEvents[t]&&this.store.messageEvents[t].forEach(n=>{let r=!1;n.event.conditions&&n.event.conditions.length?n.event.conditionType==="and"?r=n.event.conditions.every(s=>this.judgeCondition(n.pen,s.key,s)):n.event.conditionType==="or"&&(r=n.event.conditions.some(s=>this.judgeCondition(n.pen,s.key,s))):r=!0,r&&n.event.actions.forEach(s=>{this.events[s.action](n.pen,s)})})}initGlobalTriggers(){var t;this.store.globalTriggers={},(t=this.store.data.triggers)==null||t.forEach(i=>{i.conditions.forEach(n=>{n.source&&(this.store.globalTriggers[n.source]||(this.store.globalTriggers[n.source]=[]),this.store.globalTriggers[n.source].includes(i)||this.store.globalTriggers[n.source].push(i))})})}initMessageEvents(){this.store.messageEvents={},this.store.data.pens.forEach(t=>{var i;(i=t.events)==null||i.forEach(n=>{n.name==="message"&&n.message&&(this.store.messageEvents[n.message]||(this.store.messageEvents[n.message]=[]),this.store.messageEvents[n.message].push({pen:t,event:n}))})})}dataJudegeCondition(t,i,n){const{type:r,target:s,fnJs:a,fn:l,operator:c,valueType:u}=n;let h=!1;if(r==="fn"){if(l)h=l(t,{meta2d:this});else if(a){try{n.fn=new Function("data","context",a)}catch(d){console.error("Error: make function:",d)}n.fn&&(h=n.fn(t,{meta2d:this}))}}else{let d=n.value;u==="prop"&&(d=t[n.value]);let g=t[i];switch(c){case">":h=g>+d;break;case">=":h=g>=+d;break;case"<":h=g<+d;break;case"<=":h=g<=+d;break;case"=":case"==":h=g==d;break;case"!=":h=g!=d;break;case"[)":h=pr(+g,d);break;case"![)":h=!pr(+g,d);break;case"[]":h=wr(g,d);break;case"![]":h=!wr(g,d);break}}return h}judgeCondition(t,i,n){const{type:r,target:s,fnJs:a,fn:l,operator:c,valueType:u}=n;let h=!1;if(r==="fn"){if(l)h=l(t,{meta2d:this});else if(a){try{n.fn=new Function("pen","context",a)}catch(d){console.error("Error: make function:",d)}n.fn&&(h=n.fn(t,{meta2d:this}))}}else{let d=n.value;u==="prop"&&(d=this.store.pens[s][n.value]);let g=Nf(t,i);switch(["x","y","width","height"].includes(i)&&(g=this.getPenRect(t)[i]),c){case">":h=g>+d;break;case">=":h=g>=+d;break;case"<":h=g<+d;break;case"<=":h=g<=+d;break;case"=":case"==":h=g==d;break;case"!=":h=g!=d;break;case"[)":h=pr(+g,d);break;case"![)":h=!pr(+g,d);break;case"[]":h=wr(g,d);break;case"![]":h=!wr(g,d);break}}return h}pushChildren(t,i){const n=[ct(t,!0)],r=[];t.children||(t.children=[]);const s=[];i.forEach(l=>{var h;let c=ct(l,!0);if((!l.id||!this.store.pens[l.id])&&(this.canvas.makePen(l),c=null),l.parentId){const d=this.store.pens[l.parentId],g=d.children.findIndex(v=>v===l.id);n.push(ct(d,!0)),d.children.splice(g,1),s.push(ct(d,!0))}t.children.push(l.id),l.parentId=t.id;const u=mn(l.calculative.worldRect,t.calculative.worldRect);Object.assign(l,u),l.locked=(h=l.lockedOnCombine)!=null?h:Ot.DisableMove,l.locked=l.interaction||Tl.includes(l.name)?0:l.locked,c?(n.push(c),s.push(ct(l,!0))):r.push(ct(l,!0))}),s.push(ct(t,!0));let a=1;r.length&&(a=2,this.pushHistory({type:bt.Add,pens:r,step:a})),this.pushHistory({type:bt.Update,initPens:n,pens:s,step:a})}toPng(t,i,n=!1,r){return this.canvas.toPng(t,i,n,r)}activeToPng(t,i){return this.canvas.activeToPng(t,i)}pensToPng(t=this.store.active,i,n){return this.canvas.pensToPng(t,i,n)}downloadPng(t,i,n){var r;for(const s of this.store.data.pens)(s.calculative.img||["iframe"].includes(s.name))&&((r=s.onRenderPenRaw)==null||r.call(s,s));setTimeout(()=>{const s=document.createElement("a");s.setAttribute("download",(t||this.store.data.name||"le5le.meta2d")+".png"),s.setAttribute("href",this.toPng(i,void 0,!0,n));const a=document.createEvent("MouseEvents");a.initEvent("click",!0,!0),s.dispatchEvent(a)},1e3)}downloadSvg(){if(!window.C2S)throw console.error("\u8BF7\u5148\u52A0\u8F7D\u4E50\u543E\u4E50\u5B98\u7F51\u4E0B\u7684canvas2svg.js","https://assets.le5lecdn.com/2d/canvas2svg.js"),new Error("\u8BF7\u5148\u52A0\u8F7D\u4E50\u543E\u4E50\u5B98\u7F51\u4E0B\u7684canvas2svg.js");const t=this.getRect();t.x-=10,t.y-=10;const i=new window.C2S(t.width+20,t.height+20);i.textBaseline="middle";for(const u of this.store.data.pens)u.visible==!1||!Va(u,this.store)||ja(i,u,t,!0);let n=i.getSerializedSvg();this.store.data.background?(n=n.replace("{{bk}}",""),n=n.replace("{{bkRect}}",``)):(n=n.replace("{{bk}}",""),n=n.replace("{{bkRect}}","")),n=n.replace(/--le5le--/g,"&#x");const r=window.URL,s=new Blob([n]),a=r.createObjectURL(s),l=document.createElement("a");l.setAttribute("download",`${this.store.data.name||"le5le.meta2d"}.svg`),l.setAttribute("href",a);const c=document.createEvent("MouseEvents");c.initEvent("click",!0,!0),l.dispatchEvent(c)}getRect(t=this.store.data.pens){return pi(t)}hiddenTemplate(){this.canvas.canvasTemplate.hidden()}showTemplate(){this.canvas.canvasTemplate.show()}lockTemplate(t){this.store.data.pens.forEach(i=>{i.canvasLayer===zt.CanvasTemplate&&(i.locked=t)})}fitView(t=!0,i=10){var d,g;if(!this.hasView())return;const{canvas:n}=this.canvas,{offsetWidth:r,offsetHeight:s}=n;this.resize(r,s);const a=Xi(i),l=this.getRect(),c=(r-a[1]-a[3])/l.width,u=(s-a[0]-a[2])/l.height;let h=c;t?h=c>u?u:c:h=c>u?c:u,(d=this.store.data.fits)!=null&&d.length&&(this.canvas.opening=!0),this.scale(h*this.store.data.scale),this.centerView(),(g=this.store.data.fits)!=null&&g.length&&this.fillView()}fillView(){var r,s;const t=this.getRect(),i=this.canvas.width-t.width,n=this.canvas.height-t.height;if(Math.abs(i)>10){(r=this.store.data.fits)==null||r.forEach(l=>{let c=[];l.children.forEach(h=>{this.store.pens[h].locked=Ot.None,c.push(this.store.pens[h])});let u=i/2;if(l.left&&l.right){let h=l.leftValue,d=l.rightValue;h?h=Math.abs(h)<1?h*this.canvas.width:h:h=0,d?d=Math.abs(d)<1?d*this.canvas.width:d:d=0;let g=(this.canvas.width-h-d)/(t.width-h-d);c.forEach(v=>{var y;v.image&&v.imageRatio&&v.calculative.worldRect.width/this.canvas.width>.1&&(v.imageRatio=!1),v.calculative.worldRect.x=t.x-i/2+h+(v.calculative.worldRect.x-t.x)*g,v.calculative.worldRect.width*=g,v.calculative.worldRect.ex=v.calculative.worldRect.x+v.calculative.worldRect.width,v.calculative.width=v.calculative.worldRect.width,v.calculative.x=v.calculative.worldRect.x,v.width=v.calculative.worldRect.width,v.x=v.calculative.worldRect.x,this.canvas.updatePenRect(v,{worldRectIsReady:!1}),v.externElement&&((y=v.onResize)==null||y.call(v,v))})}else l.left?(u=-u,l.leftValue&&(u+=Math.abs(l.leftValue)<1?l.leftValue*this.canvas.width:l.leftValue),this.translatePens(c,u,0)):l.right&&(l.rightValue&&(u=u-(Math.abs(l.rightValue)<1?l.rightValue*this.canvas.width:l.rightValue)),this.translatePens(c,u,0))});const a=this.store.data.pens.filter(l=>l.name==="iframe");a==null||a.forEach(l=>{var u,h;const c=l.calculative.worldRect;if(c.width/this.store.data.scale>t.width*.8){let d=c.width;l.calculative.worldRect.x=c.x-i/2,l.calculative.worldRect.width=c.width+i,l.calculative.worldRect.ex=c.ex+i,l.operationalRect.x=l.operationalRect.x*d/l.calculative.worldRect.width,l.operationalRect.width=(l.calculative.worldRect.width-(1-l.operationalRect.width)*d)/l.calculative.worldRect.width,(u=l.onBeforeValue)==null||u.call(l,l,{operationalRect:l.operationalRect}),(h=l.onResize)==null||h.call(l,l)}})}if(Math.abs(n)>10){(s=this.store.data.fits)==null||s.forEach(l=>{let c=[];l.children.forEach(h=>{this.store.pens[h].locked=Ot.None,c.push(this.store.pens[h])});let u=n/2;if(l.top&&l.bottom){let h=l.topValue,d=l.bottomValue;h?h=Math.abs(h)<1?h*this.canvas.height:h:h=0,d?d=Math.abs(d)<1?d*this.canvas.height:d:d=0;let g=(this.canvas.height-h-d)/(t.height-h-d);c.forEach(v=>{var y;v.image&&v.imageRatio&&v.calculative.worldRect.height/this.canvas.height>.1&&(v.imageRatio=!1),v.calculative.worldRect.y=t.y-n/2+h+(v.calculative.worldRect.y-t.y)*g,v.calculative.worldRect.height*=g,v.calculative.worldRect.ey=v.calculative.worldRect.y+v.calculative.worldRect.height,v.calculative.height=v.calculative.worldRect.height,v.calculative.y=v.calculative.worldRect.y,v.height=v.calculative.worldRect.height,v.y=v.calculative.worldRect.y,this.canvas.updatePenRect(v,{worldRectIsReady:!1}),v.externElement&&((y=v.onResize)==null||y.call(v,v))})}else l.top?(u=-u,l.topValue&&(u+=Math.abs(l.topValue)<1?l.topValue*this.canvas.height:l.topValue),this.translatePens(c,0,u)):l.bottom&&(l.bottomValue&&(u=u-(Math.abs(l.bottomValue)<1?l.bottomValue*this.canvas.height:l.bottomValue)),this.translatePens(c,0,u))});const a=this.store.data.pens.filter(l=>l.name==="iframe");a==null||a.forEach(l=>{var u,h;const c=l.calculative.worldRect;if(c.height/this.store.data.scale>t.height*.8){let d=c.height;l.calculative.worldRect.y=c.y-n/2,l.calculative.worldRect.height=c.height+n,l.calculative.worldRect.ey=c.ey+n,l.operationalRect.y=l.operationalRect.y*d/l.calculative.worldRect.width,l.operationalRect.height=(l.calculative.worldRect.height-(1-l.operationalRect.height)*d)/l.calculative.worldRect.height,(u=l.onBeforeValue)==null||u.call(l,l,{operationalRect:l.operationalRect}),(h=l.onResize)==null||h.call(l,l)}})}this.canvas.canvasTemplate.init(),this.canvas.canvasImage.init(),this.canvas.canvasImageBottom.init(),this.render(!0)}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:n}=this.canvas,{offsetWidth:r,offsetHeight:s}=n,a=Xi(i),l=this.getRect(),c=(r-a[1]-a[3])/l.width,u=(s-a[0]-a[2])/l.height;let h=c;t?h=c>u?u:c:h=c>u?c:u,this.canvas.templateScale(h*this.store.data.scale);let d=this.getRect(),g=this.store.data.pens.filter(v=>!v.parentId);this.canvas.templateTranslatePens(g,-d.x,-d.y),this.store.data.pens.forEach(v=>{v.type?this.canvas.initLineRect(v):this.canvas.updateLines(v)}),this.centerView()}fitSizeView(t=!0,i=10){var g,v;const{canvas:n}=this.canvas,{offsetWidth:r,offsetHeight:s}=n;this.resize(r,s);const a=Xi(i),l=(this.store.data.width||this.store.options.width)*this.store.data.scale,c=(this.store.data.height||this.store.options.height)*this.store.data.scale,u=(r-a[1]-a[3])/l,h=(s-a[0]-a[2])/c;let d=u;t==="width"?d=u:t==="height"?d=h:t?d=u>h?h:u:d=u>h?u:h,(g=this.store.data.fits)!=null&&g.length&&(this.canvas.opening=!0),this.scale(d*this.store.data.scale),this.centerSizeView(),(v=this.store.data.fits)!=null&&v.length&&this.fillView()}centerSizeView(){const t=this.getViewCenter(),i=this.store.data.width||this.store.options.width,n=this.store.data.height||this.store.options.height,r={x:0,y:0,width:i,height:n};ee(r);const{center:s}=r,{scale:a,origin:l,x:c,y:u}=this.store.data;this.translate((t.x-l.x)/a-s.x-c/a,(t.y-l.y)/a-s.y-u/a);const{canvas:h}=this.canvas,d=(h.scrollWidth-h.offsetWidth)/2,g=(h.scrollHeight-h.offsetHeight)/2;h.scrollTo(d,g)}scrollView(t=10,i=!1){if(!this.hasView()||!this.canvas.scroll)return;const{canvas:n}=this.canvas,{offsetWidth:r,offsetHeight:s}=n;this.resize(r,s);const a=Xi(t),l=this.getRect(),c=(r-a[1]-a[3])/l.width;this.scale(c*this.store.data.scale),this.topView(a[0]),i&&this.canvas.scroll.changeMode()}screenView(t=10,i=!0){if(!this.hasView())return;const{canvas:n}=this.canvas,{offsetWidth:r,offsetHeight:s}=n;this.resize(r,s);const a=Xi(t),l=this.getRect();let c=(r-a[1]-a[3])/l.width;i||(c=(s-a[0]-a[2])/l.height),this.scale(c*this.store.data.scale),this.topView(a[0])}topView(t=10){if(!this.hasView())return;const i=this.getRect(),n=this.getViewCenter(),r=this.getPenRect(i);ee(r);const{center:s}=r,{scale:a,origin:l,x:c,y:u}=this.store.data;this.translate((n.x-l.x)/a-s.x-c/a,(t-l.y)/a-r.y-u/a);const{canvas:h}=this.canvas,d=(h.scrollWidth-h.offsetWidth)/2,g=(h.scrollHeight-h.offsetHeight)/2;h.scrollTo(d,g)}centerView(){if(!this.hasView())return;const t=this.getRect(),i=this.getViewCenter(),n=this.getPenRect(t);ee(n);const{center:r}=n,{scale:s,origin:a,x:l,y:c}=this.store.data;this.translate((i.x-a.x)/s-r.x-l/s,(i.y-a.y)/s-r.y-c/s);const{canvas:u}=this.canvas,h=(u.scrollWidth-u.offsetWidth)/2,d=(u.scrollHeight-u.offsetHeight)/2;u.scrollTo(h,d)}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 n=ct(t),r=t[0],{width:s,height:a}=this.getPenRect(r);for(let l=1;l{r[s]=n[s]});for(let s=1;s{r[s]=n[s]});for(let s=0;s0){const n=t[0];is.forEach(r=>{i[r]=n[r]!==void 0?n[r]:this.store.options.defaultFormat[r]||this.store.data[r]||this.store.options[r]})}else is.forEach(n=>{this.store.options.defaultFormat[n]||this.store.data[n]||this.store.options[n]});localStorage.setItem("meta2d-formatPainter",JSON.stringify(i))}formatPainter(){const t=this.store.active,i=ct(t),n=JSON.parse(localStorage.getItem("meta2d-formatPainter"));for(let r=0;r{for(let r=0;r{u=Math.min(u,g.calculative.worldRect[d]),h=Math.max(h,g.calculative.worldRect["e"+d])}),n=(h-u)/this.store.data.scale}if(i=i.filter(u=>!u.parentId),i.length<=2)return;const r=ct(i),s=i.reduce((u,h)=>{const d=this.getPenRect(h);return u+d[t]},0),a=(n-s)/(i.length-1);i=i.sort((u,h)=>t==="width"?u.x-h.x:u.y-h.y);const l=this.getPenRect(i[0]);let c=t==="width"?l.x:l.y;for(const u of i){const h=this.getPenRect(u);t==="width"?h.x=c:h.y=c,c+=h[t]+a,this.setValue({id:u.id,...h},{render:!1,doEvent:!1})}this.initImageCanvas(i),this.initTemplateCanvas(i),this.render(),this.pushHistory({type:bt.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,n=30){const r=this.getPenRect(pi(t));!i&&(i=r.width),t=t.filter(u=>!u.type&&!u.parentId);const s=ct(t);let a=0;t.forEach(u=>{const h=this.getPenRect(u);h.height>a&&(a=h.height)});let l=r.x,c=r.y;t.forEach((u,h)=>{const d=this.getPenRect(u);if(d.x=l,d.y=c+a/2-d.height/2,this.setValue({id:u.id,...d},{render:!1,doEvent:!1}),h===t.length-1)return;const g=l+d.width-r.x,v=this.getPenRect(t[h+1]);Math.round(i-g)>=Math.round(v.width+n)?l+=d.width+n:(l=r.x,c+=a+n)}),this.initImageCanvas(t),this.initTemplateCanvas(t),this.render(),this.pushHistory({type:bt.Update,initPens:s,pens:t})}gotoView(t){const i=this.getViewCenter(),n=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(n-this.store.data.x,r-this.store.data.y),this.store.data.x=n,this.store.data.y=r;for(const s of this.store.data.pens)Gi(s);this.canvas.canvasImage.init(),this.canvas.canvasImageBottom.init(),this.render()}showMap(){this.map||(this.map=new eE(this.canvas)),this.map.show()}hideMap(){this.map.hide()}onSizeUpdate(){this.mapTimer&&(clearTimeout(this.mapTimer),this.mapTimer=void 0),this.mapTimer=setTimeout(()=>{this.map&&this.map.isShow&&this.map.show(),this.canvas.scroll&&this.canvas.scroll.isShow&&this.canvas.scroll.resize()},500)}toggleAnchorMode(){this.canvas.toggleAnchorMode()}addAnchorHand(){this.canvas.addAnchorHand()}removeAnchorHand(){this.canvas.removeAnchorHand()}toggleAnchorHand(){this.canvas.toggleAnchorHand()}top(t){t||(t=this.store.active),Array.isArray(t)||(t=[t]);for(const i of t){const n=this.store.data.pens,r=[...Ci(i,this.store),i].map(a=>a.id);n.filter(a=>r.includes(a.id)).forEach(a=>{const l=n.findIndex(c=>c.id===a.id);l>-1&&(n.push(n[l]),n.splice(l,1),this.initTemplateCanvas([a]),this.initImageCanvas([a])),this.specificLayerMove(a,"top")})}this.store.emitter.emit("layer",{type:"top",pens:t})}initImageCanvas(t){this.canvas.initImageCanvas(t)}initTemplateCanvas(t){this.canvas.initTemplateCanvas(t)}bottom(t){t||(t=this.store.active),Array.isArray(t)||(t=[t]);for(const i of t){const n=this.store.data.pens,r=[...Ci(i,this.store),i].map(a=>a.id),s=n.filter(a=>r.includes(a.id));for(let a=s.length-1;a>=0;a--){const l=s[a],c=n.findIndex(u=>u.id===l.id);c>-1&&(n.unshift(n[c]),n.splice(c+1,1),this.initTemplateCanvas([l]),this.initImageCanvas([l])),this.specificLayerMove(l,"bottom")}}this.store.emitter.emit("layer",{type:"bottom",pens:t})}upByArea(t){if(this.store.data.pens.findIndex(c=>c.id===t.id)===-1){console.warn("upByArea: pen not in canvas");return}const n=[t,...Ci(t,this.store)];let r=n.map(c=>this.store.data.pens.findIndex(u=>u.id===c.id));r.includes(-1)&&(console.warn("upByArea: pen children not in canvas"),r=r.filter(c=>c!==-1));const s=Math.min(...r),a=t.calculative.worldRect,l=this.store.data.pens.findIndex((c,u)=>{if(u<=s||c.id===t.id||H_(c,t))return!1;const h=c.calculative.worldRect;return Ji(a,h)});if(l===-1){this.up(t);return}this.store.data.pens.splice(l+1,0,...n);for(const c of n){const u=this.store.data.pens.findIndex(h=>h.id===c.id);u>-1&&this.store.data.pens.splice(u,1)}this.initImageCanvas([t])}specificLayerMove(t,i){var n;if(t.image&&t.name!=="gif"){let r=zt.CanvasImageBottom;i==="top"?r=zt.CanvasImage:(i==="up"||i==="down")&&(r=zt.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}),(n=t.calculative.singleton)!=null&&n.div&&ti(t,t.calculative.singleton.div)}}up(t){t||(t=this.store.active),Array.isArray(t)||(t=[t]);for(const i of t){const n=this.store.data.pens;if(i.children&&i.children.length){const r=[...Ci(i,this.store),i],s=[];for(let c=0;ch.id===u.id)!==-1&&(u.temIndex=c,s.push(u))}let a=-1,l=0;s.forEach(c=>{c.temIndex-=l,n.splice(c.temIndex,1),l+=1,a=c.temIndex,delete c.temIndex,this.specificLayerMove(c,"up")}),n.splice(a+1,0,...s),this.initTemplateCanvas(s),this.initImageCanvas(s)}else{const r=n.findIndex(s=>s.id===i.id);r>-1&&r!==n.length-1&&(n.splice(r+2,0,n[r]),n.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 n=this.store.data.pens;if(i.children&&i.children.length){const r=[...Ci(i,this.store),i],s=[];for(let c=0;ch.id===u.id)!==-1&&(u.temIndex=c,s.push(u))}let a=-1,l=0;s.forEach((c,u)=>{c.temIndex-=l,n.splice(c.temIndex,1),l+=1,u===0&&(a=c.temIndex),delete c.temIndex,this.specificLayerMove(c,"down")}),n.splice(a-1,0,...s),this.initTemplateCanvas(s),this.initImageCanvas(s)}else{const r=n.findIndex(s=>s.id===i.id);r>-1&&r!==0&&(n.splice(r-1,0,n[r]),n.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,n=this.store.data.pens){const r=n.findIndex(s=>s.id===t.id);r>-1&&(r>i?(n.splice(i,0,n[r]),n.splice(r+1,1)):r{const a=this.store.pens[s];if(!a){console.warn(t,"node contain a error connectedLine");return}if(!n.find(l=>l.id===a.id))switch(i){case"all":n.push(a);break;case"in":qt(a).connectTo===t.id&&n.push(a);break;case"out":le(a).connectTo===t.id&&n.push(a);break}}),n}nextNode(t){if(t.type===jt.Line){const i=this.store.pens[qt(t).connectTo];return i?[i]:[]}else{const i=this.getLines(t,"out"),n=[];return i.forEach(r=>{const s=this.nextNode(r);for(const a of s)!n.find(c=>c.id===a.id)&&n.push(a)}),n}}previousNode(t){if(t.type===jt.Line){const i=this.store.pens[le(t).connectTo];return i?[i]:[]}else{const i=this.getLines(t,"in"),n=[];return i.forEach(r=>{const s=this.previousNode(r);for(const a of s)!n.find(c=>c.id===a.id)&&n.push(a)}),n}}getNext(t){var n;if(t.type===jt.Line){console.warn("\u975E\u8FDE\u7EBF\u8282\u70B9");return}const i=[];return(n=t.connectedLines)==null||n.forEach(({lineId:r,anchor:s})=>{var c,u;const a=(c=t.anchors)==null?void 0:c.filter(h=>h.id===s)[0],l=this.findOne(r);if(l.anchors[0].connectTo==t.id){const h=l.anchors[l.anchors.length-1].connectTo;if(h){const d=this.findOne(h),g=(u=d.connectedLines)==null?void 0:u.filter(y=>y.lineId===l.id)[0],v=d.anchors.filter(y=>y.id===g.anchor)[0];i.push({from:t,fromAnchor:a,line:l,to:d,toAnchor:v})}}}),i}addAnchor(t,i,n){if(!t)return;if(t.anchors||(t.anchors=[]),t.calculative.worldAnchors||(t.calculative.worldAnchors=[]),t.type===jt.Line&&(n<0&&(n=t.anchors.length+1+n),n>t.anchors.length&&(n=t.anchors.length),n<0&&(n=0),n==0&&t.anchors[0].connectTo||n==t.anchors.length&&t.anchors[n-1].connectTo)){console.warn("\u7AEF\u70B9\u5B58\u5728\u8FDE\u63A5\u5173\u7CFB");return}let r=null,s=null;i.x<=1&&i.x>=0&&i.y<=1&&i.y>=0?(s={id:i.id||It(),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&&Gt(s,t.rotate,t.calculative.worldRect.center),r={id:s.id,penId:t.id,x:i.x,y:i.y}):(s={id:i.id||It(),penId:t.id,x:i.x,y:i.y},t.calculative.worldRect&&(t.rotate%360&&Gt(i,-t.rotate,t.calculative.worldRect.center),r={id:s.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===jt.Line?(t.calculative.worldAnchors.splice(n,0,s),t.anchors.splice(n,0,r),this.canvas.updateLines(t),this.canvas.initLineRect(t),this.render()):(t.calculative.worldAnchors.push(s),t.anchors.push(r))}connectLine(t,i,n,r,s=!0){if(!n){const u=i.calculative.worldRect;n=Cr(t,{x:u.x+u.width/2,y:u.y+u.height/2})}if(!r){const u=t.calculative.worldRect;r=Cr(i,{x:u.x+u.width/2,y:u.y+u.height/2})}const a=Math.abs(n.x-r.x),c={height:Math.abs(n.y-r.y),lineName:"line",lineWidth:1,name:"line",type:1,width:a,x:Math.min(n.x,r.x),y:Math.min(n.y,r.y),anchors:[{x:n.x>r.x?1:0,y:n.y>r.y?1:0,id:It()},{x:n.x>r.x?0:1,y:n.x>r.x?0:1,id:It()}]};return this.addPens([c]),we(t,n,c,c.calculative.worldAnchors[0]),we(i,r,c,c.calculative.worldAnchors[1]),c.calculative.active=!1,this.canvas.updateLines(c),this.canvas.updateLines(t),this.canvas.updateLines(i),this.canvas.initLineRect(c),s&&this.render(),c}toComponent(t=this.store.data.pens,i,n){if(t.length===1){const h=ct(t[0]);return h.type=jt.Node,h.id=void 0,[h]}const r=ct(t,!0),s=pi(r);let a={id:It(),name:"combine",...s,children:[],showChild:i};n&&(a.anchors=[{id:"0",penId:a.id,x:.5,y:0},{id:"1",penId:a.id,x:1,y:.5},{id:"2",penId:a.id,x:.5,y:1},{id:"3",penId:a.id,x:0,y:.5}]);const l=r.filter(h=>!h.parentId),c=r.find(h=>h.width===s.width&&h.height===s.height),u=c&&i===void 0;return l.length===1?a=l[0]:u&&(c.children||(c.children=[]),a=c),r.forEach(h=>{var g;if(h===a||h.parentId===a.id||h.parentId)return;a.children.push(h.id),h.parentId=a.id;const d=mn(h.calculative.worldRect,s);Object.assign(h,d),h.locked=(g=h.lockedOnCombine)!=null?g:Ot.DisableMove}),u||l.length===1?ct(r):ct([a,...r])}installPenPlugins(t,i){if(!t.tag&&!t.name&&!t.id)return;let n;t.id?n="id":t.tag?n="tag":t.name&&(n="name"),i.forEach(r=>{let s=r.plugin,a=r.options;if(!!s&&_2(s)&&n)if(s.install(t,a),!this.penPluginMap.has(s))this.penPluginMap.set(s,[{[n]:t[n],option:a}]);else{let l=this.penPluginMap.get(s).find(c=>c[n]===t[n]);l?l.option=a:this.penPluginMap.get(s).push({[n]:t[n],option:a})}})}uninstallPenPlugins(t,i){let n;t.id?n="id":t.tag?n="tag":t.name&&(n="name"),n&&i.forEach(r=>{let s=r.plugin;s.uninstall(t,r.options);let a=this.penPluginMap.get(s),l=a.findIndex(c=>c[n]===t[n]);l!==-1&&(a.splice(l,1),a.length===0&&this.penPluginMap.delete(s))})}setVisible(t,i,n=!0){if(this.onSizeUpdate(),this.setValue({id:t.id,visible:i},{render:!1,doEvent:!1}),t.children)for(const s of t.children){const a=this.store.pens[s];a&&this.setVisible(a,i,!1)}let r=Ci(t,this.store);r.push(t),this.initImageCanvas(r),n&&this.render()}clearHover(){this.canvas.clearHover()}closeSocket(){this.closeWebsocket(),this.closeMqtt(),this.closeHttp()}destroy(t){if(this.clear(!1),this.stopDataMock(),this.closeSocket(),this.closeNetwork(),this.closeAll(),this.store.emitter.all.clear(),this.canvas.destroy(),this.canvas=void 0,At[this.store.id]=void 0,!t){for(const i in At)delete At[i];At.path2dDraws={},At.canvasDraws={},At.anchors={},At.htmlElements={}}}}function nE(e,t){const i=t||new Path2D,{x:n,y:r,width:s,ey:a}=e.calculative.worldRect,l=s/4;if(i.moveTo(n+l,r),i.lineTo(n,r),i.lineTo(n,a),i.lineTo(n+l,a),i instanceof Path2D)return i}function rE(e,t){const i=t||new Path2D,{x:n,y:r,width:s,ex:a,ey:l}=e.calculative.worldRect,c=e.offsetX;let u=s/7;if(c>1?u=c:c>0&&(u=s*c),i.moveTo(n+u,r),i.lineTo(a,r),i.lineTo(n+s-u,l),i.lineTo(n,l),i.closePath(),i instanceof Path2D)return i}function sE(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a,ex:l,ey:c}=e.calculative.worldRect,u=s/8;if(i.moveTo(n+u,r),i.lineTo(l-u,r),i.bezierCurveTo(l+u/3,r,l+u/3,c,l-u,c),i.lineTo(n+u,c),i.lineTo(n,r+a/2),i.closePath(),i instanceof Path2D)return i}function aE(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a,ex:l,center:c}=e.calculative.worldRect,u=c.x,h=r+a*6/7,d=a/6;if(i.moveTo(n,r),i.lineTo(l,r),i.lineTo(l,h),i.bezierCurveTo(l-20,h-d,u+s/5,h-d,u,h),i.bezierCurveTo(u-s/5,h+d,n,h+d,n,h),i.closePath(),i instanceof Path2D)return i}function oE(e,t){const i=t||new Path2D,{x:n,y:r,width:s,ex:a,ey:l}=e.calculative.worldRect,c=s/10;if(i.moveTo(n+c*2,r),i.bezierCurveTo(n-c*2/3,r,n-c*2/3,l,n+c*2,l),i.lineTo(a,l),i.bezierCurveTo(a-c,l,a-c,r,a,r),i.closePath(),i instanceof Path2D)return i}function lE(e,t){const i=t||new Path2D,{x:n,y:r,width:s,ex:a,ey:l}=e.calculative.worldRect;i.moveTo(n,r),i.lineTo(a,r),i.lineTo(a,l),i.lineTo(n,l),i.closePath();const c=s/7;if(i.moveTo(n,r+c),i.lineTo(a,r+c),i.moveTo(n+c,r),i.lineTo(n+c,l),i instanceof Path2D)return i}function cE(e,t){const i=t||new Path2D,{x:n,y:r,height:s,ex:a,ey:l}=e.calculative.worldRect,c=s/4;if(i.moveTo(n,r+c),i.lineTo(a,r),i.lineTo(a,l),i.lineTo(n,l),i.closePath(),i instanceof Path2D)return i}function hE(e,t){const i=t||new Path2D,{x:n,y:r,ex:s,ey:a}=e.calculative.worldRect;if(i.moveTo(n,r),i.lineTo(s,r),i.moveTo(n,a),i.lineTo(s,a),i instanceof Path2D)return i}function uE(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a,ex:l,ey:c}=e.calculative.worldRect;if(i.ellipse(n+s/2,r+a/2,s/2,a/2,0,0,Math.PI*2),i.moveTo(n+s/2,c),i.lineTo(l,c),i.closePath(),i instanceof Path2D)return i}function fE(e,t){const i=t||new Path2D,{x:n,y:r,width:s,ex:a,ey:l}=e.calculative.worldRect,c=s/7;if(i.moveTo(n,r),i.lineTo(a,r),i.lineTo(a,l),i.lineTo(n,l),i.closePath(),i.moveTo(n+c,r),i.lineTo(n+c,l),i.moveTo(a-c,r),i.lineTo(a-c,l),i instanceof Path2D)return i}function dE(e,t){const i=t||new Path2D,{x:n,y:r,height:s,ex:a,ey:l}=e.calculative.worldRect,c=s/7;if(i.moveTo(n,r+c),i.bezierCurveTo(n,r-c/2|0,a,r-c/2|0,a,r+c),i.lineTo(a,l-c),i.bezierCurveTo(a,l+c/2|0,n,l+c/2|0,n,l-c),i.closePath(),i.moveTo(n,l-c),i.bezierCurveTo(n,l-c*2|0,a,l-c*2|0,a,l-c),i instanceof Path2D)return i}function WC(){return{flowComment:nE,flowData:rE,flowDb:dE,flowDisplay:sE,flowDocument:aE,flowExternStorage:oE,flowInternalStorage:lE,flowManually:cE,flowParallel:hE,flowQueue:uE,flowSubprocess:fE}}var Ya;(function(e){e[e.Add=0]="Add",e[e.Replace=1]="Replace",e[e.ReplaceAll=2]="ReplaceAll"})(Ya||(Ya={}));function ag(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 og(e){if(e.direction=="horizontal"){const t=[];let i=0;const n=e.height;e.checkboxHeight=n,e.options.forEach((s,a)=>{t.push(a*(40+n)+i),i+=ag(s.text,e)}),e.optionPos=t;const r=t.length*(40+n)+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}},ae(e.calculative.worldRect)}else if(e.direction=="vertical"){e.optionInterval==null&&(e.optionInterval=20),e.optionHeight||(e.optionHeight=20);const t=[];e.options.forEach((n,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}},ae(e.calculative.worldRect))}}function cd(e,t){t.onAdd||(t.onAdd=lg,(!t.rowPos||!t.colPos||!t.calculative.maxOffsetY)&&t.onAdd(t),t.onMouseMove=bE,t.onMouseLeave=xE,t.onMouseDown=_E,t.onShowInput=pE,t.onInput=wE,t.onValue=AE,t.onBeforeValue=RE,t.onMouseEnter=IE,t.onWheel=CE,t.onDestroy=SE),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.data,n=t.calculative.canvas.store.options;if(t.color=t.color||i.color||n.color,t.textColor=t.textColor||t.color||i.textColor||n.textColor,t.activeColor=t.activeColor||n.activeColor,t.hoverColor=t.hoverColor||n.hoverColor,t.activeBackground=t.activeBackground||n.activeBackground,t.hoverBackground=t.hoverBackground||n.hoverBackground,!t.hasHeader){e.save(),e.beginPath();const{x:r,y:s,width:a,height:l}=t.calculative.worldRect;e.fillStyle="#fff0",e.rect(r-1,s-1,a+2,l+2),e.fill(),e.clip()}yE(e,t),mE(e,t),vE(e,t),e.restore(),t.isFirstTime=!1}function vE(e,t){if(!t.calculative.hover||!t.calculative.hoverCell||t.calculative.isInput||!t.calculative.isHover)return;let i=t.calculative.worldRect,n=t.calculative.canvas.mousePos;if(!(n.x>i.x&&n.xi.y&&n.yv.col!==void 0&&v.row===void 0&&v.width);let a={};s&&s.forEach(v=>{a[v.col]=v.width});for(let v=0;vw.col===v&&w.row===void 0);y&&(n[v]=y[0])}let l=0;const c=e.styles&&e.styles.filter(v=>v.col===void 0&&v.row!==void 0&&v.height);let u={};c&&c.forEach(v=>{u[v.row]=v.height});let h=l;for(let v=0;vt.calculative.worldRect.height)continue}else if(v<0||v>t.calculative.worldRect.height)continue;e.beginPath(),e.moveTo(t.calculative.worldRect.x,t.calculative.worldRect.y+v),e.lineTo(t.calculative.worldRect.ex,t.calculative.worldRect.y+v),e.strokeStyle=t.borderColor||"#424B61",e.stroke()}}if(t.vLine!==!1){let d=t.colPos[t.colPos.length-1];t.colPos.forEach((g,v)=>{if(g===d)return;const y=g*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||"#424B61",e.stroke()})}e.restore()}function mE(e,t){var n,r,s,a,l;if(!t.colPos)return;t.calculative.texts||(t.calculative.texts=[]);const i=1;for(let c=0;c0){let D=0;g.forEach((q,Q)=>{q.wheres&&q.wheres.every(T=>new Function("attr",`return attr ${T.comparison} ${T.value}`)(d))&&(D=Q)}),g=g[D]}else g.wheres&&Array.isArray(g.wheres)&&(v=!1,v=g.wheres.every(function(D){return new Function("attr",`return attr ${D.comparison} ${D.value}`)(d)}));let y=t.color,w=t.textColor||t.color,p=null,_=null,A=null,x=null;v&&(y=g.color||u.color||t.color,w=g.textColor||u.textColor||t.textColor,p=g.background||u.background,_=(g.fontSize||u.fontSize||0)*t.calculative.canvas.store.data.scale,A=g.fontWeight||u.fontWeight,x=g.fontStyle||u.fontStyle);let E;t.stripe&&(t.hasHeader!==!1?c%2===1&&(p=p||t.stripeColor||"#407FFF1F"):c%2===0&&(p=p||t.stripeColor||"#407FFF1F")),t.calculative.active&&((n=t.calculative.activeCell)==null?void 0:n.row)===c&&((r=t.calculative.activeCell)==null?void 0:r.col)===h&&(y=t.activeColor,p=t.activeBackground,E=y,w=t.activeTextColor||t.activeColor),t.calculative.hover&&((s=t.calculative.hoverCell)==null?void 0:s.row)===c&&((a=t.calculative.hoverCell)==null?void 0:a.col)===h&&(y=t.hoverColor,p=t.hoverBackground,w=t.hoverTextColor||t.hoverColor,E=y);const I=fg(t,c,h);if(I.y+I.heightt.calculative.worldRect.height+t.calculative.worldRect.y)continue;p&&(e.save(),e.beginPath(),e.fillStyle=p,e.fillRect(I.x,I.y,I.width+.25*t.calculative.canvas.store.data.scale,I.height),e.restore()),E&&(e.save(),e.beginPath(),e.strokeStyle=E,e.strokeRect(I.x,I.y,I.width,I.height),e.restore()),t.calculative.worldTextRect=I;let M=t.calculative.texts[c];if(t.calculative.texts[c]||(M=[],t.calculative.texts.push(M)),M[h]==null){if(typeof d=="object"){const D=t.styles&&t.styles.filter(q=>q.col===h&&q.row===void 0&&q.pens);if(D.length>0){if(M[h]="",t.isFirstTime){t.maxNum&&t.hasHeader&&c>=t.maxNum&&(d.visible=!1);let q=JSON.parse(JSON.stringify(D[0].pens));q.forEach(Q=>{Object.assign(Q,{row:c,col:h},d),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}),EE(t,I,q),t.calculative.canvas.parent.pushChildren(t,q)}continue}}else d===void 0?M[h]="":M[h]=d.text||d+"";if(!M[h])continue;M[h]=Es(t,M[h])}if(!M[h])continue;e.save(),e.beginPath(),e.fillStyle=w,e.textAlign="center",e.textBaseline="middle",e.font=(x||t.calculative.fontStyle||"")+" normal "+(A||t.calculative.fontWeight||"")+" "+(_||t.calculative.fontSize||12)*i+"px "+t.calculative.fontFamily;let B=t.colStyle&&((l=t.colStyle[h])==null?void 0:l.textAlign);if(B&&(e.textAlign=B),M[h].length===1)B==="left"?e.fillText(M[h][0],I.x,I.y+I.height/2):B==="right"?e.fillText(M[h][0],I.x+I.width,I.y+I.height/2):e.fillText(M[h][0],I.x+I.width/2,I.y+I.height/2);else{const q=(_||t.calculative.fontSize)*t.calculative.lineHeight*i,Q=M[h].length*q;let C=(I.height-Q)/2;B==="left"?M[h].forEach((T,S)=>{e.fillText(T,I.x,I.y+C+(S+.55)*q)}):B==="right"?M[h].forEach((T,S)=>{e.fillText(T,I.x+I.width,I.y+C+(S+.55)*q)}):M[h].forEach((T,S)=>{e.fillText(T,I.x+I.width/2,I.y+C+(S+.55)*q)})}e.restore()}}}function lg(e){var t;qc(e),(t=e.children)!=null&&t.length||(e.isFirstTime=!0),e.offsetY||(e.offsetY=0),gE(e)}function pE(e,t){if(!e.calculative.hoverCell)return;const{value:i}=hg(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 n=fg(e,e.calculative.hoverCell.row,e.calculative.hoverCell.col);e.calculative.tempText=i.text||i+"",e.calculative.canvas.showInput(e,n,"#ffffff")}function wE(e,t){!e.calculative.inputCell||(ug(e,e.calculative.inputCell.row,e.calculative.inputCell.col,t),e.calculative.isInput=!1,e.calculative.isHover=!0,e.calculative.canvas.render())}function bE(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=cg(e,t),e.calculative.canvas.render()}function xE(e,t){qc(e),e.calculative.hoverCell=void 0,e.calculative.canvas.render()}function _E(e,t){e.calculative.activeCell=cg(e,t),e.calculative.canvas.render()}function cg(e,t){const i=e.calculative.worldRect.width/e.tableWidth,n=e.calculative.worldRect.height/e.tableHeight,r={row:0,col:0};for(let s=0;se.calculative.worldRect.x+e.colPos[s]*i&&(r.col=s+1);for(let s=0;se.calculative.worldRect.y+e.rowPos[s]*n-e.offsetY*e.calculative.canvas.store.data.scale&&(r.row=s+1);return r}function hg(e,t,i){if(!e.data||!Array.isArray(e.data))return;const n=e.data[t],r=e.styles&&e.styles.filter(s=>s.row===t&&s.col===i);if(Array.isArray(n))return{value:n[i],style:(r==null?void 0:r.length)>0?r.length>1?r:r[0]:{}};if(!n.data||!Array.isArray(n.data))return}function kE(e,t){if(!e.data||!Array.isArray(e.data))return;const i=e.data[t],n=e.styles&&e.styles.filter(r=>r.row===t&&r.col===void 0);if(Array.isArray(i))return{value:i,style:(n==null?void 0:n.length)>0?n[0]:{}};if(!i.data||!Array.isArray(i.data))return}function ug(e,t,i,n){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]=n),e.calculative.canvas.store.emitter.emit("valueUpdate",e))}function fg(e,t,i){const n=e.calculative.worldRect.width/e.tableWidth,r=e.calculative.worldRect.height/e.tableHeight;let s=0,a=e.colPos[i]*n;i>0&&(s=e.colPos[i-1]*n);let l=0,c=e.rowPos[t]*r;t>0&&(l=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+s,y:e.calculative.worldRect.y+l-u,ex:e.calculative.worldRect.x+a,ey:e.calculative.worldRect.y+c-u,width:a-s,height:c-l}}function EE(e,t,i){if(!(i&&i.length))return;const n=e.calculative.worldRect.width/e.tableWidth,r=e.calculative.worldRect.height/e.tableHeight;let s=1,a=1;e.initWorldRect&&(e.calculative.worldRect.width!==e.initWorldRect.width&&(s=e.calculative.worldRect.width/e.initWorldRect.width),e.calculative.worldRect.height!==e.initWorldRect.height&&(a=e.calculative.worldRect.height/e.initWorldRect.height));let l=0,c=0,u=0;const h=e.calculative.canvas.store.data.scale;if(i.length>1){for(const d of i)c+d.width*n+20*h*n{d.width=d.width*s,d.height=d.height*a})}function AE(e){if(e.calculative.isUpdateData){delete e.calculative.isUpdateData;let t=ct(e.children);e.children=[],lg(e),t&&t.forEach(i=>{e.calculative.canvas.delForce(e.calculative.canvas.findOne(i))}),e.calculative.texts=void 0}}function RE(e,t){if(e.calculative.isUpdateData=!1,e.swiper!==void 0&&(e.swiper?qc(e):Wc(e)),t.styles&&(e.initWorldRect=void 0),t.table||t.col==null&&t.row==null){if(t.dataY){const n=e.replaceMode;let r=[];return n?n===Ya.Replace?(r=e.data,t.dataX&&t.dataX.forEach((s,a)=>{r[s]=t.dataY[a]})):n===Ya.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 n of Object.keys(t))n.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),ug(e,t.row,t.col,t.value),e.calculative.canvas.render(),delete t.col,delete t.row),t}function CE(e,t){if(!e.locked&&!e.calculative.canvas.store.data.locked||!e.maxNum)return;let i=0;t.deltaY>0?i=4:i=-4,kc(e,i)}function kc(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(n=>{const r=e.calculative.canvas.store.pens[n];TE(e,r)}),e.calculative.canvas.render()}function TE(e,t){if(!t)return;t.oldY||(t.oldY=t.y),t.calculative.worldRect,e.calculative.worldRect;const i=e.calculative.canvas.store.data.scale;e.calculative.worldRect.height/e.tableHeight;const n=e.rowHeight;t.y=t.oldY-e.offsetY*i/e.calculative.worldRect.height;const r=n*(e.initScale||1)/e.tableHeight*e.maxNum;if(e.calculative.canvas.updatePenRect(t),e.hasHeader)if(t.y1){if(t.calculative.visible=!1,t.visible=!1,t.y+t.height/2>1){t.oldY-=r;let s=t.row-e.maxNum;if(!e.data[s])return;let a=ct(e.data[s][t.col]);a.background&&(a.activeBackground=a.background,a.hoverBackground=a.background),a.color&&(a.hoverColor=a.color,a.activeColor=a.color),a.textColor&&(a.activeTextColor=a.textColor,a.hoverTextColor=a.textColor),Object.assign(t,a,{row:s}),Object.assign(t.calculative,a,{row:s})}}else t.visible=!0,t.calculative.visible=!0;else if(t.y<0){if(t.calculative.visible=!1,t.visible=!1,t.y<-n/e.tableHeight/2){t.oldY+=r;let s=t.row+e.maxNum;if(!e.data[s])return;let a=ct(e.data[s][t.col]);a.background&&(a.activeBackground=a.background,a.hoverBackground=a.background),a.color&&(a.hoverColor=a.color,a.activeColor=a.color),a.textColor&&(a.activeTextColor=a.textColor,a.hoverTextColor=a.textColor),Object.assign(t,a,{row:s}),Object.assign(t.calculative,a,{row:s})}}else if(t.y+t.height>1){if(t.calculative.visible=!1,t.visible=!1,t.y+t.height/2>1){t.oldY-=r;let s=t.row-e.maxNum;if(!e.data[s])return;let a=ct(e.data[s][t.col]);a.background&&(a.activeBackground=a.background,a.hoverBackground=a.background),a.color&&(a.hoverColor=a.color,a.activeColor=a.color),a.textColor&&(a.activeTextColor=a.textColor,a.hoverTextColor=a.textColor),Object.assign(t,a,{row:s}),Object.assign(t.calculative,a,{row:s})}}else t.calculative.visible=!0,t.visible=!0}function SE(e){Wc(e)}function Wc(e){e.interval&&(globalThis.clearInterval(e.interval),e.interval=null)}function qc(e){if(e.maxNum&&e.swiper){if(e.interval)return;e.interval=globalThis.setInterval(()=>{e.offsetY>=e.calculative.maxOffsetY?(e.offsetY=0,PE(e)):e.offsetY%e.rowHeight?kc(e,1):(e.calculative.stap||(e.calculative.stap=0),e.calculative.stap+=1,e.calculative.stap==12&&(e.calculative.stap=0,kc(e,1)))},50)}}function PE(e){var t;(t=e.children)==null||t.forEach(i=>{const n=e.rowHeight,r=e.calculative.canvas.store.pens[i];if(!r)return;const s=n*(e.initScale||1)/e.tableHeight*e.maxNum;r.oldY-=s;const a=r.row-e.maxNum;if(!e.data[a])return;let l=ct(e.data[a][r.col]);l.background&&(l.activeBackground=l.background,l.hoverBackground=l.background),l.color&&(l.hoverColor=l.color,l.activeColor=l.color),l.textColor&&(l.activeTextColor=l.textColor,l.hoverTextColor=l.textColor),r.calculative.visible=!0,r.visible=!0,Object.assign(r,l,{row:a}),Object.assign(r.calculative,l,{row:a})}),e.calculative.canvas.render()}function IE(e){Wc(e)}function LE(e,t){t.onClick||(t.onClick=DE);let i=t.calculative.worldRect.x,n=t.calculative.worldRect.y,r=t.calculative.worldRect.width,s=t.calculative.worldRect.height;r2?s/2-2:1,0,Math.PI*2),e.fill()):(e.fillStyle=t.offColor,(t.disabled||t.disable)&&(e.fillStyle=t.disableOffColor||Ae(.6,t.offColor)),t.lineWidth&&(e.strokeStyle=t.offStrokeColor,e.stroke()),e.fill(),e.closePath(),e.beginPath(),e.fillStyle="#ffffff",e.moveTo(i+s,n+s/2),e.arc(i+s/2,n+s/2,s/2>2?s/2-2:1,0,Math.PI*2),e.fill()),e.closePath()}function DE(e){e.disabled||e.disable||(e.checked=!e.checked,e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render())}function ME(e,t){t.onAdd||(t.onAdd=as,t.onResize=as,t.onMove=as,t.onMouseMove=BE,t.onMouseDown=dg,t.onValue=OE,t.onBeforeValue=NE),t.calculative.barRect||as(t),t.calculative.canvas.store.data;const i=t.calculative.canvas.store.options;let n=t.background;t.disabled&&(n=t.disabledBackground||Ae(.6,n)),e.fillStyle=n,e.beginPath();let r=t.calculative.worldRect.x+t.calculative.barRect.x,s=t.calculative.worldRect.y+t.calculative.barRect.y,a=t.calculative.barRect.width,l=t.calculative.barRect.height,c=l/2;e.moveTo(r+c,s),e.arcTo(r+a,s,r+a,s+l,c),e.arcTo(r+a,s+l,r,s+l,c),e.arcTo(r,s+l,t.x,t.y,c),e.arcTo(r,s,r+a,s,c),e.fill();let u=t.activeColor||i.activeColor;t.disabled&&(u=t.disabledColor||Ae(.6,u)),e.fillStyle=u,e.beginPath(),a=t.calculative.ballRect.x,e.moveTo(r+c,s),e.arcTo(r+a,s,r+a,s+l,c),e.arcTo(r+a,s+l,r,s+l,c),e.arcTo(r,s+l,t.x,t.y,c),e.arcTo(r,s,r+a,s,c),e.fill(),e.fillStyle=t.btnBackground||"#fff",e.strokeStyle=u,e.lineWidth=2,e.beginPath(),r=t.calculative.worldRect.x+t.calculative.ballRect.x,s=t.calculative.worldRect.y+t.calculative.ballRect.y+t.calculative.ballRect.height/2,e.lineWidth=t.calculative.ballRect.width/10,e.arc(r,s,t.calculative.ballRect.width/2,0,Math.PI*2),e.fill(),e.stroke()}function as(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;const t=e.calculative.worldRect.width/e.sliderWidth,i=e.calculative.worldRect.height/e.sliderHeight,n=Math.min(t,i);e.fontSize=e._fontSize*n;const r=e.calculative.worldRect.width-e._textWidth*n;e.textLeft=r+10*n,e.calculative.textLeft=e.textLeft,e.calculative.barRect={x:0,y:(e.calculative.worldRect.height-e.barHeight*i)/2,width:r,height:e.barHeight*i},ae(e.calculative.barRect),jc(e)}function jc(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},ae(e.calculative.ballRect),e.calculative.text=e.value+e.unit,Ti(e)}function dg(e,t){if(e.disabled)return;const i=t.x-e.calculative.worldRect.x;if(i>e.calculative.barRect.width)return;let n=Math.round(i/e.calculative.barRect.width*100);ne.max||n<0||n>100||(e.value=n,jc(e),e.calculative.text=e.value+e.unit,Ti(e),e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render())}function BE(e,t){e.calculative.canvas.mouseDown&&dg(e,t)}function OE(e){e.calculative.isUpdateData&&(delete e.calculative.isUpdateData,as(e)),jc(e)}function NE(e,t){return e.calculative.isUpdateData=!1,(t.textWidth||t.barHeight)&&(t.textWidth&&(e._textWidth=0),e.calculative.isUpdateData=!0),t}function FE(e,t){t.onMouseDown||(t.onMouseDown=zE),t.options||(t.options=t.data);let i=t.calculative.worldRect.x,n=t.calculative.worldRect.y,r=t.calculative.worldRect.height;t.calculative.worldRect.width;const{fontStyle:s,fontWeight:a,fontSize:l,fontFamily:c,lineHeight:u}=t.calculative;let h=2;e.beginPath(),e.moveTo(i,n),e.arcTo(i+r,n,i+r,n+r,h),e.arcTo(i+r,n+r,i,n+r,h),e.arcTo(i,n+r,i,n,h),e.arcTo(i,n,i+r,n,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||Ae(.6,t.background)||"#ebebeb",e.strokeStyle=t.disabledColor||Ae(.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,n+r/2),e.lineTo(i+220/506*r,n+346/460*r),e.lineTo(i+404/506*r,n+142/460*r),e.stroke()),e.restore(),e.save(),e.fillStyle=t.disabled||t.isForbidden?t.disabledTextColor||Ae(.6,t.textColor||t.color)||"#00000040":An(t,t.calculative.canvas.parent.store)||"#000000d9",e.textAlign="start",e.textBaseline="middle",e.font=Rn({fontStyle:s,fontWeight:a,fontFamily:c||t.calculative.canvas.parent.store.options.fontFamily,fontSize:l,lineHeight:u}),e.fillText(t.value+"",i+r+10,n+r/2),e.restore()}function zE(e,t){e.isForbidden||(e.checked=!e.checked,e.calculative.canvas.store.emitter.emit("valueUpdate",e),e.calculative.canvas.render())}function HE(e,t){t.options||(t.options=t.data),t.onAdd||(t.onAdd=UE,t.optionPos||(t.onAdd(t),t.calculative.canvas.parent.active([t])),t.onMouseDown=WE,t.onValue=qE);let i=t.calculative.worldRect.x,n=t.calculative.worldRect.y,r=t.calculative.worldRect.height,s=t.calculative.worldRect.width;if(!t.optionPos)return;const{fontStyle:a,fontWeight:l,fontSize:c,fontFamily:u,lineHeight:h}=t.calculative;if(t.direction=="horizontal")for(let d=0;de.calculative.worldRect.x+e.optionPos[i]*e.calculative.worldRect.width/e.checkboxWidth&&t.xe.calculative.worldRect.y+e.optionPos[n]*i&&t.y{const n=t.data.pens.findIndex(r=>r.id===i);n>-1&&(t.data.pens.splice(n,1),t.pens[i]=void 0)}),e.children=void 0}function XE(e,t){e.onDestroy||(e.onDestroy=ZE,e.onAdd=GE);const i=t||new Path2D,{x:n,y:r,width:s,height:a,ex:l}=e.calculative.worldRect;let c=e.calculative.borderRadius||0,u=c;c<1&&(c=s*c,u=a*u);let h=c{const n=t.data.pens.findIndex(r=>r.id===i);n>-1&&(t.data.pens.splice(n,1),t.pens[i]=void 0)}),e.children=[]}function VC(){return{interfaceClass:$E,simpleClass:XE}}function JE(e,t){const i=t||new Path2D,{x:n,y:r,width:s,height:a}=e.calculative.worldRect;if(i.rect(n,r,s,a),i.closePath(),i instanceof Path2D)return i}function QE(e,t){var g;const i=(g=t.headHeight)!=null?g:50,{x:n,y:r,width:s,height:a,ey:l}=t.calculative.worldRect;let c=t.calculative.borderRadius||0,u=c;t.calculative.borderRadius<1&&(c*=s,u*=a);let h=c"u"}function rA(e){return e!==null&&!Ec(e)&&e.constructor!==null&&!Ec(e.constructor)&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e)}function yg(e){return Cn.call(e)==="[object ArrayBuffer]"}function sA(e){return Cn.call(e)==="[object FormData]"}function aA(e){var t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&yg(e.buffer),t}function oA(e){return typeof e=="string"}function lA(e){return typeof e=="number"}function mg(e){return e!==null&&typeof e=="object"}function Ba(e){if(Cn.call(e)!=="[object Object]")return!1;var t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function cA(e){return Cn.call(e)==="[object Date]"}function hA(e){return Cn.call(e)==="[object File]"}function uA(e){return Cn.call(e)==="[object Blob]"}function pg(e){return Cn.call(e)==="[object Function]"}function fA(e){return mg(e)&&pg(e.pipe)}function dA(e){return Cn.call(e)==="[object URLSearchParams]"}function vA(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function gA(){return typeof navigator<"u"&&(navigator.product==="ReactNative"||navigator.product==="NativeScript"||navigator.product==="NS")?!1:typeof window<"u"&&typeof document<"u"}function Kc(e,t){if(!(e===null||typeof e>"u"))if(typeof e!="object"&&(e=[e]),$c(e))for(var i=0,n=e.length;i"u"||(xr.isArray(c)?u=u+"[]":c=[c],xr.forEach(c,function(d){xr.isDate(d)?d=d.toISOString():xr.isObject(d)&&(d=JSON.stringify(d)),s.push(hd(u)+"="+hd(d))}))}),r=s.join("&")}if(r){var a=t.indexOf("#");a!==-1&&(t=t.slice(0,a)),t+=(t.indexOf("?")===-1?"?":"&")+r}return t},pA=We;function Qa(){this.handlers=[]}Qa.prototype.use=function(t,i,n){return this.handlers.push({fulfilled:t,rejected:i,synchronous:n?n.synchronous:!1,runWhen:n?n.runWhen:null}),this.handlers.length-1};Qa.prototype.eject=function(t){this.handlers[t]&&(this.handlers[t]=null)};Qa.prototype.forEach=function(t){pA.forEach(this.handlers,function(n){n!==null&&t(n)})};var wA=Qa,bA=We,xA=function(t,i){bA.forEach(t,function(r,s){s!==i&&s.toUpperCase()===i.toUpperCase()&&(t[i]=r,delete t[s])})},bg=function(t,i,n,r,s){return t.config=i,n&&(t.code=n),t.request=r,t.response=s,t.isAxiosError=!0,t.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code,status:this.response&&this.response.status?this.response.status:null}},t},Nl,ud;function xg(){if(ud)return Nl;ud=1;var e=bg;return Nl=function(i,n,r,s,a){var l=new Error(i);return e(l,n,r,s,a)},Nl}var Fl,fd;function _A(){if(fd)return Fl;fd=1;var e=xg();return Fl=function(i,n,r){var s=r.config.validateStatus;!r.status||!s||s(r.status)?i(r):n(e("Request failed with status code "+r.status,r.config,null,r.request,r))},Fl}var zl,dd;function kA(){if(dd)return zl;dd=1;var e=We;return zl=e.isStandardBrowserEnv()?function(){return{write:function(n,r,s,a,l,c){var u=[];u.push(n+"="+encodeURIComponent(r)),e.isNumber(s)&&u.push("expires="+new Date(s).toGMTString()),e.isString(a)&&u.push("path="+a),e.isString(l)&&u.push("domain="+l),c===!0&&u.push("secure"),document.cookie=u.join("; ")},read:function(n){var r=document.cookie.match(new RegExp("(^|;\\s*)("+n+")=([^;]*)"));return r?decodeURIComponent(r[3]):null},remove:function(n){this.write(n,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}(),zl}var Hl,vd;function EA(){return vd||(vd=1,Hl=function(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)}),Hl}var Ul,gd;function AA(){return gd||(gd=1,Ul=function(t,i){return i?t.replace(/\/+$/,"")+"/"+i.replace(/^\/+/,""):t}),Ul}var Wl,yd;function RA(){if(yd)return Wl;yd=1;var e=EA(),t=AA();return Wl=function(n,r){return n&&!e(r)?t(n,r):r},Wl}var ql,md;function CA(){if(md)return ql;md=1;var e=We,t=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];return ql=function(n){var r={},s,a,l;return n&&e.forEach(n.split(` `),function(u){if(l=u.indexOf(":"),s=e.trim(u.substr(0,l)).toLowerCase(),a=e.trim(u.substr(l+1)),s){if(r[s]&&t.indexOf(s)>=0)return;s==="set-cookie"?r[s]=(r[s]?r[s]:[]).concat([a]):r[s]=r[s]?r[s]+", "+a:a}}),r},ql}var jl,pd;function TA(){if(pd)return jl;pd=1;var e=We;return jl=e.isStandardBrowserEnv()?function(){var i=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a"),r;function s(a){var l=a;return i&&(n.setAttribute("href",l),l=n.href),n.setAttribute("href",l),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:n.pathname.charAt(0)==="/"?n.pathname:"/"+n.pathname}}return r=s(window.location.href),function(l){var c=e.isString(l)?s(l):l;return c.protocol===r.protocol&&c.host===r.host}}():function(){return function(){return!0}}(),jl}var Vl,wd;function to(){if(wd)return Vl;wd=1;function e(t){this.message=t}return e.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},e.prototype.__CANCEL__=!0,Vl=e,Vl}var $l,bd;function xd(){if(bd)return $l;bd=1;var e=We,t=_A(),i=kA(),n=wg,r=RA(),s=CA(),a=TA(),l=xg(),c=eo(),u=to();return $l=function(d){return new Promise(function(v,y){var w=d.data,p=d.headers,_=d.responseType,A;function x(){d.cancelToken&&d.cancelToken.unsubscribe(A),d.signal&&d.signal.removeEventListener("abort",A)}e.isFormData(w)&&delete p["Content-Type"];var E=new XMLHttpRequest;if(d.auth){var I=d.auth.username||"",M=d.auth.password?unescape(encodeURIComponent(d.auth.password)):"";p.Authorization="Basic "+btoa(I+":"+M)}var B=r(d.baseURL,d.url);E.open(d.method.toUpperCase(),n(B,d.params,d.paramsSerializer),!0),E.timeout=d.timeout;function D(){if(!!E){var Q="getAllResponseHeaders"in E?s(E.getAllResponseHeaders()):null,C=!_||_==="text"||_==="json"?E.responseText:E.response,T={data:C,status:E.status,statusText:E.statusText,headers:Q,config:d,request:E};t(function(O){v(O),x()},function(O){y(O),x()},T),E=null}}if("onloadend"in E?E.onloadend=D:E.onreadystatechange=function(){!E||E.readyState!==4||E.status===0&&!(E.responseURL&&E.responseURL.indexOf("file:")===0)||setTimeout(D)},E.onabort=function(){!E||(y(l("Request aborted",d,"ECONNABORTED",E)),E=null)},E.onerror=function(){y(l("Network Error",d,null,E)),E=null},E.ontimeout=function(){var C=d.timeout?"timeout of "+d.timeout+"ms exceeded":"timeout exceeded",T=d.transitional||c.transitional;d.timeoutErrorMessage&&(C=d.timeoutErrorMessage),y(l(C,d,T.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED",E)),E=null},e.isStandardBrowserEnv()){var q=(d.withCredentials||a(B))&&d.xsrfCookieName?i.read(d.xsrfCookieName):void 0;q&&(p[d.xsrfHeaderName]=q)}"setRequestHeader"in E&&e.forEach(p,function(C,T){typeof w>"u"&&T.toLowerCase()==="content-type"?delete p[T]:E.setRequestHeader(T,C)}),e.isUndefined(d.withCredentials)||(E.withCredentials=!!d.withCredentials),_&&_!=="json"&&(E.responseType=d.responseType),typeof d.onDownloadProgress=="function"&&E.addEventListener("progress",d.onDownloadProgress),typeof d.onUploadProgress=="function"&&E.upload&&E.upload.addEventListener("progress",d.onUploadProgress),(d.cancelToken||d.signal)&&(A=function(Q){!E||(y(!Q||Q&&Q.type?new u("canceled"):Q),E.abort(),E=null)},d.cancelToken&&d.cancelToken.subscribe(A),d.signal&&(d.signal.aborted?A():d.signal.addEventListener("abort",A))),w||(w=null),E.send(w)})},$l}var Kl,_d;function eo(){if(_d)return Kl;_d=1;var e=We,t=xA,i=bg,n={"Content-Type":"application/x-www-form-urlencoded"};function r(c,u){!e.isUndefined(c)&&e.isUndefined(c["Content-Type"])&&(c["Content-Type"]=u)}function s(){var c;return(typeof XMLHttpRequest<"u"||typeof process<"u"&&Object.prototype.toString.call(process)==="[object process]")&&(c=xd()),c}function a(c,u,h){if(e.isString(c))try{return(u||JSON.parse)(c),e.trim(c)}catch(d){if(d.name!=="SyntaxError")throw d}return(h||JSON.stringify)(c)}var l={transitional:{silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},adapter:s(),transformRequest:[function(u,h){return t(h,"Accept"),t(h,"Content-Type"),e.isFormData(u)||e.isArrayBuffer(u)||e.isBuffer(u)||e.isStream(u)||e.isFile(u)||e.isBlob(u)?u:e.isArrayBufferView(u)?u.buffer:e.isURLSearchParams(u)?(r(h,"application/x-www-form-urlencoded;charset=utf-8"),u.toString()):e.isObject(u)||h&&h["Content-Type"]==="application/json"?(r(h,"application/json"),a(u)):u}],transformResponse:[function(u){var h=this.transitional||l.transitional,d=h&&h.silentJSONParsing,g=h&&h.forcedJSONParsing,v=!d&&this.responseType==="json";if(v||g&&e.isString(u)&&u.length)try{return JSON.parse(u)}catch(y){if(v)throw y.name==="SyntaxError"?i(y,this,"E_JSON_PARSE"):y}return u}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,validateStatus:function(u){return u>=200&&u<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};return e.forEach(["delete","get","head"],function(u){l.headers[u]={}}),e.forEach(["post","put","patch"],function(u){l.headers[u]=e.merge(n)}),Kl=l,Kl}var SA=We,PA=eo(),IA=function(t,i,n){var r=this||PA;return SA.forEach(n,function(a){t=a.call(r,t,i)}),t},Yl,kd;function _g(){return kd||(kd=1,Yl=function(t){return!!(t&&t.__CANCEL__)}),Yl}var Ed=We,Xl=IA,LA=_g(),DA=eo(),MA=to();function Gl(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new MA("canceled")}var BA=function(t){Gl(t),t.headers=t.headers||{},t.data=Xl.call(t,t.data,t.headers,t.transformRequest),t.headers=Ed.merge(t.headers.common||{},t.headers[t.method]||{},t.headers),Ed.forEach(["delete","get","head","post","put","patch","common"],function(r){delete t.headers[r]});var i=t.adapter||DA.adapter;return i(t).then(function(r){return Gl(t),r.data=Xl.call(t,r.data,r.headers,t.transformResponse),r},function(r){return LA(r)||(Gl(t),r&&r.response&&(r.response.data=Xl.call(t,r.response.data,r.response.headers,t.transformResponse))),Promise.reject(r)})},Xe=We,kg=function(t,i){i=i||{};var n={};function r(h,d){return Xe.isPlainObject(h)&&Xe.isPlainObject(d)?Xe.merge(h,d):Xe.isPlainObject(d)?Xe.merge({},d):Xe.isArray(d)?d.slice():d}function s(h){if(Xe.isUndefined(i[h])){if(!Xe.isUndefined(t[h]))return r(void 0,t[h])}else return r(t[h],i[h])}function a(h){if(!Xe.isUndefined(i[h]))return r(void 0,i[h])}function l(h){if(Xe.isUndefined(i[h])){if(!Xe.isUndefined(t[h]))return r(void 0,t[h])}else return r(void 0,i[h])}function c(h){if(h in i)return r(t[h],i[h]);if(h in t)return r(void 0,t[h])}var u={url:a,method:a,data:a,baseURL:l,transformRequest:l,transformResponse:l,paramsSerializer:l,timeout:l,timeoutMessage:l,withCredentials:l,adapter:l,responseType:l,xsrfCookieName:l,xsrfHeaderName:l,onUploadProgress:l,onDownloadProgress:l,decompress:l,maxContentLength:l,maxBodyLength:l,transport:l,httpAgent:l,httpsAgent:l,cancelToken:l,socketPath:l,responseEncoding:l,validateStatus:c};return Xe.forEach(Object.keys(t).concat(Object.keys(i)),function(d){var g=u[d]||s,v=g(d);Xe.isUndefined(v)&&g!==c||(n[d]=v)}),n},Zl,Ad;function Eg(){return Ad||(Ad=1,Zl={version:"0.25.0"}),Zl}var OA=Eg().version,Yc={};["object","boolean","number","function","string","symbol"].forEach(function(e,t){Yc[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}});var Rd={};Yc.transitional=function(t,i,n){function r(s,a){return"[Axios v"+OA+"] Transitional option '"+s+"'"+a+(n?". "+n:"")}return function(s,a,l){if(t===!1)throw new Error(r(a," has been removed"+(i?" in "+i:"")));return i&&!Rd[a]&&(Rd[a]=!0,console.warn(r(a," has been deprecated since v"+i+" and will be removed in the near future"))),t?t(s,a,l):!0}};function NA(e,t,i){if(typeof e!="object")throw new TypeError("options must be an object");for(var n=Object.keys(e),r=n.length;r-- >0;){var s=n[r],a=t[s];if(a){var l=e[s],c=l===void 0||a(l,s,e);if(c!==!0)throw new TypeError("option "+s+" must be "+c);continue}if(i!==!0)throw Error("Unknown option "+s)}}var FA={assertOptions:NA,validators:Yc},Ag=We,zA=wg,Cd=wA,Td=BA,io=kg,Rg=FA,_r=Rg.validators;function Rs(e){this.defaults=e,this.interceptors={request:new Cd,response:new Cd}}Rs.prototype.request=function(t,i){if(typeof t=="string"?(i=i||{},i.url=t):i=t||{},!i.url)throw new Error("Provided config url is not valid");i=io(this.defaults,i),i.method?i.method=i.method.toLowerCase():this.defaults.method?i.method=this.defaults.method.toLowerCase():i.method="get";var n=i.transitional;n!==void 0&&Rg.assertOptions(n,{silentJSONParsing:_r.transitional(_r.boolean),forcedJSONParsing:_r.transitional(_r.boolean),clarifyTimeoutError:_r.transitional(_r.boolean)},!1);var r=[],s=!0;this.interceptors.request.forEach(function(v){typeof v.runWhen=="function"&&v.runWhen(i)===!1||(s=s&&v.synchronous,r.unshift(v.fulfilled,v.rejected))});var a=[];this.interceptors.response.forEach(function(v){a.push(v.fulfilled,v.rejected)});var l;if(!s){var c=[Td,void 0];for(Array.prototype.unshift.apply(c,r),c=c.concat(a),l=Promise.resolve(i);c.length;)l=l.then(c.shift(),c.shift());return l}for(var u=i;r.length;){var h=r.shift(),d=r.shift();try{u=h(u)}catch(g){d(g);break}}try{l=Td(u)}catch(g){return Promise.reject(g)}for(;a.length;)l=l.then(a.shift(),a.shift());return l};Rs.prototype.getUri=function(t){if(!t.url)throw new Error("Provided config url is not valid");return t=io(this.defaults,t),zA(t.url,t.params,t.paramsSerializer).replace(/^\?/,"")};Ag.forEach(["delete","get","head","options"],function(t){Rs.prototype[t]=function(i,n){return this.request(io(n||{},{method:t,url:i,data:(n||{}).data}))}});Ag.forEach(["post","put","patch"],function(t){Rs.prototype[t]=function(i,n,r){return this.request(io(r||{},{method:t,url:i,data:n}))}});var HA=Rs,Jl,Sd;function UA(){if(Sd)return Jl;Sd=1;var e=to();function t(i){if(typeof i!="function")throw new TypeError("executor must be a function.");var n;this.promise=new Promise(function(a){n=a});var r=this;this.promise.then(function(s){if(!!r._listeners){var a,l=r._listeners.length;for(a=0;a{const t=localStorage.getItem("token");return t&&(e.headers.Authorization="Bearer "+t),e});en.interceptors.response.use(e=>{var t,i,n;return e.data&&e.data.code===0?Promise.resolve((t=e.data)==null?void 0:t.data):e.data&&e.data.code===401?(setTimeout(()=>{window.location.href="/"},1e3),mr.error((i=e.data)==null?void 0:i.message)):(mr.error((n=e.data)==null?void 0:n.message),Promise.reject(e.data))},e=>{var t,i;return Dd?!1:e.response?(mr.closeAll(),mr.error(((t=e.response.data)==null?void 0:t.msg)||"\u767B\u5F55\u5931\u6548\uFF0C\u7A0D\u540E\u91CD\u65B0\u767B\u5F55"),((i=e.response.data)==null?void 0:i.code)===401&&(localStorage.removeItem("token"),setTimeout(()=>{window.location.href="/"},1e3)),Promise.reject(e)):(Dd=!0,mr.closeAll(),mr.error("\u8BF7\u6C42\u51FA\u9519\uFF01\uFF01\uFF01"),Promise.reject(e))});function qi(e,t){return en.post(e,t)}function ec(e,t){return en({url:e,method:"delete",data:t})}function ji(e,t){return en.get(e,{params:t})}function KA(e,t){return en.put(e,t)}const tT={tokenRefresh:()=>qi("/tokenRefresh",{appId:0}),login:()=>qi("/jwt/login",{username:"hxy",password:"hxy123"}),folder:()=>ji("/configure/folder/list"),folderData:e=>ji("/configure/diagram/getInfoByFolderId",{folderId:e}),folderAdd:(e,t)=>qi("/configure/folder/add",{name:e,types:t}),folderEdit:(e,t,i)=>qi("/configure/folder/edit",{name:e,types:t,id:i}),folderDel:e=>ec("/configure/folder/del",{id:e}),topologyAdd:e=>qi("/configure/diagram/add",e),topologyEdit:e=>qi("/configure/diagram/edit",e),topologyDel:e=>ec("/configure/diagram/del",{id:e}),topology:e=>ji("/configure/diagram/getInfoById",{id:e}),topologyName:e=>ji("/configure/diagram/getInfoByName",{name:e}),deviceList:()=>ji("/product/device/list"),functionList:e=>ji("/product/tsl/function/all",e),devicePoint:e=>ji(`/configure/devicePoint/${e}`),do:e=>qi("/product/function/do",e),uploadImg:e=>qi("/common/singleImg",e),drawer:{pointAdd:e=>qi("/configure/point/add",e),pointDel:e=>ec("/configure/point/del",{id:e}),pointEdit:e=>KA("/configure/point/edit",e),getEchartInfo:e=>ji("/configure/point/getEchartInfo",e),getInfoByDiagramIdAndPointId:e=>ji("/configure/point/getInfoByDiagramIdAndPointId",e)}};var nn={};(function(e){var t=typeof Uint8Array<"u"&&typeof Uint16Array<"u"&&typeof Int32Array<"u";function i(s,a){return Object.prototype.hasOwnProperty.call(s,a)}e.assign=function(s){for(var a=Array.prototype.slice.call(arguments,1);a.length;){var l=a.shift();if(!!l){if(typeof l!="object")throw new TypeError(l+"must be non-object");for(var c in l)i(l,c)&&(s[c]=l[c])}}return s},e.shrinkBuf=function(s,a){return s.length===a?s:s.subarray?s.subarray(0,a):(s.length=a,s)};var n={arraySet:function(s,a,l,c,u){if(a.subarray&&s.subarray){s.set(a.subarray(l,l+c),u);return}for(var h=0;h=0;)e[t]=0}var ZA=0,Tg=1,JA=2,QA=3,tR=258,Xc=29,Ts=256,ws=Ts+1+Xc,Lr=30,Gc=19,Sg=2*ws+1,Un=15,ic=16,eR=7,Zc=256,Pg=16,Ig=17,Lg=18,Rc=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],Na=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],iR=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],Dg=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],nR=512,Yi=new Array((ws+2)*2);Fr(Yi);var fs=new Array(Lr*2);Fr(fs);var bs=new Array(nR);Fr(bs);var xs=new Array(tR-QA+1);Fr(xs);var Jc=new Array(Xc);Fr(Jc);var Xa=new Array(Lr);Fr(Xa);function nc(e,t,i,n,r){this.static_tree=e,this.extra_bits=t,this.extra_base=i,this.elems=n,this.max_length=r,this.has_stree=e&&e.length}var Mg,Bg,Og;function rc(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}function Ng(e){return e<256?bs[e]:bs[256+(e>>>7)]}function _s(e,t){e.pending_buf[e.pending++]=t&255,e.pending_buf[e.pending++]=t>>>8&255}function Ue(e,t,i){e.bi_valid>ic-i?(e.bi_buf|=t<>ic-e.bi_valid,e.bi_valid+=i-ic):(e.bi_buf|=t<>>=1,i<<=1;while(--t>0);return i>>>1}function rR(e){e.bi_valid===16?(_s(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=e.bi_buf&255,e.bi_buf>>=8,e.bi_valid-=8)}function sR(e,t){var i=t.dyn_tree,n=t.max_code,r=t.stat_desc.static_tree,s=t.stat_desc.has_stree,a=t.stat_desc.extra_bits,l=t.stat_desc.extra_base,c=t.stat_desc.max_length,u,h,d,g,v,y,w=0;for(g=0;g<=Un;g++)e.bl_count[g]=0;for(i[e.heap[e.heap_max]*2+1]=0,u=e.heap_max+1;uc&&(g=c,w++),i[h*2+1]=g,!(h>n)&&(e.bl_count[g]++,v=0,h>=l&&(v=a[h-l]),y=i[h*2],e.opt_len+=y*(g+v),s&&(e.static_len+=y*(r[h*2+1]+v)));if(w!==0){do{for(g=c-1;e.bl_count[g]===0;)g--;e.bl_count[g]--,e.bl_count[g+1]+=2,e.bl_count[c]--,w-=2}while(w>0);for(g=c;g!==0;g--)for(h=e.bl_count[g];h!==0;)d=e.heap[--u],!(d>n)&&(i[d*2+1]!==g&&(e.opt_len+=(g-i[d*2+1])*i[d*2],i[d*2+1]=g),h--)}}function zg(e,t,i){var n=new Array(Un+1),r=0,s,a;for(s=1;s<=Un;s++)n[s]=r=r+i[s-1]<<1;for(a=0;a<=t;a++){var l=e[a*2+1];l!==0&&(e[a*2]=Fg(n[l]++,l))}}function aR(){var e,t,i,n,r,s=new Array(Un+1);for(i=0,n=0;n>=7;n8?_s(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0}function oR(e,t,i,n){Ug(e),n&&(_s(e,i),_s(e,~i)),YA.arraySet(e.pending_buf,e.window,t,i,e.pending),e.pending+=i}function Od(e,t,i,n){var r=t*2,s=i*2;return e[r]>1;a>=1;a--)sc(e,i,a);u=s;do a=e.heap[1],e.heap[1]=e.heap[e.heap_len--],sc(e,i,1),l=e.heap[1],e.heap[--e.heap_max]=a,e.heap[--e.heap_max]=l,i[u*2]=i[a*2]+i[l*2],e.depth[u]=(e.depth[a]>=e.depth[l]?e.depth[a]:e.depth[l])+1,i[a*2+1]=i[l*2+1]=u,e.heap[1]=u++,sc(e,i,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],sR(e,t),zg(i,c,e.bl_count)}function Fd(e,t,i){var n,r=-1,s,a=t[0*2+1],l=0,c=7,u=4;for(a===0&&(c=138,u=3),t[(i+1)*2+1]=65535,n=0;n<=i;n++)s=a,a=t[(n+1)*2+1],!(++l=3&&e.bl_tree[Dg[t]*2+1]===0;t--);return e.opt_len+=3*(t+1)+5+5+4,t}function cR(e,t,i,n){var r;for(Ue(e,t-257,5),Ue(e,i-1,5),Ue(e,n-4,4),r=0;r>>=1)if(t&1&&e.dyn_ltree[i*2]!==0)return Md;if(e.dyn_ltree[9*2]!==0||e.dyn_ltree[10*2]!==0||e.dyn_ltree[13*2]!==0)return Bd;for(i=32;i0?(e.strm.data_type===GA&&(e.strm.data_type=hR(e)),Cc(e,e.l_desc),Cc(e,e.d_desc),a=lR(e),r=e.opt_len+3+7>>>3,s=e.static_len+3+7>>>3,s<=r&&(r=s)):r=s=i+5,i+4<=r&&t!==-1?Wg(e,t,i,n):e.strategy===XA||s===r?(Ue(e,(Tg<<1)+(n?1:0),3),Nd(e,Yi,fs)):(Ue(e,(JA<<1)+(n?1:0),3),cR(e,e.l_desc.max_code+1,e.d_desc.max_code+1,a+1),Nd(e,e.dyn_ltree,e.dyn_dtree)),Hg(e),n&&Ug(e)}function vR(e,t,i){return e.pending_buf[e.d_buf+e.last_lit*2]=t>>>8&255,e.pending_buf[e.d_buf+e.last_lit*2+1]=t&255,e.pending_buf[e.l_buf+e.last_lit]=i&255,e.last_lit++,t===0?e.dyn_ltree[i*2]++:(e.matches++,t--,e.dyn_ltree[(xs[i]+Ts+1)*2]++,e.dyn_dtree[Ng(t)*2]++),e.last_lit===e.lit_bufsize-1}Nr._tr_init=uR;Nr._tr_stored_block=Wg;Nr._tr_flush_block=dR;Nr._tr_tally=vR;Nr._tr_align=fR;function gR(e,t,i,n){for(var r=e&65535|0,s=e>>>16&65535|0,a=0;i!==0;){a=i>2e3?2e3:i,i-=a;do r=r+t[n++]|0,s=s+r|0;while(--a);r%=65521,s%=65521}return r|s<<16|0}var qg=gR;function yR(){for(var e,t=[],i=0;i<256;i++){e=i;for(var n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;t[i]=e}return t}var mR=yR();function pR(e,t,i,n){var r=mR,s=n+i;e^=-1;for(var a=n;a>>8^r[(e^t[a])&255];return e^-1}var jg=pR,Qc={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},De=nn,ui=Nr,Vg=qg,pn=jg,wR=Qc,tr=0,bR=1,xR=3,En=4,Ud=5,Pi=0,Wd=1,fi=-2,_R=-3,ac=-5,kR=-1,ER=1,Ta=2,AR=3,RR=4,CR=0,TR=2,no=8,SR=9,PR=15,IR=8,LR=29,DR=256,Tc=DR+1+LR,MR=30,BR=19,OR=2*Tc+1,NR=15,Ut=3,_n=258,wi=_n+Ut+1,FR=32,ro=42,Sc=69,Fa=73,za=91,Ha=103,Wn=113,os=666,me=1,Ss=2,Yn=3,zr=4,zR=3;function kn(e,t){return e.msg=wR[t],t}function qd(e){return(e<<1)-(e>4?9:0)}function xn(e){for(var t=e.length;--t>=0;)e[t]=0}function wn(e){var t=e.state,i=t.pending;i>e.avail_out&&(i=e.avail_out),i!==0&&(De.arraySet(e.output,t.pending_buf,t.pending_out,i,e.next_out),e.next_out+=i,t.pending_out+=i,e.total_out+=i,e.avail_out-=i,t.pending-=i,t.pending===0&&(t.pending_out=0))}function Re(e,t){ui._tr_flush_block(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,wn(e.strm)}function Wt(e,t){e.pending_buf[e.pending++]=t}function ns(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=t&255}function HR(e,t,i,n){var r=e.avail_in;return r>n&&(r=n),r===0?0:(e.avail_in-=r,De.arraySet(t,e.input,e.next_in,r,i),e.state.wrap===1?e.adler=Vg(e.adler,t,r,i):e.state.wrap===2&&(e.adler=pn(e.adler,t,r,i)),e.next_in+=r,e.total_in+=r,r)}function $g(e,t){var i=e.max_chain_length,n=e.strstart,r,s,a=e.prev_length,l=e.nice_match,c=e.strstart>e.w_size-wi?e.strstart-(e.w_size-wi):0,u=e.window,h=e.w_mask,d=e.prev,g=e.strstart+_n,v=u[n+a-1],y=u[n+a];e.prev_length>=e.good_match&&(i>>=2),l>e.lookahead&&(l=e.lookahead);do if(r=t,!(u[r+a]!==y||u[r+a-1]!==v||u[r]!==u[n]||u[++r]!==u[n+1])){n+=2,r++;do;while(u[++n]===u[++r]&&u[++n]===u[++r]&&u[++n]===u[++r]&&u[++n]===u[++r]&&u[++n]===u[++r]&&u[++n]===u[++r]&&u[++n]===u[++r]&&u[++n]===u[++r]&&na){if(e.match_start=t,a=s,s>=l)break;v=u[n+a-1],y=u[n+a]}}while((t=d[t&h])>c&&--i!==0);return a<=e.lookahead?a:e.lookahead}function Xn(e){var t=e.w_size,i,n,r,s,a;do{if(s=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-wi)){De.arraySet(e.window,e.window,t,t,0),e.match_start-=t,e.strstart-=t,e.block_start-=t,n=e.hash_size,i=n;do r=e.head[--i],e.head[i]=r>=t?r-t:0;while(--n);n=t,i=n;do r=e.prev[--i],e.prev[i]=r>=t?r-t:0;while(--n);s+=t}if(e.strm.avail_in===0)break;if(n=HR(e.strm,e.window,e.strstart+e.lookahead,s),e.lookahead+=n,e.lookahead+e.insert>=Ut)for(a=e.strstart-e.insert,e.ins_h=e.window[a],e.ins_h=(e.ins_h<e.pending_buf_size-5&&(i=e.pending_buf_size-5);;){if(e.lookahead<=1){if(Xn(e),e.lookahead===0&&t===tr)return me;if(e.lookahead===0)break}e.strstart+=e.lookahead,e.lookahead=0;var n=e.block_start+i;if((e.strstart===0||e.strstart>=n)&&(e.lookahead=e.strstart-n,e.strstart=n,Re(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-wi&&(Re(e,!1),e.strm.avail_out===0))return me}return e.insert=0,t===En?(Re(e,!0),e.strm.avail_out===0?Yn:zr):(e.strstart>e.block_start&&(Re(e,!1),e.strm.avail_out===0),me)}function oc(e,t){for(var i,n;;){if(e.lookahead=Ut&&(e.ins_h=(e.ins_h<=Ut)if(n=ui._tr_tally(e,e.strstart-e.match_start,e.match_length-Ut),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=Ut){e.match_length--;do e.strstart++,e.ins_h=(e.ins_h<=Ut&&(e.ins_h=(e.ins_h<4096)&&(e.match_length=Ut-1)),e.prev_length>=Ut&&e.match_length<=e.prev_length){r=e.strstart+e.lookahead-Ut,n=ui._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-Ut),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=r&&(e.ins_h=(e.ins_h<=Ut&&e.strstart>0&&(r=e.strstart-1,n=a[r],n===a[++r]&&n===a[++r]&&n===a[++r])){s=e.strstart+_n;do;while(n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&n===a[++r]&&re.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=Ut?(i=ui._tr_tally(e,1,e.match_length-Ut),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(i=ui._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),i&&(Re(e,!1),e.strm.avail_out===0))return me}return e.insert=0,t===En?(Re(e,!0),e.strm.avail_out===0?Yn:zr):e.last_lit&&(Re(e,!1),e.strm.avail_out===0)?me:Ss}function qR(e,t){for(var i;;){if(e.lookahead===0&&(Xn(e),e.lookahead===0)){if(t===tr)return me;break}if(e.match_length=0,i=ui._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,i&&(Re(e,!1),e.strm.avail_out===0))return me}return e.insert=0,t===En?(Re(e,!0),e.strm.avail_out===0?Yn:zr):e.last_lit&&(Re(e,!1),e.strm.avail_out===0)?me:Ss}function Ai(e,t,i,n,r){this.good_length=e,this.max_lazy=t,this.nice_length=i,this.max_chain=n,this.func=r}var Sr;Sr=[new Ai(0,0,0,0,UR),new Ai(4,4,8,4,oc),new Ai(4,5,16,8,oc),new Ai(4,6,32,32,oc),new Ai(4,4,16,16,kr),new Ai(8,16,32,32,kr),new Ai(8,16,128,128,kr),new Ai(8,32,128,256,kr),new Ai(32,128,258,1024,kr),new Ai(32,258,258,4096,kr)];function jR(e){e.window_size=2*e.w_size,xn(e.head),e.max_lazy_match=Sr[e.level].max_lazy,e.good_match=Sr[e.level].good_length,e.nice_match=Sr[e.level].nice_length,e.max_chain_length=Sr[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=Ut-1,e.match_available=0,e.ins_h=0}function VR(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=no,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new De.Buf16(OR*2),this.dyn_dtree=new De.Buf16((2*MR+1)*2),this.bl_tree=new De.Buf16((2*BR+1)*2),xn(this.dyn_ltree),xn(this.dyn_dtree),xn(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new De.Buf16(NR+1),this.heap=new De.Buf16(2*Tc+1),xn(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new De.Buf16(2*Tc+1),xn(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function Kg(e){var t;return!e||!e.state?kn(e,fi):(e.total_in=e.total_out=0,e.data_type=TR,t=e.state,t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?ro:Wn,e.adler=t.wrap===2?0:1,t.last_flush=tr,ui._tr_init(t),Pi)}function Yg(e){var t=Kg(e);return t===Pi&&jR(e.state),t}function $R(e,t){return!e||!e.state||e.state.wrap!==2?fi:(e.state.gzhead=t,Pi)}function Xg(e,t,i,n,r,s){if(!e)return fi;var a=1;if(t===kR&&(t=6),n<0?(a=0,n=-n):n>15&&(a=2,n-=16),r<1||r>SR||i!==no||n<8||n>15||t<0||t>9||s<0||s>RR)return kn(e,fi);n===8&&(n=9);var l=new VR;return e.state=l,l.strm=e,l.wrap=a,l.gzhead=null,l.w_bits=n,l.w_size=1<Ud||t<0)return e?kn(e,fi):fi;if(n=e.state,!e.output||!e.input&&e.avail_in!==0||n.status===os&&t!==En)return kn(e,e.avail_out===0?ac:fi);if(n.strm=e,i=n.last_flush,n.last_flush=t,n.status===ro)if(n.wrap===2)e.adler=0,Wt(n,31),Wt(n,139),Wt(n,8),n.gzhead?(Wt(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),Wt(n,n.gzhead.time&255),Wt(n,n.gzhead.time>>8&255),Wt(n,n.gzhead.time>>16&255),Wt(n,n.gzhead.time>>24&255),Wt(n,n.level===9?2:n.strategy>=Ta||n.level<2?4:0),Wt(n,n.gzhead.os&255),n.gzhead.extra&&n.gzhead.extra.length&&(Wt(n,n.gzhead.extra.length&255),Wt(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=pn(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=Sc):(Wt(n,0),Wt(n,0),Wt(n,0),Wt(n,0),Wt(n,0),Wt(n,n.level===9?2:n.strategy>=Ta||n.level<2?4:0),Wt(n,zR),n.status=Wn);else{var a=no+(n.w_bits-8<<4)<<8,l=-1;n.strategy>=Ta||n.level<2?l=0:n.level<6?l=1:n.level===6?l=2:l=3,a|=l<<6,n.strstart!==0&&(a|=FR),a+=31-a%31,n.status=Wn,ns(n,a),n.strstart!==0&&(ns(n,e.adler>>>16),ns(n,e.adler&65535)),e.adler=1}if(n.status===Sc)if(n.gzhead.extra){for(r=n.pending;n.gzindex<(n.gzhead.extra.length&65535)&&!(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>r&&(e.adler=pn(e.adler,n.pending_buf,n.pending-r,r)),wn(e),r=n.pending,n.pending===n.pending_buf_size));)Wt(n,n.gzhead.extra[n.gzindex]&255),n.gzindex++;n.gzhead.hcrc&&n.pending>r&&(e.adler=pn(e.adler,n.pending_buf,n.pending-r,r)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=Fa)}else n.status=Fa;if(n.status===Fa)if(n.gzhead.name){r=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>r&&(e.adler=pn(e.adler,n.pending_buf,n.pending-r,r)),wn(e),r=n.pending,n.pending===n.pending_buf_size)){s=1;break}n.gzindexr&&(e.adler=pn(e.adler,n.pending_buf,n.pending-r,r)),s===0&&(n.gzindex=0,n.status=za)}else n.status=za;if(n.status===za)if(n.gzhead.comment){r=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>r&&(e.adler=pn(e.adler,n.pending_buf,n.pending-r,r)),wn(e),r=n.pending,n.pending===n.pending_buf_size)){s=1;break}n.gzindexr&&(e.adler=pn(e.adler,n.pending_buf,n.pending-r,r)),s===0&&(n.status=Ha)}else n.status=Ha;if(n.status===Ha&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&wn(e),n.pending+2<=n.pending_buf_size&&(Wt(n,e.adler&255),Wt(n,e.adler>>8&255),e.adler=0,n.status=Wn)):n.status=Wn),n.pending!==0){if(wn(e),e.avail_out===0)return n.last_flush=-1,Pi}else if(e.avail_in===0&&qd(t)<=qd(i)&&t!==En)return kn(e,ac);if(n.status===os&&e.avail_in!==0)return kn(e,ac);if(e.avail_in!==0||n.lookahead!==0||t!==tr&&n.status!==os){var c=n.strategy===Ta?qR(n,t):n.strategy===AR?WR(n,t):Sr[n.level].func(n,t);if((c===Yn||c===zr)&&(n.status=os),c===me||c===Yn)return e.avail_out===0&&(n.last_flush=-1),Pi;if(c===Ss&&(t===bR?ui._tr_align(n):t!==Ud&&(ui._tr_stored_block(n,0,0,!1),t===xR&&(xn(n.head),n.lookahead===0&&(n.strstart=0,n.block_start=0,n.insert=0))),wn(e),e.avail_out===0))return n.last_flush=-1,Pi}return t!==En?Pi:n.wrap<=0?Wd:(n.wrap===2?(Wt(n,e.adler&255),Wt(n,e.adler>>8&255),Wt(n,e.adler>>16&255),Wt(n,e.adler>>24&255),Wt(n,e.total_in&255),Wt(n,e.total_in>>8&255),Wt(n,e.total_in>>16&255),Wt(n,e.total_in>>24&255)):(ns(n,e.adler>>>16),ns(n,e.adler&65535)),wn(e),n.wrap>0&&(n.wrap=-n.wrap),n.pending!==0?Pi:Wd)}function XR(e){var t;return!e||!e.state?fi:(t=e.state.status,t!==ro&&t!==Sc&&t!==Fa&&t!==za&&t!==Ha&&t!==Wn&&t!==os?kn(e,fi):(e.state=null,t===Wn?kn(e,_R):Pi))}function GR(e,t){var i=t.length,n,r,s,a,l,c,u,h;if(!e||!e.state||(n=e.state,a=n.wrap,a===2||a===1&&n.status!==ro||n.lookahead))return fi;for(a===1&&(e.adler=Vg(e.adler,t,i,0)),n.wrap=0,i>=n.w_size&&(a===0&&(xn(n.head),n.strstart=0,n.block_start=0,n.insert=0),h=new De.Buf8(n.w_size),De.arraySet(h,t,i-n.w_size,n.w_size,0),t=h,i=n.w_size),l=e.avail_in,c=e.next_in,u=e.input,e.avail_in=i,e.next_in=0,e.input=t,Xn(n);n.lookahead>=Ut;){r=n.strstart,s=n.lookahead-(Ut-1);do n.ins_h=(n.ins_h<=252?6:vn>=248?5:vn>=240?4:vn>=224?3:vn>=192?2:1;ks[254]=ks[254]=1;er.string2buf=function(e){var t,i,n,r,s,a=e.length,l=0;for(r=0;r>>6,t[s++]=128|i&63):i<65536?(t[s++]=224|i>>>12,t[s++]=128|i>>>6&63,t[s++]=128|i&63):(t[s++]=240|i>>>18,t[s++]=128|i>>>12&63,t[s++]=128|i>>>6&63,t[s++]=128|i&63);return t};function Jg(e,t){if(t<65534&&(e.subarray&&Zg||!e.subarray&&Gg))return String.fromCharCode.apply(null,so.shrinkBuf(e,t));for(var i="",n=0;n4){l[n++]=65533,i+=s-1;continue}for(r&=s===2?31:s===3?15:7;s>1&&i1){l[n++]=65533;continue}r<65536?l[n++]=r:(r-=65536,l[n++]=55296|r>>10&1023,l[n++]=56320|r&1023)}return Jg(l,n)};er.utf8border=function(e,t){var i;for(t=t||e.length,t>e.length&&(t=e.length),i=t-1;i>=0&&(e[i]&192)===128;)i--;return i<0||i===0?t:i+ks[e[i]]>t?i:t};function ZR(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var Qg=ZR,ds=Di,vs=nn,Pc=er,Ic=Qc,JR=Qg,ty=Object.prototype.toString,QR=0,lc=4,Dr=0,jd=1,Vd=2,tC=-1,eC=0,iC=8;function Gn(e){if(!(this instanceof Gn))return new Gn(e);this.options=vs.assign({level:tC,method:iC,chunkSize:16384,windowBits:15,memLevel:8,strategy:eC,to:""},e||{});var t=this.options;t.raw&&t.windowBits>0?t.windowBits=-t.windowBits:t.gzip&&t.windowBits>0&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new JR,this.strm.avail_out=0;var i=ds.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(i!==Dr)throw new Error(Ic[i]);if(t.header&&ds.deflateSetHeader(this.strm,t.header),t.dictionary){var n;if(typeof t.dictionary=="string"?n=Pc.string2buf(t.dictionary):ty.call(t.dictionary)==="[object ArrayBuffer]"?n=new Uint8Array(t.dictionary):n=t.dictionary,i=ds.deflateSetDictionary(this.strm,n),i!==Dr)throw new Error(Ic[i]);this._dict_set=!0}}Gn.prototype.push=function(e,t){var i=this.strm,n=this.options.chunkSize,r,s;if(this.ended)return!1;s=t===~~t?t:t===!0?lc:QR,typeof e=="string"?i.input=Pc.string2buf(e):ty.call(e)==="[object ArrayBuffer]"?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;do{if(i.avail_out===0&&(i.output=new vs.Buf8(n),i.next_out=0,i.avail_out=n),r=ds.deflate(i,s),r!==jd&&r!==Dr)return this.onEnd(r),this.ended=!0,!1;(i.avail_out===0||i.avail_in===0&&(s===lc||s===Vd))&&(this.options.to==="string"?this.onData(Pc.buf2binstring(vs.shrinkBuf(i.output,i.next_out))):this.onData(vs.shrinkBuf(i.output,i.next_out)))}while((i.avail_in>0||i.avail_out===0)&&r!==jd);return s===lc?(r=ds.deflateEnd(this.strm),this.onEnd(r),this.ended=!0,r===Dr):(s===Vd&&(this.onEnd(Dr),i.avail_out=0),!0)};Gn.prototype.onData=function(e){this.chunks.push(e)};Gn.prototype.onEnd=function(e){e===Dr&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=vs.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function th(e,t){var i=new Gn(t);if(i.push(e,!0),i.err)throw i.msg||Ic[i.err];return i.result}function nC(e,t){return t=t||{},t.raw=!0,th(e,t)}function rC(e,t){return t=t||{},t.gzip=!0,th(e,t)}Cs.Deflate=Gn;Cs.deflate=th;Cs.deflateRaw=nC;Cs.gzip=rC;var Ps={},bi={},Sa=30,sC=12,aC=function(t,i){var n,r,s,a,l,c,u,h,d,g,v,y,w,p,_,A,x,E,I,M,B,D,q,Q,C;n=t.state,r=t.next_in,Q=t.input,s=r+(t.avail_in-5),a=t.next_out,C=t.output,l=a-(i-t.avail_out),c=a+(t.avail_out-257),u=n.dmax,h=n.wsize,d=n.whave,g=n.wnext,v=n.window,y=n.hold,w=n.bits,p=n.lencode,_=n.distcode,A=(1<>>24,y>>>=I,w-=I,I=E>>>16&255,I===0)C[a++]=E&65535;else if(I&16){M=E&65535,I&=15,I&&(w>>=I,w-=I),w<15&&(y+=Q[r++]<>>24,y>>>=I,w-=I,I=E>>>16&255,I&16){if(B=E&65535,I&=15,wu){t.msg="invalid distance too far back",n.mode=Sa;break t}if(y>>>=I,w-=I,I=a-l,B>I){if(I=B-I,I>d&&n.sane){t.msg="invalid distance too far back",n.mode=Sa;break t}if(D=0,q=v,g===0){if(D+=h-I,I2;)C[a++]=q[D++],C[a++]=q[D++],C[a++]=q[D++],M-=3;M&&(C[a++]=q[D++],M>1&&(C[a++]=q[D++]))}else{D=a-B;do C[a++]=C[D++],C[a++]=C[D++],C[a++]=C[D++],M-=3;while(M>2);M&&(C[a++]=C[D++],M>1&&(C[a++]=C[D++]))}}else if((I&64)===0){E=_[(E&65535)+(y&(1<>3,r-=M,w-=M<<3,y&=(1<=1&&T[v]===0;v--);if(y>v&&(y=v),v===0)return s[a++]=1<<24|64<<16|0,s[a++]=1<<24|64<<16|0,c.bits=1,0;for(g=1;g0&&(t===Xd||v!==1))return-1;for(S[1]=0,h=1;hKd||t===Gd&&A>Yd)return 1;for(;;){Z=h-p,l[d]C?(st=O[K+l[d]],$=q[Q+l[d]]):(st=32+64,$=0),E=1<>p)+I]=Z<<24|st<<16|$|0;while(I!==0);for(E=1<>=1;if(E!==0?(x&=E-1,x+=E):x=0,d++,--T[h]===0){if(h===v)break;h=i[n+l[d]]}if(h>y&&(x&B)!==M){for(p===0&&(p=y),D+=g,w=h-p,_=1<Kd||t===Gd&&A>Yd)return 1;M=x&B,s[M]=y<<24|w<<16|D-a|0}}return x!==0&&(s[D+x]=h-p<<24|64<<16|0),c.bits=y,0},Qe=nn,Lc=qg,Ri=jg,fC=aC,gs=uC,dC=0,ey=1,iy=2,Zd=4,vC=5,Pa=6,Zn=0,gC=1,yC=2,di=-2,ny=-3,ry=-4,mC=-5,Jd=8,sy=1,Qd=2,tv=3,ev=4,iv=5,nv=6,rv=7,sv=8,av=9,ov=10,Ga=11,Vi=12,hc=13,lv=14,uc=15,cv=16,hv=17,uv=18,fv=19,Ia=20,La=21,dv=22,vv=23,gv=24,yv=25,mv=26,fc=27,pv=28,wv=29,se=30,ay=31,pC=32,wC=852,bC=592,xC=15,_C=xC;function bv(e){return(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24)}function kC(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Qe.Buf16(320),this.work=new Qe.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function oy(e){var t;return!e||!e.state?di:(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=t.wrap&1),t.mode=sy,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Qe.Buf32(wC),t.distcode=t.distdyn=new Qe.Buf32(bC),t.sane=1,t.back=-1,Zn)}function ly(e){var t;return!e||!e.state?di:(t=e.state,t.wsize=0,t.whave=0,t.wnext=0,oy(e))}function cy(e,t){var i,n;return!e||!e.state||(n=e.state,t<0?(i=0,t=-t):(i=(t>>4)+1,t<48&&(t&=15)),t&&(t<8||t>15))?di:(n.window!==null&&n.wbits!==t&&(n.window=null),n.wrap=i,n.wbits=t,ly(e))}function hy(e,t){var i,n;return e?(n=new kC,e.state=n,n.window=null,i=cy(e,t),i!==Zn&&(e.state=null),i):di}function EC(e){return hy(e,_C)}var xv=!0,dc,vc;function AC(e){if(xv){var t;for(dc=new Qe.Buf32(512),vc=new Qe.Buf32(32),t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(gs(ey,e.lens,0,288,dc,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;gs(iy,e.lens,0,32,vc,0,e.work,{bits:5}),xv=!1}e.lencode=dc,e.lenbits=9,e.distcode=vc,e.distbits=5}function uy(e,t,i,n){var r,s=e.state;return s.window===null&&(s.wsize=1<=s.wsize?(Qe.arraySet(s.window,t,i-s.wsize,s.wsize,0),s.wnext=0,s.whave=s.wsize):(r=s.wsize-s.wnext,r>n&&(r=n),Qe.arraySet(s.window,t,i-n,r,s.wnext),n-=r,n?(Qe.arraySet(s.window,t,i-n,n,0),s.wnext=n,s.whave=s.wsize):(s.wnext+=r,s.wnext===s.wsize&&(s.wnext=0),s.whave>>8&255,i.check=Ri(i.check,q,2,0),u=0,h=0,i.mode=Qd;break}if(i.flags=0,i.head&&(i.head.done=!1),!(i.wrap&1)||(((u&255)<<8)+(u>>8))%31){e.msg="incorrect header check",i.mode=se;break}if((u&15)!==Jd){e.msg="unknown compression method",i.mode=se;break}if(u>>>=4,h-=4,B=(u&15)+8,i.wbits===0)i.wbits=B;else if(B>i.wbits){e.msg="invalid window size",i.mode=se;break}i.dmax=1<>8&1),i.flags&512&&(q[0]=u&255,q[1]=u>>>8&255,i.check=Ri(i.check,q,2,0)),u=0,h=0,i.mode=tv;case tv:for(;h<32;){if(l===0)break t;l--,u+=n[s++]<>>8&255,q[2]=u>>>16&255,q[3]=u>>>24&255,i.check=Ri(i.check,q,4,0)),u=0,h=0,i.mode=ev;case ev:for(;h<16;){if(l===0)break t;l--,u+=n[s++]<>8),i.flags&512&&(q[0]=u&255,q[1]=u>>>8&255,i.check=Ri(i.check,q,2,0)),u=0,h=0,i.mode=iv;case iv:if(i.flags&1024){for(;h<16;){if(l===0)break t;l--,u+=n[s++]<>>8&255,i.check=Ri(i.check,q,2,0)),u=0,h=0}else i.head&&(i.head.extra=null);i.mode=nv;case nv:if(i.flags&1024&&(v=i.length,v>l&&(v=l),v&&(i.head&&(B=i.head.extra_len-i.length,i.head.extra||(i.head.extra=new Array(i.head.extra_len)),Qe.arraySet(i.head.extra,n,s,v,B)),i.flags&512&&(i.check=Ri(i.check,n,v,s)),l-=v,s+=v,i.length-=v),i.length))break t;i.length=0,i.mode=rv;case rv:if(i.flags&2048){if(l===0)break t;v=0;do B=n[s+v++],i.head&&B&&i.length<65536&&(i.head.name+=String.fromCharCode(B));while(B&&v>9&1,i.head.done=!0),e.adler=i.check=0,i.mode=Vi;break;case ov:for(;h<32;){if(l===0)break t;l--,u+=n[s++]<>>=h&7,h-=h&7,i.mode=fc;break}for(;h<3;){if(l===0)break t;l--,u+=n[s++]<>>=1,h-=1,u&3){case 0:i.mode=lv;break;case 1:if(AC(i),i.mode=Ia,t===Pa){u>>>=2,h-=2;break t}break;case 2:i.mode=hv;break;case 3:e.msg="invalid block type",i.mode=se}u>>>=2,h-=2;break;case lv:for(u>>>=h&7,h-=h&7;h<32;){if(l===0)break t;l--,u+=n[s++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=se;break}if(i.length=u&65535,u=0,h=0,i.mode=uc,t===Pa)break t;case uc:i.mode=cv;case cv:if(v=i.length,v){if(v>l&&(v=l),v>c&&(v=c),v===0)break t;Qe.arraySet(r,n,s,v,a),l-=v,s+=v,c-=v,a+=v,i.length-=v;break}i.mode=Vi;break;case hv:for(;h<14;){if(l===0)break t;l--,u+=n[s++]<>>=5,h-=5,i.ndist=(u&31)+1,u>>>=5,h-=5,i.ncode=(u&15)+4,u>>>=4,h-=4,i.nlen>286||i.ndist>30){e.msg="too many length or distance symbols",i.mode=se;break}i.have=0,i.mode=uv;case uv:for(;i.have>>=3,h-=3}for(;i.have<19;)i.lens[T[i.have++]]=0;if(i.lencode=i.lendyn,i.lenbits=7,Q={bits:i.lenbits},D=gs(dC,i.lens,0,19,i.lencode,0,i.work,Q),i.lenbits=Q.bits,D){e.msg="invalid code lengths set",i.mode=se;break}i.have=0,i.mode=fv;case fv:for(;i.have>>24,A=p>>>16&255,x=p&65535,!(_<=h);){if(l===0)break t;l--,u+=n[s++]<>>=_,h-=_,i.lens[i.have++]=x;else{if(x===16){for(C=_+2;h>>=_,h-=_,i.have===0){e.msg="invalid bit length repeat",i.mode=se;break}B=i.lens[i.have-1],v=3+(u&3),u>>>=2,h-=2}else if(x===17){for(C=_+3;h>>=_,h-=_,B=0,v=3+(u&7),u>>>=3,h-=3}else{for(C=_+7;h>>=_,h-=_,B=0,v=11+(u&127),u>>>=7,h-=7}if(i.have+v>i.nlen+i.ndist){e.msg="invalid bit length repeat",i.mode=se;break}for(;v--;)i.lens[i.have++]=B}}if(i.mode===se)break;if(i.lens[256]===0){e.msg="invalid code -- missing end-of-block",i.mode=se;break}if(i.lenbits=9,Q={bits:i.lenbits},D=gs(ey,i.lens,0,i.nlen,i.lencode,0,i.work,Q),i.lenbits=Q.bits,D){e.msg="invalid literal/lengths set",i.mode=se;break}if(i.distbits=6,i.distcode=i.distdyn,Q={bits:i.distbits},D=gs(iy,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,Q),i.distbits=Q.bits,D){e.msg="invalid distances set",i.mode=se;break}if(i.mode=Ia,t===Pa)break t;case Ia:i.mode=La;case La:if(l>=6&&c>=258){e.next_out=a,e.avail_out=c,e.next_in=s,e.avail_in=l,i.hold=u,i.bits=h,fC(e,g),a=e.next_out,r=e.output,c=e.avail_out,s=e.next_in,n=e.input,l=e.avail_in,u=i.hold,h=i.bits,i.mode===Vi&&(i.back=-1);break}for(i.back=0;p=i.lencode[u&(1<>>24,A=p>>>16&255,x=p&65535,!(_<=h);){if(l===0)break t;l--,u+=n[s++]<>E)],_=p>>>24,A=p>>>16&255,x=p&65535,!(E+_<=h);){if(l===0)break t;l--,u+=n[s++]<>>=E,h-=E,i.back+=E}if(u>>>=_,h-=_,i.back+=_,i.length=x,A===0){i.mode=mv;break}if(A&32){i.back=-1,i.mode=Vi;break}if(A&64){e.msg="invalid literal/length code",i.mode=se;break}i.extra=A&15,i.mode=dv;case dv:if(i.extra){for(C=i.extra;h>>=i.extra,h-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=vv;case vv:for(;p=i.distcode[u&(1<>>24,A=p>>>16&255,x=p&65535,!(_<=h);){if(l===0)break t;l--,u+=n[s++]<>E)],_=p>>>24,A=p>>>16&255,x=p&65535,!(E+_<=h);){if(l===0)break t;l--,u+=n[s++]<>>=E,h-=E,i.back+=E}if(u>>>=_,h-=_,i.back+=_,A&64){e.msg="invalid distance code",i.mode=se;break}i.offset=x,i.extra=A&15,i.mode=gv;case gv:if(i.extra){for(C=i.extra;h>>=i.extra,h-=i.extra,i.back+=i.extra}if(i.offset>i.dmax){e.msg="invalid distance too far back",i.mode=se;break}i.mode=yv;case yv:if(c===0)break t;if(v=g-c,i.offset>v){if(v=i.offset-v,v>i.whave&&i.sane){e.msg="invalid distance too far back",i.mode=se;break}v>i.wnext?(v-=i.wnext,y=i.wsize-v):y=i.wnext-v,v>i.length&&(v=i.length),w=i.window}else w=r,y=a-i.offset,v=i.length;v>c&&(v=c),c-=v,i.length-=v;do r[a++]=w[y++];while(--v);i.length===0&&(i.mode=La);break;case mv:if(c===0)break t;r[a++]=i.length,c--,i.mode=La;break;case fc:if(i.wrap){for(;h<32;){if(l===0)break t;l--,u|=n[s++]<=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,t.windowBits===0&&(t.windowBits=-15)),t.windowBits>=0&&t.windowBits<16&&!(e&&e.windowBits)&&(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(t.windowBits&15)===0&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new LC,this.strm.avail_out=0;var i=Mr.inflateInit2(this.strm,t.windowBits);if(i!==de.Z_OK)throw new Error(Dc[i]);if(this.header=new DC,Mr.inflateGetHeader(this.strm,this.header),t.dictionary&&(typeof t.dictionary=="string"?t.dictionary=Ua.string2buf(t.dictionary):dy.call(t.dictionary)==="[object ArrayBuffer]"&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(i=Mr.inflateSetDictionary(this.strm,t.dictionary),i!==de.Z_OK)))throw new Error(Dc[i])}Jn.prototype.push=function(e,t){var i=this.strm,n=this.options.chunkSize,r=this.options.dictionary,s,a,l,c,u,h=!1;if(this.ended)return!1;a=t===~~t?t:t===!0?de.Z_FINISH:de.Z_NO_FLUSH,typeof e=="string"?i.input=Ua.binstring2buf(e):dy.call(e)==="[object ArrayBuffer]"?i.input=new Uint8Array(e):i.input=e,i.next_in=0,i.avail_in=i.input.length;do{if(i.avail_out===0&&(i.output=new ys.Buf8(n),i.next_out=0,i.avail_out=n),s=Mr.inflate(i,de.Z_NO_FLUSH),s===de.Z_NEED_DICT&&r&&(s=Mr.inflateSetDictionary(this.strm,r)),s===de.Z_BUF_ERROR&&h===!0&&(s=de.Z_OK,h=!1),s!==de.Z_STREAM_END&&s!==de.Z_OK)return this.onEnd(s),this.ended=!0,!1;i.next_out&&(i.avail_out===0||s===de.Z_STREAM_END||i.avail_in===0&&(a===de.Z_FINISH||a===de.Z_SYNC_FLUSH))&&(this.options.to==="string"?(l=Ua.utf8border(i.output,i.next_out),c=i.next_out-l,u=Ua.buf2string(i.output,l),i.next_out=c,i.avail_out=n-c,c&&ys.arraySet(i.output,i.output,l,c,0),this.onData(u)):this.onData(ys.shrinkBuf(i.output,i.next_out))),i.avail_in===0&&i.avail_out===0&&(h=!0)}while((i.avail_in>0||i.avail_out===0)&&s!==de.Z_STREAM_END);return s===de.Z_STREAM_END&&(a=de.Z_FINISH),a===de.Z_FINISH?(s=Mr.inflateEnd(this.strm),this.onEnd(s),this.ended=!0,s===de.Z_OK):(a===de.Z_SYNC_FLUSH&&(this.onEnd(de.Z_OK),i.avail_out=0),!0)};Jn.prototype.onData=function(e){this.chunks.push(e)};Jn.prototype.onEnd=function(e){e===de.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=ys.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function eh(e,t){var i=new Jn(t);if(i.push(e,!0),i.err)throw i.msg||Dc[i.err];return i.result}function MC(e,t){return t=t||{},t.raw=!0,eh(e,t)}Ps.Inflate=Jn;Ps.inflate=eh;Ps.inflateRaw=MC;Ps.ungzip=eh;var BC=nn.assign,OC=Cs,NC=Ps,FC=fy,vy={};BC(vy,OC,NC,FC);var eT=vy,Mc={exports:{}};/** * @license * Lodash * Copyright OpenJS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors */(function(e,t){(function(){var i,n="4.17.21",r=200,s="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",a="Expected a function",l="Invalid `variable` option passed into `_.template`",c="__lodash_hash_undefined__",u=500,h="__lodash_placeholder__",d=1,g=2,v=4,y=1,w=2,p=1,_=2,A=4,x=8,E=16,I=32,M=64,B=128,D=256,q=512,Q=30,C="...",T=800,S=16,O=1,K=2,Z=3,st=1/0,$=9007199254740991,z=17976931348623157e292,V=0/0,Y=4294967295,U=Y-1,tt=Y>>>1,rt=[["ary",B],["bind",p],["bindKey",_],["curry",x],["curryRight",E],["flip",q],["partial",I],["partialRight",M],["rearg",D]],nt="[object Arguments]",ft="[object Array]",lt="[object AsyncFunction]",ut="[object Boolean]",b="[object Date]",k="[object DOMException]",P="[object Error]",H="[object Function]",X="[object GeneratorFunction]",J="[object Map]",at="[object Number]",mt="[object Null]",yt="[object Object]",kt="[object Promise]",Tt="[object Proxy]",be="[object RegExp]",ne="[object Set]",xe="[object String]",Vt="[object Symbol]",Qt="[object Undefined]",xi="[object WeakMap]",gy="[object WeakSet]",Hr="[object ArrayBuffer]",ir="[object DataView]",ao="[object Float32Array]",oo="[object Float64Array]",lo="[object Int8Array]",co="[object Int16Array]",ho="[object Int32Array]",uo="[object Uint8Array]",fo="[object Uint8ClampedArray]",vo="[object Uint16Array]",go="[object Uint32Array]",yy=/\b__p \+= '';/g,my=/\b(__p \+=) '' \+/g,py=/(__e\(.*?\)|\b__t\)) \+\n'';/g,ih=/&(?:amp|lt|gt|quot|#39);/g,nh=/[&<>"']/g,wy=RegExp(ih.source),by=RegExp(nh.source),xy=/<%-([\s\S]+?)%>/g,_y=/<%([\s\S]+?)%>/g,rh=/<%=([\s\S]+?)%>/g,ky=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ey=/^\w*$/,Ay=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,yo=/[\\^$.*+?()[\]{}|]/g,Ry=RegExp(yo.source),mo=/^\s+/,Cy=/\s/,Ty=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,Sy=/\{\n\/\* \[wrapped with (.+)\] \*/,Py=/,? & /,Iy=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,Ly=/[()=,{}\[\]\/\s]/,Dy=/\\(\\)?/g,My=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,sh=/\w*$/,By=/^[-+]0x[0-9a-f]+$/i,Oy=/^0b[01]+$/i,Ny=/^\[object .+?Constructor\]$/,Fy=/^0o[0-7]+$/i,zy=/^(?:0|[1-9]\d*)$/,Hy=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Is=/($^)/,Uy=/['\n\r\u2028\u2029\\]/g,Ls="\\ud800-\\udfff",Wy="\\u0300-\\u036f",qy="\\ufe20-\\ufe2f",jy="\\u20d0-\\u20ff",ah=Wy+qy+jy,oh="\\u2700-\\u27bf",lh="a-z\\xdf-\\xf6\\xf8-\\xff",Vy="\\xac\\xb1\\xd7\\xf7",$y="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Ky="\\u2000-\\u206f",Yy=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",ch="A-Z\\xc0-\\xd6\\xd8-\\xde",hh="\\ufe0e\\ufe0f",uh=Vy+$y+Ky+Yy,po="['\u2019]",Xy="["+Ls+"]",fh="["+uh+"]",Ds="["+ah+"]",dh="\\d+",Gy="["+oh+"]",vh="["+lh+"]",gh="[^"+Ls+uh+dh+oh+lh+ch+"]",wo="\\ud83c[\\udffb-\\udfff]",Zy="(?:"+Ds+"|"+wo+")",yh="[^"+Ls+"]",bo="(?:\\ud83c[\\udde6-\\uddff]){2}",xo="[\\ud800-\\udbff][\\udc00-\\udfff]",nr="["+ch+"]",mh="\\u200d",ph="(?:"+vh+"|"+gh+")",Jy="(?:"+nr+"|"+gh+")",wh="(?:"+po+"(?:d|ll|m|re|s|t|ve))?",bh="(?:"+po+"(?:D|LL|M|RE|S|T|VE))?",xh=Zy+"?",_h="["+hh+"]?",Qy="(?:"+mh+"(?:"+[yh,bo,xo].join("|")+")"+_h+xh+")*",tm="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",em="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",kh=_h+xh+Qy,im="(?:"+[Gy,bo,xo].join("|")+")"+kh,nm="(?:"+[yh+Ds+"?",Ds,bo,xo,Xy].join("|")+")",rm=RegExp(po,"g"),sm=RegExp(Ds,"g"),_o=RegExp(wo+"(?="+wo+")|"+nm+kh,"g"),am=RegExp([nr+"?"+vh+"+"+wh+"(?="+[fh,nr,"$"].join("|")+")",Jy+"+"+bh+"(?="+[fh,nr+ph,"$"].join("|")+")",nr+"?"+ph+"+"+wh,nr+"+"+bh,em,tm,dh,im].join("|"),"g"),om=RegExp("["+mh+Ls+ah+hh+"]"),lm=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,cm=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],hm=-1,ie={};ie[ao]=ie[oo]=ie[lo]=ie[co]=ie[ho]=ie[uo]=ie[fo]=ie[vo]=ie[go]=!0,ie[nt]=ie[ft]=ie[Hr]=ie[ut]=ie[ir]=ie[b]=ie[P]=ie[H]=ie[J]=ie[at]=ie[yt]=ie[be]=ie[ne]=ie[xe]=ie[xi]=!1;var te={};te[nt]=te[ft]=te[Hr]=te[ir]=te[ut]=te[b]=te[ao]=te[oo]=te[lo]=te[co]=te[ho]=te[J]=te[at]=te[yt]=te[be]=te[ne]=te[xe]=te[Vt]=te[uo]=te[fo]=te[vo]=te[go]=!0,te[P]=te[H]=te[xi]=!1;var um={\u00C0:"A",\u00C1:"A",\u00C2:"A",\u00C3:"A",\u00C4:"A",\u00C5:"A",\u00E0:"a",\u00E1:"a",\u00E2:"a",\u00E3:"a",\u00E4:"a",\u00E5:"a",\u00C7:"C",\u00E7:"c",\u00D0:"D",\u00F0:"d",\u00C8:"E",\u00C9:"E",\u00CA:"E",\u00CB:"E",\u00E8:"e",\u00E9:"e",\u00EA:"e",\u00EB:"e",\u00CC:"I",\u00CD:"I",\u00CE:"I",\u00CF:"I",\u00EC:"i",\u00ED:"i",\u00EE:"i",\u00EF:"i",\u00D1:"N",\u00F1:"n",\u00D2:"O",\u00D3:"O",\u00D4:"O",\u00D5:"O",\u00D6:"O",\u00D8:"O",\u00F2:"o",\u00F3:"o",\u00F4:"o",\u00F5:"o",\u00F6:"o",\u00F8:"o",\u00D9:"U",\u00DA:"U",\u00DB:"U",\u00DC:"U",\u00F9:"u",\u00FA:"u",\u00FB:"u",\u00FC:"u",\u00DD:"Y",\u00FD:"y",\u00FF:"y",\u00C6:"Ae",\u00E6:"ae",\u00DE:"Th",\u00FE:"th",\u00DF:"ss",\u0100:"A",\u0102:"A",\u0104:"A",\u0101:"a",\u0103:"a",\u0105:"a",\u0106:"C",\u0108:"C",\u010A:"C",\u010C:"C",\u0107:"c",\u0109:"c",\u010B:"c",\u010D:"c",\u010E:"D",\u0110:"D",\u010F:"d",\u0111:"d",\u0112:"E",\u0114:"E",\u0116:"E",\u0118:"E",\u011A:"E",\u0113:"e",\u0115:"e",\u0117:"e",\u0119:"e",\u011B:"e",\u011C:"G",\u011E:"G",\u0120:"G",\u0122:"G",\u011D:"g",\u011F:"g",\u0121:"g",\u0123:"g",\u0124:"H",\u0126:"H",\u0125:"h",\u0127:"h",\u0128:"I",\u012A:"I",\u012C:"I",\u012E:"I",\u0130:"I",\u0129:"i",\u012B:"i",\u012D:"i",\u012F:"i",\u0131:"i",\u0134:"J",\u0135:"j",\u0136:"K",\u0137:"k",\u0138:"k",\u0139:"L",\u013B:"L",\u013D:"L",\u013F:"L",\u0141:"L",\u013A:"l",\u013C:"l",\u013E:"l",\u0140:"l",\u0142:"l",\u0143:"N",\u0145:"N",\u0147:"N",\u014A:"N",\u0144:"n",\u0146:"n",\u0148:"n",\u014B:"n",\u014C:"O",\u014E:"O",\u0150:"O",\u014D:"o",\u014F:"o",\u0151:"o",\u0154:"R",\u0156:"R",\u0158:"R",\u0155:"r",\u0157:"r",\u0159:"r",\u015A:"S",\u015C:"S",\u015E:"S",\u0160:"S",\u015B:"s",\u015D:"s",\u015F:"s",\u0161:"s",\u0162:"T",\u0164:"T",\u0166:"T",\u0163:"t",\u0165:"t",\u0167:"t",\u0168:"U",\u016A:"U",\u016C:"U",\u016E:"U",\u0170:"U",\u0172:"U",\u0169:"u",\u016B:"u",\u016D:"u",\u016F:"u",\u0171:"u",\u0173:"u",\u0174:"W",\u0175:"w",\u0176:"Y",\u0177:"y",\u0178:"Y",\u0179:"Z",\u017B:"Z",\u017D:"Z",\u017A:"z",\u017C:"z",\u017E:"z",\u0132:"IJ",\u0133:"ij",\u0152:"Oe",\u0153:"oe",\u0149:"'n",\u017F:"s"},fm={"&":"&","<":"<",">":">",'"':""","'":"'"},dm={"&":"&","<":"<",">":">",""":'"',"'":"'"},vm={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},gm=parseFloat,ym=parseInt,Eh=typeof Le=="object"&&Le&&Le.Object===Object&&Le,mm=typeof self=="object"&&self&&self.Object===Object&&self,_e=Eh||mm||Function("return this")(),ko=t&&!t.nodeType&&t,Tn=ko&&!0&&e&&!e.nodeType&&e,Ah=Tn&&Tn.exports===ko,Eo=Ah&&Eh.process,ii=function(){try{var et=Tn&&Tn.require&&Tn.require("util").types;return et||Eo&&Eo.binding&&Eo.binding("util")}catch{}}(),Rh=ii&&ii.isArrayBuffer,Ch=ii&&ii.isDate,Th=ii&&ii.isMap,Sh=ii&&ii.isRegExp,Ph=ii&&ii.isSet,Ih=ii&&ii.isTypedArray;function qe(et,ht,ot){switch(ot.length){case 0:return et.call(ht);case 1:return et.call(ht,ot[0]);case 2:return et.call(ht,ot[0],ot[1]);case 3:return et.call(ht,ot[0],ot[1],ot[2])}return et.apply(ht,ot)}function pm(et,ht,ot,wt){for(var St=-1,$t=et==null?0:et.length;++St<$t;){var ge=et[St];ht(wt,ge,ot(ge),et)}return wt}function ni(et,ht){for(var ot=-1,wt=et==null?0:et.length;++ot-1}function Ao(et,ht,ot){for(var wt=-1,St=et==null?0:et.length;++wt-1;);return ot}function zh(et,ht){for(var ot=et.length;ot--&&rr(ht,et[ot],0)>-1;);return ot}function Cm(et,ht){for(var ot=et.length,wt=0;ot--;)et[ot]===ht&&++wt;return wt}var Tm=So(um),Sm=So(fm);function Pm(et){return"\\"+vm[et]}function Im(et,ht){return et==null?i:et[ht]}function sr(et){return om.test(et)}function Lm(et){return lm.test(et)}function Dm(et){for(var ht,ot=[];!(ht=et.next()).done;)ot.push(ht.value);return ot}function Do(et){var ht=-1,ot=Array(et.size);return et.forEach(function(wt,St){ot[++ht]=[St,wt]}),ot}function Hh(et,ht){return function(ot){return et(ht(ot))}}function an(et,ht){for(var ot=-1,wt=et.length,St=0,$t=[];++ot-1}function b0(o,f){var m=this.__data__,R=Zs(m,o);return R<0?(++this.size,m.push([o,f])):m[R][1]=f,this}Mi.prototype.clear=y0,Mi.prototype.delete=m0,Mi.prototype.get=p0,Mi.prototype.has=w0,Mi.prototype.set=b0;function Bi(o){var f=-1,m=o==null?0:o.length;for(this.clear();++f=f?o:f)),o}function ai(o,f,m,R,L,F){var j,G=f&d,it=f&g,dt=f&v;if(m&&(j=L?m(o,R,L,F):m(o)),j!==i)return j;if(!oe(o))return o;var vt=Pt(o);if(vt){if(j=Ep(o),!G)return Me(o,j)}else{var gt=Te(o),pt=gt==H||gt==X;if(fn(o))return _u(o,G);if(gt==yt||gt==nt||pt&&!L){if(j=it||pt?{}:Uu(o),!G)return it?dp(o,O0(j,o)):fp(o,Jh(j,o))}else{if(!te[gt])return L?o:{};j=Ap(o,gt,G)}}F||(F=new gi);var _t=F.get(o);if(_t)return _t;F.set(o,j),mf(o)?o.forEach(function(Ct){j.add(ai(Ct,f,m,Ct,o,F))}):gf(o)&&o.forEach(function(Ct,Nt){j.set(Nt,ai(Ct,f,m,Nt,o,F))});var Rt=dt?it?sl:rl:it?Oe:pe,Mt=vt?i:Rt(o);return ni(Mt||o,function(Ct,Nt){Mt&&(Nt=Ct,Ct=o[Nt]),Kr(j,Nt,ai(Ct,f,m,Nt,o,F))}),j}function N0(o){var f=pe(o);return function(m){return Qh(m,o,f)}}function Qh(o,f,m){var R=m.length;if(o==null)return!R;for(o=Zt(o);R--;){var L=m[R],F=f[L],j=o[L];if(j===i&&!(L in o)||!F(j))return!1}return!0}function tu(o,f,m){if(typeof o!="function")throw new ri(a);return ts(function(){o.apply(i,m)},f)}function Yr(o,f,m,R){var L=-1,F=Ms,j=!0,G=o.length,it=[],dt=f.length;if(!G)return it;m&&(f=re(f,je(m))),R?(F=Ao,j=!1):f.length>=r&&(F=Ur,j=!1,f=new In(f));t:for(;++LL?0:L+m),R=R===i||R>L?L:Dt(R),R<0&&(R+=L),R=m>R?0:wf(R);m0&&m(G)?f>1?ke(G,f-1,m,R,L):sn(L,G):R||(L[L.length]=G)}return L}var Ho=Tu(),nu=Tu(!0);function _i(o,f){return o&&Ho(o,f,pe)}function Uo(o,f){return o&&nu(o,f,pe)}function Qs(o,f){return rn(f,function(m){return Hi(o[m])})}function Dn(o,f){f=hn(f,o);for(var m=0,R=f.length;o!=null&&mf}function H0(o,f){return o!=null&&Xt.call(o,f)}function U0(o,f){return o!=null&&f in Zt(o)}function W0(o,f,m){return o>=Ce(f,m)&&o=120&&vt.length>=120)?new In(j&&vt):i}vt=o[0];var gt=-1,pt=G[0];t:for(;++gt-1;)G!==o&&js.call(G,it,1),js.call(o,it,1);return o}function vu(o,f){for(var m=o?f.length:0,R=m-1;m--;){var L=f[m];if(m==R||L!==F){var F=L;zi(L)?js.call(o,L,1):Zo(o,L)}}return o}function Yo(o,f){return o+Ks(Yh()*(f-o+1))}function ep(o,f,m,R){for(var L=-1,F=ye($s((f-o)/(m||1)),0),j=ot(F);F--;)j[R?F:++L]=o,o+=m;return j}function Xo(o,f){var m="";if(!o||f<1||f>$)return m;do f%2&&(m+=o),f=Ks(f/2),f&&(o+=o);while(f);return m}function Bt(o,f){return fl(ju(o,f,Ne),o+"")}function ip(o){return Zh(yr(o))}function np(o,f){var m=yr(o);return ha(m,Ln(f,0,m.length))}function Zr(o,f,m,R){if(!oe(o))return o;f=hn(f,o);for(var L=-1,F=f.length,j=F-1,G=o;G!=null&&++LL?0:L+f),m=m>L?L:m,m<0&&(m+=L),L=f>m?0:m-f>>>0,f>>>=0;for(var F=ot(L);++R>>1,j=o[F];j!==null&&!$e(j)&&(m?j<=f:j=r){var dt=f?null:mp(o);if(dt)return Os(dt);j=!1,L=Ur,it=new In}else it=f?[]:G;t:for(;++R=R?o:oi(o,f,m)}var xu=Ym||function(o){return _e.clearTimeout(o)};function _u(o,f){if(f)return o.slice();var m=o.length,R=qh?qh(m):new o.constructor(m);return o.copy(R),R}function el(o){var f=new o.constructor(o.byteLength);return new Ws(f).set(new Ws(o)),f}function lp(o,f){var m=f?el(o.buffer):o.buffer;return new o.constructor(m,o.byteOffset,o.byteLength)}function cp(o){var f=new o.constructor(o.source,sh.exec(o));return f.lastIndex=o.lastIndex,f}function hp(o){return $r?Zt($r.call(o)):{}}function ku(o,f){var m=f?el(o.buffer):o.buffer;return new o.constructor(m,o.byteOffset,o.length)}function Eu(o,f){if(o!==f){var m=o!==i,R=o===null,L=o===o,F=$e(o),j=f!==i,G=f===null,it=f===f,dt=$e(f);if(!G&&!dt&&!F&&o>f||F&&j&&it&&!G&&!dt||R&&j&&it||!m&&it||!L)return 1;if(!R&&!F&&!dt&&o=G)return it;var dt=m[R];return it*(dt=="desc"?-1:1)}}return o.index-f.index}function Au(o,f,m,R){for(var L=-1,F=o.length,j=m.length,G=-1,it=f.length,dt=ye(F-j,0),vt=ot(it+dt),gt=!R;++G1?m[L-1]:i,j=L>2?m[2]:i;for(F=o.length>3&&typeof F=="function"?(L--,F):i,j&&Pe(m[0],m[1],j)&&(F=L<3?i:F,L=1),f=Zt(f);++R-1?L[F?f[j]:j]:i}}function Iu(o){return Fi(function(f){var m=f.length,R=m,L=si.prototype.thru;for(o&&f.reverse();R--;){var F=f[R];if(typeof F!="function")throw new ri(a);if(L&&!j&&la(F)=="wrapper")var j=new si([],!0)}for(R=j?R:m;++R1&&Ht.reverse(),vt&&itG))return!1;var dt=F.get(o),vt=F.get(f);if(dt&&vt)return dt==f&&vt==o;var gt=-1,pt=!0,_t=m&w?new In:i;for(F.set(o,f),F.set(f,o);++gt1?"& ":"")+f[R],f=f.join(m>2?", ":" "),o.replace(Ty,`{ /* [wrapped with `+f+`] */ `)}function Cp(o){return Pt(o)||On(o)||!!($h&&o&&o[$h])}function zi(o,f){var m=typeof o;return f=f==null?$:f,!!f&&(m=="number"||m!="symbol"&&zy.test(o))&&o>-1&&o%1==0&&o0){if(++f>=T)return arguments[0]}else f=0;return o.apply(i,arguments)}}function ha(o,f){var m=-1,R=o.length,L=R-1;for(f=f===i?R:f;++m1?o[f-1]:i;return m=typeof m=="function"?(o.pop(),m):i,nf(o,m)});function rf(o){var f=N(o);return f.__chain__=!0,f}function Fw(o,f){return f(o),o}function ua(o,f){return f(o)}var zw=Fi(function(o){var f=o.length,m=f?o[0]:0,R=this.__wrapped__,L=function(F){return zo(F,o)};return f>1||this.__actions__.length||!(R instanceof Ft)||!zi(m)?this.thru(L):(R=R.slice(m,+m+(f?1:0)),R.__actions__.push({func:ua,args:[L],thisArg:i}),new si(R,this.__chain__).thru(function(F){return f&&!F.length&&F.push(i),F}))});function Hw(){return rf(this)}function Uw(){return new si(this.value(),this.__chain__)}function Ww(){this.__values__===i&&(this.__values__=pf(this.value()));var o=this.__index__>=this.__values__.length,f=o?i:this.__values__[this.__index__++];return{done:o,value:f}}function qw(){return this}function jw(o){for(var f,m=this;m instanceof Gs;){var R=Gu(m);R.__index__=0,R.__values__=i,f?L.__wrapped__=R:f=R;var L=R;m=m.__wrapped__}return L.__wrapped__=o,f}function Vw(){var o=this.__wrapped__;if(o instanceof Ft){var f=o;return this.__actions__.length&&(f=new Ft(this)),f=f.reverse(),f.__actions__.push({func:ua,args:[dl],thisArg:i}),new si(f,this.__chain__)}return this.thru(dl)}function $w(){return wu(this.__wrapped__,this.__actions__)}var Kw=na(function(o,f,m){Xt.call(o,m)?++o[m]:Oi(o,m,1)});function Yw(o,f,m){var R=Pt(o)?Lh:F0;return m&&Pe(o,f,m)&&(f=i),R(o,Et(f,3))}function Xw(o,f){var m=Pt(o)?rn:iu;return m(o,Et(f,3))}var Gw=Pu(Zu),Zw=Pu(Ju);function Jw(o,f){return ke(fa(o,f),1)}function Qw(o,f){return ke(fa(o,f),st)}function tb(o,f,m){return m=m===i?1:Dt(m),ke(fa(o,f),m)}function sf(o,f){var m=Pt(o)?ni:ln;return m(o,Et(f,3))}function af(o,f){var m=Pt(o)?wm:eu;return m(o,Et(f,3))}var eb=na(function(o,f,m){Xt.call(o,m)?o[m].push(f):Oi(o,m,[f])});function ib(o,f,m,R){o=Be(o)?o:yr(o),m=m&&!R?Dt(m):0;var L=o.length;return m<0&&(m=ye(L+m,0)),ma(o)?m<=L&&o.indexOf(f,m)>-1:!!L&&rr(o,f,m)>-1}var nb=Bt(function(o,f,m){var R=-1,L=typeof f=="function",F=Be(o)?ot(o.length):[];return ln(o,function(j){F[++R]=L?qe(f,j,m):Xr(j,f,m)}),F}),rb=na(function(o,f,m){Oi(o,m,f)});function fa(o,f){var m=Pt(o)?re:lu;return m(o,Et(f,3))}function sb(o,f,m,R){return o==null?[]:(Pt(f)||(f=f==null?[]:[f]),m=R?i:m,Pt(m)||(m=m==null?[]:[m]),fu(o,f,m))}var ab=na(function(o,f,m){o[m?0:1].push(f)},function(){return[[],[]]});function ob(o,f,m){var R=Pt(o)?Ro:Oh,L=arguments.length<3;return R(o,Et(f,4),m,L,ln)}function lb(o,f,m){var R=Pt(o)?bm:Oh,L=arguments.length<3;return R(o,Et(f,4),m,L,eu)}function cb(o,f){var m=Pt(o)?rn:iu;return m(o,ga(Et(f,3)))}function hb(o){var f=Pt(o)?Zh:ip;return f(o)}function ub(o,f,m){(m?Pe(o,f,m):f===i)?f=1:f=Dt(f);var R=Pt(o)?D0:np;return R(o,f)}function fb(o){var f=Pt(o)?M0:sp;return f(o)}function db(o){if(o==null)return 0;if(Be(o))return ma(o)?ar(o):o.length;var f=Te(o);return f==J||f==ne?o.size:Vo(o).length}function vb(o,f,m){var R=Pt(o)?Co:ap;return m&&Pe(o,f,m)&&(f=i),R(o,Et(f,3))}var gb=Bt(function(o,f){if(o==null)return[];var m=f.length;return m>1&&Pe(o,f[0],f[1])?f=[]:m>2&&Pe(f[0],f[1],f[2])&&(f=[f[0]]),fu(o,ke(f,1),[])}),da=Xm||function(){return _e.Date.now()};function yb(o,f){if(typeof f!="function")throw new ri(a);return o=Dt(o),function(){if(--o<1)return f.apply(this,arguments)}}function of(o,f,m){return f=m?i:f,f=o&&f==null?o.length:f,Ni(o,B,i,i,i,i,f)}function lf(o,f){var m;if(typeof f!="function")throw new ri(a);return o=Dt(o),function(){return--o>0&&(m=f.apply(this,arguments)),o<=1&&(f=i),m}}var gl=Bt(function(o,f,m){var R=p;if(m.length){var L=an(m,vr(gl));R|=I}return Ni(o,R,f,m,L)}),cf=Bt(function(o,f,m){var R=p|_;if(m.length){var L=an(m,vr(cf));R|=I}return Ni(f,R,o,m,L)});function hf(o,f,m){f=m?i:f;var R=Ni(o,x,i,i,i,i,i,f);return R.placeholder=hf.placeholder,R}function uf(o,f,m){f=m?i:f;var R=Ni(o,E,i,i,i,i,i,f);return R.placeholder=uf.placeholder,R}function ff(o,f,m){var R,L,F,j,G,it,dt=0,vt=!1,gt=!1,pt=!0;if(typeof o!="function")throw new ri(a);f=ci(f)||0,oe(m)&&(vt=!!m.leading,gt="maxWait"in m,F=gt?ye(ci(m.maxWait)||0,f):F,pt="trailing"in m?!!m.trailing:pt);function _t(ue){var mi=R,Wi=L;return R=L=i,dt=ue,j=o.apply(Wi,mi),j}function Rt(ue){return dt=ue,G=ts(Nt,f),vt?_t(ue):j}function Mt(ue){var mi=ue-it,Wi=ue-dt,If=f-mi;return gt?Ce(If,F-Wi):If}function Ct(ue){var mi=ue-it,Wi=ue-dt;return it===i||mi>=f||mi<0||gt&&Wi>=F}function Nt(){var ue=da();if(Ct(ue))return Ht(ue);G=ts(Nt,Mt(ue))}function Ht(ue){return G=i,pt&&R?_t(ue):(R=L=i,j)}function Ke(){G!==i&&xu(G),dt=0,R=it=L=G=i}function Ie(){return G===i?j:Ht(da())}function Ye(){var ue=da(),mi=Ct(ue);if(R=arguments,L=this,it=ue,mi){if(G===i)return Rt(it);if(gt)return xu(G),G=ts(Nt,f),_t(it)}return G===i&&(G=ts(Nt,f)),j}return Ye.cancel=Ke,Ye.flush=Ie,Ye}var mb=Bt(function(o,f){return tu(o,1,f)}),pb=Bt(function(o,f,m){return tu(o,ci(f)||0,m)});function wb(o){return Ni(o,q)}function va(o,f){if(typeof o!="function"||f!=null&&typeof f!="function")throw new ri(a);var m=function(){var R=arguments,L=f?f.apply(this,R):R[0],F=m.cache;if(F.has(L))return F.get(L);var j=o.apply(this,R);return m.cache=F.set(L,j)||F,j};return m.cache=new(va.Cache||Bi),m}va.Cache=Bi;function ga(o){if(typeof o!="function")throw new ri(a);return function(){var f=arguments;switch(f.length){case 0:return!o.call(this);case 1:return!o.call(this,f[0]);case 2:return!o.call(this,f[0],f[1]);case 3:return!o.call(this,f[0],f[1],f[2])}return!o.apply(this,f)}}function bb(o){return lf(2,o)}var xb=op(function(o,f){f=f.length==1&&Pt(f[0])?re(f[0],je(Et())):re(ke(f,1),je(Et()));var m=f.length;return Bt(function(R){for(var L=-1,F=Ce(R.length,m);++L=f}),On=su(function(){return arguments}())?su:function(o){return ce(o)&&Xt.call(o,"callee")&&!Vh.call(o,"callee")},Pt=ot.isArray,Ob=Rh?je(Rh):j0;function Be(o){return o!=null&&ya(o.length)&&!Hi(o)}function he(o){return ce(o)&&Be(o)}function Nb(o){return o===!0||o===!1||ce(o)&&Se(o)==ut}var fn=Zm||Cl,Fb=Ch?je(Ch):V0;function zb(o){return ce(o)&&o.nodeType===1&&!es(o)}function Hb(o){if(o==null)return!0;if(Be(o)&&(Pt(o)||typeof o=="string"||typeof o.splice=="function"||fn(o)||gr(o)||On(o)))return!o.length;var f=Te(o);if(f==J||f==ne)return!o.size;if(Qr(o))return!Vo(o).length;for(var m in o)if(Xt.call(o,m))return!1;return!0}function Ub(o,f){return Gr(o,f)}function Wb(o,f,m){m=typeof m=="function"?m:i;var R=m?m(o,f):i;return R===i?Gr(o,f,i,m):!!R}function ml(o){if(!ce(o))return!1;var f=Se(o);return f==P||f==k||typeof o.message=="string"&&typeof o.name=="string"&&!es(o)}function qb(o){return typeof o=="number"&&Kh(o)}function Hi(o){if(!oe(o))return!1;var f=Se(o);return f==H||f==X||f==lt||f==Tt}function vf(o){return typeof o=="number"&&o==Dt(o)}function ya(o){return typeof o=="number"&&o>-1&&o%1==0&&o<=$}function oe(o){var f=typeof o;return o!=null&&(f=="object"||f=="function")}function ce(o){return o!=null&&typeof o=="object"}var gf=Th?je(Th):K0;function jb(o,f){return o===f||jo(o,f,ol(f))}function Vb(o,f,m){return m=typeof m=="function"?m:i,jo(o,f,ol(f),m)}function $b(o){return yf(o)&&o!=+o}function Kb(o){if(Pp(o))throw new St(s);return au(o)}function Yb(o){return o===null}function Xb(o){return o==null}function yf(o){return typeof o=="number"||ce(o)&&Se(o)==at}function es(o){if(!ce(o)||Se(o)!=yt)return!1;var f=qs(o);if(f===null)return!0;var m=Xt.call(f,"constructor")&&f.constructor;return typeof m=="function"&&m instanceof m&&zs.call(m)==Vm}var pl=Sh?je(Sh):Y0;function Gb(o){return vf(o)&&o>=-$&&o<=$}var mf=Ph?je(Ph):X0;function ma(o){return typeof o=="string"||!Pt(o)&&ce(o)&&Se(o)==xe}function $e(o){return typeof o=="symbol"||ce(o)&&Se(o)==Vt}var gr=Ih?je(Ih):G0;function Zb(o){return o===i}function Jb(o){return ce(o)&&Te(o)==xi}function Qb(o){return ce(o)&&Se(o)==gy}var t1=oa($o),e1=oa(function(o,f){return o<=f});function pf(o){if(!o)return[];if(Be(o))return ma(o)?vi(o):Me(o);if(Wr&&o[Wr])return Dm(o[Wr]());var f=Te(o),m=f==J?Do:f==ne?Os:yr;return m(o)}function Ui(o){if(!o)return o===0?o:0;if(o=ci(o),o===st||o===-st){var f=o<0?-1:1;return f*z}return o===o?o:0}function Dt(o){var f=Ui(o),m=f%1;return f===f?m?f-m:f:0}function wf(o){return o?Ln(Dt(o),0,Y):0}function ci(o){if(typeof o=="number")return o;if($e(o))return V;if(oe(o)){var f=typeof o.valueOf=="function"?o.valueOf():o;o=oe(f)?f+"":f}if(typeof o!="string")return o===0?o:+o;o=Nh(o);var m=Oy.test(o);return m||Fy.test(o)?ym(o.slice(2),m?2:8):By.test(o)?V:+o}function bf(o){return ki(o,Oe(o))}function i1(o){return o?Ln(Dt(o),-$,$):o===0?o:0}function Yt(o){return o==null?"":Ve(o)}var n1=fr(function(o,f){if(Qr(f)||Be(f)){ki(f,pe(f),o);return}for(var m in f)Xt.call(f,m)&&Kr(o,m,f[m])}),xf=fr(function(o,f){ki(f,Oe(f),o)}),pa=fr(function(o,f,m,R){ki(f,Oe(f),o,R)}),r1=fr(function(o,f,m,R){ki(f,pe(f),o,R)}),s1=Fi(zo);function a1(o,f){var m=ur(o);return f==null?m:Jh(m,f)}var o1=Bt(function(o,f){o=Zt(o);var m=-1,R=f.length,L=R>2?f[2]:i;for(L&&Pe(f[0],f[1],L)&&(R=1);++m1),F}),ki(o,sl(o),m),R&&(m=ai(m,d|g|v,pp));for(var L=f.length;L--;)Zo(m,f[L]);return m});function A1(o,f){return kf(o,ga(Et(f)))}var R1=Fi(function(o,f){return o==null?{}:Q0(o,f)});function kf(o,f){if(o==null)return{};var m=re(sl(o),function(R){return[R]});return f=Et(f),du(o,m,function(R,L){return f(R,L[0])})}function C1(o,f,m){f=hn(f,o);var R=-1,L=f.length;for(L||(L=1,o=i);++Rf){var R=o;o=f,f=R}if(m||o%1||f%1){var L=Yh();return Ce(o+L*(f-o+gm("1e-"+((L+"").length-1))),f)}return Yo(o,f)}var F1=dr(function(o,f,m){return f=f.toLowerCase(),o+(m?Rf(f):f)});function Rf(o){return xl(Yt(o).toLowerCase())}function Cf(o){return o=Yt(o),o&&o.replace(Hy,Tm).replace(sm,"")}function z1(o,f,m){o=Yt(o),f=Ve(f);var R=o.length;m=m===i?R:Ln(Dt(m),0,R);var L=m;return m-=f.length,m>=0&&o.slice(m,L)==f}function H1(o){return o=Yt(o),o&&by.test(o)?o.replace(nh,Sm):o}function U1(o){return o=Yt(o),o&&Ry.test(o)?o.replace(yo,"\\$&"):o}var W1=dr(function(o,f,m){return o+(m?"-":"")+f.toLowerCase()}),q1=dr(function(o,f,m){return o+(m?" ":"")+f.toLowerCase()}),j1=Su("toLowerCase");function V1(o,f,m){o=Yt(o),f=Dt(f);var R=f?ar(o):0;if(!f||R>=f)return o;var L=(f-R)/2;return aa(Ks(L),m)+o+aa($s(L),m)}function $1(o,f,m){o=Yt(o),f=Dt(f);var R=f?ar(o):0;return f&&R>>0,m?(o=Yt(o),o&&(typeof f=="string"||f!=null&&!pl(f))&&(f=Ve(f),!f&&sr(o))?un(vi(o),0,m):o.split(f,m)):[]}var Q1=dr(function(o,f,m){return o+(m?" ":"")+xl(f)});function tx(o,f,m){return o=Yt(o),m=m==null?0:Ln(Dt(m),0,o.length),f=Ve(f),o.slice(m,m+f.length)==f}function ex(o,f,m){var R=N.templateSettings;m&&Pe(o,f,m)&&(f=i),o=Yt(o),f=pa({},f,R,Ou);var L=pa({},f.imports,R.imports,Ou),F=pe(L),j=Lo(L,F),G,it,dt=0,vt=f.interpolate||Is,gt="__p += '",pt=Mo((f.escape||Is).source+"|"+vt.source+"|"+(vt===rh?My:Is).source+"|"+(f.evaluate||Is).source+"|$","g"),_t="//# sourceURL="+(Xt.call(f,"sourceURL")?(f.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++hm+"]")+` `;o.replace(pt,function(Ct,Nt,Ht,Ke,Ie,Ye){return Ht||(Ht=Ke),gt+=o.slice(dt,Ye).replace(Uy,Pm),Nt&&(G=!0,gt+=`' + __e(`+Nt+`) + '`),Ie&&(it=!0,gt+=`'; `+Ie+`; __p += '`),Ht&&(gt+=`' + ((__t = (`+Ht+`)) == null ? '' : __t) + '`),dt=Ye+Ct.length,Ct}),gt+=`'; `;var Rt=Xt.call(f,"variable")&&f.variable;if(!Rt)gt=`with (obj) { `+gt+` } `;else if(Ly.test(Rt))throw new St(l);gt=(it?gt.replace(yy,""):gt).replace(my,"$1").replace(py,"$1;"),gt="function("+(Rt||"obj")+`) { `+(Rt?"":`obj || (obj = {}); `)+"var __t, __p = ''"+(G?", __e = _.escape":"")+(it?`, __j = Array.prototype.join; function print() { __p += __j.call(arguments, '') } `:`; `)+gt+`return __p }`;var Mt=Sf(function(){return $t(F,_t+"return "+gt).apply(i,j)});if(Mt.source=gt,ml(Mt))throw Mt;return Mt}function ix(o){return Yt(o).toLowerCase()}function nx(o){return Yt(o).toUpperCase()}function rx(o,f,m){if(o=Yt(o),o&&(m||f===i))return Nh(o);if(!o||!(f=Ve(f)))return o;var R=vi(o),L=vi(f),F=Fh(R,L),j=zh(R,L)+1;return un(R,F,j).join("")}function sx(o,f,m){if(o=Yt(o),o&&(m||f===i))return o.slice(0,Uh(o)+1);if(!o||!(f=Ve(f)))return o;var R=vi(o),L=zh(R,vi(f))+1;return un(R,0,L).join("")}function ax(o,f,m){if(o=Yt(o),o&&(m||f===i))return o.replace(mo,"");if(!o||!(f=Ve(f)))return o;var R=vi(o),L=Fh(R,vi(f));return un(R,L).join("")}function ox(o,f){var m=Q,R=C;if(oe(f)){var L="separator"in f?f.separator:L;m="length"in f?Dt(f.length):m,R="omission"in f?Ve(f.omission):R}o=Yt(o);var F=o.length;if(sr(o)){var j=vi(o);F=j.length}if(m>=F)return o;var G=m-ar(R);if(G<1)return R;var it=j?un(j,0,G).join(""):o.slice(0,G);if(L===i)return it+R;if(j&&(G+=it.length-G),pl(L)){if(o.slice(G).search(L)){var dt,vt=it;for(L.global||(L=Mo(L.source,Yt(sh.exec(L))+"g")),L.lastIndex=0;dt=L.exec(vt);)var gt=dt.index;it=it.slice(0,gt===i?G:gt)}}else if(o.indexOf(Ve(L),G)!=G){var pt=it.lastIndexOf(L);pt>-1&&(it=it.slice(0,pt))}return it+R}function lx(o){return o=Yt(o),o&&wy.test(o)?o.replace(ih,Nm):o}var cx=dr(function(o,f,m){return o+(m?" ":"")+f.toUpperCase()}),xl=Su("toUpperCase");function Tf(o,f,m){return o=Yt(o),f=m?i:f,f===i?Lm(o)?Hm(o):km(o):o.match(f)||[]}var Sf=Bt(function(o,f){try{return qe(o,i,f)}catch(m){return ml(m)?m:new St(m)}}),hx=Fi(function(o,f){return ni(f,function(m){m=Ei(m),Oi(o,m,gl(o[m],o))}),o});function ux(o){var f=o==null?0:o.length,m=Et();return o=f?re(o,function(R){if(typeof R[1]!="function")throw new ri(a);return[m(R[0]),R[1]]}):[],Bt(function(R){for(var L=-1;++L$)return[];var m=Y,R=Ce(o,Y);f=Et(f),o-=Y;for(var L=Io(R,f);++m0||f<0)?new Ft(m):(o<0?m=m.takeRight(-o):o&&(m=m.drop(o)),f!==i&&(f=Dt(f),m=f<0?m.dropRight(-f):m.take(f-o)),m)},Ft.prototype.takeRightWhile=function(o){return this.reverse().takeWhile(o).reverse()},Ft.prototype.toArray=function(){return this.take(Y)},_i(Ft.prototype,function(o,f){var m=/^(?:filter|find|map|reject)|While$/.test(f),R=/^(?:head|last)$/.test(f),L=N[R?"take"+(f=="last"?"Right":""):f],F=R||/^find/.test(f);!L||(N.prototype[f]=function(){var j=this.__wrapped__,G=R?[1]:arguments,it=j instanceof Ft,dt=G[0],vt=it||Pt(j),gt=function(Nt){var Ht=L.apply(N,sn([Nt],G));return R&&pt?Ht[0]:Ht};vt&&m&&typeof dt=="function"&&dt.length!=1&&(it=vt=!1);var pt=this.__chain__,_t=!!this.__actions__.length,Rt=F&&!pt,Mt=it&&!_t;if(!F&&vt){j=Mt?j:new Ft(this);var Ct=o.apply(j,G);return Ct.__actions__.push({func:ua,args:[gt],thisArg:i}),new si(Ct,pt)}return Rt&&Mt?o.apply(this,G):(Ct=this.thru(gt),Rt?R?Ct.value()[0]:Ct.value():Ct)})}),ni(["pop","push","shift","sort","splice","unshift"],function(o){var f=Ns[o],m=/^(?:push|sort|unshift)$/.test(o)?"tap":"thru",R=/^(?:pop|shift)$/.test(o);N.prototype[o]=function(){var L=arguments;if(R&&!this.__chain__){var F=this.value();return f.apply(Pt(F)?F:[],L)}return this[m](function(j){return f.apply(Pt(j)?j:[],L)})}}),_i(Ft.prototype,function(o,f){var m=N[f];if(m){var R=m.name+"";Xt.call(hr,R)||(hr[R]=[]),hr[R].push({name:f,func:m})}}),hr[ra(i,_).name]=[{name:"wrapper",func:i}],Ft.prototype.clone=l0,Ft.prototype.reverse=c0,Ft.prototype.value=h0,N.prototype.at=zw,N.prototype.chain=Hw,N.prototype.commit=Uw,N.prototype.next=Ww,N.prototype.plant=jw,N.prototype.reverse=Vw,N.prototype.toJSON=N.prototype.valueOf=N.prototype.value=$w,N.prototype.first=N.prototype.head,Wr&&(N.prototype[Wr]=qw),N},or=Um();Tn?((Tn.exports=or)._=or,ko._=or):_e._=or}).call(Le)})(Mc,Mc.exports);const iT=Mc.exports;export{UC as M,iT as _,jC as a,KC as b,VC as c,qC as d,tT as e,WC as f,QC as g,ZC as h,XC as i,GC as j,JC as k,eT as p,$C as s,YC as t};