@netless/appliance-plugin 1.0.0-beta.2 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -2
- package/cdn/cdn.js +1 -1
- package/cdn/fullWorker-wE6a5h.js +566 -0
- package/cdn/subWorker-C2CJhY.js +566 -0
- package/dist/appliance-plugin.js +1 -1
- package/dist/appliance-plugin.mjs +22 -8620
- package/dist/component/textEditor/types.d.ts +1 -0
- package/dist/component/textEditor/view.d.ts +9 -7
- package/dist/core/enum.d.ts +7 -7
- package/dist/core/mainEngine.d.ts +8 -5
- package/dist/core/mainThread/base.d.ts +81 -0
- package/dist/core/mainThread/index.d.ts +23 -0
- package/dist/core/mainThread/snapshotThread.d.ts +40 -0
- package/dist/core/mainThread/subLocalThread.d.ts +101 -0
- package/dist/core/mainThread/subServiceThread.d.ts +42 -0
- package/dist/core/mainThread/subTopThread.d.ts +46 -0
- package/dist/core/mainThread/vNodeManager.d.ts +32 -0
- package/dist/core/msgEvent/baseForMainThread.d.ts +13 -0
- package/dist/core/msgEvent/copyNode/forMainThread.d.ts +8 -0
- package/dist/core/msgEvent/deleteNode/forMainThread.d.ts +13 -0
- package/dist/core/msgEvent/forMainThread.d.ts +14 -0
- package/dist/core/msgEvent/rotateNode/forMainThread.d.ts +9 -0
- package/dist/core/msgEvent/scaleNode/forMainThread.d.ts +9 -0
- package/dist/core/msgEvent/setColor/forMainThread.d.ts +9 -0
- package/dist/core/msgEvent/setFont/forMainThread.d.ts +9 -0
- package/dist/core/msgEvent/setLock/forMainThread.d.ts +9 -0
- package/dist/core/msgEvent/setPoint/forMainThread.d.ts +9 -0
- package/dist/core/msgEvent/setShape/forMainThread.d.ts +9 -0
- package/dist/core/msgEvent/setZIndex/forMainThread.d.ts +9 -0
- package/dist/core/msgEvent/translateNode/forMain.d.ts +0 -1
- package/dist/core/msgEvent/translateNode/forMainThread.d.ts +9 -0
- package/dist/core/tools/arrow.d.ts +4 -3
- package/dist/core/tools/base.d.ts +3 -3
- package/dist/core/tools/ellipse.d.ts +4 -3
- package/dist/core/tools/eraser.d.ts +3 -3
- package/dist/core/tools/image.d.ts +1 -0
- package/dist/core/tools/pencil.d.ts +1 -0
- package/dist/core/tools/polygon.d.ts +4 -3
- package/dist/core/tools/rectangle.d.ts +4 -3
- package/dist/core/tools/selector.d.ts +11 -9
- package/dist/core/tools/speechBalloon.d.ts +4 -3
- package/dist/core/tools/star.d.ts +4 -3
- package/dist/core/tools/straight.d.ts +4 -3
- package/dist/core/tools/utils.d.ts +7 -3
- package/dist/core/types.d.ts +13 -1
- package/dist/core/utils/index.d.ts +1 -1
- package/dist/core/worker/base.d.ts +17 -34
- package/dist/core/worker/fullWorkerLocal.d.ts +1 -1
- package/dist/core/worker/fullWorkerService.d.ts +23 -7
- package/dist/core/worker/subWorkerLocal.d.ts +0 -5
- package/dist/core/worker/subWorkerTopLayer.d.ts +43 -0
- package/dist/core/worker/vNodeManager.d.ts +3 -2
- package/dist/core/worker/workerManager.d.ts +16 -15
- package/dist/displayer/floatBar/dragBox/index.d.ts +4 -0
- package/dist/displayer/floatBar/index.d.ts +1 -5
- package/dist/fullWorker.js +10 -10
- package/dist/index-0-ebfVjb.mjs +8732 -0
- package/dist/index-CQlnAm5S.mjs +5405 -0
- package/dist/index-DMJjpzvq.js +1 -0
- package/dist/index-h_PU7sdS.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/plugin/baseApplianceManager.d.ts +3 -3
- package/dist/plugin/baseViewContainerManager.d.ts +6 -3
- package/dist/plugin/const.d.ts +13 -0
- package/dist/plugin/displayerView.d.ts +4 -11
- package/dist/plugin/multi/applianceMultiManager.d.ts +1 -1
- package/dist/plugin/multi/containerManager.d.ts +1 -1
- package/dist/plugin/multi/displayer/appViewDisplayerManager.d.ts +2 -1
- package/dist/plugin/multi/displayer/mainViewDisplayerManager.d.ts +3 -1
- package/dist/plugin/single/applianceSingleManager.d.ts +1 -1
- package/dist/plugin/single/containerManager.d.ts +1 -1
- package/dist/plugin/single/displayer/mainViewDisplayerManager.d.ts +3 -1
- package/dist/plugin/types.d.ts +1 -2
- package/dist/style.css +1 -1
- package/dist/subWorker.js +10 -10
- package/package.json +3 -3
- package/cdn/fullWorker-O4uzWn.js +0 -566
- package/cdn/subWorker-CvBoLi.js +0 -566
- package/dist/core/msgEvent/activeZIndex/forMain.d.ts +0 -12
- package/dist/core/msgEvent/activeZIndex/forWorker.d.ts +0 -8
- /package/dist/displayer/{highlightBox → floatBar/highlightBox}/index.d.ts +0 -0
- /package/dist/displayer/{resizable → floatBar/resizable}/index.d.ts +0 -0
- /package/dist/displayer/{rotate → floatBar/rotate}/index.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var ae=Object.defineProperty;var ce=(W,a,t)=>a in W?ae(W,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):W[a]=t;var m=(W,a,t)=>(ce(W,typeof a!="symbol"?a+"":a,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index-DMJjpzvq.js"),x=require("spritejs"),le=require("lineclip");require("lz-string");require("white-web-sdk");require("react-dom");require("react");const O=class O{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,f={};o.isNumber(l)&&(f.zIndex=l),c&&(f.pos=[c[0],c[1]]),h&&(f.scale=h),p&&(f.rotate=p),d&&(f.translate=d),n.attr(f);const u=n==null?void 0:n.getBoundingClientRect();return u&&(t=o.computRect(t,{x:Math.floor(u.x-O.SafeBorderPadding),y:Math.floor(u.y-O.SafeBorderPadding),w:Math.floor(u.width+O.SafeBorderPadding*2),h:Math.floor(u.height+O.SafeBorderPadding*2)})),(i=this.vNodes)==null||i.setInfo(e,{rect:t,centerPos:c}),t}}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:f}=e;let u;const y=r&&o.cloneDeep(r)||s.get(t.name);if(!y)return;o.isNumber(n)&&(t.setAttribute("zIndex",n),y.opt.zIndex=n);const g=t.parent;if(g){if(h&&d&&p){const{rect:w}=y,M=[];for(let L=0;L<y.op.length;L+=3)M.push(new o.Point2d(y.op[L],y.op[L+1],y.op[L+2]));const T=o.getRectFromPoints(M),S=[T.w*g.worldScaling[0],T.h*g.worldScaling[0]],P=[w.w-S[0],w.h-S[1]],k=[(w.w*p[0]-P[0])/S[0],(w.h*p[1]-P[1])/S[1]],v=[d[0]/g.worldScaling[0],d[1]/g.worldScaling[1]],R=y.op.map((L,D)=>{const b=D%3;return b===0?L+v[0]:b===1?L+v[1]:L}),N=[y.centerPos[0]+v[0],y.centerPos[1]+v[1]];o.scalePoints(R,N,k);const I=[];for(let L=0;L<R.length;L+=3)I.push(new o.Point2d(R[L],R[L+1],R[L+2]));y.op=R,y.centerPos=N}else if(c){const w=[c[0]/g.worldScaling[0],c[1]/g.worldScaling[1]];t.setAttribute("translate",w),y.opt.translate=w,r&&(u=o.getRectTranslated(y.rect,c),y.rect=u)}else o.isNumber(l)&&(t.setAttribute("rotate",l),y.opt.rotate=l,r&&(u=o.getRectRotated(y.rect,l),y.rect=u));if(f){const w=f.get(t.name);if(w)for(let M=0,T=0;M<y.op.length;M+=3,T++)y.op[M]=w[T][0],y.op[M+1]=w[T][1]}if(i){if(c){const w=[c[0]/g.worldScaling[0],c[1]/g.worldScaling[1]],M=y.op.map((T,S)=>{const P=S%3;return P===0?T+w[0]:P===1?T+w[1]:T});y.op=M,y.centerPos=[y.centerPos[0]+w[0],y.centerPos[1]+w[1]],y!=null&&y.opt&&(y.opt.translate=void 0)}else if(o.isNumber(l)){const w=y.op;o.rotatePoints(w,y.centerPos,l),y.op=w,y!=null&&y.opt&&(y.opt.rotate=void 0)}}y&&s.setInfo(t.name,y)}}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-O.SafeBorderPadding),y:Math.floor(s.y-O.SafeBorderPadding),w:Math.floor(s.width+O.SafeBorderPadding*2),h:Math.floor(s.height+O.SafeBorderPadding*2)}}}};m(O,"SafeBorderPadding",10);let E=O;function $(W,a=!0){const t=W.length;if(t<2)return"";let e=W[0],s=W[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=W[r],s=W[r+1],i+=o.average(e,s);return a?`M${o.average(W[0],W[1])}Q${o.precise(W[1])}${o.average(W[1],W[2])}T${i}${o.average(W[t-1],W[0])}${o.average(W[0],W[1])}Z`:`M${o.precise(W[0])}Q${o.precise(W[1])}${o.average(W[1],W[2])}${W.length>3?"T":""}${i}L${o.precise(W[t-1])}`}class H 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,isClearAll:!0})),{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,isClearAll:i,isSubWorker:r,isMainThread:n}=t;if(((w=e.op)==null?void 0:w.length)===0)return{type:o.EPostMessageType.None};const{workId:c}=e,{tasks:l,effects:h,consumeIndex:p}=this.transformData(e,!1);this.syncIndex=Math.min(this.syncIndex,p,Math.max(0,this.tmpPoints.length-2));const d={name:c==null?void 0:c.toString()};let f,u=!1;const y=this.syncIndex;if(this.syncTimestamp===0&&(this.syncTimestamp=Date.now()),l.length&&(l[0].taskId-this.syncTimestamp>this.syncUnitTime&&(u=!0,this.syncTimestamp=l[0].taskId,this.syncIndex=this.tmpPoints.length),r||n)){const M=s?this.fullLayer:this.drawLayer||this.fullLayer;f=this.draw({attrs:d,tasks:l,effects:h,layer:M,isClearAll:i})}if(r)return p>10&&this.tmpPoints.splice(0,p-10),{rect:f,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local};const g=[];return this.tmpPoints.slice(y).forEach(M=>{g.push(M.x,M.y,this.computRadius(M.z,this.workOptions.thickness))}),{rect:f,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:u?c:void 0,op:u?g:void 0,index:u?y*3:void 0}}consumeAll(t){var h,p,d;if(t.data){const{op:f,workState:u}=t.data;f!=null&&f.length&&u===o.EvevtWorkState.Done&&this.workOptions.strokeType===o.EStrokeType.Stroke&&this.updateTempPointsWithPressureWhenDone(f)}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,isClearAll:!1}));const c=[];this.tmpPoints.map(f=>{c.push(f.x,f.y,this.computRadius(f.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,undoTickerId:(d=t.data)==null?void 0:d.undoTickerId}}clearTmpPoints(){this.tmpPoints.length=0,this.syncTimestamp=0,this.syncIndex=0}consumeService(t){var p,d;const{op:e,isFullWork:s,replaceId:i,isClearAll:r}=t;this.tmpPoints.length=0;for(let f=0;f<e.length;f+=3){const u=new o.Point2d(e[f],e[f+1],e[f+2]);if(this.tmpPoints.length>0){const y=this.tmpPoints[this.tmpPoints.length-1],g=o.Vec2d.Sub(u,y).uni();u.setv(g)}this.tmpPoints.push(u)}const n=this.transformDataAll(!1),c=(p=this.workId)==null?void 0:p.toString(),l={name:c};let h;if(c&&n.length){const f=s?this.fullLayer:this.drawLayer||this.fullLayer;h=this.draw({attrs:l,tasks:n,replaceId:i,layer:f,isClearAll:r}),(d=this.vNodes)==null||d.setInfo(c,{rect:h,op:e,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:h&&E.getCenterPos(h,f)})}return h}transformDataAll(t=!0){return this.getTaskPoints(this.tmpPoints,t&&this.workOptions.thickness||void 0)}draw(t){var P;const{attrs:e,tasks:s,replaceId:i,effects:r,layer:n,isClearAll:c}=t,{strokeColor:l,strokeType:h,thickness:p,zIndex:d,scale:f,rotate:u,translate:y}=this.workOptions;c&&n.removeAllChildren(),i&&(this.fullLayer.getElementsByName(i+"").map(k=>k.remove()),(P=this.drawLayer)==null||P.getElementsByName(i+"").map(k=>k.remove())),r!=null&&r.size&&(r.forEach(k=>{var v;(v=n.getElementById(k+""))==null||v.remove()}),r.clear());let g;const w=[],M=n.worldPosition,T=n.worldScaling;for(let k=0;k<s.length;k++){const{pos:v,points:R,taskId:N}=s[k];e.id=N.toString();const{ps:I,rect:L}=this.computDrawPoints(R);let D;const b=R.length===1;h===o.EStrokeType.Stroke||b?D=$(I,!0):D=$(I,!1);const V={pos:v,d:D,fillColor:h===o.EStrokeType.Stroke||b?l:void 0,lineDash:h===o.EStrokeType.Dotted&&!b?[1,p*2]:h===o.EStrokeType.LongDotted&&!b?[p,p*2]:void 0,strokeColor:l,lineCap:h===o.EStrokeType.Stroke||b?void 0:"round",lineWidth:h===o.EStrokeType.Stroke||b?0:p};g=o.computRect(g,{x:Math.floor((L.x+v[0])*T[0]+M[0]-E.SafeBorderPadding),y:Math.floor((L.y+v[1])*T[1]+M[1]-E.SafeBorderPadding),w:Math.floor(L.w*T[0]+2*E.SafeBorderPadding),h:Math.floor(L.h*T[1]+2*E.SafeBorderPadding)}),w.push(V)}f&&(e.scale=f),u&&(e.rotate=u),y&&(e.translate=y);const S=new x.Group;if(g){this.centerPos=E.getCenterPos(g,n),S.attr({...e,normalize:!0,id:e.name,anchor:[.5,.5],bgcolor:h===o.EStrokeType.Stroke?l:void 0,pos:this.centerPos,size:[(g.w-2*E.SafeBorderPadding)/T[0],(g.h-2*E.SafeBorderPadding)/T[1]],zIndex:d});const k=w.map(v=>(v.pos=[v.pos[0]-this.centerPos[0],v.pos[1]-this.centerPos[1]],new x.Path(v)));S.append(...k),h===o.EStrokeType.Stroke&&S.seal(),n.append(S)}if(f||u||y){const k=S==null?void 0:S.getBoundingClientRect();if(k)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 g}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 f=o.Vec2d.Per(d).mul(p);e.push(o.Point2d.Sub(h,f)),s.push(o.Point2d.Add(h,f))}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],f=d.x-r,u=d.y-n,y=d.z,g=e?this.computRadius(y,e):y;if(l.push({point:new o.Point2d(f,u,y,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 M=(p=l.pop())==null?void 0:p.point.clone();M&&s.push({taskId:h,pos:c,points:[...l,{point:M,radius:g}]}),r=t[i].x,n=t[i].y,c=[r,n];const T=d.x-r,S=d.y-n;l=[{point:new o.Point2d(T,S,y),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,f=this.tmpPoints[d],u=o.Vec2d.Sub(p,f).uni();if(p.isNear(f,e)){if(f.z<this.MAX_REPEAR){if(f.setz(Math.min(f.z+1,this.MAX_REPEAR)),n=Math.min(n,d),h>1){let w=h-1;for(;w>0;){const M=this.tmpPoints[w].distance(this.tmpPoints[w-1]),T=Math.max(this.tmpPoints[w].z-this.uniThickness*M,0);if(this.tmpPoints[w-1].z>=T)break;this.tmpPoints[w-1].setz(T),n=Math.min(n,w-1),w--}}}else n=1/0;continue}p.setv(u);const y=p.distance(f),g=Math.max(f.z-this.uniThickness*y,0);h>1&&o.Vec2d.Equals(u,f.v,.02)&&(g>0||f.z<=0)&&(s&&f.t&&s.add(f.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 f=p-1,u=this.tmpPoints[f],y=o.Vec2d.Sub(d,u).uni();if(d.isNear(u,e/2)){n=Math.min(f,n);continue}o.Vec2d.Equals(y,u.v,.02)&&(s&&u.t&&s.add(u.t),this.tmpPoints.pop(),n=Math.min(f,n)),d.setv(y),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 y=this.tmpPoints[u].distance(this.tmpPoints[u-1]),g=Math.max(this.tmpPoints[u].z-this.uniThickness*y,-e/4);if(this.tmpPoints[u-1].z>=g)break;this.tmpPoints[u-1].setz(g),u--}}continue}c.setv(p);const f=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(f),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 j 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,f=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]},y=this.getTaskPoints(f);if(y.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:y,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]},f=this.getTaskPoints(n);f.length&&this.draw({attrs:d,tasks:f,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 y;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 f={name:(y=this.workId)==null?void 0:y.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:f,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=$(p,!0):d=$(p,!1),l.attr({...e,pos:h,d});const{vertex:f,fragment:u}=this.workOptions;if(f&&u){const y=r.renderer.createProgram({vertex:f,fragment:u}),{width:g,height:w}=r.getResolution();l.setUniforms({u_time:0,u_resolution:[g,w]}),l.setProgram(y)}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 f=t[s].getAngleByPoints(t[s-1],t[s+1]);if(f<90||f>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 y=h.x-i,g=h.y-r;c=[new o.Point2d(y,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 f=o.Vec2d.Mul(i,d*l);p.push(this.tmpPoints[0]+f.x,this.tmpPoints[1]+f.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],f=d.findIndex((u,y)=>y<d.length-1?n([u,d[y+1]],[l[0],l[1]]):!1);if(f!==-1&&f>-1){const u=[],y=d.slice(0,f+1);if(o.Vec2d.Equals(d[f],l[0])||y.push(l[0].clone().setz(d[f].z)),y.length>1&&u.push(y),f+l.length-1<d.length-1){const g=f+l.length-1,w=d.slice(g),M=l[l.length-1];o.Vec2d.Equals(d[g],M)||w.unshift(M.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),f=[],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),f.push(new o.Point2d(w.x,w.y))}const y=f.length&&o.getRectFromPoints(f)||l.rect;if(o.isIntersect(y,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),M=this.cutPolyline(w,u);for(let T=0;T<M.length;T++){const S=`${c}_s_${T}`,P=[];M[T].forEach(k=>{P.push((k.x-this.worldPosition[0])/this.worldScaling[0],(k.y-this.worldPosition[1])/this.worldScaling[1],k.z)}),l.opt&&l.toolsType&&this.vNodes&&(this.vNodes.setInfo(S,{rect:y,op:P,opt:l.opt,canRotate:l.canRotate,scaleType:l.scaleType,toolsType:l.toolsType}),i.set(S,{workId:S,op:P,opt:l.opt,toolsType:l.toolsType}))}}}else s.add(l.name);n=o.computRect(n,y)}}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 Y=U;const F=class F 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:F.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],f=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(f)}),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(F.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,F.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=F.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)=>(h.opt.zIndex||0)-(p.opt.zIndex||0));for(const h of l){const p=this.fullLayer.getElementsByName(h.name);if(ne(p).find(f=>f.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 f=new Map,{box:u,workState:y,angle:g,translate:w}=e;let M=[0,0],T=[1,1],S=[0,0],P,k;if(u||w||o.isNumber(g)){if(y===o.EvevtWorkState.Start)return i.setTarget(),{type:o.EPostMessageType.Select,dataType:o.EDataType.Local,selectRect:this.oldSelectRect,rect:this.oldSelectRect};if(P=i.getLastTarget(),P&&u){let N;s==null||s.forEach(I=>{const L=P==null?void 0:P.get(I);N=o.computRect(N,L==null?void 0:L.rect)}),N&&(T=[u.w/N.w,u.h/N.h],M=[u.x+u.w/2-(N.x+N.w/2),u.y+u.h/2-(N.y+N.h/2)],S=[N.x+N.w/2,N.y+N.h/2]),k=N}}if(s)for(const N of s){const I=i.get(N);if(I){const{toolsType:L}=I;let D=(p==null?void 0:p.getElementsByName(N))[0];if(D){const b={...e};let V;if(L){if(P&&(V=P.get(N),V&&u)){b.boxScale=T;const z=[V.rect.x+V.rect.w/2,V.rect.y+V.rect.h/2],K=[z[0]-S[0],z[1]-S[1]];b.boxTranslate=[K[0]*(T[0]-1)+M[0]+(c&&c[0]||0),K[1]*(T[1]-1)+M[1]+(c&&c[1]||0)]}const _=re(L);if(_==null||_.updateNodeOpt({node:D,opt:b,vNodes:i,willSerializeData:r,targetNode:V}),I&&n&&(r&&(b.angle||b.translate)||b.box&&b.workState!==o.EvevtWorkState.Start||b.pointMap&&b.pointMap.has(N)||L===o.EToolsKey.Text&&(b.fontSize||b.translate||b.textInfos&&b.textInfos.get(N))||L===o.EToolsKey.Image&&(b.angle||b.translate||b.boxScale)||L===b.toolsType&&b.willRefresh)){const z=n.createWorkShapeNode({toolsType:L,toolsOpt:I.opt});z==null||z.setWorkId(N);let K;L===o.EToolsKey.Image&&l?K=await z.consumeServiceAsync({isFullWork:!0,replaceId:N,scene:l,isMainThread:h}):K=z==null?void 0:z.consumeService({op:I.op,isFullWork:!0,replaceId:N}),K&&(I.rect=K),D=(p==null?void 0:p.getElementsByName(N))[0]}I&&(f.set(N,I),d=o.computRect(d,I.rect))}}}}P&&y===o.EvevtWorkState.Done&&i.deleteLastTarget();const v=d;if(k&&e.dir&&v){let N=[0,0];switch(e.dir){case"topLeft":case"left":{const I=[k.x+k.w,k.y+k.h];N=[I[0]-(v.x+v.w),I[1]-(v.y+v.h)];break}case"bottomLeft":case"bottom":{const I=[k.x+k.w,k.y];N=[I[0]-(v.x+v.w),I[1]-v.y];break}case"topRight":case"top":{const I=[k.x,k.y+k.h];N=[I[0]-v.x,I[1]-(v.y+v.h)];break}case"right":case"bottomRight":{const I=[k.x,k.y];N=[I[0]-v.x,I[1]-v.y];break}}if(N[0]||N[1])return v.x=v.x+N[0],v.y=v.y+N[1],await this.updateSelector({...t,offset:N})}this.getSelecteorInfo(f),this.draw(F.selectorId,p,{selectIds:s||[],subNodeMap:f,intersectRect:v});const R=o.computRect(this.oldSelectRect,v);return this.oldSelectRect=v,{type:o.EPostMessageType.Select,dataType:o.EDataType.Local,selectRect:v,renderRect:d,rect:o.computRect(R,v)}}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(F.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(F,"selectorId",o.Storage_Selector_key),m(F,"selectorBorderId","selector-border");let C=F;class Z 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 y=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:y})}if(!i){const y=Date.now();return y-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=y,{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 f=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:f,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){var M;const{workId:e,layer:s}=t;this.fullLayer.getElementsByName(e).map(T=>T.remove()),(M=this.drawLayer)==null||M.getElementsByName(e).map(T=>T.remove());const{strokeColor:i,thickness:r,zIndex:n,scale:c,rotate:l,translate:h}=this.workOptions,p=s.worldPosition,d=s.worldScaling,{points:f,rect:u}=this.computDrawPoints(r),g={pos:[u.x+u.w/2,u.y+u.h/2],name:e,id:e,close:!0,points:f,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(s.append(w),c||l||h){const T=w.getBoundingClientRect();return{x:Math.floor(T.x-E.SafeBorderPadding),y:Math.floor(T.y-E.SafeBorderPadding),w:Math.floor(T.width+E.SafeBorderPadding*2),h:Math.floor(T.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),f=o.Point2d.Add(c,p),u=[i,l,d,this.tmpPoints[1],f,h,r];return{points:u.map(y=>o.Point2d.Sub(y,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 J 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 y=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:y,isDrawing:!0})}if(!i){const y=Date.now();return y-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=y,{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 f=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:f,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){var P;const{workId:e,layer:s,isDrawing:i}=t;this.fullLayer.getElementsByName(e).map(k=>k.remove()),(P=this.drawLayer)==null||P.getElementsByName(e).map(k=>k.remove());const{strokeColor:r,fillColor:n,thickness:c,zIndex:l,scale:h,rotate:p,translate:d}=this.workOptions,f=s.worldPosition,u=s.worldScaling,{radius:y,rect:g,pos:w}=this.computDrawPoints(c),M={pos:w,name:e,id:e,radius:y,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0,zIndex:l},T={x:Math.floor(g.x*u[0]+f[0]-E.SafeBorderPadding),y:Math.floor(g.y*u[1]+f[1]-E.SafeBorderPadding),w:Math.floor(g.w*u[0]+2*E.SafeBorderPadding),h:Math.floor(g.h*u[1]+2*E.SafeBorderPadding)};if(i){const{name:k,id:v,zIndex:R,strokeColor:N}=M,I=E.getCenterPos(T,s),L=new x.Group({name:k,id:v,zIndex:R,pos:I,anchor:[.5,.5],size:[T.w,T.h]}),D=new x.Ellipse({...M,pos:[0,0]}),b=new x.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:N,lineWidth:1,scale:[1/u[0],1/u[1]]});return L.append(D,b),s.append(L),T}h&&(M.scale=h),p&&(M.rotate=p),d&&(M.translate=d);const S=new x.Ellipse(M);if(s.append(S),p||h||d){const k=S.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 T}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 Q 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 y;const{data:e,isFullWork:s,isSubWorker:i,isMainThread:r}=t,n=(y=e==null?void 0:e.workId)==null?void 0:y.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 f;if(i||r){const g=s?this.fullLayer:this.drawLayer||this.fullLayer;f=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(f,this.oldRect);return this.oldRect=f,{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){var N;const{workId:e,layer:s,isDrawing:i,ps:r,replaceId:n}=t;this.fullLayer.getElementsByName(n||e).map(I=>I.remove()),(N=this.drawLayer)==null||N.getElementsByName(n||e).map(I=>I.remove());const{strokeColor:c,fillColor:l,thickness:h,zIndex:p,scale:d,rotate:f,translate:u,textOpt:y}=this.workOptions,g=s.worldPosition,w=s.worldScaling,{points:M,rect:T,pos:S}=this.computDrawPoints(r),P={close:!0,normalize:!0,points:M,lineWidth:h,fillColor:l!=="transparent"&&l||void 0,strokeColor:c,lineJoin:"round"},k={x:Math.floor(T.x*w[0]+g[0]-E.SafeBorderPadding),y:Math.floor(T.y*w[1]+g[1]-E.SafeBorderPadding),w:Math.floor(T.w*w[0]+2*E.SafeBorderPadding),h:Math.floor(T.h*w[0]+2*E.SafeBorderPadding)},v=new x.Group({name:e,id:e,zIndex:p,pos:S,anchor:[.5,.5],size:[T.w,T.h],scale:d,rotate:f,translate:u}),R=new x.Polyline({...P,pos:[0,0]});if(v.appendChild(R),i){const I=new x.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:c,lineWidth:1,scale:[1/w[0],1/w[1]]});v.appendChild(I)}if(s.append(v),d||f||u){const I=v.getBoundingClientRect();return{x:Math.floor(I.x-E.SafeBorderPadding),y:Math.floor(I.y-E.SafeBorderPadding),w:Math.floor(I.width+2*E.SafeBorderPadding),h:Math.floor(I.height+2*E.SafeBorderPadding)}}return k}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,M;const{node:e,opt:s,vNodes:i}=t,{strokeColor:r,fillColor:n,fontColor:c,fontBgColor:l,bold:h,italic:p,lineThrough:d,underline:f,fontSize:u}=s,y=i.get(e.name);let g=e;if(e.tagName==="GROUP"&&(g=e.children[0]),r&&(g.setAttribute("strokeColor",r),(w=y==null?void 0:y.opt)!=null&&w.strokeColor&&(y.opt.strokeColor=r)),n&&(n==="transparent"?g.setAttribute("fillColor","rgba(0,0,0,0)"):g.setAttribute("fillColor",n),(M=y==null?void 0:y.opt)!=null&&M.fillColor&&(y.opt.fillColor=n)),y!=null&&y.opt.textOpt){const T=y.opt.textOpt;c&&T.fontColor&&(T.fontColor=c),l&&T.fontBgColor&&(T.fontBgColor=l),h&&(T.bold=h),p&&(T.italic=p),o.isBoolean(d)&&(T.lineThrough=d),o.isBoolean(f)&&(T.underline=f),u&&(T.fontSize=u)}return y&&i.setInfo(e.name,y),E.updateNodeOpt(t)}}class ee 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 y=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:y,isDrawing:!0})}if(!i){const y=Date.now();return y-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=y,{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 f=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:f,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){var N;const{workId:e,layer:s,isDrawing:i}=t;this.fullLayer.getElementsByName(e).map(I=>I.remove()),(N=this.drawLayer)==null||N.getElementsByName(e).map(I=>I.remove());const{strokeColor:r,fillColor:n,thickness:c,zIndex:l,vertices:h,innerVerticeStep:p,innerRatio:d,scale:f,rotate:u,translate:y}=this.workOptions,g=s.worldScaling,{rect:w,pos:M,points:T}=this.computDrawPoints(c,h,p,d),S={close:!0,points:T,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0,lineJoin:"round"},P={name:e,id:e,zIndex:l,pos:M,anchor:[.5,.5],size:[w.w,w.h],className:`${M[0]},${M[1]}`};f&&(P.scale=f),u&&(P.rotate=u),y&&(P.translate=y);const k=new x.Group(P);if(i){const I=new x.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/g[0],1/g[1]]});k.append(I)}const v=new x.Polyline({...S,pos:[0,0]});k.append(v),s.append(k);const R=k.getBoundingClientRect();return{x:Math.floor(R.x-E.SafeBorderPadding),y:Math.floor(R.y-E.SafeBorderPadding),w:Math.floor(R.width+E.SafeBorderPadding*2),h:Math.floor(R.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 y=u*d-.5*Math.PI;let g,w;u%s===1?(g=h*c[0]*Math.cos(y),w=h*c[1]*Math.sin(y)):(g=l*c[0]*Math.cos(y),w=l*c[1]*Math.sin(y),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),f=d==null?void 0:d.opt;let u=e;return e.tagName==="GROUP"&&(u=e.children[0]),r&&(u.setAttribute("strokeColor",r),f!=null&&f.strokeColor&&(f.strokeColor=r)),n&&(n==="transparent"?u.setAttribute("fillColor","rgba(0,0,0,0)"):u.setAttribute("fillColor",n),f!=null&&f.fillColor&&(f.fillColor=n)),c===o.EToolsKey.Star&&(l&&(f.vertices=l),h&&(f.innerVerticeStep=h),p&&(f.innerRatio=p)),d&&i.setInfo(e.name,{...d,opt: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.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 y=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:y,isDrawing:!0})}if(!i){const y=Date.now();return y-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=y,{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 f=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:f,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){var v;const{workId:e,layer:s,isDrawing:i}=t;this.fullLayer.getElementsByName(e).map(R=>R.remove()),(v=this.drawLayer)==null||v.getElementsByName(e).map(R=>R.remove());const{strokeColor:r,fillColor:n,thickness:c,zIndex:l,vertices:h,scale:p,rotate:d,translate:f}=this.workOptions,u=s.worldScaling,{rect:y,pos:g,points:w}=this.computDrawPoints(c,h),M={close:!0,points:w,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0,lineJoin:"round"},T={name:e,id:e,zIndex:l,pos:g,anchor:[.5,.5],size:[y.w,y.h]};p&&(T.scale=p),d&&(T.rotate=d),f&&(T.translate=f);const S=new x.Group(T);if(i){const R=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(R)}const P=new x.Polyline({...M,pos:[0,0]});S.append(P),s.append(S);const k=S.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)}}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,f=n*r[0]*Math.cos(d),u=n*r[1]*Math.sin(d);c.push(f,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 A{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(...A.getBezierPoints(a,i,r,n,c)):i&&r&&n?e.push(...A.getBezierPoints(a,i,r,n)):i&&r?e.push(...A.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=A.oneBezier:s&&!i?r=A.twoBezier:s&&i&&(r=A.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 oe 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 y=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:y,isDrawing:!0})}if(!i){const y=Date.now();return y-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=y,{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 f=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:f,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){var P;const{workId:e,layer:s}=t;this.fullLayer.getElementsByName(e).map(k=>k.remove()),(P=this.drawLayer)==null||P.getElementsByName(e).map(k=>k.remove());const{strokeColor:i,fillColor:r,thickness:n,zIndex:c,placement:l,scale:h,rotate:p,translate:d}=this.workOptions,{rect:f,pos:u,points:y}=this.computDrawPoints(n,l),g={points:y.map(k=>k.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:[f.w,f.h]};h&&(w.scale=h),p&&(w.rotate=p),d&&(w.translate=d);const M=new x.Group(w),T=new x.Polyline({...g,pos:[0,0]});M.append(T),s.append(M);const S=M.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=A.getBezierPoints(10,l,i[0],h),d=o.Vec2d.Sub(i[1],new o.Vec2d(r,0,0)),f=o.Vec2d.Add(i[1],new o.Vec2d(0,n,0)),u=A.getBezierPoints(10,d,i[1],f),y=o.Vec2d.Sub(i[2],new o.Vec2d(0,n,0)),g=o.Vec2d.Sub(i[2],new o.Vec2d(r,0,0)),w=A.getBezierPoints(10,y,i[2],g),M=o.Vec2d.Add(i[3],new o.Vec2d(r,0,0)),T=o.Vec2d.Sub(i[3],new o.Vec2d(0,n,0)),S=A.getBezierPoints(10,M,i[3],T),P=r*(1-this.ratio)*10,k=n*(1-this.ratio)*10;switch(e){case"bottom":{const N=o.Vec2d.Sub(i[2],new o.Vec2d(r*5-P/2,0,0)),I=o.Vec2d.Sub(i[2],new o.Vec2d(r*5,-k,0)),L=o.Vec2d.Sub(i[2],new o.Vec2d(r*5+P/2,0,0));c.push(I,L,...S,...p,...u,...w,N);break}case"bottomRight":{const N=o.Vec2d.Sub(i[2],new o.Vec2d(r*1.1,0,0)),I=o.Vec2d.Sub(i[2],new o.Vec2d(r*1.1+P/2,-k,0)),L=o.Vec2d.Sub(i[2],new o.Vec2d(r*1.1+P,0,0));c.push(I,L,...S,...p,...u,...w,N);break}case"bottomLeft":{const N=o.Vec2d.Add(i[3],new o.Vec2d(r*1.1+P,0,0)),I=o.Vec2d.Add(i[3],new o.Vec2d(r*1.1+P/2,k,0)),L=o.Vec2d.Add(i[3],new o.Vec2d(r*1.1,0,0));c.push(I,L,...S,...p,...u,...w,N);break}case"top":{const N=o.Vec2d.Sub(i[1],new o.Vec2d(r*5-P/2,0,0)),I=o.Vec2d.Sub(i[1],new o.Vec2d(r*5,k,0)),L=o.Vec2d.Sub(i[1],new o.Vec2d(r*5+P/2,0,0));c.push(I,N,...u,...w,...S,...p,L);break}case"topRight":{const N=o.Vec2d.Sub(i[1],new o.Vec2d(r*1.1,0,0)),I=o.Vec2d.Sub(i[1],new o.Vec2d(r*1.1+P/2,k,0)),L=o.Vec2d.Sub(i[1],new o.Vec2d(r*1.1+P,0,0));c.push(I,N,...u,...w,...S,...p,L);break}case"topLeft":{const N=o.Vec2d.Add(i[0],new o.Vec2d(r*1.1+P,0,0)),I=o.Vec2d.Add(i[0],new o.Vec2d(r*1.1+P/2,-k,0)),L=o.Vec2d.Add(i[0],new o.Vec2d(r*1.1,0,0));c.push(I,N,...u,...w,...S,...p,L);break}case"left":{const N=o.Vec2d.Add(i[0],new o.Vec2d(0,n*5-k/2,0)),I=o.Vec2d.Add(i[0],new o.Vec2d(-P,n*5,0)),L=o.Vec2d.Add(i[0],new o.Vec2d(0,n*5+k/2,0));c.push(I,N,...p,...u,...w,...S,L);break}case"leftTop":{const N=o.Vec2d.Add(i[0],new o.Vec2d(0,n*1.1,0)),I=o.Vec2d.Add(i[0],new o.Vec2d(-P,n*1.1+k/2,0)),L=o.Vec2d.Add(i[0],new o.Vec2d(0,n*1.1+k,0));c.push(I,N,...p,...u,...w,...S,L);break}case"leftBottom":{const N=o.Vec2d.Sub(i[3],new o.Vec2d(0,n*1.1+k,0)),I=o.Vec2d.Sub(i[3],new o.Vec2d(P,n*1.1+k/2,0)),L=o.Vec2d.Sub(i[3],new o.Vec2d(0,n*1.1,0));c.push(I,N,...p,...u,...w,...S,L);break}case"right":{const N=o.Vec2d.Add(i[1],new o.Vec2d(0,n*5-k/2,0)),I=o.Vec2d.Add(i[1],new o.Vec2d(P,n*5,0)),L=o.Vec2d.Add(i[1],new o.Vec2d(0,n*5+k/2,0));c.push(I,L,...w,...S,...p,...u,N);break}case"rightTop":{const N=o.Vec2d.Add(i[1],new o.Vec2d(0,n*1.1,0)),I=o.Vec2d.Add(i[1],new o.Vec2d(P,n*1.1+k/2,0)),L=o.Vec2d.Add(i[1],new o.Vec2d(0,n*1.1+k,0));c.push(I,L,...w,...S,...p,...u,N);break}case"rightBottom":{const N=o.Vec2d.Sub(i[2],new o.Vec2d(0,n*1.1+k,0)),I=o.Vec2d.Sub(i[2],new o.Vec2d(-P,n*1.1+k/2,0)),L=o.Vec2d.Sub(i[2],new o.Vec2d(0,n*1.1,0));c.push(I,L,...w,...S,...p,...u,N);break}}const v=o.getRectFromPoints(this.tmpPoints,t),R=[Math.floor(v.x+v.w/2),Math.floor(v.y+v.h/2)];return{rect:v,pos:R,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 se 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=this.workOptions.uniformScale?o.EScaleType.proportional:o.EScaleType.all}consume(){return{type:o.EPostMessageType.None}}consumeAll(){return{type:o.EPostMessageType.None}}draw(t){var S;const{layer:e,workId:s,replaceId:i,imageBitmap:r,isMainThread:n}=t,{centerX:c,centerY:l,width:h,height:p,scale:d,rotate:f,translate:u,zIndex:y}=this.workOptions;this.fullLayer.getElementsByName(i||s).map(P=>P.remove()),(S=this.drawLayer)==null||S.getElementsByName(i||s).map(P=>P.remove());const g={anchor:[.5,.5],pos:[c,l],name:s,size:[h,p],zIndex:y};if(d)if(this.scaleType===o.EScaleType.proportional){const P=Math.min(d[0],d[1]);g.scale=[P,P]}else g.scale=d;u&&(g.translate=u),f&&(g.rotate=f);const w=new x.Group(g),M=new x.Sprite({anchor:[.5,.5],pos:[0,0],size:[h,p],texture:r,rotate:!n&&180||void 0});w.append(M),e.append(w);const T=w.getBoundingClientRect();if(T)return{x:Math.floor(T.x-E.SafeBorderPadding),y:Math.floor(T.y-E.SafeBorderPadding),w:Math.floor(T.width+E.SafeBorderPadding*2),h:Math.floor(T.height+E.SafeBorderPadding*2)}}consumeService(){}async consumeServiceAsync(t){var p,d,f,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 y=await i.preload({id:c,src:this.workOptions.src}),g=this.draw({workId:l,layer:h,replaceId:s,imageBitmap:y[0],isMainThread:r});return this.oldRect=l&&((f=(d=this.vNodes)==null?void 0:d.get(l))==null?void 0:f.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 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:f}=s,u=r&&o.cloneDeep(r)||i.get(e.name);if(!u)return;const y=e.parent;if(y){if(o.isNumber(f)&&(e.setAttribute("zIndex",f),u.opt.zIndex=f),o.isBoolean(d)&&(u.opt.locked=d),c&&h&&l){const{centerX:g,centerY:w,width:M,height:T,uniformScale:S}=u.opt;if(S){const v=Math.min(l[0],l[1]);u.opt.scale=[v,v]}else u.opt.scale=l;u.opt.width=Math.floor(M*l[0]),u.opt.height=Math.floor(T*l[1]);const P=[h[0]/y.worldScaling[0],h[1]/y.worldScaling[1]];u.opt.centerX=g+P[0],u.opt.centerY=w+P[1];const k=[u.centerPos[0]+P[0],u.centerPos[1]+P[1]];if(u.centerPos=k,r){let v=o.getRectScaleed(u.rect,l);v=o.getRectTranslated(v,P),u.rect=v}}else if(n){const g=[n[0]/y.worldScaling[0],n[1]/y.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)&&(e.setAttribute("rotate",p),u.opt.rotate=p,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 y=s?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:n,layer:y})}if(!i){const y=Date.now();return y-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=y,{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 f=o.computRect(d,this.oldRect);return this.oldRect=d,{rect:f,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){var T;const{workId:e,layer:s}=t;this.fullLayer.getElementsByName(e).map(S=>S.remove()),(T=this.drawLayer)==null||T.getElementsByName(e).map(S=>S.remove());const{strokeColor:i,thickness:r,zIndex:n,scale:c,rotate:l,translate:h}=this.workOptions,p=s.worldPosition,d=s.worldScaling,{d:f,rect:u}=this.computDrawPoints(r),y=[u.x+u.w/2,u.y+u.h/2],g={pos:y,name:e,id:e,d:f,fillColor:i,strokeColor:i,lineWidth:0,className:`${y[0]},${y[1]}`,normalize:!0,zIndex:n};c&&(g.scale=c),l&&(g.rotate=l),h&&(g.translate=h);const w=new x.Path(g);if(s.append(w),l||c||h){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)}}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:$(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:$(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 X 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}}draw(t){var y;const{workId:e,layer:s,isDrawLabel:i}=t;this.fullLayer.getElementsByName(e).map(g=>g.remove()),(y=this.drawLayer)==null||y.getElementsByName(e).map(g=>g.remove());const{boxSize:r,boxPoint:n,zIndex:c}=this.workOptions,l=s.worldPosition,h=s.worldScaling;if(!n||!r)return;const p=new x.Group({name:e,id:e,pos:[n[0]+r[0]/2,n[1]+r[1]/2],anchor:[.5,.5],size:r,zIndex:c}),d={x:n[0],y:n[1],w:r[0],h:r[1]},f=new x.Rect({normalize:!0,pos:[0,0],size:r}),u=i&&X.createLabels(this.workOptions,s)||[];return p.append(...u,f),s.append(p),{x:Math.floor(d.x*h[0]+l[0]),y:Math.floor(d.y*h[1]+l[1]),w:Math.floor(d.w*h[0]),h:Math.floor(d.h*h[1])}}consumeService(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=this.draw({workId:e,layer:n,isDrawLabel:r});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}updataOptService(t){var f,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=(f=this.vNodes)==null?void 0:f.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=this.draw({workId:e,layer:this.fullLayer,isDrawLabel:!1});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:f,boxSize:u,fontFamily:y,verticalAlign:g,fontColor:w,underline:M,lineThrough:T}=t,S=h||l*1.2,P=e&&e.parent.canvas.getContext("2d"),k=P&&X.getFontWidth({text:c,opt:t,ctx:P,worldScaling:e.worldScaling});if(k){const v={anchor:[0,.5],text:c,fontSize:l,lineHeight:S,fontFamily:y,fontWeight:p,fillColor:w,textAlign:d,fontStyle:f,name:n.toString(),className:"label"},R=[0,0];if(g==="middle"){const I=(r-1)/2;R[1]=(n-I)*S}d==="left"&&(R[0]=u&&-u[0]/2+5||0),v.pos=R;const N=new x.Label(v);if(s.push(N),M){const I={normalize:!1,pos:[v.pos[0],v.pos[1]+l/2],lineWidth:2*e.worldScaling[0],points:[0,0,k,0],strokeColor:w,name:`${n}_underline`,className:"underline"},L=new x.Polyline(I);s.push(L)}if(T){const I={normalize:!1,pos:v.pos,lineWidth:2*e.worldScaling[0],points:[0,0,k,0],strokeColor:w,name:`${n}_lineThrough`,className:"lineThrough"},L=new x.Polyline(I);s.push(L)}}}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:f,italic:u,lineThrough:y,underline:g,fontSize:w,textInfos:M}=s,T=r&&o.cloneDeep(r)||i.get(e.name);if(!T)return;const S=e.parent;if(!S)return;const P=T.opt;if(c&&P.fontColor&&(P.fontColor=c),n&&P.fontBgColor&&(P.fontBgColor=n),f&&(P.bold=f),u&&(P.italic=u),o.isBoolean(y)&&(P.lineThrough=y),o.isBoolean(g)&&(P.underline=g),w&&(P.fontSize=w),h&&d&&p){const k=M==null?void 0:M.get(e.name);if(k){const{fontSize:N,boxSize:I}=k;P.boxSize=I||P.boxSize,P.fontSize=N||P.fontSize}const v=T.rect,R=o.getRectTranslated(o.getRectScaleed(v,p),d);P.boxPoint=R&&[(R.x-S.worldPosition[0])/S.worldScaling[0],(R.y-S.worldPosition[1])/S.worldScaling[1]]}else if(l&&P.boxPoint){const k=[l[0]/S.worldScaling[0],l[1]/S.worldScaling[1]];P.boxPoint=[P.boxPoint[0]+k[0],P.boxPoint[1]+k[1]],T.centerPos=[T.centerPos[0]+k[0],T.centerPos[1]+k[1]],T.rect=o.getRectTranslated(T.rect,k)}return T&&i.setInfo(e.name,T),T==null?void 0:T.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(W){switch(W){case o.EToolsKey.Arrow:return Z;case o.EToolsKey.Pencil:return H;case o.EToolsKey.Straight:return ie;case o.EToolsKey.Ellipse:return J;case o.EToolsKey.Polygon:case o.EToolsKey.Triangle:return te;case o.EToolsKey.Star:case o.EToolsKey.Rhombus:return ee;case o.EToolsKey.Rectangle:return Q;case o.EToolsKey.SpeechBalloon:return oe;case o.EToolsKey.Text:return X;case o.EToolsKey.LaserPen:return j;case o.EToolsKey.Eraser:return Y;case o.EToolsKey.Selector:return C;case o.EToolsKey.Image:return se}}function q(W,a){const{toolsType:t,...e}=W;switch(t){case o.EToolsKey.Arrow:return new Z(e);case o.EToolsKey.Pencil:return new H(e);case o.EToolsKey.Straight:return new ie(e);case o.EToolsKey.Ellipse:return new J(e);case o.EToolsKey.Polygon:case o.EToolsKey.Triangle:return new te(e);case o.EToolsKey.Star:case o.EToolsKey.Rhombus:return new ee(e);case o.EToolsKey.Rectangle:return new Q(e);case o.EToolsKey.SpeechBalloon:return new oe(e);case o.EToolsKey.Text:return new X(e);case o.EToolsKey.LaserPen:return new j(e);case o.EToolsKey.Eraser:return new Y(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 se(e);default:return}}function ne(W){const a=[],t=["PATH","SPRITE","POLYLINE","RECT","ELLIPSE"];for(const e of W){if(e.tagName==="GROUP"&&e.children.length)return ne(e.children);e.tagName&&t.includes(e.tagName)&&a.push(e)}return a}const he=W=>{if(W.tagName==="GROUP"){const a=Object.getOwnPropertySymbols(W).find(t=>t.toString()==="Symbol(sealed)");if(a&&W[a])return!0}return!1},pe=W=>W!==o.EToolsKey.Text,G="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.toolsType)&&(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,isClearAll:!0,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 q({...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,f;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(!((f=this.serviceWorkShapes)!=null&&f.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),f=(l.animationWorkData||[]).slice(d,p);if((l.animationIndex||0)<p&&((s=l.node)==null||s.consumeService({op:f,isFullWork:!1}),l.animationIndex=p,f.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:f.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:f}=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]&&f===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(f=>{const u=this.vNodes.get(f);if(u){const{toolsType:y,op:g,opt:w}=u;l.set(f,{opt:w,toolsType:y,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:G,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 r;const e=this.setFullWork(a),s=a.ops&&o.transformToNormalData(a.ops),i=(r=a.workId)==null?void 0:r.toString();if(i&&e){e.toolsType===o.EToolsKey.Image&&t?await e.consumeServiceAsync({scene:t,isFullWork:!0,replaceId:i,isMainThread:!0}):e.consumeService({op:s,isFullWork:!0,replaceId:i}),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,undoTickerId:a.undoTickerId,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,i;for(const r of this.effectSelectNodeData.values()){const n=this.setFullWork(r);if(n){if(n.toolsType===o.EToolsKey.Image)await n.consumeServiceAsync({scene:(e=(t=this.thread.localLayer)==null?void 0:t.parent)==null?void 0:e.parent,isFullWork:!0,replaceId:(s=n.getWorkId())==null?void 0:s.toString(),isMainThread:!0});else{const c=r.ops&&o.transformToNormalData(r.ops);n.consumeService({op:c,isFullWork:!0,replaceId:(i=n.getWorkId())==null?void 0:i.toString()})}r!=null&&r.updateNodeOpt&&n.updataOptService(r.updateNodeOpt),r.workId&&this.workShapes.delete(r.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}]})}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,undoTickerId:a==null?void 0:a.undoTickerId,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(G),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 q({...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,f,u,y,g,w,M;this.animationId=void 0;let a=!1;const t=new Map;for(const[T,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((P,k)=>{var v;(v=P.selectIds)!=null&&v.includes(T)&&(this.willRunEffectSelectorIds.add(k),this.runEffect())}),this.workShapes.delete(T);break}case o.EToolsKey.Text:{S.node&&((i=S.node)==null||i.consumeService({op:S.animationWorkData||[],isFullWork:!0}),this.selectorWorkShapes.forEach((P,k)=>{var v;(v=P.selectIds)!=null&&v.includes(T)&&(this.willRunEffectSelectorIds.add(k),this.runEffect())}),(r=S.node)==null||r.clearTmpPoints(),this.workShapes.delete(T));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 P=!!S.ops;if((n=S.animationWorkData)!=null&&n.length){const k=S.oldRect;(c=S.node)==null||c.consumeService({op:S.animationWorkData,isFullWork:P}),P&&(this.selectorWorkShapes.forEach((v,R)=>{var N;(N=v.selectIds)!=null&&N.includes(T)&&(this.willRunEffectSelectorIds.add(R),this.runEffect())}),(l=S.node)==null||l.clearTmpPoints(),this.workShapes.delete(T)),t.set(T,{workState:k?S.ops?o.EvevtWorkState.Done:o.EvevtWorkState.Doing:o.EvevtWorkState.Start,op:S.animationWorkData.filter((v,R)=>{if(R%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:T}),(p=S.node)==null||p.updataOptService(S.updateNodeOpt),this.selectorWorkShapes.forEach((P,k)=>{var v;(v=P.selectIds)!=null&&v.includes(T)&&(this.willRunEffectSelectorIds.add(k),this.runEffect())}),(d=S.node)==null||d.clearTmpPoints(),this.workShapes.delete(T);else if(S.useAnimation){if(S.isDel){(f=S.node)==null||f.clearTmpPoints(),this.workShapes.delete(T);break}const P=3,k=this.computNextAnimationIndex(S,P),v=S.isDiff?0:Math.max(0,(S.animationIndex||0)-P),R=(S.animationWorkData||[]).slice(v,k),N=(y=(u=S.node)==null?void 0:u.getWorkId())==null?void 0:y.toString();if((S.animationIndex||0)<k||S.isDiff){if((g=S.node)==null||g.consumeService({op:R,isFullWork:!1}),S.animationIndex=k,S.isDiff&&(S.isDiff=!1),R.length){const I=R.filter((L,D)=>{if(D%P!==P-1)return!0}).slice(-2);t.set(T,{workState:v===0?o.EvevtWorkState.Start:k===((w=S.animationWorkData)==null?void 0:w.length)?o.EvevtWorkState.Done:o.EvevtWorkState.Doing,op:I})}}else S.ops&&((M=S.node)==null||M.consumeService({op:S.animationWorkData||[],isFullWork:!0,replaceId:N}),S.isDel=!0,t.set(T,{workState:o.EvevtWorkState.Done,op:R.filter((I,L)=>{if(L%P!==P-1)return!0}).slice(-2)}));a=!0;break}break}}if(a&&this.runAnimation(),t.size){const T=[];t.forEach((S,P)=>{T.push({type:o.EPostMessageType.Cursor,uid:P.split(o.Storage_Splitter)[0],op:S.op,workState:S.workState,viewId:this.thread.viewId})}),this.thread.post({sp:T})}}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 f,u,y,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=(f=this.vNodes.get(h))==null?void 0:f.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)),(y=this.workShapes)==null||y.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=q({toolsType:t,toolsOpt:e,vNodes:this.vNodes,fullLayer:this.thread.fullLayer,drawLayer:this.thread.serviceLayer},this),a}}class B{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 B{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 B{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 B{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 B{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,f=s.sp||[];if(d===o.EvevtWorkState.Start)return{sp:[],render:[]};const u=n==null?void 0:n.selectRect;if(c){d===o.EvevtWorkState.Doing&&f.push({type:o.EPostMessageType.Select,selectIds:r.selectIds,selectRect:u,willSyncService:!0,isSync:!0,points:r.getChildrenPoints(),textOpt:r.textOpt});for(const[y,g]of i.entries())p&&g.toolsType===o.EToolsKey.Text?f.push({...g,workId:y,type:o.EPostMessageType.TextUpdate,dataType:o.EDataType.Local,willSyncService:!0}):f.push({...g,workId:y,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l})}return{sp:f}}}class Te extends B{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 f=this.commandDeleteText(p);f&&i.push(f)}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,undoTickerId:t.undoTickerId}),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 B{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||[],f=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:f,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:f,willSyncService:!1,isSync:!0,points:i.getChildrenPoints(),textOpt:i.textOpt});for(const[u,y]of n.entries())y.toolsType===o.EToolsKey.Text?d.push({...y,workId:u,type:o.EPostMessageType.TextUpdate,dataType:o.EDataType.Local,willSyncService:!0}):d.push({...y,workId:u,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:!0})}return{sp:d}}}class Pe extends B{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,f=s.sp||[],u=r==null?void 0:r.selectRect;if(l){h&&d===o.EvevtWorkState.Done&&f.push({type:o.EPostMessageType.Select,selectIds:i.selectIds,selectRect:u,willSyncService:!0,isSync:p,points:i.getChildrenPoints()});for(const[y,g]of n.entries())f.push({...g,workId:y,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:p})}return{sp:f}}}class Ee extends B{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||[],f=n==null?void 0:n.selectRect;if(c&&d){h.fontSize&&d.push({type:o.EPostMessageType.Select,selectIds:r.selectIds,selectRect:f,willSyncService:c,isSync:l,points:r.getChildrenPoints()});for(const[u,y]of i.entries())p&&y.toolsType===o.EToolsKey.Text?d.push({...y,workId:u,type:o.EPostMessageType.TextUpdate,dataType:o.EDataType.Local,willSyncService:!0}):d.push({...y,workId:u,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l})}return{sp:d}}}class ve extends B{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,f]of i.entries())h.push({...f,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 B{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[f,u]of i.entries())p.push({...u,workId:f,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 B{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 Me{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 Ee;case o.EmitEventType.SetPoint:return new ve;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 We{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 Me([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){const{undoTickerId:e}=a;if(!await this.methodBuilder.consumeForMainThread(a)){const{msgType:s,toolsType:i,opt:r,dataType:n,workId:c,workState:l}=a;switch(s){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(n===o.EDataType.Local&&i&&r){const h={toolsType:i,toolsOpt:r};this.localWork.setToolsOpt(h)}break;case o.EPostMessageType.CreateWork:if(c&&r&&i){if(i===o.EToolsKey.LaserPen){this.topWork.getTmpWorkShapeNode()||this.topWork.setToolsOpt({toolsType:i,toolsOpt:r}),this.topWork.setWorkOptions(c,r);break}this.localWork.getTmpWorkShapeNode()||this.localWork.setToolsOpt({toolsType:i,toolsOpt:r}),this.localWork.setWorkOptions(c,r)}break;case o.EPostMessageType.DrawWork:l===o.EvevtWorkState.Done&&n===o.EDataType.Local?this.consumeDrawAll(n,a):this.consumeDraw(n,a);break;case o.EPostMessageType.UpdateNode:case o.EPostMessageType.FullWork:if(i===o.EToolsKey.LaserPen){this.consumeDrawAll(n,a);break}this.consumeFull(n,a);break;case o.EPostMessageType.RemoveNode:this.removeNode(a);return;case o.EPostMessageType.Select:n===o.EDataType.Service&&(c===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:n===o.EDataType.Local&&this.localWork.checkTextActive(a);break}}e&&this.post({sp:[{type:o.EPostMessageType.None,undoTickerId:e}]})}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(G);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 a.contextType&&delete a.contextType,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 Le{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 q({...a,fullLayer:this.fullLayer,drawLayer:this.fullLayer})}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,t){var i,r;const e=this.setFullWork(a),s=a.ops&&o.transformToNormalData(a.ops);if(e){let n;e.toolsType===o.EToolsKey.Image?n=await e.consumeServiceAsync({isFullWork:!0,scene:(i=this.fullLayer.parent)==null?void 0:i.parent,isMainThread:!0}):n=e.consumeService({op:s,isFullWork:!0,replaceId:(r=e.getWorkId())==null?void 0:r.toString(),isDrawLabel:t});const c=(a==null?void 0:a.updateNodeOpt)&&e.updataOptService(a.updateNodeOpt);return a.workId&&this.workShapes.delete(a.workId),c||n}}async getSnapshot(a){const{scenePath:t,scenes:e,cameraOpt:s,w:i,h:r,maxZIndex:n}=a;if(t&&e&&s){this.setCameraOpt(s);let c;const l=new Map;for(const[p,d]of Object.entries(e))if(d!=null&&d.type)switch(d==null?void 0:d.type){case o.EPostMessageType.UpdateNode:case o.EPostMessageType.FullWork:{const{toolsType:f,opt:u}=d;f===o.EToolsKey.Text&&u&&(u.zIndex=u.zIndex+(n||0),(u.lineThrough||u.underline)&&l.set(p,d));const y=await this.runFullWork({...d,opt:u,workId:p,msgType:o.EPostMessageType.FullWork,dataType:o.EDataType.Service,viewId:this.viewId},f===o.EToolsKey.Text);c=o.computRect(c,y);break}}let h;i&&r&&(h={resizeWidth:i,resizeHeight:r}),l.size&&(await new Promise(p=>{setTimeout(p,500)}),this.willRenderSpecialLabel(l)),await this.getSnapshotRender({scenePath:t,options:h})}}updateLabels(a,t){a.children.forEach(e=>{if(e.tagName==="LABEL"){const s=e.name,{width:i}=e.getBoundingClientRect(),[r]=a.worldScaling,{underline:n,lineThrough:c}=t.opt;n&&a.getElementsByName(`${s}_underline`)[0].attr({points:[0,0,i/r,0]}),c&&a.getElementsByName(`${s}_lineThrough`)[0].attr({points:[0,0,i/r,0]})}})}willRenderSpecialLabel(a){var t;for(const[e,s]of a.entries()){const i=(t=this.fullLayer)==null?void 0:t.getElementsByName(e)[0];i&&s.opt&&this.updateLabels(i,s)}}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 Re{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 We(a,t)}createSnapshotThread(a,t){return new Le(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:f}=r;if(n===o.EPostMessageType.Init){const y=(t=this.master.control.viewContainerManager.getView(c))==null?void 0:t.displayer,g=y==null?void 0:y.canvasContainerRef.current;if(y&&g&&p&&d){const w=this.createMainThread(c,{displayer:y,container:g,layerOpt:p,master:this.master,canvasOpt:d,post:this.post.bind(this)});this.mainThreadMap.set(c,w),w&&f&&w.setCameraOpt(f)}continue}if((n===o.EPostMessageType.Snapshot||n===o.EPostMessageType.BoundingBox)&&c===((e=this.master.control.viewContainerManager.mainView)==null?void 0:e.id)){const y=(s=this.master.control.viewContainerManager.getView(c))==null?void 0:s.displayer,g=(i=y.snapshotContainerRef)==null?void 0:i.current;if(y&&g&&f){g.style.width=`${f.width}px`,g.style.height=`${f.height}px`;const w={...o.ViewContainerManager.defaultLayerOpt,offscreen:!1,width:f.width,height:f.height},M={...o.ViewContainerManager.defaultScreenCanvasOpt,width:f.width,height:f.height};this.snapshotThread=this.createSnapshotThread(c,{displayer:y,container:g,layerOpt:w,master:this.master,canvasOpt:M,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[y,g]of this.mainThreadMap.entries()){const w=l.get(y);w&&g.on(w,h)}continue}if(c===o.Storage_ViewId_ALL){for(const y of this.mainThreadMap.values())y.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=Re;
|
package/dist/index.d.ts
CHANGED
|
@@ -35,13 +35,14 @@ export declare abstract class BaseApplianceManager {
|
|
|
35
35
|
readonly worker: MasterControlForWorker;
|
|
36
36
|
abstract readonly viewContainerManager: ViewContainerManager;
|
|
37
37
|
constructor(params: BaseApplianceManagerProps);
|
|
38
|
+
hasOffscreenCanvas(): boolean;
|
|
38
39
|
bindPlugin(plugin: AppliancePluginLike): void;
|
|
39
40
|
/** 激活 plugin */
|
|
40
41
|
abstract activePlugin(): void;
|
|
41
42
|
/** 初始化 */
|
|
42
43
|
abstract init(): void;
|
|
43
44
|
/** 激活worker */
|
|
44
|
-
abstract activeWorker(): void
|
|
45
|
+
abstract activeWorker(): Promise<void>;
|
|
45
46
|
/** 销毁 */
|
|
46
47
|
destroy(): void;
|
|
47
48
|
/** 清空当前获焦路径下的所有内容 */
|
|
@@ -62,7 +63,7 @@ export declare abstract class BaseApplianceManager {
|
|
|
62
63
|
toolsOpt: BaseShapeOptions;
|
|
63
64
|
};
|
|
64
65
|
/** 激活当前view容器*/
|
|
65
|
-
|
|
66
|
+
effectViewContainer(toolsKey: EToolsKey): void;
|
|
66
67
|
internalSceneChange: (viewId: string, scenePath: string) => void;
|
|
67
68
|
internalCameraChange: (viewId: string, cameraOpt: ICameraOpt) => void;
|
|
68
69
|
/** 异步获取指定路径下绘制内容的区域大小 */
|
|
@@ -71,7 +72,6 @@ export declare abstract class BaseApplianceManager {
|
|
|
71
72
|
screenshotToCanvas(context: CanvasRenderingContext2D, scenePath: string, width?: number, height?: number, camera?: Camera, originX?: number, originY?: number): Promise<void>;
|
|
72
73
|
/** 异步获取指定路径下的缩略图 */
|
|
73
74
|
scenePreview(scenePath: string, img: HTMLImageElement): Promise<void>;
|
|
74
|
-
setOriginMemberState(): void;
|
|
75
75
|
/** 切换到选择工具 */
|
|
76
76
|
switchToSelector(): void;
|
|
77
77
|
/** 开始执行副作用 */
|
|
@@ -34,7 +34,7 @@ export declare abstract class ViewContainerManager {
|
|
|
34
34
|
undo(): number;
|
|
35
35
|
redo(): number;
|
|
36
36
|
protected validator(target: ViewInfo, key: string, value: any): void;
|
|
37
|
-
abstract mountView(viewIde: string): void
|
|
37
|
+
abstract mountView(viewIde: string): Promise<void>;
|
|
38
38
|
destroyAppView(viewId: string, justLocal?: boolean): void;
|
|
39
39
|
createMianView(originMainView: ViewInfo): void;
|
|
40
40
|
createAppView(originAppView: ViewInfo): void;
|
|
@@ -75,11 +75,12 @@ export declare abstract class AppViewDisplayerManager {
|
|
|
75
75
|
readonly commiter: UndoRedoMethod;
|
|
76
76
|
abstract vDom?: BaseViewDisplayer;
|
|
77
77
|
abstract eventTragetElement?: HTMLDivElement;
|
|
78
|
+
abstract canvasContainerRef: React.RefObject<HTMLDivElement>;
|
|
79
|
+
abstract canvasTopRef: React.RefObject<HTMLCanvasElement>;
|
|
78
80
|
abstract canvasServiceFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
79
81
|
abstract canvasFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
80
82
|
abstract canvasBgRef: React.RefObject<HTMLCanvasElement>;
|
|
81
83
|
abstract floatBarRef: React.RefObject<HTMLDivElement>;
|
|
82
|
-
abstract floatBarCanvasRef: React.RefObject<HTMLCanvasElement>;
|
|
83
84
|
abstract containerOffset: {
|
|
84
85
|
x: number;
|
|
85
86
|
y: number;
|
|
@@ -130,11 +131,13 @@ export declare abstract class MainViewDisplayerManager {
|
|
|
130
131
|
abstract height: number;
|
|
131
132
|
abstract vDom?: BaseViewDisplayer;
|
|
132
133
|
abstract eventTragetElement?: HTMLDivElement;
|
|
134
|
+
abstract snapshotContainerRef?: React.RefObject<HTMLDivElement>;
|
|
135
|
+
abstract canvasContainerRef: React.RefObject<HTMLDivElement>;
|
|
136
|
+
abstract canvasTopRef: React.RefObject<HTMLCanvasElement>;
|
|
133
137
|
abstract canvasServiceFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
134
138
|
abstract canvasFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
135
139
|
abstract canvasBgRef: React.RefObject<HTMLCanvasElement>;
|
|
136
140
|
abstract floatBarRef: React.RefObject<HTMLDivElement>;
|
|
137
|
-
abstract floatBarCanvasRef: React.RefObject<HTMLCanvasElement>;
|
|
138
141
|
abstract containerOffset: {
|
|
139
142
|
x: number;
|
|
140
143
|
y: number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ECanvasContextType } from "../core/enum";
|
|
2
|
+
export declare const DefaultAppliancePluginOptions: {
|
|
3
|
+
syncOpt: {
|
|
4
|
+
interval: number;
|
|
5
|
+
};
|
|
6
|
+
canvasOpt: {
|
|
7
|
+
contextType: ECanvasContextType;
|
|
8
|
+
};
|
|
9
|
+
cdn: {
|
|
10
|
+
fullWorkerUrl: string;
|
|
11
|
+
subWorkerUrl: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -6,11 +6,13 @@ export interface BaseDisplayerProps {
|
|
|
6
6
|
viewId: string;
|
|
7
7
|
maranger: ApplianceViewManagerLike;
|
|
8
8
|
refs: {
|
|
9
|
+
snapshotContainerRef?: React.RefObject<HTMLDivElement>;
|
|
10
|
+
canvasContainerRef: React.RefObject<HTMLDivElement>;
|
|
9
11
|
canvasServiceFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
10
12
|
canvasFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
11
13
|
canvasBgRef: React.RefObject<HTMLCanvasElement>;
|
|
14
|
+
canvasTopRef: React.RefObject<HTMLCanvasElement>;
|
|
12
15
|
floatBarRef: React.RefObject<HTMLDivElement>;
|
|
13
|
-
floatBarCanvasRef: React.RefObject<HTMLCanvasElement>;
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
export interface BaseDisplayerState {
|
|
@@ -18,23 +20,15 @@ export interface BaseDisplayerState {
|
|
|
18
20
|
zIndex: number;
|
|
19
21
|
floatBarData?: ShowFloatBarMsgValue;
|
|
20
22
|
dpr: number;
|
|
21
|
-
position?: {
|
|
22
|
-
x: number;
|
|
23
|
-
y: number;
|
|
24
|
-
};
|
|
25
23
|
operationType: EmitEventType;
|
|
26
24
|
angle: number;
|
|
27
25
|
scale: [number, number];
|
|
28
26
|
editors?: Map<string, TextEditorInfo>;
|
|
29
27
|
activeTextId?: string;
|
|
30
28
|
}
|
|
31
|
-
export declare const DisplayerContext: React.Context<Pick<BaseDisplayerState, "scale" | "zIndex" | "dpr" | "
|
|
29
|
+
export declare const DisplayerContext: React.Context<Pick<BaseDisplayerState, "scale" | "zIndex" | "dpr" | "angle" | "floatBarData" | "operationType"> & {
|
|
32
30
|
maranger?: ApplianceViewManagerLike | undefined;
|
|
33
31
|
floatBarColors: [number, number, number][];
|
|
34
|
-
setPosition: (point: {
|
|
35
|
-
x: number;
|
|
36
|
-
y: number;
|
|
37
|
-
}) => void;
|
|
38
32
|
setAngle: (angle: number) => void;
|
|
39
33
|
setOperationType: (type: EmitEventType) => void;
|
|
40
34
|
setFloatBarData: (data: Partial<ShowFloatBarMsgValue>) => void;
|
|
@@ -48,7 +42,6 @@ export declare class BaseViewDisplayer extends React.Component<BaseDisplayerProp
|
|
|
48
42
|
setActiveTextEditor(activeTextId?: string): void;
|
|
49
43
|
setFloatZIndex(zIndex: number): void;
|
|
50
44
|
setFloatBarData(data: Partial<ShowFloatBarMsgValue>): void;
|
|
51
|
-
private setPosition;
|
|
52
45
|
private setAngle;
|
|
53
46
|
private setOperationType;
|
|
54
47
|
render(): ReactNode;
|
|
@@ -11,7 +11,7 @@ export declare class ViewContainerMultiManager extends ViewContainerManager {
|
|
|
11
11
|
tmpFocusedViewId?: string;
|
|
12
12
|
private checkScaleTimer?;
|
|
13
13
|
constructor(props: BaseSubWorkModuleProps);
|
|
14
|
-
mountView(viewId: string): void
|
|
14
|
+
mountView(viewId: string): Promise<void>;
|
|
15
15
|
listenerWindowManager(windowManager: WindowManager): void;
|
|
16
16
|
private onMainViewRelease;
|
|
17
17
|
onMainViewMounted: (bindMainView: View) => void;
|
|
@@ -9,11 +9,12 @@ export declare class AppViewDisplayerManagerImpl extends AppViewDisplayerManager
|
|
|
9
9
|
height: number;
|
|
10
10
|
vDom?: BaseViewDisplayer;
|
|
11
11
|
eventTragetElement?: HTMLDivElement;
|
|
12
|
+
canvasContainerRef: React.RefObject<HTMLDivElement>;
|
|
13
|
+
canvasTopRef: React.RefObject<HTMLCanvasElement>;
|
|
12
14
|
canvasServiceFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
13
15
|
canvasFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
14
16
|
canvasBgRef: React.RefObject<HTMLCanvasElement>;
|
|
15
17
|
floatBarRef: React.RefObject<HTMLDivElement>;
|
|
16
|
-
floatBarCanvasRef: React.RefObject<HTMLCanvasElement>;
|
|
17
18
|
containerOffset: {
|
|
18
19
|
x: number;
|
|
19
20
|
y: number;
|
|
@@ -9,11 +9,13 @@ export declare class MainViewMultiDisplayerManager extends MainViewDisplayerMana
|
|
|
9
9
|
dpr: number;
|
|
10
10
|
vDom?: BaseViewDisplayer;
|
|
11
11
|
eventTragetElement?: HTMLDivElement;
|
|
12
|
+
snapshotContainerRef?: React.RefObject<HTMLDivElement>;
|
|
13
|
+
canvasContainerRef: React.RefObject<HTMLDivElement>;
|
|
14
|
+
canvasTopRef: React.RefObject<HTMLCanvasElement>;
|
|
12
15
|
canvasServiceFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
13
16
|
canvasFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
14
17
|
canvasBgRef: React.RefObject<HTMLCanvasElement>;
|
|
15
18
|
floatBarRef: React.RefObject<HTMLDivElement>;
|
|
16
|
-
floatBarCanvasRef: React.RefObject<HTMLCanvasElement>;
|
|
17
19
|
containerOffset: {
|
|
18
20
|
x: number;
|
|
19
21
|
y: number;
|
|
@@ -8,6 +8,6 @@ export declare class ApplianceSingleManager extends BaseApplianceManager {
|
|
|
8
8
|
constructor(params: BaseApplianceManagerProps);
|
|
9
9
|
init(): void;
|
|
10
10
|
activePlugin(): void;
|
|
11
|
-
activeWorker(): void
|
|
11
|
+
activeWorker(): Promise<void>;
|
|
12
12
|
onCameraChange: import("lodash").DebouncedFunc<(cameraState: CameraState) => void>;
|
|
13
13
|
}
|
|
@@ -10,11 +10,13 @@ export declare class MainViewSingleDisplayerManager extends MainViewDisplayerMan
|
|
|
10
10
|
vDom?: BaseViewDisplayer;
|
|
11
11
|
viewId: string;
|
|
12
12
|
eventTragetElement?: HTMLDivElement;
|
|
13
|
+
snapshotContainerRef?: React.RefObject<HTMLDivElement>;
|
|
14
|
+
canvasContainerRef: React.RefObject<HTMLDivElement>;
|
|
15
|
+
canvasTopRef: React.RefObject<HTMLCanvasElement>;
|
|
13
16
|
canvasServiceFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
14
17
|
canvasFloatRef: React.RefObject<HTMLCanvasElement>;
|
|
15
18
|
canvasBgRef: React.RefObject<HTMLCanvasElement>;
|
|
16
19
|
floatBarRef: React.RefObject<HTMLDivElement>;
|
|
17
|
-
floatBarCanvasRef: React.RefObject<HTMLCanvasElement>;
|
|
18
20
|
containerOffset: {
|
|
19
21
|
x: number;
|
|
20
22
|
y: number;
|
package/dist/plugin/types.d.ts
CHANGED
|
@@ -128,8 +128,8 @@ export type ApplianceAdaptor = {
|
|
|
128
128
|
export type canBindMethodType = keyof Omit<AppliancePluginInstance, 'displayer' | 'windowManager' | 'injectMethodToObject' | 'callbacksOn' | 'callbacksOnce' | 'callbacksOff' | '_injectTargetObject'>;
|
|
129
129
|
export interface AppliancePluginInstance {
|
|
130
130
|
readonly displayer: Displayer;
|
|
131
|
+
readonly currentManager?: ApplianceManagerLike;
|
|
131
132
|
readonly windowManager?: WindowManager;
|
|
132
|
-
readonly _injectTargetObject: any;
|
|
133
133
|
/**
|
|
134
134
|
* 获取某个场景里包含所有元素的矩形
|
|
135
135
|
*/
|
|
@@ -173,7 +173,6 @@ export interface AppliancePluginInstance {
|
|
|
173
173
|
/** 清空当前场景 */
|
|
174
174
|
cleanCurrentScene(retainPpt?: boolean): void;
|
|
175
175
|
/** 把指定的方法注入到指定对象上 */
|
|
176
|
-
injectMethodToObject(object: WindowManager | Room | View, methodName: canBindMethodType): void;
|
|
177
176
|
/** 销毁 */
|
|
178
177
|
destroy(): void;
|
|
179
178
|
/** setMemberState */
|