@netless/appliance-plugin 1.1.17-beta.9 → 1.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/cdn/cdn.js +1 -1
  2. package/cdn/fullWorker-CTwuMS.js +500 -0
  3. package/cdn/subWorker-D7gqd9.js +500 -0
  4. package/dist/appliance-plugin.js +1 -1
  5. package/dist/appliance-plugin.mjs +1 -1
  6. package/dist/collector/collector.d.ts +1 -0
  7. package/dist/component/textEditor/manager.d.ts +1 -0
  8. package/dist/component/textEditor/view.d.ts +27 -47
  9. package/dist/core/mainEngine.d.ts +3 -1
  10. package/dist/core/tools/selector.d.ts +29 -0
  11. package/dist/core/types.d.ts +1 -0
  12. package/dist/core/worker/base.d.ts +5 -0
  13. package/dist/core/worker/fullWorkerLocal.d.ts +0 -1
  14. package/dist/core/worker/subWorkerLocal.d.ts +1 -0
  15. package/dist/cursors/index.d.ts +0 -4
  16. package/dist/displayer/const.d.ts +1 -0
  17. package/dist/displayer/floatBar/dragBox/index.d.ts +7 -1
  18. package/dist/displayer/floatBar/index.d.ts +1 -1
  19. package/dist/displayer/utils.d.ts +1 -0
  20. package/dist/fullWorker.js +120 -122
  21. package/dist/index-BqLItWo1.js +1 -0
  22. package/dist/{index-BianYC4r.mjs → index-D5p9NBLd.mjs} +10 -3
  23. package/dist/{index-CZ7SSEYU.mjs → index-DGks_HwI.mjs} +7355 -7106
  24. package/dist/index-DI0wKkQa.js +1 -0
  25. package/dist/plugin/baseApplianceManager.d.ts +7 -4
  26. package/dist/plugin/baseViewContainerManager.d.ts +6 -2
  27. package/dist/plugin/const.d.ts +5 -0
  28. package/dist/plugin/displayerView.d.ts +9 -2
  29. package/dist/plugin/types.d.ts +25 -6
  30. package/dist/style.css +1 -1
  31. package/dist/subWorker.js +120 -122
  32. package/package.json +5 -4
  33. package/cdn/fullWorker-p8Ghqw.js +0 -502
  34. package/cdn/subWorker-C1Gs0N.js +0 -502
  35. package/dist/collector/eventCollector.d.ts +0 -31
  36. package/dist/collector/magixEventCollector.d.ts +0 -31
  37. package/dist/index-BSGcWUci.js +0 -1
  38. package/dist/index-DDtbIS6S.js +0 -1
@@ -0,0 +1 @@
1
+ "use strict";var kn=Object.defineProperty;var xn=(r,s,e)=>s in r?kn(r,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[s]=e;var M=(r,s,e)=>xn(r,typeof s!="symbol"?s+"":s,e);const X=require("white-web-sdk"),he=require("spritejs"),wo=require("lz-string"),it=require("clipper-lib"),_s=require("lineclip"),Us=require("eventemitter2"),O=require("lodash"),y=require("react"),Ts=require("react-dom"),Yt=require("react-draggable"),Dn=require("xss"),Ln=require("re-resizable"),bn="/fullWorker.js",jn="/subWorker.js";var re=(r=>(r.selector="selector",r.clicker="clicker",r.laserPointer="laserPointer",r.pencil="pencil",r.rectangle="rectangle",r.ellipse="ellipse",r.shape="shape",r.eraser="eraser",r.pencilEraser="pencilEraser",r.text="text",r.straight="straight",r.arrow="arrow",r.hand="hand",r.laserPen="laserPen",r))(re||{}),oe=(r=>(r.Normal="Normal",r.Stroke="Stroke",r.Dotted="Dotted",r.LongDotted="LongDotted",r))(oe||{}),Ke=(r=>(r.Triangle="triangle",r.Rhombus="rhombus",r.Pentagram="pentagram",r.SpeechBalloon="speechBalloon",r.Star="star",r.Polygon="polygon",r))(Ke||{}),V=(r=>(r.None="None",r.ShowFloatBar="ShowFloatBar",r.ZIndexFloatBar="ZIndexFloatBar",r.DeleteNode="DeleteNode",r.CopyNode="CopyNode",r.ZIndexActive="ZIndexActive",r.ZIndexNode="ZIndexNode",r.RotateNode="RotateNode",r.SetColorNode="SetColorNode",r.TranslateNode="TranslateNode",r.ScaleNode="ScaleNode",r.OriginalEvent="OriginalEvent",r.CreateScene="CreateScene",r.ActiveCursor="ActiveCursor",r.MoveCursor="MoveCursor",r.CommandEditor="CommandEditor",r.SetEditorData="SetEditorData",r.SetFontStyle="SetFontStyle",r.SetPoint="SetPoint",r.SetLock="SetLock",r.SetShapeOpt="SetShapeOpt",r.CameraChange="CameraChange",r.ActiveMethod="ActiveMethod",r.HidFloatBarBtn="HidFloatBarBtn",r))(V||{}),ne=(r=>(r.DisplayState="DisplayState",r.MainEngine="MainEngine",r.Cursor="Cursor",r.BindMainView="BindMainView",r))(ne||{}),Io=(r=>(r[r.MainView=0]="MainView",r[r.Plugin=1]="Plugin",r[r.Both=2]="Both",r))(Io||{}),vs=(r=>(r.longPencil="longPencil",r))(vs||{}),T=(r=>(r[r.Pencil=1]="Pencil",r[r.Eraser=2]="Eraser",r[r.PencilEraser=3]="PencilEraser",r[r.BitMapEraser=4]="BitMapEraser",r[r.Selector=5]="Selector",r[r.Clicker=6]="Clicker",r[r.Arrow=7]="Arrow",r[r.Hand=8]="Hand",r[r.LaserPen=9]="LaserPen",r[r.Text=10]="Text",r[r.Straight=11]="Straight",r[r.Rectangle=12]="Rectangle",r[r.Ellipse=13]="Ellipse",r[r.Star=14]="Star",r[r.Triangle=15]="Triangle",r[r.Rhombus=16]="Rhombus",r[r.Polygon=17]="Polygon",r[r.SpeechBalloon=18]="SpeechBalloon",r[r.Image=19]="Image",r))(T||{}),B=(r=>(r[r.Local=1]="Local",r[r.Service=2]="Service",r[r.Worker=3]="Worker",r))(B||{}),j=(r=>(r[r.Pending=0]="Pending",r[r.Start=1]="Start",r[r.Doing=2]="Doing",r[r.Done=3]="Done",r[r.Unwritable=4]="Unwritable",r))(j||{}),D=(r=>(r[r.None=0]="None",r[r.Init=1]="Init",r[r.UpdateCamera=2]="UpdateCamera",r[r.UpdateTools=3]="UpdateTools",r[r.CreateWork=4]="CreateWork",r[r.DrawWork=5]="DrawWork",r[r.FullWork=6]="FullWork",r[r.UpdateNode=7]="UpdateNode",r[r.RemoveNode=8]="RemoveNode",r[r.Clear=9]="Clear",r[r.Select=10]="Select",r[r.Destroy=11]="Destroy",r[r.Snapshot=12]="Snapshot",r[r.BoundingBox=13]="BoundingBox",r[r.Cursor=14]="Cursor",r[r.TextUpdate=15]="TextUpdate",r[r.GetTextActive=16]="GetTextActive",r[r.TasksQueue=17]="TasksQueue",r[r.CursorHover=18]="CursorHover",r[r.CursorBlur=19]="CursorBlur",r[r.Console=20]="Console",r[r.PriorityWorker=21]="PriorityWorker",r[r.PriorityMainThreadWorker=22]="PriorityMainThreadWorker",r[r.GetImageBitMap=23]="GetImageBitMap",r[r.AuthWriter=24]="AuthWriter",r[r.AuthReader=25]="AuthReader",r[r.AuthClear=26]="AuthClear",r[r.AuthPage=27]="AuthPage",r[r.GetVNodeInfo=28]="GetVNodeInfo",r[r.UpdateDpr=29]="UpdateDpr",r))(D||{}),me=(r=>(r[r.None=0]="None",r[r.Bg=1]="Bg",r[r.ServiceFloat=2]="ServiceFloat",r[r.Float=3]="Float",r[r.TopFloat=4]="TopFloat",r))(me||{}),Jt=(r=>(r[r.Cursor=1]="Cursor",r[r.TextCreate=2]="TextCreate",r))(Jt||{}),qt=(r=>(r[r.Top=1]="Top",r[r.Bottom=2]="Bottom",r))(qt||{}),ce=(r=>(r[r.none=1]="none",r[r.all=2]="all",r[r.both=3]="both",r[r.proportional=4]="proportional",r))(ce||{}),To=(r=>(r[r.Pending=0]="Pending",r[r.Start=1]="Start",r[r.Doing=2]="Doing",r[r.Done=3]="Done",r[r.Unwritable=4]="Unwritable",r))(To||{}),Nt=(r=>(r[r.inside=0]="inside",r[r.outside=1]="outside",r[r.intersect=2]="intersect",r))(Nt||{}),Ye=(r=>(r.renderPage="renderPage",r.addPage="addPage",r.deletePage="deletePage",r.addElement="addElement",r.deleteElement="deleteElement",r.clearPage="clearPage",r.clearViewScenePath="clearViewScenePath",r.clearView="clearView",r))(Ye||{}),et=(r=>(r.setAuth="setAuth",r.setShow="addShow",r.setHide="setHide",r.setClear="setClear",r))(et||{}),St=(r=>(r.Image="image",r.Iconify="iconify",r))(St||{});const An={linear:r=>r,easeInQuad:r=>r*r,easeOutQuad:r=>r*(2-r),easeInOutQuad:r=>r<.5?2*r*r:-1+(4-2*r)*r,easeInCubic:r=>r*r*r,easeOutCubic:r=>--r*r*r+1,easeInOutCubic:r=>r<.5?4*r*r*r:(r-1)*(2*r-2)*(2*r-2)+1,easeInQuart:r=>r*r*r*r,easeOutQuart:r=>1- --r*r*r*r,easeInOutQuart:r=>r<.5?8*r*r*r*r:1-8*--r*r*r*r,easeInQuint:r=>r*r*r*r*r,easeOutQuint:r=>1+--r*r*r*r*r,easeInOutQuint:r=>r<.5?16*r*r*r*r*r:1+16*--r*r*r*r*r,easeInSine:r=>1-Math.cos(r*Math.PI/2),easeOutSine:r=>Math.sin(r*Math.PI/2),easeInOutSine:r=>-(Math.cos(Math.PI*r)-1)/2,easeInExpo:r=>r<=0?0:Math.pow(2,10*r-10),easeOutExpo:r=>r>=1?1:1-Math.pow(2,-10*r),easeInOutExpo:r=>r<=0?0:r>=1?1:r<.5?Math.pow(2,20*r-10)/2:(2-Math.pow(2,-20*r+10))/2};class k{constructor(s=0,e=0,t=1){this.x=s,this.y=e,this.z=t}get XY(){return[this.x,this.y]}setz(s){return this.z=s,this}setXY(s=this.x,e=this.y){return this.x=s,this.y=e,this}set(s=this.x,e=this.y,t=this.z){return this.x=s,this.y=e,this.z=t,this}setTo({x:s=0,y:e=0,z:t=1}){return this.x=s,this.y=e,this.z=t,this}rot(s){if(s===0)return this;const{x:e,y:t}=this,i=Math.sin(s),o=Math.cos(s);return this.x=e*o-t*i,this.y=e*i+t*o,this}rotWith(s,e){if(e===0)return this;const t=this.x-s.x,i=this.y-s.y,o=Math.sin(e),n=Math.cos(e);return this.x=s.x+(t*n-i*o),this.y=s.y+(t*o+i*n),this}clone(){const{x:s,y:e,z:t}=this;return new k(s,e,t)}sub(s){return this.x-=s.x,this.y-=s.y,this}subXY(s,e){return this.x-=s,this.y-=e,this}subScalar(s){return this.x-=s,this.y-=s,this}add(s){return this.x+=s.x,this.y+=s.y,this}addXY(s,e){return this.x+=s,this.y+=e,this}addScalar(s){return this.x+=s,this.y+=s,this}clamp(s,e){return this.x=Math.max(this.x,s),this.y=Math.max(this.y,s),e!==void 0&&(this.x=Math.min(this.x,e),this.y=Math.min(this.y,e)),this}div(s){return this.x/=s,this.y/=s,this}divV(s){return this.x/=s.x,this.y/=s.y,this}mul(s){return this.x*=s,this.y*=s,this}mulV(s){return this.x*=s.x,this.y*=s.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(s,e){const t=k.Tan(s,this);return this.add(t.mul(e))}neg(){return this.x*=-1,this.y*=-1,this}cross(s){return this.x=this.y*s.z-this.z*s.y,this.y=this.z*s.x-this.x*s.z,this}dpr(s){return k.Dpr(this,s)}cpr(s){return k.Cpr(this,s)}len2(){return k.Len2(this)}len(){return k.Len(this)}pry(s){return k.Pry(this,s)}per(){const{x:s,y:e}=this;return this.x=e,this.y=-s,this}uni(){return k.Uni(this)}tan(s){return k.Tan(this,s)}dist(s){return k.Dist(this,s)}distanceToLineSegment(s,e){return k.DistanceToLineSegment(s,e,this)}slope(s){return k.Slope(this,s)}snapToGrid(s){return this.x=Math.round(this.x/s)*s,this.y=Math.round(this.y/s)*s,this}angle(s){return k.Angle(this,s)}toAngle(){return k.ToAngle(this)}lrp(s,e){return this.x=this.x+(s.x-this.x)*e,this.y=this.y+(s.y-this.y)*e,this}equals(s,e){return k.Equals(this,s,e)}equalsXY(s,e){return k.EqualsXY(this,s,e)}norm(){const s=this.len();return this.x=s===0?0:this.x/s,this.y=s===0?0:this.y/s,this}toFixed(){return k.ToFixed(this)}toString(){return k.ToString(k.ToFixed(this))}toJson(){return k.ToJson(this)}toArray(){return k.ToArray(this)}static Add(s,e){return new k(s.x+e.x,s.y+e.y)}static AddXY(s,e,t){return new k(s.x+e,s.y+t)}static Sub(s,e){return new k(s.x-e.x,s.y-e.y)}static SubXY(s,e,t){return new k(s.x-e,s.y-t)}static AddScalar(s,e){return new k(s.x+e,s.y+e)}static SubScalar(s,e){return new k(s.x-e,s.y-e)}static Div(s,e){return new k(s.x/e,s.y/e)}static Mul(s,e){return new k(s.x*e,s.y*e)}static DivV(s,e){return new k(s.x/e.x,s.y/e.y)}static MulV(s,e){return new k(s.x*e.x,s.y*e.y)}static Neg(s){return new k(-s.x,-s.y)}static Per(s){return new k(s.y,-s.x)}static Dist2(s,e){return k.Sub(s,e).len2()}static Abs(s){return new k(Math.abs(s.x),Math.abs(s.y))}static Dist(s,e){return Math.hypot(s.y-e.y,s.x-e.x)}static Dpr(s,e){return s.x*e.x+s.y*e.y}static Cross(s,e){return new k(s.y*e.z-s.z*e.y,s.z*e.x-s.x*e.z)}static Cpr(s,e){return s.x*e.y-e.x*s.y}static Len2(s){return s.x*s.x+s.y*s.y}static Len(s){return Math.hypot(s.x,s.y)}static Pry(s,e){return k.Dpr(s,e)/k.Len(e)}static Uni(s){return k.Div(s,k.Len(s))}static Tan(s,e){return k.Uni(k.Sub(s,e))}static Min(s,e){return new k(Math.min(s.x,e.x),Math.min(s.y,e.y))}static Max(s,e){return new k(Math.max(s.x,e.x),Math.max(s.y,e.y))}static From(s){return new k().add(s)}static FromArray(s){return new k(s[0],s[1])}static Rot(s,e=0){const t=Math.sin(e),i=Math.cos(e);return new k(s.x*i-s.y*t,s.x*t+s.y*i)}static RotWith(s,e,t){const i=s.x-e.x,o=s.y-e.y,n=Math.sin(t),a=Math.cos(t);return new k(e.x+(i*a-o*n),e.y+(i*n+o*a))}static NearestPointOnLineThroughPoint(s,e,t){return k.Mul(e,k.Sub(t,s).pry(e)).add(s)}static NearestPointOnLineSegment(s,e,t,i=!0){const o=k.Tan(e,s),n=k.Add(s,k.Mul(o,k.Sub(t,s).pry(o)));if(i){if(n.x<Math.min(s.x,e.x))return k.Cast(s.x<e.x?s:e);if(n.x>Math.max(s.x,e.x))return k.Cast(s.x>e.x?s:e);if(n.y<Math.min(s.y,e.y))return k.Cast(s.y<e.y?s:e);if(n.y>Math.max(s.y,e.y))return k.Cast(s.y>e.y?s:e)}return n}static DistanceToLineThroughPoint(s,e,t){return k.Dist(t,k.NearestPointOnLineThroughPoint(s,e,t))}static DistanceToLineSegment(s,e,t,i=!0){return k.Dist(t,k.NearestPointOnLineSegment(s,e,t,i))}static Snap(s,e=1){return new k(Math.round(s.x/e)*e,Math.round(s.y/e)*e)}static Cast(s){return s instanceof k?s:k.From(s)}static Slope(s,e){return s.x===e.y?NaN:(s.y-e.y)/(s.x-e.x)}static Angle(s,e){return Math.atan2(e.y-s.y,e.x-s.x)}static Lrp(s,e,t){return k.Sub(e,s).mul(t).add(s)}static Med(s,e){return new k((s.x+e.x)/2,(s.y+e.y)/2)}static Equals(s,e,t=1e-4){return Math.abs(s.x-e.x)<t&&Math.abs(s.y-e.y)<t}static EqualsXY(s,e,t){return s.x===e&&s.y===t}static EqualsXYZ(s,e,t=1e-4){return k.Equals(s,e,t)&&Math.abs((s.z||0)-(e.z||0))<t}static Clockwise(s,e,t){return(t.x-s.x)*(e.y-s.y)-(e.x-s.x)*(t.y-s.y)<0}static Rescale(s,e){const t=k.Len(s);return new k(e*s.x/t,e*s.y/t)}static ScaleWithOrigin(s,e,t){return k.Sub(s,t).mul(e).add(t)}static ScaleWOrigin(s,e,t){return k.Sub(s,t).mulV(e).add(t)}static ToFixed(s,e=2){return new k(+s.x.toFixed(e),+s.y.toFixed(e),+s.z.toFixed(e))}static Nudge(s,e,t){return k.Add(s,k.Tan(e,s).mul(t))}static ToString(s){return`${s.x}, ${s.y}`}static ToAngle(s){let e=Math.atan2(s.y,s.x);return e<0&&(e+=Math.PI*2),e}static FromAngle(s,e=1){return new k(Math.cos(s)*e,Math.sin(s)*e)}static ToArray(s){return[s.x,s.y,s.z]}static ToJson(s){const{x:e,y:t,z:i}=s;return{x:e,y:t,z:i}}static Average(s){const e=s.length,t=new k(0,0);for(let i=0;i<e;i++)t.add(s[i]);return t.div(e)}static Clamp(s,e,t){return t===void 0?new k(Math.min(Math.max(s.x,e)),Math.min(Math.max(s.y,e))):new k(Math.min(Math.max(s.x,e),t),Math.min(Math.max(s.y,e),t))}static PointsBetween(s,e,t=6){const i=[];for(let o=0;o<t;o++){const n=An.easeInQuad(o/(t-1)),a=k.Lrp(s,e,n);a.z=Math.min(1,.5+Math.abs(.5-Pn(n))*.65),i.push(a)}return i}static SnapToGrid(s,e=8){return new k(Math.round(s.x/e)*e,Math.round(s.y/e)*e)}}const Pn=r=>r<.5?2*r*r:-1+(4-2*r)*r;class Q extends k{constructor(s=0,e=0,t=0,i={x:0,y:0},o=0,n=0){super(s,e,t),this.x=s,this.y=e,this.z=t,this.v=i,this.t=o,this.a=n}get timestamp(){return this.t}get pressure(){return this.z}get angleNum(){return this.a}get XY(){return[this.x,this.y]}setA(s){this.a=s}setT(s){this.t=s}setv(s){return this.v={x:s.x,y:s.y},this}set(s=this.x,e=this.y,t=this.z,i=this.v,o=this.t,n=this.a){return this.x=s,this.y=e,this.z=t,this.v=i,this.t=o,this.a=n,this}clone(){const{x:s,y:e,z:t,v:i,t:o,a:n}=this,a={x:i.x,y:i.y};return new Q(s,e,t,a,o,n)}distance(s){return Q.GetDistance(this,s)}isNear(s,e){return Q.IsNear(this,s,e)}getAngleByPoints(s,e){return Q.GetAngleByPoints(s,this,e)}static Sub(s,e){return new Q(s.x-e.x,s.y-e.y)}static Add(s,e){return new Q(s.x+e.x,s.y+e.y)}static GetDistance(s,e){return Q.Len(s.clone().sub(e))}static GetAngleByPoints(s,e,t){const i=e.x-s.x,o=t.x-e.x,n=e.y-s.y,a=t.y-e.y;let c=0;const l=Math.sqrt(i*i+n*n),u=Math.sqrt(o*o+a*a);if(l&&u){const h=i*o+n*a;c=Math.acos(h/(l*u)),c=c/Math.PI*180;let d=i*a-n*o;d=d>0?1:-1,c=180+d*c}return c}static IsNear(s,e,t){return Q.Len(s.clone().sub(e))<t}static RotWith(s,e,t,i=2){const o=s.x-e.x,n=s.y-e.y,a=Math.sin(t),c=Math.cos(t),l=Math.pow(10,i),u=Math.floor((e.x+(o*c-n*a))*l)/l,h=Math.floor((e.y+(o*a+n*c))*l)/l;return new Q(u,h)}static GetDotStroke(s,e,t=16){const i=new k(1,1),o=Math.PI+.001,n=Q.Add(s,Q.Sub(s,i).uni().per().mul(-e)),a=[];for(let c=1/t,l=c;l<=1;l+=c)a.push(Q.RotWith(n,s,o*2*l));return a}static GetSemicircleStroke(s,e,t=-1,i=8){const o=t*(Math.PI+.001),n=[];for(let a=1/i,c=a;c<=1;c+=a)n.push(Q.RotWith(e,s,o*c));return n}}var os=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ut(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var zn=typeof os=="object"&&os&&os.Object===Object&&os,vo=zn,En=vo,On=typeof self=="object"&&self&&self.Object===Object&&self,Rn=En||On||Function("return this")(),tt=Rn,Wn=tt,Yn=Wn.Symbol,es=Yn,Si=es,No=Object.prototype,Un=No.hasOwnProperty,Bn=No.toString,Gt=Si?Si.toStringTag:void 0;function Fn(r){var s=Un.call(r,Gt),e=r[Gt];try{r[Gt]=void 0;var t=!0}catch{}var i=Bn.call(r);return t&&(s?r[Gt]=e:delete r[Gt]),i}var Vn=Fn,Qn=Object.prototype,Zn=Qn.toString;function Hn(r){return Zn.call(r)}var Gn=Hn,Ci=es,$n=Vn,Xn=Gn,Jn="[object Null]",qn="[object Undefined]",ki=Ci?Ci.toStringTag:void 0;function Kn(r){return r==null?r===void 0?qn:Jn:ki&&ki in Object(r)?$n(r):Xn(r)}var kt=Kn;function _n(r){return r!=null&&typeof r=="object"}var at=_n,er=kt,tr=at,sr="[object Number]";function ir(r){return typeof r=="number"||tr(r)&&er(r)==sr}var or=ir;const ze=Ut(or);function nr(){this.__data__=[],this.size=0}var rr=nr;function ar(r,s){return r===s||r!==r&&s!==s}var ei=ar,cr=ei;function lr(r,s){for(var e=r.length;e--;)if(cr(r[e][0],s))return e;return-1}var Ns=lr,hr=Ns,ur=Array.prototype,dr=ur.splice;function pr(r){var s=this.__data__,e=hr(s,r);if(e<0)return!1;var t=s.length-1;return e==t?s.pop():dr.call(s,e,1),--this.size,!0}var gr=pr,fr=Ns;function Mr(r){var s=this.__data__,e=fr(s,r);return e<0?void 0:s[e][1]}var yr=Mr,mr=Ns;function wr(r){return mr(this.__data__,r)>-1}var Ir=wr,Tr=Ns;function vr(r,s){var e=this.__data__,t=Tr(e,r);return t<0?(++this.size,e.push([r,s])):e[t][1]=s,this}var Nr=vr,Sr=rr,Cr=gr,kr=yr,xr=Ir,Dr=Nr;function Bt(r){var s=-1,e=r==null?0:r.length;for(this.clear();++s<e;){var t=r[s];this.set(t[0],t[1])}}Bt.prototype.clear=Sr;Bt.prototype.delete=Cr;Bt.prototype.get=kr;Bt.prototype.has=xr;Bt.prototype.set=Dr;var Ss=Bt,Lr=Ss;function br(){this.__data__=new Lr,this.size=0}var jr=br;function Ar(r){var s=this.__data__,e=s.delete(r);return this.size=s.size,e}var Pr=Ar;function zr(r){return this.__data__.get(r)}var Er=zr;function Or(r){return this.__data__.has(r)}var Rr=Or;function Wr(r){var s=typeof r;return r!=null&&(s=="object"||s=="function")}var Mt=Wr,Yr=kt,Ur=Mt,Br="[object AsyncFunction]",Fr="[object Function]",Vr="[object GeneratorFunction]",Qr="[object Proxy]";function Zr(r){if(!Ur(r))return!1;var s=Yr(r);return s==Fr||s==Vr||s==Br||s==Qr}var So=Zr,Hr=tt,Gr=Hr["__core-js_shared__"],$r=Gr,zs=$r,xi=function(){var r=/[^.]+$/.exec(zs&&zs.keys&&zs.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""}();function Xr(r){return!!xi&&xi in r}var Jr=Xr,qr=Function.prototype,Kr=qr.toString;function _r(r){if(r!=null){try{return Kr.call(r)}catch{}try{return r+""}catch{}}return""}var Co=_r,ea=So,ta=Jr,sa=Mt,ia=Co,oa=/[\\^$.*+?()[\]{}|]/g,na=/^\[object .+?Constructor\]$/,ra=Function.prototype,aa=Object.prototype,ca=ra.toString,la=aa.hasOwnProperty,ha=RegExp("^"+ca.call(la).replace(oa,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ua(r){if(!sa(r)||ta(r))return!1;var s=ea(r)?ha:na;return s.test(ia(r))}var da=ua;function pa(r,s){return r==null?void 0:r[s]}var ga=pa,fa=da,Ma=ga;function ya(r,s){var e=Ma(r,s);return fa(e)?e:void 0}var xt=ya,ma=xt,wa=tt,Ia=ma(wa,"Map"),ti=Ia,Ta=xt,va=Ta(Object,"create"),Cs=va,Di=Cs;function Na(){this.__data__=Di?Di(null):{},this.size=0}var Sa=Na;function Ca(r){var s=this.has(r)&&delete this.__data__[r];return this.size-=s?1:0,s}var ka=Ca,xa=Cs,Da="__lodash_hash_undefined__",La=Object.prototype,ba=La.hasOwnProperty;function ja(r){var s=this.__data__;if(xa){var e=s[r];return e===Da?void 0:e}return ba.call(s,r)?s[r]:void 0}var Aa=ja,Pa=Cs,za=Object.prototype,Ea=za.hasOwnProperty;function Oa(r){var s=this.__data__;return Pa?s[r]!==void 0:Ea.call(s,r)}var Ra=Oa,Wa=Cs,Ya="__lodash_hash_undefined__";function Ua(r,s){var e=this.__data__;return this.size+=this.has(r)?0:1,e[r]=Wa&&s===void 0?Ya:s,this}var Ba=Ua,Fa=Sa,Va=ka,Qa=Aa,Za=Ra,Ha=Ba;function Ft(r){var s=-1,e=r==null?0:r.length;for(this.clear();++s<e;){var t=r[s];this.set(t[0],t[1])}}Ft.prototype.clear=Fa;Ft.prototype.delete=Va;Ft.prototype.get=Qa;Ft.prototype.has=Za;Ft.prototype.set=Ha;var Ga=Ft,Li=Ga,$a=Ss,Xa=ti;function Ja(){this.size=0,this.__data__={hash:new Li,map:new(Xa||$a),string:new Li}}var qa=Ja;function Ka(r){var s=typeof r;return s=="string"||s=="number"||s=="symbol"||s=="boolean"?r!=="__proto__":r===null}var _a=Ka,ec=_a;function tc(r,s){var e=r.__data__;return ec(s)?e[typeof s=="string"?"string":"hash"]:e.map}var ks=tc,sc=ks;function ic(r){var s=sc(this,r).delete(r);return this.size-=s?1:0,s}var oc=ic,nc=ks;function rc(r){return nc(this,r).get(r)}var ac=rc,cc=ks;function lc(r){return cc(this,r).has(r)}var hc=lc,uc=ks;function dc(r,s){var e=uc(this,r),t=e.size;return e.set(r,s),this.size+=e.size==t?0:1,this}var pc=dc,gc=qa,fc=oc,Mc=ac,yc=hc,mc=pc;function Vt(r){var s=-1,e=r==null?0:r.length;for(this.clear();++s<e;){var t=r[s];this.set(t[0],t[1])}}Vt.prototype.clear=gc;Vt.prototype.delete=fc;Vt.prototype.get=Mc;Vt.prototype.has=yc;Vt.prototype.set=mc;var ko=Vt,wc=Ss,Ic=ti,Tc=ko,vc=200;function Nc(r,s){var e=this.__data__;if(e instanceof wc){var t=e.__data__;if(!Ic||t.length<vc-1)return t.push([r,s]),this.size=++e.size,this;e=this.__data__=new Tc(t)}return e.set(r,s),this.size=e.size,this}var Sc=Nc,Cc=Ss,kc=jr,xc=Pr,Dc=Er,Lc=Rr,bc=Sc;function Qt(r){var s=this.__data__=new Cc(r);this.size=s.size}Qt.prototype.clear=kc;Qt.prototype.delete=xc;Qt.prototype.get=Dc;Qt.prototype.has=Lc;Qt.prototype.set=bc;var xo=Qt;function jc(r,s){for(var e=-1,t=r==null?0:r.length;++e<t&&s(r[e],e,r)!==!1;);return r}var Ac=jc,Pc=xt,zc=function(){try{var r=Pc(Object,"defineProperty");return r({},"",{}),r}catch{}}(),Do=zc,bi=Do;function Ec(r,s,e){s=="__proto__"&&bi?bi(r,s,{configurable:!0,enumerable:!0,value:e,writable:!0}):r[s]=e}var Lo=Ec,Oc=Lo,Rc=ei,Wc=Object.prototype,Yc=Wc.hasOwnProperty;function Uc(r,s,e){var t=r[s];(!(Yc.call(r,s)&&Rc(t,e))||e===void 0&&!(s in r))&&Oc(r,s,e)}var bo=Uc,Bc=bo,Fc=Lo;function Vc(r,s,e,t){var i=!e;e||(e={});for(var o=-1,n=s.length;++o<n;){var a=s[o],c=t?t(e[a],r[a],a,e,r):void 0;c===void 0&&(c=r[a]),i?Fc(e,a,c):Bc(e,a,c)}return e}var xs=Vc;function Qc(r,s){for(var e=-1,t=Array(r);++e<r;)t[e]=s(e);return t}var Zc=Qc,Hc=kt,Gc=at,$c="[object Arguments]";function Xc(r){return Gc(r)&&Hc(r)==$c}var Jc=Xc,ji=Jc,qc=at,jo=Object.prototype,Kc=jo.hasOwnProperty,_c=jo.propertyIsEnumerable,el=ji(function(){return arguments}())?ji:function(r){return qc(r)&&Kc.call(r,"callee")&&!_c.call(r,"callee")},Ao=el,tl=Array.isArray,ts=tl,ls={exports:{}};function sl(){return!1}var il=sl;ls.exports;(function(r,s){var e=tt,t=il,i=s&&!s.nodeType&&s,o=i&&!0&&r&&!r.nodeType&&r,n=o&&o.exports===i,a=n?e.Buffer:void 0,c=a?a.isBuffer:void 0,l=c||t;r.exports=l})(ls,ls.exports);var si=ls.exports,ol=9007199254740991,nl=/^(?:0|[1-9]\d*)$/;function rl(r,s){var e=typeof r;return s=s??ol,!!s&&(e=="number"||e!="symbol"&&nl.test(r))&&r>-1&&r%1==0&&r<s}var al=rl,cl=9007199254740991;function ll(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=cl}var Po=ll,hl=kt,ul=Po,dl=at,pl="[object Arguments]",gl="[object Array]",fl="[object Boolean]",Ml="[object Date]",yl="[object Error]",ml="[object Function]",wl="[object Map]",Il="[object Number]",Tl="[object Object]",vl="[object RegExp]",Nl="[object Set]",Sl="[object String]",Cl="[object WeakMap]",kl="[object ArrayBuffer]",xl="[object DataView]",Dl="[object Float32Array]",Ll="[object Float64Array]",bl="[object Int8Array]",jl="[object Int16Array]",Al="[object Int32Array]",Pl="[object Uint8Array]",zl="[object Uint8ClampedArray]",El="[object Uint16Array]",Ol="[object Uint32Array]",Ne={};Ne[Dl]=Ne[Ll]=Ne[bl]=Ne[jl]=Ne[Al]=Ne[Pl]=Ne[zl]=Ne[El]=Ne[Ol]=!0;Ne[pl]=Ne[gl]=Ne[kl]=Ne[fl]=Ne[xl]=Ne[Ml]=Ne[yl]=Ne[ml]=Ne[wl]=Ne[Il]=Ne[Tl]=Ne[vl]=Ne[Nl]=Ne[Sl]=Ne[Cl]=!1;function Rl(r){return dl(r)&&ul(r.length)&&!!Ne[hl(r)]}var Wl=Rl;function Yl(r){return function(s){return r(s)}}var Ds=Yl,hs={exports:{}};hs.exports;(function(r,s){var e=vo,t=s&&!s.nodeType&&s,i=t&&!0&&r&&!r.nodeType&&r,o=i&&i.exports===t,n=o&&e.process,a=function(){try{var c=i&&i.require&&i.require("util").types;return c||n&&n.binding&&n.binding("util")}catch{}}();r.exports=a})(hs,hs.exports);var ii=hs.exports,Ul=Wl,Bl=Ds,Ai=ii,Pi=Ai&&Ai.isTypedArray,Fl=Pi?Bl(Pi):Ul,zo=Fl,Vl=Zc,Ql=Ao,Zl=ts,Hl=si,Gl=al,$l=zo,Xl=Object.prototype,Jl=Xl.hasOwnProperty;function ql(r,s){var e=Zl(r),t=!e&&Ql(r),i=!e&&!t&&Hl(r),o=!e&&!t&&!i&&$l(r),n=e||t||i||o,a=n?Vl(r.length,String):[],c=a.length;for(var l in r)(s||Jl.call(r,l))&&!(n&&(l=="length"||i&&(l=="offset"||l=="parent")||o&&(l=="buffer"||l=="byteLength"||l=="byteOffset")||Gl(l,c)))&&a.push(l);return a}var Eo=ql,Kl=Object.prototype;function _l(r){var s=r&&r.constructor,e=typeof s=="function"&&s.prototype||Kl;return r===e}var oi=_l;function eh(r,s){return function(e){return r(s(e))}}var Oo=eh,th=Oo,sh=th(Object.keys,Object),ih=sh,oh=oi,nh=ih,rh=Object.prototype,ah=rh.hasOwnProperty;function ch(r){if(!oh(r))return nh(r);var s=[];for(var e in Object(r))ah.call(r,e)&&e!="constructor"&&s.push(e);return s}var lh=ch,hh=So,uh=Po;function dh(r){return r!=null&&uh(r.length)&&!hh(r)}var ni=dh,ph=Eo,gh=lh,fh=ni;function Mh(r){return fh(r)?ph(r):gh(r)}var ri=Mh,yh=xs,mh=ri;function wh(r,s){return r&&yh(s,mh(s),r)}var Ih=wh;function Th(r){var s=[];if(r!=null)for(var e in Object(r))s.push(e);return s}var vh=Th,Nh=Mt,Sh=oi,Ch=vh,kh=Object.prototype,xh=kh.hasOwnProperty;function Dh(r){if(!Nh(r))return Ch(r);var s=Sh(r),e=[];for(var t in r)t=="constructor"&&(s||!xh.call(r,t))||e.push(t);return e}var Lh=Dh,bh=Eo,jh=Lh,Ah=ni;function Ph(r){return Ah(r)?bh(r,!0):jh(r)}var ai=Ph,zh=xs,Eh=ai;function Oh(r,s){return r&&zh(s,Eh(s),r)}var Rh=Oh,us={exports:{}};us.exports;(function(r,s){var e=tt,t=s&&!s.nodeType&&s,i=t&&!0&&r&&!r.nodeType&&r,o=i&&i.exports===t,n=o?e.Buffer:void 0,a=n?n.allocUnsafe:void 0;function c(l,u){if(u)return l.slice();var h=l.length,d=a?a(h):new l.constructor(h);return l.copy(d),d}r.exports=c})(us,us.exports);var Wh=us.exports;function Yh(r,s){var e=-1,t=r.length;for(s||(s=Array(t));++e<t;)s[e]=r[e];return s}var Uh=Yh;function Bh(r,s){for(var e=-1,t=r==null?0:r.length,i=0,o=[];++e<t;){var n=r[e];s(n,e,r)&&(o[i++]=n)}return o}var Ro=Bh;function Fh(){return[]}var Wo=Fh,Vh=Ro,Qh=Wo,Zh=Object.prototype,Hh=Zh.propertyIsEnumerable,zi=Object.getOwnPropertySymbols,Gh=zi?function(r){return r==null?[]:(r=Object(r),Vh(zi(r),function(s){return Hh.call(r,s)}))}:Qh,ci=Gh,$h=xs,Xh=ci;function Jh(r,s){return $h(r,Xh(r),s)}var qh=Jh;function Kh(r,s){for(var e=-1,t=s.length,i=r.length;++e<t;)r[i+e]=s[e];return r}var li=Kh,_h=Oo,eu=_h(Object.getPrototypeOf,Object),Yo=eu,tu=li,su=Yo,iu=ci,ou=Wo,nu=Object.getOwnPropertySymbols,ru=nu?function(r){for(var s=[];r;)tu(s,iu(r)),r=su(r);return s}:ou,Uo=ru,au=xs,cu=Uo;function lu(r,s){return au(r,cu(r),s)}var hu=lu,uu=li,du=ts;function pu(r,s,e){var t=s(r);return du(r)?t:uu(t,e(r))}var Bo=pu,gu=Bo,fu=ci,Mu=ri;function yu(r){return gu(r,Mu,fu)}var Fo=yu,mu=Bo,wu=Uo,Iu=ai;function Tu(r){return mu(r,Iu,wu)}var vu=Tu,Nu=xt,Su=tt,Cu=Nu(Su,"DataView"),ku=Cu,xu=xt,Du=tt,Lu=xu(Du,"Promise"),bu=Lu,ju=xt,Au=tt,Pu=ju(Au,"Set"),Vo=Pu,zu=xt,Eu=tt,Ou=zu(Eu,"WeakMap"),Ru=Ou,Bs=ku,Fs=ti,Vs=bu,Qs=Vo,Zs=Ru,Qo=kt,Zt=Co,Ei="[object Map]",Wu="[object Object]",Oi="[object Promise]",Ri="[object Set]",Wi="[object WeakMap]",Yi="[object DataView]",Yu=Zt(Bs),Uu=Zt(Fs),Bu=Zt(Vs),Fu=Zt(Qs),Vu=Zt(Zs),mt=Qo;(Bs&&mt(new Bs(new ArrayBuffer(1)))!=Yi||Fs&&mt(new Fs)!=Ei||Vs&&mt(Vs.resolve())!=Oi||Qs&&mt(new Qs)!=Ri||Zs&&mt(new Zs)!=Wi)&&(mt=function(r){var s=Qo(r),e=s==Wu?r.constructor:void 0,t=e?Zt(e):"";if(t)switch(t){case Yu:return Yi;case Uu:return Ei;case Bu:return Oi;case Fu:return Ri;case Vu:return Wi}return s});var Ls=mt,Qu=Object.prototype,Zu=Qu.hasOwnProperty;function Hu(r){var s=r.length,e=new r.constructor(s);return s&&typeof r[0]=="string"&&Zu.call(r,"index")&&(e.index=r.index,e.input=r.input),e}var Gu=Hu,$u=tt,Xu=$u.Uint8Array,Zo=Xu,Ui=Zo;function Ju(r){var s=new r.constructor(r.byteLength);return new Ui(s).set(new Ui(r)),s}var hi=Ju,qu=hi;function Ku(r,s){var e=s?qu(r.buffer):r.buffer;return new r.constructor(e,r.byteOffset,r.byteLength)}var _u=Ku,ed=/\w*$/;function td(r){var s=new r.constructor(r.source,ed.exec(r));return s.lastIndex=r.lastIndex,s}var sd=td,Bi=es,Fi=Bi?Bi.prototype:void 0,Vi=Fi?Fi.valueOf:void 0;function id(r){return Vi?Object(Vi.call(r)):{}}var od=id,nd=hi;function rd(r,s){var e=s?nd(r.buffer):r.buffer;return new r.constructor(e,r.byteOffset,r.length)}var ad=rd,cd=hi,ld=_u,hd=sd,ud=od,dd=ad,pd="[object Boolean]",gd="[object Date]",fd="[object Map]",Md="[object Number]",yd="[object RegExp]",md="[object Set]",wd="[object String]",Id="[object Symbol]",Td="[object ArrayBuffer]",vd="[object DataView]",Nd="[object Float32Array]",Sd="[object Float64Array]",Cd="[object Int8Array]",kd="[object Int16Array]",xd="[object Int32Array]",Dd="[object Uint8Array]",Ld="[object Uint8ClampedArray]",bd="[object Uint16Array]",jd="[object Uint32Array]";function Ad(r,s,e){var t=r.constructor;switch(s){case Td:return cd(r);case pd:case gd:return new t(+r);case vd:return ld(r,e);case Nd:case Sd:case Cd:case kd:case xd:case Dd:case Ld:case bd:case jd:return dd(r,e);case fd:return new t;case Md:case wd:return new t(r);case yd:return hd(r);case md:return new t;case Id:return ud(r)}}var Pd=Ad,zd=Mt,Qi=Object.create,Ed=function(){function r(){}return function(s){if(!zd(s))return{};if(Qi)return Qi(s);r.prototype=s;var e=new r;return r.prototype=void 0,e}}(),Od=Ed,Rd=Od,Wd=Yo,Yd=oi;function Ud(r){return typeof r.constructor=="function"&&!Yd(r)?Rd(Wd(r)):{}}var Bd=Ud,Fd=Ls,Vd=at,Qd="[object Map]";function Zd(r){return Vd(r)&&Fd(r)==Qd}var Hd=Zd,Gd=Hd,$d=Ds,Zi=ii,Hi=Zi&&Zi.isMap,Xd=Hi?$d(Hi):Gd,Jd=Xd,qd=Ls,Kd=at,_d="[object Set]";function ep(r){return Kd(r)&&qd(r)==_d}var tp=ep,sp=tp,ip=Ds,Gi=ii,$i=Gi&&Gi.isSet,op=$i?ip($i):sp,Ho=op;const np=Ut(Ho);var rp=xo,ap=Ac,cp=bo,lp=Ih,hp=Rh,up=Wh,dp=Uh,pp=qh,gp=hu,fp=Fo,Mp=vu,yp=Ls,mp=Gu,wp=Pd,Ip=Bd,Tp=ts,vp=si,Np=Jd,Sp=Mt,Cp=Ho,kp=ri,xp=ai,Dp=1,Lp=2,bp=4,Go="[object Arguments]",jp="[object Array]",Ap="[object Boolean]",Pp="[object Date]",zp="[object Error]",$o="[object Function]",Ep="[object GeneratorFunction]",Op="[object Map]",Rp="[object Number]",Xo="[object Object]",Wp="[object RegExp]",Yp="[object Set]",Up="[object String]",Bp="[object Symbol]",Fp="[object WeakMap]",Vp="[object ArrayBuffer]",Qp="[object DataView]",Zp="[object Float32Array]",Hp="[object Float64Array]",Gp="[object Int8Array]",$p="[object Int16Array]",Xp="[object Int32Array]",Jp="[object Uint8Array]",qp="[object Uint8ClampedArray]",Kp="[object Uint16Array]",_p="[object Uint32Array]",ve={};ve[Go]=ve[jp]=ve[Vp]=ve[Qp]=ve[Ap]=ve[Pp]=ve[Zp]=ve[Hp]=ve[Gp]=ve[$p]=ve[Xp]=ve[Op]=ve[Rp]=ve[Xo]=ve[Wp]=ve[Yp]=ve[Up]=ve[Bp]=ve[Jp]=ve[qp]=ve[Kp]=ve[_p]=!0;ve[zp]=ve[$o]=ve[Fp]=!1;function as(r,s,e,t,i,o){var n,a=s&Dp,c=s&Lp,l=s&bp;if(e&&(n=i?e(r,t,i,o):e(r)),n!==void 0)return n;if(!Sp(r))return r;var u=Tp(r);if(u){if(n=mp(r),!a)return dp(r,n)}else{var h=yp(r),d=h==$o||h==Ep;if(vp(r))return up(r,a);if(h==Xo||h==Go||d&&!i){if(n=c||d?{}:Ip(r),!a)return c?gp(r,hp(n,r)):pp(r,lp(n,r))}else{if(!ve[h])return i?r:{};n=wp(r,h,a)}}o||(o=new rp);var g=o.get(r);if(g)return g;o.set(r,n),Cp(r)?r.forEach(function(m){n.add(as(m,s,e,m,r,o))}):Np(r)&&r.forEach(function(m,w){n.set(w,as(m,s,e,w,r,o))});var p=l?c?Mp:fp:c?xp:kp,f=u?void 0:p(r);return ap(f||r,function(m,w){f&&(w=m,m=r[w]),cp(n,w,as(m,s,e,w,r,o))}),n}var eg=as,tg=eg,sg=1,ig=4;function og(r){return tg(r,sg|ig)}var ng=og;const Pe=Ut(ng),Jo="1.1.17",rg="@netless/appliance-plugin",Xi=typeof OffscreenCanvas=="function"?"worker":"mainThread";if(typeof window<"u"){let r=window.__netlessUA||"";r+=` ${rg}@${Jo}`,window.__netlessUA=r}const Ie={syncOpt:{interval:500},cdn:{subWorkerUrl:"https://cdn.jsdelivr.net/npm/@netless/appliance-plugin@latest/dist/subWorker.js",fullWorkerUrl:"https://cdn.jsdelivr.net/npm/@netless/appliance-plugin@latest/dist/fullWorker.js"},cursor:{expirationTime:5e3},bufferSize:{full:2e4,sub:600},bezier:{maxDrawCount:1/0,combineUnitTime:500},pencilEraser:{useBitMap:!0,maxImageWidth:1920,maxImageHeight:1920},strokeWidth:{min:1,max:10},textEditor:{showFloatBar:!0,canSelectorSwitch:!0,rightBoundBreak:!1}};function nt(r,s=!0){const e=r.length;if(e<2)return"";let t=r[0],i=r[1];if(e===2)return`M${bt(t)}L${bt(i)}`;let o="";for(let n=2,a=e-1;n<a;n++)t=r[n],i=r[n+1],o+=jt(t,i);return s?`M${jt(r[0],r[1])}Q${bt(r[1])}${jt(r[1],r[2])}T${o}${jt(r[e-1],r[0])}${jt(r[0],r[1])}Z`:`M${bt(r[0])}Q${bt(r[1])}${jt(r[1],r[2])}${r.length>3?"T":""}${o}L${bt(r[e-1])}`}const $e=class $e{constructor(s){M(this,"maxImageWidth",Ie.pencilEraser.maxImageWidth);M(this,"maxImageHeight",Ie.pencilEraser.maxImageHeight);M(this,"syncUnitTime",Ie.syncOpt.interval);M(this,"vNodes");M(this,"drawLayer");M(this,"fullLayer");M(this,"workId");M(this,"isDelete",!1);const{vNodes:e,fullLayer:t,drawLayer:i,workId:o,toolsOpt:n}=s;this.vNodes=e,this.fullLayer=t,this.drawLayer=i,this.workId=o,this.syncUnitTime=n.syncUnitTime||this.syncUnitTime}get baseConsumeResult(){return{workId:this.workId,toolsType:this.toolsType,opt:this.workOptions}}filterSamePoints(s,e=.01){return s.reduce((t,i)=>{const o=t[t.length-1];return(i&&!o||i&&o&&!i.isNear(o,e))&&t.push(i),t},[])}setWorkId(s){this.workId=s}getWorkId(){return this.workId}getWorkOptions(){return this.workOptions}setWorkOptions(s){var i,o,n;this.workOptions=s,this.syncUnitTime=s.syncUnitTime||this.syncUnitTime;const e=(i=this.workId)==null?void 0:i.toString(),t=e&&((o=this.vNodes)==null?void 0:o.get(e))||void 0;e&&t&&(t.opt=s,(n=this.vNodes)==null||n.setInfo(e,t))}updataOptService(s){var i,o;let e;const t=(i=this.workId)==null?void 0:i.toString();if(t&&s){const n=this.fullLayer.getElementsByName(t)||this.drawLayer&&this.drawLayer.getElementsByName(t)||[];if(n.length!==1)return;const a=n[0],{pos:c,zIndex:l,scale:u,angle:h,translate:d}=s,g={};ze(l)&&(g.zIndex=l),c&&(g.pos=[c[0],c[1]]),u&&(g.scale=u),h&&(g.rotate=h),d&&(g.translate=d),a.attr(g);const p=a==null?void 0:a.getBoundingClientRect();return p&&(e=ue(e,{x:Math.floor(p.x-$e.SafeBorderPadding),y:Math.floor(p.y-$e.SafeBorderPadding),w:Math.floor(p.width+$e.SafeBorderPadding*2),h:Math.floor(p.height+$e.SafeBorderPadding*2)})),(o=this.vNodes)==null||o.setInfo(t,{rect:e,centerPos:c}),e}}drawEraserlines(s,e){const{group:t,eraserlines:i,pos:o,layer:n}=s,a=n.parent;if(e)try{const l=(n.renderer.glRenderer||n.renderer.canvasRenderer).options.displayRatio,u=t.getBoundingClientRect(),h=u.width*l*n.worldScaling[0],d=u.height*l*n.worldScaling[1];let g=1;(h>this.maxImageWidth||d>this.maxImageHeight)&&(g=Math.min(this.maxImageWidth/h,this.maxImageHeight/d));let p=n.getAttribute("scale");p=[p[0]*g,p[1]*g];const f=n.parent.parent,m=n.getAttribute("translate"),w=this.createVmRenderNode(`${this.workId}_bitMapLayer`,f,{offscreen:a.offscreen,width:a.width,height:a.height,contextType:"2d",autoRender:!1,bufferSize:500},p,m),I=t.cloneNode(!0);this.addEraserlines(I,i,o,!1),w.appendChild(I);const N=w.parent;N.render();const C=w.renderer.canvasRenderer,S=C.context;if(!S)return;const v=C.options.displayRatio,x=I.getBoundingClientRect(),L={x:x.x,y:x.y,w:x.width,h:x.height},b={x:0,y:0,w:f.width,h:f.height};if(wi(L,b)===Nt.outside){Fe(I,N),f.removeChild(N),this.isDelete=!0;return}const A=Pe(L);A.x=Math.floor(Math.max(L.x,0)),A.y=Math.floor(Math.max(L.y,0)),A.w=Math.min(L.x+L.w,f.width)-A.x,A.h=Math.min(L.y+L.h,f.height)-A.y;const E=this.getGroupRect(A,v),R=E.x,z=E.y,Z=E.w,ee=E.h;let F=S.getImageData(R,z,Z,ee);if(this.isTransparentRectByCanvas(F)){Fe(I,N),f.removeChild(N),this.isDelete=!0,F=null;return}Fe(t,a);const te=this.createSpriteNode({imageData:F,safariRect:A,originRect:L,worldScaling:w.worldScaling});te&&t.append(te),Fe(I,N),f.removeChild(N),a.deleteTexture(F),F=null}catch(c){console.error(c);return}}createVmRenderNode(s,e,t,i,o){const{width:n,height:a}=t,c=`bitMap-${s}`,l=e.layer(c,t),u=new he.Group({anchor:[.5,.5],pos:[n*.5,a*.5],size:[n,a],name:"viewport",id:s});return u.setAttribute("scale",i),u.setAttribute("translate",o),l.append(u),u}getGroupRect(s,e){const t=Math.floor(s.x*e),i=Math.floor(s.y*e),o=Math.floor(s.w*e),n=Math.floor(s.h*e);return{x:t,y:i,w:o,h:n}}addEraserlines(s,e,t,i=!0){for(const o of e){const{thickness:n,op:a}=o;for(const c of a){const l=c.map((p,f)=>f%2?p-t[1]:p-t[0]),u=this.computEraserPoints(l,n),h=nt(u,!0),d={pos:[0,0],d:h,fillColor:"rgba(0,0,0,1)"},g=new he.Path(d);g.addEventListener("beforerender",({detail:p})=>{const f=p.context;i?f.blendFuncSeparate(f.ZERO,f.ZERO,f.ZERO,f.ZERO):f.globalCompositeOperation="destination-out"}),g.addEventListener("afterrender",({detail:p})=>{const f=p.context;i?f.blendFuncSeparate(f.SRC_ALPHA,f.ONE_MINUS_SRC_ALPHA,f.ONE,f.ONE_MINUS_SRC_ALPHA):f.globalCompositeOperation="source-over"}),s.append(g)}}}isTransparentRectByCanvas(s){let e=!0;for(let t=0;t<s.data.length;t+=4)if(s.data[t+3]!==0){e=!1;break}return e}createSpriteNode(s){const{imageData:e,worldScaling:t,safariRect:i,originRect:o}=s;let n;if(typeof OffscreenCanvas=="function"){n=new OffscreenCanvas(e.width,e.height);const u=n.getContext("2d");u&&u.putImageData(e,0,0)}else if(typeof document<"u"){n=document.createElement("canvas"),n.width=e.width,n.height=e.height;const u=n.getContext("2d");u&&u.putImageData(e,0,0)}if(!n)return console.warn("Failed to create imageEraserBitmap Sprite"),null;const a=[Math.floor(o.w/t[0]),Math.floor(o.h/t[1])],c=[Math.floor((i.x-o.x)/t[0]),Math.floor((i.y-o.y)/t[1]),Math.floor(i.w/t[0]),Math.floor(i.h/t[1])],l={name:"eraserTexture",anchor:[.5,.5],pos:[0,0],size:a,texture:n,textureRect:c};return new he.Sprite(l)}computEraserPoints(s,e){const t=Math.ceil(e/2);return s.length===2?this.computDot(s,t):this.computLine(s,t)}computDot(s,e){const t=new Q(s[0],s[1]);return Q.GetDotStroke(t,e,8)}computLine(s,e){const t=[],i=[];let o,n;for(let a=0;a<s.length;a+=2){const c=new Q(s[a],s[a+1]);let l;if(a==s.length-2){const u=new Q(s[a-2],s[a-1]);l=k.Sub(c,u).uni(),o=c}else{a===0&&(n=c);const u=new Q(s[a+2],s[a+3]);l=k.Sub(u,c).uni()}if(l){const u=k.Per(l).mul(e);t.push(Q.Sub(c,u)),i.push(Q.Add(c,u))}}if(o&&n){const a=Q.GetSemicircleStroke(o,t[t.length-1],-1,8),c=Q.GetSemicircleStroke(n,i[0],-1,8);return t.concat(a,i.reverse(),c)}return[]}replace(s,e,t){var o;if(!e){t&&s.append(t);return}const i=s.getElementsByName(e);if(i.length)for(const n of i)t?gy(t,n,s):(n.remove(),He(n,s.parent));else t&&s.append(t);this.fullLayer!==this.drawLayer&&(this.fullLayer===s?(o=this.drawLayer)==null||o.getElementsByName(e).forEach(a=>{var c;a.remove(),He(a,(c=this.drawLayer)==null?void 0:c.parent)}):this.fullLayer.getElementsByName(e).forEach(a=>{a.remove(),He(a,this.fullLayer.parent)}))}removeDrawCountNodes(s,e){const t=[];s.getElementsByName(this.workId).forEach(i=>{i.id&&e&&Number(i.id)<e&&t.push(i)});for(const i of t)i.remove(),He(i,s.parent)}static updateNodeOpt(s){var I;const{node:e,opt:t,vNodes:i,willSerializeData:o,targetNode:n}=s,{zIndex:a,translate:c,angle:l,originPoint:u,scenePoint:h,scale:d,pointMap:g,thickness:p}=t;let f;const m=n&&Pe(n)||i.get(e.name);if(!m)return;ze(a)&&(e.setAttribute("zIndex",a),m.opt.zIndex=a);const w=e.parent;if(w){if(u&&d&&n){const N=[m.op[0],m.op[1]];yi(m.op,h,d,c);const C=[m.op[0],m.op[1]],S=[C[0]-N[0],C[1]-N[1]];if(m.centerPos=[m.centerPos[0]+S[0],m.centerPos[1]+S[1]],m.opt.translate=void 0,m.opt.scale=void 0,m.opt.eraserlines)for(const v of Object.values(m.opt.eraserlines)){const{op:x,thickness:L}=v;v.thickness=L*Math.max(d[0],d[1]);for(let b=0;b<x.length;b++)mi(x[b],h,d,c)}}else if(c)if(e.setAttribute("translate",c),m.opt.translate=c,n){const N=[c[0]*w.worldScaling[0],c[1]*w.worldScaling[1]];f=_t(m.rect,N),m.rect=f}else{const N=$e.getRectFromLayer(w,e.name);m.rect=N||m.rect}else if(ze(l))if(e.setAttribute("rotate",l),m.opt.rotate=l,n)f=yn(m.rect,l),m.rect=f;else{const N=$e.getRectFromLayer(w,e.name);m.rect=N||m.rect}if(g){const N=g.get(e.name);if(N)for(let C=0,S=0;C<m.op.length;C+=3,S++)m.op[C]=N[S][0],m.op[C+1]=N[S][1]}if(p&&((I=m==null?void 0:m.opt)!=null&&I.thickness)&&(m.opt.thickness=p),o&&!(u&&d&&n)){if(c){const N=m.op.map((C,S)=>{const v=S%3;return v===0?C+c[0]:v===1?C+c[1]:C});if(m.op=N,m.centerPos=[m.centerPos[0]+c[0],m.centerPos[1]+c[1]],m!=null&&m.opt&&(m.opt.translate=void 0),m.opt.eraserlines)for(const C of Object.values(m.opt.eraserlines)){const{op:S}=C;for(let v=0;v<S.length;v++){const x=S[v].map((L,b)=>b%2?L+c[1]:L+c[0]);C.op[v]=x}}}else if(ze(l)){const N=m.op;if(ay(N,m.centerPos,l),m.op=N,m!=null&&m.opt&&(m.opt.rotate=void 0),m.opt.eraserlines)for(const C of Object.values(m.opt.eraserlines)){const{op:S}=C;for(let v=0;v<S.length;v++)cy(S[v],m.centerPos,l)}}}m&&i.setInfo(e.name,m)}}static getCenterPos(s,e){const{worldPosition:t,worldScaling:i}=e;return[(s.x+s.w/2-t[0])/i[0],(s.y+s.h/2-t[1])/i[1]]}static getRectFromLayer(s,e){const t=s.getElementsByName(e)[0];if(t){const i=t.getBoundingClientRect();return{x:Math.floor(i.x-$e.SafeBorderPadding),y:Math.floor(i.y-$e.SafeBorderPadding),w:Math.floor(i.width+$e.SafeBorderPadding*2),h:Math.floor(i.height+$e.SafeBorderPadding*2)}}}static isWillRefresh(s){const{toolsType:e,opt:t,node:i,updateOpt:o,willSerializeData:n}=s;return!!(n&&(o.angle||o.translate)||o.thickness&&t.thickness&&t.thickness!==o.thickness||o.strokeType&&t.strokeType&&t.strokeType!==o.strokeType||o.originPoint&&o.scenePoint&&o.scale||o.pointMap&&o.pointMap.has(i.name)||e===T.Text&&(o.fontSize||o.translate||o.textInfos&&o.textInfos.get(i.name))||e===T.Image&&(o.angle||o.translate||o.scale||o.strokeColor&&o.type===St.Iconify)||e===o.toolsType&&o.willRefresh||t.eraserlines&&t.eraserlines.length&&(o.strokeColor||o.fillColor))}};M($e,"SafeBorderPadding",10);let Y=$e;const ui=Object.freeze([Object.freeze({width:18,height:26}),Object.freeze({width:26,height:34}),Object.freeze({width:34,height:50}),Object.freeze({width:48,height:74})]);function Dt(r){return JSON.parse(wo.decompress(r))}function Ge(r){return wo.compress(JSON.stringify(r))}const Re=Object.keys;function qo(r,s,e=.01){return Math.abs(r[0]-s[0])<e&&Math.abs(r[1]-s[1])<e}function ag(r,s=.01){if(r.length===0)return[];const e=[[r[0][0],r[0][1]]];for(let t=1;t<r.length;t++)qo([r[t][0],r[t][1]],e[e.length-1],s)||e.push([r[t][0],r[t][1]]);return e}function cg(r,s=.01){if(r.length<=2)return r;const e=r[0],t=r[r.length-1];return qo(e,t,s)?r.slice(0,-1):r}function lg(r){const s=r.reduce((t,i)=>t+i[0],0)/r.length,e=r.reduce((t,i)=>t+i[1],0)/r.length;return[s,e]}function Ji(r,s){return Math.atan2(s[1]-r[1],s[0]-r[0])}function hg(r,s=.01){if(r.length<=2)return r;const e=[];for(const i of r)e.some(n=>Math.abs(n[0]-i[0])<s&&Math.abs(n[1]-i[1])<s)||e.push([i[0],i[1]]);const t=lg(e);return e.sort((i,o)=>{const n=Ji(t,i),a=Ji(t,o);return n-a})}function ug(r,s){const e=s[0].x<s[s.length-1].x;return r.map(i=>{const n=i.map(a=>{let c=-1,l=1/0,u=0;for(let h=0;h<s.length;h++){const d=s[h],g=Math.sqrt(Math.pow(d.x-a[0],2)+Math.pow(d.y-a[1],2));g<l&&(l=g,c=h,u=d.z)}return{point:a,index:c,bestZ:u}}).sort((a,c)=>a.index-c.index).map(a=>[...a.point,a.bestZ]);return e&&n[0][0]>n[n.length-1][0]||!e&&n[0][0]<n[n.length-1][0]?n.reverse():n}).sort((i,o)=>{const n=i[0][0],a=o[0][0];return e?n-a:a-n})}function dg(r,s,e=.01){const i=r.map(h=>[h.x,h.y]),o=(h,d)=>h.map(([g,p])=>({X:Math.round(g*d),Y:Math.round(p*d)})),n=new it.ClipperOffset;n.AddPath(o(i,1e3),it.JoinType.jtRound,it.EndType.etOpenButt);const a=[];n.Execute(a,1);const c=new it.Clipper;c.AddPaths(a,it.PolyType.ptSubject,!0),s.forEach(h=>{c.AddPath(o(h,1e3),it.PolyType.ptClip,!0)});const l=new it.Paths;c.Execute(it.ClipType.ctDifference,l,it.PolyFillType.pftNonZero,it.PolyFillType.pftNonZero);const u=l.map(h=>cg(hg(ag(h.map(d=>[d.X/1e3,d.Y/1e3]),e),e),e)).filter(h=>h.length>=2);return ug(u,r)}class Ko extends Y{constructor(e){super(e);M(this,"canRotate",!0);M(this,"scaleType",ce.all);M(this,"toolsType",T.Pencil);M(this,"syncTimestamp");M(this,"syncIndex",0);M(this,"tmpPoints",[]);M(this,"MAX_REPEAR",10);M(this,"uniThickness");M(this,"workOptions");M(this,"centerPos",[0,0]);this.workOptions=e.toolsOpt,this.uniThickness=this.MAX_REPEAR/this.workOptions.thickness/10,this.syncTimestamp=0}combineConsume(){var a;const e=(a=this.workId)==null?void 0:a.toString();if(this.tmpPoints.length<2)return{type:D.None};const t=this.transformDataAll(!0),i={name:e};let o;const n=this.drawLayer||this.fullLayer;return t.length&&(o=this.draw({attrs:i,tasks:t,replaceId:e,layer:n})),{rect:o,type:D.DrawWork,dataType:B.Local}}setWorkOptions(e){super.setWorkOptions(e),this.syncTimestamp=Date.now()}consume(e){const{data:t,isFullWork:i,isSubWorker:o,isMainThread:n,drawCount:a,removeDrawCount:c}=e,{workId:l,syncUnitTime:u}=t;u&&(this.syncUnitTime=u);const{tasks:h,effects:d,consumeIndex:g}=this.transformData(t,!1);this.syncIndex=Math.min(this.syncIndex,g,Math.max(0,this.tmpPoints.length-2));const p={name:l,id:ze(a)&&a.toString()||void 0};let f,m=!1;const w=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),o||n)){const N=i?this.fullLayer:this.drawLayer||this.fullLayer;f=this.draw({attrs:p,tasks:h,effects:d,layer:N,removeDrawCount:c})}if(o)return g>10&&this.tmpPoints.splice(0,g-10),{rect:f,type:D.DrawWork,dataType:B.Local};const I=[];return this.tmpPoints.slice(w).forEach(N=>{I.push(N.x,N.y,this.computRadius(N.z,this.workOptions.thickness))}),{...this.baseConsumeResult,type:D.DrawWork,dataType:B.Local,rect:f,op:m?I:void 0,index:m?w*3:void 0,updateNodeOpt:{useAnimation:!0}}}consumeAll(e){var u;const t=this.workId;if(e.data){const{op:h,workState:d}=e.data;h!=null&&h.length&&d===j.Done&&this.workOptions.strokeType===oe.Stroke&&this.updateTempPointsWithPressureWhenDone(h)}const i=this.transformDataAll(!0),o={name:t};let n;const a=this.fullLayer;if(i.length&&(n=this.draw({attrs:o,tasks:i,replaceId:t,layer:a})),this.tmpPoints.length<2)return this.replace(a,t),{type:D.RemoveNode,removeIds:[t],rect:n};const c=[];this.tmpPoints.map(h=>{c.push(h.x,h.y,h.z)}),this.syncTimestamp=0,delete this.workOptions.syncUnitTime;const l=Ge(c);return(u=this.vNodes)==null||u.setInfo(t,{rect:n,op:c,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&Y.getCenterPos(n,a)}),{...this.baseConsumeResult,rect:n,type:D.FullWork,dataType:B.Local,ops:l,updateNodeOpt:{pos:this.centerPos,useAnimation:!0}}}clearTmpPoints(){this.tmpPoints.length=0,this.syncTimestamp=0,this.syncIndex=0}consumeService(e){var h,d;const{op:t,isFullWork:i,replaceId:o,workState:n=j.Done}=e;this.tmpPoints.length=0;for(let g=0;g<t.length;g+=3){const p=new Q(t[g],t[g+1],t[g+2]);if(this.tmpPoints.length>0){const f=this.tmpPoints[this.tmpPoints.length-1],m=k.Sub(p,f).uni();p.setv(m)}this.tmpPoints.push(p)}if(this.tmpPoints.length<2)return;const a=this.transformDataAll(!0),c=(h=this.workId)==null?void 0:h.toString(),l={name:c};let u;if(c&&a.length){const g=i?this.fullLayer:this.drawLayer||this.fullLayer;u=this.draw({attrs:l,tasks:a,replaceId:o,layer:g,isDrawEraserlines:n===j.Done}),(d=this.vNodes)==null||d.setInfo(c,{rect:u,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:u&&Y.getCenterPos(u,g)})}return u}computPencilPoints(e){const t=[],{op:i,eraserPolylines:o,eraserThickness:n}=e;this.tmpPoints.length=0;for(let c=0;c<i.length;c+=3){const l=new Q(i[c],i[c+1],i[c+2]);if(this.tmpPoints.length>0){const u=this.tmpPoints[this.tmpPoints.length-1],h=k.Sub(l,u).uni();l.setv(h)}this.tmpPoints.push(l)}if(this.tmpPoints.length<2)return;const a=this.transformDataAll(!0);if(a.length)for(let c=0;c<a.length;c++){const{pos:l,points:u}=a[c],h=u.map(p=>p.point.addXY(l[0],l[1])),d=[];for(const p of o){const f=[];for(let w=0;w<p.length;w+=2){const I=new Q(p[w],p[w+1]);if(f.length>0){const N=f[f.length-1].point,C=k.Sub(I,N).uni();I.setv(C)}f.push({point:I,radius:n})}const{ps:m}=this.computStroke(f,!1);d.push(m.map(w=>w.XY))}dg(h,d,.01).forEach(p=>{t.push(p.map(f=>[f[0],f[1],f[2]]).flat(1))})}return t}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:i,replaceId:o,effects:n,layer:a,removeDrawCount:c,isDrawEraserlines:l=!0}=e,{strokeColor:u,strokeType:h,thickness:d,zIndex:g,scale:p,rotate:f,translate:m,eraserlines:w}=this.workOptions;n!=null&&n.size&&(n.forEach(x=>{var L;(L=a.getElementById(x+""))==null||L.remove()}),n.clear()),c&&this.removeDrawCountNodes(a,c);let I;const N=[],C=a.worldPosition,S=a.worldScaling;for(let x=0;x<i.length;x++){const{pos:L,points:b}=i[x],{ps:P,rect:A}=this.computDrawPoints(b);let E;const R=b.length===1;h===oe.Stroke||R?E=nt(P,!0):E=nt(P,!1);const z={pos:L,d:E,fillColor:h===oe.Stroke||R?u:void 0,lineDash:h===oe.Dotted&&!R?[1,d*2]:h===oe.LongDotted&&!R?[d,d*2]:void 0,strokeColor:u,lineCap:h===oe.Stroke||R?void 0:"round",lineWidth:h===oe.Stroke||R?0:d};I=ue(I,{x:Math.floor((A.x+L[0])*S[0]+C[0]-Y.SafeBorderPadding),y:Math.floor((A.y+L[1])*S[1]+C[1]-Y.SafeBorderPadding),w:Math.floor(A.w*S[0]+2*Y.SafeBorderPadding),h:Math.floor(A.h*S[1]+2*Y.SafeBorderPadding)}),N.push(z)}p&&(t.scale=p),f&&(t.rotate=f),m&&(t.translate=m);const v=new he.Group;if(I){this.centerPos=Y.getCenterPos(I,a);const x=h===oe.Stroke&&!w;v.attr({...t,normalize:!0,anchor:[.5,.5],bgcolor:x?u:void 0,pos:this.centerPos,size:[(I.w-2*Y.SafeBorderPadding)/S[0],(I.h-2*Y.SafeBorderPadding)/S[1]],zIndex:g});const L=N.map(b=>(b.pos=[b.pos[0]-this.centerPos[0],b.pos[1]-this.centerPos[1]],new he.Path(b)));v.append(...L),x&&v.seal(),w&&(this.scaleType=ce.proportional,this.drawEraserlines({group:v,eraserlines:w,pos:this.centerPos,layer:a},l)),this.replace(a,o,v)}if(p||f||m){const x=v==null?void 0:v.getBoundingClientRect();x&&(I={x:Math.floor(x.x-Y.SafeBorderPadding),y:Math.floor(x.y-Y.SafeBorderPadding),w:Math.floor(x.width+Y.SafeBorderPadding*2),h:Math.floor(x.height+Y.SafeBorderPadding*2)})}return this.isDelete&&v.setAttribute("opacity",0),I}computDrawPoints(e){return this.workOptions.strokeType===oe.Stroke||e.length===1?this.computStroke(e):this.computNomal(e)}computNomal(e){let t=this.workOptions.thickness;const i=e.map(o=>(t=Math.max(t,o.radius),o.point));return{ps:i,rect:Me(i,t)}}computStroke(e,t=!0){return e.length===1?this.computDotStroke(e[0]):this.computLineStroke(e,t)}computLineStroke(e,t=!0){const i=[],o=[];for(let c=0;c<e.length;c++){const{point:l,radius:u}=e[c];let h=l.v;c===0&&e.length>1&&(h=e[c+1].point.v);const d=k.Per(h).mul(u);i.push(Q.Sub(l,d)),o.push(Q.Add(l,d))}const n=e[e.length-1];if(t){const c=Q.GetSemicircleStroke(n.point,i[i.length-1],-1,8),l=Q.GetSemicircleStroke(e[0].point,o[0],-1,8),u=i.concat(c,o.reverse(),l);return{ps:u,rect:Me(u)}}const a=i.concat(o.reverse());return{ps:a,rect:Me(a)}}computDotStroke(e){const{point:t,radius:i}=e,o={x:t.x-i,y:t.y-i,w:i*2,h:i*2};return{ps:Q.GetDotStroke(t,i,8),rect:o}}transformData(e,t){const{op:i,workState:o}=e;let n=this.tmpPoints.length-1,a=[];if(i!=null&&i.length&&o){const{strokeType:c,thickness:l}=this.workOptions,u=new Set;n=c===oe.Stroke?this.updateTempPointsWithPressure(i,l,u):this.updateTempPoints(i,l,u);const h=t?this.tmpPoints:this.tmpPoints.slice(n);return a=this.getTaskPoints(h,l),{tasks:a,effects:u,consumeIndex:n}}return{tasks:a,consumeIndex:n}}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 h;const i=[];if(e.length===0)return[];let o=0,n=e[0].x,a=e[0].y,c=[n,a],l=[],u=e[0].t;for(;o<e.length;){const d=e[o],g=d.x-n,p=d.y-a,f=d.z,m=t?this.computRadius(f,t):f;if(l.push({point:new Q(g,p,f,e[o].v),radius:m}),o>0&&o<e.length-1){const w=e[o].getAngleByPoints(e[o-1],e[o+1]);if(w<60||w>300){const I=(h=l.pop())==null?void 0:h.point.clone();I&&i.push({taskId:u,pos:c,points:[...l,{point:I,radius:m}]}),n=e[o].x,a=e[o].y,c=[n,a];const N=d.x-n,C=d.y-a;l=[{point:new Q(N,C,f),radius:m}],u=Date.now()}}o++}return i.push({taskId:u,pos:c,points:l}),i}updateTempPointsWithPressure(e,t,i){const o=Date.now(),n=this.tmpPoints.length;let a=n;for(let l=0;l<e.length;l+=2){a=Math.min(a,n);const u=this.tmpPoints.length,h=new Q(e[l],e[l+1]);if(u===0){this.tmpPoints.push(h);continue}const d=u-1,g=this.tmpPoints[d],p=k.Sub(h,g).uni();if(h.isNear(g,t)){if(g.z<this.MAX_REPEAR){if(g.setz(Math.min(g.z+1,this.MAX_REPEAR)),a=Math.min(a,d),u>1){let w=u-1;for(;w>0;){const I=this.tmpPoints[w].distance(this.tmpPoints[w-1]),N=Math.max(this.tmpPoints[w].z-this.uniThickness*I,0);if(this.tmpPoints[w-1].z>=N)break;this.tmpPoints[w-1].setz(N),a=Math.min(a,w-1),w--}}}else a=1/0;continue}h.setv(p);const f=h.distance(g),m=Math.max(g.z-this.uniThickness*f,0);u>1&&k.Equals(p,g.v,.02)&&(m>0||g.z<=0)&&(i&&g.t&&i.add(g.t),this.tmpPoints.pop(),a=Math.min(d,a)),h.setz(m),this.tmpPoints.push(h)}if(a===1/0)return this.tmpPoints.length;let c=n;if(a===n){c=Math.max(c-1,0);const l=this.tmpPoints[c].t;l&&(i==null||i.add(l))}else{let l=n-1;for(c=a;l>=0;){const u=this.tmpPoints[l].t;if(u&&(i==null||i.add(u),l<=a)){c=l,l=-1;break}l--}}return this.tmpPoints[c].setT(o),c}updateTempPoints(e,t,i){var l;const o=Date.now(),n=this.tmpPoints.length;let a=n;for(let u=0;u<e.length;u+=2){const h=this.tmpPoints.length,d=new Q(e[u],e[u+1]);if(h===0){this.tmpPoints.push(d);continue}const g=h-1,p=this.tmpPoints[g],f=k.Sub(d,p).uni();if(d.isNear(p,t/2)){a=Math.min(g,a);continue}k.Equals(f,p.v,.02)&&(i&&p.t&&i.add(p.t),this.tmpPoints.pop(),a=Math.min(g,a)),d.setv(f),this.tmpPoints.push(d)}let c=n;if(a===n){c=Math.max(c-1,0);const u=this.tmpPoints[c].t;u&&(i==null||i.add(u))}else{let u=Math.min(n-1,a);for(c=a;u>=0;){const h=(l=this.tmpPoints[u])==null?void 0:l.t;if(h&&(i==null||i.add(h),u<=a)){c=u,u=-1;break}u--}}return this.tmpPoints[c].setT(o),c}updateTempPointsWithPressureWhenDone(e){const{thickness:t}=this.workOptions,i=e.length,o=this.getMinZ(t);for(let n=0;n<i;n+=2){const a=this.tmpPoints.length,c=new Q(e[n],e[n+1]);if(a===0){this.tmpPoints.push(c);continue}const l=a-1,u=this.tmpPoints[l],h=k.Sub(c,u).uni(),d=c.distance(u);if(a>1&&u.z===o)break;if(c.isNear(u,t/2)){if(i<3&&u.z<this.MAX_REPEAR&&(u.setz(Math.min(u.z+1,this.MAX_REPEAR)),a>1)){let p=a-1;for(;p>0;){const f=this.tmpPoints[p].distance(this.tmpPoints[p-1]),m=Math.max(this.tmpPoints[p].z-this.uniThickness*f,-t/4);if(this.tmpPoints[p-1].z>=m)break;this.tmpPoints[p-1].setz(m),p--}}continue}c.setv(h);const g=Math.max(u.z-this.uniThickness*d,o);a>1&&k.Equals(h,u.v,.02)&&u.z<=0&&this.tmpPoints.pop(),c.setz(g),this.tmpPoints.push(c)}}static updateNodeOpt(e){var l,u;const{node:t,opt:i,vNodes:o}=e,{strokeColor:n,strokeType:a}=i,c=o.get(t.name);return n&&(t.tagName==="GROUP"?py(t)?t.setAttribute("bgcolor",n):t.children.forEach(h=>{h.setAttribute("strokeColor",n),h.getAttribute("fillColor")&&h.setAttribute("fillColor",n)}):(t.setAttribute("strokeColor",n),t.setAttribute("fillColor",n)),(l=c==null?void 0:c.opt)!=null&&l.strokeColor&&(c.opt.strokeColor=n)),a&&(c!=null&&c.opt)&&((u=c.opt)!=null&&u.strokeType)&&(c.opt.strokeType=a),c&&o.setInfo(t.name,c),Y.updateNodeOpt(e)}}class _o extends Y{constructor(e){super(e);M(this,"toolsType",T.LaserPen);M(this,"canRotate",!1);M(this,"scaleType",ce.none);M(this,"syncTimestamp");M(this,"syncIndex",0);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"consumeIndex",0);this.workOptions=e.toolsOpt,this.syncTimestamp=0}combineConsume(){}setWorkOptions(e){super.setWorkOptions(e),this.syncTimestamp=Date.now()}consume(e){const{data:t,isSubWorker:i}=e,{workId:o,op:n,syncUnitTime:a}=t;if((n==null?void 0:n.length)===0)return{type:D.None};if(a&&(this.syncUnitTime=a),this.updateTempPoints(n||[]),this.consumeIndex>this.tmpPoints.length-4)return{type:D.None};const{strokeColor:c,thickness:l,strokeType:u}=this.workOptions,h=Me(this.tmpPoints,l);let d=!1;const g=this.syncIndex,p=this.tmpPoints.slice(this.consumeIndex);this.consumeIndex=this.tmpPoints.length-1,this.syncTimestamp===0&&(this.syncTimestamp=Date.now());const f={name:o==null?void 0:o.toString(),opacity:1,lineDash:u===oe.Dotted?[1,l*2]:u===oe.LongDotted?[l,l*2]:void 0,strokeColor:c,lineCap:"round",lineWidth:l,anchor:[.5,.5]},m=this.getTaskPoints(p);if(m.length){const I=Date.now();I-this.syncTimestamp>this.syncUnitTime&&(d=!0,this.syncTimestamp=I,this.syncIndex=this.tmpPoints.length),i&&this.draw({attrs:f,tasks:m,isDot:!1,layer:this.drawLayer||this.fullLayer})}const w=[];return this.tmpPoints.slice(g).forEach(I=>{w.push(I.x,I.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:D.DrawWork,dataType:B.Local,op:d?w:void 0,index:d?g*2:void 0,...this.baseConsumeResult}}consumeAll(){var n;const e=(n=this.workId)==null?void 0:n.toString();let t;if(this.tmpPoints.length-1>this.consumeIndex){let a=this.tmpPoints.slice(this.consumeIndex);const c=a.length===1,{strokeColor:l,thickness:u,strokeType:h}=this.workOptions;if(c){const p=this.computDotStroke({point:a[0],radius:u/2});a=p.ps,t=p.rect}else t=Me(this.tmpPoints,u);const d={name:e==null?void 0:e.toString(),fillColor:c?l:void 0,opacity:1,lineDash:h===oe.Dotted&&!c?[1,u*2]:h===oe.LongDotted&&!c?[u,u*2]:void 0,strokeColor:l,lineCap:c?void 0:"round",lineWidth:c?0:u,anchor:[.5,.5]},g=this.getTaskPoints(a);g.length&&this.draw({attrs:d,tasks:g,isDot:c,layer:this.drawLayer||this.fullLayer})}const i=[];this.tmpPoints.forEach(a=>{i.push(a.x,a.y)});const o=Ge(i);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:D.FullWork,dataType:B.Local,ops:o,index:this.syncIndex*2,...this.baseConsumeResult}}clearTmpPoints(){this.tmpPoints.length=0,this.syncTimestamp=0,this.syncIndex=0}consumeService(e){var f;const{op:t,replaceId:i,isFullWork:o}=e,{strokeColor:n,thickness:a,strokeType:c}=this.workOptions;if(!t.length){const m=Me(this.tmpPoints,a);return{x:m.x*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],y:m.y*this.fullLayer.worldScaling[1]+this.fullLayer.worldPosition[1],w:m.w*this.fullLayer.worldScaling[0],h:m.h*this.fullLayer.worldScaling[1]}}const l=Math.max(0,this.tmpPoints.length-1);this.updateTempPoints(t||[]);let u,h=this.tmpPoints.slice(l);const d=h.length===1;if(d){const m=this.computDotStroke({point:h[0],radius:a/2});h=m.ps,u=m.rect}else u=Me(this.tmpPoints,a);const g={name:(f=this.workId)==null?void 0:f.toString(),fillColor:d?n:void 0,opacity:1,lineDash:c===oe.Dotted&&!d?[1,a*2]:c===oe.LongDotted&&!d?[a,a*2]:void 0,strokeColor:n,lineCap:d?void 0:"round",lineWidth:d?0:a,anchor:[.5,.5]},p=this.getTaskPoints(h);if(p.length){const m=o?this.fullLayer:this.drawLayer||this.fullLayer;this.draw({attrs:g,tasks:p,isDot:d,replaceId:i,layer:m})}return{x:u.x*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],y:u.y*this.fullLayer.worldScaling[1]+this.fullLayer.worldPosition[1],w:u.w*this.fullLayer.worldScaling[0],h:u.h*this.fullLayer.worldScaling[1]}}computDotStroke(e){const{point:t,radius:i}=e,o={x:t.x-i,y:t.y-i,w:i*2,h:i*2};return{ps:Q.GetDotStroke(t,i,8),rect:o}}updateTempPoints(e){const t=this.tmpPoints.length;for(let i=0;i<e.length;i+=2){if(t){const o=this.tmpPoints.slice(-1)[0];o&&o.x===e[i]&&o.y===e[i+1]&&this.tmpPoints.pop()}this.tmpPoints.push(new Q(e[i],e[i+1]))}}async draw(e){const{attrs:t,tasks:i,isDot:o,layer:n}=e,{duration:a}=this.workOptions;for(const c of i){const l=new he.Path,{pos:u,points:h}=c;let d;o?d=nt(h,!0):d=nt(h,!1),l.attr({...t,pos:u,d});const{vertex:g,fragment:p}=this.workOptions;if(g&&p){const f=n.renderer.createProgram({vertex:g,fragment:p}),{width:m,height:w}=n.getResolution();l.setUniforms({u_time:0,u_resolution:[m,w]}),l.setProgram(f)}n.appendChild(l),l.transition(a).attr({scale:o?[.1,.1]:[1,1],lineWidth:o?0:1}).then(()=>{l.remove()})}}getTaskPoints(e){var l;const t=[];if(e.length===0)return[];let i=0,o=e[0].x,n=e[0].y,a=[o,n],c=[];for(;i<e.length;){const u=e[i],h=u.x-o,d=u.y-n;if(c.push(new Q(h,d)),i>0&&i<e.length-1){const g=e[i].getAngleByPoints(e[i-1],e[i+1]);if(g<60||g>300){const p=(l=c.pop())==null?void 0:l.clone();p&&t.push({pos:a,points:[...c,p]}),o=e[i].x,n=e[i].y,a=[o,n];const f=u.x-o,m=u.y-n;c=[new Q(f,m)]}}i++}return t.push({pos:a,points:c}),t}removeLocal(){}removeService(e){let t;const i=[];return this.fullLayer.getElementsByName(e).forEach(o=>{if(o.name===e){const n=o.getBoundingClientRect();t=ue(t,{x:n.x,y:n.y,w:n.width,h:n.height}),i.push(o)}}),i.length&&i.forEach(o=>o.remove()),t}}const zt=class zt extends Y{constructor(e,t){super(e);M(this,"canRotate",!1);M(this,"scaleType",ce.none);M(this,"toolsType",T.Eraser);M(this,"serviceWork");M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"worldPosition");M(this,"worldScaling");M(this,"eraserRect");M(this,"eraserPolyline");this.serviceWork=t,this.workOptions=e.toolsOpt,this.worldPosition=this.fullLayer.worldPosition,this.worldScaling=this.fullLayer.worldScaling}combineConsume(){}consumeService(){}setWorkOptions(e){super.setWorkOptions(e)}createEraserRect(e){const t=e[0]*this.worldScaling[0]+this.worldPosition[0],i=e[1]*this.worldScaling[1]+this.worldPosition[1],{width:o,height:n}=zt.eraserSizes[this.workOptions.thickness];this.eraserRect={x:t-o*.5,y:i-n*.5,w:o,h:n},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 k(this.tmpPoints[0],this.tmpPoints[1]),i=new k(this.tmpPoints[2],this.tmpPoints[3]),o=k.Sub(i,t).uni(),n=k.Dist(t,i),{width:a,height:c}=zt.eraserSizes[this.workOptions.thickness],l=Math.min(a,c),u=Math.round(n/l);if(u>1){const h=[];for(let d=0;d<u;d++){const g=k.Mul(o,d*l);h.push(this.tmpPoints[0]+g.x,this.tmpPoints[1]+g.y)}return h.concat(e)}}return e}isNear(e,t){const i=new k(e[0],e[1]),o=new k(t[0],t[1]),{width:n,height:a}=zt.eraserSizes[this.workOptions.thickness];return k.Dist(i,o)<Math.hypot(n,a)*.5}remove(e){const{curNodeMap:t,removeIds:i}=e;let o;for(const n of t.values())if(n.rect&&this.eraserRect&&this.eraserPolyline&&Gs(this.eraserRect,n.rect)){const{op:a}=n,c=[],l=[];for(let h=0;h<a.length;h+=3){const d=new k(a[h]*this.worldScaling[0]+this.worldPosition[0],a[h+1]*this.worldScaling[1]+this.worldPosition[1],a[h+2]);l.push(d),c.push(new Q(d.x,d.y))}const u=c.length&&Me(c)||n.rect;Gs(u,this.eraserRect)&&(l.length>1?_s.polyline(l.map(d=>d.XY),this.eraserPolyline).length&&i.add(n.name):i.add(n.name),o=ue(o,n.rect||u))}return i.forEach(n=>{var c;const a=this.fullLayer.getElementsByName(n);a[0]&&(a[0].remove(),He(a[0],this.fullLayer.parent),(c=this.vNodes)==null||c.delete(n))}),o&&(o.x-=Y.SafeBorderPadding,o.y-=Y.SafeBorderPadding,o.w+=Y.SafeBorderPadding*2,o.h+=Y.SafeBorderPadding*2),o}consume(e){const{op:t,disableEraseImage:i,disableEraseText:o}=e.data;if(!t||t.length===0)return{type:D.None,...this.baseConsumeResult};const n=this.tmpPoints.length;if(n>1&&this.isNear([t[0],t[1]],[this.tmpPoints[n-2],this.tmpPoints[n-1]]))return{type:D.None,...this.baseConsumeResult};n<3?this.tmpPoints.push(t[0],t[1]):this.tmpPoints.splice(2,2,t[0],t[1]);const a=this.computRectCenterPoints();let c;const l=new Set;if(!this.vNodes)return{type:D.None,...this.baseConsumeResult};const u=this.getCanEraserNodeMap(this.vNodes.getCanEraserNodes(this.vNodes.curNodeMap,{disableEraseImage:i,disableEraseText:o}));for(let h=0;h<a.length-1;h+=2){this.createEraserRect(a.slice(h,h+2));const d=this.remove({curNodeMap:u,removeIds:l});c=ue(c,d)}return c&&l.size?{type:D.RemoveNode,rect:c,removeIds:[...l]}:{type:D.None,...this.baseConsumeResult}}consumeAll(e){return this.consume(e)}clearTmpPoints(){this.tmpPoints.length=0}getCanEraserNodeMap(e){var t;if(this.serviceWork){const i=new Map(e),o=this.serviceWork.selectorWorkShapes,n=this.serviceWork.workShapes;for(const a of o.values())if((t=a.selectIds)!=null&&t.length)for(const c of a.selectIds)i.delete(c);for(const a of n.keys())i.delete(a);return i}return e}};M(zt,"eraserSizes",ui);let ds=zt;const Ze="++",G="selector",cs="all";var pg="__lodash_hash_undefined__";function gg(r){return this.__data__.set(r,pg),this}var fg=gg;function Mg(r){return this.__data__.has(r)}var yg=Mg,mg=ko,wg=fg,Ig=yg;function ps(r){var s=-1,e=r==null?0:r.length;for(this.__data__=new mg;++s<e;)this.add(r[s])}ps.prototype.add=ps.prototype.push=wg;ps.prototype.has=Ig;var di=ps;function Tg(r,s){for(var e=-1,t=r==null?0:r.length;++e<t;)if(s(r[e],e,r))return!0;return!1}var vg=Tg;function Ng(r,s){return r.has(s)}var pi=Ng,Sg=di,Cg=vg,kg=pi,xg=1,Dg=2;function Lg(r,s,e,t,i,o){var n=e&xg,a=r.length,c=s.length;if(a!=c&&!(n&&c>a))return!1;var l=o.get(r),u=o.get(s);if(l&&u)return l==s&&u==r;var h=-1,d=!0,g=e&Dg?new Sg:void 0;for(o.set(r,s),o.set(s,r);++h<a;){var p=r[h],f=s[h];if(t)var m=n?t(f,p,h,s,r,o):t(p,f,h,r,s,o);if(m!==void 0){if(m)continue;d=!1;break}if(g){if(!Cg(s,function(w,I){if(!kg(g,I)&&(p===w||i(p,w,e,t,o)))return g.push(I)})){d=!1;break}}else if(!(p===f||i(p,f,e,t,o))){d=!1;break}}return o.delete(r),o.delete(s),d}var en=Lg;function bg(r){var s=-1,e=Array(r.size);return r.forEach(function(t,i){e[++s]=[i,t]}),e}var jg=bg;function Ag(r){var s=-1,e=Array(r.size);return r.forEach(function(t){e[++s]=t}),e}var gi=Ag,qi=es,Ki=Zo,Pg=ei,zg=en,Eg=jg,Og=gi,Rg=1,Wg=2,Yg="[object Boolean]",Ug="[object Date]",Bg="[object Error]",Fg="[object Map]",Vg="[object Number]",Qg="[object RegExp]",Zg="[object Set]",Hg="[object String]",Gg="[object Symbol]",$g="[object ArrayBuffer]",Xg="[object DataView]",_i=qi?qi.prototype:void 0,Es=_i?_i.valueOf:void 0;function Jg(r,s,e,t,i,o,n){switch(e){case Xg:if(r.byteLength!=s.byteLength||r.byteOffset!=s.byteOffset)return!1;r=r.buffer,s=s.buffer;case $g:return!(r.byteLength!=s.byteLength||!o(new Ki(r),new Ki(s)));case Yg:case Ug:case Vg:return Pg(+r,+s);case Bg:return r.name==s.name&&r.message==s.message;case Qg:case Hg:return r==s+"";case Fg:var a=Eg;case Zg:var c=t&Rg;if(a||(a=Og),r.size!=s.size&&!c)return!1;var l=n.get(r);if(l)return l==s;t|=Wg,n.set(r,s);var u=zg(a(r),a(s),t,i,o,n);return n.delete(r),u;case Gg:if(Es)return Es.call(r)==Es.call(s)}return!1}var qg=Jg,eo=Fo,Kg=1,_g=Object.prototype,ef=_g.hasOwnProperty;function tf(r,s,e,t,i,o){var n=e&Kg,a=eo(r),c=a.length,l=eo(s),u=l.length;if(c!=u&&!n)return!1;for(var h=c;h--;){var d=a[h];if(!(n?d in s:ef.call(s,d)))return!1}var g=o.get(r),p=o.get(s);if(g&&p)return g==s&&p==r;var f=!0;o.set(r,s),o.set(s,r);for(var m=n;++h<c;){d=a[h];var w=r[d],I=s[d];if(t)var N=n?t(I,w,d,s,r,o):t(w,I,d,r,s,o);if(!(N===void 0?w===I||i(w,I,e,t,o):N)){f=!1;break}m||(m=d=="constructor")}if(f&&!m){var C=r.constructor,S=s.constructor;C!=S&&"constructor"in r&&"constructor"in s&&!(typeof C=="function"&&C instanceof C&&typeof S=="function"&&S instanceof S)&&(f=!1)}return o.delete(r),o.delete(s),f}var sf=tf,Os=xo,of=en,nf=qg,rf=sf,to=Ls,so=ts,io=si,af=zo,cf=1,oo="[object Arguments]",no="[object Array]",ns="[object Object]",lf=Object.prototype,ro=lf.hasOwnProperty;function hf(r,s,e,t,i,o){var n=so(r),a=so(s),c=n?no:to(r),l=a?no:to(s);c=c==oo?ns:c,l=l==oo?ns:l;var u=c==ns,h=l==ns,d=c==l;if(d&&io(r)){if(!io(s))return!1;n=!0,u=!1}if(d&&!u)return o||(o=new Os),n||af(r)?of(r,s,e,t,i,o):nf(r,s,c,e,t,i,o);if(!(e&cf)){var g=u&&ro.call(r,"__wrapped__"),p=h&&ro.call(s,"__wrapped__");if(g||p){var f=g?r.value():r,m=p?s.value():s;return o||(o=new Os),i(f,m,e,t,o)}}return d?(o||(o=new Os),rf(r,s,e,t,i,o)):!1}var uf=hf,df=uf,ao=at;function tn(r,s,e,t,i){return r===s?!0:r==null||s==null||!ao(r)&&!ao(s)?r!==r&&s!==s:df(r,s,e,t,tn,i)}var pf=tn,gf=pf;function ff(r,s){return gf(r,s)}var Mf=ff;const lt=Ut(Mf);function ss(r,s,e){return"#"+((r<<16)+(s<<8)+e).toString(16).padStart(6,"0")}function je(r,s=1){return"rgba("+parseInt("0x"+r.slice(1,3))+","+parseInt("0x"+r.slice(3,5))+","+parseInt("0x"+r.slice(5,7))+","+s+")"}function gt(r,s,e,t=1){return`rgba(${r},${s},${e},${t})`}function bs(r){const s=r.split(","),e=parseInt(s[0].split("(")[1]),t=parseInt(s[1]),i=parseInt(s[2]),o=Number(s[3].split(")")[0]);return[ss(e,t,i),o]}function Xt(r){const s=r.split(","),e=parseInt(s[0].split("(")[1]),t=parseInt(s[1]),i=parseInt(s[2]),o=Number(s[3].split(")")[0]);return[e,t,i,o]}function rs(r){return r==="transparent"}const Is=class Is extends Y{constructor(e){super(e);M(this,"toolsType",T.Selector);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"vNodes");M(this,"selectIds");M(this,"selectorColor");M(this,"strokeColor");M(this,"fillColor");M(this,"oldSelectRect");M(this,"canRotate",!1);M(this,"canTextEdit",!1);M(this,"canLock",!1);M(this,"scaleType",ce.all);M(this,"toolsTypes");M(this,"shapeOpt");M(this,"textOpt");M(this,"isLocked");M(this,"thickness");M(this,"strokeType");M(this,"useStroke");this.workOptions=e.toolsOpt,this.vNodes=e.vNodes}computSelector(e=!0){const t=Me(this.tmpPoints);if(t.w===0||t.h===0)return{selectIds:[],intersectRect:void 0,subNodeMap:new Map};const{rectRange:i,nodeRange:o}=this.vNodes.getRectIntersectRange(t,e);return{selectIds:[...o.keys()],intersectRect:i,subNodeMap:o}}updateTempPoints(e){const t=this.tmpPoints.length,i=e.length;if(i>1){const o=new Q(e[i-2]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],e[i-1]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[1]);t===2?this.tmpPoints.splice(1,1,o):this.tmpPoints.push(o)}}drawSelector(e){const{drawRect:t,subNodeMap:i,selectorId:o,layer:n,isService:a}=e,c=new he.Group({pos:[t.x,t.y],anchor:[0,0],size:[t.w,t.h],id:o,name:o,zIndex:9999}),l=[];if(a){const u=new he.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:Is.selectorBorderId});l.push(u)}i.forEach((u,h)=>{const d=[u.rect.x+u.rect.w/2-t.x,u.rect.y+u.rect.h/2-t.y],g=new he.Rect({normalize:!0,pos:d,lineWidth:1,strokeColor:i.size>1?this.selectorColor||this.workOptions.strokeColor:void 0,width:u.rect.w,height:u.rect.h,id:`selector-${h}`,name:`selector-${h}`});l.push(g)}),l&&c.append(...l),(n==null?void 0:n.parent).appendChild(c)}draw(e,t,i,o=!1){var c,l;const{intersectRect:n,subNodeMap:a}=i;(l=(c=t.parent)==null?void 0:c.getElementById(e))==null||l.remove(),n&&this.drawSelector({drawRect:n,subNodeMap:a,selectorId:e,layer:t,isService:o})}getSelecteorInfo(e){this.scaleType=ce.all,this.canRotate=!1,this.textOpt=void 0,this.strokeColor=void 0,this.fillColor=void 0,this.canTextEdit=!1,this.canLock=!1,this.isLocked=!1,this.toolsTypes=void 0,this.shapeOpt=void 0,this.thickness=void 0,this.strokeType=void 0,this.useStroke=!1;const t=new Set;let i,o=!0;for(const n of e.values()){const{opt:a,canRotate:c,scaleType:l,toolsType:u}=n;this.selectorColor=this.workOptions.strokeColor,a.strokeColor&&(this.strokeColor=a.strokeColor),a.fillColor&&(this.fillColor=a.fillColor),a.textOpt&&(this.textOpt=a.textOpt),a.thickness&&(this.thickness=a.thickness),u!==T.Pencil&&(o=!1),a.strokeType&&(this.strokeType=a.strokeType),u===T.SpeechBalloon&&(t.add(u),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.placement=a.placement),u===T.Polygon&&(t.add(u),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=a.vertices),u===T.Star&&(t.add(u),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=a.vertices,this.shapeOpt.innerRatio=a.innerRatio,this.shapeOpt.innerVerticeStep=a.innerVerticeStep),u===T.Text&&(this.textOpt=a),e.size===1&&(this.textOpt&&(this.canTextEdit=!0),this.canRotate=c,this.scaleType=l),u===T.Image&&(i=n),(l===ce.proportional&&this.scaleType!==ce.none||l===ce.none)&&(this.scaleType=l)}o&&(this.useStroke=!0),t.size&&(this.toolsTypes=[...t]),i&&(e.size===1?(this.canLock=!0,i.opt.locked&&(this.isLocked=!0,this.scaleType=ce.none,this.canRotate=!1,this.textOpt=void 0,this.fillColor=void 0,this.selectorColor="rgb(177,177,177)",this.strokeColor=void 0,this.canTextEdit=!1,this.thickness=void 0,this.strokeType=void 0,this.useStroke=void 0)):e.size>1&&!i.opt.locked&&(this.canLock=!1,this.canRotate=!1))}getChildrenPoints(){var e,t;if(this.scaleType===ce.both&&((e=this.selectIds)==null?void 0:e.length)===1){const i=this.selectIds[0],o=(t=this.vNodes.get(i))==null?void 0:t.op;if(o){const n=[];for(let a=0;a<o.length;a+=3)n.push([o[a],o[a+1]]);return n}}}consume(e){if(e.isSubWorker)return this.subWorkerConsume(e);const{op:t,workState:i}=e.data;let o=this.oldSelectRect;if(i===j.Start&&(o=this.unSelectedAllIds()),!(t!=null&&t.length)||!this.vNodes.curNodeMap.size)return{type:D.None};this.updateTempPoints(t);const n=this.computSelector();if(this.selectIds&&lt(this.selectIds,n.selectIds))return{type:D.None};this.selectIds=n.selectIds;const a=n.intersectRect;this.getSelecteorInfo(n.subNodeMap),this.draw(G,this.fullLayer,n),this.oldSelectRect=a;const c=this.getChildrenPoints();return{type:D.Select,dataType:B.Local,rect:ue(a,o),selectIds:n.selectIds,selectRect:a,selectorColor:this.selectorColor,strokeColor:this.strokeColor,fillColor:this.fillColor,textOpt:this.textOpt,canTextEdit:this.canTextEdit,canRotate:this.canRotate,canLock:this.canLock,scaleType:this.scaleType,willSyncService:!0,points:c,isLocked:this.isLocked,toolsTypes:this.toolsTypes,shapeOpt:this.shapeOpt,thickness:this.thickness,useStroke:this.useStroke,strokeType:this.strokeType,...this.baseConsumeResult}}consumeAll(){var t,i;let e=this.oldSelectRect;if(!((t=this.selectIds)!=null&&t.length)&&this.tmpPoints[0]&&this.selectSingleTool(this.tmpPoints[0].XY,G,!1),(i=this.selectIds)!=null&&i.length&&(e=this.selectedByIds(this.selectIds)),e){const o=this.getChildrenPoints();return{type:D.Select,dataType:B.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:o,isLocked:this.isLocked,toolsTypes:this.toolsTypes,shapeOpt:this.shapeOpt,thickness:this.thickness,useStroke:this.useStroke,strokeType:this.strokeType,...this.baseConsumeResult}}return{type:D.None}}consumeService(){}updateTempPointsForSubWorker(e){const t=e.slice(-2),i=new Q(t[0],t[1]);if(this.tmpPoints[0].isNear(i,1))return!1;if(this.tmpPoints.length===2){if(i.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=i}else this.tmpPoints.push(i);return!0}computDrawPoints(e){const{thickness:t}=this.workOptions,i=[];for(const a of e)i.push(new k(...a));const o=Me(i,t),n=[o.x+o.w/2,o.y+o.h/2];return{rect:o,pos:n,points:i.map(a=>a.XY).flat(1)}}drawForSubWorker(e){const{workId:t,layer:i,ps:o}=e,{strokeColor:n,scale:a,rotate:c,translate:l}=this.workOptions,u=i.worldPosition,h=i.worldScaling,{points:d,rect:g,pos:p}=this.computDrawPoints(o),f=1/i.worldScaling[0],m=n&&Xt(n)||[0,0,0,0],w={close:!0,normalize:!0,points:d,lineWidth:f,fillColor:gt(m[0],m[1],m[2],.1),strokeColor:gt(m[0],m[1],m[2],1),lineJoin:"round",lineCap:"round"};let I={x:Math.floor(g.x*h[0]+u[0]-Y.SafeBorderPadding),y:Math.floor(g.y*h[1]+u[1]-Y.SafeBorderPadding),w:Math.floor(g.w*h[0]+2*Y.SafeBorderPadding),h:Math.floor(g.h*h[0]+2*Y.SafeBorderPadding)};const N=new he.Group({name:t,id:t,pos:p,anchor:[.5,.5],size:[g.w,g.h],scale:a,rotate:c,translate:l}),C=new he.Polyline({...w,pos:[0,0]});if(N.appendChild(C),this.replace(i,t,N),a||c||l){const S=N.getBoundingClientRect();I={x:Math.floor(S.x-Y.SafeBorderPadding),y:Math.floor(S.y-Y.SafeBorderPadding),w:Math.floor(S.width+2*Y.SafeBorderPadding),h:Math.floor(S.height+2*Y.SafeBorderPadding)}}return I}transformData(){const e=Me(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]]}subWorkerConsume(e){const{data:t,isFullWork:i}=e,{op:o,syncUnitTime:n}=t;n&&(this.syncUnitTime=n);const a=o==null?void 0:o.length;if(!a||a<2)return{type:D.None};let c;if(this.tmpPoints.length===0?(this.tmpPoints=[new Q(o[0],o[1])],c=!1):c=this.updateTempPointsForSubWorker(o),!c)return{type:D.None};const l=this.transformData(),u=i?this.fullLayer:this.drawLayer||this.fullLayer,h=this.drawForSubWorker({ps:l,workId:this.workId,layer:u}),d=ue(h,this.oldSelectRect);return this.oldSelectRect=h,{rect:d,type:D.DrawWork,dataType:B.Local,...this.baseConsumeResult}}subWorkerConsumeAll(e){const{isFullWork:t}=e,i=t?this.fullLayer:this.drawLayer||this.fullLayer;return this.replace(i,this.workId),{rect:this.oldSelectRect,type:D.FullWork,dataType:B.Local,...this.baseConsumeResult}}clearTmpPoints(){this.tmpPoints.length=0}clearSelectData(){this.selectIds=void 0,this.oldSelectRect=void 0}selectSingleTool(e,t=G,i=!1){if(e.length===2){const o=e[0],n=e[1];let a;const{nodeRange:c}=this.vNodes.getRectIntersectRange({x:o,y:n,w:0,h:0},!1),l=[...c.values()].sort((u,h)=>(h.opt.zIndex||0)-(u.opt.zIndex||0));for(const u of l){const h=this.fullLayer.getElementsByName(u.name);if(un(h).find(g=>g.isPointCollision(o,n))){a=u;break}}if(a){const u=a.name;if(!lt(this.oldSelectRect,a.rect)){const h=new Map([[u,a]]);this.getSelecteorInfo(h),this.draw(t,this.fullLayer,{intersectRect:a.rect,subNodeMap:h,selectIds:this.selectIds||[]},i)}this.selectIds=[u],this.oldSelectRect=a.rect}}}unSelectedAllIds(){let e;for(const[t,i]of this.vNodes.curNodeMap.entries())i.isSelected&&(e=ue(e,i.rect),this.vNodes.unSelected(t));return e}unSelectedByIds(e){let t;for(const i of e){const o=this.vNodes.get(i);o&&o.isSelected&&(t=ue(t,o.rect),this.vNodes.unSelected(i))}return t}selectedByIds(e){let t;for(const i of e){const o=this.vNodes.get(i);o&&(t=ue(t,o.rect),this.vNodes.selected(i))}return t}getSelectorRect(e,t){var a;let i;const o=(a=e.parent)==null?void 0:a.getElementById(t),n=o==null?void 0:o.getBoundingClientRect();return n&&(i=ue(i,{x:Math.floor(n.x),y:Math.floor(n.y),w:Math.floor(n.width+1),h:Math.floor(n.height+1)})),i}isCanFillColor(e){return e===T.Ellipse||e===T.Triangle||e===T.Rectangle||e===T.Polygon||e===T.Star||e===T.SpeechBalloon}async updateSelector(e){const{updateSelectorOpt:t,selectIds:i,vNodes:o,willSerializeData:n,worker:a,offset:c}=e,l=this.fullLayer;if(!l)return;let u;const h=new Map,{originPoint:d,workState:g,angle:p,translate:f,dir:m,scale:w}=t;c&&(f?t.translate=[f[0]+c[0],f[1]+c[1]]:t.translate=c);let I;if(d||f||ze(p)){if(g===j.Start&&i)return o.setTargetAssignKeys(i),{type:D.Select,dataType:B.Local,selectRect:this.oldSelectRect,rect:this.oldSelectRect};if(I=o.getLastTarget(),!I)return}if(i)for(const S of i){const v=o.get(S);if(v){const{toolsType:x,opt:L}=v,b=(l==null?void 0:l.getElementsByName(S))[0];if(b){const P={...t};let A;const E=Y.isWillRefresh({toolsType:x,opt:L,updateOpt:P,vNodes:o,node:b,willSerializeData:n});if(x){A=I==null?void 0:I.get(S);const R=hn(x);if(R==null||R.updateNodeOpt({node:b,opt:P,vNodes:o,willSerializeData:n,targetNode:A}),v&&a&&E){const z=a.createWorkShapeNode({workId:S,toolsType:x,toolsOpt:v.opt});z==null||z.setWorkId(S);let Z;if(x===T.Image)Z=await z.consumeServiceAsync({isFullWork:!0,replaceId:S,worker:a});else if(x===T.Text)Z=await z.consumeServiceAsync({isFullWork:!0,replaceId:S});else try{Z=z==null?void 0:z.consumeService({op:v.op,isFullWork:!0,replaceId:S,workState:g})}catch{continue}Z&&(v.rect=Z)}v&&(h.set(S,v),u=ue(u,v.rect))}}}}I&&g===j.Done&&(o.deleteLastTarget(),I=void 0);const N=u;if(d&&f&&w&&m&&N&&!c){const S=[[N.x,N.y],[N.x+N.w,N.y],[N.x+N.w,N.y+N.h],[N.x,N.y+N.h]];let v;switch(m){case"top":case"topLeft":case"left":f[0]>0&&f[1]>0?v=S[0]:f[0]>0?v=S[3]:f[1]>0?v=S[1]:v=S[2];break;case"topRight":f[0]<0&&f[1]>0?v=S[1]:f[0]<0?v=S[2]:f[1]>0?v=S[0]:v=S[3];break;case"right":case"bottomRight":case"bottom":f[0]<0&&f[1]<0?v=S[2]:f[0]<0?v=S[1]:f[1]<0?v=S[3]:v=S[0];break;case"bottomLeft":f[0]>0&&f[1]<0?v=S[3]:f[0]>0?v=S[0]:f[1]<0?v=S[2]:v=S[1];break}const x=v&&[d[0]-v[0],d[1]-v[1]]||[0,0];if(!lt(x,[0,0]))return await this.updateSelector({...e,updateSelectorOpt:{workState:g},offset:x})}this.getSelecteorInfo(h),this.draw(G,l,{selectIds:i||[],subNodeMap:h,intersectRect:N});const C=ue(this.oldSelectRect,N);return this.oldSelectRect=N,{type:D.Select,dataType:B.Local,selectRect:N,renderRect:u,rect:ue(C,N),selectIds:i}}blurSelector(){const e=this.unSelectedAllIds();return{type:D.Select,dataType:B.Local,rect:e,selectIds:[],willSyncService:!0}}getRightServiceId(e){return e.replace(Ze,"-")}selectServiceNode(e,t,i){const{selectIds:o}=t,n=this.getRightServiceId(e),a=this.getSelectorRect(this.fullLayer,n);let c;const l=new Map;return o==null||o.forEach(u=>{const h=this.vNodes.get(u);h&&(c=ue(c,h.rect),l.set(u,h))}),this.getSelecteorInfo(l),this.draw(n,this.fullLayer,{intersectRect:c,selectIds:o||[],subNodeMap:l},i),ue(c,a)}reRenderSelector(){var i;let e;const t=new Map;return(i=this.selectIds)==null||i.forEach(o=>{const n=this.vNodes.get(o);n&&(e=ue(e,n.rect),t.set(o,n))},this),this.getSelecteorInfo(t),this.draw(G,this.fullLayer,{intersectRect:e,subNodeMap:t,selectIds:this.selectIds||[]}),this.oldSelectRect=e,e}updateSelectIds(e){var n;let t;const i=(n=this.selectIds)==null?void 0:n.filter(a=>!e.includes(a));if(i!=null&&i.length&&(t=this.unSelectedByIds(i)),e.length){const a=this.selectedByIds(e);t=ue(t,a)}this.selectIds=e;const o=this.reRenderSelector();return{bgRect:t,selectRect:o}}cursorHover(e){var n,a;const t=this.oldSelectRect;this.selectIds=[];const i=(n=this.workId)==null?void 0:n.toString(),o=[e[0]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],e[1]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[1]];if(this.selectSingleTool(o,i,!0),this.oldSelectRect&&!lt(t,this.oldSelectRect))return{type:D.CursorHover,dataType:B.Local,rect:ue(t,this.oldSelectRect),selectorColor:this.selectorColor,willSyncService:!1};if((a=this.selectIds)!=null&&a.length||(this.oldSelectRect=void 0),t&&!this.oldSelectRect)return this.cursorBlur(),{type:D.CursorHover,dataType:B.Local,rect:t,selectorColor:this.selectorColor,willSyncService:!1}}cursorBlur(){var t,i;this.selectIds=[];const e=(t=this.workId)==null?void 0:t.toString();((i=this.fullLayer)==null?void 0:i.parent).children.forEach(o=>{o.name===e&&o.remove()})}};M(Is,"selectorBorderId","selector-border");let gs=Is;class sn extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",ce.both);M(this,"toolsType",T.Arrow);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"oldRect");M(this,"arrowTipWidth");M(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.arrowTipWidth=this.workOptions.thickness*4,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:i,isSubWorker:o,isMainThread:n}=e,a=this.workId,{op:c,syncUnitTime:l}=t;l&&(this.syncUnitTime=l);const u=c==null?void 0:c.length;if(!u||u<2)return{type:D.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new Q(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:D.None};let d;if(o||n){const p=i?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:a,layer:p})}if(!o){const p=Date.now();return p-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=p,{...this.baseConsumeResult,type:D.DrawWork,dataType:B.Local,op:this.tmpPoints.map(f=>[...f.XY,0]).flat(1),isSync:!0,index:0}):{type:D.None}}const g=ue(d,this.oldRect);return this.oldRect=d,{rect:g,...this.baseConsumeResult,type:D.DrawWork,dataType:B.Local}}consumeAll(){var a;const e=this.workId;if(this.tmpPoints.length<2)return{type:D.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t});this.oldRect=i;const o=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Ge(o);return(a=this.vNodes)==null||a.setInfo(e,{rect:i,op:o,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:Y.getCenterPos(i,t)}),{rect:i,...this.baseConsumeResult,type:D.FullWork,dataType:B.Local,ops:n,isSync:!0}}draw(e){const{workId:t,layer:i,isDrawEraserlines:o}=e,{strokeColor:n,thickness:a,zIndex:c,scale:l,rotate:u,translate:h,strokeType:d,eraserlines:g}=this.workOptions,p=i.worldPosition,f=i.worldScaling,{points:m,pos:w,rect:I,isTriangle:N,trianglePoints:C,trianglePos:S}=this.computDrawPoints(a),v=[I.x+I.w/2,I.y+I.h/2],x={pos:v,name:t,id:t,zIndex:c,anchor:[.5,.5],size:[I.w,I.h]};l&&(x.scale=l),u&&(x.rotate=u),h&&(x.translate=h);const L=new he.Group(x),b={points:C,pos:[S[0]-v[0],S[1]-v[1]],fillColor:n,strokeColor:n,lineWidth:0,normalize:!1},P=new he.Polyline(b);if(L.append(P),!N&&m&&w){const E={points:m,pos:[w[0]-v[0],w[1]-v[1]],fillColor:n,strokeColor:n,lineDash:d===oe.Dotted&&!N?[1,a*2]:d===oe.LongDotted&&!N?[a,a*2]:void 0,lineCap:d===oe.Normal?void 0:"round",lineWidth:a,normalize:!1},R=new he.Polyline(E);L.append(R)}g&&(this.scaleType=ce.proportional,this.drawEraserlines({group:L,eraserlines:g,pos:v,layer:i},o)),this.replace(i,t,L);let A={x:Math.floor(I.x*f[0]+p[0]-Y.SafeBorderPadding),y:Math.floor(I.y*f[1]+p[1]-Y.SafeBorderPadding),w:Math.floor(I.w*f[0]+2*Y.SafeBorderPadding),h:Math.floor(I.h*f[1]+2*Y.SafeBorderPadding)};if(l||u||h){const E=L.getBoundingClientRect();A={x:Math.floor(E.x-Y.SafeBorderPadding),y:Math.floor(E.y-Y.SafeBorderPadding),w:Math.floor(E.width+Y.SafeBorderPadding*2),h:Math.floor(E.height+Y.SafeBorderPadding*2)}}return this.isDelete&&L.setAttribute("opacity",0),A}computDrawPoints(e){return this.tmpPoints[1].distance(this.tmpPoints[0])>this.arrowTipWidth?this.computFullArrowPoints(e):this.computTrianglePoints()}computFullArrowPoints(e){const t=k.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),i=k.Per(t).mul(e/2),o=Q.Sub(this.tmpPoints[0],i),n=Q.Add(this.tmpPoints[0],i),a=k.Mul(t,this.arrowTipWidth),c=k.Sub(this.tmpPoints[1],a),l=Q.Sub(c,i),u=Q.Add(c,i),h=k.Per(t).mul(e*1.5),d=Q.Sub(c,h),g=Q.Add(c,h),p=[this.tmpPoints[0],c],f=[d,this.tmpPoints[1],g],m=[o,n,...f,l,u];return{trianglePoints:f.map(w=>Q.Sub(w,this.tmpPoints[1]).XY).flat(1),trianglePos:this.tmpPoints[1].XY,points:p.map(w=>Q.Sub(w,this.tmpPoints[0]).XY).flat(1),rect:Me(m),isTriangle:!1,pos:this.tmpPoints[0].XY}}computTrianglePoints(){const e=k.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),t=this.tmpPoints[1].distance(this.tmpPoints[0]),i=k.Per(e).mul(Math.floor(t*3/8)),o=Q.Sub(this.tmpPoints[0],i),n=Q.Add(this.tmpPoints[0],i),a=[o,this.tmpPoints[1],n];return{trianglePoints:a.map(c=>Q.Sub(c,this.tmpPoints[1]).XY).flat(1),trianglePos:this.tmpPoints[1].XY,rect:Me(a),isTriangle:!0}}updateTempPoints(e){const t=e.slice(-2),i=new Q(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n))return!1;if(this.tmpPoints.length===2){if(i.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=i}else this.tmpPoints.push(i);return!0}consumeService(e){var l,u;const{op:t,isFullWork:i,workState:o=j.Done}=e,n=(l=this.workId)==null?void 0:l.toString();if(!n)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new Q(t[h],t[h+1],t[h+2]));const a=i?this.fullLayer:this.drawLayer||this.fullLayer,c=this.draw({workId:n,layer:a,isDrawEraserlines:o===j.Done});return this.oldRect=c,(u=this.vNodes)==null||u.setInfo(n,{rect:c,op:t,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:Y.getCenterPos(c,a)}),c}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var l,u;const{node:t,opt:i,vNodes:o}=e,{strokeColor:n,strokeType:a}=i,c=o.get(t.name);return n&&(t.tagName==="GROUP"?t.children.forEach(h=>{h.setAttribute("strokeColor",n),h.getAttribute("fillColor")&&h.setAttribute("fillColor",n)}):(t.setAttribute("strokeColor",n),t.setAttribute("fillColor",n)),(l=c==null?void 0:c.opt)!=null&&l.strokeColor&&(c.opt.strokeColor=n)),a&&(c!=null&&c.opt)&&((u=c.opt)!=null&&u.strokeType)&&(c.opt.strokeType=a),c&&o.setInfo(t.name,c),Y.updateNodeOpt(e)}}class on extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",ce.all);M(this,"toolsType",T.Ellipse);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"oldRect");M(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:i,isSubWorker:o,isMainThread:n}=e,a=this.workId,{op:c,syncUnitTime:l}=t;l&&(this.syncUnitTime=l);const u=c==null?void 0:c.length;if(!u||u<2)return{type:D.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new Q(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:D.None};if(!o){const g=Date.now();return g-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=g,{type:D.DrawWork,dataType:B.Local,...this.baseConsumeResult,op:this.tmpPoints.map(p=>[...p.XY,0]).flat(1),isSync:!0,index:0}):{type:D.None}}let d;if(o||n){const g=i?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:a,layer:g,isDrawing:!0});const p=g.parent.parent,f={x:0,y:0,w:Math.floor(p.width),h:Math.floor(p.height)};if(wi(d,f)!==Nt.outside){const w=ue(d,this.oldRect);return this.oldRect=d,{rect:w,type:D.DrawWork,dataType:B.Local,...this.baseConsumeResult}}return{type:D.None}}return{type:D.None}}consumeAll(){var a;const e=this.workId;if(this.tmpPoints.length<2)return{type:D.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=i;const o=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Ge(o);return(a=this.vNodes)==null||a.setInfo(e,{rect:i,op:o,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:i&&Y.getCenterPos(i,t)}),{rect:i,type:D.FullWork,dataType:B.Local,...this.baseConsumeResult,ops:n,isSync:!0}}draw(e){const{workId:t,layer:i,isDrawing:o,isDrawEraserlines:n}=e,{strokeColor:a,fillColor:c,thickness:l,zIndex:u,scale:h,rotate:d,translate:g,strokeType:p,eraserlines:f}=this.workOptions,m=i.worldScaling,{radius:w,rect:I,pos:N}=this.computDrawPoints(l),C={closeType:"normal",radius:w,lineWidth:l,fillColor:c!=="transparent"&&c||void 0,strokeColor:a,normalize:!0,lineJoin:"round",lineCap:"round",lineDash:p===oe.Dotted?[1,l*2]:p===oe.LongDotted?[l,l*2]:void 0},S={name:t,id:t,zIndex:u,pos:N,anchor:[.5,.5],size:[I.w,I.h]};h&&(S.scale=h),d&&(S.rotate=d),g&&(S.translate=g);const v=new he.Group(S);if(o){const b=new he.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:a,lineWidth:1,scale:[1/m[0],1/m[1]]});v.append(b)}const x=new he.Ellipse({...C,pos:[0,0]});v.append(x),f&&(this.scaleType=ce.proportional,this.drawEraserlines({group:v,eraserlines:f,pos:N,layer:i},n)),this.replace(i,t,v);const L=v.getBoundingClientRect();return this.isDelete&&v.setAttribute("opacity",0),{x:Math.floor(L.x-Y.SafeBorderPadding),y:Math.floor(L.y-Y.SafeBorderPadding),w:Math.floor(L.width+Y.SafeBorderPadding*2),h:Math.floor(L.height+Y.SafeBorderPadding*2)}}computDrawPoints(e){const t=Me(this.tmpPoints),i=Me(this.tmpPoints,e),o=[Math.floor(t.x+t.w/2),Math.floor(t.y+t.h/2)];return{rect:i,pos:o,radius:[Math.floor(t.w/2),Math.floor(t.h/2)]}}updateTempPoints(e){const t=e.slice(-2),i=new Q(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n))return!1;if(this.tmpPoints.length===2){if(i.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=i}else this.tmpPoints.push(i);return!0}consumeService(e){var l,u;const{op:t,isFullWork:i,workState:o=j.Done}=e,n=(l=this.workId)==null?void 0:l.toString();if(!n)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new Q(t[h],t[h+1],t[h+2]));const a=i?this.fullLayer:this.drawLayer||this.fullLayer,c=this.draw({workId:n,layer:a,isDrawing:!1,isDrawEraserlines:o===j.Done});return this.oldRect=c,(u=this.vNodes)==null||u.setInfo(n,{rect:c,op:t,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:Y.getCenterPos(c,a)}),c}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var h,d,g;const{node:t,opt:i,vNodes:o}=e,{strokeColor:n,fillColor:a,strokeType:c}=i,l=o.get(t.name);let u=t;return t.tagName==="GROUP"&&(u=t.children[0]),n&&(u.setAttribute("strokeColor",n),(h=l==null?void 0:l.opt)!=null&&h.strokeColor&&(l.opt.strokeColor=n)),a&&(a==="transparent"?u.setAttribute("fillColor","rgba(0,0,0,0)"):u.setAttribute("fillColor",a),(d=l==null?void 0:l.opt)!=null&&d.fillColor&&(l.opt.fillColor=a)),c&&(l!=null&&l.opt)&&((g=l.opt)!=null&&g.strokeType)&&(l.opt.strokeType=c),l&&o.setInfo(t.name,l),Y.updateNodeOpt(e)}}class nn extends Y{constructor(e){super(e);M(this,"canRotate",!0);M(this,"scaleType",ce.all);M(this,"toolsType",T.Rectangle);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"oldRect");M(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}transformData(){const e=Me(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,i=[];for(const a of e)i.push(new k(...a));const o=Me(i,t),n=[o.x+o.w/2,o.y+o.h/2];return{rect:o,pos:n,points:i.map(a=>a.XY).flat(1)}}consume(e){const{data:t,isFullWork:i,isSubWorker:o,isMainThread:n}=e,a=this.workId,{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:D.None};let u;if(this.tmpPoints.length===0?(this.tmpPoints=[new Q(c[0],c[1])],u=!1):u=this.updateTempPoints(c),!u)return{type:D.None};const h=this.transformData();let d;if(o||n){const p=i?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({ps:h,workId:a,layer:p,isDrawing:!0})}if(!o){const p=Date.now();return p-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=p,{type:D.DrawWork,dataType:B.Local,op:h.flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:D.None}}const g=ue(d,this.oldRect);return this.oldRect=d,{rect:g,type:D.DrawWork,dataType:B.Local,...this.baseConsumeResult}}consumeAll(){var c;const e=this.workId;if(this.tmpPoints.length<2)return{type:D.RemoveNode,removeIds:[e]};const t=this.transformData(),i=this.fullLayer,o=this.draw({ps:t,workId:e,layer:i,isDrawing:!1});this.oldRect=o;const n=t.flat(1),a=Ge(n);return(c=this.vNodes)==null||c.setInfo(e,{rect:o,op:n,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:o&&Y.getCenterPos(o,i)}),{rect:o,type:D.FullWork,dataType:B.Local,ops:a,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:i,isDrawing:o,ps:n,replaceId:a,isDrawEraserlines:c=!0}=e,{strokeColor:l,fillColor:u,thickness:h,zIndex:d,scale:g,rotate:p,translate:f,strokeType:m,eraserlines:w}=this.workOptions,I=i.worldPosition,N=i.worldScaling,{points:C,rect:S,pos:v}=this.computDrawPoints(n),x={close:!0,normalize:!0,points:C,lineWidth:h,fillColor:u!=="transparent"&&u||void 0,strokeColor:l,lineJoin:"round",lineCap:"round",lineDash:m===oe.Dotted?[1,h*2]:m===oe.LongDotted?[h,h*2]:void 0};let L={x:Math.floor(S.x*N[0]+I[0]-Y.SafeBorderPadding),y:Math.floor(S.y*N[1]+I[1]-Y.SafeBorderPadding),w:Math.floor(S.w*N[0]+2*Y.SafeBorderPadding),h:Math.floor(S.h*N[0]+2*Y.SafeBorderPadding)};const b=new he.Group({name:t,id:t,zIndex:d,pos:v,anchor:[.5,.5],size:[S.w,S.h],scale:g,rotate:p,translate:f}),P=new he.Polyline({...x,pos:[0,0]});if(b.appendChild(P),o){const A=new he.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:l,lineWidth:1,scale:[1/N[0],1/N[1]]});b.appendChild(A)}if(w&&(this.scaleType=ce.proportional,this.drawEraserlines({group:b,eraserlines:w,pos:v,layer:i},c)),this.replace(i,a||t,b),g||p||f){const A=b.getBoundingClientRect();L={x:Math.floor(A.x-Y.SafeBorderPadding),y:Math.floor(A.y-Y.SafeBorderPadding),w:Math.floor(A.width+2*Y.SafeBorderPadding),h:Math.floor(A.height+2*Y.SafeBorderPadding)}}return this.isDelete&&b.setAttribute("opacity",0),L}updateTempPoints(e){const t=e.slice(-2),i=new Q(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n))return!1;if(this.tmpPoints.length===2){if(i.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=i}else this.tmpPoints.push(i);return!0}consumeService(e){var h,d;const{op:t,isFullWork:i,replaceId:o,workState:n=j.Done}=e,a=(h=this.workId)==null?void 0:h.toString();if(!a)return;const c=[];for(let g=0;g<t.length;g+=3)c.push([t[g],t[g+1],t[g+2]]);const l=i?this.fullLayer:this.drawLayer||this.fullLayer,u=this.draw({ps:c,workId:a,layer:l,isDrawing:!1,replaceId:o,isDrawEraserlines:n===j.Done});return this.oldRect=u,(d=this.vNodes)==null||d.setInfo(a,{rect:u,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:u&&Y.getCenterPos(u,l)}),u}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var h,d,g;const{node:t,opt:i,vNodes:o}=e,{strokeColor:n,fillColor:a,strokeType:c}=i,l=o.get(t.name);let u=t;return t.tagName==="GROUP"&&(u=t.children[0]),n&&(u.setAttribute("strokeColor",n),(h=l==null?void 0:l.opt)!=null&&h.strokeColor&&(l.opt.strokeColor=n)),a&&(a==="transparent"?u.setAttribute("fillColor","rgba(0,0,0,0)"):u.setAttribute("fillColor",a),(d=l==null?void 0:l.opt)!=null&&d.fillColor&&(l.opt.fillColor=a)),c&&(l!=null&&l.opt)&&((g=l.opt)!=null&&g.strokeType)&&(l.opt.strokeType=c),l&&o.setInfo(t.name,l),Y.updateNodeOpt(e)}}class rn extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",ce.all);M(this,"toolsType",T.Star);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"oldRect");M(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:i,isSubWorker:o,isMainThread:n}=e,a=this.workId,{op:c,syncUnitTime:l}=t,u=c==null?void 0:c.length;if(!u||u<2)return{type:D.None};l&&(this.syncUnitTime=l);let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new Q(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:D.None};let d;if(o||n){const p=i?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:a,layer:p,isDrawing:!0})}if(!o){const p=Date.now();return p-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=p,{type:D.DrawWork,dataType:B.Local,op:this.tmpPoints.map(f=>[...f.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:D.None}}const g=ue(d,this.oldRect);return this.oldRect=d,{rect:g,type:D.DrawWork,dataType:B.Local,...this.baseConsumeResult}}consumeAll(){var a;const e=this.workId;if(this.tmpPoints.length<2)return{type:D.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=i;const o=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Ge(o);return(a=this.vNodes)==null||a.setInfo(e,{rect:i,op:o,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:i&&Y.getCenterPos(i,t)}),{rect:i,type:D.FullWork,dataType:B.Local,ops:n,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:i,isDrawing:o,isDrawEraserlines:n=!0}=e,{strokeColor:a,fillColor:c,thickness:l,zIndex:u,vertices:h,innerVerticeStep:d,innerRatio:g,scale:p,rotate:f,translate:m,strokeType:w,eraserlines:I}=this.workOptions,N=i.worldScaling,{rect:C,pos:S,points:v}=this.computDrawPoints(l,h,d,g),x={close:!0,points:v,lineWidth:l,fillColor:c!=="transparent"&&c||void 0,strokeColor:a,normalize:!0,lineJoin:"round",lineCap:"round",lineDash:w===oe.Dotted?[1,l*2]:w===oe.LongDotted?[l,l*2]:void 0},L={name:t,id:t,zIndex:u,pos:S,anchor:[.5,.5],size:[C.w,C.h]};p&&(L.scale=p),f&&(L.rotate=f),m&&(L.translate=m);const b=new he.Group(L);if(o){const E=new he.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:a,lineWidth:1,scale:[1/N[0],1/N[1]]});b.append(E)}const P=new he.Polyline({...x,pos:[0,0]});b.append(P),I&&(this.scaleType=ce.proportional,this.drawEraserlines({group:b,eraserlines:I,pos:S,layer:i},n)),this.replace(i,t,b);const A=b.getBoundingClientRect();return this.isDelete&&b.setAttribute("opacity",0),{x:Math.floor(A.x-Y.SafeBorderPadding),y:Math.floor(A.y-Y.SafeBorderPadding),w:Math.floor(A.width+Y.SafeBorderPadding*2),h:Math.floor(A.height+Y.SafeBorderPadding*2)}}computDrawPoints(e,t,i,o){const n=Me(this.tmpPoints),a=[Math.floor(n.x+n.w/2),Math.floor(n.y+n.h/2)],c=In(n.w,n.h),l=Math.floor(Math.min(n.w,n.h)/2),u=o*l,h=[],d=2*Math.PI/t;for(let p=0;p<t;p++){const f=p*d-.5*Math.PI;let m,w;p%i===1?(m=u*c[0]*Math.cos(f),w=u*c[1]*Math.sin(f)):(m=l*c[0]*Math.cos(f),w=l*c[1]*Math.sin(f),h.push(m,w)),h.push(m,w)}return{rect:Me(this.tmpPoints,e),pos:a,points:h}}updateTempPoints(e){const t=e.slice(-2),i=new Q(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n)||Q.Sub(o,i).XY.includes(0))return!1;if(this.tmpPoints.length===2){if(i.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=i}else this.tmpPoints.push(i);return!0}consumeService(e){var l,u;const{op:t,isFullWork:i,workState:o=j.Done}=e,n=(l=this.workId)==null?void 0:l.toString();if(!n)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new Q(t[h],t[h+1],t[h+2]));const a=i?this.fullLayer:this.drawLayer||this.fullLayer,c=this.draw({workId:n,layer:a,isDrawing:!1,isDrawEraserlines:o===j.Done});return this.oldRect=c,(u=this.vNodes)==null||u.setInfo(n,{rect:c,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:c&&Y.getCenterPos(c,a)}),c}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var m;const{node:t,opt:i,vNodes:o}=e,{strokeColor:n,fillColor:a,toolsType:c,vertices:l,innerVerticeStep:u,innerRatio:h,strokeType:d}=i,g=o.get(t.name),p=g==null?void 0:g.opt;let f=t;return t.tagName==="GROUP"&&(f=t.children[0]),n&&(f.setAttribute("strokeColor",n),p!=null&&p.strokeColor&&(p.strokeColor=n)),a&&(a==="transparent"?f.setAttribute("fillColor","rgba(0,0,0,0)"):f.setAttribute("fillColor",a),p!=null&&p.fillColor&&(p.fillColor=a)),c===T.Star&&(l&&(p.vertices=l),u&&(p.innerVerticeStep=u),h&&(p.innerRatio=h)),d&&(g!=null&&g.opt)&&((m=g.opt)!=null&&m.strokeType)&&(g.opt.strokeType=d),g&&o.setInfo(t.name,{...g,opt:p}),Y.updateNodeOpt(e)}}class an extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",ce.all);M(this,"toolsType",T.Polygon);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"oldRect");M(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:i,isSubWorker:o,isMainThread:n}=e,{op:a,syncUnitTime:c}=t;c&&(this.syncUnitTime=c);const l=this.workId,u=a==null?void 0:a.length;if(!u||u<2)return{type:D.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new Q(a[0],a[1])],h=!1):h=this.updateTempPoints(a),!h)return{type:D.None};let d;if(o||n){const p=i?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:l,layer:p,isDrawing:!0})}if(!o){const p=Date.now();return p-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=p,{type:D.DrawWork,dataType:B.Local,op:this.tmpPoints.map(f=>[...f.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:D.None}}const g=ue(d,this.oldRect);return this.oldRect=d,{rect:g,type:D.DrawWork,dataType:B.Local,...this.baseConsumeResult}}consumeAll(){var a;const e=this.workId;if(this.tmpPoints.length<2)return{type:D.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=i;const o=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Ge(o);return(a=this.vNodes)==null||a.setInfo(e,{rect:i,op:o,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:i&&Y.getCenterPos(i,t)}),{rect:i,type:D.FullWork,dataType:B.Local,ops:n,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:i,isDrawing:o,isDrawEraserlines:n=!0}=e,{strokeColor:a,fillColor:c,thickness:l,zIndex:u,vertices:h,scale:d,rotate:g,translate:p,strokeType:f,eraserlines:m}=this.workOptions,w=i.worldScaling,{rect:I,pos:N,points:C}=this.computDrawPoints(l,h),S={close:!0,points:C,lineWidth:l,fillColor:c!=="transparent"&&c||void 0,strokeColor:a,normalize:!0,lineJoin:"round",lineCap:"round",lineDash:f===oe.Dotted?[1,l*2]:f===oe.LongDotted?[l,l*2]:void 0},v={name:t,id:t,zIndex:u,pos:N,anchor:[.5,.5],size:[I.w,I.h]};d&&(v.scale=d),g&&(v.rotate=g),p&&(v.translate=p);const x=new he.Group(v);if(o){const P=new he.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:a,lineWidth:1,scale:[1/w[0],1/w[1]]});x.append(P)}const L=new he.Polyline({...S,pos:[0,0]});x.append(L),m&&(this.scaleType=ce.proportional,this.drawEraserlines({group:x,eraserlines:m,pos:N,layer:i},n)),this.replace(i,t,x);const b=x.getBoundingClientRect();return this.isDelete&&x.setAttribute("opacity",0),{x:Math.floor(b.x-Y.SafeBorderPadding),y:Math.floor(b.y-Y.SafeBorderPadding),w:Math.floor(b.width+Y.SafeBorderPadding*2),h:Math.floor(b.height+Y.SafeBorderPadding*2)}}computDrawPoints(e,t){const i=Me(this.tmpPoints),o=[Math.floor(i.x+i.w/2),Math.floor(i.y+i.h/2)],n=In(i.w,i.h),a=Math.floor(Math.min(i.w,i.h)/2),c=[],l=2*Math.PI/t;for(let h=0;h<t;h++){const d=h*l-.5*Math.PI,g=a*n[0]*Math.cos(d),p=a*n[1]*Math.sin(d);c.push(g,p)}return{rect:Me(this.tmpPoints,e),pos:o,points:c}}updateTempPoints(e){const t=e.slice(-2),i=new Q(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n)||Q.Sub(o,i).XY.includes(0))return!1;if(this.tmpPoints.length===2){if(i.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=i}else this.tmpPoints.push(i);return!0}consumeService(e){var l,u;const{op:t,isFullWork:i,workState:o=j.Done}=e,n=(l=this.workId)==null?void 0:l.toString();if(!n)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new Q(t[h],t[h+1],t[h+2]));const a=i?this.fullLayer:this.drawLayer||this.fullLayer,c=this.draw({workId:n,layer:a,isDrawing:!1,isDrawEraserlines:o===j.Done});return this.oldRect=c,(u=this.vNodes)==null||u.setInfo(n,{rect:c,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:c&&Y.getCenterPos(c,a)}),c}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var p;const{node:t,opt:i,vNodes:o}=e,{strokeColor:n,fillColor:a,toolsType:c,vertices:l,strokeType:u}=i,h=o.get(t.name),d=h==null?void 0:h.opt;let g=t;return t.tagName==="GROUP"&&(g=t.children[0]),n&&(g.setAttribute("strokeColor",n),d!=null&&d.strokeColor&&(d.strokeColor=n)),a&&(a==="transparent"?g.setAttribute("fillColor","rgba(0,0,0,0)"):g.setAttribute("fillColor",a),d!=null&&d.fillColor&&(d.fillColor=a)),c===T.Polygon&&l&&(d.vertices=l),u&&(h!=null&&h.opt)&&((p=h.opt)!=null&&p.strokeType)&&(h.opt.strokeType=u),h&&o.setInfo(t.name,{...h,opt:d}),Y.updateNodeOpt(e)}}class _e{static bezier(s,e){const t=[];for(let i=0;i<e.length;i+=4){const o=e[i],n=e[i+1],a=e[i+2],c=e[i+3];o&&n&&a&&c?t.push(..._e.getBezierPoints(s,o,n,a,c)):o&&n&&a?t.push(..._e.getBezierPoints(s,o,n,a)):o&&n?t.push(..._e.getBezierPoints(s,o,n)):o&&t.push(o)}return t}static getBezierPoints(s=10,e,t,i,o){let n=null;const a=[];!i&&!o?n=_e.oneBezier:i&&!o?n=_e.twoBezier:i&&o&&(n=_e.threeBezier);for(let c=0;c<s;c++)n&&a.push(n(c/s,e,t,i,o));return o?a.push(o):i&&a.push(i),a}static oneBezier(s,e,t){const i=e.x+(t.x-e.x)*s,o=e.y+(t.y-e.y)*s;return new k(i,o)}static twoBezier(s,e,t,i){const o=(1-s)*(1-s)*e.x+2*s*(1-s)*t.x+s*s*i.x,n=(1-s)*(1-s)*e.y+2*s*(1-s)*t.y+s*s*i.y;return new k(o,n)}static threeBezier(s,e,t,i,o){const n=e.x*(1-s)*(1-s)*(1-s)+3*t.x*s*(1-s)*(1-s)+3*i.x*s*s*(1-s)+o.x*s*s*s,a=e.y*(1-s)*(1-s)*(1-s)+3*t.y*s*(1-s)*(1-s)+3*i.y*s*s*(1-s)+o.y*s*s*s;return new k(n,a)}}class cn extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",ce.all);M(this,"toolsType",T.SpeechBalloon);M(this,"ratio",.8);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"oldRect");M(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){var g;const{data:t,isFullWork:i,isSubWorker:o,isMainThread:n}=e,a=(g=t==null?void 0:t.workId)==null?void 0:g.toString();if(!a)return{type:D.None};const{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:D.None};let u;if(this.tmpPoints.length===0?(this.tmpPoints=[new Q(c[0],c[1])],u=!1):u=this.updateTempPoints(c),!u)return{type:D.None};let h;if(o||n){const p=i?this.fullLayer:this.drawLayer||this.fullLayer;h=this.draw({workId:a,layer:p,isDrawing:!0})}if(!o){const p=Date.now();return p-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=p,{type:D.DrawWork,dataType:B.Local,op:this.tmpPoints.map(f=>[...f.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:D.None}}const d=ue(h,this.oldRect);return this.oldRect=h,{rect:d,type:D.DrawWork,dataType:B.Local,...this.baseConsumeResult}}consumeAll(){var a;const e=this.workId;if(this.tmpPoints.length<2)return{type:D.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=i;const o=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Ge(o);return(a=this.vNodes)==null||a.setInfo(e,{rect:i,op:o,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:i&&Y.getCenterPos(i,t)}),{rect:i,type:D.FullWork,dataType:B.Local,ops:n,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:i,isDrawEraserlines:o=!0}=e,{strokeColor:n,fillColor:a,thickness:c,zIndex:l,placement:u,scale:h,rotate:d,translate:g,strokeType:p,eraserlines:f}=this.workOptions,{rect:m,pos:w,points:I}=this.computDrawPoints(c,u),N={points:I.map(L=>L.XY),lineWidth:c,fillColor:a!=="transparent"&&a||void 0,strokeColor:n,normalize:!0,className:`${w[0]},${w[1]}`,close:!0,lineJoin:"round",lineCap:"round",lineDash:p===oe.Dotted?[1,c*2]:p===oe.LongDotted?[c,c*2]:void 0},C={name:t,id:t,zIndex:l,pos:w,anchor:[.5,.5],size:[m.w,m.h]};h&&(C.scale=h),d&&(C.rotate=d),g&&(C.translate=g);const S=new he.Group(C),v=new he.Polyline({...N,pos:[0,0]});S.append(v),f&&(this.scaleType=ce.proportional,this.drawEraserlines({group:S,eraserlines:f,pos:w,layer:i},o)),this.replace(i,t,S);const x=S.getBoundingClientRect();return this.isDelete&&S.setAttribute("opacity",0),{x:Math.floor(x.x-Y.SafeBorderPadding),y:Math.floor(x.y-Y.SafeBorderPadding),w:Math.floor(x.width+Y.SafeBorderPadding*2),h:Math.floor(x.height+Y.SafeBorderPadding*2)}}transformControlPoints(e){const t=Me(this.tmpPoints);switch(e){case"bottom":case"bottomLeft":case"bottomRight":{const i=t.y+t.h*this.ratio;return[new k(t.x,t.y,0),new k(t.x+t.w,t.y,0),new k(t.x+t.w,i,0),new k(t.x,i,0)]}case"top":case"topLeft":case"topRight":{const i=t.y+t.h*(1-this.ratio);return[new k(t.x,i,0),new k(t.x+t.w,i,0),new k(t.x+t.w,t.y+t.h,0),new k(t.x,t.y+t.h,0)]}case"left":case"leftBottom":case"leftTop":{const i=t.x+t.w*(1-this.ratio);return[new k(i,t.y,0),new k(t.x+t.w,t.y,0),new k(t.x+t.w,t.y+t.h,0),new k(i,t.y+t.h,0)]}case"right":case"rightBottom":case"rightTop":{const i=t.x+t.w*this.ratio;return[new k(t.x,t.y,0),new k(i,t.y,0),new k(i,t.y+t.h,0),new k(t.x,t.y+t.h,0)]}}}computDrawPoints(e,t){const i=Me(this.tmpPoints),o=this.transformControlPoints(t),n=Math.floor(i.w*.1),a=Math.floor(i.h*.1),c=[],l=k.Add(o[0],new k(0,a,0)),u=k.Add(o[0],new k(n,0,0)),h=_e.getBezierPoints(10,l,o[0],u),d=k.Sub(o[1],new k(n,0,0)),g=k.Add(o[1],new k(0,a,0)),p=_e.getBezierPoints(10,d,o[1],g),f=k.Sub(o[2],new k(0,a,0)),m=k.Sub(o[2],new k(n,0,0)),w=_e.getBezierPoints(10,f,o[2],m),I=k.Add(o[3],new k(n,0,0)),N=k.Sub(o[3],new k(0,a,0)),C=_e.getBezierPoints(10,I,o[3],N),S=n*(1-this.ratio)*10,v=a*(1-this.ratio)*10;switch(t){case"bottom":{const b=k.Sub(o[2],new k(n*5-S/2,0,0)),P=k.Sub(o[2],new k(n*5,-v,0)),A=k.Sub(o[2],new k(n*5+S/2,0,0));c.push(P,A,...C,...h,...p,...w,b);break}case"bottomRight":{const b=k.Sub(o[2],new k(n*1.1,0,0)),P=k.Sub(o[2],new k(n*1.1+S/2,-v,0)),A=k.Sub(o[2],new k(n*1.1+S,0,0));c.push(P,A,...C,...h,...p,...w,b);break}case"bottomLeft":{const b=k.Add(o[3],new k(n*1.1+S,0,0)),P=k.Add(o[3],new k(n*1.1+S/2,v,0)),A=k.Add(o[3],new k(n*1.1,0,0));c.push(P,A,...C,...h,...p,...w,b);break}case"top":{const b=k.Sub(o[1],new k(n*5-S/2,0,0)),P=k.Sub(o[1],new k(n*5,v,0)),A=k.Sub(o[1],new k(n*5+S/2,0,0));c.push(P,b,...p,...w,...C,...h,A);break}case"topRight":{const b=k.Sub(o[1],new k(n*1.1,0,0)),P=k.Sub(o[1],new k(n*1.1+S/2,v,0)),A=k.Sub(o[1],new k(n*1.1+S,0,0));c.push(P,b,...p,...w,...C,...h,A);break}case"topLeft":{const b=k.Add(o[0],new k(n*1.1+S,0,0)),P=k.Add(o[0],new k(n*1.1+S/2,-v,0)),A=k.Add(o[0],new k(n*1.1,0,0));c.push(P,b,...p,...w,...C,...h,A);break}case"left":{const b=k.Add(o[0],new k(0,a*5-v/2,0)),P=k.Add(o[0],new k(-S,a*5,0)),A=k.Add(o[0],new k(0,a*5+v/2,0));c.push(P,b,...h,...p,...w,...C,A);break}case"leftTop":{const b=k.Add(o[0],new k(0,a*1.1,0)),P=k.Add(o[0],new k(-S,a*1.1+v/2,0)),A=k.Add(o[0],new k(0,a*1.1+v,0));c.push(P,b,...h,...p,...w,...C,A);break}case"leftBottom":{const b=k.Sub(o[3],new k(0,a*1.1+v,0)),P=k.Sub(o[3],new k(S,a*1.1+v/2,0)),A=k.Sub(o[3],new k(0,a*1.1,0));c.push(P,b,...h,...p,...w,...C,A);break}case"right":{const b=k.Add(o[1],new k(0,a*5-v/2,0)),P=k.Add(o[1],new k(S,a*5,0)),A=k.Add(o[1],new k(0,a*5+v/2,0));c.push(P,A,...w,...C,...h,...p,b);break}case"rightTop":{const b=k.Add(o[1],new k(0,a*1.1,0)),P=k.Add(o[1],new k(S,a*1.1+v/2,0)),A=k.Add(o[1],new k(0,a*1.1+v,0));c.push(P,A,...w,...C,...h,...p,b);break}case"rightBottom":{const b=k.Sub(o[2],new k(0,a*1.1+v,0)),P=k.Sub(o[2],new k(-S,a*1.1+v/2,0)),A=k.Sub(o[2],new k(0,a*1.1,0));c.push(P,A,...w,...C,...h,...p,b);break}}const x=Me(this.tmpPoints,e),L=[Math.floor(x.x+x.w/2),Math.floor(x.y+x.h/2)];return{rect:x,pos:L,points:c}}updateTempPoints(e){const t=e.slice(-2),i=new Q(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n)||Q.Sub(o,i).XY.includes(0))return!1;if(this.tmpPoints.length===2){if(i.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=i}else this.tmpPoints.push(i);return!0}consumeService(e){var l,u;const{op:t,isFullWork:i,workState:o=j.Done}=e,n=(l=this.workId)==null?void 0:l.toString();if(!n)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new Q(t[h],t[h+1],t[h+2]));const a=i?this.fullLayer:this.drawLayer||this.fullLayer,c=this.draw({workId:n,layer:a,isDrawing:!1,isDrawEraserlines:o===j.Done});return this.oldRect=c,(u=this.vNodes)==null||u.setInfo(n,{rect:c,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:c&&Y.getCenterPos(c,a)}),c}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var p;const{node:t,opt:i,vNodes:o}=e,{strokeColor:n,fillColor:a,toolsType:c,placement:l,strokeType:u}=i,h=o.get(t.name),d=h==null?void 0:h.opt;let g=t;return t.tagName==="GROUP"&&(g=t.children[0]),n&&(g.setAttribute("strokeColor",n),d!=null&&d.strokeColor&&(d.strokeColor=n)),a&&(a==="transparent"?g.setAttribute("fillColor","rgba(0,0,0,0)"):g.setAttribute("fillColor",a),d!=null&&d.fillColor&&(d.fillColor=a)),c===T.SpeechBalloon&&l&&(d.placement=l),u&&(h!=null&&h.opt)&&((p=h.opt)!=null&&p.strokeType)&&(h.opt.strokeType=u),h&&o.setInfo(t.name,{...h,opt:d}),Y.updateNodeOpt(e)}}var yf=kt,mf=at,wf="[object Boolean]";function If(r){return r===!0||r===!1||mf(r)&&yf(r)==wf}var Tf=If;const Pt=Ut(Tf);class ln extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",ce.both);M(this,"toolsType",T.Straight);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"oldRect");M(this,"straightTipWidth");M(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.straightTipWidth=this.workOptions.thickness/2,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:i,isSubWorker:o,isMainThread:n}=e,a=this.workId,{op:c,syncUnitTime:l}=t,u=c==null?void 0:c.length;if(!u||u<2)return{type:D.None};l&&(this.syncUnitTime=l);let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new Q(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:D.None};let d;if(o||n){const p=i?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({workId:a,layer:p})}if(!o){const p=Date.now();return p-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=p,{type:D.DrawWork,dataType:B.Local,op:this.tmpPoints.map(f=>[...f.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:D.None}}const g=ue(d,this.oldRect);return this.oldRect=d,{rect:g,type:D.DrawWork,dataType:B.Local,...this.baseConsumeResult}}consumeAll(){var a;const e=this.workId;if(this.tmpPoints.length<2)return{type:D.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t});this.oldRect=i;const o=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Ge(o);return(a=this.vNodes)==null||a.setInfo(e,{rect:i,op:o,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:i&&Y.getCenterPos(i,t)}),{rect:i,type:D.FullWork,dataType:B.Local,ops:n,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:i,isDrawEraserlines:o=!0}=e,{strokeColor:n,thickness:a,zIndex:c,scale:l,rotate:u,translate:h,strokeType:d,eraserlines:g}=this.workOptions,p=i.worldPosition,f=i.worldScaling,{d:m,rect:w,isDot:I}=this.computDrawPoints(a,d),N=[w.x+w.w/2,w.y+w.h/2],C=new he.Group({pos:N,anchor:[.5,.5],size:[w.w,w.h],name:t,id:t,normalize:!0,zIndex:c}),S={pos:[0,0],normalize:!0,d:m,fillColor:n,strokeColor:n,lineDash:d===oe.Dotted&&!I?[1,a*2]:d===oe.LongDotted&&!I?[a,a*2]:void 0,lineCap:d===oe.Normal||I?void 0:"round",lineWidth:d===oe.Normal||I?0:a};l&&(S.scale=l),u&&(S.rotate=u),h&&(S.translate=h);const v=new he.Path(S);C.append(v),g&&(this.scaleType=ce.proportional,this.drawEraserlines({group:C,eraserlines:g,pos:N,layer:i},o)),this.replace(i,t,C);let x={x:Math.floor(w.x*f[0]+p[0]-Y.SafeBorderPadding),y:Math.floor(w.y*f[1]+p[1]-Y.SafeBorderPadding),w:Math.floor(w.w*f[0]+2*Y.SafeBorderPadding),h:Math.floor(w.h*f[1]+2*Y.SafeBorderPadding)};if(u||l||h){const L=v.getBoundingClientRect();x={x:Math.floor(L.x-Y.SafeBorderPadding),y:Math.floor(L.y-Y.SafeBorderPadding),w:Math.floor(L.width+Y.SafeBorderPadding*2),h:Math.floor(L.height+Y.SafeBorderPadding*2)}}return this.isDelete&&C.setAttribute("opacity",0),x}computDrawPoints(e,t){return this.tmpPoints[1].distance(this.tmpPoints[0])>this.straightTipWidth?this.computFullPoints(e,t):this.computDotPoints(e)}computFullPoints(e,t){const i=k.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),o=k.Per(i).mul(e/2),n=Q.Sub(this.tmpPoints[0],o),a=Q.Add(this.tmpPoints[0],o),c=Q.Sub(this.tmpPoints[1],o),l=Q.Add(this.tmpPoints[1],o),u=Q.GetSemicircleStroke(this.tmpPoints[1],c,-1,8),h=Q.GetSemicircleStroke(this.tmpPoints[0],a,-1,8),d=[n,c,...u,l,a,...h];let g;return t!==oe.Normal?g=nt(this.tmpPoints,!1):g=nt(d,!0),{d:g,rect:Me(d),isDot:!1,pos:this.tmpPoints[0].XY}}computDotPoints(e){const t=Q.GetDotStroke(this.tmpPoints[0],e/2,8);return{d:nt(t,!0),rect:Me(t),isDot:!0,pos:this.tmpPoints[0].XY}}updateTempPoints(e){const t=e.slice(-2),i=new Q(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n))return!1;if(this.tmpPoints.length===2){if(i.isNear(this.tmpPoints[1],1))return!1;this.tmpPoints[1]=i}else this.tmpPoints.push(i);return!0}consumeService(e){var l,u;const{op:t,isFullWork:i,workState:o=j.Done}=e,n=(l=this.workId)==null?void 0:l.toString();if(!n)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new Q(t[h],t[h+1],t[h+2]));const a=i?this.fullLayer:this.drawLayer||this.fullLayer,c=this.draw({workId:n,layer:a,isDrawEraserlines:o===j.Done});return this.oldRect=c,(u=this.vNodes)==null||u.setInfo(n,{rect:c,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:c&&Y.getCenterPos(c,a)}),c}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var l,u;const{node:t,opt:i,vNodes:o}=e,{strokeColor:n,strokeType:a}=i,c=o.get(t.name);return n&&(t.tagName==="GROUP"?t.children.forEach(h=>{h.setAttribute("strokeColor",n),h.getAttribute("fillColor")&&h.setAttribute("fillColor",n)}):(t.setAttribute("strokeColor",n),t.setAttribute("fillColor",n)),(l=c==null?void 0:c.opt)!=null&&l.strokeColor&&(c.opt.strokeColor=n)),a&&(c!=null&&c.opt)&&((u=c.opt)!=null&&u.strokeType)&&(c.opt.strokeType=a),c&&o.setInfo(t.name,c),Y.updateNodeOpt(e)}}const ft=class ft extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",ce.proportional);M(this,"toolsType",T.Text);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"oldRect");this.workOptions=e.toolsOpt}consume(){return{type:D.None}}consumeAll(){return{type:D.None}}consumeService(){}async draw(e){const{workId:t,layer:i,isDrawLabel:o}=e,{boxSize:n,boxPoint:a,zIndex:c}=this.workOptions,l=i.worldPosition,u=i.worldScaling;if(!a||!n)return;const h={name:t,id:t,pos:[a[0],a[1]],anchor:[0,0],size:n,zIndex:c},d=new he.Group(h),g={x:a[0],y:a[1],w:n[0],h:n[1]},p={x:Math.floor(g.x*u[0]+l[0]),y:Math.floor(g.y*u[1]+l[1]),w:Math.floor(g.w*u[0])+2,h:Math.floor(g.h*u[1])+2};if(this.replace(i,t,d),o&&i&&this.workOptions.text){const f=await ft.createLabels(this.workOptions,i,p),{labels:m,maxWidth:w}=f;d.append(...m),p.w=Math.ceil(Math.max(w*i.worldScaling[0],p.w))}return p}async consumeServiceAsync(e){var l,u,h,d;const t=(l=this.workId)==null?void 0:l.toString();if(!t)return;const{isFullWork:i,replaceId:o,isDrawLabel:n}=e;this.oldRect=o&&((h=(u=this.vNodes)==null?void 0:u.get(o))==null?void 0:h.rect)||void 0;const a=i?this.fullLayer:this.drawLayer||this.fullLayer,c=await this.draw({workId:t,layer:a,isDrawLabel:typeof n>"u"&&this.workOptions.workState===j.Done||n});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&&Y.getCenterPos(c,a)}),c}updataOptService(){}async updataOptServiceAsync(e,t){var p,f;if(!this.workId)return;const i=this.workId.toString(),{fontColor:o,fontBgColor:n,bold:a,italic:c,lineThrough:l,underline:u,zIndex:h}=e,d=(p=this.vNodes)==null?void 0:p.get(i);if(!d)return;o&&(d.opt.fontColor=o),n&&(d.opt.fontBgColor=n),a&&(d.opt.bold=a),c&&(d.opt.italic=c),Pt(l)&&(d.opt.lineThrough=l),Pt(u)&&(d.opt.underline=u),ze(h)&&(d.opt.zIndex=h),this.oldRect=d.rect;const g=await this.draw({workId:i,layer:this.fullLayer,isDrawLabel:typeof t>"u"&&this.workOptions.workState===j.Done||t});return(f=this.vNodes)==null||f.setInfo(i,{rect:g,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:g&&Y.getCenterPos(g,this.fullLayer)}),g}clearTmpPoints(){this.tmpPoints.length=0}static getSafetySnippetRatio(e){const t=(e==null?void 0:e.parent).displayRatio||1,i=Math.ceil(e.worldScaling[0]*10)/10;let o=i;return i>=.2&&i<1?o=i*t:i<=2&&i>=1?o=i*t*1.6:i>2&&i<=3?o=i*t*1.4:i>3&&i<=4?o=i*t*.8:i>4&&(o=i*t*.6),Math.floor(o*1e3)/1e3}static getSafetySnippetFontLength(e){return Math.floor(ft.textImageSnippetSize*3/4/e)||1}static async createLabels(e,t,i){var A;const o=[],{x:n,y:a}=i,{width:c,height:l}=(A=t.parent)==null?void 0:A.parent,u=Dt(e.text),h=u.length,{fontSize:d,lineHeight:g,bold:p,textAlign:f,italic:m,fontFamily:w,verticalAlign:I,fontColor:N,fontBgColor:C,underline:S,lineThrough:v}=e,x=ft.getSafetySnippetRatio(t)||1,L=Math.floor(d*x),b=ft.getSafetySnippetFontLength(L);let P=0;for(let E=0;E<h;E++){const R=u[E],z=g||L*1.5;if(R){const Z=My(R),ee=[0,0],F=[0,d*1.2];I==="middle"&&(ee[1]=E*d*1.2+5);const $=[0,-d*.15];ee[0]=5;const te=Math.sin(Math.PI/180*20);let le=0;const ie=[];let _=0;for(;_<Z;){f==="left"&&($[0]=le),_===0&&m==="italic"&&($[0]=$[0]-te/2*d);const de=R.slice(_,_+b),Be={anchor:[0,0],pos:$,text:de,fontFamily:w,fontSize:L,lineHeight:z,strokeColor:N,fontWeight:p,fillColor:N,textAlign:f,fontStyle:m,scale:[1/x,1/x]},ke=new he.Label(Be),q=await ke.textImageReady;let Le=!0;if(q){const Ue=q.rect&&q.rect[2],st=q.rect&&q.rect[3];if(Ue&&st){const H=Ue/x,K=st/x;le=H+le,m==="italic"&&(p==="bold"?le=le-te*d*1.2:le=le-te*d),(($[0]+ee[0]+H)*t.worldScaling[0]+n<=0||($[0]+ee[0])*t.worldScaling[0]+n>=c||($[1]+ee[1]+K)*t.worldScaling[1]+a<=0||($[1]+ee[1])*t.worldScaling[1]+a>=l)&&(ke.disconnect(),Le=!1),Le&&ie.push(ke)}}_+=b}F[0]=le,m==="italic"&&(F[0]=F[0]+te*d),P=Math.max(P,F[0]);let J=!0;if(((ee[0]+F[0])*t.worldScaling[0]+n<=0||ee[0]*t.worldScaling[0]+n>=c||(ee[1]+F[1])*t.worldScaling[0]+a<=0||ee[1]*t.worldScaling[1]+a>=l)&&(J=!1),J){if(S){const ke=Math.floor(d/10),q={normalize:!1,pos:[0,d*1.1+ke/2],lineWidth:ke,points:[0,0,Math.ceil(F[0]),0],strokeColor:N,className:"underline"},Le=new he.Polyline(q);ie.push(Le)}if(v){const ke={normalize:!1,pos:[0,d*1.2/2],lineWidth:Math.floor(d/10),points:[0,0,Math.ceil(F[0]),0],strokeColor:N,className:"lineThrough"},q=new he.Polyline(ke);ie.push(q)}const de={pos:ee,anchor:[0,0],size:F,bgcolor:C},Be=new he.Group(de);Be.append(...ie),o.push(Be)}}}return{labels:o,maxWidth:P}}static updateNodeOpt(e){const{node:t,opt:i,vNodes:o,targetNode:n}=e,{fontBgColor:a,fontColor:c,translate:l,originPoint:u,scenePoint:h,scale:d,bold:g,italic:p,lineThrough:f,underline:m,fontSize:w,textInfos:I,zIndex:N}=i,C=n&&Pe(n)||o.get(t.name);if(!C||!t.parent)return;const v=C.opt;if(ze(N)&&(t.setAttribute("zIndex",N),C.opt.zIndex=N),c&&v.fontColor&&(v.fontColor=c,t.children.forEach(x=>{x.tagName==="GROUP"&&x.children.forEach(L=>{L.tagName==="LABEL"?(L.setAttribute("fillColor",c),L.setAttribute("strokeColor",c)):L.tagName==="POLYLINE"&&L.setAttribute("strokeColor",c)})})),a&&v.fontBgColor&&(v.fontBgColor=a,t.children.forEach(x=>{x.tagName==="GROUP"&&x.setAttribute("bgcolor",a)})),g&&(v.bold=g),p&&(v.italic=p),Pt(f)&&(v.lineThrough=f),Pt(m)&&(v.underline=m),w&&(v.fontSize=w),u&&h&&d&&n&&v.boxPoint){const x=I==null?void 0:I.get(t.name);if(x){const{fontSize:A,boxSize:E}=x;v.boxSize=E||v.boxSize,v.fontSize=A||v.fontSize}const L=[v.boxPoint[0],v.boxPoint[1]];yi(v.boxPoint,h,d,l);const b=[C.op[0],C.op[1]],P=[b[0]-L[0],b[1]-L[1]];if(C.centerPos=[C.centerPos[0]+P[0],C.centerPos[1]+P[1]],C.opt.eraserlines)for(const A of Object.values(C.opt.eraserlines)){const{op:E,thickness:R}=A;A.thickness=R*Math.max(d[0],d[1]);for(let z=0;z<E.length;z++)mi(E[z],h,d,l)}}else if(l&&v.boxPoint&&(v.boxPoint=[v.boxPoint[0]+l[0],v.boxPoint[1]+l[1]],C.centerPos=[C.centerPos[0]+l[0],C.centerPos[1]+l[1]],C.opt.eraserlines))for(const x of Object.values(C.opt.eraserlines)){const{op:L}=x;for(let b=0;b<L.length;b++){const P=L[b].map((A,E)=>E%2?A+l[1]:A+l[0]);x.op[b]=P}}return C&&o.setInfo(t.name,C),C==null?void 0:C.rect}static getRectFromLayer(e,t){const i=e.getElementsByName(t)[0];if(i){const o=i.getBoundingClientRect();let n={x:Math.floor(o.x),y:Math.floor(o.y),w:Math.floor(o.width+2),h:Math.floor(o.height+2)};return i.children.forEach(a=>{if(a.tagName==="GROUP"){const c=i.getBoundingClientRect();n=ue(n,{x:Math.floor(c.x),y:Math.floor(c.y),w:Math.floor(c.width+2),h:Math.floor(c.height+2)})}}),n}}};M(ft,"textImageSnippetSize",1024*4),M(ft,"SafeBorderPadding",30);let fs=ft;const Et=class Et extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",ce.none);M(this,"toolsType",T.PencilEraser);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"worldPosition");M(this,"worldScaling");M(this,"eraserRect");M(this,"eraserPolyline");M(this,"syncUnitTime",Ie.syncOpt.interval);M(this,"syncIndex",0);M(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.worldPosition=this.fullLayer.worldPosition,this.worldScaling=this.fullLayer.worldScaling,this.syncTimestamp=0}combineConsume(){if(this.tmpPoints.length<2)return{type:D.None};const{thickness:e}=this.workOptions,{width:t,height:i}=Et.eraserSizes[e],o=Math.max(t,i)/this.worldScaling[0],n=this.drawLayer||this.fullLayer,a=this.workId,c={name:a};return{rect:this.draw({attrs:c,consumePoints:this.tmpPoints,replaceId:a,layer:n,thickness:o}),type:D.DrawWork,dataType:B.Local}}consumeService(e){const{op:t,isFullWork:i,replaceId:o}=e;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3){const d=new Q(t[h],t[h+1],t[h+2]);if(this.tmpPoints.length>0){const g=this.tmpPoints[this.tmpPoints.length-1],p=k.Sub(d,g).uni();d.setv(p)}this.tmpPoints.push(d)}if(this.tmpPoints.length<2)return;const n=this.tmpPoints[0].z*2,a=i?this.fullLayer:this.drawLayer||this.fullLayer,l={name:this.workId};return this.draw({attrs:l,consumePoints:this.tmpPoints,layer:a,thickness:n,replaceId:o})}updateTempPoints(e,t){let i=this.tmpPoints.length-1;const o=Date.now();for(let n=0;n<e.length;n+=2){const a=this.tmpPoints.length,c=new Q(e[n],e[n+1]);if(a===0){this.tmpPoints.push(c);continue}const l=a-1,u=this.tmpPoints[l],h=k.Sub(c,u).uni();c.isNear(u,t/2)||(k.Equals(h,u.v,.02)&&(this.tmpPoints.pop(),i--),c.setv(h),c.setT(o),this.tmpPoints.push(c))}return Math.max(i,0)}getChangeNodes(e,t){const i=new Map,o=new Set;let n;if(!this.vNodes)return{willDeleteNodes:o,willNewNodes:i,rect:n};const a=this.worldPosition;let c=Me(this.tmpPoints,e);c=_t(c,a),c=mn(c,this.worldScaling,a);const{nodeRange:l}=this.vNodes.getRectIntersectRange(c);if(!l.size)return{willDeleteNodes:o,willNewNodes:i,rect:n};const u=this.computEraserPointLines(this.tmpPoints,90);for(const[h,d]of l.entries()){if(d.toolsType!==T.Pencil)continue;let g=_t(d.rect,[-a[0],-a[1]]);g={x:g.x/this.worldScaling[0],y:g.y/this.worldScaling[1],w:g.w/this.worldScaling[0],h:g.h/this.worldScaling[1]};const p=[g.x,g.y,g.x+g.w,g.y+g.h],f=[],m=[];for(const w of u)_s.polyline(w,p,f);if(f.length&&d.opt)for(const w of f){const I=[];for(let N=0;N<w.length;N++)N!==0&&lt(w[N],w[N-1])||I.push(...w[N]);m.push(I)}if(m.length&&t){const w=t.createWorkShapeNode({workId:h,toolsType:T.Pencil,toolsOpt:d.opt});w.setWorkId(h);const I=w==null?void 0:w.computPencilPoints({op:d.op,eraserPolylines:m,eraserThickness:e});if(n=ue(n,d.rect),o.add(h),t.removeNode(h),I.length)for(let N=0;N<I.length;N++){const C=`${h}_${Date.now()}_${N}`,S=C,x=t.setFullWork({workId:S,opt:d.opt,toolsType:T.Pencil}).consumeService({op:I[N],isFullWork:!0,replaceId:S});t.clearWorkShapeNodeCache(S),n=ue(n,x),i.set(C,{...d,rect:x??d.rect,name:C,op:I[N]})}}}return{willNewNodes:i,willDeleteNodes:o,rect:n}}consume(e){const{data:t,isFullWork:i,isSubWorker:o,isMainThread:n,removeDrawCount:a,drawCount:c}=e,{op:l,syncUnitTime:u}=t;if(!l||l.length===0)return{type:D.None,...this.baseConsumeResult};u&&(this.syncUnitTime=u);const{thickness:h}=this.workOptions,{width:d,height:g}=Et.eraserSizes[h],p=Math.max(d,g)/this.worldScaling[0],f=this.tmpPoints.length,m=this.tmpPoints[this.tmpPoints.length-1],w=this.updateTempPoints(l,p),I=this.tmpPoints[this.tmpPoints.length-1];if(f===this.tmpPoints.length&&I.equalsXY(m.x,m.y))return{type:D.None,...this.baseConsumeResult};this.syncIndex=Math.min(this.syncIndex,w,Math.max(0,this.tmpPoints.length-2));const N={name:this.workId,id:ze(c)&&c.toString()||void 0},C=this.syncIndex;this.syncTimestamp===0&&(this.syncTimestamp=Date.now());let S=!1,v;const x=this.tmpPoints.slice(w);if(o||n){const b=i?this.fullLayer:this.drawLayer||this.fullLayer;v=this.draw({attrs:N,consumePoints:x,layer:b,removeDrawCount:a,thickness:p})}if(o)return w>10&&this.tmpPoints.splice(0,w-10),{rect:v,type:D.DrawWork,dataType:B.Local};x[0].t-this.syncTimestamp>this.syncUnitTime&&(S=!0,this.syncTimestamp=x[0].t,this.syncIndex=this.tmpPoints.length);const L=[];return this.tmpPoints.slice(C).forEach(b=>{L.push(b.x,b.y,p/2)}),{...this.baseConsumeResult,type:D.DrawWork,dataType:B.Local,rect:v,op:S?L:void 0,index:S?C*3:void 0,updateNodeOpt:{useAnimation:!0}}}draw(e){const{attrs:t,consumePoints:i,layer:o,thickness:n,replaceId:a,removeDrawCount:c}=e;c&&this.removeDrawCountNodes(o,c);let l=Me(i,n);l={x:Math.floor(l.x*this.worldScaling[0]+this.worldPosition[0]-Y.SafeBorderPadding),y:Math.floor(l.y*this.worldScaling[1]+this.worldPosition[1]-Y.SafeBorderPadding),w:Math.floor(l.w*this.worldScaling[0]+2*Y.SafeBorderPadding),h:Math.floor(l.h*this.worldScaling[1]+2*Y.SafeBorderPadding)};const u=new he.Group({...t,normalize:!0,pos:[0,0],anchor:[.5,.5],zIndex:9999,bgcolor:this.workOptions.eraserColor}),h=this.computEraserPointLines(i,90),d=[];for(const g of h)d.push({op:g,thickness:n});for(const g of d){const{thickness:p,op:f}=g,m=f.reduce((S,v,x,L)=>x>0&&L[x-1][0]===v[0]&&L[x-1][1]===v[1]?S:S.concat(v[0],v[1]),[]),w=this.computEraserPoints(m,p),I=nt(w,!0),N={pos:[0,0],d:I,fillColor:this.workOptions.eraserColor},C=new he.Path(N);u.append(C),u.seal()}return this.replace(o,a,u),l}computEraserPointLines(e,t=60){const i=[];let o=0;const n=360-t;for(let a=1;a<e.length;a++){const c=e[a-1],l=e[a];if(a===1&&o===0&&(i[o]=[c.XY]),i[o].push(l.XY),a<e.length-1){const u=l.getAngleByPoints(c,e[a+1]);(u<t||u>n)&&(o++,i[o]=[l.XY])}}return e.length===1&&i.length===0&&i.push([e[0].XY,e[0].XY]),i}consumeAll(e){const{workerEngine:t}=e;if(this.replace(this.fullLayer,this.workId),!this.tmpPoints.length)return{type:D.None,...this.baseConsumeResult};const{thickness:i}=this.workOptions,{width:o,height:n}=Et.eraserSizes[i],a=Math.max(o,n)/this.worldScaling[0],{willDeleteNodes:c,willNewNodes:l,rect:u}=this.getChangeNodes(a,t);if(c.size===0&&l.size===0)return{type:D.FullWork,...this.baseConsumeResult,rect:u};const h=[];this.tmpPoints.map(g=>{h.push(g.x,g.y,a/2)});const d=Ge(h);return{...this.baseConsumeResult,type:D.FullWork,dataType:B.Local,rect:u,ops:d,willNewNodes:l,willDeleteNodes:c}}clearTmpPoints(){this.tmpPoints.length=0}};M(Et,"eraserSizes",ui);let Ms=Et;const Ot=class Ot extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",ce.none);M(this,"toolsType",T.BitMapEraser);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"worldPosition");M(this,"worldScaling");M(this,"eraserRect");M(this,"eraserPolyline");M(this,"syncUnitTime",Ie.syncOpt.interval);M(this,"syncIndex",0);M(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.worldPosition=this.fullLayer.worldPosition,this.worldScaling=this.fullLayer.worldScaling,this.syncTimestamp=0}combineConsume(){if(this.tmpPoints.length<2)return{type:D.None};const{thickness:e}=this.workOptions,{width:t,height:i}=Ot.eraserSizes[e],o=Math.max(t,i)/this.worldScaling[0],n=this.drawLayer||this.fullLayer,a=this.workId,c={name:a};return{rect:this.draw({attrs:c,consumePoints:this.tmpPoints,replaceId:a,layer:n,thickness:o}),type:D.DrawWork,dataType:B.Local}}consumeService(e){const{op:t,isFullWork:i,replaceId:o}=e;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3){const d=new Q(t[h],t[h+1],t[h+2]);if(this.tmpPoints.length>0){const g=this.tmpPoints[this.tmpPoints.length-1],p=k.Sub(d,g).uni();d.setv(p)}this.tmpPoints.push(d)}if(this.tmpPoints.length<2)return;const n=this.tmpPoints[0].z*2,a=i?this.fullLayer:this.drawLayer||this.fullLayer,l={name:this.workId};return this.draw({attrs:l,consumePoints:this.tmpPoints,layer:a,thickness:n,replaceId:o})}updateTempPoints(e,t){let i=this.tmpPoints.length-1;const o=Date.now();for(let n=0;n<e.length;n+=2){const a=this.tmpPoints.length,c=new Q(e[n],e[n+1]);if(a===0){this.tmpPoints.push(c);continue}const l=a-1,u=this.tmpPoints[l],h=k.Sub(c,u).uni();c.isNear(u,t/2)||(k.Equals(h,u.v,.02)&&(this.tmpPoints.pop(),i--),c.setv(h),c.setT(o),this.tmpPoints.push(c))}return Math.max(i,0)}getChangeNodes(e,t){const i=new Map,o=new Set;let n;if(!this.vNodes)return{willDeleteNodes:o,willUpdateNodes:i,rect:n};const a=this.worldPosition;let c=Me(this.tmpPoints,e);c=_t(c,a),c=mn(c,this.worldScaling,a);const{nodeRange:l}=this.vNodes.getRectIntersectRange(c);if(!l.size)return{willDeleteNodes:o,willUpdateNodes:i,rect:n};const u=this.computEraserPointLines(this.tmpPoints);for(const[h,d]of l.entries()){if(d.toolsType===T.Text||d.toolsType===T.Image)continue;let g=_t(d.rect,[-a[0],-a[1]]);g={x:g.x/this.worldScaling[0],y:g.y/this.worldScaling[1],w:g.w/this.worldScaling[0],h:g.h/this.worldScaling[1]};const p=[g.x,g.y,g.x+g.w,g.y+g.h],f=[],m=[];for(const I of u)_s.polyline(I,p,f);if(f.length&&d.opt)for(const I of f){const N=[];for(let C=0;C<I.length&&!(isNaN(I[C][0])||isNaN(I[C][1]));C++)C!==0&&lt(I[C],I[C-1])||N.push(...I[C]);N.length!==0&&m.push(N)}if(d.opt.eraserlines||(d.opt.eraserlines=[]),d.opt.eraserlines){if(d.opt.eraserlines.push({op:m,thickness:e}),t){const{toolsType:I}=d,N=t.createWorkShapeNode({workId:h,toolsType:I,toolsOpt:d.opt});N==null||N.setWorkId(h);const C=N==null?void 0:N.consumeService({op:d.op,isFullWork:!0,replaceId:h});if(n=ue(n,C),N!=null&&N.isDelete){t.removeNode(h),o.add(h);continue}}i.set(h,d)}}return{willUpdateNodes:i,willDeleteNodes:o,rect:n}}consume(e){const{data:t,isFullWork:i,isSubWorker:o,isMainThread:n,removeDrawCount:a,drawCount:c}=e,{op:l,syncUnitTime:u}=t;if(!l||l.length===0)return{type:D.None,...this.baseConsumeResult};u&&(this.syncUnitTime=u);const{thickness:h}=this.workOptions,{width:d,height:g}=Ot.eraserSizes[h],p=Math.max(d,g)/this.worldScaling[0],f=this.tmpPoints.length,m=this.tmpPoints[this.tmpPoints.length-1],w=this.updateTempPoints(l,p),I=this.tmpPoints[this.tmpPoints.length-1];if(f===this.tmpPoints.length&&I.equalsXY(m.x,m.y))return{type:D.None,...this.baseConsumeResult};this.syncIndex=Math.min(this.syncIndex,w,Math.max(0,this.tmpPoints.length-2));const N={name:this.workId,id:ze(c)&&c.toString()||void 0},C=this.syncIndex;this.syncTimestamp===0&&(this.syncTimestamp=Date.now());let S=!1,v;const x=this.tmpPoints.slice(w);if(o||n){const b=i?this.fullLayer:this.drawLayer||this.fullLayer;v=this.draw({attrs:N,consumePoints:x,layer:b,removeDrawCount:a,thickness:p})}if(o)return w>10&&this.tmpPoints.splice(0,w-10),{rect:v,type:D.DrawWork,dataType:B.Local};x[0].t-this.syncTimestamp>this.syncUnitTime&&(S=!0,this.syncTimestamp=x[0].t,this.syncIndex=this.tmpPoints.length);const L=[];return this.tmpPoints.slice(C).forEach(b=>{L.push(b.x,b.y,p/2)}),{...this.baseConsumeResult,type:D.DrawWork,dataType:B.Local,rect:v,op:S?L:void 0,index:S?C*3:void 0,updateNodeOpt:{useAnimation:!0}}}draw(e){const{attrs:t,consumePoints:i,layer:o,thickness:n,replaceId:a,removeDrawCount:c}=e;c&&this.removeDrawCountNodes(o,c);let l=Me(i,n);l={x:Math.floor(l.x*this.worldScaling[0]+this.worldPosition[0]-Y.SafeBorderPadding),y:Math.floor(l.y*this.worldScaling[1]+this.worldPosition[1]-Y.SafeBorderPadding),w:Math.floor(l.w*this.worldScaling[0]+2*Y.SafeBorderPadding),h:Math.floor(l.h*this.worldScaling[1]+2*Y.SafeBorderPadding)};const u=new he.Group({...t,normalize:!0,pos:[0,0],anchor:[.5,.5],zIndex:9999,bgcolor:this.workOptions.eraserColor}),h=this.computEraserPointLines(i),d=[];for(const g of h)d.push({op:g,thickness:n});for(const g of d){const{thickness:p,op:f}=g,m=f.reduce((S,v,x,L)=>x>0&&L[x-1][0]===v[0]&&L[x-1][1]===v[1]?S:S.concat(v[0],v[1]),[]),w=this.computEraserPoints(m,p),I=nt(w,!0),N={pos:[0,0],d:I,fillColor:this.workOptions.eraserColor},C=new he.Path(N);u.append(C),u.seal()}return this.replace(o,a,u),l}computEraserPointLines(e,t=60){const i=[];let o=0;const n=360-t;for(let a=1;a<e.length;a++){const c=e[a-1],l=e[a];if(a===1&&o===0&&(i[o]=[c.XY]),i[o].push(l.XY),a<e.length-1){const u=l.getAngleByPoints(c,e[a+1]);(u<t||u>n)&&(o++,i[o]=[l.XY])}}return e.length===1&&i.length===0&&i.push([e[0].XY,e[0].XY]),i}consumeAll(e){const{workerEngine:t}=e;if(this.replace(this.fullLayer,this.workId),!this.tmpPoints.length)return{type:D.None,...this.baseConsumeResult};const{thickness:i}=this.workOptions,{width:o,height:n}=Ot.eraserSizes[i],a=Math.max(o,n)/this.worldScaling[0],{willDeleteNodes:c,willUpdateNodes:l,rect:u}=this.getChangeNodes(a,t);if(c.size===0&&l.size===0)return{type:D.FullWork,...this.baseConsumeResult,rect:u};const h=[];this.tmpPoints.map(g=>{h.push(g.x,g.y,a/2)});const d=Ge(h);return{...this.baseConsumeResult,type:D.FullWork,dataType:B.Local,rect:u,ops:d,willUpdateNodes:l,willDeleteNodes:c}}clearTmpPoints(){this.tmpPoints.length=0}};M(Ot,"eraserSizes",ui);let ys=Ot;function hn(r){switch(r){case T.Arrow:return sn;case T.Pencil:return Ko;case T.Straight:return ln;case T.Ellipse:return on;case T.Polygon:case T.Triangle:return an;case T.Star:case T.Rhombus:return rn;case T.Rectangle:return nn;case T.SpeechBalloon:return cn;case T.Text:return fs;case T.LaserPen:return _o;case T.Eraser:return ds;case T.PencilEraser:return Ms;case T.BitMapEraser:return ys;case T.Selector:return gs;case T.Image:return Kt}}function js(r,s){const{toolsType:e,...t}=r;switch(e){case T.Arrow:return new sn(t);case T.Pencil:return new Ko(t);case T.Straight:return new ln(t);case T.Ellipse:return new on(t);case T.Polygon:case T.Triangle:return new an(t);case T.Star:case T.Rhombus:return new rn(t);case T.Rectangle:return new nn(t);case T.SpeechBalloon:return new cn(t);case T.Text:return new fs(t);case T.LaserPen:return new _o(t);case T.Eraser:return new ds(t,s);case T.BitMapEraser:return new ys(t);case T.PencilEraser:return new Ms(t);case T.Selector:return t.vNodes?new gs({...t,vNodes:t.vNodes,drawLayer:t.fullLayer}):void 0;case T.Image:return new Kt(t);default:return}}function un(r){const s=[],e=["PATH","SPRITE","POLYLINE","RECT","ELLIPSE","LABEL"];for(const t of r){if(t.tagName==="GROUP"&&t.children.length){const i=un(t.children);s.push(...i)}t.tagName&&e.includes(t.tagName)&&s.push(t)}return s}const vf="cursorhover",fi=20,fe="mainView";class dn{constructor(s,e){M(this,"viewId");M(this,"scene");M(this,"fullLayer");M(this,"curNodeMap",new Map);M(this,"targetNodeMap",[]);M(this,"highLevelIds");M(this,"canClearUids");M(this,"localUid");this.viewId=s,this.scene=e}init(s){this.fullLayer=s}get(s){return this.curNodeMap.get(s)}setLocalUid(s){this.localUid=s}getLocalUid(){return this.localUid}setCanClearUids(s){this.canClearUids=s}getCanClearUids(){return this.canClearUids}getCanEraserNodes(s,e){const t=new Map;for(const[i,o]of s.entries())o.toolsType===T.Image&&(o.opt.locked||e&&e.disableEraseImage)||o.toolsType===T.Text&&(o.opt.workState===j.Doing||o.opt.workState===j.Start||e&&e.disableEraseText)||this.isCanClearWorkId(i)&&t.set(i,o);return t}getNodesByType(s){const e=new Map;return this.curNodeMap.forEach((t,i)=>{t.toolsType===s&&e.set(i,t)}),e}gethasEraserNodes(){const s=new Map;return this.curNodeMap.forEach((e,t)=>{var i;(i=e.opt.eraserlines)!=null&&i.length&&s.set(t,e)}),s}hasRenderNodes(){return!0}has(s){return this.curNodeMap.has(s)}setInfo(s,e){const t=this.curNodeMap.get(s)||{name:s,rect:e.rect};e.rect&&(t.rect=Pe(e.rect)),e.op&&ly(e.op)&&(t.op=Pe(e.op)),e.canRotate&&(t.canRotate=e.canRotate),e.scaleType&&(t.scaleType=e.scaleType),e.opt&&(t.opt=Pe(e.opt)),e.toolsType&&(t.toolsType=e.toolsType),e.centerPos&&(t.centerPos=Pe(e.centerPos)),Pt(e.isSelected)&&(t.isSelected=e.isSelected),t.rect?this.curNodeMap.set(s,t):this.curNodeMap.delete(s)}selected(s){this.setInfo(s,{isSelected:!0})}unSelected(s){this.setInfo(s,{isSelected:!1})}delete(s){this.curNodeMap.delete(s)}clear(){this.curNodeMap.clear(),this.targetNodeMap.length=0}getRectIntersectRange(s,e=!0,t=!0){let i;const o=new Map;for(const[n,a]of this.curNodeMap.entries())if(Gs(s,a.rect)){if(e&&a.toolsType===T.Image&&a.opt.locked||t&&a.toolsType===T.Text&&(a.opt.workState===j.Doing||a.opt.workState===j.Start))continue;i=ue(i,a.rect),o.set(n,a)}return{rectRange:i,nodeRange:o}}getNodeRectFormShape(s,e){const t=hn(e.toolsType);return this.fullLayer&&(t==null?void 0:t.getRectFromLayer(this.fullLayer,s))}updateNodeRect(s){const e=this.curNodeMap.get(s);if(e){const t=this.getNodeRectFormShape(s,e);if(!t){this.curNodeMap.delete(s);return}e.rect=t,this.curNodeMap.set(s,e)}}updateHighLevelNodesRect(s){this.highLevelIds=s;for(const e of this.highLevelIds.keys())this.updateNodeRect(e)}updateLowLevelNodesRect(){var s;for(const e of this.curNodeMap.keys())(s=this.highLevelIds)!=null&&s.has(e)||this.updateNodeRect(e)}clearHighLevelIds(){this.highLevelIds=void 0}setTargetAssignKeys(s){const e=new Map;for(const t of s){const i=this.curNodeMap.get(t);i&&e.set(t,Pe(i))}return this.targetNodeMap.push(Pe(e)),this.targetNodeMap.length-1}setTarget(){return this.targetNodeMap.push(Pe(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(s){return this.targetNodeMap[s]}deleteTarget(s){this.targetNodeMap.length=s}clearTarget(){this.targetNodeMap.length=0}isLocalWorkId(s){return s.split(Ze).length===1}isCanClearWorkId(s){if(this.canClearUids===void 0||this.canClearUids===!0)return!0;if(np(this.canClearUids)){const e=s.split(Ze);if(e.length===1)return this.canClearUids.has("localSelf")||this.localUid&&this.canClearUids.has(this.localUid);if(e.length===2)return this.canClearUids.has(e[0])}return!1}}class Nf{constructor(s,e,t){M(this,"viewId");M(this,"scene");M(this,"fullLayer");M(this,"vNodes");M(this,"dpr");M(this,"contextType");M(this,"opt");M(this,"cameraOpt");M(this,"isSafari",!1);M(this,"combinePostMsg",new Set);M(this,"workerTaskId");M(this,"protectedTask");M(this,"hasPriorityDraw",!0);M(this,"delayPostDoneResolve");M(this,"cacheImages",new Map);M(this,"imageResolveMap",new Map);M(this,"taskUpdateCameraId");M(this,"debounceUpdateCameraId");var i,o;if(this.viewId=s,this.opt=e,this.dpr=e.dpr,this.contextType=this.getSupportContextType(t,(i=e==null?void 0:e.offscreenCanvasOpt)==null?void 0:i.contextType),!this.contextType)throw new Error("Sorry, your browser doesn't support canvas context type 2d or webgl");try{this.createRenderLayer(e)}catch{if(this.contextType!=="2d")this.contextType="2d",(o=this.scene)==null||o.disconnect(),this.createRenderLayer(e);else throw new Error(`Sorry, your browser doesn't support canvas context type ${this.contextType}`)}this.vNodes=new dn(s,this.scene)}createRenderLayer(s){this.scene=this.createScene(s.offscreenCanvasOpt);const e=Ie.bufferSize.full,t=Ie.bufferSize.sub;this.fullLayer=this.createLayer("fullLayer",this.scene,{...s.layerOpt,bufferSize:this.viewId===fe?e:t*2})}async updateDpr(s){this.dpr=s,this.scene.displayRatio=s}getCachedImages(s){var e;return(e=this.cacheImages.get(s))==null?void 0:e.imageBitmap}getCachedImagesByWorkId(s){for(const[e,t]of this.cacheImages.entries())if(e===s&&t.imageBitmap)return t.imageBitmap}deleteCachedImagesByWorkId(s,e){for(const[t,i]of this.cacheImages.entries())e&&t===e||i.workId===s&&(i.imageBitmap.close(),this.cacheImages.delete(t))}clearCacheImages(){this.cacheImages.forEach(s=>s.imageBitmap.close()),this.cacheImages.clear()}clearImageResolveMap(){this.imageResolveMap.forEach(({timer:s})=>{s&&clearTimeout(s)}),this.imageResolveMap.clear()}setHasPriorityDraw(s){this.hasPriorityDraw=s}getPriorityDraw(){return this.hasPriorityDraw}setIsSafari(s){this.isSafari=s}async on(s){const{msgType:e,toolsType:t,opt:i,imageSrc:o,imageBitmap:n,workId:a,dpr:c}=s;switch(e){case D.UpdateDpr:ze(c)&&await this.updateDpr(c);break;case D.UpdateCamera:await this.updateCamera(s);break;case D.Destroy:this.destroy();break;case D.Clear:await this.clearAll();break;case D.UpdateTools:if(t&&i){const l={toolsType:t,toolsOpt:i,combineUnitTime:s.combineUnitTime};this.localWork.setToolsOpt(l)}break;case D.GetImageBitMap:if(o&&n&&a){const l=a.toString();this.cacheImages.set(o,{imageBitmap:n,workId:l});const u=this.imageResolveMap.get(o);if(u){const{resolve:h,timer:d}=u;d&&clearTimeout(d),h&&h(o)}this.deleteCachedImagesByWorkId(l,o)}break}}getIconSize(s,e,t){const i=s*t,o=e*t;return i<=50||o<=50?[50,50]:i<=100||o<=100?[100,100]:i<=200||o<=200?[200,200]:i<=400||o<=400?[400,400]:i<=800||o<=800?[800,800]:[1600,1600]}async loadImageBitMap(s){const{toolsType:e,opt:t,workId:i,isSubWorker:o}=s;if(e===T.Image&&t&&i){const n=i.toString(),{src:a,type:c,width:l,height:u,strokeColor:h}=t;if(!a||!c||!l||!u)return;let d=a;if(c===St.Iconify){const[m,w]=this.getIconSize(l,u,this.dpr);d=`${a}?width=${m}&height=${w}&color=${h}`}if(this.cacheImages.has(d)){const m=this.getCachedImages(d);if(m)return m}if(this.imageResolveMap.has(d)){const m=this.getCachedImagesByWorkId(n);if(m)return m}const f=await new Promise(m=>{const w=this.imageResolveMap.get(d)||{resolve:void 0,timer:void 0};w.timer&&clearTimeout(w.timer),w.resolve=m,w.timer=setTimeout(()=>{const I=this.imageResolveMap.get(d);I!=null&&I.resolve&&I.resolve(d)},5e3),this.imageResolveMap.set(d,w),this._post({sp:[{imageSrc:d,workId:n,viewId:this.viewId,isgl:!!this.fullLayer.parent.gl,isSubWorker:o,type:D.GetImageBitMap}]})});return this.imageResolveMap.delete(f),this.getCachedImages(d)}}createLocalWork(s){const{workId:e,opt:t,toolsType:i}=s;e&&t&&(!this.localWork.getToolsOpt()&&i&&this.setToolsOpt({toolsType:i,toolsOpt:t}),this.setWorkOpt({workId:e,toolsOpt:t}))}updateScene(s){this.scene.attr({...s});const{width:e,height:t}=s;this.scene.container.width=e,this.scene.container.height=t,this.scene.width=e,this.scene.height=t,this.updateLayer({width:e,height:t})}updateLayer(s){const{width:e,height:t}=s;this.fullLayer&&(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]))}getSupportContextType(s,e){const t=new OffscreenCanvas(100,100);let i=["2d"];s===Hs.Full&&this.viewId===fe&&(i=["webgl2","webgl","2d"],e&&i.unshift(e));for(const o of i)try{if(t.getContext(o))return o}catch{continue}}createScene(s){const{width:e,height:t}=s,i=new OffscreenCanvas(e,t);s.contextType&&delete s.contextType;const o=new he.Scene({container:i,displayRatio:this.dpr,depth:!1,desynchronized:!0,failIfMajorPerformanceCaveat:!0,...s,contextType:this.contextType,id:this.viewId});return o.setAttribute("id",this.viewId),o}createLayer(s,e,t){const{width:i,height:o}=t,n=`offscreen-${s}`,a=e.layer(n,t),c=new he.Group({anchor:[.5,.5],pos:[i*.5,o*.5],size:[i,o],name:"viewport",id:s});return a.append(c),c}async clearAll(){var s;this.fullLayer&&(this.fullLayer.parent.children.forEach(e=>{e.name!=="viewport"&&e.remove()}),Fe(this.fullLayer,this.fullLayer.parent)),this.taskUpdateCameraId&&(clearTimeout(this.taskUpdateCameraId),this.taskUpdateCameraId=void 0),this.debounceUpdateCameraId&&(clearTimeout(this.debounceUpdateCameraId),this.debounceUpdateCameraId=void 0),this.clearCacheImages(),this.clearImageResolveMap(),this.localWork.destroy(),(s=this.serviceWork)==null||s.destroy()}setToolsOpt(s){this.localWork.setToolsOpt(s)}setWorkOpt(s){const{workId:e,toolsOpt:t}=s;e&&t&&this.localWork.setWorkOptions(e.toString(),t)}destroy(){var s;this.vNodes.clear(),this.fullLayer.remove(),He(this.fullLayer,this.fullLayer.parent),this.clearCacheImages(),this.clearImageResolveMap(),this.scene.remove(),this.localWork.destroy(),(s=this.serviceWork)==null||s.destroy()}async post(s){this.combinePostMsg.add(s),await this.runBatchPostData()}async runBatchPostData(){this.workerTaskId||(this.workerTaskId=setTimeout(()=>{this.workerTaskId=void 0,this.combinePost()},16)),this.type===Hs.Full&&!this.delayPostDoneResolve&&await new Promise(e=>{this.delayPostDoneResolve=e})&&(this.delayPostDoneResolve=void 0)}combinePostData(){var a,c;this.workerTaskId=void 0;const s=[],e=[];let t,i,o;const n=new Set;for(const l of this.combinePostMsg.values()){if((a=l.render)!=null&&a.length)for(const u of l.render){let h=!1;if(u.workId&&n.add(u.workId),u.isClearAll&&(u.rect=this.getSceneRect(),u.isClear=!0,delete u.isClearAll),u.drawCanvas){const d=this.getLayer(u.drawCanvas);if(!d||!(d.parent instanceof he.Layer))continue;if(d.parent.render(),u.isDrawAll){const g=this.getSceneRect();u.rect=g,delete u.isDrawAll}}for(const d of s)if(u.viewId===d.viewId){u.isClear&&d.clearCanvas&&d.isClear&&d.clearCanvas===u.clearCanvas&&(d.rect=ue(d.rect,u.rect),h=!0),d.drawCanvas&&d.drawCanvas===u.drawCanvas&&(d.rect=ue(d.rect,u.rect),h=!0);continue}h||(u.isClear&&!u.drawCanvas?s.unshift(u):s.push(u))}if((c=l.sp)!=null&&c.length)for(const u of l.sp){let h=!1;for(const d of e)if(lt(u,d)){h=!0;break}h||e.push(u)}ze(l.fullWorkerDrawCount)&&(t=l.fullWorkerDrawCount),ze(l.subWorkerDrawCount)&&(i=l.subWorkerDrawCount),ze(l.consumeCount)&&(o=l.consumeCount)}return this.combinePostMsg.clear(),{render:s,sp:e,fullWorkerDrawCount:t,subWorkerDrawCount:i,consumeCount:o,workIds:n,viewId:this.viewId}}getSceneRect(){const{width:s,height:e}=this.scene;return{x:0,y:0,w:Math.floor(s),h:Math.floor(e)}}}class Sf{constructor(s){M(this,"viewId");M(this,"vNodes");M(this,"thread");M(this,"fullLayer");M(this,"drawLayer");M(this,"_post");M(this,"tmpOpt");M(this,"workShapes",new Map);M(this,"drawCount",0);M(this,"consumeCount",0);M(this,"syncUnitTime",Ie.syncOpt.interval);M(this,"combineUnitTime",Ie.bezier.combineUnitTime);this.thread=s.thread,this.viewId=s.viewId,this.vNodes=s.vNodes,this.fullLayer=s.fullLayer,this.drawLayer=s.drawLayer,this._post=this.thread.post.bind(s.thread)}setCombineUnitTime(s){this.combineUnitTime=s}setSyncUnitTime(s){this.syncUnitTime=s}destroy(){this.workShapes.clear()}getWorkShapes(){return this.workShapes}getWorkShape(s){return this.workShapes.get(s)}createWorkShape(s,e){if(s&&this.tmpOpt){const t={toolsType:this.tmpOpt.toolsType,toolsOpt:e||this.tmpOpt.toolsOpt},i=this.createWorkShapeNode({...t,workId:s});i&&this.workShapes.set(s,i)}}setWorkOptions(s,e){const t=this.getWorkShape(s);t||this.createWorkShape(s,e),t==null||t.setWorkOptions(e)}createWorkShapeNode(s){var e;return js({...s,vNodes:this.vNodes,fullLayer:this.fullLayer,drawLayer:this.drawLayer},(e=this.thread)==null?void 0:e.serviceWork)}setToolsOpt(s){var e,t,i;((e=this.tmpOpt)==null?void 0:e.toolsType)!==s.toolsType&&(t=this.tmpOpt)!=null&&t.toolsType&&this.clearAllWorkShapesCache(),this.tmpOpt=s,(i=s.toolsOpt)!=null&&i.syncUnitTime&&(this.syncUnitTime=s.toolsOpt.syncUnitTime),s.combineUnitTime&&(this.combineUnitTime=s.combineUnitTime)}getToolsOpt(){return this.tmpOpt}clearWorkShapeNodeCache(s){var e;(e=this.getWorkShape(s))==null||e.clearTmpPoints(),this.workShapes.delete(s)}clearAllWorkShapesCache(){this.workShapes.forEach(s=>s.clearTmpPoints()),this.workShapes.clear()}setFullWork(s){const{workId:e,opt:t,toolsType:i}=s;if(e&&t&&i){const o=e.toString();let n;return e&&this.workShapes.has(o)?(n=this.workShapes.get(o),n==null||n.setWorkOptions(t)):n=this.createWorkShapeNode({toolsOpt:t,toolsType:i,workId:o}),n?(this.workShapes.set(o,n),n):void 0}}}function Cf(r){return r}var pn=Cf;function kf(r,s,e){switch(e.length){case 0:return r.call(s);case 1:return r.call(s,e[0]);case 2:return r.call(s,e[0],e[1]);case 3:return r.call(s,e[0],e[1],e[2])}return r.apply(s,e)}var xf=kf,Df=xf,co=Math.max;function Lf(r,s,e){return s=co(s===void 0?r.length-1:s,0),function(){for(var t=arguments,i=-1,o=co(t.length-s,0),n=Array(o);++i<o;)n[i]=t[s+i];i=-1;for(var a=Array(s+1);++i<s;)a[i]=t[i];return a[s]=e(n),Df(r,this,a)}}var bf=Lf;function jf(r){return function(){return r}}var Af=jf,Pf=Af,lo=Do,zf=pn,Ef=lo?function(r,s){return lo(r,"toString",{configurable:!0,enumerable:!1,value:Pf(s),writable:!0})}:zf,Of=Ef,Rf=800,Wf=16,Yf=Date.now;function Uf(r){var s=0,e=0;return function(){var t=Yf(),i=Wf-(t-e);if(e=t,i>0){if(++s>=Rf)return arguments[0]}else s=0;return r.apply(void 0,arguments)}}var Bf=Uf,Ff=Of,Vf=Bf,Qf=Vf(Ff),Zf=Qf,Hf=pn,Gf=bf,$f=Zf;function Xf(r,s){return $f(Gf(r,s,Hf),r+"")}var Jf=Xf;function qf(r,s,e,t){for(var i=r.length,o=e+(t?1:-1);t?o--:++o<i;)if(s(r[o],o,r))return o;return-1}var Kf=qf;function _f(r){return r!==r}var eM=_f;function tM(r,s,e){for(var t=e-1,i=r.length;++t<i;)if(r[t]===s)return t;return-1}var sM=tM,iM=Kf,oM=eM,nM=sM;function rM(r,s,e){return s===s?nM(r,s,e):iM(r,oM,e)}var aM=rM,cM=aM;function lM(r,s){var e=r==null?0:r.length;return!!e&&cM(r,s,0)>-1}var gn=lM;function hM(r,s,e){for(var t=-1,i=r==null?0:r.length;++t<i;)if(e(s,r[t]))return!0;return!1}var fn=hM;function uM(r,s){for(var e=-1,t=r==null?0:r.length,i=Array(t);++e<t;)i[e]=s(r[e],e,r);return i}var dM=uM,pM=di,gM=gn,fM=fn,MM=dM,yM=Ds,mM=pi,wM=200;function IM(r,s,e,t){var i=-1,o=gM,n=!0,a=r.length,c=[],l=s.length;if(!a)return c;e&&(s=MM(s,yM(e))),t?(o=fM,n=!1):s.length>=wM&&(o=mM,n=!1,s=new pM(s));e:for(;++i<a;){var u=r[i],h=e==null?u:e(u);if(u=t||u!==0?u:0,n&&h===h){for(var d=l;d--;)if(s[d]===h)continue e;c.push(u)}else o(s,h,t)||c.push(u)}return c}var TM=IM,ho=es,vM=Ao,NM=ts,uo=ho?ho.isConcatSpreadable:void 0;function SM(r){return NM(r)||vM(r)||!!(uo&&r&&r[uo])}var CM=SM,kM=li,xM=CM;function Mn(r,s,e,t,i){var o=-1,n=r.length;for(e||(e=xM),i||(i=[]);++o<n;){var a=r[o];s>0&&e(a)?s>1?Mn(a,s-1,e,t,i):kM(i,a):t||(i[i.length]=a)}return i}var DM=Mn;function LM(){}var bM=LM,Rs=Vo,jM=bM,AM=gi,PM=1/0,zM=Rs&&1/AM(new Rs([,-0]))[1]==PM?function(r){return new Rs(r)}:jM,EM=zM,OM=di,RM=gn,WM=fn,YM=pi,UM=EM,BM=gi,FM=200;function VM(r,s,e){var t=-1,i=RM,o=r.length,n=!0,a=[],c=a;if(e)n=!1,i=WM;else if(o>=FM){var l=s?null:UM(r);if(l)return BM(l);n=!1,i=YM,c=new OM}else c=s?[]:a;e:for(;++t<o;){var u=r[t],h=s?s(u):u;if(u=e||u!==0?u:0,n&&h===h){for(var d=c.length;d--;)if(c[d]===h)continue e;s&&c.push(h),a.push(u)}else i(c,h,e)||(c!==a&&c.push(h),a.push(u))}return a}var QM=VM,ZM=TM,HM=DM,po=QM;function GM(r,s,e){var t=r.length;if(t<2)return t?po(r[0]):[];for(var i=-1,o=Array(t);++i<t;)for(var n=r[i],a=-1;++a<t;)a!=i&&(o[i]=ZM(o[i]||n,r[a],s,e));return po(HM(o,1),s,e)}var $M=GM,XM=ni,JM=at;function qM(r){return JM(r)&&XM(r)}var KM=qM,_M=Ro,ey=Jf,ty=$M,sy=KM;ey(function(r){return ty(_M(r,sy))});class iy extends Sf{constructor(e){super(e);M(this,"drawWorkActiveId")}async runFullWork(e){var o;const t=this.setFullWork(e),i=e.ops&&Dt(e.ops);if(t){let n,a;const c=(o=t.getWorkId())==null?void 0:o.toString();return t.toolsType===T.Image?n=await t.consumeServiceAsync({isFullWork:!0,worker:this.thread}):t.toolsType===T.Text?n=await t.consumeServiceAsync({isFullWork:!0,replaceId:c,isDrawLabel:!0}):(n=t.consumeService({op:i,isFullWork:!0,replaceId:c}),a=(e==null?void 0:e.updateNodeOpt)&&t.updataOptService(e.updateNodeOpt)),e.workId&&this.workShapes.delete(e.workId.toString()),ue(n,a)}}runSelectWork(e){var i;const t=this.setFullWork(e);t&&((i=e.selectIds)!=null&&i.length)&&e.workId&&t.selectServiceNode(e.workId.toString(),{selectIds:e.selectIds},!1)}workShapesDone(){for(const e of this.workShapes.keys())this.clearWorkShapeNodeCache(e);Fe(this.fullLayer,this.fullLayer.parent)}canUseSubWorker(e){const t=this.thread.getPriorityDraw();return t||!t&&e!==T.Pencil}async consumeDraw(e){const{workId:t,fullWorkerDrawCount:i,postCount:o}=e,n=t==null?void 0:t.toString(),a=n&&this.workShapes.get(n);if(!a)return;this.drawWorkActiveId&&this.drawWorkActiveId!==n&&(await this.consumeDrawAll({workId:this.drawWorkActiveId,viewId:this.viewId,msgType:D.DrawWork,dataType:B.Local}),this.drawWorkActiveId=void 0),!this.drawWorkActiveId&&n!==G&&(this.drawWorkActiveId=n);const c=a.toolsType;ze(o)&&(this.consumeCount=o);const l=a.consume({data:e,drawCount:this.drawCount,isFullWork:!0,isSubWorker:!0,removeDrawCount:i});switch(c){case T.Selector:l&&(this.drawCount++,await this.drawSelector(l));break;case T.Ellipse:case T.Arrow:case T.Straight:case T.Rectangle:case T.Star:case T.Polygon:case T.SpeechBalloon:{l&&(this.drawCount++,await this.drawShape(l));break}case T.Pencil:case T.PencilEraser:case T.BitMapEraser:{l&&(this.drawCount++,await this.drawPencil(l,t==null?void 0:t.toString()));break}}}async consumeDrawAll(e){const{workId:t}=e;if(t){const i=t.toString();this.drawWorkActiveId===i&&(this.drawWorkActiveId=void 0);const o=this.workShapes.get(i);if(!o)return;switch(o.toolsType){case T.Selector:this.drawCount=0,Fe(this.fullLayer,this.fullLayer.parent),this.clearWorkShapeNodeCache(i),this._post({render:[{isClearAll:!0,clearCanvas:me.Float,viewId:this.viewId}]});break;case T.Arrow:case T.Straight:case T.Ellipse:case T.Pencil:case T.Rectangle:case T.Star:case T.Polygon:case T.SpeechBalloon:case T.BitMapEraser:case T.PencilEraser:this.drawCount=0,Fe(this.fullLayer,this.fullLayer.parent),this.clearWorkShapeNodeCache(i);break}}}async removeWork(e){const{workId:t}=e,i=t==null?void 0:t.toString();if(i){const o=this.removeNode(i);if(o){const n=[];n.push({rect:wt(o),clearCanvas:me.Float,isClear:!0,viewId:this.viewId},{rect:wt(o),drawCanvas:me.Float,viewId:this.viewId}),await this._post({render:n})}}}removeNode(e){const t=this.workShapes.has(e);let i;return t&&(this.fullLayer.getElementsByName(e).forEach(o=>{const n=o.getBoundingClientRect();i=ue(i,{x:n.x-Y.SafeBorderPadding,y:n.y-Y.SafeBorderPadding,w:n.width+Y.SafeBorderPadding*2,h:n.height+Y.SafeBorderPadding*2}),o.remove(),He(o,this.fullLayer.parent)}),i&&this.clearWorkShapeNodeCache(e)),i}async drawPencil(e,t){await this._post({subWorkerDrawCount:this.drawCount,consumeCount:this.consumeCount,render:[{rect:e==null?void 0:e.rect,workId:t,drawCanvas:me.Float,viewId:this.viewId}],sp:(e==null?void 0:e.op)&&[e]})}async drawShape(e){await this._post({subWorkerDrawCount:this.drawCount,consumeCount:this.consumeCount,render:[{rect:(e==null?void 0:e.rect)&&wt(e.rect),isClear:!0,clearCanvas:me.Float,viewId:this.viewId},{rect:(e==null?void 0:e.rect)&&wt(e.rect),drawCanvas:me.Float,viewId:this.viewId}]})}async drawSelector(e){await this._post({subWorkerDrawCount:this.drawCount,consumeCount:this.consumeCount,render:[{rect:(e==null?void 0:e.rect)&&wt(e.rect),isClear:!0,clearCanvas:me.Float,viewId:this.viewId},{rect:(e==null?void 0:e.rect)&&wt(e.rect),drawCanvas:me.Float,viewId:this.viewId}]})}}class oy{constructor(s){M(this,"viewId");M(this,"vNodes");M(this,"topLayer");M(this,"thread");M(this,"post");M(this,"serviceWorkShapes",new Map);M(this,"localWorkShapes",new Map);M(this,"tmpOpt");M(this,"syncUnitTime",Ie.syncOpt.interval);M(this,"animationId");this.viewId=s.viewId,this.vNodes=s.vNodes,this.topLayer=s.topLayer,this.thread=s.thread,this.post=s.thread.post.bind(s.thread)}canUseTopLayer(s){return s===T.LaserPen}getWorkShape(s){return this.localWorkShapes.get(s)}createWorkShape(s,e){if(s&&this.tmpOpt){const t={toolsType:this.tmpOpt.toolsType,toolsOpt:e||this.tmpOpt.toolsOpt},i=this.createWorkShapeNode({...t,workId:s});return i&&this.localWorkShapes.set(s,{node:i,toolsType:i.toolsType,workState:j.Start}),i}}setWorkOptions(s,e){var i;const t=(i=this.localWorkShapes.get(s))==null?void 0:i.node;t||this.createWorkShape(s,e),t==null||t.setWorkOptions(e)}createWorkShapeNode(s){const{toolsType:e}=s;if(e===T.LaserPen)return js({...s,vNodes:this.vNodes,fullLayer:this.topLayer,drawLayer:this.topLayer})}clearAllWorkShapesCache(){this.localWorkShapes.forEach(s=>{var e;return(e=s.node)==null?void 0:e.clearTmpPoints()}),this.localWorkShapes.clear()}setToolsOpt(s){var e;this.tmpOpt=s,(e=s.toolsOpt)!=null&&e.syncUnitTime&&(this.syncUnitTime=s.toolsOpt.syncUnitTime)}getToolsOpt(){return this.tmpOpt}consumeDraw(s){const{workId:e,dataType:t}=s;if(t===B.Service)this.activeServiceWorkShape(s);else{const i=e==null?void 0:e.toString(),o=i&&this.localWorkShapes.get(i);if(!o)return;const n=o.node.consume({data:s,isFullWork:!1,isSubWorker:!0});n.rect&&(o.totalRect=ue(n.rect,o.totalRect),o.result=n,o.workState=j.Doing,i&&this.localWorkShapes.set(i,o))}this.runAnimation()}consumeDrawAll(s){const{workId:e,dataType:t}=s;if(t===B.Service)this.activeServiceWorkShape(s);else{const i=e==null?void 0:e.toString(),o=i&&this.localWorkShapes.get(i);if(!o)return;const n=o.node.consumeAll({data:s});o.totalRect=ue(n.rect,o.totalRect),o.result=n,o.workState=j.Done,i&&this.localWorkShapes.set(i,o)}this.runAnimation()}destroy(){this.serviceWorkShapes.clear(),this.localWorkShapes.clear()}setNodeKey(s,e,t,i){return e.toolsType=t,e.node=this.createWorkShapeNode({workId:s,toolsType:t,toolsOpt:i}),e}activeServiceWorkShape(s){var d,g;const{workId:e,opt:t,toolsType:i,type:o,updateNodeOpt:n,ops:a,op:c}=s;if(!e)return;const l=e.toString(),u=(d=this.vNodes.get(l))==null?void 0:d.rect;if(!((g=this.serviceWorkShapes)!=null&&g.has(l))){let p={toolsType:i,animationWorkData:c||[],animationIndex:0,type:o,updateNodeOpt:n,ops:a,oldRect:u};i&&t&&(p=this.setNodeKey(l,p,i,t)),this.serviceWorkShapes.set(l,p)}const h=this.serviceWorkShapes.get(l);o&&(h.type=o),a&&(h.animationWorkData=Dt(a),h.ops=a),n&&(h.updateNodeOpt=n),c&&(h.animationWorkData=c),h.node&&h.node.getWorkId()!==l&&h.node.setWorkId(l),u&&(h.oldRect=u),i&&t&&(h.toolsType!==i&&i&&t&&this.setNodeKey(l,h,i,t),h.node&&h.node.setWorkOptions(t))}computNextAnimationIndex(s,e){const t=Math.floor((s.animationWorkData||[]).slice(s.animationIndex).length*32/e/this.syncUnitTime)*e;return Math.min((s.animationIndex||0)+(t||e),(s.animationWorkData||[]).length)}async animationDraw(){var n,a,c,l;this.animationId=void 0;let s=!1;const e=new Map,t=[],i=[],o=[];for(const[u,h]of this.serviceWorkShapes.entries())switch(h.toolsType){case T.LaserPen:{const g=this.computNextAnimationIndex(h,8),p=Math.max(0,h.animationIndex||0),f=(h.animationWorkData||[]).slice(p,g);if((h.animationIndex||0)<g){const m=(n=h.node)==null?void 0:n.consumeService({op:f,isFullWork:!1});h.totalRect=ue(h.totalRect,m),h.animationIndex=g,f.length&&e.set(u,{workState:p===0?j.Start:g===((a=h.animationWorkData)==null?void 0:a.length)?j.Done:j.Doing,op:f.slice(-2)})}if(i.push({isClear:!0,rect:h.totalRect,clearCanvas:me.TopFloat,viewId:this.viewId}),t.push({rect:h.totalRect,drawCanvas:me.TopFloat,viewId:this.viewId}),h.isDel){(c=h.node)==null||c.clearTmpPoints(),this.serviceWorkShapes.delete(u);break}h.ops&&h.animationIndex===((l=h.animationWorkData)==null?void 0:l.length)&&!h.isDel&&(this.topLayer.getElementsByName(u.toString())[0]||(h.isDel=!0,this.serviceWorkShapes.set(u,h))),s=!0;break}}for(const[u,h]of this.localWorkShapes.entries()){const{result:d,toolsType:g,totalRect:p,isDel:f,workState:m}=h;switch(g){case T.LaserPen:{if(p&&(i.push({isClear:!0,rect:p,clearCanvas:me.TopFloat,viewId:this.viewId}),t.push({rect:p,drawCanvas:me.TopFloat,viewId:this.viewId})),f){h.node.clearTmpPoints(),this.localWorkShapes.delete(u),o.push({removeIds:[u.toString()],viewId:this.viewId,type:D.RemoveNode});break}d&&((d.op||d.ops)&&o.push(d),h.result=void 0),!this.topLayer.getElementsByName(u.toString())[0]&&m===j.Done&&(h.isDel=!0,this.localWorkShapes.set(u,h)),s=!0;break}}}s&&this.runAnimation(),e.size&&e.forEach((u,h)=>{o.push({type:D.Cursor,uid:h.split(Ze)[0],op:u.op,workState:u.workState,viewId:this.viewId})}),(t.length||i.length||o.length)&&this.post({render:[...i,...t],sp:o})}runAnimation(){this.animationId||(this.animationId=setTimeout(()=>{this.animationId=void 0,this.animationDraw()},16))}}var Hs=(r=>(r.Full="full",r.Sub="sub",r))(Hs||{});class ny extends Nf{constructor(e,t,i){super(e,t,"sub");M(this,"type","sub");M(this,"_post");M(this,"topLayer");M(this,"snapshotFullLayer");M(this,"serviceWork");M(this,"localWork");M(this,"topLayerWork");this._post=i;const o=Ie.bufferSize.sub;this.topLayer=this.createLayer("topLayer",this.scene,{...t.layerOpt,bufferSize:o,contextType:"2d"});const n={thread:this,viewId:this.viewId,vNodes:this.vNodes,fullLayer:this.fullLayer,topLayer:this.topLayer};this.localWork=new iy(n),this.topLayerWork=new oy(n),this.vNodes.init(this.fullLayer)}async combinePost(){var n,a;const{render:e,...t}=this.combinePostData();let i;if(e!=null&&e.length){const c=[];for(const l of e)if(l.rect){if(l.rect=fy(Pe(l.rect),this.scene,this.dpr),!l.rect)continue;if(l.drawCanvas&&l.rect&&l.rect.w>0&&l.rect.h>0){const u=await this.getRectImageBitmap(l);l.imageBitmap=u,i||(i=[]),i.push(u)}c.push(l)}t.render=c}const o=(n=t.sp)==null?void 0:n.filter(c=>c.type!==D.None||c.isLockSentEventCursor);o!=null&&o.length?t.sp=o.map(c=>({...c,viewId:this.viewId})):delete t.sp,t.consumeCount===void 0&&delete t.consumeCount,t.subWorkerDrawCount===void 0&&delete t.subWorkerDrawCount,(o!=null&&o.length||t.consumeCount||t.subWorkerDrawCount||(a=t==null?void 0:t.render)!=null&&a.length)&&this._post(t,i),this.delayPostDoneResolve&&this.delayPostDoneResolve(!0)}getLayer(e,t){if(t&&this.snapshotFullLayer)return this.snapshotFullLayer;switch(e){case me.TopFloat:return this.topLayer;default:return this.fullLayer}}async on(e){const{msgType:t,toolsType:i,opt:o,dataType:n,workState:a,isLockSentEventCursor:c}=e;switch(t){case D.UpdateTools:if(i&&this.topLayerWork.canUseTopLayer(i)&&o){const l={toolsType:i,toolsOpt:o};this.topLayerWork.setToolsOpt(l);return}break;case D.CreateWork:this.createLocalWork(e);return;case D.DrawWork:a===j.Done&&n===B.Local?(await this.consumeDrawAll(n,e),i===T.LaserPen&&c&&this.post({sp:[{type:D.None,isLockSentEventCursor:c}]})):this.consumeDraw(n,e);return;case D.RemoveNode:await this.removeNode(e);return;case D.FullWork:i&&this.topLayerWork.canUseTopLayer(i)&&await this.consumeDrawAll(n,e);return;case D.Snapshot:this.snapshotFullLayer=this.createLayer("snapshotFullLayer",this.scene,{...this.opt.layerOpt,bufferSize:this.viewId===fe?6e3:3e3,contextType:"2d"}),this.snapshotFullLayer&&(await this.getSnapshot(e),this.snapshotFullLayer=void 0);return;case D.BoundingBox:this.snapshotFullLayer=this.createLayer("snapshotFullLayer",this.scene,{...this.opt.layerOpt,bufferSize:this.viewId===fe?6e3:3e3,contextType:"2d"}),this.snapshotFullLayer&&(await this.getBoundingRect(e),this.snapshotFullLayer=void 0);return}await super.on(e)}createLocalWork(e){const{workId:t,toolsType:i,opt:o}=e;if(i&&this.topLayerWork.canUseTopLayer(i)&&t&&o){this.topLayerWork.getToolsOpt()||this.topLayerWork.setToolsOpt({toolsType:i,toolsOpt:o}),this.topLayerWork.setWorkOptions(t.toString(),o);return}i&&this.localWork.canUseSubWorker(i)&&super.createLocalWork(e)}async removeNode(e){const{dataType:t}=e;t===B.Local&&await this.localWork.removeWork(e)}getOffscreen(e,t){return this.getLayer(e,t).parent.canvas}async consumeDraw(e,t){const{workId:i,toolsType:o}=t;if(i){if(o&&this.topLayerWork.canUseTopLayer(o)){e===B.Local&&(this.topLayerWork.getWorkShape(i.toString())||this.createLocalWork(t)),this.topLayerWork.consumeDraw(t);return}o&&this.localWork.canUseSubWorker(o)&&(this.localWork.getWorkShape(i.toString())||this.createLocalWork(t),await this.localWork.consumeDraw(t));return}}async consumeDrawAll(e,t){const{workId:i,toolsType:o,dataType:n}=t;if(i){const a=i.toString();if(o&&this.topLayerWork.canUseTopLayer(o)){n===B.Local&&(this.topLayerWork.getWorkShape(a)||this.createLocalWork(t)),this.topLayerWork.consumeDrawAll(t);return}o&&this.localWork.canUseSubWorker(o)&&(this.localWork.getWorkShape(a)||super.createLocalWork(t),this.localWork.consumeDrawAll(t));return}}async clearAll(){this.vNodes.clear(),super.clearAll(),this.topLayer&&(this.topLayer.parent.children.forEach(e=>{e.name!=="viewport"&&e.remove()}),Fe(this.topLayer,this.topLayer.parent)),await this.post({render:[{isClearAll:!0,clearCanvas:me.TopFloat,viewId:this.viewId}],sp:[{type:D.Clear}]})}getRectImageBitmap(e,t=!1,i){const{rect:o,drawCanvas:n}=e,a=Math.floor(o.x*this.dpr),c=Math.floor(o.y*this.dpr),l=Math.floor(o.w*this.dpr||1),u=Math.floor(o.h*this.dpr||1);return createImageBitmap(this.getOffscreen(n,t),a,c,l,u,i)}updateLayer(e){const{width:t,height:i}=e;super.updateLayer(e),this.topLayer&&(this.topLayer.parent.setAttribute("width",t),this.topLayer.parent.setAttribute("height",i),this.topLayer.setAttribute("size",[t,i]),this.topLayer.setAttribute("pos",[t*.5,i*.5])),this.snapshotFullLayer&&(this.snapshotFullLayer.parent.setAttribute("width",t),this.snapshotFullLayer.parent.setAttribute("height",i),this.snapshotFullLayer.setAttribute("size",[t,i]),this.snapshotFullLayer.setAttribute("pos",[t*.5,i*.5]))}async updateDpr(e){super.updateDpr(e);const t=!!this.topLayerWork.localWorkShapes.size,i=!!this.localWork.getWorkShapes().size,o=[];i&&o.push({isClearAll:!0,clearCanvas:me.Float,viewId:this.viewId}),t&&o.push({isClearAll:!0,clearCanvas:me.TopFloat,viewId:this.viewId}),o.length&&await this.post({render:o})}async updateCamera(e){const t=[],{cameraOpt:i}=e;if(i&&!lt(this.cameraOpt,i)){const o=!!this.topLayerWork.localWorkShapes.size,n=!!this.localWork.getWorkShapes().size;if(n&&this.localWork.workShapesDone(),this.setCameraOpt(i),n&&t.push({isClearAll:!0,clearCanvas:me.Float,viewId:this.viewId}),o){t.push({isClearAll:!0,clearCanvas:me.TopFloat,viewId:this.viewId});for(const[a,c]of this.topLayerWork.localWorkShapes.entries())if(c.totalRect){let l;this.topLayer.getElementsByName(a.toString()).forEach(u=>{const h=u.getBoundingClientRect(),d=wt({x:h.x,y:h.y,w:h.width,h:h.height});l=ue(l,d)}),c.totalRect=l,this.topLayerWork.localWorkShapes.set(a,c)}}t.length&&await this.post({render:t})}}setCameraOpt(e,t){this.cameraOpt=e;const{scale:i,centerX:o,centerY:n,width:a,height:c}=e;(a!==this.scene.width||c!==this.scene.height)&&this.updateScene({width:a,height:c}),t?(t.setAttribute("scale",[i,i]),t.setAttribute("translate",[-o,-n])):(this.fullLayer.setAttribute("scale",[i,i]),this.fullLayer.setAttribute("translate",[-o,-n]),this.topLayer.setAttribute("scale",[i,i]),this.topLayer.setAttribute("translate",[-o,-n]))}async getSnapshot(e){const{scenePath:t,scenes:i,cameraOpt:o,w:n,h:a}=e;if(t&&i&&o&&this.snapshotFullLayer){const c=Pe(this.cameraOpt);this.setCameraOpt(o,this.snapshotFullLayer),this.localWork.fullLayer=this.snapshotFullLayer,this.localWork.drawLayer=void 0;let l;for(const[h,d]of Object.entries(i))if(d!=null&&d.type)switch(d==null?void 0:d.type){case D.UpdateNode:case D.FullWork:{const{opt:g}=d,p={...d,opt:g,workId:h,msgType:D.FullWork,dataType:B.Service,viewId:this.viewId},f=await this.localWork.runFullWork(p);l=ue(l,f);break}}let u;n&&a&&(u={resizeWidth:n,resizeHeight:a}),await this.getSnapshotRender({scenePath:t,curCameraOpt:c,options:u}),this.localWork.fullLayer=this.fullLayer,this.localWork.drawLayer=void 0}}async getSnapshotRender(e){var a;const{scenePath:t,curCameraOpt:i,options:o}=e;((a=this.snapshotFullLayer)==null?void 0:a.parent).render();const n=await this.getRectImageBitmap({rect:this.getSceneRect(),drawCanvas:me.None},!0,o);n&&(this._post({sp:[{type:D.Snapshot,scenePath:t,imageBitmap:n,viewId:this.viewId}]},[n]),n.close(),this.snapshotFullLayer&&Fe(this.snapshotFullLayer,this.snapshotFullLayer.parent),this.setCameraOpt(i,this.fullLayer))}async getBoundingRect(e){const{scenePath:t,scenes:i,cameraOpt:o}=e;if(t&&i&&o&&this.snapshotFullLayer){const n=Pe(this.cameraOpt);this.setCameraOpt(o,this.snapshotFullLayer),this.localWork.fullLayer=this.snapshotFullLayer,this.localWork.drawLayer=void 0;let a;for(const[c,l]of Object.entries(i))if(l!=null&&l.type)switch(l==null?void 0:l.type){case D.UpdateNode:case D.FullWork:{const u=await this.localWork.runFullWork({...l,workId:c,msgType:D.FullWork,dataType:B.Service,viewId:this.viewId});a=ue(a,u);break}}a&&await this.post({sp:[{type:D.BoundingBox,scenePath:t,rect:a}]}),this.localWork.fullLayer=this.fullLayer,this.localWork.drawLayer=void 0,Fe(this.snapshotFullLayer,this.snapshotFullLayer.parent),this.setCameraOpt(n,this.fullLayer)}}}class Kt extends Y{constructor(e){super(e);M(this,"canRotate",!0);M(this,"scaleType",ce.all);M(this,"toolsType",T.Image);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"oldRect");this.workOptions=e.toolsOpt,this.scaleType=Kt.getScaleType(this.workOptions)}consume(){return{type:D.None}}consumeAll(){return{type:D.None}}draw(e){const{layer:t,workId:i,replaceId:o,imageBitmap:n}=e,{centerX:a,centerY:c,width:l,height:u,rotate:h,zIndex:d,eraserlines:g}=this.workOptions,p=new he.Group({anchor:[.5,.5],pos:[a,c],name:i,size:[l,u],zIndex:d,rotate:h}),f={anchor:[.5,.5],pos:[0,0],size:[l,u],texture:n};n||(f.bgcolor="rgba(0,0,0,0.3)");const m=new he.Sprite(f);p.append(m),g&&this.drawEraserlines({group:p,eraserlines:g,pos:[a,c],layer:t}),this.replace(t,o||i,p);const w=p.getBoundingClientRect();if(w)return{x:Math.floor(w.x-Y.SafeBorderPadding),y:Math.floor(w.y-Y.SafeBorderPadding),w:Math.floor(w.width+Y.SafeBorderPadding*2),h:Math.floor(w.height+Y.SafeBorderPadding*2)}}consumeService(){}async consumeServiceAsync(e){var u,h,d,g;const{isFullWork:t,replaceId:i,worker:o}=e,{src:n,uuid:a}=this.workOptions,c=((u=this.workId)==null?void 0:u.toString())||a,l=t?this.fullLayer:this.drawLayer||this.fullLayer;if(n){const p=await o.loadImageBitMap({toolsType:this.toolsType,opt:this.workOptions,workId:c,isSubWorker:o instanceof ny});if(p){const f=this.draw({workId:c,layer:l,replaceId:i,imageBitmap:p});return this.oldRect=c&&((d=(h=this.vNodes)==null?void 0:h.get(c))==null?void 0:d.rect)||void 0,(g=this.vNodes)==null||g.setInfo(c,{rect:f,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:f&&Y.getCenterPos(f,l)}),f}}}clearTmpPoints(){this.tmpPoints.length=0}static getScaleType(e){const{uniformScale:t,rotate:i}=e;return t!==!1||i&&Math.abs(i)%90>0?ce.proportional:ce.all}static updateNodeOpt(e){const{node:t,opt:i,vNodes:o,targetNode:n}=e,{translate:a,originPoint:c,scenePoint:l,scale:u,angle:h,isLocked:d,zIndex:g,strokeColor:p}=i,f=n&&Pe(n)||o.get(t.name);if(!f)return;const m=t.parent;if(m){if(p&&(f.opt.strokeColor=p),ze(g)&&(t.setAttribute("zIndex",g),f.opt.zIndex=g),Pt(d)&&(f.opt.locked=d),c&&l&&u&&a){const{centerX:w,centerY:I,width:N,height:C,uniformScale:S}=f.opt,v=S!==!1?[u[0],u[0]]:u,x=[w,I],L=[w,I];yi(L,l,v,a);const b=[L[0]-x[0],L[1]-x[1]];if(f.centerPos=[f.centerPos[0]+b[0],f.centerPos[1]+b[1]],f.opt.width=Math.round(N*v[0]),f.opt.height=Math.round(C*v[1]),f.opt.centerX=L[0],f.opt.centerY=L[1],f.opt.eraserlines)for(const P of Object.values(f.opt.eraserlines)){const{op:A,thickness:E}=P;P.thickness=E*Math.max(u[0],u[1]);for(let R=0;R<A.length;R++)mi(A[R],l,u,a)}}else if(a){if(f.opt.centerX=f.opt.centerX+a[0],f.opt.centerY=f.opt.centerY+a[1],f.centerPos=[f.centerPos[0]+a[0],f.centerPos[1]+a[1]],f.opt.eraserlines)for(const w of Object.values(f.opt.eraserlines)){const{op:I}=w;for(let N=0;N<I.length;N++){const C=I[N].map((S,v)=>v%2?S+a[1]:S+a[0]);w.op[N]=C}}}else if(ze(h))if(f.opt.rotate=h,f.scaleType=Kt.getScaleType(f.opt),n){const w=yn(f.rect,h);f.rect=w}else{const w=Y.getRectFromLayer(m,t.name);f.rect=w||f.rect}return f&&o.setInfo(t.name,f),f==null?void 0:f.rect}}}function ue(r,s){if(r&&s){const e=Math.min(r.x,s.x),t=Math.min(r.y,s.y),i=Math.max(r.x+r.w,s.x+s.w),o=Math.max(r.y+r.h,s.y+s.h),n=i-e,a=o-t;return{x:e,y:t,w:n,h:a}}return s||r}function Mi(r,s){if(r&&s){const e=Math.min(r.originX,s.originX),t=Math.min(r.originY,s.originY),i=Math.max(r.originX+r.width,s.originX+s.width),o=Math.max(r.originY+r.height,s.originY+s.height),n=i-e,a=o-t;return{originX:e,originY:t,width:n,height:a}}return s||r}function Me(r,s=0){const e={x:0,y:0,w:0,h:0};let t=1/0,i=1/0,o=-1/0,n=-1/0;return r.forEach(a=>{const[c,l]=a.XY;t=Math.min(t,c-s),i=Math.min(i,l-s),o=Math.max(o,c+s),n=Math.max(n,l+s)}),e.x=t,e.y=i,e.w=o-t,e.h=n-i,e}function Gs(r,s){return!(r.x+r.w<s.x||r.x>s.x+s.w||r.y+r.h<s.y||r.y>s.y+s.h)}function wt(r,s=10){return{x:Math.floor(r.x-s),y:Math.floor(r.y-s),w:Math.ceil(r.w+s*2),h:Math.ceil(r.h+s*2)}}function _t(r,s){return{x:r.x+s[0],y:r.y+s[1],w:r.w,h:r.h}}function ry(r,s){const e=new k(r.x,r.y),t=new k(r.x+r.w,r.y),i=new k(r.x+r.w,r.y+r.h),o=new k(r.x,r.y+r.h),n=new k(r.x+r.w/2,r.y+r.h/2),a=Math.PI*s/180,c=k.RotWith(e,n,a),l=k.RotWith(t,n,a),u=k.RotWith(i,n,a),h=k.RotWith(o,n,a);return[c,l,u,h]}function yn(r,s){const e=ry(r,s);return Me(e)}function mn(r,s,e){const t=new k(r.x,r.y),i=new k(r.x+r.w,r.y),o=new k(r.x+r.w,r.y+r.h),n=new k(r.x,r.y+r.h),a=new k(e[0],e[1]),c=new k(s[0],s[1]),l=k.ScaleWOrigin(t,c,a),u=k.ScaleWOrigin(i,c,a),h=k.ScaleWOrigin(o,c,a),d=k.ScaleWOrigin(n,c,a);return Me([l,u,h,d])}function ay(r,s,e){const t=new k(s[0],s[1]);for(let i=0;i<r.length;i+=3){const o=new k(r[i],r[i+1]),n=Math.PI*e/180,a=k.RotWith(o,t,n);r[i]=a.x,r[i+1]=a.y}}function cy(r,s,e){const t=new k(s[0],s[1]);for(let i=0;i<r.length;i+=2){const o=new k(r[i],r[i+1]),n=Math.PI*e/180,a=k.RotWith(o,t,n);r[i]=a.x,r[i+1]=a.y}}function yi(r,s,e,t=[0,0]){const i=new k(s[0],s[1]);for(let o=0;o<r.length;o+=3){const n=new k(r[o],r[o+1]),a=new k(e[0],e[1]),c=k.ScaleWOrigin(n,a,i);r[o]=c.x+t[0],r[o+1]=c.y+t[1]}}function mi(r,s,e,t=[0,0]){const i=new k(s[0],s[1]);for(let o=0;o<r.length;o+=2){const n=new k(r[o],r[o+1]),a=new k(e[0],e[1]),c=k.ScaleWOrigin(n,a,i);r[o]=c.x+t[0],r[o+1]=c.y+t[1]}}function wn(r,s){return r[0]>=s.x&&r[0]<=s.x+s.w&&r[1]>=s.y&&r[1]<=s.y+s.h}function In(r,s){const e=r<=s?1:r/s,t=s<=r?1:s/r;return[e,t]}function ly(r){for(const s of r)if(isNaN(s)||s===1/0||s===-1/0)return!1;return!0}function hy(r){return r!==Math.floor(r)}function uy(r){const s=r.toString();return s.indexOf(".")!==-1?s.split(".")[1].length:0}function dy(r,s){for(;s!==0;)[r,s]=[s,r%s];return r}const py=r=>{if(r.tagName==="GROUP"){const s=Object.getOwnPropertySymbols(r).find(e=>e.toString()==="Symbol(sealed)");if(s&&r[s])return!0}return!1},He=(r,s)=>{if(r.mesh&&r.mesh.texture&&r.name==="eraserTexture"){const e=r.mesh.texture.image;s.deleteTexture(e)}else if(r.tagName==="GROUP"&&r&&r.children)for(const e of r.children)He(e,s)},Fe=(r,s)=>{He(r,s),r.removeAllChildren()},gy=(r,s,e)=>{const t=e.parent;if(s){const i=s.children;if(i){for(const o of i)if(He(o,t),o.tagName==="GROUP")for(const n of o.children)He(n,t)}}s.parent.replaceChild(r,s)},fy=(r,s,e)=>{if(r.w+r.x<=0||r.h+r.y<=0||r.w<=0||r.h<=0)return;const t=s.width,i=s.height,o={x:Math.floor(Math.max(0,r.x)),y:Math.floor(Math.max(0,r.y)),w:Math.floor(Math.min(t,r.w)),h:Math.floor(Math.min(i,r.h))};if(o.x+o.w>t&&(o.w=Math.floor(t-o.x)),o.y+o.h>i&&(o.h=Math.floor(i-o.y)),hy(e)){const n=uy(e),a=Math.pow(10,n),c=dy(a,e*a),l=o.x%c,u=o.x-l;u>=0?(o.x=u,o.w=o.w+l):(o.x=0,o.w=o.w+l-u);const h=o.y%c,d=o.y-h;d>=0?(o.y=d,o.h=o.h+h):(o.y=0,o.h=o.h+h-d)}return o};function bt(r){return`${ms(r.x)},${ms(r.y)} `}function jt(r,s){return`${ms((r.x+s.x)/2)},${ms((r.y+s.y)/2)} `}function ms(r){return+r.toFixed(4)}const ht=async(r,s)=>{let e,t;return new Promise(function(i){if(typeof window.requestIdleCallback=="function"){const o=typeof s=="number"&&!isNaN(s)&&s>0?s:0;t=window.requestIdleCallback(()=>{clearTimeout(e),i(1)},{timeout:o})}e=setTimeout(()=>{t&&window.cancelIdleCallback(t),i(1)},s||0)}).then(function(){r()}).catch(function(){r()})},ut=r=>{const s=(r==null?void 0:r.webkitBackingStorePixelRatio)||(r==null?void 0:r.mozBackingStorePixelRatio)||(r==null?void 0:r.msBackingStorePixelRatio)||(r==null?void 0:r.oBackingStorePixelRatio)||(r==null?void 0:r.backingStorePixelRatio)||1;return Math.max(1,(window.devicePixelRatio||1)/s)},wi=(r,s)=>r.x+r.w<s.x||r.x>s.x+s.w||r.y+r.h<s.y||r.y>s.y+s.h?Nt.outside:r.x>=s.x&&r.y>=s.y&&r.x+r.w<=s.x+s.w&&r.y+r.h<=s.y+s.h?Nt.inside:Nt.intersect;function My(r){let s=0;for(let e=0;e<r.length;e++){const t=r.charCodeAt(e);t>=1&&t<=126||65376<=t&&t<=65439?s++:s+=2}return s}class yy{constructor(s,e){M(this,"plugin");M(this,"uid");M(this,"control");this.control=s,this.plugin=e,this.uid=e.displayer.uid}getNamespaceData(){var s;return X.toJS((s=this.plugin)==null?void 0:s.attributes[this.namespace])||{}}getAuthSpaceData(){var s;return X.toJS((s=this.plugin)==null?void 0:s.attributes[this.authSpace])||{}}getUidFromKey(s){return s.split(Ze).length===2&&s.split(Ze)[0]||this.uid}isLocalId(s){return s.split(Ze).length===1}getLocalId(s){return s.split(Ze)[1]}isSelector(s){return this.getLocalId(s)===G}}const De=class De extends yy{constructor(e,t,i){super(e,t);M(this,"authSpace");M(this,"namespace");M(this,"serviceStorage",{});M(this,"storage",{});M(this,"authStorage",{});M(this,"stateDisposer");M(this,"authDisposer");M(this,"asyncClockState",!1);M(this,"limitNums",new Map);M(this,"limitComponents",O.debounce((e,t)=>{var n,a,c,l,u,h,d,g;const i=((a=(n=this.storage)==null?void 0:n[e])==null?void 0:a[t])&&Object.keys(this.storage[e][t]).length||0;if(i===0)return;let o=this.limitNums.get(`${e}/${t}`);if(!o){const p=this.getLimitNum(i);this.limitNums.set(`${e}/${t}`,p),o=p}if(o>0&&i>=o){const p=De.componentsLimits.indexOf(o),f=p>=0&&p<De.componentsLimits.length-1;if((u=(l=(c=this.control.room)==null?void 0:c.callbacks)==null?void 0:l.listeners)!=null&&u.map.onObjectsLimit&&((d=(h=this.control.room)==null?void 0:h.callbacks)==null||d.dispatch("onObjectsLimit",w=>w(o,f))),!f){this.control.room.logger.error(`exceeds the limit of ${o} components, current: ${i}`),(g=this.control.room)==null||g.disconnect().then(()=>{var w,I,N,C,S;(N=(I=(w=this.control.room)==null?void 0:w.callbacks)==null?void 0:I.listeners)!=null&&N.map.onKickedWithReason&&((S=(C=this.control.room)==null?void 0:C.callbacks)==null||S.dispatch("onKickedWithReason",v=>v("kickByAdmin")))});return}console.warn(`exceeds the limit of ${o} components, current: ${i}`);const m=f?De.componentsLimits[p+1]:0;this.limitNums.set(`${e}/${t}`,m)}},2e3,{maxWait:5e3}));M(this,"clearLimitComponents",(e,t)=>{if(t)this.limitNums.delete(`${e}/${t}`);else for(const i of this.limitNums.keys())`${e}/`.indexOf(i)===0&&this.limitNums.delete(i)});De.syncInterval=(i||De.syncInterval)*.5,this.namespace=De.namespace,this.authSpace=De.authSpace,this.serviceStorage=this.getNamespaceData(),this.storage=O.cloneDeep(this.serviceStorage),this.authStorage=this.getAuthSpaceData(),this.getLimitNums()}getLimitNum(e){return e>=De.componentsLimits[0]?De.componentsLimits[1]:De.componentsLimits[0]}getLimitNums(){for(const[e,t]of Object.entries(this.storage))if(e&&t){for(const[i,o]of Object.entries(t))if(i&&o){const n=this.getLimitNum(Object.keys(o).length);this.limitNums.set(`${e}/${i}`,n)}}}getViewIdBySecenPath(e){const t=this.getNamespaceData();for(const[i,o]of Object.entries(t))if(o){for(const n of Object.keys(o))if(n===e)return i}}getScenePathData(e){const t=this.getNamespaceData();for(const i of Object.values(t))if(i){for(const o of Object.keys(i))if(o===e)return O.cloneDeep(i[o])}}getStorageData(e,t){const i=this.getNamespaceData();return i&&i[e]&&O.cloneDeep(i[e][t])||void 0}hasSelector(e,t){const i=this.storage&&this.storage[e]&&this.storage[e][t];return!!(i&&Object.keys(i).find(o=>this.isOwn(o)&&this.getLocalId(o)===G))}hasIncludeSelector(e,t,i){for(const o of Object.keys(this.storage))if(!(t&&o!==t)){for(const n of Object.keys(this.storage[o]))if(!(i&&n!==i)){for(const a of Object.keys(this.storage[o][n]))if(this.getLocalId(a)===G){const c=this.storage[o][n][a],l=this.isLocalId(e)?this.transformKey(e):e;if(c&&c.selectIds&&c.selectIds.length&&c.selectIds.includes(l))return!0}}}return!1}addStorageStateListener(e){this.stateDisposer=X.autorun(async()=>{var c,l,u,h,d,g;const t=this.getNamespaceData(),{diffView:i,diffScenePath:o,diffData:n}=this.diffFunByView(this.serviceStorage,t);this.serviceStorage=t;const a={};if(Object.keys(i).length>0)for(const[p,f]of Object.entries(i))f&&!O.isEqual((c=this.storage)==null?void 0:c[p],f.newValue)&&(a.diffView||(a.diffView={}),a.diffView[p]=f,this.storage||(this.storage={}),f.newValue===void 0?delete this.storage[p]:this.storage[p]=O.cloneDeep(f.newValue));if(Object.keys(o).length>0){for(const[p,f]of Object.entries(o))if(f){const{viewId:m,newValue:w}=f;f&&!O.isEqual((u=(l=this.storage)==null?void 0:l[m])==null?void 0:u[p],w)&&(a.diffScenePath||(a.diffScenePath={}),a.diffScenePath[p]=f,this.storage||(this.storage={}),this.storage[m]||(this.storage[m]={}),f.newValue===void 0?delete this.storage[m][p]:this.storage[m][p]=O.cloneDeep(f.newValue))}}if(Object.keys(n).length>0){for(const[p,f]of Object.entries(n))if(f){const{viewId:m,scenePath:w,newValue:I}=f;f&&!O.isEqual((g=(d=(h=this.storage)==null?void 0:h[m])==null?void 0:d[w])==null?void 0:g[p],I)&&(a.diffData||(a.diffData={}),a.diffData[p]=f,this.storage||(this.storage={}),this.storage[m]||(this.storage[m]={}),this.storage[m][w]||(this.storage[m][w]={}),f.newValue===void 0?delete this.storage[m][w][p]:this.storage[m][w][p]=O.cloneDeep(f.newValue))}}Object.keys(a).length>0&&e(a)})}removeStorageStateListener(){this.stateDisposer&&this.stateDisposer()}diffFunByView(e,t){const i=Re(e),o=Re(t),n={},a={},c={};for(const l of o)if(!i.includes(l)||e[l]===void 0){n[l]={newValue:t[l],oldValue:void 0};continue}for(const l of i){if(O.isEqual(e[l],t[l]))continue;if(!o.includes(l)||t[l]===void 0){n[l]={newValue:void 0,oldValue:e[l]};continue}const u=this.diffFunByScenePath(e[l],t[l],l);Object.assign(a,u.diffScenePath),Object.assign(c,u.diffData)}return{diffData:c,diffScenePath:a,diffView:n}}diffFunByScenePath(e,t,i){const o=Re(e),n=Re(t),a={},c={};for(const l of n)if(!o.includes(l)||e[l]===void 0){a[l]={newValue:t[l],oldValue:void 0,viewId:i};continue}for(const l of o){if(O.isEqual(e[l],t[l]))continue;if(!n.includes(l)||t[l]===void 0){a[l]={newValue:void 0,oldValue:e[l],viewId:i};continue}const u=this.diffFunByKeys(e[l],t[l],l,i);Object.assign(c,u)}return{diffScenePath:a,diffData:c}}diffFunByKeys(e,t,i,o){const n=Re(e),a=Re(t),c={};for(const l of a)(!n.includes(l)||e[l]===void 0)&&(c[l]={oldValue:void 0,newValue:t[l],viewId:o,scenePath:i});for(const l of n)if(!O.isEqual(e[l],t[l])){if(!a.includes(l)||t[l]===void 0){c[l]={newValue:void 0,oldValue:e[l],viewId:o,scenePath:i};continue}a.includes(l)&&(c[l]={oldValue:e[l],newValue:t[l],viewId:o,scenePath:i})}return c}transformKey(e){return this.uid+Ze+e}isOwn(e){return e.split(Ze)[0]===this.uid}dispatch(e){const{type:t,workId:i,ops:o,index:n,opt:a,toolsType:c,removeIds:l,updateNodeOpt:u,op:h,selectIds:d,isSync:g,scenePath:p,viewId:f}=e;if(f)switch(t){case D.Clear:const m={};p&&this.storage[f]&&this.storage[f][p]?(delete this.storage[f][p],this.setState(m,{isSync:g,viewId:f,scenePath:p})):this.storage[f]&&(delete this.storage[f],this.setState(m,{isSync:g,viewId:f,scenePath:""})),ht(()=>{var S;this.control.pluginManager.dispatchPluginEvent("syncStorage",f,p),(S=this.control.miniMapManager)==null||S.updateMiniMapCamera(f),this.clearLimitComponents(f,p)},De.syncInterval);break;case D.CreateWork:if(p&&i&&c&&a){const S=this.isLocalId(i.toString())?this.transformKey(i):i;this.control.renderControl.isUsePageAuth(f)&&this.control.renderControl.addRenderPageElementId({viewId:f,scenePath:p,elementId:S.toString()}),this.updateValue(S.toString(),{type:D.CreateWork,workId:i,toolsType:c,opt:a},{isSync:g,viewId:f,scenePath:p})}break;case D.DrawWork:if(p&&i&&typeof n=="number"&&(h!=null&&h.length)){const S=this.isLocalId(i.toString())?this.transformKey(i):i,v=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][S]||void 0;if(v!=null&&v.ops||(v==null?void 0:v.type)===D.FullWork)return;const x=n?((v==null?void 0:v.op)||[]).slice(0,n).concat(h):h||(v==null?void 0:v.op),L=c||(v==null?void 0:v.toolsType),b=a||(v==null?void 0:v.opt),P=u||(v==null?void 0:v.updateNodeOpt);i&&L&&b&&x&&(this.control.renderControl.isUsePageAuth(f)&&this.control.renderControl.addRenderPageElementId({viewId:f,scenePath:p,elementId:S.toString()}),this.updateValue(S.toString(),{...v,type:D.DrawWork,workId:i,updateNodeOpt:P,toolsType:L,opt:b,op:x,index:n},{isSync:g,viewId:f,scenePath:p}))}break;case D.FullWork:if(p&&i){const S=this.isLocalId(i.toString())?this.transformKey(i):i,v=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][S]||void 0,x=u||(v==null?void 0:v.updateNodeOpt),L=c||(v==null?void 0:v.toolsType),b=a||(v==null?void 0:v.opt),P=o||(v==null?void 0:v.ops);L&&b&&(this.control.renderControl.isUsePageAuth(f)&&this.control.renderControl.addRenderPageElementId({viewId:f,scenePath:p,elementId:S.toString()}),this.updateValue(S.toString(),{type:D.FullWork,updateNodeOpt:x,workId:S,toolsType:L,opt:b,ops:P},{isSync:g,viewId:f,scenePath:p}),ht(()=>{var A;this.control.pluginManager.dispatchPluginEvent("syncStorage",f,p),(A=this.control.miniMapManager)==null||A.updateMiniMapCamera(f),this.limitComponents(f,p)},De.syncInterval))}break;case D.RemoveNode:if(p&&(l!=null&&l.length)){const S=l.map(v=>this.isLocalId(v+"")?this.transformKey(v):v);this.storage[f]&&this.storage[f][p]&&(Object.keys(this.storage[f][p]).map(v=>{S!=null&&S.includes(v)&&(this.control.renderControl.isUsePageAuth(f)&&this.control.renderControl.delRenderPageElementId({viewId:f,scenePath:p,elementId:v}),this.updateValue(v,void 0,{isSync:g,viewId:f,scenePath:p}))}),ht(()=>{var v;this.control.pluginManager.dispatchPluginEvent("syncStorage",f,p),(v=this.control.miniMapManager)==null||v.updateMiniMapCamera(f)},De.syncInterval))}break;case D.UpdateNode:if(p&&i&&(u||o||a)){const S=this.isLocalId(i.toString())?this.transformKey(i):i,v=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][S]||void 0;v&&(v.updateNodeOpt=u,(o||h)&&(v.ops=o,v.op=h),a&&(v.opt=a),v.type=D.FullWork,this.updateValue(S.toString(),v,{isSync:g,viewId:f,scenePath:p}),ht(()=>{var x;(x=this.control.miniMapManager)==null||x.updateMiniMapCamera(f)},De.syncInterval))}break;case D.Select:if(!p)return;let w;d!=null&&d.length&&(w=d.map(S=>this.isLocalId(S+"")?this.transformKey(S):S));const I=this.transformKey(G),N=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][I]||void 0,C=a||(N==null?void 0:N.opt);w&&this.checkOtherSelector(I,w,{isSync:g,viewId:f,scenePath:p}),this.updateValue(I,w&&{type:D.Select,toolsType:T.Selector,opt:C,selectIds:w},{isSync:g,viewId:f,scenePath:p});break}}checkOtherSelector(e,t,i){const{viewId:o,scenePath:n}=i;for(const a of Object.keys(this.storage[o][n]))if(a!==e&&this.getLocalId(a)===G){const c=this.storage[o][n][a];if(c&&c.selectIds){const l=c.selectIds.filter(u=>!t.includes(u));l.length>0&&(c.selectIds=l),this.updateValue(a,l.length&&c||void 0,i)}}}setState(e,t){const{viewId:i,scenePath:o}=t,n=Re(e);for(let a=0;a<n.length;a++){const c=n[a],l=e[c];typeof l<"u"?(this.storage[i]||(this.storage[i]={}),this.storage[i][o]||(this.storage[i][o]={}),this.storage[i][o][c]=l):delete this.storage[i][o][c]}this.runSyncService(t)}updateValue(e,t,i){const{viewId:o,scenePath:n,storage:a}=i,c=a||this.storage;t===void 0?delete c[o][n][e]:(c[o]||(c[o]={}),c[o][n]||(c[o][n]={}),c[o][n][e]=t),this.runSyncService(i)}runSyncService(e){if(!this.control.renderControl.isWritable){console.warn("The current state is not writable and synchronization cannot be synchronized");return}this.asyncClockState||(this.asyncClockState=!0,setTimeout(()=>{this.asyncClockState=!1,this.syncSerivice(e)},e.isSync?0:De.syncInterval))}syncSerivice(e={storage:this.storage}){const{storage:t}=e,i=t||this.storage,o=Re(this.serviceStorage),n=Re(i),a=new Map;for(const c of o){if(!n.includes(c)){a.set(c,void 0);continue}O.isEqual(this.serviceStorage[c],i[c])||this.syncViewData(i,c)}for(const c of n)o.includes(c)||a.set(c,i[c]);if(a.size>5)this.syncStorageView(i);else for(const[c,l]of a.entries())this.syncUpdataView(i,c,l)}syncViewData(e,t){const i=Re(this.serviceStorage[t]),o=Re(e[t]),n=new Map;for(const a of i){if(!o.includes(a)){n.set(a,void 0);continue}O.isEqual(this.serviceStorage[t][a],e[t][a])||this.syncScenePathData(e,t,a)}for(const a of o)i.includes(a)||n.set(a,e[t][a]);if(n.size>5)this.syncStorageScenePath(t,e[t]);else for(const[a,c]of n.entries())this.syncUpdataScenePath(e,t,a,c)}syncScenePathData(e,t,i){const o=Re(this.serviceStorage[t][i]),n=Re(e[t][i]),a=new Map;for(const c of o){if(!n.includes(c)){a.set(c,void 0);continue}O.isEqual(this.serviceStorage[t][i][c],e[t][i][c])||a.set(c,e[t][i][c])}for(const c of n)o.includes(c)||a.set(c,e[t][i][c]);if(a.size>5)this.syncStorageKey(t,i,e[t][i]);else for(const[c,l]of a.entries())this.syncUpdataKey(e,t,i,c,l)}syncUpdataView(e,t,i){var n;Object.keys(this.serviceStorage).length?(n=this.plugin)==null||n.updateAttributes([this.namespace,t],i):this.syncStorageView(e)}syncStorageView(e){var t;(t=this.plugin)==null||t.updateAttributes([this.namespace],e)}syncUpdataScenePath(e,t,i,o){var a;Object.keys(this.serviceStorage[t]).length?(a=this.plugin)==null||a.updateAttributes([this.namespace,t,i],o):this.syncStorageScenePath(t,e[t])}syncStorageScenePath(e,t){var i;(i=this.plugin)==null||i.updateAttributes([this.namespace,e],t)}syncUpdataKey(e,t,i,o,n){var c;Object.keys(this.serviceStorage[t][i]).length?(c=this.plugin)==null||c.updateAttributes([this.namespace,t,i,o],n):this.syncStorageKey(t,i,e[t][i])}syncStorageKey(e,t,i){var o;(o=this.plugin)==null||o.updateAttributes([this.namespace,e,t],i)}keyTransformWorkId(e){const t=e.split(Ze);return t.length===2?t[1]:e}destroy(){this.removeStorageStateListener(),this.serviceStorage={},this.storage={},this.removeAuthStateListener(),this.authStorage={}}dispatchPageAuth(e,t=!0){var l,u,h,d,g,p,f,m,w,I,N,C,S,v,x,L,b,P,A,E,R,z,Z,ee,F,$,te,le,ie,_,J,de,Be,ke,q,Le,Ue,st;const{operation:i,viewId:o,scenePath:n,pageId:a,pageData:c}=e;switch(i){case Ye.addPage:{if(!o||!n||!a)return;const H=[this.authSpace];Object.keys(this.authStorage).length&&H.push("pageAuth");const K=this.authStorage.pageAuth||{};this.authStorage.pageAuth=K,Object.keys(K).length&&H.push(o),K[o]=K[o]||{},Object.keys(K[o]).length&&H.push(n),K[o][n]=K[o][n]||{render:(c==null?void 0:c.render)||"localSelf",pages:{}},Object.keys(K[o][n].pages).length&&H.push("pages",a);const se={};if(c!=null&&c.elementIds)for(const pe of c.elementIds.keys())se[pe]=!0;K[o][n].pages[a]=se,t&&(H.length===1?(l=this.plugin)==null||l.updateAttributes(H,O.cloneDeep(this.authStorage)):H.length===2?(u=this.plugin)==null||u.updateAttributes(H,O.cloneDeep(K)):H.length===3?(h=this.plugin)==null||h.updateAttributes(H,O.cloneDeep(K[o])):H.length===4?(d=this.plugin)==null||d.updateAttributes(H,O.cloneDeep(K[o][n])):(g=this.plugin)==null||g.updateAttributes(H,O.cloneDeep(se)));return}case Ye.renderPage:{if(!o||!n||!(c!=null&&c.render))return;this.authStorage.pageAuth&&this.authStorage.pageAuth[o]&&this.authStorage.pageAuth[o][n]&&c.render!==this.authStorage.pageAuth[o][n].render&&(this.authStorage.pageAuth[o][n].render=c.render,t&&((p=this.plugin)==null||p.updateAttributes([this.authSpace,"pageAuth",o,n,"render"],c.render)));return}case Ye.deletePage:{if(!o||!n||!a)return;(N=(I=(w=(m=(f=this.authStorage)==null?void 0:f.pageAuth)==null?void 0:m[o])==null?void 0:w[n])==null?void 0:I.pages)!=null&&N[a]&&(delete this.authStorage.pageAuth[o][n].pages[a],t&&((C=this.plugin)==null||C.updateAttributes([this.authSpace,"pageAuth",o,n,"pages",a],void 0)));return}case Ye.clearPage:{if(!o||!n||!a)return;(b=(L=(x=(v=(S=this.authStorage)==null?void 0:S.pageAuth)==null?void 0:v[o])==null?void 0:x[n])==null?void 0:L.pages)!=null&&b[a]&&(delete this.authStorage.pageAuth[o][n].pages[a],t&&((P=this.plugin)==null||P.updateAttributes([this.authSpace,"pageAuth",o,n,"pages",a],{})));return}case Ye.addElement:{if(!o||!n||!a||!(c!=null&&c.elementId))return;(Z=(z=(R=(E=(A=this.authStorage)==null?void 0:A.pageAuth)==null?void 0:E[o])==null?void 0:R[n])==null?void 0:z.pages)!=null&&Z[a]&&(this.authStorage.pageAuth[o][n].pages[a][c.elementId]=!0,t&&((ee=this.plugin)==null||ee.updateAttributes([this.authSpace,"pageAuth",o,n,"pages",a,c.elementId],!0)));return}case Ye.deleteElement:{if(!o||!n||!a||!(c!=null&&c.elementId))return;(_=(ie=(le=(te=($=(F=this.authStorage)==null?void 0:F.pageAuth)==null?void 0:$[o])==null?void 0:te[n])==null?void 0:le.pages)==null?void 0:ie[a])!=null&&_[c.elementId]&&(delete this.authStorage.pageAuth[o][n].pages[a][c.elementId],t&&((J=this.plugin)==null||J.updateAttributes([this.authSpace,"pageAuth",o,n,"pages",a,c.elementId],void 0)));return}case Ye.clearViewScenePath:{if(!o||!n)return;(ke=(Be=(de=this.authStorage)==null?void 0:de.pageAuth)==null?void 0:Be[o])!=null&&ke[n]&&(delete this.authStorage.pageAuth[o][n],t&&((q=this.plugin)==null||q.updateAttributes([this.authSpace,"pageAuth",o,n],void 0)));return}case Ye.clearView:{if(!o)return;(Ue=(Le=this.authStorage)==null?void 0:Le.pageAuth)!=null&&Ue[o]&&(delete this.authStorage.pageAuth[o],t&&((st=this.plugin)==null||st.updateAttributes([this.authSpace,"pageAuth",o],void 0)));return}}}dispatchRenderAuth(e,t=!0){var l,u,h,d,g,p,f,m,w,I,N,C,S,v,x,L,b,P,A,E;const{operation:i,viewId:o,uid:n,renderData:a,isClear:c}=e;if(o)switch(i){case et.setAuth:{if(!a||a.render===void 0&&a.hide===void 0&&a.clear===void 0){this.authStorage.renderAuth&&this.authStorage.renderAuth[o]&&(delete this.authStorage.renderAuth[o],t&&((l=this.plugin)==null||l.updateAttributes([this.authSpace,"renderAuth",o],void 0)));return}const R=[this.authSpace];Object.keys(this.authStorage).length&&R.push("renderAuth");const z=this.authStorage.renderAuth||{};Object.keys(z).length&&R.push(o),z[o]={},this.authStorage.renderAuth=z;const{render:Z,hide:ee,clear:F}=a;if(Z===!0)z[o].render=!0;else if(O.isSet(Z)){z[o].render={};for(const $ of Z.keys())z[o].render[$]=!0}if(ee===!0)z[o].hide=!0;else if(O.isSet(ee)){z[o].hide={};for(const $ of ee.keys())z[o].hide[$]=!0}if(F===!0)z[o].clear=!0;else if(O.isSet(F)){z[o].clear={};for(const $ of F.keys())z[o].clear[$]=!0}t&&(R.length===1?(u=this.plugin)==null||u.updateAttributes(R,O.cloneDeep(this.authStorage)):R.length===2?(h=this.plugin)==null||h.updateAttributes(R,O.cloneDeep(z)):(d=this.plugin)==null||d.updateAttributes(R,O.cloneDeep(z[o])));return}case et.setShow:{if(!n)return;const R=[this.authSpace];Object.keys(this.authStorage).length&&R.push("renderAuth");const z=this.authStorage.renderAuth||{};Object.keys(z).length&&R.push(o),z[o]=z[o]||{},this.authStorage.renderAuth=z,Object.keys(z[o]).length&&R.push("render"),z[o].render=z[o].render||{},z[o].render!==!0&&(Object.keys(z[o].render).length&&R.push(n),z[o].render[n]=!0),z[o].hide!==!0&&((g=z[o].hide)!=null&&g[n])&&(delete z[o].hide[n],t&&((p=this.plugin)==null||p.updateAttributes([this.authSpace,"renderAuth",o,"hide",n],void 0))),t&&(R.length===1?(f=this.plugin)==null||f.updateAttributes(R,O.cloneDeep(this.authStorage)):R.length===2?(m=this.plugin)==null||m.updateAttributes(R,O.cloneDeep(z)):R.length===3?(w=this.plugin)==null||w.updateAttributes(R,O.cloneDeep(z[o])):(I=this.plugin)==null||I.updateAttributes(R,!0));return}case et.setHide:{if(!n)return;const R=[this.authSpace];Object.keys(this.authStorage).length&&R.push("renderAuth");const z=this.authStorage.renderAuth||{};Object.keys(z).length&&R.push(o),z[o]=z[o]||{},this.authStorage.renderAuth=z,Object.keys(z[o]).length&&R.push("hide"),z[o].hide=z[o].hide||{},z[o].hide!==!0&&(Object.keys(z[o].hide).length&&R.push(n),z[o].hide[n]=!0),z[o].render!==!0&&((N=z[o].render)!=null&&N[n])&&(delete z[o].render[n],t&&((C=this.plugin)==null||C.updateAttributes([this.authSpace,"renderAuth",o,"render",n],void 0))),t&&(R.length===1?(S=this.plugin)==null||S.updateAttributes(R,O.cloneDeep(this.authStorage)):R.length===2?(v=this.plugin)==null||v.updateAttributes(R,O.cloneDeep(z)):R.length===3?(x=this.plugin)==null||x.updateAttributes(R,O.cloneDeep(z[o])):(L=this.plugin)==null||L.updateAttributes(R,!0));return}case et.setClear:{if(!n)return;const R=[this.authSpace];Object.keys(this.authStorage).length&&R.push("renderAuth");const z=this.authStorage.renderAuth||{};Object.keys(z).length&&R.push(o),z[o]=z[o]||{},this.authStorage.renderAuth=z,Object.keys(z[o]).length&&R.push("clear"),z[o].clear=z[o].clear||{},z[o].clear!==!0&&(Object.keys(z[o].clear).length&&R.push(n),c?z[o].clear[n]=!0:delete z[o].clear[n]),t&&(R.length===1?(b=this.plugin)==null||b.updateAttributes(R,O.cloneDeep(this.authStorage)):R.length===2?(P=this.plugin)==null||P.updateAttributes(R,O.cloneDeep(z)):R.length===3?(A=this.plugin)==null||A.updateAttributes(R,O.cloneDeep(z[o])):(E=this.plugin)==null||E.updateAttributes(R,c?!0:void 0));return}}}addAuthStateListener(e){this.authDisposer=X.autorun(async()=>{const t=this.getAuthSpaceData(),{renderAuth:i,pageAuth:o}=t;let n,a;O.isEqual(i,this.authStorage.renderAuth)||(n=this.diffAuthFun(this.authStorage.renderAuth||{},i||{}),this.authStorage.renderAuth=i),O.isEqual(o,this.authStorage.pageAuth)||(a=this.diffAuthPageFun(this.authStorage.pageAuth||{},o||{}),this.authStorage.pageAuth=o),(n||a)&&e(n,a)})}removeAuthStateListener(){this.authDisposer&&this.authDisposer()}diffAuthFun(e,t){const i=Re(e),o=Re(t),n={};for(const a of o)if(!i.includes(a)||e[a]===void 0){n[a]={newValue:t[a],oldValue:void 0};continue}for(const a of i)if(!O.isEqual(e[a],t[a])){if(!o.includes(a)||t[a]===void 0){n[a]={newValue:void 0,oldValue:e[a]};continue}n[a]={newValue:t[a],oldValue:e[a]}}return n}diffAuthPageFun(e,t){const i=Re(e),o=Re(t),n={};for(const a of o)if(!i.includes(a)||e[a]===void 0){n[a]={newValue:t[a],oldValue:void 0};continue}for(const a of i)if(!O.isEqual(e[a],t[a])){if(!o.includes(a)||t[a]===void 0){n[a]={newValue:void 0,oldValue:e[a]};continue}n[a]={newValue:t[a],oldValue:e[a]}}return n}};M(De,"namespace","PluginState"),M(De,"authSpace","PluginAuth"),M(De,"syncInterval",500),M(De,"componentsLimits",[500,1e3]);let $s=De;class my{constructor(){M(this,"roomMembers",[]);M(this,"onChangeHooks",new Set)}setRoomMembers(s){this.executChangeUidHook(this.roomMembers,s),this.roomMembers=s}executChangeUidHook(s,e){const t={online:e.map(i=>{var o;return((o=i.payload)==null?void 0:o.uid)||i.session}),offline:s.map(i=>{var o;return((o=i.payload)==null?void 0:o.uid)||i.session})};this.onChangeHooks.forEach(i=>i(t))}getAllRoomMembers(){return this.roomMembers}getRoomMember(s){return this.roomMembers.find(e=>{var t;return((t=e.payload)==null?void 0:t.uid)===s})}isOnLine(s){return!!this.getRoomMember(s)}onUidChangeHook(s){this.onChangeHooks.add(s)}destroy(){this.onChangeHooks.clear()}}var rt=(r=>(r[r.Text=1]="Text",r[r.Shape=2]="Shape",r))(rt||{});const Qe=class Qe{createProxy(s){const e=new Proxy(s,{get(t,i,o){const n=Qe.interceptors.hasOwnProperty(i)?Qe.interceptors:t;return Reflect.get(n,i,o)}});return Qe.proxyToRaw.set(e,s),e}};M(Qe,"proxyToRaw",new WeakMap),M(Qe,"interceptors",{entries(...s){return Qe.proxyToRaw.get(this).entries(...s)},forEach(...s){return Qe.proxyToRaw.get(this).forEach(...s)},size(){return Qe.proxyToRaw.get(this).size},get(s){return Qe.proxyToRaw.get(this).get(s)},set(s,e){return Qe.proxyToRaw.get(this).set(s,e)},delete(s,e){return Qe.proxyToRaw.get(this).delete(s)},clear(){return Qe.proxyToRaw.get(this).clear()}});let It=Qe;class wy{constructor(s){M(this,"internalMsgEmitter");M(this,"publicMsgEmitter");M(this,"control");M(this,"editors");M(this,"activeId");M(this,"proxyMap");M(this,"taskqueue",new Map);const{control:e,internalMsgEmitter:t,publicMsgEmitter:i}=s;this.control=e,this.internalMsgEmitter=t,this.publicMsgEmitter=i;const o=new Map;this.proxyMap=new It;const n=this,a=It.interceptors.set;It.interceptors.set=function(l,u){return n.interceptors.set(l,u),a.call(this,l,u)};const c=It.interceptors.delete;It.interceptors.delete=function(l,u){return n.interceptors.delete(l,u),c.call(this,l)},this.editors=this.proxyMap.createProxy(o)}get collector(){return this.control.collector}filterEditor(s){const e=new Map;return this.editors.forEach((t,i)=>{t.viewId===s&&e.set(i,t)}),e}get interceptors(){return{set:(s,e)=>{var g,p,f,m,w,I,N,C;if(!this.collector)return!0;const{viewId:t,scenePath:i,canSync:o,canWorker:n,type:a,opt:c,dataType:l}=e;if(!n&&!o)return!0;const h=((g=this.collector)==null?void 0:g.isLocalId(s))?(p=this.collector)==null?void 0:p.transformKey(s):s,d=((f=this.collector)==null?void 0:f.storage[t])&&this.collector.storage[t][i]&&this.collector.storage[t][i][h]||void 0;d?d.toolsType===T.Text&&(n&&(this.control.worker.queryTaskBatchData({workId:s,msgType:D.UpdateNode}).forEach(S=>{var v;(v=this.control.worker)==null||v.taskBatchData.delete(S)}),(N=this.control.worker)==null||N.taskBatchData.add({workId:s,msgType:D.UpdateNode,dataType:l||B.Local,toolsType:T.Text,opt:c,viewId:t,scenePath:i,willRefresh:!0}),(C=this.control.worker)==null||C.runAnimation()),o&&(ht(()=>{var S;(S=this.collector)==null||S.dispatch({type:D.UpdateNode,workId:s,toolsType:T.Text,opt:c,viewId:t,scenePath:i})},this.control.worker.maxLastSyncTime),c.workState===j.Done&&this.control.runEffectWork(()=>{this.control.worker.setShapeSelectorByWorkId(s,t)}))):a===rt.Text&&(o&&((m=this.collector)==null||m.dispatch({type:c.text&&D.FullWork||D.CreateWork,workId:s,toolsType:T.Text,opt:c,isSync:!0,viewId:t,scenePath:i})),n&&((w=this.control.worker)==null||w.taskBatchData.add({workId:s,msgType:c.text&&D.FullWork||D.CreateWork,dataType:l||B.Local,toolsType:T.Text,opt:c,viewId:t,scenePath:i,willRefresh:!0}),(I=this.control.worker)==null||I.runAnimation()))},delete:s=>{var a,c;if(!this.collector)return!0;const e=this.editors.get(s);if(!e)return!0;const{viewId:t,scenePath:i,canSync:o,canWorker:n}=e;if(!n&&!o)return!0;n&&((a=this.control.worker)==null||a.taskBatchData.add({workId:s,toolsType:T.Text,msgType:D.RemoveNode,dataType:B.Local,viewId:t,scenePath:i,willRefresh:!0}),(c=this.control.worker)==null||c.runAnimation()),o&&ht(()=>{var l;(l=this.collector)==null||l.dispatch({type:D.RemoveNode,removeIds:[s],toolsType:T.Text,viewId:t,scenePath:i})},this.control.worker.maxLastSyncTime)},clear(){return!0}}}computeTextActive(s,e){var o,n,a,c;const t=(o=this.control.viewContainerManager)==null?void 0:o.transformToScenePoint(s,e),i=(n=this.control.viewContainerManager)==null?void 0:n.getCurScenePath(e);e&&i&&((a=this.control.worker)==null||a.taskBatchData.add({msgType:D.GetTextActive,dataType:B.Local,op:t,viewId:e,scenePath:i}),(c=this.control.worker)==null||c.runAnimation())}checkEmptyTextBlur(){var e;let s=this.activeId;for(const[t,i]of this.editors.entries())if(i.opt.uid&&i.opt.uid===((e=this.collector)==null?void 0:e.uid)){s=t;break}if(s){const t=this.editors.get(s);(t==null?void 0:t.opt.text)&&(t==null?void 0:t.opt.text.replace(/\s*,/g,""))?this.unActive(s):this.delete(s,!0,!0)}}onCameraChange(s,e){var t,i;for(const[o,n]of this.editors.entries())if(n.viewId===e){const{boxPoint:a,boxSize:c}=n.opt,l=a&&((t=this.control.viewContainerManager)==null?void 0:t.transformToOriginPoint(a,n.viewId)),u=(i=this.control.viewContainerManager)==null?void 0:i.getCurScenePath(e);if(u&&e){const h={x:l&&l[0]||0,y:l&&l[1]||0,w:c&&c[0]||0,h:c&&c[1]||0,opt:n.opt,scale:s.scale,type:rt.Text,viewId:e,scenePath:u,canWorker:!1,canSync:!1};this.editors.set(o,h),this.control.viewContainerManager.updateTextEditorInfo(e,this.activeId)}}}onServiceDerive(s){var p,f;const{workId:e,opt:t,msgType:i,viewId:o,scenePath:n,dataType:a}=s;if(!e||!o||!n)return;const c=e.toString();if(i===D.RemoveNode){this.delete(c,!0,!0);return}const{boxPoint:l,boxSize:u}=t,h=l&&((p=this.control.viewContainerManager)==null?void 0:p.transformToOriginPoint(l,o)),d=this.control.viewContainerManager.getView(o),g={x:h&&h[0]||0,y:h&&h[1]||0,w:u&&u[0]||0,h:u&&u[1]||0,opt:t,type:rt.Text,canWorker:!0,canSync:!1,dataType:a,scale:((f=d==null?void 0:d.cameraOpt)==null?void 0:f.scale)||1,viewId:o,scenePath:n};this.editors.set(c,g),a===B.Service&&t.workState===j.Done&&this.activeId===c&&(this.activeId=void 0),this.control.viewContainerManager.updateTextEditorInfo(o,this.activeId)}updateForViewEdited(s,e){var i;this.editors.set(s,e);const t=(i=this.taskqueue.get(s))==null?void 0:i.resolve;t&&t(e)}active(s){var t;const e=this.editors.get(s);e&&e.viewId&&(e.opt.workState=j.Start,e.opt.uid=(t=this.collector)==null?void 0:t.uid,this.activeId=s,e.canWorker=!0,e.canSync=!0,this.editors.set(s,e),this.control.viewContainerManager.updateTextEditorInfo(e.viewId,this.activeId))}unActive(s){const e=this.editors.get(s);e&&e.viewId&&(e.opt.workState=j.Done,e.opt.uid=void 0,e.canWorker=!0,e.canSync=!0,this.editors.set(s,e),this.activeId=void 0,this.control.viewContainerManager.updateTextEditorInfo(e.viewId,this.activeId))}createTextForMasterController(s,e){var n;const{workId:t,isActive:i,...o}=s;e&&this.internalMsgEmitter.emit("addUndoTicker",e,o.viewId),o.opt.uid=(n=this.collector)==null?void 0:n.uid,i&&(this.activeId=t),o.dataType=B.Local,o.canWorker=!0,o.canSync=!0,this.editors.set(t,o),this.control.viewContainerManager.updateTextEditorInfo(o.viewId,this.activeId)}updateTextForMasterController(s,e){var n;const{workId:t,...i}=s;e&&this.internalMsgEmitter.emit("addUndoTicker",e,i.viewId);const o=this.editors.get(t)||{};i.opt&&(i.opt.uid=(n=this.collector)==null?void 0:n.uid),i.dataType=B.Local,this.editors.set(t,{...o,...i}),this.control.viewContainerManager.updateTextEditorInfo(i.viewId,this.activeId)}async updateTextControllerWithEffectAsync(s,e){var u;const{workId:t,...i}=s;e&&this.internalMsgEmitter.emit("addUndoTicker",e,i.viewId);const o=this.editors.get(t)||{};i.opt&&(i.opt.uid=(u=this.collector)==null?void 0:u.uid),i.dataType=B.Local;const n={...o,...i};if(this.editors.set(t,n),this.control.viewContainerManager.updateTextEditorInfo(i.viewId,this.activeId),this.taskqueue.has(t)){const h=this.taskqueue.get(t);return h&&(h.clocker&&clearTimeout(h.clocker),this.taskqueue.delete(t)),await this.updateTextControllerWithEffectAsync(s)}const a=setTimeout(()=>{var d;const h=(d=this.taskqueue.get(t))==null?void 0:d.resolve;h&&h(n)},50),c=await new Promise(h=>{this.taskqueue.set(t,{resolve:h,clocker:a})}),l=this.taskqueue.get(t);return l&&(l.clocker&&clearTimeout(l.clocker),this.taskqueue.delete(t)),c}updateTextForWorker(s,e){const{workId:t,isActive:i,...o}=s,a={...this.editors.get(t)||{},...o};if(i){a.canWorker=!1,a.canSync=!1,this.editors.set(t,a),this.active(t);return}this.editors.set(t,a),this.control.viewContainerManager.updateTextEditorInfo(o.viewId,this.activeId),e&&this.internalMsgEmitter.emit("addUndoTicker",e,o.viewId)}get(s){return this.editors.get(s)}delete(s,e,t){const i=this.editors.get(s);if(i){const o=i.viewId;i.canSync=e,i.canWorker=t,this.editors.delete(s),this.activeId===s&&(this.activeId=void 0),this.control.viewContainerManager.updateTextEditorInfo(o,this.activeId)}}deleteBatch(s,e,t){const i=new Set;for(const o of s){const n=this.editors.get(o);if(n){const a=n.viewId;n.canSync=e,n.canWorker=t,this.editors.delete(o),this.activeId===o&&(this.activeId=void 0),i.add(a)}}for(const o of i)this.control.viewContainerManager.updateTextEditorInfo(o,this.activeId)}clear(s,e){this.editors.forEach((t,i)=>{t.viewId===s&&(e&&(t.canSync=!1),t.canWorker=!1,this.editors.delete(i))}),this.activeId=void 0,this.control.viewContainerManager.updateTextEditorInfo(s,this.activeId)}destory(){this.editors.clear(),this.activeId=void 0}}class Iy{constructor(s){M(this,"expirationTime",Ie.cursor.expirationTime);M(this,"internalMsgEmitter");M(this,"control");M(this,"eventName","applianc-cursor");M(this,"displayer");M(this,"roomMember");M(this,"animationId");M(this,"maxLastSyncTime",Ie.syncOpt.interval);M(this,"willSendEventWorkers",[]);M(this,"willConsumeEventWorkers",new Map);M(this,"sendEventTimerId");M(this,"animationDrawWorkers",new Map);M(this,"animationEventWorkers",new Map);M(this,"cursorInfoMap",new Map);M(this,"doneRenderCursorInfoMap",new Map);var i,o;const{control:e,internalMsgEmitter:t}=s;this.internalMsgEmitter=t,this.control=e,this.roomMember=e.roomMember,this.maxLastSyncTime=((o=(i=this.control.pluginOptions)==null?void 0:i.syncOpt)==null?void 0:o.interval)||this.maxLastSyncTime}activeCollector(){this.control.plugin&&(this.displayer=this.control.room||this.control.play,this.displayer.addMagixEventListener(this.eventName,this.mainMagixEventListener.bind(this)))}mainMagixEventListener(s){var a;const{event:e,payload:t}=s;if(e!==this.eventName)return;const{uid:i,op:o,type:n}=t;if(((a=this.control.collector)==null?void 0:a.uid)!==i&&n===Jt.Cursor&&(o!=null&&o.length)){const c=this.willConsumeEventWorkers.get(i)||[];for(const l of o){const{viewId:u}=l;O.isNumber(l.consumPoint[0])&&O.isNumber(l.consumPoint[1])&&(l.consumPoint=this.control.viewContainerManager.transformToOriginPoint(l.consumPoint,u)),this.control.renderControl.isFilterCursor(u)&&c.unshift({...l,timestamp:Date.now()})}this.willConsumeEventWorkers.set(i,c),this.runAnimation()}}onFocusViewChange(){this.checkDrawWorks(),this.runAnimation()}updateRoomMembers(s){const{offline:e}=s;for(const t of this.cursorInfoMap.keys())t&&e.includes(t)&&this.cursorInfoMap.delete(t)}getKey(s,e){return`${s}${Ze}${e}`}getUidAndviewId(s){const[e,t]=s.split(Ze);return{uid:e,viewId:t}}runAnimation(){this.animationId||(this.animationId=requestAnimationFrame(this.animationCursor.bind(this)))}checkDrawWorks(){var e;const s=this.control.viewContainerManager.focuedViewId;for(const[t,i]of this.animationDrawWorkers.entries()){const{viewId:o,uid:n}=this.getUidAndviewId(t);n!==((e=this.control.collector)==null?void 0:e.uid)&&o!==s&&i.workState===j.Done&&(i.consumPoint=[void 0,void 0])}}animationCursor(){this.animationId=void 0;const s=Date.now();for(const[t,i]of this.animationDrawWorkers.entries()){const{uid:o,viewId:n}=this.getUidAndviewId(t),a=this.roomMember.getRoomMember(o);if(!a){this.animationDrawWorkers.delete(t);continue}const{consumPoint:c,timestamp:l,workState:u}=i,h=this.cursorInfoMap.get(n)||new Map;c&&O.isNumber(c[0])&&O.isNumber(c[1])&&l+this.expirationTime>s?h.set(a.memberId,{x:c[0],y:c[1],roomMember:a,timestamp:l,type:1,workState:u}):h.delete(a.memberId),h.size?this.cursorInfoMap.set(n,h):this.cursorInfoMap.delete(n),this.animationDrawWorkers.delete(t)}const e=new Set;for(const[t,i]of this.cursorInfoMap.entries())if(i)for(const[o,n]of i.entries())n.type===1&&n.workState!==j.Done&&e.add(o);else this.cursorInfoMap.delete(t);for(const[t,i]of this.willConsumeEventWorkers.entries()){const o=this.roomMember.getRoomMember(t);if(O.isNumber(o==null?void 0:o.memberId)&&!e.has(o.memberId)){const n=i.pop();n?this.animationEventWorkers.set(t,n):this.willConsumeEventWorkers.delete(t)}}for(const[t,i]of this.animationEventWorkers.entries()){const o=this.roomMember.getRoomMember(t);if(!o){this.animationEventWorkers.delete(t);continue}const{viewId:n,consumPoint:a,timestamp:c}=i,l=this.cursorInfoMap.get(n)||new Map;a&&O.isNumber(a[0])&&O.isNumber(a[1])&&c+this.expirationTime>s?l.set(o.memberId,{x:a[0],y:a[1],roomMember:o,timestamp:c,type:0}):l.delete(o.memberId),l.size?this.cursorInfoMap.set(n,l):this.cursorInfoMap.delete(n),this.animationEventWorkers.delete(t)}for(const t of this.doneRenderCursorInfoMap.keys())this.cursorInfoMap.has(t)||(this.doneRenderCursorInfoMap.delete(t),this.internalMsgEmitter.emit([ne.Cursor,t],[]));for(const[t,i]of this.cursorInfoMap.entries())if(i!=null&&i.size){const o=[];for(const[a,c]of i.entries()){const{timestamp:l,...u}=c;l+this.expirationTime>s?o.push(u):(i.delete(a),i.size===0&&(this.cursorInfoMap.delete(t),this.doneRenderCursorInfoMap.delete(t),this.internalMsgEmitter.emit([ne.Cursor,t],[])))}const n=this.doneRenderCursorInfoMap.get(t);O.isEqual(n,o)||(this.doneRenderCursorInfoMap.set(t,o),this.internalMsgEmitter.emit([ne.Cursor,t],o))}else this.cursorInfoMap.delete(t),this.doneRenderCursorInfoMap.delete(t),this.internalMsgEmitter.emit([ne.Cursor,t],[]);(this.willConsumeEventWorkers.size||this.cursorInfoMap.size)&&this.runAnimation()}sendEvent(s,e){if(this.displayer&&X.isRoom(this.displayer)){const t=O.isNumber(s[0])&&O.isNumber(s[1])&&this.control.viewContainerManager.transformToScenePoint(s,e)||[void 0,void 0];this.willSendEventWorkers.push({consumPoint:t,viewId:e}),this.sendEventTimerId||(this.sendEventTimerId=setTimeout(()=>{this.dispatchMagixEvent()},this.maxLastSyncTime))}}dispatchMagixEvent(){var s;this.displayer&&X.isRoom(this.displayer)&&this.displayer.isWritable&&this.displayer.dispatchMagixEvent(this.eventName,{type:Jt.Cursor,op:O.cloneDeep(this.willSendEventWorkers),uid:(s=this.control.collector)==null?void 0:s.uid}),this.willSendEventWorkers.length=0,this.sendEventTimerId&&(clearTimeout(this.sendEventTimerId),this.sendEventTimerId=void 0)}collectServiceCursor(s){var n;const{op:e,uid:t,workState:i,viewId:o}=s;if(t&&e&&i&&o){const a=this.roomMember.getRoomMember(t);if(!a||t===((n=this.control.collector)==null?void 0:n.uid))return;const c=this.getKey(t,o);let l=[void 0,void 0];if(O.isNumber(e[0])&&O.isNumber(e[1])){const[h,d]=this.control.viewContainerManager.transformToOriginPoint(e,o);l=[h,d]}if(i===j.Start){for(const h of this.cursorInfoMap.values())if(h!=null&&h.size)for(const d of h.keys())d===a.memberId&&h.delete(d)}const u={consumPoint:l,workState:i,viewId:o,timestamp:Date.now()};if(i===j.Start||i===j.Done){const h=this.willConsumeEventWorkers.get(t);i===j.Start&&h&&this.willConsumeEventWorkers.delete(t),h&&i===j.Done&&(u.timestamp=u.timestamp-this.expirationTime)}this.animationDrawWorkers.set(c,u),this.runAnimation()}}unabled(){var s;this.displayer&&X.isRoom(this.displayer)&&(this.willSendEventWorkers.length=0,this.displayer.dispatchMagixEvent(this.eventName,{type:Jt.Cursor,op:[{viewId:this.control.viewContainerManager.focuedViewId,consumPoint:[void 0,void 0]}],uid:(s=this.control.collector)==null?void 0:s.uid}),this.sendEventTimerId&&(clearTimeout(this.sendEventTimerId),this.sendEventTimerId=void 0))}clearViewCursor(s){var e,t,i;for(const[o]of this.animationDrawWorkers.entries()){const{uid:n}=this.getUidAndviewId(o);n===((e=this.control.collector)==null?void 0:e.uid)&&s===s&&this.animationDrawWorkers.delete(o)}for(const[o]of this.willConsumeEventWorkers.entries())o===((t=this.control.collector)==null?void 0:t.uid)&&this.willConsumeEventWorkers.delete(o);for(const[o]of this.animationEventWorkers.entries())o===((i=this.control.collector)==null?void 0:i.uid)&&this.animationEventWorkers.delete(o);for(const[o]of this.cursorInfoMap.entries())o===o&&(this.cursorInfoMap.delete(o),this.doneRenderCursorInfoMap.delete(o),this.internalMsgEmitter.emit([ne.Cursor,o],[]))}stopAnimation(){this.animationDrawWorkers.clear(),this.willConsumeEventWorkers.clear(),this.cursorInfoMap.clear()}destroy(){var s;(s=this.displayer)==null||s.removeMagixEventListener(this.eventName),this.stopAnimation()}}class qe{constructor(){M(this,"useEmtMsg");M(this,"emtType");M(this,"control");M(this,"mainEngine");M(this,"collectListener",(s,e)=>{this.collect(s,e)})}static dispatch(s,e,t){var i;(i=be.InternalMsgEmitter)==null||i.emit([s,e],t)}get serviceColloctor(){return this.control.collector}registerForMainEngine(s,e){return this.emtType=s,this.control=e,this.mainEngine=e.worker,this.mainEngine.internalMsgEmitter.on([this.emtType,this.emitEventType],this.collectListener),this}destroy(){this.emtType&&this.mainEngine&&this.mainEngine.internalMsgEmitter.off([this.emtType,this.emitEventType],this.collectListener)}collectForLocalWorker(s,e){var t,i,o;for(const[n,a]of s)(t=this.mainEngine)==null||t.queryTaskBatchData(a).forEach(c=>{var l;(l=this.mainEngine)==null||l.taskBatchData.delete(c)}),(i=this.mainEngine)==null||i.taskBatchData.add(n);if(e){this.mainEngine.consume();return}(o=this.mainEngine)==null||o.runAnimation()}collectForServiceWorker(s){ht(()=>{s.forEach(e=>{var t;(t=this.serviceColloctor)==null||t.dispatch(e)})},this.mainEngine.maxLastSyncTime)}pause(){var s;if(this.lastEmtData){this.useEmtMsg=!0;const e={...this.lastEmtData,workState:j.Done};this.collect(e,!0),(s=be.InternalMsgEmitter)==null||s.emit(V.ActiveMethod,!1)}}recover(){var s;this.useEmtMsg&&be.InternalMsgEmitter.hasListeners(V.ActiveMethod)&&((s=be.InternalMsgEmitter)==null||s.emit(V.ActiveMethod,!0))}}class Ty extends qe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",V.CopyNode)}collect(e){var c;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,viewId:i}=e,o=this.control.viewContainerManager.getView(i);if(!(o!=null&&o.displayer))return;const n=o.focusScenePath,a=Date.now();this.mainEngine.internalMsgEmitter.emit("addUndoTicker",a,i);for(const l of t){const u=l.toString(),d=this.serviceColloctor.isLocalId(u)?this.serviceColloctor.transformKey(l):u,g=(c=this.serviceColloctor.getStorageData(i,n))==null?void 0:c[d];if(g){if(l===G){const p=g&&this.copySelector({viewId:i,store:g});p&&this.pasteSelector({...p,viewId:i,scenePath:n,undoTickerId:a});break}if(g.toolsType===T.Text&&g.opt&&g.opt.workState&&g.opt.workState!==j.Done){const p=g&&this.copyText({viewId:i,store:g});p&&this.pasteText({...p,viewId:i,scenePath:n,key:d,store:g,undoTickerId:a});break}}}}copyText(e){const{viewId:t,store:i}=e,o=this.control.viewContainerManager.getView(t);if(!this.serviceColloctor||!o)return;const n=o==null?void 0:o.cameraOpt,a=n&&[n.centerX,n.centerY],c=i.opt,l=c.boxPoint&&c.boxSize&&[c.boxPoint[0]+c.boxSize[0]/2,c.boxPoint[1]+c.boxSize[1]/2];return{bgCenter:a,textCenter:l}}pasteText(e){var m,w;const{bgCenter:t,textCenter:i,store:o,key:n,viewId:a,scenePath:c,undoTickerId:l}=e,u=this.control.viewContainerManager.getView(a);if(!this.serviceColloctor||!u)return;const h=Math.floor(Math.random()*30+1),d=((m=u.cameraOpt)==null?void 0:m.scale)||1,g=t&&i&&[t[0]-i[0]+h,t[1]-i[1]+h]||[h/d,h/d],f=(this.serviceColloctor.isLocalId(n)?n:this.serviceColloctor.getLocalId(n.toString()))+"-"+l;if(o.toolsType===T.Text&&o.opt){const I=o.opt;if(I&&I.boxPoint&&I.text){I.workState=j.Done;const N=I.boxPoint;I.boxPoint=[N[0]+g[0],N[1]+g[1]],I.workState=j.Done;const C=this.control.viewContainerManager.transformToOriginPoint(I.boxPoint,a);this.control.textEditorManager.createTextForMasterController({workId:f,x:C[0],y:C[1],opt:I,scale:((w=u.cameraOpt)==null?void 0:w.scale)||1,type:rt.Text,isActive:!1,viewId:a,scenePath:c}),this.collectForServiceWorker([{...o,opt:I,type:D.FullWork,workId:f,viewId:a,scenePath:c}])}}}copySelector(e){var f,m,w,I,N,C,S,v,x;const{viewId:t,store:i}=e,o=this.control.viewContainerManager.getView(t),n=i.selectIds;if(!this.serviceColloctor||!(n!=null&&n.length)||!o)return;const a=new Map,c={offset:{x:0,y:0},cameraOpt:{centerX:((f=o.cameraOpt)==null?void 0:f.centerX)||0,centerY:((m=o.cameraOpt)==null?void 0:m.centerY)||0,scale:((w=o.cameraOpt)==null?void 0:w.scale)||1}},l=this.control.hasOffscreenCanvas()&&((I=o.displayer.canvasBgRef.current)==null?void 0:I.getBoundingClientRect())||((N=o.displayer.canvasContainerRef.current)==null?void 0:N.getBoundingClientRect()),u=(S=(C=o.displayer)==null?void 0:C.floatBarRef.current)==null?void 0:S.getBoundingClientRect(),h=l&&[l.x+l.width/2,l.y+l.height/2],d=u&&[u.x+u.width/2,u.y+u.height/2],g=h&&o.viewData&&o.viewData.convertToPointInWorld({x:h[0],y:h[1]}),p=d&&o.viewData&&o.viewData.convertToPointInWorld({x:d[0],y:d[1]});g&&p&&(c.offset={x:g.x-p.x,y:g.y-p.y});for(const L of n){const b=(x=(v=this.serviceColloctor)==null?void 0:v.getStorageData(o.id,o.focusScenePath))==null?void 0:x[L];b&&a.set(L,b)}return{copyStores:a,copyCoordInfo:c}}pasteSelector(e){var m,w;const{copyStores:t,copyCoordInfo:i,viewId:o,scenePath:n,undoTickerId:a}=e,c=this.control.viewContainerManager.getView(o);if(!t.size||!this.serviceColloctor||!c)return;const{offset:l,cameraOpt:u}=i,{scale:h}=u,d=Math.floor(Math.random()*30+1),g=l&&[l.x+d,l.y+d]||[d/h,d/h],p=[],f=[];for(const[I,N]of t.entries()){const S=(this.serviceColloctor.isLocalId(I)?I:this.serviceColloctor.getLocalId(I.toString()))+"-"+a,v={useAnimation:!1};if(N.toolsType===T.Text&&N.opt){const L=N.opt;if(L&&L.boxPoint&&L.text){L.workState=j.Done;const b=L.boxPoint;L.boxPoint=[b[0]+g[0],b[1]+g[1]],L.workState=j.Done;const P=this.control.viewContainerManager.transformToOriginPoint(L.boxPoint,o);this.control.textEditorManager.createTextForMasterController({workId:S,x:P[0],y:P[1],opt:L,scale:((m=c.cameraOpt)==null?void 0:m.scale)||1,type:rt.Text,isActive:!1,viewId:o,scenePath:n})}f.push({...N,opt:L,type:D.FullWork,workId:S,viewId:o,scenePath:n});continue}if(N.toolsType===T.Image&&(N.opt.uuid=S,N.opt.centerX=N.opt.centerX+g[0],N.opt.centerY=N.opt.centerY+g[1]),N.ops){const L=Dt(N.ops).map((P,A)=>{const E=A%3;return E===0?P+g[0]:E===1?P+g[1]:P}),b=Ge(L);N.ops=b}const x=((w=N==null?void 0:N.opt)==null?void 0:w.eraserlines)??[];if(x.length)for(const L of Object.values(x)){const{op:b}=L;for(let P=0;P<b.length;P++){const A=b[P].map((E,R)=>R%2?E+g[1]:E+g[0]);L.op[P]=A}}f.push({...N,updateNodeOpt:v,type:D.FullWork,workId:S,viewId:o,scenePath:n}),p.push([{...N,updateNodeOpt:v,workId:S,msgType:D.FullWork,dataType:B.Local,emitEventType:V.CopyNode,willSyncService:!1,willRefresh:!0,viewId:o},{workId:S,msgType:D.FullWork,emitEventType:V.CopyNode}])}p.length&&this.collectForLocalWorker(p),f.length&&this.collectForServiceWorker(f)}}class vy extends qe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",V.SetColorNode);M(this,"undoTickerId")}setTextColor(e,t,i,o){const{fontColor:n,fontBgColor:a}=i;t.opt&&(n&&(t.opt.fontColor=n),a&&(t.opt.fontBgColor=a),this.control.textEditorManager.updateTextForMasterController({workId:e,opt:t.opt,viewId:o,canSync:!0,canWorker:!0}))}collect(e){var I,N;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,strokeColor:i,fillColor:o,fontColor:n,fontBgColor:a,viewId:c,workState:l,thickness:u,strokeType:h}=e,d=this.control.viewContainerManager.getView(c);if(!(d!=null&&d.displayer))return;const g=d.focusScenePath,p=[...t],f=this.serviceColloctor.storage,m=[],w={};for((l===j.Start||!this.undoTickerId&&l===j.Done)&&(this.undoTickerId=Date.now(),this.mainEngine.internalMsgEmitter.emit("addUndoTicker",this.undoTickerId,c));p.length;){const C=p.pop();if(!C)continue;const S=C.toString(),v=this.serviceColloctor.isLocalId(S),x=v?this.serviceColloctor.transformKey(C):S;let L=S;!v&&this.serviceColloctor.isOwn(L)&&(L=this.serviceColloctor.getLocalId(L));const b=(N=(I=f==null?void 0:f[c])==null?void 0:I[g])==null?void 0:N[x];if(b){const P=b.updateNodeOpt||{};if(n||a){if(n){P.fontColor=n;const[E,R,z,Z]=Xt(n);w.textColor=[E,R,z],w.textOpacity=Z}if(a)if(P.fontBgColor=rs(a)?"transparent":a,rs(a))w.textBgColor=void 0,w.textBgOpacity=void 0;else{const[E,R,z,Z]=Xt(a);w.textBgColor=[E,R,z],w.textBgOpacity=Z}if(b.toolsType===T.Text&&b.opt&&l!==j.Start){this.setTextColor(L,Pe(b),P,c),l===j.Done&&(this.undoTickerId=void 0);continue}}if(i){P.strokeColor=i;const[E,R,z,Z]=Xt(i);w.strokeColor=[E,R,z],w.strokeOpacity=Z}if(o)if(P.fillColor=rs(o)?"transparent":o,rs(o))w.fillColor=void 0,w.fillOpacity=void 0;else{const[E,R,z,Z]=Xt(o);w.fillColor=[E,R,z],w.fillOpacity=Z}u&&(P.thickness=u,w.strokeWidth=u),h&&(P.strokeType=h,w.strokeType=h);const A={workId:L,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:P,emitEventType:this.emitEventType,willRefresh:!0,willRefreshSelector:!0,willSyncService:!0,textUpdateForWoker:!0,viewId:c};m.push([A,{workId:L,msgType:D.UpdateNode,emitEventType:this.emitEventType}])}}m.length&&(l===j.Done&&(this.undoTickerId=void 0),this.collectForLocalWorker(m)),Object.keys(w).length&&setTimeout(()=>{var C;(C=this.control.room)==null||C.setMemberState(w)},0)}}class Ny extends qe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",V.ZIndexNode);M(this,"zIndexMap",new Map)}clearZIndex(e){this.zIndexMap.delete(e)}getMinZIndex(e){var t;return((t=this.zIndexMap.get(e))==null?void 0:t.min)||0}getMaxZIndex(e){var t;return((t=this.zIndexMap.get(e))==null?void 0:t.max)||0}setMaxZIndex(e,t){const i=this.getMinZIndex(t);this.zIndexMap.set(t,{min:i,max:e})}setMinZIndex(e,t){const i=this.getMaxZIndex(t);this.zIndexMap.set(t,{min:e,max:i})}addMaxLayer(e){const t=this.getMaxZIndex(e)+1;this.setMaxZIndex(t,e)}addMinLayer(e){const t=this.getMinZIndex(e)-1;this.setMinZIndex(t,e)}correct(e){const t=e.sort((i,o)=>i[1]-o[1]);for(let i=1;i<t.length;i++){const o=t[i][1],n=t[i-1][1];o<=n&&(t[i][1]=n+1)}return t}collect(e){if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,layer:i,viewId:o}=e,n=this.control.viewContainerManager.getView(o);if(!(n!=null&&n.displayer))return;const a=n.focusScenePath,c=[...t],l=this.serviceColloctor.storage,u=[],h=[];for(;c.length;){const g=c.pop();if(!g)continue;const p=g.toString(),f=this.serviceColloctor.isLocalId(p),m=f?this.serviceColloctor.transformKey(g):p;let w=p;!f&&this.serviceColloctor.isOwn(w)&&(w=this.serviceColloctor.getLocalId(w));const I=Pe(l[o][a][m]);let N;if(I&&w===G){if(I.selectIds){h.push(...I.selectIds),h.sort((x,L)=>{var A,E,R,z;const b=((E=(A=l[d(x,this.serviceColloctor)])==null?void 0:A.opt)==null?void 0:E.zIndex)||0,P=((z=(R=l[d(x,this.serviceColloctor)])==null?void 0:R.opt)==null?void 0:z.zIndex)||0;return b>P?1:x<L?-1:0});const C=I.updateNodeOpt||{};C.zIndexLayer=i;const S={workId:g,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:C,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:o},v=new Map;i===qt.Top?(this.addMaxLayer(o),N=this.getMaxZIndex(o)):(this.addMinLayer(o),N=this.getMinZIndex(o)),h.forEach(x=>{var A,E,R,z,Z;const L=(A=this.serviceColloctor)==null?void 0:A.isLocalId(x);let b=L&&((E=this.serviceColloctor)==null?void 0:E.transformKey(x))||x;const P=(z=(R=l==null?void 0:l[o])==null?void 0:R[a])==null?void 0:z[b];P&&(!L&&((Z=this.serviceColloctor)!=null&&Z.isOwn(b))&&(b=this.serviceColloctor.getLocalId(b)),C.zIndex=N,P!=null&&P.opt&&(P.opt.zIndex=N),P!=null&&P.opt&&v.set(b,{updateNodeOpt:P.updateNodeOpt,opt:P.opt}))}),S.selectStore=v,S.willSerializeData=!0,u.push([S,{workId:g,msgType:D.UpdateNode,emitEventType:this.emitEventType}])}continue}}u.length&&this.collectForLocalWorker(u);function d(g,p){return p.isLocalId(g)&&p.transformKey(g)||g}}}class Sy extends qe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",V.TranslateNode);M(this,"cachePosition")}collect(e,t){var p,f,m;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:i,position:o,workState:n,viewId:a}=e;this.lastEmtData=e;const c=this.control.viewContainerManager.getView(a);if(!(c!=null&&c.displayer))return;const l=c.focusScenePath,u=[...i],h=(p=this.serviceColloctor)==null?void 0:p.storage,d=[],g=n===j.Start&&Date.now()||void 0;for(g&&this.mainEngine.internalMsgEmitter.emit("addUndoTicker",g,a);u.length;){const w=u.pop();if(!w)continue;const I=w.toString(),N=this.serviceColloctor.isLocalId(I),C=N&&this.serviceColloctor.transformKey(w)||I;let S=I;!N&&this.serviceColloctor.isOwn(S)&&(S=this.serviceColloctor.getLocalId(S));const v=(m=(f=h==null?void 0:h[a])==null?void 0:f[l])==null?void 0:m[C];if(v&&S===G){if(v.selectIds){const x=this.control.viewContainerManager.transformToScenePoint([o.x,o.y],a);if(n===j.Start&&(this.cachePosition=x),this.cachePosition){const L=v.updateNodeOpt||{};L.translate=[x[0]-this.cachePosition[0],x[1]-this.cachePosition[1]],L.workState=n;const b={workId:w,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:L,emitEventType:this.emitEventType,willSyncService:!0,textUpdateForWoker:!0,viewId:a};n===j.Done&&(b.textUpdateForWoker=!0,b.willSerializeData=!0,this.cachePosition=void 0),d.push([b,{workId:w,msgType:D.UpdateNode,emitEventType:this.emitEventType,workState:n}])}}continue}}n===j.Start?this.mainEngine.unWritable():n===j.Done&&(this.mainEngine.abled(),this.lastEmtData=void 0),d.length&&this.collectForLocalWorker(d,t)}}class Cy extends qe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",V.DeleteNode)}collect(e){var d,g;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,viewId:i}=e,o=this.control.viewContainerManager.getView(i);if(!(o!=null&&o.displayer))return;const n=o.focusScenePath,a=this.serviceColloctor.storage,c=[...t],l=[],u=[],h=Date.now();for(;c.length;){const p=c.pop();if(!p)continue;const f=p.toString(),m=this.serviceColloctor.isLocalId(f),w=m?this.serviceColloctor.transformKey(p):f,I=(g=(d=a==null?void 0:a[i])==null?void 0:d[n])==null?void 0:g[w];if(I){let N=f;if(!m&&this.serviceColloctor.isOwn(N)&&(N=this.serviceColloctor.getLocalId(N)),I.toolsType===T.Text){this.control.textEditorManager.delete(N,!0,!0);continue}u.push(N)}}u.length&&(l.push([{msgType:D.RemoveNode,emitEventType:V.DeleteNode,removeIds:u,dataType:B.Local,willSyncService:!0,willRefresh:!0,viewId:i},void 0]),this.mainEngine.internalMsgEmitter.emit("addUndoTicker",h,i),this.collectForLocalWorker(l))}}class ky extends qe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",V.ScaleNode);M(this,"targetText",new Map);M(this,"cacheTextInfo",new Map)}async setTextStyle(e,t,i){const o=await this.control.textEditorManager.updateTextControllerWithEffectAsync({workId:e,opt:t,viewId:i,canSync:!1,canWorker:!1});return{key:e,textInfo:o}}async collect(e,t){var I,N,C,S,v,x,L;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:i,workState:o,viewId:n,originPoint:a,scenePoint:c,dir:l,scale:u,translate:h}=e;this.lastEmtData=e;const d=this.control.viewContainerManager.getView(n);if(!(d!=null&&d.displayer))return;const g=d.focusScenePath,p=[...i],f=(I=this.serviceColloctor)==null?void 0:I.storage,m=[],w=o===j.Start&&Date.now()||void 0;for(w&&this.mainEngine.internalMsgEmitter.emit("addUndoTicker",w,n);p.length;){const b=p.pop();if(!b)continue;const P=b.toString(),A=this.serviceColloctor.isLocalId(P),E=A&&this.serviceColloctor.transformKey(b)||P;let R=P;!A&&this.serviceColloctor.isOwn(R)&&(R=this.serviceColloctor.getLocalId(R));const z=(C=(N=f==null?void 0:f[n])==null?void 0:N[g])==null?void 0:C[E];if(z&&R===G&&z.selectIds){const Z=z.updateNodeOpt||{};if(Z.dir=l,Z.originPoint=a,Z.scenePoint=c,Z.workState=o,Z.scale=u,Z.translate=h,o===j.Start){this.cacheTextInfo.clear();for(const F of z.selectIds){const $=(S=this.serviceColloctor)==null?void 0:S.isLocalId(F),te=$&&((v=this.serviceColloctor)==null?void 0:v.transformKey(F))||F;let le=te;!$&&((x=this.serviceColloctor)!=null&&x.isOwn(te))&&(le=this.serviceColloctor.getLocalId(te));const ie=this.control.textEditorManager.get(le);ie&&o===j.Start&&this.targetText.set(le,Pe(ie))}}if(this.targetText.size&&o!==j.Start&&u){const F=[];for(const[te,le]of this.targetText.entries()){const{opt:ie}=le,_=Math.floor(ie.fontSize*u[0]),J=this.cacheTextInfo.get(te),de=!J&&ie.fontSize!==_||J&&J.fontSize!==_||!1,Be=(L=this.control.textEditorManager.get(te))==null?void 0:L.opt;if(de&&Be&&ie.boxSize&&ie.boxPoint){const ke=this.setTextStyle(te,{...Be,fontSize:_},n);F.push(ke)}}const $=await Promise.all(F);for(const te of $)if(te){const{key:le,textInfo:ie}=te;this.cacheTextInfo.set(le,{fontSize:ie.opt.fontSize,boxSize:ie.opt.boxSize,boxPoint:ie.opt.boxPoint})}Z.textInfos=this.cacheTextInfo}const ee={workId:b,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:Z,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:n};o===j.Done&&(ee.willSerializeData=!0,this.targetText.clear()),m.push([ee,{workId:b,msgType:D.UpdateNode,emitEventType:this.emitEventType,workState:o}]);continue}}o===j.Start?this.mainEngine.unWritable():o===j.Done&&(this.mainEngine.abled(),this.lastEmtData=void 0),m.length&&this.collectForLocalWorker(m,t)}}class xy extends qe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",V.RotateNode);M(this,"cacheOriginRotate",0)}collect(e,t){var p,f,m,w,I,N,C;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:i,angle:o,workState:n,viewId:a}=e;this.lastEmtData=e;const c=this.control.viewContainerManager.getView(a);if(!(c!=null&&c.displayer))return;const l=c.focusScenePath,u=[...i],h=(p=this.serviceColloctor)==null?void 0:p.storage,d=[],g=n===j.Start&&Date.now()||void 0;for(g&&this.mainEngine.internalMsgEmitter.emit("addUndoTicker",g,a);u.length;){const S=u.pop();if(!S)continue;const v=S.toString(),x=this.serviceColloctor.isLocalId(v),L=x&&this.serviceColloctor.transformKey(S)||v;let b=v;!x&&this.serviceColloctor.isOwn(b)&&(b=this.serviceColloctor.getLocalId(b));const P=(m=(f=h==null?void 0:h[a])==null?void 0:f[l])==null?void 0:m[L];if(P&&b===G){if(((w=P.selectIds)==null?void 0:w.length)===1){const A=P.selectIds[0];if(n===j.Start){const Z=((I=this.serviceColloctor)==null?void 0:I.isLocalId(A))&&((N=this.serviceColloctor)==null?void 0:N.transformKey(A))||A,ee=h[a][l][Z];this.cacheOriginRotate=((C=ee==null?void 0:ee.opt)==null?void 0:C.rotate)||0}const E=P.updateNodeOpt||{};E.angle=(o+this.cacheOriginRotate)%360,E.workState=n;const R={workId:S,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:E,emitEventType:this.emitEventType,willRefreshSelector:!1,willSyncService:!0,viewId:a};n===j.Done&&(R.willRefreshSelector=!0,R.willSerializeData=!0,this.cacheOriginRotate=0),d.push([R,{workId:S,msgType:D.UpdateNode,emitEventType:this.emitEventType,workState:n}])}continue}}n===j.Start?this.mainEngine.unWritable():n===j.Done&&(this.mainEngine.abled(),this.lastEmtData=void 0),d.length&&this.collectForLocalWorker(d,t)}}function Dy(r){switch(r){case T.Text:return rt.Text;case T.SpeechBalloon:case T.Star:case T.Ellipse:case T.Rectangle:case T.Triangle:case T.Rhombus:case T.Polygon:return rt.Shape}}class Ly extends qe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",V.SetFontStyle);M(this,"timerId")}async setTextStyle(e,t,i,o){const{bold:n,underline:a,lineThrough:c,italic:l,fontSize:u}=i;if(t.toolsType&&Dy(t.toolsType)===rt.Text){t.opt&&(n&&(t.opt.bold=n),O.isBoolean(a)&&(t.opt.underline=a),O.isBoolean(c)&&(t.opt.lineThrough=c),l&&(t.opt.italic=l),u&&(t.opt.fontSize=u));const d=await this.control.textEditorManager.updateTextControllerWithEffectAsync({workId:e,opt:t.opt,viewId:o,canSync:!1,canWorker:!1});return{key:e,textInfo:d}}}async collect(e){var I,N,C,S,v,x;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,bold:i,italic:o,lineThrough:n,underline:a,viewId:c,fontSize:l}=e,u=this.control.viewContainerManager.getView(c);if(!(u!=null&&u.displayer))return;const h=u.focusScenePath,d=[...t],g=this.serviceColloctor.storage,p={},f=Date.now();this.mainEngine.internalMsgEmitter.emit("addUndoTicker",f,c);const m=[];for(;d.length;){const L=d.pop();if(!L)continue;const b=L.toString(),P=this.serviceColloctor.isLocalId(b),A=P?this.serviceColloctor.transformKey(L):b;let E=b;!P&&this.serviceColloctor.isOwn(E)&&(E=this.serviceColloctor.getLocalId(E));const R=(N=(I=g==null?void 0:g[c])==null?void 0:I[h])==null?void 0:N[A];if(R){const z=R.updateNodeOpt||{};if(i&&(z.bold=i,p.bold=i==="bold"),o&&(z.italic=o,p.italic=o==="italic"),O.isBoolean(n)&&(z.lineThrough=n,p.lineThrough=n),O.isBoolean(a)&&(z.underline=a,p.underline=a),l&&(z.fontSize=l,p.textSize=l),R.toolsType===T.Text&&R.opt){const Z=this.setTextStyle(E,O.cloneDeep(R),z,c);m.push(Z);continue}if(R&&E===G&&((C=R.selectIds)!=null&&C.length))for(const Z of R.selectIds){const ee=(S=this.serviceColloctor)==null?void 0:S.isLocalId(Z);let F=ee&&((v=this.serviceColloctor)==null?void 0:v.transformKey(Z))||Z;const $=g[c][h][F]||void 0;if(!ee&&((x=this.serviceColloctor)!=null&&x.isOwn(F))&&(F=this.serviceColloctor.getLocalId(F)),$&&$.toolsType===T.Text&&R.opt){const te=this.setTextStyle(F,O.cloneDeep($),z,c);m.push(te);continue}}}}const w=await Promise.all(m);for(const L of w)if(L){const{key:b,textInfo:P}=L;P&&(P.canSync=!0,P.canWorker=!0,this.control.textEditorManager.updateForViewEdited(b,P))}Object.keys(p).length&&(this.timerId&&(clearTimeout(this.timerId),this.timerId=void 0),this.timerId=setTimeout(()=>{var L;this.timerId=void 0,(L=this.control.room)==null||L.setMemberState(p)},0))}}class by extends qe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",V.SetPoint);M(this,"undoTickerId")}collect(e){var I,N,C;if(!this.serviceColloctor||!this.mainEngine)return;const{workId:t,pointMap:i,workState:o,viewId:n}=e,a=this.control.viewContainerManager.getView(n);if(!(a!=null&&a.displayer))return;const c=a.focusScenePath,l=(I=this.serviceColloctor)==null?void 0:I.storage,u=[],h=o===j.Start&&Date.now()||void 0;h&&(this.undoTickerId=h,this.mainEngine.internalMsgEmitter.emit("addUndoTicker",h,n));const d=t;if(!d)return;const g=d.toString(),p=this.serviceColloctor.isLocalId(g),f=p&&this.serviceColloctor.transformKey(d)||g;let m=g;!p&&this.serviceColloctor.isOwn(m)&&(m=this.serviceColloctor.getLocalId(m));const w=(C=(N=l==null?void 0:l[n])==null?void 0:N[c])==null?void 0:C[f];if(w&&m===G&&w.selectIds){const S=w.updateNodeOpt||{};S.pointMap=i,S.workState=o;const v={workId:d,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:S,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:n};o===j.Done&&(v.undoTickerId=this.undoTickerId),u.push([v,{workId:d,msgType:D.UpdateNode,emitEventType:this.emitEventType}])}o===j.Start?this.mainEngine.unWritable():o===j.Done&&this.mainEngine.abled(),u.length&&this.collectForLocalWorker(u)}}class jy extends qe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",V.SetLock)}collect(e){var d,g;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,isLocked:i,viewId:o}=e,n=this.control.viewContainerManager.getView(o);if(!(n!=null&&n.displayer))return;const a=n.focusScenePath,c=[...t],l=this.serviceColloctor.storage,u=[],h=Date.now();for(;c.length;){const p=c.pop();if(!p)continue;const f=p.toString(),m=this.serviceColloctor.isLocalId(f),w=m?this.serviceColloctor.transformKey(p):f;let I=f;!m&&this.serviceColloctor.isOwn(I)&&(I=this.serviceColloctor.getLocalId(I));const N=(g=(d=l==null?void 0:l[o])==null?void 0:d[a])==null?void 0:g[w];if(N){const C=N.updateNodeOpt||{};C.isLocked=i;const S={workId:I,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:C,emitEventType:this.emitEventType,willRefresh:!0,willRefreshSelector:!0,willSyncService:!0,viewId:o};u.push([S,{workId:I,msgType:D.UpdateNode,emitEventType:this.emitEventType}])}}this.mainEngine.internalMsgEmitter.emit("addUndoTicker",h,o),u.length&&this.collectForLocalWorker(u)}}class Ay extends qe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",V.SetShapeOpt)}collect(e){var d,g;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,viewId:i,...o}=e,n=this.control.viewContainerManager.getView(i);if(!(n!=null&&n.displayer))return;const a=n.focusScenePath,c=[...t],l=this.serviceColloctor.storage,u=[],h=Date.now();for(;c.length;){const p=c.pop();if(!p)continue;const f=p.toString(),m=this.serviceColloctor.isLocalId(f),w=m?this.serviceColloctor.transformKey(p):f;let I=f;!m&&this.serviceColloctor.isOwn(I)&&(I=this.serviceColloctor.getLocalId(I));const N=(g=(d=l==null?void 0:l[i])==null?void 0:d[a])==null?void 0:g[w];if(N){const C={...N.updateNodeOpt,...o,willRefresh:!0};if(N&&I===G){const S={workId:I,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:C,emitEventType:this.emitEventType,willRefresh:!0,willRefreshSelector:!0,willSyncService:!0,viewId:i};u.push([S,{workId:I,msgType:D.UpdateNode,emitEventType:this.emitEventType}])}}}u.length&&(this.mainEngine.internalMsgEmitter.emit("addUndoTicker",h,i),this.collectForLocalWorker(u))}}class ae{constructor(s){M(this,"builders",new Map);this.builders=new Map(s.map(e=>[e,this.build(e)]))}build(s){switch(s){case V.TranslateNode:return new Sy;case V.ZIndexNode:return new Ny;case V.CopyNode:return new Ty;case V.SetColorNode:return new vy;case V.DeleteNode:return new Cy;case V.ScaleNode:return new ky;case V.RotateNode:return new xy;case V.SetFontStyle:return new Ly;case V.SetPoint:return new by;case V.SetLock:return new jy;case V.SetShapeOpt:return new Ay}}getBuilder(s){return this.builders.get(s)}registerForMainEngine(s,e){return this.builders.forEach(t=>{t&&t.registerForMainEngine(s,e)}),this}destroy(){this.builders.forEach(s=>{s&&s.destroy()}),this.builders.clear()}pause(){return this.builders.forEach(s=>{s&&s.pause()}),this}recover(){return this.builders.forEach(s=>{s&&s.recover()}),this}static emitMethod(s,e,t){qe.dispatch(s,e,t)}static activeListener(s){be.InternalMsgEmitter.on(V.ActiveMethod,s)}static unmountActiveListener(s){be.InternalMsgEmitter.off(V.ActiveMethod,s)}}class Py{constructor(s){M(this,"master");M(this,"mainThreadWorkerMap",new Map);this.master=s}updateCamera(){for(const[s,e]of this.mainThreadWorkerMap.entries()){const t=this.master.control.viewContainerManager.getView(s);if(t){const{cameraOpt:i}=t;e.updateCamera({cameraOpt:i,viewId:t.viewId,msgType:D.UpdateCamera,dataType:B.Local})}}}notifyDrawCount(s){const e=this.master.getFullWorkDrawCount(),t=this.mainThreadWorkerMap.get(s);t&&t.clearDrawLayer(e)}clearDrawCount(s){const e=this.mainThreadWorkerMap.get(s);e&&e.clearDrawLayer(1/0)}createMainThreadWorker(s,e){return new zy(s,e,this)}consume(s){var e;for(const t of s.values()){const{msgType:i,viewId:o,layerOpt:n,offscreenCanvasOpt:a,cameraOpt:c}=t;if(i===D.Console){console.log(this);continue}if(i===D.Init){const u=(e=this.master.control.viewContainerManager.getView(o))==null?void 0:e.displayer,h=u==null?void 0:u.subLocalCanvasContainerRef.current;if(u&&h&&n&&a){const d=this.createMainThreadWorker(o,{displayer:u,container:h,layerOpt:n,master:this.master,canvasOpt:a,post:this.post.bind(this)});this.mainThreadWorkerMap.set(o,d),d&&c&&d.setCameraOpt(c)}continue}if(i===D.TasksQueue)continue;const l=this.mainThreadWorkerMap.get(o);l&&(l.on(t),i===D.Destroy&&(l.destroy(),this.mainThreadWorkerMap.delete(o)))}}post(s){const{sp:e}=s;e&&this.master.collectorSyncData(e)}destroy(){for(const s of this.mainThreadWorkerMap.values())s.destroy();this.mainThreadWorkerMap.clear()}active(){}}class zy{constructor(s,e,t){M(this,"viewId");M(this,"opt");M(this,"manager");M(this,"subLocalLayer");M(this,"subLocalWork");M(this,"scene");M(this,"cameraOpt");this.viewId=s,this.opt=e,this.manager=t,this.scene=this.createScene({...e.canvasOpt,container:e.container});const i=Ie.bufferSize.full,o=Ie.bufferSize.sub;this.subLocalLayer=this.createLayer("subLocalLayer",this.scene,{...e.layerOpt,bufferSize:this.viewId===fe?i:o,contextType:"2d"});const n={thread:this};this.subLocalWork=new Ey(n)}createScene(s){return new he.Scene({displayRatio:this.opt.displayer.dpr,depth:!1,desynchronized:!0,...s,contextType:"2d",autoRender:!0,id:this.viewId})}createLayer(s,e,t){const{width:i,height:o}=t,n=`canvas-${s}`,a=e.layer(n,{...t,offscreen:!1}),c=new he.Group({anchor:[.5,.5],pos:[i*.5,o*.5],size:[i,o],name:"viewport",id:s});return a.append(c),c}updateScene(s){this.scene.attr({...s});const{width:e,height:t}=s;this.scene.width=e,this.scene.height=t,this.updateLayer({width:e,height:t})}updateLayer(s){const{width:e,height:t}=s;this.subLocalLayer.parent.setAttribute("width",e),this.subLocalLayer.parent.setAttribute("height",t),this.subLocalLayer.setAttribute("size",[e,t]),this.subLocalLayer.setAttribute("pos",[e*.5,t*.5])}updateDpr(s){this.scene.displayRatio=s}on(s){const{msgType:e,toolsType:t,opt:i,dataType:o,workId:n,workState:a}=s,c=n==null?void 0:n.toString();switch(e){case D.Destroy:this.destroy();break;case D.Clear:this.clearAll();break;case D.UpdateDpr:O.isNumber(s.dpr)&&this.updateDpr(s.dpr);break;case D.UpdateCamera:this.updateCamera(s);break;case D.UpdateTools:if(t&&this.subLocalWork.canUseSubWorkerLayer(t)&&i){const l={toolsType:t,toolsOpt:i};this.subLocalWork.setToolsOpt(l)}break;case D.CreateWork:c&&i&&t&&this.subLocalWork.canUseSubWorkerLayer(t)&&(this.subLocalWork.getToolsOpt()||this.subLocalWork.setToolsOpt({toolsType:t,toolsOpt:i}),this.subLocalWork.setWorkOptions(c,i));break;case D.DrawWork:t&&this.subLocalWork.canUseSubWorkerLayer(t)&&(a===j.Done&&o===B.Local?this.subLocalWork.consumeDrawAll(s):this.subLocalWork.consumeDraw(s));break;case D.RemoveNode:this.subLocalWork.removeNode(s);return}}setCameraOpt(s){this.cameraOpt=s;const{scale:e,centerX:t,centerY:i,width:o,height:n}=s;(o!==this.scene.width||n!==this.scene.height)&&this.updateScene({width:o,height:n}),this.subLocalLayer&&(this.subLocalLayer.setAttribute("scale",[e,e]),this.subLocalLayer.setAttribute("translate",[-t,-i]))}updateCamera(s){const{cameraOpt:e}=s;e&&!O.isEqual(this.cameraOpt,e)&&(this.subLocalWork.workShapes.size&&this.clearAll(),this.setCameraOpt(e))}clearAll(){this.subLocalLayer.children.length&&(this.subLocalLayer.parent.children.forEach(s=>{s.name!=="viewport"&&s.remove()}),Fe(this.subLocalLayer,this.subLocalLayer.parent)),this.subLocalWork.clearAll()}destroy(){this.subLocalLayer.remove(),He(this.subLocalLayer,this.subLocalLayer.parent),this.scene.remove(),this.subLocalWork.destroy()}clearDrawLayer(s){if(s===1/0){this.clearAll();return}const e=this.subLocalLayer.children.filter(t=>t.id&&O.isNumber(parseInt(t.id))&&parseInt(t.id)<s);for(const t of e)t.remove(),He(t,this.subLocalLayer.parent)}}class Ey{constructor(s){M(this,"thread");M(this,"workShapes",new Map);M(this,"tmpOpt");M(this,"syncUnitTime",Ie.syncOpt.interval);M(this,"subWorkerDrawCount",0);this.thread=s.thread}getToolsOpt(){return this.tmpOpt}consumeDrawAll(s){const{workId:e}=s,t=e==null?void 0:e.toString();t&&this.workShapes.get(t)&&(this.subWorkerDrawCount=0,Fe(this.thread.subLocalLayer,this.thread.subLocalLayer.parent),this.clearWorkShapeNodeCache(t))}consumeDraw(s){const{workId:e,toolsType:t,postCount:i}=s;e&&t&&this.canUseSubWorkerLayer(t)&&(this.getWorkShape(e.toString())||this.createLocalWork(s));const o=e==null?void 0:e.toString(),n=o&&this.workShapes.get(o);if(!n)return;n.consume({data:s,drawCount:this.subWorkerDrawCount,isFullWork:!1,isSubWorker:!0}),this.subWorkerDrawCount++;const a=this.thread.manager.master;a.setSubWorkerDrawCount(this.subWorkerDrawCount);const c=Math.max(a.getMaxDrawCount(),this.subWorkerDrawCount);a.setMaxDrawCount(c),O.isNumber(i)&&a.setConsumeCount(i)}removeNode(s){const{workId:e}=s,t=e==null?void 0:e.toString();t&&this.workShapes.has(t)&&(this.thread.subLocalLayer.getElementsByName(t).forEach(o=>{o.remove()}),this.clearWorkShapeNodeCache(t))}createLocalWork(s){const{workId:e,toolsType:t,opt:i}=s,o=e==null?void 0:e.toString();t&&this.canUseSubWorkerLayer(t)&&o&&i&&(this.getToolsOpt()||this.setToolsOpt({toolsType:t,toolsOpt:i}),this.setWorkOptions(o,i))}setWorkOptions(s,e){let t=this.workShapes.get(s);if(!t&&this.tmpOpt){const{toolsType:i}=this.tmpOpt;this.tmpOpt.toolsOpt=e,t=this.createWorkShapeNode({workId:s,toolsType:i,toolsOpt:e}),t&&this.workShapes.set(s,t),this.setToolsOpt(this.tmpOpt)}e!=null&&e.syncUnitTime||(e.syncUnitTime=this.syncUnitTime),t&&t.setWorkOptions(e)}destroy(){this.clearAll()}clearAll(){Fe(this.thread.subLocalLayer,this.thread.subLocalLayer.parent),this.workShapes.clear()}canUseSubWorkerLayer(s){return s===T.Pencil}setToolsOpt(s){var e;this.tmpOpt=s,(e=s.toolsOpt)!=null&&e.syncUnitTime&&(this.syncUnitTime=s.toolsOpt.syncUnitTime)}createWorkShapeNode(s){return js({...s,fullLayer:this.thread.subLocalLayer,drawLayer:this.thread.subLocalLayer})}clearWorkShapeNodeCache(s){this.workShapes.delete(s)}getWorkShape(s){return this.workShapes.get(s)}}const Oy=async(r,s)=>{const{src:e,isgl:t,isCache:i}=r;if(typeof Image=="function"){const o=new Image;return typeof e=="string"&&(o.crossOrigin="anonymous"),new Promise(n=>{o.onload=function(){createImageBitmap(o,{imageOrientation:t?"flipY":"none"}).then(a=>{n(a)})},o.onerror=function(){n(void 0)},o.src=e})}else return fetch(e,{method:"GET",mode:"cors",cache:"default"}).then(o=>o.blob()).then(o=>createImageBitmap(o,{imageOrientation:t?"flipY":"none"}).then(n=>n))};class Ry{constructor(){M(this,"maxLastSyncTime",Ie.syncOpt.interval);M(this,"combineUnitTime",Ie.bezier.combineUnitTime)}setCurrentToolsData(s){this.currentToolsData=s}getCurrentToolsData(){return this.currentToolsData}setCurrentLocalWorkData(s){this.currentLocalWorkData=s}getWorkId(){return this.currentLocalWorkData.workId}get workState(){return this.currentLocalWorkData.workState}}class Wy extends Ry{constructor(e){var n,a,c,l;super();M(this,"isActive",!1);M(this,"currentToolsData");M(this,"currentLocalWorkData");M(this,"control");M(this,"internalMsgEmitter");M(this,"publicMsgEmitter");M(this,"taskBatchData",new Set);M(this,"fullWorker");M(this,"subWorker");M(this,"fullWorkerUrl");M(this,"subWorkerUrl");M(this,"methodBuilder");M(this,"zIndexNodeMethod");M(this,"subWorkerDrawCount",0);M(this,"fullWorkerDrawCount",0);M(this,"maxDrawCount",0);M(this,"_consumeCount",0);M(this,"_postCount",0);M(this,"reRenders",new Map);M(this,"localWorkViewId");M(this,"localPointsBatchData",new Map);M(this,"tasksqueue",new Map);M(this,"useTasksqueue",!1);M(this,"useTasksClockId");M(this,"mainTasksqueueCount");M(this,"workerTasksqueueCount");M(this,"snapshotMap",new Map);M(this,"boundingRectMap",new Map);M(this,"clearAllResolveMap",new Map);M(this,"delayWorkStateToDoneResolve");M(this,"animationId");M(this,"tmpImageConfigMap",new Map);M(this,"mainThread");M(this,"willSelectorWorkId");M(this,"isLockSentEventCursor",!1);M(this,"subMainThreadWorker");M(this,"getVNodeInfoResolveMap",new Map);M(this,"isLocalWorkActive",!1);const{control:t,internalMsgEmitter:i,publicMsgEmitter:o}=e;this.control=t,this.maxLastSyncTime=((a=(n=this.control.pluginOptions)==null?void 0:n.syncOpt)==null?void 0:a.interval)||this.maxLastSyncTime,this.combineUnitTime=((l=(c=this.control.pluginOptions)==null?void 0:c.bezier)==null?void 0:l.combineUnitTime)||this.combineUnitTime,this.fullWorkerUrl=this.control.pluginOptions.cdn.fullWorkerUrl||"",this.subWorkerUrl=this.control.pluginOptions.cdn.subWorkerUrl||"",this.internalMsgEmitter=i,this.publicMsgEmitter=o,this.currentLocalWorkData={workState:j.Pending}}destroy(){var e,t,i;(e=this.methodBuilder)==null||e.destroy(),this.unWritable(),this.taskBatchData.clear(),this.tasksqueue.clear(),this.tmpImageConfigMap.clear(),this.localPointsBatchData.clear(),this.isActive=!1,this.clearAllResolveMap.clear(),this.snapshotMap.clear(),this.boundingRectMap.clear(),(t=this.fullWorker)==null||t.terminate(),(i=this.subWorker)==null||i.terminate()}get consumeCount(){return this._consumeCount}set consumeCount(e){this._consumeCount=e}get postCount(){return this._postCount}set postCount(e){this._postCount=e}get viewContainerManager(){return this.control.viewContainerManager}get collector(){return this.control.collector}get isRunSubWork(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.PencilEraser||e===T.BitMapEraser||e===T.LaserPen||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Selector}get isCanDrawWork(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.LaserPen||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Triangle||e===T.Rhombus||e===T.BitMapEraser||e===T.PencilEraser}get isUseZIndex(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Text||e===T.Image}get isCanRecordUndoRedo(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.Eraser||e===T.PencilEraser||e===T.BitMapEraser||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Text||e===T.Image}get isCanSentCursor(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.Text||e===T.LaserPen||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Triangle||e===T.Rhombus||e===T.Eraser||e===T.PencilEraser||e===T.BitMapEraser||e===T.Selector}get isPostCountType(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Triangle||e===T.Rhombus||e===T.Eraser||e===T.PencilEraser||e===T.BitMapEraser||e===T.Selector}get isCanPostDraw(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.PencilEraser||e===T.BitMapEraser}get isCanStartEventConsum(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Selector||e===T.Eraser||e===T.PencilEraser||e===T.BitMapEraser}async init(){this.destroy(),await this.on(),this.internalMsgEmitterListener(),this.isActive=!0}async useMainThread(){console.info("no OffscreenCanvas");const{MainThreadManagerImpl:e}=await Promise.resolve().then(()=>require("./index-BqLItWo1.js"));this.mainThread=new e(this)}async on(){if(!this.control.hasOffscreenCanvas()){await this.useMainThread();return}if(!this.fullWorkerUrl||!this.subWorkerUrl){console.error("no worker url config");return}this.fullWorker=new Worker(this.fullWorkerUrl,{type:"classic"}),this.subWorker=new Worker(this.subWorkerUrl,{type:"classic"}),this.subMainThreadWorker=new Py(this),this.fullWorker.onmessage=e=>{var t,i;if(e.data){const{render:o,sp:n,fullWorkerDrawCount:a,workerTasksqueueCount:c,viewId:l,consumeCount:u}=e.data;u&&(this.consumeCount=u),this.isBusy&&c&&this.setWorkerTasksqueueCount(c),n!=null&&n.length&&this.collectorSyncData(n);const h=(o==null?void 0:o.length)&&o||[];if(a&&l){if(this.fullWorkerDrawCount=a,this.fullWorkerDrawCount<1/0){const d=Math.max(this.maxDrawCount,this.fullWorkerDrawCount);this.setMaxDrawCount(d),this.control.priority==="ui"?(t=this.subMainThreadWorker)==null||t.notifyDrawCount(l):this.clearReRenders(this.fullWorkerDrawCount)}else this.setMaxDrawCount(0),this.control.priority==="ui"?(i=this.subMainThreadWorker)==null||i.clearDrawCount(l):this.clearReRenders(1/0);if(this.reRenders.size)for(const d of this.reRenders.values())h.push(...d)}h.length&&this.viewContainerManager.render(h)}},this.subWorker.onmessage=e=>{if(e.data){const{render:t,sp:i,subWorkerDrawCount:o,consumeCount:n}=e.data;n&&(this.consumeCount=n),i!=null&&i.length&&this.collectorSyncData(i);const a=(t==null?void 0:t.length)&&t||[];if(this.control.priority==="cpu"&&O.isNumber(o)){if(this.subWorkerDrawCount=o,this.fullWorkerDrawCount<1/0){const c=Math.max(this.maxDrawCount,this.subWorkerDrawCount);this.setMaxDrawCount(c)}if(t!=null&&t.length)if(this.subWorkerDrawCount>this.fullWorkerDrawCount){const c=[];for(const l of t)l.imageBitmap&&(l.isUnClose=!0,c.push(l));this.reRenders.set(this.subWorkerDrawCount,c)}else this.reRenders.size&&this.clearReRenders(this.subWorkerDrawCount)}a.length&&this.viewContainerManager.render(a)}}}clearReRenders(e=1/0){for(const t of this.reRenders.keys())if(O.isNumber(Number(t))&&Number(t)<=e){const i=this.reRenders.get(Number(t));i==null||i.forEach(o=>{var n;(n=o.imageBitmap)==null||n.close()}),this.reRenders.delete(t)}}get isBusy(){return this.getTasksqueueState()===j.Doing}getLockSentEventCursor(){return this.isLockSentEventCursor}setLockSentEventCursor(e){this.isLockSentEventCursor=e}getTasksqueueState(){return this.useTasksqueue&&j.Doing||j.Done}setMaxDrawCount(e){this.maxDrawCount=e}getFullWorkDrawCount(){return this.fullWorkerDrawCount}getMaxDrawCount(){return this.maxDrawCount}setSubWorkerDrawCount(e){this.subWorkerDrawCount=e}setConsumeCount(e){this.consumeCount=e}getConsumeCount(){return this.consumeCount}setWorkerTasksqueueCount(e){const t=Math.max(this.workerTasksqueueCount||0,e);this.workerTasksqueueCount=t}collectorSyncData(e){var i,o,n,a;let t=!1;for(const c of e){const{type:l,selectIds:u,opt:h,selectRect:d,strokeColor:g,fillColor:p,willSyncService:f,isSync:m,imageBitmap:w,canvasHeight:I,canvasWidth:N,rect:C,op:S,canTextEdit:v,points:x,selectorColor:L,canRotate:b,scaleType:P,textOpt:A,toolsType:E,workId:R,viewId:z,dataType:Z,canLock:ee,isLocked:F,shapeOpt:$,toolsTypes:te,thickness:le,strokeType:ie,useStroke:_,isgl:J,imageSrc:de,isSubWorker:Be}=c;if(!z)return;const ke=c.scenePath||this.viewContainerManager.getCurScenePath(z);switch(l){case D.Select:{const q=u!=null&&u.length?{...d,selectIds:u,canvasHeight:I,canvasWidth:N,points:x}:void 0;q&&(h!=null&&h.strokeColor)&&(q.selectorColor=h.strokeColor),q&&L&&(q.selectorColor=L),q&&g&&(q.strokeColor=g),q&&(h!=null&&h.fillColor)&&(q.fillColor=h.fillColor),q&&p&&(q.fillColor=p),q&&O.isBoolean(b)&&(q.canRotate=b),q&&P&&(q.scaleType=P),q&&v&&(q.canTextEdit=v),q&&A&&(q.textOpt=A),q&&O.isBoolean(ee)&&(q.canLock=ee),q&&O.isBoolean(F)&&(q.isLocked=F),q&&$&&(q.shapeOpt=$),q&&te&&(q.toolsTypes=te),q&&le&&(q.thickness=le),q&&ie&&(q.strokeType=ie),q&&O.isBoolean(_)&&(q.useStroke=_),z&&this.viewContainerManager.showFloatBar(z,!!q,q),f&&((i=this.collector)==null||i.dispatch({type:l,selectIds:u,opt:h,isSync:m,viewId:z,scenePath:ke}));break}case D.Snapshot:if(w&&ke){const q=this.snapshotMap.get(ke);q&&q(w)}break;case D.BoundingBox:if(C&&ke){const q=this.boundingRectMap.get(ke);q&&q(C)}break;case D.Cursor:S&&this.control.cursor.collectServiceCursor({...c});break;case D.Clear:if(z){this.viewContainerManager.showFloatBar(z,!1);const q=(o=this.clearAllResolveMap.get(z))==null?void 0:o.resolve;q&&q(z)}break;case D.TextUpdate:if(E===T.Text&&R&&z){const q=this.viewContainerManager.transformToOriginPoint((h==null?void 0:h.boxPoint)||[0,0],z),Le=(h==null?void 0:h.boxSize)||[0,0],Ue=(n=this.viewContainerManager.getView(z))==null?void 0:n.cameraOpt;h?this.control.textEditorManager.updateTextForWorker({x:q[0],y:q[1],w:Le[0],h:Le[1],scale:(Ue==null?void 0:Ue.scale)||1,workId:R,opt:h,dataType:Z,viewId:z,canSync:f||!1,canWorker:!1}):this.control.textEditorManager.delete(R,f||!1,!1)}break;case D.GetTextActive:E===T.Text&&R&&z&&this.control.textEditorManager.updateTextForWorker({workId:R,isActive:!0,viewId:z,dataType:B.Local,canWorker:!1,canSync:!0},Date.now());break;case D.GetImageBitMap:de&&z&&R&&Oy({src:de,isgl:J}).then(q=>{var Ue;const Le=new Set;if(Le.add({msgType:D.GetImageBitMap,dataType:B.Local,workId:R,viewId:z,imageSrc:de,isSubWorker:Be,imageBitmap:q}),!this.control.hasOffscreenCanvas())(Ue=this.mainThread)==null||Ue.consume(Le);else{const st=Be?this.subWorker:this.fullWorker;q?st.postMessage(Le,[q]):st.postMessage(Le)}});break;case D.GetVNodeInfo:if(R){const q=R.toString(),Le=(a=this.getVNodeInfoResolveMap.get(q))==null?void 0:a.resolve,Ue={...c,uuid:q};Le&&Le(Ue)}break;default:t=!0;break}}t&&this.collectorAsyncData(e)}collectorAsyncData(e){var t,i,o,n;for(const a of e){const{type:c,op:l,workId:u,index:h,removeIds:d,ops:g,opt:p,updateNodeOpt:f,toolsType:m,isSync:w,viewId:I,isLockSentEventCursor:N,nextTasks:C}=a;if(!I){console.error("collectorAsyncData",a);return}const S=a.scenePath||this.viewContainerManager.getCurScenePath(I);switch(c){case D.None:{N&&ht(()=>{this.setLockSentEventCursor(!1)},this.maxLastSyncTime);break}case D.DrawWork:{(t=this.collector)==null||t.dispatch({type:c,op:l,opt:p,toolsType:m,workId:u,index:h,isSync:w,viewId:I,scenePath:S,updateNodeOpt:f});break}case D.FullWork:{(i=this.collector)==null||i.dispatch({type:c,ops:g,workId:u,updateNodeOpt:f,opt:p,toolsType:m,isSync:w,viewId:I,scenePath:S}),this.willSelectorWorkId&&u&&u.toString()===this.willSelectorWorkId&&this.control.runEffectWork(()=>{this.setShapeSelectorByWorkId(this.willSelectorWorkId,I),this.willSelectorWorkId=void 0});break}case D.UpdateNode:{(o=this.collector)==null||o.dispatch({type:c,updateNodeOpt:f,workId:u,opt:p,ops:g,op:l,isSync:w,viewId:I,scenePath:S});break}case D.RemoveNode:{d&&this.control.textEditorManager.deleteBatch(d,!1,!1),(n=this.collector)==null||n.dispatch({type:c,removeIds:d,isSync:w,viewId:I,scenePath:S}),this.willSelectorWorkId&&(d!=null&&d.includes(this.willSelectorWorkId))&&(this.willSelectorWorkId=void 0);break}}C&&this.collectorAsyncData(C)}}async onLocalEventEnd(e,t){var l;const i=this.viewContainerManager.getView(t);if(!i)return;const{focusScenePath:o,cameraOpt:n}=i,a=this.viewContainerManager.transformToScenePoint(e,t),c=[];for(const u of this.localPointsBatchData.keys())if(((l=this.currentToolsData)==null?void 0:l.toolsType)===T.Text){const h=this.getLocalPointInfo(u),d=h==null?void 0:h.state;if(d&&d===j.Start){const g=this.currentLocalWorkData.toolsOpt;g.workState=j.Doing,g.boxPoint=a,g.boxSize=[g.fontSize,g.fontSize],this.control.textEditorManager.checkEmptyTextBlur(),this.control.textEditorManager.createTextForMasterController({workId:Date.now().toString(),x:e[0],y:e[1],scale:(n==null?void 0:n.scale)||1,opt:g,type:rt.Text,isActive:!0,viewId:t,scenePath:o},Date.now())}this.deleteLocalPoint(u);continue}else this.pushLocalPoint(u,a,j.Done,t),c.push(u);if(c.length){try{if(await new Promise(h=>{setTimeout(async()=>{c.forEach(d=>{this.setLocalPointIsFullWork(d)}),this.delayWorkStateToDoneResolve=h,this.consume()},0)})&&c[0]){const h=c[0];c.forEach(d=>{this.deleteLocalPoint(d)}),this.willSelectorWorkId=h.toString()}}catch(u){console.log("error",u)}this.delayWorkStateToDoneResolve=void 0,c.length=0}}onLocalEventDoing(e,t){var o;if(((o=this.currentToolsData)==null?void 0:o.toolsType)===T.Text)return;this.currentLocalWorkData.workState===j.Start&&this.setCurrentLocalWorkData({...this.currentLocalWorkData,workState:j.Doing});let i=!1;for(const[n,{state:a}]of this.localPointsBatchData.entries())if(this.isAbled()&&a!==j.Pending){const c=this.viewContainerManager.transformToScenePoint(e,t);this.pushLocalPoint(n,c,a===j.Start?j.Doing:a,t),i=!0}if(i){this.runAnimation();return}}onLocalEventStart(e,t){var c,l,u;this.viewContainerManager.focuedViewId!==t&&this.viewContainerManager.setFocuedViewId(t),this.isCanDrawWork&&this.control.room&&!this.control.room.disableDeviceInputs&&(this.control.room.disableDeviceInputs=!0);const i=(c=this.currentToolsData)==null?void 0:c.toolsType,o=i===T.Selector?G:Date.now(),n=this.setZIndex(t);this.setCurrentLocalWorkData({workState:j.Start,toolsOpt:n,viewId:t});const a=this.viewContainerManager.transformToScenePoint(e,t);if(this.pushLocalPoint(o,a,j.Start,t,n),i!==T.Text){if(this.control.textEditorManager.checkEmptyTextBlur(),this.isCanRecordUndoRedo&&this.internalMsgEmitter.emit("addUndoTicker",o,t),o&&n&&i&&this.isCanStartEventConsum&&this.prepareOnceWork({workId:o,toolsOpt:n,viewId:t},i),this.consumeCount=0,this.postCount=0,this.maxDrawCount=0,this.fullWorkerDrawCount=0,this.subWorkerDrawCount=0,this.clearReRenders(1/0),(l=this.subMainThreadWorker)==null||l.clearDrawCount(t),this.isCanDrawWork){const h=this.viewContainerManager.getCurScenePath(t);h&&((u=this.collector)!=null&&u.hasSelector(t,h))&&this.blurSelector(t,h)}this.consume()}}setLocalPointIsFullWork(e){const t=this.getLocalPointInfo(e);t&&(t.isFullWork=!0,this.localPointsBatchData.set(e,t))}pushLocalPoint(e,t,i,o,n){let a=this.getLocalPointInfo(e);i===j.Start?a={state:j.Start,points:t,opt:n||this.currentLocalWorkData.toolsOpt,isFullWork:!1,viewId:o}:a&&(a.state=i,a.points.push(t[0],t[1])),a&&this.localPointsBatchData.set(e,a)}deleteLocalPoint(e){this.localPointsBatchData.delete(e)}getLocalPointInfo(e){return this.localPointsBatchData.get(e)}getLocalPointsInfo(){return this.localPointsBatchData}correctStorage(e,t,i){var c;const o=new Map,n=[];Object.keys(e).forEach(l=>{var h,d;const u=(d=(h=e[l])==null?void 0:h.opt)==null?void 0:d.zIndex;O.isNumber(u)&&n.push([l,u])});const a=n.length&&((c=this.zIndexNodeMethod)==null?void 0:c.correct(n))||[];this.zIndexNodeMethod&&a.length&&(this.zIndexNodeMethod.setMinZIndex(a[0][1]||0,t),this.zIndexNodeMethod.setMaxZIndex(a[a.length-1][1]||0,t));for(const[l,u]of a){if(!e[l])continue;const h=e[l];h.opt&&O.isNumber(h.opt.zIndex)&&h.opt.zIndex!==u&&(h.opt.zIndex=u,o.set(l,h))}return o.size&&o.forEach((l,u)=>{var h;(h=this.collector)==null||h.updateValue(u,l,{viewId:t,scenePath:i,isSync:!0}),e[u]=l}),e}async originalEventLintener(e,t,i){var c,l,u;if(!this.isAbled())return;const o=(c=this.collector)==null?void 0:c.uid,n=this.viewContainerManager.getCurScenePath(i);if(o&&!this.control.renderControl.isWritable)return;const a=((l=this.currentToolsData)==null?void 0:l.toolsType)===T.Selector;switch((u=this.currentToolsData)==null?void 0:u.toolsType){case T.Eraser:case T.PencilEraser:case T.BitMapEraser:{if(o&&!this.control.renderControl.isClearAble({uid:o,viewId:i,scenePath:n}))return;break}default:{if(o&&!this.control.renderControl.isRenderAble({uid:o,viewId:i,scenePath:n}))return;break}}switch(ht(()=>{this.control.pluginManager.dispatchPluginEvent("localEvent",i,e,t)},fi),e){case j.Start:this.isLocalWorkActive=!0,this.setLocalWorkViewId(i),i&&this.onLocalEventStart(t,i),a&&this.viewContainerManager.showFloatBarBtn(i,!1);break;case j.Doing:i&&i===this.getLocalWorkViewId()&&this.onLocalEventDoing(t,i);break;case j.Done:i&&i===this.getLocalWorkViewId()&&(this.setCurrentLocalWorkData({...this.currentLocalWorkData,workState:j.Done}),await this.onLocalEventEnd(t,i),setTimeout(()=>{this.isLocalWorkActive=!1,this.setCurrentLocalWorkData({workState:j.Pending}),a&&this.viewContainerManager.showFloatBarBtn(i,!0)},0));break}this.isLocalWorkActive&&this.viewContainerManager.focuedViewId===i&&this.publicMsgEmitter.emit("workState",e,i)}getLocalWorkViewId(){return this.localWorkViewId}setLocalWorkViewId(e){this.localWorkViewId=e}setCurrentToolsData(e){var o,n,a;const t=e.toolsType,i=((o=this.currentToolsData)==null?void 0:o.toolsType)!==e.toolsType;if(super.setCurrentToolsData(e),i){const c=(n=this.viewContainerManager)==null?void 0:n.getAllViews();for(const l of c)if(l){const{id:u,focusScenePath:h}=l;i&&u&&h&&((a=this.collector)!=null&&a.hasSelector(u,h)&&this.blurSelector(u,h),this.control.textEditorManager.checkEmptyTextBlur())}this.taskBatchData.add({msgType:D.UpdateTools,dataType:B.Local,toolsType:t,opt:{...e.toolsOpt,syncUnitTime:this.maxLastSyncTime},combineUnitTime:this.combineUnitTime,isRunSubWork:this.isRunSubWork,viewId:cs}),this.runAnimation()}}prepareOnceWork(e,t){const{workId:i,toolsOpt:o,viewId:n}=e,a={msgType:D.CreateWork,dataType:B.Local,viewId:n,toolsType:t};this.queryTaskBatchData(a).forEach(c=>{this.taskBatchData.delete(c)}),this.taskBatchData.add({...a,workId:i,opt:{...o,syncUnitTime:this.maxLastSyncTime},dataType:B.Local,isRunSubWork:this.isRunSubWork}),this.runAnimation()}createViewWorker(e,t){const{offscreenCanvasOpt:i,layerOpt:o,dpr:n,cameraOpt:a}=t;this.taskBatchData.add({msgType:D.Init,dataType:B.Local,viewId:e,offscreenCanvasOpt:i,layerOpt:o,dpr:n,cameraOpt:a,isRunSubWork:!0,isSafari:navigator.userAgent.indexOf("Safari")!==-1&&navigator.userAgent.indexOf("Chrome")===-1,combineUnitTime:this.combineUnitTime,syncUnitTime:this.maxLastSyncTime}),this.isBusy&&this.destroyTaskQueue(),this.consume()}destroyViewWorker(e,t=!1){var i;this.getLocalWorkViewId()===e&&this.setLocalWorkViewId(void 0),this.zIndexNodeMethod&&this.zIndexNodeMethod.clearZIndex(e),this.taskBatchData.add({msgType:D.Destroy,dataType:B.Local,viewId:e,isRunSubWork:!0}),this.consume(),t||(i=this.collector)==null||i.dispatch({type:D.Clear,viewId:e}),this.control.renderControl.destoryByViewId(e,t)}onServiceDerive(e,t){var g,p,f,m,w,I,N;const{newValue:i,oldValue:o,viewId:n,scenePath:a}=t,c=O.cloneDeep(i)||{},l=e;let u=c.type;if(!i&&o){if(l&&((g=this.collector)==null?void 0:g.getLocalId(l))===G){this.collector.isOwn(l)?this.blurSelector(n,a):this.blurSelector(n,a,l);return}if(u=D.RemoveNode,o.toolsType===T.LaserPen)return}const h=(p=this.viewContainerManager.getView(n))==null?void 0:p.focusScenePath;if(h&&h!==a)return;if((f=this.collector)!=null&&f.isSelector(e)){const C=(m=this.collector)==null?void 0:m.getUidFromKey(e);if(C&&!this.control.roomMember.isOnLine(C))return}if(u&&l){if(!this.control.renderControl.isFilterAble({viewId:n,elementId:e,scenePath:a},u))return;const C=c;if(C.workId=(w=this.collector)!=null&&w.isOwn(l)?(I=this.collector)==null?void 0:I.getLocalId(l):l,C.msgType=u,C.toolsType===T.LaserPen&&(C.isRunSubWork=!0),C.dataType=B.Service,C.viewId=n,C.scenePath=a,C.selectIds&&(C.selectIds=C.selectIds.map(S=>{var v,x;return(v=this.collector)!=null&&v.isOwn(S)?(x=this.collector)==null?void 0:x.getLocalId(S):S})),C&&C.toolsType===T.Text||(o==null?void 0:o.toolsType)===T.Text){this.control.textEditorManager.onServiceDerive(C);return}this.taskBatchData.add(C)}this.runAnimation();const d=t.newValue&&((N=t.newValue.opt)==null?void 0:N.zIndex);if(this.zIndexNodeMethod&&O.isNumber(d)){const C=this.zIndexNodeMethod.getMinZIndex(n);this.zIndexNodeMethod.getMaxZIndex(n)<d&&this.zIndexNodeMethod.setMaxZIndex(d,n),C>d&&this.zIndexNodeMethod.setMinZIndex(d,n)}}pullServiceData(e,t,i={isAsync:!1,useAnimation:!1}){var c,l,u,h,d,g,p;let o=(c=this.collector)==null?void 0:c.getStorageData(e,t);const{isAsync:n,useAnimation:a}=i;if(o){this.control.renderControl.isWritable&&(o=this.correctStorage(o,e,t));const f=Object.keys(o);for(const m of f){if((l=this.collector)!=null&&l.isSelector(m)){const I=(u=this.collector)==null?void 0:u.getUidFromKey(m);if(I&&!this.control.roomMember.isOnLine(I))continue}const w=(h=o[m])==null?void 0:h.type;if(w&&m){if(!this.control.renderControl.isFilterAble({viewId:e,elementId:m,scenePath:t},w))continue;const I=o[m];if(I.workId=(d=this.collector)!=null&&d.isOwn(m)?(g=this.collector)==null?void 0:g.getLocalId(m):m,I.msgType=w,I.dataType=B.Service,I.viewId=e,I.scenePath=t,I.useAnimation=I.ops?!!a:((p=I.updateNodeOpt)==null?void 0:p.useAnimation)||!1,I.selectIds&&(I.selectIds=I.selectIds.map(N=>{var C,S;return(C=this.collector)!=null&&C.isOwn(N)?(S=this.collector)==null?void 0:S.getLocalId(N):N})),I.toolsType===T.Text){this.control.textEditorManager.onServiceDerive(I);continue}this.taskBatchData.add(I)}this.internalMsgEmitter.emit("excludeIds",f,e)}n?this.consume():this.runAnimation()}}runAnimation(){!this.animationId&&!this.isBusy&&(this.animationId=requestAnimationFrame(this.consume.bind(this)))}consume(){var t;this.animationId=void 0;const{viewId:e}=this.currentLocalWorkData;if(this.tasksqueue.size){const i=this.consumeQueue(),o=!!i.size;if(this.taskBatchData.size)for(const n of this.taskBatchData.values())n.dataType===B.Service&&(i.add(n),this.taskBatchData.delete(n));i.size?(this.post(i),o&&this.tasksqueue.clear()):this.tasksqueue.size&&(this.animationId=requestAnimationFrame(this.consume.bind(this)));return}if(this.isAbled()&&this.localPointsBatchData.size&&e)for(const[i,{state:o,isFullWork:n,points:a,opt:c}]of this.localPointsBatchData.entries()){if(o===j.Done&&!n||o===j.Start&&!this.isCanStartEventConsum)continue;const l=a.map(u=>u);if(l.length){if(this.isPostCountType&&o===j.Doing){if(this.postCount>this.consumeCount)continue;this.postCount++}this.delayWorkStateToDoneResolve&&o===j.Done&&(this.delayWorkStateToDoneResolve(!0),this.setLockSentEventCursor(!0)),this.taskBatchData.add({op:l,workState:o,workId:i,dataType:B.Local,msgType:D.DrawWork,isRunSubWork:this.isRunSubWork,toolsType:(t=this.currentToolsData)==null?void 0:t.toolsType,viewId:e,scenePath:e&&this.viewContainerManager.getCurScenePath(e),opt:c,isLockSentEventCursor:this.getLockSentEventCursor(),syncUnitTime:this.maxLastSyncTime,disableEraseImage:this.control.disableEraseImage,disableEraseText:this.control.disableEraseText,postCount:this.isPostCountType&&this.postCount||void 0,fullWorkerDrawCount:this.isCanPostDraw&&this.fullWorkerDrawCount||void 0}),a.length=0}}this.taskBatchData.size&&(this.post(this.taskBatchData),this.taskBatchData.clear()),this.taskBatchData.size&&(this.animationId=requestAnimationFrame(this.consume.bind(this)))}unWritable(){this.setCurrentLocalWorkData({workState:j.Unwritable}),this.setLockSentEventCursor(!0)}abled(){this.setCurrentLocalWorkData({workState:j.Pending}),this.setLockSentEventCursor(!1)}isAbled(){return this.currentLocalWorkData.workState!==j.Unwritable}post(e){var i;if(!this.control.hasOffscreenCanvas()){if(!this.mainThread){let o=[];o=O.cloneDeep([...e]),setTimeout(()=>{for(const n of o)this.taskBatchData.add(n)},0);return}this.mainThread.consume(e);return}this.fullWorker.postMessage(e);const t=new Set;for(const o of e.values()){const n=o.msgType;(n===D.Init||n===D.Clear||n===D.Destroy||n===D.UpdateCamera||o.isRunSubWork)&&t.add(o)}t.size&&(this.subWorker.postMessage(t),this.control.priority==="ui"&&((i=this.subMainThreadWorker)==null||i.consume(t)))}updateNode(e,t,i,o){this.taskBatchData.add({msgType:D.UpdateNode,workId:e,updateNodeOpt:t,viewId:i,scenePath:o,dataType:B.Local}),this.runAnimation()}destroyTaskQueue(){this.useTasksqueue=!1,this.useTasksClockId&&(clearTimeout(this.useTasksClockId),this.useTasksClockId=void 0),this.mainTasksqueueCount=void 0,this.workerTasksqueueCount=void 0}updateDpr(e,t){this.queryTaskBatchData({msgType:D.UpdateDpr,dataType:B.Local,viewId:e}).forEach(i=>{this.taskBatchData.delete(i)}),this.taskBatchData.add({dataType:B.Local,msgType:D.UpdateDpr,viewId:e,dpr:t,isRunSubWork:!0}),this.runAnimation()}updateCamera(e,t){var i;this.useTasksqueue||((i=this.methodBuilder)==null||i.pause(),this.blurCursor(e),this.checkDrawingWork(e),this.useTasksqueue=!0,this.mainTasksqueueCount=1,this.workerTasksqueueCount=1),this.useTasksqueue&&(this.tasksqueue.set(e,{msgType:D.UpdateCamera,dataType:B.Local,cameraOpt:{...t,width:t.width,height:t.height},scenePath:this.viewContainerManager.getCurScenePath(e),isRunSubWork:!0,viewId:e}),this.consume(),this.useTasksClockId&&clearTimeout(this.useTasksClockId),this.updateCameraDone())}updateCameraDone(){this.useTasksClockId=setTimeout(()=>{var e,t;this.useTasksClockId=void 0,this.mainTasksqueueCount===this.workerTasksqueueCount?(this.tasksqueue.size&&this.consume(),this.useTasksqueue=!1,this.mainTasksqueueCount=void 0,this.workerTasksqueueCount=void 0,this.control.priority==="ui"&&((e=this.subMainThreadWorker)==null||e.updateCamera()),(t=this.methodBuilder)==null||t.recover(),this.runAnimation()):this.updateCameraDone()},this.maxLastSyncTime)}consumeQueue(){const e=new Set;let t=!this.isBusy;if(this.isBusy&&this.mainTasksqueueCount&&this.workerTasksqueueCount&&this.mainTasksqueueCount<=this.workerTasksqueueCount&&(t=!0),t){this.mainTasksqueueCount&&this.workerTasksqueueCount&&this.mainTasksqueueCount++,e.add({msgType:D.TasksQueue,dataType:B.Local,isRunSubWork:!0,mainTasksqueueCount:this.mainTasksqueueCount,tasksqueue:this.tasksqueue,viewId:""});for(const[i,o]of this.tasksqueue.entries())o.cameraOpt&&this.control.textEditorManager.onCameraChange(o.cameraOpt,i)}return e}async clearViewScenePath(e,t,i){var n,a;const o=this.viewContainerManager.getCurScenePath(e);if(i){const c=(n=this.collector)==null?void 0:n.uid;if(c&&!this.control.renderControl.isClearAble({uid:c,viewId:e,scenePath:o}))return}this.control.textEditorManager.clear(e,t),this.queryTaskBatchData({msgType:D.Clear,dataType:B.Local,viewId:e}).forEach(c=>{this.taskBatchData.delete(c)}),this.taskBatchData.add({dataType:B.Local,msgType:D.Clear,viewId:e}),this.runAnimation(),t||(this.control.renderControl.isUsePageAuth(e)&&o?this.control.renderControl.clearRenderPage(e,o):(a=this.collector)==null||a.dispatch({type:D.Clear,viewId:e,scenePath:o})),this.zIndexNodeMethod&&this.zIndexNodeMethod.clearZIndex(e);for(const[c,l]of this.localPointsBatchData.entries())l.viewId===e&&this.localPointsBatchData.delete(c);await new Promise(c=>{const l=this.clearAllResolveMap.get(e)||{resolve:void 0,timer:void 0};l.timer&&clearTimeout(l.timer),l.resolve=c,l.timer=setTimeout(()=>{const u=this.clearAllResolveMap.get(e);u!=null&&u.resolve&&u.resolve(e)},this.maxLastSyncTime),this.clearAllResolveMap.set(e,l)}).then(c=>{this.clearAllResolveMap.delete(c)})}internalMsgEmitterListener(){var e;this.methodBuilder=new ae([V.CopyNode,V.SetColorNode,V.DeleteNode,V.RotateNode,V.ScaleNode,V.TranslateNode,V.ZIndexNode,V.SetFontStyle,V.SetPoint,V.SetLock,V.SetShapeOpt]).registerForMainEngine(ne.MainEngine,this.control),this.zIndexNodeMethod=(e=this.methodBuilder)==null?void 0:e.getBuilder(V.ZIndexNode)}setZIndex(e){const t=this.currentToolsData&&O.cloneDeep(this.currentToolsData.toolsOpt);return t&&this.zIndexNodeMethod&&this.isUseZIndex&&(this.zIndexNodeMethod.addMaxLayer(e),t.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),t}checkDrawingWork(e){var o,n,a;let t=!1;const i=[];for(const[c,{state:l,viewId:u,points:h,opt:d}]of this.localPointsBatchData.entries())if(e===u&&l===j.Start||l===j.Doing){if(l===j.Doing&&this.isCanDrawWork){Number(c)&&Number(c)+60>Date.now()&&(i.push(c.toString()),this.taskBatchData.add({msgType:D.RemoveNode,workId:c,viewId:u,dataType:B.Local,isRunSubWork:!0}));const g=h.map(p=>p);this.taskBatchData.add({op:g,workState:j.Done,workId:c,dataType:B.Local,msgType:D.DrawWork,isRunSubWork:this.isRunSubWork,toolsType:(o=this.currentToolsData)==null?void 0:o.toolsType,viewId:u,opt:d,scenePath:u&&this.viewContainerManager.getCurScenePath(u)}),t=!0}this.deleteLocalPoint(c)}if((t||i.length)&&(this.consume(),i.length)){const c=(n=this.viewContainerManager.getView(e))==null?void 0:n.focusScenePath;(a=this.collector)==null||a.dispatch({type:D.RemoveNode,removeIds:i,viewId:e,scenePath:c})}}removeDrawingWork(e){var i,o;const t=[];for(const[n,{state:a,viewId:c}]of this.localPointsBatchData.entries())(e===c&&a===j.Start||a===j.Doing)&&(this.deleteLocalPoint(n),a===j.Doing&&this.isCanDrawWork&&(t.push(n.toString()),this.taskBatchData.add({msgType:D.RemoveNode,workId:n,viewId:c,dataType:B.Local,isRunSubWork:!0})));if(t.length){this.consume();const n=(i=this.viewContainerManager.getView(e))==null?void 0:i.focusScenePath;(o=this.collector)==null||o.dispatch({type:D.RemoveNode,removeIds:t,viewId:e,scenePath:n})}}removeNodes(e,t){var o,n;const i=(o=this.viewContainerManager.getView(e))==null?void 0:o.focusScenePath;if(i&&t.length){for(const a of t)this.taskBatchData.add({msgType:D.RemoveNode,workId:a,viewId:e,dataType:B.Local,isRunSubWork:!1});this.consume(),(n=this.collector)==null||n.dispatch({type:D.RemoveNode,removeIds:t,viewId:e,scenePath:i})}}hoverCursor(e,t){var i;if(((i=this.currentToolsData)==null?void 0:i.toolsType)===T.Selector&&!this.isBusy){const o=this.viewContainerManager.getView(t);if(o&&o.displayer&&o.displayer.vDom){const c=o.displayer.vDom.state.floatBarData;if(c){const{x:l,y:u,w:h,h:d}=c;if(wn(e,{x:l,y:u,w:h,h:d}))return}}const n=this.viewContainerManager.transformToScenePoint(e,t),a={msgType:D.CursorHover,dataType:B.Local,point:n,toolsType:this.currentToolsData.toolsType,opt:this.currentToolsData.toolsOpt,isRunSubWork:!1,viewId:t};this.queryTaskBatchData({msgType:D.CursorHover,dataType:B.Local,toolsType:this.currentToolsData.toolsType,viewId:t}).forEach(c=>{this.taskBatchData.delete(c)}),this.taskBatchData.add(a),this.runAnimation()}}blurCursor(e){var i;if(((i=this.currentToolsData)==null?void 0:i.toolsType)!==T.Selector)return;const t={msgType:D.CursorBlur,dataType:B.Local,isRunSubWork:!1,viewId:e};this.queryTaskBatchData({msgType:D.CursorHover,dataType:B.Local,viewId:e}).forEach(o=>{this.taskBatchData.delete(o)}),this.taskBatchData.add(t),this.consume()}sendCursorEvent(e,t){var c,l,u;if(!this.currentLocalWorkData||this.currentLocalWorkData.workState===j.Unwritable||this.isBusy)return;const i=(c=this.currentToolsData)==null?void 0:c.toolsType;if(!this.useTasksqueue&&this.workState===j.Pending&&i===T.Selector&&O.isNumber(e[0])&&O.isNumber(e[1])&&this.hoverCursor(e,t),!this.currentToolsData||!this.isCanSentCursor)return;const o=(l=this.collector)==null?void 0:l.uid,n=this.viewContainerManager.getCurScenePath(t);switch((u=this.currentToolsData)==null?void 0:u.toolsType){case T.Eraser:case T.PencilEraser:case T.BitMapEraser:{if(o&&!this.control.renderControl.isClearAble({uid:o,viewId:t,filterLocalSelf:!1,scenePath:n}))return;break}default:if(o&&!this.control.renderControl.isWritable||o&&!this.control.renderControl.isRenderAble({uid:o,viewId:t,filterLocalSelf:!1,scenePath:n}))return;break}let a=[void 0,void 0];this.currentToolsData&&this.isCanSentCursor&&!this.localPointsBatchData.size&&!this.getLockSentEventCursor()&&(a=e,this.control.cursor.sendEvent(a,t))}getBoundingRect(e){var i,o;if(!((i=this.boundingRectMap)==null?void 0:i.get(e))){const n=(o=this.collector)==null?void 0:o.getScenePathData(e);if(!n)return;if(Object.keys(n).forEach(a=>{var c;((c=this.collector)==null?void 0:c.getLocalId(a))===G&&delete n[a]}),Object.keys(n).length&&this.viewContainerManager.mainView&&this.viewContainerManager.mainView.cameraOpt){const a={msgType:D.BoundingBox,dataType:B.Local,scenePath:e,scenes:n,cameraOpt:{...this.viewContainerManager.mainView.cameraOpt},isRunSubWork:!0,viewId:this.viewContainerManager.mainView.id};return this.taskBatchData.add(a),this.runAnimation(),new Promise(c=>{this.boundingRectMap.set(e,c)}).then(c=>(this.boundingRectMap.delete(e),c))}}}getSnapshot(e,t,i,o){var a,c,l,u,h;if(!((a=this.snapshotMap)==null?void 0:a.get(e))){const d=(c=this.collector)==null?void 0:c.getViewIdBySecenPath(e);if(!d)return;const g=(l=this.collector)==null?void 0:l.getStorageData(d,e);if(!g)return;if(Object.keys(g).forEach(p=>{var f;((f=this.collector)==null?void 0:f.getLocalId(p))===G&&delete g[p]}),Object.keys(g).length){const p=this.viewContainerManager.mainView;if(!p)return;const f=t||((u=p.cameraOpt)==null?void 0:u.width),m=i||((h=p.cameraOpt)==null?void 0:h.height),w={msgType:D.Snapshot,dataType:B.Local,scenePath:e,scenes:g,w:f,h:m,cameraOpt:o&&{...o,width:f,height:m}||p.cameraOpt,isRunSubWork:!0,viewId:p.id};return this.taskBatchData.add(w),this.runAnimation(),new Promise(I=>{this.snapshotMap.set(e,I)}).then(I=>(this.snapshotMap.delete(e),I))}}}queryTaskBatchData(e){const t=[];if(e)for(const i of this.taskBatchData.values()){let o=!0;for(const[n,a]of Object.entries(e))if(i[n]!==a){o=!1;break}o&&t.push(i)}return t}insertIconify(e,t){var a;const i=this.viewContainerManager.getView(e);if(!i)throw new Error("insertIconify viewId is not exist");if(!t.src)throw new Error("iconify src must be required");if(!/^(http|https):\/\//.test(t.src))throw new Error("iconify src must be http or https");t.strokeColor||(t.strokeColor=(a=this.currentLocalWorkData.toolsOpt)==null?void 0:a.strokeColor);const n=i==null?void 0:i.focusScenePath;if(e&&n){const c=Date.now();be.InternalMsgEmitter.emit("addUndoTicker",c,e);const l={...t,type:St.Iconify};this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayer(e),l.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),this.taskBatchData.add({msgType:D.FullWork,dataType:B.Local,toolsType:T.Image,workId:t.uuid,opt:l,viewId:e,willRefresh:!0,willSyncService:!0}),this.runAnimation()}}insertImage(e,t){const i=this.viewContainerManager.getView(e);if(!i)throw new Error("insertImage viewId is not exist");if(t.src&&!/^(http|https):\/\//.test(t.src))throw new Error("Image src must be http or https");const o=i==null?void 0:i.focusScenePath;if(e&&o){const{src:n,uuid:a}=t;if(a&&!n){this.tmpImageConfigMap.set(a,t);return}const c=Date.now();be.InternalMsgEmitter.emit("addUndoTicker",c,e);const l={...t,type:St.Image};this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayer(e),l.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),this.taskBatchData.add({msgType:D.FullWork,dataType:B.Local,toolsType:T.Image,workId:t.uuid,opt:l,viewId:e,willRefresh:!0,willSyncService:!0}),this.runAnimation()}}lockImage(e,t,i){var a,c;const o=this.viewContainerManager.getView(e);if(!o)throw new Error("insertImage viewId is not exist");const n=o==null?void 0:o.focusScenePath;if(e&&n&&this.collector){const l=this.collector.getStorageData(e,n);if(!l)return;for(const[u,h]of Object.entries(l))if(h&&h.toolsType===T.Image&&h.opt.uuid===t){const d=Date.now();be.InternalMsgEmitter.emit("addUndoTicker",d,e);const g=(a=this.collector)!=null&&a.isOwn(u)?(c=this.collector)==null?void 0:c.getLocalId(u):u,p={...h.opt,locked:i,type:St.Image};this.taskBatchData.add({msgType:D.FullWork,dataType:B.Local,toolsType:T.Image,workId:g,opt:p,viewId:e,willRefresh:!0,willSyncService:!0}),this.runAnimation();return}}}completeImageUpload(e,t,i){const o=this.viewContainerManager.getView(e);if(!o)throw new Error("insertImage viewId is not exist");const n=o==null?void 0:o.focusScenePath;if(e&&n){const a=this.tmpImageConfigMap.get(t);a&&(a.src=i,this.insertImage(e,a),this.tmpImageConfigMap.delete(t));return}}getImagesInformation(e){const t=[];if(this.collector){const i=this.collector.getScenePathData(e);if(!i)return t;for(const o of Object.values(i))if(o&&o.toolsType===T.Image){const n=o.opt;t.push({uuid:n.uuid,centerX:n.centerX,centerY:n.centerY,width:n.width,height:n.height,locked:n.locked,uniformScale:n.uniformScale,crossOrigin:n.crossOrigin})}}return t}setShapeSelectorByWorkId(e,t){this.taskBatchData.add({workId:G,selectIds:[e],msgType:D.Select,dataType:B.Local,viewId:t,willSyncService:!0}),this.runAnimation()}blurSelector(e,t,i){this.taskBatchData.add({workId:i||G,selectIds:[],msgType:D.Select,dataType:B.Service,viewId:e,scenePath:t}),this.runAnimation()}consoleWorkerInfo(){this.taskBatchData.add({msgType:D.Console,dataType:B.Local,isRunSubWork:!0,viewId:""}),this.consume()}setPriority(e){var o,n;const t=new Set,i=new Set;if(e==="cpu"&&((o=this.subMainThreadWorker)==null||o.destroy(),t.add({msgType:D.PriorityWorker,viewId:cs,dataType:B.Local,isRunSubWork:!0})),e==="ui"){t.add({msgType:D.PriorityMainThreadWorker,viewId:cs,dataType:B.Local,isRunSubWork:!0});const a=this.viewContainerManager.mainView;if(a){const l=this.viewContainerManager.getViewInitData(a.id);if(l){const{offscreenCanvasOpt:u,layerOpt:h,dpr:d,cameraOpt:g}=l;i.add({msgType:D.Init,dataType:B.Local,viewId:a.id,offscreenCanvasOpt:u,layerOpt:h,dpr:d,cameraOpt:g,isRunSubWork:!0,isSafari:navigator.userAgent.indexOf("Safari")!==-1&&navigator.userAgent.indexOf("Chrome")===-1})}}const c=this.viewContainerManager.appViews;for(const l of c.keys()){const u=this.viewContainerManager.getViewInitData(l);if(u){const{offscreenCanvasOpt:h,layerOpt:d,dpr:g,cameraOpt:p}=u;i.add({msgType:D.Init,dataType:B.Local,viewId:l,offscreenCanvasOpt:h,layerOpt:d,dpr:g,cameraOpt:p,isRunSubWork:!0,isSafari:navigator.userAgent.indexOf("Safari")!==-1&&navigator.userAgent.indexOf("Chrome")===-1})}}}t.size&&this.subWorker.postMessage(t),i.size&&((n=this.subMainThreadWorker)==null||n.consume(i))}sendClearUids(e,t){var o,n;const i=new Set;i.add({msgType:D.AuthClear,dataType:B.Local,viewId:e,clearUids:t,localUid:(o=this.collector)==null?void 0:o.uid}),this.control.hasOffscreenCanvas()?this.fullWorker.postMessage(i):(n=this.mainThread)==null||n.consume(i)}async getVNodeInfo(e,t,i){if(!this.getVNodeInfoResolveMap.has(e))return this.taskBatchData.add({msgType:D.GetVNodeInfo,dataType:B.Local,isRunSubWork:!0,viewId:t,workIds:i,workId:e}),this.consume(),await new Promise(o=>{const n=this.getVNodeInfoResolveMap.get(e)||{resolve:void 0,timer:void 0};n.timer&&clearTimeout(n.timer),n.resolve=o,n.timer=setTimeout(()=>{const a=this.getVNodeInfoResolveMap.get(e);a!=null&&a.resolve&&a.resolve({uuid:e})},this.maxLastSyncTime*5),this.getVNodeInfoResolveMap.set(e,n)}).then(o=>{const{uuid:n}=o;return this.getVNodeInfoResolveMap.delete(n),o})}}var Yy=tt,Uy=function(){return Yy.Date.now()},By=Uy,Fy=/\s/;function Vy(r){for(var s=r.length;s--&&Fy.test(r.charAt(s)););return s}var Qy=Vy,Zy=Qy,Hy=/^\s+/;function Gy(r){return r&&r.slice(0,Zy(r)+1).replace(Hy,"")}var $y=Gy,Xy=kt,Jy=at,qy="[object Symbol]";function Ky(r){return typeof r=="symbol"||Jy(r)&&Xy(r)==qy}var _y=Ky,em=$y,go=Mt,tm=_y,fo=NaN,sm=/^[-+]0x[0-9a-f]+$/i,im=/^0b[01]+$/i,om=/^0o[0-7]+$/i,nm=parseInt;function rm(r){if(typeof r=="number")return r;if(tm(r))return fo;if(go(r)){var s=typeof r.valueOf=="function"?r.valueOf():r;r=go(s)?s+"":s}if(typeof r!="string")return r===0?r:+r;r=em(r);var e=im.test(r);return e||om.test(r)?nm(r.slice(2),e?2:8):sm.test(r)?fo:+r}var am=rm,cm=Mt,Ws=By,Mo=am,lm="Expected a function",hm=Math.max,um=Math.min;function dm(r,s,e){var t,i,o,n,a,c,l=0,u=!1,h=!1,d=!0;if(typeof r!="function")throw new TypeError(lm);s=Mo(s)||0,cm(e)&&(u=!!e.leading,h="maxWait"in e,o=h?hm(Mo(e.maxWait)||0,s):o,d="trailing"in e?!!e.trailing:d);function g(v){var x=t,L=i;return t=i=void 0,l=v,n=r.apply(L,x),n}function p(v){return l=v,a=setTimeout(w,s),u?g(v):n}function f(v){var x=v-c,L=v-l,b=s-x;return h?um(b,o-L):b}function m(v){var x=v-c,L=v-l;return c===void 0||x>=s||x<0||h&&L>=o}function w(){var v=Ws();if(m(v))return I(v);a=setTimeout(w,f(v))}function I(v){return a=void 0,d&&t?g(v):(t=i=void 0,n)}function N(){a!==void 0&&clearTimeout(a),l=0,t=c=i=a=void 0}function C(){return a===void 0?n:I(Ws())}function S(){var v=Ws(),x=m(v);if(t=arguments,i=this,c=v,x){if(a===void 0)return p(c);if(h)return clearTimeout(a),a=setTimeout(w,s),g(c)}return a===void 0&&(a=setTimeout(w,s)),n}return S.cancel=N,S.flush=C,S}var pm=dm,gm=pm,fm=Mt,Mm="Expected a function";function ym(r,s,e){var t=!0,i=!0;if(typeof r!="function")throw new TypeError(Mm);return fm(e)&&(t="leading"in e?!!e.leading:t,i="trailing"in e?!!e.trailing:i),gm(r,s,{leading:t,maxWait:s,trailing:i})}var mm=ym;const Tn=Ut(mm);class wm{constructor(s){M(this,"internalMsgEmitter");M(this,"control");M(this,"roomHotkeyCheckers");M(this,"tmpCopyStore",new Map);M(this,"tmpCopyCoordInfo");var i;const{control:e,internalMsgEmitter:t}=s;this.control=e,this.internalMsgEmitter=t,this.roomHotkeyCheckers=((i=this.control.room)==null?void 0:i.viewsParams.hotKeys.nodes)||[]}get isUseSelf(){var s;return((s=this.control)==null?void 0:s.disableDeviceInputs)||!1}get isSelector(){var s;return((s=this.control.worker.currentToolsData)==null?void 0:s.toolsType)===T.Selector}get collector(){return this.control.collector}get mainEngine(){return this.control.worker}get keyboardKind(){return/^Mac/i.test(navigator.platform)?"mac":"windows"}getEventKey(s){switch(s.type){case"keydown":return"KeyDown"}return"KeyUp"}onActiveHotkey(s){var i,o,n;const e=this.control.viewContainerManager.focuedViewId,t=(i=this.control.viewContainerManager.focuedView)==null?void 0:i.focusScenePath;if(e&&t)switch(s){case"delete":this.isSelector&&((o=this.collector)!=null&&o.hasSelector(e,t))&&ae.emitMethod(ne.MainEngine,V.DeleteNode,{workIds:[G],viewId:e});break;case"copy":this.isSelector&&((n=this.collector)!=null&&n.hasSelector(e,t))&&this.copySelectorToTemp(e,t);break;case"paste":this.tmpCopyStore.size&&this.pasteTempToFocusView(e,t);break}(s==="changeToPencil"||s==="redo"||s==="undo")&&this.onSelfActiveHotkey(s)}colloctHotkey(s){if(this.isUseSelf){const e=this.checkHotkey(s);e&&this.onSelfActiveHotkey(e)}}onSelfActiveHotkey(s){switch(s){case"changeToPencil":this.setMemberState({currentApplianceName:re.pencil,useNewPencil:!0});break;case"changeToArrow":this.setMemberState({currentApplianceName:re.arrow});break;case"changeToClick":this.setMemberState({currentApplianceName:re.clicker});break;case"changeToEllipse":this.setMemberState({currentApplianceName:re.ellipse});break;case"changeToEraser":this.setMemberState({currentApplianceName:re.eraser,isLine:!0});break;case"changeToHand":this.setMemberState({currentApplianceName:re.hand});break;case"changeToLaserPointer":this.setMemberState({currentApplianceName:re.laserPointer});break;case"changeToSelector":this.setMemberState({currentApplianceName:re.selector});break;case"changeToRectangle":this.setMemberState({currentApplianceName:re.rectangle});break;case"changeToStraight":this.setMemberState({currentApplianceName:re.straight});break;case"redo":this.control.room&&!this.control.room.disableSerialization&&this.control.viewContainerManager.redo();break;case"undo":this.control.room&&!this.control.room.disableSerialization&&this.control.viewContainerManager.undo();break;case"changeToText":this.setMemberState({currentApplianceName:re.text});break}}checkHotkey(s){for(const e of this.roomHotkeyCheckers){const{kind:t,checker:i}=e;if(i({nativeEvent:s,kind:this.getEventKey(s),key:s.key,altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey},this.keyboardKind))return t}}copySelectorToTemp(s,e){var l,u;const t=this.control.viewContainerManager.getView(s),i=(u=(l=this.mainEngine)==null?void 0:l.methodBuilder)==null?void 0:u.getBuilder(V.CopyNode);if(!t||!this.collector||!i)return;const o=this.collector.transformKey(G),n=this.collector.getStorageData(s,e);if(!n)return;const a=n[o],c=a&&i.copySelector({viewId:s,store:a});c&&(this.tmpCopyCoordInfo=c==null?void 0:c.copyCoordInfo,this.tmpCopyStore=c==null?void 0:c.copyStores)}pasteTempToFocusView(s,e){var o,n;const t=this.control.viewContainerManager.getView(s),i=(n=(o=this.mainEngine)==null?void 0:o.methodBuilder)==null?void 0:n.getBuilder(V.CopyNode);if(!(!t||!this.tmpCopyCoordInfo||!this.tmpCopyStore.size||!this.collector||!i)&&t.viewData&&this.tmpCopyCoordInfo){const a=O.cloneDeep(this.tmpCopyCoordInfo.offset),c=this.tmpCopyCoordInfo.cameraOpt,l=t.viewData.camera;a.x=a.x+l.centerX-c.centerX,a.y=a.y+l.centerY-c.centerY;const u=Date.now();this.control.worker.internalMsgEmitter.emit("addUndoTicker",u,s),i.pasteSelector({viewId:s,scenePath:e,copyStores:O.cloneDeep(this.tmpCopyStore),copyCoordInfo:{offset:a,cameraOpt:l},undoTickerId:u})}}setMemberState(s){var e;(e=this.control.room)==null||e.setMemberState(s)}}class Im{constructor(s){M(this,"control");M(this,"roomMemberManager");M(this,"worker");M(this,"publicMsgEmitter");M(this,"renderUids",new Map);M(this,"pageAuth",new Map);M(this,"isLocalRender",!1);M(this,"isCurWritable",!1);var i;const{control:e,publicMsgEmitter:t}=s;this.control=e,this.publicMsgEmitter=t,this.roomMemberManager=e.roomMember,this.worker=e.worker,this.isCurWritable=((i=this.control.room)==null?void 0:i.isWritable)||!1}get isWritable(){return this.isCurWritable}onWritableChange(s){this.isCurWritable=s}addPage(s,e=!0){var l,u;const{viewId:t,render:i="localSelf",elementIds:o,pageId:n=(l=this.control.collector)==null?void 0:l.uid}=s,a=this.pageAuth.get(t)||new Map,c=this.control.viewContainerManager.getCurScenePath(t);if(c&&n){const h=a.get(c)||{render:"localSelf",pages:new Map};e&&(h.render=i);const d=o&&this.cloneElementIds(t,c,o,n)||new Set;h.pages.set(n,d),a.set(c,h),this.pageAuth.set(t,a),e&&this.pageAuthEffect(t),this.isLocalRender=!1,(u=this.control.collector)==null||u.dispatchPageAuth({operation:Ye.addPage,viewId:t,scenePath:c,pageId:n,pageData:{render:i,elementIds:d}},!0)}}delPage(s,e){var n,a;const t=this.pageAuth.get(e);if(!t)return;const i=[...t.keys()].find(c=>{const l=t.get(c);return!!(l&&l.pages.has(s))});if(!i)return;const o=t.get(i);if(o){const{render:c,pages:l}=o,u=c==="localSelf"?(n=this.control.collector)==null?void 0:n.uid:c,h=l.get(s);h!=null&&h.size&&this.delElementIds(e,i,h),l.delete(s),u===s&&this.pageAuthEffect(e)}(a=this.control.collector)==null||a.dispatchPageAuth({operation:Ye.deletePage,viewId:e,scenePath:i,pageId:s},!0)}delViewPage(s,e=!0){var i;this.pageAuth.get(s)&&(this.pageAuth.delete(s),e&&((i=this.control.collector)==null||i.dispatchPageAuth({operation:Ye.clearView,viewId:s},e)))}clearRenderPage(s,e,t=!0){var a,c;const i=this.pageAuth.get(s);if(!i)return;const o=i.get(e);let n;if(o){const{render:l,pages:u}=o,h=l==="localSelf"?(a=this.control.collector)==null?void 0:a.uid:l;if(h){if(t){const d=u.get(h);d&&this.delElementIds(s,e,d)}u.set(h,new Set),n=h}}t&&n&&((c=this.control.collector)==null||c.dispatchPageAuth({operation:Ye.clearPage,viewId:s,scenePath:e,pageId:n},t))}hasPage(s,e,t){const i=this.pageAuth.get(e);if(!i)return!1;const o=i.get(t);return o?o.pages.has(s):!1}getPageInfo(s,e,t){const i=this.pageAuth.get(e);if(!i)return;const o=i.get(t);if(o)return o.pages.get(s)}addRenderPageElementId(s,e=!0,t=!1){var u,h;const{viewId:i,elementId:o,scenePath:n}=s,a=this.pageAuth.get(i);if(!a)throw new Error(`no view info in viewId: ${i}`);const c=a.get(n);let l;if(c){const{render:d,pages:g}=c,p=d==="localSelf"?(u=this.control.collector)==null?void 0:u.uid:d;if(p&&g.has(p)){const f=g.get(p)||new Set;f.add(o),g.set(p,f),l=p}}t&&this.pageAuthEffect(i),e&&l&&((h=this.control.collector)==null||h.dispatchPageAuth({operation:Ye.addElement,viewId:i,scenePath:n,pageId:l,pageData:{elementId:o}},e))}delRenderPageElementId(s,e=!0,t=!1){var u,h;const{viewId:i,elementId:o,scenePath:n}=s,a=this.pageAuth.get(i);if(!a)throw new Error(`no view info in viewId: ${i}`);const c=a.get(n);let l;if(c){const{render:d,pages:g}=c,p=d==="localSelf"?(u=this.control.collector)==null?void 0:u.uid:d;if(p&&g.has(p)){const f=g.get(p);f&&(f.delete(o),g.set(p,f),l=p)}}t&&this.pageAuthEffect(i),e&&l&&((h=this.control.collector)==null||h.dispatchPageAuth({operation:Ye.deleteElement,viewId:i,scenePath:n,pageId:l,pageData:{elementId:o}},e))}setPageRender(s,e,t,i=!0){var a;const o=this.pageAuth.get(s);if(!o)throw new Error(`no view info in viewId: ${s}`);const n=o.get(e);n&&(n.render=t),e===this.control.viewContainerManager.getCurScenePath(s)&&this.pageAuthEffect(s),i||(this.isLocalRender=!0),i&&(this.isLocalRender=!1,(a=this.control.collector)==null||a.dispatchPageAuth({operation:Ye.renderPage,viewId:s,scenePath:e,pageData:{render:t}},i))}isRenderAble(s){var c,l;const{uid:e,viewId:t,filterLocalSelf:i=!0,scenePath:o}=s,n=this.renderUids.get(t);if(n){const{render:u,hide:h}=n;if(u===void 0&&h===void 0)return!0;if(O.isSet(u)){if(u.has(e)||i&&((c=this.control.collector)==null?void 0:c.uid)===e&&u.has("localSelf"))return!0}else if(u===!0&&(!h||O.isSet(h)&&!h.has(e)&&!(i&&h.has("localSelf")&&((l=this.control.collector)==null?void 0:l.uid)===e)))return!0;return!1}const a=this.pageAuth.get(t);if(a&&o){const u=a.get(o);if(u){const{render:h}=u;if(h)return!(h==="localSelf"&&!i)}}return!0}isClearAble(s){var c;const{uid:e,viewId:t,filterLocalSelf:i=!0,scenePath:o}=s,n=this.renderUids.get(t);if(n){const{clear:l}=n;return!!(l===void 0||l===!0||O.isSet(l)&&(l.has(e)||i&&((c=this.control.collector)==null?void 0:c.uid)===e&&l.has("localSelf")))}const a=this.pageAuth.get(t);if(a&&o){const l=a.get(o);if(l){const{render:u}=l;if(u)return!(u==="localSelf"&&!i)}}return!0}isFilterAble(s,e){var c,l,u,h;const{viewId:t,scenePath:i,elementId:o}=s,n=this.renderUids.get(t);if(n&&o){const{render:d,hide:g}=n;if(d===void 0&&g===void 0)return!0;const p=(c=this.control.collector)==null?void 0:c.getUidFromKey(o);return p?!!(O.isSet(d)&&(d.has(p)||d.has("localSelf")&&((l=this.control.collector)==null?void 0:l.uid)===p)||d===!0&&(!g||O.isSet(g)&&!g.has(p)&&!(g.has("localSelf")&&((u=this.control.collector)==null?void 0:u.uid)===p))):!1}const a=this.pageAuth.get(t);if(a&&i&&o){const d=a.get(i);if(d){const{render:g,pages:p}=d;if(!g)return!0;const f=(h=this.control.collector)==null?void 0:h.uid,m=g==="localSelf"?f:g,w=m&&p.get(m)||void 0;if(w)switch(e){case D.RemoveNode:return!0;default:return w.has(o)}return!1}}return!0}isFilterCursor(s){if(this.isUsePageAuth(s)){const e=this.control.viewContainerManager.getCurScenePath(s),t=this.pageAuth.get(s);if(e&&t){const i=t.get(e);if(i){const{render:o}=i;return o!=="localSelf"}}}return!0}isUsePageAuth(s){var i;if(!this.pageAuth.has(s))return!1;const t=this.control.viewContainerManager.getCurScenePath(s);return t&&((i=this.pageAuth.get(s))==null?void 0:i.has(t))||!1}publishRender(s){var n;const{viewId:e,option:t,isSync:i=!0}=s,o={};if(t){const{render:a,hide:c,clear:l}=t;a&&(o.render=a===!0&&!0||new Set(a)),c&&(o.hide=c===!0&&!0||new Set(c)),l&&(o.clear=l===!0&&!0||new Set(l)),this.renderUids.set(e,o)}else this.renderUids.delete(e);i&&((n=this.control.collector)==null||n.dispatchRenderAuth({operation:et.setAuth,viewId:e,renderData:o},i)),this.renderEffect(e)}publishOneRender(s,e,t,i=!0){var a;const o=this.renderUids.get(s);let n;switch(t){case"show":o?(o.render||(o.render=new Set),O.isSet(o.render)&&o.render.add(e),O.isSet(o.hide)&&o.hide.delete(e)):this.renderUids.set(s,{render:new Set([e])}),n=et.setShow;break;case"hide":o?(o.hide||(o.hide=new Set),O.isSet(o.hide)&&o.hide.add(e),O.isSet(o.render)&&o.render.delete(e)):this.renderUids.set(s,{hide:new Set([e])}),n=et.setHide;break}o?this.renderUids.set(s,o):this.renderUids.delete(s),i&&n&&((a=this.control.collector)==null||a.dispatchRenderAuth({operation:n,viewId:s,uid:e},i)),this.renderEffect(s)}publishOneClear(s,e,t,i=!0){var n;const o=this.renderUids.get(s);t?o?(o.clear||(o.clear=new Set),O.isSet(o.clear)&&o.clear.add(e)):this.renderUids.set(s,{clear:new Set([e])}):o&&O.isSet(o.clear)&&o.clear.has(e)&&o.clear.delete(e),o?this.renderUids.set(s,o):this.renderUids.delete(s),i&&((n=this.control.collector)==null||n.dispatchRenderAuth({operation:et.setClear,viewId:s,uid:e,isClear:t},i)),this.renderEffect(s)}syncRenderUids(s,e,t,i){const o=e===!0?!0:e&&Object.keys(e)?new Set(Object.keys(e)):void 0,n=t===!0?!0:t&&Object.keys(t)?new Set(Object.keys(t)):void 0,a=i===!0?!0:i&&Object.keys(i)?new Set(Object.keys(i)):void 0;o||n||a?this.renderUids.set(s,{render:o,hide:n,clear:a}):this.renderUids.delete(s),this.renderEffect(s),this.publicMsgEmitter.emit("syncRenderUids",s,{render:o,hide:n,clear:a})}syncPageAuth(s,e,t=!1){let i=!1;if(!e)this.pageAuth.delete(s);else{const o=this.pageAuth.get(s)||new Map;for(const[n,a]of Object.entries(e)){const{render:c,pages:l}=a,u=o.get(n),h=this.isLocalRender?u==null?void 0:u.render:c;if(h){h!==(u==null?void 0:u.render)&&(i=!0);const d=new Map;for(const[p,f]of Object.entries(l))d.set(p,new Set(Object.keys(f)));const g={render:h,pages:d};d.size&&o.set(n,g)}}o.size&&(this.pageAuth.set(s,o),this.publicMsgEmitter.emit("syncPageAuth",s,o))}(t||i)&&this.pageAuthEffect(s)}destoryByViewId(s,e=!1){var t;this.renderUids.has(s)&&(this.renderUids.delete(s),e||(t=this.control.collector)==null||t.dispatchRenderAuth({operation:et.setAuth,viewId:s})),this.pageAuth.has(s)&&this.control.renderControl.delViewPage(s,!e)}renderEffect(s){var t;const e=(t=this.control.viewContainerManager.getView(s))==null?void 0:t.focusScenePath;e&&this.worker.clearViewScenePath(s,!0).then(()=>{var i;this.worker.pullServiceData(s,e,{isAsync:!0,useAnimation:!1}),this.worker.sendClearUids(s,(i=this.renderUids.get(s))==null?void 0:i.clear)})}pageAuthEffect(s){var t;const e=(t=this.control.viewContainerManager.getView(s))==null?void 0:t.focusScenePath;e&&this.worker.clearViewScenePath(s,!0).then(()=>{this.worker.pullServiceData(s,e,{isAsync:!0,useAnimation:!1}),this.worker.sendClearUids(s,!0)})}cloneElementIds(s,e,t,i){var a,c;const o=(a=this.control.collector)==null?void 0:a.getStorageData(s,e),n=new Set;if(o){for(const l of Object.keys(o))if(t.has(l)){const u=`${l}_${i}`;if(n.add(u),!Object.keys(o).includes(u)){const h=O.cloneDeep(o[l]);(c=this.control.collector)==null||c.updateValue(u,{type:D.FullWork,...h,workId:u},{isSync:!0,viewId:s,scenePath:e})}}}return n}delElementIds(s,e,t){var o,n;const i=(o=this.control.collector)==null?void 0:o.getStorageData(s,e);if(i)for(const a of Object.keys(i))t.has(a)&&Object.keys(i).includes(a)&&((n=this.control.collector)==null||n.updateValue(a,void 0,{isSync:!0,viewId:s,scenePath:e}))}}class Tm{constructor(s){M(this,"internalMsgEmitter");M(this,"control");M(this,"maps",new Map);M(this,"showId");M(this,"color");M(this,"timer");M(this,"updateMiniMapCamera",O.debounce(async s=>{const e=this.maps.get(s);if(e){const t=await this.getMiniMapCamera(s);if(t){const i=t.width/t.scale,o=t.height/t.scale,n=e.miniMapCamera.width/e.miniMapCamera.scale,a=e.miniMapCamera.height/e.miniMapCamera.scale;(i>=n||o>=a)&&(e.miniMapCamera=t);const c=e.miniMapCanvas.current;if(c){const l=c.getContext("2d");if(l){const u=this.control.viewContainerManager.getView(s);if(!(u!=null&&u.focusScenePath))return;const{miniMapCamera:h,contianer:d}=e,{width:g,height:p}=d.getBoundingClientRect(),f=Math.min(g/h.width,p/h.height);l.clearRect(0,0,c.width,c.height),c.width=h.width,c.height=h.height,c.style.width=`${h.width*f}px`,c.style.height=`${h.height*f}px`,await this.control.screenshotToCanvas(l,u.focusScenePath,h.width,h.height,h),this.listener.emitAsync([s,"viewCameraUpate"],1)}}}}},2e3,{maxWait:5e3}));var i;const{control:e,internalMsgEmitter:t}=s;this.control=e,this.internalMsgEmitter=t,this.color=((i=this.control.worker.currentToolsData)==null?void 0:i.toolsOpt.strokeColor)||"#000"}get listener(){return this.internalMsgEmitter}get activeViewId(){return this.showId}get highlightColor(){return this.color}setHighlightColor(s){this.color=s}async createMiniMap(s,e,t){const i=this.control.viewContainerManager.getView(s);if(!i)throw new Error("view not found");const o=i.cameraOpt;if(!o)throw new Error("view camera not found");const{width:n,height:a}=e.getBoundingClientRect();if(!n||!a)throw new Error("contianer width or height is 0");const c=y.createRef();this.maps.set(s,{contianer:e,miniMapCanvas:c,miniMapCamera:t,viewCamera:o}),this.showId=s,this.control.viewContainerManager.setActiveMiniMap(this.showId,!0);const l=Math.min(n/t.width,a/t.height),u=await new Promise(h=>{this.listener.once([s,"miniMapCreate"],()=>{const d=c.current;d&&(d.width=t.width,d.height=t.height,d.style.width=`${t.width*l}px`,d.style.height=`${t.height*l}px`),h(!0)}),this.timer=setTimeout(()=>{h(!1)},2e3)});return this.timer&&clearTimeout(this.timer),u}async getMiniMapCamera(s){const e=this.control.viewContainerManager.getView(s);if(!e)return;const{cameraOpt:t,focusScenePath:i}=e;if(!t||!i)return;const o={originX:t.centerX-t.width/t.scale/2,originY:t.centerY-t.height/t.scale/2,width:t.width/t.scale,height:t.height/t.scale};let n=await this.control.getBoundingRect(i)||o;n=Mi(n,o)||o;let a=n.width,c=n.height,l=1;const u=a>t.width&&Math.min(t.width/a,l)||l,h=c>t.height&&Math.min(t.height/c,l)||l;return u<=h?(a=u<1&&t.width||a,c=Math.floor(c*u)+1,l=u):u>h&&(c=h<1&&t.height||c,a=Math.floor(a*h)+1,l=h),{scale:l,centerX:n.originX+n.width/2,centerY:n.originY+n.height/2,width:a,height:c}}getMiniMapCanvas(s){const e=this.maps.get(s);return(e==null?void 0:e.miniMapCanvas.current)||null}updateViewCamera(s,e){const t=this.maps.get(s);t&&(t.viewCamera=e,this.listener.emitAsync([s,"viewCameraUpate"],1))}destroyMiniMap(s){const e=s||this.showId;e&&(this.maps.delete(e),this.control.viewContainerManager.setActiveMiniMap(e,!1))}}class vn{constructor(){M(this,"control");M(this,"_listeners",{})}_inject(s){this.control=s}_onEvent(s,e){this._listeners[s]&&this._listeners[s](...e)}callbacks(s,e){this._listeners[s]=e}removeCallback(s){delete this._listeners[s]}}class vm{constructor(s){M(this,"control");M(this,"worker");M(this,"publicMsgEmitter");M(this,"plugins",new Map);const{control:e,publicMsgEmitter:t}=s;this.control=e,this.publicMsgEmitter=t,this.worker=e.worker}use(s){this.plugins.set(s.kind,s),s._inject(this.control),s.onCreate()}destroy(){this.plugins.forEach(s=>{this.plugins.delete(s.kind),s.onDestroy()})}dispatchPluginEvent(s,...e){this.plugins.forEach(t=>{t._onEvent(s,e)})}}const Tt=class Tt{constructor(s){M(this,"version",Jo);M(this,"plugin");M(this,"room");M(this,"play");M(this,"collector");M(this,"hasSwitchToSelectorEffect");M(this,"snapshootStateMap");M(this,"_disableDeviceInputs");M(this,"_disableEraseImage");M(this,"_disableEraseText");M(this,"_disableCameraTransform");M(this,"_disableUseWorker",!1);M(this,"priority","cpu");M(this,"effectResolve");M(this,"hotkeyManager");M(this,"pluginOptions");M(this,"roomMember");M(this,"cursor");M(this,"textEditorManager");M(this,"worker");M(this,"renderControl");M(this,"miniMapManager");M(this,"pluginManager");M(this,"onSceneChange",async(s,e)=>{var n;const t=this.viewContainerManager.getView(e);t!=null&&t.focusScenePath&&(n=this.collector)!=null&&n.hasSelector(e,t.focusScenePath)&&this.worker.blurSelector(e,t.focusScenePath),this.textEditorManager.checkEmptyTextBlur();const i=t==null?void 0:t.displayer;i&&(i.setActive(!1),await i.stopEventHandler());const o=s;o&&this.viewContainerManager.setViewScenePath(e,o),i==null||i.setActive(!0)});M(this,"onRoomMembersChange",s=>{this.roomMember.setRoomMembers(X.toJS(s))});M(this,"onMemberChange",Tn(s=>{var n;if(!this.room||!this.worker||!s||!this.room.isWritable)return;const e=this.getToolsKey(s),t=(n=this.worker.getCurrentToolsData())==null?void 0:n.toolsType,i=this.viewContainerManager.focuedViewId;i&&t===T.Selector&&e!==T.Selector&&this.worker.blurCursor(i);const o=this.getToolsOpt(e,s);this.worker.setCurrentToolsData(o),this.pluginManager.dispatchPluginEvent("setToolkey",e),this.effectViewContainer(e),this.effectResolve&&this.effectResolve(!0)},100,{leading:!1}));M(this,"internalSceneChange",(s,e)=>{var i;this.miniMapManager.activeViewId===s&&this.miniMapManager.destroyMiniMap(s),this.pluginManager.dispatchPluginEvent("sceneChange",s,e),(i=this.worker)==null||i.clearViewScenePath(s,!0).then(()=>{var o;(o=this.worker)==null||o.pullServiceData(s,e,{isAsync:!0,useAnimation:!1})})});M(this,"internalCameraChange",(s,e)=>{var t;(t=this.worker)==null||t.updateCamera(s,e),this.miniMapManager.updateViewCamera(s,e)});const{displayer:e,plugin:t,options:i}=s;this.plugin=t,this.room=X.isRoom(e)?e:void 0,this.play=X.isPlayer(e)?e:void 0,this.room&&(this._disableDeviceInputs=this.room.disableDeviceInputs,this._disableEraseImage=this.room.disableEraseImage,this._disableEraseText=!1),this.pluginOptions=i,i.cdn.useWorker==="mainThread"?this._disableUseWorker=!0:this._disableUseWorker=Xi!=="worker",this.roomMember=new my;const o={control:this,internalMsgEmitter:Tt.InternalMsgEmitter,publicMsgEmitter:Tt.PublicMsgEmitter};this.cursor=new Iy(o),this.textEditorManager=new wy(o),this.worker=new Wy(o),this.hotkeyManager=new wm(o),this.renderControl=new Im(o),this.miniMapManager=new Tm(o),this.pluginManager=new vm(o)}get disableEraseText(){return this._disableEraseText||!1}set disableEraseText(s){this._disableEraseText=s}get disableEraseImage(){return this._disableEraseImage||!1}set disableEraseImage(s){this._disableEraseImage=s}get disableDeviceInputs(){return this._disableDeviceInputs||!1}set disableDeviceInputs(s){var t;this._disableDeviceInputs=s;const e=(t=this.worker.getCurrentToolsData())==null?void 0:t.toolsType;e&&this.effectViewContainer(e)}get disableCameraTransform(){return this._disableCameraTransform||!1}set disableCameraTransform(s){this._disableCameraTransform=s}get disableUseWorker(){return this._disableUseWorker||!1}set disableUseWorker(s){this._disableUseWorker=s}setPriority(s){var e;this.priority=s,this.hasOffscreenCanvas()&&((e=this.worker)==null||e.setPriority(s))}hasOffscreenCanvas(){return this._disableUseWorker?!1:Xi==="worker"}bindPlugin(s){var e,t;this.plugin=s,this.collector&&(this.collector.removeStorageStateListener(),this.collector.removeAuthStateListener()),this.collector=new $s(this,s,(t=(e=this.pluginOptions)==null?void 0:e.syncOpt)==null?void 0:t.interval),this.activePlugin()}destroy(){var s,e,t,i,o,n;this.roomMember.destroy(),(s=this.collector)==null||s.destroy(),(e=this.worker)==null||e.destroy(),(t=this.viewContainerManager)==null||t.destroy(),(i=this.cursor)==null||i.destroy(),(o=this.textEditorManager)==null||o.destory(),(n=this.pluginManager)==null||n.destroy()}cleanCurrentScene(){const s=Date.now(),e=this.worker.getLocalWorkViewId()||this.viewContainerManager.focuedViewId;e&&(Tt.InternalMsgEmitter.emit("addUndoTicker",s,e),this.worker.clearViewScenePath(e,!1,!0))}async setWritable(s){var e,t;if(!s){(e=this.cursor)==null||e.unabled(),this.textEditorManager.checkEmptyTextBlur();const i=this.viewContainerManager.getAllViews();for(const o of i){o!=null&&o.focusScenePath&&(t=this.collector)!=null&&t.hasSelector(o.id,o.focusScenePath)&&this.worker.blurSelector(o.id,o.focusScenePath);const n=o==null?void 0:o.displayer;n&&n.getActive()&&(n.setActive(!1),await n.stopEventHandler())}}await new Promise(i=>{setTimeout(()=>{i()},500)})}onWritableChange(s){var i;s?this.worker.abled():this.worker.unWritable(),((i=this.worker.getCurrentToolsData())==null?void 0:i.toolsType)===T.Text&&this.viewContainerManager.focuedViewId&&(s?this.viewContainerManager.activeTextEditor(this.viewContainerManager.focuedViewId):this.viewContainerManager.unActiveTextEditor(this.viewContainerManager.focuedViewId)),this.renderControl.onWritableChange(s),this.viewContainerManager.getAllViews().forEach(o=>{const n=o==null?void 0:o.displayer;n&&(n.bindToolsClass(),s?n.setActive(!0):n.setActive(!1))})}getToolsKey(s){var t;const e=s.currentApplianceName;switch(this.hasSwitchToSelectorEffect=!1,e){case re.text:return s.textCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),T.Text;case re.pencil:return s.useLaserPen?T.LaserPen:T.Pencil;case re.eraser:return T.Eraser;case re.pencilEraser:return((t=this.pluginOptions.pencilEraser)==null?void 0:t.useBitMap)===!1?T.PencilEraser:T.BitMapEraser;case re.selector:return T.Selector;case re.arrow:return s.arrowCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),T.Arrow;case re.straight:return s.straightCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),T.Straight;case re.ellipse:return s.ellipseCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),T.Ellipse;case re.rectangle:return s.rectangleCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),T.Rectangle;case re.shape:if(s.shapeCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),s.shapeType===Ke.Pentagram||s.shapeType===Ke.Star)return T.Star;if(s.shapeType===Ke.Polygon||s.shapeType===Ke.Triangle||s.shapeType===Ke.Rhombus)return T.Polygon;if(s.shapeType===Ke.SpeechBalloon)return T.SpeechBalloon;break}return T.Clicker}getToolsOpt(s,e){if(s===T.Clicker)return{toolsType:s,toolsOpt:{}};const t={strokeColor:gt(e.strokeColor[0],e.strokeColor[1],e.strokeColor[2],e.strokeOpacity||1),thickness:e.strokeWidth,isOpacity:(e==null?void 0:e.strokeOpacity)&&e.strokeOpacity<1||(e==null?void 0:e.fillOpacity)&&e.fillOpacity<1||(e==null?void 0:e.textOpacity)&&e.textOpacity<1||(e==null?void 0:e.textBgOpacity)&&e.textBgOpacity<1||!1};switch(s){case T.Text:t.fontFamily=window.getComputedStyle(document.documentElement).getPropertyValue("font-family"),t.fontSize=(e==null?void 0:e.textSizeOverride)||(e==null?void 0:e.textSize)||Number(window.getComputedStyle(document.body).fontSize),t.textAlign=(e==null?void 0:e.textAlign)||"left",t.verticalAlign=(e==null?void 0:e.verticalAlign)||"middle",t.fontColor=(e==null?void 0:e.textColor)&&gt(e.textColor[0],e.textColor[1],e.textColor[2],e.textOpacity||1)||t.strokeColor||"rgba(0,0,0,1)",t.fontBgColor=Array.isArray(e==null?void 0:e.textBgColor)&&gt(e.textBgColor[0],e.textBgColor[1],e.textBgColor[2],e.textBgOpacity||1)||"transparent",t.bold=(e==null?void 0:e.bold)&&"bold"||void 0,t.italic=(e==null?void 0:e.italic)&&"italic"||void 0,t.underline=(e==null?void 0:e.underline)||void 0,t.lineThrough=(e==null?void 0:e.lineThrough)||void 0,t.text="",t.strokeColor=void 0;break;case T.Pencil:t.strokeType=(e==null?void 0:e.strokeType)||oe.Normal;break;case T.PencilEraser:case T.BitMapEraser:case T.Eraser:t.thickness=Math.min(4,Math.max(1,Math.floor(e.pencilEraserSize||1)))-1,(s===T.BitMapEraser||s===T.PencilEraser)&&(t.eraserColor=e.eraserColor&&gt(e.eraserColor[0],e.eraserColor[1],e.eraserColor[2],e.eraserOpacity||.3)||"rgba(136,136,136,0.3)");break;case T.LaserPen:t.duration=(e==null?void 0:e.duration)||1,e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===oe.Stroke?t.strokeType=oe.Normal:t.strokeType=(e==null?void 0:e.strokeType)||oe.Normal;break;case T.Arrow:case T.Straight:e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===oe.Stroke?t.strokeType=oe.Normal:t.strokeType=(e==null?void 0:e.strokeType)||oe.Normal;break;case T.Ellipse:case T.Rectangle:case T.Star:case T.Polygon:case T.SpeechBalloon:e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===oe.Stroke?t.strokeType=oe.Normal:t.strokeType=(e==null?void 0:e.strokeType)||oe.Normal,s===T.Star&&(e.shapeType===Ke.Pentagram?(t.vertices=10,t.innerVerticeStep=2,t.innerRatio=.4):e!=null&&e.vertices&&(e!=null&&e.innerVerticeStep)&&(e!=null&&e.innerRatio)&&(t.vertices=e.vertices,t.innerVerticeStep=e.innerVerticeStep,t.innerRatio=e.innerRatio)),s===T.Polygon&&(e.shapeType===Ke.Triangle?t.vertices=3:e.shapeType===Ke.Rhombus?t.vertices=4:e.vertices&&(t.vertices=e.vertices)),t.fillColor=(e==null?void 0:e.fillColor)&&gt(e.fillColor[0],e.fillColor[1],e.fillColor[2],e==null?void 0:e.fillOpacity)||"transparent",s===T.SpeechBalloon&&(t.placement=e.placement||"bottomLeft");break}return{toolsType:s,toolsOpt:t}}effectViewContainer(s){var e,t,i,o,n;if(this.disableDeviceInputs===!0)this.room.disableDeviceInputs=!0,(e=this.worker)==null||e.unWritable(),(t=this.cursor)==null||t.unabled();else switch(s!==T.Text&&this.viewContainerManager.focuedViewId&&this.viewContainerManager.unActiveTextEditor(this.viewContainerManager.focuedViewId),s){case T.Text:case T.Pencil:case T.LaserPen:case T.Arrow:case T.Straight:case T.Rectangle:case T.Ellipse:case T.Star:case T.Polygon:case T.SpeechBalloon:case T.Triangle:case T.Rhombus:case T.Eraser:case T.PencilEraser:case T.BitMapEraser:case T.Selector:this.room.disableDeviceInputs=!0,(i=this.worker)==null||i.abled(),s===T.Text&&this.viewContainerManager.focuedViewId&&this.viewContainerManager.activeTextEditor(this.viewContainerManager.focuedViewId);break;default:this.room.disableDeviceInputs=!1,(o=this.worker)==null||o.unWritable(),(n=this.cursor)==null||n.unabled();break}setTimeout(()=>{this.viewContainerManager.getAllViews().forEach(c=>{c!=null&&c.displayer&&c.displayer.bindToolsClass()})},0)}async getBoundingRect(s){var t,i,o,n,a;const e=await((t=this.worker)==null?void 0:t.getBoundingRect(s));if(e){const c=((o=(i=this.viewContainerManager.mainView)==null?void 0:i.viewData)==null?void 0:o.convertToPointInWorld({x:e.x,y:e.y}))||{x:e.x,y:e.y},l=((a=(n=this.viewContainerManager.mainView)==null?void 0:n.viewData)==null?void 0:a.camera.scale)||1;return{width:Math.floor(e.w/l)+1,height:Math.floor(e.h/l)+1,originX:c.x,originY:c.y}}}async screenshotToCanvas(s,e,t,i,o,n,a){const c=await this.worker.getSnapshot(e,t,i,o);c&&(s.drawImage(c,n||0,a||0),c.close())}async scenePreview(s,e){var n,a,c,l;const t=(n=this.collector)==null?void 0:n.getViewIdBySecenPath(s);if(!t)return;const i=this.viewContainerManager.getView(t);if(!i||!((a=i.cameraOpt)!=null&&a.width)||!((c=i.cameraOpt)!=null&&c.height))return;const o=await((l=this.worker)==null?void 0:l.getSnapshot(s));if(o&&this.worker){const u=document.createElement("canvas"),h=u.getContext("2d"),{width:d,height:g}=i.cameraOpt;u.width=d,u.height=g,h&&(h.drawImage(o,0,0),e.crossOrigin="anonymous",e.src=u.toDataURL(),e.onload=()=>{u.remove()},e.onerror=()=>{u.remove(),e.remove()}),o.close()}}switchToText(){var s;(s=this.room)==null||s.setMemberState({currentApplianceName:re.text})}switchToSelector(){var s;(s=this.room)==null||s.setMemberState({currentApplianceName:re.selector})}async runEffectWork(s){if(this.hasSwitchToSelectorEffect){const e=await new Promise(t=>{this.switchToSelector(),this.effectResolve=t});this.effectResolve=void 0,e&&s&&s()}}setSnapshootData(){var s;this.room&&(this.snapshootStateMap=new Map,this.snapshootStateMap.set("memberState",(s=this.room)==null?void 0:s.state.memberState))}getSnapshootData(s){var e;return(e=this.snapshootStateMap)==null?void 0:e.get(s)}clearSnapshootData(){var s;(s=this.snapshootStateMap)==null||s.clear(),this.snapshootStateMap=void 0}useBitMapEraser(s){var e;if(((e=this.pluginOptions.pencilEraser)==null?void 0:e.useBitMap)===void 0){this.pluginOptions.pencilEraser={useBitMap:s,maxImageWidth:Ie.pencilEraser.maxImageWidth,maxImageHeight:Ie.pencilEraser.maxImageHeight};return}this.pluginOptions.pencilEraser.useBitMap=s}consoleWorkerInfo(){var s;(s=this.worker)==null||s.consoleWorkerInfo()}filterRenderByUid(s,e,t=!0){var o;this.viewContainerManager.getView(s)&&((o=this.renderControl)==null||o.publishRender({viewId:s,option:e,isSync:t}))}cancelFilterRender(s,e=!0){var t;(t=this.renderControl)==null||t.publishRender({viewId:s,isSync:e})}async createMiniMap(s,e){const t=await this.miniMapManager.getMiniMapCamera(s);if(t&&await this.miniMapManager.createMiniMap(s,e,t)){const o=this.miniMapManager.getMiniMapCanvas(s);if(o){const n=o.getContext("2d");if(n){const a=this.viewContainerManager.getView(s);a!=null&&a.focusScenePath&&this.screenshotToCanvas(n,a.focusScenePath,t.width,t.height,t)}}}}async destroyMiniMap(s){this.miniMapManager.destroyMiniMap(s)}insertIconify(s,e){var i;if(this.viewContainerManager.getView(s)&&this.room){const o=this.room.state.memberState,n=gt(o.strokeColor[0],o.strokeColor[1],o.strokeColor[2],o.strokeOpacity||1);(i=this.worker)==null||i.insertIconify(s,{...e,strokeColor:n})}}usePlugin(s){return this.pluginManager.use(s)}};M(Tt,"InternalMsgEmitter",new Us),M(Tt,"PublicMsgEmitter",new Us);let be=Tt;const vt=class vt{constructor(s){M(this,"emitter",new Us);M(this,"undoStack");M(this,"redoStack");M(this,"worker");M(this,"control");M(this,"room");M(this,"isTicking");M(this,"undoTickerId");M(this,"viewId");M(this,"scenePath");M(this,"tickStartStorerCache");M(this,"excludeIds",new Set);M(this,"onChangeScene",O.debounce(()=>{const s=this.control.viewContainerManager.getCurScenePath(this.viewId);if(s){let e=this.undoStack.filter(i=>i.scenePath===s).length;const t=this.redoStack.filter(i=>i.scenePath===s).length;e===0&&t===0&&this.tickStartStorerCache&&this.scenePath===s&&(e=1),this.emitter.emit("onCanUndoStepsUpdate",e),this.emitter.emit("onCanRedoStepsUpdate",t)}},vt.waitTime));const{control:e,internalMsgEmitter:t,viewId:i}=s;this.control=e,this.emitter=t,this.undoStack=[],this.redoStack=[],this.room=e.room,this.worker=e.worker,this.isTicking=!1,this.viewId=i}get collector(){return this.control.collector}addExcludeIds(s){if(this.isTicking)for(const e of s)this.excludeIds.add(e)}undoTickerStart(s,e){var t,i;if(this.collector&&(this.undoTickerId!==s||this.scenePath!==e)){!this.undoTickerId&&!this.tickStartStorerCache&&!this.scenePath&&this.emitter.emit("onCanUndoStepsUpdate",1),this.undoTickerId&&this.viewId&&this.scenePath&&this.undoTickerEndSync(this.undoTickerId,this.viewId,this.scenePath),this.isTicking=!0;const o=this.collector.transformKey(G);this.excludeIds.add(o),this.undoTickerId=s,this.scenePath=e;const n=((t=this.collector)==null?void 0:t.storage[this.viewId])&&((i=this.collector)==null?void 0:i.storage[this.viewId][this.scenePath])||{};this.tickStartStorerCache=new Map(Object.entries(O.cloneDeep(n)))}}undoTickerEndSync(s,e,t,i=!0){var o,n;if(s===this.undoTickerId&&t===this.scenePath&&e===this.viewId&&this.tickStartStorerCache){const a=((o=this.collector)==null?void 0:o.storage[e])&&((n=this.collector)==null?void 0:n.storage[e][t])||{},c=this.diffFun(this.tickStartStorerCache,new Map(Object.entries(a)));c.size&&(this.undoStack.push({id:s,type:2,data:O.cloneDeep(c),scenePath:t}),this.undoStack.length>vt.MaxStackLength&&this.undoStack.shift(),i&&this.emitter.emit("onCanUndoStepsUpdate",this.undoStack.length+1)),this.redoStack.length&&(this.redoStack.length=0,this.emitter.emit("onCanRedoStepsUpdate",this.redoStack.length)),this.isTicking=!1,this.scenePath=void 0,this.tickStartStorerCache=void 0,this.undoTickerId=void 0,this.excludeIds.clear()}}undo(s){this.undoTickerId&&this.tickStartStorerCache&&this.scenePath&&this.undoTickerEndSync(this.undoTickerId,this.viewId,this.scenePath,!1);let e=this.undoStack.length-1;for(;e>=0;){if(this.undoStack[e].scenePath===s){const n=this.undoStack[e];n&&(this.redoStack.push(n),n.type===2&&n.data&&this.refreshPlugin(n)),this.undoStack.splice(e,1);break}e--}const t=this.undoStack.filter(o=>o.scenePath===s).length,i=this.redoStack.filter(o=>o.scenePath===s).length;return this.emitter.emit("onCanUndoStepsUpdate",t),this.emitter.emit("onCanRedoStepsUpdate",i),t}redo(s){let e=this.redoStack.length-1;for(;e>=0;){if(this.redoStack[e].scenePath===s){const n=this.redoStack[e];n&&(!this.undoTickerId&&n.tickStartStorerCache?(this.undoTickerId=n.id,this.tickStartStorerCache=n.tickStartStorerCache,this.scenePath=n.scenePath):this.undoStack.push(n),n.type===2&&n.data&&this.refreshPlugin(n,!0)),this.redoStack.splice(e,1);break}e--}const t=this.undoStack.filter(o=>o.scenePath===s).length,i=this.redoStack.filter(o=>o.scenePath===s).length;return this.emitter.emit("onCanUndoStepsUpdate",t),this.emitter.emit("onCanRedoStepsUpdate",i),i}clear(){this.clearUndo(),this.clearRedo()}clearUndo(){this.undoStack.length=0,this.emitter.emit("onCanUndoStepsUpdate",this.undoStack.length)}clearRedo(){this.redoStack.length=0,this.emitter.emit("onCanRedoStepsUpdate",this.redoStack.length)}canUndo(){return!!this.undoStack.length}canRedo(){return!!this.redoStack.length}onFocusView(){const s=this.control.viewContainerManager.getCurScenePath(this.viewId);if(s){let e=this.undoStack.filter(i=>i.scenePath===s).length;const t=this.redoStack.filter(i=>i.scenePath===s).length;e===0&&t===0&&this.tickStartStorerCache&&this.scenePath===s&&(e=1),this.emitter.emit("onCanUndoStepsUpdate",e),this.emitter.emit("onCanRedoStepsUpdate",t)}}diffFun(s,e){const t=new Set,i=s.keys(),o=e.keys();for(const n of i){if(this.excludeIds.has(n))continue;const a=s.get(n),c=e.get(n);if(a&&c){if(O.isEqual(c,a))continue;t.add({dataType:3,key:n,data:[a,c]});continue}a&&t.add({dataType:2,key:n,data:a})}for(const n of o){if(this.excludeIds.has(n))continue;const a=e.get(n);a&&!s.has(n)&&t.add({dataType:1,key:n,data:a})}return t}isDrawEffectiveScene(s,e){const{key:t}=s;return!e.includes(t)}isDeleteEffectiveScene(s,e,t){var n;const{key:i}=s;if(!e.includes(i))return!1;const o=e.filter(a=>{var c,l;return((c=this.collector)==null?void 0:c.getLocalId(a))===G&&!((l=this.collector)!=null&&l.isOwn(a))}).map(a=>{var c;return(c=this.collector)==null?void 0:c.storage[this.viewId][t][a]});for(const a of o)if((n=a==null?void 0:a.selectIds)!=null&&n.includes(i))return!1;return!0}isOldEffectiveScene(s,e,t){var n;const{key:i}=s;if(!e.includes(i))return!1;const o=e.filter(a=>{var c,l;return((c=this.collector)==null?void 0:c.getLocalId(a))===G&&!((l=this.collector)!=null&&l.isOwn(a))}).map(a=>{var c;return(c=this.collector)==null?void 0:c.storage[this.viewId][t][a]});for(const a of o)if((n=a==null?void 0:a.selectIds)!=null&&n.includes(i))return!1;return!0}isNewEffectiveScene(s,e){const{key:t}=s;return!!e.includes(t)}refreshPlugin(s,e=!1){var a,c,l,u,h,d,g,p,f,m,w,I,N,C,S,v,x,L,b,P,A;let t;const{scenePath:i}=s,o=s.data;if(!o||!this.collector)return;const n=O.cloneDeep(this.collector.storage);for(const E of o.values()){const{dataType:R,data:z,key:Z}=E,ee=this.collector.getStorageData(this.viewId,i),F=ee&&Object.keys(ee)||[];switch(R){case 1:if(t=e?this.isDrawEffectiveScene(E,F):this.isDeleteEffectiveScene(E,F,i),t)if(e&&!Array.isArray(z)){if((a=z.updateNodeOpt)!=null&&a.useAnimation&&(z.updateNodeOpt.useAnimation=!1),((c=this.collector)==null?void 0:c.getLocalId(Z))===G&&((l=this.collector)!=null&&l.isOwn(E.key))){const $=z.selectIds;if($){const te=F.filter(ie=>{var _,J;return((_=this.collector)==null?void 0:_.getLocalId(ie))===G&&!((J=this.collector)!=null&&J.isOwn(ie))}).map(ie=>{var _;return(_=this.collector)==null?void 0:_.storage[this.viewId][i][ie]});let le=!1;for(const ie of te)for(let _=0;_<$.length;_++)(u=ie==null?void 0:ie.selectIds)!=null&&u.includes($[_])&&(delete $[_],le=!0);le&&(z.selectIds=$.filter(ie=>!!ie))}}(h=this.collector)==null||h.updateValue(E.key,z,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}else!e&&!Array.isArray(E.data)&&((d=this.collector)==null||d.updateValue(E.key,void 0,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n}));break;case 2:if(t=e?this.isDeleteEffectiveScene(E,F,i):this.isDrawEffectiveScene(E,F),t){if(e&&!Array.isArray(z))(g=this.collector)==null||g.updateValue(Z,void 0,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n});else if(!e&&!Array.isArray(z)){if((p=z.updateNodeOpt)!=null&&p.useAnimation&&(z.updateNodeOpt.useAnimation=!1),((f=this.collector)==null?void 0:f.getLocalId(E.key))===G&&((m=this.collector)!=null&&m.isOwn(E.key))){const $=z.selectIds;if($){const te=F.filter(ie=>{var _,J;return((_=this.collector)==null?void 0:_.getLocalId(ie))===G&&!((J=this.collector)!=null&&J.isOwn(ie))}).map(ie=>{var _;return(_=this.collector)==null?void 0:_.storage[this.viewId][i][ie]});let le=!1;for(const ie of te)for(let _=0;_<$.length;_++)(w=ie==null?void 0:ie.selectIds)!=null&&w.includes($[_])&&(delete $[_],le=!0);le&&(z.selectIds=$.filter(ie=>!!ie))}}(I=this.collector)==null||I.updateValue(E.key,E.data,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}}break;case 3:if(t=e?this.isNewEffectiveScene(E,F):this.isOldEffectiveScene(E,F,i),t){if(e&&Array.isArray(z)&&z.length===2){const $=z[1];if((N=$.updateNodeOpt)!=null&&N.useAnimation&&($.updateNodeOpt.useAnimation=!1),((C=this.collector)==null?void 0:C.getLocalId(E.key))===G&&((S=this.collector)!=null&&S.isOwn(E.key))){const te=$.selectIds;if(te){const le=F.filter(_=>{var J,de;return((J=this.collector)==null?void 0:J.getLocalId(_))===G&&!((de=this.collector)!=null&&de.isOwn(_))}).map(_=>{var J;return(J=this.collector)==null?void 0:J.storage[this.viewId][i][_]});let ie=!1;for(const _ of le)for(let J=0;J<te.length;J++)_!=null&&_.selectIds&&((v=_.selectIds)!=null&&v.includes(te[J]))&&(delete te[J],ie=!0);ie&&($.selectIds=te.filter(_=>!!_))}}(x=this.collector)==null||x.updateValue(Z,$,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}else if(!e&&Array.isArray(z)&&z.length===2){const $=z[0];if((L=$.updateNodeOpt)!=null&&L.useAnimation&&($.updateNodeOpt.useAnimation=!1),((b=this.collector)==null?void 0:b.getLocalId(E.key))===G&&((P=this.collector)!=null&&P.isOwn(E.key))){const te=$.selectIds;if(te){const le=F.filter(_=>{var J,de;return((J=this.collector)==null?void 0:J.getLocalId(_))===G&&!((de=this.collector)!=null&&de.isOwn(_))}).map(_=>{var J;return(J=this.collector)==null?void 0:J.storage[this.viewId][i][_]});let ie=!1;for(const _ of le)for(let J=0;J<te.length;J++)_!=null&&_.selectIds&&_.selectIds.includes(te[J])&&(delete te[J],ie=!0);ie&&($.selectIds=te.filter(_=>!!_))}}(A=this.collector)==null||A.updateValue(E.key,$,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}}break}}}};M(vt,"sdkCallBack"),M(vt,"MaxStackLength",20),M(vt,"waitTime",100);let ws=vt;function Nm(r){return r instanceof TouchEvent||r instanceof window.TouchEvent||(r==null?void 0:r.touches)&&(r==null?void 0:r.touches.length)||(r==null?void 0:r.changedTouches)&&(r==null?void 0:r.changedTouches.length)}function Ct(r){return Nm(r)&&(r.touches&&r.touches.length===1||r.changedTouches&&r.changedTouches.length===1)}function Ii(r){return r.touches&&r.touches.length?{x:r.touches[0].pageX,y:r.touches[0].pageY}:r.changedTouches&&r.changedTouches.length?{x:r.changedTouches[0].pageX,y:r.changedTouches[0].pageY}:{x:r.pageX,y:r.pageY}}class Wt{constructor(s){M(this,"internalMsgEmitter");M(this,"control");M(this,"mainView");M(this,"appViews",new Map);M(this,"undoTickerStart",(s,e)=>{const t=this.getView(e);t&&t.displayer&&t.focusScenePath&&t.displayer.commiter.undoTickerStart(s,t.focusScenePath)});M(this,"addExcludeIds",(s,e)=>{const t=this.getView(e);t&&t.displayer&&t.focusScenePath&&t.displayer.commiter.addExcludeIds(s)});const{control:e,internalMsgEmitter:t}=s;this.control=e,this.internalMsgEmitter=t,this.internalMsgEmitter.on("addUndoTicker",this.undoTickerStart),this.internalMsgEmitter.on("excludeIds",this.addExcludeIds)}get worker(){return this.control.worker}undo(){const s=this.focuedView;let e=0;if(s){const t=s.focusScenePath;e=s.displayer.commiter.undo(t)||0}return e}redo(){const s=this.focuedView;let e=0;if(s){const t=s.focusScenePath;e=s.displayer.commiter.redo(t)||0}return e}validator(s,e,t){var n;const i=O.clone(s[e]),o=O.clone(t);e==="focusScenePath"&&t&&!O.isEqual(i,o)&&(this.control.internalSceneChange(s.id,o),(n=this.focuedView)==null||n.displayer.commiter.onChangeScene()),e==="cameraOpt"&&!O.isEqual(i,o)&&this.control.internalCameraChange(s.id,o)}destroyAppView(s,e=!1){const t=this.appViews.get(s);t&&(this.control.textEditorManager.clear(s,e),t.displayer.destroy(),this.appViews.delete(s))}createMianView(s){this.mainView=new Proxy(s,{set:(e,t,i)=>(this.worker.isActive&&this.validator(e,t,i),e[t]=i,!0)})}createAppView(s){const e=s.id,t=new Proxy(s,{set:(i,o,n)=>(this.worker.isActive&&this.validator(i,o,n),i[o]=n,!0)});this.appViews.set(e,t)}isAppView(s){return s!==fe&&this.appViews.has(s)}getView(s){var e;return s===fe?this.mainView:(e=this.appViews)==null?void 0:e.get(s)}getCurScenePath(s){const e=this.getView(s);if(e)return e.focusScenePath}getAllViews(){return[this.mainView,...this.appViews.values()]}setViewScenePath(s,e){var t;if(s===fe&&this.mainView)this.mainView.focusScenePath=e;else{const i=s&&((t=this.appViews)==null?void 0:t.get(s))||void 0;i&&(i.focusScenePath=e)}}setViewData(s,e){var t;if(s===fe&&this.mainView)this.mainView.viewData=e;else{const i=s&&((t=this.appViews)==null?void 0:t.get(s))||void 0;i&&(i.viewData=e)}}setFocuedViewId(s){var e;this.focuedViewId=s,s===fe?this.focuedView=this.mainView:this.focuedView=s&&((e=this.appViews)==null?void 0:e.get(s))||void 0,this.worker.currentToolsData&&this.worker.currentToolsData.toolsType===T.Text&&this.activeTextEditor(s),this.control.cursor.onFocusViewChange(),this.focuedView&&this.focuedView.displayer.commiter.onFocusView()}setViewFocusScenePath(s,e){var i;let t;s===fe?t=this.mainView:t=(i=this.appViews)==null?void 0:i.get(s),t&&(t.focusScenePath=e)}destroy(){var s;this.internalMsgEmitter.off("addUndoTicker",this.undoTickerStart),this.internalMsgEmitter.off("excludeIds",this.addExcludeIds),(s=this.mainView)==null||s.displayer.destroy(),this.control.destroyMiniMap(fe),this.appViews.forEach(e=>{this.destroyAppView(e.id,!0),this.worker.destroyViewWorker(e.id),this.control.destroyMiniMap(e.id)})}setFocuedViewCameraOpt(s){if(this.focuedView){const e=this.focuedView.cameraOpt;O.isEqual(e,s)||(this.focuedView.cameraOpt=s)}}transformToOriginPoint(s,e){const t=this.getView(e);if(t!=null&&t.viewData){const i=t.viewData.convertToPointOnScreen(s[0],s[1]);return[i.x,i.y]}return s}transformToScenePoint(s,e){const t=this.getView(e);if(t!=null&&t.viewData){const i=t.viewData.convertToPointInWorld({x:s[0],y:s[1]});return[i.x,i.y]}return s}render(s){var e,t,i,o,n,a,c,l,u,h,d,g,p,f,m,w,I;for(const N of s){const{rect:C,imageBitmap:S,isClear:v,isUnClose:x,drawCanvas:L,clearCanvas:b,viewId:P}=N,A=(e=this.getView(P))==null?void 0:e.displayer;if(A&&C){const{dpr:E,canvasBgRef:R,canvasFloatRef:z,canvasServiceFloatRef:Z,canvasTopRef:ee}=A,F=Math.floor(C.w*E),$=Math.floor(C.h*E),te=C.x*E,le=C.y*E;if(v){switch(b){case me.TopFloat:(i=(t=ee.current)==null?void 0:t.getContext("2d"))==null||i.clearRect(te,le,F,$);break;case me.Float:(n=(o=z.current)==null?void 0:o.getContext("2d"))==null||n.clearRect(te,le,F,$);break;case me.ServiceFloat:(c=(a=Z.current)==null?void 0:a.getContext("2d"))==null||c.clearRect(te,le,F,$);break;case me.Bg:(u=(l=R.current)==null?void 0:l.getContext("2d"))==null||u.clearRect(te,le,F,$);break}continue}if(L&&S)switch(L){case me.TopFloat:(d=(h=ee.current)==null?void 0:h.getContext("2d"))==null||d.drawImage(S,0,0,F,$,te,le,F,$);break;case me.Float:{(p=(g=z.current)==null?void 0:g.getContext("2d"))==null||p.drawImage(S,0,0,F,$,te,le,F,$);break}case me.ServiceFloat:{(m=(f=Z.current)==null?void 0:f.getContext("2d"))==null||m.drawImage(S,0,0,F,$,te,le,F,$);break}case me.Bg:{(I=(w=R.current)==null?void 0:w.getContext("2d"))==null||I.drawImage(S,0,0,F,$,te,le,F,$);break}}if(x)continue;S==null||S.close()}}}showFloatBar(s,e,t){const i=this.getView(s),o=i==null?void 0:i.displayer.vDom;o&&o.showFloatBar(e,t)}activeTextEditor(s){const e=this.getView(s),t=e==null?void 0:e.displayer.vDom;t&&t.activeTextEditor()}unActiveTextEditor(s){const e=this.getView(s),t=e==null?void 0:e.displayer.vDom;t&&t.unActiveTextEditor()}showFloatBarBtn(s,e){const t=this.getView(s),i=t==null?void 0:t.displayer.vDom;i&&i.showFloatBarBtn(e)}updateTextEditorInfo(s,e){const t=this.getView(s),i=t==null?void 0:t.displayer.vDom;i&&i.updateTextEditorInfo(e)}setActiveMiniMap(s,e){const t=this.getView(s),i=t==null?void 0:t.displayer.vDom;i&&i.setActiveMiniMap(e&&s||void 0)}}M(Wt,"defaultCameraOpt",{centerX:0,centerY:0,scale:1}),M(Wt,"defaultScreenCanvasOpt",{autoRender:!1,contextType:"webgl2"}),M(Wt,"defaultLayerOpt",{offscreen:!0,handleEvent:!1,depth:!1});class Sm{constructor(s,e,t){M(this,"viewId");M(this,"control");M(this,"internalMsgEmitter");M(this,"commiter");M(this,"cachePoint");M(this,"cacheCursorPoint");M(this,"active",!0);M(this,"toolsKey");M(this,"mousedown",s=>{var e;if(this.active&&s.button===0&&this.viewId){this.worker.checkDrawingWork(this.viewId),this.reflashContainerOffset(),this.toolsKey=(e=this.worker.getCurrentToolsData())==null?void 0:e.toolsType;const t=this.getPoint(s);this.cachePoint=t,t&&this.worker.originalEventLintener(j.Start,t,this.viewId),document.addEventListener("mousemove",this.mousemove,!1),document.addEventListener("mouseleave",this.mouseup,!1),document.addEventListener("mouseup",this.mouseup,!1)}});M(this,"mousemove",s=>{if(this.active&&this.viewId){const e=this.getPoint(s);if(this.cachePoint=e,this.checkConsumeCount())return;e&&this.worker.originalEventLintener(j.Doing,e,this.viewId)}});M(this,"mouseup",s=>{if(this.active&&s.button===0&&this.viewId){const e=this.getPoint(s)||this.cachePoint;e?(this.worker.originalEventLintener(j.Done,e,this.viewId).finally(()=>{document.removeEventListener("mouseleave",this.mouseup,!1),document.removeEventListener("mousemove",this.mousemove,!1),document.removeEventListener("mouseup",this.mouseup,!1)}),this.cachePoint=void 0):(document.removeEventListener("mouseleave",this.mouseup,!1),document.removeEventListener("mousemove",this.mousemove,!1),document.removeEventListener("mouseup",this.mouseup,!1))}});M(this,"touchstart",s=>{var e;if(this.active){if(!Ct(s)){this.worker.unWritable(),this.viewId&&this.worker.removeDrawingWork(this.viewId);return}if(this.viewId){this.toolsKey=(e=this.worker.getCurrentToolsData())==null?void 0:e.toolsType,!this.worker.isAbled()&&this.toolsKey&&this.control.effectViewContainer(this.toolsKey),this.worker.checkDrawingWork(this.viewId),this.reflashContainerOffset();const t=this.getPoint(s);this.cachePoint=t,t&&(this.worker.originalEventLintener(j.Start,t,this.viewId),document.addEventListener("touchmove",this.touchmove,!1),document.addEventListener("touchend",this.touchend,!1))}}});M(this,"touchmove",s=>{if(this.active){if(!Ct(s)){this.worker.unWritable(),this.worker.removeDrawingWork(this.viewId);return}if(this.viewId){const e=this.getPoint(s);if(this.cachePoint=e,this.checkConsumeCount())return;e&&this.worker.originalEventLintener(j.Doing,e,this.viewId)}}});M(this,"touchend",s=>{if(this.active){if(!Ct(s)||!this.worker.isAbled()){this.worker.unWritable(),this.worker.removeDrawingWork(this.viewId);return}if(this.viewId){const e=this.getPoint(s)||this.cachePoint;e?(this.worker.originalEventLintener(j.Done,e,this.viewId).finally(()=>{document.removeEventListener("touchmove",this.touchmove,!1),document.removeEventListener("touchend",this.touchend,!1)}),this.cachePoint=void 0):(document.removeEventListener("touchmove",this.touchmove,!1),document.removeEventListener("touchend",this.touchend,!1))}}});M(this,"cursorMouseMove",O.throttle(s=>{const e=this.getPoint(s);this.cacheCursorPoint&&O.isEqual(e,this.cacheCursorPoint)||!this.viewId||(this.cacheCursorPoint=e,e&&this.worker.sendCursorEvent(e,this.viewId))},30,{leading:!1}));M(this,"cursorMouseLeave",O.throttle(()=>{this.viewId&&(this.cacheCursorPoint=[void 0,void 0],this.worker.sendCursorEvent(this.cacheCursorPoint,this.viewId))},30,{leading:!1}));M(this,"keydown",s=>{this.control.hotkeyManager.colloctHotkey(s)});this.viewId=s,this.control=e,this.internalMsgEmitter=t;const i={control:this.control,internalMsgEmitter:this.internalMsgEmitter,viewId:this.viewId};this.commiter=new ws(i)}get worker(){return this.control.worker}bindToolsClass(){var e,t;const s=(t=(e=this.worker)==null?void 0:e.currentToolsData)==null?void 0:t.toolsType;switch(s){case T.Text:case T.Pencil:case T.LaserPen:case T.Arrow:case T.Straight:case T.Rectangle:case T.Ellipse:case T.Star:case T.Polygon:case T.SpeechBalloon:case T.Eraser:case T.PencilEraser:case T.BitMapEraser:case T.Selector:this.eventTragetElement&&(this.eventTragetElement.className=`netless-whiteboard ${s===T.Selector?"cursor-selector":s===T.Text?"cursor-text":s===T.Eraser||s===T.PencilEraser||s===T.BitMapEraser?"cursor-eraser":s===T.Pencil||s===T.LaserPen?"cursor-pencil":"cursor-arrow"}`);break}}mountView(){this.setCanvassStyle(),this.control.viewContainerManager.mountView(this.viewId)}reflashContainerOffset(){this.eventTragetElement&&(this.containerOffset=this.getContainerOffset(this.eventTragetElement,{x:0,y:0}))}updateSize(){this.setCanvassStyle(),this.reflashContainerOffset()}setViewId(s){this.viewId=s}get parentElement(){var s;return(s=this.eventTragetElement)==null?void 0:s.parentElement}destroy(){this.eventTragetElement&&this.removeDisplayerEvent(this.eventTragetElement),this.vDom=void 0,this.control.cursor.clearViewCursor(this.viewId),this.internalMsgEmitter.removeAllListeners([ne.Cursor,this.viewId])}getPoint(s){const e=Ii(s);if(e&&O.isNumber(e.x)&&O.isNumber(e.y))return[e.x-this.containerOffset.x,e.y-this.containerOffset.y]}getActive(){this.active=!0}setActive(s){this.active=s}async stopEventHandler(){this.cachePoint&&(await this.worker.originalEventLintener(j.Done,this.cachePoint,this.viewId).finally(()=>{document.removeEventListener("mouseleave",this.mouseup,!1),document.removeEventListener("mousemove",this.mousemove,!1),document.removeEventListener("mouseup",this.mouseup,!1)}),this.cachePoint=void 0)}getTranslate(s){const t=(s.style.WebkitTransform||getComputedStyle(s,"").getPropertyValue("-webkit-transform")||s.style.transform||getComputedStyle(s,"").getPropertyValue("transform")).match(/-?[0-9]+\.?[0-9]*/g),i=t&&parseInt(t[0])||0,o=t&&parseInt(t[1])||0;return[i,o]}getContainerOffset(s,e){var o;const t=this.getTranslate(s);let i={x:e.x+s.offsetLeft-s.scrollLeft+t[0],y:e.y+s.offsetTop-s.scrollTop+t[1]};return(o=s.offsetParent)!=null&&o.nodeName&&s.offsetParent.nodeName!=="BODY"&&(i=this.getContainerOffset(s.offsetParent,i)),i}checkConsumeCount(){return this.cachePoint&&this.control.pluginOptions.bezier&&this.worker.getConsumeCount()>this.control.pluginOptions.bezier.maxDrawCount?(this.stopEventHandler().finally(()=>{this.worker.publicMsgEmitter.emit("forceStop",vs.longPencil,this.viewId)}),!0):!1}bindDisplayerEvent(s){s.addEventListener("mousedown",this.mousedown,!1),s.addEventListener("touchstart",this.touchstart,!1),s.addEventListener("mousemove",this.cursorMouseMove,!1),s.addEventListener("mouseleave",this.cursorMouseLeave,!1),s.addEventListener("keydown",this.keydown,!0)}removeDisplayerEvent(s){s.removeEventListener("mousedown",this.mousedown,!1),s.removeEventListener("touchstart",this.touchstart,!1),document.removeEventListener("mouseleave",this.mouseup,!1),document.removeEventListener("mousemove",this.mousemove,!1),document.removeEventListener("mouseup",this.mouseup,!1),document.removeEventListener("touchmove",this.touchmove,!1),document.removeEventListener("touchend",this.touchend,!1),s.removeEventListener("mousemove",this.cursorMouseMove,!1),s.removeEventListener("mouseleave",this.cursorMouseLeave,!1),s.removeEventListener("keydown",this.keydown,!0)}}class Nn{constructor(s,e){M(this,"viewId",fe);M(this,"control");M(this,"internalMsgEmitter");M(this,"commiter");M(this,"cachePoint");M(this,"cacheCursorPoint");M(this,"active",!0);M(this,"toolsKey");M(this,"mousedown",s=>{var e;if(this.active&&s.button===0){this.worker.checkDrawingWork(this.viewId),this.reflashContainerOffset();const t=this.getPoint(s);this.cachePoint=t,this.toolsKey=(e=this.worker.getCurrentToolsData())==null?void 0:e.toolsType,t&&(this.worker.originalEventLintener(j.Start,t,this.viewId),document.addEventListener("mousemove",this.mousemove,!1),document.addEventListener("mouseleave",this.mouseup,!1),document.addEventListener("mouseup",this.mouseup,!1))}});M(this,"mousemove",s=>{if(!this.active)return;const e=this.getPoint(s);this.cachePoint=e,!this.checkConsumeCount()&&e&&this.worker.originalEventLintener(j.Doing,e,this.viewId)});M(this,"mouseup",s=>{if(this.active&&s.button===0){const e=this.getPoint(s)||this.cachePoint;e?(this.worker.originalEventLintener(j.Done,e,this.viewId).finally(()=>{document.removeEventListener("mouseleave",this.mouseup,!1),document.removeEventListener("mousemove",this.mousemove,!1),document.removeEventListener("mouseup",this.mouseup,!1)}),this.cachePoint=void 0):(document.removeEventListener("mouseleave",this.mouseup,!1),document.removeEventListener("mousemove",this.mousemove,!1),document.removeEventListener("mouseup",this.mouseup,!1))}});M(this,"touchstart",s=>{var t;if(!this.active)return;if(!Ct(s)){this.worker.unWritable(),this.viewId&&this.worker.removeDrawingWork(this.viewId);return}this.toolsKey=(t=this.worker.getCurrentToolsData())==null?void 0:t.toolsType,!this.worker.isAbled()&&this.toolsKey&&this.control.effectViewContainer(this.toolsKey),this.worker.checkDrawingWork(this.viewId),this.reflashContainerOffset();const e=this.getPoint(s);this.cachePoint=e,e&&(this.worker.originalEventLintener(j.Start,e,this.viewId),document.addEventListener("touchmove",this.touchmove,!1),document.addEventListener("touchend",this.touchend,!1))});M(this,"touchmove",s=>{if(!this.active)return;if(!Ct(s)){this.worker.unWritable(),this.viewId&&this.worker.removeDrawingWork(this.viewId);return}const e=this.getPoint(s);this.cachePoint=e,!this.checkConsumeCount()&&e&&this.worker.originalEventLintener(j.Doing,e,this.viewId)});M(this,"touchend",s=>{if(!this.active)return;if(!Ct(s)||!this.worker.isAbled()){this.worker.unWritable(),this.worker.removeDrawingWork(this.viewId);return}const e=this.getPoint(s)||this.cachePoint;e?(this.worker.originalEventLintener(j.Done,e,this.viewId).finally(()=>{document.removeEventListener("touchmove",this.touchmove,!1),document.removeEventListener("touchend",this.touchend,!1)}),this.cachePoint=void 0):(document.removeEventListener("touchmove",this.touchmove,!1),document.removeEventListener("touchend",this.touchend,!1))});M(this,"cursorMouseMove",O.throttle(s=>{const e=this.getPoint(s);this.cacheCursorPoint&&O.isEqual(e,this.cacheCursorPoint)||(this.cacheCursorPoint=e,e&&this.worker.sendCursorEvent(e,this.viewId))},30,{leading:!1}));M(this,"cursorMouseLeave",O.throttle(()=>{this.cacheCursorPoint=[void 0,void 0],this.worker.sendCursorEvent(this.cacheCursorPoint,this.viewId)},30,{leading:!1}));M(this,"keydown",s=>{this.control.hotkeyManager.colloctHotkey(s)});this.control=s,this.internalMsgEmitter=e;const t={control:this.control,internalMsgEmitter:this.internalMsgEmitter,viewId:this.viewId};this.commiter=new ws(t)}get worker(){return this.control.worker}bindToolsClass(){var i,o;const s=(o=(i=this.worker)==null?void 0:i.currentToolsData)==null?void 0:o.toolsType,e=this.control.renderControl.isWritable,t=this.worker.isAbled();switch(s){case T.Text:case T.Pencil:case T.LaserPen:case T.Arrow:case T.Straight:case T.Rectangle:case T.Ellipse:case T.Star:case T.Polygon:case T.SpeechBalloon:case T.Eraser:case T.PencilEraser:case T.BitMapEraser:case T.Selector:this.eventTragetElement&&(this.eventTragetElement.className=e&&t?`netless-whiteboard ${s===T.Selector?"cursor-selector":s===T.Text?"cursor-text":s===T.Eraser||s===T.PencilEraser||s===T.BitMapEraser?"cursor-eraser":s===T.Pencil||s===T.LaserPen?"cursor-pencil":"cursor-arrow"}`:"netless-whiteboard");break}}mountView(){this.setCanvassStyle(),this.control.viewContainerManager.mountView(this.viewId)}updateSize(){this.setCanvassStyle()}reflashContainerOffset(){this.eventTragetElement&&(this.containerOffset=this.getContainerOffset(this.eventTragetElement,{x:0,y:0}))}get parentElement(){var s;return(s=this.eventTragetElement)==null?void 0:s.parentElement}destroy(){this.eventTragetElement&&this.removeDisplayerEvent(this.eventTragetElement),this.vDom=void 0,this.control.cursor.destroy(),this.internalMsgEmitter.removeAllListeners([ne.Cursor,this.viewId])}getPoint(s){const e=Ii(s);if(e&&O.isNumber(e.x)&&O.isNumber(e.y))return[e.x-this.containerOffset.x,e.y-this.containerOffset.y]}getActive(){return this.active}setActive(s){this.active=s}async stopEventHandler(){this.cachePoint&&(await this.worker.originalEventLintener(j.Done,this.cachePoint,this.viewId).finally(()=>{document.removeEventListener("mouseleave",this.mouseup,!1),document.removeEventListener("mousemove",this.mousemove,!1),document.removeEventListener("mouseup",this.mouseup,!1)}),this.cachePoint=void 0)}getTranslate(s){const t=(s.style.WebkitTransform||getComputedStyle(s,"").getPropertyValue("-webkit-transform")||s.style.transform||getComputedStyle(s,"").getPropertyValue("transform")).match(/-?[0-9]+\.?[0-9]*/g),i=t&&parseInt(t[0])||0,o=t&&parseInt(t[1])||0;return[i,o]}getContainerOffset(s,e){var o;const t=this.getTranslate(s);let i={x:e.x+s.offsetLeft-s.scrollLeft+t[0],y:e.y+s.offsetTop-s.scrollTop+t[1]};return(o=s.offsetParent)!=null&&o.nodeName&&s.offsetParent.nodeName!=="BODY"&&(i=this.getContainerOffset(s.offsetParent,i)),i}checkConsumeCount(){const s=this.worker.getConsumeCount();return this.cachePoint&&this.toolsKey&&this.toolsKey===T.Pencil&&this.control.pluginOptions.bezier&&s>this.control.pluginOptions.bezier.maxDrawCount?(this.stopEventHandler().finally(()=>{this.worker.publicMsgEmitter.emit("forceStop",vs.longPencil,this.viewId)}),!0):!1}bindDisplayerEvent(s){s.addEventListener("mousedown",this.mousedown,!1),s.addEventListener("touchstart",this.touchstart,!1),s.addEventListener("mousemove",this.cursorMouseMove,!1),s.addEventListener("mouseleave",this.cursorMouseLeave,!1),s.addEventListener("keydown",this.keydown,!0)}removeDisplayerEvent(s){s.removeEventListener("mousedown",this.mousedown,!1),document.removeEventListener("mouseleave",this.mouseup,!1),document.removeEventListener("mousemove",this.mousemove,!1),document.removeEventListener("mouseup",this.mouseup,!1),s.removeEventListener("touchstart",this.touchstart,!1),document.removeEventListener("touchmove",this.touchmove,!1),document.removeEventListener("touchend",this.touchend,!1),s.removeEventListener("mousemove",this.cursorMouseMove,!1),s.removeEventListener("mouseleave",this.cursorMouseLeave,!1),s.removeEventListener("keydown",this.keydown,!0)}}const Cm="index-module__Container__nLsM3",km="index-module__CanvasBox__j2Xe-",xm="index-module__FloatCanvas__d1YR7",Dm="index-module__TopFloatCanvas__7IaCw",Lm="index-module__CanvasBoxSub__hcMeK",bm="index-module__SnapshotBox__--eeE",jm="index-module__FloatBar__cm-EL",Am="index-module__RotateBtn__HSSkf",Pm="index-module__ResizeBtn__yjvda",zm="index-module__CursorBox__2UHvI",Em="index-module__TextEditorContainer__Qm8KC",Om="index-module__ResizeTowBox__HOllX",Rm="index-module__FloatBarBtn__FJrOG",We={Container:Cm,CanvasBox:km,FloatCanvas:xm,TopFloatCanvas:Dm,CanvasBoxSub:Lm,SnapshotBox:bm,FloatBar:jm,RotateBtn:Am,ResizeBtn:Pm,CursorBox:zm,TextEditorContainer:Em,ResizeTowBox:Om,FloatBarBtn:Rm},Wm={delete:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDZ2NmEyIDIgMCAwIDEtMiAySDZhMiAyIDAgMCAxLTItMlY2aDBtMS0yYTIgMiAwIDAgMSAyLTJoMmEyIDIgMCAwIDEgMiAyaDBNMyA0aDEwIiBzdHJva2U9IiM0NDRFNjAiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==",duplicate:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgc3Ryb2tlPSIjNDQ0RTYwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjxwYXRoIGQ9Ik0xMSAySDZhMSAxIDAgMCAwLTEgMXY4YTEgMSAwIDAgMCAxIDFoNmExIDEgMCAwIDAgMS0xVjRoMGwtMi0yeiIg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91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=",bold:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTQuNSAySDhhMi41IDIuNSAwIDAgMSAwIDVINS41aDBtLTEgMGg0YTMgMyAwIDAgMSAwIDZoLTQgMG0wIDFWMiIgc3Ryb2tlPSIjNDQ0RTYwIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","underline-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDJ2NWE0IDQgMCAxIDEtOCAwVjJoME0zIDE0aDEwIiBzdHJva2U9IiMzMzgxRkYiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==",underline:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDJ2NWE0IDQgMCAxIDEtOCAwVjJoME0zIDE0aDEwIiBzdHJva2U9IiM0NDRFNjAiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==","line-through-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTQgOGg4bS0xLTNhMyAzID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gMCAwIDAgMTM4LjY2NjY2Ny0xMzguNjY2NjY3aC02NHpNMjEzLjMzMzMzMyA4NjRhNzQuNjY2NjY3IDc0LjY2NjY2NyAwIDAgMS03NC42NjY2NjYtNzQuNjY2NjY3aC02NEExMzguNjY2NjY3IDEzOC42NjY2NjcgMCAwIDAgMjEzLjMzMzMzMyA5Mjh2LTY0ek0yNDUuMzMzMzMzIDY4Mi42NjY2Njd2LTIzNC42NjY2NjdoLTY0VjY4Mi42NjY2NjdoNjR6IG0tNTQuNjEzMzMzLTIxMi4wNTMzMzRsODUuMzMzMzMzIDg1LjMzMzMzNCA0NS4yMjY2NjctNDUuMjI2NjY3LTg1LjMzMzMzMy04NS4zMzMzMzMtNDUuMjI2NjY3IDQ1LjIyNjY2NnogbTAtNDUuMjI2NjY2bC04NS4zMzMzMzMgODUuMzMzMzMzIDQ1LjIyNjY2NiA0NS4yMjY2NjcgODUuMzMzMzM0LTg1LjMzMzMzNC00NS4yMjY2NjctNDUuMjI2NjY2eiIgIGZpbGw9IiM0NDRFNjAiPjwvcGF0aD48L3N2Zz4="};function Ee(r){return Wm[r]}const Ym=r=>{const{workIds:s,mananger:e}=r;return y.createElement("div",{className:"button normal-button",style:{touchAction:"none"},onPointerUp:t=>{t.cancelable&&t.preventDefault(),t.stopPropagation(),t.nativeEvent.stopImmediatePropagation(),ae.emitMethod(ne.MainEngine,V.DeleteNode,{workIds:s||[G],viewId:e.viewId})}},y.createElement("img",{alt:"icon",src:Ee("delete")}))},Um=r=>{const{workIds:s,viewId:e}=r;return y.createElement("div",{className:"button normal-button",onPointerUp:t=>{t.stopPropagation(),ae.emitMethod(ne.MainEngine,V.CopyNode,{workIds:s||[G],viewId:e})}},y.createElement("img",{alt:"icon",src:Ee("duplicate")}))},yo=r=>{const{icon:s,onPointerUpHandler:e}=r;return y.createElement("div",{className:"button normal-button",onPointerUp:e},y.createElement("img",{src:Ee(s)}))},Bm=r=>{const{open:s,setOpen:e,floatBarRef:t}=r,{floatBarData:i,mananger:o}=y.useContext(Se),[n,a]=y.useState([]),c=y.useMemo(()=>{if(t!=null&&t.current&&O.isNumber(i==null?void 0:i.y)&&(o!=null&&o.height)){if(t.current.offsetTop&&t.current.offsetTop+i.y>180){const h={};return h.top="inherit",h.bottom=50,h}else if(!t.current.offsetTop&&(o==null?void 0:o.height)-t.current.offsetTop-i.y<120){const h={};return h.top="inherit",h.bottom=50,h}}},[t==null?void 0:t.current,i,o]),l=y.useMemo(()=>s?y.createElement("div",{className:"image-layer-menu",style:c},y.createElement(yo,{icon:"to-top",onPointerUpHandler:h=>{h.stopPropagation(),ae.emitMethod(ne.MainEngine,V.ZIndexNode,{workIds:[G],layer:qt.Top,viewId:o==null?void 0:o.viewId})}}),y.createElement(yo,{icon:"to-bottom",onPointerUpHandler:h=>{h.stopPropagation(),ae.emitMethod(ne.MainEngine,V.ZIndexNode,{workIds:[G],layer:qt.Bottom,viewId:o==null?void 0:o.viewId})}})):null,[s,c]),u=h=>{h.stopPropagation(),h.nativeEvent.stopImmediatePropagation(),e(!s)};return y.useEffect(()=>{O.isEqual(i==null?void 0:i.selectIds,n)||i!=null&&i.selectIds&&!O.isEqual(i==null?void 0:i.selectIds,n)&&(a(i==null?void 0:i.selectIds),e(!1))},[s,i,n,e]),y.createElement("div",{className:`button normal-button ${s&&"active"}`,onPointerUp:u},l,y.createElement("img",{alt:"icon",src:Ee(s?"layer-pressed":"layer")}))},is=r=>{r.stopPropagation(),r.nativeEvent.stopImmediatePropagation()},Fm=()=>y.createElement("svg",{style:{marginLeft:"2px"},viewBox:"0 0 1025 1024",width:"14",height:"14"},y.createElement("path",{d:"M1016.5248 493.8752c-9.984-9.984-26.2144-9.984-36.1984 0l-183.6032 183.6032c-29.952 29.952-78.6944 29.952-108.5952 0l-239.2064-239.2064c-14.4384-14.4384-22.3744-33.6896-22.3744-54.3232s7.936-39.8848 22.3744-54.3232l183.6032-183.6032c9.984-9.984 9.984-26.2144 0-36.1984s-26.2144-9.984-36.1984 0l-183.6032 183.6032c-24.1152 24.1152-37.376 56.2176-37.376 90.5216 0 14.592 2.4576 28.8256 7.0656 42.1888l-374.8864 374.8864c-4.8128 4.8128-7.4752 11.3152-7.4752 18.1248l0 76.8c0 14.1312 11.4688 25.6 25.6 25.6l486.4 0c6.8096 0 13.312-2.7136 18.1248-7.4752l170.0864-170.0864c13.3632 4.6592 27.5968 7.0656 42.1888 7.0656 34.2528 0 66.4064-13.2608 90.5216-37.376l183.6032-183.6032c9.984-9.984 9.984-26.2144 0-36.1984zM501.4016 870.4l-450.2016 0 0-40.6016 358.5024-358.5024c1.024 1.0752 1.9968 2.1504 3.0208 3.1744l239.2064 239.2064c1.024 1.024 2.0992 2.048 3.1744 3.0208l-153.7024 153.7024z",fill:"#000000"})),Sn=r=>{const{activeColor:s,onPointerUpHandler:e}=r;return y.createElement("div",{className:`font-color-button ${s==="transparent"?"active":""}`,onPointerUp:e},y.createElement("div",{className:"circle none"}))},As=r=>{const{color:s,activeColor:e,onPointerUpHandler:t}=r;return y.createElement("div",{className:`font-color-button ${s===e?"active":""}`,onPointerUp:t},y.createElement("div",{className:"circle",style:{backgroundColor:je(s,1)}}))},Ps=r=>{const{opacity:s,activeColor:e,setCurOpacity:t}=r,[i,o]=y.useState({x:108,y:0}),n=y.useRef(0);if(y.useEffect(()=>{o({x:s*100+8,y:0})},[]),!e)return null;const a=(h,d)=>{const g=Math.min(Math.max(h-8,0),100)/100;(s!==g||d===j.Done)&&t(g,e,d)},c=(h,d)=>{d.x!==(i==null?void 0:i.x)&&o({x:d.x,y:0}),!n.current&&(n.current=setTimeout(()=>{n.current=0,a(d.x,j.Doing)},100))},l=()=>{t(s,e,j.Start)},u=(h,d)=>{d.x!==(i==null?void 0:i.x)&&o({x:d.x,y:0}),n.current&&(clearTimeout(n.current),n.current=0),a(d.x,j.Done)};return y.createElement("div",{className:"font-color-opacity",style:{marginLeft:"10px"},onPointerUp:h=>{n.current&&(clearTimeout(n.current),n.current=0);const d=h.nativeEvent.offsetX,g=Math.min(Math.max(d-12,0),100)/100;o({x:g*100+8,y:0}),t(g,e,j.Done)}},y.createElement("div",{className:"range-color",style:{background:`linear-gradient(to right, ${je(e,0)}, ${je(e,1)})`}}),y.createElement("div",{className:"range-opacity"},y.createElement(Yt,{bounds:"parent",axis:"x",position:i,onDrag:c,onStart:l,onStop:u},y.createElement("div",{className:"circle",style:{backgroundColor:je(e,s)},onPointerUp:is}))))},Vm=r=>{const{min:s,max:e,activeNumber:t,setActiveNumber:i,color:o}=r,[n,a]=y.useState({x:108,y:0}),c=y.useRef(0);if(y.useEffect(()=>{const g=Math.ceil((t-s)/(e-s)*100)+8;a({x:g,y:0})},[]),!t)return null;const l=(g,p)=>{const f=Math.ceil(Math.max(g-8,0)/100*(e-s)+s);(t!==f||p===j.Done)&&i(f,p)},u=(g,p)=>{p.x!==(n==null?void 0:n.x)&&a({x:p.x,y:0}),!c.current&&(c.current=setTimeout(()=>{c.current=0,l(p.x,j.Doing)},100))},h=()=>{i(t,j.Start)},d=(g,p)=>{p.x!==(n==null?void 0:n.x)&&a({x:p.x,y:0}),c.current&&(clearTimeout(c.current),c.current=0),l(p.x,j.Done)};return y.createElement("div",{className:"font-color-opacity",style:{marginLeft:"10px"},onPointerUp:g=>{c.current&&(clearTimeout(c.current),c.current=0);const p=g.nativeEvent.offsetX,f=Math.ceil(Math.max(p-12,0)/100*(e-s)+s),m=Math.ceil((f-s)/(e-s)*100)+8;a({x:m,y:0}),i(f,j.Done)}},y.createElement("div",{className:"range-color",style:{backgroundColor:o}}),y.createElement("div",{className:"range-opacity"},y.createElement(Yt,{bounds:"parent",axis:"x",position:n,onDrag:u,onStart:h,onStop:d},y.createElement("div",{className:"circle",style:{backgroundColor:o},onPointerUp:is},y.createElement("div",{className:"range-opacity-data-icon"},t)))))},Qm=r=>{const{useStroke:s,color:e,activeStrokeType:t,setStrokeType:i}=r;return y.createElement("div",{className:"stroke-type-box"},!!s&&y.createElement("div",{className:`stroke-type-box-item Stroke ${t===oe.Stroke&&"active"}`,style:{backgroundColor:e},onPointerUp:()=>{i(oe.Stroke)}}),y.createElement("div",{className:`stroke-type-box-item Normal ${t===oe.Normal&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(oe.Normal)}}),y.createElement("div",{className:`stroke-type-box-item Dotted ${t===oe.Dotted&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(oe.Dotted)}}),y.createElement("div",{className:`stroke-type-box-item LongDotted ${t===oe.LongDotted&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(oe.LongDotted)}}))},Zm=r=>{var I,N;const{open:s,setOpen:e,floatBarRef:t}=r,{floatBarData:i,floatBarColors:o,mananger:n,setFloatBarData:a}=y.useContext(Se),[c,l]=y.useState(),[u,h]=y.useState(1);y.useEffect(()=>{if(i!=null&&i.strokeColor){const[C,S]=bs(i.strokeColor);l(C),h(S)}},[i]);const d=y.useMemo(()=>{if(t!=null&&t.current&&i&&O.isNumber(i==null?void 0:i.y)&&(n!=null&&n.height)){if(t.current.offsetTop&&t.current.offsetTop+i.y>180){const C={};return C.top="inherit",C.bottom=50,C}else if(!t.current.offsetTop&&(n==null?void 0:n.height)-t.current.offsetTop-i.y<120){const C={};return C.top="inherit",C.bottom=50,C}}},[i,t,n==null?void 0:n.height]),g=y.useMemo(()=>y.createElement(Ps,{key:"strokeColors",opacity:u,activeColor:c,setCurOpacity:(C,S,v)=>{h(C);const x=je(S,C);i!=null&&i.strokeColor&&a({strokeColor:x}),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:[G],strokeColor:x,workState:v,viewId:n==null?void 0:n.viewId})}}),[u,c,i==null?void 0:i.strokeColor,n==null?void 0:n.viewId,a]),p=y.useMemo(()=>{var C,S;return c&&i&&i.thickness?y.createElement(Vm,{key:"strokeThickness",min:Math.min(i.thickness,((C=n==null?void 0:n.control.pluginOptions.strokeWidth)==null?void 0:C.min)||1),max:Math.max(i.thickness,((S=n==null?void 0:n.control.pluginOptions.strokeWidth)==null?void 0:S.max)||10),activeNumber:i.thickness,setActiveNumber:(v,x)=>{i!=null&&i.thickness&&a({thickness:v}),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:[G],thickness:v,workState:x,viewId:n==null?void 0:n.viewId})},color:c}):null},[c,i,(I=n==null?void 0:n.control.pluginOptions.strokeWidth)==null?void 0:I.max,(N=n==null?void 0:n.control.pluginOptions.strokeWidth)==null?void 0:N.min,n==null?void 0:n.viewId,a]),f=y.useMemo(()=>c&&i&&(i!=null&&i.strokeType)?y.createElement(Qm,{key:"strokeType",useStroke:i==null?void 0:i.useStroke,activeStrokeType:i.strokeType,setStrokeType:C=>{i.strokeType&&a({strokeType:C}),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:[G],strokeType:C,workState:j.Done,viewId:n==null?void 0:n.viewId})},color:c}):null,[c,i,n==null?void 0:n.viewId,a]),m=y.useMemo(()=>s?y.createElement("div",{className:"font-colors-menu",style:d,onPointerUp:C=>{C.stopPropagation(),C.nativeEvent.stopImmediatePropagation()}},f,p,y.createElement("div",{className:"font-colors-line"}),o.concat().map((C,S)=>{const v=ss(...C);return y.createElement(As,{key:S,color:v,activeColor:c,onPointerUpHandler:x=>{x.stopPropagation(),l(v);const L=je(v,u);i!=null&&i.strokeColor&&(i.strokeColor=L,a({strokeColor:L})),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:[G],workState:j.Done,strokeColor:L,viewId:n==null?void 0:n.viewId})}})}),g):null,[s,d,f,p,o,g,c,u,i,n==null?void 0:n.viewId,a]),w=y.useMemo(()=>c?y.createElement("div",{className:"color-bar-ring",style:{backgroundColor:je(c,u)}},y.createElement("div",{className:"circle"})):null,[c,u]);return y.createElement("div",{className:`button normal-button font-colors-icon ${s&&"active"}`,onPointerUp:C=>{C.stopPropagation(),C.nativeEvent.stopImmediatePropagation(),e(!s)}},w,m)},Hm=r=>{const{open:s,setOpen:e,floatBarRef:t}=r,{floatBarData:i,floatBarColors:o,mananger:n,setFloatBarData:a}=y.useContext(Se),[c,l]=y.useState(),[u,h]=y.useState(1);y.useEffect(()=>{if(i!=null&&i.fillColor){const[m,w]=(i==null?void 0:i.fillColor)==="transparent"&&["transparent",1]||bs(i.fillColor);l(m),h(w)}},[i]);const d=y.useMemo(()=>{if(t!=null&&t.current&&O.isNumber(i==null?void 0:i.y)&&(n!=null&&n.height)){if(t.current.offsetTop&&t.current.offsetTop+i.y>200){const m={};return m.top="inherit",m.bottom=50,m}else if(!t.current.offsetTop&&(n==null?void 0:n.height)-t.current.offsetTop-i.y<140){const m={};return m.top="inherit",m.bottom=50,m}}},[t,i,n==null?void 0:n.height]),g=y.useMemo(()=>c&&c!=="transparent"?y.createElement(Ps,{key:"fillColors",opacity:u||0,activeColor:c,setCurOpacity:(m,w,I)=>{h(m);const N=je(w,m);i!=null&&i.fillColor&&(i.fillColor=N,a({fillColor:N})),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:[G],fillColor:c&&je(w,m),workState:I,viewId:n==null?void 0:n.viewId})}}):null,[c,u,i,n==null?void 0:n.viewId,a]),p=y.useMemo(()=>s?y.createElement("div",{className:"font-colors-menu",style:d,onPointerUp:m=>{m.stopPropagation(),m.nativeEvent.stopImmediatePropagation()}},y.createElement(Sn,{activeColor:c,onPointerUpHandler:m=>{m.stopPropagation(),l("transparent");const w="transparent";i!=null&&i.fillColor&&(i.fillColor=w,a({fillColor:w})),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:[G],workState:j.Done,fillColor:w,viewId:n==null?void 0:n.viewId})}}),o.map((m,w)=>{const I=ss(...m);return y.createElement(As,{key:w,color:I,activeColor:c,onPointerUpHandler:N=>{N.cancelable&&N.preventDefault(),N.stopPropagation(),l(I);const C=je(I,u);i!=null&&i.fillColor&&(i.fillColor=C,a({fillColor:C})),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:[G],workState:j.Done,fillColor:C,viewId:n==null?void 0:n.viewId})}})}),g):null,[s,d,c,o,g,i,n==null?void 0:n.viewId,a,u]),f=y.useMemo(()=>{const m=c&&c!=="transparent"&&je(c,u)||"transparent";return y.createElement("div",{className:"color-bar-fill"},y.createElement("div",{className:"circle",style:{backgroundColor:m}}))},[c,u]);return y.createElement("div",{className:`button normal-button font-colors-icon ${s&&"active"}`,onPointerUp:m=>{m.stopPropagation(),m.nativeEvent.stopImmediatePropagation(),e(!s)}},f,p)},Gm=r=>{const{open:s,setOpen:e,textOpt:t,workIds:i,floatBarRef:o}=r,{floatBarColors:n,mananger:a,setFloatBarData:c,floatBarData:l}=y.useContext(Se),[u,h]=y.useState(),[d,g]=y.useState(1);y.useEffect(()=>{if(t!=null&&t.fontColor){const[I,N]=(t==null?void 0:t.fontColor)==="transparent"&&["transparent",0]||bs(t.fontColor);h(I),g(N)}},[t==null?void 0:t.fontColor]);const p=y.useMemo(()=>{if(o!=null&&o.current&&l&&O.isNumber(l==null?void 0:l.y)&&(a!=null&&a.height)){if(o.current.offsetTop&&o.current.offsetTop+l.y>180){const I={};return I.top="inherit",I.bottom=50,I}else if(!o.current.offsetTop&&(a==null?void 0:a.height)-o.current.offsetTop-l.y<120){const I={};return I.top="inherit",I.bottom=50,I}}},[o,l,a==null?void 0:a.height]),f=y.useMemo(()=>u&&u!=="transparent"?y.createElement(Ps,{key:"fontColors",opacity:d,activeColor:u,setCurOpacity:(I,N,C)=>{g(I);const S=je(N,I);l!=null&&l.textOpt&&(l.textOpt.fontColor=S,c({textOpt:l.textOpt})),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:i||[G],fontColor:u&&S,workState:C,viewId:a==null?void 0:a.viewId})}}):null,[u,d,a==null?void 0:a.control.room,a==null?void 0:a.viewId,l==null?void 0:l.textOpt,i]),m=y.useMemo(()=>s?y.createElement("div",{className:"font-colors-menu",style:p,onPointerUp:I=>{I.stopPropagation(),I.nativeEvent.stopImmediatePropagation()}},n.map((I,N)=>{const C=ss(...I);return y.createElement(As,{key:N,color:C,activeColor:u,onPointerUpHandler:S=>{S.stopPropagation(),h(C);const v=je(C,d);l!=null&&l.textOpt&&(l.textOpt.fontColor=v,c({textOpt:l.textOpt})),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:i||[G],workState:j.Done,fontColor:v,viewId:a==null?void 0:a.viewId})}})}),f):null,[s,n,f,u,d,l==null?void 0:l.textOpt,i,a==null?void 0:a.viewId,p]),w=y.useMemo(()=>{const I=u&&u!=="transparent"&&je(u,d)||"transparent";return y.createElement("div",{className:"color-bar"},y.createElement("div",{className:"color-bar-color",style:{backgroundColor:I}}))},[u,d]);return y.createElement("div",{className:`button normal-button font-colors-icon ${s&&"active"}`,onPointerUp:I=>{I.stopPropagation(),I.nativeEvent.stopImmediatePropagation(),e(!s)}},y.createElement("img",{alt:"icon",src:Ee("font-colors")}),w,m)},$m=r=>{const{open:s,setOpen:e,textOpt:t,workIds:i,floatBarRef:o}=r,{floatBarColors:n,mananger:a,setFloatBarData:c,floatBarData:l}=y.useContext(Se),[u,h]=y.useState(),[d,g]=y.useState(1);y.useEffect(()=>{if(t!=null&&t.fontBgColor){const[I,N]=(t==null?void 0:t.fontBgColor)==="transparent"&&["transparent",1]||bs(t.fontBgColor);h(I),g(N)}},[t==null?void 0:t.fontBgColor]);const p=y.useMemo(()=>{if(o!=null&&o.current&&l&&O.isNumber(l==null?void 0:l.y)&&(a!=null&&a.height)){if(o.current.offsetTop&&o.current.offsetTop+l.y>180){const I={};return I.top="inherit",I.bottom=50,I}else if(!o.current.offsetTop&&(a==null?void 0:a.height)-o.current.offsetTop-l.y<120){const I={};return I.top="inherit",I.bottom=50,I}}},[o,l,a==null?void 0:a.height]),f=y.useMemo(()=>u&&u!=="transparent"?y.createElement(Ps,{key:"fontBgColor",opacity:d||0,activeColor:u,setCurOpacity:(I,N,C)=>{g(I);const S=je(N,I);l!=null&&l.textOpt&&(l.textOpt.fontBgColor=S,c({textOpt:l.textOpt})),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:i||[G],fontBgColor:u&&je(N,I),workState:C,viewId:a==null?void 0:a.viewId})}}):null,[u,d,l==null?void 0:l.textOpt,i,a==null?void 0:a.viewId,c]),m=y.useMemo(()=>s?y.createElement("div",{className:"font-colors-menu",style:p,onPointerUp:I=>{I.stopPropagation(),I.nativeEvent.stopImmediatePropagation()}},y.createElement(Sn,{activeColor:u,onPointerUpHandler:I=>{I.stopPropagation();const N="transparent";h(N),l!=null&&l.textOpt&&(l.textOpt.fontBgColor=N,c({textOpt:l.textOpt})),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:i||[G],workState:j.Done,fontBgColor:N,viewId:a==null?void 0:a.viewId})}}),n.map((I,N)=>{const C=ss(...I);return y.createElement(As,{key:N,color:C,activeColor:u,onPointerUpHandler:S=>{S.stopPropagation(),h(C);const v=je(C,d);l!=null&&l.textOpt&&(l.textOpt.fontBgColor=v,c({textOpt:l.textOpt})),ae.emitMethod(ne.MainEngine,V.SetColorNode,{workIds:i||[G],workState:j.Done,fontBgColor:je(C,d),viewId:a==null?void 0:a.viewId})}})}),f):null,[s,n,f,d,u,l==null?void 0:l.textOpt,i,a==null?void 0:a.viewId,p]),w=y.useMemo(()=>{const I=u&&u!=="transparent"&&je(u,d)||"transparent";return y.createElement("div",{className:"color-bar",style:{marginTop:0}},y.createElement("div",{className:"color-bar-color",style:{backgroundColor:I}}))},[u,d]);return y.createElement("div",{className:`button normal-button font-colors-icon ${s&&"active"}`,onPointerUp:I=>{I.stopPropagation(),I.nativeEvent.stopImmediatePropagation(),e(!s)}},y.createElement(Fm,null),w,m)},Xm=r=>{const{bold:s,setBold:e,workIds:t,viewId:i}=r,o=n=>{const a=s==="bold"?"normal":"bold";n==null||n.stopPropagation(),e(a),ae.emitMethod(ne.MainEngine,V.SetFontStyle,{workIds:t,viewId:i,bold:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:Ee(s==="bold"?"bold-active":"bold")}))},Jm=r=>{const{underline:s,setUnderline:e,workIds:t,viewId:i}=r,o=n=>{const a=!s;n==null||n.stopPropagation(),e(a),ae.emitMethod(ne.MainEngine,V.SetFontStyle,{workIds:t,viewId:i,underline:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:Ee(s?"underline-active":"underline")}))},qm=r=>{const{lineThrough:s,setLineThrough:e,workIds:t,viewId:i}=r,o=n=>{const a=!s;n==null||n.stopPropagation(),e(a),ae.emitMethod(ne.MainEngine,V.SetFontStyle,{workIds:t,viewId:i,lineThrough:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:Ee(s?"line-through-active":"line-through")}))},Km=r=>{const{italic:s,setItalic:e,workIds:t,viewId:i}=r,o=n=>{const a=s==="italic"?"normal":"italic";n==null||n.stopPropagation(),e(a),ae.emitMethod(ne.MainEngine,V.SetFontStyle,{workIds:t,viewId:i,italic:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:Ee(s==="italic"?"italic-active":"italic")}))},_m=r=>{const{open:s,setOpen:e,textOpt:t,workIds:i,style:o,floatBarRef:n}=r,{mananger:a,floatBarData:c}=y.useContext(Se),[l,u]=y.useState("normal"),[h,d]=y.useState("normal"),[g,p]=y.useState(!1),[f,m]=y.useState(!1);y.useEffect(()=>{t!=null&&t.bold&&u(t.bold),O.isBoolean(t==null?void 0:t.underline)&&p(t.underline||!1),O.isBoolean(t==null?void 0:t.lineThrough)&&m(t.lineThrough||!1),t!=null&&t.italic&&d(t.italic)},[t]);const w=y.useMemo(()=>{if(o&&(n!=null&&n.current)&&O.isNumber(c==null?void 0:c.y)&&(a!=null&&a.height)){if(n.current.offsetTop&&n.current.offsetTop+c.y>180){const N={};return N.top="inherit",N.bottom=50,N}else if(!n.current.offsetTop&&(a==null?void 0:a.height)-n.current.offsetTop-c.y<120){const N={};return N.top="inherit",N.bottom=50,N}}},[o,n==null?void 0:n.current,c,a]),I=y.useMemo(()=>s?y.createElement("div",{className:"font-style-menu",style:w,onPointerUp:N=>{N.stopPropagation(),N.nativeEvent.stopImmediatePropagation()}},y.createElement(Xm,{workIds:i||[G],bold:l,setBold:u,viewId:a==null?void 0:a.viewId}),y.createElement(Jm,{workIds:i||[G],underline:g,setUnderline:p,viewId:a==null?void 0:a.viewId}),y.createElement(qm,{workIds:i||[G],lineThrough:f,setLineThrough:m,viewId:a==null?void 0:a.viewId}),y.createElement(Km,{workIds:i||[G],italic:h,setItalic:d,viewId:a==null?void 0:a.viewId})):null,[s,i,l,a==null?void 0:a.viewId,g,f,h,w]);return y.createElement("div",{className:`button normal-button ${s&&"active"}`,onPointerUp:N=>{N.stopPropagation(),N.nativeEvent.stopImmediatePropagation(),e(!s)}},y.createElement("img",{alt:"icon",src:Ee(s?"font-style-active":"font-style")}),I)},ot=Object.freeze([12,14,18,24,36,48,64,80,144,288]),At=["top","topLeft","topRight","bottom","bottomLeft","bottomRight","left","leftTop","leftBottom","right","rightTop","rightBottom"],$t=new Map([["selector","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAKeSURBVHgB3VTLi1JhFD86zlQ4ysxSXAy1GWYZzMxmYAhHagRB/QN8FLqPFq4FIQhXkS6kTQ4t2ilIKEWgSS0SmVpIm0BdaBJSaOP78XU+PXey6+saburAD+73uL/feX0H4H81GQdj7D7ilrCGFRonk3c6nXvhcJiFQiGWy+Xy/X7/WbPZ1K1KkBOsl0qlO36/n+3t7Q1hs9kYF+WC3W73MTpxc1lBmej7KuJaoVDInZ6eqsWXDw4OwGKxwPHx8Se1Wn1Wr9cjW1tbOTxi9D9bJCJHXEFslsvlR263+246nYZZptPpQK/Xg8lkSvZ6vbNGo5EgQRCLiSPhIqpoNHobo3keCARgkalUKjg5ORlGuL+/n8T6PVAqlefjYmKRdYQSsZ3P5z8aDAYVLGFarRbi8fhbhUKhx2VPEJGP3eEbfTrs4MUwr4EU49FYrVbweDy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iAyMC40OTE5NDQzLDEyLjkxMDEyNDQgTDIwLjUsMTMgTDIwLjUsMTggQzIwLjUsMTguMjc2MTQyNCAyMC4yNzYxNDI0LDE4LjUgMjAsMTguNSBDMTkuNzU0NTQwMSwxOC41IDE5LjU1MDM5MTYsMTguMzIzMTI0OCAxOS41MDgwNTU3LDE4LjA4OTg3NTYgTDE5LjUsMTggTDE5LjUsMTMgQzE5LjUsMTIuNzIzODU3NiAxOS43MjM4NTc2LDEyLjUgMjAsMTIuNSBaIiBpZD0i5b2i54q257uT5ZCIIiBmaWxsPSIjMjEyMzI0IiBmaWxsLXJ1bGU9Im5vbnplcm8iPjwvcGF0aD4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+"]]),ew=r=>{const{style:s,onClickHandler:e}=r;return y.createElement("div",{className:"font-size-menu",style:s,onPointerUp:t=>{t.stopPropagation(),t.nativeEvent.stopImmediatePropagation()}},ot.map(t=>y.createElement("div",{className:"font-size-btn",key:t,onPointerUp:()=>{e(t)}},t)))},tw=r=>{const s=y.useRef(null),{open:e,setOpen:t,textOpt:i,workIds:o,floatBarRef:n}=r,{mananger:a,floatBarData:c}=y.useContext(Se),[l,u]=y.useState(0),h=ot.length-1;y.useEffect(()=>{i!=null&&i.fontSize&&(u(i.fontSize),s.current&&(s.current.value=i.fontSize.toString()))},[i==null?void 0:i.fontSize]);const d=y.useMemo(()=>{if(n!=null&&n.current&&O.isNumber(c==null?void 0:c.y)&&(a!=null&&a.height)){if(n.current.offsetTop&&n.current.offsetTop+c.y>180){const w={};return w.top="inherit",w.bottom=35,w}else if(!n.current.offsetTop&&(a==null?void 0:a.height)-n.current.offsetTop-c.y<120){const w={};return w.top="inherit",w.bottom=35,w}}},[n==null?void 0:n.current,c,a]);function g(w){u(w),w&&w>=ot[0]&&w<=ot[h]&&ae.emitMethod(ne.MainEngine,V.SetFontStyle,{workIds:o||[G],fontSize:w,viewId:a==null?void 0:a.viewId})}const p=w=>{var I;(I=s.current)==null||I.blur(),t(!1),m(w)},f=y.useMemo(()=>e?y.createElement(ew,{onClickHandler:p,style:d}):null,[e,p,d]),m=w=>{w>ot[h]&&(w=ot[h]),w<ot[0]&&(w=ot[0]),g(w)};return y.createElement("div",{className:"button normal-button font-size-barBtn",style:{width:50},onPointerUp:w=>{w.stopPropagation(),w.nativeEvent.stopImmediatePropagation()}},y.createElement("input",{className:"font-size-input",ref:s,onTouchEnd:()=>{s.current&&s.current.focus()},onClick:()=>{t(!e),s.current&&s.current.focus()},onKeyDown:w=>{if(w.key==="Backspace"){const I=window.getSelection(),N=I==null?void 0:I.getRangeAt(0);if(N!=null&&N.collapsed)return w.cancelable&&w.preventDefault(),document.execCommand("delete",!1),!1}return!1},onKeyUp:w=>{var I;if(s.current){const N=s.current.value,C=parseInt(N);isNaN(C)?s.current.value="0":s.current.value=C.toString(),C&&w.key==="Enter"&&(m(C),(I=s.current)==null||I.blur(),t(!1))}}}),y.createElement("div",{className:"font-size-btns"},y.createElement("div",{className:"font-size-add",onPointerUp:()=>{m(l+ot[0])}}),y.createElement("div",{className:"font-size-cut",onPointerUp:()=>{m(l-ot[0])}})),f)},sw=r=>{const{workIds:s,mananger:e,islocked:t}=r;return y.createElement("div",{className:"button normal-button",onPointerUp:i=>{i.stopPropagation(),ae.emitMethod(ne.MainEngine,V.SetLock,{workIds:s||[G],isLocked:!t,viewId:e==null?void 0:e.viewId})}},y.createElement("img",{alt:"icon",src:Ee(t?"unlock-new":"lock-new")}))},Xs=r=>{const{icon:s,min:e,max:t,step:i,value:o,onInputHandler:n}=r,[a,c]=y.useState(0),l=y.useRef(null),u=h=>{h>t&&(h=t),h<e&&(h=e),c(h),n(h),l.current&&(l.current.value=h.toString())};return y.useEffect(()=>{o&&(c(o),l.current&&(l.current.value=o.toString()))},[o]),y.createElement("div",{className:"button input-button"},y.createElement("img",{src:Ee(s)}),y.createElement("input",{className:"input-number",type:"text",ref:l,onPointerUp:()=>{l.current&&l.current.focus()},onKeyDown:h=>{if(h.key==="Backspace"){const d=window.getSelection(),g=d==null?void 0:d.getRangeAt(0);if(g!=null&&g.collapsed)return h.cancelable&&h.preventDefault(),document.execCommand("delete",!1),!1}},onKeyUp:()=>{if(l.current){const h=l.current.value,d=parseInt(h);isNaN(d)?l.current.value="0":l.current.value=d.toString()}},onChange:h=>{const d=h.target.value,g=parseInt(d);g&&g&&g>=e&&g<=t&&u(g)}}),y.createElement("div",{className:"input-number-btns"},y.createElement("div",{className:"input-number-add",onPointerUp:()=>{u(a+i)}}),y.createElement("div",{className:"input-number-cut",onPointerUp:()=>{u(a-i)}})))},iw=r=>{const{icon:s,min:e,max:t,step:i,value:o,onInputHandler:n}=r;return y.createElement("div",{className:"button input-button"},y.createElement("img",{src:Ee(s)}),y.createElement(ow,{min:e,max:t,step:i,value:o,onInputHandler:n}))},ow=r=>{const{value:s,min:e,max:t,onInputHandler:i}=r,[o,n]=y.useState({x:0,y:0});y.useEffect(()=>{n({x:s*100,y:0})},[]);const a=(u,h)=>{let d=Math.floor(Math.max(h.x,e*100));d=Math.floor(Math.min(d,t*100)),h.x!==(o==null?void 0:o.x)&&n({x:d,y:0});const g=d/100;s!==g&&i(g)},c=()=>{},l=(u,h)=>{let d=Math.floor(Math.max(h.x,e*100));d=Math.floor(Math.min(d,t*100)),h.x!==(o==null?void 0:o.x)&&n({x:d,y:0});const g=d/100;s!==g&&i(g)};return y.createElement("div",{className:"range-number-container",onPointerUp:u=>{const h=u.nativeEvent.offsetX-6;let d=Math.floor(Math.max(h,e*100));d=Math.floor(Math.min(d,t*100)),n({x:d,y:0});const g=d/100;s!==g&&i(g)}},y.createElement("div",{className:"range-number-color"}),y.createElement("div",{className:"range-number"},y.createElement(Yt,{bounds:"parent",axis:"x",position:o,onDrag:a,onStart:c,onStop:l},y.createElement("div",{className:"circle",onPointerUp:is}))))},nw=r=>{const{icon:s,value:e,onChangeHandler:t,style:i}=r,[o,n]=y.useState(0),[a,c]=y.useState(),l=y.useRef(null),u=y.useCallback(g=>{g>=At.length&&(g=0),g<0&&(g=At.length-1),n(g),t(At[g]),c(!1),l.current&&(l.current.value=At[g])},[t]),h=y.useMemo(()=>{if(i&&i.bottom){const g={};return g.top="inherit",g.bottom=50,g}},[i]);y.useEffect(()=>{e&&(n(At.indexOf(e)),l.current&&(l.current.value=e))},[e]);const d=y.useMemo(()=>a?y.createElement(rw,{options:At,onClickHandler:u,style:h}):null,[a,u,h]);return y.createElement("div",{className:"button input-button"},y.createElement("img",{src:Ee(s)}),y.createElement("input",{readOnly:!0,className:"input-number",type:"text",ref:l,onPointerUp:()=>{l.current&&(l.current.focus(),c(!a))}}),y.createElement("div",{className:"input-number-btns"},y.createElement("div",{className:"input-number-add",onPointerUp:()=>{u(o+1)}}),y.createElement("div",{className:"input-number-cut",onPointerUp:()=>{u(o-1)}})),d)},rw=r=>{const{options:s,style:e,onClickHandler:t}=r;return y.createElement("div",{className:"select-option-menu",style:e},s.map((i,o)=>y.createElement("div",{className:"select-option-btn",key:i,onPointerUp:()=>{t(o)}},i)))},aw=r=>{const{innerRatio:s,innerVerticeStep:e,vertices:t,mananger:i,setShapeOpt:o}=r,n=l=>{o({vertices:l}),ae.emitMethod(ne.MainEngine,V.SetShapeOpt,{workIds:[G],toolsType:T.Star,viewId:i.viewId,vertices:l})},a=l=>{o({innerVerticeStep:l}),ae.emitMethod(ne.MainEngine,V.SetShapeOpt,{workIds:[G],toolsType:T.Star,viewId:i.viewId,innerVerticeStep:l})},c=l=>{o({innerRatio:l}),ae.emitMethod(ne.MainEngine,V.SetShapeOpt,{workIds:[G],toolsType:T.Star,viewId:i.viewId,innerRatio:l})};return y.createElement(y.Fragment,null,y.createElement(Xs,{value:t,icon:"polygon-vertex",min:3,max:100,step:1,onInputHandler:n}),y.createElement(Xs,{value:e,icon:"star-innerVertex",min:1,max:100,step:1,onInputHandler:a}),y.createElement(iw,{value:s,icon:"star-innerRatio",min:.1,max:1,step:.1,onInputHandler:c}))},cw=r=>{const{mananger:s,vertices:e,setShapeOpt:t}=r,i=o=>{t({vertices:o}),ae.emitMethod(ne.MainEngine,V.SetShapeOpt,{workIds:[G],toolsType:T.Polygon,viewId:s.viewId,vertices:o})};return y.createElement(Xs,{value:e,icon:"polygon-vertex",min:3,max:100,step:1,onInputHandler:i})},lw=r=>{const{mananger:s,placement:e,setShapeOpt:t}=r,i=o=>{t({placement:o}),ae.emitMethod(ne.MainEngine,V.SetShapeOpt,{workIds:[G],toolsType:T.SpeechBalloon,viewId:s.viewId,placement:o})};return y.createElement(nw,{value:e,icon:"speechBallon-placement",onChangeHandler:i})},Ys=r=>{const{icon:s,isActive:e,onPointerUpHandler:t}=r;return y.createElement("div",{className:`button tab-button ${e?"active":""}`,onPointerUp:t},y.createElement("img",{src:Ee(s)}))},hw=r=>{const{toolsTypes:s,style:e,mananger:t,shapeOpt:i,setShapeOpt:o}=r,[n,a]=y.useState();y.useEffect(()=>{s.includes(T.Polygon)?a(T.Polygon):s.includes(T.Star)?a(T.Star):a(T.SpeechBalloon)},[s]);const c=d=>{a(d)},l=y.useMemo(()=>n===T.Polygon&&t&&i.vertices?y.createElement(cw,{vertices:i.vertices,mananger:t,setShapeOpt:o}):null,[t,n,i,o]),u=y.useMemo(()=>n===T.Star&&t&&i.vertices&&i.innerVerticeStep&&i.innerRatio?y.createElement(aw,{mananger:t,vertices:i.vertices,innerVerticeStep:i.innerVerticeStep,innerRatio:i.innerRatio,setShapeOpt:o}):null,[t,n,i,o]),h=y.useMemo(()=>n===T.SpeechBalloon&&t&&i.placement?y.createElement(lw,{mananger:t,placement:i.placement,setShapeOpt:o}):null,[n,t,i.placement,o]);return y.createElement("div",{className:"shapeOpt-sub-menu",style:e,onPointerUp:is},y.createElement("div",{className:"shapeOpt-sub-menu-tabs"},s.includes(T.Polygon)&&y.createElement(Ys,{isActive:n===T.Polygon,icon:n===T.Polygon?"polygon-active":"polygon",onPointerUpHandler:c.bind(void 0,T.Polygon)})||null,s.includes(T.Star)&&y.createElement(Ys,{isActive:n===T.Star,icon:n===T.Star?"star-active":"star",onPointerUpHandler:c.bind(void 0,T.Star)})||null,s.includes(T.SpeechBalloon)&&y.createElement(Ys,{isActive:n===T.SpeechBalloon,icon:n===T.SpeechBalloon?"speechBallon-active":"speechBallon",onPointerUpHandler:c.bind(void 0,T.SpeechBalloon)})||null),y.createElement("div",{className:"shapeOpt-sub-menu-content"},l,u,h))},uw=r=>{const{open:s,setOpen:e,floatBarRef:t,toolsTypes:i,shapeOpt:o}=r,{floatBarData:n,mananger:a,setFloatBarData:c}=y.useContext(Se),l=y.useRef(null),u=y.useMemo(()=>{if(t!=null&&t.current&&O.isNumber(n==null?void 0:n.x)&&O.isNumber(n==null?void 0:n.y)&&(a!=null&&a.height)){if(t.current.offsetTop&&t.current.offsetTop+n.y>200){const p={};return p.top="inherit",p.bottom=50,p}else if(!t.current.offsetTop&&(a==null?void 0:a.height)-t.current.offsetTop-(n==null?void 0:n.y)<140){const p={};return p.top="inherit",p.bottom=50,p}}},[t,n==null?void 0:n.x,n==null?void 0:n.y,a==null?void 0:a.height]),h=y.useCallback(p=>{c({shapeOpt:{...o,...p}})},[c,o]),d=y.useMemo(()=>s&&i&&a&&o?y.createElement(hw,{shapeOpt:o,style:u,toolsTypes:i,mananger:a,setShapeOpt:h}):null,[s,u,i,a,o,h]),g=()=>{e(!s)};return y.createElement("div",{ref:l,className:`button normal-button ${s&&"active"}`,onPointerUp:g},d,y.createElement("img",{alt:"icon",src:Ee(s?"shapes-active":"shapes")}))},Cn=y.memo(r=>{const{textOpt:s,workIds:e,noLayer:t,position:i,noDelete:o,noCopy:n}=r,{floatBarData:a,mananger:c}=y.useContext(Se),[l,u]=y.useState(0),[h,d]=y.useState(),g=y.useRef(null);y.useEffect(()=>{var P,A,E,R;const x={},L=(a==null?void 0:a.w)||((P=s==null?void 0:s.boxSize)==null?void 0:P[0])||0,b=(a==null?void 0:a.h)||((A=s==null?void 0:s.boxSize)==null?void 0:A[1])||0;if(i&&L&&b&&(c!=null&&c.width)&&(c!=null&&c.height)){if(i.y<60?i.y+b<c.height-60?x.bottom=-120:i.y+b<c.height?x.bottom=-58:i.y>0?x.top=62:x.top=-i.y+62:x.top=0,i.x<0)x.left=-i.x+3;else if(i.x+(((E=g.current)==null?void 0:E.offsetWidth)||L)>c.width){const z=c.width-(((R=g.current)==null?void 0:R.offsetWidth)||L)-i.x;x.left=z}d(x);return}d(void 0)},[g,i,a==null?void 0:a.w,a==null?void 0:a.h,c==null?void 0:c.width,c==null?void 0:c.height,s==null?void 0:s.boxSize]);const p=y.useMemo(()=>a!=null&&a.fillColor?y.createElement(Hm,{floatBarRef:g,open:l===3,setOpen:x=>{u(x===!0?3:0)}}):null,[a==null?void 0:a.fillColor,l,g]),f=y.useMemo(()=>a!=null&&a.strokeColor?y.createElement(Zm,{floatBarRef:g,open:l===2,setOpen:x=>{u(x===!0?2:0)}}):null,[a==null?void 0:a.strokeColor,l,g]),m=y.useMemo(()=>s!=null&&s.fontColor&&(c!=null&&c.viewId)?y.createElement(Gm,{floatBarRef:g,open:l===4,setOpen:x=>{u(x===!0?4:0)},textOpt:s,workIds:e}):null,[s,l,e,c,g]),w=y.useMemo(()=>s!=null&&s.fontBgColor&&(c!=null&&c.viewId)?y.createElement($m,{floatBarRef:g,open:l===5,setOpen:x=>{u(x===!0?5:0)},textOpt:s,workIds:e}):null,[s,l,e,c,g]),I=y.useMemo(()=>s&&(c!=null&&c.viewId)?y.createElement(_m,{floatBarRef:g,open:l===6,setOpen:x=>{u(x===!0?6:0)},textOpt:s,workIds:e,style:h}):null,[s,l,e,c,h,g]),N=y.useMemo(()=>s&&(c!=null&&c.viewId)?y.createElement(tw,{open:l===7,setOpen:x=>{u(x===!0?7:0)},textOpt:s,workIds:e,floatBarRef:g}):null,[s,l,e,c,g]),C=y.useMemo(()=>t?null:y.createElement(Bm,{open:l===1,setOpen:x=>{u(x===!0?1:0)},floatBarRef:g}),[t,l,g]),S=y.useMemo(()=>a!=null&&a.canLock&&c?y.createElement(sw,{workIds:e,mananger:c,islocked:a.isLocked}):null,[a,c,e]),v=y.useMemo(()=>c&&(c!=null&&c.viewId)&&h&&(a!=null&&a.shapeOpt)&&(a!=null&&a.toolsTypes)?y.createElement(uw,{open:l===8,setOpen:x=>{u(x===!0?8:0)},floatBarRef:g,workIds:e,toolsTypes:a.toolsTypes,shapeOpt:a.shapeOpt}):null,[a,c,l,h,e,g]);return y.createElement("div",{className:"appliance-plugin-floatbtns",style:h,ref:g},c&&!o&&y.createElement(Ym,{workIds:e,mananger:c}),C,S,!!(c!=null&&c.viewId)&&!n&&y.createElement(Um,{workIds:e,viewId:c.viewId}),v,I,N,m,w,f,p)}),dw=r=>{const{data:s,workId:e,updateOptInfo:t,handlePointerDown:i,handlePointerUp:o}=r,{opt:n,scale:a,translate:c,x:l,y:u}=s,h=y.useRef(null),{floatBarData:d}=y.useContext(Se),g=y.useMemo(()=>{const{fontSize:m,fontFamily:w,underline:I,fontColor:N,lineThrough:C,textAlign:S,strokeColor:v,lineHeight:x,bold:L,italic:b}=n,P=x||m*1.2,A={fontSize:`${m}px`,lineHeight:`${P}px`,color:N,borderColor:v,minHeight:`${P}px`,pointerEvents:"none",paddingRight:`${b==="italic"?Math.round(m*.3):5}px`};return w&&(A.fontFamily=`${w}`),(C||I)&&(A.textDecoration=`${C&&"line-through"||""}${I&&" underline"||""}`),S&&(A.textAlign=`${S}`),L&&(A.fontWeight=`${L}`),b&&(A.fontStyle=`${b}`),A},[n]),p=y.useMemo(()=>{const m=[];if(n.text){const w=Dt(n.text);for(let I=0;I<w.length;I++){const N=w[I];N===""?m.push(y.createElement("div",{key:I})):m.push(y.createElement("div",{key:I},N))}}return m.length?m:y.createElement("div",null)},[n.text]),f=y.useMemo(()=>{if(!d)return{};const m=`scale(${a||1}) ${c&&"translate("+c[0]+"px,"+c[1]+"px)"||""}`;return{left:`${l-d.x}px`,top:`${u-d.y}px`,zIndex:1,transform:m,transformOrigin:"left top",opacity:0,pointerEvents:"auto"}},[a,c,l,u,d]);return y.useEffect(()=>{var m,w;if((m=h.current)!=null&&m.offsetWidth&&((w=h.current)!=null&&w.offsetHeight)){const I=n.boxSize;if((I==null?void 0:I[0])!==h.current.offsetWidth||I[1]!==h.current.offsetHeight||!I){const N=[h.current.offsetWidth,h.current.offsetHeight];t({activeTextId:e,update:{boxSize:N,workState:j.Done}})}}},[n.fontSize,n.italic,n.bold,n.boxSize,e,t]),y.createElement("div",{className:"editor-box readonly",style:f,onPointerDown:()=>{i(e)},onPointerUp:()=>{o()}},y.createElement("div",{className:"editor",ref:h,style:g},p))},pw=r=>{const{mananger:s}=y.useContext(Se),e=y.useMemo(()=>{var i;const t=o=>{var u,h;if(!s)return;const{activeTextId:n,update:a,syncData:c}=o,l=n&&O.cloneDeep(((u=s.control.textEditorManager)==null?void 0:u.get(n))||((h=r.editors)==null?void 0:h.get(n)));l&&l.opt&&(l.opt={...l.opt,...a},c&&(l.canSync=Object.keys(c).includes("canSync")&&c.canSync||l.canSync,l.canWorker=Object.keys(c).includes("canWorker")&&c.canWorker||l.canWorker),s.control.textEditorManager.updateForViewEdited(n,l))};if((i=r.editors)!=null&&i.size){const o=[];return r.editors.forEach((n,a)=>{if(r.selectIds&&r.selectIds.includes(a)){const c=y.createElement(dw,{key:a,workId:a,data:n,updateOptInfo:t,handlePointerDown:r.handleTextEditorPointerDown,handlePointerUp:r.handleTextEditorPointerUp});o.push(c)}}),o}return null},[r.editors,r.selectIds,s,r.handleTextEditorPointerDown,r.handleTextEditorPointerUp]);return y.createElement(y.Fragment,null,e)},gw=r=>{const{position:s,textOpt:e,workIds:t,noLayer:i,noCopy:o,noDelete:n,style:a}=r,c=y.useRef(null);return y.createElement("div",{className:We.FloatBarBtn,ref:c,style:a},y.createElement(Cn,{position:s,textOpt:e,workIds:t,noLayer:i,noCopy:o,noDelete:n}))},fw=r=>{const{data:s,workId:e,showFloatBtns:t,handleKeyUp:i,handleFocus:o,runAnimation:n,updateSize:a,rightBoundBreak:c}=r,{activeTextEditor:l,activeTextId:u,mananger:h}=y.useContext(Se),{opt:d,scale:g,translate:p,x:f,y:m}=s,{fontSize:w,fontFamily:I,underline:N,fontColor:C,lineThrough:S,textAlign:v,lineHeight:x,bold:L,italic:b}=d,P=y.useRef(null),A=y.useMemo(()=>{const H=w,K=x||H*1.2,se={fontSize:`${H}px`,lineHeight:`${K}px`,color:C,minHeight:`${K}px`,paddingRight:`${b==="italic"?Math.round(H*.3):5}px`,borderWidth:`${Math.max(Math.round(1/(g||1)),1)}px`};return I&&(se.fontFamily=`${I}`),(S||N)&&(se.textDecoration=`${S&&"line-through"||""} ${N&&" underline"||""}`),v&&(se.textAlign=`${v}`),L&&(se.fontWeight=`${L}`),b&&(se.fontStyle=`${b}`),se},[L,C,I,w,b,x,S,g,v,N]),E=y.useRef(!1),R=y.useRef(6),z=y.useRef({fontSize:A.fontSize,lineHeight:A.lineHeight,fontStyle:A.fontStyle,fontWeight:A.fontWeight,fontFamily:A.fontFamily}),Z=y.useMemo(()=>u===e?"hover":d.workState===j.Doing||d.workState===j.Start?"editing":l?"active":"none",[u,e,d.workState,l]);function ee(H){if(P.current){const K=window==null?void 0:window.getSelection(),se=P.current,pe=(ye,we)=>{var ge;const Te=document.createRange();if(we.childNodes.length>0){const xe=we.lastChild;if(xe){const Oe=xe.lastChild;Oe&&Oe.nodeType===Node.TEXT_NODE?Te.setStart(Oe,((ge=Oe.textContent)==null?void 0:ge.length)||0):Te.setStart(xe,0)}else Te.setStart(we,0)}else Te.setStart(we,0);Te.collapse(!0),ye.removeAllRanges(),ye.addRange(Te)};if(K&&se)if(H&&Ct(H.nativeEvent)){const{x:ye,y:we}=Ii(H.nativeEvent);if(document.caretPositionFromPoint){const Te=document.caretPositionFromPoint(ye,we);if(Te){const ge=document.createRange();ge.setStart(Te.offsetNode,Te.offset),ge.collapse(!0),K.removeAllRanges(),K.addRange(ge)}else pe(K,se)}else if(document.caretRangeFromPoint){const Te=document.caretRangeFromPoint(ye,we);Te?(K.removeAllRanges(),K.addRange(Te)):pe(K,se)}else pe(K,se)}else pe(K,se);P.current.focus()}}const F=y.useMemo(()=>{const H=`scale(${g||1}) ${p&&"translate("+p[0]+"px,"+p[1]+"px)"||""}`;return{left:`${f}px`,top:`${m}px`,zIndex:2,transform:H,transformOrigin:"left top",borderColor:Z==="editing"||Z==="hover"?C:"transparent"}},[g,p,f,m,C,Z]),$=y.useMemo(()=>{let H="";const K=`<div style="background-color:${d.fontBgColor};"></div>`;if(d.text){const se=Dt(d.text);for(let pe=0;pe<se.length;pe++){const ye=se[pe];if(ye==="")H=H+K;else{const we=ye.replace(/[<>&]/g,Te=>({"<":"&lt;",">":"&gt;","&":"&amp;"})[Te]);H=H+`<div style="background-color:${d.fontBgColor}">${we}</div>`}}}else H=K;return H},[d.fontBgColor,d.text]),te=y.useMemo(()=>{var H,K;if(Z==="hover"){if(g&&t&&O.isNumber(f)&&O.isNumber(m)&&d.boxSize&&O.isNumber((H=d.boxSize)==null?void 0:H[0])&&O.isNumber((K=d.boxSize)==null?void 0:K[1])){const se={x:f,y:m},pe={left:f,top:m,width:d.boxSize[0]*g,height:d.boxSize[1]*g};return y.createElement(gw,{position:se,style:pe,textOpt:d,workIds:[e],noLayer:!0,noCopy:!0,noDelete:!0})}return null}return null},[d,t,e,f,m,g,Z]);y.useEffect(()=>{u===e&&P.current&&(document.activeElement!==P.current&&ee(),o(P.current))},[u,o,e]),y.useEffect(()=>{if(P.current){const H=parseInt(getComputedStyle(P.current).paddingRight,10)+parseInt(getComputedStyle(P.current).borderWidth,10);R.current=Number(H)}},[]),y.useEffect(()=>{if(P.current){const H={fontSize:A.fontSize,lineHeight:A.lineHeight,fontStyle:A.fontStyle,fontWeight:A.fontWeight,fontFamily:A.fontFamily};if(!O.isEqual(z.current,H)){z.current=H;const K=[P.current.offsetWidth,P.current.offsetHeight];a(e,K)}}},[A,e,a]);const le=y.useCallback(H=>{var we,Te;const K=h==null?void 0:h.parentElement;if(!K||!P.current||!c)return!1;const se=P.current.lastChild;if(!se)return!1;const pe=se.getBoundingClientRect(),ye=K.getBoundingClientRect();if(pe.right+H>ye.right){const ge=se.lastChild;if(!(ge instanceof Text))return!1;const xe=ge.length||0;let Oe=0,Ce=0,Ve=xe;for(;Ce<Ve;){const Ae=Math.floor((Ce+Ve)/2),dt=document.createRange();dt.setStart(ge,0),dt.setEnd(ge,Ae);const Lt=dt.getBoundingClientRect(),vi=ye.right-Lt.right;if(vi<H){if(Ae>0){const yt=document.createRange();yt.setStart(ge,0),yt.setEnd(ge,Ae-1);const Ht=yt.getBoundingClientRect();if(ye.right-Ht.right>=H){Oe=Ae-1;break}}Ve=Ae}else{const yt=Ae+1;if(yt<xe){const Ht=document.createRange();Ht.setStart(ge,0),Ht.setEnd(ge,yt);const Ni=Ht.getBoundingClientRect();if(ye.right-Ni.right<=H&&vi>H){Oe=Ae;break}}Ce=yt}}if(!Oe){const Ae=document.createRange();Ae.setStart(ge,0),Ae.setEnd(ge,Ce);const dt=Ae.getBoundingClientRect();ye.right-dt.right>H?Oe=Ce:Ce>0&&(Oe=Ce-1)}if(Oe>0){const Ae=((we=ge.textContent)==null?void 0:we.slice(0,Oe))||"",dt=((Te=ge.textContent)==null?void 0:Te.slice(Oe))||"";ge.textContent=Ae;const Lt=document.createElement("div");return d.fontBgColor&&(Lt.style.backgroundColor=d.fontBgColor),dt&&(Lt.textContent=dt),P.current.appendChild(Lt),le(H),!0}}return!1},[h==null?void 0:h.parentElement,d.fontBgColor,c]);function ie(H){if(H.key==="Backspace"){const K=window.getSelection(),se=K==null?void 0:K.getRangeAt(0);if(se!=null&&se.collapsed)return H.cancelable&&H.preventDefault(),document.execCommand("delete",!1),!1}return!1}function _(H,K){const se=window==null?void 0:window.getSelection();if(se!=null&&se.rangeCount&&H&&se&&se.anchorNode){const pe=se.anchorOffset,ye=se.anchorNode.textContent||"",we=ye.slice(0,pe)||"",Te=ye.slice(pe)||"",ge=we.concat(H)||"";J(ge,Te,K)}}function J(H,K,se){const pe=window==null?void 0:window.getSelection();if(!(pe!=null&&pe.rangeCount)||!pe.anchorNode)return;const ye=H.split(/\n/);let we=pe.anchorNode.parentNode;we===se&&(we=pe.anchorNode);const Te=[...se.childNodes],ge=[];let xe,Oe=pe.anchorOffset;for(;Te.length;){const Ce=Te.pop();if(Ce){if(Ce===we){let Ve=ye[0];ye.length===1&&(Oe=ye[0].length,Ve=ye[0].concat(K)),we.nodeName==="#text"?(we.textContent=Ve,xe=we):we.nodeName==="DIV"&&(we.innerText=Ve,xe=we.childNodes[0]);break}ge.push(Ce),se.removeChild(Ce)}}if(ye.length>1)for(let Ce=1;Ce<ye.length;Ce++){let Ve=ye[Ce];const Ae=document.createElement("div");d.fontBgColor&&(Ae.style.backgroundColor=d.fontBgColor),Ce===ye.length-1&&(Oe=Ve.length,Ve=Ve.concat(K)),Ae.innerText=Ve,se.appendChild(Ae),Ce===ye.length-1&&(xe=Ae.childNodes[0])}if(ge.length){ge.reverse();for(const Ce of ge)se.appendChild(Ce)}if(xe&&xe.nodeName==="#text"){pe.deleteFromDocument();const Ce=document.createRange(),Ve=Math.min(Oe,(xe==null?void 0:xe.length)||0);Ce.setStart(xe,Ve),Ce.collapse(!0),pe.removeAllRanges(),pe.addRange(Ce)}}function de(H){if(H.cancelable&&H.preventDefault(),H.stopPropagation(),P.current){const K=(H.clipboardData||window.clipboardData).getData("text"),se=window==null?void 0:window.getSelection();if(!(se!=null&&se.rangeCount))return;if(K&&se&&se.anchorNode){const pe=Dn(K,{whiteList:{},stripIgnoreTag:!0,stripIgnoreTagBody:["script"]});_(pe,P.current),i(P.current)}n()}}function Be(H){var se;const K=H.querySelector("div");if(K){const pe=document.createTreeWalker(H,NodeFilter.SHOW_TEXT,null);let ye;const we=[];for(;(ye=pe.nextNode())!==null;)ye.parentNode===H&&we.push(ye);if(we.length>0){for(const ge of we)K.appendChild(ge);const Te=window.getSelection();if(Te){const ge=document.createRange(),xe=K.lastChild;xe&&xe.nodeType===Node.TEXT_NODE&&(ge.setStart(xe,((se=xe.textContent)==null?void 0:se.length)||0),ge.collapse(!0),Te.removeAllRanges(),Te.addRange(ge))}}}}const ke=y.useCallback(()=>{const H=P.current;n(()=>{if(!E.current&&H){if(Be(H),le((g||1)*R.current)){const K=window.getSelection();if(!(K!=null&&K.rangeCount))return!1;const se=document.createRange(),pe=P.current.lastChild;se.selectNodeContents(pe),se.collapse(!1),K.removeAllRanges(),K.addRange(se)}i(H)}})},[n,i,le,g]);function q(){E.current=!0,n()}function Le(){E.current=!1,ke()}const Ue=y.useCallback(()=>{if(Z==="active"&&P.current&&P.current.parentElement){const H=P.current.parentElement;H.style.borderColor=C}},[Z,C]),st=y.useCallback(()=>{if(Z==="active"&&P.current&&P.current.parentElement){const H=P.current.parentElement;H.style.borderColor="transparent"}},[Z]);return y.createElement(y.Fragment,null,te,y.createElement("div",{className:`editor-box ${Z}`,style:F,onPointerUp:()=>{var H;if(Z==="editing"){n(()=>{var K;(K=document.activeElement)==null||K.blur(),h==null||h.control.textEditorManager.checkEmptyTextBlur()});return}if(Z==="active"&&h){if((H=h.control.collector)!=null&&H.hasIncludeSelector(e)){n(()=>{var K;(K=document.activeElement)==null||K.blur(),h==null||h.control.textEditorManager.checkEmptyTextBlur()});return}if(h&&u!==e){h.control.textEditorManager.checkEmptyTextBlur(),h.control.textEditorManager.active(e);return}}},onMouseOver:Ue,onMouseLeave:st},y.createElement("div",{id:e,suppressContentEditableWarning:!0,contentEditable:!0,className:"editor",ref:P,style:A,onKeyDown:ie,onPaste:de,onTouchEnd:ee,onInput:ke,onCompositionStart:q,onCompositionEnd:Le,dangerouslySetInnerHTML:{__html:$}})))},Mw=r=>{const s=y.useRef(null),{mananger:e}=y.useContext(Se),t=y.useRef(),i=y.useCallback(n=>{var h,d;const{activeTextId:a,update:c,syncData:l}=n;if(!e)return;const u=a&&O.cloneDeep(((h=e.control.textEditorManager)==null?void 0:h.get(a))||((d=r.editors)==null?void 0:d.get(a)));u&&u.opt&&(u.opt={...u.opt,...c},l&&(u.canSync=Object.keys(l).includes("canSync")&&l.canSync||u.canSync,u.canWorker=Object.keys(l).includes("canWorker")&&l.canWorker||u.canWorker),e.control.textEditorManager.updateForViewEdited(a,u))},[e,r.editors]),o=y.useMemo(()=>{var h;const n=d=>{const g=[];for(let p=0;p<d.childNodes.length;p++){const f=d.childNodes[p];if(f.nodeName==="#text"&&p===0){const m=f.textContent.split(/\n/),w=m.pop();g.push(...m),w&&g.push(w)}else if(f.nodeName==="DIV"){const m=f.innerText.split(/\n/);if(m.length===2&&m[0]===""&&m[1]==="")g.push("");else{const w=m.shift();(w||w==="")&&g.push(w);const I=m.pop();g.push(...m),I&&g.push(I)}}}return g},a=d=>{if(!e)return;const g=d.id,p=e.control.textEditorManager.get(g),f=j.Doing,m=[d.offsetWidth,d.offsetHeight];(!p||p&&(!O.isEqual(p.opt.boxSize,m)||!O.isEqual(p.opt.workState,f)))&&i({activeTextId:g,update:{boxSize:m,workState:f},syncData:{canSync:!0,canWorker:!0}})},c=d=>{var N,C;if(!e)return;const g=n(d),p=d.id,f=e.control.textEditorManager.get(p),m=Ge(g),w=j.Doing,I=[d.offsetWidth,d.offsetHeight];if(!f||f&&(f.opt.text!==m||!O.isEqual(f.opt.boxSize,I)||!O.isEqual(f.opt.workState,w))){const S=p&&O.cloneDeep(((N=e.control.textEditorManager)==null?void 0:N.get(p))||((C=r.editors)==null?void 0:C.get(p)));S&&S.opt&&(S.opt={...S.opt,text:m,boxSize:I,workState:w},S.canSync=!0,S.canWorker=!0,e.control.textEditorManager.updateForViewEdited(p,S)),e.control.textEditorManager.publicMsgEmitter.emit("textChange",p,d,g,S)}},l=(d,g)=>{if(!e)return;const p=d,f=e.control.textEditorManager.get(p);if(f&&!O.isEqual(f.opt.boxSize,g)){const m=O.cloneDeep(f);m.opt={...m.opt,boxSize:g},m.canSync=!1,m.canWorker=!1,e.control.textEditorManager.updateForViewEdited(p,m)}},u=d=>{t.current&&cancelAnimationFrame(t.current),t.current=requestAnimationFrame(()=>{s!=null&&s.current&&(s==null||s.current.scrollTo({left:0,behavior:"instant"}),d&&d(),t.current=void 0)})};if((h=r.editors)!=null&&h.size){const d=[];return r.editors.forEach((g,p)=>{d.push(y.createElement(fw,{key:p,workId:p,data:g,showFloatBtns:r.showFloatBtns||!1,handleFocus:a,handleKeyUp:c,updateSize:l,runAnimation:u,rightBoundBreak:r.rightBoundBreak||!1}))}),d}return null},[r.editors,r.showFloatBtns,r.rightBoundBreak,e,i]);return y.createElement("div",{className:`${r.className}`,ref:s},o)},yw=()=>{const{floatBarData:r}=y.useContext(Se);return y.createElement("div",{className:"appliance-plugin-hightlight-box",style:{borderColor:r==null?void 0:r.selectorColor}},y.createElement("div",{className:"point LT nwse-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}),y.createElement("div",{className:"point LC ew-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}),y.createElement("div",{className:"point LB nesw-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}),y.createElement("div",{className:"point TC ns-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}),y.createElement("div",{className:"point RT nesw-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}),y.createElement("div",{className:"point RC ew-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}),y.createElement("div",{className:"point RB nwse-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}),y.createElement("div",{className:"point BC ns-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}))},mw=()=>{const{floatBarData:r,mananger:s}=y.useContext(Se),[e,t]=y.useState(),[i,o]=y.useState();y.useEffect(()=>{const c=[];if(s&&O.isNumber(r==null?void 0:r.x)&&O.isNumber(r==null?void 0:r.y)&&(r!=null&&r.points)){const l=s.viewId;if(s.control.viewContainerManager.getView(l))for(const h of r.points){const d=s.control.viewContainerManager.transformToOriginPoint(h,l);c.push(d)}c[0]&&t({x:c[0][0]-((r==null?void 0:r.x)||0),y:c[0][1]-((r==null?void 0:r.y)||0)}),c[1]&&o({x:c[1][0]-((r==null?void 0:r.x)||0),y:c[1][1]-((r==null?void 0:r.y)||0)})}},[s,r==null?void 0:r.points,r==null?void 0:r.x,r==null?void 0:r.y]);const n=y.useMemo(()=>e?y.createElement("div",{className:"point point-dot",style:{borderColor:r==null?void 0:r.selectorColor,left:e.x,top:e.y}}):null,[r==null?void 0:r.selectorColor,e]),a=y.useMemo(()=>i?y.createElement("div",{className:"point point-dot",style:{borderColor:r==null?void 0:r.selectorColor,left:i.x,top:i.y}}):null,[i,r==null?void 0:r.selectorColor]);return y.createElement("div",{className:"appliance-plugin-hightlight-box",style:{borderColor:r==null?void 0:r.selectorColor}},n,a)},ww=()=>{const{floatBarData:r}=y.useContext(Se);return y.createElement("div",{className:"appliance-plugin-hightlight-box",style:{borderColor:r==null?void 0:r.selectorColor}},y.createElement("div",{className:"point LT nwse-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}),y.createElement("div",{className:"point LB nesw-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}),y.createElement("div",{className:"point RT nesw-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}),y.createElement("div",{className:"point RB nwse-resize",style:{backgroundColor:r==null?void 0:r.selectorColor}}))},Iw=()=>{const{floatBarData:r}=y.useContext(Se);return y.createElement("div",{className:"appliance-plugin-hightlight-box",style:{borderColor:r==null?void 0:r.selectorColor}},y.createElement("img",{className:"lock",alt:"lock",src:"https://sdk.netless.link/resource/icons/lock.svg"}))},Tw=r=>{const{className:s}=r,{floatBarData:e,angle:t,setAngle:i,setOperationType:o,mananger:n}=y.useContext(Se),[a,c]=y.useState(j.Pending),[l,u]=y.useState(),[h,d]=y.useState(!1),[g,p]=y.useState(new Q),[f,m]=y.useState(new Q),[w,I]=y.useState(!1),N=y.useRef(0),C=y.useRef(null),S=P=>{if(!P){I(!0),d(!1),o(V.None),c(j.Pending);return}I(!1)},v=(P,A)=>{N.current&&(clearTimeout(N.current),N.current=0),c(j.Done),d(!1);const E=Math.round(Q.GetAngleByPoints(g,f,new Q(A.x,A.y)))||0;i(E),o(V.None),ae.emitMethod(ne.MainEngine,V.RotateNode,{workIds:[G],angle:E,workState:j.Done,viewId:n==null?void 0:n.viewId})};y.useEffect(()=>(ae.activeListener(S),()=>{ae.unmountActiveListener(S)}),[]),y.useEffect(()=>{if(e&&(a===j.Pending||a===j.Done)){const P={x:(e==null?void 0:e.x)-20,y:(e==null?void 0:e.y)+(e==null?void 0:e.h)},A={x:(e==null?void 0:e.x)+(e==null?void 0:e.w)/2,y:(e==null?void 0:e.y)+(e==null?void 0:e.h)/2};m(new Q(A.x,A.y)),p(new Q(P.x,P.y)),u({x:P.x,y:P.y})}},[e,a]);const x=(P,A)=>{if(n!=null&&n.control.worker.isBusy){I(!0),c(j.Pending);return}N.current&&(clearTimeout(N.current),N.current=0),c(j.Start),d(!0);const E=Math.round(Q.GetAngleByPoints(g,f,new Q(A.x,A.y)))||0;i(E),o(V.RotateNode),ae.emitMethod(ne.MainEngine,V.RotateNode,{workIds:[G],angle:0,workState:j.Start,viewId:n==null?void 0:n.viewId})},L=(P,A)=>{if(n!=null&&n.control.worker.isBusy){I(!0),v(P,A);return}v(P,A)},b=(P,A)=>{if(n!=null&&n.control.worker.isBusy){I(!0),v(P,A);return}N.current||(u({x:A.x,y:A.y}),d(!0),N.current=setTimeout(()=>{N.current=0;const E=Math.round(Q.GetAngleByPoints(g,f,new Q(A.x,A.y)))||0;i(E),o(V.RotateNode),c(j.Doing),ae.emitMethod(ne.MainEngine,V.RotateNode,{workIds:[G],angle:E,workState:j.Doing,viewId:n==null?void 0:n.viewId})},60))};return y.createElement(Yt,{disabled:w,position:l,onStart:x,onDrag:b,onStop:L},y.createElement("div",{className:`${s}`,style:e?{left:0,top:0,touchAction:"none"}:void 0},!h&&y.createElement("div",{className:"appliance-plugin-rotate-btn",style:{backgroundColor:e==null?void 0:e.selectorColor}},y.createElement("img",{alt:"icon",src:Ee("rotation-button")})),y.createElement("div",{ref:C,className:`appliance-plugin-rotate-mouse-pointer ${h?"active":""}`},y.createElement("img",{alt:"icon",src:Ee("rotation")}),y.createElement("div",{className:"angle-icon"},t,"°"))))},vw=r=>{const{editors:s,canSelectorSwitch:e}=r,{floatBarData:t,setOperationType:i,mananger:o,isNoPointerEvents:n}=y.useContext(Se),[a,c]=y.useState(),[l,u]=y.useState(!1),h=y.useRef(0),d=y.useRef(),g=y.useRef(j.Pending),p=y.useMemo(()=>!!((t==null?void 0:t.scaleType)===ce.none&&(t!=null&&t.canLock)),[t]),f=y.useMemo(()=>t&&t.w&&t.h?{position:"absolute",left:0,top:0,width:t.w,height:t.h,zIndex:2,pointerEvents:p||n?"none":"auto",touchAction:"none"}:{display:"none",pointerEvents:"none"},[t,p,n]),m=v=>{if(!v||t!=null&&t.isLocked){u(!0),g.current=j.Pending,i(V.None);return}u(!1)},w=(v,x)=>{h.current&&(clearTimeout(h.current),h.current=0);const L={x:x.x,y:x.y};i(V.None),g.current=j.Done,c(L),ae.emitMethod(ne.MainEngine,V.TranslateNode,{workIds:[G],position:L,workState:j.Done,viewId:o==null?void 0:o.viewId})};y.useEffect(()=>(ae.activeListener(m),()=>{ae.unmountActiveListener(m)}),[]),y.useEffect(()=>{if(t&&(t!=null&&t.isLocked)||o!=null&&o.control.worker.isBusy){u(!0);return}u(!1)},[t,o==null?void 0:o.control.worker.isBusy]),y.useEffect(()=>{(g.current===j.Pending||g.current===j.Done)&&O.isNumber(t==null?void 0:t.x)&&O.isNumber(t==null?void 0:t.y)&&c({x:t==null?void 0:t.x,y:t==null?void 0:t.y})},[t==null?void 0:t.x,t==null?void 0:t.y]);const I=()=>{if(o!=null&&o.control.worker.isBusy){u(!0);return}h.current&&(clearTimeout(h.current),h.current=0),O.isNumber(t==null?void 0:t.x)&&O.isNumber(t==null?void 0:t.y)&&(i(V.TranslateNode),g.current=j.Start,ae.emitMethod(ne.MainEngine,V.TranslateNode,{workIds:[G],position:{x:t==null?void 0:t.x,y:t==null?void 0:t.y},workState:j.Start,viewId:o==null?void 0:o.viewId}))},N=(v,x)=>{var P;o!=null&&o.control.worker.isBusy&&u(!0);const L=g.current,b=d.current;if(w(v,x),d.current&&(d.current=void 0),L===j.Start&&(s!=null&&s.size)&&b){const A=(P=o==null?void 0:o.control.viewContainerManager.getView(o.viewId))==null?void 0:P.focusScenePath;A&&(o==null||o.control.worker.blurSelector(o.viewId,A))}},C=(v,x)=>{if(o!=null&&o.control.worker.isBusy){u(!0),w(v,x);return}if(h.current)return;const L={x:x.x,y:x.y};c(L),h.current=setTimeout(()=>{h.current=0,(L.x!==(a==null?void 0:a.x)||L.y!==(a==null?void 0:a.y))&&(d.current&&(d.current=void 0),g.current=j.Doing,ae.emitMethod(ne.MainEngine,V.TranslateNode,{workIds:[G],position:L,workState:j.Doing,viewId:o==null?void 0:o.viewId}))},60)},S=y.useMemo(()=>{if(s){const v=L=>{e&&(d.current=L)},x=()=>{o&&e&&g.current===j.Start&&d.current&&o.control.textEditorManager.active(d.current)};return y.createElement(pw,{editors:s,selectIds:(t==null?void 0:t.selectIds)||[],handleTextEditorPointerDown:v,handleTextEditorPointerUp:x})}return null},[s,t==null?void 0:t.selectIds,o,e]);return y.createElement(Yt,{disabled:l,position:a,onStart:I,onDrag:C,onStop:N},y.createElement("div",{style:f},S))},Nw=r=>{const{className:s}=r,[e,t]=y.useState({x:0,y:0,h:0,w:0}),[i,o]=y.useState(),[n,a]=y.useState(),[c,l]=y.useState(),{floatBarData:u,mananger:h,isNoPointerEvents:d,setOperationType:g}=y.useContext(Se),[p,f]=y.useState(),[m,w]=y.useState(!1),I=y.useRef(0);y.useEffect(()=>{if(u&&h){const A={x:u.x,y:u.y,w:u.w,h:u.h};t(A)}return ae.activeListener(C),()=>{ae.unmountActiveListener(C)}},[]),y.useEffect(()=>{if(h!=null&&h.control.worker.isBusy){w(!0);return}w(!1)},[h==null?void 0:h.control.worker.isBusy]);const N=()=>{if(I.current&&(clearTimeout(I.current),I.current=0),p){const{scale:A,translate:E}=p;g(V.None),ae.emitMethod(ne.MainEngine,V.ScaleNode,{workIds:[G],scale:A,dir:c,translate:E,originPoint:i,scenePoint:n,workState:j.Done,viewId:h==null?void 0:h.viewId})}},C=A=>{if(!A){w(!0);return}w(!1)},S=A=>[[A.x,A.y],[A.x+A.w,A.y],[A.x+A.w,A.y+A.h],[A.x,A.y+A.h]],v=(A,E)=>{switch(E){case"top":case"topLeft":case"left":return A[2];case"topRight":return A[3];case"right":case"bottomRight":case"bottom":return A[0];case"bottomLeft":return A[1]}},x=(A,E,R,z)=>{let Z=!1,ee=!1;const F={x:e.x,y:e.y,w:e.w,h:e.h},$=[1,1],te=[0,0];switch(A){case"top":{const J=E.height+e.h;J<0?(ee=!0,F.y=e.y+e.h,F.h=Math.abs(J)):(F.y=e.y-E.height,F.h=e.h+E.height);break}case"topLeft":{const J=E.width+e.w;J<0?(Z=!0,F.x=e.x+e.w,F.w=Math.abs(J)):(F.x=e.x-E.width,F.w=e.w+E.width);const de=E.height+e.h;de<0?(ee=!0,F.y=e.y+e.h,F.h=Math.abs(de)):(F.y=e.y-E.height,F.h=e.h+E.height);break}case"topRight":{const J=E.width+e.w;J<0?(Z=!0,F.x=e.x+J,F.w=Math.abs(J)):F.w=e.w+E.width;const de=E.height+e.h;de<0?(ee=!0,F.y=e.y+e.h,F.h=Math.abs(de)):(F.y=e.y-E.height,F.h=e.h+E.height);break}case"bottom":{const J=E.height+e.h;J<0?(ee=!0,F.y=e.y+J,F.h=Math.abs(J)):F.h=e.h+E.height;break}case"bottomLeft":{const J=E.width+e.w;J<0?(Z=!0,F.x=e.x+e.w,F.w=Math.abs(J)):(F.x=e.x-E.width,F.w=e.w+E.width);const de=E.height+e.h;de<0?(ee=!0,F.y=e.y+de,F.h=Math.abs(de)):F.h=e.h+E.height;break}case"left":{const J=E.width+e.w;J<0?(Z=!0,F.x=e.x+e.w,F.w=Math.abs(J)):(F.x=e.x-E.width,F.w=e.w+E.width);break}case"bottomRight":{const J=E.width+e.w;J<0?(Z=!0,F.x=e.x+J,F.w=Math.abs(J)):F.w=e.w+E.width;const de=E.height+e.h;de<0?(ee=!0,F.y=e.y+de,F.h=Math.abs(de)):F.h=e.h+E.height;break}case"right":{const J=E.width+e.w;J<0?(Z=!0,F.x=e.x+J,F.w=Math.abs(J)):F.w=e.w+E.width;break}}$[0]=F.w/e.w,$[1]=F.h/e.h;const ie=S(F).map(J=>R.control.viewContainerManager.transformToScenePoint(J,R.viewId)),_=v(ie,A);return ee&&(te[1]=_[1]-z[1]),Z&&(te[0]=_[0]-z[0]),{scale:$,translate:te}},L=(A,E)=>{if(I.current&&(clearTimeout(I.current),I.current=0),h!=null&&h.control.worker.isBusy){w(!0);return}if(u!=null&&u.w&&(u!=null&&u.h)&&h){const R={x:u.x,y:u.y,w:u.w,h:u.h},z=S(R),Z=z.map($=>h.control.viewContainerManager.transformToScenePoint($,h.viewId)),ee=v(z,E),F=v(Z,E);t(R),o(ee),a(F),l(E),g(V.ScaleNode),ae.emitMethod(ne.MainEngine,V.ScaleNode,{workIds:[G],originPoint:ee,scenePoint:F,workState:j.Start,viewId:h.viewId})}},b=(A,E,R,z)=>{if(!(!h||!i||!n)){if(h!=null&&h.control.worker.isBusy){w(!0),N();return}I.current||(I.current=setTimeout(()=>{I.current=0;const{scale:Z,translate:ee}=x(E,z,h,n);(!O.isEqual(Z,p==null?void 0:p.scale)||!O.isEqual(ee,p==null?void 0:p.translate))&&(f({scale:Z,translate:ee}),g(V.ScaleNode),ae.emitMethod(ne.MainEngine,V.ScaleNode,{workIds:[G],scale:Z,dir:E,translate:ee,originPoint:i,scenePoint:n,workState:j.Doing,viewId:h.viewId}))},60))}},P=()=>{h!=null&&h.control.worker.isBusy&&w(!0),N()};return y.createElement(Ln.Resizable,{className:`${s}`,boundsByDirection:!0,minWidth:-(((u==null?void 0:u.x)||0)+((u==null?void 0:u.w)||0)),minHeight:-(((u==null?void 0:u.y)||0)+((u==null?void 0:u.h)||0)),size:{width:(u==null?void 0:u.w)||0,height:(u==null?void 0:u.h)||0},style:{position:"absolute",left:u==null?void 0:u.x,top:u==null?void 0:u.y,pointerEvents:d?"none":"auto"},enable:m?!1:{top:(u==null?void 0:u.scaleType)===ce.all&&!0||!1,right:(u==null?void 0:u.scaleType)===ce.all&&!0||!1,bottom:(u==null?void 0:u.scaleType)===ce.all&&!0||!1,left:(u==null?void 0:u.scaleType)===ce.all&&!0||!1,topRight:!0,bottomRight:!0,bottomLeft:!0,topLeft:!0},lockAspectRatio:(u==null?void 0:u.scaleType)===ce.proportional,onResizeStart:L,onResize:b,onResizeStop:P})},mo=r=>{const{id:s,pos:e,pointMap:t,type:i}=r,{setOperationType:o,mananger:n,floatBarData:a}=y.useContext(Se),[c,l]=y.useState({x:0,y:0}),[u,h]=y.useState(j.Pending),[d,g]=y.useState(!1),p=y.useRef(0),f=y.useMemo(()=>a?{left:0,top:0}:{},[a]),m=S=>{if(!S||a!=null&&a.isLocked){g(!0),h(j.Pending),o(V.None);return}g(!1)};y.useEffect(()=>(ae.activeListener(m),()=>{ae.unmountActiveListener(m)}),[]),y.useEffect(()=>{O.isNumber(e.x)&&O.isNumber(e.y)&&(u===j.Pending||u===j.Done)&&l({x:e.x,y:e.y})},[e,u]),y.useEffect(()=>{if(a&&(a!=null&&a.isLocked)||n!=null&&n.control.worker.isBusy){g(!0);return}g(!1)},[a,n==null?void 0:n.control.worker.isBusy]);const w=(S,v)=>{p.current&&(clearTimeout(p.current),p.current=0),o(V.None),h(j.Done);const x={x:v.x,y:v.y};if(l(x),n!=null&&n.control.viewContainerManager){const L=n.control.viewContainerManager.transformToScenePoint([x.x,x.y],n.viewId),b=t.get(s);b&&i==="start"?b[0]=L:b&&i==="end"&&(b[1]=L),ae.emitMethod(ne.MainEngine,V.SetPoint,{workId:G,pointMap:t,workState:j.Done,viewId:n==null?void 0:n.viewId})}},I=()=>{if(p.current&&(clearTimeout(p.current),p.current=0),n!=null&&n.control.worker.isBusy){g(!0);return}O.isNumber(e.x)&&O.isNumber(e.y)&&(o(V.SetPoint),h(j.Start),ae.emitMethod(ne.MainEngine,V.SetPoint,{workId:G,pointMap:t,workState:j.Start,viewId:n==null?void 0:n.viewId}))},N=(S,v)=>{if(n!=null&&n.control.worker.isBusy){g(!0),w(S,v);return}if(p.current)return;const x={x:v.x,y:v.y};l(x),p.current=setTimeout(()=>{if(p.current=0,(x.x!==(v==null?void 0:v.x)||x.y!==(v==null?void 0:v.y))&&(n!=null&&n.control.viewContainerManager)){const L=n.control.viewContainerManager.transformToScenePoint([x.x,x.y],n.viewId),b=t.get(s);b&&i==="start"?b[0]=L:b&&i==="end"&&(b[1]=L),h(j.Doing),ae.emitMethod(ne.MainEngine,V.SetPoint,{workId:G,pointMap:t,workState:j.Doing,viewId:n==null?void 0:n.viewId})}},60)},C=(S,v)=>{n!=null&&n.control.worker.isBusy&&g(!0),w(S,v)};return y.createElement(Yt,{disabled:d,position:c,onStart:I,onDrag:N,onStop:C},y.createElement("div",{className:"appliance-plugin-point-draggable-btn",style:f}))},Sw=r=>{const{className:s}=r,{floatBarData:e,mananger:t}=y.useContext(Se),[i,o]=y.useState(),[n,a]=y.useState(),[c,l]=y.useState(new Map);y.useEffect(()=>{const d=[];if(t&&(e!=null&&e.points)){const g=t.viewId;if(t.control.viewContainerManager.getView(g))for(const f of e.points){const m=t.control.viewContainerManager.transformToOriginPoint(f,g);d.push(m)}e!=null&&e.selectIds&&e.selectIds.length===1&&(c.set(e.selectIds[0],e.points),l(c))}d[0]&&o({x:d[0][0],y:d[0][1]}),d[1]&&a({x:d[1][0],y:d[1][1]})},[t,e==null?void 0:e.points,e==null?void 0:e.selectIds,c]);const u=y.useMemo(()=>i&&(e!=null&&e.selectIds)?y.createElement(mo,{pos:i,type:"start",id:e.selectIds[0],pointMap:c}):null,[i,e==null?void 0:e.selectIds,c]),h=y.useMemo(()=>n&&(e!=null&&e.selectIds)?y.createElement(mo,{pos:n,type:"end",id:e.selectIds[0],pointMap:c}):null,[n,e==null?void 0:e.selectIds,c]);return y.createElement("div",{className:`${s}`},u,h)},Cw=y.forwardRef((r,s)=>{const{floatBarData:e,operationType:t}=y.useContext(Se),i=y.useMemo(()=>(e==null?void 0:e.scaleType)!==ce.all||t===V.RotateNode?null:y.createElement(yw,null),[e,t]),o=y.useMemo(()=>(e==null?void 0:e.scaleType)!==ce.both||t===V.RotateNode?null:y.createElement(mw,null),[e,t]),n=y.useMemo(()=>(e==null?void 0:e.scaleType)!==ce.proportional||t===V.RotateNode?null:y.createElement(ww,null),[e,t]),a=y.useMemo(()=>(e==null?void 0:e.scaleType)===ce.none&&(e!=null&&e.canLock)?y.createElement(Iw,null):null,[e]);return y.createElement("div",{ref:s,style:e?{transform:`translate(${e.x}px,${e.y}px)`,width:e.w,height:e.h,pointerEvents:"none"}:void 0},a,i,o,n,r.children)}),kw=y.forwardRef((r,s)=>{const{floatBarData:e,operationType:t,mananger:i}=y.useContext(Se),{editors:o,isHide:n,canSelectorSwitch:a}=r,c=y.useMemo(()=>{var d;return e!=null&&e.canRotate&&((d=e==null?void 0:e.selectIds)==null?void 0:d.length)===1&&(t===V.None||t===V.RotateNode)?y.createElement(Tw,{className:We.RotateBtn}):null},[e,t]),l=y.useMemo(()=>((e==null?void 0:e.scaleType)===ce.all||(e==null?void 0:e.scaleType)===ce.proportional)&&(t===V.None||t===V.ScaleNode)&&O.isNumber(e==null?void 0:e.x)&&O.isNumber(e==null?void 0:e.y)?y.createElement(Nw,{className:We.ResizeBtn}):null,[e==null?void 0:e.scaleType,t,e==null?void 0:e.x,e==null?void 0:e.y]),u=y.useMemo(()=>(e==null?void 0:e.scaleType)===ce.both&&(t===V.None||t===V.SetPoint)?y.createElement(Sw,{className:We.ResizeTowBox}):null,[e==null?void 0:e.scaleType,t]),h=y.useMemo(()=>n&&t===V.None&&O.isNumber(e==null?void 0:e.x)&&O.isNumber(e==null?void 0:e.y)&&O.isNumber(e==null?void 0:e.w)&&O.isNumber(e==null?void 0:e.h)?y.createElement("div",{className:We.FloatBarBtn,style:{left:e==null?void 0:e.x,top:e==null?void 0:e.y,width:e.w,height:e.h}},y.createElement(Cn,{position:{x:e.x,y:e.y},textOpt:e==null?void 0:e.textOpt,noLayer:e==null?void 0:e.isLocked})):null,[e==null?void 0:e.x,e==null?void 0:e.y,e==null?void 0:e.w,e==null?void 0:e.h,e==null?void 0:e.textOpt,e==null?void 0:e.isLocked,t,n]);return y.createElement("div",{className:We.FloatBar,onPointerOver:d=>(is(d),i==null||i.control.worker.blurCursor(i.viewId),!1)},y.createElement(Cw,{ref:s}),y.createElement(vw,{editors:o,canSelectorSwitch:a}),c,l,u,h)}),xw=y.memo(kw,(r,s)=>!!O.isEqual(r,s));class Dw extends y.Component{constructor(e){super(e);M(this,"renderAvatar",e=>{var i;const t=`rgb(${e.memberState.strokeColor[0]}, ${e.memberState.strokeColor[1]}, ${e.memberState.strokeColor[2]})`;if(this.detectAvatar(e)){const o=this.getCursorName(e);return y.createElement("img",{className:"cursor-selector-avatar",style:{width:o?19:28,height:o?19:28,position:o?"initial":"absolute",borderColor:o?"white":t,marginRight:o?4:0},src:(i=e.payload)==null?void 0:i.avatar,alt:"avatar"})}else return null});M(this,"getOpacity",e=>{const t=this.getCursorName(e),i=this.detectAvatar(e);return t===void 0&&i===void 0?0:1});M(this,"getCursorName",e=>{if(e.payload)return e.payload.nickName||e.payload.cursorName||e.payload.uid});M(this,"getThemeClass",e=>e.payload&&e.payload.theme?"cursor-inner-mellow":"cursor-inner");M(this,"getCursorBackgroundColor",e=>{const t=this.getCursorName(e);return e.payload&&e.payload.cursorBackgroundColor?e.payload.cursorBackgroundColor:t?`rgb(${e.memberState.strokeColor[0]}, ${e.memberState.strokeColor[1]}, ${e.memberState.strokeColor[2]})`:void 0});M(this,"getCursorTextColor",e=>e.payload&&e.payload.cursorTextColor?e.payload.cursorTextColor:"#FFFFFF");M(this,"getCursorTagBackgroundColor",e=>e.payload&&e.payload.cursorTagBackgroundColor?e.payload.cursorTagBackgroundColor:this.getCursorBackgroundColor(e));M(this,"detectAvatar",e=>!!(e.payload&&e.payload.avatar));M(this,"renderTag",e=>{if(e.payload&&e.payload.cursorTagName)return y.createElement("span",{className:"cursor-tag-name",style:{backgroundColor:this.getCursorTagBackgroundColor(e)}},e.payload.cursorTagName)})}render(){const{roomMember:e}=this.props,t=this.getCursorName(e);switch(e.memberState.currentApplianceName){case re.pencil:return y.createElement("div",{className:"cursor-box"},y.createElement("div",{className:"cursor-mid cursor-pencil-offset",style:{transform:"translate(-50%, -100%)",marginLeft:"5px",marginTop:"4px"}},y.createElement("div",{className:"cursor-name"},y.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),y.createElement("span",{className:"cursor-name-text"},t),this.renderTag(e))),y.createElement("div",null,y.createElement("img",{className:"cursor-pencil-image",src:$t.get("pencil"),alt:"pencilCursor"}))));case re.selector:return y.createElement("div",{className:"cursor-box"},y.createElement("div",{className:"cursor-mid cursor-selector-offset",style:{transform:"translate(-50%, -100%)",marginLeft:"3px",marginTop:"17px"}},y.createElement("div",{className:"cursor-name"},y.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),y.createElement("span",{className:"cursor-name-text"},t),this.renderTag(e))),y.createElement("div",null,y.createElement("img",{className:"cursor-selector-image",src:$t.get("selector"),alt:"selectorCursor"}))));case re.eraser:case re.pencilEraser:return y.createElement("div",{className:"cursor-box"},y.createElement("div",{className:"cursor-mid cursor-eraser-offset",style:{transform:"translate(-50%, -100%)",marginLeft:"2px",marginTop:"8px"}},y.createElement("div",{className:"cursor-name"},y.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),y.createElement("span",{className:"cursor-name-text"},t),this.renderTag(e))),y.createElement("div",null,y.createElement("img",{className:"cursor-eraser-image",src:$t.get("eraser"),alt:"eraserCursor"}))));case re.text:return y.createElement("div",{className:"cursor-box"},y.createElement("div",{className:"cursor-mid cursor-text-offset",style:{transform:"translate(-50%, -100%)",marginLeft:"0px"}},y.createElement("div",{className:"cursor-name"},y.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),y.createElement("span",{className:"cursor-name-text"},t),this.renderTag(e))),y.createElement("div",null,y.createElement("img",{className:"cursor-text-image",src:$t.get("text"),alt:"textCursor"}))));case re.rectangle:case re.arrow:case re.straight:case re.shape:case re.ellipse:return y.createElement("div",{className:"cursor-box"},y.createElement("div",{className:"cursor-mid cursor-shape-offset",style:{transform:"translate(-50%, -100%)",marginLeft:"-3px",marginTop:"19px"}},y.createElement("div",{className:"cursor-name"},y.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),y.createElement("span",{className:"cursor-name-text"},t),this.renderTag(e))),y.createElement("div",null,y.createElement("img",{className:"cursor-shape-image",src:$t.get("shape"),alt:"shapeCursor"}))));default:return null}}}const Lw=r=>{var o;const{className:s,info:e}=r,{roomMember:t,...i}=e||{};return y.createElement("div",{"data-cursor-uid":(o=t==null?void 0:t.payload)==null?void 0:o.uid,className:`${s}`,style:i?{transform:`translate(${i.x}px, ${i.y}px)`}:{display:"none"}},t&&y.createElement(Dw,{roomMember:t}))},bw=r=>{const{className:s,manager:e}=r,[t,i]=y.useState();y.useEffect(()=>(e.internalMsgEmitter.on([ne.Cursor,e.viewId],o),()=>{e.internalMsgEmitter.off([ne.Cursor,e.viewId],o)}),[e]);function o(a){i(a)}return y.useMemo(()=>{if(t!=null&&t.length){const a=t.map(c=>{var l;return c.roomMember?y.createElement(Lw,{key:(l=c.roomMember)==null?void 0:l.memberId,className:s,info:c}):null});return y.createElement(y.Fragment,null,a)}return null},[t])},jw=r=>{const{viewId:s,miniMapCanvas:e,highlightColor:t,miniMapManager:i,contianer:o}=r,[n,a]=y.useState();y.useEffect(()=>(c(),i.listener.addListener([s,"viewCameraUpate"],c),i.listener.emitAsync([s,"miniMapCreate"],!0),()=>{i.listener.removeListener([s,"viewCameraUpate"],c)}),[]);const c=()=>{const h=i.maps.get(s);h&&l(h.miniMapCamera,h.viewCamera)},l=(h,d)=>{const{width:g,height:p}=o.getBoundingClientRect(),f=Math.min(g/h.width,p/h.height),m=d.width/d.scale,w=d.height/d.scale,I=[d.centerX,d.centerY],N=[h.centerX,h.centerY],C=[I[0]-N[0],I[1]-N[1]],S=Math.min(h.scale*f,h.scale*f),v=[C[0]*S,C[1]*S,m,w,S];a(v)},u=h=>{var d;if(i.control.renderControl.isWritable){const g=h.nativeEvent.target||h.nativeEvent.srcElement;if(g&&h.nativeEvent&&n){const{width:p,height:f}=g.getBoundingClientRect(),[m,w]=[p/2,f/2],[I,N]=[(h.nativeEvent.offsetX-m)/n[4],(h.nativeEvent.offsetY-w)/n[4]],C=i.maps.get(s);if(C!=null&&C.viewCamera){const[S,v]=[C.miniMapCamera.centerX+I,C.miniMapCamera.centerY+N];(d=i.control.room)==null||d.moveCamera({centerX:S,centerY:v,animationMode:"immediately"})}}}};return y.createElement("div",{style:{position:"relative",width:"100%",height:"100%",overflow:"hidden",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",pointerEvents:"auto"},onClick:u},y.createElement("canvas",{style:{pointerEvents:"none"},ref:e}),n&&y.createElement("div",{className:"minimap-highlightBox",style:{position:"absolute",top:"50%",left:"50%",width:n[2]*n[4],height:n[3]*n[4],boxSizing:"content-box",border:`2px solid ${t}`,transform:`translate(calc(-50% + ${n[0]}px), calc(-50% + ${n[1]}px))`,pointerEvents:"none"}}))},Aw=r=>{const{miniMapManager:s,active:e,className:t}=r,i=y.useMemo(()=>{const o=s.maps;if(e){const n=o.get(e);if(n){const{miniMapCamera:a,viewCamera:c,...l}=n;if(l.contianer&&a&&c){const u=s.highlightColor;return Ts.createPortal(y.createElement(jw,{viewId:e,...l,highlightColor:u,miniMapManager:s}),l.contianer)}}}return null},[e,s]);return y.createElement("div",{className:t},i)},Se=y.createContext({viewId:"",mananger:void 0,floatBarColors:[],floatBarData:void 0,dpr:1,angle:0,operationType:V.None,scale:[1,1],isNoPointerEvents:!1,activeTextEditor:!1,activeTextId:void 0,setAngle:()=>{},setOperationType:()=>{},setFloatBarData:()=>{}});class Ti extends y.Component{constructor(e){var i,o,n;super(e);M(this,"showTextFloatBar");M(this,"canSelectorSwitch");M(this,"rightBoundBreak");M(this,"setAngle",e=>{this.setState({angle:e})});M(this,"setOperationType",e=>{this.setState({operationType:e})});this.state={floatBarData:void 0,showFloatBar:!1,showFloatBarBtn:!0,dpr:1,angle:0,operationType:V.None,scale:[1,1],editors:this.editors,activeTextId:(i=this.props.mananger.control.textEditorManager)==null?void 0:i.activeId,activeMiniMapViewId:(o=this.props.mananger.control.miniMapManager)==null?void 0:o.activeViewId};const t=(n=this.props.mananger.control.pluginOptions)==null?void 0:n.textEditor;this.showTextFloatBar=O.isBoolean(t==null?void 0:t.showFloatBar)?t.showFloatBar:Ie.textEditor.showFloatBar,this.canSelectorSwitch=O.isBoolean(t==null?void 0:t.canSelectorSwitch)?t.canSelectorSwitch:Ie.textEditor.canSelectorSwitch,this.rightBoundBreak=O.isBoolean(t==null?void 0:t.rightBoundBreak)?t.rightBoundBreak:Ie.textEditor.rightBoundBreak}get editors(){return Pe(this.props.mananger.control.textEditorManager.filterEditor(this.props.mananger.viewId))}componentDidMount(){this.props.mananger.vDom=this,this.props.mananger.mountView(),this.setState({dpr:this.props.mananger.dpr})}componentWillUnmount(){}setActiveMiniMap(e){this.setState({activeMiniMapViewId:e})}showFloatBarBtn(e){this.setState({showFloatBarBtn:e})}showFloatBar(e,t){const i=e&&t&&{...this.state.floatBarData,...t}||void 0;this.setState({showFloatBar:e,floatBarData:i,angle:0})}activeTextEditor(){this.setState({activeTextEditor:!0})}unActiveTextEditor(){this.setState({activeTextEditor:!1})}updateTextEditorInfo(e){this.setState({activeTextId:e,editors:this.editors})}setFloatBarData(e){this.state.floatBarData&&this.setState({floatBarData:{...this.state.floatBarData,...e}})}render(){var t,i,o,n,a,c;const e=!!((i=(t=this.props.mananger.control)==null?void 0:t.room)!=null&&i.floatBarOptions);return y.createElement("div",{className:We.Container},!this.props.mananger.control.hasOffscreenCanvas()&&y.createElement("div",{className:We.CanvasBox,ref:this.props.refs.canvasContainerRef})||y.createElement("div",{className:We.CanvasBox},y.createElement("canvas",{id:"bgCanvas",ref:this.props.refs.canvasBgRef,style:{width:"100%",height:"100%"}}),y.createElement("canvas",{id:"serviceCanvas",className:We.FloatCanvas,ref:this.props.refs.canvasServiceFloatRef,style:{width:"100%",height:"100%"}}),y.createElement("canvas",{id:"localCanvas",className:We.FloatCanvas,ref:this.props.refs.canvasFloatRef,style:{width:"100%",height:"100%"}}),y.createElement("div",{id:"subLocalCanvas",className:We.CanvasBoxSub,ref:this.props.refs.subLocalCanvasContainerRef}),y.createElement("canvas",{id:"topCanvas",className:We.TopFloatCanvas,ref:this.props.refs.canvasTopRef,style:{width:"100%",height:"100%"}})),!this.props.mananger.control.hasOffscreenCanvas()&&this.props.refs.snapshotContainerRef&&y.createElement("div",{className:We.SnapshotBox,ref:this.props.refs.snapshotContainerRef})||null,y.createElement(Se.Provider,{value:{viewId:this.props.viewId,mananger:this.props.mananger,floatBarColors:e&&((a=(n=(o=this.props.mananger.control)==null?void 0:o.room)==null?void 0:n.floatBarOptions)==null?void 0:a.colors)||[],isNoPointerEvents:!this.state.showFloatBarBtn,floatBarData:this.state.floatBarData,dpr:this.state.dpr,angle:this.state.angle,operationType:this.state.operationType,scale:this.state.scale,activeTextEditor:this.state.activeTextEditor,activeTextId:this.state.activeTextId,setAngle:this.setAngle.bind(this),setOperationType:this.setOperationType.bind(this),setFloatBarData:this.setFloatBarData.bind(this)}},this.state.showFloatBar&&y.createElement(xw,{ref:this.props.refs.floatBarRef,editors:this.state.editors,isHide:e&&this.state.showFloatBarBtn,canSelectorSwitch:this.canSelectorSwitch})||null,((c=this.state.editors)==null?void 0:c.size)&&y.createElement(Mw,{className:We.TextEditorContainer,showFloatBtns:this.showTextFloatBar&&e&&this.state.showFloatBarBtn||!1,editors:this.state.editors,rightBoundBreak:this.rightBoundBreak})||null),y.createElement(bw,{className:We.CursorBox,manager:this.props.mananger}),y.createElement(Aw,{className:We.MiniMapBox,active:this.state.activeMiniMapViewId,miniMapManager:this.props.mananger.control.miniMapManager}))}}class Pw extends Nn{constructor(e,t){super(e,t);M(this,"width",1e3);M(this,"height",1e3);M(this,"dpr",ut());M(this,"vDom");M(this,"eventTragetElement");M(this,"snapshotContainerRef");M(this,"canvasContainerRef",y.createRef());M(this,"subLocalCanvasContainerRef",y.createRef());M(this,"canvasTopRef",y.createRef());M(this,"canvasServiceFloatRef",y.createRef());M(this,"canvasFloatRef",y.createRef());M(this,"canvasBgRef",y.createRef());M(this,"floatBarRef",y.createRef());M(this,"containerOffset",{x:0,y:0});this.control.hasOffscreenCanvas()||(this.snapshotContainerRef=y.createRef())}setCanvassStyle(){if(this.eventTragetElement){const e=this.eventTragetElement.offsetWidth||this.width,t=this.eventTragetElement.offsetHeight||this.height;let i=ut();this.canvasBgRef.current&&(i=ut(this.canvasBgRef.current.getContext("2d"))),i!==this.dpr&&(this.dpr=i,this.control.worker.updateDpr(this.viewId,this.dpr)),e&&t&&this.canvasContainerRef.current&&(e!==this.width||t!==this.height)&&(this.width=e,this.height=t,this.canvasContainerRef.current.style.width=`${e}px`,this.canvasContainerRef.current.style.height=`${t}px`),e&&t&&this.snapshotContainerRef&&this.snapshotContainerRef.current&&(e!==this.width||t!==this.height)&&(this.width=e,this.height=t),e&&t&&this.canvasBgRef.current&&(e!==this.width||t!==this.height)&&(this.width=e,this.height=t,this.canvasBgRef.current.width=e*this.dpr,this.canvasBgRef.current.height=t*this.dpr,this.canvasFloatRef.current&&(this.canvasFloatRef.current.width=e*this.dpr,this.canvasFloatRef.current.height=t*this.dpr),this.canvasServiceFloatRef.current&&(this.canvasServiceFloatRef.current.width=e*this.dpr,this.canvasServiceFloatRef.current.height=t*this.dpr),this.canvasTopRef.current&&(this.canvasTopRef.current.width=e*this.dpr,this.canvasTopRef.current.height=t*this.dpr))}}destroy(){if(super.destroy(),this.eventTragetElement){const e=this.eventTragetElement.parentElement;if(e){const t=e.querySelectorAll(".appliance-plugin-main-view-displayer");for(const i of t)i.remove()}}}createMainViewDisplayer(e){const t=document.createElement("div");return t.className="appliance-plugin-main-view-displayer",e.appendChild(t),this.eventTragetElement=e.children[0],this.containerOffset=this.getContainerOffset(this.eventTragetElement,this.containerOffset),this.bindToolsClass(),Ts.render(y.createElement(Ti,{viewId:this.viewId,mananger:this,refs:{canvasServiceFloatRef:this.canvasServiceFloatRef,canvasFloatRef:this.canvasFloatRef,canvasBgRef:this.canvasBgRef,floatBarRef:this.floatBarRef,canvasTopRef:this.canvasTopRef,canvasContainerRef:this.canvasContainerRef,snapshotContainerRef:this.snapshotContainerRef,subLocalCanvasContainerRef:this.subLocalCanvasContainerRef}}),t),this.control.room&&this.bindDisplayerEvent(this.eventTragetElement),this}}class zw extends Sm{constructor(e,t,i){super(e,t,i);M(this,"dpr",ut());M(this,"width",1e3);M(this,"height",1e3);M(this,"vDom");M(this,"eventTragetElement");M(this,"canvasContainerRef",y.createRef());M(this,"subLocalCanvasContainerRef",y.createRef());M(this,"canvasTopRef",y.createRef());M(this,"canvasServiceFloatRef",y.createRef());M(this,"canvasFloatRef",y.createRef());M(this,"canvasBgRef",y.createRef());M(this,"floatBarRef",y.createRef());M(this,"containerOffset",{x:0,y:0})}setCanvassStyle(){if(this.eventTragetElement){let e=ut();if(this.canvasBgRef.current&&(e=ut(this.canvasBgRef.current.getContext("2d"))),e!==this.dpr&&(this.dpr=e,this.control.worker.updateDpr(this.viewId,this.dpr)),this.canvasContainerRef.current){const t=this.eventTragetElement.offsetWidth||this.width,i=this.eventTragetElement.offsetHeight||this.height;t&&i&&(t!==this.width||i!==this.height)&&(this.width=t,this.height=i,this.canvasContainerRef.current.style.width=`${t}px`,this.canvasContainerRef.current.style.height=`${i}px`)}if(this.canvasBgRef.current){const t=this.eventTragetElement.offsetWidth||this.width,i=this.eventTragetElement.offsetHeight||this.height;t&&i&&(t!==this.width||i!==this.height)&&(this.width=t,this.height=i,this.canvasBgRef.current.width=t*this.dpr,this.canvasBgRef.current.height=i*this.dpr,this.canvasFloatRef.current&&(this.canvasFloatRef.current.width=t*this.dpr,this.canvasFloatRef.current.height=i*this.dpr),this.canvasServiceFloatRef.current&&(this.canvasServiceFloatRef.current.width=t*this.dpr,this.canvasServiceFloatRef.current.height=i*this.dpr),this.canvasTopRef.current&&(this.canvasTopRef.current.width=t*this.dpr,this.canvasTopRef.current.height=i*this.dpr))}}}createAppViewDisplayer(e,t){const i=document.createElement("div");return i.className="appliance-plugin-app-view-displayer",t.appendChild(i),this.eventTragetElement=t.children[0],this.containerOffset=this.getContainerOffset(this.eventTragetElement,this.containerOffset),this.bindToolsClass(),Ts.render(y.createElement(Ti,{viewId:e,mananger:this,refs:{canvasServiceFloatRef:this.canvasServiceFloatRef,canvasFloatRef:this.canvasFloatRef,canvasBgRef:this.canvasBgRef,floatBarRef:this.floatBarRef,canvasTopRef:this.canvasTopRef,canvasContainerRef:this.canvasContainerRef,subLocalCanvasContainerRef:this.subLocalCanvasContainerRef}}),i),this.control.room&&this.bindDisplayerEvent(this.eventTragetElement),this}}class Xe extends Wt{constructor(e){super(e);M(this,"focuedViewId");M(this,"focuedView");M(this,"control");M(this,"tmpFocusedViewId");M(this,"checkScaleTimer");M(this,"onMainViewRelease",async e=>{this.control.textEditorManager.clear(fe,!0),this.mainViewDestroy(e),await new Promise(i=>{setTimeout(()=>{i(!0)},0)}),this.onMainViewMounted(e);const t=this.control.getSnapshootData("memberState");this.control.room&&this.control.onMemberChange(t),this.control.clearSnapshootData()});M(this,"mainViewDestroy",e=>{var t;if(this.mainView&&this.mainView.displayer){this.mainView.displayer.destroy();const i=e.divElement;if(i){const o=i.getElementsByClassName("appliance-plugin-main-view-displayer");for(const n of o)n.remove()}if(this.mainView.container&&i!==this.mainView.container){const o=this.mainView.container.getElementsByClassName("appliance-plugin-main-view-displayer");for(const n of o)n.remove()}(t=this.control.worker)==null||t.destroyViewWorker(this.mainView.id,!0),this.mainView.displayer.destroy(),this.mainView=void 0}});M(this,"onMainViewMounted",e=>{const t=e.divElement;if(!t||!e.focusScenePath||!(e.focusScenePath||e.scenePath))return;const o=new Pw(this.control,be.InternalMsgEmitter),n=e.size.width||o.width,a=e.size.height||o.height,l={dpr:o.dpr,originalPoint:[n/2,a/2],offscreenCanvasOpt:{...Xe.defaultScreenCanvasOpt,width:n,height:a},layerOpt:{...Xe.defaultLayerOpt,width:n,height:a},cameraOpt:{...Xe.defaultCameraOpt,width:n,height:a}},{scale:u,...h}=e.camera;l.cameraOpt={...l.cameraOpt,...h,scale:u===1/0?1:u},this.createMianView({id:fe,container:t,displayer:o,focusScenePath:e.focusScenePath,cameraOpt:l.cameraOpt,viewData:e}),this.setFocuedViewId(fe),o.createMainViewDisplayer(t),e.callbacks.on("onSizeUpdated",this.onMainViewSizeUpdated),e.callbacks.on("onCameraUpdated",this.onMainViewCameraUpdated),e.callbacks.on("onActiveHotkey",this.onActiveHotkeyChange.bind(this))});M(this,"onMainViewSizeUpdated",async()=>{await new Promise(e=>{setTimeout(()=>{e(!0)},0)}),this.mainView&&this.mainView.viewData&&this.updateMainViewCamera()});M(this,"onMainViewCameraUpdated",async()=>{await new Promise(e=>{setTimeout(()=>{e(!0)},0)}),this.updateMainViewCamera()});M(this,"updateMainViewCamera",()=>{if(this.mainView&&this.mainView.viewData){const e=this.mainView.viewData.camera,t=this.mainView.cameraOpt;if(t){const i=t.width,o=t.height,{width:n,height:a}=this.mainView.viewData.size;(n!==i||a!==o)&&this.mainView.displayer.updateSize();const c=e.scale===1/0?1:e.scale,l=e.centerX||0,u=e.centerY||0,h={...t,scale:c,centerX:l,centerY:u,width:n,height:a};O.isEqual(t,h)||(this.mainView.cameraOpt=h),this.checkScaleTimer&&e.scale==1/0&&(clearTimeout(this.checkScaleTimer),this.checkScaleTimer=void 0),!this.checkScaleTimer&&e.scale===1/0&&this.mainView.viewData&&this.mainView.viewData.camera.scale===1/0&&(this.checkScaleTimer=setTimeout(()=>{var d,g;(g=(d=this.mainView)==null?void 0:d.viewData)==null||g.moveCamera({scale:c,centerX:l,centerY:u,animationMode:"immediately"}),this.checkScaleTimer=void 0},500))}}});M(this,"onAppViewMounted",async e=>{var d;const{appId:t,view:i}=e,o=i.divElement;if(!o||!i.focusScenePath)return;const n=this.appViews.get(t);if(n&&n.displayer){let g=o.getElementsByClassName("appliance-plugin-app-view-displayer");for(const p of g)p.remove();if(n.container&&n.container!==o){g=n.container.getElementsByClassName("appliance-plugin-app-view-displayer");for(const p of g)p.remove()}this.destroyAppView(e.appId,!0),(d=this.control.worker)==null||d.destroyViewWorker(t,!0),await new Promise(p=>{setTimeout(()=>{p(!0)},0)})}const a=new zw(t,this.control,be.InternalMsgEmitter),c=i.size.width||a.width,l=i.size.height||a.height,h={dpr:a.dpr,originalPoint:[c/2,l/2],offscreenCanvasOpt:{...Xe.defaultScreenCanvasOpt,width:c,height:l},layerOpt:{...Xe.defaultLayerOpt,width:c,height:l},cameraOpt:{...Xe.defaultCameraOpt,...i.camera,width:c,height:l}};if(this.createAppView({id:t,container:o,displayer:a,cameraOpt:h.cameraOpt,focusScenePath:i.focusScenePath,viewData:i}),a.createAppViewDisplayer(t,o),i.callbacks.on("onSizeUpdated",this.onAppViewSizeUpdated.bind(this,t)),i.callbacks.on("onCameraUpdated",this.onAppViewCameraUpdated.bind(this,t)),i.callbacks.on("onActiveHotkey",this.onActiveHotkeyChange.bind(this)),this.tmpFocusedViewId===t){const g=this.control.worker.getLocalWorkViewId();g&&g!==t?this.setFocuedViewId(g):this.setFocuedViewId(t),this.tmpFocusedViewId=void 0}setTimeout(()=>{this.onAppViewCameraUpdated(t)},0)});M(this,"onAppViewSizeUpdated",async e=>{await new Promise(i=>{setTimeout(()=>{i(!0)},0)});const t=this.appViews.get(e);t&&t.viewData&&this.updateAppCamera(e)});M(this,"onAppViewCameraUpdated",async e=>{await new Promise(t=>{setTimeout(()=>{t(!0)},0)}),this.updateAppCamera(e)});M(this,"updateAppCamera",e=>{const t=this.appViews.get(e);if(t&&t.viewData){const i=t.viewData.camera,o=t.cameraOpt;if(o){const{width:n,height:a}=t.viewData.size,c=o.width,l=o.height;(n!==c||a!==l)&&t.displayer.updateSize();const u=i.scale===1/0?1:i.scale,h=i.centerX||0,d=i.centerY||0,g={...o,scale:u,centerX:h,centerY:d,width:n,height:a};O.isEqual(g,o)||(t.cameraOpt=g)}}});this.control=e.control}getViewInitData(e){var i;const t=this.getView(e);if(t){const{width:o,height:n,dpr:a}=t.displayer;(i=this.control.pluginOptions.canvasOpt)!=null&&i.contextType&&(Xe.defaultScreenCanvasOpt.contextType=this.control.pluginOptions.canvasOpt.contextType);const c={dpr:a,originalPoint:[o/2,n/2],offscreenCanvasOpt:{...Xe.defaultScreenCanvasOpt,width:o,height:n},layerOpt:{...Xe.defaultLayerOpt,width:o,height:n},cameraOpt:{...Xe.defaultCameraOpt,width:o,height:n}};if(t.viewData){const{scale:l,...u}=t.viewData.camera;c.cameraOpt={...c.cameraOpt,...u,scale:l===1/0?1:l}}return c}}async mountView(e){var i,o;const t=this.getView(e);if(t){e===((i=this.mainView)==null?void 0:i.id)&&(this.control.cursor.activeCollector(),await this.control.activeWorker());const n=this.getViewInitData(e);if(n&&((o=this.control.worker)==null||o.createViewWorker(e,n)),t.focusScenePath&&this.control.collector){if(this.control.collector.authStorage){const{renderAuth:a,pageAuth:c}=this.control.collector.authStorage;if(a){const l=a[e];if(l){const{render:u,hide:h,clear:d}=l;this.control.renderControl.syncRenderUids(e,u,h,d);return}}if(c){const l=c[e];if(l){this.control.renderControl.syncPageAuth(e,l,!0);return}}}this.control.worker.pullServiceData(e,t.focusScenePath,{isAsync:!0,useAnimation:!1})}}}listenerWindowManager(e){e.emitter.on("focusedChange",t=>{const i=t||fe;if(this.focuedViewId!==i)if(this.getView(i)){const n=this.control.worker.getLocalWorkViewId();n&&n!==i?this.setFocuedViewId(n):this.setFocuedViewId(i)}else this.tmpFocusedViewId=i}),e.emitter.on("mainViewScenePathChange",t=>{this.control.onSceneChange(t,fe)}),e.emitter.on("onMainViewMounted",this.onMainViewMounted),e.emitter.on("onAppViewMounted",this.onAppViewMounted),e.emitter.on("onMainViewRebind",this.onMainViewRelease),e.emitter.on("onBoxClose",t=>{this.appViews.get(t.appId)&&(this.destroyAppView(t.appId),this.control.worker.destroyViewWorker(t.appId))}),e.emitter.on("onAppScenePathChange",t=>{const{appId:i,view:o}=t;this.control.onSceneChange(o.focusScenePath,i)}),e.emitter.on("appsChange",t=>{for(const i of this.appViews.keys())t.includes(i)||(this.destroyAppView(i),this.control.worker.destroyViewWorker(i,!0))})}onActiveHotkeyChange(e){this.control.hotkeyManager.onActiveHotkey(e)}}class pt extends be{constructor(e){super(e);M(this,"windowManager");M(this,"viewContainerManager");const t={control:this,internalMsgEmitter:be.InternalMsgEmitter,publicMsgEmitter:be.PublicMsgEmitter};this.viewContainerManager=new Xe(t)}init(){}activePlugin(){this.collector&&(this.collector.addAuthStateListener((e,t)=>{e&&Object.keys(e).forEach(i=>{var n;const o=(n=e[i])==null?void 0:n.newValue;this.renderControl.syncRenderUids(i,o==null?void 0:o.render,o==null?void 0:o.hide,o==null?void 0:o.clear)}),t&&Object.keys(t).forEach(i=>{var n;const o=(n=t[i])==null?void 0:n.newValue;this.renderControl.syncPageAuth(i,o)})}),this.collector.addStorageStateListener(e=>{var a,c;if((a=this.collector)!=null&&a.storage&&Object.keys(this.collector.storage).length===0){(c=this.worker)==null||c.clearViewScenePath(fe,!0);return}const{diffView:t,diffScenePath:i,diffData:o}=e,n=new Map;if(t){let l;Object.keys(t).forEach(u=>{var d;const h=t[u];if(h&&!h.newValue)(d=this.worker)==null||d.clearViewScenePath(u,!0),h.oldValue&&(l=h.oldValue);else if(h&&h.newValue){for(const g of Object.keys(h.newValue))this.worker.pullServiceData(u,g,{isAsync:!1,useAnimation:!1});l=h.newValue}if(l)for(const g of Object.values(l)){const p=new Set;for(const f of Object.keys(g))f&&p.add(f);n.set(u,p)}})}if(i){let l;Object.keys(i).forEach(u=>{var d;const h=i[u];if(h&&h.viewId&&!h.newValue?((d=this.worker)==null||d.clearViewScenePath(h.viewId,!0),h.oldValue&&(l=h.oldValue)):h&&h.viewId&&h.newValue&&(this.worker.pullServiceData(h.viewId,u,{isAsync:!1,useAnimation:!1}),l=h.newValue),h!=null&&h.viewId&&l){const g=new Set;for(const p of Object.keys(l))p&&g.add(p),n.set(h.viewId,g)}})}o&&Object.keys(o).forEach(l=>{var h,d;const u=o[l];if(u){const{viewId:g}=u,p=n.get(g)||new Set;p.add(l),n.set(g,p),(h=this.worker)==null||h.onServiceDerive(l,u),(d=this.miniMapManager)==null||d.updateMiniMapCamera(g)}});for(const[l,u]of n.entries())be.InternalMsgEmitter.emit("excludeIds",[...u],l)}),this.worker.isActive&&this.viewContainerManager.getAllViews().forEach(e=>{e&&e.focusScenePath&&this.worker.pullServiceData(e.id,e.focusScenePath,{isAsync:!0,useAnimation:!1})}),this.room&&this.roomMember.onUidChangeHook(e=>{var t,i;(t=this.collector)!=null&&t.serviceStorage&&this.viewContainerManager.getAllViews().forEach(o=>{var n,a,c,l;if(o&&o.focusScenePath&&((n=this.collector)!=null&&n.serviceStorage[o.id])&&this.collector.serviceStorage[o.id][o.focusScenePath]){const u=Object.keys(this.collector.serviceStorage[o.id][o.focusScenePath]);for(const h of u){const d=(a=this.collector)==null?void 0:a.getUidFromKey(h);if(d&&!e.online.includes(d))if((c=this.collector)!=null&&c.isSelector(h))this.renderControl.isWritable&&((l=this.collector)==null||l.updateValue(h,void 0,{viewId:o.id,scenePath:o.focusScenePath,isSync:!0})),this.worker.blurSelector(o.id,o.focusScenePath,h);else{const g=this.textEditorManager.editors.get(h);g&&g.opt&&(g.opt.workState===j.Doing||g.opt.workState===j.Start)&&(g.opt.text&&g.opt.text.replace(/\s*,/g,"")?this.textEditorManager.unActive(h):this.textEditorManager.delete(h))}}}}),(i=this.cursor)==null||i.updateRoomMembers(e)}))}async activeWorker(){await this.worker.init()}setWindowManager(e){var t,i,o,n,a;this.windowManager=e,(i=(t=this.windowManager)==null?void 0:t.mainView)!=null&&i.divElement&&this.viewContainerManager.onMainViewMounted(this.windowManager.mainView),(a=(n=(o=this.windowManager.appManager)==null?void 0:o.viewManager)==null?void 0:n.views)!=null&&a.size&&this.windowManager.appManager.viewManager.views.forEach((c,l)=>{this.viewContainerManager.onAppViewMounted({appId:l,view:c})}),this.viewContainerManager.listenerWindowManager(this.windowManager)}}const U=class U extends X.InvisiblePlugin{constructor(){super(...arguments);M(this,"onPhaseChanged",e=>{var t;e===X.RoomPhase.Reconnecting&&((t=U.currentManager)==null||t.setSnapshootData())});M(this,"updateRoomWritable",()=>{var e;(e=U.currentManager)==null||e.onWritableChange(this.displayer.isWritable)});M(this,"roomStateChangeListener",async e=>{var t,i;e!=null&&e.roomMembers&&((t=U.currentManager)==null||t.onRoomMembersChange(e.roomMembers)),!(X.isRoom(this.displayer)&&!this.displayer.isWritable)&&e.memberState&&((i=U.currentManager)==null||i.onMemberChange(e.memberState))})}static async getInstance(e,t){t.options&&(t.options.cdn.useWorker!=="mainThread"&&!t.options.cdn.fullWorkerUrl&&!t.options.cdn.subWorkerUrl&&U.logger.error("[ApplianceMultiPlugin] you must adaptor options cdn fullWorkerUrl and subWorkerUrl"),U.options={...Ie,...t.options});const i=e.displayer,o=i.callbacks.on,n=i.callbacks.off,a=i.callbacks.once,c=e.cleanCurrentScene,l=e.mainView.setMemberState;let u;X.isRoom(i)&&(u=i.setWritable),t!=null&&t.logger&&(U.logger=t.logger);let h=i.getInvisiblePlugin(U.kind);h||(h=await U.createApplianceMultiPlugin(i,U.kind)),i&&h&&U.createCurrentManager(e,U.options,h),h&&U.currentManager&&(U.currentManager.bindPlugin(h),h.init(i));const d={displayer:i,windowManager:e,currentManager:U.currentManager,maxScreenshotWidth:10*1024,maxScreenshotHeight:10*1024,getBoundingRectAsync:async function(p){var w;U.logger.info("[ApplianceMultiPlugin] getBoundingRectAsync");const f=(e.mainView||i).getBoundingRect(p),m=await((w=U.currentManager)==null?void 0:w.getBoundingRect(p));return!f.width||!f.height?m:Mi(f,m)},screenshotToCanvasAsync:async function(p,f,m,w,I,N){var b;U.logger.info("[ApplianceMultiPlugin] screenshotToCanvasAsync");let C=m,S=w,v=I.scale;C>this.maxScreenshotWidth&&(v=this.maxScreenshotWidth/C*v,C=this.maxScreenshotWidth),S>this.maxScreenshotHeight&&(v=Math.min(this.maxScreenshotHeight/S*v,v),S=this.maxScreenshotHeight),I.scale=v;const x=document.createElement("canvas"),L=x.getContext("2d");x.width=C*(N||1),x.height=S*(N||1),L&&((e.mainView||i).screenshotToCanvas(L,f,C,S,I,N),p.drawImage(x,Math.floor((m-C)/2),Math.floor((w-S)/2),C*(N||1),S*(N||1),0,0,C,S),x.remove()),U.currentManager&&await((b=U.currentManager)==null?void 0:b.screenshotToCanvas(p,f,C,S,I,Math.floor((m-C)/2),Math.floor((w-S)/2)))},scenePreviewAsync:async function(p,f,m,w,I){U.logger.info("[ApplianceMultiPlugin] scenePreviewAsync"),(e.mainView||i).scenePreview(p,f,m,w,I);const N=document.createElement("img");N.className="appliance-plugin-fill-scene-snapshot-img",f.append(N),getComputedStyle(f).position||(f.style.position="relative"),U.currentManager&&await U.currentManager.scenePreview(p,N)},fillSceneSnapshotAsync:async function(p,f,m,w,I){U.logger.info("[ApplianceMultiPlugin] fillSceneSnapshotAsync"),f.innerHTML="",(e.mainView||i).fillSceneSnapshot(p,f,m,w,I);const N=m||e.mainView.size.width,C=w||e.mainView.size.height;let S=await this.getBoundingRectAsync(p);S||(S={originX:0,originY:0,width:N,height:C});let v=Math.max(S==null?void 0:S.width,N),x=Math.max(S==null?void 0:S.height,C),L=1;const b=v>N&&Math.min(N/v,L)||L,P=x>C&&Math.min(C/x,L)||L;b<=P?(v=b<1&&N||v,x=Math.floor(x*b)+1,L=b):b>P&&(x=P<1&&C||x,v=Math.floor(v*P)+1,L=P);const A={scale:L,centerX:S.originX+S.width/2,centerY:S.originY+S.height/2},E=document.createElement("canvas"),R=E.getContext("2d");E.width=v,E.height=x,R&&await this.screenshotToCanvasAsync(R,p,v,x,A,devicePixelRatio);const z=document.createElement("img");z.className="appliance-plugin-fill-scene-snapshot-img",z.src=E.toDataURL(),z.onload=()=>{E.remove()},z.onerror=()=>{E.remove(),z.remove()},f.append(z),getComputedStyle(f).position||(f.style.position="relative")},_callbacksOn:function(p,f){U.logger.info(`[ApplianceMultiPlugin] callbacks ${p}`),(p==="onCanUndoStepsUpdate"||p==="onCanRedoStepsUpdate")&&X.isRoom(i)&&i.isWritable?pt.InternalMsgEmitter.on(p,f):o.call(i.callbacks,p,f)},_callbacksOnce:function(p,f){U.logger.info(`[ApplianceMultiPlugin] callbacks ${p}`),(p==="onCanUndoStepsUpdate"||p==="onCanRedoStepsUpdate")&&X.isRoom(i)&&i.isWritable?pt.InternalMsgEmitter.on(p,f):a.call(i.callbacks,p,f)},_callbacksOff:function(p,f){U.logger.info(`[ApplianceMultiPlugin] callbacks ${p}`),(p==="onCanUndoStepsUpdate"||p==="onCanRedoStepsUpdate")&&X.isRoom(i)&&i.isWritable?pt.InternalMsgEmitter.off(p,f):n.call(i.callbacks,p,f)},canRedoSteps(){if(U.logger.info("[ApplianceMultiPlugin] canRedoSteps"),U.currentManager&&X.isRoom(i)&&!i.disableSerialization){const p=U.currentManager.viewContainerManager.focuedView,f=p==null?void 0:p.focusScenePath;if(p&&f)return p.displayer.commiter.redoStack.filter(m=>m.scenePath===f).length}return 0},canUndoSteps(){if(U.logger.info("[ApplianceMultiPlugin] canUndoSteps"),U.currentManager&&X.isRoom(i)&&!i.disableSerialization){const p=U.currentManager.viewContainerManager.focuedView,f=p==null?void 0:p.focusScenePath;if(p&&f)return p.displayer.commiter.undoStack.filter(m=>m.scenePath===f).length}return 0},undo:function(){return U.logger.info("[ApplianceMultiPlugin] undo"),U.currentManager&&X.isRoom(i)&&!i.disableSerialization?U.currentManager.viewContainerManager.undo():0},redo:function(){return U.logger.info("[ApplianceMultiPlugin] redo"),U.currentManager&&X.isRoom(i)&&!i.disableSerialization?U.currentManager.viewContainerManager.redo():0},cleanCurrentScene:function(){U.logger.info("[ApplianceMultiPlugin] cleanCurrentScene"),U.currentManager&&X.isRoom(i)&&i.isWritable&&(U.currentManager.cleanCurrentScene(),c.call(e))},insertImage:function(p){U.logger.info("[ApplianceMultiPlugin] insertImage"),U.currentManager&&X.isRoom(i)&&i.isWritable&&U.currentManager.worker.insertImage(fe,p)},lockImage:function(p,f){U.logger.info("[ApplianceMultiPlugin] lockImage"),U.currentManager&&X.isRoom(i)&&i.isWritable&&U.currentManager.worker.lockImage(fe,p,f)},completeImageUpload:function(p,f){U.logger.info("[ApplianceMultiPlugin] completeImageUpload"),U.currentManager&&X.isRoom(i)&&i.isWritable&&U.currentManager.worker.completeImageUpload(fe,p,f)},getImagesInformation:function(p){return U.logger.info("[ApplianceMultiPlugin] completeImageUpload"),U.currentManager&&X.isRoom(i)&&i.isWritable?U.currentManager.worker.getImagesInformation(p):[]},callbacks:()=>(U.logger.info("[ApplianceMultiPlugin] callbacks bind"),{...i.callbacks,on:d._callbacksOn.bind(d),once:d._callbacksOnce.bind(d),off:d._callbacksOff.bind(d)}),destroy(){U.currentManager&&(U.logger.info("[ApplianceMultiPlugin] destroy"),U.currentManager.destroy(),U.currentManager=void 0)},setMemberState(p){U.logger.info(`[ApplianceMultiPlugin] setMemberState ${JSON.stringify(p)}`);const f=Object.keys(p);if(X.isRoom(i)&&i.isWritable){f.includes("currentApplianceName")&&(p.currentApplianceName&&p.currentApplianceName===re.laserPen?(p.currentApplianceName=re.pencil,p.useLaserPen=!0):p.currentApplianceName&&p.currentApplianceName===re.pencil&&(p.useLaserPen=!1)),l.call(e.mainView,p);return}throw new Error("[ApplianceMultiPlugin] setMemberState must be called in writable room")},setPerformancePriority(p){U.logger.info("[ApplianceMultiPlugin] setPriority"),U.currentManager&&U.currentManager.setPriority(p)},createMiniMap:async function(p,f){if(U.logger.info("[ApplianceMultiPlugin] createMiniMap"),U.currentManager&&X.isRoom(i)&&i.isWritable)return U.currentManager.createMiniMap(p,f)},destroyMiniMap:async function(p){if(U.logger.info("[ApplianceMultiPlugin] destroyeMiniMap"),U.currentManager&&X.isRoom(i)&&i.isWritable)return U.currentManager.destroyMiniMap(p)},filterRenderByUid(p,f,m){if(U.logger.info("[ApplianceMultiPlugin] filterRenderByUid"),U.currentManager&&X.isRoom(i)&&i.isWritable)return U.currentManager.filterRenderByUid(p,f,m)},cancelFilterRender(p,f){if(U.logger.info("[ApplianceMultiPlugin] filterRenderByUid"),U.currentManager&&X.isRoom(i)&&i.isWritable)return U.currentManager.cancelFilterRender(p,f)},addListener:(p,f)=>{U.logger.info(`[ApplianceMultiPlugin] addListener ${p}`),pt.PublicMsgEmitter.on(p,f)},removeListener:(p,f)=>{U.logger.info(`[ApplianceMultiPlugin] removeListener ${p}`),pt.PublicMsgEmitter.off(p,f)},usePlugin:p=>{var f;U.logger.info("[ApplianceMultiPlugin] usePlugin",p.kind),(f=U.currentManager)==null||f.usePlugin(p)},getDisableDeviceInputs(){if(U.currentManager&&X.isRoom(i))return U.currentManager.disableDeviceInputs},setDisableDeviceInputs(p){U.logger.info(`[ApplianceMultiPlugin] setDisableDeviceInputs ${p}`),U.currentManager&&X.isRoom(i)&&(U.currentManager.disableDeviceInputs=p)},getDisableCameraTransform(){if(U.currentManager&&X.isRoom(i))return U.currentManager.disableCameraTransform},setDisableCameraTransform(p){U.logger.info(`[ApplianceMultiPlugin] setDisableCameraTransform ${p}`),U.currentManager&&X.isRoom(i)&&(U.currentManager.disableCameraTransform=p)},getDisableEraseImage(){if(U.currentManager&&X.isRoom(i))return U.currentManager.disableEraseImage},setDisableEraseImage(p){U.logger.info(`[ApplianceMultiPlugin] setDisableEraseImage ${p}`),U.currentManager&&X.isRoom(i)&&(U.currentManager.disableEraseImage=p)},setWritable:async function(p){var f;U.logger.info(`[ApplianceMultiPlugin] setWritable ${p}`),X.isRoom(i)&&u&&(await((f=U.currentManager)==null?void 0:f.setWritable(p)),await u.call(i,p))},requestIdleCallback:(p,f)=>{const m=(f==null?void 0:f.timeout)||0,w=performance.now();let I;const N=new MessageChannel;let C;const S=v=>{try{p({didTimeout:v,timeRemaining:()=>{const L=performance.now()-w;return Math.max(0,m-L)}})}catch(x){U.logger.error("[ApplianceMultiPlugin] requestIdleCallback error:",x)}finally{N.port1.close(),N.port2.close(),I!==void 0&&cancelAnimationFrame(I),C!==void 0&&clearTimeout(C)}};return N.port1.onmessage=()=>{I=requestAnimationFrame(()=>{m>0&&performance.now()-w>=m?S(!0):S(!1)})},N.port2.postMessage(null),m>0&&(C=setTimeout(()=>{S(!0)},m)),C||I||0},cancelIdleCallback:p=>{try{clearTimeout(p),cancelAnimationFrame(p)}catch(f){U.logger.error("[ApplianceMultiPlugin] cancelIdleCallback error:",f)}},injectMethodToObject:(p,f)=>{if(U.logger.info(`[ApplianceMultiPlugin] injectMethodToObject ${f}`),typeof p[f]=="function"||typeof p[f]>"u"){p[f]=d[f];return}f==="callbacks"&&(p.callbacks.on=d._callbacksOn.bind(d),p.callbacks.off=d._callbacksOff.bind(d),p.callbacks.once=d._callbacksOnce.bind(d))}};d.injectMethodToObject(e,"undo"),d.injectMethodToObject(e,"redo"),d.injectMethodToObject(e,"cleanCurrentScene"),d.injectMethodToObject(e,"insertImage"),d.injectMethodToObject(e,"completeImageUpload"),d.injectMethodToObject(e,"lockImage"),d.injectMethodToObject(i,"getImagesInformation"),d.injectMethodToObject(i,"callbacks"),d.injectMethodToObject(i,"screenshotToCanvasAsync"),d.injectMethodToObject(i,"getBoundingRectAsync"),d.injectMethodToObject(i,"scenePreviewAsync"),d.injectMethodToObject(i,"fillSceneSnapshotAsync"),d.injectMethodToObject(e.mainView,"setMemberState"),X.isRoom(i)&&d.injectMethodToObject(i,"setWritable"),Object.defineProperty(e,"canUndoSteps",{get(){return d.canUndoSteps()}}),Object.defineProperty(e,"canRedoSteps",{get(){return d.canRedoSteps()}}),pt.InternalMsgEmitter.on("onCanUndoStepsUpdate",p=>{e.emitter.emit("canUndoStepsChange",p)}),pt.InternalMsgEmitter.on("onCanRedoStepsUpdate",p=>{e.emitter.emit("canRedoStepsChange",p)});const g={...d,callbacks:d.callbacks()};return Object.defineProperty(g,"disableDeviceInputs",{set(p){d.setDisableDeviceInputs(p)},get(){return d.getDisableDeviceInputs()}}),Object.defineProperty(g,"disableCameraTransform",{set(p){d.setDisableCameraTransform(p)},get(){return d.getDisableCameraTransform()}}),Object.defineProperty(g,"disableEraseImage",{set(p){d.setDisableEraseImage(p)},get(){return d.getDisableEraseImage()}}),e._appliancePlugin=g,e._appliancePlugin}static onCreate(e){e&&U.currentManager&&(U.currentManager.bindPlugin(e),e.init(e.displayer))}static async createApplianceMultiPlugin(e,t){try{await e.createInvisiblePlugin(U,{})}catch{if(!e.isWritable){await e.setWritable(!0);const n=await this.createApplianceMultiPlugin(e,t);return await e.setWritable(!1),n}}let i=e.getInvisiblePlugin(t);return i||(i=await U.createApplianceMultiPlugin(e,t)),i}get isReplay(){return X.isPlayer(this.displayer)}get callbackName(){return this.isReplay?"onPlayerStateChanged":"onRoomStateChanged"}init(e){var i,o;const t=e.state;(i=U.currentManager)==null||i.onRoomMembersChange(t.roomMembers),X.isRoom(e)&&((o=U.currentManager)==null||o.onMemberChange(t.memberState)),this.displayer.callbacks.on(this.callbackName,this.roomStateChangeListener),this.displayer.callbacks.on("onEnableWriteNowChanged",this.updateRoomWritable),this.displayer.callbacks.on("onPhaseChanged",this.onPhaseChanged)}destroy(){var e;U.logger.info("[ApplianceMultiPlugin] passive destroy"),(e=U.currentManager)==null||e.destroy(),U.currentManager=void 0}};M(U,"kind","appliance-multi-plugin"),M(U,"currentManager"),M(U,"logger",{info:console.log,warn:console.warn,error:console.error}),M(U,"options",Ie),M(U,"createCurrentManager",(e,t,i)=>{U.currentManager&&U.currentManager.destroy();const o={plugin:i,displayer:e.displayer,options:t},n=new pt(o);if(U.logger.info("[ApplianceMultiPlugin] refresh ApplianceMultiManager object"),n.setWindowManager(e),U.currentManager=n,e.room){const a=n.hasOffscreenCanvas();e.room.logger.info(`[ApplianceMultiPlugin] use ${a?"worker":"mainThread"}`)}});let Js=U;class Ew extends Nn{constructor(e,t){super(e,t);M(this,"width",1e3);M(this,"height",1e3);M(this,"dpr",ut());M(this,"vDom");M(this,"viewId",fe);M(this,"eventTragetElement");M(this,"snapshotContainerRef");M(this,"canvasContainerRef",y.createRef());M(this,"subLocalCanvasContainerRef",y.createRef());M(this,"canvasTopRef",y.createRef());M(this,"canvasServiceFloatRef",y.createRef());M(this,"canvasFloatRef",y.createRef());M(this,"canvasBgRef",y.createRef());M(this,"floatBarRef",y.createRef());M(this,"containerOffset",{x:0,y:0});this.control.hasOffscreenCanvas()||(this.snapshotContainerRef=y.createRef())}setCanvassStyle(){if(this.eventTragetElement){const e=this.eventTragetElement.offsetWidth,t=this.eventTragetElement.offsetHeight;let i=ut();this.canvasBgRef.current&&(i=ut(this.canvasBgRef.current.getContext("2d"))),i!==this.dpr&&(this.dpr=i,this.control.worker.updateDpr(this.viewId,this.dpr)),e&&t&&this.canvasContainerRef.current&&(e!==this.width||t!==this.height)&&(this.width=e,this.height=t),e&&t&&this.canvasBgRef.current&&(e!==this.width||t!==this.height)&&(this.width=e,this.height=t,this.canvasBgRef.current.width=e*this.dpr,this.canvasBgRef.current.height=t*this.dpr,this.canvasFloatRef.current&&(this.canvasFloatRef.current.width=e*this.dpr,this.canvasFloatRef.current.height=t*this.dpr),this.canvasServiceFloatRef.current&&(this.canvasServiceFloatRef.current.width=e*this.dpr,this.canvasServiceFloatRef.current.height=t*this.dpr),this.canvasTopRef.current&&(this.canvasTopRef.current.width=e*this.dpr,this.canvasTopRef.current.height=t*this.dpr))}}createMainViewDisplayer(e){return this.vDom||(this.containerOffset=this.getContainerOffset(e,this.containerOffset),this.eventTragetElement=e.parentElement.children[0],e.innerHTML="",Ts.render(y.createElement(Ti,{viewId:this.viewId,mananger:this,refs:{canvasServiceFloatRef:this.canvasServiceFloatRef,canvasFloatRef:this.canvasFloatRef,canvasBgRef:this.canvasBgRef,floatBarRef:this.floatBarRef,canvasTopRef:this.canvasTopRef,canvasContainerRef:this.canvasContainerRef,snapshotContainerRef:this.snapshotContainerRef,subLocalCanvasContainerRef:this.subLocalCanvasContainerRef}}),e),this.control.room&&this.bindDisplayerEvent(this.eventTragetElement)),this}}class ct extends Wt{constructor(e){super(e);M(this,"focuedViewId");M(this,"control");M(this,"focuedView");this.control=e.control}bindMainView(){if(!this.control.divMainView)return;const e=new Ew(this.control,be.InternalMsgEmitter),{width:t,height:i,dpr:o}=e,n={dpr:o,originalPoint:[t/2,i/2],offscreenCanvasOpt:{...ct.defaultScreenCanvasOpt,width:t,height:i},layerOpt:{...ct.defaultLayerOpt,width:t,height:i},cameraOpt:{...ct.defaultCameraOpt,width:t,height:i}},a=this.control.room&&this.control.room.mainView||this.control.play&&this.control.play.mainView;if(a){const{scale:c,...l}=a.camera;n.cameraOpt={...n.cameraOpt,...l,scale:c===1/0?1:c},this.createMianView({id:fe,displayer:e,focusScenePath:a.focusScenePath||a.scenePath,cameraOpt:n.cameraOpt,viewData:a}),this.setFocuedViewId(fe),e.createMainViewDisplayer(this.control.divMainView)}}getViewInitData(e){var i;const t=this.getView(e);if(t){const{width:o,height:n,dpr:a}=t.displayer;(i=this.control.pluginOptions.canvasOpt)!=null&&i.contextType&&(ct.defaultScreenCanvasOpt.contextType=this.control.pluginOptions.canvasOpt.contextType);const c={dpr:a,originalPoint:[o/2,n/2],offscreenCanvasOpt:{...ct.defaultScreenCanvasOpt,width:o,height:n},layerOpt:{...ct.defaultLayerOpt,width:o,height:n},cameraOpt:{...ct.defaultCameraOpt,width:o,height:n}};if(t.viewData){const{scale:l,...u}=t.viewData.camera;c.cameraOpt={...c.cameraOpt,...u,scale:l===1/0?1:l}}return c}}async mountView(e){var i;const t=this.getView(e);if(t){this.control.worker.isActive||(this.control.cursor.activeCollector(),await this.control.activeWorker());const o=this.getViewInitData(e);o&&((i=this.control.worker)==null||i.createViewWorker(e,o)),t.focusScenePath&&this.control.collector&&this.control.worker.pullServiceData(e,t.focusScenePath,{isAsync:!0,useAnimation:!1})}}}class Je extends be{constructor(e){super(e);M(this,"viewContainerManager");M(this,"divMainView");M(this,"onCameraChange",Tn(e=>{var i;const t=this.viewContainerManager.mainView;t&&t.cameraOpt&&(t.cameraOpt.width!==e.width||t.cameraOpt.height!==e.height)&&((i=this.viewContainerManager.mainView)==null||i.displayer.updateSize()),this.viewContainerManager.setFocuedViewCameraOpt(e)},fi,{leading:!1}));const t={control:this,internalMsgEmitter:Je.InternalMsgEmitter,publicMsgEmitter:Je.PublicMsgEmitter};this.viewContainerManager=new ct(t)}init(){Je.InternalMsgEmitter.on(ne.BindMainView,e=>{this.divMainView=e,this.plugin&&!this.viewContainerManager.mainView&&this.viewContainerManager.bindMainView()})}activePlugin(){this.plugin&&this.divMainView&&!this.viewContainerManager.mainView&&this.viewContainerManager.bindMainView(),this.collector&&(this.collector.addStorageStateListener(e=>{var a,c;if((a=this.collector)!=null&&a.storage&&Object.keys(this.collector.storage).length===0){(c=this.worker)==null||c.clearViewScenePath(fe,!0);return}const{diffView:t,diffScenePath:i,diffData:o}=e,n=new Map;if(t){let l;Object.keys(t).forEach(u=>{var d;const h=t[u];if(h&&!h.newValue)(d=this.worker)==null||d.clearViewScenePath(u,!0),h.oldValue&&(l=h.oldValue);else if(h&&h.newValue){for(const g of Object.keys(h.newValue))this.worker.pullServiceData(u,g,{isAsync:!1,useAnimation:!0});l=h.newValue}if(l)for(const g of Object.values(l)){const p=new Set;for(const f of Object.keys(g))f&&p.add(f);n.set(u,p)}})}if(i){let l;Object.keys(i).forEach(u=>{var d;const h=i[u];if(h&&h.viewId&&!h.newValue?((d=this.worker)==null||d.clearViewScenePath(h.viewId,!0),h.oldValue&&(l=h.oldValue)):h&&h.viewId&&h.newValue&&(this.worker.pullServiceData(h.viewId,u,{isAsync:!1,useAnimation:!0}),l=h.newValue),h!=null&&h.viewId&&l){const g=new Set;for(const p of Object.keys(l))p&&g.add(p),n.set(h.viewId,g)}})}o&&Object.keys(o).forEach(l=>{var h,d;const u=o[l];if(u){const{viewId:g}=u,p=n.get(g)||new Set;p.add(l),n.set(g,p),(h=this.worker)==null||h.onServiceDerive(l,u),(d=this.miniMapManager)==null||d.updateMiniMapCamera(g)}});for(const[l,u]of n.entries())be.InternalMsgEmitter.emit("excludeIds",[...u],l)}),this.room&&(this.roomMember.onUidChangeHook(e=>{var t;(t=this.collector)!=null&&t.serviceStorage&&this.viewContainerManager.getAllViews().forEach(i=>{var o,n,a,c,l,u;if(i&&i.focusScenePath&&((o=this.collector)!=null&&o.serviceStorage[i.id])&&((n=this.collector)!=null&&n.serviceStorage[i.id][i.focusScenePath])){const h=Object.keys((a=this.collector)==null?void 0:a.serviceStorage[i.id][i.focusScenePath]);for(const d of h){const g=(c=this.collector)==null?void 0:c.getUidFromKey(d);if(g&&!e.online.includes(g))if((l=this.collector)!=null&&l.isSelector(d))this.renderControl.isWritable&&((u=this.collector)==null||u.updateValue(d,void 0,{viewId:i.id,scenePath:i.focusScenePath,isSync:!0})),this.worker.blurSelector(i.id,i.focusScenePath,d);else{const p=this.textEditorManager.editors.get(d);p&&p.opt&&(p.opt.workState===j.Doing||p.opt.workState===j.Start)&&(p.opt.text&&p.opt.text.replace(/\s*,/g,"")?this.textEditorManager.unActive(d):this.textEditorManager.delete(d))}}}})}),this.worker.isActive&&this.viewContainerManager.getAllViews().forEach(e=>{e&&e.focusScenePath&&this.worker.pullServiceData(e.id,e.focusScenePath,{isAsync:!0,useAnimation:!1})})))}async activeWorker(){await this.worker.init()}}const W=class W extends X.InvisiblePlugin{constructor(){super(...arguments);M(this,"onPhaseChanged",e=>{var t;e===X.RoomPhase.Reconnecting&&((t=W.currentManager)==null||t.setSnapshootData())});M(this,"updateRoomWritable",()=>{var e;(e=W.currentManager)==null||e.onWritableChange(this.displayer.isWritable)});M(this,"roomStateChangeListener",async e=>{var t,i;W.currentManager instanceof Je&&(e.cameraState&&W.currentManager.onCameraChange(e.cameraState),e.sceneState&&W.currentManager.onSceneChange(e.sceneState.scenePath,fe)),e!=null&&e.roomMembers&&((t=W.currentManager)==null||t.onRoomMembersChange(e.roomMembers)),!(X.isRoom(this.displayer)&&!this.displayer.isWritable)&&e.memberState&&((i=W.currentManager)==null||i.onMemberChange(e.memberState))})}static async getInstance(e,t){t.options&&(t.options.cdn.useWorker!=="mainThread"&&!t.options.cdn.fullWorkerUrl&&!t.options.cdn.subWorkerUrl&&W.logger.error("[ApplianceSinglePlugin] you must adaptor options cdn fullWorkerUrl and subWorkerUrl"),W.options={...Ie,...t.options});const i=e.callbacks.on,o=e.callbacks.off,n=e.callbacks.once,a=e.cleanCurrentScene.bind(e),c=e.setMemberState.bind(e);let l;X.isRoom(e)&&(l=e.setWritable),t!=null&&t.logger&&(W.logger=t.logger);let u=e.getInvisiblePlugin(W.kind);u||(u=await W.createAppliancePlugin(e,W.kind)),e&&u&&W.createCurrentManager(e,W.options,u),u&&W.currentManager&&(W.currentManager.bindPlugin(u),u.init(e)),t!=null&&t.cursorAdapter&&(W.cursorAdapter=t.cursorAdapter),W.effectInstance();const h={displayer:e,currentManager:W.currentManager,maxScreenshotWidth:10*1024,maxScreenshotHeight:10*1024,_injectTargetObject:void 0,getBoundingRectAsync:async function(g){var m;W.logger.info("[ApplianceSinglePlugin] getBoundingRectAsync");const p=e.getBoundingRect(g),f=await((m=W.currentManager)==null?void 0:m.getBoundingRect(g));return!p.width||!p.height?f:Mi(p,f)},screenshotToCanvasAsync:async function(g,p,f,m,w,I){var L;W.logger.info("[ApplianceSinglePlugin] screenshotToCanvasAsync");let N=f,C=m,S=w.scale;N>this.maxScreenshotWidth&&(S=this.maxScreenshotWidth/N*S,N=this.maxScreenshotWidth),C>this.maxScreenshotHeight&&(S=Math.min(this.maxScreenshotHeight/C*S,S),C=this.maxScreenshotHeight),w.scale=S;const v=document.createElement("canvas"),x=v.getContext("2d");v.width=N*(I||1),v.height=C*(I||1),x&&(e.screenshotToCanvas(x,p,N,C,w,I),g.drawImage(v,Math.floor((f-N)/2),Math.floor((m-C)/2),N*(I||1),C*(I||1),0,0,N,C),v.remove()),W.currentManager&&await((L=W.currentManager)==null?void 0:L.screenshotToCanvas(g,p,N,C,w,Math.floor((f-N)/2),Math.floor((m-C)/2)))},scenePreviewAsync:async function(g,p,f,m,w){W.logger.info("[ApplianceSinglePlugin] scenePreviewAsync"),e.scenePreview(g,p,f,m,w);const I=document.createElement("img");I.className="appliance-plugin-fill-scene-snapshot-img",p.append(I),getComputedStyle(p).position||(p.style.position="relative"),W.currentManager&&await W.currentManager.scenePreview(g,I)},fillSceneSnapshotAsync:async function(g,p,f,m,w){var z,Z;W.logger.info("[ApplianceSinglePlugin] fillSceneSnapshotAsync"),p.innerHTML="",e.fillSceneSnapshot(g,p,f,m,w);const I=f||((z=e.state.cameraState)==null?void 0:z.width)||0,N=m||((Z=e.state.cameraState)==null?void 0:Z.height)||0;let C=await this.getBoundingRectAsync(g);C||(C={originX:0,originY:0,width:I,height:N});let S=Math.max(C==null?void 0:C.width,I),v=Math.max(C==null?void 0:C.height,N),x=1;const L=S>I&&Math.min(I/S,x)||x,b=v>N&&Math.min(N/v,x)||x;L<=b?(S=L<1&&I||S,v=Math.floor(v*L)+1,x=L):L>b&&(v=b<1&&N||v,S=Math.floor(S*b)+1,x=b);const P={scale:x,centerX:C.originX+C.width/2,centerY:C.originY+C.height/2},A=document.createElement("canvas"),E=A.getContext("2d");A.width=S,A.height=v,E&&await this.screenshotToCanvasAsync(E,g,S,v,P,devicePixelRatio);const R=document.createElement("img");R.className="appliance-plugin-fill-scene-snapshot-img",R.src=A.toDataURL(),R.onload=()=>{A.remove()},R.onerror=()=>{A.remove(),R.remove()},p.append(R),getComputedStyle(p).position||(p.style.position="relative")},_callbacksOn:function(g,p){W.logger.info(`[ApplianceSinglePlugin] callbacks ${g}`),(g==="onCanUndoStepsUpdate"||g==="onCanRedoStepsUpdate")&&X.isRoom(e)&&e.isWritable?Je.InternalMsgEmitter.on(g,p):i.call(e.callbacks,g,p)},_callbacksOnce:function(g,p){W.logger.info(`[ApplianceSinglePlugin] callbacks ${g}`),(g==="onCanUndoStepsUpdate"||g==="onCanRedoStepsUpdate")&&X.isRoom(e)&&e.isWritable?Je.InternalMsgEmitter.on(g,p):n.call(e.callbacks,g,p)},_callbacksOff:function(g,p){W.logger.info(`[ApplianceSinglePlugin] callbacks ${g}`),(g==="onCanUndoStepsUpdate"||g==="onCanRedoStepsUpdate")&&X.isRoom(e)&&e.isWritable?Je.InternalMsgEmitter.off(g,p):o.call(e.callbacks,g,p)},canRedoSteps(){if(W.logger.info("[ApplianceSinglePlugin] canRedoSteps"),W.currentManager&&X.isRoom(e)&&!e.disableSerialization){const g=W.currentManager.viewContainerManager.focuedView,p=g==null?void 0:g.focusScenePath;if(g&&p)return g.displayer.commiter.redoStack.filter(f=>f.scenePath===p).length}return 0},canUndoSteps(){if(W.logger.info("[ApplianceSinglePlugin] canUndoSteps"),W.currentManager&&X.isRoom(e)&&!e.disableSerialization){const g=W.currentManager.viewContainerManager.focuedView,p=g==null?void 0:g.focusScenePath;if(g&&p)return g.displayer.commiter.undoStack.filter(f=>f.scenePath===p).length}return 0},undo:function(){return W.logger.info("[ApplianceSinglePlugin] undo"),W.currentManager&&X.isRoom(e)&&!e.disableSerialization?W.currentManager.viewContainerManager.undo():0},redo:function(){return W.logger.info("[ApplianceSinglePlugin] redo"),W.currentManager&&X.isRoom(e)&&!e.disableSerialization?W.currentManager.viewContainerManager.redo():0},cleanCurrentScene:function(g){W.logger.info("[ApplianceSinglePlugin] cleanCurrentScene"),W.currentManager&&X.isRoom(e)&&e.isWritable&&(W.currentManager.cleanCurrentScene(),a.call(e,g))},insertImage:function(g){W.logger.info("[ApplianceSinglePlugin] insertImage"),W.currentManager&&X.isRoom(e)&&e.isWritable&&W.currentManager.worker.insertImage(fe,g)},lockImage:function(g,p){W.logger.info("[ApplianceSinglePlugin] lockImage"),W.currentManager&&X.isRoom(e)&&e.isWritable&&W.currentManager.worker.lockImage(fe,g,p)},completeImageUpload:function(g,p){W.logger.info("[ApplianceSinglePlugin] completeImageUpload"),W.currentManager&&X.isRoom(e)&&e.isWritable&&W.currentManager.worker.completeImageUpload(fe,g,p)},getImagesInformation:function(g){return W.logger.info("[ApplianceSinglePlugin] completeImageUpload"),W.currentManager&&X.isRoom(e)&&e.isWritable?W.currentManager.worker.getImagesInformation(g):[]},callbacks:()=>({...e.callbacks,on:h._callbacksOn.bind(h),once:h._callbacksOnce.bind(h),off:h._callbacksOff.bind(h)}),destroy(){W.currentManager&&(W.logger.info("[ApplianceSinglePlugin] destroy"),W.currentManager.destroy(),W.currentManager=void 0,W.cursorAdapter=void 0)},setMemberState(g){W.logger.info(`[ApplianceSinglePlugin] setMemberState ${JSON.stringify(g)}`);const p=Object.keys(g);if(X.isRoom(e)&&e.isWritable){p.includes("currentApplianceName")&&(g.currentApplianceName&&g.currentApplianceName===re.laserPen?(g.currentApplianceName=re.pencil,g.useLaserPen=!0):g.currentApplianceName&&g.currentApplianceName===re.pencil&&(g.useLaserPen=!1)),c(g);return}throw new Error("setMemberState must be called in writable room")},setPerformancePriority(g){W.logger.info("[ApplianceSinglePlugin] setPriority"),W.currentManager&&W.currentManager.setPriority(g)},createMiniMap:async function(g,p){if(W.logger.info("[ApplianceSinglePlugin] createMiniMap"),W.currentManager&&X.isRoom(e)&&e.isWritable)return W.currentManager.createMiniMap(g,p)},destroyMiniMap:async function(g){if(W.logger.info("[ApplianceMultiPlugin] destroyeMiniMap"),W.currentManager&&X.isRoom(e)&&e.isWritable)return W.currentManager.destroyMiniMap(g)},filterRenderByUid(g,p,f){if(W.logger.info("[ApplianceSinglePlugin] filterRenderByUid"),W.currentManager&&X.isRoom(e)&&e.isWritable)return W.currentManager.filterRenderByUid(g,p,f)},cancelFilterRender(g,p){if(W.logger.info("[ApplianceSinglePlugin] filterRenderByUid"),W.currentManager&&X.isRoom(e)&&e.isWritable)return W.currentManager.cancelFilterRender(g,p)},addListener:(g,p)=>{W.logger.info(`[ApplianceSinglePlugin] addListener ${g}`),Je.PublicMsgEmitter.on(g,p)},removeListener:(g,p)=>{W.logger.info(`[ApplianceSinglePlugin] removeListener ${g}`),Je.PublicMsgEmitter.off(g,p)},usePlugin:g=>{var p;W.logger.info("[ApplianceSinglePlugin] usePlugin",g.kind),(p=W.currentManager)==null||p.usePlugin(g)},getDisableDeviceInputs(){if(W.currentManager&&X.isRoom(e))return W.currentManager.disableDeviceInputs},setDisableDeviceInputs(g){W.logger.info(`[ApplianceSinglePlugin] setDisableDeviceInputs ${g}`),W.currentManager&&X.isRoom(e)&&(W.currentManager.disableDeviceInputs=g)},getDisableCameraTransform(){if(W.currentManager&&X.isRoom(e))return W.currentManager.disableCameraTransform},setDisableCameraTransform(g){W.logger.info(`[ApplianceSinglePlugin] setDisableCameraTransform ${g}`),W.currentManager&&X.isRoom(e)&&(W.currentManager.disableCameraTransform=g)},getDisableEraseImage(){if(W.currentManager&&X.isRoom(e))return W.currentManager.disableEraseImage},setDisableEraseImage(g){W.logger.info(`[ApplianceSinglePlugin] setDisableEraseImage ${g}`),W.currentManager&&X.isRoom(e)&&(W.currentManager.disableEraseImage=g)},setWritable:async function(g){var p;W.logger.info(`[ApplianceSinglePlugin] setWritable ${g}`),X.isRoom(e)&&l&&(await((p=W.currentManager)==null?void 0:p.setWritable(g)),await l.call(e,g))},requestIdleCallback:(g,p)=>{const f=(p==null?void 0:p.timeout)||0,m=performance.now();let w;const I=new MessageChannel;let N;const C=S=>{try{g({didTimeout:S,timeRemaining:()=>{const x=performance.now()-m;return Math.max(0,f-x)}})}catch(v){W.logger.error("[ApplianceSinglePlugin] requestIdleCallback error:",v)}finally{I.port1.close(),I.port2.close(),w!==void 0&&cancelAnimationFrame(w),N!==void 0&&clearTimeout(N)}};return I.port1.onmessage=()=>{w=requestAnimationFrame(()=>{f>0&&performance.now()-m>=f?C(!0):C(!1)})},I.port2.postMessage(null),f>0&&(N=setTimeout(()=>{C(!0)},f)),N||w||0},cancelIdleCallback:g=>{try{clearTimeout(g),cancelAnimationFrame(g)}catch(p){W.logger.error("[ApplianceSinglePlugin] cancelIdleCallback error:",p)}},injectMethodToObject:(g,p)=>{if(W.logger.info(`[ApplianceSinglePlugin] injectMethodToObject ${p}`),typeof g[p]=="function"||typeof g[p]>"u"){g[p]=h[p];return}p==="callbacks"&&(g.callbacks.on=h._callbacksOn.bind(h),g.callbacks.off=h._callbacksOff.bind(h),g.callbacks.once=h._callbacksOnce.bind(h))}};h.injectMethodToObject(e,"undo"),h.injectMethodToObject(e,"redo"),h.injectMethodToObject(e,"cleanCurrentScene"),h.injectMethodToObject(e,"insertImage"),h.injectMethodToObject(e,"completeImageUpload"),h.injectMethodToObject(e,"lockImage"),h.injectMethodToObject(e,"getImagesInformation"),h.injectMethodToObject(e,"callbacks"),h.injectMethodToObject(e,"screenshotToCanvasAsync"),h.injectMethodToObject(e,"getBoundingRectAsync"),h.injectMethodToObject(e,"scenePreviewAsync"),h.injectMethodToObject(e,"fillSceneSnapshotAsync"),h.injectMethodToObject(e,"setMemberState"),X.isRoom(e)&&h.injectMethodToObject(e,"setWritable"),Object.defineProperty(e,"canUndoSteps",{get(){return h.canUndoSteps()}}),Object.defineProperty(e,"canRedoSteps",{get(){return h.canRedoSteps()}});const d={...h,callbacks:h.callbacks()};return Object.defineProperty(d,"disableDeviceInputs",{set(g){h.setDisableDeviceInputs(g)},get(){return h.getDisableDeviceInputs()}}),Object.defineProperty(d,"disableEraseImage",{set(g){h.setDisableEraseImage(g)},get(){return h.getDisableEraseImage()}}),Object.defineProperty(d,"disableCameraTransform",{set(g){h.setDisableCameraTransform(g)},get(){return h.getDisableCameraTransform()}}),e._appliancePlugin=d,e._appliancePlugin}static onCreate(e){e&&W.currentManager&&(W.currentManager.bindPlugin(e),e.init(e.displayer))}static async createAppliancePlugin(e,t){try{await e.createInvisiblePlugin(W,{})}catch{if(!e.isWritable){await e.setWritable(!0);const n=await this.createAppliancePlugin(e,t);return await e.setWritable(!1),n}}let i=e.getInvisiblePlugin(t);return i||(i=await W.createAppliancePlugin(e,t)),i}static effectInstance(){if(W.cursorAdapter){const e=W.cursorAdapter.onAddedCursor;W.cursorAdapter.onAddedCursor=function(t){t.onCursorMemberChanged=i=>{try{i.appliance===re.pencil||i.appliance===re.shape||i.appliance===re.text||i.appliance===re.arrow||i.appliance===re.straight||i.appliance===re.rectangle||i.appliance===re.ellipse||i.appliance===re.eraser||i.appliance===re.selector?t!=null&&t.divElement&&(t.divElement.style.display="none"):t!=null&&t.divElement&&(t.divElement.style.display="block")}catch{}},e.call(W.cursorAdapter,t)}}}get isReplay(){return X.isPlayer(this.displayer)}get callbackName(){return this.isReplay?"onPlayerStateChanged":"onRoomStateChanged"}init(e){var i,o;const t=e.state;(i=W.currentManager)==null||i.onRoomMembersChange(t.roomMembers),X.isRoom(e)&&t!=null&&t.memberState&&((o=W.currentManager)==null||o.onMemberChange(t.memberState)),this.displayer.callbacks.on(this.callbackName,this.roomStateChangeListener),this.displayer.callbacks.on("onEnableWriteNowChanged",this.updateRoomWritable),this.displayer.callbacks.on("onPhaseChanged",this.onPhaseChanged)}destroy(){var e;W.logger.info("[ApplianceSinglePlugin] passive destroy"),(e=W.currentManager)==null||e.destroy(),W.currentManager=void 0,W.cursorAdapter=void 0}};M(W,"kind","appliance-aids-single-plugin"),M(W,"cursorAdapter"),M(W,"currentManager"),M(W,"logger",{info:console.log,warn:console.warn,error:console.error}),M(W,"options",Ie),M(W,"createCurrentManager",(e,t,i)=>{W.currentManager&&W.currentManager.destroy();const o={plugin:i,displayer:e,options:t},n=new Je(o);if(n.init(),W.logger.info("[ApplianceSinglePlugin] refresh ApplianceSingleManager object"),W.currentManager=n,X.isRoom(e)){const a=n.hasOffscreenCanvas();e.logger.info(`[ApplianceSinglePlugin] use ${a?"worker":"mainThread"}`)}});let qs=W;const Rt=class Rt extends y.Component{constructor(){super(...arguments);M(this,"mainViewRef",null)}componentDidMount(){Rt.emiter||(Rt.emiter=Je.InternalMsgEmitter),Rt.emiter.emit(ne.BindMainView,this.mainViewRef)}render(){return y.createElement(y.Fragment,null,this.props.children,y.createElement("div",{className:"appliance-plugin-main-view-displayer",ref:e=>this.mainViewRef=e}))}};M(Rt,"emiter");let Ks=Rt;class Ow extends vn{constructor(e){super();M(this,"kind","autoDraw");M(this,"localStorage",[]);M(this,"excludeStorage",[]);M(this,"timer");M(this,"hostServer");M(this,"iconsContainer");M(this,"icons",[]);M(this,"iconRect");M(this,"isActive",!1);M(this,"viewId",fe);M(this,"scenePath");M(this,"delay",2e3);const{container:t,hostServer:i,delay:o}=e;this.hostServer=i,this.iconsContainer=t,this.delay=o||2e3}get collector(){return this.control.collector}onDestroy(){this.unMount()}onCreate(){}onSetToolkey(e){e===T.Pencil?this.isActive=!0:(this.isActive&&(this.localStorage.length=0,this.timer&&clearTimeout(this.timer),this.timer=void 0,this.iconRect&&(this.iconRect=void 0),this.icons.length=0),this.isActive=!1)}syncStorage(e,t){if(!this.isActive||e!==this.viewId)return;if(!t){this.localStorage.length=0;return}const i=this.getOwnStorage(this.viewId,t);this.localStorage=i.map(o=>{var n;return((n=this.collector)==null?void 0:n.getLocalId(o))||o})}getOwnStorage(e,t){var n,a;if(!e||!t)return[];const i=(a=(n=this.collector)==null?void 0:n.storage[e])==null?void 0:a[t];return i?Object.keys(i).filter(c=>{var l,u;return((l=this.collector)==null?void 0:l.isOwn(c))&&((u=i[c])==null?void 0:u.toolsType)===T.Pencil&&!this.excludeStorage.includes(c)}):[]}async batchLocalDraw(){var a;if(this.localStorage.length===0||!this.scenePath||!((a=this.collector)==null?void 0:a.getStorageData(this.viewId,this.scenePath)))return;const t=this.localStorage.toString(),i=await this.control.worker.getVNodeInfo(this.localStorage.toString(),this.viewId,this.localStorage);if(!i)return;const{vInfo:o,uuid:n}=i;if(n===t&&o){const c={rect:{centerX:0,centerY:0,width:0,height:0},ink:[]};let l;const u=[];for(const{rect:h,op:d}of o){l=ue(l,h);const g=[],p=[];for(let f=0;f<d.length;f+=3){g.push(d[f]),p.push(d[f+1]);const m=u.length&&u[u.length-1]||0;f===0?u.length===0?u.push(0):u.push(m+100):u.push(m+15)}c.ink.push([g,p,u])}return l&&(c.rect.centerX=Math.floor(l.x+l.w/2),c.rect.centerY=Math.floor(l.y+l.h/2),c.rect.width=Math.floor(l.w),c.rect.height=Math.floor(l.h)),c}}async computAutoDraw(e){const{rect:t,ink:i}=e;this.iconRect=t;const o=await fetch(this.hostServer,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({width:t.width,height:t.height,ink:i})}).then(n=>n.json()).then(n=>n.data);this.icons=o||[]}buildHTML(){var i;this.iconsContainer.innerHTML="";const e=document.createElement("div");e.style.display="flex",e.style.overflow="auto",e.style.padding="10px 0";const t=((i=this.control.worker.currentToolsData)==null?void 0:i.toolsOpt.strokeColor)||"#7f7f7f";this.icons.forEach(o=>{const n=document.createElement("img");n.src=`https://api.iconify.design/${o}.svg?color=${t}`,n.onclick=()=>{this.onClickIcon(o)},n.onload=()=>{e.appendChild(n)}}),this.iconsContainer.appendChild(e)}onClickIcon(e){var t,i;if(this.iconRect){const o=this.control.viewContainerManager.transformToScenePoint([this.iconRect.centerX,this.iconRect.centerY],this.viewId),n=((i=(t=this.control.viewContainerManager.getView(this.viewId))==null?void 0:t.cameraOpt)==null?void 0:i.scale)||1;this.icons.length=0,this.iconsContainer.innerHTML="";const a=Date.now().toString();this.control.worker.removeNodes(this.viewId,this.localStorage),this.localStorage.length=0,this.control.insertIconify(this.viewId,{uuid:a,centerX:o[0],centerY:o[1],width:Math.floor(this.iconRect.width/n),height:Math.floor(this.iconRect.height/n),src:`https://api.iconify.design/${e}.svg`,uniformScale:!1,locked:!1}),this.iconRect=void 0}}sceneChange(e,t){e===this.viewId&&(this.scenePath=t,this.excludeStorage=this.getOwnStorage(e,t)),this.localStorage.length=0}localEvent(e,t){var i;if(e===this.viewId&&((i=this.control.worker.currentToolsData)==null?void 0:i.toolsType)===T.Pencil)switch(t){case j.Start:this.timer&&(clearTimeout(this.timer),this.timer=void 0);break;case j.Done:this.timer&&clearTimeout(this.timer),this.timer=setTimeout(async()=>{this.timer=void 0;const o=await this.batchLocalDraw();o&&(await this.computAutoDraw(o),this.buildHTML())},this.delay);break}}mount(){var t,i;this.scenePath=(t=this.control.viewContainerManager.getView(this.viewId))==null?void 0:t.focusScenePath,this.excludeStorage=this.getOwnStorage(this.viewId,this.scenePath);const e=(i=this.control.worker.currentToolsData)==null?void 0:i.toolsType;e&&this.onSetToolkey(e),this.callbacks("setToolkey",this.onSetToolkey.bind(this)),this.callbacks("syncStorage",this.syncStorage.bind(this)),this.callbacks("sceneChange",this.sceneChange.bind(this)),this.callbacks("localEvent",this.localEvent.bind(this))}unMount(){this.timer&&clearTimeout(this.timer),this.timer=void 0,this.iconRect&&(this.iconRect=void 0),this.icons.length=0,this.excludeStorage.length=0,this.localStorage.length=0,this.iconsContainer.innerHTML="",this.removeCallback("setToolkey"),this.removeCallback("syncStorage"),this.removeCallback("sceneChange"),this.removeCallback("localEvent")}}exports.ActiveContainerType=Io;exports.ApplianceMultiPlugin=Js;exports.ApplianceNames=re;exports.ApplianceSigleWrapper=Ks;exports.ApplianceSinglePlugin=qs;exports.AutoDrawPlugin=Ow;exports.Cursor_Hover_Id=vf;exports.DefaultAppliancePluginOptions=Ie;exports.ECanvasShowType=me;exports.EDataType=B;exports.EForceStopReason=vs;exports.EImageType=St;exports.EMatrixrRelationType=Nt;exports.EOperationType=Ye;exports.EPostMessageType=D;exports.ERenderFilterType=et;exports.EScaleType=ce;exports.EStrokeType=oe;exports.EToolsKey=T;exports.ElayerType=qt;exports.EmitEventType=V;exports.EventMessageType=Jt;exports.EvevtWorkState=j;exports.EvevtWorkType=To;exports.InternalMsgEmitterType=ne;exports.Main_View_Id=fe;exports.Plugin=vn;exports.ShapeType=Ke;exports.Storage_Selector_key=G;exports.Storage_Splitter=Ze;exports.Storage_ViewId_ALL=cs;exports.Task_Time_Interval=fi;exports.VNodeManager=dn;exports.ViewContainerManager=Wt;exports.computRect=ue;exports.fullWorker=bn;exports.getRectMatrixrRelation=wi;exports.getShapeInstance=js;exports.isEqual=lt;exports.isIntersectForPoint=wn;exports.isNumber=ze;exports.removeAllChildren=Fe;exports.removeTexture=He;exports.subWorker=jn;exports.transformToNormalData=Dt;exports.transformToSerializableData=Ge;