@netless/appliance-plugin 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -10
- package/cdn/cdn.js +1 -1
- package/cdn/fullWorker-6Cu08P.js +438 -0
- package/cdn/subWorker-B3CHpe.js +438 -0
- package/dist/appliance-plugin.js +1 -1
- package/dist/appliance-plugin.mjs +12 -11
- package/dist/collector/base.d.ts +3 -1
- package/dist/collector/collector.d.ts +5 -4
- package/dist/collector/eventCollector.d.ts +2 -1
- package/dist/collector/magixEventCollector.d.ts +30 -0
- package/dist/collector/types.d.ts +27 -7
- package/dist/component/textEditor/manager.d.ts +2 -2
- package/dist/component/textEditor/types.d.ts +0 -1
- package/dist/component/textEditor/view.d.ts +4 -1
- package/dist/core/const.d.ts +2 -0
- package/dist/core/enum.d.ts +12 -5
- package/dist/core/mainEngine.d.ts +31 -10
- package/dist/core/mainThread/base.d.ts +6 -2
- package/dist/core/mainThread/snapshotThread.d.ts +3 -3
- package/dist/core/mainThread/subLocalThread.d.ts +18 -10
- package/dist/core/mainThread/subServiceThread.d.ts +2 -1
- package/dist/core/mainThread/subTopThread.d.ts +15 -8
- package/dist/core/msgEvent/deleteNode/forMainThread.d.ts +1 -5
- package/dist/core/msgEvent/deleteNode/forWorker.d.ts +1 -5
- package/dist/core/msgEvent/scaleNode/forMain.d.ts +1 -0
- package/dist/core/msgEvent/setFont/forMain.d.ts +2 -1
- package/dist/core/tools/arrow.d.ts +36 -7
- package/dist/core/tools/base.d.ts +22 -8
- package/dist/core/tools/ellipse.d.ts +36 -7
- package/dist/core/tools/eraser.d.ts +40 -4
- package/dist/core/tools/image.d.ts +9 -5
- package/dist/core/tools/laserPen.d.ts +34 -4
- package/dist/core/tools/pencil.d.ts +37 -4
- package/dist/core/tools/polygon.d.ts +36 -7
- package/dist/core/tools/rectangle.d.ts +36 -7
- package/dist/core/tools/selector.d.ts +52 -4
- package/dist/core/tools/speechBalloon.d.ts +36 -8
- package/dist/core/tools/star.d.ts +36 -7
- package/dist/core/tools/straight.d.ts +36 -7
- package/dist/core/tools/text.d.ts +20 -10
- package/dist/core/tools/utils.d.ts +6 -5
- package/dist/core/types.d.ts +1 -1
- package/dist/core/utils/index.d.ts +10 -0
- package/dist/core/utils/math.d.ts +1 -0
- package/dist/core/{mainThread/vNodeManager.d.ts → vNodeManager.d.ts} +9 -3
- package/dist/core/worker/base.d.ts +18 -16
- package/dist/core/worker/fullWorkerLocal.d.ts +18 -9
- package/dist/core/worker/fullWorkerService.d.ts +10 -9
- package/dist/core/worker/subWorkerLocal.d.ts +5 -8
- package/dist/core/worker/subWorkerTopLayer.d.ts +13 -9
- package/dist/core/worker/workerManager.d.ts +18 -10
- package/dist/cursors/index.d.ts +44 -18
- package/dist/fullWorker.js +131 -146
- package/dist/index-CeTiLZdq.mjs +5619 -0
- package/dist/index-DHkeFixk.js +1 -0
- package/dist/index-DmkMw23K.mjs +9486 -0
- package/dist/index-Dmq7rqSP.js +1 -0
- package/dist/plugin/applianceSinglePlugin.d.ts +1 -0
- package/dist/plugin/baseApplianceManager.d.ts +7 -1
- package/dist/plugin/baseViewContainerManager.d.ts +0 -3
- package/dist/plugin/const.d.ts +11 -1
- package/dist/plugin/displayerView.d.ts +1 -3
- package/dist/plugin/multi/containerManager.d.ts +2 -1
- package/dist/style.css +1 -1
- package/dist/subWorker.js +131 -146
- package/package.json +3 -4
- package/cdn/fullWorker-CIvt1j.js +0 -453
- package/cdn/subWorker-BE-0dg.js +0 -453
- package/dist/core/worker/vNodeManager.d.ts +0 -34
- package/dist/index-BcIJbozZ.js +0 -1
- package/dist/index-C1YKkWHE.mjs +0 -9090
- package/dist/index-ClJPZxV-.mjs +0 -5462
- package/dist/index-SsMz_ohn.js +0 -1
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Group, Scene } from "spritejs";
|
|
2
|
-
import { BaseNodeMapItem, IRectType } from "../types";
|
|
3
|
-
export declare class VNodeManager {
|
|
4
|
-
viewId: string;
|
|
5
|
-
scene: Scene;
|
|
6
|
-
scenePath?: string;
|
|
7
|
-
fullLayer?: Group;
|
|
8
|
-
curNodeMap: Map<string, BaseNodeMapItem>;
|
|
9
|
-
targetNodeMap: Map<string, BaseNodeMapItem>[];
|
|
10
|
-
constructor(viewId: string, scene: Scene);
|
|
11
|
-
init(fullLayer: Group): void;
|
|
12
|
-
get(name: string): BaseNodeMapItem | undefined;
|
|
13
|
-
hasRenderNodes(): boolean;
|
|
14
|
-
has(name: string): boolean;
|
|
15
|
-
setInfo(name: string, info: Partial<BaseNodeMapItem>): void;
|
|
16
|
-
selected(name: string): void;
|
|
17
|
-
unSelected(name: string): void;
|
|
18
|
-
delete(name: string): void;
|
|
19
|
-
clear(): void;
|
|
20
|
-
hasRectIntersectRange(rect: IRectType, filterLock?: boolean): boolean;
|
|
21
|
-
getRectIntersectRange(rect: IRectType, filterLock?: boolean): {
|
|
22
|
-
rectRange: IRectType | undefined;
|
|
23
|
-
nodeRange: Map<string, BaseNodeMapItem>;
|
|
24
|
-
};
|
|
25
|
-
getNodeRectFormShape(name: string, value: BaseNodeMapItem): IRectType | undefined;
|
|
26
|
-
updateNodesRect(): void;
|
|
27
|
-
combineIntersectRect(rect: IRectType): IRectType;
|
|
28
|
-
setTarget(): number;
|
|
29
|
-
getLastTarget(): Map<string, BaseNodeMapItem>;
|
|
30
|
-
deleteLastTarget(): void;
|
|
31
|
-
getTarget(i: number): Map<string, BaseNodeMapItem>;
|
|
32
|
-
deleteTarget(i: number): void;
|
|
33
|
-
clearTarget(): void;
|
|
34
|
-
}
|
package/dist/index-BcIJbozZ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var ae=Object.defineProperty;var ce=(R,a,t)=>a in R?ae(R,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):R[a]=t;var m=(R,a,t)=>(ce(R,typeof a!="symbol"?a+"":a,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index-SsMz_ohn.js"),x=require("spritejs"),le=require("lineclip");require("lz-string");require("white-web-sdk");require("react-dom");require("react");require("lodash");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}}replace(a,t,e){var n;const s=a.getElementsByName(t),i=s.length;if(i){if(i>1)for(let c=1;c<s.length;c++)s[c].remove();a.replaceChild(e,s[0])}else a.append(e);this.fullLayer===a?(n=this.drawLayer)==null||n.getElementsByName(t).forEach(c=>{c.remove()}):this.fullLayer.getElementsByName(t).forEach(c=>{c.remove()})}static updateNodeOpt(a){const{node:t,opt:e,vNodes:s,willSerializeData:i,targetNode:r}=a,{zIndex:n,translate:c,angle:l,box:h,boxScale:p,boxTranslate:d,pointMap: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:S}=y,N=[];for(let M=0;M<y.op.length;M+=3)N.push(new o.Point2d(y.op[M],y.op[M+1],y.op[M+2]));const P=o.getRectFromPoints(N),w=[P.w*g.worldScaling[0],P.h*g.worldScaling[0]],I=[S.w-w[0],S.h-w[1]],k=[(S.w*p[0]-I[0])/w[0],(S.h*p[1]-I[1])/w[1]],E=[d[0]/g.worldScaling[0],d[1]/g.worldScaling[1]],L=y.op.map((M,D)=>{const b=D%3;return b===0?M+E[0]:b===1?M+E[1]:M}),T=[y.centerPos[0]+E[0],y.centerPos[1]+E[1]];o.scalePoints(L,T,k);const W=[];for(let M=0;M<L.length;M+=3)W.push(new o.Point2d(L[M],L[M+1],L[M+2]));y.op=L,y.centerPos=T}else if(c)if(t.setAttribute("translate",c),y.opt.translate=c,r){const S=[c[0]*g.worldScaling[0],c[1]*g.worldScaling[1]];u=o.getRectTranslated(y.rect,S),y.rect=u}else{const S=O.getRectFromLayer(g,t.name);y.rect=S||y.rect}else if(o.isNumber(l))if(t.setAttribute("rotate",l),y.opt.rotate=l,r)u=o.getRectRotated(y.rect,l),y.rect=u;else{const S=O.getRectFromLayer(g,t.name);y.rect=S||y.rect}if(f){const S=f.get(t.name);if(S)for(let N=0,P=0;N<y.op.length;N+=3,P++)y.op[N]=S[P][0],y.op[N+1]=S[P][1]}if(i){if(c){const S=[c[0],c[1]],N=y.op.map((P,w)=>{const I=w%3;return I===0?P+S[0]:I===1?P+S[1]:P});y.op=N,y.centerPos=[y.centerPos[0]+S[0],y.centerPos[1]+S[1]],y!=null&&y.opt&&(y.opt.translate=void 0)}else if(o.isNumber(l)){const S=y.op;o.rotatePoints(S,y.centerPos,l),y.op=S,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 v=O;function X(R,a=!0){const t=R.length;if(t<2)return"";let e=R[0],s=R[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=R[r],s=R[r+1],i+=o.average(e,s);return a?`M${o.average(R[0],R[1])}Q${o.precise(R[1])}${o.average(R[1],R[2])}T${i}${o.average(R[t-1],R[0])}${o.average(R[0],R[1])}Z`:`M${o.precise(R[0])}Q${o.precise(R[1])}${o.average(R[1],R[2])}${R.length>3?"T":""}${i}L${o.precise(R[t-1])}`}class j extends v{constructor(t){super(t);m(this,"canRotate",!0);m(this,"scaleType",o.EScaleType.all);m(this,"toolsType",o.EToolsKey.Pencil);m(this,"syncTimestamp");m(this,"syncIndex",0);m(this,"tmpPoints",[]);m(this,"MAX_REPEAR",10);m(this,"uniThickness");m(this,"workOptions");m(this,"centerPos",[0,0]);this.workOptions=t.toolsOpt,this.uniThickness=this.MAX_REPEAR/this.workOptions.thickness/10,this.syncTimestamp=0}combineConsume(){var n;const t=(n=this.workId)==null?void 0:n.toString(),e=this.transformDataAll(!0),s={name:t};let i;const r=this.drawLayer||this.fullLayer;return e.length&&(i=this.draw({attrs:s,tasks:e,replaceId:t,layer:r})),{rect:i,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local}}setWorkOptions(t){super.setWorkOptions(t),this.syncTimestamp=Date.now()}consume(t){var N;const{data:e,isFullWork:s,isSubWorker:i,isMainThread:r,drawCount:n,replaceId:c}=t;if(((N=e.op)==null?void 0:N.length)===0)return{type:o.EPostMessageType.None};const{workId:l}=e,{tasks:h,effects:p,consumeIndex:d}=this.transformData(e,!1);this.syncIndex=Math.min(this.syncIndex,d,Math.max(0,this.tmpPoints.length-2));const f={name:l==null?void 0:l.toString(),id:n==null?void 0:n.toString()};let u,y=!1;const g=this.syncIndex;if(this.syncTimestamp===0&&(this.syncTimestamp=Date.now()),h.length&&(h[0].taskId-this.syncTimestamp>this.syncUnitTime&&(y=!0,this.syncTimestamp=h[0].taskId,this.syncIndex=this.tmpPoints.length),i||r)){const P=s?this.fullLayer:this.drawLayer||this.fullLayer;u=this.draw({attrs:f,tasks:h,effects:p,layer:P,replaceId:c})}if(i)return d>10&&this.tmpPoints.splice(0,d-10),{rect:u,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local};const S=[];return this.tmpPoints.slice(g).forEach(P=>{S.push(P.x,P.y,this.computRadius(P.z,this.workOptions.thickness))}),{rect:u,type:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local,workId:y?l:void 0,op:y?S:void 0,index:y?g*3:void 0}}consumeAll(t){var h,p;if(t.data){const{op:d,workState:f}=t.data;d!=null&&d.length&&f===o.EvevtWorkState.Done&&this.workOptions.strokeType===o.EStrokeType.Stroke&&this.updateTempPointsWithPressureWhenDone(d)}const e=(h=this.workId)==null?void 0:h.toString();if(!e)return{type:o.EPostMessageType.None};const s=this.transformDataAll(!0),i={name:e};let r;const n=this.fullLayer;s.length&&(r=this.draw({attrs:i,tasks:s,replaceId:e,layer:n}));const c=[];this.tmpPoints.map(d=>{c.push(d.x,d.y,this.computRadius(d.z,this.workOptions.thickness))}),this.syncTimestamp=0,delete this.workOptions.syncUnitTime;const l=o.transformToSerializableData(c);return(p=this.vNodes)==null||p.setInfo(e,{rect:r,op:c,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:r&&v.getCenterPos(r,n)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:e,ops:l,updateNodeOpt:{pos:this.centerPos,useAnimation:!0},opt:this.workOptions}}clearTmpPoints(){this.tmpPoints.length=0,this.syncTimestamp=0,this.syncIndex=0}consumeService(t){var h,p;const{op:e,isFullWork:s,replaceId:i}=t;this.tmpPoints.length=0;for(let d=0;d<e.length;d+=3){const f=new o.Point2d(e[d],e[d+1],e[d+2]);if(this.tmpPoints.length>0){const u=this.tmpPoints[this.tmpPoints.length-1],y=o.Vec2d.Sub(f,u).uni();f.setv(y)}this.tmpPoints.push(f)}const r=this.transformDataAll(!1),n=(h=this.workId)==null?void 0:h.toString(),c={name:n};let l;if(n&&r.length){const d=s?this.fullLayer:this.drawLayer||this.fullLayer;l=this.draw({attrs:c,tasks:r,replaceId:i,layer:d}),(p=this.vNodes)==null||p.setInfo(n,{rect:l,op:e,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:l&&v.getCenterPos(l,d)})}return l}transformDataAll(t=!0){return this.getTaskPoints(this.tmpPoints,t&&this.workOptions.thickness||void 0)}draw(t){const{attrs:e,tasks:s,replaceId:i,effects:r,layer:n}=t,{strokeColor:c,strokeType:l,thickness:h,zIndex:p,scale:d,rotate:f,translate:u}=this.workOptions;r!=null&&r.size&&(r.forEach(w=>{var I;(I=n.getElementById(w+""))==null||I.remove()}),r.clear());let y;const g=[],S=n.worldPosition,N=n.worldScaling;for(let w=0;w<s.length;w++){const{pos:I,points:k}=s[w],{ps:E,rect:L}=this.computDrawPoints(k);let T;const W=k.length===1;l===o.EStrokeType.Stroke||W?T=X(E,!0):T=X(E,!1);const M={pos:I,d:T,fillColor:l===o.EStrokeType.Stroke||W?c:void 0,lineDash:l===o.EStrokeType.Dotted&&!W?[1,h*2]:l===o.EStrokeType.LongDotted&&!W?[h,h*2]:void 0,strokeColor:c,lineCap:l===o.EStrokeType.Stroke||W?void 0:"round",lineWidth:l===o.EStrokeType.Stroke||W?0:h};y=o.computRect(y,{x:Math.floor((L.x+I[0])*N[0]+S[0]-v.SafeBorderPadding),y:Math.floor((L.y+I[1])*N[1]+S[1]-v.SafeBorderPadding),w:Math.floor(L.w*N[0]+2*v.SafeBorderPadding),h:Math.floor(L.h*N[1]+2*v.SafeBorderPadding)}),g.push(M)}d&&(e.scale=d),f&&(e.rotate=f),u&&(e.translate=u);const P=new x.Group;if(y){this.centerPos=v.getCenterPos(y,n),P.attr({...e,normalize:!0,anchor:[.5,.5],bgcolor:l===o.EStrokeType.Stroke?c:void 0,pos:this.centerPos,size:[(y.w-2*v.SafeBorderPadding)/N[0],(y.h-2*v.SafeBorderPadding)/N[1]],zIndex:p});const w=g.map(I=>(I.pos=[I.pos[0]-this.centerPos[0],I.pos[1]-this.centerPos[1]],new x.Path(I)));P.append(...w),l===o.EStrokeType.Stroke&&P.seal(),this.replace(n,i||e.workId,P)}if(d||f||u){const w=P==null?void 0:P.getBoundingClientRect();if(w)return{x:Math.floor(w.x-v.SafeBorderPadding),y:Math.floor(w.y-v.SafeBorderPadding),w:Math.floor(w.width+v.SafeBorderPadding*2),h:Math.floor(w.height+v.SafeBorderPadding*2)}}return y}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 S=t[i].getAngleByPoints(t[i-1],t[i+1]);if(S<90||S>270){const N=(p=l.pop())==null?void 0:p.point.clone();N&&s.push({taskId:h,pos:c,points:[...l,{point:N,radius:g}]}),r=t[i].x,n=t[i].y,c=[r,n];const P=d.x-r,w=d.y-n;l=[{point:new o.Point2d(P,w,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 S=h-1;for(;S>0;){const N=this.tmpPoints[S].distance(this.tmpPoints[S-1]),P=Math.max(this.tmpPoints[S].z-this.uniThickness*N,0);if(this.tmpPoints[S-1].z>=P)break;this.tmpPoints[S-1].setz(P),n=Math.min(n,S-1),S--}}}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),v.updateNodeOpt(t)}}class Z extends v{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 S=Date.now();S-this.syncTimestamp>this.syncUnitTime&&(p=!0,this.syncTimestamp=S,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(S=>{g.push(S.x,S.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=X(p,!0):d=X(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:S}=r.getResolution();l.setUniforms({u_time:0,u_resolution:[g,S]}),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 v{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,S=d.slice(g),N=l[l.length-1];o.Vec2d.Equals(d[g],N)||S.unshift(N.clone().setz(d[g].z)),S.length>1&&u.push(S)}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 S=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(S),f.push(new o.Point2d(S.x,S.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(S=>S.XY),this.eraserPolyline);if(g.length&&(s.add(l.name),!d)){const S=this.translateIntersect(g),N=this.cutPolyline(S,u);for(let P=0;P<N.length;P++){const w=`${c}_s_${P}`,I=[];N[P].forEach(k=>{I.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(w,{rect:y,op:I,opt:l.opt,canRotate:l.canRotate,scaleType:l.scaleType,toolsType:l.toolsType}),i.set(w,{workId:w,op:I,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-=v.SafeBorderPadding,n.y-=v.SafeBorderPadding,n.w+=v.SafeBorderPadding*2,n.h+=v.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 $=U;const V=class V extends v{constructor(t){super(t);m(this,"toolsType",o.EToolsKey.Selector);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"vNodes");m(this,"selectIds");m(this,"selectorColor");m(this,"strokeColor");m(this,"fillColor");m(this,"oldSelectRect");m(this,"canRotate",!1);m(this,"canTextEdit",!1);m(this,"canLock",!1);m(this,"scaleType",o.EScaleType.all);m(this,"toolsTypes");m(this,"shapeOpt");m(this,"textOpt");m(this,"isLocked");this.workOptions=t.toolsOpt,this.vNodes=t.vNodes}computSelector(t=!0){const e=o.getRectFromPoints(this.tmpPoints);if(e.w===0||e.h===0)return{selectIds:[],intersectRect:void 0,subNodeMap:new Map};const{rectRange:s,nodeRange:i}=this.vNodes.getRectIntersectRange(e,t);return{selectIds:[...i.keys()],intersectRect:s,subNodeMap:i}}updateTempPoints(t){const e=this.tmpPoints.length,s=t.length;if(s>1){const i=new o.Point2d(t[s-2]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],t[s-1]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[1]);e===2?this.tmpPoints.splice(1,1,i):this.tmpPoints.push(i)}}drawSelector(t){const{drawRect:e,subNodeMap:s,selectorId:i,layer:r,isService:n}=t,c=new x.Group({pos:[e.x,e.y],anchor:[0,0],size:[e.w,e.h],id:i,name:i,zIndex:1e3}),l=[];if(n){const h=new x.Rect({normalize:!0,pos:[e.w/2,e.h/2],lineWidth:1,strokeColor:this.selectorColor||this.workOptions.strokeColor,width:e.w,height:e.h,name:V.selectorBorderId});l.push(h)}s.forEach((h,p)=>{const d=[h.rect.x+h.rect.w/2-e.x,h.rect.y+h.rect.h/2-e.y],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(V.selectorId,this.fullLayer,r),this.oldSelectRect=n;const c=this.getChildrenPoints();return{type:o.EPostMessageType.Select,dataType:o.EDataType.Local,rect:o.computRect(n,i),selectIds:r.selectIds,opt:this.workOptions,selectRect:n,selectorColor:this.selectorColor,strokeColor:this.strokeColor,fillColor:this.fillColor,textOpt:this.textOpt,canTextEdit:this.canTextEdit,canRotate:this.canRotate,canLock:this.canLock,scaleType:this.scaleType,willSyncService:!0,points:c,isLocked:this.isLocked,toolsTypes:this.toolsTypes,shapeOpt:this.shapeOpt}}consumeAll(){var e,s;let t=this.oldSelectRect;if(!((e=this.selectIds)!=null&&e.length)&&this.tmpPoints[0]&&this.selectSingleTool(this.tmpPoints[0].XY,V.selectorId,!1),(s=this.selectIds)!=null&&s.length&&(t=this.selectedByIds(this.selectIds)),t){const i=this.getChildrenPoints();return{type:o.EPostMessageType.Select,dataType:o.EDataType.Local,rect:this.oldSelectRect,selectIds:this.selectIds,opt:this.workOptions,selectorColor:this.selectorColor,selectRect:this.oldSelectRect,strokeColor:this.strokeColor,fillColor:this.fillColor,textOpt:this.textOpt,canTextEdit:this.canTextEdit,canRotate:this.canRotate,canLock:this.canLock,scaleType:this.scaleType,willSyncService:!0,points:i,isLocked:this.isLocked,toolsTypes:this.toolsTypes,shapeOpt:this.shapeOpt}}return{type:o.EPostMessageType.None}}consumeService(){}clearTmpPoints(){this.tmpPoints.length=0}clearSelectData(){this.selectIds=void 0,this.oldSelectRect=void 0}selectSingleTool(t,e=V.selectorId,s=!1){if(t.length===2){const i=t[0],r=t[1];let n;const{nodeRange:c}=this.vNodes.getRectIntersectRange({x:i,y:r,w:0,h:0},!1),l=[...c.values()].sort((h,p)=>(p.opt.zIndex||0)-(h.opt.zIndex||0));for(const h of l){const p=this.fullLayer.getElementsByName(h.name);if(ne(p).find(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:S}=e;let N=[0,0],P=[1,1],w=[0,0],I,k;if(u||S||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(I=i.getLastTarget(),I&&u){let T;s==null||s.forEach(W=>{const M=I==null?void 0:I.get(W);T=o.computRect(T,M==null?void 0:M.rect)}),T&&(P=[u.w/T.w,u.h/T.h],N=[u.x+u.w/2-(T.x+T.w/2),u.y+u.h/2-(T.y+T.h/2)],w=[T.x+T.w/2,T.y+T.h/2]),k=T}}if(s)for(const T of s){const W=i.get(T);if(W){const{toolsType:M}=W;let D=(p==null?void 0:p.getElementsByName(T))[0];if(D){const b={...e};let C;if(M){if(C=I==null?void 0:I.get(T),C&&u){b.boxScale=P;const B=[C.rect.x+C.rect.w/2,C.rect.y+C.rect.h/2],K=[B[0]-w[0],B[1]-w[1]];b.boxTranslate=[K[0]*(P[0]-1)+N[0]+(c&&c[0]||0),K[1]*(P[1]-1)+N[1]+(c&&c[1]||0)]}const H=re(M);if(H==null||H.updateNodeOpt({node:D,opt:b,vNodes:i,willSerializeData:r,targetNode:C}),W&&n&&(r&&(b.angle||b.translate)||b.box&&b.workState!==o.EvevtWorkState.Start||b.pointMap&&b.pointMap.has(T)||M===o.EToolsKey.Text&&(b.fontSize||b.translate||b.textInfos&&b.textInfos.get(T))||M===o.EToolsKey.Image&&(b.angle||b.translate||b.boxScale)||M===b.toolsType&&b.willRefresh)){const B=n.createWorkShapeNode({toolsType:M,toolsOpt:W.opt});B==null||B.setWorkId(T);let K;M===o.EToolsKey.Image&&l?K=await B.consumeServiceAsync({isFullWork:!0,replaceId:T,scene:l,isMainThread:h}):M===o.EToolsKey.Text?K=await B.consumeServiceAsync({isFullWork:!0,replaceId:T}):K=B==null?void 0:B.consumeService({op:W.op,isFullWork:!0,replaceId:T}),K&&(W.rect=K),D=(p==null?void 0:p.getElementsByName(T))[0]}W&&(f.set(T,W),d=o.computRect(d,W.rect))}}}}I&&y===o.EvevtWorkState.Done&&(i.deleteLastTarget(),I=void 0);const E=d;if(k&&e.dir&&E&&!c){const T=[0,0];switch(e.dir){case"top":{const W=[k.x,k.y+k.h];e.reverseY?T[1]=W[1]-E.y:T[1]=W[1]-(E.y+E.h);break}case"topLeft":{const W=[k.x+k.w,k.y+k.h];e.reverseY?T[1]=W[1]-E.y:T[1]=W[1]-(E.y+E.h),e.reverseX?T[0]=W[0]-E.x:T[0]=W[0]-(E.x+E.w);break}case"topRight":{const W=[k.x,k.y+k.h];e.reverseY?T[1]=W[1]-E.y:T[1]=W[1]-(E.y+E.h),e.reverseX?T[0]=W[0]-(E.x+E.w):T[0]=W[0]-E.x;break}case"bottom":{const W=[k.x,k.y];e.reverseY?T[1]=W[1]-(E.y+E.h):T[1]=W[1]-E.y;break}case"bottomLeft":{const W=[k.x+k.w,k.y];e.reverseY?T[1]=W[1]-(E.y+E.h):T[1]=W[1]-E.y,e.reverseX?T[0]=W[0]-E.x:T[0]=W[0]-(E.x+E.w);break}case"bottomRight":{const W=[k.x,k.y];e.reverseY?T[1]=W[1]-(E.y+E.h):T[1]=W[1]-E.y,e.reverseX?T[0]=W[0]-(E.x+E.w):T[0]=W[0]-E.x;break}case"right":{const W=[k.x,k.y];e.reverseX?T[0]=W[0]-(E.x+E.w):T[0]=W[0]-E.x;break}}if(T[0]||T[1])return E.x=E.x+T[0],E.y=E.y+T[1],await this.updateSelector({...t,offset:T})}this.getSelecteorInfo(f),this.draw(V.selectorId,p,{selectIds:s||[],subNodeMap:f,intersectRect:E});const L=o.computRect(this.oldSelectRect,E);return this.oldSelectRect=E,{type:o.EPostMessageType.Select,dataType:o.EDataType.Local,selectRect:E,renderRect:d,rect:o.computRect(L,E)}}blurSelector(){const t=this.unSelectedAllIds();return{type:o.EPostMessageType.Select,dataType:o.EDataType.Local,rect:t,selectIds:[],willSyncService:!0}}getRightServiceId(t){return t.replace(o.Storage_Splitter,"-")}selectServiceNode(t,e,s){const{selectIds:i}=e,r=this.getRightServiceId(t),n=this.getSelectorRect(this.fullLayer,r);let c;const l=new Map;return i==null||i.forEach(h=>{const p=this.vNodes.get(h);p&&(c=o.computRect(c,p.rect),l.set(h,p))}),this.getSelecteorInfo(l),this.draw(r,this.fullLayer,{intersectRect:c,selectIds:i||[],subNodeMap:l},s),o.computRect(c,n)}reRenderSelector(){var s;let t;const e=new Map;return(s=this.selectIds)==null||s.forEach(i=>{const r=this.vNodes.get(i);r&&(t=o.computRect(t,r.rect),e.set(i,r))},this),this.getSelecteorInfo(e),this.draw(V.selectorId,this.fullLayer,{intersectRect:t,subNodeMap:e,selectIds:this.selectIds||[]}),this.oldSelectRect=t,t}updateSelectIds(t){var r;let e;const s=(r=this.selectIds)==null?void 0:r.filter(n=>!t.includes(n));if(s!=null&&s.length&&(e=this.unSelectedByIds(s)),t.length){const n=this.selectedByIds(t);e=o.computRect(e,n)}this.selectIds=t;const i=this.reRenderSelector();return{bgRect:e,selectRect:i}}cursorHover(t){var r,n;const e=this.oldSelectRect;this.selectIds=[];const s=(r=this.workId)==null?void 0:r.toString(),i=[t[0]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],t[1]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[1]];if(this.selectSingleTool(i,s,!0),this.oldSelectRect&&!o.isEqual(e,this.oldSelectRect))return{type:o.EPostMessageType.CursorHover,dataType:o.EDataType.Local,rect:o.computRect(e,this.oldSelectRect),selectorColor:this.selectorColor,willSyncService:!1};if((n=this.selectIds)!=null&&n.length||(this.oldSelectRect=void 0),e&&!this.oldSelectRect)return this.cursorBlur(),{type:o.EPostMessageType.CursorHover,dataType:o.EDataType.Local,rect:e,selectorColor:this.selectorColor,willSyncService:!1}}cursorBlur(){var e,s;this.selectIds=[];const t=(e=this.workId)==null?void 0:e.toString();((s=this.fullLayer)==null?void 0:s.parent).children.forEach(i=>{i.name===t&&i.remove()})}};m(V,"selectorId",o.Storage_Selector_key),m(V,"selectorBorderId","selector-border");let A=V;class J extends v{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:v.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s}=t,{strokeColor:i,thickness:r,zIndex:n,scale:c,rotate:l,translate:h}=this.workOptions,p=s.worldPosition,d=s.worldScaling,{points: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 S=new x.Polyline(g);if(this.replace(s,e,S),c||l||h){const N=S.getBoundingClientRect();return{x:Math.floor(N.x-v.SafeBorderPadding),y:Math.floor(N.y-v.SafeBorderPadding),w:Math.floor(N.width+v.SafeBorderPadding*2),h:Math.floor(N.height+v.SafeBorderPadding*2)}}return{x:Math.floor(u.x*d[0]+p[0]-v.SafeBorderPadding),y:Math.floor(u.y*d[1]+p[1]-v.SafeBorderPadding),w:Math.floor(u.w*d[0]+2*v.SafeBorderPadding),h:Math.floor(u.h*d[1]+2*v.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:v.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)),v.updateNodeOpt(t)}}class Q extends v{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&&v.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s,isDrawing:i}=t,{strokeColor:r,fillColor:n,thickness:c,zIndex:l,scale:h,rotate:p,translate:d}=this.workOptions,f=s.worldScaling,{radius:u,rect:y,pos:g}=this.computDrawPoints(c),S={pos:g,name:e,id:e,radius:u,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0},N={name:e,id:e,zIndex:l,pos:g,anchor:[.5,.5],size:[y.w,y.h]};h&&(N.scale=h),p&&(N.rotate=p),d&&(N.translate=d);const P=new x.Group(N);if(i){const k=new x.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/f[0],1/f[1]]});P.append(k)}const w=new x.Ellipse({...S,pos:[0,0]});P.append(w),this.replace(s,e,P);const I=P.getBoundingClientRect();return{x:Math.floor(I.x-v.SafeBorderPadding),y:Math.floor(I.y-v.SafeBorderPadding),w:Math.floor(I.width+v.SafeBorderPadding*2),h:Math.floor(I.height+v.SafeBorderPadding*2)}}computDrawPoints(t){const e=o.getRectFromPoints(this.tmpPoints),s=o.getRectFromPoints(this.tmpPoints,t),i=[Math.floor(e.x+e.w/2),Math.floor(e.y+e.h/2)];return{rect:s,pos:i,radius:[Math.floor(e.w/2),Math.floor(e.h/2)]}}updateTempPoints(t){const e=t.slice(-2),s=new o.Point2d(e[0],e[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(s,r))return!1;if(this.tmpPoints.length===2){if(s.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=s}else this.tmpPoints.push(s);return!0}consumeService(t){var c,l;const{op:e,isFullWork:s}=t,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<e.length;h+=3)this.tmpPoints.push(new o.Point2d(e[h],e[h+1],e[h+2]));const r=s?this.fullLayer:this.drawLayer||this.fullLayer,n=this.draw({workId:i,layer:r,isDrawing:!1});return this.oldRect=n,(l=this.vNodes)==null||l.setInfo(i,{rect:n,op:e,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:v.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),v.updateNodeOpt(t)}}class ee extends v{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&&v.getCenterPos(n,r)}),{rect:n,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:l,opt:this.workOptions,isSync:!0}}draw(t){const{workId:e,layer:s,isDrawing:i,ps:r,replaceId:n}=t,{strokeColor:c,fillColor:l,thickness:h,zIndex:p,scale:d,rotate:f,translate:u,textOpt:y}=this.workOptions,g=s.worldPosition,S=s.worldScaling,{points:N,rect:P,pos:w}=this.computDrawPoints(r),I={close:!0,normalize:!0,points:N,lineWidth:h,fillColor:l!=="transparent"&&l||void 0,strokeColor:c,lineJoin:"round"},k={x:Math.floor(P.x*S[0]+g[0]-v.SafeBorderPadding),y:Math.floor(P.y*S[1]+g[1]-v.SafeBorderPadding),w:Math.floor(P.w*S[0]+2*v.SafeBorderPadding),h:Math.floor(P.h*S[0]+2*v.SafeBorderPadding)},E=new x.Group({name:e,id:e,zIndex:p,pos:w,anchor:[.5,.5],size:[P.w,P.h],scale:d,rotate:f,translate:u}),L=new x.Polyline({...I,pos:[0,0]});if(E.appendChild(L),i){const T=new x.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:c,lineWidth:1,scale:[1/S[0],1/S[1]]});E.appendChild(T)}if(this.replace(s,n||e,E),d||f||u){const T=E.getBoundingClientRect();return{x:Math.floor(T.x-v.SafeBorderPadding),y:Math.floor(T.y-v.SafeBorderPadding),w:Math.floor(T.width+2*v.SafeBorderPadding),h:Math.floor(T.height+2*v.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&&v.getCenterPos(l,c)}),l}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(t){var S,N;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),(S=y==null?void 0:y.opt)!=null&&S.strokeColor&&(y.opt.strokeColor=r)),n&&(n==="transparent"?g.setAttribute("fillColor","rgba(0,0,0,0)"):g.setAttribute("fillColor",n),(N=y==null?void 0:y.opt)!=null&&N.fillColor&&(y.opt.fillColor=n)),y!=null&&y.opt.textOpt){const P=y.opt.textOpt;c&&P.fontColor&&(P.fontColor=c),l&&P.fontBgColor&&(P.fontBgColor=l),h&&(P.bold=h),p&&(P.italic=p),o.isBoolean(d)&&(P.lineThrough=d),o.isBoolean(f)&&(P.underline=f),u&&(P.fontSize=u)}return y&&i.setInfo(e.name,y),v.updateNodeOpt(t)}}class te extends v{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&&v.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s,isDrawing:i}=t,{strokeColor:r,fillColor:n,thickness:c,zIndex:l,vertices:h,innerVerticeStep:p,innerRatio:d,scale:f,rotate:u,translate:y}=this.workOptions,g=s.worldScaling,{rect:S,pos:N,points:P}=this.computDrawPoints(c,h,p,d),w={close:!0,points:P,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0,lineJoin:"round"},I={name:e,id:e,zIndex:l,pos:N,anchor:[.5,.5],size:[S.w,S.h],className:`${N[0]},${N[1]}`};f&&(I.scale=f),u&&(I.rotate=u),y&&(I.translate=y);const k=new x.Group(I);if(i){const T=new x.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/g[0],1/g[1]]});k.append(T)}const E=new x.Polyline({...w,pos:[0,0]});k.append(E),this.replace(s,e,k);const L=k.getBoundingClientRect();return{x:Math.floor(L.x-v.SafeBorderPadding),y:Math.floor(L.y-v.SafeBorderPadding),w:Math.floor(L.width+v.SafeBorderPadding*2),h:Math.floor(L.height+v.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,S;u%s===1?(g=h*c[0]*Math.cos(y),S=h*c[1]*Math.sin(y)):(g=l*c[0]*Math.cos(y),S=l*c[1]*Math.sin(y),p.push(g,S)),p.push(g,S)}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&&v.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}),v.updateNodeOpt(t)}}class oe extends v{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&&v.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s,isDrawing:i}=t,{strokeColor:r,fillColor:n,thickness:c,zIndex:l,vertices:h,scale:p,rotate:d,translate:f}=this.workOptions,u=s.worldScaling,{rect:y,pos:g,points:S}=this.computDrawPoints(c,h),N={close:!0,points:S,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0,lineJoin:"round"},P={name:e,id:e,zIndex:l,pos:g,anchor:[.5,.5],size:[y.w,y.h]};p&&(P.scale=p),d&&(P.rotate=d),f&&(P.translate=f);const w=new x.Group(P);if(i){const E=new x.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/u[0],1/u[1]]});w.append(E)}const I=new x.Polyline({...N,pos:[0,0]});w.append(I),this.replace(s,e,w);const k=w.getBoundingClientRect();return{x:Math.floor(k.x-v.SafeBorderPadding),y:Math.floor(k.y-v.SafeBorderPadding),w:Math.floor(k.width+v.SafeBorderPadding*2),h:Math.floor(k.height+v.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&&v.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}),v.updateNodeOpt(t)}}class F{static bezier(a,t){const e=[];for(let s=0;s<t.length;s+=4){const i=t[s],r=t[s+1],n=t[s+2],c=t[s+3];i&&r&&n&&c?e.push(...F.getBezierPoints(a,i,r,n,c)):i&&r&&n?e.push(...F.getBezierPoints(a,i,r,n)):i&&r?e.push(...F.getBezierPoints(a,i,r)):i&&e.push(i)}return e}static getBezierPoints(a=10,t,e,s,i){let r=null;const n=[];!s&&!i?r=F.oneBezier:s&&!i?r=F.twoBezier:s&&i&&(r=F.threeBezier);for(let c=0;c<a;c++)r&&n.push(r(c/a,t,e,s,i));return i?n.push(i):s&&n.push(s),n}static oneBezier(a,t,e){const s=t.x+(e.x-t.x)*a,i=t.y+(e.y-t.y)*a;return new o.Vec2d(s,i)}static twoBezier(a,t,e,s){const i=(1-a)*(1-a)*t.x+2*a*(1-a)*e.x+a*a*s.x,r=(1-a)*(1-a)*t.y+2*a*(1-a)*e.y+a*a*s.y;return new o.Vec2d(i,r)}static threeBezier(a,t,e,s,i){const r=t.x*(1-a)*(1-a)*(1-a)+3*e.x*a*(1-a)*(1-a)+3*s.x*a*a*(1-a)+i.x*a*a*a,n=t.y*(1-a)*(1-a)*(1-a)+3*e.y*a*(1-a)*(1-a)+3*s.y*a*a*(1-a)+i.y*a*a*a;return new o.Vec2d(r,n)}}class se extends v{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&&v.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s}=t,{strokeColor:i,fillColor:r,thickness:n,zIndex:c,placement:l,scale:h,rotate:p,translate:d}=this.workOptions,{rect:f,pos:u,points:y}=this.computDrawPoints(n,l),g={points:y.map(I=>I.XY),lineWidth:n,fillColor:r!=="transparent"&&r||void 0,strokeColor:i,normalize:!0,className:`${u[0]},${u[1]}`,lineJoin:"round",close:!0},S={name:e,id:e,zIndex:c,pos:u,anchor:[.5,.5],size:[f.w,f.h]};h&&(S.scale=h),p&&(S.rotate=p),d&&(S.translate=d);const N=new x.Group(S),P=new x.Polyline({...g,pos:[0,0]});N.append(P),this.replace(s,e,N);const w=N.getBoundingClientRect();return{x:Math.floor(w.x-v.SafeBorderPadding),y:Math.floor(w.y-v.SafeBorderPadding),w:Math.floor(w.width+v.SafeBorderPadding*2),h:Math.floor(w.height+v.SafeBorderPadding*2)}}transformControlPoints(t){const e=o.getRectFromPoints(this.tmpPoints);switch(t){case"bottom":case"bottomLeft":case"bottomRight":{const s=e.y+e.h*this.ratio;return[new o.Vec2d(e.x,e.y,0),new o.Vec2d(e.x+e.w,e.y,0),new o.Vec2d(e.x+e.w,s,0),new o.Vec2d(e.x,s,0)]}case"top":case"topLeft":case"topRight":{const s=e.y+e.h*(1-this.ratio);return[new o.Vec2d(e.x,s,0),new o.Vec2d(e.x+e.w,s,0),new o.Vec2d(e.x+e.w,e.y+e.h,0),new o.Vec2d(e.x,e.y+e.h,0)]}case"left":case"leftBottom":case"leftTop":{const s=e.x+e.w*(1-this.ratio);return[new o.Vec2d(s,e.y,0),new o.Vec2d(e.x+e.w,e.y,0),new o.Vec2d(e.x+e.w,e.y+e.h,0),new o.Vec2d(s,e.y+e.h,0)]}case"right":case"rightBottom":case"rightTop":{const s=e.x+e.w*this.ratio;return[new o.Vec2d(e.x,e.y,0),new o.Vec2d(s,e.y,0),new o.Vec2d(s,e.y+e.h,0),new o.Vec2d(e.x,e.y+e.h,0)]}}}computDrawPoints(t,e){const s=o.getRectFromPoints(this.tmpPoints),i=this.transformControlPoints(e),r=Math.floor(s.w*.1),n=Math.floor(s.h*.1),c=[],l=o.Vec2d.Add(i[0],new o.Vec2d(0,n,0)),h=o.Vec2d.Add(i[0],new o.Vec2d(r,0,0)),p=F.getBezierPoints(10,l,i[0],h),d=o.Vec2d.Sub(i[1],new o.Vec2d(r,0,0)),f=o.Vec2d.Add(i[1],new o.Vec2d(0,n,0)),u=F.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)),S=F.getBezierPoints(10,y,i[2],g),N=o.Vec2d.Add(i[3],new o.Vec2d(r,0,0)),P=o.Vec2d.Sub(i[3],new o.Vec2d(0,n,0)),w=F.getBezierPoints(10,N,i[3],P),I=r*(1-this.ratio)*10,k=n*(1-this.ratio)*10;switch(e){case"bottom":{const T=o.Vec2d.Sub(i[2],new o.Vec2d(r*5-I/2,0,0)),W=o.Vec2d.Sub(i[2],new o.Vec2d(r*5,-k,0)),M=o.Vec2d.Sub(i[2],new o.Vec2d(r*5+I/2,0,0));c.push(W,M,...w,...p,...u,...S,T);break}case"bottomRight":{const T=o.Vec2d.Sub(i[2],new o.Vec2d(r*1.1,0,0)),W=o.Vec2d.Sub(i[2],new o.Vec2d(r*1.1+I/2,-k,0)),M=o.Vec2d.Sub(i[2],new o.Vec2d(r*1.1+I,0,0));c.push(W,M,...w,...p,...u,...S,T);break}case"bottomLeft":{const T=o.Vec2d.Add(i[3],new o.Vec2d(r*1.1+I,0,0)),W=o.Vec2d.Add(i[3],new o.Vec2d(r*1.1+I/2,k,0)),M=o.Vec2d.Add(i[3],new o.Vec2d(r*1.1,0,0));c.push(W,M,...w,...p,...u,...S,T);break}case"top":{const T=o.Vec2d.Sub(i[1],new o.Vec2d(r*5-I/2,0,0)),W=o.Vec2d.Sub(i[1],new o.Vec2d(r*5,k,0)),M=o.Vec2d.Sub(i[1],new o.Vec2d(r*5+I/2,0,0));c.push(W,T,...u,...S,...w,...p,M);break}case"topRight":{const T=o.Vec2d.Sub(i[1],new o.Vec2d(r*1.1,0,0)),W=o.Vec2d.Sub(i[1],new o.Vec2d(r*1.1+I/2,k,0)),M=o.Vec2d.Sub(i[1],new o.Vec2d(r*1.1+I,0,0));c.push(W,T,...u,...S,...w,...p,M);break}case"topLeft":{const T=o.Vec2d.Add(i[0],new o.Vec2d(r*1.1+I,0,0)),W=o.Vec2d.Add(i[0],new o.Vec2d(r*1.1+I/2,-k,0)),M=o.Vec2d.Add(i[0],new o.Vec2d(r*1.1,0,0));c.push(W,T,...u,...S,...w,...p,M);break}case"left":{const T=o.Vec2d.Add(i[0],new o.Vec2d(0,n*5-k/2,0)),W=o.Vec2d.Add(i[0],new o.Vec2d(-I,n*5,0)),M=o.Vec2d.Add(i[0],new o.Vec2d(0,n*5+k/2,0));c.push(W,T,...p,...u,...S,...w,M);break}case"leftTop":{const T=o.Vec2d.Add(i[0],new o.Vec2d(0,n*1.1,0)),W=o.Vec2d.Add(i[0],new o.Vec2d(-I,n*1.1+k/2,0)),M=o.Vec2d.Add(i[0],new o.Vec2d(0,n*1.1+k,0));c.push(W,T,...p,...u,...S,...w,M);break}case"leftBottom":{const T=o.Vec2d.Sub(i[3],new o.Vec2d(0,n*1.1+k,0)),W=o.Vec2d.Sub(i[3],new o.Vec2d(I,n*1.1+k/2,0)),M=o.Vec2d.Sub(i[3],new o.Vec2d(0,n*1.1,0));c.push(W,T,...p,...u,...S,...w,M);break}case"right":{const T=o.Vec2d.Add(i[1],new o.Vec2d(0,n*5-k/2,0)),W=o.Vec2d.Add(i[1],new o.Vec2d(I,n*5,0)),M=o.Vec2d.Add(i[1],new o.Vec2d(0,n*5+k/2,0));c.push(W,M,...S,...w,...p,...u,T);break}case"rightTop":{const T=o.Vec2d.Add(i[1],new o.Vec2d(0,n*1.1,0)),W=o.Vec2d.Add(i[1],new o.Vec2d(I,n*1.1+k/2,0)),M=o.Vec2d.Add(i[1],new o.Vec2d(0,n*1.1+k,0));c.push(W,M,...S,...w,...p,...u,T);break}case"rightBottom":{const T=o.Vec2d.Sub(i[2],new o.Vec2d(0,n*1.1+k,0)),W=o.Vec2d.Sub(i[2],new o.Vec2d(-I,n*1.1+k/2,0)),M=o.Vec2d.Sub(i[2],new o.Vec2d(0,n*1.1,0));c.push(W,M,...S,...w,...p,...u,T);break}}const E=o.getRectFromPoints(this.tmpPoints,t),L=[Math.floor(E.x+E.w/2),Math.floor(E.y+E.h/2)];return{rect:E,pos:L,points:c}}updateTempPoints(t){const e=t.slice(-2),s=new o.Point2d(e[0],e[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(s,r)||o.Point2d.Sub(i,s).XY.includes(0))return!1;if(this.tmpPoints.length===2){if(s.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=s}else this.tmpPoints.push(s);return!0}consumeService(t){var c,l;const{op:e,isFullWork:s}=t,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<e.length;h+=3)this.tmpPoints.push(new o.Point2d(e[h],e[h+1],e[h+2]));const r=s?this.fullLayer:this.drawLayer||this.fullLayer,n=this.draw({workId:i,layer:r,isDrawing:!1});return this.oldRect=n,(l=this.vNodes)==null||l.setInfo(i,{rect:n,op:e,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&v.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}),v.updateNodeOpt(t)}}class Y extends v{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=Y.getScaleType(this.workOptions)}consume(){return{type:o.EPostMessageType.None}}consumeAll(){return{type:o.EPostMessageType.None}}draw(t){const{layer:e,workId:s,replaceId:i,imageBitmap:r,isMainThread:n}=t,{centerX:c,centerY:l,width:h,height:p,rotate:d,zIndex:f}=this.workOptions,u=!!e.parent.gl,y={anchor:[.5,.5],pos:[c,l],name:s,size:[h,p],zIndex:f,rotate:!n&&!u&&180+(d||0)||d,texture:r},g=new x.Sprite(y);this.replace(e,i||s,g);const S=g.getBoundingClientRect();if(S)return{x:Math.floor(S.x-v.SafeBorderPadding),y:Math.floor(S.y-v.SafeBorderPadding),w:Math.floor(S.width+v.SafeBorderPadding*2),h:Math.floor(S.height+v.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&&v.getCenterPos(g,h)}),g}}clearTmpPoints(){this.tmpPoints.length=0}static getScaleType(t){const{uniformScale:e,rotate:s}=t;return e!==!1||s&&Math.abs(s)%90>0?o.EScaleType.proportional:o.EScaleType.all}static updateNodeOpt(t){const{node:e,opt:s,vNodes:i,targetNode:r}=t,{translate:n,box:c,boxScale:l,boxTranslate:h,angle:p,isLocked:d,zIndex: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:S,width:N,height:P,uniformScale:w,rotate:I}=u.opt,k=Math.min(l[0],l[1]),E=w!==!1?[k,k]:l,L=o.getRectRotatedPoints({x:g-N/2,y:S-P/2,w:N,h:P},I||0),T=o.getScalePoints(L,new o.Vec2d(g,S),E),W=o.getRotatePoints(T,new o.Vec2d(g,S),-(I||0)),M=o.getRectFromPoints(W);u.opt.width=Math.round(M.w),u.opt.height=Math.round(M.h);const D=[h[0]/y.worldScaling[0],h[1]/y.worldScaling[1]];u.opt.centerX=g+D[0],u.opt.centerY=S+D[1];const b=[u.centerPos[0]+D[0],u.centerPos[1]+D[1]];if(u.centerPos=b,r){let C=o.getRectScaleed(u.rect,l);C=o.getRectTranslated(C,D),u.rect=C}else{const C=v.getRectFromLayer(y,e.name);u.rect=C||u.rect}}else if(n)if(u.opt.centerX=u.opt.centerX+n[0],u.opt.centerY=u.opt.centerY+n[1],u.centerPos=[u.centerPos[0]+n[0],u.centerPos[1]+n[1]],r){const g=[n[0]*y.worldScaling[0],n[1]*y.worldScaling[1]],S=o.getRectTranslated(u.rect,g);u.rect=S}else{const g=v.getRectFromLayer(y,e.name);u.rect=g||u.rect}else if(o.isNumber(p))if(u.opt.rotate=p,u.scaleType=Y.getScaleType(u.opt),r){const g=o.getRectRotated(u.rect,p);u.rect=g}else{const g=v.getRectFromLayer(y,e.name);u.rect=g||u.rect}return u&&i.setInfo(e.name,u),u==null?void 0:u.rect}}}class ie extends v{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&&v.getCenterPos(r,i)}),{rect:r,type:o.EPostMessageType.FullWork,dataType:o.EDataType.Local,workId:s,ops:c,isSync:!0,opt:this.workOptions}}draw(t){const{workId:e,layer:s}=t,{strokeColor:i,thickness:r,zIndex:n,scale:c,rotate:l,translate:h}=this.workOptions,p=s.worldPosition,d=s.worldScaling,{d: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 S=new x.Path(g);if(this.replace(s,e,S),l||c||h){const P=S.getBoundingClientRect();return{x:Math.floor(P.x-v.SafeBorderPadding),y:Math.floor(P.y-v.SafeBorderPadding),w:Math.floor(P.width+v.SafeBorderPadding*2),h:Math.floor(P.height+v.SafeBorderPadding*2)}}return{x:Math.floor(u.x*d[0]+p[0]-v.SafeBorderPadding),y:Math.floor(u.y*d[1]+p[1]-v.SafeBorderPadding),w:Math.floor(u.w*d[0]+2*v.SafeBorderPadding),h:Math.floor(u.h*d[1]+2*v.SafeBorderPadding)}}computDrawPoints(t){return this.tmpPoints[1].distance(this.tmpPoints[0])>this.straightTipWidth?this.computFullPoints(t):this.computDotPoints(t)}computFullPoints(t){const e=o.Vec2d.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),s=o.Vec2d.Per(e).mul(t/2),i=o.Point2d.Sub(this.tmpPoints[0],s),r=o.Point2d.Add(this.tmpPoints[0],s),n=o.Point2d.Sub(this.tmpPoints[1],s),c=o.Point2d.Add(this.tmpPoints[1],s),l=o.Point2d.GetSemicircleStroke(this.tmpPoints[1],n,-1,8),h=o.Point2d.GetSemicircleStroke(this.tmpPoints[0],r,-1,8),p=[i,n,...l,c,r,...h];return{d:X(p,!0),rect:o.getRectFromPoints(p),isDot:!1,pos:this.tmpPoints[0].XY}}computDotPoints(t){const e=o.Point2d.GetDotStroke(this.tmpPoints[0],t/2,8);return{d:X(e,!0),rect:o.getRectFromPoints(e),isDot:!0,pos:this.tmpPoints[0].XY}}updateTempPoints(t){const e=t.slice(-2),s=new o.Point2d(e[0],e[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(s,r))return!1;if(this.tmpPoints.length===2){if(s.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=s}else this.tmpPoints.push(s);return!0}consumeService(t){var c,l;const{op:e,isFullWork:s}=t,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<e.length;h+=3)this.tmpPoints.push(new o.Point2d(e[h],e[h+1],e[h+2]));const r=s?this.fullLayer:this.drawLayer||this.fullLayer,n=this.draw({workId:i,layer:r});return this.oldRect=n,(l=this.vNodes)==null||l.setInfo(i,{rect:n,op:e,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&v.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),v.updateNodeOpt(t)}}class _ extends v{constructor(t){super(t);m(this,"canRotate",!1);m(this,"scaleType",o.EScaleType.all);m(this,"toolsType",o.EToolsKey.Text);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");this.workOptions=t.toolsOpt}consume(){return{type:o.EPostMessageType.None}}consumeAll(){return{type:o.EPostMessageType.None}}consumeService(){}async draw(t){const{workId:e,layer:s,isDrawLabel:i}=t,{boxSize:r,boxPoint:n,zIndex:c}=this.workOptions,l=s.worldPosition,h=s.worldScaling;if(!n||!r)return;const p={name:e,id:e,pos:[n[0]+r[0]/2,n[1]+r[1]/2],anchor:[.5,.5],size:r,zIndex:c},d=new x.Group(p),f={x:n[0],y:n[1],w:r[0],h:r[1]},u=new x.Rect({normalize:!0,pos:[0,0],size:r});if(d.append(u),i){const y=i&&await _.createLabels(this.workOptions,d,s)||[];d.append(...y)}return this.replace(s,e,d),{x:Math.floor(f.x*h[0]+l[0]),y:Math.floor(f.y*h[1]+l[1]),w:Math.floor(f.w*h[0]),h:Math.floor(f.h*h[1])}}async consumeServiceAsync(t){var l,h,p,d;const e=(l=this.workId)==null?void 0:l.toString();if(!e)return;const{isFullWork:s,replaceId:i,isDrawLabel:r}=t;this.oldRect=i&&((p=(h=this.vNodes)==null?void 0:h.get(i))==null?void 0:p.rect)||void 0;const n=s?this.fullLayer:this.drawLayer||this.fullLayer,c=await this.draw({workId:e,layer:n,isDrawLabel:r||this.workOptions.workState===o.EvevtWorkState.Done});return(d=this.vNodes)==null||d.setInfo(e,{rect:c,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:c&&v.getCenterPos(c,n)}),c}updataOptService(){}async updataOptServiceAsync(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),o.isNumber(h)&&(p.opt.zIndex=h),this.oldRect=p.rect;const d=await this.draw({workId:e,layer:this.fullLayer,isDrawLabel:this.workOptions.workState===o.EvevtWorkState.Done});return(u=this.vNodes)==null||u.setInfo(e,{rect:d,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:d&&v.getCenterPos(d,this.fullLayer)}),d}clearTmpPoints(){this.tmpPoints.length=0}static async createLabels(t,e,s){const i=[],r=t.text.split(","),n=r.length,{fontSize:c,lineHeight:l,bold:h,textAlign:p,italic:d,boxSize:f,fontFamily:u,verticalAlign:y,fontColor:g,fontBgColor:S,underline:N,lineThrough:P}=t,w=((s==null?void 0:s.parent).displayRatio||1)*((s==null?void 0:s.worldScaling[0])||1),I=c*w;for(let k=0;k<n;k++){const E=r[k],L=l||I*1.2;if(E){const T={anchor:[0,.5],text:E,fontSize:I,lineHeight:L,fontFamily:u,fontWeight:h,fillColor:g,bgcolor:S,textAlign:p,fontStyle:d,name:k.toString(),className:"label",scale:[1/w,1/w]},W=[0,0];if(y==="middle"){const D=(n-1)/2;W[1]=(k-D)*(l||c*1.2)}if(p==="left"){const D=f&&-f[0]/2||0;W[0]=d==="italic"&&D||D+5}T.pos=W;const M=new x.Label(T);i.push(M)}}if(await new Promise(k=>{setTimeout(k,0)}),N||P){const k=[],[E]=e.worldScaling;for(let L=0;L<i.length;L++){const{width:T}=i[L].getBoundingClientRect();if(T){const W=i[L].getAttribute("pos");if(N){const M={normalize:!1,pos:[W[0],W[1]+c/2],lineWidth:Math.floor(c/10),points:[0,0,T/E,0],strokeColor:g,name:`${L}_underline`,className:"underline"},D=new x.Polyline(M);k.push(D)}if(P){const M={normalize:!1,pos:W,lineWidth:Math.floor(c/10),points:[0,0,T/E,0],strokeColor:g,name:`${L}_lineThrough`,className:"lineThrough"},D=new x.Polyline(M);k.push(D)}}}return i.concat(k)}return i}static async updateLabels(t,e,s){const{fontSize:i}=t.opt,r=((s==null?void 0:s.parent).displayRatio||1)*((s==null?void 0:s.worldScaling[0])||1),n=i*r;e.children.forEach(c=>{c.tagName==="LABEL"&&(c.setAttribute("fontSize",n),c.setAttribute("scale",[1/r,1/r]),c.setAttribute("lineHeight",n*1.2))})}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:S,textInfos:N,zIndex:P}=s,w=r&&o.cloneDeep(r)||i.get(e.name);if(!w)return;const I=e.parent;if(!I)return;const k=w.opt;if(o.isNumber(P)&&(e.setAttribute("zIndex",P),w.opt.zIndex=P),c&&k.fontColor&&(k.fontColor=c,e.children.forEach(E=>{E.tagName==="LABEL"?E.setAttribute("fillColor",c):E.tagName==="POLYLINE"&&E.setAttribute("strokeColor",c)})),n&&k.fontBgColor&&(k.fontBgColor=n,e.children.forEach(E=>{E.tagName==="LABEL"&&E.setAttribute("bgcolor",n)})),f&&(k.bold=f),u&&(k.italic=u),o.isBoolean(y)&&(k.lineThrough=y),o.isBoolean(g)&&(k.underline=g),S&&(k.fontSize=S),h&&d&&p){const E=N==null?void 0:N.get(e.name);if(E){const{fontSize:W,boxSize:M}=E;k.boxSize=M||k.boxSize,k.fontSize=W||k.fontSize}const L=w.rect,T=o.getRectTranslated(o.getRectScaleed(L,p),d);k.boxPoint=T&&[(T.x-I.worldPosition[0])/I.worldScaling[0],(T.y-I.worldPosition[1])/I.worldScaling[1]]}else if(l&&k.boxPoint&&(k.boxPoint=[k.boxPoint[0]+l[0],k.boxPoint[1]+l[1]],w.centerPos=[w.centerPos[0]+l[0],w.centerPos[1]+l[1]],r)){const E=[l[0]/I.worldScaling[0],l[1]/I.worldScaling[1]];w.rect=o.getRectTranslated(w.rect,E)}return w&&i.setInfo(e.name,w),w==null?void 0:w.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(R){switch(R){case o.EToolsKey.Arrow:return J;case o.EToolsKey.Pencil:return j;case o.EToolsKey.Straight:return ie;case o.EToolsKey.Ellipse:return Q;case o.EToolsKey.Polygon:case o.EToolsKey.Triangle:return oe;case o.EToolsKey.Star:case o.EToolsKey.Rhombus:return te;case o.EToolsKey.Rectangle:return ee;case o.EToolsKey.SpeechBalloon:return se;case o.EToolsKey.Text:return _;case o.EToolsKey.LaserPen:return Z;case o.EToolsKey.Eraser:return $;case o.EToolsKey.Selector:return A;case o.EToolsKey.Image:return Y}}function q(R,a){const{toolsType:t,...e}=R;switch(t){case o.EToolsKey.Arrow:return new J(e);case o.EToolsKey.Pencil:return new j(e);case o.EToolsKey.Straight:return new ie(e);case o.EToolsKey.Ellipse:return new Q(e);case o.EToolsKey.Polygon:case o.EToolsKey.Triangle:return new oe(e);case o.EToolsKey.Star:case o.EToolsKey.Rhombus:return new te(e);case o.EToolsKey.Rectangle:return new ee(e);case o.EToolsKey.SpeechBalloon:return new se(e);case o.EToolsKey.Text:return new _(e);case o.EToolsKey.LaserPen:return new Z(e);case o.EToolsKey.Eraser:return new $(e,a);case o.EToolsKey.Selector:return e.vNodes?new A({...e,vNodes:e.vNodes,drawLayer:e.fullLayer}):void 0;case o.EToolsKey.Image:return new Y(e);default:return}}function ne(R){const a=[],t=["PATH","SPRITE","POLYLINE","RECT","ELLIPSE"];for(const e of R){if(e.tagName==="GROUP"&&e.children.length)return ne(e.children);e.tagName&&t.includes(e.tagName)&&a.push(e)}return a}const he=R=>{if(R.tagName==="GROUP"){const a=Object.getOwnPropertySymbols(R).find(t=>t.toString()==="Symbol(sealed)");if(a&&R[a])return!0}return!1},pe=R=>!R.isHid,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)&&(a=!0);return a}has(a){return 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){var i;const e=re(t.toolsType);if(t.toolsType===o.EToolsKey.Text){const r=(i=this.fullLayer)==null?void 0:i.getElementsByName(a)[0];r&&e.updateLabels(t,r,this.fullLayer)}return this.fullLayer&&(e==null?void 0:e.getRectFromLayer(this.fullLayer,a))}updateNodesRect(){for(const[a,t]of this.curNodeMap.entries()){const e=this.getNodeRectFormShape(a,t);e?(t.rect=e,this.curNodeMap.set(a,t)):this.curNodeMap.delete(a)}}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}clearTarget(){this.targetNodeMap.length=0}}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=t==null?void 0:t.toString(),i=s&&this.localWorkShapes.get(s);if(!i)return;const r=i.node.consume({data:a,isFullWork:!1,isSubWorker:!0});r.rect&&(i.result=r,i.workState=o.EvevtWorkState.Doing,s&&this.localWorkShapes.set(s,i))}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=t==null?void 0:t.toString(),i=s&&this.localWorkShapes.get(s);if(!i)return;const r=i.node.consumeAll({data:a});i.result=r,i.workState=o.EvevtWorkState.Done,s&&this.localWorkShapes.set(s,i)}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}workShapesDone(a,t){for(const e of this.workShapes.keys())this.consumeDrawAll({workId:e,scenePath:a,viewId:this.thread.viewId,msgType:o.EPostMessageType.DrawWork,dataType:o.EDataType.Local},t)}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:S}=u;l.set(f,{opt:S,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.toString()),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 s;this.vNodes.get(a)&&((s=this.thread.fullLayer)==null||s.getElementsByName(a).forEach(i=>{i.remove()}),this.vNodes.delete(a)),this.workShapes.has(a)&&(this.thread.localLayer.getElementsByName(a).forEach(i=>{i.remove()}),this.clearWorkShapeNodeCache(a))}setFullWork(a){const{workId:t,opt:e,toolsType:s}=a;if(t&&e&&s){const i=t.toString(),r=this.workShapes.get(i)||this.createWorkShapeNode({toolsOpt:e,toolsType:s,workId:i});return r?(r.setWorkId(i),this.workShapes.set(i,r),r):void 0}}async consumeFull(a,t){var i;const e=this.setFullWork(a),s=a.ops&&o.transformToNormalData(a.ops);if(e){const r=(i=a.workId)==null?void 0:i.toString();e.toolsType===o.EToolsKey.Image&&t?await e.consumeServiceAsync({scene:t,isFullWork:!0,replaceId:r,isMainThread:!0}):e.toolsType===o.EToolsKey.Text?await e.consumeServiceAsync({isFullWork:!0,replaceId:r}):e.consumeService({op:s,isFullWork:!0,replaceId:r}),a!=null&&a.updateNodeOpt&&e.updataOptService(a.updateNodeOpt);const n=[];a.workId&&this.workShapes.delete(a.workId.toString()),a.willSyncService&&n.push({opt:a.opt,toolsType:a.toolsType,type:o.EPostMessageType.FullWork,workId:a.workId,ops:a.ops,updateNodeOpt:a.updateNodeOpt,viewId:this.thread.viewId}),n.length&&this.thread.post({sp:n})}}async colloctEffectSelectWork(a){const t=this.workShapes.get(o.Storage_Selector_key),{workId:e,msgType:s}=a;if(t&&e&&t.selectIds&&t.selectIds.includes(e.toString())){s===o.EPostMessageType.RemoveNode?t.selectIds=t.selectIds.filter(i=>i!==e.toString()):this.effectSelectNodeData.add(a),await new Promise(i=>{setTimeout(()=>{i(!0)},0)}),await this.runEffectSelectWork(!0).then(()=>{var i;(i=this.effectSelectNodeData)==null||i.clear()});return}return a}async runEffectSelectWork(a){var t,e,s;for(const i of this.effectSelectNodeData.values()){const r=this.setFullWork(i);if(r){const n=(t=i.workId)==null?void 0:t.toString();if(r.toolsType===o.EToolsKey.Image)await r.consumeServiceAsync({scene:(s=(e=this.thread.localLayer)==null?void 0:e.parent)==null?void 0:s.parent,isFullWork:!0,replaceId:n,isMainThread:!0});else if(r.toolsType===o.EToolsKey.Text)await r.consumeServiceAsync({isFullWork:!0,replaceId:n});else{const c=i.ops&&o.transformToNormalData(i.ops);r.consumeService({op:c,isFullWork:!0,replaceId:n}),i!=null&&i.updateNodeOpt&&r.updataOptService(i.updateNodeOpt)}i.workId&&this.workShapes.delete(i.workId.toString())}}this.reRenderSelector(a)}reRenderSelector(a=!1){var s;const t=this.workShapes.get(o.Storage_Selector_key);if(!t)return;if(t&&!((s=t.selectIds)!=null&&s.length))return this.blurSelector();const e=t.reRenderSelector();e&&this.thread.post({sp:[{type:o.EPostMessageType.Select,selectIds:t.selectIds,selectRect:e,willSyncService:a,viewId:this.thread.viewId,points:t.getChildrenPoints(),textOpt:t.textOpt,selectorColor:t.selectorColor,strokeColor:t.strokeColor,fillColor:t.fillColor,canTextEdit:t.canTextEdit,canRotate:t.canRotate,scaleType:t.scaleType,opt:t.getWorkOptions()||void 0,canLock:t.canLock,isLocked:t.isLocked,toolsTypes:t.toolsTypes,shapeOpt:t.shapeOpt}]})}async blurSelector(a){var s;const t=this.workShapes.get(o.Storage_Selector_key),e=t==null?void 0:t.blurSelector();if(this.clearWorkShapeNodeCache(o.Storage_Selector_key),((s=this.thread.fullLayer)==null?void 0:s.parent).children.forEach(i=>{i.name===o.Storage_Selector_key&&i.remove()}),e){const i=[];i.push({...e,isSync:a==null?void 0:a.isSync}),this.thread.post({sp:i})}}clearWorkShapeNodeCache(a){var t,e;(t=this.getWorkShape(a))==null||t.clearTmpPoints(),this.workShapes.delete(a),((e=this.tmpWorkShapeNode)==null?void 0:e.getWorkId())===a&&this.setTmpWorkId(void 0)}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)}),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)}getWorkShapes(){return this.workShapes}consumeDraw(a,t){const{op:e,workId:s,scenePath:i}=a;if(e!=null&&e.length&&s){const r=this.workShapes.get(s.toString());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=e.toString(),l=this.workShapes.get(c);if(!l)return;const h=l.toolsType;if(h===o.EToolsKey.LaserPen)return;const p=this.workShapes.get(G),d=(i=p==null?void 0:p.selectIds)==null?void 0:i[0],f=l.consumeAll({data:a});switch(h){case o.EToolsKey.Selector:f.selectIds&&d&&((r=f.selectIds)!=null&&r.includes(d))&&p.cursorBlur(),f.type===o.EPostMessageType.Select&&(f.selectIds&&t.runReverseSelectWork(f.selectIds),this.thread.post({sp:[{...f,scenePath:s}]})),(n=l.selectIds)!=null&&n.length?l.clearTmpPoints():this.clearWorkShapeNodeCache(c);break;case o.EToolsKey.Eraser:f!=null&&f.rect&&this.drawEraser({...f,scenePath:s}),l.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:f&&(this.drawCount=0,this.thread.post({drawCount:this.drawCount,sp:[f]})),this.clearWorkShapeNodeCache(c);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,S,N;this.animationId=void 0;let a=!1;const t=new Map;for(const[P,w]of this.workShapes.entries())switch(w.toolsType){case o.EToolsKey.Image:{await((s=w.node)==null?void 0:s.consumeServiceAsync({isFullWork:!0,scene:(e=this.thread.fullLayer.parent)==null?void 0:e.parent,isMainThread:!0})),this.selectorWorkShapes.forEach((I,k)=>{var E;(E=I.selectIds)!=null&&E.includes(P)&&(this.willRunEffectSelectorIds.add(k),this.runEffect())}),this.workShapes.delete(P);break}case o.EToolsKey.Text:{w.node&&(await((i=w.node)==null?void 0:i.consumeServiceAsync({isFullWork:!0,replaceId:P})),this.selectorWorkShapes.forEach((I,k)=>{var E;(E=I.selectIds)!=null&&E.includes(P)&&(this.willRunEffectSelectorIds.add(k),this.runEffect())}),(r=w.node)==null||r.clearTmpPoints(),this.workShapes.delete(P));break}case o.EToolsKey.Arrow:case o.EToolsKey.Straight:case o.EToolsKey.Rectangle:case o.EToolsKey.Ellipse:case o.EToolsKey.Star:case o.EToolsKey.Polygon:case o.EToolsKey.SpeechBalloon:{const I=!!w.ops;if((n=w.animationWorkData)!=null&&n.length){const k=w.oldRect;(c=w.node)==null||c.consumeService({op:w.animationWorkData,isFullWork:I}),I&&(this.selectorWorkShapes.forEach((E,L)=>{var T;(T=E.selectIds)!=null&&T.includes(P)&&(this.willRunEffectSelectorIds.add(L),this.runEffect())}),(l=w.node)==null||l.clearTmpPoints(),this.workShapes.delete(P)),t.set(P,{workState:k?w.ops?o.EvevtWorkState.Done:o.EvevtWorkState.Doing:o.EvevtWorkState.Start,op:w.animationWorkData.filter((E,L)=>{if(L%3!==2)return!0}).slice(-2)}),w.animationWorkData.length=0}break}case o.EToolsKey.Pencil:{if(!w.useAnimation&&w.ops)(h=w.node)==null||h.consumeService({op:w.animationWorkData||[],isFullWork:!0,replaceId:P}),(p=w.node)==null||p.updataOptService(w.updateNodeOpt),this.selectorWorkShapes.forEach((I,k)=>{var E;(E=I.selectIds)!=null&&E.includes(P)&&(this.willRunEffectSelectorIds.add(k),this.runEffect())}),(d=w.node)==null||d.clearTmpPoints(),this.workShapes.delete(P);else if(w.useAnimation){if(w.isDel){(f=w.node)==null||f.clearTmpPoints(),this.workShapes.delete(P);break}const I=3,k=this.computNextAnimationIndex(w,I),E=w.isDiff?0:Math.max(0,(w.animationIndex||0)-I),L=(w.animationWorkData||[]).slice(E,k),T=(y=(u=w.node)==null?void 0:u.getWorkId())==null?void 0:y.toString();if((w.animationIndex||0)<k||w.isDiff){if((g=w.node)==null||g.consumeService({op:L,isFullWork:!1}),w.animationIndex=k,w.isDiff&&(w.isDiff=!1),L.length){const W=L.filter((M,D)=>{if(D%I!==I-1)return!0}).slice(-2);t.set(P,{workState:E===0?o.EvevtWorkState.Start:k===((S=w.animationWorkData)==null?void 0:S.length)?o.EvevtWorkState.Done:o.EvevtWorkState.Doing,op:W})}}else w.ops&&((N=w.node)==null||N.consumeService({op:w.animationWorkData||[],isFullWork:!0,replaceId:T}),w.isDel=!0,t.set(P,{workState:o.EvevtWorkState.Done,op:L.filter((W,M)=>{if(M%I!==I-1)return!0}).slice(-2)}));a=!0;break}break}}if(a&&this.runAnimation(),t.size){const P=[];t.forEach((w,I)=>{P.push({type:o.EPostMessageType.Cursor,uid:I.split(o.Storage_Splitter)[0],op:w.op,workState:w.workState,viewId:this.thread.viewId})}),this.thread.post({sp:P})}}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 S={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&&(S=this.setNodeKey(S,s,e)),(y=this.workShapes)==null||y.set(h,S)}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 z{constructor(){m(this,"localWork");m(this,"serviceWork");m(this,"scene")}registerMainThread(a,t,e){return this.localWork=a,this.serviceWork=t,this.scene=e,this}}class me extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.CopyNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.FullWork&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var s;const{workId:e}=t;e&&await((s=this.localWork)==null?void 0:s.consumeFull(t,this.scene))}}class ge extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.SetColorNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var l;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c}=t;e===A.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 Se extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.ZIndexNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var c;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n}=t;e===A.selectorId&&s&&await((c=this.localWork)==null?void 0:c.updateSelector({updateSelectorOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,callback:this.updateSelectorCallback}))}updateSelectorCallback(t){const{param:e,postData:s,newServiceStore:i}=t,{willSyncService:r,isSync:n}=e,c=s.sp||[];if(r&&c)for(const[l,h]of i.entries())c.push({...h,workId:l,type:o.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:n});return{sp:c}}}class we extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.TranslateNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var h,p;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c,emitEventType:l}=t;e===A.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 z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.DeleteNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.RemoveNode){if(s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0;if(s===o.EDataType.Service&&i===this.emitEventType)return this.consumeForServiceWorker(t),!0}}consumeForLocalWorker(t){if(!this.localWork)return;const{removeIds:e,willSyncService:s}=t;if(!(e!=null&&e.length))return;const i=[],r=[];for(const n of e){if(n===o.Storage_Selector_key){const l=this.localWork.workShapes.get(o.Storage_Selector_key);if(!l)return;const h=l.selectIds&&[...l.selectIds]||[];for(const p of h){if(this.localWork.vNodes.get(p)){const 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}),i.length&&this.localWork.thread.post({sp:i})}consumeForServiceWorker(t){this.serviceWork&&this.serviceWork.removeWork(t)}commandDeleteText(t){var s;const e=(s=this.localWork)==null?void 0:s.vNodes.get(t);if(e&&e.toolsType===o.EToolsKey.Text)return{type:o.EPostMessageType.TextUpdate,toolsType:o.EToolsKey.Text,workId:t,dataType:o.EDataType.Local}}}class ke extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.ScaleNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var n;const{workId:e,updateNodeOpt:s,willSyncService:i,willSerializeData:r}=t;e===A.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 z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.RotateNode)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var l;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,emitEventType:c}=t;e===A.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 ve extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.SetFontStyle)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var l;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c}=t;e===A.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 Ee extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.SetPoint)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var l;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c}=t;e===A.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 z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.SetLock)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var c;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n}=t;e===A.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 We extends z{constructor(){super(...arguments);m(this,"emitEventType",o.EmitEventType.SetShapeOpt)}async consume(t){const{msgType:e,dataType:s,emitEventType:i}=t;if(e===o.EPostMessageType.UpdateNode&&s===o.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(t),!0}async consumeForLocalWorker(t){var c;const{workId:e,updateNodeOpt:s,willRefreshSelector:i,willSyncService:r,willSerializeData:n}=t;e===A.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 Ne{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 we;case o.EmitEventType.ZIndexNode:return new Se;case o.EmitEventType.CopyNode:return new me;case o.EmitEventType.SetColorNode:return new ge;case o.EmitEventType.DeleteNode:return new Te;case o.EmitEventType.ScaleNode:return new ke;case o.EmitEventType.RotateNode:return new Pe;case o.EmitEventType.SetFontStyle:return new ve;case o.EmitEventType.SetPoint:return new Ee;case o.EmitEventType.SetLock:return new Ie;case o.EmitEventType.SetShapeOpt:return new We}}registerForMainThread(a,t,e){return this.builders.forEach(s=>{s&&s.registerMainThread(a,t,e)}),this}async consumeForMainThread(a){for(const t of this.builders.values())if(await(t==null?void 0:t.consume(a)))return!0;return!1}}class Me{constructor(a,t){m(this,"viewId");m(this,"fullLayer");m(this,"topLayer");m(this,"localLayer");m(this,"serviceLayer");m(this,"snapshotFullLayer");m(this,"vNodes");m(this,"master");m(this,"opt");m(this,"cameraOpt");m(this,"scene");m(this,"localWork");m(this,"serviceWork");m(this,"topWork");m(this,"mainThreadPostId");m(this,"combinePostMsg",new Set);m(this,"methodBuilder");this.viewId=a,this.opt=t,this.scene=this.createScene({...t.canvasOpt,container:t.container}),this.master=t.master,this.fullLayer=this.createLayer("fullLayer",this.scene,{...t.layerOpt,bufferSize:this.viewId==="mainView"?4e3:2e3}),this.topLayer=this.createLayer("topLayer",this.scene,{...t.layerOpt,bufferSize:this.viewId==="mainView"?1500:1e3}),this.localLayer=this.createLayer("localLayer",this.scene,{...t.layerOpt,bufferSize:this.viewId==="mainView"?1500:1e3}),this.serviceLayer=this.createLayer("serviceLayer",this.scene,{...t.layerOpt,bufferSize:this.viewId==="mainView"?1500:1e3}),this.vNodes=new de(a,this.scene);const e={thread:this,vNodes:this.vNodes};this.localWork=new fe(e),this.serviceWork=new ye(e),this.topWork=new ue(e),this.vNodes.init(this.fullLayer),this.methodBuilder=new Ne([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){if(!await this.methodBuilder.consumeForMainThread(a)){const{msgType:t,toolsType:e,opt:s,dataType:i,workId:r,workState:n}=a,c=r==null?void 0:r.toString();switch(t){case o.EPostMessageType.Destroy:this.destroy();break;case o.EPostMessageType.Clear:this.clearAll();break;case o.EPostMessageType.UpdateCamera:this.updateCamera(a);break;case o.EPostMessageType.UpdateTools:if(i===o.EDataType.Local&&e&&s){const l={toolsType:e,toolsOpt:s};this.localWork.setToolsOpt(l)}break;case o.EPostMessageType.CreateWork:if(r&&s&&e){if(e===o.EToolsKey.LaserPen){this.topWork.getTmpWorkShapeNode()||this.topWork.setToolsOpt({toolsType:e,toolsOpt:s}),c&&this.topWork.setWorkOptions(c,s);break}this.localWork.getTmpWorkShapeNode()||this.localWork.setToolsOpt({toolsType:e,toolsOpt:s}),c&&this.localWork.setWorkOptions(c,s)}break;case o.EPostMessageType.DrawWork:n===o.EvevtWorkState.Done&&i===o.EDataType.Local?this.consumeDrawAll(i,a):this.consumeDraw(i,a);break;case o.EPostMessageType.UpdateNode:case o.EPostMessageType.FullWork:if(e===o.EToolsKey.LaserPen){this.consumeDrawAll(i,a);break}this.consumeFull(i,a);break;case o.EPostMessageType.RemoveNode:this.removeNode(a);return;case o.EPostMessageType.Select:i===o.EDataType.Service&&(r===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:i===o.EDataType.Local&&this.localWork.checkTextActive(a);break}}}async removeNode(a){const{dataType:t,workId:e}=a;if(e===o.Storage_Selector_key){this.localWork.blurSelector(a);return}t===o.EDataType.Local&&(this.localWork.removeWork(a),await this.localWork.colloctEffectSelectWork(a)),t===o.EDataType.Service&&(this.serviceWork.removeWork(a),await this.localWork.colloctEffectSelectWork(a))}async consumeFull(a,t){const e=await this.localWork.colloctEffectSelectWork(t);e&&a===o.EDataType.Local&&await this.localWork.consumeFull(e,this.scene),e&&a===o.EDataType.Service&&this.serviceWork.consumeFull(e)}setCameraOpt(a){this.cameraOpt=a;const{scale:t,centerX:e,centerY:s,width:i,height:r}=a;(i!==this.scene.width||r!==this.scene.height)&&this.updateScene({width:i,height:r}),this.fullLayer.setAttribute("scale",[t,t]),this.fullLayer.setAttribute("translate",[-e,-s]),this.topLayer.setAttribute("scale",[t,t]),this.topLayer.setAttribute("translate",[-e,-s]),this.localLayer.setAttribute("scale",[t,t]),this.localLayer.setAttribute("translate",[-e,-s]),this.serviceLayer.setAttribute("scale",[t,t]),this.serviceLayer.setAttribute("translate",[-e,-s])}runBatchPostData(){this.mainThreadPostId||(this.mainThreadPostId=requestAnimationFrame(this.combinePost.bind(this)))}combinePostData(){var e;this.mainThreadPostId=void 0;const a=[];let t;for(const s of this.combinePostMsg.values()){if((e=s.sp)!=null&&e.length)for(const i of s.sp){let r=!1;for(const n of a)if(o.isEqual(i,n)){r=!0;break}r||a.push(i)}o.isNumber(s.drawCount)&&(t=s.drawCount)}return this.combinePostMsg.clear(),{sp:a,drawCount:t}}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!=null&&a.drawCount||(i=a.sp)!=null&&i.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(),this.post({sp:[{type:o.EPostMessageType.Clear}]})}consumeDrawAll(a,t){const{ops:e,op:s,workId:i}=t;if((e||s!=null&&s.length)&&i){const r=i.toString();if(this.topWork.localWorkShapes.get(r)){this.topWork.consumeDrawAll(t);return}if(this.localWork.workShapes.get(r)){this.localWork.consumeDrawAll(t,this.serviceWork);return}}}consumeDraw(a,t){const{op:e,workId:s}=t;if(e!=null&&e.length&&s){const i=s.toString();if(this.topWork.localWorkShapes.get(i)){this.topWork.consumeDraw(t);return}if(this.localWork.workShapes.get(i)){this.localWork.consumeDraw(t,this.serviceWork);return}a===o.EDataType.Service&&this.serviceWork.consumeDraw(t)}}updateCamera(a){var s;const{cameraOpt:t,scenePath:e}=a;if(t&&!o.isEqual(this.cameraOpt,t)){const i=this.localWork.getWorkShape(G);if(i&&((s=i.selectIds)!=null&&s.length)&&i.cursorBlur(),e&&[...this.localWork.getWorkShapes().keys()].filter(n=>n!==G).length&&this.localWork.workShapesDone(e,this.serviceWork),this.setCameraOpt(t),this.vNodes.curNodeMap.size&&(this.vNodes.clearTarget(),this.vNodes.updateNodesRect(),this.localWork.reRenderSelector(),this.serviceWork.selectorWorkShapes.size))for(const[r,n]of this.serviceWork.selectorWorkShapes.entries())this.serviceWork.runSelectWork({workId:r,selectIds:n.selectIds,msgType:o.EPostMessageType.Select,dataType:o.EDataType.Service,viewId:this.viewId})}}createScene(a){return new x.Scene({displayRatio:this.opt.displayer.dpr,depth:!1,desynchronized:!0,...a,autoRender:!0,id:this.viewId})}createLayer(a,t,e){const{width:s,height:i}=e,r=`canvas-${a}`,n=t.layer(r,{...e,offscreen:!1}),c=new x.Group({anchor:[.5,.5],pos:[s*.5,i*.5],size:[s,i],name:"viewport",id:a});return n.append(c),c}updateScene(a){this.scene.attr({...a});const{width:t,height:e}=a;this.scene.width=t,this.scene.height=e,this.updateLayer({width:t,height:e})}updateLayer(a){const{width:t,height:e}=a;this.fullLayer.parent.setAttribute("width",t),this.fullLayer.parent.setAttribute("height",e),this.fullLayer.setAttribute("size",[t,e]),this.fullLayer.setAttribute("pos",[t*.5,e*.5]),this.topLayer.parent.setAttribute("width",t),this.topLayer.parent.setAttribute("height",e),this.topLayer.setAttribute("size",[t,e]),this.topLayer.setAttribute("pos",[t*.5,e*.5]),this.localLayer.parent.setAttribute("width",t),this.localLayer.parent.setAttribute("height",e),this.localLayer.setAttribute("size",[t,e]),this.localLayer.setAttribute("pos",[t*.5,e*.5]),this.serviceLayer.parent.setAttribute("width",t),this.serviceLayer.parent.setAttribute("height",e),this.serviceLayer.setAttribute("size",[t,e]),this.serviceLayer.setAttribute("pos",[t*.5,e*.5])}destroy(){this.vNodes.clear(),this.fullLayer.remove(),this.topLayer.remove(),this.localLayer.remove(),this.serviceLayer.remove(),this.scene.remove(),this.localWork.destroy(),this.serviceWork.destroy(),this.topWork.destroy()}}class Re{constructor(a,t){m(this,"viewId");m(this,"fullLayer");m(this,"master");m(this,"opt");m(this,"scene");m(this,"mainThreadPostId");m(this,"combinePostMsg",new Set);m(this,"workShapes",new Map);this.viewId=a,this.opt=t,this.scene=this.createScene({...t.canvasOpt,container:t.container}),this.master=t.master,this.fullLayer=this.createLayer("fullLayer",this.scene,{...t.layerOpt,bufferSize:this.viewId==="mainView"?6e3:3e3})}post(a){this.combinePostMsg.add(a),this.runBatchPostData()}async on(a){const{msgType:t}=a;switch(t){case o.EPostMessageType.Snapshot:await this.getSnapshot(a),this.destroy();return;case o.EPostMessageType.BoundingBox:await this.getBoundingRect(a),this.destroy();return}}createWorkShapeNode(a){return q({...a,fullLayer:this.fullLayer,drawLayer:void 0})}setFullWork(a){const{workId:t,opt:e,toolsType:s}=a;if(t&&e&&s){const i=t.toString(),r=this.workShapes.get(i)||this.createWorkShapeNode({toolsOpt:e,toolsType:s,workId:i});return r?(r.setWorkId(t.toString()),this.workShapes.set(i,r),r):void 0}}async runFullWork(a){var s,i;const t=this.setFullWork(a),e=a.ops&&o.transformToNormalData(a.ops);if(t){let r,n;const c=(s=t.getWorkId())==null?void 0:s.toString();return t.toolsType===o.EToolsKey.Image?r=await t.consumeServiceAsync({isFullWork:!0,scene:(i=this.fullLayer.parent)==null?void 0:i.parent,isMainThread:!0}):t.toolsType===o.EToolsKey.Text?r=await t.consumeServiceAsync({isFullWork:!0,replaceId:c,isDrawLabel:!0}):(r=t.consumeService({op:e,isFullWork:!0,replaceId:c}),n=(a==null?void 0:a.updateNodeOpt)&&t.updataOptService(a.updateNodeOpt)),o.computRect(r,n)}}async getSnapshot(a){const{scenePath:t,scenes:e,cameraOpt:s,w:i,h:r}=a;if(t&&e&&s){this.setCameraOpt(s);let n;for(const[l,h]of Object.entries(e))if(h!=null&&h.type)switch(h==null?void 0:h.type){case o.EPostMessageType.UpdateNode:case o.EPostMessageType.FullWork:{const{opt:p}=h,d=await this.runFullWork({...h,opt:p,workId:l,msgType:o.EPostMessageType.FullWork,dataType:o.EDataType.Service,viewId:this.viewId});n=o.computRect(n,d);break}}let c;i&&r&&(c={resizeWidth:i,resizeHeight:r}),await this.getSnapshotRender({scenePath:t,options:c})}}getSceneRect(){const{width:a,height:t}=this.scene;return{x:0,y:0,w:Math.floor(a),h:Math.floor(t)}}getRectImageBitmap(a,t){const e=a.x*this.opt.displayer.dpr,s=a.y*this.opt.displayer.dpr,i=a.w>0&&a.w*this.opt.displayer.dpr||1,r=a.h>0&&a.h*this.opt.displayer.dpr||1;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||(i=a.sp)!=null&&i.length)&&this.opt.post(a)}createScene(a){return new x.Scene({displayRatio:this.opt.displayer.dpr,depth:!1,desynchronized:!0,...a,autoRender:!1})}createLayer(a,t,e){const{width:s,height:i}=e,r=`canvas-${a}`,n=t.layer(r,e),c=new x.Group({anchor:[.5,.5],pos:[s*.5,i*.5],size:[s,i],name:"viewport",id:a});return n.append(c),c}updateScene(a){this.scene.attr({...a});const{width:t,height:e}=a;this.scene.width=t,this.scene.height=e,this.updateLayer({width:t,height:e})}updateLayer(a){const{width:t,height:e}=a;this.fullLayer.parent.setAttribute("width",t),this.fullLayer.parent.setAttribute("height",e),this.fullLayer.setAttribute("size",[t,e]),this.fullLayer.setAttribute("pos",[t*.5,e*.5])}destroy(){this.fullLayer.remove(),this.scene.remove()}}class Le{constructor(a){m(this,"mainThreadMap",new Map);m(this,"snapshotThread");m(this,"master");this.master=a}post(a){const{drawCount:t,sp:e,workerTasksqueueCount:s}=a;this.master.isBusy&&o.isNumber(s)&&this.master.setWorkerTasksqueueCount(s),o.isNumber(t)&&this.master.setMaxDrawCount(t),e&&this.master.collectorSyncData(e)}destroy(){this.mainThreadMap.clear()}createMainThread(a,t){return new Me(a,t)}createSnapshotThread(a,t){return new Re(a,t)}async 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 S=this.createMainThread(c,{displayer:y,container:g,layerOpt:p,master:this.master,canvasOpt:d,post:this.post.bind(this)});this.mainThreadMap.set(c,S),S&&f&&S.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 S={...o.ViewContainerManager.defaultLayerOpt,offscreen:!1,width:f.width,height:f.height},N={...o.ViewContainerManager.defaultScreenCanvasOpt,width:f.width,height:f.height};this.snapshotThread=this.createSnapshotThread(c,{displayer:y,container:g,layerOpt:S,master:this.master,canvasOpt:N,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)){for(const[y,g]of this.mainThreadMap.entries()){const S=l.get(y);S&&(await g.on(S),h&&this.post({workerTasksqueueCount: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=Le;
|