@netless/appliance-plugin 1.0.6 → 1.0.7

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 (45) hide show
  1. package/cdn/cdn.js +1 -1
  2. package/cdn/fullWorker-CF7R0e.js +438 -0
  3. package/cdn/subWorker-BbF9q2.js +438 -0
  4. package/dist/appliance-plugin.js +1 -1
  5. package/dist/appliance-plugin.mjs +7 -7
  6. package/dist/core/enum.d.ts +22 -16
  7. package/dist/core/mainEngine.d.ts +9 -2
  8. package/dist/core/mainThread/snapshotThread.d.ts +1 -1
  9. package/dist/core/mainThread/subLocalThread.d.ts +2 -1
  10. package/dist/core/mainThread/subTopThread.d.ts +2 -2
  11. package/dist/core/mainThread/workerMainThread.d.ts +99 -0
  12. package/dist/core/tools/eraser.d.ts +1 -20
  13. package/dist/core/tools/pencilEraser.d.ts +76 -0
  14. package/dist/core/tools/utils.d.ts +6 -5
  15. package/dist/core/types.d.ts +1 -0
  16. package/dist/core/utils/math.d.ts +3 -0
  17. package/dist/core/vNodeManager.d.ts +1 -0
  18. package/dist/core/worker/base.d.ts +5 -2
  19. package/dist/core/worker/fullWorkerLocal.d.ts +2 -0
  20. package/dist/core/worker/subWorkerLocal.d.ts +3 -2
  21. package/dist/core/worker/subWorkerTopLayer.d.ts +2 -2
  22. package/dist/core/worker/workerManager.d.ts +1 -0
  23. package/dist/fullWorker.js +125 -124
  24. package/dist/index-2kLI3OsH.js +1 -0
  25. package/dist/index-C7xQ-iwn.mjs +2304 -0
  26. package/dist/index-DWP99OFK.mjs +13721 -0
  27. package/dist/index-OwNIkbKl.js +1 -0
  28. package/dist/plugin/baseApplianceManager.d.ts +5 -3
  29. package/dist/plugin/baseViewContainerManager.d.ts +4 -1
  30. package/dist/plugin/displayerView.d.ts +1 -0
  31. package/dist/plugin/multi/containerManager.d.ts +2 -0
  32. package/dist/plugin/multi/displayer/appViewDisplayerManager.d.ts +1 -0
  33. package/dist/plugin/multi/displayer/mainViewDisplayerManager.d.ts +1 -0
  34. package/dist/plugin/single/containerManager.d.ts +2 -0
  35. package/dist/plugin/single/displayer/mainViewDisplayerManager.d.ts +1 -0
  36. package/dist/plugin/types.d.ts +11 -0
  37. package/dist/style.css +1 -1
  38. package/dist/subWorker.js +125 -124
  39. package/package.json +1 -1
  40. package/cdn/fullWorker-B41ROv.js +0 -437
  41. package/cdn/subWorker-D3x__X.js +0 -437
  42. package/dist/index-BUV3AIdR.js +0 -1
  43. package/dist/index-BwY-Y-lK.js +0 -1
  44. package/dist/index-DDd3tlz2.mjs +0 -9770
  45. package/dist/index-D_EDUBFF.mjs +0 -5675
