@netless/appliance-plugin 1.0.0-beta.8 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cdn/cdn.js +1 -1
- package/cdn/fullWorker-CIvt1j.js +453 -0
- package/cdn/subWorker-BE-0dg.js +453 -0
- package/dist/appliance-plugin.js +1 -1
- package/dist/appliance-plugin.mjs +13 -13
- package/dist/core/enum.d.ts +8 -1
- package/dist/core/mainEngine.d.ts +9 -2
- package/dist/core/mainThread/base.d.ts +2 -2
- package/dist/core/mainThread/index.d.ts +2 -2
- package/dist/core/mainThread/snapshotThread.d.ts +4 -4
- package/dist/core/mainThread/subLocalThread.d.ts +17 -13
- package/dist/core/mainThread/subTopThread.d.ts +7 -7
- package/dist/core/mainThread/vNodeManager.d.ts +2 -1
- package/dist/core/msgEvent/base.d.ts +6 -2
- package/dist/core/msgEvent/copyNode/forMain.d.ts +1 -0
- package/dist/core/msgEvent/deleteNode/forMain.d.ts +1 -0
- package/dist/core/msgEvent/deleteNode/forMainThread.d.ts +1 -4
- package/dist/core/msgEvent/deleteNode/forWorker.d.ts +1 -4
- package/dist/core/msgEvent/index.d.ts +4 -0
- package/dist/core/msgEvent/rotateNode/forMain.d.ts +2 -1
- package/dist/core/msgEvent/scaleNode/forMain.d.ts +2 -1
- package/dist/core/msgEvent/setColor/forMain.d.ts +1 -0
- package/dist/core/msgEvent/setFont/forMain.d.ts +1 -0
- package/dist/core/msgEvent/setLock/forMain.d.ts +1 -0
- package/dist/core/msgEvent/setPoint/forMain.d.ts +1 -0
- package/dist/core/msgEvent/setShape/forMain.d.ts +1 -0
- package/dist/core/msgEvent/setZIndex/forMain.d.ts +1 -0
- package/dist/core/msgEvent/translateNode/forMain.d.ts +2 -1
- package/dist/core/tools/base.d.ts +1 -1
- package/dist/core/tools/text.d.ts +2 -8
- package/dist/core/tools/utils.d.ts +2 -2
- package/dist/core/types.d.ts +1 -1
- package/dist/core/worker/base.d.ts +21 -13
- package/dist/core/worker/fullWorkerLocal.d.ts +1 -0
- package/dist/core/worker/subWorkerLocal.d.ts +3 -0
- package/dist/core/worker/subWorkerTopLayer.d.ts +7 -7
- package/dist/core/worker/vNodeManager.d.ts +2 -1
- package/dist/core/worker/workerManager.d.ts +2 -1
- package/dist/fullWorker.js +453 -566
- package/dist/index-BcIJbozZ.js +1 -0
- package/dist/index-C1YKkWHE.mjs +9090 -0
- package/dist/{index-Bt9t1FKB.mjs → index-ClJPZxV-.mjs} +1195 -1151
- package/dist/index-SsMz_ohn.js +1 -0
- package/dist/plugin/single/applianceDisplayer.d.ts +0 -1
- package/dist/plugin/types.d.ts +6 -14
- package/dist/style.css +1 -1
- package/dist/subWorker.js +453 -566
- package/package.json +5 -2
- package/cdn/fullWorker-BlZ1Wa.js +0 -566
- package/cdn/subWorker-BKoiIW.js +0 -566
- package/dist/index-BUCsfWH1.js +0 -1
- package/dist/index-Bz3L5rvA.js +0 -1
- package/dist/index-CTYUQm0L.mjs +0 -8859
package/dist/index-Bz3L5rvA.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var ae=Object.defineProperty;var ce=(M,a,t)=>a in M?ae(M,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):M[a]=t;var m=(M,a,t)=>(ce(M,typeof a!="symbol"?a+"":a,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index-BUCsfWH1.js"),x=require("spritejs"),le=require("lineclip");require("lz-string");require("white-web-sdk");require("react-dom");require("react");const B=class B{constructor(a){m(this,"syncUnitTime",1e3);m(this,"vNodes");m(this,"drawLayer");m(this,"fullLayer");m(this,"workId");const{vNodes:t,fullLayer:e,drawLayer:s}=a;this.vNodes=t,this.fullLayer=e,this.drawLayer=s}setWorkId(a){this.workId=a}getWorkId(){return this.workId}getWorkOptions(){return this.workOptions}setWorkOptions(a){var s,i,r;this.workOptions=a,this.syncUnitTime=a.syncUnitTime||this.syncUnitTime;const t=(s=this.workId)==null?void 0:s.toString(),e=t&&((i=this.vNodes)==null?void 0:i.get(t))||void 0;t&&e&&(e.opt=a,(r=this.vNodes)==null||r.setInfo(t,e))}updataOptService(a){var s,i;let t;const e=(s=this.workId)==null?void 0:s.toString();if(e&&a){const r=this.fullLayer.getElementsByName(e)||this.drawLayer&&this.drawLayer.getElementsByName(e)||[];if(r.length!==1)return;const n=r[0],{pos:c,zIndex:l,scale:h,angle:p,translate:d}=a,y={};o.isNumber(l)&&(y.zIndex=l),c&&(y.pos=[c[0],c[1]]),h&&(y.scale=h),p&&(y.rotate=p),d&&(y.translate=d),n.attr(y);const u=n==null?void 0:n.getBoundingClientRect();return u&&(t=o.computRect(t,{x:Math.floor(u.x-B.SafeBorderPadding),y:Math.floor(u.y-B.SafeBorderPadding),w:Math.floor(u.width+B.SafeBorderPadding*2),h:Math.floor(u.height+B.SafeBorderPadding*2)})),(i=this.vNodes)==null||i.setInfo(e,{rect:t,centerPos:c}),t}}replace(a,t,e){var n;const s=a.getElementsByName(t),i=s.length;if(i){if(i>1)for(let c=1;c<s.length;c++)s[c].remove();a.replaceChild(e,s[0])}else a.append(e);this.fullLayer===a?(n=this.drawLayer)==null||n.getElementsByName(t).forEach(c=>{c.remove()}):this.fullLayer.getElementsByName(t).forEach(c=>{c.remove()})}static updateNodeOpt(a){const{node:t,opt:e,vNodes:s,willSerializeData:i,targetNode:r}=a,{zIndex:n,translate:c,angle:l,box:h,boxScale:p,boxTranslate:d,pointMap:y}=e;let u;const f=r&&o.cloneDeep(r)||s.get(t.name);if(!f)return;o.isNumber(n)&&(t.setAttribute("zIndex",n),f.opt.zIndex=n);const g=t.parent;if(g){if(h&&d&&p){const{rect:w}=f,W=[];for(let R=0;R<f.op.length;R+=3)W.push(new o.Point2d(f.op[R],f.op[R+1],f.op[R+2]));const k=o.getRectFromPoints(W),S=[k.w*g.worldScaling[0],k.h*g.worldScaling[0]],I=[w.w-S[0],w.h-S[1]],v=[(w.w*p[0]-I[0])/S[0],(w.h*p[1]-I[1])/S[1]],P=[d[0]/g.worldScaling[0],d[1]/g.worldScaling[1]],L=f.op.map((R,D)=>{const b=D%3;return b===0?R+P[0]:b===1?R+P[1]:R}),T=[f.centerPos[0]+P[0],f.centerPos[1]+P[1]];o.scalePoints(L,T,v);const N=[];for(let R=0;R<L.length;R+=3)N.push(new o.Point2d(L[R],L[R+1],L[R+2]));f.op=L,f.centerPos=T}else if(c){const w=[c[0]/g.worldScaling[0],c[1]/g.worldScaling[1]];t.setAttribute("translate",w),f.opt.translate=w,r&&(u=o.getRectTranslated(f.rect,c),f.rect=u)}else o.isNumber(l)&&(t.setAttribute("rotate",l),f.opt.rotate=l,r&&(u=o.getRectRotated(f.rect,l),f.rect=u));if(y){const w=y.get(t.name);if(w)for(let W=0,k=0;W<f.op.length;W+=3,k++)f.op[W]=w[k][0],f.op[W+1]=w[k][1]}if(i){if(c){const w=[c[0]/g.worldScaling[0],c[1]/g.worldScaling[1]],W=f.op.map((k,S)=>{const I=S%3;return I===0?k+w[0]:I===1?k+w[1]:k});f.op=W,f.centerPos=[f.centerPos[0]+w[0],f.centerPos[1]+w[1]],f!=null&&f.opt&&(f.opt.translate=void 0)}else if(o.isNumber(l)){const w=f.op;o.rotatePoints(w,f.centerPos,l),f.op=w,f!=null&&f.opt&&(f.opt.rotate=void 0)}}f&&s.setInfo(t.name,f)}}static getCenterPos(a,t){const{worldPosition:e,worldScaling:s}=t;return[(a.x+a.w/2-e[0])/s[0],(a.y+a.h/2-e[1])/s[1]]}static getRectFromLayer(a,t){const e=a.getElementsByName(t)[0];if(e){const s=e.getBoundingClientRect();return{x:Math.floor(s.x-B.SafeBorderPadding),y:Math.floor(s.y-B.SafeBorderPadding),w:Math.floor(s.width+B.SafeBorderPadding*2),h:Math.floor(s.height+B.SafeBorderPadding*2)}}}};m(B,"SafeBorderPadding",10);let E=B;function X(M,a=!0){const t=M.length;if(t<2)return"";let e=M[0],s=M[1];if(t===2)return`M${o.precise(e)}L${o.precise(s)}`;let i="";for(let r=2,n=t-1;r<n;r++)e=M[r],s=M[r+1],i+=o.average(e,s);return a?`M${o.average(M[0],M[1])}Q${o.precise(M[1])}${o.average(M[1],M[2])}T${i}${o.average(M[t-1],M[0])}${o.average(M[0],M[1])}Z`:`M${o.precise(M[0])}Q${o.precise(M[1])}${o.average(M[1],M[2])}${M.length>3?"T":""}${i}L${o.precise(M[t-1])}`}class j extends E{constructor(t){super(t);m(this,"canRotate",!0);m(this,"scaleType",o.EScaleType.all);m(this,"toolsType",o.EToolsKey.Pencil);m(this,"syncTimestamp");m(this,"syncIndex",0);m(this,"tmpPoints",[]);m(this,"MAX_REPEAR",10);m(this,"uniThickness");m(this,"workOptions");m(this,"centerPos",[0,0]);this.workOptions=t.toolsOpt,this.uniThickness=this.MAX_REPEAR/this.workOptions.thickness/10,this.syncTimestamp=0}combineConsume(){var n;const t=(n=this.workId)==null?void 0:n.toString(),e=this.transformDataAll(!0),s={name:t};let i;const r=this.drawLayer||this.fullLayer;return e.length&&(i=this.draw({attrs:s,tasks:e,replaceId:t,layer:r})),{rect:i,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local}}setWorkOptions(t){super.setWorkOptions(t),this.syncTimestamp=Date.now()}consume(t){var W;const{data:e,isFullWork:s,isSubWorker:i,isMainThread:r,drawCount:n,replaceId:c}=t;if(((W=e.op)==null?void 0:W.length)===0)return{type:o.EPostMessageType.None};const{workId:l}=e,{tasks:h,effects:p,consumeIndex:d}=this.transformData(e,!1);this.syncIndex=Math.min(this.syncIndex,d,Math.max(0,this.tmpPoints.length-2));const y={name:l==null?void 0:l.toString(),id:n==null?void 0:n.toString()};let u,f=!1;const g=this.syncIndex;if(this.syncTimestamp===0&&(this.syncTimestamp=Date.now()),h.length&&(h[0].taskId-this.syncTimestamp>this.syncUnitTime&&(f=!0,this.syncTimestamp=h[0].taskId,this.syncIndex=this.tmpPoints.length),i||r)){const k=s?this.fullLayer:this.drawLayer||this.fullLayer;u=this.draw({attrs:y,tasks:h,effects:p,layer:k,replaceId:c})}if(i)return d>10&&this.tmpPoints.splice(0,d-10),{rect:u,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local};const w=[];return this.tmpPoints.slice(g).forEach(k=>{w.push(k.x,k.y,this.computRadius(k.z,this.workOptions.thickness))}),{rect:u,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:f?l:void 0,op:f?w:void 0,index:f?g*3:void 0}}consumeAll(t){var h,p;if(t.data){const{op:d,workState:y}=t.data;d!=null&&d.length&&y===o.EvevtWorkState.Done&&this.workOptions.strokeType===o.EStrokeType.Stroke&&this.updateTempPointsWithPressureWhenDone(d)}const e=(h=this.workId)==null?void 0:h.toString();if(!e)return{type:o.EPostMessageType.None};const s=this.transformDataAll(!0),i={name:e};let r;const n=this.fullLayer;s.length&&(r=this.draw({attrs:i,tasks:s,replaceId:e,layer:n}));const c=[];this.tmpPoints.map(d=>{c.push(d.x,d.y,this.computRadius(d.z,this.workOptions.thickness))}),this.syncTimestamp=0,delete this.workOptions.syncUnitTime;const l=o.transformToSerializableData(c);return(p=this.vNodes)==null||p.setInfo(e,{rect:r,op:c,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:r&&E.getCenterPos(r,n)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:e,ops:l,updateNodeOpt:{pos:this.centerPos,useAnimation:!0},opt:this.workOptions}}clearTmpPoints(){this.tmpPoints.length=0,this.syncTimestamp=0,this.syncIndex=0}consumeService(t){var h,p;const{op:e,isFullWork:s,replaceId:i}=t;this.tmpPoints.length=0;for(let d=0;d<e.length;d+=3){const y=new o.Point2d(e[d],e[d+1],e[d+2]);if(this.tmpPoints.length>0){const u=this.tmpPoints[this.tmpPoints.length-1],f=o.Vec2d.Sub(y,u).uni();y.setv(f)}this.tmpPoints.push(y)}const r=this.transformDataAll(!1),n=(h=this.workId)==null?void 0:h.toString(),c={name:n};let l;if(n&&r.length){const d=s?this.fullLayer:this.drawLayer||this.fullLayer;l=this.draw({attrs:c,tasks:r,replaceId:i,layer:d}),(p=this.vNodes)==null||p.setInfo(n,{rect:l,op:e,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:l&&E.getCenterPos(l,d)})}return l}transformDataAll(t=!0){return this.getTaskPoints(this.tmpPoints,t&&this.workOptions.thickness||void 0)}draw(t){const{attrs:e,tasks:s,replaceId:i,effects:r,layer:n}=t,{strokeColor:c,strokeType:l,thickness:h,zIndex:p,scale:d,rotate:y,translate:u}=this.workOptions;r!=null&&r.size&&(r.forEach(S=>{var I;(I=n.getElementById(S+""))==null||I.remove()}),r.clear());let f;const g=[],w=n.worldPosition,W=n.worldScaling;for(let S=0;S<s.length;S++){const{pos:I,points:v}=s[S],{ps:P,rect:L}=this.computDrawPoints(v);let T;const N=v.length===1;l===o.EStrokeType.Stroke||N?T=X(P,!0):T=X(P,!1);const R={pos:I,d:T,fillColor:l===o.EStrokeType.Stroke||N?c:void 0,lineDash:l===o.EStrokeType.Dotted&&!N?[1,h*2]:l===o.EStrokeType.LongDotted&&!N?[h,h*2]:void 0,strokeColor:c,lineCap:l===o.EStrokeType.Stroke||N?void 0:"round",lineWidth:l===o.EStrokeType.Stroke||N?0:h};f=o.computRect(f,{x:Math.floor((L.x+I[0])*W[0]+w[0]-E.SafeBorderPadding),y:Math.floor((L.y+I[1])*W[1]+w[1]-E.SafeBorderPadding),w:Math.floor(L.w*W[0]+2*E.SafeBorderPadding),h:Math.floor(L.h*W[1]+2*E.SafeBorderPadding)}),g.push(R)}d&&(e.scale=d),y&&(e.rotate=y),u&&(e.translate=u);const k=new x.Group;if(f){this.centerPos=E.getCenterPos(f,n),k.attr({...e,normalize:!0,anchor:[.5,.5],bgcolor:l===o.EStrokeType.Stroke?c:void 0,pos:this.centerPos,size:[(f.w-2*E.SafeBorderPadding)/W[0],(f.h-2*E.SafeBorderPadding)/W[1]],zIndex:p});const S=g.map(I=>(I.pos=[I.pos[0]-this.centerPos[0],I.pos[1]-this.centerPos[1]],new x.Path(I)));k.append(...S),l===o.EStrokeType.Stroke&&k.seal(),this.replace(n,i||e.workId,k)}if(d||y||u){const S=k==null?void 0:k.getBoundingClientRect();if(S)return{x:Math.floor(S.x-E.SafeBorderPadding),y:Math.floor(S.y-E.SafeBorderPadding),w:Math.floor(S.width+E.SafeBorderPadding*2),h:Math.floor(S.height+E.SafeBorderPadding*2)}}return f}computDrawPoints(t){return this.workOptions.strokeType===o.EStrokeType.Stroke||t.length===1?this.computStroke(t):this.computNomal(t)}computNomal(t){let e=this.workOptions.thickness;const s=t.map(i=>(e=Math.max(e,i.radius),i.point));return{ps:s,rect:o.getRectFromPoints(s,e)}}computStroke(t){return t.length===1?this.computDotStroke(t[0]):this.computLineStroke(t)}computLineStroke(t){const e=[],s=[];for(let l=0;l<t.length;l++){const{point:h,radius:p}=t[l];let d=h.v;l===0&&t.length>1&&(d=t[l+1].point.v);const y=o.Vec2d.Per(d).mul(p);e.push(o.Point2d.Sub(h,y)),s.push(o.Point2d.Add(h,y))}const i=t[t.length-1],r=o.Point2d.GetSemicircleStroke(i.point,e[e.length-1],-1,8),n=o.Point2d.GetSemicircleStroke(t[0].point,s[0],-1,8),c=e.concat(r,s.reverse(),n);return{ps:c,rect:o.getRectFromPoints(c)}}computDotStroke(t){const{point:e,radius:s}=t,i={x:e.x-s,y:e.y-s,w:s*2,h:s*2};return{ps:o.Point2d.GetDotStroke(e,s,8),rect:i}}transformData(t,e){const{op:s,workState:i}=t;let r=this.tmpPoints.length-1,n=[];if(s!=null&&s.length&&i){const{strokeType:c,thickness:l}=this.workOptions,h=new Set;r=c===o.EStrokeType.Stroke?this.updateTempPointsWithPressure(s,l,h):this.updateTempPoints(s,l,h);const p=e?this.tmpPoints:this.tmpPoints.slice(r);return n=this.getTaskPoints(p,l),{tasks:n,effects:h,consumeIndex:r}}return{tasks:n,consumeIndex:r}}computRadius(t,e){return t*.03*e+e*.5}getMinZ(t,e){return((e||Math.max(1,Math.floor(t*.3)))-t*.5)*100/t/3}getTaskPoints(t,e){var p;const s=[];if(t.length===0)return[];let i=0,r=t[0].x,n=t[0].y,c=[r,n],l=[],h=t[0].t;for(;i<t.length;){const d=t[i],y=d.x-r,u=d.y-n,f=d.z,g=e?this.computRadius(f,e):f;if(l.push({point:new o.Point2d(y,u,f,t[i].v),radius:g}),i>0&&i<t.length-1){const w=t[i].getAngleByPoints(t[i-1],t[i+1]);if(w<90||w>270){const W=(p=l.pop())==null?void 0:p.point.clone();W&&s.push({taskId:h,pos:c,points:[...l,{point:W,radius:g}]}),r=t[i].x,n=t[i].y,c=[r,n];const k=d.x-r,S=d.y-n;l=[{point:new o.Point2d(k,S,f),radius:g}],h=Date.now()}}i++}return s.push({taskId:h,pos:c,points:l}),s}updateTempPointsWithPressure(t,e,s){const i=Date.now(),r=this.tmpPoints.length;let n=r;for(let l=0;l<t.length;l+=2){n=Math.min(n,r);const h=this.tmpPoints.length,p=new o.Point2d(t[l],t[l+1]);if(h===0){this.tmpPoints.push(p);continue}const d=h-1,y=this.tmpPoints[d],u=o.Vec2d.Sub(p,y).uni();if(p.isNear(y,e)){if(y.z<this.MAX_REPEAR){if(y.setz(Math.min(y.z+1,this.MAX_REPEAR)),n=Math.min(n,d),h>1){let w=h-1;for(;w>0;){const W=this.tmpPoints[w].distance(this.tmpPoints[w-1]),k=Math.max(this.tmpPoints[w].z-this.uniThickness*W,0);if(this.tmpPoints[w-1].z>=k)break;this.tmpPoints[w-1].setz(k),n=Math.min(n,w-1),w--}}}else n=1/0;continue}p.setv(u);const f=p.distance(y),g=Math.max(y.z-this.uniThickness*f,0);h>1&&o.Vec2d.Equals(u,y.v,.02)&&(g>0||y.z<=0)&&(s&&y.t&&s.add(y.t),this.tmpPoints.pop(),n=Math.min(d,n)),p.setz(g),this.tmpPoints.push(p)}if(n===1/0)return this.tmpPoints.length;let c=r;if(n===r){c=Math.max(c-1,0);const l=this.tmpPoints[c].t;l&&(s==null||s.add(l))}else{let l=r-1;for(c=n;l>=0;){const h=this.tmpPoints[l].t;if(h&&(s==null||s.add(h),l<=n)){c=l,l=-1;break}l--}}return this.tmpPoints[c].setT(i),c}updateTempPoints(t,e,s){var l;const i=Date.now(),r=this.tmpPoints.length;let n=r;for(let h=0;h<t.length;h+=2){const p=this.tmpPoints.length,d=new o.Point2d(t[h],t[h+1]);if(p===0){this.tmpPoints.push(d);continue}const y=p-1,u=this.tmpPoints[y],f=o.Vec2d.Sub(d,u).uni();if(d.isNear(u,e/2)){n=Math.min(y,n);continue}o.Vec2d.Equals(f,u.v,.02)&&(s&&u.t&&s.add(u.t),this.tmpPoints.pop(),n=Math.min(y,n)),d.setv(f),this.tmpPoints.push(d)}let c=r;if(n===r){c=Math.max(c-1,0);const h=this.tmpPoints[c].t;h&&(s==null||s.add(h))}else{let h=Math.min(r-1,n);for(c=n;h>=0;){const p=(l=this.tmpPoints[h])==null?void 0:l.t;if(p&&(s==null||s.add(p),h<=n)){c=h,h=-1;break}h--}}return this.tmpPoints[c].setT(i),c}updateTempPointsWithPressureWhenDone(t){const{thickness:e}=this.workOptions,s=t.length,i=this.getMinZ(e);for(let r=0;r<s;r+=2){const n=this.tmpPoints.length,c=new o.Point2d(t[r],t[r+1]);if(n===0){this.tmpPoints.push(c);continue}const l=n-1,h=this.tmpPoints[l],p=o.Vec2d.Sub(c,h).uni(),d=c.distance(h);if(n>1&&h.z===i)break;if(c.isNear(h,e/2)){if(s<3&&h.z<this.MAX_REPEAR&&(h.setz(Math.min(h.z+1,this.MAX_REPEAR)),n>1)){let u=n-1;for(;u>0;){const f=this.tmpPoints[u].distance(this.tmpPoints[u-1]),g=Math.max(this.tmpPoints[u].z-this.uniThickness*f,-e/4);if(this.tmpPoints[u-1].z>=g)break;this.tmpPoints[u-1].setz(g),u--}}continue}c.setv(p);const y=Math.max(h.z-this.uniThickness*d,i);n>1&&o.Vec2d.Equals(p,h.v,.02)&&h.z<=0&&this.tmpPoints.pop(),c.setz(y),this.tmpPoints.push(c)}}static updateNodeOpt(t){var c;const{node:e,opt:s,vNodes:i}=t,{strokeColor:r}=s,n=i.get(e.name);return r&&(e.tagName==="GROUP"?he(e)?e.setAttribute("bgcolor",r):e.children.forEach(l=>{l.setAttribute("strokeColor",r),l.getAttribute("fillColor")&&l.setAttribute("fillColor",r)}):(e.setAttribute("strokeColor",r),e.setAttribute("fillColor",r)),(c=n==null?void 0:n.opt)!=null&&c.strokeColor&&(n.opt.strokeColor=r)),n&&i.setInfo(e.name,n),E.updateNodeOpt(t)}}class Z extends E{constructor(t){super(t);m(this,"toolsType",o.EToolsKey.LaserPen);m(this,"canRotate",!1);m(this,"scaleType",o.EScaleType.none);m(this,"syncTimestamp");m(this,"syncIndex",0);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"consumeIndex",0);this.workOptions=t.toolsOpt,this.syncTimestamp=0}combineConsume(){}setWorkOptions(t){super.setWorkOptions(t),this.syncTimestamp=Date.now()}consume(t){const{data:e,isSubWorker:s}=t,{workId:i,op:r}=e;if((r==null?void 0:r.length)===0)return{type:o.EPostMessageType.None};if(this.updateTempPoints(r||[]),this.consumeIndex>this.tmpPoints.length-4)return{type:o.EPostMessageType.None};const{strokeColor:n,thickness:c,strokeType:l}=this.workOptions,h=o.getRectFromPoints(this.tmpPoints,c);let p=!1;const d=this.syncIndex,y=this.tmpPoints.slice(this.consumeIndex);this.consumeIndex=this.tmpPoints.length-1,this.syncTimestamp===0&&(this.syncTimestamp=Date.now());const u={name:i==null?void 0:i.toString(),opacity:1,lineDash:l===o.EStrokeType.Dotted?[1,c*2]:l===o.EStrokeType.LongDotted?[c,c*2]:void 0,strokeColor:n,lineCap:"round",lineWidth:c,anchor:[.5,.5]},f=this.getTaskPoints(y);if(f.length){const w=Date.now();w-this.syncTimestamp>this.syncUnitTime&&(p=!0,this.syncTimestamp=w,this.syncIndex=this.tmpPoints.length),s&&this.draw({attrs:u,tasks:f,isDot:!1,layer:this.drawLayer||this.fullLayer})}const g=[];return this.tmpPoints.slice(d).forEach(w=>{g.push(w.x,w.y)}),{rect:{x:h.x*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],y:h.y*this.fullLayer.worldScaling[1]+this.fullLayer.worldPosition[1],w:h.w*this.fullLayer.worldScaling[0],h:h.h*this.fullLayer.worldScaling[1]},type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:p?i:void 0,op:p?g:void 0,index:p?d*2:void 0}}consumeAll(){var r;const t=(r=this.workId)==null?void 0:r.toString();let e;if(this.tmpPoints.length-1>this.consumeIndex){let n=this.tmpPoints.slice(this.consumeIndex);const c=n.length===1,{strokeColor:l,thickness:h,strokeType:p}=this.workOptions;if(c){const u=this.computDotStroke({point:n[0],radius:h/2});n=u.ps,e=u.rect}else e=o.getRectFromPoints(this.tmpPoints,h);const d={name:t==null?void 0:t.toString(),fillColor:c?l:void 0,opacity:1,lineDash:p===o.EStrokeType.Dotted&&!c?[1,h*2]:p===o.EStrokeType.LongDotted&&!c?[h,h*2]:void 0,strokeColor:l,lineCap:c?void 0:"round",lineWidth:c?0:h,anchor:[.5,.5]},y=this.getTaskPoints(n);y.length&&this.draw({attrs:d,tasks:y,isDot:c,layer:this.drawLayer||this.fullLayer})}const s=[];this.tmpPoints.forEach(n=>{s.push(n.x,n.y)});const i=o.transformToSerializableData(s);return{rect:e&&{x:e.x*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],y:e.y*this.fullLayer.worldScaling[1]+this.fullLayer.worldPosition[1],w:e.w*this.fullLayer.worldScaling[0],h:e.h*this.fullLayer.worldScaling[1]},type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:t,ops:i,index:this.syncIndex*2}}clearTmpPoints(){this.tmpPoints.length=0,this.syncTimestamp=0,this.syncIndex=0}consumeService(t){var f;const{op:e,replaceId:s,isFullWork:i}=t,{strokeColor:r,thickness:n,strokeType:c}=this.workOptions;if(!e.length){const g=o.getRectFromPoints(this.tmpPoints,n);return{x:g.x*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],y:g.y*this.fullLayer.worldScaling[1]+this.fullLayer.worldPosition[1],w:g.w*this.fullLayer.worldScaling[0],h:g.h*this.fullLayer.worldScaling[1]}}const l=Math.max(0,this.tmpPoints.length-1);this.updateTempPoints(e||[]);let h,p=this.tmpPoints.slice(l);const d=p.length===1;if(d){const g=this.computDotStroke({point:p[0],radius:n/2});p=g.ps,h=g.rect}else h=o.getRectFromPoints(this.tmpPoints,n);const y={name:(f=this.workId)==null?void 0:f.toString(),fillColor:d?r:void 0,opacity:1,lineDash:c===o.EStrokeType.Dotted&&!d?[1,n*2]:c===o.EStrokeType.LongDotted&&!d?[n,n*2]:void 0,strokeColor:r,lineCap:d?void 0:"round",lineWidth:d?0:n,anchor:[.5,.5]},u=this.getTaskPoints(p);if(u.length){const g=i?this.fullLayer:this.drawLayer||this.fullLayer;this.draw({attrs:y,tasks:u,isDot:d,replaceId:s,layer:g})}return{x:h.x*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],y:h.y*this.fullLayer.worldScaling[1]+this.fullLayer.worldPosition[1],w:h.w*this.fullLayer.worldScaling[0],h:h.h*this.fullLayer.worldScaling[1]}}computDotStroke(t){const{point:e,radius:s}=t,i={x:e.x-s,y:e.y-s,w:s*2,h:s*2};return{ps:o.Point2d.GetDotStroke(e,s,8),rect:i}}updateTempPoints(t){const e=this.tmpPoints.length;for(let s=0;s<t.length;s+=2){if(e){const i=this.tmpPoints.slice(-1)[0];i&&i.x===t[s]&&i.y===t[s+1]&&this.tmpPoints.pop()}this.tmpPoints.push(new o.Point2d(t[s],t[s+1]))}}async draw(t){const{attrs:e,tasks:s,isDot:i,layer:r}=t,{duration:n}=this.workOptions;for(const c of s){const l=new x.Path,{pos:h,points:p}=c;let d;i?d=X(p,!0):d=X(p,!1),l.attr({...e,pos:h,d});const{vertex:y,fragment:u}=this.workOptions;if(y&&u){const f=r.renderer.createProgram({vertex:y,fragment:u}),{width:g,height:w}=r.getResolution();l.setUniforms({u_time:0,u_resolution:[g,w]}),l.setProgram(f)}r.appendChild(l),l.transition(n).attr({scale:i?[.1,.1]:[1,1],lineWidth:i?0:1}).then(()=>{l.remove()})}}getTaskPoints(t){var l;const e=[];if(t.length===0)return[];let s=0,i=t[0].x,r=t[0].y,n=[i,r],c=[];for(;s<t.length;){const h=t[s],p=h.x-i,d=h.y-r;if(c.push(new o.Point2d(p,d)),s>0&&s<t.length-1){const y=t[s].getAngleByPoints(t[s-1],t[s+1]);if(y<90||y>270){const u=(l=c.pop())==null?void 0:l.clone();u&&e.push({pos:n,points:[...c,u]}),i=t[s].x,r=t[s].y,n=[i,r];const f=h.x-i,g=h.y-r;c=[new o.Point2d(f,g)]}}s++}return e.push({pos:n,points:c}),e}removeLocal(){}removeService(t){let e;const s=[];return this.fullLayer.getElementsByName(t).forEach(i=>{if(i.name===t){const r=i.getBoundingClientRect();e=o.computRect(e,{x:r.x,y:r.y,w:r.width,h:r.height}),s.push(i)}}),s.length&&s.forEach(i=>i.remove()),e}}const U=class U extends E{constructor(t,e){super(t);m(this,"canRotate",!1);m(this,"scaleType",o.EScaleType.none);m(this,"toolsType",o.EToolsKey.Eraser);m(this,"serviceWork");m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"worldPosition");m(this,"worldScaling");m(this,"eraserRect");m(this,"eraserPolyline");this.serviceWork=e,this.workOptions=t.toolsOpt,this.worldPosition=this.fullLayer.worldPosition,this.worldScaling=this.fullLayer.worldScaling}combineConsume(){}consumeService(){}setWorkOptions(t){super.setWorkOptions(t)}createEraserRect(t){const e=t[0]*this.worldScaling[0]+this.worldPosition[0],s=t[1]*this.worldScaling[1]+this.worldPosition[1],{width:i,height:r}=U.eraserSizes[this.workOptions.thickness];this.eraserRect={x:e-i*.5,y:s-r*.5,w:i,h:r},this.eraserPolyline=[this.eraserRect.x,this.eraserRect.y,this.eraserRect.x+this.eraserRect.w,this.eraserRect.y+this.eraserRect.h]}computRectCenterPoints(){const t=this.tmpPoints.slice(-2);if(this.tmpPoints.length===4){const e=new o.Vec2d(this.tmpPoints[0],this.tmpPoints[1]),s=new o.Vec2d(this.tmpPoints[2],this.tmpPoints[3]),i=o.Vec2d.Sub(s,e).uni(),r=o.Vec2d.Dist(e,s),{width:n,height:c}=U.eraserSizes[this.workOptions.thickness],l=Math.min(n,c),h=Math.round(r/l);if(h>1){const p=[];for(let d=0;d<h;d++){const y=o.Vec2d.Mul(i,d*l);p.push(this.tmpPoints[0]+y.x,this.tmpPoints[1]+y.y)}return p.concat(t)}}return t}isNear(t,e){const s=new o.Vec2d(t[0],t[1]),i=new o.Vec2d(e[0],e[1]),{width:r,height:n}=U.eraserSizes[this.workOptions.thickness];return o.Vec2d.Dist(s,i)<Math.hypot(r,n)*.5}cutPolyline(t,e){let s=[e],i=0;for(;i<t.length;){const c=t[i];if(c.length<2)break;s=r(s,c),i++}return s;function r(c,l){const h=c;for(let p=0;p<c.length;p++){const d=c[p],y=d.findIndex((u,f)=>f<d.length-1?n([u,d[f+1]],[l[0],l[1]]):!1);if(y!==-1&&y>-1){const u=[],f=d.slice(0,y+1);if(o.Vec2d.Equals(d[y],l[0])||f.push(l[0].clone().setz(d[y].z)),f.length>1&&u.push(f),y+l.length-1<d.length-1){const g=y+l.length-1,w=d.slice(g),W=l[l.length-1];o.Vec2d.Equals(d[g],W)||w.unshift(W.clone().setz(d[g].z)),w.length>1&&u.push(w)}return h.splice(p,1,...u),h}}return h}function n(c,l){const h=o.Vec2d.Sub(c[1],c[0]),p=o.Vec2d.Sub(l[1],l[0]),d=o.Vec2d.Sub(l[0],c[0]);return Math.abs(o.Vec2d.Cpr(h,p))<.1&&Math.abs(o.Vec2d.Cpr(h,d))<.1}}isSamePoint(t,e){return t[0]===e[0]&&t[1]===e[1]}translateIntersect(t){const e=[];for(let s=0;s<t.length;s++){const i=t[s].filter((c,l,h)=>!(l>0&&this.isSamePoint(c,h[l-1]))),r=[];let n=0;for(;n<i.length;){const c=i[n],l=new o.Vec2d(c[0],c[1]);r.push(l),n++}e.push(r)}return e}isLineEraser(t,e){return!(t===o.EToolsKey.Pencil&&!e)}remove(t){const{curNodeMap:e,removeIds:s,newWorkDatas:i}=t,{isLine:r}=this.workOptions;let n;for(const[c,l]of e.entries())if(l.rect&&this.eraserRect&&this.eraserPolyline&&o.isIntersect(this.eraserRect,l.rect)){const{op:h,toolsType:p}=l,d=this.isLineEraser(p,r),y=[],u=[];for(let g=0;g<h.length;g+=3){const w=new o.Vec2d(h[g]*this.worldScaling[0]+this.worldPosition[0],h[g+1]*this.worldScaling[1]+this.worldPosition[1],h[g+2]);u.push(w),y.push(new o.Point2d(w.x,w.y))}const f=y.length&&o.getRectFromPoints(y)||l.rect;if(o.isIntersect(f,this.eraserRect)){if(u.length>1){const g=le.polyline(u.map(w=>w.XY),this.eraserPolyline);if(g.length&&(s.add(l.name),!d)){const w=this.translateIntersect(g),W=this.cutPolyline(w,u);for(let k=0;k<W.length;k++){const S=`${c}_s_${k}`,I=[];W[k].forEach(v=>{I.push((v.x-this.worldPosition[0])/this.worldScaling[0],(v.y-this.worldPosition[1])/this.worldScaling[1],v.z)}),l.opt&&l.toolsType&&this.vNodes&&(this.vNodes.setInfo(S,{rect:f,op:I,opt:l.opt,canRotate:l.canRotate,scaleType:l.scaleType,toolsType:l.toolsType}),i.set(S,{workId:S,op:I,opt:l.opt,toolsType:l.toolsType}))}}}else s.add(l.name);n=o.computRect(n,f)}}return s.forEach(c=>{var l;return(l=this.vNodes)==null?void 0:l.delete(c)}),n&&(n.x-=E.SafeBorderPadding,n.y-=E.SafeBorderPadding,n.w+=E.SafeBorderPadding*2,n.h+=E.SafeBorderPadding*2),n}consume(t){const{op:e}=t.data;if(!e||e.length===0)return{type:o.EPostMessageType.None};const s=this.tmpPoints.length;if(s>1&&this.isNear([e[0],e[1]],[this.tmpPoints[s-2],this.tmpPoints[s-1]]))return{type:o.EPostMessageType.None};s===4&&(this.tmpPoints.shift(),this.tmpPoints.shift()),this.tmpPoints.push(e[0],e[1]);const i=this.computRectCenterPoints();let r;const n=new Set,c=new Map;if(!this.vNodes)return{type:o.EPostMessageType.None};this.vNodes.setTarget();const l=this.getUnLockNodeMap(this.vNodes.getLastTarget());for(let h=0;h<i.length-1;h+=2){this.createEraserRect(i.slice(h,h+2));const p=this.remove({curNodeMap:l,removeIds:n,newWorkDatas:c});r=o.computRect(r,p)}if(this.vNodes.deleteLastTarget(),r&&n.size){for(const h of c.keys())n.has(h)&&c.delete(h);return{type:o.EPostMessageType.RemoveNode,dataType:o.EDataType.Local,rect:r,removeIds:[...n],newWorkDatas:c}}return{type:o.EPostMessageType.None}}consumeAll(t){return this.consume(t)}clearTmpPoints(){this.tmpPoints.length=0}getUnLockNodeMap(t){var e;if(this.serviceWork){const s=o.cloneDeep(t),i=this.serviceWork.selectorWorkShapes,r=this.serviceWork.workShapes;for(const n of i.values())if((e=n.selectIds)!=null&&e.length)for(const c of n.selectIds)s.delete(c);for(const n of r.keys())s.delete(n);return s}return t}};m(U,"eraserSizes",Object.freeze([Object.freeze({width:18,height:26}),Object.freeze({width:26,height:34}),Object.freeze({width:34,height:50})]));let q=U;const V=class V extends E{constructor(t){super(t);m(this,"toolsType",o.EToolsKey.Selector);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"vNodes");m(this,"selectIds");m(this,"selectorColor");m(this,"strokeColor");m(this,"fillColor");m(this,"oldSelectRect");m(this,"canRotate",!1);m(this,"canTextEdit",!1);m(this,"canLock",!1);m(this,"scaleType",o.EScaleType.all);m(this,"toolsTypes");m(this,"shapeOpt");m(this,"textOpt");m(this,"isLocked");this.workOptions=t.toolsOpt,this.vNodes=t.vNodes}computSelector(t=!0){const e=o.getRectFromPoints(this.tmpPoints);if(e.w===0||e.h===0)return{selectIds:[],intersectRect:void 0,subNodeMap:new Map};const{rectRange:s,nodeRange:i}=this.vNodes.getRectIntersectRange(e,t);return{selectIds:[...i.keys()],intersectRect:s,subNodeMap:i}}updateTempPoints(t){const e=this.tmpPoints.length,s=t.length;if(s>1){const i=new o.Point2d(t[s-2]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],t[s-1]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[1]);e===2?this.tmpPoints.splice(1,1,i):this.tmpPoints.push(i)}}drawSelector(t){const{drawRect:e,subNodeMap:s,selectorId:i,layer:r,isService:n}=t,c=new x.Group({pos:[e.x,e.y],anchor:[0,0],size:[e.w,e.h],id:i,name:i,zIndex:1e3}),l=[];if(n){const h=new x.Rect({normalize:!0,pos:[e.w/2,e.h/2],lineWidth:1,strokeColor:this.selectorColor||this.workOptions.strokeColor,width:e.w,height:e.h,name:V.selectorBorderId});l.push(h)}s.forEach((h,p)=>{const d=[h.rect.x+h.rect.w/2-e.x,h.rect.y+h.rect.h/2-e.y],y=new x.Rect({normalize:!0,pos:d,lineWidth:1,strokeColor:s.size>1?this.selectorColor||this.workOptions.strokeColor:void 0,width:h.rect.w,height:h.rect.h,id:`selector-${p}`,name:`selector-${p}`});l.push(y)}),l&&c.append(...l),(r==null?void 0:r.parent).appendChild(c)}draw(t,e,s,i=!1){var c,l;const{intersectRect:r,subNodeMap:n}=s;(l=(c=e.parent)==null?void 0:c.getElementById(t))==null||l.remove(),r&&this.drawSelector({drawRect:r,subNodeMap:n,selectorId:t,layer:e,isService:i})}getSelecteorInfo(t){this.scaleType=o.EScaleType.all,this.canRotate=!1,this.textOpt=void 0,this.strokeColor=void 0,this.fillColor=void 0,this.canTextEdit=!1,this.canLock=!1,this.isLocked=!1,this.toolsTypes=void 0,this.shapeOpt=void 0;const e=new Set;let s;for(const i of t.values()){const{opt:r,canRotate:n,scaleType:c,toolsType:l}=i;this.selectorColor=this.workOptions.strokeColor,r.strokeColor&&(this.strokeColor=r.strokeColor),r.fillColor&&(this.fillColor=r.fillColor),r.textOpt&&(this.textOpt=r.textOpt),l===o.EToolsKey.SpeechBalloon&&(e.add(l),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.placement=r.placement),l===o.EToolsKey.Polygon&&(e.add(l),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=r.vertices),l===o.EToolsKey.Star&&(e.add(l),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=r.vertices,this.shapeOpt.innerRatio=r.innerRatio,this.shapeOpt.innerVerticeStep=r.innerVerticeStep),l===o.EToolsKey.Text&&(this.textOpt=r),t.size===1&&(this.textOpt&&(this.canTextEdit=!0),this.canRotate=n,this.scaleType=c),c===o.EScaleType.none&&(this.scaleType=c),l===o.EToolsKey.Image&&(s=i)}e.size&&(this.toolsTypes=[...e]),s&&(t.size===1?(this.canLock=!0,s.opt.locked&&(this.isLocked=!0,this.scaleType=o.EScaleType.none,this.canRotate=!1,this.textOpt=void 0,this.fillColor=void 0,this.selectorColor="rgb(177,177,177)",this.strokeColor=void 0,this.canTextEdit=!1)):t.size>1&&!s.opt.locked&&(this.canLock=!1,this.canRotate=!1))}getChildrenPoints(){var t,e;if(this.scaleType===o.EScaleType.both&&((t=this.selectIds)==null?void 0:t.length)===1){const s=this.selectIds[0],i=(e=this.vNodes.get(s))==null?void 0:e.op;if(i){const r=[];for(let n=0;n<i.length;n+=3)r.push([i[n],i[n+1]]);return r}}}consume(t){const{op:e,workState:s}=t.data;let i=this.oldSelectRect;if(s===o.EvevtWorkState.Start&&(i=this.unSelectedAllIds()),!(e!=null&&e.length)||!this.vNodes.curNodeMap.size)return{type:o.EPostMessageType.None};this.updateTempPoints(e);const r=this.computSelector();if(this.selectIds&&o.isEqual(this.selectIds,r.selectIds))return{type:o.EPostMessageType.None};this.selectIds=r.selectIds;const n=r.intersectRect;this.getSelecteorInfo(r.subNodeMap),this.draw(V.selectorId,this.fullLayer,r),this.oldSelectRect=n;const c=this.getChildrenPoints();return{type:o.EPostMessageType.Select,dataType:o.EDataType.Local,rect:o.computRect(n,i),selectIds:r.selectIds,opt:this.workOptions,selectRect:n,selectorColor:this.selectorColor,strokeColor:this.strokeColor,fillColor:this.fillColor,textOpt:this.textOpt,canTextEdit:this.canTextEdit,canRotate:this.canRotate,canLock:this.canLock,scaleType:this.scaleType,willSyncService:!0,points:c,isLocked:this.isLocked,toolsTypes:this.toolsTypes,shapeOpt:this.shapeOpt}}consumeAll(){var e,s;let t=this.oldSelectRect;if(!((e=this.selectIds)!=null&&e.length)&&this.tmpPoints[0]&&this.selectSingleTool(this.tmpPoints[0].XY,V.selectorId,!1),(s=this.selectIds)!=null&&s.length&&(t=this.selectedByIds(this.selectIds)),t){const i=this.getChildrenPoints();return{type:o.EPostMessageType.Select,dataType:o.EDataType.Local,rect:this.oldSelectRect,selectIds:this.selectIds,opt:this.workOptions,selectorColor:this.selectorColor,selectRect:this.oldSelectRect,strokeColor:this.strokeColor,fillColor:this.fillColor,textOpt:this.textOpt,canTextEdit:this.canTextEdit,canRotate:this.canRotate,canLock:this.canLock,scaleType:this.scaleType,willSyncService:!0,points:i,isLocked:this.isLocked,toolsTypes:this.toolsTypes,shapeOpt:this.shapeOpt}}return{type:o.EPostMessageType.None}}consumeService(){}clearTmpPoints(){this.tmpPoints.length=0}clearSelectData(){this.selectIds=void 0,this.oldSelectRect=void 0}selectSingleTool(t,e=V.selectorId,s=!1){if(t.length===2){const i=t[0],r=t[1];let n;const{nodeRange:c}=this.vNodes.getRectIntersectRange({x:i,y:r,w:0,h:0},!1),l=[...c.values()].sort((h,p)=>(p.opt.zIndex||0)-(h.opt.zIndex||0));for(const h of l){const p=this.fullLayer.getElementsByName(h.name);if(ne(p).find(y=>y.isPointCollision(i,r))){n=h;break}}if(n){const h=n.name;if(!o.isEqual(this.oldSelectRect,n.rect)){const p=new Map([[h,n]]);this.getSelecteorInfo(p),this.draw(e,this.fullLayer,{intersectRect:n.rect,subNodeMap:p,selectIds:this.selectIds||[]},s)}this.selectIds=[h],this.oldSelectRect=n.rect}}}unSelectedAllIds(){let t;for(const[e,s]of this.vNodes.curNodeMap.entries())s.isSelected&&(t=o.computRect(t,s.rect),this.vNodes.unSelected(e));return t}unSelectedByIds(t){let e;for(const s of t){const i=this.vNodes.get(s);i&&i.isSelected&&(e=o.computRect(e,i.rect),this.vNodes.unSelected(s))}return e}selectedByIds(t){let e;for(const s of t){const i=this.vNodes.get(s);i&&(e=o.computRect(e,i.rect),this.vNodes.selected(s))}return e}getSelectorRect(t,e){var n;let s;const i=(n=t.parent)==null?void 0:n.getElementById(e),r=i==null?void 0:i.getBoundingClientRect();return r&&(s=o.computRect(s,{x:Math.floor(r.x),y:Math.floor(r.y),w:Math.floor(r.width+1),h:Math.floor(r.height+1)})),s}isCanFillColor(t){return t===o.EToolsKey.Ellipse||t===o.EToolsKey.Triangle||t===o.EToolsKey.Rectangle||t===o.EToolsKey.Polygon||t===o.EToolsKey.Star||t===o.EToolsKey.SpeechBalloon}async updateSelector(t){const{updateSelectorOpt:e,selectIds:s,vNodes:i,willSerializeData:r,worker:n,offset:c,scene:l,isMainThread:h}=t,p=this.fullLayer;if(!p)return;let d;const y=new Map,{box:u,workState:f,angle:g,translate:w}=e;let W=[0,0],k=[1,1],S=[0,0],I,v;if(u||w||o.isNumber(g)){if(f===o.EvevtWorkState.Start)return i.setTarget(),{type:o.EPostMessageType.Select,dataType:o.EDataType.Local,selectRect:this.oldSelectRect,rect:this.oldSelectRect};if(I=i.getLastTarget(),I&&u){let T;s==null||s.forEach(N=>{const R=I==null?void 0:I.get(N);T=o.computRect(T,R==null?void 0:R.rect)}),T&&(k=[u.w/T.w,u.h/T.h],W=[u.x+u.w/2-(T.x+T.w/2),u.y+u.h/2-(T.y+T.h/2)],S=[T.x+T.w/2,T.y+T.h/2]),v=T}}if(s)for(const T of s){const N=i.get(T);if(N){const{toolsType:R}=N;let D=(p==null?void 0:p.getElementsByName(T))[0];if(D){const b={...e};let O;if(R){if(I&&(O=I.get(T),O&&u)){b.boxScale=k;const A=[O.rect.x+O.rect.w/2,O.rect.y+O.rect.h/2],K=[A[0]-S[0],A[1]-S[1]];b.boxTranslate=[K[0]*(k[0]-1)+W[0]+(c&&c[0]||0),K[1]*(k[1]-1)+W[1]+(c&&c[1]||0)]}const G=re(R);if(G==null||G.updateNodeOpt({node:D,opt:b,vNodes:i,willSerializeData:r,targetNode:O}),N&&n&&(r&&(b.angle||b.translate)||b.box&&b.workState!==o.EvevtWorkState.Start||b.pointMap&&b.pointMap.has(T)||R===o.EToolsKey.Text&&(b.fontSize||b.translate||b.textInfos&&b.textInfos.get(T))||R===o.EToolsKey.Image&&(b.angle||b.translate||b.boxScale)||R===b.toolsType&&b.willRefresh)){const A=n.createWorkShapeNode({toolsType:R,toolsOpt:N.opt});A==null||A.setWorkId(T);let K;R===o.EToolsKey.Image&&l?K=await A.consumeServiceAsync({isFullWork:!0,replaceId:T,scene:l,isMainThread:h}):R===o.EToolsKey.Text?K=await A.consumeServiceAsync({isFullWork:!0,replaceId:T}):K=A==null?void 0:A.consumeService({op:N.op,isFullWork:!0,replaceId:T}),K&&(N.rect=K),D=(p==null?void 0:p.getElementsByName(T))[0]}N&&(y.set(T,N),d=o.computRect(d,N.rect))}}}}I&&f===o.EvevtWorkState.Done&&i.deleteLastTarget();const P=d;if(v&&e.dir&&P&&!c){const T=[0,0];switch(e.dir){case"top":{const N=[v.x,v.y+v.h];e.reverseY?T[1]=N[1]-P.y:T[1]=N[1]-(P.y+P.h);break}case"topLeft":{const N=[v.x+v.w,v.y+v.h];e.reverseY?T[1]=N[1]-P.y:T[1]=N[1]-(P.y+P.h),e.reverseX?T[0]=N[0]-P.x:T[0]=N[0]-(P.x+P.w);break}case"topRight":{const N=[v.x,v.y+v.h];e.reverseY?T[1]=N[1]-P.y:T[1]=N[1]-(P.y+P.h),e.reverseX?T[0]=N[0]-(P.x+P.w):T[0]=N[0]-P.x;break}case"bottom":{const N=[v.x,v.y];e.reverseY?T[1]=N[1]-(P.y+P.h):T[1]=N[1]-P.y;break}case"bottomLeft":{const N=[v.x+v.w,v.y];e.reverseY?T[1]=N[1]-(P.y+P.h):T[1]=N[1]-P.y,e.reverseX?T[0]=N[0]-P.x:T[0]=N[0]-(P.x+P.w);break}case"bottomRight":{const N=[v.x,v.y];e.reverseY?T[1]=N[1]-(P.y+P.h):T[1]=N[1]-P.y,e.reverseX?T[0]=N[0]-(P.x+P.w):T[0]=N[0]-P.x;break}case"right":{const N=[v.x,v.y];e.reverseX?T[0]=N[0]-(P.x+P.w):T[0]=N[0]-P.x;break}}if(T[0]||T[1])return P.x=P.x+T[0],P.y=P.y+T[1],await this.updateSelector({...t,offset:T})}this.getSelecteorInfo(y),this.draw(V.selectorId,p,{selectIds:s||[],subNodeMap:y,intersectRect:P});const L=o.computRect(this.oldSelectRect,P);return this.oldSelectRect=P,{type:o.EPostMessageType.Select,dataType:o.EDataType.Local,selectRect:P,renderRect:d,rect:o.computRect(L,P)}}blurSelector(){const t=this.unSelectedAllIds();return{type:o.EPostMessageType.Select,dataType:o.EDataType.Local,rect:t,selectIds:[],willSyncService:!0}}getRightServiceId(t){return t.replace(o.Storage_Splitter,"-")}selectServiceNode(t,e,s){const{selectIds:i}=e,r=this.getRightServiceId(t),n=this.getSelectorRect(this.fullLayer,r);let c;const l=new Map;return i==null||i.forEach(h=>{const p=this.vNodes.get(h);p&&(c=o.computRect(c,p.rect),l.set(h,p))}),this.getSelecteorInfo(l),this.draw(r,this.fullLayer,{intersectRect:c,selectIds:i||[],subNodeMap:l},s),o.computRect(c,n)}reRenderSelector(){var s;let t;const e=new Map;return(s=this.selectIds)==null||s.forEach(i=>{const r=this.vNodes.get(i);r&&(t=o.computRect(t,r.rect),e.set(i,r))},this),this.getSelecteorInfo(e),this.draw(V.selectorId,this.fullLayer,{intersectRect:t,subNodeMap:e,selectIds:this.selectIds||[]}),this.oldSelectRect=t,t}updateSelectIds(t){var r;let e;const s=(r=this.selectIds)==null?void 0:r.filter(n=>!t.includes(n));if(s!=null&&s.length&&(e=this.unSelectedByIds(s)),t.length){const n=this.selectedByIds(t);e=o.computRect(e,n)}this.selectIds=t;const i=this.reRenderSelector();return{bgRect:e,selectRect:i}}cursorHover(t){var r,n;const e=this.oldSelectRect;this.selectIds=[];const s=(r=this.workId)==null?void 0:r.toString(),i=[t[0]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],t[1]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[1]];if(this.selectSingleTool(i,s,!0),this.oldSelectRect&&!o.isEqual(e,this.oldSelectRect))return{type:o.EPostMessageType.CursorHover,dataType:o.EDataType.Local,rect:o.computRect(e,this.oldSelectRect),selectorColor:this.selectorColor,willSyncService:!1};if((n=this.selectIds)!=null&&n.length||(this.oldSelectRect=void 0),e&&!this.oldSelectRect)return this.cursorBlur(),{type:o.EPostMessageType.CursorHover,dataType:o.EDataType.Local,rect:e,selectorColor:this.selectorColor,willSyncService:!1}}cursorBlur(){var e,s;this.selectIds=[];const t=(e=this.workId)==null?void 0:e.toString();((s=this.fullLayer)==null?void 0:s.parent).children.forEach(i=>{i.name===t&&i.remove()})}};m(V,"selectorId",o.Storage_Selector_key),m(V,"selectorBorderId","selector-border");let C=V;class J extends E{constructor(t){super(t);m(this,"canRotate",!1);m(this,"scaleType",o.EScaleType.both);m(this,"toolsType",o.EToolsKey.Arrow);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"arrowTipWidth");m(this,"syncTimestamp");this.workOptions=t.toolsOpt,this.arrowTipWidth=this.workOptions.thickness*4,this.syncTimestamp=0,this.syncUnitTime=50}consume(t){var u;const{data:e,isFullWork:s,isSubWorker:i,isMainThread:r}=t,n=(u=e==null?void 0:e.workId)==null?void 0:u.toString();if(!n)return{type:o.EPostMessageType.None};const{op:c,workState:l}=e,h=c==null?void 0:c.length;if(!h||h<2)return{type:o.EPostMessageType.None};let p;if(l===o.EvevtWorkState.Start?(this.tmpPoints=[new o.Point2d(c[0],c[1])],p=!1):p=this.updateTempPoints(c),!p)return{type:o.EPostMessageType.None};let d;if(i||r){const f=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:f})}if(!i){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n,op:this.tmpPoints.map(g=>[...g.XY,0]).flat(1),isSync:!0,index:0}):{type:o.EPostMessageType.None}}const y=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:y,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n}}consumeAll(t){var l,h;const{data:e}=t,s=(l=e==null?void 0:e.workId)==null?void 0:l.toString();if(!s)return{type:o.EPostMessageType.None};if(this.tmpPoints.length<2)return{type:o.EPostMessageType.RemoveNode,removeIds:[s]};const i=this.fullLayer,r=this.draw({workId:s,layer:i});this.oldRect=r;const n=this.tmpPoints.map(p=>[...p.XY,0]).flat(1),c=o.transformToSerializableData(n);return(h=this.vNodes)==null||h.setInfo(s,{rect:r,op:n,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:E.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s}=t,{strokeColor:i,thickness:r,zIndex:n,scale:c,rotate:l,translate:h}=this.workOptions,p=s.worldPosition,d=s.worldScaling,{points:y,rect:u}=this.computDrawPoints(r),g={pos:[u.x+u.w/2,u.y+u.h/2],name:e,id:e,close:!0,points:y,fillColor:i,strokeColor:i,lineWidth:0,normalize:!0,zIndex:n};c&&(g.scale=c),l&&(g.rotate=l),h&&(g.translate=h);const w=new x.Polyline(g);if(this.replace(s,e,w),c||l||h){const W=w.getBoundingClientRect();return{x:Math.floor(W.x-E.SafeBorderPadding),y:Math.floor(W.y-E.SafeBorderPadding),w:Math.floor(W.width+E.SafeBorderPadding*2),h:Math.floor(W.height+E.SafeBorderPadding*2)}}return{x:Math.floor(u.x*d[0]+p[0]-E.SafeBorderPadding),y:Math.floor(u.y*d[1]+p[1]-E.SafeBorderPadding),w:Math.floor(u.w*d[0]+2*E.SafeBorderPadding),h:Math.floor(u.h*d[1]+2*E.SafeBorderPadding)}}computDrawPoints(t){return this.tmpPoints[1].distance(this.tmpPoints[0])>this.arrowTipWidth?this.computFullArrowPoints(t):this.computTrianglePoints()}computFullArrowPoints(t){const e=o.Vec2d.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),s=o.Vec2d.Per(e).mul(t/2),i=o.Point2d.Sub(this.tmpPoints[0],s),r=o.Point2d.Add(this.tmpPoints[0],s),n=o.Vec2d.Mul(e,this.arrowTipWidth),c=o.Vec2d.Sub(this.tmpPoints[1],n),l=o.Point2d.Sub(c,s),h=o.Point2d.Add(c,s),p=o.Vec2d.Per(e).mul(t*1.5),d=o.Point2d.Sub(c,p),y=o.Point2d.Add(c,p),u=[i,l,d,this.tmpPoints[1],y,h,r];return{points:u.map(f=>o.Point2d.Sub(f,this.tmpPoints[0]).XY).flat(1),rect:o.getRectFromPoints(u),isTriangle:!1,pos:this.tmpPoints[0].XY}}computTrianglePoints(){const t=o.Vec2d.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),e=this.tmpPoints[1].distance(this.tmpPoints[0]),s=o.Vec2d.Per(t).mul(Math.floor(e*3/8)),i=o.Point2d.Sub(this.tmpPoints[0],s),r=o.Point2d.Add(this.tmpPoints[0],s),n=[i,this.tmpPoints[1],r];return{points:n.map(c=>o.Point2d.Sub(c,this.tmpPoints[0]).XY).flat(1),rect:o.getRectFromPoints(n),isTriangle:!0,pos:this.tmpPoints[0].XY}}updateTempPoints(t){const e=t.slice(-2),s=new o.Point2d(e[0],e[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(s,r))return!1;if(this.tmpPoints.length===2){if(s.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=s}else this.tmpPoints.push(s);return!0}consumeService(t){var c,l;const{op:e,isFullWork:s}=t,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<e.length;h+=3)this.tmpPoints.push(new o.Point2d(e[h],e[h+1],e[h+2]));const r=s?this.fullLayer:this.drawLayer||this.fullLayer,n=this.draw({workId:i,layer:r});return this.oldRect=n,(l=this.vNodes)==null||l.setInfo(i,{rect:n,op:e,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:E.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(t){var c;const{node:e,opt:s,vNodes:i}=t,{strokeColor:r}=s,n=i.get(e.name);return r&&(e.setAttribute("strokeColor",r),e.setAttribute("fillColor",r),(c=n==null?void 0:n.opt)!=null&&c.strokeColor&&(n.opt.strokeColor=r),n&&i.setInfo(e.name,n)),E.updateNodeOpt(t)}}class Q extends E{constructor(t){super(t);m(this,"canRotate",!1);m(this,"scaleType",o.EScaleType.all);m(this,"toolsType",o.EToolsKey.Ellipse);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"syncTimestamp");this.workOptions=t.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(t){var u;const{data:e,isFullWork:s,isSubWorker:i,isMainThread:r}=t,n=(u=e==null?void 0:e.workId)==null?void 0:u.toString();if(!n)return{type:o.EPostMessageType.None};const{op:c,workState:l}=e,h=c==null?void 0:c.length;if(!h||h<2)return{type:o.EPostMessageType.None};let p;if(l===o.EvevtWorkState.Start?(this.tmpPoints=[new o.Point2d(c[0],c[1])],p=!1):p=this.updateTempPoints(c),!p)return{type:o.EPostMessageType.None};let d;if(i||r){const f=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:f,isDrawing:!0})}if(!i){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n,op:this.tmpPoints.map(g=>[...g.XY,0]).flat(1),isSync:!0,index:0}):{type:o.EPostMessageType.None}}const y=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:y,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n}}consumeAll(t){var l,h;const{data:e}=t,s=(l=e==null?void 0:e.workId)==null?void 0:l.toString();if(!s)return{type:o.EPostMessageType.None};if(this.tmpPoints.length<2)return{type:o.EPostMessageType.RemoveNode,removeIds:[s]};const i=this.fullLayer,r=this.draw({workId:s,layer:i,isDrawing:!1});this.oldRect=r;const n=this.tmpPoints.map(p=>[...p.XY,0]).flat(1),c=o.transformToSerializableData(n);return(h=this.vNodes)==null||h.setInfo(s,{rect:r,op:n,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:r&&E.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s,isDrawing:i}=t,{strokeColor:r,fillColor:n,thickness:c,zIndex:l,scale:h,rotate:p,translate:d}=this.workOptions,y=s.worldScaling,{radius:u,rect:f,pos:g}=this.computDrawPoints(c),w={pos:g,name:e,id:e,radius:u,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0},W={name:e,id:e,zIndex:l,pos:g,anchor:[.5,.5],size:[f.w,f.h]};h&&(W.scale=h),p&&(W.rotate=p),d&&(W.translate=d);const k=new x.Group(W);if(i){const v=new x.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/y[0],1/y[1]]});k.append(v)}const S=new x.Ellipse({...w,pos:[0,0]});k.append(S),this.replace(s,e,k);const I=k.getBoundingClientRect();return{x:Math.floor(I.x-E.SafeBorderPadding),y:Math.floor(I.y-E.SafeBorderPadding),w:Math.floor(I.width+E.SafeBorderPadding*2),h:Math.floor(I.height+E.SafeBorderPadding*2)}}computDrawPoints(t){const e=o.getRectFromPoints(this.tmpPoints),s=o.getRectFromPoints(this.tmpPoints,t),i=[Math.floor(e.x+e.w/2),Math.floor(e.y+e.h/2)];return{rect:s,pos:i,radius:[Math.floor(e.w/2),Math.floor(e.h/2)]}}updateTempPoints(t){const e=t.slice(-2),s=new o.Point2d(e[0],e[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(s,r))return!1;if(this.tmpPoints.length===2){if(s.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=s}else this.tmpPoints.push(s);return!0}consumeService(t){var c,l;const{op:e,isFullWork:s}=t,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<e.length;h+=3)this.tmpPoints.push(new o.Point2d(e[h],e[h+1],e[h+2]));const r=s?this.fullLayer:this.drawLayer||this.fullLayer,n=this.draw({workId:i,layer:r,isDrawing:!1});return this.oldRect=n,(l=this.vNodes)==null||l.setInfo(i,{rect:n,op:e,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:E.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(t){var h,p;const{node:e,opt:s,vNodes:i}=t,{strokeColor:r,fillColor:n}=s,c=i.get(e.name);let l=e;return e.tagName==="GROUP"&&(l=e.children[0]),r&&(l.setAttribute("strokeColor",r),(h=c==null?void 0:c.opt)!=null&&h.strokeColor&&(c.opt.strokeColor=r)),n&&(n==="transparent"?l.setAttribute("fillColor","rgba(0,0,0,0)"):l.setAttribute("fillColor",n),(p=c==null?void 0:c.opt)!=null&&p.fillColor&&(c.opt.fillColor=n)),c&&i.setInfo(e.name,c),E.updateNodeOpt(t)}}class ee extends E{constructor(t){super(t);m(this,"canRotate",!0);m(this,"scaleType",o.EScaleType.all);m(this,"toolsType",o.EToolsKey.Rectangle);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"syncTimestamp");this.workOptions=t.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}transformData(){const t=o.getRectFromPoints(this.tmpPoints);return[[t.x,t.y,0],[t.x+t.w,t.y,0],[t.x+t.w,t.y+t.h,0],[t.x,t.y+t.h,0]]}computDrawPoints(t){const{thickness:e}=this.workOptions,s=[];for(const n of t)s.push(new o.Vec2d(...n));const i=o.getRectFromPoints(s,e),r=[i.x+i.w/2,i.y+i.h/2];return{rect:i,pos:r,points:s.map(n=>n.XY).flat(1)}}consume(t){var f;const{data:e,isFullWork:s,isSubWorker:i,isMainThread:r}=t,n=(f=e==null?void 0:e.workId)==null?void 0:f.toString();if(!n)return{type:o.EPostMessageType.None};const{op:c,workState:l}=e,h=c==null?void 0:c.length;if(!h||h<2)return{type:o.EPostMessageType.None};let p;if(l===o.EvevtWorkState.Start?(this.tmpPoints=[new o.Point2d(c[0],c[1])],p=!1):p=this.updateTempPoints(c),!p)return{type:o.EPostMessageType.None};const d=this.transformData();let y;if(i||r){const g=s?this.fullLayer:this.drawLayer||this.fullLayer;y=this.draw({ps:d,workId:n,layer:g,isDrawing:!0})}if(!i){const g=Date.now();return g-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=g,{type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n,op:d.flat(1),isSync:!0,index:0}):{type:o.EPostMessageType.None}}const u=o.computRect(y,this.oldRect);return this.oldRect=y,{rect:u,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n}}consumeAll(t){var h,p;const{data:e}=t,s=(h=e==null?void 0:e.workId)==null?void 0:h.toString();if(!s)return{type:o.EPostMessageType.None};if(this.tmpPoints.length<2)return{type:o.EPostMessageType.RemoveNode,removeIds:[s]};const i=this.transformData(),r=this.fullLayer,n=this.draw({ps:i,workId:s,layer:r,isDrawing:!1});this.oldRect=n;const c=i.flat(1),l=o.transformToSerializableData(c);return(p=this.vNodes)==null||p.setInfo(s,{rect:n,op:c,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&E.getCenterPos(n,r)}),{rect:n,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:l,opt:this.workOptions,isSync:!0}}draw(t){const{workId:e,layer:s,isDrawing:i,ps:r,replaceId:n}=t,{strokeColor:c,fillColor:l,thickness:h,zIndex:p,scale:d,rotate:y,translate:u,textOpt:f}=this.workOptions,g=s.worldPosition,w=s.worldScaling,{points:W,rect:k,pos:S}=this.computDrawPoints(r),I={close:!0,normalize:!0,points:W,lineWidth:h,fillColor:l!=="transparent"&&l||void 0,strokeColor:c,lineJoin:"round"},v={x:Math.floor(k.x*w[0]+g[0]-E.SafeBorderPadding),y:Math.floor(k.y*w[1]+g[1]-E.SafeBorderPadding),w:Math.floor(k.w*w[0]+2*E.SafeBorderPadding),h:Math.floor(k.h*w[0]+2*E.SafeBorderPadding)},P=new x.Group({name:e,id:e,zIndex:p,pos:S,anchor:[.5,.5],size:[k.w,k.h],scale:d,rotate:y,translate:u}),L=new x.Polyline({...I,pos:[0,0]});if(P.appendChild(L),i){const T=new x.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:c,lineWidth:1,scale:[1/w[0],1/w[1]]});P.appendChild(T)}if(this.replace(s,n||e,P),d||y||u){const T=P.getBoundingClientRect();return{x:Math.floor(T.x-E.SafeBorderPadding),y:Math.floor(T.y-E.SafeBorderPadding),w:Math.floor(T.width+2*E.SafeBorderPadding),h:Math.floor(T.height+2*E.SafeBorderPadding)}}return v}updateTempPoints(t){const e=t.slice(-2),s=new o.Point2d(e[0],e[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(s,r))return!1;if(this.tmpPoints.length===2){if(s.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=s}else this.tmpPoints.push(s);return!0}consumeService(t){var h,p;const{op:e,isFullWork:s,replaceId:i}=t,r=(h=this.workId)==null?void 0:h.toString();if(!r)return;const n=[];for(let d=0;d<e.length;d+=3)n.push([e[d],e[d+1],e[d+2]]);const c=s?this.fullLayer:this.drawLayer||this.fullLayer,l=this.draw({ps:n,workId:r,layer:c,isDrawing:!1,replaceId:i});return this.oldRect=l,(p=this.vNodes)==null||p.setInfo(r,{rect:l,op:e,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:l&&E.getCenterPos(l,c)}),l}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(t){var w,W;const{node:e,opt:s,vNodes:i}=t,{strokeColor:r,fillColor:n,fontColor:c,fontBgColor:l,bold:h,italic:p,lineThrough:d,underline:y,fontSize:u}=s,f=i.get(e.name);let g=e;if(e.tagName==="GROUP"&&(g=e.children[0]),r&&(g.setAttribute("strokeColor",r),(w=f==null?void 0:f.opt)!=null&&w.strokeColor&&(f.opt.strokeColor=r)),n&&(n==="transparent"?g.setAttribute("fillColor","rgba(0,0,0,0)"):g.setAttribute("fillColor",n),(W=f==null?void 0:f.opt)!=null&&W.fillColor&&(f.opt.fillColor=n)),f!=null&&f.opt.textOpt){const k=f.opt.textOpt;c&&k.fontColor&&(k.fontColor=c),l&&k.fontBgColor&&(k.fontBgColor=l),h&&(k.bold=h),p&&(k.italic=p),o.isBoolean(d)&&(k.lineThrough=d),o.isBoolean(y)&&(k.underline=y),u&&(k.fontSize=u)}return f&&i.setInfo(e.name,f),E.updateNodeOpt(t)}}class te extends E{constructor(t){super(t);m(this,"canRotate",!1);m(this,"scaleType",o.EScaleType.all);m(this,"toolsType",o.EToolsKey.Star);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"syncTimestamp");this.workOptions=t.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(t){var u;const{data:e,isFullWork:s,isSubWorker:i,isMainThread:r}=t,n=(u=e==null?void 0:e.workId)==null?void 0:u.toString();if(!n)return{type:o.EPostMessageType.None};const{op:c,workState:l}=e,h=c==null?void 0:c.length;if(!h||h<2)return{type:o.EPostMessageType.None};let p;if(l===o.EvevtWorkState.Start?(this.tmpPoints=[new o.Point2d(c[0],c[1])],p=!1):p=this.updateTempPoints(c),!p)return{type:o.EPostMessageType.None};let d;if(i||r){const f=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:f,isDrawing:!0})}if(!i){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n,op:this.tmpPoints.map(g=>[...g.XY,0]).flat(1),isSync:!0,index:0}):{type:o.EPostMessageType.None}}const y=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:y,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n}}consumeAll(t){var l,h;const{data:e}=t,s=(l=e==null?void 0:e.workId)==null?void 0:l.toString();if(!s)return{type:o.EPostMessageType.None};if(this.tmpPoints.length<2)return{type:o.EPostMessageType.RemoveNode,removeIds:[s]};const i=this.fullLayer,r=this.draw({workId:s,layer:i,isDrawing:!1});this.oldRect=r;const n=this.tmpPoints.map(p=>[...p.XY,0]).flat(1),c=o.transformToSerializableData(n);return(h=this.vNodes)==null||h.setInfo(s,{rect:r,op:n,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:r&&E.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s,isDrawing:i}=t,{strokeColor:r,fillColor:n,thickness:c,zIndex:l,vertices:h,innerVerticeStep:p,innerRatio:d,scale:y,rotate:u,translate:f}=this.workOptions,g=s.worldScaling,{rect:w,pos:W,points:k}=this.computDrawPoints(c,h,p,d),S={close:!0,points:k,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0,lineJoin:"round"},I={name:e,id:e,zIndex:l,pos:W,anchor:[.5,.5],size:[w.w,w.h],className:`${W[0]},${W[1]}`};y&&(I.scale=y),u&&(I.rotate=u),f&&(I.translate=f);const v=new x.Group(I);if(i){const T=new x.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/g[0],1/g[1]]});v.append(T)}const P=new x.Polyline({...S,pos:[0,0]});v.append(P),this.replace(s,e,v);const L=v.getBoundingClientRect();return{x:Math.floor(L.x-E.SafeBorderPadding),y:Math.floor(L.y-E.SafeBorderPadding),w:Math.floor(L.width+E.SafeBorderPadding*2),h:Math.floor(L.height+E.SafeBorderPadding*2)}}computDrawPoints(t,e,s,i){const r=o.getRectFromPoints(this.tmpPoints),n=[Math.floor(r.x+r.w/2),Math.floor(r.y+r.h/2)],c=o.getWHRatio(r.w,r.h),l=Math.floor(Math.min(r.w,r.h)/2),h=i*l,p=[],d=2*Math.PI/e;for(let u=0;u<e;u++){const f=u*d-.5*Math.PI;let g,w;u%s===1?(g=h*c[0]*Math.cos(f),w=h*c[1]*Math.sin(f)):(g=l*c[0]*Math.cos(f),w=l*c[1]*Math.sin(f),p.push(g,w)),p.push(g,w)}return{rect:o.getRectFromPoints(this.tmpPoints,t),pos:n,points:p}}updateTempPoints(t){const e=t.slice(-2),s=new o.Point2d(e[0],e[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(s,r)||o.Point2d.Sub(i,s).XY.includes(0))return!1;if(this.tmpPoints.length===2){if(s.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=s}else this.tmpPoints.push(s);return!0}consumeService(t){var c,l;const{op:e,isFullWork:s}=t,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<e.length;h+=3)this.tmpPoints.push(new o.Point2d(e[h],e[h+1],e[h+2]));const r=s?this.fullLayer:this.drawLayer||this.fullLayer,n=this.draw({workId:i,layer:r,isDrawing:!1});return this.oldRect=n,(l=this.vNodes)==null||l.setInfo(i,{rect:n,op:e,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&E.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(t){const{node:e,opt:s,vNodes:i}=t,{strokeColor:r,fillColor:n,toolsType:c,vertices:l,innerVerticeStep:h,innerRatio:p}=s,d=i.get(e.name),y=d==null?void 0:d.opt;let u=e;return e.tagName==="GROUP"&&(u=e.children[0]),r&&(u.setAttribute("strokeColor",r),y!=null&&y.strokeColor&&(y.strokeColor=r)),n&&(n==="transparent"?u.setAttribute("fillColor","rgba(0,0,0,0)"):u.setAttribute("fillColor",n),y!=null&&y.fillColor&&(y.fillColor=n)),c===o.EToolsKey.Star&&(l&&(y.vertices=l),h&&(y.innerVerticeStep=h),p&&(y.innerRatio=p)),d&&i.setInfo(e.name,{...d,opt:y}),E.updateNodeOpt(t)}}class oe extends E{constructor(t){super(t);m(this,"canRotate",!1);m(this,"scaleType",o.EScaleType.all);m(this,"toolsType",o.EToolsKey.Polygon);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"syncTimestamp");this.workOptions=t.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(t){var u;const{data:e,isFullWork:s,isSubWorker:i,isMainThread:r}=t,n=(u=e==null?void 0:e.workId)==null?void 0:u.toString();if(!n)return{type:o.EPostMessageType.None};const{op:c,workState:l}=e,h=c==null?void 0:c.length;if(!h||h<2)return{type:o.EPostMessageType.None};let p;if(l===o.EvevtWorkState.Start?(this.tmpPoints=[new o.Point2d(c[0],c[1])],p=!1):p=this.updateTempPoints(c),!p)return{type:o.EPostMessageType.None};let d;if(i||r){const f=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:f,isDrawing:!0})}if(!i){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n,op:this.tmpPoints.map(g=>[...g.XY,0]).flat(1),isSync:!0,index:0}):{type:o.EPostMessageType.None}}const y=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:y,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n}}consumeAll(t){var l,h;const{data:e}=t,s=(l=e==null?void 0:e.workId)==null?void 0:l.toString();if(!s)return{type:o.EPostMessageType.None};if(this.tmpPoints.length<2)return{type:o.EPostMessageType.RemoveNode,removeIds:[s]};const i=this.fullLayer,r=this.draw({workId:s,layer:i,isDrawing:!1});this.oldRect=r;const n=this.tmpPoints.map(p=>[...p.XY,0]).flat(1),c=o.transformToSerializableData(n);return(h=this.vNodes)==null||h.setInfo(s,{rect:r,op:n,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:r&&E.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s,isDrawing:i}=t,{strokeColor:r,fillColor:n,thickness:c,zIndex:l,vertices:h,scale:p,rotate:d,translate:y}=this.workOptions,u=s.worldScaling,{rect:f,pos:g,points:w}=this.computDrawPoints(c,h),W={close:!0,points:w,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0,lineJoin:"round"},k={name:e,id:e,zIndex:l,pos:g,anchor:[.5,.5],size:[f.w,f.h]};p&&(k.scale=p),d&&(k.rotate=d),y&&(k.translate=y);const S=new x.Group(k);if(i){const P=new x.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/u[0],1/u[1]]});S.append(P)}const I=new x.Polyline({...W,pos:[0,0]});S.append(I),this.replace(s,e,S);const v=S.getBoundingClientRect();return{x:Math.floor(v.x-E.SafeBorderPadding),y:Math.floor(v.y-E.SafeBorderPadding),w:Math.floor(v.width+E.SafeBorderPadding*2),h:Math.floor(v.height+E.SafeBorderPadding*2)}}computDrawPoints(t,e){const s=o.getRectFromPoints(this.tmpPoints),i=[Math.floor(s.x+s.w/2),Math.floor(s.y+s.h/2)],r=o.getWHRatio(s.w,s.h),n=Math.floor(Math.min(s.w,s.h)/2),c=[],l=2*Math.PI/e;for(let p=0;p<e;p++){const d=p*l-.5*Math.PI,y=n*r[0]*Math.cos(d),u=n*r[1]*Math.sin(d);c.push(y,u)}return{rect:o.getRectFromPoints(this.tmpPoints,t),pos:i,points:c}}updateTempPoints(t){const e=t.slice(-2),s=new o.Point2d(e[0],e[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(s,r)||o.Point2d.Sub(i,s).XY.includes(0))return!1;if(this.tmpPoints.length===2){if(s.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=s}else this.tmpPoints.push(s);return!0}consumeService(t){var c,l;const{op:e,isFullWork:s}=t,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<e.length;h+=3)this.tmpPoints.push(new o.Point2d(e[h],e[h+1],e[h+2]));const r=s?this.fullLayer:this.drawLayer||this.fullLayer,n=this.draw({workId:i,layer:r,isDrawing:!1});return this.oldRect=n,(l=this.vNodes)==null||l.setInfo(i,{rect:n,op:e,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&E.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(t){const{node:e,opt:s,vNodes:i}=t,{strokeColor:r,fillColor:n,toolsType:c,vertices:l}=s,h=i.get(e.name),p=h==null?void 0:h.opt;let d=e;return e.tagName==="GROUP"&&(d=e.children[0]),r&&(d.setAttribute("strokeColor",r),p!=null&&p.strokeColor&&(p.strokeColor=r)),n&&(n==="transparent"?d.setAttribute("fillColor","rgba(0,0,0,0)"):d.setAttribute("fillColor",n),p!=null&&p.fillColor&&(p.fillColor=n)),c===o.EToolsKey.Polygon&&l&&(p.vertices=l),h&&i.setInfo(e.name,{...h,opt:p}),E.updateNodeOpt(t)}}class F{static bezier(a,t){const e=[];for(let s=0;s<t.length;s+=4){const i=t[s],r=t[s+1],n=t[s+2],c=t[s+3];i&&r&&n&&c?e.push(...F.getBezierPoints(a,i,r,n,c)):i&&r&&n?e.push(...F.getBezierPoints(a,i,r,n)):i&&r?e.push(...F.getBezierPoints(a,i,r)):i&&e.push(i)}return e}static getBezierPoints(a=10,t,e,s,i){let r=null;const n=[];!s&&!i?r=F.oneBezier:s&&!i?r=F.twoBezier:s&&i&&(r=F.threeBezier);for(let c=0;c<a;c++)r&&n.push(r(c/a,t,e,s,i));return i?n.push(i):s&&n.push(s),n}static oneBezier(a,t,e){const s=t.x+(e.x-t.x)*a,i=t.y+(e.y-t.y)*a;return new o.Vec2d(s,i)}static twoBezier(a,t,e,s){const i=(1-a)*(1-a)*t.x+2*a*(1-a)*e.x+a*a*s.x,r=(1-a)*(1-a)*t.y+2*a*(1-a)*e.y+a*a*s.y;return new o.Vec2d(i,r)}static threeBezier(a,t,e,s,i){const r=t.x*(1-a)*(1-a)*(1-a)+3*e.x*a*(1-a)*(1-a)+3*s.x*a*a*(1-a)+i.x*a*a*a,n=t.y*(1-a)*(1-a)*(1-a)+3*e.y*a*(1-a)*(1-a)+3*s.y*a*a*(1-a)+i.y*a*a*a;return new o.Vec2d(r,n)}}class se extends E{constructor(t){super(t);m(this,"canRotate",!1);m(this,"scaleType",o.EScaleType.all);m(this,"toolsType",o.EToolsKey.SpeechBalloon);m(this,"ratio",.8);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"syncTimestamp");this.workOptions=t.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(t){var u;const{data:e,isFullWork:s,isSubWorker:i,isMainThread:r}=t,n=(u=e==null?void 0:e.workId)==null?void 0:u.toString();if(!n)return{type:o.EPostMessageType.None};const{op:c,workState:l}=e,h=c==null?void 0:c.length;if(!h||h<2)return{type:o.EPostMessageType.None};let p;if(l===o.EvevtWorkState.Start?(this.tmpPoints=[new o.Point2d(c[0],c[1])],p=!1):p=this.updateTempPoints(c),!p)return{type:o.EPostMessageType.None};let d;if(i||r){const f=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:f,isDrawing:!0})}if(!i){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n,op:this.tmpPoints.map(g=>[...g.XY,0]).flat(1),isSync:!0,index:0}):{type:o.EPostMessageType.None}}const y=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:y,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n}}consumeAll(t){var l,h;const{data:e}=t,s=(l=e==null?void 0:e.workId)==null?void 0:l.toString();if(!s)return{type:o.EPostMessageType.None};if(this.tmpPoints.length<2)return{type:o.EPostMessageType.RemoveNode,removeIds:[s]};const i=this.fullLayer,r=this.draw({workId:s,layer:i,isDrawing:!1});this.oldRect=r;const n=this.tmpPoints.map(p=>[...p.XY,0]).flat(1),c=o.transformToSerializableData(n);return(h=this.vNodes)==null||h.setInfo(s,{rect:r,op:n,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:r&&E.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s}=t,{strokeColor:i,fillColor:r,thickness:n,zIndex:c,placement:l,scale:h,rotate:p,translate:d}=this.workOptions,{rect:y,pos:u,points:f}=this.computDrawPoints(n,l),g={points:f.map(I=>I.XY),lineWidth:n,fillColor:r!=="transparent"&&r||void 0,strokeColor:i,normalize:!0,className:`${u[0]},${u[1]}`,lineJoin:"round",close:!0},w={name:e,id:e,zIndex:c,pos:u,anchor:[.5,.5],size:[y.w,y.h]};h&&(w.scale=h),p&&(w.rotate=p),d&&(w.translate=d);const W=new x.Group(w),k=new x.Polyline({...g,pos:[0,0]});W.append(k),this.replace(s,e,W);const S=W.getBoundingClientRect();return{x:Math.floor(S.x-E.SafeBorderPadding),y:Math.floor(S.y-E.SafeBorderPadding),w:Math.floor(S.width+E.SafeBorderPadding*2),h:Math.floor(S.height+E.SafeBorderPadding*2)}}transformControlPoints(t){const e=o.getRectFromPoints(this.tmpPoints);switch(t){case"bottom":case"bottomLeft":case"bottomRight":{const s=e.y+e.h*this.ratio;return[new o.Vec2d(e.x,e.y,0),new o.Vec2d(e.x+e.w,e.y,0),new o.Vec2d(e.x+e.w,s,0),new o.Vec2d(e.x,s,0)]}case"top":case"topLeft":case"topRight":{const s=e.y+e.h*(1-this.ratio);return[new o.Vec2d(e.x,s,0),new o.Vec2d(e.x+e.w,s,0),new o.Vec2d(e.x+e.w,e.y+e.h,0),new o.Vec2d(e.x,e.y+e.h,0)]}case"left":case"leftBottom":case"leftTop":{const s=e.x+e.w*(1-this.ratio);return[new o.Vec2d(s,e.y,0),new o.Vec2d(e.x+e.w,e.y,0),new o.Vec2d(e.x+e.w,e.y+e.h,0),new o.Vec2d(s,e.y+e.h,0)]}case"right":case"rightBottom":case"rightTop":{const s=e.x+e.w*this.ratio;return[new o.Vec2d(e.x,e.y,0),new o.Vec2d(s,e.y,0),new o.Vec2d(s,e.y+e.h,0),new o.Vec2d(e.x,e.y+e.h,0)]}}}computDrawPoints(t,e){const s=o.getRectFromPoints(this.tmpPoints),i=this.transformControlPoints(e),r=Math.floor(s.w*.1),n=Math.floor(s.h*.1),c=[],l=o.Vec2d.Add(i[0],new o.Vec2d(0,n,0)),h=o.Vec2d.Add(i[0],new o.Vec2d(r,0,0)),p=F.getBezierPoints(10,l,i[0],h),d=o.Vec2d.Sub(i[1],new o.Vec2d(r,0,0)),y=o.Vec2d.Add(i[1],new o.Vec2d(0,n,0)),u=F.getBezierPoints(10,d,i[1],y),f=o.Vec2d.Sub(i[2],new o.Vec2d(0,n,0)),g=o.Vec2d.Sub(i[2],new o.Vec2d(r,0,0)),w=F.getBezierPoints(10,f,i[2],g),W=o.Vec2d.Add(i[3],new o.Vec2d(r,0,0)),k=o.Vec2d.Sub(i[3],new o.Vec2d(0,n,0)),S=F.getBezierPoints(10,W,i[3],k),I=r*(1-this.ratio)*10,v=n*(1-this.ratio)*10;switch(e){case"bottom":{const T=o.Vec2d.Sub(i[2],new o.Vec2d(r*5-I/2,0,0)),N=o.Vec2d.Sub(i[2],new o.Vec2d(r*5,-v,0)),R=o.Vec2d.Sub(i[2],new o.Vec2d(r*5+I/2,0,0));c.push(N,R,...S,...p,...u,...w,T);break}case"bottomRight":{const T=o.Vec2d.Sub(i[2],new o.Vec2d(r*1.1,0,0)),N=o.Vec2d.Sub(i[2],new o.Vec2d(r*1.1+I/2,-v,0)),R=o.Vec2d.Sub(i[2],new o.Vec2d(r*1.1+I,0,0));c.push(N,R,...S,...p,...u,...w,T);break}case"bottomLeft":{const T=o.Vec2d.Add(i[3],new o.Vec2d(r*1.1+I,0,0)),N=o.Vec2d.Add(i[3],new o.Vec2d(r*1.1+I/2,v,0)),R=o.Vec2d.Add(i[3],new o.Vec2d(r*1.1,0,0));c.push(N,R,...S,...p,...u,...w,T);break}case"top":{const T=o.Vec2d.Sub(i[1],new o.Vec2d(r*5-I/2,0,0)),N=o.Vec2d.Sub(i[1],new o.Vec2d(r*5,v,0)),R=o.Vec2d.Sub(i[1],new o.Vec2d(r*5+I/2,0,0));c.push(N,T,...u,...w,...S,...p,R);break}case"topRight":{const T=o.Vec2d.Sub(i[1],new o.Vec2d(r*1.1,0,0)),N=o.Vec2d.Sub(i[1],new o.Vec2d(r*1.1+I/2,v,0)),R=o.Vec2d.Sub(i[1],new o.Vec2d(r*1.1+I,0,0));c.push(N,T,...u,...w,...S,...p,R);break}case"topLeft":{const T=o.Vec2d.Add(i[0],new o.Vec2d(r*1.1+I,0,0)),N=o.Vec2d.Add(i[0],new o.Vec2d(r*1.1+I/2,-v,0)),R=o.Vec2d.Add(i[0],new o.Vec2d(r*1.1,0,0));c.push(N,T,...u,...w,...S,...p,R);break}case"left":{const T=o.Vec2d.Add(i[0],new o.Vec2d(0,n*5-v/2,0)),N=o.Vec2d.Add(i[0],new o.Vec2d(-I,n*5,0)),R=o.Vec2d.Add(i[0],new o.Vec2d(0,n*5+v/2,0));c.push(N,T,...p,...u,...w,...S,R);break}case"leftTop":{const T=o.Vec2d.Add(i[0],new o.Vec2d(0,n*1.1,0)),N=o.Vec2d.Add(i[0],new o.Vec2d(-I,n*1.1+v/2,0)),R=o.Vec2d.Add(i[0],new o.Vec2d(0,n*1.1+v,0));c.push(N,T,...p,...u,...w,...S,R);break}case"leftBottom":{const T=o.Vec2d.Sub(i[3],new o.Vec2d(0,n*1.1+v,0)),N=o.Vec2d.Sub(i[3],new o.Vec2d(I,n*1.1+v/2,0)),R=o.Vec2d.Sub(i[3],new o.Vec2d(0,n*1.1,0));c.push(N,T,...p,...u,...w,...S,R);break}case"right":{const T=o.Vec2d.Add(i[1],new o.Vec2d(0,n*5-v/2,0)),N=o.Vec2d.Add(i[1],new o.Vec2d(I,n*5,0)),R=o.Vec2d.Add(i[1],new o.Vec2d(0,n*5+v/2,0));c.push(N,R,...w,...S,...p,...u,T);break}case"rightTop":{const T=o.Vec2d.Add(i[1],new o.Vec2d(0,n*1.1,0)),N=o.Vec2d.Add(i[1],new o.Vec2d(I,n*1.1+v/2,0)),R=o.Vec2d.Add(i[1],new o.Vec2d(0,n*1.1+v,0));c.push(N,R,...w,...S,...p,...u,T);break}case"rightBottom":{const T=o.Vec2d.Sub(i[2],new o.Vec2d(0,n*1.1+v,0)),N=o.Vec2d.Sub(i[2],new o.Vec2d(-I,n*1.1+v/2,0)),R=o.Vec2d.Sub(i[2],new o.Vec2d(0,n*1.1,0));c.push(N,R,...w,...S,...p,...u,T);break}}const P=o.getRectFromPoints(this.tmpPoints,t),L=[Math.floor(P.x+P.w/2),Math.floor(P.y+P.h/2)];return{rect:P,pos:L,points:c}}updateTempPoints(t){const e=t.slice(-2),s=new o.Point2d(e[0],e[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(s,r)||o.Point2d.Sub(i,s).XY.includes(0))return!1;if(this.tmpPoints.length===2){if(s.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=s}else this.tmpPoints.push(s);return!0}consumeService(t){var c,l;const{op:e,isFullWork:s}=t,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<e.length;h+=3)this.tmpPoints.push(new o.Point2d(e[h],e[h+1],e[h+2]));const r=s?this.fullLayer:this.drawLayer||this.fullLayer,n=this.draw({workId:i,layer:r,isDrawing:!1});return this.oldRect=n,(l=this.vNodes)==null||l.setInfo(i,{rect:n,op:e,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&E.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(t){const{node:e,opt:s,vNodes:i}=t,{strokeColor:r,fillColor:n,toolsType:c,placement:l}=s,h=i.get(e.name),p=h==null?void 0:h.opt;let d=e;return e.tagName==="GROUP"&&(d=e.children[0]),r&&(d.setAttribute("strokeColor",r),p!=null&&p.strokeColor&&(p.strokeColor=r)),n&&(n==="transparent"?d.setAttribute("fillColor","rgba(0,0,0,0)"):d.setAttribute("fillColor",n),p!=null&&p.fillColor&&(p.fillColor=n)),c===o.EToolsKey.SpeechBalloon&&l&&(p.placement=l),h&&i.setInfo(e.name,{...h,opt:p}),E.updateNodeOpt(t)}}class $ extends E{constructor(t){super(t);m(this,"canRotate",!0);m(this,"scaleType",o.EScaleType.all);m(this,"toolsType",o.EToolsKey.Image);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");this.workOptions=t.toolsOpt,this.scaleType=$.getScaleType(this.workOptions)}consume(){return{type:o.EPostMessageType.None}}consumeAll(){return{type:o.EPostMessageType.None}}draw(t){const{layer:e,workId:s,replaceId:i,imageBitmap:r,isMainThread:n}=t,{centerX:c,centerY:l,width:h,height:p,rotate:d,zIndex:y}=this.workOptions,u={anchor:[.5,.5],pos:[c,l],name:s,size:[h,p],zIndex:y,rotate:!n&&180+(d||0)||d,texture:r},f=new x.Sprite(u);this.replace(e,i||s,f);const g=f.getBoundingClientRect();if(g)return{x:Math.floor(g.x-E.SafeBorderPadding),y:Math.floor(g.y-E.SafeBorderPadding),w:Math.floor(g.width+E.SafeBorderPadding*2),h:Math.floor(g.height+E.SafeBorderPadding*2)}}consumeService(){}async consumeServiceAsync(t){var p,d,y,u;const{isFullWork:e,replaceId:s,scene:i,isMainThread:r}=t,{src:n,uuid:c}=this.workOptions,l=((p=this.workId)==null?void 0:p.toString())||c,h=e?this.fullLayer:this.drawLayer||this.fullLayer;if(n){const f=await i.preload({id:c,src:this.workOptions.src}),g=this.draw({workId:l,layer:h,replaceId:s,imageBitmap:f[0],isMainThread:r});return this.oldRect=l&&((y=(d=this.vNodes)==null?void 0:d.get(l))==null?void 0:y.rect)||void 0,(u=this.vNodes)==null||u.setInfo(l,{rect:g,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:g&&E.getCenterPos(g,h)}),g}}clearTmpPoints(){this.tmpPoints.length=0}static getScaleType(t){const{uniformScale:e,rotate:s}=t;return e!==!1||s&&Math.abs(s)%90>0?o.EScaleType.proportional:o.EScaleType.all}static updateNodeOpt(t){const{node:e,opt:s,vNodes:i,targetNode:r}=t,{translate:n,box:c,boxScale:l,boxTranslate:h,angle:p,isLocked:d,zIndex:y}=s,u=r&&o.cloneDeep(r)||i.get(e.name);if(!u)return;const f=e.parent;if(f){if(o.isNumber(y)&&(e.setAttribute("zIndex",y),u.opt.zIndex=y),o.isBoolean(d)&&(u.opt.locked=d),c&&h&&l){const{centerX:g,centerY:w,width:W,height:k,uniformScale:S,rotate:I}=u.opt,v=Math.min(l[0],l[1]),P=S!==!1?[v,v]:l,L=o.getRectRotatedPoints({x:g-W/2,y:w-k/2,w:W,h:k},I||0),T=o.getScalePoints(L,new o.Vec2d(g,w),P),N=o.getRotatePoints(T,new o.Vec2d(g,w),-(I||0)),R=o.getRectFromPoints(N);u.opt.width=Math.round(R.w),u.opt.height=Math.round(R.h);const D=[h[0]/f.worldScaling[0],h[1]/f.worldScaling[1]];u.opt.centerX=g+D[0],u.opt.centerY=w+D[1];const b=[u.centerPos[0]+D[0],u.centerPos[1]+D[1]];if(u.centerPos=b,r){let O=o.getRectScaleed(u.rect,l);O=o.getRectTranslated(O,D),u.rect=O}}else if(n){const g=[n[0]/f.worldScaling[0],n[1]/f.worldScaling[1]];if(u.opt.centerX=u.opt.centerX+g[0],u.opt.centerY=u.opt.centerY+g[1],u.centerPos=[u.centerPos[0]+g[0],u.centerPos[1]+g[1]],r){const w=o.getRectTranslated(u.rect,g);u.rect=w}}else if(o.isNumber(p)&&(u.opt.rotate=p,u.scaleType=$.getScaleType(u.opt),r)){const g=o.getRectRotated(u.rect,p);u.rect=g}return u&&i.setInfo(e.name,u),u==null?void 0:u.rect}}}class ie extends E{constructor(t){super(t);m(this,"canRotate",!1);m(this,"scaleType",o.EScaleType.both);m(this,"toolsType",o.EToolsKey.Straight);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"straightTipWidth");m(this,"syncTimestamp");this.workOptions=t.toolsOpt,this.straightTipWidth=this.workOptions.thickness/2,this.syncTimestamp=0,this.syncUnitTime=50}consume(t){var u;const{data:e,isFullWork:s,isSubWorker:i,isMainThread:r}=t,n=(u=e==null?void 0:e.workId)==null?void 0:u.toString();if(!n)return{type:o.EPostMessageType.None};const{op:c,workState:l}=e,h=c==null?void 0:c.length;if(!h||h<2)return{type:o.EPostMessageType.None};let p;if(l===o.EvevtWorkState.Start?(this.tmpPoints=[new o.Point2d(c[0],c[1])],p=!1):p=this.updateTempPoints(c),!p)return{type:o.EPostMessageType.None};let d;if(i||r){const f=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:f})}if(!i){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n,op:this.tmpPoints.map(g=>[...g.XY,0]).flat(1),isSync:!0,index:0}):{type:o.EPostMessageType.None}}const y=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:y,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:n}}consumeAll(t){var l,h;const{data:e}=t,s=(l=e==null?void 0:e.workId)==null?void 0:l.toString();if(!s)return{type:o.EPostMessageType.None};if(this.tmpPoints.length<2)return{type:o.EPostMessageType.RemoveNode,removeIds:[s]};const i=this.fullLayer,r=this.draw({workId:s,layer:i});this.oldRect=r;const n=this.tmpPoints.map(p=>[...p.XY,0]).flat(1),c=o.transformToSerializableData(n);return(h=this.vNodes)==null||h.setInfo(s,{rect:r,op:n,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:r&&E.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s}=t,{strokeColor:i,thickness:r,zIndex:n,scale:c,rotate:l,translate:h}=this.workOptions,p=s.worldPosition,d=s.worldScaling,{d:y,rect:u}=this.computDrawPoints(r),f=[u.x+u.w/2,u.y+u.h/2],g={pos:f,name:e,id:e,d:y,fillColor:i,strokeColor:i,lineWidth:0,className:`${f[0]},${f[1]}`,normalize:!0,zIndex:n};c&&(g.scale=c),l&&(g.rotate=l),h&&(g.translate=h);const w=new x.Path(g);if(this.replace(s,e,w),l||c||h){const k=w.getBoundingClientRect();return{x:Math.floor(k.x-E.SafeBorderPadding),y:Math.floor(k.y-E.SafeBorderPadding),w:Math.floor(k.width+E.SafeBorderPadding*2),h:Math.floor(k.height+E.SafeBorderPadding*2)}}return{x:Math.floor(u.x*d[0]+p[0]-E.SafeBorderPadding),y:Math.floor(u.y*d[1]+p[1]-E.SafeBorderPadding),w:Math.floor(u.w*d[0]+2*E.SafeBorderPadding),h:Math.floor(u.h*d[1]+2*E.SafeBorderPadding)}}computDrawPoints(t){return this.tmpPoints[1].distance(this.tmpPoints[0])>this.straightTipWidth?this.computFullPoints(t):this.computDotPoints(t)}computFullPoints(t){const e=o.Vec2d.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),s=o.Vec2d.Per(e).mul(t/2),i=o.Point2d.Sub(this.tmpPoints[0],s),r=o.Point2d.Add(this.tmpPoints[0],s),n=o.Point2d.Sub(this.tmpPoints[1],s),c=o.Point2d.Add(this.tmpPoints[1],s),l=o.Point2d.GetSemicircleStroke(this.tmpPoints[1],n,-1,8),h=o.Point2d.GetSemicircleStroke(this.tmpPoints[0],r,-1,8),p=[i,n,...l,c,r,...h];return{d:X(p,!0),rect:o.getRectFromPoints(p),isDot:!1,pos:this.tmpPoints[0].XY}}computDotPoints(t){const e=o.Point2d.GetDotStroke(this.tmpPoints[0],t/2,8);return{d:X(e,!0),rect:o.getRectFromPoints(e),isDot:!0,pos:this.tmpPoints[0].XY}}updateTempPoints(t){const e=t.slice(-2),s=new o.Point2d(e[0],e[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(s,r))return!1;if(this.tmpPoints.length===2){if(s.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=s}else this.tmpPoints.push(s);return!0}consumeService(t){var c,l;const{op:e,isFullWork:s}=t,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<e.length;h+=3)this.tmpPoints.push(new o.Point2d(e[h],e[h+1],e[h+2]));const r=s?this.fullLayer:this.drawLayer||this.fullLayer,n=this.draw({workId:i,layer:r});return this.oldRect=n,(l=this.vNodes)==null||l.setInfo(i,{rect:n,op:e,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&E.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(t){var c;const{node:e,opt:s,vNodes:i}=t,{strokeColor:r}=s,n=i.get(e.name);return r&&(e.setAttribute("strokeColor",r),e.setAttribute("fillColor",r),(c=n==null?void 0:n.opt)!=null&&c.strokeColor&&(n.opt.strokeColor=r)),n&&i.setInfo(e.name,n),E.updateNodeOpt(t)}}class Y extends E{constructor(t){super(t);m(this,"canRotate",!1);m(this,"scaleType",o.EScaleType.all);m(this,"toolsType",o.EToolsKey.Text);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");this.workOptions=t.toolsOpt}consume(){return{type:o.EPostMessageType.None}}consumeAll(){return{type:o.EPostMessageType.None}}consumeService(){}async draw(t){const{workId:e,layer:s,isDrawLabel:i}=t,{boxSize:r,boxPoint:n,zIndex:c}=this.workOptions,l=s.worldPosition,h=s.worldScaling;if(!n||!r)return;const p={name:e,id:e,pos:[n[0]+r[0]/2,n[1]+r[1]/2],anchor:[.5,.5],size:r,zIndex:c},d=new x.Group(p),y={x:n[0],y:n[1],w:r[0],h:r[1]},u=new x.Rect({normalize:!0,pos:[0,0],size:r}),f=i&&Y.createLabels(this.workOptions,s)||[];return d.append(...f,u),this.replace(s,e,d),i&&(await new Promise(g=>{setTimeout(g,0)}),this.updateLabelsWidth(d)),{x:Math.floor(y.x*h[0]+l[0]),y:Math.floor(y.y*h[1]+l[1]),w:Math.floor(y.w*h[0]),h:Math.floor(y.h*h[1])}}async consumeServiceAsync(t){var l,h,p,d;const e=(l=this.workId)==null?void 0:l.toString();if(!e)return;const{isFullWork:s,replaceId:i,isDrawLabel:r}=t;this.oldRect=i&&((p=(h=this.vNodes)==null?void 0:h.get(i))==null?void 0:p.rect)||void 0;const n=s?this.fullLayer:this.drawLayer||this.fullLayer,c=await this.draw({workId:e,layer:n,isDrawLabel:r||this.workOptions.workState===o.EvevtWorkState.Done});return(d=this.vNodes)==null||d.setInfo(e,{rect:c,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:c&&E.getCenterPos(c,n)}),c}updateLabelsWidth(t){t.children.forEach(e=>{if(e.tagName==="LABEL"){const s=e.name,{width:i}=e.getBoundingClientRect(),[r]=t.worldScaling,{underline:n,lineThrough:c}=this.getWorkOptions();n&&t.getElementsByName(`${s}_underline`)[0].attr({points:[0,0,i/r,0]}),c&&t.getElementsByName(`${s}_lineThrough`)[0].attr({points:[0,0,i/r,0]})}})}updataOptService(){}async updataOptServiceAsync(t){var y,u;if(!this.workId)return;const e=this.workId.toString(),{fontColor:s,fontBgColor:i,bold:r,italic:n,lineThrough:c,underline:l,zIndex:h}=t,p=(y=this.vNodes)==null?void 0:y.get(e);if(!p)return;s&&(p.opt.fontColor=s),i&&(p.opt.fontBgColor=i),r&&(p.opt.bold=r),n&&(p.opt.italic=n),o.isBoolean(c)&&(p.opt.lineThrough=c),o.isBoolean(l)&&(p.opt.underline=l),i&&(p.opt.fontBgColor=i),o.isNumber(h)&&(p.opt.zIndex=h),this.oldRect=p.rect;const d=await this.draw({workId:e,layer:this.fullLayer,isDrawLabel:this.workOptions.workState===o.EvevtWorkState.Done});return(u=this.vNodes)==null||u.setInfo(e,{rect:d,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:d&&E.getCenterPos(d,this.fullLayer)}),d}clearTmpPoints(){this.tmpPoints.length=0}static getFontWidth(t){const{ctx:e,opt:s,text:i}=t,{bold:r,italic:n,fontSize:c,fontFamily:l}=s;return e.font=`${r} ${n} ${c}px ${l}`,e.measureText(i).width}static createLabels(t,e){const s=[],i=t.text.split(","),r=i.length;for(let n=0;n<r;n++){const c=i[n],{fontSize:l,lineHeight:h,bold:p,textAlign:d,italic:y,boxSize:u,fontFamily:f,verticalAlign:g,fontColor:w,underline:W,lineThrough:k}=t,S=h||l*1.2,I=e&&e.parent.canvas.getContext("2d"),v=I&&Y.getFontWidth({text:c,opt:t,ctx:I,worldScaling:e.worldScaling});if(v){const P={anchor:[0,.5],text:c,fontSize:l,lineHeight:S,fontFamily:f,fontWeight:p,fillColor:w,textAlign:d,fontStyle:y,name:n.toString(),className:"label"},L=[0,0];if(g==="middle"){const N=(r-1)/2;L[1]=(n-N)*S}if(d==="left"){const N=u&&-u[0]/2||0;L[0]=y==="italic"&&N||N+5,console.log("text-left",L)}P.pos=L;const T=new x.Label(P);if(s.push(T),W){const N={normalize:!1,pos:[P.pos[0],P.pos[1]+l/2],lineWidth:Math.floor(l/10),points:[0,0,v,0],strokeColor:w,name:`${n}_underline`,className:"underline"},R=new x.Polyline(N);s.push(R)}if(k){const N={normalize:!1,pos:P.pos,lineWidth:Math.floor(l/10),points:[0,0,v,0],strokeColor:w,name:`${n}_lineThrough`,className:"lineThrough"},R=new x.Polyline(N);s.push(R)}}}return s}static updateNodeOpt(t){const{node:e,opt:s,vNodes:i,targetNode:r}=t,{fontBgColor:n,fontColor:c,translate:l,box:h,boxScale:p,boxTranslate:d,bold:y,italic:u,lineThrough:f,underline:g,fontSize:w,textInfos:W,zIndex:k}=s,S=r&&o.cloneDeep(r)||i.get(e.name);if(!S)return;const I=e.parent;if(!I)return;const v=S.opt;if(o.isNumber(k)&&(e.setAttribute("zIndex",k),S.opt.zIndex=k),c&&v.fontColor&&(v.fontColor=c,e.children.forEach(P=>{P.tagName==="LABEL"?P.setAttribute("fillColor",c):P.tagName==="POLYLINE"&&P.setAttribute("strokeColor",c)})),n&&v.fontBgColor&&(v.fontBgColor=n),y&&(v.bold=y),u&&(v.italic=u),o.isBoolean(f)&&(v.lineThrough=f),o.isBoolean(g)&&(v.underline=g),w&&(v.fontSize=w),h&&d&&p){const P=W==null?void 0:W.get(e.name);if(P){const{fontSize:N,boxSize:R}=P;v.boxSize=R||v.boxSize,v.fontSize=N||v.fontSize}const L=S.rect,T=o.getRectTranslated(o.getRectScaleed(L,p),d);v.boxPoint=T&&[(T.x-I.worldPosition[0])/I.worldScaling[0],(T.y-I.worldPosition[1])/I.worldScaling[1]]}else if(l&&v.boxPoint){const P=[l[0]/I.worldScaling[0],l[1]/I.worldScaling[1]];v.boxPoint=[v.boxPoint[0]+P[0],v.boxPoint[1]+P[1]],S.centerPos=[S.centerPos[0]+P[0],S.centerPos[1]+P[1]],S.rect=o.getRectTranslated(S.rect,P)}return S&&i.setInfo(e.name,S),S==null?void 0:S.rect}static getRectFromLayer(t,e){const s=t.getElementsByName(e)[0];if(s){const i=s.getBoundingClientRect();return{x:Math.floor(i.x),y:Math.floor(i.y),w:Math.floor(i.width),h:Math.floor(i.height)}}}}function re(M){switch(M){case o.EToolsKey.Arrow:return J;case o.EToolsKey.Pencil:return j;case o.EToolsKey.Straight:return ie;case o.EToolsKey.Ellipse:return Q;case o.EToolsKey.Polygon:case o.EToolsKey.Triangle:return oe;case o.EToolsKey.Star:case o.EToolsKey.Rhombus:return te;case o.EToolsKey.Rectangle:return ee;case o.EToolsKey.SpeechBalloon:return se;case o.EToolsKey.Text:return Y;case o.EToolsKey.LaserPen:return Z;case o.EToolsKey.Eraser:return q;case o.EToolsKey.Selector:return C;case o.EToolsKey.Image:return $}}function _(M,a){const{toolsType:t,...e}=M;switch(t){case o.EToolsKey.Arrow:return new J(e);case o.EToolsKey.Pencil:return new j(e);case o.EToolsKey.Straight:return new ie(e);case o.EToolsKey.Ellipse:return new Q(e);case o.EToolsKey.Polygon:case o.EToolsKey.Triangle:return new oe(e);case o.EToolsKey.Star:case o.EToolsKey.Rhombus:return new te(e);case o.EToolsKey.Rectangle:return new ee(e);case o.EToolsKey.SpeechBalloon:return new se(e);case o.EToolsKey.Text:return new Y(e);case o.EToolsKey.LaserPen:return new Z(e);case o.EToolsKey.Eraser:return new q(e,a);case o.EToolsKey.Selector:return e.vNodes?new C({...e,vNodes:e.vNodes,drawLayer:e.fullLayer}):void 0;case o.EToolsKey.Image:return new $(e);default:return}}function ne(M){const a=[],t=["PATH","SPRITE","POLYLINE","RECT","ELLIPSE"];for(const e of M){if(e.tagName==="GROUP"&&e.children.length)return ne(e.children);e.tagName&&t.includes(e.tagName)&&a.push(e)}return a}const he=M=>{if(M.tagName==="GROUP"){const a=Object.getOwnPropertySymbols(M).find(t=>t.toString()==="Symbol(sealed)");if(a&&M[a])return!0}return!1},pe=M=>!M.isHid,H="cursorhover";class de{constructor(a,t){m(this,"viewId");m(this,"scene");m(this,"fullLayer");m(this,"curNodeMap",new Map);m(this,"targetNodeMap",[]);this.viewId=a,this.scene=t}init(a){this.fullLayer=a}get(a){return this.curNodeMap.get(a)}hasRenderNodes(){let a=!1;for(const t of this.curNodeMap.values())pe(t)&&(a=!0);return a}has(a){this.curNodeMap.has(a)}setInfo(a,t){const e=this.curNodeMap.get(a)||{name:a,rect:t.rect};t.rect&&(e.rect=o.cloneDeep(t.rect)),t.op&&(e.op=o.cloneDeep(t.op)),t.canRotate&&(e.canRotate=t.canRotate),t.scaleType&&(e.scaleType=t.scaleType),t.opt&&(e.opt=o.cloneDeep(t.opt)),t.toolsType&&(e.toolsType=t.toolsType),t.centerPos&&(e.centerPos=o.cloneDeep(t.centerPos)),o.isBoolean(t.isSelected)&&(e.isSelected=t.isSelected),e.rect?this.curNodeMap.set(a,e):this.curNodeMap.delete(a)}selected(a){this.setInfo(a,{isSelected:!0})}unSelected(a){this.setInfo(a,{isSelected:!1})}delete(a){this.curNodeMap.delete(a)}clear(){this.curNodeMap.clear(),this.targetNodeMap.length=0}hasRectIntersectRange(a,t=!0){for(const e of this.curNodeMap.values())if(o.isIntersect(a,e.rect)){if(t&&e.toolsType===o.EToolsKey.Image&&e.opt.locked||t&&e.toolsType===o.EToolsKey.Text&&(e.opt.workState===o.EvevtWorkState.Doing||e.opt.workState===o.EvevtWorkState.Start))continue;return!0}return!1}getRectIntersectRange(a,t=!0){let e;const s=new Map;for(const[i,r]of this.curNodeMap.entries())if(o.isIntersect(a,r.rect)){if(t&&r.toolsType===o.EToolsKey.Image&&r.opt.locked||t&&r.toolsType===o.EToolsKey.Text&&(r.opt.workState===o.EvevtWorkState.Doing||r.opt.workState===o.EvevtWorkState.Start))continue;e=o.computRect(e,r.rect),s.set(i,r)}return{rectRange:e,nodeRange:s}}getNodeRectFormShape(a,t){const e=re(t.toolsType);return this.fullLayer&&(e==null?void 0:e.getRectFromLayer(this.fullLayer,a))}updateNodesRect(){this.curNodeMap.forEach((a,t)=>{const e=this.getNodeRectFormShape(t,a);e?(a.rect=e,this.curNodeMap.set(t,a)):this.curNodeMap.delete(t)})}combineIntersectRect(a){let t=a;return this.curNodeMap.forEach(e=>{o.isIntersect(t,e.rect)&&(t=o.computRect(t,e.rect))}),t}setTarget(){return this.targetNodeMap.push(o.cloneDeep(this.curNodeMap)),this.targetNodeMap.length-1}getLastTarget(){return this.targetNodeMap[this.targetNodeMap.length-1]}deleteLastTarget(){this.targetNodeMap.length=this.targetNodeMap.length-1}getTarget(a){return this.targetNodeMap[a]}deleteTarget(a){this.targetNodeMap.length=a}}class ue{constructor(a){m(this,"vNodes");m(this,"thread");m(this,"serviceWorkShapes",new Map);m(this,"localWorkShapes",new Map);m(this,"tmpOpt");m(this,"tmpWorkShapeNode");m(this,"animationId");this.vNodes=a.vNodes,this.thread=a.thread}destroy(){this.clearAll()}clearAll(){this.thread.topLayer.children.length&&(this.thread.topLayer.parent.children.forEach(a=>{a.name!=="viewport"&&a.remove()}),this.thread.serviceLayer.removeAllChildren()),this.serviceWorkShapes.clear(),this.localWorkShapes.clear()}consumeDraw(a){const{workId:t,dataType:e}=a;if(e===o.EDataType.Service)this.activeServiceWorkShape(a);else{const s=this.localWorkShapes.get(t);if(!s)return;const i=s.node.consume({data:a,isFullWork:!1,isSubWorker:!0});i.rect&&(s.result=i,s.workState=o.EvevtWorkState.Doing,t&&this.localWorkShapes.set(t,s))}this.runAnimation()}setToolsOpt(a){this.tmpOpt=a,this.tmpWorkShapeNode=this.createWorkShapeNode(a)}createWorkShapeNode(a){const{toolsType:t}=a;if(t===o.EToolsKey.LaserPen)return _({...a,vNodes:this.vNodes,fullLayer:this.thread.topLayer,drawLayer:this.thread.topLayer})}getTmpWorkShapeNode(){return this.tmpWorkShapeNode}setTmpWorkId(a){if(a&&this.tmpWorkShapeNode){this.tmpWorkShapeNode.setWorkId(a),this.localWorkShapes.set(a,{node:this.tmpWorkShapeNode,toolsType:this.tmpWorkShapeNode.toolsType,workState:o.EvevtWorkState.Start}),this.tmpOpt&&this.setToolsOpt(this.tmpOpt);return}}setNodeKey(a,t,e){return a.toolsType=t,a.node=this.createWorkShapeNode({toolsType:t,toolsOpt:e}),a}activeServiceWorkShape(a){var d,y;const{workId:t,opt:e,toolsType:s,type:i,updateNodeOpt:r,ops:n,op:c}=a;if(!t)return;const l=t.toString(),h=(d=this.vNodes.get(l))==null?void 0:d.rect;if(!((y=this.serviceWorkShapes)!=null&&y.has(l))){let u={toolsType:s,animationWorkData:c||[],animationIndex:0,type:i,updateNodeOpt:r,ops:n,oldRect:h};s&&e&&(u=this.setNodeKey(u,s,e)),this.serviceWorkShapes.set(l,u)}const p=this.serviceWorkShapes.get(l);i&&(p.type=i),n&&(p.animationWorkData=o.transformToNormalData(n),p.ops=n),r&&(p.updateNodeOpt=r),c&&(p.animationWorkData=c),p.node&&p.node.getWorkId()!==l&&p.node.setWorkId(l),h&&(p.oldRect=h),s&&e&&(p.toolsType!==s&&s&&e&&this.setNodeKey(p,s,e),p.node&&p.node.setWorkOptions(e))}computNextAnimationIndex(a,t){var s;const e=Math.floor((a.animationWorkData||[]).slice(a.animationIndex).length*32/t/(((s=a.node)==null?void 0:s.syncUnitTime)||1e3))*t;return Math.min((a.animationIndex||0)+(e||t),(a.animationWorkData||[]).length)}animationDraw(){var s,i,r,n;this.animationId=void 0;let a=!1;const t=new Map,e=[];for(const[c,l]of this.serviceWorkShapes.entries())switch(l.toolsType){case o.EToolsKey.LaserPen:{const p=this.computNextAnimationIndex(l,8),d=Math.max(0,l.animationIndex||0),y=(l.animationWorkData||[]).slice(d,p);if((l.animationIndex||0)<p&&((s=l.node)==null||s.consumeService({op:y,isFullWork:!1}),l.animationIndex=p,y.length&&t.set(c,{workState:d===0?o.EvevtWorkState.Start:p===((i=l.animationWorkData)==null?void 0:i.length)?o.EvevtWorkState.Done:o.EvevtWorkState.Doing,op:y.slice(-2)})),l.isDel){(r=l.node)==null||r.clearTmpPoints(),this.serviceWorkShapes.delete(c);break}l.ops&&l.animationIndex===((n=l.animationWorkData)==null?void 0:n.length)&&!l.isDel&&(this.thread.topLayer.getElementsByName(c.toString())[0]||(l.isDel=!0,this.serviceWorkShapes.set(c,l))),a=!0;break}}for(const[c,l]of this.localWorkShapes.entries()){const{result:h,toolsType:p,isDel:d,workState:y}=l;switch(p){case o.EToolsKey.LaserPen:{if(d){l.node.clearTmpPoints(),this.localWorkShapes.delete(c),e.push({removeIds:[c.toString()],type:o.EPostMessageType.RemoveNode});break}h&&((h.op||h.ops)&&e.push(h),l.result=void 0),!this.thread.topLayer.getElementsByName(c.toString())[0]&&y===o.EvevtWorkState.Done&&(l.isDel=!0,this.localWorkShapes.set(c,l)),a=!0;break}}}a&&this.runAnimation(),t.size&&t.forEach((c,l)=>{e.push({type:o.EPostMessageType.Cursor,uid:l.split(o.Storage_Splitter)[0],op:c.op,workState:c.workState,viewId:this.thread.viewId})}),e.length&&this.thread.post({sp:e})}runAnimation(){this.animationId||(this.animationId=requestAnimationFrame(this.animationDraw.bind(this)))}setWorkOptions(a,t){var s,i,r;((s=this.localWorkShapes.get(a))==null?void 0:s.node)||this.setTmpWorkId(a),(r=(i=this.localWorkShapes.get(a))==null?void 0:i.node)==null||r.setWorkOptions(t)}consumeDrawAll(a){const{workId:t,dataType:e}=a;if(e===o.EDataType.Service)this.activeServiceWorkShape(a);else{const s=this.localWorkShapes.get(t);if(!s)return;const i=s.node.consumeAll({data:a});s.result=i,s.workState=o.EvevtWorkState.Done,t&&this.localWorkShapes.set(t,s)}this.runAnimation()}}class fe{constructor(a){m(this,"vNodes");m(this,"thread");m(this,"workShapes",new Map);m(this,"effectSelectNodeData",new Set);m(this,"batchEraserRemoveNodes",new Set);m(this,"batchEraserWorks",new Set);m(this,"tmpOpt");m(this,"tmpWorkShapeNode");m(this,"drawCount",0);m(this,"batchEraserCombine",o.throttle(()=>{this.updateBatchEraserCombineNode(this.batchEraserWorks,this.batchEraserRemoveNodes),this.batchEraserWorks.clear(),this.batchEraserRemoveNodes.clear()},100,{leading:!1}));this.vNodes=a.vNodes,this.thread=a.thread}async updateSelector(a){var d;const t=this.workShapes.get(o.Storage_Selector_key);if(!((d=t==null?void 0:t.selectIds)!=null&&d.length))return;const{callback:e,...s}=a,{updateSelectorOpt:i,willSerializeData:r,scene:n}=s,c=await(t==null?void 0:t.updateSelector({updateSelectorOpt:i,selectIds:t.selectIds,vNodes:this.vNodes,willSerializeData:r,worker:this,scene:n,isMainThread:!0})),l=new Map;t.selectIds.forEach(y=>{const u=this.vNodes.get(y);if(u){const{toolsType:f,op:g,opt:w}=u;l.set(y,{opt:w,toolsType:f,ops:(g==null?void 0:g.length)&&o.transformToSerializableData(g)||void 0})}});const h=[],p=e&&e({res:c,workShapeNode:t,param:s,postData:{sp:h},newServiceStore:l})||{sp:h};p.sp.length&&this.thread.post(p)}destroy(){this.clearAll()}clearAllWorkShapesCache(){this.workShapes.forEach(a=>a.clearTmpPoints()),this.workShapes.clear()}clearAll(){if(this.thread.localLayer.children.length&&(this.thread.topLayer.parent.children.forEach(t=>{t.name!=="viewport"&&t.remove()}),this.thread.localLayer.removeAllChildren()),this.workShapes.get(o.Storage_Selector_key)){const t=[];t.push({type:o.EPostMessageType.Select,dataType:o.EDataType.Local,selectIds:[],willSyncService:!1}),this.thread.post({sp:t})}this.workShapes.clear(),this.effectSelectNodeData.clear(),this.batchEraserWorks.clear(),this.batchEraserRemoveNodes.clear()}async checkTextActive(a){const{op:t,viewId:e,dataType:s}=a;if(t!=null&&t.length){let i;for(const r of this.vNodes.curNodeMap.values()){const{rect:n,name:c,toolsType:l,opt:h}=r,p=t[0]*this.thread.fullLayer.worldScaling[0]+this.thread.fullLayer.worldPosition[0],d=t[1]*this.thread.fullLayer.worldScaling[1]+this.thread.fullLayer.worldPosition[1];if(l===o.EToolsKey.Text&&o.isIntersectForPoint([p,d],n)&&h.workState===o.EvevtWorkState.Done){i=c;break}}i&&(await this.blurSelector({viewId:e,msgType:o.EPostMessageType.Select,dataType:s,isSync:!0}),this.thread.post({sp:[{type:o.EPostMessageType.GetTextActive,toolsType:o.EToolsKey.Text,workId:i}]}))}}cursorHover(a){const{opt:t,toolsType:e,point:s}=a,i=this.setFullWork({workId:H,toolsType:e,opt:t});i&&s&&i.cursorHover(s)}updateFullSelectWork(a){var s,i,r,n,c;const t=this.workShapes.get(o.Storage_Selector_key),{selectIds:e}=a;if(!(e!=null&&e.length)){this.blurSelector(a);return}if(!t){!this.setFullWork(a)&&a.workId&&((s=this.tmpWorkShapeNode)==null?void 0:s.toolsType)===o.EToolsKey.Selector&&this.setTmpWorkId(a.workId),this.updateFullSelectWork(a);return}if(t&&(e!=null&&e.length)){const{selectRect:l}=t.updateSelectIds(e),h=[{...a,selectorColor:((i=a.opt)==null?void 0:i.strokeColor)||t.selectorColor,strokeColor:((r=a.opt)==null?void 0:r.strokeColor)||t.strokeColor,fillColor:((n=a.opt)==null?void 0:n.fillColor)||t.fillColor,textOpt:((c=a.opt)==null?void 0:c.textOpt)||t.textOpt,canTextEdit:t.canTextEdit,canRotate:t.canRotate,scaleType:t.scaleType,type:o.EPostMessageType.Select,selectRect:l,points:t.getChildrenPoints(),willSyncService:(a==null?void 0:a.willSyncService)||!1,opt:(a==null?void 0:a.willSyncService)&&t.getWorkOptions()||void 0,canLock:t.canLock,isLocked:t.isLocked,toolsTypes:t.toolsTypes,shapeOpt:t.shapeOpt}];this.thread.post({sp:h})}}removeWork(a){const{workId:t}=a,e=t==null?void 0:t.toString();e&&this.removeNode(e)}removeNode(a){var e;this.workShapes.has(a)&&this.clearWorkShapeNodeCache(a),this.vNodes.get(a)&&(this.thread.fullLayer.getElementsByName(a).concat(((e=this.thread.localLayer)==null?void 0:e.getElementsByName(a))||[]).forEach(s=>{s.remove()}),this.vNodes.delete(a))}setFullWork(a){const{workId:t,opt:e,toolsType:s}=a;if(t&&e&&s){const i=t&&this.workShapes.get(t)||this.createWorkShapeNode({toolsOpt:e,toolsType:s,workId:t});return i?(i.setWorkId(t),this.workShapes.set(t,i),i):void 0}}async consumeFull(a,t){var i;const e=this.setFullWork(a),s=a.ops&&o.transformToNormalData(a.ops);if(e){const r=(i=a.workId)==null?void 0:i.toString();e.toolsType===o.EToolsKey.Image&&t?await e.consumeServiceAsync({scene:t,isFullWork:!0,replaceId:r,isMainThread:!0}):e.toolsType===o.EToolsKey.Text?await e.consumeServiceAsync({isFullWork:!0,replaceId:r}):e.consumeService({op:s,isFullWork:!0,replaceId:r}),a!=null&&a.updateNodeOpt&&e.updataOptService(a.updateNodeOpt);const n=[];a.workId&&this.workShapes.delete(a.workId),a.willSyncService&&n.push({opt:a.opt,toolsType:a.toolsType,type:o.EPostMessageType.FullWork,workId:a.workId,ops:a.ops,updateNodeOpt:a.updateNodeOpt,viewId:this.thread.viewId}),n.length&&this.thread.post({sp:n})}}async colloctEffectSelectWork(a){const t=this.workShapes.get(o.Storage_Selector_key),{workId:e,msgType:s}=a;if(t&&e&&t.selectIds&&t.selectIds.includes(e.toString())){s===o.EPostMessageType.RemoveNode?t.selectIds=t.selectIds.filter(i=>i!==e.toString()):this.effectSelectNodeData.add(a),await new Promise(i=>{setTimeout(()=>{i(!0)},0)}),await this.runEffectSelectWork(!0).then(()=>{var i;(i=this.effectSelectNodeData)==null||i.clear()});return}return a}async runEffectSelectWork(a){var t,e,s;for(const i of this.effectSelectNodeData.values()){const r=this.setFullWork(i);if(r){const n=(t=i.workId)==null?void 0:t.toString();if(r.toolsType===o.EToolsKey.Image)await r.consumeServiceAsync({scene:(s=(e=this.thread.localLayer)==null?void 0:e.parent)==null?void 0:s.parent,isFullWork:!0,replaceId:n,isMainThread:!0});else if(r.toolsType===o.EToolsKey.Text)await r.consumeServiceAsync({isFullWork:!0,replaceId:n});else{const c=i.ops&&o.transformToNormalData(i.ops);r.consumeService({op:c,isFullWork:!0,replaceId:n}),i!=null&&i.updateNodeOpt&&r.updataOptService(i.updateNodeOpt)}i.workId&&this.workShapes.delete(i.workId)}}this.reRenderSelector(a)}reRenderSelector(a=!1){var s;const t=this.workShapes.get(o.Storage_Selector_key);if(!t)return;if(t&&!((s=t.selectIds)!=null&&s.length))return this.blurSelector();const e=t.reRenderSelector();e&&this.thread.post({sp:[{type:o.EPostMessageType.Select,selectIds:t.selectIds,selectRect:e,willSyncService:a,viewId:this.thread.viewId,points:t.getChildrenPoints(),textOpt:t.textOpt,selectorColor:t.selectorColor,strokeColor:t.strokeColor,fillColor:t.fillColor,canTextEdit:t.canTextEdit,canRotate:t.canRotate,scaleType:t.scaleType,opt:t.getWorkOptions()||void 0,canLock:t.canLock,isLocked:t.isLocked,toolsTypes:t.toolsTypes,shapeOpt:t.shapeOpt}]})}async blurSelector(a){var s;const t=this.workShapes.get(o.Storage_Selector_key),e=t==null?void 0:t.blurSelector();if(this.clearWorkShapeNodeCache(o.Storage_Selector_key),((s=this.thread.fullLayer)==null?void 0:s.parent).children.forEach(i=>{i.name===o.Storage_Selector_key&&i.remove()}),e){const i=[];i.push({...e,isSync:a==null?void 0:a.isSync}),this.thread.post({sp:i})}}clearWorkShapeNodeCache(a){var t;(t=this.getWorkShape(a))==null||t.clearTmpPoints(),this.workShapes.delete(a)}drawEraser(a){var e,s;const t=[];if((e=a.newWorkDatas)!=null&&e.size){for(const i of a.newWorkDatas.values()){const r=i.workId.toString();this.batchEraserWorks.add(r),t.push({type:o.EPostMessageType.FullWork,workId:r,ops:o.transformToSerializableData(i.op),opt:i.opt,toolsType:i.toolsType,updateNodeOpt:{useAnimation:!1}})}delete a.newWorkDatas}(s=a.removeIds)==null||s.forEach(i=>{this.batchEraserRemoveNodes.add(i)}),console.log("first",a),t.push(a),this.thread.post({sp:t}),this.batchEraserCombine()}updateBatchEraserCombineNode(a,t){for(const e of t.keys())this.thread.fullLayer.getElementsByName(e).forEach(s=>{s.remove()});a.forEach(e=>{const s=this.vNodes.get(e);if(s&&s.toolsType===o.EToolsKey.Pencil&&!this.thread.fullLayer.getElementsByName(e)[0]){const r=this.setFullWork({...s,workId:e});r&&r.consumeService({op:s.op,isFullWork:!0})}})}getWorkShape(a){return this.workShapes.get(a)}consumeDraw(a,t){const{op:e,workId:s,scenePath:i}=a;if(e!=null&&e.length&&s){const r=this.workShapes.get(s);if(!r)return;const n=r.toolsType;if(n===o.EToolsKey.LaserPen)return;switch(n){case o.EToolsKey.Selector:{const c=r.consume({data:a,isFullWork:!0});c.type===o.EPostMessageType.Select&&(c.selectIds&&t.runReverseSelectWork(c.selectIds),this.thread.post({sp:[c]}))}break;case o.EToolsKey.Eraser:{const c=r.consume({data:a,isFullWork:!0});c!=null&&c.rect&&this.drawEraser(c)}break;case o.EToolsKey.Arrow:case o.EToolsKey.Straight:case o.EToolsKey.Ellipse:case o.EToolsKey.Rectangle:case o.EToolsKey.Star:case o.EToolsKey.Polygon:case o.EToolsKey.SpeechBalloon:case o.EToolsKey.Pencil:{const c=r.consume({data:a,isFullWork:!1,isMainThread:!0});c&&(this.drawCount++,this.thread.post({drawCount:this.drawCount,sp:c.op&&[{...c,scenePath:i}]||void 0}))}break}}}consumeDrawAll(a,t){var i,r,n;const{workId:e,scenePath:s}=a;if(e){const c=this.workShapes.get(e);if(!c)return;const l=c.toolsType;if(l===o.EToolsKey.LaserPen)return;const h=this.workShapes.get(H),p=(i=h==null?void 0:h.selectIds)==null?void 0:i[0],d=c.consumeAll({data:a});switch(l){case o.EToolsKey.Selector:d.selectIds&&p&&((r=d.selectIds)!=null&&r.includes(p))&&h.cursorBlur(),d.type===o.EPostMessageType.Select&&(d.selectIds&&t.runReverseSelectWork(d.selectIds),this.thread.post({sp:[{...d,scenePath:s}]})),(n=c.selectIds)!=null&&n.length?c.clearTmpPoints():this.clearWorkShapeNodeCache(e);break;case o.EToolsKey.Eraser:d!=null&&d.rect&&this.drawEraser({...d,scenePath:s}),c.clearTmpPoints();break;case o.EToolsKey.Arrow:case o.EToolsKey.Straight:case o.EToolsKey.Ellipse:case o.EToolsKey.Rectangle:case o.EToolsKey.Star:case o.EToolsKey.Polygon:case o.EToolsKey.SpeechBalloon:case o.EToolsKey.Pencil:d&&(this.drawCount=0,this.thread.post({drawCount:this.drawCount,sp:[d]})),this.clearWorkShapeNodeCache(e);break}}}getTmpWorkShapeNode(){return this.tmpWorkShapeNode}setToolsOpt(a){var e;const{toolsType:t}=a;(e=this.tmpOpt)!=null&&e.toolsType&&this.tmpOpt.toolsType!==t&&this.clearAllWorkShapesCache(),this.tmpOpt=a,this.tmpWorkShapeNode=this.createWorkShapeNode(a)}setTmpWorkId(a){if(a&&this.tmpWorkShapeNode){this.tmpWorkShapeNode.setWorkId(a),this.workShapes.set(a,this.tmpWorkShapeNode),this.tmpOpt&&this.setToolsOpt(this.tmpOpt);return}}setWorkOptions(a,t){var s;this.workShapes.get(a)||this.setTmpWorkId(a),(s=this.workShapes.get(a))==null||s.setWorkOptions(t)}createWorkShapeNode(a){return _({...a,vNodes:this.vNodes,fullLayer:this.thread.fullLayer,drawLayer:this.thread.localLayer},this.thread.serviceWork)}}class ye{constructor(a){m(this,"vNodes");m(this,"thread");m(this,"workShapes",new Map);m(this,"selectorWorkShapes",new Map);m(this,"willRunEffectSelectorIds",new Set);m(this,"runEffectId");m(this,"animationId");this.vNodes=a.vNodes,this.thread=a.thread}destroy(){this.clearAll()}clearAll(){this.thread.serviceLayer.children.length&&(this.thread.serviceLayer.parent.children.forEach(a=>{a.name!=="viewport"&&a.remove()}),this.thread.serviceLayer.removeAllChildren()),this.workShapes.clear(),this.selectorWorkShapes.clear(),this.willRunEffectSelectorIds.clear()}runEffect(){this.runEffectId||(this.runEffectId=setTimeout(this.effectRunSelector.bind(this),0))}effectRunSelector(){this.runEffectId=void 0,this.willRunEffectSelectorIds.forEach(a=>{var e,s;const t=this.selectorWorkShapes.get(a);t&&t.selectIds&&((e=t.node)==null||e.selectServiceNode(a,t,!0)),(s=t==null?void 0:t.selectIds)!=null&&s.length||this.selectorWorkShapes.delete(a)}),this.willRunEffectSelectorIds.clear()}runSelectWork(a){this.activeSelectorShape(a);const{workId:t}=a,e=t==null?void 0:t.toString();e&&this.willRunEffectSelectorIds.add(e),this.runEffect()}removeWork(a){const{workId:t}=a,e=t==null?void 0:t.toString();if(e){if(this.workShapes.get(e)){this.workShapes.delete(e),this.removeNode(e,a);return}this.removeNode(e,a)}}consumeFull(a){this.activeWorkShape(a),this.runAnimation()}runReverseSelectWork(a){a.forEach(t=>{this.selectorWorkShapes.forEach((e,s)=>{var i;if((i=e.selectIds)!=null&&i.length){const r=e.selectIds.indexOf(t);r>-1&&(e.selectIds.splice(r,1),this.willRunEffectSelectorIds.add(s))}})}),this.willRunEffectSelectorIds.size&&this.runEffect()}consumeDraw(a){this.activeWorkShape(a),this.runAnimation()}computNextAnimationIndex(a,t){var s;const e=Math.floor((a.animationWorkData||[]).slice(a.animationIndex).length*32/t/(((s=a.node)==null?void 0:s.syncUnitTime)||1e3))*t;return Math.min((a.animationIndex||0)+(e||t),(a.animationWorkData||[]).length)}async animationDraw(){var e,s,i,r,n,c,l,h,p,d,y,u,f,g,w,W;this.animationId=void 0;let a=!1;const t=new Map;for(const[k,S]of this.workShapes.entries())switch(S.toolsType){case o.EToolsKey.Image:{await((s=S.node)==null?void 0:s.consumeServiceAsync({isFullWork:!0,scene:(e=this.thread.fullLayer.parent)==null?void 0:e.parent,isMainThread:!0})),this.selectorWorkShapes.forEach((I,v)=>{var P;(P=I.selectIds)!=null&&P.includes(k)&&(this.willRunEffectSelectorIds.add(v),this.runEffect())}),this.workShapes.delete(k);break}case o.EToolsKey.Text:{S.node&&(await((i=S.node)==null?void 0:i.consumeServiceAsync({isFullWork:!0,replaceId:k})),this.selectorWorkShapes.forEach((I,v)=>{var P;(P=I.selectIds)!=null&&P.includes(k)&&(this.willRunEffectSelectorIds.add(v),this.runEffect())}),(r=S.node)==null||r.clearTmpPoints(),this.workShapes.delete(k));break}case o.EToolsKey.Arrow:case o.EToolsKey.Straight:case o.EToolsKey.Rectangle:case o.EToolsKey.Ellipse:case o.EToolsKey.Star:case o.EToolsKey.Polygon:case o.EToolsKey.SpeechBalloon:{const I=!!S.ops;if((n=S.animationWorkData)!=null&&n.length){const v=S.oldRect;(c=S.node)==null||c.consumeService({op:S.animationWorkData,isFullWork:I}),I&&(this.selectorWorkShapes.forEach((P,L)=>{var T;(T=P.selectIds)!=null&&T.includes(k)&&(this.willRunEffectSelectorIds.add(L),this.runEffect())}),(l=S.node)==null||l.clearTmpPoints(),this.workShapes.delete(k)),t.set(k,{workState:v?S.ops?o.EvevtWorkState.Done:o.EvevtWorkState.Doing:o.EvevtWorkState.Start,op:S.animationWorkData.filter((P,L)=>{if(L%3!==2)return!0}).slice(-2)}),S.animationWorkData.length=0}break}case o.EToolsKey.Pencil:{if(!S.useAnimation&&S.ops)(h=S.node)==null||h.consumeService({op:S.animationWorkData||[],isFullWork:!0,replaceId:k}),(p=S.node)==null||p.updataOptService(S.updateNodeOpt),this.selectorWorkShapes.forEach((I,v)=>{var P;(P=I.selectIds)!=null&&P.includes(k)&&(this.willRunEffectSelectorIds.add(v),this.runEffect())}),(d=S.node)==null||d.clearTmpPoints(),this.workShapes.delete(k);else if(S.useAnimation){if(S.isDel){(y=S.node)==null||y.clearTmpPoints(),this.workShapes.delete(k);break}const I=3,v=this.computNextAnimationIndex(S,I),P=S.isDiff?0:Math.max(0,(S.animationIndex||0)-I),L=(S.animationWorkData||[]).slice(P,v),T=(f=(u=S.node)==null?void 0:u.getWorkId())==null?void 0:f.toString();if((S.animationIndex||0)<v||S.isDiff){if((g=S.node)==null||g.consumeService({op:L,isFullWork:!1}),S.animationIndex=v,S.isDiff&&(S.isDiff=!1),L.length){const N=L.filter((R,D)=>{if(D%I!==I-1)return!0}).slice(-2);t.set(k,{workState:P===0?o.EvevtWorkState.Start:v===((w=S.animationWorkData)==null?void 0:w.length)?o.EvevtWorkState.Done:o.EvevtWorkState.Doing,op:N})}}else S.ops&&((W=S.node)==null||W.consumeService({op:S.animationWorkData||[],isFullWork:!0,replaceId:T}),S.isDel=!0,t.set(k,{workState:o.EvevtWorkState.Done,op:L.filter((N,R)=>{if(R%I!==I-1)return!0}).slice(-2)}));a=!0;break}break}}if(a&&this.runAnimation(),t.size){const k=[];t.forEach((S,I)=>{k.push({type:o.EPostMessageType.Cursor,uid:I.split(o.Storage_Splitter)[0],op:S.op,workState:S.workState,viewId:this.thread.viewId})}),this.thread.post({sp:k})}}runAnimation(){this.animationId||(this.animationId=requestAnimationFrame(this.animationDraw.bind(this)))}hasDiffData(a,t,e){const s=a.length;if(t.length<s)return!0;switch(e){case o.EToolsKey.Pencil:{for(let i=0;i<s;i+=3)if(t[i]!==a[i]||t[i+1]!==a[i+1])return!0;break}case o.EToolsKey.LaserPen:{for(let i=0;i<s;i+=2)if(t[i]!==a[i]||t[i+1]!==a[i+1])return!0;break}}return!1}activeWorkShape(a){var y,u,f,g;const{workId:t,opt:e,toolsType:s,type:i,updateNodeOpt:r,ops:n,op:c,useAnimation:l}=a;if(!t)return;const h=t.toString(),p=(y=this.vNodes.get(h))==null?void 0:y.rect;if(!((u=this.workShapes)!=null&&u.has(h))){let w={toolsType:s,animationWorkData:c||[],animationIndex:0,type:i,updateNodeOpt:r,ops:n,useAnimation:typeof l<"u"?l:typeof(r==null?void 0:r.useAnimation)<"u"?r==null?void 0:r.useAnimation:!0,oldRect:p,isDiff:!1};s&&e&&(w=this.setNodeKey(w,s,e)),(f=this.workShapes)==null||f.set(h,w)}const d=(g=this.workShapes)==null?void 0:g.get(h);i&&(d.type=i),n&&(d.animationWorkData=o.transformToNormalData(n),d.ops=n),r&&(d.updateNodeOpt=r),c&&(d.isDiff=this.hasDiffData(d.animationWorkData||[],c,d.toolsType),d.animationWorkData=c),d.node&&d.node.getWorkId()!==h&&d.node.setWorkId(h),p&&(d.oldRect=p),s&&e&&(d.toolsType!==s&&s&&e&&this.setNodeKey(d,s,e),d.node&&d.node.setWorkOptions(e))}removeNode(a,t){a.indexOf(o.Storage_Selector_key)>-1&&this.removeSelectWork(t),this.thread.fullLayer.getElementsByName(a).forEach(e=>{e.remove()}),this.thread.serviceLayer.getElementsByName(a).forEach(e=>{e.remove()}),this.vNodes.delete(a)}removeSelectWork(a){const{workId:t}=a,e=t==null?void 0:t.toString();e&&(this.activeSelectorShape(a),this.willRunEffectSelectorIds.add(e)),this.runEffect()}activeSelectorShape(a){var l,h,p;const{workId:t,opt:e,toolsType:s,type:i,selectIds:r}=a;if(!t)return;const n=t.toString();if(!((l=this.selectorWorkShapes)!=null&&l.has(n))){let d={toolsType:s,selectIds:r,type:i,opt:e};s&&e&&(d=this.setNodeKey(d,s,e)),(h=this.selectorWorkShapes)==null||h.set(n,d)}const c=(p=this.selectorWorkShapes)==null?void 0:p.get(n);i&&(c.type=i),c.node&&c.node.getWorkId()!==n&&c.node.setWorkId(n),c.selectIds=r||[]}setNodeKey(a,t,e){return a.toolsType=t,a.node=_({toolsType:t,toolsOpt:e,vNodes:this.vNodes,fullLayer:this.thread.fullLayer,drawLayer:this.thread.serviceLayer},this),a}}class z{constructor(){m(this,"localWork");m(this,"serviceWork");m(this,"scene")}registerMainThread(a,t,e){return this.localWork=a,this.serviceWork=t,this.scene=e,this}}class me extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.CopyNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.FullWork&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var s;const{workId:e}=t;e&&await((s=this.localWork)==null?void 0:s.consumeFull(t,this.scene))}}class ge extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.SetColorNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var l;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c}=t;e===C.selectorId&&s&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c,callback:this.updateSelectorCallback}))}updateSelectorCallback(t){const{param:e,postData:s,newServiceStore:i}=t,{willSyncService:r,isSync:n,textUpdateForWoker:c}=e,l=s.sp||[];if(r)for(const[h,p]of i.entries())c&&p.toolsType===o.EToolsKey.Text?l.push({...p,workId:h,type:o.EPostMessageType.TextUpdate,dataType:o.EDataType.Local,willSyncService:!0}):l.push({...p,workId:h,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:n});return{sp:l}}}class we extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.ZIndexNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var c;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n}=t;e===C.selectorId&&s&&await((c=this.localWork)==null?void 0:c.updateSelector({updateSelectorOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,callback:this.updateSelectorCallback}))}updateSelectorCallback(t){const{param:e,postData:s,newServiceStore:i}=t,{willSyncService:r,isSync:n}=e,c=s.sp||[];if(r&&c)for(const[l,h]of i.entries())c.push({...h,workId:l,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:n});return{sp:c}}}class Se extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.TranslateNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var h,p;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c,emitEventType:l}=t;e===C.selectorId&&s&&(s.workState===o.EvevtWorkState.Done&&(s!=null&&s.translate)&&(s.translate[0]||s.translate[1])||s.workState!==o.EvevtWorkState.Done?await((h=this.localWork)==null?void 0:h.updateSelector({updateSelectorOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,isSync:!0,textUpdateForWoker:c,emitEventType:l,scene:this.scene,callback:this.updateSelectorCallback})):s.workState===o.EvevtWorkState.Done&&((p=this.localWork)==null||p.vNodes.deleteLastTarget()))}updateSelectorCallback(t){const{param:e,postData:s,newServiceStore:i,workShapeNode:r,res:n}=t,{willSyncService:c,isSync:l,updateSelectorOpt:h,textUpdateForWoker:p}=e,d=h.workState,y=s.sp||[];if(d===o.EvevtWorkState.Start)return{sp:[],render:[]};const u=n==null?void 0:n.selectRect;if(c){d===o.EvevtWorkState.Doing&&y.push({type:o.EPostMessageType.Select,selectIds:r.selectIds,selectRect:u,willSyncService:!0,isSync:!0,points:r.getChildrenPoints(),textOpt:r.textOpt});for(const[f,g]of i.entries())p&&g.toolsType===o.EToolsKey.Text?y.push({...g,workId:f,type:o.EPostMessageType.TextUpdate,dataType:o.EDataType.Local,willSyncService:!0}):y.push({...g,workId:f,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l})}return{sp:y}}}class Te extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.DeleteNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.RemoveNode){if(s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0;if(s===o.EDataType.Service&&i===this.emitEventType)return this.consumeForServiceWorker(t),!0}}consumeForLocalWorker(t){if(!this.localWork)return;const{removeIds:e,willSyncService:s}=t;if(!(e!=null&&e.length))return;const i=[],r=[];for(const n of e){if(n===o.Storage_Selector_key){const l=this.localWork.workShapes.get(o.Storage_Selector_key);if(!l)return;const h=l.selectIds&&[...l.selectIds]||[];for(const p of h){if(this.localWork.vNodes.get(p)){const y=this.commandDeleteText(p);y&&i.push(y)}this.localWork.removeNode(p),r.push(p)}this.localWork.blurSelector();continue}const c=this.commandDeleteText(n);c&&i.push(c),this.localWork.removeNode(n),r.push(n)}s&&i.push({type:o.EPostMessageType.RemoveNode,removeIds:r}),i.length&&this.localWork.thread.post({sp:i})}consumeForServiceWorker(t){this.serviceWork&&this.serviceWork.removeWork(t)}commandDeleteText(t){var s;const e=(s=this.localWork)==null?void 0:s.vNodes.get(t);if(e&&e.toolsType===o.EToolsKey.Text)return{type:o.EPostMessageType.TextUpdate,toolsType:o.EToolsKey.Text,workId:t,dataType:o.EDataType.Local}}}class ke extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.ScaleNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var n;const{workId:e,updateNodeOpt:s,willSyncService:i,willSerializeData:r}=t;e===C.selectorId&&s&&await((n=this.localWork)==null?void 0:n.updateSelector({updateSelectorOpt:s,willSyncService:i,willSerializeData:r,isSync:!0,scene:this.scene,callback:this.updateSelectorCallback.bind(this)}))}updateSelectorCallback(t){const{param:e,postData:s,workShapeNode:i,res:r,newServiceStore:n}=t,{updateSelectorOpt:c,willSyncService:l,willSerializeData:h}=e,p=c.workState,d=s.sp||[],y=r==null?void 0:r.selectRect;if(p===o.EvevtWorkState.Start)return{sp:[],render:[]};if(l){p===o.EvevtWorkState.Doing&&d.push({type:o.EPostMessageType.Select,selectIds:i.selectIds,selectRect:y,willSyncService:!0,isSync:!0,points:i.getChildrenPoints(),textOpt:i.textOpt}),h&&p===o.EvevtWorkState.Done&&d.push({type:o.EPostMessageType.Select,selectIds:i.selectIds,selectRect:y,willSyncService:!1,isSync:!0,points:i.getChildrenPoints(),textOpt:i.textOpt});for(const[u,f]of n.entries())f.toolsType===o.EToolsKey.Text?d.push({...f,workId:u,type:o.EPostMessageType.TextUpdate,dataType:o.EDataType.Local,willSyncService:!0}):d.push({...f,workId:u,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:!0})}return{sp:d}}}class Pe extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.RotateNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var l;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,emitEventType:c}=t;e===C.selectorId&&s&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,emitEventType:c,isSync:!0,scene:this.scene,callback:this.updateSelectorCallback}))}updateSelectorCallback(t){const{param:e,postData:s,workShapeNode:i,res:r,newServiceStore:n}=t,{updateSelectorOpt:c,willSyncService:l,willSerializeData:h,isSync:p}=e,d=c.workState,y=s.sp||[],u=r==null?void 0:r.selectRect;if(l){h&&d===o.EvevtWorkState.Done&&y.push({type:o.EPostMessageType.Select,selectIds:i.selectIds,selectRect:u,willSyncService:!0,isSync:p,points:i.getChildrenPoints()});for(const[f,g]of n.entries())y.push({...g,workId:f,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:p})}return{sp:y}}}class ve extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.SetFontStyle)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var l;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c}=t;e===C.selectorId&&s&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c,callback:this.updateSelectorCallback}))}updateSelectorCallback(t){const{param:e,postData:s,newServiceStore:i,workShapeNode:r,res:n}=t,{willSyncService:c,isSync:l,updateSelectorOpt:h,textUpdateForWoker:p}=e,d=s.sp||[],y=n==null?void 0:n.selectRect;if(c&&d){h.fontSize&&d.push({type:o.EPostMessageType.Select,selectIds:r.selectIds,selectRect:y,willSyncService:c,isSync:l,points:r.getChildrenPoints()});for(const[u,f]of i.entries())p&&f.toolsType===o.EToolsKey.Text?d.push({...f,workId:u,type:o.EPostMessageType.TextUpdate,dataType:o.EDataType.Local,willSyncService:!0}):d.push({...f,workId:u,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l})}return{sp:d}}}class Ee extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.SetPoint)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var l;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c}=t;e===C.selectorId&&s&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:s,willRefreshSelector:i,willSyncService:r,emitEventType:this.emitEventType,willSerializeData:n,isSync:!0,textUpdateForWoker:c,callback:this.updateSelectorCallback}))}updateSelectorCallback(t){const{param:e,postData:s,newServiceStore:i,workShapeNode:r,res:n}=t,{willSyncService:c,isSync:l}=e,h=s.sp||[],p=n==null?void 0:n.selectRect;if(c&&h){for(const[d,y]of i.entries())h.push({...y,workId:d,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l});h.push({type:o.EPostMessageType.Select,selectIds:r.selectIds,selectRect:p,willSyncService:c,isSync:l,points:r.getChildrenPoints()})}return{sp:h}}}class Ie extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.SetLock)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var c;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n}=t;e===C.selectorId&&s&&await((c=this.localWork)==null?void 0:c.updateSelector({updateSelectorOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,callback:this.updateSelectorCallback}))}updateSelectorCallback(t){const{param:e,postData:s,newServiceStore:i,workShapeNode:r,res:n}=t,{willSyncService:c,isSync:l,updateSelectorOpt:h}=e,p=s.sp||[],d=n==null?void 0:n.selectRect;if(c&&p){for(const[y,u]of i.entries())p.push({...u,workId:y,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l});p.push({isLocked:h.isLocked,selectorColor:r.selectorColor,scaleType:r.scaleType,canRotate:r.canRotate,type:o.EPostMessageType.Select,selectIds:r.selectIds,selectRect:d,willSyncService:c,isSync:l})}return{sp:p}}}class Ne extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.SetShapeOpt)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var c;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n}=t;e===C.selectorId&&s&&await((c=this.localWork)==null?void 0:c.updateSelector({updateSelectorOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,callback:this.updateSelectorCallback}))}updateSelectorCallback(t){const{param:e,postData:s,newServiceStore:i}=t,{willSyncService:r,isSync:n}=e,c=s.sp||[];if(r&&c)for(const[l,h]of i.entries())c.push({...h,workId:l,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:n});return{sp:c}}}class We{constructor(a){m(this,"builders",new Map);this.builders=new Map(a.map(t=>[t,this.build(t)]))}build(a){switch(a){case o.EmitEventType.TranslateNode:return new Se;case o.EmitEventType.ZIndexNode:return new we;case o.EmitEventType.CopyNode:return new me;case o.EmitEventType.SetColorNode:return new ge;case o.EmitEventType.DeleteNode:return new Te;case o.EmitEventType.ScaleNode:return new ke;case o.EmitEventType.RotateNode:return new Pe;case o.EmitEventType.SetFontStyle:return new ve;case o.EmitEventType.SetPoint:return new Ee;case o.EmitEventType.SetLock:return new Ie;case o.EmitEventType.SetShapeOpt:return new Ne}}registerForMainThread(a,t,e){return this.builders.forEach(s=>{s&&s.registerMainThread(a,t,e)}),this}async consumeForMainThread(a){for(const t of this.builders.values())if(await(t==null?void 0:t.consume(a)))return!0;return!1}}class Me{constructor(a,t){m(this,"viewId");m(this,"fullLayer");m(this,"topLayer");m(this,"localLayer");m(this,"serviceLayer");m(this,"snapshotFullLayer");m(this,"vNodes");m(this,"master");m(this,"opt");m(this,"cameraOpt");m(this,"scene");m(this,"localWork");m(this,"serviceWork");m(this,"topWork");m(this,"mainThreadPostId");m(this,"combinePostMsg",new Set);m(this,"methodBuilder");this.viewId=a,this.opt=t,this.scene=this.createScene({...t.canvasOpt,container:t.container}),this.master=t.master,this.fullLayer=this.createLayer("fullLayer",this.scene,{...t.layerOpt,bufferSize:this.viewId==="mainView"?4e3:2e3}),this.topLayer=this.createLayer("topLayer",this.scene,{...t.layerOpt,bufferSize:this.viewId==="mainView"?1500:1e3}),this.localLayer=this.createLayer("localLayer",this.scene,{...t.layerOpt,bufferSize:this.viewId==="mainView"?1500:1e3}),this.serviceLayer=this.createLayer("serviceLayer",this.scene,{...t.layerOpt,bufferSize:this.viewId==="mainView"?1500:1e3}),this.vNodes=new de(a,this.scene);const e={thread:this,vNodes:this.vNodes};this.localWork=new fe(e),this.serviceWork=new ye(e),this.topWork=new ue(e),this.vNodes.init(this.fullLayer),this.methodBuilder=new We([o.EmitEventType.CopyNode,o.EmitEventType.SetColorNode,o.EmitEventType.DeleteNode,o.EmitEventType.RotateNode,o.EmitEventType.ScaleNode,o.EmitEventType.TranslateNode,o.EmitEventType.ZIndexNode,o.EmitEventType.SetFontStyle,o.EmitEventType.SetPoint,o.EmitEventType.SetLock,o.EmitEventType.SetShapeOpt]).registerForMainThread(this.localWork,this.serviceWork,this.scene)}post(a){this.combinePostMsg.add(a),this.runBatchPostData()}async on(a,t){if(!await this.methodBuilder.consumeForMainThread(a)){const{msgType:e,toolsType:s,opt:i,dataType:r,workId:n,workState:c}=a;switch(e){case o.EPostMessageType.Destroy:this.destroy();break;case o.EPostMessageType.Clear:this.clearAll();break;case o.EPostMessageType.UpdateCamera:this.updateCamera(a),t&&this.post({workerTasksqueueCount:t});break;case o.EPostMessageType.UpdateTools:if(r===o.EDataType.Local&&s&&i){const l={toolsType:s,toolsOpt:i};this.localWork.setToolsOpt(l)}break;case o.EPostMessageType.CreateWork:if(n&&i&&s){if(s===o.EToolsKey.LaserPen){this.topWork.getTmpWorkShapeNode()||this.topWork.setToolsOpt({toolsType:s,toolsOpt:i}),this.topWork.setWorkOptions(n,i);break}this.localWork.getTmpWorkShapeNode()||this.localWork.setToolsOpt({toolsType:s,toolsOpt:i}),this.localWork.setWorkOptions(n,i)}break;case o.EPostMessageType.DrawWork:c===o.EvevtWorkState.Done&&r===o.EDataType.Local?this.consumeDrawAll(r,a):this.consumeDraw(r,a);break;case o.EPostMessageType.UpdateNode:case o.EPostMessageType.FullWork:if(s===o.EToolsKey.LaserPen){this.consumeDrawAll(r,a);break}this.consumeFull(r,a);break;case o.EPostMessageType.RemoveNode:this.removeNode(a);return;case o.EPostMessageType.Select:r===o.EDataType.Service&&(n===o.Storage_Selector_key?this.localWork.updateFullSelectWork(a):this.serviceWork.runSelectWork(a));break;case o.EPostMessageType.CursorHover:this.localWork.cursorHover(a);break;case o.EPostMessageType.GetTextActive:r===o.EDataType.Local&&this.localWork.checkTextActive(a);break}}}async removeNode(a){const{dataType:t,workId:e}=a;if(e===o.Storage_Selector_key){this.localWork.blurSelector(a);return}t===o.EDataType.Local&&(this.localWork.removeWork(a),await this.localWork.colloctEffectSelectWork(a)),t===o.EDataType.Service&&(this.serviceWork.removeWork(a),await this.localWork.colloctEffectSelectWork(a))}async consumeFull(a,t){const e=await this.localWork.colloctEffectSelectWork(t);e&&a===o.EDataType.Local&&await this.localWork.consumeFull(e,this.scene),e&&a===o.EDataType.Service&&this.serviceWork.consumeFull(e)}setCameraOpt(a){this.cameraOpt=a;const{scale:t,centerX:e,centerY:s,width:i,height:r}=a;(i!==this.scene.width||r!==this.scene.height)&&this.updateScene({width:i,height:r}),this.fullLayer.setAttribute("scale",[t,t]),this.fullLayer.setAttribute("translate",[-e,-s]),this.topLayer.setAttribute("scale",[t,t]),this.topLayer.setAttribute("translate",[-e,-s]),this.localLayer.setAttribute("scale",[t,t]),this.localLayer.setAttribute("translate",[-e,-s]),this.serviceLayer.setAttribute("scale",[t,t]),this.serviceLayer.setAttribute("translate",[-e,-s])}runBatchPostData(){this.mainThreadPostId||(this.mainThreadPostId=requestAnimationFrame(this.combinePost.bind(this)))}combinePostData(){var s;this.mainThreadPostId=void 0;const a=[];let t,e;for(const i of this.combinePostMsg.values()){if((s=i.sp)!=null&&s.length)for(const r of i.sp){let n=!1;for(const c of a)if(o.isEqual(r,c)){n=!0;break}n||a.push(r)}o.isNumber(i.drawCount)&&(t=i.drawCount),o.isNumber(i.workerTasksqueueCount)&&(e=i.workerTasksqueueCount)}return this.combinePostMsg.clear(),{sp:a,drawCount:t,workerTasksqueueCount:e}}combinePost(){var e,s,i;const a=this.combinePostData(),t=(e=a.sp)==null?void 0:e.filter(r=>r.type!==o.EPostMessageType.None||Object.keys(r).filter(n=>n==="type").length);t!=null&&t.length&&(a.sp=t.map(r=>r.viewId?r:{...r,viewId:this.viewId})),((s=a.sp)==null?void 0:s.length)===0&&delete a.sp,a.drawCount===void 0&&delete a.drawCount,a.workerTasksqueueCount===void 0&&delete a.workerTasksqueueCount,(a!=null&&a.drawCount||a!=null&&a.workerTasksqueueCount||(i=a.sp)!=null&&i.length)&&(console.log("mainThread-post-end--001",this.fullLayer.children.length,this.localLayer.children.length,this.topLayer.children.length,this.serviceLayer.children.length),this.opt.post(a))}clearAll(){this.fullLayer.children.length&&(this.fullLayer.parent.children.forEach(a=>{a.name!=="viewport"&&a.remove()}),this.fullLayer.removeAllChildren()),this.localWork.clearAll(),this.topWork.clearAll(),this.serviceWork.clearAll(),this.vNodes.clear()}consumeDrawAll(a,t){const{ops:e,op:s,workId:i}=t;if((e||s!=null&&s.length)&&i){if(this.topWork.localWorkShapes.get(i)){this.topWork.consumeDrawAll(t);return}if(this.localWork.workShapes.get(i)){this.localWork.consumeDrawAll(t,this.serviceWork);return}}}consumeDraw(a,t){const{op:e,workId:s}=t;if(e!=null&&e.length&&s){if(this.topWork.localWorkShapes.get(s)){this.topWork.consumeDraw(t);return}if(this.localWork.workShapes.get(s)){this.localWork.consumeDraw(t,this.serviceWork);return}a===o.EDataType.Service&&this.serviceWork.consumeDraw(t)}}updateCamera(a){var e;const{cameraOpt:t}=a;if(t&&!o.isEqual(this.cameraOpt,t)){const s=this.localWork.getWorkShape(H);if(s&&((e=s.selectIds)!=null&&e.length)&&s.cursorBlur(),this.setCameraOpt(t),this.vNodes.curNodeMap.size&&(this.vNodes.updateNodesRect(),this.localWork.reRenderSelector(),this.serviceWork.selectorWorkShapes.size))for(const[i,r]of this.serviceWork.selectorWorkShapes.entries())this.serviceWork.runSelectWork({workId:i,selectIds:r.selectIds,msgType:o.EPostMessageType.Select,dataType:o.EDataType.Service,viewId:this.viewId})}}createScene(a){return new x.Scene({displayRatio:this.opt.displayer.dpr,depth:!1,desynchronized:!0,...a,autoRender:!0})}createLayer(a,t,e){const{width:s,height:i}=e,r=`canvas-${a}`,n=t.layer(r,{...e,offscreen:!1}),c=new x.Group({anchor:[.5,.5],pos:[s*.5,i*.5],size:[s,i],name:"viewport",id:a});return n.append(c),c}updateScene(a){this.scene.attr({...a});const{width:t,height:e}=a;this.scene.width=t,this.scene.height=e,this.updateLayer({width:t,height:e})}updateLayer(a){const{width:t,height:e}=a;this.fullLayer.parent.setAttribute("width",t),this.fullLayer.parent.setAttribute("height",e),this.fullLayer.setAttribute("size",[t,e]),this.fullLayer.setAttribute("pos",[t*.5,e*.5]),this.topLayer.parent.setAttribute("width",t),this.topLayer.parent.setAttribute("height",e),this.topLayer.setAttribute("size",[t,e]),this.topLayer.setAttribute("pos",[t*.5,e*.5]),this.localLayer.parent.setAttribute("width",t),this.localLayer.parent.setAttribute("height",e),this.localLayer.setAttribute("size",[t,e]),this.localLayer.setAttribute("pos",[t*.5,e*.5]),this.serviceLayer.parent.setAttribute("width",t),this.serviceLayer.parent.setAttribute("height",e),this.serviceLayer.setAttribute("size",[t,e]),this.serviceLayer.setAttribute("pos",[t*.5,e*.5])}destroy(){this.vNodes.clear(),this.fullLayer.remove(),this.topLayer.remove(),this.localLayer.remove(),this.serviceLayer.remove(),this.scene.remove(),this.localWork.destroy(),this.serviceWork.destroy(),this.topWork.destroy()}}class Re{constructor(a,t){m(this,"viewId");m(this,"fullLayer");m(this,"master");m(this,"opt");m(this,"scene");m(this,"mainThreadPostId");m(this,"combinePostMsg",new Set);m(this,"workShapes",new Map);this.viewId=a,this.opt=t,this.scene=this.createScene({...t.canvasOpt,container:t.container}),this.master=t.master,this.fullLayer=this.createLayer("fullLayer",this.scene,{...t.layerOpt,bufferSize:this.viewId==="mainView"?6e3:3e3})}post(a){this.combinePostMsg.add(a),this.runBatchPostData()}async on(a){const{msgType:t}=a;switch(t){case o.EPostMessageType.Snapshot:await this.getSnapshot(a),this.destroy();return;case o.EPostMessageType.BoundingBox:await this.getBoundingRect(a),this.destroy();return}}createWorkShapeNode(a){return _({...a,fullLayer:this.fullLayer,drawLayer:void 0})}setFullWork(a){const{workId:t,opt:e,toolsType:s}=a;if(t&&e&&s){const i=t&&this.workShapes.get(t)||this.createWorkShapeNode({toolsOpt:e,toolsType:s,workId:t});return i?(i.setWorkId(t),this.workShapes.set(t,i),i):void 0}}async runFullWork(a){var s,i;const t=this.setFullWork(a),e=a.ops&&o.transformToNormalData(a.ops);if(t){let r,n;const c=(s=t.getWorkId())==null?void 0:s.toString();return t.toolsType===o.EToolsKey.Image?r=await t.consumeServiceAsync({isFullWork:!0,scene:(i=this.fullLayer.parent)==null?void 0:i.parent,isMainThread:!0}):t.toolsType===o.EToolsKey.Text?r=await t.consumeServiceAsync({isFullWork:!0,replaceId:c,isDrawLabel:!0}):(r=t.consumeService({op:e,isFullWork:!0,replaceId:c}),n=(a==null?void 0:a.updateNodeOpt)&&t.updataOptService(a.updateNodeOpt)),o.computRect(r,n)}}async getSnapshot(a){const{scenePath:t,scenes:e,cameraOpt:s,w:i,h:r}=a;if(t&&e&&s){this.setCameraOpt(s);let n;for(const[l,h]of Object.entries(e))if(h!=null&&h.type)switch(h==null?void 0:h.type){case o.EPostMessageType.UpdateNode:case o.EPostMessageType.FullWork:{const{opt:p}=h,d=await this.runFullWork({...h,opt:p,workId:l,msgType:o.EPostMessageType.FullWork,dataType:o.EDataType.Service,viewId:this.viewId});n=o.computRect(n,d);break}}let c;i&&r&&(c={resizeWidth:i,resizeHeight:r}),await this.getSnapshotRender({scenePath:t,options:c})}}getSceneRect(){const{width:a,height:t}=this.scene;return{x:0,y:0,w:Math.floor(a),h:Math.floor(t)}}getRectImageBitmap(a,t){const e=a.x*this.opt.displayer.dpr,s=a.y*this.opt.displayer.dpr,i=a.w*this.opt.displayer.dpr,r=a.h*this.opt.displayer.dpr;return createImageBitmap(this.fullLayer.parent.canvas,e,s,i,r,t)}async getSnapshotRender(a){var i,r;const{scenePath:t,options:e}=a;((i=this.fullLayer)==null?void 0:i.parent).render();const s=await this.getRectImageBitmap(this.getSceneRect(),e);s&&(this.post({sp:[{type:o.EPostMessageType.Snapshot,scenePath:t,imageBitmap:s,viewId:this.viewId}]}),(r=this.fullLayer)==null||r.removeAllChildren())}async getBoundingRect(a){const{scenePath:t,scenes:e,cameraOpt:s}=a;if(t&&e&&s){this.setCameraOpt(s);let i;for(const[r,n]of Object.entries(e))if(n!=null&&n.type)switch(n==null?void 0:n.type){case o.EPostMessageType.UpdateNode:case o.EPostMessageType.FullWork:{const c=await this.runFullWork({...n,workId:r,msgType:o.EPostMessageType.FullWork,dataType:o.EDataType.Service,viewId:this.viewId});i=o.computRect(i,c);break}}i&&this.post({sp:[{type:o.EPostMessageType.BoundingBox,scenePath:t,rect:i}]})}}setCameraOpt(a){const{scale:t,centerX:e,centerY:s,width:i,height:r}=a;this.updateScene({width:i,height:r}),this.fullLayer.setAttribute("scale",[t,t]),this.fullLayer.setAttribute("translate",[-e,-s])}runBatchPostData(){this.mainThreadPostId||(this.mainThreadPostId=requestAnimationFrame(this.combinePost.bind(this)))}combinePostData(){var t;this.mainThreadPostId=void 0;const a=[];for(const e of this.combinePostMsg.values())if((t=e.sp)!=null&&t.length)for(const s of e.sp){let i=!1;for(const r of a)if(o.isEqual(s,r)){i=!0;break}i||a.push(s)}return this.combinePostMsg.clear(),{sp:a}}combinePost(){var e,s,i;const a=this.combinePostData(),t=(e=a.sp)==null?void 0:e.filter(r=>r.type!==o.EPostMessageType.None||Object.keys(r).filter(n=>n==="type").length);t!=null&&t.length&&(a.sp=t.map(r=>r.viewId?r:{...r,viewId:this.viewId})),((s=a.sp)==null?void 0:s.length)===0&&delete a.sp,(a!=null&&a.drawCount||a!=null&&a.workerTasksqueueCount||(i=a.sp)!=null&&i.length)&&(console.log("mainThread-post-end--001",this.fullLayer.children.length),this.opt.post(a))}createScene(a){return new x.Scene({displayRatio:this.opt.displayer.dpr,depth:!1,desynchronized:!0,...a,autoRender:!1})}createLayer(a,t,e){const{width:s,height:i}=e,r=`canvas-${a}`,n=t.layer(r,e),c=new x.Group({anchor:[.5,.5],pos:[s*.5,i*.5],size:[s,i],name:"viewport",id:a});return n.append(c),c}updateScene(a){this.scene.attr({...a});const{width:t,height:e}=a;this.scene.width=t,this.scene.height=e,this.updateLayer({width:t,height:e})}updateLayer(a){const{width:t,height:e}=a;this.fullLayer.parent.setAttribute("width",t),this.fullLayer.parent.setAttribute("height",e),this.fullLayer.setAttribute("size",[t,e]),this.fullLayer.setAttribute("pos",[t*.5,e*.5])}destroy(){this.fullLayer.remove(),this.scene.remove()}}class Le{constructor(a){m(this,"mainThreadMap",new Map);m(this,"snapshotThread");m(this,"master");this.master=a}post(a){const{drawCount:t,sp:e,workerTasksqueueCount:s}=a;console.log("mainThread-post-end",a),o.isNumber(s)&&this.master.setWorkerTasksqueueCount(s),o.isNumber(t)&&this.master.setMaxDrawCount(t),e&&this.master.collectorSyncData(e)}destroy(){this.mainThreadMap.clear()}createMainThread(a,t){return new Me(a,t)}createSnapshotThread(a,t){return new Re(a,t)}consume(a){var t,e,s,i;for(const r of a.values()){const{msgType:n,viewId:c,tasksqueue:l,mainTasksqueueCount:h,layerOpt:p,offscreenCanvasOpt:d,cameraOpt:y}=r;if(n===o.EPostMessageType.Init){const f=(t=this.master.control.viewContainerManager.getView(c))==null?void 0:t.displayer,g=f==null?void 0:f.canvasContainerRef.current;if(f&&g&&p&&d){const w=this.createMainThread(c,{displayer:f,container:g,layerOpt:p,master:this.master,canvasOpt:d,post:this.post.bind(this)});this.mainThreadMap.set(c,w),w&&y&&w.setCameraOpt(y)}continue}if((n===o.EPostMessageType.Snapshot||n===o.EPostMessageType.BoundingBox)&&c===((e=this.master.control.viewContainerManager.mainView)==null?void 0:e.id)){const f=(s=this.master.control.viewContainerManager.getView(c))==null?void 0:s.displayer,g=(i=f.snapshotContainerRef)==null?void 0:i.current;if(f&&g&&y){g.style.width=`${y.width}px`,g.style.height=`${y.height}px`;const w={...o.ViewContainerManager.defaultLayerOpt,offscreen:!1,width:y.width,height:y.height},W={...o.ViewContainerManager.defaultScreenCanvasOpt,width:y.width,height:y.height};this.snapshotThread=this.createSnapshotThread(c,{displayer:f,container:g,layerOpt:w,master:this.master,canvasOpt:W,post:this.post.bind(this)}),this.snapshotThread.on(r).then(()=>{this.snapshotThread=void 0,g.innerHTML="",g.style.width="",g.style.height=""});continue}}if(n===o.EPostMessageType.TasksQueue&&(l!=null&&l.size)&&h){for(const[f,g]of this.mainThreadMap.entries()){const w=l.get(f);w&&g.on(w,h)}continue}if(c===o.Storage_ViewId_ALL){for(const f of this.mainThreadMap.values())f.on(r),n===o.EPostMessageType.Destroy&&this.mainThreadMap.delete(c);continue}const u=this.mainThreadMap.get(c);u&&(u.on(r),n===o.EPostMessageType.Destroy&&this.mainThreadMap.delete(c))}}}exports.MainThreadManagerImpl=Le;
|