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