@@ -1 +0,0 @@
1
- "use strict";var Be=Object.defineProperty;var Fe=(k,n,e)=>n in k?Be(k,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):k[n]=e;var m=(k,n,e)=>Fe(k,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index-BUV3AIdR.js"),b=require("spritejs"),ze=require("lineclip");require("lz-string");const q=require("lodash");require("white-web-sdk");require("react-dom");require("react");var Ve=s._baseGetTag,Ke=s.isObjectLike_1,Ue="[object Number]";function _e(k){return typeof k=="number"||Ke(k)&&Ve(k)==Ue}var $e=_e;const z=s.getDefaultExportFromCjs($e),A=class A{constructor(n){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}=n;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(n,e=.01){return n.reduce((t,o)=>{const i=t[t.length-1];return(o&&!i||o&&i&&!o.isNear(i,e))&&t.push(o),t},[])}setWorkId(n){this.workId=n}getWorkId(){return this.workId}getWorkOptions(){return this.workOptions}setWorkOptions(n){var o,i,r;this.workOptions=n,this.syncUnitTime=n.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=n,(r=this.vNodes)==null||r.setInfo(e,t))}updataOptService(n){var o,i;let e;const t=(o=this.workId)==null?void 0:o.toString();if(t&&n){const r=this.fullLayer.getElementsByName(t)||this.drawLayer&&this.drawLayer.getElementsByName(t)||[];if(r.length!==1)return;const a=r[0],{pos:c,zIndex:l,scale:h,angle:p,translate:d}=n,u={};z(l)&&(u.zIndex=l),c&&(u.pos=[c[0],c[1]]),h&&(u.scale=h),p&&(u.rotate=p),d&&(u.translate=d),a.attr(u);const f=a==null?void 0:a.getBoundingClientRect();return f&&(e=s.computRect(e,{x:Math.floor(f.x-A.SafeBorderPadding),y:Math.floor(f.y-A.SafeBorderPadding),w:Math.floor(f.width+A.SafeBorderPadding*2),h:Math.floor(f.height+A.SafeBorderPadding*2)})),(i=this.vNodes)==null||i.setInfo(t,{rect:e,centerPos:c}),e}}replace(n,e,t){var a;const o=n.getElementsByName(e),i=o.length;if(i){if(i>1)for(let c=1;c<o.length;c++)n.removeChild(o[c]),o[c].disconnect();t?n.replaceChild(t,o[0]):n.removeChild(o[0]),o[0].disconnect()}else t&&n.append(t);this.fullLayer===n?(a=this.drawLayer)==null||a.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(n){var M;const{node:e,opt:t,vNodes:o,willSerializeData:i,targetNode:r}=n,{zIndex:a,translate:c,angle:l,originPoint:h,scenePoint:p,scale:d,pointMap:u,thickness:f}=t;let S;const y=r&&s.cloneDeep(r)||o.get(e.name);if(!y)return;z(a)&&(e.setAttribute("zIndex",a),y.opt.zIndex=a);const g=e.parent;if(g){if(h&&d&&r){const v=[y.op[0],y.op[1]];s.scalePoints(y.op,p,d,c);const T=[y.op[0],y.op[1]],w=[T[0]-v[0],T[1]-v[1]];y.centerPos=[y.centerPos[0]+w[0],y.centerPos[1]+w[1]],y.opt.translate=void 0,y.opt.scale=void 0}else if(c)if(e.setAttribute("translate",c),y.opt.translate=c,r){const v=[c[0]*g.worldScaling[0],c[1]*g.worldScaling[1]];S=s.getRectTranslated(y.rect,v),y.rect=S}else{const v=A.getRectFromLayer(g,e.name);y.rect=v||y.rect}else if(z(l))if(e.setAttribute("rotate",l),y.opt.rotate=l,r)S=s.getRectRotated(y.rect,l),y.rect=S;else{const v=A.getRectFromLayer(g,e.name);y.rect=v||y.rect}if(u){const v=u.get(e.name);if(v)for(let T=0,w=0;T<y.op.length;T+=3,w++)y.op[T]=v[w][0],y.op[T+1]=v[w][1]}if(f&&((M=y==null?void 0:y.opt)!=null&&M.thickness)&&(y.opt.thickness=f),i&&!(h&&d&&r)){if(c){const v=y.op.map((T,w)=>{const E=w%3;return E===0?T+c[0]:E===1?T+c[1]:T});y.op=v,y.centerPos=[y.centerPos[0]+c[0],y.centerPos[1]+c[1]],y!=null&&y.opt&&(y.opt.translate=void 0)}else if(z(l)){const v=y.op;s.rotatePoints(v,y.centerPos,l),y.op=v,y!=null&&y.opt&&(y.opt.rotate=void 0)}}y&&o.setInfo(e.name,y)}}static getCenterPos(n,e){const{worldPosition:t,worldScaling:o}=e;return[(n.x+n.w/2-t[0])/o[0],(n.y+n.h/2-t[1])/o[1]]}static getRectFromLayer(n,e){const t=n.getElementsByName(e)[0];if(t){const o=t.getBoundingClientRect();return{x:Math.floor(o.x-A.SafeBorderPadding),y:Math.floor(o.y-A.SafeBorderPadding),w:Math.floor(o.width+A.SafeBorderPadding*2),h:Math.floor(o.height+A.SafeBorderPadding*2)}}}};m(A,"SafeBorderPadding",10);let P=A;function G(k,n=!0){const e=k.length;if(e<2)return"";let t=k[0],o=k[1];if(e===2)return`M${s.precise(t)}L${s.precise(o)}`;let i="";for(let r=2,a=e-1;r<a;r++)t=k[r],o=k[r+1],i+=s.average(t,o);return n?`M${s.average(k[0],k[1])}Q${s.precise(k[1])}${s.average(k[1],k[2])}T${i}${s.average(k[e-1],k[0])}${s.average(k[0],k[1])}Z`:`M${s.precise(k[0])}Q${s.precise(k[1])}${s.average(k[1],k[2])}${k.length>3?"T":""}${i}L${s.precise(k[e-1])}`}class Ee 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 a;const e=(a=this.workId)==null?void 0:a.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:a,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 u={name:l,id:a==null?void 0:a.toString()};let f,S=!1;const y=this.syncIndex;if(this.syncTimestamp===0&&(this.syncTimestamp=Date.now()),h.length&&(h[0].taskId-this.syncTimestamp>this.syncUnitTime&&(S=!0,this.syncTimestamp=h[0].taskId,this.syncIndex=this.tmpPoints.length),i||r)){const M=o?this.fullLayer:this.drawLayer||this.fullLayer;f=this.draw({attrs:u,tasks:h,effects:p,layer:M,replaceId:c})}if(i)return d>10&&this.tmpPoints.splice(0,d-10),{rect:f,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local};const g=[];return this.tmpPoints.slice(y).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:f,op:S?g:void 0,index:S?y*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 a=this.fullLayer;if(o.length&&(r=this.draw({attrs:i,tasks:o,replaceId:t,layer:a})),this.tmpPoints.length<2)return this.replace(a,t),{type:s.EPostMessageType.RemoveNode,removeIds:[t],rect:r};const c=[];this.tmpPoints.map(p=>{c.push(p.x,p.y,p.z)}),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,a)}),{...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 u=new s.Point2d(t[d],t[d+1],t[d+2]);if(this.tmpPoints.length>0){const f=this.tmpPoints[this.tmpPoints.length-1],S=s.Vec2d.Sub(u,f).uni();u.setv(S)}this.tmpPoints.push(u)}if(this.tmpPoints.length<2)return;const r=this.transformDataAll(!0),a=(h=this.workId)==null?void 0:h.toString(),c={name:a};let l;if(a&&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(a,{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:a}=e,{strokeColor:c,strokeType:l,thickness:h,zIndex:p,scale:d,rotate:u,translate:f}=this.workOptions;r!=null&&r.size&&(r.forEach(T=>{var w;(w=a.getElementById(T+""))==null||w.remove()}),r.clear());let S;const y=[],g=a.worldPosition,M=a.worldScaling;for(let T=0;T<o.length;T++){const{pos:w,points:E}=o[T],{ps:R,rect:L}=this.computDrawPoints(E);let I;const N=E.length===1;l===s.EStrokeType.Stroke||N?I=G(R,!0):I=G(R,!1);const W={pos:w,d:I,fillColor:l===s.EStrokeType.Stroke||N?c:void 0,lineDash:l===s.EStrokeType.Dotted&&!N?[1,h*2]:l===s.EStrokeType.LongDotted&&!N?[h,h*2]:void 0,strokeColor:c,lineCap:l===s.EStrokeType.Stroke||N?void 0:"round",lineWidth:l===s.EStrokeType.Stroke||N?0:h};S=s.computRect(S,{x:Math.floor((L.x+w[0])*M[0]+g[0]-P.SafeBorderPadding),y:Math.floor((L.y+w[1])*M[1]+g[1]-P.SafeBorderPadding),w:Math.floor(L.w*M[0]+2*P.SafeBorderPadding),h:Math.floor(L.h*M[1]+2*P.SafeBorderPadding)}),y.push(W)}d&&(t.scale=d),u&&(t.rotate=u),f&&(t.translate=f);const v=new b.Group;if(S){this.centerPos=P.getCenterPos(S,a),v.attr({...t,normalize:!0,anchor:[.5,.5],bgcolor:l===s.EStrokeType.Stroke?c:void 0,pos:this.centerPos,size:[(S.w-2*P.SafeBorderPadding)/M[0],(S.h-2*P.SafeBorderPadding)/M[1]],zIndex:p});const T=y.map(w=>(w.pos=[w.pos[0]-this.centerPos[0],w.pos[1]-this.centerPos[1]],new b.Path(w)));v.append(...T),l===s.EStrokeType.Stroke&&v.seal(),this.replace(a,i||t.workId,v)}if(d||u||f){const T=v==null?void 0:v.getBoundingClientRect();if(T)return{x:Math.floor(T.x-P.SafeBorderPadding),y:Math.floor(T.y-P.SafeBorderPadding),w:Math.floor(T.width+P.SafeBorderPadding*2),h:Math.floor(T.height+P.SafeBorderPadding*2)}}return S}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 u=s.Vec2d.Per(d).mul(p);t.push(s.Point2d.Sub(h,u)),o.push(s.Point2d.Add(h,u))}const i=e[e.length-1],r=s.Point2d.GetSemicircleStroke(i.point,t[t.length-1],-1,8),a=s.Point2d.GetSemicircleStroke(e[0].point,o[0],-1,8),c=t.concat(r,o.reverse(),a);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,a=[];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 a=this.getTaskPoints(p,l),{tasks:a,effects:h,consumeIndex:r}}return{tasks:a,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,a=e[0].y,c=[r,a],l=[],h=e[0].t;for(;i<e.length;){const d=e[i],u=d.x-r,f=d.y-a,S=d.z,y=t?this.computRadius(S,t):S;if(l.push({point:new s.Point2d(u,f,S,e[i].v),radius:y}),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:y}]}),r=e[i].x,a=e[i].y,c=[r,a];const v=d.x-r,T=d.y-a;l=[{point:new s.Point2d(v,T,S),radius:y}],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 a=r;for(let l=0;l<e.length;l+=2){a=Math.min(a,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,u=this.tmpPoints[d],f=s.Vec2d.Sub(p,u).uni();if(p.isNear(u,t)){if(u.z<this.MAX_REPEAR){if(u.setz(Math.min(u.z+1,this.MAX_REPEAR)),a=Math.min(a,d),h>1){let g=h-1;for(;g>0;){const M=this.tmpPoints[g].distance(this.tmpPoints[g-1]),v=Math.max(this.tmpPoints[g].z-this.uniThickness*M,0);if(this.tmpPoints[g-1].z>=v)break;this.tmpPoints[g-1].setz(v),a=Math.min(a,g-1),g--}}}else a=1/0;continue}p.setv(f);const S=p.distance(u),y=Math.max(u.z-this.uniThickness*S,0);h>1&&s.Vec2d.Equals(f,u.v,.02)&&(y>0||u.z<=0)&&(o&&u.t&&o.add(u.t),this.tmpPoints.pop(),a=Math.min(d,a)),p.setz(y),this.tmpPoints.push(p)}if(a===1/0)return this.tmpPoints.length;let c=r;if(a===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=a;l>=0;){const h=this.tmpPoints[l].t;if(h&&(o==null||o.add(h),l<=a)){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 a=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 u=p-1,f=this.tmpPoints[u],S=s.Vec2d.Sub(d,f).uni();if(d.isNear(f,t/2)){a=Math.min(u,a);continue}s.Vec2d.Equals(S,f.v,.02)&&(o&&f.t&&o.add(f.t),this.tmpPoints.pop(),a=Math.min(u,a)),d.setv(S),this.tmpPoints.push(d)}let c=r;if(a===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,a);for(c=a;h>=0;){const p=(l=this.tmpPoints[h])==null?void 0:l.t;if(p&&(o==null||o.add(p),h<=a)){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 a=this.tmpPoints.length,c=new s.Point2d(e[r],e[r+1]);if(a===0){this.tmpPoints.push(c);continue}const l=a-1,h=this.tmpPoints[l],p=s.Vec2d.Sub(c,h).uni(),d=c.distance(h);if(a>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)),a>1)){let f=a-1;for(;f>0;){const S=this.tmpPoints[f].distance(this.tmpPoints[f-1]),y=Math.max(this.tmpPoints[f].z-this.uniThickness*S,-t/4);if(this.tmpPoints[f-1].z>=y)break;this.tmpPoints[f-1].setz(y),f--}}continue}c.setv(p);const u=Math.max(h.z-this.uniThickness*d,i);a>1&&s.Vec2d.Equals(p,h.v,.02)&&h.z<=0&&this.tmpPoints.pop(),c.setz(u),this.tmpPoints.push(c)}}static updateNodeOpt(e){var l,h;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,strokeType:a}=o,c=i.get(t.name);return r&&(t.tagName==="GROUP"?ft(t)?t.setAttribute("bgcolor",r):t.children.forEach(p=>{p.setAttribute("strokeColor",r),p.getAttribute("fillColor")&&p.setAttribute("fillColor",r)}):(t.setAttribute("strokeColor",r),t.setAttribute("fillColor",r)),(l=c==null?void 0:c.opt)!=null&&l.strokeColor&&(c.opt.strokeColor=r)),a&&(c!=null&&c.opt)&&((h=c.opt)!=null&&h.strokeType)&&(c.opt.strokeType=a),c&&i.setInfo(t.name,c),P.updateNodeOpt(e)}}class Ie 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:a,thickness:c,strokeType:l}=this.workOptions,h=s.getRectFromPoints(this.tmpPoints,c);let p=!1;const d=this.syncIndex,u=this.tmpPoints.slice(this.consumeIndex);this.consumeIndex=this.tmpPoints.length-1,this.syncTimestamp===0&&(this.syncTimestamp=Date.now());const f={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:a,lineCap:"round",lineWidth:c,anchor:[.5,.5]},S=this.getTaskPoints(u);if(S.length){const g=Date.now();g-this.syncTimestamp>this.syncUnitTime&&(p=!0,this.syncTimestamp=g,this.syncIndex=this.tmpPoints.length),o&&this.draw({attrs:f,tasks:S,isDot:!1,layer:this.drawLayer||this.fullLayer})}const y=[];return this.tmpPoints.slice(d).forEach(g=>{y.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?y: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 a=this.tmpPoints.slice(this.consumeIndex);const c=a.length===1,{strokeColor:l,thickness:h,strokeType:p}=this.workOptions;if(c){const f=this.computDotStroke({point:a[0],radius:h/2});a=f.ps,t=f.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]},u=this.getTaskPoints(a);u.length&&this.draw({attrs:d,tasks:u,isDot:c,layer:this.drawLayer||this.fullLayer})}const o=[];this.tmpPoints.forEach(a=>{o.push(a.x,a.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 S;const{op:t,replaceId:o,isFullWork:i}=e,{strokeColor:r,thickness:a,strokeType:c}=this.workOptions;if(!t.length){const y=s.getRectFromPoints(this.tmpPoints,a);return{x:y.x*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],y:y.y*this.fullLayer.worldScaling[1]+this.fullLayer.worldPosition[1],w:y.w*this.fullLayer.worldScaling[0],h:y.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 y=this.computDotStroke({point:p[0],radius:a/2});p=y.ps,h=y.rect}else h=s.getRectFromPoints(this.tmpPoints,a);const u={name:(S=this.workId)==null?void 0:S.toString(),fillColor:d?r:void 0,opacity:1,lineDash:c===s.EStrokeType.Dotted&&!d?[1,a*2]:c===s.EStrokeType.LongDotted&&!d?[a,a*2]:void 0,strokeColor:r,lineCap:d?void 0:"round",lineWidth:d?0:a,anchor:[.5,.5]},f=this.getTaskPoints(p);if(f.length){const y=i?this.fullLayer:this.drawLayer||this.fullLayer;this.draw({attrs:u,tasks:f,isDot:d,replaceId:o,layer:y})}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:a}=this.workOptions;for(const c of o){const l=new b.Path,{pos:h,points:p}=c;let d;i?d=G(p,!0):d=G(p,!1),l.attr({...t,pos:h,d});const{vertex:u,fragment:f}=this.workOptions;if(u&&f){const S=r.renderer.createProgram({vertex:u,fragment:f}),{width:y,height:g}=r.getResolution();l.setUniforms({u_time:0,u_resolution:[y,g]}),l.setProgram(S)}r.appendChild(l),l.transition(a).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,a=[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 u=e[o].getAngleByPoints(e[o-1],e[o+1]);if(u<90||u>270){const f=(l=c.pop())==null?void 0:l.clone();f&&t.push({pos:a,points:[...c,f]}),i=e[o].x,r=e[o].y,a=[i,r];const S=h.x-i,y=h.y-r;c=[new s.Point2d(S,y)]}}o++}return t.push({pos:a,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 H=class H 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}=H.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:a,height:c}=H.eraserSizes[this.workOptions.thickness],l=Math.min(a,c),h=Math.round(r/l);if(h>1){const p=[];for(let d=0;d<h;d++){const u=s.Vec2d.Mul(i,d*l);p.push(this.tmpPoints[0]+u.x,this.tmpPoints[1]+u.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:a}=H.eraserSizes[this.workOptions.thickness];return s.Vec2d.Dist(o,i)<Math.hypot(r,a)*.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],u=d.findIndex((f,S)=>S<d.length-1?a([f,d[S+1]],[l[0],l[1]]):!1);if(u!==-1&&u>-1){const f=[],S=d.slice(0,u+1);if(s.Vec2d.Equals(d[u],l[0])||S.push(l[0].clone().setz(d[u].z)),S.length>1&&f.push(S),u+l.length-1<d.length-1){const y=u+l.length-1,g=d.slice(y),M=l[l.length-1];s.Vec2d.Equals(d[y],M)||g.unshift(M.clone().setz(d[y].z)),g.length>1&&f.push(g)}return h.splice(p,1,...f),h}}return h}function a(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 a=0;for(;a<i.length;){const c=i[a],l=new s.Vec2d(c[0],c[1]);r.push(l),a++}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 a;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),u=[],f=[];for(let y=0;y<h.length;y+=3){const g=new s.Vec2d(h[y]*this.worldScaling[0]+this.worldPosition[0],h[y+1]*this.worldScaling[1]+this.worldPosition[1],h[y+2]);f.push(g),u.push(new s.Point2d(g.x,g.y))}const S=u.length&&s.getRectFromPoints(u)||l.rect;if(s.isIntersect(S,this.eraserRect)){if(f.length>1){const y=ze.polyline(f.map(g=>g.XY),this.eraserPolyline);if(y.length&&(o.add(l.name),!d)){const g=this.translateIntersect(y),M=this.cutPolyline(g,f);for(let v=0;v<M.length;v++){const T=`${c}_s_${v}`,w=[];M[v].forEach(E=>{w.push((E.x-this.worldPosition[0])/this.worldScaling[0],(E.y-this.worldPosition[1])/this.worldScaling[1],E.z)}),l.opt&&l.toolsType&&this.vNodes&&(this.vNodes.setInfo(T,{rect:S,op:w,opt:l.opt,canRotate:l.canRotate,scaleType:l.scaleType,toolsType:l.toolsType}),i.set(T,{workId:T,op:w,opt:l.opt,toolsType:l.toolsType}))}}}else o.add(l.name);a=s.computRect(a,S)}}return o.forEach(c=>{var l;return(l=this.vNodes)==null?void 0:l.delete(c)}),a&&(a.x-=P.SafeBorderPadding,a.y-=P.SafeBorderPadding,a.w+=P.SafeBorderPadding*2,a.h+=P.SafeBorderPadding*2),a}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 a=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:a,newWorkDatas:c});r=s.computRect(r,p)}if(this.vNodes.deleteLastTarget(),r&&a.size){for(const h of c.keys())a.has(h)&&c.delete(h);return{type:s.EPostMessageType.RemoveNode,rect:r,removeIds:[...a],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 a of i.values())if((t=a.selectIds)!=null&&t.length)for(const c of a.selectIds)o.delete(c);for(const a of r.keys())o.delete(a);return o}return e}};m(H,"eraserSizes",Object.freeze([Object.freeze({width:18,height:26}),Object.freeze({width:26,height:34}),Object.freeze({width:34,height:50})]));let re=H;var me=s._getAllKeys,Xe=1,Ge=Object.prototype,Ye=Ge.hasOwnProperty;function qe(k,n,e,t,o,i){var r=e&Xe,a=me(k),c=a.length,l=me(n),h=l.length;if(c!=h&&!r)return!1;for(var p=c;p--;){var d=a[p];if(!(r?d in n:Ye.call(n,d)))return!1}var u=i.get(k),f=i.get(n);if(u&&f)return u==n&&f==k;var S=!0;i.set(k,n),i.set(n,k);for(var y=r;++p<c;){d=a[p];var g=k[d],M=n[d];if(t)var v=r?t(M,g,d,n,k,i):t(g,M,d,k,n,i);if(!(v===void 0?g===M||o(g,M,e,t,i):v)){S=!1;break}y||(y=d=="constructor")}if(S&&!y){var T=k.constructor,w=n.constructor;T!=w&&"constructor"in k&&"constructor"in n&&!(typeof T=="function"&&T instanceof T&&typeof w=="function"&&w instanceof w)&&(S=!1)}return i.delete(k),i.delete(n),S}var He=qe,pe=s._Stack,je=s._equalArrays,Ze=s._equalByTag,Je=He,ge=s._getTag,Se=s.isArray_1,Te=s.isBufferExports,Qe=s.isTypedArray_1,et=1,we="[object Arguments]",ke="[object Array]",ie="[object Object]",tt=Object.prototype,Pe=tt.hasOwnProperty;function st(k,n,e,t,o,i){var r=Se(k),a=Se(n),c=r?ke:ge(k),l=a?ke:ge(n);c=c==we?ie:c,l=l==we?ie:l;var h=c==ie,p=l==ie,d=c==l;if(d&&Te(k)){if(!Te(n))return!1;r=!0,h=!1}if(d&&!h)return i||(i=new pe),r||Qe(k)?je(k,n,e,t,o,i):Ze(k,n,c,e,t,o,i);if(!(e&et)){var u=h&&Pe.call(k,"__wrapped__"),f=p&&Pe.call(n,"__wrapped__");if(u||f){var S=u?k.value():k,y=f?n.value():n;return i||(i=new pe),o(S,y,e,t,i)}}return d?(i||(i=new pe),Je(k,n,e,t,o,i)):!1}var ot=st,it=ot,ve=s.isObjectLike_1;function Me(k,n,e,t,o){return k===n?!0:k==null||n==null||!ve(k)&&!ve(n)?k!==k&&n!==n:it(k,n,e,t,Me,o)}var rt=Me,nt=rt;function at(k,n){return nt(k,n)}var ct=at;const J=s.getDefaultExportFromCjs(ct),ce=class ce 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");m(this,"thickness");m(this,"strokeType");m(this,"useStroke");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:a}=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(a){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:ce.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],u=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(u)}),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:a}=o;(l=(c=t.parent)==null?void 0:c.getElementById(e))==null||l.remove(),r&&this.drawSelector({drawRect:r,subNodeMap:a,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,this.thickness=void 0,this.strokeType=void 0,this.useStroke=!1;const t=new Set;let o,i=!0;for(const r of e.values()){const{opt:a,canRotate:c,scaleType:l,toolsType:h}=r;this.selectorColor=this.workOptions.strokeColor,a.strokeColor&&(this.strokeColor=a.strokeColor),a.fillColor&&(this.fillColor=a.fillColor),a.textOpt&&(this.textOpt=a.textOpt),a.thickness&&(this.thickness=a.thickness),h!==s.EToolsKey.Pencil&&(i=!1),a.strokeType&&(this.strokeType=a.strokeType),h===s.EToolsKey.SpeechBalloon&&(t.add(h),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.placement=a.placement),h===s.EToolsKey.Polygon&&(t.add(h),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=a.vertices),h===s.EToolsKey.Star&&(t.add(h),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=a.vertices,this.shapeOpt.innerRatio=a.innerRatio,this.shapeOpt.innerVerticeStep=a.innerVerticeStep),h===s.EToolsKey.Text&&(this.textOpt=a),e.size===1&&(this.textOpt&&(this.canTextEdit=!0),this.canRotate=c,this.scaleType=l),l===s.EScaleType.none&&(this.scaleType=l),h===s.EToolsKey.Image&&(o=r)}i&&(this.useStroke=!0),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,this.thickness=void 0,this.strokeType=void 0,this.useStroke=void 0)):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 a=0;a<i.length;a+=3)r.push([i[a],i[a+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&&J(this.selectIds,r.selectIds))return{type:s.EPostMessageType.None};this.selectIds=r.selectIds;const a=r.intersectRect;this.getSelecteorInfo(r.subNodeMap),this.draw(s.Storage_Selector_key,this.fullLayer,r),this.oldSelectRect=a;const c=this.getChildrenPoints();return{type:s.EPostMessageType.Select,dataType:s.EDataType.Local,rect:s.computRect(a,i),selectIds:r.selectIds,selectRect:a,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,thickness:this.thickness,useStroke:this.useStroke,strokeType:this.strokeType,...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,s.Storage_Selector_key,!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,thickness:this.thickness,useStroke:this.useStroke,strokeType:this.strokeType,...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=s.Storage_Selector_key,o=!1){if(e.length===2){const i=e[0],r=e[1];let a;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(Oe(p).find(u=>u.isPointCollision(i,r))){a=h;break}}if(a){const h=a.name;if(!J(this.oldSelectRect,a.rect)){const p=new Map([[h,a]]);this.getSelecteorInfo(p),this.draw(t,this.fullLayer,{intersectRect:a.rect,subNodeMap:p,selectIds:this.selectIds||[]},o)}this.selectIds=[h],this.oldSelectRect=a.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 a;let o;const i=(a=e.parent)==null?void 0:a.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){var R;const{updateSelectorOpt:t,selectIds:o,vNodes:i,willSerializeData:r,worker:a,scene:c,isMainThread:l,offset:h}=e,p=this.fullLayer;if(!p)return;let d;const u=new Map,{originPoint:f,workState:S,angle:y,translate:g,dir:M,scale:v}=t;h&&(g?t.translate=[g[0]+h[0],g[1]+h[1]]:t.translate=h);let T;if(f||g||z(y)){if(S===s.EvevtWorkState.Start&&o)return i.setTargetAssignKeys(o),{type:s.EPostMessageType.Select,dataType:s.EDataType.Local,selectRect:this.oldSelectRect,rect:this.oldSelectRect};T=i.getLastTarget()}if(o)for(const L of o){const I=i.get(L);if(I){const{toolsType:N}=I,W=(p==null?void 0:p.getElementsByName(L))[0];if(W){let B=!1,Y=!1;const x={...t};let ee;if(N){x.thickness&&I.opt.thickness&&(B=I.opt.thickness!==x.thickness),x.strokeType&&((R=I.opt)!=null&&R.strokeType)&&(Y=I.opt.strokeType!==x.strokeType),ee=T==null?void 0:T.get(L);const C=Ce(N);if(C==null||C.updateNodeOpt({node:W,opt:x,vNodes:i,willSerializeData:r,targetNode:ee}),I&&a&&(r&&(x.angle||x.translate)||x.originPoint&&x.scenePoint&&x.scale||x.pointMap&&x.pointMap.has(L)||N===s.EToolsKey.Text&&(x.fontSize||x.translate||x.textInfos&&x.textInfos.get(L))||N===s.EToolsKey.Image&&(x.angle||x.translate||x.scale)||N===x.toolsType&&x.willRefresh||B||Y)){const D=a.createWorkShapeNode({workId:L,toolsType:N,toolsOpt:I.opt});D==null||D.setWorkId(L);let O;if(N===s.EToolsKey.Image&&c)O=await D.consumeServiceAsync({isFullWork:!0,replaceId:L,scene:c,isMainThread:l});else if(N===s.EToolsKey.Text)O=await D.consumeServiceAsync({isFullWork:!0,replaceId:L});else try{O=D==null?void 0:D.consumeService({op:I.op,isFullWork:!0,replaceId:L})}catch{continue}O&&(I.rect=O)}I&&(u.set(L,I),d=s.computRect(d,I.rect))}}}}T&&S===s.EvevtWorkState.Done&&(i.deleteLastTarget(),T=void 0);const w=d;if(f&&g&&v&&M&&w&&!h){const L=[[w.x,w.y],[w.x+w.w,w.y],[w.x+w.w,w.y+w.h],[w.x,w.y+w.h]];let I;switch(M){case"top":case"topLeft":case"left":g[0]>0&&g[1]>0?I=L[0]:g[0]>0?I=L[3]:g[1]>0?I=L[1]:I=L[2];break;case"topRight":g[0]<0&&g[1]>0?I=L[1]:g[0]<0?I=L[2]:g[1]>0?I=L[0]:I=L[3];break;case"right":case"bottomRight":case"bottom":g[0]<0&&g[1]<0?I=L[2]:g[0]<0?I=L[1]:g[1]<0?I=L[3]:I=L[0];break;case"bottomLeft":g[0]>0&&g[1]<0?I=L[3]:g[0]>0?I=L[0]:g[1]<0?I=L[2]:I=L[1];break}const N=I&&[f[0]-I[0],f[1]-I[1]]||[0,0];if(!J(N,[0,0]))return await this.updateSelector({...e,updateSelectorOpt:{},offset:N})}this.getSelecteorInfo(u),this.draw(s.Storage_Selector_key,p,{selectIds:o||[],subNodeMap:u,intersectRect:w});const E=s.computRect(this.oldSelectRect,w);return this.oldSelectRect=w,{type:s.EPostMessageType.Select,dataType:s.EDataType.Local,selectRect:w,renderRect:d,rect:s.computRect(E,w),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),a=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,a)}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(s.Storage_Selector_key,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(a=>!e.includes(a));if(o!=null&&o.length&&(t=this.unSelectedByIds(o)),e.length){const a=this.selectedByIds(e);t=s.computRect(t,a)}this.selectIds=e;const i=this.reRenderSelector();return{bgRect:t,selectRect:i}}cursorHover(e){var r,a;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&&!J(t,this.oldSelectRect))return{type:s.EPostMessageType.CursorHover,dataType:s.EDataType.Local,rect:s.computRect(t,this.oldSelectRect),selectorColor:this.selectorColor,willSyncService:!1};if((a=this.selectIds)!=null&&a.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(ce,"selectorBorderId","selector-border");let ne=ce;class Le 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,a=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 u=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:a,layer:u})}if(!i){const u=Date.now();return u-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=u,{...this.baseConsumeResult,type:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local,op:this.tmpPoints.map(f=>[...f.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 a;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(a=this.vNodes)==null||a.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:a,scale:c,rotate:l,translate:h,strokeType:p}=this.workOptions,d=o.worldPosition,u=o.worldScaling,{points:f,pos:S,rect:y,isTriangle:g,trianglePoints:M,trianglePos:v}=this.computDrawPoints(r),T=[y.x+y.w/2,y.y+y.h/2],w={pos:T,name:t,id:t,zIndex:a,anchor:[.5,.5],size:[y.w,y.h]};c&&(w.scale=c),l&&(w.rotate=l),h&&(w.translate=h);const E=new b.Group(w),R={points:M,pos:[v[0]-T[0],v[1]-T[1]],fillColor:i,strokeColor:i,lineWidth:0,normalize:!1},L=new b.Polyline(R);if(E.append(L),!g&&f&&S){const I={points:f,pos:[S[0]-T[0],S[1]-T[1]],fillColor:i,strokeColor:i,lineDash:p===s.EStrokeType.Dotted&&!g?[1,r*2]:p===s.EStrokeType.LongDotted&&!g?[r,r*2]:void 0,lineCap:p===s.EStrokeType.Normal?void 0:"round",lineWidth:r,normalize:!1},N=new b.Polyline(I);E.append(N)}if(this.replace(o,t,E),c||l||h){const I=E.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)}}return{x:Math.floor(y.x*u[0]+d[0]-P.SafeBorderPadding),y:Math.floor(y.y*u[1]+d[1]-P.SafeBorderPadding),w:Math.floor(y.w*u[0]+2*P.SafeBorderPadding),h:Math.floor(y.h*u[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),a=s.Vec2d.Mul(t,this.arrowTipWidth),c=s.Vec2d.Sub(this.tmpPoints[1],a),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),u=s.Point2d.Add(c,p),f=[this.tmpPoints[0],c],S=[d,this.tmpPoints[1],u],y=[i,r,...S,l,h];return{trianglePoints:S.map(g=>s.Point2d.Sub(g,this.tmpPoints[1]).XY).flat(1),trianglePos:this.tmpPoints[1].XY,points:f.map(g=>s.Point2d.Sub(g,this.tmpPoints[0]).XY).flat(1),rect:s.getRectFromPoints(y),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),a=[i,this.tmpPoints[1],r];return{trianglePoints:a.map(c=>s.Point2d.Sub(c,this.tmpPoints[1]).XY).flat(1),trianglePos:this.tmpPoints[1].XY,rect:s.getRectFromPoints(a),isTriangle:!0}}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,a=this.draw({workId:i,layer:r});return this.oldRect=a,(l=this.vNodes)==null||l.setInfo(i,{rect:a,op:t,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:P.getCenterPos(a,r)}),a}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var l,h;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,strokeType:a}=o,c=i.get(t.name);return r&&(t.setAttribute("strokeColor",r),t.setAttribute("fillColor",r),(l=c==null?void 0:c.opt)!=null&&l.strokeColor&&(c.opt.strokeColor=r),c&&i.setInfo(t.name,c)),a&&(c!=null&&c.opt)&&((h=c.opt)!=null&&h.strokeType)&&(c.opt.strokeType=a),P.updateNodeOpt(e)}}class Re 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,a=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 u=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:a,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,...this.baseConsumeResult,op:this.tmpPoints.map(f=>[...f.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 a;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(a=this.vNodes)==null||a.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:a,thickness:c,zIndex:l,scale:h,rotate:p,translate:d,strokeType:u}=this.workOptions,f=o.worldScaling,{radius:S,rect:y,pos:g}=this.computDrawPoints(c),M={pos:g,name:t,id:t,radius:S,lineWidth:c,fillColor:a!=="transparent"&&a||void 0,strokeColor:r,normalize:!0,lineJoin:"round",lineCap:"round",lineDash:u===s.EStrokeType.Dotted?[1,c*2]:u===s.EStrokeType.LongDotted?[c,c*2]:void 0},v={name:t,id:t,zIndex:l,pos:g,anchor:[.5,.5],size:[y.w,y.h]};h&&(v.scale=h),p&&(v.rotate=p),d&&(v.translate=d);const T=new b.Group(v);if(i){const R=new b.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/f[0],1/f[1]]});T.append(R)}const w=new b.Ellipse({...M,pos:[0,0]});T.append(w),this.replace(o,t,T);const E=T.getBoundingClientRect();return{x:Math.floor(E.x-P.SafeBorderPadding),y:Math.floor(E.y-P.SafeBorderPadding),w:Math.floor(E.width+P.SafeBorderPadding*2),h:Math.floor(E.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,a=this.draw({workId:i,layer:r,isDrawing:!1});return this.oldRect=a,(l=this.vNodes)==null||l.setInfo(i,{rect:a,op:t,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:P.getCenterPos(a,r)}),a}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var p,d,u;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,fillColor:a,strokeType:c}=o,l=i.get(t.name);let h=t;return t.tagName==="GROUP"&&(h=t.children[0]),r&&(h.setAttribute("strokeColor",r),(p=l==null?void 0:l.opt)!=null&&p.strokeColor&&(l.opt.strokeColor=r)),a&&(a==="transparent"?h.setAttribute("fillColor","rgba(0,0,0,0)"):h.setAttribute("fillColor",a),(d=l==null?void 0:l.opt)!=null&&d.fillColor&&(l.opt.fillColor=a)),c&&(l!=null&&l.opt)&&((u=l.opt)!=null&&u.strokeType)&&(l.opt.strokeType=c),l&&i.setInfo(t.name,l),P.updateNodeOpt(e)}}var lt=s._baseGetTag,ht=s.isObjectLike_1,pt="[object Boolean]";function dt(k){return k===!0||k===!1||ht(k)&&lt(k)==pt}var ut=dt;const X=s.getDefaultExportFromCjs(ut);class Ne 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 a of e)o.push(new s.Vec2d(...a));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(a=>a.XY).flat(1)}}consume(e){const{data:t,isFullWork:o,isSubWorker:i,isMainThread:r}=e,a=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 f=o?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({ps:p,workId:a,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:p.flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:s.EPostMessageType.None}}const u=s.computRect(d,this.oldRect);return this.oldRect=d,{rect:u,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),a=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:a,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:o,isDrawing:i,ps:r,replaceId:a}=e,{strokeColor:c,fillColor:l,thickness:h,zIndex:p,scale:d,rotate:u,translate:f,textOpt:S,strokeType:y}=this.workOptions,g=o.worldPosition,M=o.worldScaling,{points:v,rect:T,pos:w}=this.computDrawPoints(r),E={close:!0,normalize:!0,points:v,lineWidth:h,fillColor:l!=="transparent"&&l||void 0,strokeColor:c,lineJoin:"round",lineCap:"round",lineDash:y===s.EStrokeType.Dotted?[1,h*2]:y===s.EStrokeType.LongDotted?[h,h*2]:void 0},R={x:Math.floor(T.x*M[0]+g[0]-P.SafeBorderPadding),y:Math.floor(T.y*M[1]+g[1]-P.SafeBorderPadding),w:Math.floor(T.w*M[0]+2*P.SafeBorderPadding),h:Math.floor(T.h*M[0]+2*P.SafeBorderPadding)},L=new b.Group({name:t,id:t,zIndex:p,pos:w,anchor:[.5,.5],size:[T.w,T.h],scale:d,rotate:u,translate:f}),I=new b.Polyline({...E,pos:[0,0]});if(L.appendChild(I),i){const N=new b.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:c,lineWidth:1,scale:[1/M[0],1/M[1]]});L.appendChild(N)}if(this.replace(o,a||t,L),d||u||f){const N=L.getBoundingClientRect();return{x:Math.floor(N.x-P.SafeBorderPadding),y:Math.floor(N.y-P.SafeBorderPadding),w:Math.floor(N.width+2*P.SafeBorderPadding),h:Math.floor(N.height+2*P.SafeBorderPadding)}}return R}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 a=[];for(let d=0;d<t.length;d+=3)a.push([t[d],t[d+1],t[d+2]]);const c=o?this.fullLayer:this.drawLayer||this.fullLayer,l=this.draw({ps:a,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 M,v,T;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,fillColor:a,fontColor:c,fontBgColor:l,bold:h,italic:p,lineThrough:d,underline:u,fontSize:f,strokeType:S}=o,y=i.get(t.name);let g=t;if(t.tagName==="GROUP"&&(g=t.children[0]),r&&(g.setAttribute("strokeColor",r),(M=y==null?void 0:y.opt)!=null&&M.strokeColor&&(y.opt.strokeColor=r)),a&&(a==="transparent"?g.setAttribute("fillColor","rgba(0,0,0,0)"):g.setAttribute("fillColor",a),(v=y==null?void 0:y.opt)!=null&&v.fillColor&&(y.opt.fillColor=a)),y!=null&&y.opt.textOpt){const w=y.opt.textOpt;c&&w.fontColor&&(w.fontColor=c),l&&w.fontBgColor&&(w.fontBgColor=l),h&&(w.bold=h),p&&(w.italic=p),X(d)&&(w.lineThrough=d),X(u)&&(w.underline=u),f&&(w.fontSize=f)}return S&&(y!=null&&y.opt)&&((T=y.opt)!=null&&T.strokeType)&&(y.opt.strokeType=S),y&&i.setInfo(t.name,y),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.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,a=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 u=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:a,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(f=>[...f.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 a;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(a=this.vNodes)==null||a.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:a,thickness:c,zIndex:l,vertices:h,innerVerticeStep:p,innerRatio:d,scale:u,rotate:f,translate:S,strokeType:y}=this.workOptions,g=o.worldScaling,{rect:M,pos:v,points:T}=this.computDrawPoints(c,h,p,d),w={close:!0,points:T,lineWidth:c,fillColor:a!=="transparent"&&a||void 0,strokeColor:r,normalize:!0,lineJoin:"round",lineCap:"round",lineDash:y===s.EStrokeType.Dotted?[1,c*2]:y===s.EStrokeType.LongDotted?[c,c*2]:void 0},E={name:t,id:t,zIndex:l,pos:v,anchor:[.5,.5],size:[M.w,M.h]};u&&(E.scale=u),f&&(E.rotate=f),S&&(E.translate=S);const R=new b.Group(E);if(i){const N=new b.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/g[0],1/g[1]]});R.append(N)}const L=new b.Polyline({...w,pos:[0,0]});R.append(L),this.replace(o,t,R);const I=R.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,t,o,i){const r=s.getRectFromPoints(this.tmpPoints),a=[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 f=0;f<t;f++){const S=f*d-.5*Math.PI;let y,g;f%o===1?(y=h*c[0]*Math.cos(S),g=h*c[1]*Math.sin(S)):(y=l*c[0]*Math.cos(S),g=l*c[1]*Math.sin(S),p.push(y,g)),p.push(y,g)}return{rect:s.getRectFromPoints(this.tmpPoints,e),pos:a,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,a=this.draw({workId:i,layer:r,isDrawing:!1});return this.oldRect=a,(l=this.vNodes)==null||l.setInfo(i,{rect:a,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:a&&P.getCenterPos(a,r)}),a}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var y;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,fillColor:a,toolsType:c,vertices:l,innerVerticeStep:h,innerRatio:p,strokeType:d}=o,u=i.get(t.name),f=u==null?void 0:u.opt;let S=t;return t.tagName==="GROUP"&&(S=t.children[0]),r&&(S.setAttribute("strokeColor",r),f!=null&&f.strokeColor&&(f.strokeColor=r)),a&&(a==="transparent"?S.setAttribute("fillColor","rgba(0,0,0,0)"):S.setAttribute("fillColor",a),f!=null&&f.fillColor&&(f.fillColor=a)),c===s.EToolsKey.Star&&(l&&(f.vertices=l),h&&(f.innerVerticeStep=h),p&&(f.innerRatio=p)),d&&(u!=null&&u.opt)&&((y=u.opt)!=null&&y.strokeType)&&(u.opt.strokeType=d),u&&i.setInfo(t.name,{...u,opt:f}),P.updateNodeOpt(e)}}class be 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:a}=t,c=this.workId,l=a==null?void 0:a.length;if(!l||l<2)return{type:s.EPostMessageType.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new s.Point2d(a[0],a[1])],h=!1):h=this.updateTempPoints(a),!h)return{type:s.EPostMessageType.None};let p;if(i||r){const u=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:c,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(f=>[...f.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 a;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(a=this.vNodes)==null||a.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:a,thickness:c,zIndex:l,vertices:h,scale:p,rotate:d,translate:u,strokeType:f}=this.workOptions,S=o.worldScaling,{rect:y,pos:g,points:M}=this.computDrawPoints(c,h),v={close:!0,points:M,lineWidth:c,fillColor:a!=="transparent"&&a||void 0,strokeColor:r,normalize:!0,lineJoin:"round",lineCap:"round",lineDash:f===s.EStrokeType.Dotted?[1,c*2]:f===s.EStrokeType.LongDotted?[c,c*2]:void 0},T={name:t,id:t,zIndex:l,pos:g,anchor:[.5,.5],size:[y.w,y.h]};p&&(T.scale=p),d&&(T.rotate=d),u&&(T.translate=u);const w=new b.Group(T);if(i){const L=new b.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:r,lineWidth:1,scale:[1/S[0],1/S[1]]});w.append(L)}const E=new b.Polyline({...v,pos:[0,0]});w.append(E),this.replace(o,t,w);const R=w.getBoundingClientRect();return{x:Math.floor(R.x-P.SafeBorderPadding),y:Math.floor(R.y-P.SafeBorderPadding),w:Math.floor(R.width+P.SafeBorderPadding*2),h:Math.floor(R.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),a=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,u=a*r[0]*Math.cos(d),f=a*r[1]*Math.sin(d);c.push(u,f)}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,a=this.draw({workId:i,layer:r,isDrawing:!1});return this.oldRect=a,(l=this.vNodes)==null||l.setInfo(i,{rect:a,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:a&&P.getCenterPos(a,r)}),a}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var f;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,fillColor:a,toolsType:c,vertices:l,strokeType:h}=o,p=i.get(t.name),d=p==null?void 0:p.opt;let u=t;return t.tagName==="GROUP"&&(u=t.children[0]),r&&(u.setAttribute("strokeColor",r),d!=null&&d.strokeColor&&(d.strokeColor=r)),a&&(a==="transparent"?u.setAttribute("fillColor","rgba(0,0,0,0)"):u.setAttribute("fillColor",a),d!=null&&d.fillColor&&(d.fillColor=a)),c===s.EToolsKey.Polygon&&l&&(d.vertices=l),h&&(p!=null&&p.opt)&&((f=p.opt)!=null&&f.strokeType)&&(p.opt.strokeType=h),p&&i.setInfo(t.name,{...p,opt:d}),P.updateNodeOpt(e)}}class F{static bezier(n,e){const t=[];for(let o=0;o<e.length;o+=4){const i=e[o],r=e[o+1],a=e[o+2],c=e[o+3];i&&r&&a&&c?t.push(...F.getBezierPoints(n,i,r,a,c)):i&&r&&a?t.push(...F.getBezierPoints(n,i,r,a)):i&&r?t.push(...F.getBezierPoints(n,i,r)):i&&t.push(i)}return t}static getBezierPoints(n=10,e,t,o,i){let r=null;const a=[];!o&&!i?r=F.oneBezier:o&&!i?r=F.twoBezier:o&&i&&(r=F.threeBezier);for(let c=0;c<n;c++)r&&a.push(r(c/n,e,t,o,i));return i?a.push(i):o&&a.push(o),a}static oneBezier(n,e,t){const o=e.x+(t.x-e.x)*n,i=e.y+(t.y-e.y)*n;return new s.Vec2d(o,i)}static twoBezier(n,e,t,o){const i=(1-n)*(1-n)*e.x+2*n*(1-n)*t.x+n*n*o.x,r=(1-n)*(1-n)*e.y+2*n*(1-n)*t.y+n*n*o.y;return new s.Vec2d(i,r)}static threeBezier(n,e,t,o,i){const r=e.x*(1-n)*(1-n)*(1-n)+3*t.x*n*(1-n)*(1-n)+3*o.x*n*n*(1-n)+i.x*n*n*n,a=e.y*(1-n)*(1-n)*(1-n)+3*t.y*n*(1-n)*(1-n)+3*o.y*n*n*(1-n)+i.y*n*n*n;return new s.Vec2d(r,a)}}class xe 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 u;const{data:t,isFullWork:o,isSubWorker:i,isMainThread:r}=e,a=(u=t==null?void 0:t.workId)==null?void 0:u.toString();if(!a)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 f=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:a,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(S=>[...S.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 a;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(a=this.vNodes)==null||a.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:a,zIndex:c,placement:l,scale:h,rotate:p,translate:d,strokeType:u}=this.workOptions,{rect:f,pos:S,points:y}=this.computDrawPoints(a,l),g={points:y.map(E=>E.XY),lineWidth:a,fillColor:r!=="transparent"&&r||void 0,strokeColor:i,normalize:!0,className:`${S[0]},${S[1]}`,close:!0,lineJoin:"round",lineCap:"round",lineDash:u===s.EStrokeType.Dotted?[1,a*2]:u===s.EStrokeType.LongDotted?[a,a*2]:void 0},M={name:t,id:t,zIndex:c,pos:S,anchor:[.5,.5],size:[f.w,f.h]};h&&(M.scale=h),p&&(M.rotate=p),d&&(M.translate=d);const v=new b.Group(M),T=new b.Polyline({...g,pos:[0,0]});v.append(T),this.replace(o,t,v);const w=v.getBoundingClientRect();return{x:Math.floor(w.x-P.SafeBorderPadding),y:Math.floor(w.y-P.SafeBorderPadding),w:Math.floor(w.width+P.SafeBorderPadding*2),h:Math.floor(w.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),a=Math.floor(o.h*.1),c=[],l=s.Vec2d.Add(i[0],new s.Vec2d(0,a,0)),h=s.Vec2d.Add(i[0],new s.Vec2d(r,0,0)),p=F.getBezierPoints(10,l,i[0],h),d=s.Vec2d.Sub(i[1],new s.Vec2d(r,0,0)),u=s.Vec2d.Add(i[1],new s.Vec2d(0,a,0)),f=F.getBezierPoints(10,d,i[1],u),S=s.Vec2d.Sub(i[2],new s.Vec2d(0,a,0)),y=s.Vec2d.Sub(i[2],new s.Vec2d(r,0,0)),g=F.getBezierPoints(10,S,i[2],y),M=s.Vec2d.Add(i[3],new s.Vec2d(r,0,0)),v=s.Vec2d.Sub(i[3],new s.Vec2d(0,a,0)),T=F.getBezierPoints(10,M,i[3],v),w=r*(1-this.ratio)*10,E=a*(1-this.ratio)*10;switch(t){case"bottom":{const I=s.Vec2d.Sub(i[2],new s.Vec2d(r*5-w/2,0,0)),N=s.Vec2d.Sub(i[2],new s.Vec2d(r*5,-E,0)),W=s.Vec2d.Sub(i[2],new s.Vec2d(r*5+w/2,0,0));c.push(N,W,...T,...p,...f,...g,I);break}case"bottomRight":{const I=s.Vec2d.Sub(i[2],new s.Vec2d(r*1.1,0,0)),N=s.Vec2d.Sub(i[2],new s.Vec2d(r*1.1+w/2,-E,0)),W=s.Vec2d.Sub(i[2],new s.Vec2d(r*1.1+w,0,0));c.push(N,W,...T,...p,...f,...g,I);break}case"bottomLeft":{const I=s.Vec2d.Add(i[3],new s.Vec2d(r*1.1+w,0,0)),N=s.Vec2d.Add(i[3],new s.Vec2d(r*1.1+w/2,E,0)),W=s.Vec2d.Add(i[3],new s.Vec2d(r*1.1,0,0));c.push(N,W,...T,...p,...f,...g,I);break}case"top":{const I=s.Vec2d.Sub(i[1],new s.Vec2d(r*5-w/2,0,0)),N=s.Vec2d.Sub(i[1],new s.Vec2d(r*5,E,0)),W=s.Vec2d.Sub(i[1],new s.Vec2d(r*5+w/2,0,0));c.push(N,I,...f,...g,...T,...p,W);break}case"topRight":{const I=s.Vec2d.Sub(i[1],new s.Vec2d(r*1.1,0,0)),N=s.Vec2d.Sub(i[1],new s.Vec2d(r*1.1+w/2,E,0)),W=s.Vec2d.Sub(i[1],new s.Vec2d(r*1.1+w,0,0));c.push(N,I,...f,...g,...T,...p,W);break}case"topLeft":{const I=s.Vec2d.Add(i[0],new s.Vec2d(r*1.1+w,0,0)),N=s.Vec2d.Add(i[0],new s.Vec2d(r*1.1+w/2,-E,0)),W=s.Vec2d.Add(i[0],new s.Vec2d(r*1.1,0,0));c.push(N,I,...f,...g,...T,...p,W);break}case"left":{const I=s.Vec2d.Add(i[0],new s.Vec2d(0,a*5-E/2,0)),N=s.Vec2d.Add(i[0],new s.Vec2d(-w,a*5,0)),W=s.Vec2d.Add(i[0],new s.Vec2d(0,a*5+E/2,0));c.push(N,I,...p,...f,...g,...T,W);break}case"leftTop":{const I=s.Vec2d.Add(i[0],new s.Vec2d(0,a*1.1,0)),N=s.Vec2d.Add(i[0],new s.Vec2d(-w,a*1.1+E/2,0)),W=s.Vec2d.Add(i[0],new s.Vec2d(0,a*1.1+E,0));c.push(N,I,...p,...f,...g,...T,W);break}case"leftBottom":{const I=s.Vec2d.Sub(i[3],new s.Vec2d(0,a*1.1+E,0)),N=s.Vec2d.Sub(i[3],new s.Vec2d(w,a*1.1+E/2,0)),W=s.Vec2d.Sub(i[3],new s.Vec2d(0,a*1.1,0));c.push(N,I,...p,...f,...g,...T,W);break}case"right":{const I=s.Vec2d.Add(i[1],new s.Vec2d(0,a*5-E/2,0)),N=s.Vec2d.Add(i[1],new s.Vec2d(w,a*5,0)),W=s.Vec2d.Add(i[1],new s.Vec2d(0,a*5+E/2,0));c.push(N,W,...g,...T,...p,...f,I);break}case"rightTop":{const I=s.Vec2d.Add(i[1],new s.Vec2d(0,a*1.1,0)),N=s.Vec2d.Add(i[1],new s.Vec2d(w,a*1.1+E/2,0)),W=s.Vec2d.Add(i[1],new s.Vec2d(0,a*1.1+E,0));c.push(N,W,...g,...T,...p,...f,I);break}case"rightBottom":{const I=s.Vec2d.Sub(i[2],new s.Vec2d(0,a*1.1+E,0)),N=s.Vec2d.Sub(i[2],new s.Vec2d(-w,a*1.1+E/2,0)),W=s.Vec2d.Sub(i[2],new s.Vec2d(0,a*1.1,0));c.push(N,W,...g,...T,...p,...f,I);break}}const R=s.getRectFromPoints(this.tmpPoints,e),L=[Math.floor(R.x+R.w/2),Math.floor(R.y+R.h/2)];return{rect:R,pos:L,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,a=this.draw({workId:i,layer:r,isDrawing:!1});return this.oldRect=a,(l=this.vNodes)==null||l.setInfo(i,{rect:a,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:a&&P.getCenterPos(a,r)}),a}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var f;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,fillColor:a,toolsType:c,placement:l,strokeType:h}=o,p=i.get(t.name),d=p==null?void 0:p.opt;let u=t;return t.tagName==="GROUP"&&(u=t.children[0]),r&&(u.setAttribute("strokeColor",r),d!=null&&d.strokeColor&&(d.strokeColor=r)),a&&(a==="transparent"?u.setAttribute("fillColor","rgba(0,0,0,0)"):u.setAttribute("fillColor",a),d!=null&&d.fillColor&&(d.fillColor=a)),c===s.EToolsKey.SpeechBalloon&&l&&(d.placement=l),h&&(p!=null&&p.opt)&&((f=p.opt)!=null&&f.strokeType)&&(p.opt.strokeType=h),p&&i.setInfo(t.name,{...p,opt:d}),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:a}=e,{centerX:c,centerY:l,width:h,height:p,rotate:d,zIndex:u}=this.workOptions,f=!!t.parent.gl,S={anchor:[.5,.5],pos:[c,l],name:o,size:[h,p],zIndex:u,rotate:!a&&!f&&180+(d||0)||d,texture:r},y=new b.Sprite(S);this.replace(t,i||o,y);const g=y.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,u,f;const{isFullWork:t,replaceId:o,scene:i,isMainThread:r}=e,{src:a,uuid:c}=this.workOptions,l=((p=this.workId)==null?void 0:p.toString())||c,h=t?this.fullLayer:this.drawLayer||this.fullLayer;if(a){const S=await i.preload({id:c,src:this.workOptions.src}),y=this.draw({workId:l,layer:h,replaceId:o,imageBitmap:S[0],isMainThread:r});return this.oldRect=l&&((u=(d=this.vNodes)==null?void 0:d.get(l))==null?void 0:u.rect)||void 0,(f=this.vNodes)==null||f.setInfo(l,{rect:y,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:y&&P.getCenterPos(y,h)}),y}}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:a,originPoint:c,scenePoint:l,scale:h,angle:p,isLocked:d,zIndex:u}=o,f=r&&s.cloneDeep(r)||i.get(t.name);if(!f)return;const S=t.parent;if(S){if(z(u)&&(t.setAttribute("zIndex",u),f.opt.zIndex=u),X(d)&&(f.opt.locked=d),c&&l&&h){const{centerX:y,centerY:g,width:M,height:v,uniformScale:T}=f.opt,w=T!==!1?[h[0],h[0]]:h,E=[y,g],R=[y,g];s.scalePoints(R,l,w,a);const L=[R[0]-E[0],R[1]-E[1]];f.centerPos=[f.centerPos[0]+L[0],f.centerPos[1]+L[1]],f.opt.width=Math.round(M*w[0]),f.opt.height=Math.round(v*w[1]),f.opt.centerX=R[0],f.opt.centerY=R[1]}else if(a)f.opt.centerX=f.opt.centerX+a[0],f.opt.centerY=f.opt.centerY+a[1],f.centerPos=[f.centerPos[0]+a[0],f.centerPos[1]+a[1]];else if(z(p))if(f.opt.rotate=p,f.scaleType=Q.getScaleType(f.opt),r){const y=s.getRectRotated(f.rect,p);f.rect=y}else{const y=P.getRectFromLayer(S,t.name);f.rect=y||f.rect}return f&&i.setInfo(t.name,f),f==null?void 0:f.rect}}}class De 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,a=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 u=o?this.fullLayer:this.drawLayer||this.fullLayer;p=this.draw({workId:a,layer:u})}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(f=>[...f.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 a;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(a=this.vNodes)==null||a.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:a,scale:c,rotate:l,translate:h,strokeType:p}=this.workOptions,d=o.worldPosition,u=o.worldScaling,{d:f,rect:S,isDot:y}=this.computDrawPoints(r,p),g=[S.x+S.w/2,S.y+S.h/2],M={pos:g,name:t,id:t,d:f,fillColor:i,strokeColor:i,lineDash:p===s.EStrokeType.Dotted&&!y?[1,r*2]:p===s.EStrokeType.LongDotted&&!y?[r,r*2]:void 0,lineCap:p===s.EStrokeType.Normal||y?void 0:"round",lineWidth:p===s.EStrokeType.Normal||y?0:r,className:`${g[0]},${g[1]}`,normalize:!0,zIndex:a};c&&(M.scale=c),l&&(M.rotate=l),h&&(M.translate=h);const v=new b.Path(M);if(this.replace(o,t,v),l||c||h){const w=v.getBoundingClientRect();return{x:Math.floor(w.x-P.SafeBorderPadding),y:Math.floor(w.y-P.SafeBorderPadding),w:Math.floor(w.width+P.SafeBorderPadding*2),h:Math.floor(w.height+P.SafeBorderPadding*2)}}return{x:Math.floor(S.x*u[0]+d[0]-P.SafeBorderPadding),y:Math.floor(S.y*u[1]+d[1]-P.SafeBorderPadding),w:Math.floor(S.w*u[0]+2*P.SafeBorderPadding),h:Math.floor(S.h*u[1]+2*P.SafeBorderPadding)}}computDrawPoints(e,t){return this.tmpPoints[1].distance(this.tmpPoints[0])>this.straightTipWidth?this.computFullPoints(e,t):this.computDotPoints(e)}computFullPoints(e,t){const o=s.Vec2d.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),i=s.Vec2d.Per(o).mul(e/2),r=s.Point2d.Sub(this.tmpPoints[0],i),a=s.Point2d.Add(this.tmpPoints[0],i),c=s.Point2d.Sub(this.tmpPoints[1],i),l=s.Point2d.Add(this.tmpPoints[1],i),h=s.Point2d.GetSemicircleStroke(this.tmpPoints[1],c,-1,8),p=s.Point2d.GetSemicircleStroke(this.tmpPoints[0],a,-1,8),d=[r,c,...h,l,a,...p];let u;return t!==s.EStrokeType.Normal?u=G(this.tmpPoints,!1):u=G(d,!0),{d:u,rect:s.getRectFromPoints(d),isDot:!1,pos:this.tmpPoints[0].XY}}computDotPoints(e){const t=s.Point2d.GetDotStroke(this.tmpPoints[0],e/2,8);return{d:G(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,a=this.draw({workId:i,layer:r});return this.oldRect=a,(l=this.vNodes)==null||l.setInfo(i,{rect:a,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:a&&P.getCenterPos(a,r)}),a}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var l,h;const{node:t,opt:o,vNodes:i}=e,{strokeColor:r,strokeType:a}=o,c=i.get(t.name);return r&&(t.setAttribute("strokeColor",r),t.setAttribute("fillColor",r),(l=c==null?void 0:c.opt)!=null&&l.strokeColor&&(c.opt.strokeColor=r)),a&&(c!=null&&c.opt)&&((h=c.opt)!=null&&h.strokeType)&&(c.opt.strokeType=a),c&&i.setInfo(t.name,c),P.updateNodeOpt(e)}}const $=class $ 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:a,zIndex:c}=this.workOptions,l=o.worldPosition,h=o.worldScaling;if(!a||!r)return;const p={name:t,id:t,pos:[a[0],a[1]],anchor:[0,0],size:r,zIndex:c},d=new b.Group(p),u={x:a[0],y:a[1],w:r[0],h:r[1]},f={x:Math.floor(u.x*h[0]+l[0]),y:Math.floor(u.y*h[1]+l[1]),w:Math.floor(u.w*h[0])+2,h:Math.floor(u.h*h[1])+2};if(this.replace(o,t,d),i&&o&&this.workOptions.text){const S=await $.createLabels(this.workOptions,o,f),{labels:y,maxWidth:g}=S;d.append(...y),f.w=Math.ceil(Math.max(g*o.worldScaling[0],f.w))}return f}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 a=o?this.fullLayer:this.drawLayer||this.fullLayer,c=await this.draw({workId:t,layer:a,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,a)}),c}updataOptService(){}async updataOptServiceAsync(e,t){var f,S;if(!this.workId)return;const o=this.workId.toString(),{fontColor:i,fontBgColor:r,bold:a,italic:c,lineThrough:l,underline:h,zIndex:p}=e,d=(f=this.vNodes)==null?void 0:f.get(o);if(!d)return;i&&(d.opt.fontColor=i),r&&(d.opt.fontBgColor=r),a&&(d.opt.bold=a),c&&(d.opt.italic=c),X(l)&&(d.opt.lineThrough=l),X(h)&&(d.opt.underline=h),z(p)&&(d.opt.zIndex=p),this.oldRect=d.rect;const u=await this.draw({workId:o,layer:this.fullLayer,isDrawLabel:typeof t>"u"&&this.workOptions.workState===s.EvevtWorkState.Done||t});return(S=this.vNodes)==null||S.setInfo(o,{rect:u,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:u&&P.getCenterPos(u,this.fullLayer)}),u}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($.textImageSnippetSize*3/4/e)||1}static async createLabels(e,t,o){var W;const i=[],{x:r,y:a}=o,{width:c,height:l}=(W=t.parent)==null?void 0:W.parent,h=s.transformToNormalData(e.text),p=h.length,{fontSize:d,lineHeight:u,bold:f,textAlign:S,italic:y,fontFamily:g,verticalAlign:M,fontColor:v,fontBgColor:T,underline:w,lineThrough:E}=e,R=$.getSafetySnippetRatio(t)||1,L=Math.floor(d*R),I=$.getSafetySnippetFontLength(L);let N=0;for(let B=0;B<p;B++){const Y=h[B],x=u||L*1.5;if(Y){const ee=s.strlen(Y),C=[0,0],D=[0,d*1.2];M==="middle"&&(C[1]=B*d*1.2+5);const O=[0,-d*.15];C[0]=5;const j=Math.sin(Math.PI/180*20);let U=0;const te=[];let Z=0;for(;Z<ee;){S==="left"&&(O[0]=U),Z===0&&y==="italic"&&(O[0]=O[0]-j/2*d);const he=Y.slice(Z,Z+I),se={anchor:[0,0],pos:O,text:he,fontFamily:g,fontSize:L,lineHeight:x,strokeColor:v,fontWeight:f,fillColor:v,textAlign:S,fontStyle:y,scale:[1/R,1/R]},_=new b.Label(se),K=await _.textImageReady;let oe=!0;if(K){const ue=K.rect&&K.rect[2],fe=K.rect&&K.rect[3];if(ue&&fe){const ye=ue/R,Ae=fe/R;U=ye+U,y==="italic"&&(f==="bold"?U=U-j*d*1.2:U=U-j*d),((O[0]+C[0]+ye)*t.worldScaling[0]+r<=0||(O[0]+C[0])*t.worldScaling[0]+r>=c||(O[1]+C[1]+Ae)*t.worldScaling[1]+a<=0||(O[1]+C[1])*t.worldScaling[1]+a>=l)&&(_.disconnect(),oe=!1),oe&&te.push(_)}}Z+=I}D[0]=U,y==="italic"&&(D[0]=D[0]+j*d),N=Math.max(N,D[0]);let de=!0;if(((C[0]+D[0])*t.worldScaling[0]+r<=0||C[0]*t.worldScaling[0]+r>=c||(C[1]+D[1])*t.worldScaling[0]+a<=0||C[1]*t.worldScaling[1]+a>=l)&&(de=!1),de){if(w){const _=Math.floor(d/10),K={normalize:!1,pos:[0,d*1.1+_/2],lineWidth:_,points:[0,0,Math.ceil(D[0]),0],strokeColor:v,className:"underline"},oe=new b.Polyline(K);te.push(oe)}if(E){const _={normalize:!1,pos:[0,d*1.2/2],lineWidth:Math.floor(d/10),points:[0,0,Math.ceil(D[0]),0],strokeColor:v,className:"lineThrough"},K=new b.Polyline(_);te.push(K)}const he={pos:C,anchor:[0,0],size:D,bgcolor:T},se=new b.Group(he);se.append(...te),i.push(se)}}}return{labels:i,maxWidth:N}}static updateNodeOpt(e){const{node:t,opt:o,vNodes:i,targetNode:r}=e,{fontBgColor:a,fontColor:c,translate:l,originPoint:h,scenePoint:p,scale:d,bold:u,italic:f,lineThrough:S,underline:y,fontSize:g,textInfos:M,zIndex:v}=o,T=r&&s.cloneDeep(r)||i.get(t.name);if(!T||!t.parent)return;const E=T.opt;if(z(v)&&(t.setAttribute("zIndex",v),T.opt.zIndex=v),c&&E.fontColor&&(E.fontColor=c,t.children.forEach(R=>{R.tagName==="GROUP"&&R.children.forEach(L=>{L.tagName==="LABEL"?(L.setAttribute("fillColor",c),L.setAttribute("strokeColor",c)):L.tagName==="POLYLINE"&&L.setAttribute("strokeColor",c)})})),a&&E.fontBgColor&&(E.fontBgColor=a,t.children.forEach(R=>{R.tagName==="GROUP"&&R.setAttribute("bgcolor",a)})),u&&(E.bold=u),f&&(E.italic=f),X(S)&&(E.lineThrough=S),X(y)&&(E.underline=y),g&&(E.fontSize=g),h&&p&&d&&r&&E.boxPoint){const R=M==null?void 0:M.get(t.name);if(R){const{fontSize:W,boxSize:B}=R;E.boxSize=B||E.boxSize,E.fontSize=W||E.fontSize}const L=[E.boxPoint[0],E.boxPoint[1]];s.scalePoints(E.boxPoint,p,d,l);const I=[T.op[0],T.op[1]],N=[I[0]-L[0],I[1]-L[1]];T.centerPos=[T.centerPos[0]+N[0],T.centerPos[1]+N[1]]}else l&&E.boxPoint&&(E.boxPoint=[E.boxPoint[0]+l[0],E.boxPoint[1]+l[1]],T.centerPos=[T.centerPos[0]+l[0],T.centerPos[1]+l[1]]);return T&&i.setInfo(t.name,T),T==null?void 0:T.rect}static getRectFromLayer(e,t){const o=e.getElementsByName(t)[0];if(o){const i=o.getBoundingClientRect();let r={x:Math.floor(i.x),y:Math.floor(i.y),w:Math.floor(i.width+2),h:Math.floor(i.height+2)};return o.children.forEach(a=>{if(a.tagName==="GROUP"){const c=o.getBoundingClientRect();r=s.computRect(r,{x:Math.floor(c.x),y:Math.floor(c.y),w:Math.floor(c.width+2),h:Math.floor(c.height+2)})}}),r}}};m($,"textImageSnippetSize",1024*4),m($,"SafeBorderPadding",30);let ae=$;function Ce(k){switch(k){case s.EToolsKey.Arrow:return Le;case s.EToolsKey.Pencil:return Ee;case s.EToolsKey.Straight:return De;case s.EToolsKey.Ellipse:return Re;case s.EToolsKey.Polygon:case s.EToolsKey.Triangle:return be;case s.EToolsKey.Star:case s.EToolsKey.Rhombus:return We;case s.EToolsKey.Rectangle:return Ne;case s.EToolsKey.SpeechBalloon:return xe;case s.EToolsKey.Text:return ae;case s.EToolsKey.LaserPen:return Ie;case s.EToolsKey.Eraser:return re;case s.EToolsKey.Selector:return ne;case s.EToolsKey.Image:return Q}}function le(k,n){const{toolsType:e,...t}=k;switch(e){case s.EToolsKey.Arrow:return new Le(t);case s.EToolsKey.Pencil:return new Ee(t);case s.EToolsKey.Straight:return new De(t);case s.EToolsKey.Ellipse:return new Re(t);case s.EToolsKey.Polygon:case s.EToolsKey.Triangle:return new be(t);case s.EToolsKey.Star:case s.EToolsKey.Rhombus:return new We(t);case s.EToolsKey.Rectangle:return new Ne(t);case s.EToolsKey.SpeechBalloon:return new xe(t);case s.EToolsKey.Text:return new ae(t);case s.EToolsKey.LaserPen:return new Ie(t);case s.EToolsKey.Eraser:return new re(t,n);case s.EToolsKey.Selector:return t.vNodes?new ne({...t,vNodes:t.vNodes,drawLayer:t.fullLayer}):void 0;case s.EToolsKey.Image:return new Q(t);default:return}}function Oe(k){const n=[],e=["PATH","SPRITE","POLYLINE","RECT","ELLIPSE","LABEL"];for(const t of k){if(t.tagName==="GROUP"&&t.children.length)return Oe(t.children);t.tagName&&e.includes(t.tagName)&&n.push(t)}return n}const ft=k=>{if(k.tagName==="GROUP"){const n=Object.getOwnPropertySymbols(k).find(e=>e.toString()==="Symbol(sealed)");if(n&&k[n])return!0}return!1},yt=k=>!k.isHid;class mt{constructor(n,e){m(this,"viewId");m(this,"scene");m(this,"fullLayer");m(this,"curNodeMap",new Map);m(this,"targetNodeMap",[]);m(this,"highLevelIds");this.viewId=n,this.scene=e}init(n){this.fullLayer=n}get(n){return this.curNodeMap.get(n)}getNodesByType(n){const e=new Map;return this.curNodeMap.forEach((t,o)=>{t.toolsType===n&&e.set(o,t)}),e}hasRenderNodes(){let n=!1;for(const e of this.curNodeMap.values())yt(e)&&(n=!0);return n}has(n){return this.curNodeMap.has(n)}setInfo(n,e){const t=this.curNodeMap.get(n)||{name:n,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)),X(e.isSelected)&&(t.isSelected=e.isSelected),t.rect?this.curNodeMap.set(n,t):this.curNodeMap.delete(n)}selected(n){this.setInfo(n,{isSelected:!0})}unSelected(n){this.setInfo(n,{isSelected:!1})}delete(n){this.curNodeMap.delete(n)}clear(){this.curNodeMap.clear(),this.targetNodeMap.length=0}hasRectIntersectRange(n,e=!0){for(const t of this.curNodeMap.values())if(s.isIntersect(n,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(n,e=!0,t=!0){let o;const i=new Map;for(const[r,a]of this.curNodeMap.entries())if(s.isIntersect(n,a.rect)){if(e&&a.toolsType===s.EToolsKey.Image&&a.opt.locked||t&&a.toolsType===s.EToolsKey.Text&&(a.opt.workState===s.EvevtWorkState.Doing||a.opt.workState===s.EvevtWorkState.Start))continue;o=s.computRect(o,a.rect),i.set(r,a)}return{rectRange:o,nodeRange:i}}getNodeRectFormShape(n,e){const t=Ce(e.toolsType);return this.fullLayer&&(t==null?void 0:t.getRectFromLayer(this.fullLayer,n))}updateNodeRect(n){const e=this.curNodeMap.get(n);if(e){const t=this.getNodeRectFormShape(n,e);if(!t){this.curNodeMap.delete(n);return}e.rect=t,this.curNodeMap.set(n,e)}}updateHighLevelNodesRect(n){this.highLevelIds=n;for(const e of this.highLevelIds.keys())this.updateNodeRect(e)}updateLowLevelNodesRect(){var n;for(const e of this.curNodeMap.keys())(n=this.highLevelIds)!=null&&n.has(e)||this.updateNodeRect(e)}clearHighLevelIds(){this.highLevelIds=void 0}combineIntersectRect(n){let e=n;return this.curNodeMap.forEach(t=>{s.isIntersect(e,t.rect)&&(e=s.computRect(e,t.rect))}),e}setTargetAssignKeys(n){const e=new Map;for(const t of n){const o=this.curNodeMap.get(t);o&&e.set(t,s.cloneDeep(o))}return this.targetNodeMap.push(s.cloneDeep(e)),this.targetNodeMap.length-1}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(n){return this.targetNodeMap[n]}deleteTarget(n){this.targetNodeMap.length=n}clearTarget(){this.targetNodeMap.length=0}}class gt{constructor(n){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=n.vNodes,this.thread=n.thread}createLocalWork(n){const{workId:e,opt:t,toolsType:o}=n;if(e&&t){const i=e.toString();!this.getToolsOpt()&&o&&this.setToolsOpt({toolsType:o,toolsOpt:t}),this.setWorkOptions(i,t)}}getLocalWorkShape(n){return this.localWorkShapes.get(n)}createLocalWorkShape(n,e){if(n&&this.tmpOpt){const t={toolsType:this.tmpOpt.toolsType,toolsOpt:e||this.tmpOpt.toolsOpt},o=this.createWorkShapeNode({...t,workId:n});return o&&this.localWorkShapes.set(n,{node:o,toolsType:o.toolsType,workState:s.EvevtWorkState.Start}),o}}canUseTopLayer(n){return n===s.EToolsKey.LaserPen}destroy(){this.clearAll()}clearAll(){this.thread.topLayer.children.length&&(this.thread.topLayer.parent.children.forEach(n=>{n.name!=="viewport"&&n.remove()}),this.thread.serviceLayer.removeAllChildren()),this.serviceWorkShapes.clear(),this.localWorkShapes.clear()}consumeDraw(n){const{workId:e,dataType:t}=n;if(t===s.EDataType.Service)this.activeServiceWorkShape(n);else{const o=e==null?void 0:e.toString(),i=o&&this.localWorkShapes.get(o);if(!i)return;const r=i.node.consume({data:n,isFullWork:!1,isSubWorker:!0});r.rect&&(i.result=r,i.workState=s.EvevtWorkState.Doing,o&&this.localWorkShapes.set(o,i))}this.runAnimation()}setToolsOpt(n){var e;this.tmpOpt=n,(e=n.toolsOpt)!=null&&e.syncUnitTime&&(this.syncUnitTime=n.toolsOpt.syncUnitTime)}getToolsOpt(){return this.tmpOpt}createWorkShapeNode(n){const{toolsType:e}=n;if(e===s.EToolsKey.LaserPen)return le({...n,vNodes:this.vNodes,fullLayer:this.thread.topLayer,drawLayer:this.thread.topLayer})}setNodeKey(n,e,t,o){return e.toolsType=t,e.node=this.createWorkShapeNode({workId:n,toolsType:t,toolsOpt:o}),e}activeServiceWorkShape(n){var d,u;const{workId:e,opt:t,toolsType:o,type:i,updateNodeOpt:r,ops:a,op:c}=n;if(!e)return;const l=e.toString(),h=(d=this.vNodes.get(l))==null?void 0:d.rect;if(!((u=this.serviceWorkShapes)!=null&&u.has(l))){let f={toolsType:o,animationWorkData:c||[],animationIndex:0,type:i,updateNodeOpt:r,ops:a,oldRect:h};o&&t&&(f=this.setNodeKey(l,f,o,t)),this.serviceWorkShapes.set(l,f)}const p=this.serviceWorkShapes.get(l);i&&(p.type=i),a&&(p.animationWorkData=s.transformToNormalData(a),p.ops=a),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(n,e){var i;const t=((i=n.node)==null?void 0:i.syncUnitTime)||this.syncUnitTime,o=Math.floor((n.animationWorkData||[]).slice(n.animationIndex).length*32/e/t)*e;return Math.min((n.animationIndex||0)+(o||e),(n.animationWorkData||[]).length)}animationDraw(){var o,i,r,a;this.animationId=void 0;let n=!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),u=(l.animationWorkData||[]).slice(d,p);if((l.animationIndex||0)<p&&((o=l.node)==null||o.consumeService({op:u,isFullWork:!1}),l.animationIndex=p,u.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:u.slice(-2)})),l.isDel){(r=l.node)==null||r.clearTmpPoints(),this.serviceWorkShapes.delete(c);break}l.ops&&l.animationIndex===((a=l.animationWorkData)==null?void 0:a.length)&&!l.isDel&&(this.thread.topLayer.getElementsByName(c.toString())[0]||(l.isDel=!0,this.serviceWorkShapes.set(c,l))),n=!0;break}}for(const[c,l]of this.localWorkShapes.entries()){const{result:h,toolsType:p,isDel:d,workState:u}=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]&&u===s.EvevtWorkState.Done&&(l.isDel=!0,this.localWorkShapes.set(c,l)),n=!0;break}}}n&&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(n,e){var o;let t=(o=this.localWorkShapes.get(n))==null?void 0:o.node;if(!t&&this.tmpOpt){const{toolsType:i}=this.tmpOpt;this.tmpOpt.toolsOpt=e,t=this.createWorkShapeNode({workId:n,toolsType:i,toolsOpt:e}),t&&this.localWorkShapes.set(n,{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(n){const{workId:e,dataType:t}=n;if(t===s.EDataType.Service)this.activeServiceWorkShape(n);else{const o=e==null?void 0:e.toString(),i=o&&this.localWorkShapes.get(o);if(!i)return;const r=i.node.consumeAll({data:n});i.result=r,i.workState=s.EvevtWorkState.Done,o&&this.localWorkShapes.set(o,i)}this.runAnimation()}}class St{constructor(n){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=n.vNodes,this.thread=n.thread}createLocalWork(n){const{workId:e,opt:t,toolsType:o}=n;if(e&&t){const i=e.toString();!this.getToolsOpt()&&o&&this.setToolsOpt({toolsType:o,toolsOpt:t}),this.setWorkOptions(i,t)}}workShapesDone(n,e){for(const t of this.workShapes.keys())this.consumeDrawAll({workId:t,scenePath:n,viewId:this.thread.viewId,msgType:s.EPostMessageType.DrawWork,dataType:s.EDataType.Local},e)}async updateSelector(n){var u;const e=this.workShapes.get(s.Storage_Selector_key);if(!((u=e==null?void 0:e.selectIds)!=null&&u.length))return;const{callback:t,...o}=n,{updateSelectorOpt:i,willSerializeData:r,scene:a}=o,c=await(e==null?void 0:e.updateSelector({updateSelectorOpt:i,selectIds:q.cloneDeep(e.selectIds),vNodes:this.vNodes,willSerializeData:r,worker:this,scene:a,isMainThread:!0})),l=new Map;let h;c!=null&&c.selectIds&&(h=q.xor(e.selectIds,c.selectIds),c.selectIds.forEach(f=>{const S=this.vNodes.get(f);if(S){const{toolsType:y,op:g,opt:M}=S;l.set(f,{opt:M,toolsType:y,ops:(g==null?void 0:g.length)&&s.transformToSerializableData(g)||void 0})}}),e.selectIds=c.selectIds);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(n){const{op:e,viewId:t,dataType:o}=n;if(e!=null&&e.length){let i;for(const r of this.vNodes.curNodeMap.values()){const{rect:a,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],a)&&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(n){const{opt:e,toolsType:t,point:o}=n,i=this.setFullWork({workId:s.Cursor_Hover_Id,toolsType:t,opt:e});i&&o&&i.cursorHover(o)}updateFullSelectWork(n){var o,i,r,a,c;const e=this.workShapes.get(s.Storage_Selector_key),{selectIds:t}=n;if(!(t!=null&&t.length)){this.blurSelector(n);return}if(!e){const l=this.setFullWork(n);!l&&n.workId&&this.tmpOpt&&((o=this.tmpOpt)==null?void 0:o.toolsType)===s.EToolsKey.Selector&&this.setWorkOptions(n.workId.toString(),n.opt||this.tmpOpt.toolsOpt),l&&this.updateFullSelectWork(n);return}if(e&&(t!=null&&t.length)){const{selectRect:l}=e.updateSelectIds(t),h=[{...n,selectorColor:((i=n.opt)==null?void 0:i.strokeColor)||e.selectorColor,strokeColor:((r=n.opt)==null?void 0:r.strokeColor)||e.strokeColor,fillColor:((a=n.opt)==null?void 0:a.fillColor)||e.fillColor,textOpt:((c=n.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:(n==null?void 0:n.willSyncService)||!1,opt:(n==null?void 0:n.willSyncService)&&e.getWorkOptions()||void 0,canLock:e.canLock,isLocked:e.isLocked,toolsTypes:e.toolsTypes,shapeOpt:e.shapeOpt,thickness:e.thickness,useStroke:e.useStroke,strokeType:e.strokeType}];this.thread.post({sp:h})}}commandDeleteText(n){const e=this.vNodes.get(n);if(e&&e.toolsType===s.EToolsKey.Text)return{type:s.EPostMessageType.TextUpdate,toolsType:s.EToolsKey.Text,workId:n,dataType:s.EDataType.Local}}async removeSelector(n){const{willSyncService:e}=n,t=[],o=[],i=this.workShapes.get(s.Storage_Selector_key);if(!i)return;const r=i.selectIds&&[...i.selectIds]||[];for(const a of r){if(this.vNodes.get(a)){const l=this.commandDeleteText(a);l&&t.push(l)}this.removeNode(a),o.push(a)}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(n){const{workId:e}=n,t=e==null?void 0:e.toString();t&&this.removeNode(t)}removeNode(n){var o;this.vNodes.get(n)&&((o=this.thread.fullLayer)==null||o.getElementsByName(n).forEach(i=>{i.remove()}),this.vNodes.delete(n)),this.workShapes.has(n)&&(this.thread.localLayer.getElementsByName(n).forEach(i=>{i.remove()}),this.clearWorkShapeNodeCache(n))}setFullWork(n){const{workId:e,opt:t,toolsType:o}=n;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(n,e){var i;const t=this.setFullWork(n),o=n.ops&&s.transformToNormalData(n.ops);if(t){const r=(i=n.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}),n!=null&&n.updateNodeOpt&&t.updataOptService(n.updateNodeOpt);const a=[];n.workId&&this.workShapes.delete(n.workId.toString()),n.willSyncService&&a.push({opt:n.opt,toolsType:n.toolsType,type:s.EPostMessageType.FullWork,workId:n.workId,ops:n.ops,updateNodeOpt:n.updateNodeOpt,viewId:this.thread.viewId}),a.length&&this.thread.post({sp:a})}}async colloctEffectSelectWork(n){const e=this.workShapes.get(s.Storage_Selector_key),{workId:t,msgType:o}=n;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(n),await new Promise(i=>{setTimeout(()=>{i(!0)},0)}),await this.runEffectSelectWork(!0).then(()=>{var i;(i=this.effectSelectNodeData)==null||i.clear()});return}return n}async runEffectSelectWork(n){var e,t,o;for(const i of this.effectSelectNodeData.values()){const r=this.setFullWork(i);if(r){const a=(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:a,isMainThread:!0});else if(r.toolsType===s.EToolsKey.Text)await r.consumeServiceAsync({isFullWork:!0,replaceId:a});else{const c=i.ops&&s.transformToNormalData(i.ops);r.consumeService({op:c,isFullWork:!0,replaceId:a}),i!=null&&i.updateNodeOpt&&r.updataOptService(i.updateNodeOpt)}i.workId&&this.workShapes.delete(i.workId.toString())}}this.reRenderSelector(n)}hasSelector(){return this.workShapes.has(s.Storage_Selector_key)}getSelector(){return this.workShapes.get(s.Storage_Selector_key)}reRenderSelector(n=!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:n,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,thickness:e.thickness,useStroke:e.useStroke,strokeType:e.strokeType}]})}async blurSelector(n){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:n==null?void 0:n.isSync}),this.thread.post({sp:i})}}clearWorkShapeNodeCache(n){var e;(e=this.getWorkShape(n))==null||e.clearTmpPoints(),this.workShapes.delete(n)}drawEraser(n){var t,o;const e=[];if((t=n.newWorkDatas)!=null&&t.size){for(const i of n.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 n.newWorkDatas}(o=n.removeIds)==null||o.forEach(i=>{this.batchEraserRemoveNodes.add(i)}),e.push(n),this.thread.post({sp:e}),this.batchEraserCombine()}updateBatchEraserCombineNode(n,e){for(const t of e.keys())this.thread.fullLayer.getElementsByName(t).forEach(o=>{o.remove()});n.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(n){return this.workShapes.get(n)}getWorkShapes(){return this.workShapes}consumeDraw(n,e){const{op:t,workId:o,scenePath:i}=n;if(t!=null&&t.length&&o){const r=o.toString(),a=this.workShapes.get(r);if(!a)return;const c=a.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=a.consume({data:n,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=a.consume({data:n,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=a.consume({data:n,isFullWork:!1,isMainThread:!0});l&&(this.drawCount++,this.thread.post({drawCount:this.drawCount,sp:l.op&&[{...l,scenePath:i}]||void 0}))}break}}}consumeDrawAll(n,e){var i,r,a;const{workId:t,scenePath:o}=n;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],u=l.consumeAll({data:n});switch(h){case s.EToolsKey.Selector:u.selectIds&&d&&((r=u.selectIds)!=null&&r.includes(d))&&p.cursorBlur(),u.type===s.EPostMessageType.Select&&(u.selectIds&&e.runReverseSelectWork(u.selectIds),this.thread.post({sp:[{...u,scenePath:o}]})),(a=l.selectIds)!=null&&a.length?l.clearTmpPoints():this.clearWorkShapeNodeCache(c);break;case s.EToolsKey.Eraser:u!=null&&u.rect&&this.drawEraser({...u,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:u&&(this.drawCount=0,this.thread.post({drawCount:this.drawCount,sp:[u]})),this.clearWorkShapeNodeCache(c);break}}}getToolsOpt(){return this.tmpOpt}setToolsOpt(n){var e;this.tmpOpt=n,(e=n.toolsOpt)!=null&&e.syncUnitTime&&(this.syncUnitTime=n.toolsOpt.syncUnitTime)}setWorkOptions(n,e){let t=this.workShapes.get(n);if(!t&&this.tmpOpt){const{toolsType:o}=this.tmpOpt;this.tmpOpt.toolsOpt=e,t=this.createWorkShapeNode({workId:n,toolsType:o,toolsOpt:e}),t&&this.workShapes.set(n,t),this.setToolsOpt(this.tmpOpt)}e.syncUnitTime||(e.syncUnitTime=this.syncUnitTime),t==null||t.setWorkOptions(e)}createWorkShapeNode(n){return le({...n,vNodes:this.vNodes,fullLayer:this.thread.fullLayer,drawLayer:this.thread.localLayer},this.thread.serviceWork)}}class Tt{constructor(n){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=n.vNodes,this.thread=n.thread}destroy(){this.clearAll()}clearAll(){this.thread.serviceLayer.children.length&&(this.thread.serviceLayer.parent.children.forEach(n=>{n.name!=="viewport"&&n.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(n=>{var t,o;const e=this.selectorWorkShapes.get(n);e&&e.selectIds&&((t=e.node)==null||t.selectServiceNode(n,e,!0)),(o=e==null?void 0:e.selectIds)!=null&&o.length||this.selectorWorkShapes.delete(n)}),this.willRunEffectSelectorIds.clear()}runSelectWork(n){this.activeSelectorShape(n);const{workId:e}=n,t=e==null?void 0:e.toString();t&&this.willRunEffectSelectorIds.add(t),this.runEffect()}removeWork(n){const{workId:e}=n,t=e==null?void 0:e.toString();if(t){if(this.workShapes.get(t)){this.workShapes.delete(t),this.removeNode(t,n);return}this.removeNode(t,n)}}consumeFull(n){this.activeWorkShape(n),this.runAnimation()}runReverseSelectWork(n){n.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(n){this.activeWorkShape(n),this.runAnimation()}computNextAnimationIndex(n,e){const t=Math.floor((n.animationWorkData||[]).slice(n.animationIndex).length*32/e/this.syncUnitTime)*e;return Math.min((n.animationIndex||0)+(t||e),(n.animationWorkData||[]).length)}async animationDraw(){var t,o,i,r,a,c,l,h,p,d,u,f,S,y,g,M;this.animationId=void 0;let n=!1;const e=new Map;for(const[v,T]of this.workShapes.entries())switch(T.toolsType){case s.EToolsKey.Image:{await((o=T.node)==null?void 0:o.consumeServiceAsync({isFullWork:!0,scene:(t=this.thread.fullLayer.parent)==null?void 0:t.parent,isMainThread:!0})),this.selectorWorkShapes.forEach((w,E)=>{var R;(R=w.selectIds)!=null&&R.includes(v)&&(this.willRunEffectSelectorIds.add(E),this.runEffect())}),this.workShapes.delete(v);break}case s.EToolsKey.Text:{T.node&&(await((i=T.node)==null?void 0:i.consumeServiceAsync({isFullWork:!0,replaceId:v})),this.selectorWorkShapes.forEach((w,E)=>{var R;(R=w.selectIds)!=null&&R.includes(v)&&(this.willRunEffectSelectorIds.add(E),this.runEffect())}),(r=T.node)==null||r.clearTmpPoints(),this.workShapes.delete(v));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 w=!!T.ops;if((a=T.animationWorkData)!=null&&a.length){const E=T.oldRect;(c=T.node)==null||c.consumeService({op:T.animationWorkData,isFullWork:w}),w&&(this.selectorWorkShapes.forEach((R,L)=>{var I;(I=R.selectIds)!=null&&I.includes(v)&&(this.willRunEffectSelectorIds.add(L),this.runEffect())}),(l=T.node)==null||l.clearTmpPoints(),this.workShapes.delete(v)),e.set(v,{workState:E?T.ops?s.EvevtWorkState.Done:s.EvevtWorkState.Doing:s.EvevtWorkState.Start,op:T.animationWorkData.filter((R,L)=>{if(L%3!==2)return!0}).slice(-2)}),T.animationWorkData.length=0}break}case s.EToolsKey.Pencil:{if(!T.useAnimation&&T.ops)(h=T.node)==null||h.consumeService({op:T.animationWorkData||[],isFullWork:!0,replaceId:v}),(p=T.node)==null||p.updataOptService(T.updateNodeOpt),this.selectorWorkShapes.forEach((w,E)=>{var R;(R=w.selectIds)!=null&&R.includes(v)&&(this.willRunEffectSelectorIds.add(E),this.runEffect())}),(d=T.node)==null||d.clearTmpPoints(),this.workShapes.delete(v);else if(T.useAnimation){if(T.isDel){(u=T.node)==null||u.clearTmpPoints(),this.workShapes.delete(v);break}const w=3,E=this.computNextAnimationIndex(T,w),R=T.isDiff?0:Math.max(0,(T.animationIndex||0)-w),L=(T.animationWorkData||[]).slice(R,E),I=(S=(f=T.node)==null?void 0:f.getWorkId())==null?void 0:S.toString();if((T.animationIndex||0)<E||T.isDiff){if((y=T.node)==null||y.consumeService({op:L,isFullWork:!1}),T.animationIndex=E,T.isDiff&&(T.isDiff=!1),L.length){const N=L.filter((W,B)=>{if(B%w!==w-1)return!0}).slice(-2);e.set(v,{workState:R===0?s.EvevtWorkState.Start:E===((g=T.animationWorkData)==null?void 0:g.length)?s.EvevtWorkState.Done:s.EvevtWorkState.Doing,op:N})}}else T.ops&&((M=T.node)==null||M.consumeService({op:T.animationWorkData||[],isFullWork:!0,replaceId:I}),T.isDel=!0,e.set(v,{workState:s.EvevtWorkState.Done,op:L.filter((N,W)=>{if(W%w!==w-1)return!0}).slice(-2)}));n=!0;break}break}}if(n&&this.runAnimation(),e.size){const v=[];e.forEach((T,w)=>{v.push({type:s.EPostMessageType.Cursor,uid:w.split(s.Storage_Splitter)[0],op:T.op,workState:T.workState,viewId:this.thread.viewId})}),this.thread.post({sp:v})}}runAnimation(){this.animationId||(this.animationId=requestAnimationFrame(this.animationDraw.bind(this)))}hasDiffData(n,e,t){const o=n.length;if(e.length<o)return!0;switch(t){case s.EToolsKey.Pencil:{for(let i=0;i<o;i+=3)if(e[i]!==n[i]||e[i+1]!==n[i+1])return!0;break}case s.EToolsKey.LaserPen:{for(let i=0;i<o;i+=2)if(e[i]!==n[i]||e[i+1]!==n[i+1])return!0;break}}return!1}activeWorkShape(n){var u,f,S,y;const{workId:e,opt:t,toolsType:o,type:i,updateNodeOpt:r,ops:a,op:c,useAnimation:l}=n;if(!e)return;const h=e.toString(),p=(u=this.vNodes.get(h))==null?void 0:u.rect;if(!((f=this.workShapes)!=null&&f.has(h))){let g={toolsType:o,animationWorkData:c||[],animationIndex:0,type:i,updateNodeOpt:r,ops:a,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)),(S=this.workShapes)==null||S.set(h,g)}const d=(y=this.workShapes)==null?void 0:y.get(h);i&&(d.type=i),a&&(d.animationWorkData=s.transformToNormalData(a),d.ops=a),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(n,e){n.indexOf(s.Storage_Selector_key)>-1&&this.removeSelectWork(e),this.thread.fullLayer.getElementsByName(n).forEach(t=>{t.remove()}),this.thread.serviceLayer.getElementsByName(n).forEach(t=>{t.remove()}),this.vNodes.delete(n)}removeSelectWork(n){const{workId:e}=n,t=e==null?void 0:e.toString();t&&(this.activeSelectorShape(n),this.willRunEffectSelectorIds.add(t)),this.runEffect()}activeSelectorShape(n){var l,h,p;const{workId:e,opt:t,toolsType:o,type:i,selectIds:r}=n;if(!e)return;const a=e.toString();if(!((l=this.selectorWorkShapes)!=null&&l.has(a))){let d={toolsType:o,selectIds:r,type:i,opt:t};o&&t&&(d=this.setNodeKey(a,d,o,t)),(h=this.selectorWorkShapes)==null||h.set(a,d)}const c=(p=this.selectorWorkShapes)==null?void 0:p.get(a);i&&(c.type=i),c.node&&c.node.getWorkId()!==a&&c.node.setWorkId(a),c.selectIds=r||[]}setNodeKey(n,e,t,o){return e.toolsType=t,e.node=le({toolsType:t,toolsOpt:o,vNodes:this.vNodes,fullLayer:this.thread.fullLayer,drawLayer:this.thread.serviceLayer,workId:n},this),e}}class V{constructor(){m(this,"localWork");m(this,"serviceWork");m(this,"scene")}registerMainThread(n,e,t){return this.localWork=n,this.serviceWork=e,this.scene=t,this}}class wt extends V{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 kt extends V{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:a,textUpdateForWoker:c}=e;t===s.Storage_Selector_key&&o&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:a,textUpdateForWoker:c,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i}=e,{willSyncService:r,isSync:a,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:a});return{sp:l}}}class Pt extends V{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:a}=e;t===s.Storage_Selector_key&&o&&await((c=this.localWork)==null?void 0:c.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:a,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i}=e,{willSyncService:r,isSync:a}=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:a});return{sp:c}}}class vt extends V{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:a,textUpdateForWoker:c,emitEventType:l}=e;t===s.Storage_Selector_key&&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:a,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:a}=e,{willSyncService:c,isSync:l,updateSelectorOpt:h,textUpdateForWoker:p}=t,d=h.workState,u=o.sp||[];if(d===s.EvevtWorkState.Start)return{sp:[],render:[]};const f=a==null?void 0:a.selectRect;if(c){d===s.EvevtWorkState.Doing&&u.push({type:s.EPostMessageType.Select,selectIds:r.selectIds,selectRect:f,willSyncService:!0,isSync:!0,points:r.getChildrenPoints(),textOpt:r.textOpt});for(const[S,y]of i.entries())p&&y.toolsType===s.EToolsKey.Text?u.push({...y,workId:S,type:s.EPostMessageType.TextUpdate,dataType:s.EDataType.Local,willSyncService:!0}):u.push({...y,workId:S,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l})}return{sp:u}}}class Et extends V{constructor(){super(...arguments);m(this,"emitEventType",s.EmitEventType.DeleteNode)}async consume(){return!1}}class It extends V{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 a;const{workId:t,updateNodeOpt:o,willSyncService:i,willSerializeData:r}=e;t===s.Storage_Selector_key&&o&&await((a=this.localWork)==null?void 0:a.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:a}=e,{updateSelectorOpt:c,willSyncService:l}=t,h=c.workState,p=o.sp||[],d=r==null?void 0:r.selectRect;if(h===s.EvevtWorkState.Start)return{sp:[],render:[]};if(l){p.push({type:s.EPostMessageType.Select,selectIds:i.selectIds,selectRect:d,willSyncService:!0,isSync:!0,points:h===s.EvevtWorkState.Done&&i.getChildrenPoints()||void 0,textOpt:i.textOpt});for(const[u,f]of a.entries())f.toolsType===s.EToolsKey.Text?p.push({...f,workId:u,type:s.EPostMessageType.TextUpdate,dataType:s.EDataType.Local,willSyncService:!0}):p.push({...f,workId:u,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:!0})}return{sp:p}}}class Mt extends V{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:a,emitEventType:c}=e;t===s.Storage_Selector_key&&o&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:a,emitEventType:c,isSync:!0,scene:this.scene,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,workShapeNode:i,res:r,newServiceStore:a}=e,{updateSelectorOpt:c,willSyncService:l,willSerializeData:h,isSync:p}=t,d=c.workState,u=o.sp||[],f=r==null?void 0:r.selectRect;if(l){h&&d===s.EvevtWorkState.Done&&u.push({type:s.EPostMessageType.Select,selectIds:i.selectIds,selectRect:f,willSyncService:!0,isSync:p,points:i.getChildrenPoints()});for(const[S,y]of a.entries())u.push({...y,workId:S,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:p})}return{sp:u}}}class Lt extends V{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:a,textUpdateForWoker:c}=e;t===s.Storage_Selector_key&&o&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:a,textUpdateForWoker:c,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i,workShapeNode:r,res:a}=e,{willSyncService:c,isSync:l,updateSelectorOpt:h,textUpdateForWoker:p}=t,d=o.sp||[],u=a==null?void 0:a.selectRect;if(c&&d){h.fontSize&&d.push({type:s.EPostMessageType.Select,selectIds:r.selectIds,selectRect:u,willSyncService:c,isSync:l,points:r.getChildrenPoints()});for(const[f,S]of i.entries())p&&S.toolsType===s.EToolsKey.Text?d.push({...S,workId:f,type:s.EPostMessageType.TextUpdate,dataType:s.EDataType.Local,willSyncService:!0}):d.push({...S,workId:f,type:s.EPostMessageType.UpdateNode,updateNodeOpt:{useAnimation:!1},isSync:l})}return{sp:d}}}class Rt extends V{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:a,textUpdateForWoker:c}=e;t===s.Storage_Selector_key&&o&&await((l=this.localWork)==null?void 0:l.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,emitEventType:this.emitEventType,willSerializeData:a,isSync:!0,textUpdateForWoker:c,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i,workShapeNode:r,res:a}=e,{willSyncService:c,isSync:l}=t,h=o.sp||[],p=a==null?void 0:a.selectRect;if(c&&h){for(const[d,u]of i.entries())h.push({...u,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 Nt extends V{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:a}=e;t===s.Storage_Selector_key&&o&&await((c=this.localWork)==null?void 0:c.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:a,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i,workShapeNode:r,res:a}=e,{willSyncService:c,isSync:l,updateSelectorOpt:h}=t,p=o.sp||[],d=a==null?void 0:a.selectRect;if(c&&p){for(const[u,f]of i.entries())p.push({...f,workId:u,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 Wt extends V{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:a}=e;t===s.Storage_Selector_key&&o&&await((c=this.localWork)==null?void 0:c.updateSelector({updateSelectorOpt:o,willRefreshSelector:i,willSyncService:r,willSerializeData:a,callback:this.updateSelectorCallback}))}updateSelectorCallback(e){const{param:t,postData:o,newServiceStore:i}=e,{willSyncService:r,isSync:a}=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:a});return{sp:c}}}class bt{constructor(n){m(this,"builders",new Map);this.builders=new Map(n.map(e=>[e,this.build(e)]))}build(n){switch(n){case s.EmitEventType.TranslateNode:return new vt;case s.EmitEventType.ZIndexNode:return new Pt;case s.EmitEventType.CopyNode:return new wt;case s.EmitEventType.SetColorNode:return new kt;case s.EmitEventType.DeleteNode:return new Et;case s.EmitEventType.ScaleNode:return new It;case s.EmitEventType.RotateNode:return new Mt;case s.EmitEventType.SetFontStyle:return new Lt;case s.EmitEventType.SetPoint:return new Rt;case s.EmitEventType.SetLock:return new Nt;case s.EmitEventType.SetShapeOpt:return new Wt}}registerForMainThread(n,e,t){return this.builders.forEach(o=>{o&&o.registerMainThread(n,e,t)}),this}async consumeForMainThread(n){for(const e of this.builders.values())if(await(e==null?void 0:e.consume(n)))return!0;return!1}}class xt{constructor(n,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=n,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 mt(n,this.scene);const i={thread:this,vNodes:this.vNodes};this.localWork=new St(i),this.serviceWork=new Tt(i),this.topWork=new gt(i),this.vNodes.init(this.fullLayer),this.methodBuilder=new bt([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(n){this.combinePostMsg.add(n),this.runBatchPostData()}async on(n){if(!await this.methodBuilder.consumeForMainThread(n)){const{msgType:e,toolsType:t,opt:o,dataType:i,workId:r,workState:a}=n,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(n);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:a===s.EvevtWorkState.Done&&i===s.EDataType.Local?this.consumeDrawAll(i,n):this.consumeDraw(i,n);break;case s.EPostMessageType.UpdateNode:case s.EPostMessageType.FullWork:if(t&&this.topWork.canUseTopLayer(t)){this.consumeDrawAll(i,n);break}this.consumeFull(i,n);break;case s.EPostMessageType.RemoveNode:await this.removeNode(n);return;case s.EPostMessageType.Select:i===s.EDataType.Service&&(r===s.Storage_Selector_key?this.localWork.updateFullSelectWork(n):this.serviceWork.runSelectWork(n));break;case s.EPostMessageType.CursorHover:this.localWork.cursorHover(n);break;case s.EPostMessageType.GetTextActive:i===s.EDataType.Local&&this.localWork.checkTextActive(n);break}}}async removeNode(n){const{dataType:e,workId:t,removeIds:o}=n,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(n);continue}e===s.EDataType.Local?this.localWork.removeWork(n):e===s.EDataType.Service&&this.serviceWork.removeWork(n),await this.localWork.colloctEffectSelectWork(n)}}async consumeFull(n,e){const t=await this.localWork.colloctEffectSelectWork(e);t&&n===s.EDataType.Local&&await this.localWork.consumeFull(t,this.scene),t&&n===s.EDataType.Service&&this.serviceWork.consumeFull(t)}setCameraOpt(n){this.cameraOpt=n;const{scale:e,centerX:t,centerY:o,width:i,height:r}=n;(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 n=[];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 a of n)if(q.isEqual(i,a)){r=!0;break}r||n.push(i)}q.isNumber(o.drawCount)&&(e=o.drawCount)}return this.combinePostMsg.clear(),{sp:n,drawCount:e}}combinePost(){var t,o;const n=this.combinePostData(),e=(t=n.sp)==null?void 0:t.filter(i=>i.type!==s.EPostMessageType.None);e!=null&&e.length?n.sp=e.map(i=>i.viewId?i:{...i,viewId:this.viewId}):delete n.sp,n.drawCount===void 0&&delete n.drawCount,(n!=null&&n.drawCount||(o=n.sp)!=null&&o.length)&&this.opt.post(n)}clearAll(){this.fullLayer.children.length&&(this.fullLayer.parent.children.forEach(n=>{n.name!=="viewport"&&n.remove()}),this.fullLayer.removeAllChildren()),this.localWork.clearAll(),this.topWork.clearAll(),this.serviceWork.clearAll(),this.vNodes.clear(),this.post({sp:[{type:s.EPostMessageType.Clear}]})}consumeDrawAll(n,e){const{toolsType:t,workId:o}=e;if(o){const i=o.toString();if(t&&this.topWork.canUseTopLayer(t)){n===s.EDataType.Local&&(this.topWork.getLocalWorkShape(o.toString())||this.topWork.createLocalWork(e)),this.topWork.consumeDrawAll(e);return}n===s.EDataType.Local&&(this.localWork.getWorkShape(i)||this.localWork.createLocalWork(e),this.localWork.consumeDrawAll(e,this.serviceWork))}}consumeDraw(n,e){const{opt:t,workId:o,toolsType:i}=e;if(o&&i&&t){const r=o.toString();if(this.topWork.canUseTopLayer(i)){n===s.EDataType.Local&&(this.topWork.getLocalWorkShape(r)||this.topWork.createLocalWork(e)),this.topWork.consumeDraw(e);return}n===s.EDataType.Local?(this.localWork.getWorkShape(r)||this.localWork.createLocalWork(e),this.localWork.consumeDraw(e,this.serviceWork)):n===s.EDataType.Service&&this.serviceWork.consumeDraw(e);return}}async updateCamera(n){var o;const{cameraOpt:e,scenePath:t}=n;if(e&&!q.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(n)},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,q.cloneDeep(p))}const r=new Set(i.keys());let a=!1;if(this.localWork.hasSelector()){const l=(o=this.localWork.getSelector())==null?void 0:o.selectIds;if(l){a=!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,u=p.rect,f=this.getSceneRect(),S=s.getRectMatrixrRelation(d,f),y=s.getRectMatrixrRelation(u,f);let g=!1;if((S!==y||d.w!==u.w||d.h!==u.h||y===s.EMatrixrRelationType.intersect)&&(g=!0),g){const{toolsType:M,opt:v}=p;M===s.EToolsKey.Text&&v.workState===s.EvevtWorkState.Done&&this.debounceUpdateCache.add(l)}}}if(a&&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 u=this.vNodes.get(p);if(u){const{toolsType:f,opt:S,rect:y}=u,g=this.localWork.setFullWork({toolsType:f,opt:S,workId:p});if(g){const M=this.getSceneRect(),v=s.getRectMatrixrRelation(y,M);l.push(g.consumeServiceAsync({isFullWork:!0,replaceId:p,isDrawLabel:v!==s.EMatrixrRelationType.outside}))}}}this.debounceUpdateCache.delete(p)}this.vNodes.updateLowLevelNodesRect(),this.vNodes.clearHighLevelIds()},s.Task_Time_Interval)}}}getSceneRect(){const{width:n,height:e}=this.scene;return{x:0,y:0,w:Math.floor(n),h:Math.floor(e)}}createScene(n){return new b.Scene({displayRatio:this.opt.displayer.dpr,depth:!1,desynchronized:!0,...n,autoRender:!0,id:this.viewId})}createLayer(n,e,t){const{width:o,height:i}=t,r=`canvas-${n}`,a=e.layer(r,{...t,offscreen:!1}),c=new b.Group({anchor:[.5,.5],pos:[o*.5,i*.5],size:[o,i],name:"viewport",id:n});return a.append(c),c}updateScene(n){this.scene.attr({...n});const{width:e,height:t}=n;this.scene.width=e,this.scene.height=t,this.updateLayer({width:e,height:t})}updateLayer(n){const{width:e,height:t}=n;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 Dt{constructor(n,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=n,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(n){this.combinePostMsg.add(n),this.runBatchPostData()}async on(n){const{msgType:e}=n;switch(e){case s.EPostMessageType.Snapshot:await this.getSnapshot(n),this.destroy();return;case s.EPostMessageType.BoundingBox:await this.getBoundingRect(n),this.destroy();return}}createWorkShapeNode(n){return le({...n,fullLayer:this.fullLayer,drawLayer:void 0})}setFullWork(n){const{workId:e,opt:t,toolsType:o}=n;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(n){var o,i;const e=this.setFullWork(n),t=n.ops&&s.transformToNormalData(n.ops);if(e){let r,a;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}),a=(n==null?void 0:n.updateNodeOpt)&&e.updataOptService(n.updateNodeOpt)),s.computRect(r,a)}}async getSnapshot(n){const{scenePath:e,scenes:t,cameraOpt:o,w:i,h:r}=n;if(e&&t&&o){this.setCameraOpt(o);let a;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});a=s.computRect(a,d);break}}let c;i&&r&&(c={resizeWidth:i,resizeHeight:r}),await this.getSnapshotRender({scenePath:e,options:c})}}getSceneRect(){const{width:n,height:e}=this.scene;return{x:0,y:0,w:Math.floor(n),h:Math.floor(e)}}getRectImageBitmap(n,e){const t=Math.floor(n.x*this.opt.displayer.dpr),o=Math.floor(n.y*this.opt.displayer.dpr),i=n.w>0&&Math.floor(n.w*this.opt.displayer.dpr||1)||1,r=n.h>0&&Math.floor(n.h*this.opt.displayer.dpr||1)||1;return createImageBitmap(this.fullLayer.parent.canvas,t,o,i,r,e)}async getSnapshotRender(n){var i,r;const{scenePath:e,options:t}=n;((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(n){const{scenePath:e,scenes:t,cameraOpt:o}=n;if(e&&t&&o){this.setCameraOpt(o);let i;for(const[r,a]of Object.entries(t))if(a!=null&&a.type)switch(a==null?void 0:a.type){case s.EPostMessageType.UpdateNode:case s.EPostMessageType.FullWork:{const c=await this.runFullWork({...a,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(n){const{scale:e,centerX:t,centerY:o,width:i,height:r}=n;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 n=[];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 n)if(J(o,r)){i=!0;break}i||n.push(o)}return this.combinePostMsg.clear(),{sp:n}}combinePost(){var t,o;const n=this.combinePostData(),e=(t=n.sp)==null?void 0:t.filter(i=>i.type!==s.EPostMessageType.None);e!=null&&e.length?n.sp=e.map(i=>i.viewId?i:{...i,viewId:this.viewId}):delete n.sp,(n!=null&&n.drawCount||(o=n.sp)!=null&&o.length)&&this.opt.post(n)}createScene(n){return new b.Scene({displayRatio:this.opt.displayer.dpr,depth:!1,desynchronized:!0,...n,autoRender:!1})}createLayer(n,e,t){const{width:o,height:i}=t,r=`canvas-${n}`,a=e.layer(r,t),c=new b.Group({anchor:[.5,.5],pos:[o*.5,i*.5],size:[o,i],name:"viewport",id:n});return a.append(c),c}updateScene(n){this.scene.attr({...n});const{width:e,height:t}=n;this.scene.width=e,this.scene.height=t,this.updateLayer({width:e,height:t})}updateLayer(n){const{width:e,height:t}=n;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 Ct{constructor(n){m(this,"mainThreadMap",new Map);m(this,"snapshotThread");m(this,"master");this.master=n}post(n){const{drawCount:e,sp:t,workerTasksqueueCount:o}=n;this.master.isBusy&&z(o)&&this.master.setWorkerTasksqueueCount(o),z(e)&&this.master.setMaxDrawCount(e),t&&this.master.collectorSyncData(t)}destroy(){this.mainThreadMap.clear()}createMainThread(n,e){return new xt(n,e)}createSnapshotThread(n,e){return new Dt(n,e)}async consume(n){var e,t,o,i;for(const r of n.values()){const{msgType:a,viewId:c,tasksqueue:l,mainTasksqueueCount:h,layerOpt:p,offscreenCanvasOpt:d,cameraOpt:u}=r;if(a===s.EPostMessageType.Console){console.log(this);continue}if(a===s.EPostMessageType.Init){const S=(e=this.master.control.viewContainerManager.getView(c))==null?void 0:e.displayer,y=S==null?void 0:S.canvasContainerRef.current;if(S&&y&&p&&d){const g=this.createMainThread(c,{displayer:S,container:y,layerOpt:p,master:this.master,canvasOpt:d,post:this.post.bind(this)});this.mainThreadMap.set(c,g),g&&u&&g.setCameraOpt(u)}continue}if((a===s.EPostMessageType.Snapshot||a===s.EPostMessageType.BoundingBox)&&c===((t=this.master.control.viewContainerManager.mainView)==null?void 0:t.id)){const S=(o=this.master.control.viewContainerManager.getView(c))==null?void 0:o.displayer,y=(i=S.snapshotContainerRef)==null?void 0:i.current;if(S&&y&&u){y.style.width=`${u.width}px`,y.style.height=`${u.height}px`;const g={...s.ViewContainerManager.defaultLayerOpt,offscreen:!1,width:u.width,height:u.height},M={...s.ViewContainerManager.defaultScreenCanvasOpt,width:u.width,height:u.height};this.snapshotThread=this.createSnapshotThread(c,{displayer:S,container:y,layerOpt:g,master:this.master,canvasOpt:M,post:this.post.bind(this)}),this.snapshotThread.on(r).then(()=>{this.snapshotThread=void 0,y.innerHTML="",y.style.width="",y.style.height=""});continue}}if(a===s.EPostMessageType.TasksQueue&&(l!=null&&l.size)){for(const[S,y]of this.mainThreadMap.entries()){const g=l.get(S);g&&(await y.on(g),h&&this.post({workerTasksqueueCount:h}))}continue}if(c===s.Storage_ViewId_ALL){for(const S of this.mainThreadMap.values())S.on(r),a===s.EPostMessageType.Destroy&&this.mainThreadMap.delete(c);continue}const f=this.mainThreadMap.get(c);f&&(f.on(r),a===s.EPostMessageType.Destroy&&this.mainThreadMap.delete(c))}}}exports.MainThreadManagerImpl=Ct;