@netless/appliance-plugin 1.0.1 → 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.
Files changed (73) hide show
  1. package/README.md +1 -10
  2. package/cdn/cdn.js +1 -1
  3. package/cdn/fullWorker-6Cu08P.js +438 -0
  4. package/cdn/subWorker-B3CHpe.js +438 -0
  5. package/dist/appliance-plugin.js +1 -1
  6. package/dist/appliance-plugin.mjs +12 -11
  7. package/dist/collector/base.d.ts +3 -1
  8. package/dist/collector/collector.d.ts +5 -4
  9. package/dist/collector/eventCollector.d.ts +2 -1
  10. package/dist/collector/magixEventCollector.d.ts +30 -0
  11. package/dist/collector/types.d.ts +27 -7
  12. package/dist/component/textEditor/manager.d.ts +2 -2
  13. package/dist/component/textEditor/types.d.ts +0 -1
  14. package/dist/component/textEditor/view.d.ts +4 -1
  15. package/dist/core/const.d.ts +2 -0
  16. package/dist/core/enum.d.ts +12 -5
  17. package/dist/core/mainEngine.d.ts +31 -10
  18. package/dist/core/mainThread/base.d.ts +6 -2
  19. package/dist/core/mainThread/snapshotThread.d.ts +3 -3
  20. package/dist/core/mainThread/subLocalThread.d.ts +18 -10
  21. package/dist/core/mainThread/subServiceThread.d.ts +2 -1
  22. package/dist/core/mainThread/subTopThread.d.ts +15 -8
  23. package/dist/core/msgEvent/deleteNode/forMainThread.d.ts +1 -5
  24. package/dist/core/msgEvent/deleteNode/forWorker.d.ts +1 -5
  25. package/dist/core/msgEvent/scaleNode/forMain.d.ts +1 -0
  26. package/dist/core/msgEvent/setFont/forMain.d.ts +2 -1
  27. package/dist/core/tools/arrow.d.ts +36 -7
  28. package/dist/core/tools/base.d.ts +22 -8
  29. package/dist/core/tools/ellipse.d.ts +36 -7
  30. package/dist/core/tools/eraser.d.ts +40 -4
  31. package/dist/core/tools/image.d.ts +9 -5
  32. package/dist/core/tools/laserPen.d.ts +34 -4
  33. package/dist/core/tools/pencil.d.ts +37 -4
  34. package/dist/core/tools/polygon.d.ts +36 -7
  35. package/dist/core/tools/rectangle.d.ts +36 -7
  36. package/dist/core/tools/selector.d.ts +52 -4
  37. package/dist/core/tools/speechBalloon.d.ts +36 -8
  38. package/dist/core/tools/star.d.ts +36 -7
  39. package/dist/core/tools/straight.d.ts +36 -7
  40. package/dist/core/tools/text.d.ts +20 -10
  41. package/dist/core/tools/utils.d.ts +6 -5
  42. package/dist/core/types.d.ts +1 -1
  43. package/dist/core/utils/index.d.ts +10 -0
  44. package/dist/core/utils/math.d.ts +1 -0
  45. package/dist/core/{mainThread/vNodeManager.d.ts → vNodeManager.d.ts} +9 -3
  46. package/dist/core/worker/base.d.ts +18 -16
  47. package/dist/core/worker/fullWorkerLocal.d.ts +18 -9
  48. package/dist/core/worker/fullWorkerService.d.ts +10 -9
  49. package/dist/core/worker/subWorkerLocal.d.ts +5 -8
  50. package/dist/core/worker/subWorkerTopLayer.d.ts +13 -9
  51. package/dist/core/worker/workerManager.d.ts +18 -10
  52. package/dist/cursors/index.d.ts +44 -18
  53. package/dist/fullWorker.js +131 -146
  54. package/dist/index-CeTiLZdq.mjs +5619 -0
  55. package/dist/index-DHkeFixk.js +1 -0
  56. package/dist/index-DmkMw23K.mjs +9486 -0
  57. package/dist/index-Dmq7rqSP.js +1 -0
  58. package/dist/plugin/applianceSinglePlugin.d.ts +1 -0
  59. package/dist/plugin/baseApplianceManager.d.ts +7 -1
  60. package/dist/plugin/baseViewContainerManager.d.ts +0 -3
  61. package/dist/plugin/const.d.ts +11 -1
  62. package/dist/plugin/displayerView.d.ts +1 -3
  63. package/dist/plugin/multi/containerManager.d.ts +2 -1
  64. package/dist/style.css +1 -1
  65. package/dist/subWorker.js +131 -146
  66. package/package.json +2 -3
  67. package/cdn/fullWorker-CIvt1j.js +0 -453
  68. package/cdn/subWorker-BE-0dg.js +0 -453
  69. package/dist/core/worker/vNodeManager.d.ts +0 -34
  70. package/dist/index-BcIJbozZ.js +0 -1
  71. package/dist/index-C1YKkWHE.mjs +0 -9090
  72. package/dist/index-ClJPZxV-.mjs +0 -5462
  73. package/dist/index-SsMz_ohn.js +0 -1
@@ -0,0 +1 @@
1
+ "use strict";var Ee=Object.defineProperty;var Ie=(L,a,e)=>a in L?Ee(L,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):L[a]=e;var m=(L,a,e)=>(Ie(L,typeof a!="symbol"?a+"":a,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index-Dmq7rqSP.js"),b=require("spritejs"),Re=require("lineclip");require("lz-string");const H=require("lodash");require("white-web-sdk");require("react-dom");require("react");var Me=s._baseGetTag,Le=s.isObjectLike_1,We="[object Number]";function Ne(L){return typeof L=="number"||Le(L)&&Me(L)==We}var be=Ne;const K=s.getDefaultExportFromCjs(be),F=class F{constructor(a){m(this,"syncUnitTime",s.DefaultAppliancePluginOptions.syncOpt.interval);m(this,"vNodes");m(this,"drawLayer");m(this,"fullLayer");m(this,"workId");const{vNodes:e,fullLayer:t,drawLayer:o,workId:i,toolsOpt:r}=a;this.vNodes=e,this.fullLayer=t,this.drawLayer=o,this.workId=i,this.syncUnitTime=r.syncUnitTime||this.syncUnitTime}get baseConsumeResult(){return{workId:this.workId,toolsType:this.toolsType,opt:this.workOptions}}filterSamePoints(a,e=.01){return a.reduce((t,o)=>{const i=t[t.length-1];return(o&&!i||o&&i&&!o.isNear(i,e))&&t.push(o),t},[])}setWorkId(a){this.workId=a}getWorkId(){return this.workId}getWorkOptions(){return this.workOptions}setWorkOptions(a){var o,i,r;this.workOptions=a,this.syncUnitTime=a.syncUnitTime||this.syncUnitTime;const e=(o=this.workId)==null?void 0:o.toString(),t=e&&((i=this.vNodes)==null?void 0:i.get(e))||void 0;e&&t&&(t.opt=a,(r=this.vNodes)==null||r.setInfo(e,t))}updataOptService(a){var o,i;let e;const t=(o=this.workId)==null?void 0:o.toString();if(t&&a){const r=this.fullLayer.getElementsByName(t)||this.drawLayer&&this.drawLayer.getElementsByName(t)||[];if(r.length!==1)return;const n=r[0],{pos:c,zIndex:l,scale:h,angle:p,translate:d}=a,f={};K(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&&(e=s.computRect(e,{x:Math.floor(u.x-F.SafeBorderPadding),y:Math.floor(u.y-F.SafeBorderPadding),w:Math.floor(u.width+F.SafeBorderPadding*2),h:Math.floor(u.height+F.SafeBorderPadding*2)})),(i=this.vNodes)==null||i.setInfo(t,{rect:e,centerPos:c}),e}}replace(a,e,t){var n;const o=a.getElementsByName(e),i=o.length;if(i){if(i>1)for(let c=1;c<o.length;c++)a.removeChild(o[c]),o[c].disconnect();t?a.replaceChild(t,o[0]):a.removeChild(o[0]),o[0].disconnect()}else t&&a.append(t);this.fullLayer===a?(n=this.drawLayer)==null||n.getElementsByName(e).forEach(c=>{var l;(l=this.drawLayer)==null||l.removeChild(c),c.disconnect()}):this.fullLayer.getElementsByName(e).forEach(c=>{this.fullLayer.removeChild(c),c.disconnect()})}static updateNodeOpt(a){const{node:e,opt:t,vNodes:o,willSerializeData:i,targetNode:r}=a,{zIndex:n,translate:c,angle:l,box:h,boxScale:p,boxTranslate:d,pointMap:f}=t;let u;const y=r&&s.cloneDeep(r)||o.get(e.name);if(!y)return;K(n)&&(e.setAttribute("zIndex",n),y.opt.zIndex=n);const w=e.parent;if(w){if(h&&d&&p){const{rect:g}=y,M=[];for(let R=0;R<y.op.length;R+=3)M.push(new s.Point2d(y.op[R],y.op[R+1],y.op[R+2]));const k=s.getRectFromPoints(M),S=[k.w*w.worldScaling[0],k.h*w.worldScaling[0]],I=[g.w-S[0],g.h-S[1]],v=[(g.w*p[0]-I[0])/S[0],(g.h*p[1]-I[1])/S[1]],E=[d[0]/w.worldScaling[0],d[1]/w.worldScaling[1]],N=y.op.map((R,W)=>{const D=W%3;return D===0?R+E[0]:D===1?R+E[1]:R}),T=[y.centerPos[0]+E[0],y.centerPos[1]+E[1]];s.scalePoints(N,T,v),s.checkOp(N)&&(y.op=N),y.centerPos=T}else if(c)if(e.setAttribute("translate",c),y.opt.translate=c,r){const g=[c[0]*w.worldScaling[0],c[1]*w.worldScaling[1]];u=s.getRectTranslated(y.rect,g),y.rect=u}else{const g=F.getRectFromLayer(w,e.name);y.rect=g||y.rect}else if(K(l))if(e.setAttribute("rotate",l),y.opt.rotate=l,r)u=s.getRectRotated(y.rect,l),y.rect=u;else{const g=F.getRectFromLayer(w,e.name);y.rect=g||y.rect}if(f){const g=f.get(e.name);if(g)for(let M=0,k=0;M<y.op.length;M+=3,k++)y.op[M]=g[k][0],y.op[M+1]=g[k][1]}if(i){if(c){const g=[c[0],c[1]],M=y.op.map((k,S)=>{const I=S%3;return I===0?k+g[0]:I===1?k+g[1]:k});y.op=M,y.centerPos=[y.centerPos[0]+g[0],y.centerPos[1]+g[1]],y!=null&&y.opt&&(y.opt.translate=void 0)}else if(K(l)){const g=y.op;s.rotatePoints(g,y.centerPos,l),y.op=g,y!=null&&y.opt&&(y.opt.rotate=void 0)}}y&&o.setInfo(e.name,y)}}static getCenterPos(a,e){const{worldPosition:t,worldScaling:o}=e;return[(a.x+a.w/2-t[0])/o[0],(a.y+a.h/2-t[1])/o[1]]}static getRectFromLayer(a,e){const t=a.getElementsByName(e)[0];if(t){const o=t.getBoundingClientRect();return{x:Math.floor(o.x-F.SafeBorderPadding),y:Math.floor(o.y-F.SafeBorderPadding),w:Math.floor(o.width+F.SafeBorderPadding*2),h:Math.floor(o.height+F.SafeBorderPadding*2)}}}};m(F,"SafeBorderPadding",10);let P=F;function j(L,a=!0){const e=L.length;if(e<2)return"";let t=L[0],o=L[1];if(e===2)return`M${s.precise(t)}L${s.precise(o)}`;let i="";for(let r=2,n=e-1;r<n;r++)t=L[r],o=L[r+1],i+=s.average(t,o);return a?`M${s.average(L[0],L[1])}Q${s.precise(L[1])}${s.average(L[1],L[2])}T${i}${s.average(L[e-1],L[0])}${s.average(L[0],L[1])}Z`:`M${s.precise(L[0])}Q${s.precise(L[1])}${s.average(L[1],L[2])}${L.length>3?"T":""}${i}L${s.precise(L[e-1])}`}class de extends P{constructor(e){super(e);m(this,"canRotate",!0);m(this,"scaleType",s.EScaleType.all);m(this,"toolsType",s.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=e.toolsOpt,this.uniThickness=this.MAX_REPEAR/this.workOptions.thickness/10,this.syncTimestamp=0}combineConsume(){var n;const e=(n=this.workId)==null?void 0:n.toString();if(this.tmpPoints.length<2)return{type:s.EPostMessageType.None};const t=this.transformDataAll(!0),o={name:e};let i;const r=this.drawLayer||this.fullLayer;return t.length&&(i=this.draw({attrs:o,tasks:t,replaceId:e,layer:r})),{rect:i,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local}}setWorkOptions(e){super.setWorkOptions(e),this.syncTimestamp=Date.now()}consume(e){const{data:t,isFullWork:o,isSubWorker:i,isMainThread:r,drawCount:n,replaceId:c}=e,{workId:l}=t,{tasks:h,effects:p,consumeIndex:d}=this.transformData(t,!1);this.syncIndex=Math.min(this.syncIndex,d,Math.max(0,this.tmpPoints.length-2));const f={name:l,id:n==null?void 0:n.toString()};let u,y=!1;const w=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 M=o?this.fullLayer:this.drawLayer||this.fullLayer;u=this.draw({attrs:f,tasks:h,effects:p,layer:M,replaceId:c})}if(i)return d>10&&this.tmpPoints.splice(0,d-10),{rect:u,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local};const g=[];return this.tmpPoints.slice(w).forEach(M=>{g.push(M.x,M.y,this.computRadius(M.z,this.workOptions.thickness))}),{...this.baseConsumeResult,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,rect:u,op:y?g:void 0,index:y?w*3:void 0,updateNodeOpt:{useAnimation:!0}}}consumeAll(e){var h;const t=this.workId;if(e.data){const{op:p,workState:d}=e.data;p!=null&&p.length&&d===s.EvevtWorkState.Done&&this.workOptions.strokeType===s.EStrokeType.Stroke&&this.updateTempPointsWithPressureWhenDone(p)}const o=this.transformDataAll(!0),i={name:t};let r;const n=this.fullLayer;if(o.length&&(r=this.draw({attrs:i,tasks:o,replaceId:t,layer:n})),this.tmpPoints.length<2)return this.replace(n,t),{type:s.EPostMessageType.RemoveNode,removeIds:[t],rect:r};const c=[];this.tmpPoints.map(p=>{c.push(p.x,p.y,this.computRadius(p.z,this.workOptions.thickness))}),this.syncTimestamp=0,delete this.workOptions.syncUnitTime;const l=s.transformToSerializableData(c);return(h=this.vNodes)==null||h.setInfo(t,{rect:r,op:c,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:r&&P.getCenterPos(r,n)}),{...this.baseConsumeResult,rect:r,type:s.EPostMessageType.FullWork,dataType:s.EDataType.Local,ops:l,updateNodeOpt:{pos:this.centerPos,useAnimation:!0}}}clearTmpPoints(){this.tmpPoints.length=0,this.syncTimestamp=0,this.syncIndex=0}consumeService(e){var h,p;const{op:t,isFullWork:o,replaceId:i}=e;this.tmpPoints.length=0;for(let d=0;d<t.length;d+=3){const f=new s.Point2d(t[d],t[d+1],t[d+2]);if(this.tmpPoints.length>0){const u=this.tmpPoints[this.tmpPoints.length-1],y=s.Vec2d.Sub(f,u).uni();f.setv(y)}this.tmpPoints.push(f)}if(this.tmpPoints.length<2)return;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=o?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:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:l&&P.getCenterPos(l,d)})}return l}transformDataAll(e=!0){const t=this.filterSamePoints(this.tmpPoints,this.workOptions.thickness);return this.getTaskPoints(t,e&&this.workOptions.thickness||void 0)}draw(e){const{attrs:t,tasks:o,replaceId:i,effects:r,layer:n}=e,{strokeColor:c,strokeType:l,thickness:h,zIndex:p,scale:d,rotate:f,translate:u}=this.workOptions;r!=null&&r.size&&(r.forEach(S=>{var I;(I=n.getElementById(S+""))==null||I.remove()}),r.clear());let y;const w=[],g=n.worldPosition,M=n.worldScaling;for(let S=0;S<o.length;S++){const{pos:I,points:v}=o[S],{ps:E,rect:N}=this.computDrawPoints(v);let T;const R=v.length===1;l===s.EStrokeType.Stroke||R?T=j(E,!0):T=j(E,!1);const W={pos:I,d:T,fillColor:l===s.EStrokeType.Stroke||R?c:void 0,lineDash:l===s.EStrokeType.Dotted&&!R?[1,h*2]:l===s.EStrokeType.LongDotted&&!R?[h,h*2]:void 0,strokeColor:c,lineCap:l===s.EStrokeType.Stroke||R?void 0:"round",lineWidth:l===s.EStrokeType.Stroke||R?0:h};y=s.computRect(y,{x:Math.floor((N.x+I[0])*M[0]+g[0]-P.SafeBorderPadding),y:Math.floor((N.y+I[1])*M[1]+g[1]-P.SafeBorderPadding),w:Math.floor(N.w*M[0]+2*P.SafeBorderPadding),h:Math.floor(N.h*M[1]+2*P.SafeBorderPadding)}),w.push(W)}d&&(t.scale=d),f&&(t.rotate=f),u&&(t.translate=u);const k=new b.Group;if(y){this.centerPos=P.getCenterPos(y,n),k.attr({...t,normalize:!0,anchor:[.5,.5],bgcolor:l===s.EStrokeType.Stroke?c:void 0,pos:this.centerPos,size:[(y.w-2*P.SafeBorderPadding)/M[0],(y.h-2*P.SafeBorderPadding)/M[1]],zIndex:p});const S=w.map(I=>(I.pos=[I.pos[0]-this.centerPos[0],I.pos[1]-this.centerPos[1]],new b.Path(I)));k.append(...S),l===s.EStrokeType.Stroke&&k.seal(),this.replace(n,i||t.workId,k)}if(d||f||u){const S=k==null?void 0:k.getBoundingClientRect();if(S)return{x:Math.floor(S.x-P.SafeBorderPadding),y:Math.floor(S.y-P.SafeBorderPadding),w:Math.floor(S.width+P.SafeBorderPadding*2),h:Math.floor(S.height+P.SafeBorderPadding*2)}}return y}computDrawPoints(e){return this.workOptions.strokeType===s.EStrokeType.Stroke||e.length===1?this.computStroke(e):this.computNomal(e)}computNomal(e){let t=this.workOptions.thickness;const o=e.map(i=>(t=Math.max(t,i.radius),i.point));return{ps:o,rect:s.getRectFromPoints(o,t)}}computStroke(e){return e.length===1?this.computDotStroke(e[0]):this.computLineStroke(e)}computLineStroke(e){const t=[],o=[];for(let l=0;l<e.length;l++){const{point:h,radius:p}=e[l];let d=h.v;l===0&&e.length>1&&(d=e[l+1].point.v);const f=s.Vec2d.Per(d).mul(p);t.push(s.Point2d.Sub(h,f)),o.push(s.Point2d.Add(h,f))}const i=e[e.length-1],r=s.Point2d.GetSemicircleStroke(i.point,t[t.length-1],-1,8),n=s.Point2d.GetSemicircleStroke(e[0].point,o[0],-1,8),c=t.concat(r,o.reverse(),n);return{ps:c,rect:s.getRectFromPoints(c)}}computDotStroke(e){const{point:t,radius:o}=e,i={x:t.x-o,y:t.y-o,w:o*2,h:o*2};return{ps:s.Point2d.GetDotStroke(t,o,8),rect:i}}transformData(e,t){const{op:o,workState:i}=e;let r=this.tmpPoints.length-1,n=[];if(o!=null&&o.length&&i){const{strokeType:c,thickness:l}=this.workOptions,h=new Set;r=c===s.EStrokeType.Stroke?this.updateTempPointsWithPressure(o,l,h):this.updateTempPoints(o,l,h);const p=t?this.tmpPoints:this.tmpPoints.slice(r);return n=this.getTaskPoints(p,l),{tasks:n,effects:h,consumeIndex:r}}return{tasks:n,consumeIndex:r}}computRadius(e,t){return e*.03*t+t*.5}getMinZ(e,t){return((t||Math.max(1,Math.floor(e*.3)))-e*.5)*100/e/3}getTaskPoints(e,t){var p;const o=[];if(e.length===0)return[];let i=0,r=e[0].x,n=e[0].y,c=[r,n],l=[],h=e[0].t;for(;i<e.length;){const d=e[i],f=d.x-r,u=d.y-n,y=d.z,w=t?this.computRadius(y,t):y;if(l.push({point:new s.Point2d(f,u,y,e[i].v),radius:w}),i>0&&i<e.length-1){const g=e[i].getAngleByPoints(e[i-1],e[i+1]);if(g<90||g>270){const M=(p=l.pop())==null?void 0:p.point.clone();M&&o.push({taskId:h,pos:c,points:[...l,{point:M,radius:w}]}),r=e[i].x,n=e[i].y,c=[r,n];const k=d.x-r,S=d.y-n;l=[{point:new s.Point2d(k,S,y),radius:w}],h=Date.now()}}i++}return o.push({taskId:h,pos:c,points:l}),o}updateTempPointsWithPressure(e,t,o){const i=Date.now(),r=this.tmpPoints.length;let n=r;for(let l=0;l<e.length;l+=2){n=Math.min(n,r);const h=this.tmpPoints.length,p=new s.Point2d(e[l],e[l+1]);if(h===0){this.tmpPoints.push(p);continue}const d=h-1,f=this.tmpPoints[d],u=s.Vec2d.Sub(p,f).uni();if(p.isNear(f,t)){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 g=h-1;for(;g>0;){const M=this.tmpPoints[g].distance(this.tmpPoints[g-1]),k=Math.max(this.tmpPoints[g].z-this.uniThickness*M,0);if(this.tmpPoints[g-1].z>=k)break;this.tmpPoints[g-1].setz(k),n=Math.min(n,g-1),g--}}}else n=1/0;continue}p.setv(u);const y=p.distance(f),w=Math.max(f.z-this.uniThickness*y,0);h>1&&s.Vec2d.Equals(u,f.v,.02)&&(w>0||f.z<=0)&&(o&&f.t&&o.add(f.t),this.tmpPoints.pop(),n=Math.min(d,n)),p.setz(w),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&&(o==null||o.add(l))}else{let l=r-1;for(c=n;l>=0;){const h=this.tmpPoints[l].t;if(h&&(o==null||o.add(h),l<=n)){c=l,l=-1;break}l--}}return this.tmpPoints[c].setT(i),c}updateTempPoints(e,t,o){var l;const i=Date.now(),r=this.tmpPoints.length;let n=r;for(let h=0;h<e.length;h+=2){const p=this.tmpPoints.length,d=new s.Point2d(e[h],e[h+1]);if(p===0){this.tmpPoints.push(d);continue}const f=p-1,u=this.tmpPoints[f],y=s.Vec2d.Sub(d,u).uni();if(d.isNear(u,t/2)){n=Math.min(f,n);continue}s.Vec2d.Equals(y,u.v,.02)&&(o&&u.t&&o.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&&(o==null||o.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&&(o==null||o.add(p),h<=n)){c=h,h=-1;break}h--}}return this.tmpPoints[c].setT(i),c}updateTempPointsWithPressureWhenDone(e){const{thickness:t}=this.workOptions,o=e.length,i=this.getMinZ(t);for(let r=0;r<o;r+=2){const n=this.tmpPoints.length,c=new s.Point2d(e[r],e[r+1]);if(n===0){this.tmpPoints.push(c);continue}const l=n-1,h=this.tmpPoints[l],p=s.Vec2d.Sub(c,h).uni(),d=c.distance(h);if(n>1&&h.z===i)break;if(c.isNear(h,t/2)){if(o<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]),w=Math.max(this.tmpPoints[u].z-this.uniThickness*y,-t/4);if(this.tmpPoints[u-1].z>=w)break;this.tmpPoints[u-1].setz(w),u--}}continue}c.setv(p);const f=Math.max(h.z-this.uniThickness*d,i);n>1&&s.Vec2d.Equals(p,h.v,.02)&&h.z<=0&&this.tmpPoints.pop(),c.setz(f),this.tmpPoints.push(c)}}static updateNodeOpt(e){var c;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r}=o,n=i.get(t.name);return r&&(t.tagName==="GROUP"?xe(t)?t.setAttribute("bgcolor",r):t.children.forEach(l=>{l.setAttribute("strokeColor",r),l.getAttribute("fillColor")&&l.setAttribute("fillColor",r)}):(t.setAttribute("strokeColor",r),t.setAttribute("fillColor",r)),(c=n==null?void 0:n.opt)!=null&&c.strokeColor&&(n.opt.strokeColor=r)),n&&i.setInfo(t.name,n),P.updateNodeOpt(e)}}class ue extends P{constructor(e){super(e);m(this,"toolsType",s.EToolsKey.LaserPen);m(this,"canRotate",!1);m(this,"scaleType",s.EScaleType.none);m(this,"syncTimestamp");m(this,"syncIndex",0);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"consumeIndex",0);this.workOptions=e.toolsOpt,this.syncTimestamp=0}combineConsume(){}setWorkOptions(e){super.setWorkOptions(e),this.syncTimestamp=Date.now()}consume(e){const{data:t,isSubWorker:o}=e,{workId:i,op:r}=t;if((r==null?void 0:r.length)===0)return{type:s.EPostMessageType.None};if(this.updateTempPoints(r||[]),this.consumeIndex>this.tmpPoints.length-4)return{type:s.EPostMessageType.None};const{strokeColor:n,thickness:c,strokeType:l}=this.workOptions,h=s.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===s.EStrokeType.Dotted?[1,c*2]:l===s.EStrokeType.LongDotted?[c,c*2]:void 0,strokeColor:n,lineCap:"round",lineWidth:c,anchor:[.5,.5]},y=this.getTaskPoints(f);if(y.length){const g=Date.now();g-this.syncTimestamp>this.syncUnitTime&&(p=!0,this.syncTimestamp=g,this.syncIndex=this.tmpPoints.length),o&&this.draw({attrs:u,tasks:y,isDot:!1,layer:this.drawLayer||this.fullLayer})}const w=[];return this.tmpPoints.slice(d).forEach(g=>{w.push(g.x,g.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:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,op:p?w:void 0,index:p?d*2:void 0,...this.baseConsumeResult}}consumeAll(){var r;const e=(r=this.workId)==null?void 0:r.toString();let t;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,t=u.rect}else t=s.getRectFromPoints(this.tmpPoints,h);const d={name:e==null?void 0:e.toString(),fillColor:c?l:void 0,opacity:1,lineDash:p===s.EStrokeType.Dotted&&!c?[1,h*2]:p===s.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 o=[];this.tmpPoints.forEach(n=>{o.push(n.x,n.y)});const i=s.transformToSerializableData(o);return{rect:t&&{x:t.x*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],y:t.y*this.fullLayer.worldScaling[1]+this.fullLayer.worldPosition[1],w:t.w*this.fullLayer.worldScaling[0],h:t.h*this.fullLayer.worldScaling[1]},type:s.EPostMessageType.FullWork,dataType:s.EDataType.Local,ops:i,index:this.syncIndex*2,...this.baseConsumeResult}}clearTmpPoints(){this.tmpPoints.length=0,this.syncTimestamp=0,this.syncIndex=0}consumeService(e){var y;const{op:t,replaceId:o,isFullWork:i}=e,{strokeColor:r,thickness:n,strokeType:c}=this.workOptions;if(!t.length){const w=s.getRectFromPoints(this.tmpPoints,n);return{x:w.x*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],y:w.y*this.fullLayer.worldScaling[1]+this.fullLayer.worldPosition[1],w:w.w*this.fullLayer.worldScaling[0],h:w.h*this.fullLayer.worldScaling[1]}}const l=Math.max(0,this.tmpPoints.length-1);this.updateTempPoints(t||[]);let h,p=this.tmpPoints.slice(l);const d=p.length===1;if(d){const w=this.computDotStroke({point:p[0],radius:n/2});p=w.ps,h=w.rect}else h=s.getRectFromPoints(this.tmpPoints,n);const f={name:(y=this.workId)==null?void 0:y.toString(),fillColor:d?r:void 0,opacity:1,lineDash:c===s.EStrokeType.Dotted&&!d?[1,n*2]:c===s.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 w=i?this.fullLayer:this.drawLayer||this.fullLayer;this.draw({attrs:f,tasks:u,isDot:d,replaceId:o,layer:w})}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(e){const{point:t,radius:o}=e,i={x:t.x-o,y:t.y-o,w:o*2,h:o*2};return{ps:s.Point2d.GetDotStroke(t,o,8),rect:i}}updateTempPoints(e){const t=this.tmpPoints.length;for(let o=0;o<e.length;o+=2){if(t){const i=this.tmpPoints.slice(-1)[0];i&&i.x===e[o]&&i.y===e[o+1]&&this.tmpPoints.pop()}this.tmpPoints.push(new s.Point2d(e[o],e[o+1]))}}async draw(e){const{attrs:t,tasks:o,isDot:i,layer:r}=e,{duration:n}=this.workOptions;for(const c of o){const l=new b.Path,{pos:h,points:p}=c;let d;i?d=j(p,!0):d=j(p,!1),l.attr({...t,pos:h,d});const{vertex:f,fragment:u}=this.workOptions;if(f&&u){const y=r.renderer.createProgram({vertex:f,fragment:u}),{width:w,height:g}=r.getResolution();l.setUniforms({u_time:0,u_resolution:[w,g]}),l.setProgram(y)}r.appendChild(l),l.transition(n).attr({scale:i?[.1,.1]:[1,1],lineWidth:i?0:1}).then(()=>{l.remove()})}}getTaskPoints(e){var l;const t=[];if(e.length===0)return[];let o=0,i=e[0].x,r=e[0].y,n=[i,r],c=[];for(;o<e.length;){const h=e[o],p=h.x-i,d=h.y-r;if(c.push(new s.Point2d(p,d)),o>0&&o<e.length-1){const f=e[o].getAngleByPoints(e[o-1],e[o+1]);if(f<90||f>270){const u=(l=c.pop())==null?void 0:l.clone();u&&t.push({pos:n,points:[...c,u]}),i=e[o].x,r=e[o].y,n=[i,r];const y=h.x-i,w=h.y-r;c=[new s.Point2d(y,w)]}}o++}return t.push({pos:n,points:c}),t}removeLocal(){}removeService(e){let t;const o=[];return this.fullLayer.getElementsByName(e).forEach(i=>{if(i.name===e){const r=i.getBoundingClientRect();t=s.computRect(t,{x:r.x,y:r.y,w:r.width,h:r.height}),o.push(i)}}),o.length&&o.forEach(i=>i.remove()),t}}const q=class q extends P{constructor(e,t){super(e);m(this,"canRotate",!1);m(this,"scaleType",s.EScaleType.none);m(this,"toolsType",s.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=t,this.workOptions=e.toolsOpt,this.worldPosition=this.fullLayer.worldPosition,this.worldScaling=this.fullLayer.worldScaling}combineConsume(){}consumeService(){}setWorkOptions(e){super.setWorkOptions(e)}createEraserRect(e){const t=e[0]*this.worldScaling[0]+this.worldPosition[0],o=e[1]*this.worldScaling[1]+this.worldPosition[1],{width:i,height:r}=q.eraserSizes[this.workOptions.thickness];this.eraserRect={x:t-i*.5,y:o-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 e=this.tmpPoints.slice(-2);if(this.tmpPoints.length===4){const t=new s.Vec2d(this.tmpPoints[0],this.tmpPoints[1]),o=new s.Vec2d(this.tmpPoints[2],this.tmpPoints[3]),i=s.Vec2d.Sub(o,t).uni(),r=s.Vec2d.Dist(t,o),{width:n,height:c}=q.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=s.Vec2d.Mul(i,d*l);p.push(this.tmpPoints[0]+f.x,this.tmpPoints[1]+f.y)}return p.concat(e)}}return e}isNear(e,t){const o=new s.Vec2d(e[0],e[1]),i=new s.Vec2d(t[0],t[1]),{width:r,height:n}=q.eraserSizes[this.workOptions.thickness];return s.Vec2d.Dist(o,i)<Math.hypot(r,n)*.5}cutPolyline(e,t){let o=[t],i=0;for(;i<e.length;){const c=e[i];if(c.length<2)break;o=r(o,c),i++}return o;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(s.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 w=f+l.length-1,g=d.slice(w),M=l[l.length-1];s.Vec2d.Equals(d[w],M)||g.unshift(M.clone().setz(d[w].z)),g.length>1&&u.push(g)}return h.splice(p,1,...u),h}}return h}function n(c,l){const h=s.Vec2d.Sub(c[1],c[0]),p=s.Vec2d.Sub(l[1],l[0]),d=s.Vec2d.Sub(l[0],c[0]);return Math.abs(s.Vec2d.Cpr(h,p))<.1&&Math.abs(s.Vec2d.Cpr(h,d))<.1}}isSamePoint(e,t){return e[0]===t[0]&&e[1]===t[1]}translateIntersect(e){const t=[];for(let o=0;o<e.length;o++){const i=e[o].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 s.Vec2d(c[0],c[1]);r.push(l),n++}t.push(r)}return t}isLineEraser(e,t){return!(e===s.EToolsKey.Pencil&&!t)}remove(e){const{curNodeMap:t,removeIds:o,newWorkDatas:i}=e,{isLine:r}=this.workOptions;let n;for(const[c,l]of t.entries())if(l.rect&&this.eraserRect&&this.eraserPolyline&&s.isIntersect(this.eraserRect,l.rect)){const{op:h,toolsType:p}=l,d=this.isLineEraser(p,r),f=[],u=[];for(let w=0;w<h.length;w+=3){const g=new s.Vec2d(h[w]*this.worldScaling[0]+this.worldPosition[0],h[w+1]*this.worldScaling[1]+this.worldPosition[1],h[w+2]);u.push(g),f.push(new s.Point2d(g.x,g.y))}const y=f.length&&s.getRectFromPoints(f)||l.rect;if(s.isIntersect(y,this.eraserRect)){if(u.length>1){const w=Re.polyline(u.map(g=>g.XY),this.eraserPolyline);if(w.length&&(o.add(l.name),!d)){const g=this.translateIntersect(w),M=this.cutPolyline(g,u);for(let k=0;k<M.length;k++){const S=`${c}_s_${k}`,I=[];M[k].forEach(v=>{I.push((v.x-this.worldPosition[0])/this.worldScaling[0],(v.y-this.worldPosition[1])/this.worldScaling[1],v.z)}),l.opt&&l.toolsType&&this.vNodes&&(this.vNodes.setInfo(S,{rect:y,op:I,opt:l.opt,canRotate:l.canRotate,scaleType:l.scaleType,toolsType:l.toolsType}),i.set(S,{workId:S,op:I,opt:l.opt,toolsType:l.toolsType}))}}}else o.add(l.name);n=s.computRect(n,y)}}return o.forEach(c=>{var l;return(l=this.vNodes)==null?void 0:l.delete(c)}),n&&(n.x-=P.SafeBorderPadding,n.y-=P.SafeBorderPadding,n.w+=P.SafeBorderPadding*2,n.h+=P.SafeBorderPadding*2),n}consume(e){const{op:t}=e.data;if(!t||t.length===0)return{type:s.EPostMessageType.None,...this.baseConsumeResult};const o=this.tmpPoints.length;if(o>1&&this.isNear([t[0],t[1]],[this.tmpPoints[o-2],this.tmpPoints[o-1]]))return{type:s.EPostMessageType.None,...this.baseConsumeResult};o===4&&(this.tmpPoints.shift(),this.tmpPoints.shift()),this.tmpPoints.push(t[0],t[1]);const i=this.computRectCenterPoints();let r;const n=new Set,c=new Map;if(!this.vNodes)return{type:s.EPostMessageType.None,...this.baseConsumeResult};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=s.computRect(r,p)}if(this.vNodes.deleteLastTarget(),r&&n.size){for(const h of c.keys())n.has(h)&&c.delete(h);return{type:s.EPostMessageType.RemoveNode,rect:r,removeIds:[...n],newWorkDatas:c}}return{type:s.EPostMessageType.None,...this.baseConsumeResult}}consumeAll(e){return this.consume(e)}clearTmpPoints(){this.tmpPoints.length=0}getUnLockNodeMap(e){var t;if(this.serviceWork){const o=s.cloneDeep(e),i=this.serviceWork.selectorWorkShapes,r=this.serviceWork.workShapes;for(const n of i.values())if((t=n.selectIds)!=null&&t.length)for(const c of n.selectIds)o.delete(c);for(const n of r.keys())o.delete(n);return o}return e}};m(q,"eraserSizes",Object.freeze([Object.freeze({width:18,height:26}),Object.freeze({width:26,height:34}),Object.freeze({width:34,height:50})]));let ie=q;const X=class X extends P{constructor(e){super(e);m(this,"toolsType",s.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",s.EScaleType.all);m(this,"toolsTypes");m(this,"shapeOpt");m(this,"textOpt");m(this,"isLocked");this.workOptions=e.toolsOpt,this.vNodes=e.vNodes}computSelector(e=!0){const t=s.getRectFromPoints(this.tmpPoints);if(t.w===0||t.h===0)return{selectIds:[],intersectRect:void 0,subNodeMap:new Map};const{rectRange:o,nodeRange:i}=this.vNodes.getRectIntersectRange(t,e);return{selectIds:[...i.keys()],intersectRect:o,subNodeMap:i}}updateTempPoints(e){const t=this.tmpPoints.length,o=e.length;if(o>1){const i=new s.Point2d(e[o-2]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],e[o-1]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[1]);t===2?this.tmpPoints.splice(1,1,i):this.tmpPoints.push(i)}}drawSelector(e){const{drawRect:t,subNodeMap:o,selectorId:i,layer:r,isService:n}=e,c=new b.Group({pos:[t.x,t.y],anchor:[0,0],size:[t.w,t.h],id:i,name:i,zIndex:9999}),l=[];if(n){const h=new b.Rect({normalize:!0,pos:[t.w/2,t.h/2],lineWidth:1,strokeColor:this.selectorColor||this.workOptions.strokeColor,width:t.w,height:t.h,name:X.selectorBorderId});l.push(h)}o.forEach((h,p)=>{const d=[h.rect.x+h.rect.w/2-t.x,h.rect.y+h.rect.h/2-t.y],f=new b.Rect({normalize:!0,pos:d,lineWidth:1,strokeColor:o.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(e,t,o,i=!1){var c,l;const{intersectRect:r,subNodeMap:n}=o;(l=(c=t.parent)==null?void 0:c.getElementById(e))==null||l.remove(),r&&this.drawSelector({drawRect:r,subNodeMap:n,selectorId:e,layer:t,isService:i})}getSelecteorInfo(e){this.scaleType=s.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 t=new Set;let o;for(const i of e.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===s.EToolsKey.SpeechBalloon&&(t.add(l),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.placement=r.placement),l===s.EToolsKey.Polygon&&(t.add(l),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=r.vertices),l===s.EToolsKey.Star&&(t.add(l),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=r.vertices,this.shapeOpt.innerRatio=r.innerRatio,this.shapeOpt.innerVerticeStep=r.innerVerticeStep),l===s.EToolsKey.Text&&(this.textOpt=r),e.size===1&&(this.textOpt&&(this.canTextEdit=!0),this.canRotate=n,this.scaleType=c),c===s.EScaleType.none&&(this.scaleType=c),l===s.EToolsKey.Image&&(o=i)}t.size&&(this.toolsTypes=[...t]),o&&(e.size===1?(this.canLock=!0,o.opt.locked&&(this.isLocked=!0,this.scaleType=s.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)):e.size>1&&!o.opt.locked&&(this.canLock=!1,this.canRotate=!1))}getChildrenPoints(){var e,t;if(this.scaleType===s.EScaleType.both&&((e=this.selectIds)==null?void 0:e.length)===1){const o=this.selectIds[0],i=(t=this.vNodes.get(o))==null?void 0:t.op;if(i){const r=[];for(let n=0;n<i.length;n+=3)r.push([i[n],i[n+1]]);return r}}}consume(e){const{op:t,workState:o}=e.data;let i=this.oldSelectRect;if(o===s.EvevtWorkState.Start&&(i=this.unSelectedAllIds()),!(t!=null&&t.length)||!this.vNodes.curNodeMap.size)return{type:s.EPostMessageType.None};this.updateTempPoints(t);const r=this.computSelector();if(this.selectIds&&s.isEqual(this.selectIds,r.selectIds))return{type:s.EPostMessageType.None};this.selectIds=r.selectIds;const n=r.intersectRect;this.getSelecteorInfo(r.subNodeMap),this.draw(X.selectorId,this.fullLayer,r),this.oldSelectRect=n;const c=this.getChildrenPoints();return{type:s.EPostMessageType.Select,dataType:s.EDataType.Local,rect:s.computRect(n,i),selectIds:r.selectIds,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,...this.baseConsumeResult}}consumeAll(){var t,o;let e=this.oldSelectRect;if(!((t=this.selectIds)!=null&&t.length)&&this.tmpPoints[0]&&this.selectSingleTool(this.tmpPoints[0].XY,X.selectorId,!1),(o=this.selectIds)!=null&&o.length&&(e=this.selectedByIds(this.selectIds)),e){const i=this.getChildrenPoints();return{type:s.EPostMessageType.Select,dataType:s.EDataType.Local,rect:this.oldSelectRect,selectIds:this.selectIds,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,...this.baseConsumeResult}}return{type:s.EPostMessageType.None}}consumeService(){}clearTmpPoints(){this.tmpPoints.length=0}clearSelectData(){this.selectIds=void 0,this.oldSelectRect=void 0}selectSingleTool(e,t=X.selectorId,o=!1){if(e.length===2){const i=e[0],r=e[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(Pe(p).find(f=>f.isPointCollision(i,r))){n=h;break}}if(n){const h=n.name;if(!s.isEqual(this.oldSelectRect,n.rect)){const p=new Map([[h,n]]);this.getSelecteorInfo(p),this.draw(t,this.fullLayer,{intersectRect:n.rect,subNodeMap:p,selectIds:this.selectIds||[]},o)}this.selectIds=[h],this.oldSelectRect=n.rect}}}unSelectedAllIds(){let e;for(const[t,o]of this.vNodes.curNodeMap.entries())o.isSelected&&(e=s.computRect(e,o.rect),this.vNodes.unSelected(t));return e}unSelectedByIds(e){let t;for(const o of e){const i=this.vNodes.get(o);i&&i.isSelected&&(t=s.computRect(t,i.rect),this.vNodes.unSelected(o))}return t}selectedByIds(e){let t;for(const o of e){const i=this.vNodes.get(o);i&&(t=s.computRect(t,i.rect),this.vNodes.selected(o))}return t}getSelectorRect(e,t){var n;let o;const i=(n=e.parent)==null?void 0:n.getElementById(t),r=i==null?void 0:i.getBoundingClientRect();return r&&(o=s.computRect(o,{x:Math.floor(r.x),y:Math.floor(r.y),w:Math.floor(r.width+1),h:Math.floor(r.height+1)})),o}isCanFillColor(e){return e===s.EToolsKey.Ellipse||e===s.EToolsKey.Triangle||e===s.EToolsKey.Rectangle||e===s.EToolsKey.Polygon||e===s.EToolsKey.Star||e===s.EToolsKey.SpeechBalloon}async updateSelector(e){const{updateSelectorOpt:t,selectIds:o,vNodes:i,willSerializeData:r,worker:n,offset:c,scene:l,isMainThread:h}=e,p=this.fullLayer;if(!p)return;let d;const f=new Map,{box:u,workState:y,angle:w,translate:g}=t;let M=[0,0],k=[1,1],S=[0,0],I,v;if(u||g||K(w)){if(y===s.EvevtWorkState.Start)return i.setTarget(),{type:s.EPostMessageType.Select,dataType:s.EDataType.Local,selectRect:this.oldSelectRect,rect:this.oldSelectRect};if(I=i.getLastTarget(),I&&u){let T;o==null||o.forEach(R=>{const W=I==null?void 0:I.get(R);T=s.computRect(T,W==null?void 0:W.rect)}),T&&(k=[u.w/T.w,u.h/T.h],M=[u.x+u.w/2-(T.x+T.w/2),u.y+u.h/2-(T.y+T.h/2)],S=[T.x+T.w/2,T.y+T.h/2]),v=T}}if(o)for(const T of o){const R=i.get(T);if(R){const{toolsType:W}=R;let D=(p==null?void 0:p.getElementsByName(T))[0];if(D){const x={...t};let B;if(W){if(B=I==null?void 0:I.get(T),B&&u){x.boxScale=k;const C=[B.rect.x+B.rect.w/2,B.rect.y+B.rect.h/2],O=[C[0]-S[0],C[1]-S[1]];x.boxTranslate=[O[0]*(k[0]-1)+M[0]+(c&&c[0]||0),O[1]*(k[1]-1)+M[1]+(c&&c[1]||0)]}const Z=ke(W);if(Z==null||Z.updateNodeOpt({node:D,opt:x,vNodes:i,willSerializeData:r,targetNode:B}),R&&n&&(r&&(x.angle||x.translate)||x.box&&x.workState!==s.EvevtWorkState.Start||x.pointMap&&x.pointMap.has(T)||W===s.EToolsKey.Text&&(x.fontSize||x.translate||x.textInfos&&x.textInfos.get(T))||W===s.EToolsKey.Image&&(x.angle||x.translate||x.boxScale)||W===x.toolsType&&x.willRefresh)){const C=n.createWorkShapeNode({workId:T,toolsType:W,toolsOpt:R.opt});C==null||C.setWorkId(T);let O;if(W===s.EToolsKey.Image&&l)O=await C.consumeServiceAsync({isFullWork:!0,replaceId:T,scene:l,isMainThread:h});else if(W===s.EToolsKey.Text)O=await C.consumeServiceAsync({isFullWork:!0,replaceId:T});else try{O=C==null?void 0:C.consumeService({op:R.op,isFullWork:!0,replaceId:T})}catch{continue}O&&(R.rect=O),D=(p==null?void 0:p.getElementsByName(T))[0]}R&&(f.set(T,R),d=s.computRect(d,R.rect))}}}}I&&y===s.EvevtWorkState.Done&&(i.deleteLastTarget(),I=void 0);const E=d;if(v&&t.dir&&E&&!c){const T=[0,0];switch(t.dir){case"top":{const R=[v.x,v.y+v.h];t.reverseY?T[1]=R[1]-E.y:T[1]=R[1]-(E.y+E.h);break}case"topLeft":{const R=[v.x+v.w,v.y+v.h];t.reverseY?T[1]=R[1]-E.y:T[1]=R[1]-(E.y+E.h),t.reverseX?T[0]=R[0]-E.x:T[0]=R[0]-(E.x+E.w);break}case"topRight":{const R=[v.x,v.y+v.h];t.reverseY?T[1]=R[1]-E.y:T[1]=R[1]-(E.y+E.h),t.reverseX?T[0]=R[0]-(E.x+E.w):T[0]=R[0]-E.x;break}case"bottom":{const R=[v.x,v.y];t.reverseY?T[1]=R[1]-(E.y+E.h):T[1]=R[1]-E.y;break}case"bottomLeft":{const R=[v.x+v.w,v.y];t.reverseY?T[1]=R[1]-(E.y+E.h):T[1]=R[1]-E.y,t.reverseX?T[0]=R[0]-E.x:T[0]=R[0]-(E.x+E.w);break}case"bottomRight":{const R=[v.x,v.y];t.reverseY?T[1]=R[1]-(E.y+E.h):T[1]=R[1]-E.y,t.reverseX?T[0]=R[0]-(E.x+E.w):T[0]=R[0]-E.x;break}case"right":{const R=[v.x,v.y];t.reverseX?T[0]=R[0]-(E.x+E.w):T[0]=R[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({...e,offset:T})}this.getSelecteorInfo(f),this.draw(X.selectorId,p,{selectIds:o||[],subNodeMap:f,intersectRect:E});const N=s.computRect(this.oldSelectRect,E);return this.oldSelectRect=E,{type:s.EPostMessageType.Select,dataType:s.EDataType.Local,selectRect:E,renderRect:d,rect:s.computRect(N,E),selectIds:o}}blurSelector(){const e=this.unSelectedAllIds();return{type:s.EPostMessageType.Select,dataType:s.EDataType.Local,rect:e,selectIds:[],willSyncService:!0}}getRightServiceId(e){return e.replace(s.Storage_Splitter,"-")}selectServiceNode(e,t,o){const{selectIds:i}=t,r=this.getRightServiceId(e),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=s.computRect(c,p.rect),l.set(h,p))}),this.getSelecteorInfo(l),this.draw(r,this.fullLayer,{intersectRect:c,selectIds:i||[],subNodeMap:l},o),s.computRect(c,n)}reRenderSelector(){var o;let e;const t=new Map;return(o=this.selectIds)==null||o.forEach(i=>{const r=this.vNodes.get(i);r&&(e=s.computRect(e,r.rect),t.set(i,r))},this),this.getSelecteorInfo(t),this.draw(X.selectorId,this.fullLayer,{intersectRect:e,subNodeMap:t,selectIds:this.selectIds||[]}),this.oldSelectRect=e,e}updateSelectIds(e){var r;let t;const o=(r=this.selectIds)==null?void 0:r.filter(n=>!e.includes(n));if(o!=null&&o.length&&(t=this.unSelectedByIds(o)),e.length){const n=this.selectedByIds(e);t=s.computRect(t,n)}this.selectIds=e;const i=this.reRenderSelector();return{bgRect:t,selectRect:i}}cursorHover(e){var r,n;const t=this.oldSelectRect;this.selectIds=[];const o=(r=this.workId)==null?void 0:r.toString(),i=[e[0]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],e[1]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[1]];if(this.selectSingleTool(i,o,!0),this.oldSelectRect&&!s.isEqual(t,this.oldSelectRect))return{type:s.EPostMessageType.CursorHover,dataType:s.EDataType.Local,rect:s.computRect(t,this.oldSelectRect),selectorColor:this.selectorColor,willSyncService:!1};if((n=this.selectIds)!=null&&n.length||(this.oldSelectRect=void 0),t&&!this.oldSelectRect)return this.cursorBlur(),{type:s.EPostMessageType.CursorHover,dataType:s.EDataType.Local,rect:t,selectorColor:this.selectorColor,willSyncService:!1}}cursorBlur(){var t,o;this.selectIds=[];const e=(t=this.workId)==null?void 0:t.toString();((o=this.fullLayer)==null?void 0:o.parent).children.forEach(i=>{i.name===e&&i.remove()})}};m(X,"selectorId",s.Storage_Selector_key),m(X,"selectorBorderId","selector-border");let z=X;class fe extends P{constructor(e){super(e);m(this,"canRotate",!1);m(this,"scaleType",s.EScaleType.both);m(this,"toolsType",s.EToolsKey.Arrow);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"arrowTipWidth");m(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.arrowTipWidth=this.workOptions.thickness*4,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:o,isSubWorker:i,isMainThread:r}=e,n=this.workId,{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:s.EPostMessageType.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new s.Point2d(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:s.EPostMessageType.None};let p;if(i||r){const f=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:n,layer:f})}if(!i){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{...this.baseConsumeResult,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,op:this.tmpPoints.map(u=>[...u.XY,0]).flat(1),isSync:!0,index:0}):{type:s.EPostMessageType.None}}const d=s.computRect(p,this.oldRect);return this.oldRect=p,{rect:d,...this.baseConsumeResult,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local}}consumeAll(){var n;const e=this.workId;if(this.tmpPoints.length<2)return{type:s.EPostMessageType.RemoveNode,removeIds:[e]};const t=this.fullLayer,o=this.draw({workId:e,layer:t});this.oldRect=o;const i=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),r=s.transformToSerializableData(i);return(n=this.vNodes)==null||n.setInfo(e,{rect:o,op:i,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:P.getCenterPos(o,t)}),{rect:o,...this.baseConsumeResult,type:s.EPostMessageType.FullWork,dataType:s.EDataType.Local,ops:r,isSync:!0}}draw(e){const{workId:t,layer:o}=e,{strokeColor:i,thickness:r,zIndex:n,scale:c,rotate:l,translate:h}=this.workOptions,p=o.worldPosition,d=o.worldScaling,{points:f,rect:u}=this.computDrawPoints(r),w={pos:[u.x+u.w/2,u.y+u.h/2],name:t,id:t,close:!0,points:f,fillColor:i,strokeColor:i,lineWidth:0,normalize:!0,zIndex:n};c&&(w.scale=c),l&&(w.rotate=l),h&&(w.translate=h);const g=new b.Polyline(w);if(this.replace(o,t,g),c||l||h){const M=g.getBoundingClientRect();return{x:Math.floor(M.x-P.SafeBorderPadding),y:Math.floor(M.y-P.SafeBorderPadding),w:Math.floor(M.width+P.SafeBorderPadding*2),h:Math.floor(M.height+P.SafeBorderPadding*2)}}return{x:Math.floor(u.x*d[0]+p[0]-P.SafeBorderPadding),y:Math.floor(u.y*d[1]+p[1]-P.SafeBorderPadding),w:Math.floor(u.w*d[0]+2*P.SafeBorderPadding),h:Math.floor(u.h*d[1]+2*P.SafeBorderPadding)}}computDrawPoints(e){return this.tmpPoints[1].distance(this.tmpPoints[0])>this.arrowTipWidth?this.computFullArrowPoints(e):this.computTrianglePoints()}computFullArrowPoints(e){const t=s.Vec2d.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),o=s.Vec2d.Per(t).mul(e/2),i=s.Point2d.Sub(this.tmpPoints[0],o),r=s.Point2d.Add(this.tmpPoints[0],o),n=s.Vec2d.Mul(t,this.arrowTipWidth),c=s.Vec2d.Sub(this.tmpPoints[1],n),l=s.Point2d.Sub(c,o),h=s.Point2d.Add(c,o),p=s.Vec2d.Per(t).mul(e*1.5),d=s.Point2d.Sub(c,p),f=s.Point2d.Add(c,p),u=[i,l,d,this.tmpPoints[1],f,h,r];return{points:u.map(y=>s.Point2d.Sub(y,this.tmpPoints[0]).XY).flat(1),rect:s.getRectFromPoints(u),isTriangle:!1,pos:this.tmpPoints[0].XY}}computTrianglePoints(){const e=s.Vec2d.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),t=this.tmpPoints[1].distance(this.tmpPoints[0]),o=s.Vec2d.Per(e).mul(Math.floor(t*3/8)),i=s.Point2d.Sub(this.tmpPoints[0],o),r=s.Point2d.Add(this.tmpPoints[0],o),n=[i,this.tmpPoints[1],r];return{points:n.map(c=>s.Point2d.Sub(c,this.tmpPoints[0]).XY).flat(1),rect:s.getRectFromPoints(n),isTriangle:!0,pos:this.tmpPoints[0].XY}}updateTempPoints(e){const t=e.slice(-2),o=new s.Point2d(t[0],t[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(o,r))return!1;if(this.tmpPoints.length===2){if(o.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=o}else this.tmpPoints.push(o);return!0}consumeService(e){var c,l;const{op:t,isFullWork:o}=e,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new s.Point2d(t[h],t[h+1],t[h+2]));const r=o?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:t,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:P.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var c;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r}=o,n=i.get(t.name);return r&&(t.setAttribute("strokeColor",r),t.setAttribute("fillColor",r),(c=n==null?void 0:n.opt)!=null&&c.strokeColor&&(n.opt.strokeColor=r),n&&i.setInfo(t.name,n)),P.updateNodeOpt(e)}}class ye extends P{constructor(e){super(e);m(this,"canRotate",!1);m(this,"scaleType",s.EScaleType.all);m(this,"toolsType",s.EToolsKey.Ellipse);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:o,isSubWorker:i,isMainThread:r}=e,n=this.workId,{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:s.EPostMessageType.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new s.Point2d(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:s.EPostMessageType.None};let p;if(i||r){const f=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:n,layer:f,isDrawing:!0})}if(!i){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,...this.baseConsumeResult,op:this.tmpPoints.map(u=>[...u.XY,0]).flat(1),isSync:!0,index:0}):{type:s.EPostMessageType.None}}const d=s.computRect(p,this.oldRect);return this.oldRect=p,{rect:d,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,...this.baseConsumeResult}}consumeAll(){var n;const e=this.workId;if(this.tmpPoints.length<2)return{type:s.EPostMessageType.RemoveNode,removeIds:[e]};const t=this.fullLayer,o=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=o;const i=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),r=s.transformToSerializableData(i);return(n=this.vNodes)==null||n.setInfo(e,{rect:o,op:i,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:o&&P.getCenterPos(o,t)}),{rect:o,type:s.EPostMessageType.FullWork,dataType:s.EDataType.Local,...this.baseConsumeResult,ops:r,isSync:!0}}draw(e){const{workId:t,layer:o,isDrawing:i}=e,{strokeColor:r,fillColor:n,thickness:c,zIndex:l,scale:h,rotate:p,translate:d}=this.workOptions,f=o.worldScaling,{radius:u,rect:y,pos:w}=this.computDrawPoints(c),g={pos:w,name:t,id:t,radius:u,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0},M={name:t,id:t,zIndex:l,pos:w,anchor:[.5,.5],size:[y.w,y.h]};h&&(M.scale=h),p&&(M.rotate=p),d&&(M.translate=d);const k=new b.Group(M);if(i){const v=new b.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/f[0],1/f[1]]});k.append(v)}const S=new b.Ellipse({...g,pos:[0,0]});k.append(S),this.replace(o,t,k);const I=k.getBoundingClientRect();return{x:Math.floor(I.x-P.SafeBorderPadding),y:Math.floor(I.y-P.SafeBorderPadding),w:Math.floor(I.width+P.SafeBorderPadding*2),h:Math.floor(I.height+P.SafeBorderPadding*2)}}computDrawPoints(e){const t=s.getRectFromPoints(this.tmpPoints),o=s.getRectFromPoints(this.tmpPoints,e),i=[Math.floor(t.x+t.w/2),Math.floor(t.y+t.h/2)];return{rect:o,pos:i,radius:[Math.floor(t.w/2),Math.floor(t.h/2)]}}updateTempPoints(e){const t=e.slice(-2),o=new s.Point2d(t[0],t[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(o,r))return!1;if(this.tmpPoints.length===2){if(o.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=o}else this.tmpPoints.push(o);return!0}consumeService(e){var c,l;const{op:t,isFullWork:o}=e,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new s.Point2d(t[h],t[h+1],t[h+2]));const r=o?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:t,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:P.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var h,p;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,fillColor:n}=o,c=i.get(t.name);let l=t;return t.tagName==="GROUP"&&(l=t.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(t.name,c),P.updateNodeOpt(e)}}class me extends P{constructor(e){super(e);m(this,"canRotate",!0);m(this,"scaleType",s.EScaleType.all);m(this,"toolsType",s.EToolsKey.Rectangle);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}transformData(){const e=s.getRectFromPoints(this.tmpPoints);return[[e.x,e.y,0],[e.x+e.w,e.y,0],[e.x+e.w,e.y+e.h,0],[e.x,e.y+e.h,0]]}computDrawPoints(e){const{thickness:t}=this.workOptions,o=[];for(const n of e)o.push(new s.Vec2d(...n));const i=s.getRectFromPoints(o,t),r=[i.x+i.w/2,i.y+i.h/2];return{rect:i,pos:r,points:o.map(n=>n.XY).flat(1)}}consume(e){const{data:t,isFullWork:o,isSubWorker:i,isMainThread:r}=e,n=this.workId,{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:s.EPostMessageType.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new s.Point2d(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:s.EPostMessageType.None};const p=this.transformData();let d;if(i||r){const u=o?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({ps:p,workId:n,layer:u,isDrawing:!0})}if(!i){const u=Date.now();return u-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=u,{type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,op:p.flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:s.EPostMessageType.None}}const f=s.computRect(d,this.oldRect);return this.oldRect=d,{rect:f,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,...this.baseConsumeResult}}consumeAll(){var c;const e=this.workId;if(this.tmpPoints.length<2)return{type:s.EPostMessageType.RemoveNode,removeIds:[e]};const t=this.transformData(),o=this.fullLayer,i=this.draw({ps:t,workId:e,layer:o,isDrawing:!1});this.oldRect=i;const r=t.flat(1),n=s.transformToSerializableData(r);return(c=this.vNodes)==null||c.setInfo(e,{rect:i,op:r,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:i&&P.getCenterPos(i,o)}),{rect:i,type:s.EPostMessageType.FullWork,dataType:s.EDataType.Local,ops:n,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:o,isDrawing:i,ps:r,replaceId:n}=e,{strokeColor:c,fillColor:l,thickness:h,zIndex:p,scale:d,rotate:f,translate:u,textOpt:y}=this.workOptions,w=o.worldPosition,g=o.worldScaling,{points:M,rect:k,pos:S}=this.computDrawPoints(r),I={close:!0,normalize:!0,points:M,lineWidth:h,fillColor:l!=="transparent"&&l||void 0,strokeColor:c,lineJoin:"round"},v={x:Math.floor(k.x*g[0]+w[0]-P.SafeBorderPadding),y:Math.floor(k.y*g[1]+w[1]-P.SafeBorderPadding),w:Math.floor(k.w*g[0]+2*P.SafeBorderPadding),h:Math.floor(k.h*g[0]+2*P.SafeBorderPadding)},E=new b.Group({name:t,id:t,zIndex:p,pos:S,anchor:[.5,.5],size:[k.w,k.h],scale:d,rotate:f,translate:u}),N=new b.Polyline({...I,pos:[0,0]});if(E.appendChild(N),i){const T=new b.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:c,lineWidth:1,scale:[1/g[0],1/g[1]]});E.appendChild(T)}if(this.replace(o,n||t,E),d||f||u){const T=E.getBoundingClientRect();return{x:Math.floor(T.x-P.SafeBorderPadding),y:Math.floor(T.y-P.SafeBorderPadding),w:Math.floor(T.width+2*P.SafeBorderPadding),h:Math.floor(T.height+2*P.SafeBorderPadding)}}return v}updateTempPoints(e){const t=e.slice(-2),o=new s.Point2d(t[0],t[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(o,r))return!1;if(this.tmpPoints.length===2){if(o.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=o}else this.tmpPoints.push(o);return!0}consumeService(e){var h,p;const{op:t,isFullWork:o,replaceId:i}=e,r=(h=this.workId)==null?void 0:h.toString();if(!r)return;const n=[];for(let d=0;d<t.length;d+=3)n.push([t[d],t[d+1],t[d+2]]);const c=o?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:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:l&&P.getCenterPos(l,c)}),l}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var g,M;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,fillColor:n,fontColor:c,fontBgColor:l,bold:h,italic:p,lineThrough:d,underline:f,fontSize:u}=o,y=i.get(t.name);let w=t;if(t.tagName==="GROUP"&&(w=t.children[0]),r&&(w.setAttribute("strokeColor",r),(g=y==null?void 0:y.opt)!=null&&g.strokeColor&&(y.opt.strokeColor=r)),n&&(n==="transparent"?w.setAttribute("fillColor","rgba(0,0,0,0)"):w.setAttribute("fillColor",n),(M=y==null?void 0:y.opt)!=null&&M.fillColor&&(y.opt.fillColor=n)),y!=null&&y.opt.textOpt){const k=y.opt.textOpt;c&&k.fontColor&&(k.fontColor=c),l&&k.fontBgColor&&(k.fontBgColor=l),h&&(k.bold=h),p&&(k.italic=p),s.isBoolean(d)&&(k.lineThrough=d),s.isBoolean(f)&&(k.underline=f),u&&(k.fontSize=u)}return y&&i.setInfo(t.name,y),P.updateNodeOpt(e)}}class ge extends P{constructor(e){super(e);m(this,"canRotate",!1);m(this,"scaleType",s.EScaleType.all);m(this,"toolsType",s.EToolsKey.Star);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:o,isSubWorker:i,isMainThread:r}=e,n=this.workId,{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:s.EPostMessageType.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new s.Point2d(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:s.EPostMessageType.None};let p;if(i||r){const f=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:n,layer:f,isDrawing:!0})}if(!i){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,op:this.tmpPoints.map(u=>[...u.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:s.EPostMessageType.None}}const d=s.computRect(p,this.oldRect);return this.oldRect=p,{rect:d,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,...this.baseConsumeResult}}consumeAll(){var n;const e=this.workId;if(this.tmpPoints.length<2)return{type:s.EPostMessageType.RemoveNode,removeIds:[e]};const t=this.fullLayer,o=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=o;const i=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),r=s.transformToSerializableData(i);return(n=this.vNodes)==null||n.setInfo(e,{rect:o,op:i,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:o&&P.getCenterPos(o,t)}),{rect:o,type:s.EPostMessageType.FullWork,dataType:s.EDataType.Local,ops:r,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:o,isDrawing:i}=e,{strokeColor:r,fillColor:n,thickness:c,zIndex:l,vertices:h,innerVerticeStep:p,innerRatio:d,scale:f,rotate:u,translate:y}=this.workOptions,w=o.worldScaling,{rect:g,pos:M,points:k}=this.computDrawPoints(c,h,p,d),S={close:!0,points:k,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0,lineJoin:"round"},I={name:t,id:t,zIndex:l,pos:M,anchor:[.5,.5],size:[g.w,g.h],className:`${M[0]},${M[1]}`};f&&(I.scale=f),u&&(I.rotate=u),y&&(I.translate=y);const v=new b.Group(I);if(i){const T=new b.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/w[0],1/w[1]]});v.append(T)}const E=new b.Polyline({...S,pos:[0,0]});v.append(E),this.replace(o,t,v);const N=v.getBoundingClientRect();return{x:Math.floor(N.x-P.SafeBorderPadding),y:Math.floor(N.y-P.SafeBorderPadding),w:Math.floor(N.width+P.SafeBorderPadding*2),h:Math.floor(N.height+P.SafeBorderPadding*2)}}computDrawPoints(e,t,o,i){const r=s.getRectFromPoints(this.tmpPoints),n=[Math.floor(r.x+r.w/2),Math.floor(r.y+r.h/2)],c=s.getWHRatio(r.w,r.h),l=Math.floor(Math.min(r.w,r.h)/2),h=i*l,p=[],d=2*Math.PI/t;for(let u=0;u<t;u++){const y=u*d-.5*Math.PI;let w,g;u%o===1?(w=h*c[0]*Math.cos(y),g=h*c[1]*Math.sin(y)):(w=l*c[0]*Math.cos(y),g=l*c[1]*Math.sin(y),p.push(w,g)),p.push(w,g)}return{rect:s.getRectFromPoints(this.tmpPoints,e),pos:n,points:p}}updateTempPoints(e){const t=e.slice(-2),o=new s.Point2d(t[0],t[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(o,r)||s.Point2d.Sub(i,o).XY.includes(0))return!1;if(this.tmpPoints.length===2){if(o.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=o}else this.tmpPoints.push(o);return!0}consumeService(e){var c,l;const{op:t,isFullWork:o}=e,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new s.Point2d(t[h],t[h+1],t[h+2]));const r=o?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:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&P.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,fillColor:n,toolsType:c,vertices:l,innerVerticeStep:h,innerRatio:p}=o,d=i.get(t.name),f=d==null?void 0:d.opt;let u=t;return t.tagName==="GROUP"&&(u=t.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===s.EToolsKey.Star&&(l&&(f.vertices=l),h&&(f.innerVerticeStep=h),p&&(f.innerRatio=p)),d&&i.setInfo(t.name,{...d,opt:f}),P.updateNodeOpt(e)}}class we extends P{constructor(e){super(e);m(this,"canRotate",!1);m(this,"scaleType",s.EScaleType.all);m(this,"toolsType",s.EToolsKey.Polygon);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:o,isSubWorker:i,isMainThread:r}=e,{op:n}=t,c=this.workId,l=n==null?void 0:n.length;if(!l||l<2)return{type:s.EPostMessageType.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new s.Point2d(n[0],n[1])],h=!1):h=this.updateTempPoints(n),!h)return{type:s.EPostMessageType.None};let p;if(i||r){const f=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:c,layer:f,isDrawing:!0})}if(!i){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,op:this.tmpPoints.map(u=>[...u.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:s.EPostMessageType.None}}const d=s.computRect(p,this.oldRect);return this.oldRect=p,{rect:d,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,...this.baseConsumeResult}}consumeAll(){var n;const e=this.workId;if(this.tmpPoints.length<2)return{type:s.EPostMessageType.RemoveNode,removeIds:[e]};const t=this.fullLayer,o=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=o;const i=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),r=s.transformToSerializableData(i);return(n=this.vNodes)==null||n.setInfo(e,{rect:o,op:i,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:o&&P.getCenterPos(o,t)}),{rect:o,type:s.EPostMessageType.FullWork,dataType:s.EDataType.Local,ops:r,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:o,isDrawing:i}=e,{strokeColor:r,fillColor:n,thickness:c,zIndex:l,vertices:h,scale:p,rotate:d,translate:f}=this.workOptions,u=o.worldScaling,{rect:y,pos:w,points:g}=this.computDrawPoints(c,h),M={close:!0,points:g,lineWidth:c,fillColor:n!=="transparent"&&n||void 0,strokeColor:r,normalize:!0,lineJoin:"round"},k={name:t,id:t,zIndex:l,pos:w,anchor:[.5,.5],size:[y.w,y.h]};p&&(k.scale=p),d&&(k.rotate=d),f&&(k.translate=f);const S=new b.Group(k);if(i){const E=new b.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/u[0],1/u[1]]});S.append(E)}const I=new b.Polyline({...M,pos:[0,0]});S.append(I),this.replace(o,t,S);const v=S.getBoundingClientRect();return{x:Math.floor(v.x-P.SafeBorderPadding),y:Math.floor(v.y-P.SafeBorderPadding),w:Math.floor(v.width+P.SafeBorderPadding*2),h:Math.floor(v.height+P.SafeBorderPadding*2)}}computDrawPoints(e,t){const o=s.getRectFromPoints(this.tmpPoints),i=[Math.floor(o.x+o.w/2),Math.floor(o.y+o.h/2)],r=s.getWHRatio(o.w,o.h),n=Math.floor(Math.min(o.w,o.h)/2),c=[],l=2*Math.PI/t;for(let p=0;p<t;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:s.getRectFromPoints(this.tmpPoints,e),pos:i,points:c}}updateTempPoints(e){const t=e.slice(-2),o=new s.Point2d(t[0],t[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(o,r)||s.Point2d.Sub(i,o).XY.includes(0))return!1;if(this.tmpPoints.length===2){if(o.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=o}else this.tmpPoints.push(o);return!0}consumeService(e){var c,l;const{op:t,isFullWork:o}=e,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new s.Point2d(t[h],t[h+1],t[h+2]));const r=o?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:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&P.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,fillColor:n,toolsType:c,vertices:l}=o,h=i.get(t.name),p=h==null?void 0:h.opt;let d=t;return t.tagName==="GROUP"&&(d=t.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===s.EToolsKey.Polygon&&l&&(p.vertices=l),h&&i.setInfo(t.name,{...h,opt:p}),P.updateNodeOpt(e)}}class V{static bezier(a,e){const t=[];for(let o=0;o<e.length;o+=4){const i=e[o],r=e[o+1],n=e[o+2],c=e[o+3];i&&r&&n&&c?t.push(...V.getBezierPoints(a,i,r,n,c)):i&&r&&n?t.push(...V.getBezierPoints(a,i,r,n)):i&&r?t.push(...V.getBezierPoints(a,i,r)):i&&t.push(i)}return t}static getBezierPoints(a=10,e,t,o,i){let r=null;const n=[];!o&&!i?r=V.oneBezier:o&&!i?r=V.twoBezier:o&&i&&(r=V.threeBezier);for(let c=0;c<a;c++)r&&n.push(r(c/a,e,t,o,i));return i?n.push(i):o&&n.push(o),n}static oneBezier(a,e,t){const o=e.x+(t.x-e.x)*a,i=e.y+(t.y-e.y)*a;return new s.Vec2d(o,i)}static twoBezier(a,e,t,o){const i=(1-a)*(1-a)*e.x+2*a*(1-a)*t.x+a*a*o.x,r=(1-a)*(1-a)*e.y+2*a*(1-a)*t.y+a*a*o.y;return new s.Vec2d(i,r)}static threeBezier(a,e,t,o,i){const r=e.x*(1-a)*(1-a)*(1-a)+3*t.x*a*(1-a)*(1-a)+3*o.x*a*a*(1-a)+i.x*a*a*a,n=e.y*(1-a)*(1-a)*(1-a)+3*t.y*a*(1-a)*(1-a)+3*o.y*a*a*(1-a)+i.y*a*a*a;return new s.Vec2d(r,n)}}class Se extends P{constructor(e){super(e);m(this,"canRotate",!1);m(this,"scaleType",s.EScaleType.all);m(this,"toolsType",s.EToolsKey.SpeechBalloon);m(this,"ratio",.8);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){var f;const{data:t,isFullWork:o,isSubWorker:i,isMainThread:r}=e,n=(f=t==null?void 0:t.workId)==null?void 0:f.toString();if(!n)return{type:s.EPostMessageType.None};const{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:s.EPostMessageType.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new s.Point2d(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:s.EPostMessageType.None};let p;if(i||r){const u=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:n,layer:u,isDrawing:!0})}if(!i){const u=Date.now();return u-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=u,{type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,op:this.tmpPoints.map(y=>[...y.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:s.EPostMessageType.None}}const d=s.computRect(p,this.oldRect);return this.oldRect=p,{rect:d,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,...this.baseConsumeResult}}consumeAll(){var n;const e=this.workId;if(this.tmpPoints.length<2)return{type:s.EPostMessageType.RemoveNode,removeIds:[e]};const t=this.fullLayer,o=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=o;const i=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),r=s.transformToSerializableData(i);return(n=this.vNodes)==null||n.setInfo(e,{rect:o,op:i,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:o&&P.getCenterPos(o,t)}),{rect:o,type:s.EPostMessageType.FullWork,dataType:s.EDataType.Local,ops:r,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:o}=e,{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),w={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},g={name:t,id:t,zIndex:c,pos:u,anchor:[.5,.5],size:[f.w,f.h]};h&&(g.scale=h),p&&(g.rotate=p),d&&(g.translate=d);const M=new b.Group(g),k=new b.Polyline({...w,pos:[0,0]});M.append(k),this.replace(o,t,M);const S=M.getBoundingClientRect();return{x:Math.floor(S.x-P.SafeBorderPadding),y:Math.floor(S.y-P.SafeBorderPadding),w:Math.floor(S.width+P.SafeBorderPadding*2),h:Math.floor(S.height+P.SafeBorderPadding*2)}}transformControlPoints(e){const t=s.getRectFromPoints(this.tmpPoints);switch(e){case"bottom":case"bottomLeft":case"bottomRight":{const o=t.y+t.h*this.ratio;return[new s.Vec2d(t.x,t.y,0),new s.Vec2d(t.x+t.w,t.y,0),new s.Vec2d(t.x+t.w,o,0),new s.Vec2d(t.x,o,0)]}case"top":case"topLeft":case"topRight":{const o=t.y+t.h*(1-this.ratio);return[new s.Vec2d(t.x,o,0),new s.Vec2d(t.x+t.w,o,0),new s.Vec2d(t.x+t.w,t.y+t.h,0),new s.Vec2d(t.x,t.y+t.h,0)]}case"left":case"leftBottom":case"leftTop":{const o=t.x+t.w*(1-this.ratio);return[new s.Vec2d(o,t.y,0),new s.Vec2d(t.x+t.w,t.y,0),new s.Vec2d(t.x+t.w,t.y+t.h,0),new s.Vec2d(o,t.y+t.h,0)]}case"right":case"rightBottom":case"rightTop":{const o=t.x+t.w*this.ratio;return[new s.Vec2d(t.x,t.y,0),new s.Vec2d(o,t.y,0),new s.Vec2d(o,t.y+t.h,0),new s.Vec2d(t.x,t.y+t.h,0)]}}}computDrawPoints(e,t){const o=s.getRectFromPoints(this.tmpPoints),i=this.transformControlPoints(t),r=Math.floor(o.w*.1),n=Math.floor(o.h*.1),c=[],l=s.Vec2d.Add(i[0],new s.Vec2d(0,n,0)),h=s.Vec2d.Add(i[0],new s.Vec2d(r,0,0)),p=V.getBezierPoints(10,l,i[0],h),d=s.Vec2d.Sub(i[1],new s.Vec2d(r,0,0)),f=s.Vec2d.Add(i[1],new s.Vec2d(0,n,0)),u=V.getBezierPoints(10,d,i[1],f),y=s.Vec2d.Sub(i[2],new s.Vec2d(0,n,0)),w=s.Vec2d.Sub(i[2],new s.Vec2d(r,0,0)),g=V.getBezierPoints(10,y,i[2],w),M=s.Vec2d.Add(i[3],new s.Vec2d(r,0,0)),k=s.Vec2d.Sub(i[3],new s.Vec2d(0,n,0)),S=V.getBezierPoints(10,M,i[3],k),I=r*(1-this.ratio)*10,v=n*(1-this.ratio)*10;switch(t){case"bottom":{const T=s.Vec2d.Sub(i[2],new s.Vec2d(r*5-I/2,0,0)),R=s.Vec2d.Sub(i[2],new s.Vec2d(r*5,-v,0)),W=s.Vec2d.Sub(i[2],new s.Vec2d(r*5+I/2,0,0));c.push(R,W,...S,...p,...u,...g,T);break}case"bottomRight":{const T=s.Vec2d.Sub(i[2],new s.Vec2d(r*1.1,0,0)),R=s.Vec2d.Sub(i[2],new s.Vec2d(r*1.1+I/2,-v,0)),W=s.Vec2d.Sub(i[2],new s.Vec2d(r*1.1+I,0,0));c.push(R,W,...S,...p,...u,...g,T);break}case"bottomLeft":{const T=s.Vec2d.Add(i[3],new s.Vec2d(r*1.1+I,0,0)),R=s.Vec2d.Add(i[3],new s.Vec2d(r*1.1+I/2,v,0)),W=s.Vec2d.Add(i[3],new s.Vec2d(r*1.1,0,0));c.push(R,W,...S,...p,...u,...g,T);break}case"top":{const T=s.Vec2d.Sub(i[1],new s.Vec2d(r*5-I/2,0,0)),R=s.Vec2d.Sub(i[1],new s.Vec2d(r*5,v,0)),W=s.Vec2d.Sub(i[1],new s.Vec2d(r*5+I/2,0,0));c.push(R,T,...u,...g,...S,...p,W);break}case"topRight":{const T=s.Vec2d.Sub(i[1],new s.Vec2d(r*1.1,0,0)),R=s.Vec2d.Sub(i[1],new s.Vec2d(r*1.1+I/2,v,0)),W=s.Vec2d.Sub(i[1],new s.Vec2d(r*1.1+I,0,0));c.push(R,T,...u,...g,...S,...p,W);break}case"topLeft":{const T=s.Vec2d.Add(i[0],new s.Vec2d(r*1.1+I,0,0)),R=s.Vec2d.Add(i[0],new s.Vec2d(r*1.1+I/2,-v,0)),W=s.Vec2d.Add(i[0],new s.Vec2d(r*1.1,0,0));c.push(R,T,...u,...g,...S,...p,W);break}case"left":{const T=s.Vec2d.Add(i[0],new s.Vec2d(0,n*5-v/2,0)),R=s.Vec2d.Add(i[0],new s.Vec2d(-I,n*5,0)),W=s.Vec2d.Add(i[0],new s.Vec2d(0,n*5+v/2,0));c.push(R,T,...p,...u,...g,...S,W);break}case"leftTop":{const T=s.Vec2d.Add(i[0],new s.Vec2d(0,n*1.1,0)),R=s.Vec2d.Add(i[0],new s.Vec2d(-I,n*1.1+v/2,0)),W=s.Vec2d.Add(i[0],new s.Vec2d(0,n*1.1+v,0));c.push(R,T,...p,...u,...g,...S,W);break}case"leftBottom":{const T=s.Vec2d.Sub(i[3],new s.Vec2d(0,n*1.1+v,0)),R=s.Vec2d.Sub(i[3],new s.Vec2d(I,n*1.1+v/2,0)),W=s.Vec2d.Sub(i[3],new s.Vec2d(0,n*1.1,0));c.push(R,T,...p,...u,...g,...S,W);break}case"right":{const T=s.Vec2d.Add(i[1],new s.Vec2d(0,n*5-v/2,0)),R=s.Vec2d.Add(i[1],new s.Vec2d(I,n*5,0)),W=s.Vec2d.Add(i[1],new s.Vec2d(0,n*5+v/2,0));c.push(R,W,...g,...S,...p,...u,T);break}case"rightTop":{const T=s.Vec2d.Add(i[1],new s.Vec2d(0,n*1.1,0)),R=s.Vec2d.Add(i[1],new s.Vec2d(I,n*1.1+v/2,0)),W=s.Vec2d.Add(i[1],new s.Vec2d(0,n*1.1+v,0));c.push(R,W,...g,...S,...p,...u,T);break}case"rightBottom":{const T=s.Vec2d.Sub(i[2],new s.Vec2d(0,n*1.1+v,0)),R=s.Vec2d.Sub(i[2],new s.Vec2d(-I,n*1.1+v/2,0)),W=s.Vec2d.Sub(i[2],new s.Vec2d(0,n*1.1,0));c.push(R,W,...g,...S,...p,...u,T);break}}const E=s.getRectFromPoints(this.tmpPoints,e),N=[Math.floor(E.x+E.w/2),Math.floor(E.y+E.h/2)];return{rect:E,pos:N,points:c}}updateTempPoints(e){const t=e.slice(-2),o=new s.Point2d(t[0],t[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(o,r)||s.Point2d.Sub(i,o).XY.includes(0))return!1;if(this.tmpPoints.length===2){if(o.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=o}else this.tmpPoints.push(o);return!0}consumeService(e){var c,l;const{op:t,isFullWork:o}=e,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new s.Point2d(t[h],t[h+1],t[h+2]));const r=o?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:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&P.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,fillColor:n,toolsType:c,placement:l}=o,h=i.get(t.name),p=h==null?void 0:h.opt;let d=t;return t.tagName==="GROUP"&&(d=t.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===s.EToolsKey.SpeechBalloon&&l&&(p.placement=l),h&&i.setInfo(t.name,{...h,opt:p}),P.updateNodeOpt(e)}}class Q extends P{constructor(e){super(e);m(this,"canRotate",!0);m(this,"scaleType",s.EScaleType.all);m(this,"toolsType",s.EToolsKey.Image);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");this.workOptions=e.toolsOpt,this.scaleType=Q.getScaleType(this.workOptions)}consume(){return{type:s.EPostMessageType.None}}consumeAll(){return{type:s.EPostMessageType.None}}draw(e){const{layer:t,workId:o,replaceId:i,imageBitmap:r,isMainThread:n}=e,{centerX:c,centerY:l,width:h,height:p,rotate:d,zIndex:f}=this.workOptions,u=!!t.parent.gl,y={anchor:[.5,.5],pos:[c,l],name:o,size:[h,p],zIndex:f,rotate:!n&&!u&&180+(d||0)||d,texture:r},w=new b.Sprite(y);this.replace(t,i||o,w);const g=w.getBoundingClientRect();if(g)return{x:Math.floor(g.x-P.SafeBorderPadding),y:Math.floor(g.y-P.SafeBorderPadding),w:Math.floor(g.width+P.SafeBorderPadding*2),h:Math.floor(g.height+P.SafeBorderPadding*2)}}consumeService(){}async consumeServiceAsync(e){var p,d,f,u;const{isFullWork:t,replaceId:o,scene:i,isMainThread:r}=e,{src:n,uuid:c}=this.workOptions,l=((p=this.workId)==null?void 0:p.toString())||c,h=t?this.fullLayer:this.drawLayer||this.fullLayer;if(n){const y=await i.preload({id:c,src:this.workOptions.src}),w=this.draw({workId:l,layer:h,replaceId:o,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:w,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:w&&P.getCenterPos(w,h)}),w}}clearTmpPoints(){this.tmpPoints.length=0}static getScaleType(e){const{uniformScale:t,rotate:o}=e;return t!==!1||o&&Math.abs(o)%90>0?s.EScaleType.proportional:s.EScaleType.all}static updateNodeOpt(e){const{node:t,opt:o,vNodes:i,targetNode:r}=e,{translate:n,box:c,boxScale:l,boxTranslate:h,angle:p,isLocked:d,zIndex:f}=o,u=r&&s.cloneDeep(r)||i.get(t.name);if(!u)return;const y=t.parent;if(y){if(K(f)&&(t.setAttribute("zIndex",f),u.opt.zIndex=f),s.isBoolean(d)&&(u.opt.locked=d),c&&h&&l){const{centerX:w,centerY:g,width:M,height:k,uniformScale:S,rotate:I}=u.opt,v=Math.min(l[0],l[1]),E=S!==!1?[v,v]:l,N=s.getRectRotatedPoints({x:w-M/2,y:g-k/2,w:M,h:k},I||0),T=s.getScalePoints(N,new s.Vec2d(w,g),E),R=s.getRotatePoints(T,new s.Vec2d(w,g),-(I||0)),W=s.getRectFromPoints(R);u.opt.width=Math.round(W.w),u.opt.height=Math.round(W.h);const D=[h[0]/y.worldScaling[0],h[1]/y.worldScaling[1]];u.opt.centerX=w+D[0],u.opt.centerY=g+D[1];const x=[u.centerPos[0]+D[0],u.centerPos[1]+D[1]];if(u.centerPos=x,r){let B=s.getRectScaleed(u.rect,l);B=s.getRectTranslated(B,D),u.rect=B}else{const B=P.getRectFromLayer(y,t.name);u.rect=B||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 w=[n[0]*y.worldScaling[0],n[1]*y.worldScaling[1]],g=s.getRectTranslated(u.rect,w);u.rect=g}else{const w=P.getRectFromLayer(y,t.name);u.rect=w||u.rect}else if(K(p))if(u.opt.rotate=p,u.scaleType=Q.getScaleType(u.opt),r){const w=s.getRectRotated(u.rect,p);u.rect=w}else{const w=P.getRectFromLayer(y,t.name);u.rect=w||u.rect}return u&&i.setInfo(t.name,u),u==null?void 0:u.rect}}}class Te extends P{constructor(e){super(e);m(this,"canRotate",!1);m(this,"scaleType",s.EScaleType.both);m(this,"toolsType",s.EToolsKey.Straight);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");m(this,"straightTipWidth");m(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.straightTipWidth=this.workOptions.thickness/2,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:o,isSubWorker:i,isMainThread:r}=e,n=this.workId,{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:s.EPostMessageType.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new s.Point2d(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:s.EPostMessageType.None};let p;if(i||r){const f=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:n,layer:f})}if(!i){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,op:this.tmpPoints.map(u=>[...u.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:s.EPostMessageType.None}}const d=s.computRect(p,this.oldRect);return this.oldRect=p,{rect:d,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,...this.baseConsumeResult}}consumeAll(){var n;const e=this.workId;if(this.tmpPoints.length<2)return{type:s.EPostMessageType.RemoveNode,removeIds:[e]};const t=this.fullLayer,o=this.draw({workId:e,layer:t});this.oldRect=o;const i=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),r=s.transformToSerializableData(i);return(n=this.vNodes)==null||n.setInfo(e,{rect:o,op:i,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:o&&P.getCenterPos(o,t)}),{rect:o,type:s.EPostMessageType.FullWork,dataType:s.EDataType.Local,ops:r,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:o}=e,{strokeColor:i,thickness:r,zIndex:n,scale:c,rotate:l,translate:h}=this.workOptions,p=o.worldPosition,d=o.worldScaling,{d:f,rect:u}=this.computDrawPoints(r),y=[u.x+u.w/2,u.y+u.h/2],w={pos:y,name:t,id:t,d:f,fillColor:i,strokeColor:i,lineWidth:0,className:`${y[0]},${y[1]}`,normalize:!0,zIndex:n};c&&(w.scale=c),l&&(w.rotate=l),h&&(w.translate=h);const g=new b.Path(w);if(this.replace(o,t,g),l||c||h){const k=g.getBoundingClientRect();return{x:Math.floor(k.x-P.SafeBorderPadding),y:Math.floor(k.y-P.SafeBorderPadding),w:Math.floor(k.width+P.SafeBorderPadding*2),h:Math.floor(k.height+P.SafeBorderPadding*2)}}return{x:Math.floor(u.x*d[0]+p[0]-P.SafeBorderPadding),y:Math.floor(u.y*d[1]+p[1]-P.SafeBorderPadding),w:Math.floor(u.w*d[0]+2*P.SafeBorderPadding),h:Math.floor(u.h*d[1]+2*P.SafeBorderPadding)}}computDrawPoints(e){return this.tmpPoints[1].distance(this.tmpPoints[0])>this.straightTipWidth?this.computFullPoints(e):this.computDotPoints(e)}computFullPoints(e){const t=s.Vec2d.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),o=s.Vec2d.Per(t).mul(e/2),i=s.Point2d.Sub(this.tmpPoints[0],o),r=s.Point2d.Add(this.tmpPoints[0],o),n=s.Point2d.Sub(this.tmpPoints[1],o),c=s.Point2d.Add(this.tmpPoints[1],o),l=s.Point2d.GetSemicircleStroke(this.tmpPoints[1],n,-1,8),h=s.Point2d.GetSemicircleStroke(this.tmpPoints[0],r,-1,8),p=[i,n,...l,c,r,...h];return{d:j(p,!0),rect:s.getRectFromPoints(p),isDot:!1,pos:this.tmpPoints[0].XY}}computDotPoints(e){const t=s.Point2d.GetDotStroke(this.tmpPoints[0],e/2,8);return{d:j(t,!0),rect:s.getRectFromPoints(t),isDot:!0,pos:this.tmpPoints[0].XY}}updateTempPoints(e){const t=e.slice(-2),o=new s.Point2d(t[0],t[1]),i=this.tmpPoints[0],{thickness:r}=this.workOptions;if(i.isNear(o,r))return!1;if(this.tmpPoints.length===2){if(o.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=o}else this.tmpPoints.push(o);return!0}consumeService(e){var c,l;const{op:t,isFullWork:o}=e,i=(c=this.workId)==null?void 0:c.toString();if(!i)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new s.Point2d(t[h],t[h+1],t[h+2]));const r=o?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:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&P.getCenterPos(n,r)}),n}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var c;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r}=o,n=i.get(t.name);return r&&(t.setAttribute("strokeColor",r),t.setAttribute("fillColor",r),(c=n==null?void 0:n.opt)!=null&&c.strokeColor&&(n.opt.strokeColor=r)),n&&i.setInfo(t.name,n),P.updateNodeOpt(e)}}const A=class A extends P{constructor(e){super(e);m(this,"canRotate",!1);m(this,"scaleType",s.EScaleType.proportional);m(this,"toolsType",s.EToolsKey.Text);m(this,"tmpPoints",[]);m(this,"workOptions");m(this,"oldRect");this.workOptions=e.toolsOpt}consume(){return{type:s.EPostMessageType.None}}consumeAll(){return{type:s.EPostMessageType.None}}consumeService(){}async draw(e){const{workId:t,layer:o,isDrawLabel:i}=e,{boxSize:r,boxPoint:n,zIndex:c}=this.workOptions,l=o.worldPosition,h=o.worldScaling;if(!n||!r)return;const p={name:t,id:t,pos:[n[0],n[1]],anchor:[0,0],size:r,zIndex:c},d=new b.Group(p),f={x:n[0],y:n[1],w:r[0],h:r[1]},u={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])+2,h:Math.floor(f.h*h[1])+2};if(this.replace(o,t,d),i&&o&&this.workOptions.text){const y=await A.createLabels(this.workOptions,o,u),{labels:w,maxWidth:g}=y;d.append(...w),u.w=Math.ceil(Math.max(g*o.worldScaling[0],u.w))}return u}async consumeServiceAsync(e){var l,h,p,d;const t=(l=this.workId)==null?void 0:l.toString();if(!t)return;const{isFullWork:o,replaceId:i,isDrawLabel:r}=e;this.oldRect=i&&((p=(h=this.vNodes)==null?void 0:h.get(i))==null?void 0:p.rect)||void 0;const n=o?this.fullLayer:this.drawLayer||this.fullLayer,c=await this.draw({workId:t,layer:n,isDrawLabel:typeof r>"u"&&this.workOptions.workState===s.EvevtWorkState.Done||r});return(d=this.vNodes)==null||d.setInfo(t,{rect:c,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:c&&P.getCenterPos(c,n)}),c}updataOptService(){}async updataOptServiceAsync(e,t){var u,y;if(!this.workId)return;const o=this.workId.toString(),{fontColor:i,fontBgColor:r,bold:n,italic:c,lineThrough:l,underline:h,zIndex:p}=e,d=(u=this.vNodes)==null?void 0:u.get(o);if(!d)return;i&&(d.opt.fontColor=i),r&&(d.opt.fontBgColor=r),n&&(d.opt.bold=n),c&&(d.opt.italic=c),s.isBoolean(l)&&(d.opt.lineThrough=l),s.isBoolean(h)&&(d.opt.underline=h),K(p)&&(d.opt.zIndex=p),this.oldRect=d.rect;const f=await this.draw({workId:o,layer:this.fullLayer,isDrawLabel:typeof t>"u"&&this.workOptions.workState===s.EvevtWorkState.Done||t});return(y=this.vNodes)==null||y.setInfo(o,{rect:f,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:f&&P.getCenterPos(f,this.fullLayer)}),f}clearTmpPoints(){this.tmpPoints.length=0}static getSafetySnippetRatio(e){const t=(e==null?void 0:e.parent).displayRatio||1,o=Math.ceil(e.worldScaling[0]*10)/10;let i=o;return o>=.2&&o<1?i=o*t:o<=2&&o>=1?i=o*t*1.6:o>2&&o<=3?i=o*t*1.4:o>3&&o<=4?i=o*t*.8:o>4&&(i=o*t*.6),Math.floor(i*1e3)/1e3}static getSafetySnippetFontLength(e){return Math.floor(A.textImageSnippetSize*3/4/e)||1}static async createLabels(e,t,o){var W;const i=[],{x:r,y:n}=o,{width:c,height:l}=(W=t.parent)==null?void 0:W.parent,h=s.transformToNormalData(e.text),p=h.length,{fontSize:d,lineHeight:f,bold:u,textAlign:y,italic:w,fontFamily:g,verticalAlign:M,fontColor:k,fontBgColor:S,underline:I,lineThrough:v}=e,E=A.getSafetySnippetRatio(t)||1,N=Math.floor(d*E),T=A.getSafetySnippetFontLength(N);let R=0;for(let D=0;D<p;D++){const x=h[D],B=f||N*1.5;if(x){const Z=s.strlen(x),C=[0,0],O=[0,d*1.2];M==="middle"&&(C[1]=D*d*1.2+5);const Y=[0,-d*.15];C[0]=5;const ee=Math.sin(Math.PI/180*20);let $=0;const te=[];let J=0;for(;J<Z;){y==="left"&&(Y[0]=$),J===0&&w==="italic"&&(Y[0]=Y[0]-ee/2*d);const ae=x.slice(J,J+T),se={anchor:[0,0],pos:Y,text:ae,fontFamily:g,fontSize:N,lineHeight:B,strokeColor:k,fontWeight:u,fillColor:k,textAlign:y,fontStyle:w,scale:[1/E,1/E]},G=new b.Label(se),_=await G.textImageReady;let oe=!0;if(_){const le=_.rect&&_.rect[2],he=_.rect&&_.rect[3];if(le&&he){const pe=le/E,ve=he/E;$=pe+$,w==="italic"&&(u==="bold"?$=$-ee*d*1.2:$=$-ee*d),((Y[0]+C[0]+pe)*t.worldScaling[0]+r<=0||(Y[0]+C[0])*t.worldScaling[0]+r>=c||(Y[1]+C[1]+ve)*t.worldScaling[1]+n<=0||(Y[1]+C[1])*t.worldScaling[1]+n>=l)&&(G.disconnect(),oe=!1),oe&&te.push(G)}}J+=T}O[0]=$,w==="italic"&&(O[0]=O[0]+ee*d),R=Math.max(R,O[0]);let ce=!0;if(((C[0]+O[0])*t.worldScaling[0]+r<=0||C[0]*t.worldScaling[0]+r>=c||(C[1]+O[1])*t.worldScaling[0]+n<=0||C[1]*t.worldScaling[1]+n>=l)&&(ce=!1),ce){if(I){const G=Math.floor(d/10),_={normalize:!1,pos:[0,d*1.1+G/2],lineWidth:G,points:[0,0,Math.ceil(O[0]),0],strokeColor:k,className:"underline"},oe=new b.Polyline(_);te.push(oe)}if(v){const G={normalize:!1,pos:[0,d*1.2/2],lineWidth:Math.floor(d/10),points:[0,0,Math.ceil(O[0]),0],strokeColor:k,className:"lineThrough"},_=new b.Polyline(G);te.push(_)}const ae={pos:C,anchor:[0,0],size:O,bgcolor:S},se=new b.Group(ae);se.append(...te),i.push(se)}}}return{labels:i,maxWidth:R}}static updateNodeOpt(e){const{node:t,opt:o,vNodes:i,targetNode:r}=e,{fontBgColor:n,fontColor:c,translate:l,box:h,boxScale:p,boxTranslate:d,bold:f,italic:u,lineThrough:y,underline:w,fontSize:g,textInfos:M,zIndex:k}=o,S=r&&s.cloneDeep(r)||i.get(t.name);if(!S)return;const I=t.parent;if(!I)return;const v=S.opt;if(K(k)&&(t.setAttribute("zIndex",k),S.opt.zIndex=k),c&&v.fontColor&&(v.fontColor=c,t.children.forEach(E=>{E.tagName==="GROUP"&&E.children.forEach(N=>{N.tagName==="LABEL"?(N.setAttribute("fillColor",c),N.setAttribute("strokeColor",c)):N.tagName==="POLYLINE"&&N.setAttribute("strokeColor",c)})})),n&&v.fontBgColor&&(v.fontBgColor=n,t.children.forEach(E=>{E.tagName==="GROUP"&&E.setAttribute("bgcolor",n)})),f&&(v.bold=f),u&&(v.italic=u),s.isBoolean(y)&&(v.lineThrough=y),s.isBoolean(w)&&(v.underline=w),g&&(v.fontSize=g),h&&d&&p){const E=M==null?void 0:M.get(t.name);if(E){const{fontSize:R,boxSize:W}=E;v.boxSize=W||v.boxSize,v.fontSize=R||v.fontSize}const N=S.rect,T=s.getRectTranslated(s.getRectScaleed(N,p),d);v.boxPoint=T&&[(T.x-I.worldPosition[0])/I.worldScaling[0],(T.y-I.worldPosition[1])/I.worldScaling[1]]}else if(l&&v.boxPoint&&(v.boxPoint=[v.boxPoint[0]+l[0],v.boxPoint[1]+l[1]],S.centerPos=[S.centerPos[0]+l[0],S.centerPos[1]+l[1]],r)){const E=[l[0]/I.worldScaling[0],l[1]/I.worldScaling[1]];S.rect=s.getRectTranslated(S.rect,E)}return S&&i.setInfo(t.name,S),S==null?void 0:S.rect}static getRectFromLayer(e,t){const o=e.getElementsByName(t)[0];if(o){const i=o.getBoundingClientRect();let r={x:Math.floor(i.x-A.SafeBorderPadding*e.worldScaling[0]),y:Math.floor(i.y-A.SafeBorderPadding*e.worldScaling[1]),w:Math.floor(i.width+A.SafeBorderPadding*e.worldScaling[0]*2),h:Math.floor(i.height+A.SafeBorderPadding*e.worldScaling[1]*2)};return o.children.forEach(n=>{if(n.tagName==="GROUP"){const c=o.getBoundingClientRect();r=s.computRect(r,{x:Math.floor(c.x-A.SafeBorderPadding*e.worldScaling[0]),y:Math.floor(c.y-A.SafeBorderPadding*e.worldScaling[1]),w:Math.floor(c.width+A.SafeBorderPadding*e.worldScaling[0]*2),h:Math.floor(c.height+A.SafeBorderPadding*e.worldScaling[1]*2)})}}),r}}};m(A,"textImageSnippetSize",1024*4),m(A,"SafeBorderPadding",30);let re=A;function ke(L){switch(L){case s.EToolsKey.Arrow:return fe;case s.EToolsKey.Pencil:return de;case s.EToolsKey.Straight:return Te;case s.EToolsKey.Ellipse:return ye;case s.EToolsKey.Polygon:case s.EToolsKey.Triangle:return we;case s.EToolsKey.Star:case s.EToolsKey.Rhombus:return ge;case s.EToolsKey.Rectangle:return me;case s.EToolsKey.SpeechBalloon:return Se;case s.EToolsKey.Text:return re;case s.EToolsKey.LaserPen:return ue;case s.EToolsKey.Eraser:return ie;case s.EToolsKey.Selector:return z;case s.EToolsKey.Image:return Q}}function ne(L,a){const{toolsType:e,...t}=L;switch(e){case s.EToolsKey.Arrow:return new fe(t);case s.EToolsKey.Pencil:return new de(t);case s.EToolsKey.Straight:return new Te(t);case s.EToolsKey.Ellipse:return new ye(t);case s.EToolsKey.Polygon:case s.EToolsKey.Triangle:return new we(t);case s.EToolsKey.Star:case s.EToolsKey.Rhombus:return new ge(t);case s.EToolsKey.Rectangle:return new me(t);case s.EToolsKey.SpeechBalloon:return new Se(t);case s.EToolsKey.Text:return new re(t);case s.EToolsKey.LaserPen:return new ue(t);case s.EToolsKey.Eraser:return new ie(t,a);case s.EToolsKey.Selector:return t.vNodes?new z({...t,vNodes:t.vNodes,drawLayer:t.fullLayer}):void 0;case s.EToolsKey.Image:return new Q(t);default:return}}function Pe(L){const a=[],e=["PATH","SPRITE","POLYLINE","RECT","ELLIPSE","LABEL"];for(const t of L){if(t.tagName==="GROUP"&&t.children.length)return Pe(t.children);t.tagName&&e.includes(t.tagName)&&a.push(t)}return a}const xe=L=>{if(L.tagName==="GROUP"){const a=Object.getOwnPropertySymbols(L).find(e=>e.toString()==="Symbol(sealed)");if(a&&L[a])return!0}return!1},Ce=L=>!L.isHid;class De{constructor(a,e){m(this,"viewId");m(this,"scene");m(this,"fullLayer");m(this,"curNodeMap",new Map);m(this,"targetNodeMap",[]);m(this,"highLevelIds");this.viewId=a,this.scene=e}init(a){this.fullLayer=a}get(a){return this.curNodeMap.get(a)}getNodesByType(a){const e=new Map;return this.curNodeMap.forEach((t,o)=>{t.toolsType===a&&e.set(o,t)}),e}hasRenderNodes(){let a=!1;for(const e of this.curNodeMap.values())Ce(e)&&(a=!0);return a}has(a){return this.curNodeMap.has(a)}setInfo(a,e){const t=this.curNodeMap.get(a)||{name:a,rect:e.rect};e.rect&&(t.rect=s.cloneDeep(e.rect)),e.op&&s.checkOp(e.op)&&(t.op=s.cloneDeep(e.op)),e.canRotate&&(t.canRotate=e.canRotate),e.scaleType&&(t.scaleType=e.scaleType),e.opt&&(t.opt=s.cloneDeep(e.opt)),e.toolsType&&(t.toolsType=e.toolsType),e.centerPos&&(t.centerPos=s.cloneDeep(e.centerPos)),s.isBoolean(e.isSelected)&&(t.isSelected=e.isSelected),t.rect?this.curNodeMap.set(a,t):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,e=!0){for(const t of this.curNodeMap.values())if(s.isIntersect(a,t.rect)){if(e&&t.toolsType===s.EToolsKey.Image&&t.opt.locked||e&&t.toolsType===s.EToolsKey.Text&&(t.opt.workState===s.EvevtWorkState.Doing||t.opt.workState===s.EvevtWorkState.Start))continue;return!0}return!1}getRectIntersectRange(a,e=!0,t=!0){let o;const i=new Map;for(const[r,n]of this.curNodeMap.entries())if(s.isIntersect(a,n.rect)){if(e&&n.toolsType===s.EToolsKey.Image&&n.opt.locked||t&&n.toolsType===s.EToolsKey.Text&&(n.opt.workState===s.EvevtWorkState.Doing||n.opt.workState===s.EvevtWorkState.Start))continue;o=s.computRect(o,n.rect),i.set(r,n)}return{rectRange:o,nodeRange:i}}getNodeRectFormShape(a,e){const t=ke(e.toolsType);return this.fullLayer&&(t==null?void 0:t.getRectFromLayer(this.fullLayer,a))}updateNodeRect(a){const e=this.curNodeMap.get(a);if(e){const t=this.getNodeRectFormShape(a,e);if(!t){this.curNodeMap.delete(a);return}e.rect=t,this.curNodeMap.set(a,e)}}updateHighLevelNodesRect(a){this.highLevelIds=a;for(const e of this.highLevelIds.keys())this.updateNodeRect(e)}updateLowLevelNodesRect(){var a;for(const e of this.curNodeMap.keys())(a=this.highLevelIds)!=null&&a.has(e)||this.updateNodeRect(e)}clearHighLevelIds(){this.highLevelIds=void 0}combineIntersectRect(a){let e=a;return this.curNodeMap.forEach(t=>{s.isIntersect(e,t.rect)&&(e=s.computRect(e,t.rect))}),e}setTarget(){return this.targetNodeMap.push(s.cloneDeep(this.curNodeMap)),this.targetNodeMap.length-1}getLastTarget(){return this.targetNodeMap[this.targetNodeMap.length-1]}deleteLastTarget(){this.targetNodeMap.length&&(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 Oe{constructor(a){m(this,"vNodes");m(this,"thread");m(this,"serviceWorkShapes",new Map);m(this,"localWorkShapes",new Map);m(this,"tmpOpt");m(this,"animationId");m(this,"syncUnitTime",s.DefaultAppliancePluginOptions.syncOpt.interval);this.vNodes=a.vNodes,this.thread=a.thread}createLocalWork(a){const{workId:e,opt:t,toolsType:o}=a;if(e&&t){const i=e.toString();!this.getToolsOpt()&&o&&this.setToolsOpt({toolsType:o,toolsOpt:t}),this.setWorkOptions(i,t)}}getLocalWorkShape(a){return this.localWorkShapes.get(a)}createLocalWorkShape(a,e){if(a&&this.tmpOpt){const t={toolsType:this.tmpOpt.toolsType,toolsOpt:e||this.tmpOpt.toolsOpt},o=this.createWorkShapeNode({...t,workId:a});return o&&this.localWorkShapes.set(a,{node:o,toolsType:o.toolsType,workState:s.EvevtWorkState.Start}),o}}canUseTopLayer(a){return a===s.EToolsKey.LaserPen}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:e,dataType:t}=a;if(t===s.EDataType.Service)this.activeServiceWorkShape(a);else{const o=e==null?void 0:e.toString(),i=o&&this.localWorkShapes.get(o);if(!i)return;const r=i.node.consume({data:a,isFullWork:!1,isSubWorker:!0});r.rect&&(i.result=r,i.workState=s.EvevtWorkState.Doing,o&&this.localWorkShapes.set(o,i))}this.runAnimation()}setToolsOpt(a){var e;this.tmpOpt=a,(e=a.toolsOpt)!=null&&e.syncUnitTime&&(this.syncUnitTime=a.toolsOpt.syncUnitTime)}getToolsOpt(){return this.tmpOpt}createWorkShapeNode(a){const{toolsType:e}=a;if(e===s.EToolsKey.LaserPen)return ne({...a,vNodes:this.vNodes,fullLayer:this.thread.topLayer,drawLayer:this.thread.topLayer})}setNodeKey(a,e,t,o){return e.toolsType=t,e.node=this.createWorkShapeNode({workId:a,toolsType:t,toolsOpt:o}),e}activeServiceWorkShape(a){var d,f;const{workId:e,opt:t,toolsType:o,type:i,updateNodeOpt:r,ops:n,op:c}=a;if(!e)return;const l=e.toString(),h=(d=this.vNodes.get(l))==null?void 0:d.rect;if(!((f=this.serviceWorkShapes)!=null&&f.has(l))){let u={toolsType:o,animationWorkData:c||[],animationIndex:0,type:i,updateNodeOpt:r,ops:n,oldRect:h};o&&t&&(u=this.setNodeKey(l,u,o,t)),this.serviceWorkShapes.set(l,u)}const p=this.serviceWorkShapes.get(l);i&&(p.type=i),n&&(p.animationWorkData=s.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),o&&t&&(p.toolsType!==o&&o&&t&&this.setNodeKey(l,p,o,t),p.node&&p.node.setWorkOptions(t))}computNextAnimationIndex(a,e){var i;const t=((i=a.node)==null?void 0:i.syncUnitTime)||this.syncUnitTime,o=Math.floor((a.animationWorkData||[]).slice(a.animationIndex).length*32/e/t)*e;return Math.min((a.animationIndex||0)+(o||e),(a.animationWorkData||[]).length)}animationDraw(){var o,i,r,n;this.animationId=void 0;let a=!1;const e=new Map,t=[];for(const[c,l]of this.serviceWorkShapes.entries())switch(l.toolsType){case s.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&&((o=l.node)==null||o.consumeService({op:f,isFullWork:!1}),l.animationIndex=p,f.length&&e.set(c,{workState:d===0?s.EvevtWorkState.Start:p===((i=l.animationWorkData)==null?void 0:i.length)?s.EvevtWorkState.Done:s.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 s.EToolsKey.LaserPen:{if(d){l.node.clearTmpPoints(),this.localWorkShapes.delete(c),t.push({removeIds:[c.toString()],type:s.EPostMessageType.RemoveNode});break}h&&((h.op||h.ops)&&t.push(h),l.result=void 0),!this.thread.topLayer.getElementsByName(c.toString())[0]&&f===s.EvevtWorkState.Done&&(l.isDel=!0,this.localWorkShapes.set(c,l)),a=!0;break}}}a&&this.runAnimation(),e.size&&e.forEach((c,l)=>{t.push({type:s.EPostMessageType.Cursor,uid:l.split(s.Storage_Splitter)[0],op:c.op,workState:c.workState,viewId:this.thread.viewId})}),t.length&&this.thread.post({sp:t})}runAnimation(){this.animationId||(this.animationId=requestAnimationFrame(this.animationDraw.bind(this)))}setWorkOptions(a,e){var o;let t=(o=this.localWorkShapes.get(a))==null?void 0:o.node;if(!t&&this.tmpOpt){const{toolsType:i}=this.tmpOpt;this.tmpOpt.toolsOpt=e,t=this.createWorkShapeNode({workId:a,toolsType:i,toolsOpt:e}),t&&this.localWorkShapes.set(a,{node:t,toolsType:i,workState:s.EvevtWorkState.Start}),this.setToolsOpt(this.tmpOpt)}e!=null&&e.syncUnitTime||(e.syncUnitTime=this.syncUnitTime),t&&t.setWorkOptions(e)}consumeDrawAll(a){const{workId:e,dataType:t}=a;if(t===s.EDataType.Service)this.activeServiceWorkShape(a);else{const o=e==null?void 0:e.toString(),i=o&&this.localWorkShapes.get(o);if(!i)return;const r=i.node.consumeAll({data:a});i.result=r,i.workState=s.EvevtWorkState.Done,o&&this.localWorkShapes.set(o,i)}this.runAnimation()}}class Ae{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,"syncUnitTime",s.DefaultAppliancePluginOptions.syncOpt.interval);m(this,"drawCount",0);m(this,"drawWorkActiveId");m(this,"batchEraserCombine",s.throttle(()=>{this.updateBatchEraserCombineNode(this.batchEraserWorks,this.batchEraserRemoveNodes),this.batchEraserWorks.clear(),this.batchEraserRemoveNodes.clear()},100,{leading:!1}));this.vNodes=a.vNodes,this.thread=a.thread}createLocalWork(a){const{workId:e,opt:t,toolsType:o}=a;if(e&&t){const i=e.toString();!this.getToolsOpt()&&o&&this.setToolsOpt({toolsType:o,toolsOpt:t}),this.setWorkOptions(i,t)}}workShapesDone(a,e){for(const t of this.workShapes.keys())this.consumeDrawAll({workId:t,scenePath:a,viewId:this.thread.viewId,msgType:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local},e)}async updateSelector(a){var f;const e=this.workShapes.get(s.Storage_Selector_key);if(!((f=e==null?void 0:e.selectIds)!=null&&f.length))return;const{callback:t,...o}=a,{updateSelectorOpt:i,willSerializeData:r,scene:n}=o,c=await(e==null?void 0:e.updateSelector({updateSelectorOpt:i,selectIds:H.cloneDeep(e.selectIds),vNodes:this.vNodes,willSerializeData:r,worker:this,scene:n,isMainThread:!0})),l=new Map;let h;c!=null&&c.selectIds&&(h=H.xor(e.selectIds,c.selectIds),c.selectIds.forEach(u=>{const y=this.vNodes.get(u);if(y){const{toolsType:w,op:g,opt:M}=y;l.set(u,{opt:M,toolsType:w,ops:(g==null?void 0:g.length)&&s.transformToSerializableData(g)||void 0})}}),e.selectIds=c.selectIds,console.log("removeIds",h));const p=[],d=t&&t({res:c,workShapeNode:e,param:o,postData:{sp:p},newServiceStore:l})||{sp:p};h&&d.sp.push({type:s.EPostMessageType.RemoveNode,removeIds:h,viewId:this.thread.viewId}),d.sp.length&&this.thread.post(d)}destroy(){this.clearAll()}clearAll(){if(this.thread.localLayer.children.length&&(this.thread.topLayer.parent.children.forEach(e=>{e.name!=="viewport"&&e.remove()}),this.thread.localLayer.removeAllChildren()),this.workShapes.get(s.Storage_Selector_key)){const e=[];e.push({type:s.EPostMessageType.Select,dataType:s.EDataType.Local,selectIds:[],willSyncService:!1}),this.thread.post({sp:e})}this.workShapes.clear(),this.effectSelectNodeData.clear(),this.batchEraserWorks.clear(),this.batchEraserRemoveNodes.clear()}async checkTextActive(a){const{op:e,viewId:t,dataType:o}=a;if(e!=null&&e.length){let i;for(const r of this.vNodes.curNodeMap.values()){const{rect:n,name:c,toolsType:l,opt:h}=r,p=e[0]*this.thread.fullLayer.worldScaling[0]+this.thread.fullLayer.worldPosition[0],d=e[1]*this.thread.fullLayer.worldScaling[1]+this.thread.fullLayer.worldPosition[1];if(l===s.EToolsKey.Text&&s.isIntersectForPoint([p,d],n)&&h.workState===s.EvevtWorkState.Done){i=c;break}}i&&(await this.blurSelector({viewId:t,msgType:s.EPostMessageType.Select,dataType:o,isSync:!0}),this.thread.post({sp:[{type:s.EPostMessageType.GetTextActive,toolsType:s.EToolsKey.Text,workId:i}]}))}}cursorHover(a){const{opt:e,toolsType:t,point:o}=a,i=this.setFullWork({workId:s.Cursor_Hover_Id,toolsType:t,opt:e});i&&o&&i.cursorHover(o)}updateFullSelectWork(a){var o,i,r,n,c;const e=this.workShapes.get(s.Storage_Selector_key),{selectIds:t}=a;if(!(t!=null&&t.length)){this.blurSelector(a);return}if(!e){const l=this.setFullWork(a);!l&&a.workId&&this.tmpOpt&&((o=this.tmpOpt)==null?void 0:o.toolsType)===s.EToolsKey.Selector&&this.setWorkOptions(a.workId.toString(),a.opt||this.tmpOpt.toolsOpt),l&&this.updateFullSelectWork(a);return}if(e&&(t!=null&&t.length)){const{selectRect:l}=e.updateSelectIds(t),h=[{...a,selectorColor:((i=a.opt)==null?void 0:i.strokeColor)||e.selectorColor,strokeColor:((r=a.opt)==null?void 0:r.strokeColor)||e.strokeColor,fillColor:((n=a.opt)==null?void 0:n.fillColor)||e.fillColor,textOpt:((c=a.opt)==null?void 0:c.textOpt)||e.textOpt,canTextEdit:e.canTextEdit,canRotate:e.canRotate,scaleType:e.scaleType,type:s.EPostMessageType.Select,selectRect:l,points:e.getChildrenPoints(),willSyncService:(a==null?void 0:a.willSyncService)||!1,opt:(a==null?void 0:a.willSyncService)&&e.getWorkOptions()||void 0,canLock:e.canLock,isLocked:e.isLocked,toolsTypes:e.toolsTypes,shapeOpt:e.shapeOpt}];this.thread.post({sp:h})}}commandDeleteText(a){const e=this.vNodes.get(a);if(e&&e.toolsType===s.EToolsKey.Text)return{type:s.EPostMessageType.TextUpdate,toolsType:s.EToolsKey.Text,workId:a,dataType:s.EDataType.Local}}async removeSelector(a){const{willSyncService:e}=a,t=[],o=[],i=this.workShapes.get(s.Storage_Selector_key);if(!i)return;const r=i.selectIds&&[...i.selectIds]||[];for(const n of r){if(this.vNodes.get(n)){const l=this.commandDeleteText(n);l&&t.push(l)}this.removeNode(n),o.push(n)}o.length&&t.push({type:s.EPostMessageType.RemoveNode,removeIds:o}),t.push({type:s.EPostMessageType.Select,selectIds:[],willSyncService:e}),await this.blurSelector(),t.length&&this.thread.post({sp:t})}removeWork(a){const{workId:e}=a,t=e==null?void 0:e.toString();t&&this.removeNode(t)}removeNode(a){var o;this.vNodes.get(a)&&((o=this.thread.fullLayer)==null||o.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:e,opt:t,toolsType:o}=a;if(e&&t&&o){const i=e.toString();let r;return e&&this.workShapes.has(i)?(r=this.workShapes.get(i),r==null||r.setWorkOptions(t)):r=this.createWorkShapeNode({toolsOpt:t,toolsType:o,workId:i}),r?(this.workShapes.set(i,r),r):void 0}}async consumeFull(a,e){var i;const t=this.setFullWork(a),o=a.ops&&s.transformToNormalData(a.ops);if(t){const r=(i=a.workId)==null?void 0:i.toString();t.toolsType===s.EToolsKey.Image&&e?await t.consumeServiceAsync({scene:e,isFullWork:!0,replaceId:r,isMainThread:!0}):t.toolsType===s.EToolsKey.Text?await t.consumeServiceAsync({isFullWork:!0,replaceId:r}):t.consumeService({op:o,isFullWork:!0,replaceId:r}),a!=null&&a.updateNodeOpt&&t.updataOptService(a.updateNodeOpt);const n=[];a.workId&&this.workShapes.delete(a.workId.toString()),a.willSyncService&&n.push({opt:a.opt,toolsType:a.toolsType,type:s.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 e=this.workShapes.get(s.Storage_Selector_key),{workId:t,msgType:o}=a;if(e&&t&&e.selectIds&&e.selectIds.includes(t.toString())){o===s.EPostMessageType.RemoveNode?e.selectIds=e.selectIds.filter(i=>i!==t.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 e,t,o;for(const i of this.effectSelectNodeData.values()){const r=this.setFullWork(i);if(r){const n=(e=i.workId)==null?void 0:e.toString();if(r.toolsType===s.EToolsKey.Image)await r.consumeServiceAsync({scene:(o=(t=this.thread.localLayer)==null?void 0:t.parent)==null?void 0:o.parent,isFullWork:!0,replaceId:n,isMainThread:!0});else if(r.toolsType===s.EToolsKey.Text)await r.consumeServiceAsync({isFullWork:!0,replaceId:n});else{const c=i.ops&&s.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)}hasSelector(){return this.workShapes.has(s.Storage_Selector_key)}getSelector(){return this.workShapes.get(s.Storage_Selector_key)}reRenderSelector(a=!1){var o;const e=this.workShapes.get(s.Storage_Selector_key);if(!e)return;if(e&&!((o=e.selectIds)!=null&&o.length))return this.blurSelector();const t=e.reRenderSelector();t&&this.thread.post({sp:[{type:s.EPostMessageType.Select,selectIds:e.selectIds,selectRect:t,willSyncService:a,viewId:this.thread.viewId,points:e.getChildrenPoints(),textOpt:e.textOpt,selectorColor:e.selectorColor,strokeColor:e.strokeColor,fillColor:e.fillColor,canTextEdit:e.canTextEdit,canRotate:e.canRotate,scaleType:e.scaleType,opt:e.getWorkOptions()||void 0,canLock:e.canLock,isLocked:e.isLocked,toolsTypes:e.toolsTypes,shapeOpt:e.shapeOpt}]})}async blurSelector(a){var o;const e=this.workShapes.get(s.Storage_Selector_key),t=e==null?void 0:e.blurSelector();if(this.clearWorkShapeNodeCache(s.Storage_Selector_key),((o=this.thread.fullLayer)==null?void 0:o.parent).children.forEach(i=>{i.name===s.Storage_Selector_key&&i.remove()}),t){const i=[];i.push({...t,isSync:a==null?void 0:a.isSync}),this.thread.post({sp:i})}}clearWorkShapeNodeCache(a){var e;(e=this.getWorkShape(a))==null||e.clearTmpPoints(),this.workShapes.delete(a)}drawEraser(a){var t,o;const e=[];if((t=a.newWorkDatas)!=null&&t.size){for(const i of a.newWorkDatas.values()){const r=i.workId.toString();this.batchEraserWorks.add(r),e.push({type:s.EPostMessageType.FullWork,workId:r,ops:s.transformToSerializableData(i.op),opt:i.opt,toolsType:i.toolsType,updateNodeOpt:{useAnimation:!1}})}delete a.newWorkDatas}(o=a.removeIds)==null||o.forEach(i=>{this.batchEraserRemoveNodes.add(i)}),e.push(a),this.thread.post({sp:e}),this.batchEraserCombine()}updateBatchEraserCombineNode(a,e){for(const t of e.keys())this.thread.fullLayer.getElementsByName(t).forEach(o=>{o.remove()});a.forEach(t=>{const o=this.vNodes.get(t);if(o&&o.toolsType===s.EToolsKey.Pencil&&!this.thread.fullLayer.getElementsByName(t)[0]){const r=this.setFullWork({...o,workId:t});r&&r.consumeService({op:o.op,isFullWork:!0})}})}getWorkShape(a){return this.workShapes.get(a)}getWorkShapes(){return this.workShapes}consumeDraw(a,e){const{op:t,workId:o,scenePath:i}=a;if(t!=null&&t.length&&o){const r=o.toString(),n=this.workShapes.get(r);if(!n)return;const c=n.toolsType;if(c===s.EToolsKey.LaserPen)return;switch(this.drawWorkActiveId&&this.drawWorkActiveId!==r&&(this.consumeDrawAll({workId:this.drawWorkActiveId,scenePath:i,viewId:this.thread.viewId,msgType:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local},e),this.drawWorkActiveId=void 0),!this.drawWorkActiveId&&r!==s.Storage_Selector_key&&(this.drawWorkActiveId=r),c){case s.EToolsKey.Selector:{const l=n.consume({data:a,isFullWork:!0});l.type===s.EPostMessageType.Select&&(l.selectIds&&e.runReverseSelectWork(l.selectIds),this.thread.post({sp:[l]}))}break;case s.EToolsKey.Eraser:{const l=n.consume({data:a,isFullWork:!0});l!=null&&l.rect&&this.drawEraser(l)}break;case s.EToolsKey.Arrow:case s.EToolsKey.Straight:case s.EToolsKey.Ellipse:case s.EToolsKey.Rectangle:case s.EToolsKey.Star:case s.EToolsKey.Polygon:case s.EToolsKey.SpeechBalloon:case s.EToolsKey.Pencil:{const l=n.consume({data:a,isFullWork:!1,isMainThread:!0});l&&(this.drawCount++,this.thread.post({drawCount:this.drawCount,sp:l.op&&[{...l,scenePath:i}]||void 0}))}break}}}consumeDrawAll(a,e){var i,r,n;const{workId:t,scenePath:o}=a;if(t){const c=t.toString();this.drawWorkActiveId===c&&(this.drawWorkActiveId=void 0);const l=this.workShapes.get(c);if(!l)return;const h=l.toolsType;if(h===s.EToolsKey.LaserPen)return;const p=this.workShapes.get(s.Cursor_Hover_Id),d=(i=p==null?void 0:p.selectIds)==null?void 0:i[0],f=l.consumeAll({data:a});switch(h){case s.EToolsKey.Selector:f.selectIds&&d&&((r=f.selectIds)!=null&&r.includes(d))&&p.cursorBlur(),f.type===s.EPostMessageType.Select&&(f.selectIds&&e.runReverseSelectWork(f.selectIds),this.thread.post({sp:[{...f,scenePath:o}]})),(n=l.selectIds)!=null&&n.length?l.clearTmpPoints():this.clearWorkShapeNodeCache(c);break;case s.EToolsKey.Eraser:f!=null&&f.rect&&this.drawEraser({...f,scenePath:o}),l.clearTmpPoints();break;case s.EToolsKey.Arrow:case s.EToolsKey.Straight:case s.EToolsKey.Ellipse:case s.EToolsKey.Rectangle:case s.EToolsKey.Star:case s.EToolsKey.Polygon:case s.EToolsKey.SpeechBalloon:case s.EToolsKey.Pencil:f&&(this.drawCount=0,this.thread.post({drawCount:this.drawCount,sp:[f]})),this.clearWorkShapeNodeCache(c);break}}}getToolsOpt(){return this.tmpOpt}setToolsOpt(a){var e;this.tmpOpt=a,(e=a.toolsOpt)!=null&&e.syncUnitTime&&(this.syncUnitTime=a.toolsOpt.syncUnitTime)}setWorkOptions(a,e){let t=this.workShapes.get(a);if(!t&&this.tmpOpt){const{toolsType:o}=this.tmpOpt;this.tmpOpt.toolsOpt=e,t=this.createWorkShapeNode({workId:a,toolsType:o,toolsOpt:e}),t&&this.workShapes.set(a,t),this.setToolsOpt(this.tmpOpt)}e.syncUnitTime||(e.syncUnitTime=this.syncUnitTime),t==null||t.setWorkOptions(e)}createWorkShapeNode(a){return ne({...a,vNodes:this.vNodes,fullLayer:this.thread.fullLayer,drawLayer:this.thread.localLayer},this.thread.serviceWork)}}class Be{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");m(this,"syncUnitTime",s.DefaultAppliancePluginOptions.syncOpt.interval);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 t,o;const e=this.selectorWorkShapes.get(a);e&&e.selectIds&&((t=e.node)==null||t.selectServiceNode(a,e,!0)),(o=e==null?void 0:e.selectIds)!=null&&o.length||this.selectorWorkShapes.delete(a)}),this.willRunEffectSelectorIds.clear()}runSelectWork(a){this.activeSelectorShape(a);const{workId:e}=a,t=e==null?void 0:e.toString();t&&this.willRunEffectSelectorIds.add(t),this.runEffect()}removeWork(a){const{workId:e}=a,t=e==null?void 0:e.toString();if(t){if(this.workShapes.get(t)){this.workShapes.delete(t),this.removeNode(t,a);return}this.removeNode(t,a)}}consumeFull(a){this.activeWorkShape(a),this.runAnimation()}runReverseSelectWork(a){a.forEach(e=>{this.selectorWorkShapes.forEach((t,o)=>{var i;if((i=t.selectIds)!=null&&i.length){const r=t.selectIds.indexOf(e);r>-1&&(t.selectIds.splice(r,1),this.willRunEffectSelectorIds.add(o))}})}),this.willRunEffectSelectorIds.size&&this.runEffect()}consumeDraw(a){this.activeWorkShape(a),this.runAnimation()}computNextAnimationIndex(a,e){const t=Math.floor((a.animationWorkData||[]).slice(a.animationIndex).length*32/e/this.syncUnitTime)*e;return Math.min((a.animationIndex||0)+(t||e),(a.animationWorkData||[]).length)}async animationDraw(){var t,o,i,r,n,c,l,h,p,d,f,u,y,w,g,M;this.animationId=void 0;let a=!1;const e=new Map;for(const[k,S]of this.workShapes.entries())switch(S.toolsType){case s.EToolsKey.Image:{await((o=S.node)==null?void 0:o.consumeServiceAsync({isFullWork:!0,scene:(t=this.thread.fullLayer.parent)==null?void 0:t.parent,isMainThread:!0})),this.selectorWorkShapes.forEach((I,v)=>{var E;(E=I.selectIds)!=null&&E.includes(k)&&(this.willRunEffectSelectorIds.add(v),this.runEffect())}),this.workShapes.delete(k);break}case s.EToolsKey.Text:{S.node&&(await((i=S.node)==null?void 0:i.consumeServiceAsync({isFullWork:!0,replaceId:k})),this.selectorWorkShapes.forEach((I,v)=>{var E;(E=I.selectIds)!=null&&E.includes(k)&&(this.willRunEffectSelectorIds.add(v),this.runEffect())}),(r=S.node)==null||r.clearTmpPoints(),this.workShapes.delete(k));break}case s.EToolsKey.Arrow:case s.EToolsKey.Straight:case s.EToolsKey.Rectangle:case s.EToolsKey.Ellipse:case s.EToolsKey.Star:case s.EToolsKey.Polygon:case s.EToolsKey.SpeechBalloon:{const I=!!S.ops;if((n=S.animationWorkData)!=null&&n.length){const v=S.oldRect;(c=S.node)==null||c.consumeService({op:S.animationWorkData,isFullWork:I}),I&&(this.selectorWorkShapes.forEach((E,N)=>{var T;(T=E.selectIds)!=null&&T.includes(k)&&(this.willRunEffectSelectorIds.add(N),this.runEffect())}),(l=S.node)==null||l.clearTmpPoints(),this.workShapes.delete(k)),e.set(k,{workState:v?S.ops?s.EvevtWorkState.Done:s.EvevtWorkState.Doing:s.EvevtWorkState.Start,op:S.animationWorkData.filter((E,N)=>{if(N%3!==2)return!0}).slice(-2)}),S.animationWorkData.length=0}break}case s.EToolsKey.Pencil:{if(!S.useAnimation&&S.ops)(h=S.node)==null||h.consumeService({op:S.animationWorkData||[],isFullWork:!0,replaceId:k}),(p=S.node)==null||p.updataOptService(S.updateNodeOpt),this.selectorWorkShapes.forEach((I,v)=>{var E;(E=I.selectIds)!=null&&E.includes(k)&&(this.willRunEffectSelectorIds.add(v),this.runEffect())}),(d=S.node)==null||d.clearTmpPoints(),this.workShapes.delete(k);else if(S.useAnimation){if(S.isDel){(f=S.node)==null||f.clearTmpPoints(),this.workShapes.delete(k);break}const I=3,v=this.computNextAnimationIndex(S,I),E=S.isDiff?0:Math.max(0,(S.animationIndex||0)-I),N=(S.animationWorkData||[]).slice(E,v),T=(y=(u=S.node)==null?void 0:u.getWorkId())==null?void 0:y.toString();if((S.animationIndex||0)<v||S.isDiff){if((w=S.node)==null||w.consumeService({op:N,isFullWork:!1}),S.animationIndex=v,S.isDiff&&(S.isDiff=!1),N.length){const R=N.filter((W,D)=>{if(D%I!==I-1)return!0}).slice(-2);e.set(k,{workState:E===0?s.EvevtWorkState.Start:v===((g=S.animationWorkData)==null?void 0:g.length)?s.EvevtWorkState.Done:s.EvevtWorkState.Doing,op:R})}}else S.ops&&((M=S.node)==null||M.consumeService({op:S.animationWorkData||[],isFullWork:!0,replaceId:T}),S.isDel=!0,e.set(k,{workState:s.EvevtWorkState.Done,op:N.filter((R,W)=>{if(W%I!==I-1)return!0}).slice(-2)}));a=!0;break}break}}if(a&&this.runAnimation(),e.size){const k=[];e.forEach((S,I)=>{k.push({type:s.EPostMessageType.Cursor,uid:I.split(s.Storage_Splitter)[0],op:S.op,workState:S.workState,viewId:this.thread.viewId})}),this.thread.post({sp:k})}}runAnimation(){this.animationId||(this.animationId=requestAnimationFrame(this.animationDraw.bind(this)))}hasDiffData(a,e,t){const o=a.length;if(e.length<o)return!0;switch(t){case s.EToolsKey.Pencil:{for(let i=0;i<o;i+=3)if(e[i]!==a[i]||e[i+1]!==a[i+1])return!0;break}case s.EToolsKey.LaserPen:{for(let i=0;i<o;i+=2)if(e[i]!==a[i]||e[i+1]!==a[i+1])return!0;break}}return!1}activeWorkShape(a){var f,u,y,w;const{workId:e,opt:t,toolsType:o,type:i,updateNodeOpt:r,ops:n,op:c,useAnimation:l}=a;if(!e)return;const h=e.toString(),p=(f=this.vNodes.get(h))==null?void 0:f.rect;if(!((u=this.workShapes)!=null&&u.has(h))){let g={toolsType:o,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};o&&t&&(g=this.setNodeKey(h,g,o,t)),(y=this.workShapes)==null||y.set(h,g)}const d=(w=this.workShapes)==null?void 0:w.get(h);i&&(d.type=i),n&&(d.animationWorkData=s.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),o&&t&&(t.syncUnitTime&&(this.syncUnitTime=t.syncUnitTime),d.toolsType!==o&&o&&t&&this.setNodeKey(h,d,o,t),d.node&&d.node.setWorkOptions(t))}removeNode(a,e){a.indexOf(s.Storage_Selector_key)>-1&&this.removeSelectWork(e),this.thread.fullLayer.getElementsByName(a).forEach(t=>{t.remove()}),this.thread.serviceLayer.getElementsByName(a).forEach(t=>{t.remove()}),this.vNodes.delete(a)}removeSelectWork(a){const{workId:e}=a,t=e==null?void 0:e.toString();t&&(this.activeSelectorShape(a),this.willRunEffectSelectorIds.add(t)),this.runEffect()}activeSelectorShape(a){var l,h,p;const{workId:e,opt:t,toolsType:o,type:i,selectIds:r}=a;if(!e)return;const n=e.toString();if(!((l=this.selectorWorkShapes)!=null&&l.has(n))){let d={toolsType:o,selectIds:r,type:i,opt:t};o&&t&&(d=this.setNodeKey(n,d,o,t)),(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,e,t,o){return e.toolsType=t,e.node=ne({toolsType:t,toolsOpt:o,vNodes:this.vNodes,fullLayer:this.thread.fullLayer,drawLayer:this.thread.serviceLayer,workId:a},this),e}}class U{constructor(){m(this,"localWork");m(this,"serviceWork");m(this,"scene")}registerMainThread(a,e,t){return this.localWork=a,this.serviceWork=e,this.scene=t,this}}class Fe extends U{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.CopyNode)}async consume(e){const{msgType:t,dataType:o,emitEventType:i}=e;if(t===s.EPostMessageType.FullWork&&o===s.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(e),!0}async consumeForLocalWorker(e){var o;const{workId:t}=e;t&&await((o=this.localWork)==null?void 0:o.consumeFull(e,this.scene))}}class ze extends U{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.SetColorNode)}async consume(e){const{msgType:t,dataType:o,emitEventType:i}=e;if(t===s.EPostMessageType.UpdateNode&&o===s.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(e),!0}async consumeForLocalWorker(e){var l;const{workId:t,updateNodeOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c}=e;t===z.selectorId&&o&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i}=e,{willSyncService:r,isSync:n,textUpdateForWoker:c}=t,l=o.sp||[];if(r)for(const[h,p]of i.entries())c&&p.toolsType===s.EToolsKey.Text?l.push({...p,workId:h,type:s.EPostMessageType.TextUpdate,dataType:s.EDataType.Local,willSyncService:!0}):l.push({...p,workId:h,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:n});return{sp:l}}}class Ve extends U{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.ZIndexNode)}async consume(e){const{msgType:t,dataType:o,emitEventType:i}=e;if(t===s.EPostMessageType.UpdateNode&&o===s.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(e),!0}async consumeForLocalWorker(e){var c;const{workId:t,updateNodeOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n}=e;t===z.selectorId&&o&&await((c=this.localWork)==null?void 0:c.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i}=e,{willSyncService:r,isSync:n}=t,c=o.sp||[];if(r&&c)for(const[l,h]of i.entries())c.push({...h,workId:l,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:n});return{sp:c}}}class Ke extends U{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.TranslateNode)}async consume(e){const{msgType:t,dataType:o,emitEventType:i}=e;if(t===s.EPostMessageType.UpdateNode&&o===s.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(e),!0}async consumeForLocalWorker(e){var h,p;const{workId:t,updateNodeOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c,emitEventType:l}=e;t===z.selectorId&&o&&(o.workState===s.EvevtWorkState.Done&&(o!=null&&o.translate)&&(o.translate[0]||o.translate[1])||o.workState!==s.EvevtWorkState.Done?await((h=this.localWork)==null?void 0:h.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,isSync:!0,textUpdateForWoker:c,emitEventType:l,scene:this.scene,callback:this.updateSelectorCallback})):o.workState===s.EvevtWorkState.Done&&((p=this.localWork)==null||p.vNodes.deleteLastTarget()))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i,workShapeNode:r,res:n}=e,{willSyncService:c,isSync:l,updateSelectorOpt:h,textUpdateForWoker:p}=t,d=h.workState,f=o.sp||[];if(d===s.EvevtWorkState.Start)return{sp:[],render:[]};const u=n==null?void 0:n.selectRect;if(c){d===s.EvevtWorkState.Doing&&f.push({type:s.EPostMessageType.Select,selectIds:r.selectIds,selectRect:u,willSyncService:!0,isSync:!0,points:r.getChildrenPoints(),textOpt:r.textOpt});for(const[y,w]of i.entries())p&&w.toolsType===s.EToolsKey.Text?f.push({...w,workId:y,type:s.EPostMessageType.TextUpdate,dataType:s.EDataType.Local,willSyncService:!0}):f.push({...w,workId:y,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l})}return{sp:f}}}class Ue extends U{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.DeleteNode)}async consume(){return!1}}class Xe extends U{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.ScaleNode)}async consume(e){const{msgType:t,dataType:o,emitEventType:i}=e;if(t===s.EPostMessageType.UpdateNode&&o===s.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(e),!0}async consumeForLocalWorker(e){var n;const{workId:t,updateNodeOpt:o,willSyncService:i,willSerializeData:r}=e;t===z.selectorId&&o&&await((n=this.localWork)==null?void 0:n.updateSelector({updateSelectorOpt:o,willSyncService:i,willSerializeData:r,isSync:!0,scene:this.scene,callback:this.updateSelectorCallback.bind(this)}))}updateSelectorCallback(e){const{param:t,postData:o,workShapeNode:i,res:r,newServiceStore:n}=e,{updateSelectorOpt:c,willSyncService:l,willSerializeData:h}=t,p=c.workState,d=o.sp||[],f=r==null?void 0:r.selectRect;if(p===s.EvevtWorkState.Start)return{sp:[],render:[]};if(l){p===s.EvevtWorkState.Doing&&d.push({type:s.EPostMessageType.Select,selectIds:i.selectIds,selectRect:f,willSyncService:!0,isSync:!0,points:i.getChildrenPoints(),textOpt:i.textOpt}),h&&p===s.EvevtWorkState.Done&&d.push({type:s.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===s.EToolsKey.Text?d.push({...y,workId:u,type:s.EPostMessageType.TextUpdate,dataType:s.EDataType.Local,willSyncService:!0}):d.push({...y,workId:u,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:!0})}return{sp:d}}}class Ye extends U{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.RotateNode)}async consume(e){const{msgType:t,dataType:o,emitEventType:i}=e;if(t===s.EPostMessageType.UpdateNode&&o===s.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(e),!0}async consumeForLocalWorker(e){var l;const{workId:t,updateNodeOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,emitEventType:c}=e;t===z.selectorId&&o&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,emitEventType:c,isSync:!0,scene:this.scene,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,workShapeNode:i,res:r,newServiceStore:n}=e,{updateSelectorOpt:c,willSyncService:l,willSerializeData:h,isSync:p}=t,d=c.workState,f=o.sp||[],u=r==null?void 0:r.selectRect;if(l){h&&d===s.EvevtWorkState.Done&&f.push({type:s.EPostMessageType.Select,selectIds:i.selectIds,selectRect:u,willSyncService:!0,isSync:p,points:i.getChildrenPoints()});for(const[y,w]of n.entries())f.push({...w,workId:y,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:p})}return{sp:f}}}class _e extends U{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.SetFontStyle)}async consume(e){const{msgType:t,dataType:o,emitEventType:i}=e;if(t===s.EPostMessageType.UpdateNode&&o===s.EDataType.Local&&i===this.emitEventType)return await this.consumeForLocalWorker(e),!0}async consumeForLocalWorker(e){var l;const{workId:t,updateNodeOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c}=e;t===z.selectorId&&o&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i,workShapeNode:r,res:n}=e,{willSyncService:c,isSync:l,updateSelectorOpt:h,textUpdateForWoker:p}=t,d=o.sp||[],f=n==null?void 0:n.selectRect;if(c&&d){h.fontSize&&d.push({type:s.EPostMessageType.Select,selectIds:r.selectIds,selectRect:f,willSyncService:c,isSync:l,points:r.getChildrenPoints()});for(const[u,y]of i.entries())p&&y.toolsType===s.EToolsKey.Text?d.push({...y,workId:u,type:s.EPostMessageType.TextUpdate,dataType:s.EDataType.Local,willSyncService:!0}):d.push({...y,workId:u,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l})}return{sp:d}}}class $e extends U{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.SetPoint)}async consume(e){const{msgType:t,dataType:o,emitEventType:i}=e;if(t===s.EPostMessageType.UpdateNode&&o===s.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(e),!0}async consumeForLocalWorker(e){var l;const{workId:t,updateNodeOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,textUpdateForWoker:c}=e;t===z.selectorId&&o&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,emitEventType:this.emitEventType,willSerializeData:n,isSync:!0,textUpdateForWoker:c,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i,workShapeNode:r,res:n}=e,{willSyncService:c,isSync:l}=t,h=o.sp||[],p=n==null?void 0:n.selectRect;if(c&&h){for(const[d,f]of i.entries())h.push({...f,workId:d,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l});h.push({type:s.EPostMessageType.Select,selectIds:r.selectIds,selectRect:p,willSyncService:c,isSync:l,points:r.getChildrenPoints()})}return{sp:h}}}class Ge extends U{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.SetLock)}async consume(e){const{msgType:t,dataType:o,emitEventType:i}=e;if(t===s.EPostMessageType.UpdateNode&&o===s.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(e),!0}async consumeForLocalWorker(e){var c;const{workId:t,updateNodeOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n}=e;t===z.selectorId&&o&&await((c=this.localWork)==null?void 0:c.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i,workShapeNode:r,res:n}=e,{willSyncService:c,isSync:l,updateSelectorOpt:h}=t,p=o.sp||[],d=n==null?void 0:n.selectRect;if(c&&p){for(const[f,u]of i.entries())p.push({...u,workId:f,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l});p.push({isLocked:h.isLocked,selectorColor:r.selectorColor,scaleType:r.scaleType,canRotate:r.canRotate,type:s.EPostMessageType.Select,selectIds:r.selectIds,selectRect:d,willSyncService:c,isSync:l})}return{sp:p}}}class He extends U{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.SetShapeOpt)}async consume(e){const{msgType:t,dataType:o,emitEventType:i}=e;if(t===s.EPostMessageType.UpdateNode&&o===s.EDataType.Local&&i===this.emitEventType)return this.consumeForLocalWorker(e),!0}async consumeForLocalWorker(e){var c;const{workId:t,updateNodeOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n}=e;t===z.selectorId&&o&&await((c=this.localWork)==null?void 0:c.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:n,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i}=e,{willSyncService:r,isSync:n}=t,c=o.sp||[];if(r&&c)for(const[l,h]of i.entries())c.push({...h,workId:l,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:n});return{sp:c}}}class qe{constructor(a){m(this,"builders",new Map);this.builders=new Map(a.map(e=>[e,this.build(e)]))}build(a){switch(a){case s.EmitEventType.TranslateNode:return new Ke;case s.EmitEventType.ZIndexNode:return new Ve;case s.EmitEventType.CopyNode:return new Fe;case s.EmitEventType.SetColorNode:return new ze;case s.EmitEventType.DeleteNode:return new Ue;case s.EmitEventType.ScaleNode:return new Xe;case s.EmitEventType.RotateNode:return new Ye;case s.EmitEventType.SetFontStyle:return new _e;case s.EmitEventType.SetPoint:return new $e;case s.EmitEventType.SetLock:return new Ge;case s.EmitEventType.SetShapeOpt:return new He}}registerForMainThread(a,e,t){return this.builders.forEach(o=>{o&&o.registerMainThread(a,e,t)}),this}async consumeForMainThread(a){for(const e of this.builders.values())if(await(e==null?void 0:e.consume(a)))return!0;return!1}}class je{constructor(a,e){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,"taskUpdateCameraId");m(this,"debounceUpdateCameraId");m(this,"debounceUpdateCache",new Set);m(this,"mainThreadPostId");m(this,"combinePostMsg",new Set);m(this,"methodBuilder");this.viewId=a,this.opt=e,this.scene=this.createScene({...e.canvasOpt,container:e.container}),this.master=e.master;const t=s.DefaultAppliancePluginOptions.bufferSize.full,o=s.DefaultAppliancePluginOptions.bufferSize.sub;this.fullLayer=this.createLayer("fullLayer",this.scene,{...e.layerOpt,bufferSize:this.viewId===s.Main_View_Id?t:o}),this.topLayer=this.createLayer("topLayer",this.scene,{...e.layerOpt,bufferSize:(this.viewId===s.Main_View_Id,o)}),this.localLayer=this.createLayer("localLayer",this.scene,{...e.layerOpt,bufferSize:(this.viewId===s.Main_View_Id,o)}),this.serviceLayer=this.createLayer("serviceLayer",this.scene,{...e.layerOpt,bufferSize:(this.viewId===s.Main_View_Id,o)}),this.vNodes=new De(a,this.scene);const i={thread:this,vNodes:this.vNodes};this.localWork=new Ae(i),this.serviceWork=new Be(i),this.topWork=new Oe(i),this.vNodes.init(this.fullLayer),this.methodBuilder=new qe([s.EmitEventType.CopyNode,s.EmitEventType.SetColorNode,s.EmitEventType.DeleteNode,s.EmitEventType.RotateNode,s.EmitEventType.ScaleNode,s.EmitEventType.TranslateNode,s.EmitEventType.ZIndexNode,s.EmitEventType.SetFontStyle,s.EmitEventType.SetPoint,s.EmitEventType.SetLock,s.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:e,toolsType:t,opt:o,dataType:i,workId:r,workState:n}=a,c=r==null?void 0:r.toString();switch(e){case s.EPostMessageType.Destroy:this.destroy();break;case s.EPostMessageType.Clear:this.clearAll();break;case s.EPostMessageType.UpdateCamera:await this.updateCamera(a);break;case s.EPostMessageType.UpdateTools:if(t&&o){const l={toolsType:t,toolsOpt:o};this.topWork.canUseTopLayer(t)?this.topWork.setToolsOpt(l):this.localWork.setToolsOpt(l)}break;case s.EPostMessageType.CreateWork:if(c&&o&&t){if(this.topWork.canUseTopLayer(t)){this.topWork.getToolsOpt()||this.topWork.setToolsOpt({toolsType:t,toolsOpt:o}),this.topWork.setWorkOptions(c,o);break}this.localWork.getToolsOpt()||this.localWork.setToolsOpt({toolsType:t,toolsOpt:o}),this.localWork.setWorkOptions(c,o)}break;case s.EPostMessageType.DrawWork:n===s.EvevtWorkState.Done&&i===s.EDataType.Local?this.consumeDrawAll(i,a):this.consumeDraw(i,a);break;case s.EPostMessageType.UpdateNode:case s.EPostMessageType.FullWork:if(t&&this.topWork.canUseTopLayer(t)){this.consumeDrawAll(i,a);break}this.consumeFull(i,a);break;case s.EPostMessageType.RemoveNode:await this.removeNode(a);return;case s.EPostMessageType.Select:i===s.EDataType.Service&&(r===s.Storage_Selector_key?this.localWork.updateFullSelectWork(a):this.serviceWork.runSelectWork(a));break;case s.EPostMessageType.CursorHover:this.localWork.cursorHover(a);break;case s.EPostMessageType.GetTextActive:i===s.EDataType.Local&&this.localWork.checkTextActive(a);break}}}async removeNode(a){const{dataType:e,workId:t,removeIds:o}=a,i=o||[];if(t&&i.push(t.toString()),i.length)for(const r of i){if(r===s.Storage_Selector_key){await this.localWork.removeSelector(a);continue}e===s.EDataType.Local?this.localWork.removeWork(a):e===s.EDataType.Service&&this.serviceWork.removeWork(a),await this.localWork.colloctEffectSelectWork(a)}}async consumeFull(a,e){const t=await this.localWork.colloctEffectSelectWork(e);t&&a===s.EDataType.Local&&await this.localWork.consumeFull(t,this.scene),t&&a===s.EDataType.Service&&this.serviceWork.consumeFull(t)}setCameraOpt(a){this.cameraOpt=a;const{scale:e,centerX:t,centerY:o,width:i,height:r}=a;(i!==this.scene.width||r!==this.scene.height)&&this.updateScene({width:i,height:r}),this.fullLayer.setAttribute("scale",[e,e]),this.fullLayer.setAttribute("translate",[-t,-o]),this.topLayer.setAttribute("scale",[e,e]),this.topLayer.setAttribute("translate",[-t,-o]),this.localLayer.setAttribute("scale",[e,e]),this.localLayer.setAttribute("translate",[-t,-o]),this.serviceLayer.setAttribute("scale",[e,e]),this.serviceLayer.setAttribute("translate",[-t,-o])}runBatchPostData(){this.mainThreadPostId||(this.mainThreadPostId=requestAnimationFrame(this.combinePost.bind(this)))}combinePostData(){var t;this.mainThreadPostId=void 0;const a=[];let e;for(const o of this.combinePostMsg.values()){if((t=o.sp)!=null&&t.length)for(const i of o.sp){let r=!1;for(const n of a)if(H.isEqual(i,n)){r=!0;break}r||a.push(i)}H.isNumber(o.drawCount)&&(e=o.drawCount)}return this.combinePostMsg.clear(),{sp:a,drawCount:e}}combinePost(){var t,o;const a=this.combinePostData(),e=(t=a.sp)==null?void 0:t.filter(i=>i.type!==s.EPostMessageType.None);e!=null&&e.length?a.sp=e.map(i=>i.viewId?i:{...i,viewId:this.viewId}):delete a.sp,a.drawCount===void 0&&delete a.drawCount,(a!=null&&a.drawCount||(o=a.sp)!=null&&o.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:s.EPostMessageType.Clear}]})}consumeDrawAll(a,e){const{toolsType:t,workId:o}=e;if(o){const i=o.toString();if(t&&this.topWork.canUseTopLayer(t)){a===s.EDataType.Local&&(this.topWork.getLocalWorkShape(o.toString())||this.topWork.createLocalWork(e)),this.topWork.consumeDrawAll(e);return}a===s.EDataType.Local&&(this.localWork.getWorkShape(i)||this.localWork.createLocalWork(e),this.localWork.consumeDrawAll(e,this.serviceWork))}}consumeDraw(a,e){const{opt:t,workId:o,toolsType:i}=e;if(o&&i&&t){const r=o.toString();if(this.topWork.canUseTopLayer(i)){a===s.EDataType.Local&&(this.topWork.getLocalWorkShape(r)||this.topWork.createLocalWork(e)),this.topWork.consumeDraw(e);return}a===s.EDataType.Local?(this.localWork.getWorkShape(r)||this.localWork.createLocalWork(e),this.localWork.consumeDraw(e,this.serviceWork)):a===s.EDataType.Service&&this.serviceWork.consumeDraw(e);return}}async updateCamera(a){var o;const{cameraOpt:e,scenePath:t}=a;if(e&&!H.isEqual(this.cameraOpt,e)){if(this.taskUpdateCameraId&&(clearTimeout(this.taskUpdateCameraId),this.taskUpdateCameraId=void 0),t){let l=!1;for(const[h,p]of this.localWork.getWorkShapes().entries())if(p.toolsType!==s.EToolsKey.Text&&p.toolsType!==s.EToolsKey.Eraser&&p.toolsType!==s.EToolsKey.Selector&&p.toolsType!==s.EToolsKey.LaserPen&&h!==s.Cursor_Hover_Id&&h!==s.Storage_Selector_key){l=!0;break}if(l){this.taskUpdateCameraId=setTimeout(()=>{this.taskUpdateCameraId=void 0,this.updateCamera(a)},s.Task_Time_Interval);return}}const i=new Map;for(const[l,h]of this.vNodes.getNodesByType(s.EToolsKey.Text).entries()){const p=h.rect;i.set(l,H.cloneDeep(p))}const r=new Set(i.keys());let n=!1;if(this.localWork.hasSelector()){const l=(o=this.localWork.getSelector())==null?void 0:o.selectIds;if(l){n=!0;for(const h of l)r.add(h)}}let c=!1;if(this.serviceWork.selectorWorkShapes.size)for(const l of this.serviceWork.selectorWorkShapes.values()){const h=l.selectIds;if(h){c=!0;for(const p of h)r.add(p)}}if(this.setCameraOpt(e),this.vNodes.curNodeMap.size){this.vNodes.clearTarget(),this.vNodes.updateHighLevelNodesRect(r),this.debounceUpdateCameraId&&clearTimeout(this.debounceUpdateCameraId);for(const[l,h]of i.entries()){const p=this.vNodes.get(l);if(p){const d=h,f=p.rect,u=this.getSceneRect(),y=s.getRectMatrixrRelation(d,u),w=s.getRectMatrixrRelation(f,u);let g=!1;if((y!==w||d.w!==f.w||d.h!==f.h||w===s.EMatrixrRelationType.intersect)&&(g=!0),g){const{toolsType:M,opt:k}=p;M===s.EToolsKey.Text&&k.workState===s.EvevtWorkState.Done&&this.debounceUpdateCache.add(l)}}}if(n&&this.localWork.reRenderSelector(),c)for(const[l,h]of this.serviceWork.selectorWorkShapes.entries())this.serviceWork.runSelectWork({workId:l,selectIds:h.selectIds,msgType:s.EPostMessageType.Select,dataType:s.EDataType.Service,viewId:this.viewId});this.debounceUpdateCameraId=setTimeout(()=>{var h;this.debounceUpdateCameraId=void 0;const l=[];for(const p of this.debounceUpdateCache.values()){if((h=this.fullLayer)==null?void 0:h.getElementsByName(p)[0]){const f=this.vNodes.get(p);if(f){const{toolsType:u,opt:y,rect:w}=f,g=this.localWork.setFullWork({toolsType:u,opt:y,workId:p});if(g){const M=this.getSceneRect(),k=s.getRectMatrixrRelation(w,M);l.push(g.consumeServiceAsync({isFullWork:!0,replaceId:p,isDrawLabel:k!==s.EMatrixrRelationType.outside}))}}}this.debounceUpdateCache.delete(p)}this.vNodes.updateLowLevelNodesRect(),this.vNodes.clearHighLevelIds()},s.Task_Time_Interval)}}}getSceneRect(){const{width:a,height:e}=this.scene;return{x:0,y:0,w:Math.floor(a),h:Math.floor(e)}}createScene(a){return new b.Scene({displayRatio:this.opt.displayer.dpr,depth:!1,desynchronized:!0,...a,autoRender:!0,id:this.viewId})}createLayer(a,e,t){const{width:o,height:i}=t,r=`canvas-${a}`,n=e.layer(r,{...t,offscreen:!1}),c=new b.Group({anchor:[.5,.5],pos:[o*.5,i*.5],size:[o,i],name:"viewport",id:a});return n.append(c),c}updateScene(a){this.scene.attr({...a});const{width:e,height:t}=a;this.scene.width=e,this.scene.height=t,this.updateLayer({width:e,height:t})}updateLayer(a){const{width:e,height:t}=a;this.fullLayer.parent.setAttribute("width",e),this.fullLayer.parent.setAttribute("height",t),this.fullLayer.setAttribute("size",[e,t]),this.fullLayer.setAttribute("pos",[e*.5,t*.5]),this.topLayer.parent.setAttribute("width",e),this.topLayer.parent.setAttribute("height",t),this.topLayer.setAttribute("size",[e,t]),this.topLayer.setAttribute("pos",[e*.5,t*.5]),this.localLayer.parent.setAttribute("width",e),this.localLayer.parent.setAttribute("height",t),this.localLayer.setAttribute("size",[e,t]),this.localLayer.setAttribute("pos",[e*.5,t*.5]),this.serviceLayer.parent.setAttribute("width",e),this.serviceLayer.parent.setAttribute("height",t),this.serviceLayer.setAttribute("size",[e,t]),this.serviceLayer.setAttribute("pos",[e*.5,t*.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 Ze{constructor(a,e){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=e,this.scene=this.createScene({...e.canvasOpt,container:e.container}),this.master=e.master,this.fullLayer=this.createLayer("fullLayer",this.scene,{...e.layerOpt,bufferSize:this.viewId===s.Main_View_Id?6e3:3e3})}post(a){this.combinePostMsg.add(a),this.runBatchPostData()}async on(a){const{msgType:e}=a;switch(e){case s.EPostMessageType.Snapshot:await this.getSnapshot(a),this.destroy();return;case s.EPostMessageType.BoundingBox:await this.getBoundingRect(a),this.destroy();return}}createWorkShapeNode(a){return ne({...a,fullLayer:this.fullLayer,drawLayer:void 0})}setFullWork(a){const{workId:e,opt:t,toolsType:o}=a;if(e&&t&&o){const i=e.toString();let r;return e&&this.workShapes.has(i)?(r=this.workShapes.get(i),r==null||r.setWorkOptions(t)):r=this.createWorkShapeNode({toolsOpt:t,toolsType:o,workId:i}),r?(this.workShapes.set(i,r),r):void 0}}async runFullWork(a){var o,i;const e=this.setFullWork(a),t=a.ops&&s.transformToNormalData(a.ops);if(e){let r,n;const c=(o=e.getWorkId())==null?void 0:o.toString();return e.toolsType===s.EToolsKey.Image?r=await e.consumeServiceAsync({isFullWork:!0,scene:(i=this.fullLayer.parent)==null?void 0:i.parent,isMainThread:!0}):e.toolsType===s.EToolsKey.Text?r=await e.consumeServiceAsync({isFullWork:!0,replaceId:c,isDrawLabel:!0}):(r=e.consumeService({op:t,isFullWork:!0,replaceId:c}),n=(a==null?void 0:a.updateNodeOpt)&&e.updataOptService(a.updateNodeOpt)),s.computRect(r,n)}}async getSnapshot(a){const{scenePath:e,scenes:t,cameraOpt:o,w:i,h:r}=a;if(e&&t&&o){this.setCameraOpt(o);let n;for(const[l,h]of Object.entries(t))if(h!=null&&h.type)switch(h==null?void 0:h.type){case s.EPostMessageType.UpdateNode:case s.EPostMessageType.FullWork:{const{opt:p}=h,d=await this.runFullWork({...h,opt:p,workId:l,msgType:s.EPostMessageType.FullWork,dataType:s.EDataType.Service,viewId:this.viewId});n=s.computRect(n,d);break}}let c;i&&r&&(c={resizeWidth:i,resizeHeight:r}),await this.getSnapshotRender({scenePath:e,options:c})}}getSceneRect(){const{width:a,height:e}=this.scene;return{x:0,y:0,w:Math.floor(a),h:Math.floor(e)}}getRectImageBitmap(a,e){const t=Math.floor(a.x*this.opt.displayer.dpr),o=Math.floor(a.y*this.opt.displayer.dpr),i=a.w>0&&Math.floor(a.w*this.opt.displayer.dpr||1)||1,r=a.h>0&&Math.floor(a.h*this.opt.displayer.dpr||1)||1;return createImageBitmap(this.fullLayer.parent.canvas,t,o,i,r,e)}async getSnapshotRender(a){var i,r;const{scenePath:e,options:t}=a;((i=this.fullLayer)==null?void 0:i.parent).render();const o=await this.getRectImageBitmap(this.getSceneRect(),t);o&&(this.post({sp:[{type:s.EPostMessageType.Snapshot,scenePath:e,imageBitmap:o,viewId:this.viewId}]}),(r=this.fullLayer)==null||r.removeAllChildren())}async getBoundingRect(a){const{scenePath:e,scenes:t,cameraOpt:o}=a;if(e&&t&&o){this.setCameraOpt(o);let i;for(const[r,n]of Object.entries(t))if(n!=null&&n.type)switch(n==null?void 0:n.type){case s.EPostMessageType.UpdateNode:case s.EPostMessageType.FullWork:{const c=await this.runFullWork({...n,workId:r,msgType:s.EPostMessageType.FullWork,dataType:s.EDataType.Service,viewId:this.viewId});i=s.computRect(i,c);break}}i&&this.post({sp:[{type:s.EPostMessageType.BoundingBox,scenePath:e,rect:i}]})}}setCameraOpt(a){const{scale:e,centerX:t,centerY:o,width:i,height:r}=a;this.updateScene({width:i,height:r}),this.fullLayer.setAttribute("scale",[e,e]),this.fullLayer.setAttribute("translate",[-t,-o])}runBatchPostData(){this.mainThreadPostId||(this.mainThreadPostId=requestAnimationFrame(this.combinePost.bind(this)))}combinePostData(){var e;this.mainThreadPostId=void 0;const a=[];for(const t of this.combinePostMsg.values())if((e=t.sp)!=null&&e.length)for(const o of t.sp){let i=!1;for(const r of a)if(s.isEqual(o,r)){i=!0;break}i||a.push(o)}return this.combinePostMsg.clear(),{sp:a}}combinePost(){var t,o;const a=this.combinePostData(),e=(t=a.sp)==null?void 0:t.filter(i=>i.type!==s.EPostMessageType.None);e!=null&&e.length?a.sp=e.map(i=>i.viewId?i:{...i,viewId:this.viewId}):delete a.sp,(a!=null&&a.drawCount||(o=a.sp)!=null&&o.length)&&this.opt.post(a)}createScene(a){return new b.Scene({displayRatio:this.opt.displayer.dpr,depth:!1,desynchronized:!0,...a,autoRender:!1})}createLayer(a,e,t){const{width:o,height:i}=t,r=`canvas-${a}`,n=e.layer(r,t),c=new b.Group({anchor:[.5,.5],pos:[o*.5,i*.5],size:[o,i],name:"viewport",id:a});return n.append(c),c}updateScene(a){this.scene.attr({...a});const{width:e,height:t}=a;this.scene.width=e,this.scene.height=t,this.updateLayer({width:e,height:t})}updateLayer(a){const{width:e,height:t}=a;this.fullLayer.parent.setAttribute("width",e),this.fullLayer.parent.setAttribute("height",t),this.fullLayer.setAttribute("size",[e,t]),this.fullLayer.setAttribute("pos",[e*.5,t*.5])}destroy(){this.fullLayer.remove(),this.scene.remove()}}class Je{constructor(a){m(this,"mainThreadMap",new Map);m(this,"snapshotThread");m(this,"master");this.master=a}post(a){const{drawCount:e,sp:t,workerTasksqueueCount:o}=a;this.master.isBusy&&K(o)&&this.master.setWorkerTasksqueueCount(o),K(e)&&this.master.setMaxDrawCount(e),t&&this.master.collectorSyncData(t)}destroy(){this.mainThreadMap.clear()}createMainThread(a,e){return new je(a,e)}createSnapshotThread(a,e){return new Ze(a,e)}async consume(a){var e,t,o,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===s.EPostMessageType.Console){console.log(this);continue}if(n===s.EPostMessageType.Init){const y=(e=this.master.control.viewContainerManager.getView(c))==null?void 0:e.displayer,w=y==null?void 0:y.canvasContainerRef.current;if(y&&w&&p&&d){const g=this.createMainThread(c,{displayer:y,container:w,layerOpt:p,master:this.master,canvasOpt:d,post:this.post.bind(this)});this.mainThreadMap.set(c,g),g&&f&&g.setCameraOpt(f)}continue}if((n===s.EPostMessageType.Snapshot||n===s.EPostMessageType.BoundingBox)&&c===((t=this.master.control.viewContainerManager.mainView)==null?void 0:t.id)){const y=(o=this.master.control.viewContainerManager.getView(c))==null?void 0:o.displayer,w=(i=y.snapshotContainerRef)==null?void 0:i.current;if(y&&w&&f){w.style.width=`${f.width}px`,w.style.height=`${f.height}px`;const g={...s.ViewContainerManager.defaultLayerOpt,offscreen:!1,width:f.width,height:f.height},M={...s.ViewContainerManager.defaultScreenCanvasOpt,width:f.width,height:f.height};this.snapshotThread=this.createSnapshotThread(c,{displayer:y,container:w,layerOpt:g,master:this.master,canvasOpt:M,post:this.post.bind(this)}),this.snapshotThread.on(r).then(()=>{this.snapshotThread=void 0,w.innerHTML="",w.style.width="",w.style.height=""});continue}}if(n===s.EPostMessageType.TasksQueue&&(l!=null&&l.size)){for(const[y,w]of this.mainThreadMap.entries()){const g=l.get(y);g&&(await w.on(g),h&&this.post({workerTasksqueueCount:h}))}continue}if(c===s.Storage_ViewId_ALL){for(const y of this.mainThreadMap.values())y.on(r),n===s.EPostMessageType.Destroy&&this.mainThreadMap.delete(c);continue}const u=this.mainThreadMap.get(c);u&&(u.on(r),n===s.EPostMessageType.Destroy&&this.mainThreadMap.delete(c))}}}exports.MainThreadManagerImpl=Je;