@netless/appliance-plugin 1.1.17-beta.13 → 1.1.17-beta.14

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.
@@ -1 +1 @@
1
- "use strict";var Mn=Object.defineProperty;var yn=(r,s,e)=>s in r?Mn(r,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[s]=e;var M=(r,s,e)=>yn(r,typeof s!="symbol"?s+"":s,e);const $=require("white-web-sdk"),ae=require("spritejs"),ao=require("lz-string"),$e=require("clipper-lib"),Zs=require("lineclip"),As=require("eventemitter2"),O=require("lodash"),y=require("react"),us=require("react-dom"),bt=require("react-draggable"),mn=require("re-resizable"),wn="/fullWorker.js",In="/subWorker.js";var oe=(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))(oe||{}),te=(r=>(r.Normal="Normal",r.Stroke="Stroke",r.Dotted="Dotted",r.LongDotted="LongDotted",r))(te||{}),Ve=(r=>(r.Triangle="triangle",r.Rhombus="rhombus",r.Pentagram="pentagram",r.SpeechBalloon="speechBalloon",r.Star="star",r.Polygon="polygon",r))(Ve||{}),Q=(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))(Q||{}),se=(r=>(r.DisplayState="DisplayState",r.MainEngine="MainEngine",r.Cursor="Cursor",r.BindMainView="BindMainView",r))(se||{}),co=(r=>(r[r.MainView=0]="MainView",r[r.Plugin=1]="Plugin",r[r.Both=2]="Both",r))(co||{}),ds=(r=>(r.longPencil="longPencil",r))(ds||{}),v=(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))(v||{}),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||{}),ye=(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))(ye||{}),Bt=(r=>(r[r.Cursor=1]="Cursor",r[r.TextCreate=2]="TextCreate",r))(Bt||{}),Ft=(r=>(r[r.Top=1]="Top",r[r.Bottom=2]="Bottom",r))(Ft||{}),re=(r=>(r[r.none=1]="none",r[r.all=2]="all",r[r.both=3]="both",r[r.proportional=4]="proportional",r))(re||{}),lo=(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))(lo||{}),ft=(r=>(r[r.inside=0]="inside",r[r.outside=1]="outside",r[r.intersect=2]="intersect",r))(ft||{}),je=(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))(je||{}),He=(r=>(r.setAuth="setAuth",r.setShow="addShow",r.setHide="setHide",r.setClear="setClear",r))(He||{}),Mt=(r=>(r.Image="image",r.Iconify="iconify",r))(Mt||{});const vn={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=vn.easeInQuad(o/(t-1)),a=k.Lrp(s,e,n);a.z=Math.min(1,.5+Math.abs(.5-Tn(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 Tn=r=>r<.5?2*r*r:-1+(4-2*r)*r;class Z 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 Z(s,e,t,a,o,n)}distance(s){return Z.GetDistance(this,s)}isNear(s,e){return Z.IsNear(this,s,e)}getAngleByPoints(s,e){return Z.GetAngleByPoints(s,this,e)}static Sub(s,e){return new Z(s.x-e.x,s.y-e.y)}static Add(s,e){return new Z(s.x+e.x,s.y+e.y)}static GetDistance(s,e){return Z.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 Z.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 Z(u,h)}static GetDotStroke(s,e,t=16){const i=new k(1,1),o=Math.PI+.001,n=Z.Add(s,Z.Sub(s,i).uni().per().mul(-e)),a=[];for(let c=1/t,l=c;l<=1;l+=c)a.push(Z.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(Z.RotWith(e,s,o*c));return n}}var $t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function jt(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Nn=typeof $t=="object"&&$t&&$t.Object===Object&&$t,ho=Nn,Sn=ho,Cn=typeof self=="object"&&self&&self.Object===Object&&self,kn=Sn||Cn||Function("return this")(),Ge=kn,Dn=Ge,xn=Dn.Symbol,Zt=xn,pi=Zt,uo=Object.prototype,Ln=uo.hasOwnProperty,bn=uo.toString,Wt=pi?pi.toStringTag:void 0;function jn(r){var s=Ln.call(r,Wt),e=r[Wt];try{r[Wt]=void 0;var t=!0}catch{}var i=bn.call(r);return t&&(s?r[Wt]=e:delete r[Wt]),i}var An=jn,zn=Object.prototype,Pn=zn.toString;function En(r){return Pn.call(r)}var On=En,gi=Zt,Rn=An,Wn=On,Yn="[object Null]",Un="[object Undefined]",fi=gi?gi.toStringTag:void 0;function Bn(r){return r==null?r===void 0?Un:Yn:fi&&fi in Object(r)?Rn(r):Wn(r)}var yt=Bn;function Fn(r){return r!=null&&typeof r=="object"}var Ke=Fn,Qn=yt,Vn=Ke,Zn="[object Number]";function Hn(r){return typeof r=="number"||Vn(r)&&Qn(r)==Zn}var Gn=Hn;const De=jt(Gn);function $n(){this.__data__=[],this.size=0}var Xn=$n;function Jn(r,s){return r===s||r!==r&&s!==s}var Hs=Jn,qn=Hs;function Kn(r,s){for(var e=r.length;e--;)if(qn(r[e][0],s))return e;return-1}var ps=Kn,_n=ps,er=Array.prototype,tr=er.splice;function sr(r){var s=this.__data__,e=_n(s,r);if(e<0)return!1;var t=s.length-1;return e==t?s.pop():tr.call(s,e,1),--this.size,!0}var ir=sr,or=ps;function nr(r){var s=this.__data__,e=or(s,r);return e<0?void 0:s[e][1]}var rr=nr,ar=ps;function cr(r){return ar(this.__data__,r)>-1}var lr=cr,hr=ps;function ur(r,s){var e=this.__data__,t=hr(e,r);return t<0?(++this.size,e.push([r,s])):e[t][1]=s,this}var dr=ur,pr=Xn,gr=ir,fr=rr,Mr=lr,yr=dr;function At(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])}}At.prototype.clear=pr;At.prototype.delete=gr;At.prototype.get=fr;At.prototype.has=Mr;At.prototype.set=yr;var gs=At,mr=gs;function wr(){this.__data__=new mr,this.size=0}var Ir=wr;function vr(r){var s=this.__data__,e=s.delete(r);return this.size=s.size,e}var Tr=vr;function Nr(r){return this.__data__.get(r)}var Sr=Nr;function Cr(r){return this.__data__.has(r)}var kr=Cr;function Dr(r){var s=typeof r;return r!=null&&(s=="object"||s=="function")}var lt=Dr,xr=yt,Lr=lt,br="[object AsyncFunction]",jr="[object Function]",Ar="[object GeneratorFunction]",zr="[object Proxy]";function Pr(r){if(!Lr(r))return!1;var s=xr(r);return s==jr||s==Ar||s==br||s==zr}var po=Pr,Er=Ge,Or=Er["__core-js_shared__"],Rr=Or,ks=Rr,Mi=function(){var r=/[^.]+$/.exec(ks&&ks.keys&&ks.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""}();function Wr(r){return!!Mi&&Mi in r}var Yr=Wr,Ur=Function.prototype,Br=Ur.toString;function Fr(r){if(r!=null){try{return Br.call(r)}catch{}try{return r+""}catch{}}return""}var go=Fr,Qr=po,Vr=Yr,Zr=lt,Hr=go,Gr=/[\\^$.*+?()[\]{}|]/g,$r=/^\[object .+?Constructor\]$/,Xr=Function.prototype,Jr=Object.prototype,qr=Xr.toString,Kr=Jr.hasOwnProperty,_r=RegExp("^"+qr.call(Kr).replace(Gr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ea(r){if(!Zr(r)||Vr(r))return!1;var s=Qr(r)?_r:$r;return s.test(Hr(r))}var ta=ea;function sa(r,s){return r==null?void 0:r[s]}var ia=sa,oa=ta,na=ia;function ra(r,s){var e=na(r,s);return oa(e)?e:void 0}var mt=ra,aa=mt,ca=Ge,la=aa(ca,"Map"),Gs=la,ha=mt,ua=ha(Object,"create"),fs=ua,yi=fs;function da(){this.__data__=yi?yi(null):{},this.size=0}var pa=da;function ga(r){var s=this.has(r)&&delete this.__data__[r];return this.size-=s?1:0,s}var fa=ga,Ma=fs,ya="__lodash_hash_undefined__",ma=Object.prototype,wa=ma.hasOwnProperty;function Ia(r){var s=this.__data__;if(Ma){var e=s[r];return e===ya?void 0:e}return wa.call(s,r)?s[r]:void 0}var va=Ia,Ta=fs,Na=Object.prototype,Sa=Na.hasOwnProperty;function Ca(r){var s=this.__data__;return Ta?s[r]!==void 0:Sa.call(s,r)}var ka=Ca,Da=fs,xa="__lodash_hash_undefined__";function La(r,s){var e=this.__data__;return this.size+=this.has(r)?0:1,e[r]=Da&&s===void 0?xa:s,this}var ba=La,ja=pa,Aa=fa,za=va,Pa=ka,Ea=ba;function zt(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])}}zt.prototype.clear=ja;zt.prototype.delete=Aa;zt.prototype.get=za;zt.prototype.has=Pa;zt.prototype.set=Ea;var Oa=zt,mi=Oa,Ra=gs,Wa=Gs;function Ya(){this.size=0,this.__data__={hash:new mi,map:new(Wa||Ra),string:new mi}}var Ua=Ya;function Ba(r){var s=typeof r;return s=="string"||s=="number"||s=="symbol"||s=="boolean"?r!=="__proto__":r===null}var Fa=Ba,Qa=Fa;function Va(r,s){var e=r.__data__;return Qa(s)?e[typeof s=="string"?"string":"hash"]:e.map}var Ms=Va,Za=Ms;function Ha(r){var s=Za(this,r).delete(r);return this.size-=s?1:0,s}var Ga=Ha,$a=Ms;function Xa(r){return $a(this,r).get(r)}var Ja=Xa,qa=Ms;function Ka(r){return qa(this,r).has(r)}var _a=Ka,ec=Ms;function tc(r,s){var e=ec(this,r),t=e.size;return e.set(r,s),this.size+=e.size==t?0:1,this}var sc=tc,ic=Ua,oc=Ga,nc=Ja,rc=_a,ac=sc;function Pt(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])}}Pt.prototype.clear=ic;Pt.prototype.delete=oc;Pt.prototype.get=nc;Pt.prototype.has=rc;Pt.prototype.set=ac;var fo=Pt,cc=gs,lc=Gs,hc=fo,uc=200;function dc(r,s){var e=this.__data__;if(e instanceof cc){var t=e.__data__;if(!lc||t.length<uc-1)return t.push([r,s]),this.size=++e.size,this;e=this.__data__=new hc(t)}return e.set(r,s),this.size=e.size,this}var pc=dc,gc=gs,fc=Ir,Mc=Tr,yc=Sr,mc=kr,wc=pc;function Et(r){var s=this.__data__=new gc(r);this.size=s.size}Et.prototype.clear=fc;Et.prototype.delete=Mc;Et.prototype.get=yc;Et.prototype.has=mc;Et.prototype.set=wc;var Mo=Et;function Ic(r,s){for(var e=-1,t=r==null?0:r.length;++e<t&&s(r[e],e,r)!==!1;);return r}var vc=Ic,Tc=mt,Nc=function(){try{var r=Tc(Object,"defineProperty");return r({},"",{}),r}catch{}}(),yo=Nc,wi=yo;function Sc(r,s,e){s=="__proto__"&&wi?wi(r,s,{configurable:!0,enumerable:!0,value:e,writable:!0}):r[s]=e}var mo=Sc,Cc=mo,kc=Hs,Dc=Object.prototype,xc=Dc.hasOwnProperty;function Lc(r,s,e){var t=r[s];(!(xc.call(r,s)&&kc(t,e))||e===void 0&&!(s in r))&&Cc(r,s,e)}var wo=Lc,bc=wo,jc=mo;function Ac(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?jc(e,a,c):bc(e,a,c)}return e}var ys=Ac;function zc(r,s){for(var e=-1,t=Array(r);++e<r;)t[e]=s(e);return t}var Pc=zc,Ec=yt,Oc=Ke,Rc="[object Arguments]";function Wc(r){return Oc(r)&&Ec(r)==Rc}var Yc=Wc,Ii=Yc,Uc=Ke,Io=Object.prototype,Bc=Io.hasOwnProperty,Fc=Io.propertyIsEnumerable,Qc=Ii(function(){return arguments}())?Ii:function(r){return Uc(r)&&Bc.call(r,"callee")&&!Fc.call(r,"callee")},vo=Qc,Vc=Array.isArray,Ht=Vc,_t={exports:{}};function Zc(){return!1}var Hc=Zc;_t.exports;(function(r,s){var e=Ge,t=Hc,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})(_t,_t.exports);var $s=_t.exports,Gc=9007199254740991,$c=/^(?:0|[1-9]\d*)$/;function Xc(r,s){var e=typeof r;return s=s??Gc,!!s&&(e=="number"||e!="symbol"&&$c.test(r))&&r>-1&&r%1==0&&r<s}var Jc=Xc,qc=9007199254740991;function Kc(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=qc}var To=Kc,_c=yt,el=To,tl=Ke,sl="[object Arguments]",il="[object Array]",ol="[object Boolean]",nl="[object Date]",rl="[object Error]",al="[object Function]",cl="[object Map]",ll="[object Number]",hl="[object Object]",ul="[object RegExp]",dl="[object Set]",pl="[object String]",gl="[object WeakMap]",fl="[object ArrayBuffer]",Ml="[object DataView]",yl="[object Float32Array]",ml="[object Float64Array]",wl="[object Int8Array]",Il="[object Int16Array]",vl="[object Int32Array]",Tl="[object Uint8Array]",Nl="[object Uint8ClampedArray]",Sl="[object Uint16Array]",Cl="[object Uint32Array]",we={};we[yl]=we[ml]=we[wl]=we[Il]=we[vl]=we[Tl]=we[Nl]=we[Sl]=we[Cl]=!0;we[sl]=we[il]=we[fl]=we[ol]=we[Ml]=we[nl]=we[rl]=we[al]=we[cl]=we[ll]=we[hl]=we[ul]=we[dl]=we[pl]=we[gl]=!1;function kl(r){return tl(r)&&el(r.length)&&!!we[_c(r)]}var Dl=kl;function xl(r){return function(s){return r(s)}}var ms=xl,es={exports:{}};es.exports;(function(r,s){var e=ho,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})(es,es.exports);var Xs=es.exports,Ll=Dl,bl=ms,vi=Xs,Ti=vi&&vi.isTypedArray,jl=Ti?bl(Ti):Ll,No=jl,Al=Pc,zl=vo,Pl=Ht,El=$s,Ol=Jc,Rl=No,Wl=Object.prototype,Yl=Wl.hasOwnProperty;function Ul(r,s){var e=Pl(r),t=!e&&zl(r),i=!e&&!t&&El(r),o=!e&&!t&&!i&&Rl(r),n=e||t||i||o,a=n?Al(r.length,String):[],c=a.length;for(var l in r)(s||Yl.call(r,l))&&!(n&&(l=="length"||i&&(l=="offset"||l=="parent")||o&&(l=="buffer"||l=="byteLength"||l=="byteOffset")||Ol(l,c)))&&a.push(l);return a}var So=Ul,Bl=Object.prototype;function Fl(r){var s=r&&r.constructor,e=typeof s=="function"&&s.prototype||Bl;return r===e}var Js=Fl;function Ql(r,s){return function(e){return r(s(e))}}var Co=Ql,Vl=Co,Zl=Vl(Object.keys,Object),Hl=Zl,Gl=Js,$l=Hl,Xl=Object.prototype,Jl=Xl.hasOwnProperty;function ql(r){if(!Gl(r))return $l(r);var s=[];for(var e in Object(r))Jl.call(r,e)&&e!="constructor"&&s.push(e);return s}var Kl=ql,_l=po,eh=To;function th(r){return r!=null&&eh(r.length)&&!_l(r)}var qs=th,sh=So,ih=Kl,oh=qs;function nh(r){return oh(r)?sh(r):ih(r)}var Ks=nh,rh=ys,ah=Ks;function ch(r,s){return r&&rh(s,ah(s),r)}var lh=ch;function hh(r){var s=[];if(r!=null)for(var e in Object(r))s.push(e);return s}var uh=hh,dh=lt,ph=Js,gh=uh,fh=Object.prototype,Mh=fh.hasOwnProperty;function yh(r){if(!dh(r))return gh(r);var s=ph(r),e=[];for(var t in r)t=="constructor"&&(s||!Mh.call(r,t))||e.push(t);return e}var mh=yh,wh=So,Ih=mh,vh=qs;function Th(r){return vh(r)?wh(r,!0):Ih(r)}var _s=Th,Nh=ys,Sh=_s;function Ch(r,s){return r&&Nh(s,Sh(s),r)}var kh=Ch,ts={exports:{}};ts.exports;(function(r,s){var e=Ge,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})(ts,ts.exports);var Dh=ts.exports;function xh(r,s){var e=-1,t=r.length;for(s||(s=Array(t));++e<t;)s[e]=r[e];return s}var Lh=xh;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 ko=bh;function jh(){return[]}var Do=jh,Ah=ko,zh=Do,Ph=Object.prototype,Eh=Ph.propertyIsEnumerable,Ni=Object.getOwnPropertySymbols,Oh=Ni?function(r){return r==null?[]:(r=Object(r),Ah(Ni(r),function(s){return Eh.call(r,s)}))}:zh,ei=Oh,Rh=ys,Wh=ei;function Yh(r,s){return Rh(r,Wh(r),s)}var Uh=Yh;function Bh(r,s){for(var e=-1,t=s.length,i=r.length;++e<t;)r[i+e]=s[e];return r}var ti=Bh,Fh=Co,Qh=Fh(Object.getPrototypeOf,Object),xo=Qh,Vh=ti,Zh=xo,Hh=ei,Gh=Do,$h=Object.getOwnPropertySymbols,Xh=$h?function(r){for(var s=[];r;)Vh(s,Hh(r)),r=Zh(r);return s}:Gh,Lo=Xh,Jh=ys,qh=Lo;function Kh(r,s){return Jh(r,qh(r),s)}var _h=Kh,eu=ti,tu=Ht;function su(r,s,e){var t=s(r);return tu(r)?t:eu(t,e(r))}var bo=su,iu=bo,ou=ei,nu=Ks;function ru(r){return iu(r,nu,ou)}var jo=ru,au=bo,cu=Lo,lu=_s;function hu(r){return au(r,lu,cu)}var uu=hu,du=mt,pu=Ge,gu=du(pu,"DataView"),fu=gu,Mu=mt,yu=Ge,mu=Mu(yu,"Promise"),wu=mu,Iu=mt,vu=Ge,Tu=Iu(vu,"Set"),Ao=Tu,Nu=mt,Su=Ge,Cu=Nu(Su,"WeakMap"),ku=Cu,zs=fu,Ps=Gs,Es=wu,Os=Ao,Rs=ku,zo=yt,Ot=go,Si="[object Map]",Du="[object Object]",Ci="[object Promise]",ki="[object Set]",Di="[object WeakMap]",xi="[object DataView]",xu=Ot(zs),Lu=Ot(Ps),bu=Ot(Es),ju=Ot(Os),Au=Ot(Rs),ht=zo;(zs&&ht(new zs(new ArrayBuffer(1)))!=xi||Ps&&ht(new Ps)!=Si||Es&&ht(Es.resolve())!=Ci||Os&&ht(new Os)!=ki||Rs&&ht(new Rs)!=Di)&&(ht=function(r){var s=zo(r),e=s==Du?r.constructor:void 0,t=e?Ot(e):"";if(t)switch(t){case xu:return xi;case Lu:return Si;case bu:return Ci;case ju:return ki;case Au:return Di}return s});var ws=ht,zu=Object.prototype,Pu=zu.hasOwnProperty;function Eu(r){var s=r.length,e=new r.constructor(s);return s&&typeof r[0]=="string"&&Pu.call(r,"index")&&(e.index=r.index,e.input=r.input),e}var Ou=Eu,Ru=Ge,Wu=Ru.Uint8Array,Po=Wu,Li=Po;function Yu(r){var s=new r.constructor(r.byteLength);return new Li(s).set(new Li(r)),s}var si=Yu,Uu=si;function Bu(r,s){var e=s?Uu(r.buffer):r.buffer;return new r.constructor(e,r.byteOffset,r.byteLength)}var Fu=Bu,Qu=/\w*$/;function Vu(r){var s=new r.constructor(r.source,Qu.exec(r));return s.lastIndex=r.lastIndex,s}var Zu=Vu,bi=Zt,ji=bi?bi.prototype:void 0,Ai=ji?ji.valueOf:void 0;function Hu(r){return Ai?Object(Ai.call(r)):{}}var Gu=Hu,$u=si;function Xu(r,s){var e=s?$u(r.buffer):r.buffer;return new r.constructor(e,r.byteOffset,r.length)}var Ju=Xu,qu=si,Ku=Fu,_u=Zu,ed=Gu,td=Ju,sd="[object Boolean]",id="[object Date]",od="[object Map]",nd="[object Number]",rd="[object RegExp]",ad="[object Set]",cd="[object String]",ld="[object Symbol]",hd="[object ArrayBuffer]",ud="[object DataView]",dd="[object Float32Array]",pd="[object Float64Array]",gd="[object Int8Array]",fd="[object Int16Array]",Md="[object Int32Array]",yd="[object Uint8Array]",md="[object Uint8ClampedArray]",wd="[object Uint16Array]",Id="[object Uint32Array]";function vd(r,s,e){var t=r.constructor;switch(s){case hd:return qu(r);case sd:case id:return new t(+r);case ud:return Ku(r,e);case dd:case pd:case gd:case fd:case Md:case yd:case md:case wd:case Id:return td(r,e);case od:return new t;case nd:case cd:return new t(r);case rd:return _u(r);case ad:return new t;case ld:return ed(r)}}var Td=vd,Nd=lt,zi=Object.create,Sd=function(){function r(){}return function(s){if(!Nd(s))return{};if(zi)return zi(s);r.prototype=s;var e=new r;return r.prototype=void 0,e}}(),Cd=Sd,kd=Cd,Dd=xo,xd=Js;function Ld(r){return typeof r.constructor=="function"&&!xd(r)?kd(Dd(r)):{}}var bd=Ld,jd=ws,Ad=Ke,zd="[object Map]";function Pd(r){return Ad(r)&&jd(r)==zd}var Ed=Pd,Od=Ed,Rd=ms,Pi=Xs,Ei=Pi&&Pi.isMap,Wd=Ei?Rd(Ei):Od,Yd=Wd,Ud=ws,Bd=Ke,Fd="[object Set]";function Qd(r){return Bd(r)&&Ud(r)==Fd}var Vd=Qd,Zd=Vd,Hd=ms,Oi=Xs,Ri=Oi&&Oi.isSet,Gd=Ri?Hd(Ri):Zd,Eo=Gd;const $d=jt(Eo);var Xd=Mo,Jd=vc,qd=wo,Kd=lh,_d=kh,ep=Dh,tp=Lh,sp=Uh,ip=_h,op=jo,np=uu,rp=ws,ap=Ou,cp=Td,lp=bd,hp=Ht,up=$s,dp=Yd,pp=lt,gp=Eo,fp=Ks,Mp=_s,yp=1,mp=2,wp=4,Oo="[object Arguments]",Ip="[object Array]",vp="[object Boolean]",Tp="[object Date]",Np="[object Error]",Ro="[object Function]",Sp="[object GeneratorFunction]",Cp="[object Map]",kp="[object Number]",Wo="[object Object]",Dp="[object RegExp]",xp="[object Set]",Lp="[object String]",bp="[object Symbol]",jp="[object WeakMap]",Ap="[object ArrayBuffer]",zp="[object DataView]",Pp="[object Float32Array]",Ep="[object Float64Array]",Op="[object Int8Array]",Rp="[object Int16Array]",Wp="[object Int32Array]",Yp="[object Uint8Array]",Up="[object Uint8ClampedArray]",Bp="[object Uint16Array]",Fp="[object Uint32Array]",me={};me[Oo]=me[Ip]=me[Ap]=me[zp]=me[vp]=me[Tp]=me[Pp]=me[Ep]=me[Op]=me[Rp]=me[Wp]=me[Cp]=me[kp]=me[Wo]=me[Dp]=me[xp]=me[Lp]=me[bp]=me[Yp]=me[Up]=me[Bp]=me[Fp]=!0;me[Np]=me[Ro]=me[jp]=!1;function qt(r,s,e,t,i,o){var n,a=s&yp,c=s&mp,l=s&wp;if(e&&(n=i?e(r,t,i,o):e(r)),n!==void 0)return n;if(!pp(r))return r;var u=hp(r);if(u){if(n=ap(r),!a)return tp(r,n)}else{var h=rp(r),d=h==Ro||h==Sp;if(up(r))return ep(r,a);if(h==Wo||h==Oo||d&&!i){if(n=c||d?{}:lp(r),!a)return c?ip(r,_d(n,r)):sp(r,Kd(n,r))}else{if(!me[h])return i?r:{};n=cp(r,h,a)}}o||(o=new Xd);var g=o.get(r);if(g)return g;o.set(r,n),gp(r)?r.forEach(function(m){n.add(qt(m,s,e,m,r,o))}):dp(r)&&r.forEach(function(m,w){n.set(w,qt(m,s,e,w,r,o))});var p=l?c?np:op:c?Mp:fp,f=u?void 0:p(r);return Jd(f||r,function(m,w){f&&(w=m,m=r[w]),qd(n,w,qt(m,s,e,w,r,o))}),n}var Qp=qt,Vp=Qp,Zp=1,Hp=4;function Gp(r){return Vp(r,Zp|Hp)}var $p=Gp;const ke=jt($p),Yo="1.1.17-beta.13",Xp="@netless/appliance-plugin",Wi=typeof OffscreenCanvas=="function"?"worker":"mainThread";if(typeof window<"u"){let r=window.__netlessUA||"";r+=` ${Xp}@${Yo}`,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}};function Je(r,s=!0){const e=r.length;if(e<2)return"";let t=r[0],i=r[1];if(e===2)return`M${It(t)}L${It(i)}`;let o="";for(let n=2,a=e-1;n<a;n++)t=r[n],i=r[n+1],o+=vt(t,i);return s?`M${vt(r[0],r[1])}Q${It(r[1])}${vt(r[1],r[2])}T${o}${vt(r[e-1],r[0])}${vt(r[0],r[1])}Z`:`M${It(r[0])}Q${It(r[1])}${vt(r[1],r[2])}${r.length>3?"T":""}${o}L${It(r[e-1])}`}const Ye=class Ye{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={};De(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=he(e,{x:Math.floor(p.x-Ye.SafeBorderPadding),y:Math.floor(p.y-Ye.SafeBorderPadding),w:Math.floor(p.width+Ye.SafeBorderPadding*2),h:Math.floor(p.height+Ye.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)return;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 T=w.parent;T.render();const C=w.renderer.canvasRenderer,S=C.context;if(!S)return;const N=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(ui(L,b)===ft.outside){Pe(I,T),f.removeChild(T),this.isDelete=!0;return}const A=ke(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 P=this.getGroupRect(A,N),R=P.x,z=P.y,X=P.w,K=P.h;let F=S.getImageData(R,z,X,K);if(this.isTransparentRectByCanvas(F)){Pe(I,T),f.removeChild(T),this.isDelete=!0,F=null;return}Pe(t,a);const _=this.createSpriteNode({imageData:F,safariRect:A,originRect:L,worldScaling:w.worldScaling});_&&t.append(_),Pe(I,T),f.removeChild(T),a.deleteTexture(F),F=null}createVmRenderNode(s,e,t,i,o){const{width:n,height:a}=t,c=`bitMap-${s}`,l=e.layer(c,t),u=new ae.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=Je(u,!0),d={pos:[0,0],d:h,fillColor:"rgba(0,0,0,1)"},g=new ae.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 ae.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 Z(s[0],s[1]);return Z.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 Z(s[a],s[a+1]);let l;if(a==s.length-2){const u=new Z(s[a-2],s[a-1]);l=k.Sub(c,u).uni(),o=c}else{a===0&&(n=c);const u=new Z(s[a+2],s[a+3]);l=k.Sub(u,c).uni()}if(l){const u=k.Per(l).mul(e);t.push(Z.Sub(c,u)),i.push(Z.Add(c,u))}}if(o&&n){const a=Z.GetSemicircleStroke(o,t[t.length-1],-1,8),c=Z.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?iy(t,n,s):(n.remove(),Re(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(),Re(a,(c=this.drawLayer)==null?void 0:c.parent)}):this.fullLayer.getElementsByName(e).forEach(a=>{a.remove(),Re(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(),Re(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&&ke(n)||i.get(e.name);if(!m)return;De(a)&&(e.setAttribute("zIndex",a),m.opt.zIndex=a);const w=e.parent;if(w){if(u&&d&&n){const T=[m.op[0],m.op[1]];li(m.op,h,d,c);const C=[m.op[0],m.op[1]],S=[C[0]-T[0],C[1]-T[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 N of Object.values(m.opt.eraserlines)){const{op:x,thickness:L}=N;N.thickness=L*Math.max(d[0],d[1]);for(let b=0;b<x.length;b++)hi(x[b],h,d,c)}}else if(c)if(e.setAttribute("translate",c),m.opt.translate=c,n){const T=[c[0]*w.worldScaling[0],c[1]*w.worldScaling[1]];f=Vt(m.rect,T),m.rect=f}else{const T=Ye.getRectFromLayer(w,e.name);m.rect=T||m.rect}else if(De(l))if(e.setAttribute("rotate",l),m.opt.rotate=l,n)f=rn(m.rect,l),m.rect=f;else{const T=Ye.getRectFromLayer(w,e.name);m.rect=T||m.rect}if(g){const T=g.get(e.name);if(T)for(let C=0,S=0;C<m.op.length;C+=3,S++)m.op[C]=T[S][0],m.op[C+1]=T[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 T=m.op.map((C,S)=>{const N=S%3;return N===0?C+c[0]:N===1?C+c[1]:C});if(m.op=T,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 N=0;N<S.length;N++){const x=S[N].map((L,b)=>b%2?L+c[1]:L+c[0]);C.op[N]=x}}}else if(De(l)){const T=m.op;if(JM(T,m.centerPos,l),m.op=T,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 N=0;N<S.length;N++)qM(S[N],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-Ye.SafeBorderPadding),y:Math.floor(i.y-Ye.SafeBorderPadding),w:Math.floor(i.width+Ye.SafeBorderPadding*2),h:Math.floor(i.height+Ye.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===v.Text&&(o.fontSize||o.translate||o.textInfos&&o.textInfos.get(i.name))||e===v.Image&&(o.angle||o.translate||o.scale||o.strokeColor&&o.type===Mt.Iconify)||e===o.toolsType&&o.willRefresh||t.eraserlines&&t.eraserlines.length&&(o.strokeColor||o.fillColor))}};M(Ye,"SafeBorderPadding",10);let Y=Ye;const ii=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 wt(r){return JSON.parse(ao.decompress(r))}function We(r){return ao.compress(JSON.stringify(r))}const Le=Object.keys;function Uo(r,s,e=.01){return Math.abs(r[0]-s[0])<e&&Math.abs(r[1]-s[1])<e}function Jp(r,s=.01){if(r.length===0)return[];const e=[[r[0][0],r[0][1]]];for(let t=1;t<r.length;t++)Uo([r[t][0],r[t][1]],e[e.length-1],s)||e.push([r[t][0],r[t][1]]);return e}function qp(r,s=.01){if(r.length<=2)return r;const e=r[0],t=r[r.length-1];return Uo(e,t,s)?r.slice(0,-1):r}function Kp(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 Yi(r,s){return Math.atan2(s[1]-r[1],s[0]-r[0])}function _p(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=Kp(e);return e.sort((i,o)=>{const n=Yi(t,i),a=Yi(t,o);return n-a})}function eg(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 tg(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 $e.ClipperOffset;n.AddPath(o(i,1e3),$e.JoinType.jtRound,$e.EndType.etOpenButt);const a=[];n.Execute(a,1);const c=new $e.Clipper;c.AddPaths(a,$e.PolyType.ptSubject,!0),s.forEach(h=>{c.AddPath(o(h,1e3),$e.PolyType.ptClip,!0)});const l=new $e.Paths;c.Execute($e.ClipType.ctDifference,l,$e.PolyFillType.pftNonZero,$e.PolyFillType.pftNonZero);const u=l.map(h=>qp(_p(Jp(h.map(d=>[d.X/1e3,d.Y/1e3]),e),e),e)).filter(h=>h.length>=2);return eg(u,r)}class Bo extends Y{constructor(e){super(e);M(this,"canRotate",!0);M(this,"scaleType",re.all);M(this,"toolsType",v.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:De(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 T=i?this.fullLayer:this.drawLayer||this.fullLayer;f=this.draw({attrs:p,tasks:h,effects:d,layer:T,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(T=>{I.push(T.x,T.y,this.computRadius(T.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===te.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=We(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 Z(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 Z(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 Z(p[w],p[w+1]);if(f.length>0){const T=f[f.length-1].point,C=k.Sub(I,T).uni();I.setv(C)}f.push({point:I,radius:n})}const{ps:m}=this.computStroke(f,!1);d.push(m.map(w=>w.XY))}tg(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 T=[],C=a.worldPosition,S=a.worldScaling;for(let x=0;x<i.length;x++){const{pos:L,points:b}=i[x],{ps:E,rect:A}=this.computDrawPoints(b);let P;const R=b.length===1;h===te.Stroke||R?P=Je(E,!0):P=Je(E,!1);const z={pos:L,d:P,fillColor:h===te.Stroke||R?u:void 0,lineDash:h===te.Dotted&&!R?[1,d*2]:h===te.LongDotted&&!R?[d,d*2]:void 0,strokeColor:u,lineCap:h===te.Stroke||R?void 0:"round",lineWidth:h===te.Stroke||R?0:d};I=he(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)}),T.push(z)}p&&(t.scale=p),f&&(t.rotate=f),m&&(t.translate=m);const N=new ae.Group;if(I){this.centerPos=Y.getCenterPos(I,a);const x=h===te.Stroke&&!w;N.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=T.map(b=>(b.pos=[b.pos[0]-this.centerPos[0],b.pos[1]-this.centerPos[1]],new ae.Path(b)));N.append(...L),x&&N.seal(),w&&(this.scaleType=re.proportional,this.drawEraserlines({group:N,eraserlines:w,pos:this.centerPos,layer:a},l)),this.replace(a,o,N)}if(p||f||m){const x=N==null?void 0:N.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&&N.setAttribute("opacity",0),I}computDrawPoints(e){return this.workOptions.strokeType===te.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:fe(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(Z.Sub(l,d)),o.push(Z.Add(l,d))}const n=e[e.length-1];if(t){const c=Z.GetSemicircleStroke(n.point,i[i.length-1],-1,8),l=Z.GetSemicircleStroke(e[0].point,o[0],-1,8),u=i.concat(c,o.reverse(),l);return{ps:u,rect:fe(u)}}const a=i.concat(o.reverse());return{ps:a,rect:fe(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:Z.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===te.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 Z(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 T=d.x-n,C=d.y-a;l=[{point:new Z(T,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 Z(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]),T=Math.max(this.tmpPoints[w].z-this.uniThickness*I,0);if(this.tmpPoints[w-1].z>=T)break;this.tmpPoints[w-1].setz(T),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 Z(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 Z(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"?sy(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 Fo extends Y{constructor(e){super(e);M(this,"toolsType",v.LaserPen);M(this,"canRotate",!1);M(this,"scaleType",re.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=fe(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===te.Dotted?[1,l*2]:u===te.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=fe(this.tmpPoints,u);const d={name:e==null?void 0:e.toString(),fillColor:c?l:void 0,opacity:1,lineDash:h===te.Dotted&&!c?[1,u*2]:h===te.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=We(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=fe(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=fe(this.tmpPoints,a);const g={name:(f=this.workId)==null?void 0:f.toString(),fillColor:d?n:void 0,opacity:1,lineDash:c===te.Dotted&&!d?[1,a*2]:c===te.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:Z.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 Z(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 ae.Path,{pos:u,points:h}=c;let d;o?d=Je(h,!0):d=Je(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 Z(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 Z(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=he(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 St=class St extends Y{constructor(e,t){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.none);M(this,"toolsType",v.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}=St.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}=St.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}=St.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&&Ys(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 Z(d.x,d.y))}const u=c.length&&fe(c)||n.rect;Ys(u,this.eraserRect)&&(l.length>1?Zs.polyline(l.map(d=>d.XY),this.eraserPolyline).length&&i.add(n.name):i.add(n.name),o=he(o,n.rect||u))}return i.forEach(n=>{var c;const a=this.fullLayer.getElementsByName(n);a[0]&&(a[0].remove(),Re(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=he(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(St,"eraserSizes",ii);let ss=St;const Oe="++",H="selector",Kt="all";var sg="__lodash_hash_undefined__";function ig(r){return this.__data__.set(r,sg),this}var og=ig;function ng(r){return this.__data__.has(r)}var rg=ng,ag=fo,cg=og,lg=rg;function is(r){var s=-1,e=r==null?0:r.length;for(this.__data__=new ag;++s<e;)this.add(r[s])}is.prototype.add=is.prototype.push=cg;is.prototype.has=lg;var oi=is;function hg(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 ug=hg;function dg(r,s){return r.has(s)}var ni=dg,pg=oi,gg=ug,fg=ni,Mg=1,yg=2;function mg(r,s,e,t,i,o){var n=e&Mg,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&yg?new pg: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(!gg(s,function(w,I){if(!fg(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 Qo=mg;function wg(r){var s=-1,e=Array(r.size);return r.forEach(function(t,i){e[++s]=[i,t]}),e}var Ig=wg;function vg(r){var s=-1,e=Array(r.size);return r.forEach(function(t){e[++s]=t}),e}var ri=vg,Ui=Zt,Bi=Po,Tg=Hs,Ng=Qo,Sg=Ig,Cg=ri,kg=1,Dg=2,xg="[object Boolean]",Lg="[object Date]",bg="[object Error]",jg="[object Map]",Ag="[object Number]",zg="[object RegExp]",Pg="[object Set]",Eg="[object String]",Og="[object Symbol]",Rg="[object ArrayBuffer]",Wg="[object DataView]",Fi=Ui?Ui.prototype:void 0,Ds=Fi?Fi.valueOf:void 0;function Yg(r,s,e,t,i,o,n){switch(e){case Wg:if(r.byteLength!=s.byteLength||r.byteOffset!=s.byteOffset)return!1;r=r.buffer,s=s.buffer;case Rg:return!(r.byteLength!=s.byteLength||!o(new Bi(r),new Bi(s)));case xg:case Lg:case Ag:return Tg(+r,+s);case bg:return r.name==s.name&&r.message==s.message;case zg:case Eg:return r==s+"";case jg:var a=Sg;case Pg:var c=t&kg;if(a||(a=Cg),r.size!=s.size&&!c)return!1;var l=n.get(r);if(l)return l==s;t|=Dg,n.set(r,s);var u=Ng(a(r),a(s),t,i,o,n);return n.delete(r),u;case Og:if(Ds)return Ds.call(r)==Ds.call(s)}return!1}var Ug=Yg,Qi=jo,Bg=1,Fg=Object.prototype,Qg=Fg.hasOwnProperty;function Vg(r,s,e,t,i,o){var n=e&Bg,a=Qi(r),c=a.length,l=Qi(s),u=l.length;if(c!=u&&!n)return!1;for(var h=c;h--;){var d=a[h];if(!(n?d in s:Qg.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 T=n?t(I,w,d,s,r,o):t(w,I,d,r,s,o);if(!(T===void 0?w===I||i(w,I,e,t,o):T)){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 Zg=Vg,xs=Mo,Hg=Qo,Gg=Ug,$g=Zg,Vi=ws,Zi=Ht,Hi=$s,Xg=No,Jg=1,Gi="[object Arguments]",$i="[object Array]",Xt="[object Object]",qg=Object.prototype,Xi=qg.hasOwnProperty;function Kg(r,s,e,t,i,o){var n=Zi(r),a=Zi(s),c=n?$i:Vi(r),l=a?$i:Vi(s);c=c==Gi?Xt:c,l=l==Gi?Xt:l;var u=c==Xt,h=l==Xt,d=c==l;if(d&&Hi(r)){if(!Hi(s))return!1;n=!0,u=!1}if(d&&!u)return o||(o=new xs),n||Xg(r)?Hg(r,s,e,t,i,o):Gg(r,s,c,e,t,i,o);if(!(e&Jg)){var g=u&&Xi.call(r,"__wrapped__"),p=h&&Xi.call(s,"__wrapped__");if(g||p){var f=g?r.value():r,m=p?s.value():s;return o||(o=new xs),i(f,m,e,t,o)}}return d?(o||(o=new xs),$g(r,s,e,t,i,o)):!1}var _g=Kg,ef=_g,Ji=Ke;function Vo(r,s,e,t,i){return r===s?!0:r==null||s==null||!Ji(r)&&!Ji(s)?r!==r&&s!==s:ef(r,s,e,t,Vo,i)}var tf=Vo,sf=tf;function of(r,s){return sf(r,s)}var nf=of;const tt=jt(nf);function Gt(r,s,e){return"#"+((r<<16)+(s<<8)+e).toString(16).padStart(6,"0")}function Ce(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 at(r,s,e,t=1){return`rgba(${r},${s},${e},${t})`}function Is(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[Gt(e,t,i),o]}function Ut(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 Jt(r){return r==="transparent"}const hs=class hs extends Y{constructor(e){super(e);M(this,"toolsType",v.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",re.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=fe(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 Z(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 ae.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 ae.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:hs.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 ae.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=re.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!==v.Pencil&&(o=!1),a.strokeType&&(this.strokeType=a.strokeType),u===v.SpeechBalloon&&(t.add(u),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.placement=a.placement),u===v.Polygon&&(t.add(u),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=a.vertices),u===v.Star&&(t.add(u),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=a.vertices,this.shapeOpt.innerRatio=a.innerRatio,this.shapeOpt.innerVerticeStep=a.innerVerticeStep),u===v.Text&&(this.textOpt=a),e.size===1&&(this.textOpt&&(this.canTextEdit=!0),this.canRotate=c,this.scaleType=l),u===v.Image&&(i=n),(l===re.proportional&&this.scaleType!==re.none||l===re.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=re.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===re.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&&tt(this.selectIds,n.selectIds))return{type:D.None};this.selectIds=n.selectIds;const a=n.intersectRect;this.getSelecteorInfo(n.subNodeMap),this.draw(H,this.fullLayer,n),this.oldSelectRect=a;const c=this.getChildrenPoints();return{type:D.Select,dataType:B.Local,rect:he(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,H,!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 Z(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=fe(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&&Ut(n)||[0,0,0,0],w={close:!0,normalize:!0,points:d,lineWidth:f,fillColor:at(m[0],m[1],m[2],.1),strokeColor:at(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 T=new ae.Group({name:t,id:t,pos:p,anchor:[.5,.5],size:[g.w,g.h],scale:a,rotate:c,translate:l}),C=new ae.Polyline({...w,pos:[0,0]});if(T.appendChild(C),this.replace(i,t,T),a||c||l){const S=T.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=fe(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 Z(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=he(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=H,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(_o(h).find(g=>g.isPointCollision(o,n))){a=u;break}}if(a){const u=a.name;if(!tt(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=he(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=he(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=he(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=he(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===v.Ellipse||e===v.Triangle||e===v.Rectangle||e===v.Polygon||e===v.Star||e===v.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||De(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 N=o.get(S);if(N){const{toolsType:x,opt:L}=N,b=(l==null?void 0:l.getElementsByName(S))[0];if(b){const E={...t};let A;const P=Y.isWillRefresh({toolsType:x,opt:L,updateOpt:E,vNodes:o,node:b,willSerializeData:n});if(x){A=I==null?void 0:I.get(S);const R=Ko(x);if(R==null||R.updateNodeOpt({node:b,opt:E,vNodes:o,willSerializeData:n,targetNode:A}),N&&a&&P){const z=a.createWorkShapeNode({workId:S,toolsType:x,toolsOpt:N.opt});z==null||z.setWorkId(S);let X;if(x===v.Image)X=await z.consumeServiceAsync({isFullWork:!0,replaceId:S,worker:a});else if(x===v.Text)X=await z.consumeServiceAsync({isFullWork:!0,replaceId:S});else try{X=z==null?void 0:z.consumeService({op:N.op,isFullWork:!0,replaceId:S,workState:g})}catch{continue}X&&(N.rect=X)}N&&(h.set(S,N),u=he(u,N.rect))}}}}I&&g===j.Done&&(o.deleteLastTarget(),I=void 0);const T=u;if(d&&f&&w&&m&&T&&!c){const S=[[T.x,T.y],[T.x+T.w,T.y],[T.x+T.w,T.y+T.h],[T.x,T.y+T.h]];let N;switch(m){case"top":case"topLeft":case"left":f[0]>0&&f[1]>0?N=S[0]:f[0]>0?N=S[3]:f[1]>0?N=S[1]:N=S[2];break;case"topRight":f[0]<0&&f[1]>0?N=S[1]:f[0]<0?N=S[2]:f[1]>0?N=S[0]:N=S[3];break;case"right":case"bottomRight":case"bottom":f[0]<0&&f[1]<0?N=S[2]:f[0]<0?N=S[1]:f[1]<0?N=S[3]:N=S[0];break;case"bottomLeft":f[0]>0&&f[1]<0?N=S[3]:f[0]>0?N=S[0]:f[1]<0?N=S[2]:N=S[1];break}const x=N&&[d[0]-N[0],d[1]-N[1]]||[0,0];if(!tt(x,[0,0]))return await this.updateSelector({...e,updateSelectorOpt:{workState:g},offset:x})}this.getSelecteorInfo(h),this.draw(H,l,{selectIds:i||[],subNodeMap:h,intersectRect:T});const C=he(this.oldSelectRect,T);return this.oldSelectRect=T,{type:D.Select,dataType:B.Local,selectRect:T,renderRect:u,rect:he(C,T),selectIds:i}}blurSelector(){const e=this.unSelectedAllIds();return{type:D.Select,dataType:B.Local,rect:e,selectIds:[],willSyncService:!0}}getRightServiceId(e){return e.replace(Oe,"-")}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=he(c,h.rect),l.set(u,h))}),this.getSelecteorInfo(l),this.draw(n,this.fullLayer,{intersectRect:c,selectIds:o||[],subNodeMap:l},i),he(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=he(e,n.rect),t.set(o,n))},this),this.getSelecteorInfo(t),this.draw(H,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=he(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&&!tt(t,this.oldSelectRect))return{type:D.CursorHover,dataType:B.Local,rect:he(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(hs,"selectorBorderId","selector-border");let os=hs;class Zo extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.both);M(this,"toolsType",v.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 Z(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=he(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=We(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:T,trianglePoints:C,trianglePos:S}=this.computDrawPoints(a),N=[I.x+I.w/2,I.y+I.h/2],x={pos:N,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 ae.Group(x),b={points:C,pos:[S[0]-N[0],S[1]-N[1]],fillColor:n,strokeColor:n,lineWidth:0,normalize:!1},E=new ae.Polyline(b);if(L.append(E),!T&&m&&w){const P={points:m,pos:[w[0]-N[0],w[1]-N[1]],fillColor:n,strokeColor:n,lineDash:d===te.Dotted&&!T?[1,a*2]:d===te.LongDotted&&!T?[a,a*2]:void 0,lineCap:d===te.Normal?void 0:"round",lineWidth:a,normalize:!1},R=new ae.Polyline(P);L.append(R)}g&&(this.scaleType=re.proportional,this.drawEraserlines({group:L,eraserlines:g,pos:N,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 P=L.getBoundingClientRect();A={x:Math.floor(P.x-Y.SafeBorderPadding),y:Math.floor(P.y-Y.SafeBorderPadding),w:Math.floor(P.width+Y.SafeBorderPadding*2),h:Math.floor(P.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=Z.Sub(this.tmpPoints[0],i),n=Z.Add(this.tmpPoints[0],i),a=k.Mul(t,this.arrowTipWidth),c=k.Sub(this.tmpPoints[1],a),l=Z.Sub(c,i),u=Z.Add(c,i),h=k.Per(t).mul(e*1.5),d=Z.Sub(c,h),g=Z.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=>Z.Sub(w,this.tmpPoints[1]).XY).flat(1),trianglePos:this.tmpPoints[1].XY,points:p.map(w=>Z.Sub(w,this.tmpPoints[0]).XY).flat(1),rect:fe(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=Z.Sub(this.tmpPoints[0],i),n=Z.Add(this.tmpPoints[0],i),a=[o,this.tmpPoints[1],n];return{trianglePoints:a.map(c=>Z.Sub(c,this.tmpPoints[1]).XY).flat(1),trianglePos:this.tmpPoints[1].XY,rect:fe(a),isTriangle:!0}}updateTempPoints(e){const t=e.slice(-2),i=new Z(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 Z(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 Ho extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.all);M(this,"toolsType",v.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 Z(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(ui(d,f)!==ft.outside){const w=he(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=We(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:T}=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===te.Dotted?[1,l*2]:p===te.LongDotted?[l,l*2]:void 0},S={name:t,id:t,zIndex:u,pos:T,anchor:[.5,.5],size:[I.w,I.h]};h&&(S.scale=h),d&&(S.rotate=d),g&&(S.translate=g);const N=new ae.Group(S);if(o){const b=new ae.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:a,lineWidth:1,scale:[1/m[0],1/m[1]]});N.append(b)}const x=new ae.Ellipse({...C,pos:[0,0]});N.append(x),f&&(this.scaleType=re.proportional,this.drawEraserlines({group:N,eraserlines:f,pos:T,layer:i},n)),this.replace(i,t,N);const L=N.getBoundingClientRect();return this.isDelete&&N.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=fe(this.tmpPoints),i=fe(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 Z(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 Z(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 Go extends Y{constructor(e){super(e);M(this,"canRotate",!0);M(this,"scaleType",re.all);M(this,"toolsType",v.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=fe(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=fe(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 Z(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=he(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=We(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,T=i.worldScaling,{points:C,rect:S,pos:N}=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===te.Dotted?[1,h*2]:m===te.LongDotted?[h,h*2]:void 0};let L={x:Math.floor(S.x*T[0]+I[0]-Y.SafeBorderPadding),y:Math.floor(S.y*T[1]+I[1]-Y.SafeBorderPadding),w:Math.floor(S.w*T[0]+2*Y.SafeBorderPadding),h:Math.floor(S.h*T[0]+2*Y.SafeBorderPadding)};const b=new ae.Group({name:t,id:t,zIndex:d,pos:N,anchor:[.5,.5],size:[S.w,S.h],scale:g,rotate:p,translate:f}),E=new ae.Polyline({...x,pos:[0,0]});if(b.appendChild(E),o){const A=new ae.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:l,lineWidth:1,scale:[1/T[0],1/T[1]]});b.appendChild(A)}if(w&&(this.scaleType=re.proportional,this.drawEraserlines({group:b,eraserlines:w,pos:N,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 Z(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 $o extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.all);M(this,"toolsType",v.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 Z(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=he(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=We(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,T=i.worldScaling,{rect:C,pos:S,points:N}=this.computDrawPoints(l,h,d,g),x={close:!0,points:N,lineWidth:l,fillColor:c!=="transparent"&&c||void 0,strokeColor:a,normalize:!0,lineJoin:"round",lineCap:"round",lineDash:w===te.Dotted?[1,l*2]:w===te.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 ae.Group(L);if(o){const P=new ae.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:a,lineWidth:1,scale:[1/T[0],1/T[1]]});b.append(P)}const E=new ae.Polyline({...x,pos:[0,0]});b.append(E),I&&(this.scaleType=re.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=fe(this.tmpPoints),a=[Math.floor(n.x+n.w/2),Math.floor(n.y+n.h/2)],c=ln(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:fe(this.tmpPoints,e),pos:a,points:h}}updateTempPoints(e){const t=e.slice(-2),i=new Z(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n)||Z.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 Z(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===v.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 Xo extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.all);M(this,"toolsType",v.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 Z(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=he(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=We(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:T,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===te.Dotted?[1,l*2]:f===te.LongDotted?[l,l*2]:void 0},N={name:t,id:t,zIndex:u,pos:T,anchor:[.5,.5],size:[I.w,I.h]};d&&(N.scale=d),g&&(N.rotate=g),p&&(N.translate=p);const x=new ae.Group(N);if(o){const E=new ae.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:a,lineWidth:1,scale:[1/w[0],1/w[1]]});x.append(E)}const L=new ae.Polyline({...S,pos:[0,0]});x.append(L),m&&(this.scaleType=re.proportional,this.drawEraserlines({group:x,eraserlines:m,pos:T,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=fe(this.tmpPoints),o=[Math.floor(i.x+i.w/2),Math.floor(i.y+i.h/2)],n=ln(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:fe(this.tmpPoints,e),pos:o,points:c}}updateTempPoints(e){const t=e.slice(-2),i=new Z(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n)||Z.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 Z(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===v.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 Ze{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(...Ze.getBezierPoints(s,o,n,a,c)):o&&n&&a?t.push(...Ze.getBezierPoints(s,o,n,a)):o&&n?t.push(...Ze.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=Ze.oneBezier:i&&!o?n=Ze.twoBezier:i&&o&&(n=Ze.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 Jo extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.all);M(this,"toolsType",v.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 Z(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=he(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=We(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),T={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===te.Dotted?[1,c*2]:p===te.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 ae.Group(C),N=new ae.Polyline({...T,pos:[0,0]});S.append(N),f&&(this.scaleType=re.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=fe(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=fe(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=Ze.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=Ze.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=Ze.getBezierPoints(10,f,o[2],m),I=k.Add(o[3],new k(n,0,0)),T=k.Sub(o[3],new k(0,a,0)),C=Ze.getBezierPoints(10,I,o[3],T),S=n*(1-this.ratio)*10,N=a*(1-this.ratio)*10;switch(t){case"bottom":{const b=k.Sub(o[2],new k(n*5-S/2,0,0)),E=k.Sub(o[2],new k(n*5,-N,0)),A=k.Sub(o[2],new k(n*5+S/2,0,0));c.push(E,A,...C,...h,...p,...w,b);break}case"bottomRight":{const b=k.Sub(o[2],new k(n*1.1,0,0)),E=k.Sub(o[2],new k(n*1.1+S/2,-N,0)),A=k.Sub(o[2],new k(n*1.1+S,0,0));c.push(E,A,...C,...h,...p,...w,b);break}case"bottomLeft":{const b=k.Add(o[3],new k(n*1.1+S,0,0)),E=k.Add(o[3],new k(n*1.1+S/2,N,0)),A=k.Add(o[3],new k(n*1.1,0,0));c.push(E,A,...C,...h,...p,...w,b);break}case"top":{const b=k.Sub(o[1],new k(n*5-S/2,0,0)),E=k.Sub(o[1],new k(n*5,N,0)),A=k.Sub(o[1],new k(n*5+S/2,0,0));c.push(E,b,...p,...w,...C,...h,A);break}case"topRight":{const b=k.Sub(o[1],new k(n*1.1,0,0)),E=k.Sub(o[1],new k(n*1.1+S/2,N,0)),A=k.Sub(o[1],new k(n*1.1+S,0,0));c.push(E,b,...p,...w,...C,...h,A);break}case"topLeft":{const b=k.Add(o[0],new k(n*1.1+S,0,0)),E=k.Add(o[0],new k(n*1.1+S/2,-N,0)),A=k.Add(o[0],new k(n*1.1,0,0));c.push(E,b,...p,...w,...C,...h,A);break}case"left":{const b=k.Add(o[0],new k(0,a*5-N/2,0)),E=k.Add(o[0],new k(-S,a*5,0)),A=k.Add(o[0],new k(0,a*5+N/2,0));c.push(E,b,...h,...p,...w,...C,A);break}case"leftTop":{const b=k.Add(o[0],new k(0,a*1.1,0)),E=k.Add(o[0],new k(-S,a*1.1+N/2,0)),A=k.Add(o[0],new k(0,a*1.1+N,0));c.push(E,b,...h,...p,...w,...C,A);break}case"leftBottom":{const b=k.Sub(o[3],new k(0,a*1.1+N,0)),E=k.Sub(o[3],new k(S,a*1.1+N/2,0)),A=k.Sub(o[3],new k(0,a*1.1,0));c.push(E,b,...h,...p,...w,...C,A);break}case"right":{const b=k.Add(o[1],new k(0,a*5-N/2,0)),E=k.Add(o[1],new k(S,a*5,0)),A=k.Add(o[1],new k(0,a*5+N/2,0));c.push(E,A,...w,...C,...h,...p,b);break}case"rightTop":{const b=k.Add(o[1],new k(0,a*1.1,0)),E=k.Add(o[1],new k(S,a*1.1+N/2,0)),A=k.Add(o[1],new k(0,a*1.1+N,0));c.push(E,A,...w,...C,...h,...p,b);break}case"rightBottom":{const b=k.Sub(o[2],new k(0,a*1.1+N,0)),E=k.Sub(o[2],new k(-S,a*1.1+N/2,0)),A=k.Sub(o[2],new k(0,a*1.1,0));c.push(E,A,...w,...C,...h,...p,b);break}}const x=fe(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 Z(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n)||Z.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 Z(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===v.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 rf=yt,af=Ke,cf="[object Boolean]";function lf(r){return r===!0||r===!1||af(r)&&rf(r)==cf}var hf=lf;const Nt=jt(hf);class qo extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.both);M(this,"toolsType",v.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 Z(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=he(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=We(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),T=[w.x+w.w/2,w.y+w.h/2],C=new ae.Group({pos:T,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===te.Dotted&&!I?[1,a*2]:d===te.LongDotted&&!I?[a,a*2]:void 0,lineCap:d===te.Normal||I?void 0:"round",lineWidth:d===te.Normal||I?0:a};l&&(S.scale=l),u&&(S.rotate=u),h&&(S.translate=h);const N=new ae.Path(S);C.append(N),g&&(this.scaleType=re.proportional,this.drawEraserlines({group:C,eraserlines:g,pos:T,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=N.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=Z.Sub(this.tmpPoints[0],o),a=Z.Add(this.tmpPoints[0],o),c=Z.Sub(this.tmpPoints[1],o),l=Z.Add(this.tmpPoints[1],o),u=Z.GetSemicircleStroke(this.tmpPoints[1],c,-1,8),h=Z.GetSemicircleStroke(this.tmpPoints[0],a,-1,8),d=[n,c,...u,l,a,...h];let g;return t!==te.Normal?g=Je(this.tmpPoints,!1):g=Je(d,!0),{d:g,rect:fe(d),isDot:!1,pos:this.tmpPoints[0].XY}}computDotPoints(e){const t=Z.GetDotStroke(this.tmpPoints[0],e/2,8);return{d:Je(t,!0),rect:fe(t),isDot:!0,pos:this.tmpPoints[0].XY}}updateTempPoints(e){const t=e.slice(-2),i=new Z(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 Z(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 ct=class ct extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.proportional);M(this,"toolsType",v.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 ae.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 ct.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),Nt(l)&&(d.opt.lineThrough=l),Nt(u)&&(d.opt.underline=u),De(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(ct.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=wt(e.text),h=u.length,{fontSize:d,lineHeight:g,bold:p,textAlign:f,italic:m,fontFamily:w,verticalAlign:I,fontColor:T,fontBgColor:C,underline:S,lineThrough:N}=e,x=ct.getSafetySnippetRatio(t)||1,L=Math.floor(d*x),b=ct.getSafetySnippetFontLength(L);let E=0;for(let P=0;P<h;P++){const R=u[P],z=g||L*1.5;if(R){const X=ny(R),K=[0,0],F=[0,d*1.2];I==="middle"&&(K[1]=P*d*1.2+5);const G=[0,-d*.15];K[0]=5;const _=Math.sin(Math.PI/180*20);let ce=0;const ee=[];let q=0;for(;q<X;){f==="left"&&(G[0]=ce),q===0&&m==="italic"&&(G[0]=G[0]-_/2*d);const ue=R.slice(q,q+b),ze={anchor:[0,0],pos:G,text:ue,fontFamily:w,fontSize:L,lineHeight:z,strokeColor:T,fontWeight:p,fillColor:T,textAlign:f,fontStyle:m,scale:[1/x,1/x]},Te=new ae.Label(ze),V=await Te.textImageReady;let le=!0;if(V){const ie=V.rect&&V.rect[2],pe=V.rect&&V.rect[3];if(ie&&pe){const de=ie/x,Me=pe/x;ce=de+ce,m==="italic"&&(p==="bold"?ce=ce-_*d*1.2:ce=ce-_*d),((G[0]+K[0]+de)*t.worldScaling[0]+n<=0||(G[0]+K[0])*t.worldScaling[0]+n>=c||(G[1]+K[1]+Me)*t.worldScaling[1]+a<=0||(G[1]+K[1])*t.worldScaling[1]+a>=l)&&(Te.disconnect(),le=!1),le&&ee.push(Te)}}q+=b}F[0]=ce,m==="italic"&&(F[0]=F[0]+_*d),E=Math.max(E,F[0]);let J=!0;if(((K[0]+F[0])*t.worldScaling[0]+n<=0||K[0]*t.worldScaling[0]+n>=c||(K[1]+F[1])*t.worldScaling[0]+a<=0||K[1]*t.worldScaling[1]+a>=l)&&(J=!1),J){if(S){const Te=Math.floor(d/10),V={normalize:!1,pos:[0,d*1.1+Te/2],lineWidth:Te,points:[0,0,Math.ceil(F[0]),0],strokeColor:T,className:"underline"},le=new ae.Polyline(V);ee.push(le)}if(N){const Te={normalize:!1,pos:[0,d*1.2/2],lineWidth:Math.floor(d/10),points:[0,0,Math.ceil(F[0]),0],strokeColor:T,className:"lineThrough"},V=new ae.Polyline(Te);ee.push(V)}const ue={pos:K,anchor:[0,0],size:F,bgcolor:C},ze=new ae.Group(ue);ze.append(...ee),o.push(ze)}}}return{labels:o,maxWidth:E}}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:T}=i,C=n&&ke(n)||o.get(t.name);if(!C||!t.parent)return;const N=C.opt;if(De(T)&&(t.setAttribute("zIndex",T),C.opt.zIndex=T),c&&N.fontColor&&(N.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&&N.fontBgColor&&(N.fontBgColor=a,t.children.forEach(x=>{x.tagName==="GROUP"&&x.setAttribute("bgcolor",a)})),g&&(N.bold=g),p&&(N.italic=p),Nt(f)&&(N.lineThrough=f),Nt(m)&&(N.underline=m),w&&(N.fontSize=w),u&&h&&d&&n&&N.boxPoint){const x=I==null?void 0:I.get(t.name);if(x){const{fontSize:A,boxSize:P}=x;N.boxSize=P||N.boxSize,N.fontSize=A||N.fontSize}const L=[N.boxPoint[0],N.boxPoint[1]];li(N.boxPoint,h,d,l);const b=[C.op[0],C.op[1]],E=[b[0]-L[0],b[1]-L[1]];if(C.centerPos=[C.centerPos[0]+E[0],C.centerPos[1]+E[1]],C.opt.eraserlines)for(const A of Object.values(C.opt.eraserlines)){const{op:P,thickness:R}=A;A.thickness=R*Math.max(d[0],d[1]);for(let z=0;z<P.length;z++)hi(P[z],h,d,l)}}else if(l&&N.boxPoint&&(N.boxPoint=[N.boxPoint[0]+l[0],N.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 E=L[b].map((A,P)=>P%2?A+l[1]:A+l[0]);x.op[b]=E}}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=he(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(ct,"textImageSnippetSize",1024*4),M(ct,"SafeBorderPadding",30);let ns=ct;const Ct=class Ct extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.none);M(this,"toolsType",v.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}=Ct.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 Z(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 Z(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=fe(this.tmpPoints,e);c=Vt(c,a),c=an(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!==v.Pencil)continue;let g=Vt(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)Zs.polyline(w,p,f);if(f.length&&d.opt)for(const w of f){const I=[];for(let T=0;T<w.length;T++)T!==0&&tt(w[T],w[T-1])||I.push(...w[T]);m.push(I)}if(m.length&&t){const w=t.createWorkShapeNode({workId:h,toolsType:v.Pencil,toolsOpt:d.opt});w.setWorkId(h);const I=w==null?void 0:w.computPencilPoints({op:d.op,eraserPolylines:m,eraserThickness:e});if(n=he(n,d.rect),o.add(h),t.removeNode(h),I.length)for(let T=0;T<I.length;T++){const C=`${h}_${Date.now()}_${T}`,S=C,x=t.setFullWork({workId:S,opt:d.opt,toolsType:v.Pencil}).consumeService({op:I[T],isFullWork:!0,replaceId:S});t.clearWorkShapeNodeCache(S),n=he(n,x),i.set(C,{...d,rect:x??d.rect,name:C,op:I[T]})}}}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}=Ct.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 T={name:this.workId,id:De(c)&&c.toString()||void 0},C=this.syncIndex;this.syncTimestamp===0&&(this.syncTimestamp=Date.now());let S=!1,N;const x=this.tmpPoints.slice(w);if(o||n){const b=i?this.fullLayer:this.drawLayer||this.fullLayer;N=this.draw({attrs:T,consumePoints:x,layer:b,removeDrawCount:a,thickness:p})}if(o)return w>10&&this.tmpPoints.splice(0,w-10),{rect:N,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:N,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=fe(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 ae.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,N,x,L)=>x>0&&L[x-1][0]===N[0]&&L[x-1][1]===N[1]?S:S.concat(N[0],N[1]),[]),w=this.computEraserPoints(m,p),I=Je(w,!0),T={pos:[0,0],d:I,fillColor:this.workOptions.eraserColor},C=new ae.Path(T);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}=Ct.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=We(h);return{...this.baseConsumeResult,type:D.FullWork,dataType:B.Local,rect:u,ops:d,willNewNodes:l,willDeleteNodes:c}}clearTmpPoints(){this.tmpPoints.length=0}};M(Ct,"eraserSizes",ii);let rs=Ct;const kt=class kt extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.none);M(this,"toolsType",v.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}=kt.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 Z(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 Z(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=fe(this.tmpPoints,e);c=Vt(c,a),c=an(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===v.Text||d.toolsType===v.Image)continue;let g=Vt(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)Zs.polyline(I,p,f);if(f.length&&d.opt)for(const I of f){const T=[];for(let C=0;C<I.length;C++)C!==0&&tt(I[C],I[C-1])||T.push(...I[C]);m.push(T)}if(d.opt.eraserlines||(d.opt.eraserlines=[]),d.opt.eraserlines){if(d.opt.eraserlines.push({op:m,thickness:e}),t){const{toolsType:I}=d,T=t.createWorkShapeNode({workId:h,toolsType:I,toolsOpt:d.opt});T==null||T.setWorkId(h);const C=T==null?void 0:T.consumeService({op:d.op,isFullWork:!0,replaceId:h});if(n=he(n,C),T!=null&&T.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}=kt.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 T={name:this.workId,id:De(c)&&c.toString()||void 0},C=this.syncIndex;this.syncTimestamp===0&&(this.syncTimestamp=Date.now());let S=!1,N;const x=this.tmpPoints.slice(w);if(o||n){const b=i?this.fullLayer:this.drawLayer||this.fullLayer;N=this.draw({attrs:T,consumePoints:x,layer:b,removeDrawCount:a,thickness:p})}if(o)return w>10&&this.tmpPoints.splice(0,w-10),{rect:N,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:N,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=fe(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 ae.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,N,x,L)=>x>0&&L[x-1][0]===N[0]&&L[x-1][1]===N[1]?S:S.concat(N[0],N[1]),[]),w=this.computEraserPoints(m,p),I=Je(w,!0),T={pos:[0,0],d:I,fillColor:this.workOptions.eraserColor},C=new ae.Path(T);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}=kt.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=We(h);return{...this.baseConsumeResult,type:D.FullWork,dataType:B.Local,rect:u,ops:d,willUpdateNodes:l,willDeleteNodes:c}}clearTmpPoints(){this.tmpPoints.length=0}};M(kt,"eraserSizes",ii);let as=kt;function Ko(r){switch(r){case v.Arrow:return Zo;case v.Pencil:return Bo;case v.Straight:return qo;case v.Ellipse:return Ho;case v.Polygon:case v.Triangle:return Xo;case v.Star:case v.Rhombus:return $o;case v.Rectangle:return Go;case v.SpeechBalloon:return Jo;case v.Text:return ns;case v.LaserPen:return Fo;case v.Eraser:return ss;case v.PencilEraser:return rs;case v.BitMapEraser:return as;case v.Selector:return os;case v.Image:return Qt}}function vs(r,s){const{toolsType:e,...t}=r;switch(e){case v.Arrow:return new Zo(t);case v.Pencil:return new Bo(t);case v.Straight:return new qo(t);case v.Ellipse:return new Ho(t);case v.Polygon:case v.Triangle:return new Xo(t);case v.Star:case v.Rhombus:return new $o(t);case v.Rectangle:return new Go(t);case v.SpeechBalloon:return new Jo(t);case v.Text:return new ns(t);case v.LaserPen:return new Fo(t);case v.Eraser:return new ss(t,s);case v.BitMapEraser:return new as(t);case v.PencilEraser:return new rs(t);case v.Selector:return t.vNodes?new os({...t,vNodes:t.vNodes,drawLayer:t.fullLayer}):void 0;case v.Image:return new Qt(t);default:return}}function _o(r){const s=[],e=["PATH","SPRITE","POLYLINE","RECT","ELLIPSE","LABEL"];for(const t of r){if(t.tagName==="GROUP"&&t.children.length){const i=_o(t.children);s.push(...i)}t.tagName&&e.includes(t.tagName)&&s.push(t)}return s}const uf="cursorhover",ai=20,ge="mainView";class en{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===v.Image&&(o.opt.locked||e&&e.disableEraseImage)||o.toolsType===v.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=ke(e.rect)),e.op&&KM(e.op)&&(t.op=ke(e.op)),e.canRotate&&(t.canRotate=e.canRotate),e.scaleType&&(t.scaleType=e.scaleType),e.opt&&(t.opt=ke(e.opt)),e.toolsType&&(t.toolsType=e.toolsType),e.centerPos&&(t.centerPos=ke(e.centerPos)),Nt(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(Ys(s,a.rect)){if(e&&a.toolsType===v.Image&&a.opt.locked||t&&a.toolsType===v.Text&&(a.opt.workState===j.Doing||a.opt.workState===j.Start))continue;i=he(i,a.rect),o.set(n,a)}return{rectRange:i,nodeRange:o}}getNodeRectFormShape(s,e){const t=Ko(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,ke(i))}return this.targetNodeMap.push(ke(e)),this.targetNodeMap.length-1}setTarget(){return this.targetNodeMap.push(ke(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(Oe).length===1}isCanClearWorkId(s){if(this.canClearUids===void 0||this.canClearUids===!0)return!0;if($d(this.canClearUids)){const e=s.split(Oe);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 df{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 en(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===ge?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:De(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===v.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===Mt.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===Ws.Full&&this.viewId===ge&&(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 ae.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 ae.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()}),Pe(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(),Re(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===Ws.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 ae.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=he(d.rect,u.rect),h=!0),d.drawCanvas&&d.drawCanvas===u.drawCanvas&&(d.rect=he(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(tt(u,d)){h=!0;break}h||e.push(u)}De(l.fullWorkerDrawCount)&&(t=l.fullWorkerDrawCount),De(l.subWorkerDrawCount)&&(i=l.subWorkerDrawCount),De(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 pf{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 vs({...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 gf(r){return r}var tn=gf;function ff(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 Mf=ff,yf=Mf,qi=Math.max;function mf(r,s,e){return s=qi(s===void 0?r.length-1:s,0),function(){for(var t=arguments,i=-1,o=qi(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),yf(r,this,a)}}var wf=mf;function If(r){return function(){return r}}var vf=If,Tf=vf,Ki=yo,Nf=tn,Sf=Ki?function(r,s){return Ki(r,"toString",{configurable:!0,enumerable:!1,value:Tf(s),writable:!0})}:Nf,Cf=Sf,kf=800,Df=16,xf=Date.now;function Lf(r){var s=0,e=0;return function(){var t=xf(),i=Df-(t-e);if(e=t,i>0){if(++s>=kf)return arguments[0]}else s=0;return r.apply(void 0,arguments)}}var bf=Lf,jf=Cf,Af=bf,zf=Af(jf),Pf=zf,Ef=tn,Of=wf,Rf=Pf;function Wf(r,s){return Rf(Of(r,s,Ef),r+"")}var Yf=Wf;function Uf(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 Bf=Uf;function Ff(r){return r!==r}var Qf=Ff;function Vf(r,s,e){for(var t=e-1,i=r.length;++t<i;)if(r[t]===s)return t;return-1}var Zf=Vf,Hf=Bf,Gf=Qf,$f=Zf;function Xf(r,s,e){return s===s?$f(r,s,e):Hf(r,Gf,e)}var Jf=Xf,qf=Jf;function Kf(r,s){var e=r==null?0:r.length;return!!e&&qf(r,s,0)>-1}var sn=Kf;function _f(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 on=_f;function eM(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 tM=eM,sM=oi,iM=sn,oM=on,nM=tM,rM=ms,aM=ni,cM=200;function lM(r,s,e,t){var i=-1,o=iM,n=!0,a=r.length,c=[],l=s.length;if(!a)return c;e&&(s=nM(s,rM(e))),t?(o=oM,n=!1):s.length>=cM&&(o=aM,n=!1,s=new sM(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 hM=lM,_i=Zt,uM=vo,dM=Ht,eo=_i?_i.isConcatSpreadable:void 0;function pM(r){return dM(r)||uM(r)||!!(eo&&r&&r[eo])}var gM=pM,fM=ti,MM=gM;function nn(r,s,e,t,i){var o=-1,n=r.length;for(e||(e=MM),i||(i=[]);++o<n;){var a=r[o];s>0&&e(a)?s>1?nn(a,s-1,e,t,i):fM(i,a):t||(i[i.length]=a)}return i}var yM=nn;function mM(){}var wM=mM,Ls=Ao,IM=wM,vM=ri,TM=1/0,NM=Ls&&1/vM(new Ls([,-0]))[1]==TM?function(r){return new Ls(r)}:IM,SM=NM,CM=oi,kM=sn,DM=on,xM=ni,LM=SM,bM=ri,jM=200;function AM(r,s,e){var t=-1,i=kM,o=r.length,n=!0,a=[],c=a;if(e)n=!1,i=DM;else if(o>=jM){var l=s?null:LM(r);if(l)return bM(l);n=!1,i=xM,c=new CM}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 zM=AM,PM=hM,EM=yM,to=zM;function OM(r,s,e){var t=r.length;if(t<2)return t?to(r[0]):[];for(var i=-1,o=Array(t);++i<t;)for(var n=r[i],a=-1;++a<t;)a!=i&&(o[i]=PM(o[i]||n,r[a],s,e));return to(EM(o,1),s,e)}var RM=OM,WM=qs,YM=Ke;function UM(r){return YM(r)&&WM(r)}var BM=UM,FM=ko,QM=Yf,VM=RM,ZM=BM;QM(function(r){return VM(FM(r,ZM))});class HM extends pf{constructor(e){super(e);M(this,"drawWorkActiveId")}async runFullWork(e){var o;const t=this.setFullWork(e),i=e.ops&&wt(e.ops);if(t){let n,a;const c=(o=t.getWorkId())==null?void 0:o.toString();return t.toolsType===v.Image?n=await t.consumeServiceAsync({isFullWork:!0,worker:this.thread}):t.toolsType===v.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()),he(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);Pe(this.fullLayer,this.fullLayer.parent)}canUseSubWorker(e){const t=this.thread.getPriorityDraw();return t||!t&&e!==v.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!==H&&(this.drawWorkActiveId=n);const c=a.toolsType;De(o)&&(this.consumeCount=o);const l=a.consume({data:e,drawCount:this.drawCount,isFullWork:!0,isSubWorker:!0,removeDrawCount:i});switch(c){case v.Selector:l&&(this.drawCount++,await this.drawSelector(l));break;case v.Ellipse:case v.Arrow:case v.Straight:case v.Rectangle:case v.Star:case v.Polygon:case v.SpeechBalloon:{l&&(this.drawCount++,await this.drawShape(l));break}case v.Pencil:case v.PencilEraser:case v.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 v.Selector:this.drawCount=0,Pe(this.fullLayer,this.fullLayer.parent),this.clearWorkShapeNodeCache(i),this._post({render:[{isClearAll:!0,clearCanvas:ye.Float,viewId:this.viewId}]});break;case v.Arrow:case v.Straight:case v.Ellipse:case v.Pencil:case v.Rectangle:case v.Star:case v.Polygon:case v.SpeechBalloon:case v.BitMapEraser:case v.PencilEraser:this.drawCount=0,Pe(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:ut(o),clearCanvas:ye.Float,isClear:!0,viewId:this.viewId},{rect:ut(o),drawCanvas:ye.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=he(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(),Re(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:ye.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)&&ut(e.rect),isClear:!0,clearCanvas:ye.Float,viewId:this.viewId},{rect:(e==null?void 0:e.rect)&&ut(e.rect),drawCanvas:ye.Float,viewId:this.viewId}]})}async drawSelector(e){await this._post({subWorkerDrawCount:this.drawCount,consumeCount:this.consumeCount,render:[{rect:(e==null?void 0:e.rect)&&ut(e.rect),isClear:!0,clearCanvas:ye.Float,viewId:this.viewId},{rect:(e==null?void 0:e.rect)&&ut(e.rect),drawCanvas:ye.Float,viewId:this.viewId}]})}}class GM{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===v.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===v.LaserPen)return vs({...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=he(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=he(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=wt(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 v.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=he(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:ye.TopFloat,viewId:this.viewId}),t.push({rect:h.totalRect,drawCanvas:ye.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 v.LaserPen:{if(p&&(i.push({isClear:!0,rect:p,clearCanvas:ye.TopFloat,viewId:this.viewId}),t.push({rect:p,drawCanvas:ye.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(Oe)[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 Ws=(r=>(r.Full="full",r.Sub="sub",r))(Ws||{});class $M extends df{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 HM(n),this.topLayerWork=new GM(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=oy(ke(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 ye.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===v.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===ge?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===ge?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()}),Pe(this.topLayer,this.topLayer.parent)),await this.post({render:[{isClearAll:!0,clearCanvas:ye.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:ye.Float,viewId:this.viewId}),t&&o.push({isClearAll:!0,clearCanvas:ye.TopFloat,viewId:this.viewId}),o.length&&await this.post({render:o})}async updateCamera(e){const t=[],{cameraOpt:i}=e;if(i&&!tt(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:ye.Float,viewId:this.viewId}),o){t.push({isClearAll:!0,clearCanvas:ye.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=ut({x:h.x,y:h.y,w:h.width,h:h.height});l=he(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=ke(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=he(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:ye.None},!0,o);n&&(this._post({sp:[{type:D.Snapshot,scenePath:t,imageBitmap:n,viewId:this.viewId}]},[n]),n.close(),this.snapshotFullLayer&&Pe(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=ke(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=he(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,Pe(this.snapshotFullLayer,this.snapshotFullLayer.parent),this.setCameraOpt(n,this.fullLayer)}}}class Qt extends Y{constructor(e){super(e);M(this,"canRotate",!0);M(this,"scaleType",re.all);M(this,"toolsType",v.Image);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"oldRect");this.workOptions=e.toolsOpt,this.scaleType=Qt.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 ae.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 ae.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 $M});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?re.proportional:re.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&&ke(n)||o.get(t.name);if(!f)return;const m=t.parent;if(m){if(p&&(f.opt.strokeColor=p),De(g)&&(t.setAttribute("zIndex",g),f.opt.zIndex=g),Nt(d)&&(f.opt.locked=d),c&&l&&u&&a){const{centerX:w,centerY:I,width:T,height:C,uniformScale:S}=f.opt,N=S!==!1?[u[0],u[0]]:u,x=[w,I],L=[w,I];li(L,l,N,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(T*N[0]),f.opt.height=Math.round(C*N[1]),f.opt.centerX=L[0],f.opt.centerY=L[1],f.opt.eraserlines)for(const E of Object.values(f.opt.eraserlines)){const{op:A,thickness:P}=E;E.thickness=P*Math.max(u[0],u[1]);for(let R=0;R<A.length;R++)hi(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 T=0;T<I.length;T++){const C=I[T].map((S,N)=>N%2?S+a[1]:S+a[0]);w.op[T]=C}}}else if(De(h))if(f.opt.rotate=h,f.scaleType=Qt.getScaleType(f.opt),n){const w=rn(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 he(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 ci(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 fe(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 Ys(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 ut(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 Vt(r,s){return{x:r.x+s[0],y:r.y+s[1],w:r.w,h:r.h}}function XM(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 rn(r,s){const e=XM(r,s);return fe(e)}function an(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 fe([l,u,h,d])}function JM(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 qM(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 li(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 hi(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 cn(r,s){return r[0]>=s.x&&r[0]<=s.x+s.w&&r[1]>=s.y&&r[1]<=s.y+s.h}function ln(r,s){const e=r<=s?1:r/s,t=s<=r?1:s/r;return[e,t]}function KM(r){for(const s of r)if(isNaN(s)||s===1/0||s===-1/0)return!1;return!0}function _M(r){return r!==Math.floor(r)}function ey(r){const s=r.toString();return s.indexOf(".")!==-1?s.split(".")[1].length:0}function ty(r,s){for(;s!==0;)[r,s]=[s,r%s];return r}const sy=r=>{if(r.tagName==="GROUP"){const s=Object.getOwnPropertySymbols(r).find(e=>e.toString()==="Symbol(sealed)");if(s&&r[s])return!0}return!1},Re=(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)Re(e,s)},Pe=(r,s)=>{Re(r,s),r.removeAllChildren()},iy=(r,s,e)=>{const t=e.parent;if(s){const i=s.children;if(i){for(const o of i)if(Re(o,t),o.tagName==="GROUP")for(const n of o.children)Re(n,t)}}s.parent.replaceChild(r,s)},oy=(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)),_M(e)){const n=ey(e),a=Math.pow(10,n),c=ty(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 It(r){return`${cs(r.x)},${cs(r.y)} `}function vt(r,s){return`${cs((r.x+s.x)/2)},${cs((r.y+s.y)/2)} `}function cs(r){return+r.toFixed(4)}const st=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()})},it=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)},ui=(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?ft.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?ft.inside:ft.intersect;function ny(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 ry{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 $.toJS((s=this.plugin)==null?void 0:s.attributes[this.namespace])||{}}getAuthSpaceData(){var s;return $.toJS((s=this.plugin)==null?void 0:s.attributes[this.authSpace])||{}}getUidFromKey(s){return s.split(Oe).length===2&&s.split(Oe)[0]||this.uid}isLocalId(s){return s.split(Oe).length===1}getLocalId(s){return s.split(Oe)[1]}isSelector(s){return this.getLocalId(s)===H}}const Ne=class Ne extends ry{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=Ne.componentsLimits.indexOf(o),f=p>=0&&p<Ne.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,T,C,S;(T=(I=(w=this.control.room)==null?void 0:w.callbacks)==null?void 0:I.listeners)!=null&&T.map.onKickedWithReason&&((S=(C=this.control.room)==null?void 0:C.callbacks)==null||S.dispatch("onKickedWithReason",N=>N("kickByAdmin")))});return}console.warn(`exceeds the limit of ${o} components, current: ${i}`);const m=f?Ne.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)});Ne.syncInterval=(i||Ne.syncInterval)*.5,this.namespace=Ne.namespace,this.authSpace=Ne.authSpace,this.serviceStorage=this.getNamespaceData(),this.storage=O.cloneDeep(this.serviceStorage),this.authStorage=this.getAuthSpaceData(),this.getLimitNums()}getLimitNum(e){return e>=Ne.componentsLimits[0]?Ne.componentsLimits[1]:Ne.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)===H))}addStorageStateListener(e){this.stateDisposer=$.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=Le(e),o=Le(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=Le(e),n=Le(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=Le(e),a=Le(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+Oe+e}isOwn(e){return e.split(Oe)[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:""})),st(()=>{var S;this.control.pluginManager.dispatchPluginEvent("syncStorage",f,p),(S=this.control.miniMapManager)==null||S.updateMiniMapCamera(f),this.clearLimitComponents(f,p)},Ne.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,N=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][S]||void 0;if(N!=null&&N.ops||(N==null?void 0:N.type)===D.FullWork)return;const x=n?((N==null?void 0:N.op)||[]).slice(0,n).concat(h):h||(N==null?void 0:N.op),L=c||(N==null?void 0:N.toolsType),b=a||(N==null?void 0:N.opt),E=u||(N==null?void 0:N.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(),{...N,type:D.DrawWork,workId:i,updateNodeOpt:E,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,N=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][S]||void 0,x=u||(N==null?void 0:N.updateNodeOpt),L=c||(N==null?void 0:N.toolsType),b=a||(N==null?void 0:N.opt),E=o||(N==null?void 0:N.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:E},{isSync:g,viewId:f,scenePath:p}),st(()=>{var A;this.control.pluginManager.dispatchPluginEvent("syncStorage",f,p),(A=this.control.miniMapManager)==null||A.updateMiniMapCamera(f),this.limitComponents(f,p)},Ne.syncInterval))}break;case D.RemoveNode:if(p&&(l!=null&&l.length)){const S=l.map(N=>this.isLocalId(N+"")?this.transformKey(N):N);this.storage[f]&&this.storage[f][p]&&(Object.keys(this.storage[f][p]).map(N=>{S!=null&&S.includes(N)&&(this.control.renderControl.isUsePageAuth(f)&&this.control.renderControl.delRenderPageElementId({viewId:f,scenePath:p,elementId:N}),this.updateValue(N,void 0,{isSync:g,viewId:f,scenePath:p}))}),st(()=>{var N;this.control.pluginManager.dispatchPluginEvent("syncStorage",f,p),(N=this.control.miniMapManager)==null||N.updateMiniMapCamera(f)},Ne.syncInterval))}break;case D.UpdateNode:if(p&&i&&(u||o||a)){const S=this.isLocalId(i.toString())?this.transformKey(i):i,N=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][S]||void 0;N&&(N.updateNodeOpt=u,(o||h)&&(N.ops=o,N.op=h),a&&(N.opt=a),N.type=D.FullWork,this.updateValue(S.toString(),N,{isSync:g,viewId:f,scenePath:p}),st(()=>{var x;(x=this.control.miniMapManager)==null||x.updateMiniMapCamera(f)},Ne.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(H),T=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][I]||void 0,C=a||(T==null?void 0:T.opt);w&&this.checkOtherSelector(I,w,{isSync:g,viewId:f,scenePath:p}),this.updateValue(I,w&&{type:D.Select,toolsType:v.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)===H){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=Le(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:Ne.syncInterval))}syncSerivice(e={storage:this.storage}){const{storage:t}=e,i=t||this.storage,o=Le(this.serviceStorage),n=Le(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=Le(this.serviceStorage[t]),o=Le(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=Le(this.serviceStorage[t][i]),n=Le(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(Oe);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,T,C,S,N,x,L,b,E,A,P,R,z,X,K,F,G,_,ce,ee,q,J,ue,ze,Te,V,le,ie,pe;const{operation:i,viewId:o,scenePath:n,pageId:a,pageData:c}=e;switch(i){case je.addPage:{if(!o||!n||!a)return;const de=[this.authSpace];Object.keys(this.authStorage).length&&de.push("pageAuth");const Me=this.authStorage.pageAuth||{};this.authStorage.pageAuth=Me,Object.keys(Me).length&&de.push(o),Me[o]=Me[o]||{},Object.keys(Me[o]).length&&de.push(n),Me[o][n]=Me[o][n]||{render:(c==null?void 0:c.render)||"localSelf",pages:{}},Object.keys(Me[o][n].pages).length&&de.push("pages",a);const ot={};if(c!=null&&c.elementIds)for(const nt of c.elementIds.keys())ot[nt]=!0;Me[o][n].pages[a]=ot,t&&(de.length===1?(l=this.plugin)==null||l.updateAttributes(de,O.cloneDeep(this.authStorage)):de.length===2?(u=this.plugin)==null||u.updateAttributes(de,O.cloneDeep(Me)):de.length===3?(h=this.plugin)==null||h.updateAttributes(de,O.cloneDeep(Me[o])):de.length===4?(d=this.plugin)==null||d.updateAttributes(de,O.cloneDeep(Me[o][n])):(g=this.plugin)==null||g.updateAttributes(de,O.cloneDeep(ot)));return}case je.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 je.deletePage:{if(!o||!n||!a)return;(T=(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&&T[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 je.clearPage:{if(!o||!n||!a)return;(b=(L=(x=(N=(S=this.authStorage)==null?void 0:S.pageAuth)==null?void 0:N[o])==null?void 0:x[n])==null?void 0:L.pages)!=null&&b[a]&&(delete this.authStorage.pageAuth[o][n].pages[a],t&&((E=this.plugin)==null||E.updateAttributes([this.authSpace,"pageAuth",o,n,"pages",a],{})));return}case je.addElement:{if(!o||!n||!a||!(c!=null&&c.elementId))return;(X=(z=(R=(P=(A=this.authStorage)==null?void 0:A.pageAuth)==null?void 0:P[o])==null?void 0:R[n])==null?void 0:z.pages)!=null&&X[a]&&(this.authStorage.pageAuth[o][n].pages[a][c.elementId]=!0,t&&((K=this.plugin)==null||K.updateAttributes([this.authSpace,"pageAuth",o,n,"pages",a,c.elementId],!0)));return}case je.deleteElement:{if(!o||!n||!a||!(c!=null&&c.elementId))return;(q=(ee=(ce=(_=(G=(F=this.authStorage)==null?void 0:F.pageAuth)==null?void 0:G[o])==null?void 0:_[n])==null?void 0:ce.pages)==null?void 0:ee[a])!=null&&q[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 je.clearViewScenePath:{if(!o||!n)return;(Te=(ze=(ue=this.authStorage)==null?void 0:ue.pageAuth)==null?void 0:ze[o])!=null&&Te[n]&&(delete this.authStorage.pageAuth[o][n],t&&((V=this.plugin)==null||V.updateAttributes([this.authSpace,"pageAuth",o,n],void 0)));return}case je.clearView:{if(!o)return;(ie=(le=this.authStorage)==null?void 0:le.pageAuth)!=null&&ie[o]&&(delete this.authStorage.pageAuth[o],t&&((pe=this.plugin)==null||pe.updateAttributes([this.authSpace,"pageAuth",o],void 0)));return}}}dispatchRenderAuth(e,t=!0){var l,u,h,d,g,p,f,m,w,I,T,C,S,N,x,L,b,E,A,P;const{operation:i,viewId:o,uid:n,renderData:a,isClear:c}=e;if(o)switch(i){case He.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:X,hide:K,clear:F}=a;if(X===!0)z[o].render=!0;else if(O.isSet(X)){z[o].render={};for(const G of X.keys())z[o].render[G]=!0}if(K===!0)z[o].hide=!0;else if(O.isSet(K)){z[o].hide={};for(const G of K.keys())z[o].hide[G]=!0}if(F===!0)z[o].clear=!0;else if(O.isSet(F)){z[o].clear={};for(const G of F.keys())z[o].clear[G]=!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 He.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 He.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&&((T=z[o].render)!=null&&T[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?(N=this.plugin)==null||N.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 He.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?(E=this.plugin)==null||E.updateAttributes(R,O.cloneDeep(z)):R.length===3?(A=this.plugin)==null||A.updateAttributes(R,O.cloneDeep(z[o])):(P=this.plugin)==null||P.updateAttributes(R,c?!0:void 0));return}}}addAuthStateListener(e){this.authDisposer=$.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=Le(e),o=Le(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=Le(e),o=Le(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(Ne,"namespace","PluginState"),M(Ne,"authSpace","PluginAuth"),M(Ne,"syncInterval",500),M(Ne,"componentsLimits",[500,1e3]);let Us=Ne;class ay{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 qe=(r=>(r[r.Text=1]="Text",r[r.Shape=2]="Shape",r))(qe||{});const Ee=class Ee{createProxy(s){const e=new Proxy(s,{get(t,i,o){const n=Ee.interceptors.hasOwnProperty(i)?Ee.interceptors:t;return Reflect.get(n,i,o)}});return Ee.proxyToRaw.set(e,s),e}};M(Ee,"proxyToRaw",new WeakMap),M(Ee,"interceptors",{entries(...s){return Ee.proxyToRaw.get(this).entries(...s)},forEach(...s){return Ee.proxyToRaw.get(this).forEach(...s)},size(){return Ee.proxyToRaw.get(this).size},get(s){return Ee.proxyToRaw.get(this).get(s)},set(s,e){return Ee.proxyToRaw.get(this).set(s,e)},delete(s,e){return Ee.proxyToRaw.get(this).delete(s)},clear(){return Ee.proxyToRaw.get(this).clear()}});let dt=Ee;class cy{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 dt;const n=this,a=dt.interceptors.set;dt.interceptors.set=function(l,u){return n.interceptors.set(l,u),a.call(this,l,u)};const c=dt.interceptors.delete;dt.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,T,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===v.Text&&(n&&(this.control.worker.queryTaskBatchData({workId:s,msgType:D.UpdateNode}).forEach(S=>{var N;(N=this.control.worker)==null||N.taskBatchData.delete(S)}),(T=this.control.worker)==null||T.taskBatchData.add({workId:s,msgType:D.UpdateNode,dataType:l||B.Local,toolsType:v.Text,opt:c,viewId:t,scenePath:i,willRefresh:!0}),(C=this.control.worker)==null||C.runAnimation()),o&&(st(()=>{var S;(S=this.collector)==null||S.dispatch({type:D.UpdateNode,workId:s,toolsType:v.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===qe.Text&&(o&&((m=this.collector)==null||m.dispatch({type:c.text&&D.FullWork||D.CreateWork,workId:s,toolsType:v.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:v.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:v.Text,msgType:D.RemoveNode,dataType:B.Local,viewId:t,scenePath:i,willRefresh:!0}),(c=this.control.worker)==null||c.runAnimation()),o&&st(()=>{var l;(l=this.collector)==null||l.dispatch({type:D.RemoveNode,removeIds:[s],toolsType:v.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:qe.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:qe.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 ly{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===Bt.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}${Oe}${e}`}getUidAndviewId(s){const[e,t]=s.split(Oe);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([se.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([se.Cursor,t],[])))}const n=this.doneRenderCursorInfoMap.get(t);O.isEqual(n,o)||(this.doneRenderCursorInfoMap.set(t,o),this.internalMsgEmitter.emit([se.Cursor,t],o))}else this.cursorInfoMap.delete(t),this.doneRenderCursorInfoMap.delete(t),this.internalMsgEmitter.emit([se.Cursor,t],[]);(this.willConsumeEventWorkers.size||this.cursorInfoMap.size)&&this.runAnimation()}sendEvent(s,e){if(this.displayer&&$.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&&$.isRoom(this.displayer)&&this.displayer.isWritable&&this.displayer.dispatchMagixEvent(this.eventName,{type:Bt.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&&$.isRoom(this.displayer)&&(this.willSendEventWorkers.length=0,this.displayer.dispatchMagixEvent(this.eventName,{type:Bt.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([se.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 Fe{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=Se.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){st(()=>{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=Se.InternalMsgEmitter)==null||s.emit(Q.ActiveMethod,!1)}}recover(){var s;this.useEmtMsg&&Se.InternalMsgEmitter.hasListeners(Q.ActiveMethod)&&((s=Se.InternalMsgEmitter)==null||s.emit(Q.ActiveMethod,!0))}}class hy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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===H){const p=g&&this.copySelector({viewId:i,store:g});p&&this.pasteSelector({...p,viewId:i,scenePath:n,undoTickerId:a});break}if(g.toolsType===v.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===v.Text&&o.opt){const I=o.opt;if(I&&I.boxPoint&&I.text){I.workState=j.Done;const T=I.boxPoint;I.boxPoint=[T[0]+g[0],T[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:qe.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,T,C,S,N,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())||((T=o.displayer.canvasContainerRef.current)==null?void 0:T.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=(N=this.serviceColloctor)==null?void 0:N.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,T]of t.entries()){const S=(this.serviceColloctor.isLocalId(I)?I:this.serviceColloctor.getLocalId(I.toString()))+"-"+a,N={useAnimation:!1};if(T.toolsType===v.Text&&T.opt){const L=T.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 E=this.control.viewContainerManager.transformToOriginPoint(L.boxPoint,o);this.control.textEditorManager.createTextForMasterController({workId:S,x:E[0],y:E[1],opt:L,scale:((m=c.cameraOpt)==null?void 0:m.scale)||1,type:qe.Text,isActive:!1,viewId:o,scenePath:n})}f.push({...T,opt:L,type:D.FullWork,workId:S,viewId:o,scenePath:n});continue}if(T.toolsType===v.Image&&(T.opt.uuid=S,T.opt.centerX=T.opt.centerX+g[0],T.opt.centerY=T.opt.centerY+g[1]),T.ops){const L=wt(T.ops).map((E,A)=>{const P=A%3;return P===0?E+g[0]:P===1?E+g[1]:E}),b=We(L);T.ops=b}const x=((w=T==null?void 0:T.opt)==null?void 0:w.eraserlines)??[];if(x.length)for(const L of Object.values(x)){const{op:b}=L;for(let E=0;E<b.length;E++){const A=b[E].map((P,R)=>R%2?P+g[1]:P+g[0]);L.op[E]=A}}f.push({...T,updateNodeOpt:N,type:D.FullWork,workId:S,viewId:o,scenePath:n}),p.push([{...T,updateNodeOpt:N,workId:S,msgType:D.FullWork,dataType:B.Local,emitEventType:Q.CopyNode,willSyncService:!1,willRefresh:!0,viewId:o},{workId:S,msgType:D.FullWork,emitEventType:Q.CopyNode}])}p.length&&this.collectForLocalWorker(p),f.length&&this.collectForServiceWorker(f)}}class uy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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,T;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(),N=this.serviceColloctor.isLocalId(S),x=N?this.serviceColloctor.transformKey(C):S;let L=S;!N&&this.serviceColloctor.isOwn(L)&&(L=this.serviceColloctor.getLocalId(L));const b=(T=(I=f==null?void 0:f[c])==null?void 0:I[g])==null?void 0:T[x];if(b){const E=b.updateNodeOpt||{};if(n||a){if(n){E.fontColor=n;const[P,R,z,X]=Ut(n);w.textColor=[P,R,z],w.textOpacity=X}if(a)if(E.fontBgColor=Jt(a)?"transparent":a,Jt(a))w.textBgColor=void 0,w.textBgOpacity=void 0;else{const[P,R,z,X]=Ut(a);w.textBgColor=[P,R,z],w.textBgOpacity=X}if(b.toolsType===v.Text&&b.opt&&l!==j.Start){this.setTextColor(L,ke(b),E,c),l===j.Done&&(this.undoTickerId=void 0);continue}}if(i){E.strokeColor=i;const[P,R,z,X]=Ut(i);w.strokeColor=[P,R,z],w.strokeOpacity=X}if(o)if(E.fillColor=Jt(o)?"transparent":o,Jt(o))w.fillColor=void 0,w.fillOpacity=void 0;else{const[P,R,z,X]=Ut(o);w.fillColor=[P,R,z],w.fillOpacity=X}u&&(E.thickness=u,w.strokeWidth=u),h&&(E.strokeType=h,w.strokeType=h);const A={workId:L,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:E,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 dy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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=ke(l[o][a][m]);let T;if(I&&w===H){if(I.selectIds){h.push(...I.selectIds),h.sort((x,L)=>{var A,P,R,z;const b=((P=(A=l[d(x,this.serviceColloctor)])==null?void 0:A.opt)==null?void 0:P.zIndex)||0,E=((z=(R=l[d(x,this.serviceColloctor)])==null?void 0:R.opt)==null?void 0:z.zIndex)||0;return b>E?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},N=new Map;i===Ft.Top?(this.addMaxLayer(o),T=this.getMaxZIndex(o)):(this.addMinLayer(o),T=this.getMinZIndex(o)),h.forEach(x=>{var A,P,R,z,X;const L=(A=this.serviceColloctor)==null?void 0:A.isLocalId(x);let b=L&&((P=this.serviceColloctor)==null?void 0:P.transformKey(x))||x;const E=(z=(R=l==null?void 0:l[o])==null?void 0:R[a])==null?void 0:z[b];E&&(!L&&((X=this.serviceColloctor)!=null&&X.isOwn(b))&&(b=this.serviceColloctor.getLocalId(b)),C.zIndex=T,E!=null&&E.opt&&(E.opt.zIndex=T),E!=null&&E.opt&&N.set(b,{updateNodeOpt:E.updateNodeOpt,opt:E.opt}))}),S.selectStore=N,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 py extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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(),T=this.serviceColloctor.isLocalId(I),C=T&&this.serviceColloctor.transformKey(w)||I;let S=I;!T&&this.serviceColloctor.isOwn(S)&&(S=this.serviceColloctor.getLocalId(S));const N=(m=(f=h==null?void 0:h[a])==null?void 0:f[l])==null?void 0:m[C];if(N&&S===H){if(N.selectIds){const x=this.control.viewContainerManager.transformToScenePoint([o.x,o.y],a);if(n===j.Start&&(this.cachePosition=x),this.cachePosition){const L=N.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 gy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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 T=f;if(!m&&this.serviceColloctor.isOwn(T)&&(T=this.serviceColloctor.getLocalId(T)),I.toolsType===v.Text){this.control.textEditorManager.delete(T,!0,!0);continue}u.push(T)}}u.length&&(l.push([{msgType:D.RemoveNode,emitEventType:Q.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 fy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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,T,C,S,N,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 E=b.toString(),A=this.serviceColloctor.isLocalId(E),P=A&&this.serviceColloctor.transformKey(b)||E;let R=E;!A&&this.serviceColloctor.isOwn(R)&&(R=this.serviceColloctor.getLocalId(R));const z=(C=(T=f==null?void 0:f[n])==null?void 0:T[g])==null?void 0:C[P];if(z&&R===H&&z.selectIds){const X=z.updateNodeOpt||{};if(X.dir=l,X.originPoint=a,X.scenePoint=c,X.workState=o,X.scale=u,X.translate=h,o===j.Start){this.cacheTextInfo.clear();for(const F of z.selectIds){const G=(S=this.serviceColloctor)==null?void 0:S.isLocalId(F),_=G&&((N=this.serviceColloctor)==null?void 0:N.transformKey(F))||F;let ce=_;!G&&((x=this.serviceColloctor)!=null&&x.isOwn(_))&&(ce=this.serviceColloctor.getLocalId(_));const ee=this.control.textEditorManager.get(ce);ee&&o===j.Start&&this.targetText.set(ce,ke(ee))}}if(this.targetText.size&&o!==j.Start&&u){const F=[];for(const[_,ce]of this.targetText.entries()){const{opt:ee}=ce,q=Math.floor(ee.fontSize*u[0]),J=this.cacheTextInfo.get(_),ue=!J&&ee.fontSize!==q||J&&J.fontSize!==q||!1,ze=(L=this.control.textEditorManager.get(_))==null?void 0:L.opt;if(ue&&ze&&ee.boxSize&&ee.boxPoint){const Te=this.setTextStyle(_,{...ze,fontSize:q},n);F.push(Te)}}const G=await Promise.all(F);for(const _ of G)if(_){const{key:ce,textInfo:ee}=_;this.cacheTextInfo.set(ce,{fontSize:ee.opt.fontSize,boxSize:ee.opt.boxSize,boxPoint:ee.opt.boxPoint})}X.textInfos=this.cacheTextInfo}const K={workId:b,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:X,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:n};o===j.Done&&(K.willSerializeData=!0,this.targetText.clear()),m.push([K,{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 My extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.RotateNode);M(this,"cacheOriginRotate",0)}collect(e,t){var p,f,m,w,I,T,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 N=S.toString(),x=this.serviceColloctor.isLocalId(N),L=x&&this.serviceColloctor.transformKey(S)||N;let b=N;!x&&this.serviceColloctor.isOwn(b)&&(b=this.serviceColloctor.getLocalId(b));const E=(m=(f=h==null?void 0:h[a])==null?void 0:f[l])==null?void 0:m[L];if(E&&b===H){if(((w=E.selectIds)==null?void 0:w.length)===1){const A=E.selectIds[0];if(n===j.Start){const X=((I=this.serviceColloctor)==null?void 0:I.isLocalId(A))&&((T=this.serviceColloctor)==null?void 0:T.transformKey(A))||A,K=h[a][l][X];this.cacheOriginRotate=((C=K==null?void 0:K.opt)==null?void 0:C.rotate)||0}const P=E.updateNodeOpt||{};P.angle=(o+this.cacheOriginRotate)%360,P.workState=n;const R={workId:S,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:P,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 yy(r){switch(r){case v.Text:return qe.Text;case v.SpeechBalloon:case v.Star:case v.Ellipse:case v.Rectangle:case v.Triangle:case v.Rhombus:case v.Polygon:return qe.Shape}}class my extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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&&yy(t.toolsType)===qe.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,T,C,S,N,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(),E=this.serviceColloctor.isLocalId(b),A=E?this.serviceColloctor.transformKey(L):b;let P=b;!E&&this.serviceColloctor.isOwn(P)&&(P=this.serviceColloctor.getLocalId(P));const R=(T=(I=g==null?void 0:g[c])==null?void 0:I[h])==null?void 0:T[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===v.Text&&R.opt){const X=this.setTextStyle(P,O.cloneDeep(R),z,c);m.push(X);continue}if(R&&P===H&&((C=R.selectIds)!=null&&C.length))for(const X of R.selectIds){const K=(S=this.serviceColloctor)==null?void 0:S.isLocalId(X);let F=K&&((N=this.serviceColloctor)==null?void 0:N.transformKey(X))||X;const G=g[c][h][F]||void 0;if(!K&&((x=this.serviceColloctor)!=null&&x.isOwn(F))&&(F=this.serviceColloctor.getLocalId(F)),G&&G.toolsType===v.Text&&R.opt){const _=this.setTextStyle(F,O.cloneDeep(G),z,c);m.push(_);continue}}}}const w=await Promise.all(m);for(const L of w)if(L){const{key:b,textInfo:E}=L;E&&(E.canSync=!0,E.canWorker=!0,this.control.textEditorManager.updateForViewEdited(b,E))}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 wy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.SetPoint);M(this,"undoTickerId")}collect(e){var I,T,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=(T=l==null?void 0:l[n])==null?void 0:T[c])==null?void 0:C[f];if(w&&m===H&&w.selectIds){const S=w.updateNodeOpt||{};S.pointMap=i,S.workState=o;const N={workId:d,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:S,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:n};o===j.Done&&(N.undoTickerId=this.undoTickerId),u.push([N,{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 Iy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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 T=(g=(d=l==null?void 0:l[o])==null?void 0:d[a])==null?void 0:g[w];if(T){const C=T.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 vy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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 T=(g=(d=l==null?void 0:l[i])==null?void 0:d[a])==null?void 0:g[w];if(T){const C={...T.updateNodeOpt,...o,willRefresh:!0};if(T&&I===H){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 ne{constructor(s){M(this,"builders",new Map);this.builders=new Map(s.map(e=>[e,this.build(e)]))}build(s){switch(s){case Q.TranslateNode:return new py;case Q.ZIndexNode:return new dy;case Q.CopyNode:return new hy;case Q.SetColorNode:return new uy;case Q.DeleteNode:return new gy;case Q.ScaleNode:return new fy;case Q.RotateNode:return new My;case Q.SetFontStyle:return new my;case Q.SetPoint:return new wy;case Q.SetLock:return new Iy;case Q.SetShapeOpt:return new vy}}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){Fe.dispatch(s,e,t)}static activeListener(s){Se.InternalMsgEmitter.on(Q.ActiveMethod,s)}static unmountActiveListener(s){Se.InternalMsgEmitter.off(Q.ActiveMethod,s)}}class Ty{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 Ny(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 Ny{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===ge?i:o,contextType:"2d"});const n={thread:this};this.subLocalWork=new Sy(n)}createScene(s){return new ae.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 ae.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()}),Pe(this.subLocalLayer,this.subLocalLayer.parent)),this.subLocalWork.clearAll()}destroy(){this.subLocalLayer.remove(),Re(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(),Re(t,this.subLocalLayer.parent)}}class Sy{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,Pe(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(){Pe(this.thread.subLocalLayer,this.thread.subLocalLayer.parent),this.workShapes.clear()}canUseSubWorkerLayer(s){return s===v.Pencil}setToolsOpt(s){var e;this.tmpOpt=s,(e=s.toolsOpt)!=null&&e.syncUnitTime&&(this.syncUnitTime=s.toolsOpt.syncUnitTime)}createWorkShapeNode(s){return vs({...s,fullLayer:this.thread.subLocalLayer,drawLayer:this.thread.subLocalLayer})}clearWorkShapeNodeCache(s){this.workShapes.delete(s)}getWorkShape(s){return this.workShapes.get(s)}}const Cy=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 ky{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 Dy extends ky{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===v.Pencil||e===v.PencilEraser||e===v.BitMapEraser||e===v.LaserPen||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Selector}get isCanDrawWork(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.LaserPen||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Triangle||e===v.Rhombus||e===v.BitMapEraser||e===v.PencilEraser}get isUseZIndex(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Text||e===v.Image}get isCanRecordUndoRedo(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.Eraser||e===v.PencilEraser||e===v.BitMapEraser||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Text||e===v.Image}get isCanSentCursor(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.Text||e===v.LaserPen||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Triangle||e===v.Rhombus||e===v.Eraser||e===v.PencilEraser||e===v.BitMapEraser||e===v.Selector}get isPostCountType(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Triangle||e===v.Rhombus||e===v.Eraser||e===v.PencilEraser||e===v.BitMapEraser||e===v.Selector}get isCanPostDraw(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.PencilEraser||e===v.BitMapEraser}get isCanStartEventConsum(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Selector||e===v.Eraser||e===v.PencilEraser||e===v.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-CRvrJ44z.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 Ty(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:T,rect:C,op:S,canTextEdit:N,points:x,selectorColor:L,canRotate:b,scaleType:E,textOpt:A,toolsType:P,workId:R,viewId:z,dataType:X,canLock:K,isLocked:F,shapeOpt:G,toolsTypes:_,thickness:ce,strokeType:ee,useStroke:q,isgl:J,imageSrc:ue,isSubWorker:ze}=c;if(!z)return;const Te=c.scenePath||this.viewContainerManager.getCurScenePath(z);switch(l){case D.Select:{const V=u!=null&&u.length?{...d,selectIds:u,canvasHeight:I,canvasWidth:T,points:x}:void 0;V&&(h!=null&&h.strokeColor)&&(V.selectorColor=h.strokeColor),V&&L&&(V.selectorColor=L),V&&g&&(V.strokeColor=g),V&&(h!=null&&h.fillColor)&&(V.fillColor=h.fillColor),V&&p&&(V.fillColor=p),V&&O.isBoolean(b)&&(V.canRotate=b),V&&E&&(V.scaleType=E),V&&N&&(V.canTextEdit=N),V&&A&&(V.textOpt=A),V&&O.isBoolean(K)&&(V.canLock=K),V&&O.isBoolean(F)&&(V.isLocked=F),V&&G&&(V.shapeOpt=G),V&&_&&(V.toolsTypes=_),V&&ce&&(V.thickness=ce),V&&ee&&(V.strokeType=ee),V&&O.isBoolean(q)&&(V.useStroke=q),z&&this.viewContainerManager.showFloatBar(z,!!V,V),f&&((i=this.collector)==null||i.dispatch({type:l,selectIds:u,opt:h,isSync:m,viewId:z,scenePath:Te}));break}case D.Snapshot:if(w&&Te){const V=this.snapshotMap.get(Te);V&&V(w)}break;case D.BoundingBox:if(C&&Te){const V=this.boundingRectMap.get(Te);V&&V(C)}break;case D.Cursor:S&&this.control.cursor.collectServiceCursor({...c});break;case D.Clear:if(z){this.viewContainerManager.showFloatBar(z,!1);const V=(o=this.clearAllResolveMap.get(z))==null?void 0:o.resolve;V&&V(z)}break;case D.TextUpdate:if(P===v.Text&&R&&z){const V=this.viewContainerManager.transformToOriginPoint((h==null?void 0:h.boxPoint)||[0,0],z),le=(h==null?void 0:h.boxSize)||[0,0],ie=(n=this.viewContainerManager.getView(z))==null?void 0:n.cameraOpt;h?this.control.textEditorManager.updateTextForWorker({x:V[0],y:V[1],w:le[0],h:le[1],scale:(ie==null?void 0:ie.scale)||1,workId:R,opt:h,dataType:X,viewId:z,canSync:f||!1,canWorker:!1}):this.control.textEditorManager.delete(R,f||!1,!1)}break;case D.GetTextActive:P===v.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:ue&&z&&R&&Cy({src:ue,isgl:J}).then(V=>{var ie;const le=new Set;if(le.add({msgType:D.GetImageBitMap,dataType:B.Local,workId:R,viewId:z,imageSrc:ue,isSubWorker:ze,imageBitmap:V}),!this.control.hasOffscreenCanvas())(ie=this.mainThread)==null||ie.consume(le);else{const pe=ze?this.subWorker:this.fullWorker;V?pe.postMessage(le,[V]):pe.postMessage(le)}});break;case D.GetVNodeInfo:if(R){const V=R.toString(),le=(a=this.getVNodeInfoResolveMap.get(V))==null?void 0:a.resolve,ie={...c,uuid:V};le&&le(ie)}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:T,nextTasks:C}=a;if(!I){console.error("collectorAsyncData",a);return}const S=a.scenePath||this.viewContainerManager.getCurScenePath(I);switch(c){case D.None:{T&&st(()=>{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)===v.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:qe.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)===v.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===v.Selector?H: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!==v.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)===v.Selector;switch((u=this.currentToolsData)==null?void 0:u.toolsType){case v.Eraser:case v.PencilEraser:case v.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(st(()=>{this.control.pluginManager.dispatchPluginEvent("localEvent",i,e,t)},ai),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:Kt}),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}),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,T;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))===H){this.collector.isOwn(l)?this.blurSelector(n,a):this.blurSelector(n,a,l);return}if(u=D.RemoveNode,o.toolsType===v.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===v.LaserPen&&(C.isRunSubWork=!0),C.dataType=B.Service,C.viewId=n,C.scenePath=a,C.selectIds&&(C.selectIds=C.selectIds.map(S=>{var N,x;return(N=this.collector)!=null&&N.isOwn(S)?(x=this.collector)==null?void 0:x.getLocalId(S):S})),C&&C.toolsType===v.Text||(o==null?void 0:o.toolsType)===v.Text){this.control.textEditorManager.onServiceDerive(C);return}this.taskBatchData.add(C)}this.runAnimation();const d=t.newValue&&((T=t.newValue.opt)==null?void 0:T.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(T=>{var C,S;return(C=this.collector)!=null&&C.isOwn(T)?(S=this.collector)==null?void 0:S.getLocalId(T):T})),I.toolsType===v.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),this.localPointsBatchData.clear(),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 ne([Q.CopyNode,Q.SetColorNode,Q.DeleteNode,Q.RotateNode,Q.ScaleNode,Q.TranslateNode,Q.ZIndexNode,Q.SetFontStyle,Q.SetPoint,Q.SetLock,Q.SetShapeOpt]).registerForMainEngine(se.MainEngine,this.control),this.zIndexNodeMethod=(e=this.methodBuilder)==null?void 0:e.getBuilder(Q.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)===v.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(cn(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)!==v.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===v.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 v.Eraser:case v.PencilEraser:case v.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))===H&&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))===H&&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();Se.InternalMsgEmitter.emit("addUndoTicker",c,e);const l={...t,type:Mt.Iconify};this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayer(e),l.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),this.taskBatchData.add({msgType:D.FullWork,dataType:B.Local,toolsType:v.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();Se.InternalMsgEmitter.emit("addUndoTicker",c,e);const l={...t,type:Mt.Image};this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayer(e),l.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),this.taskBatchData.add({msgType:D.FullWork,dataType:B.Local,toolsType:v.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===v.Image&&h.opt.uuid===t){const d=Date.now();Se.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:Mt.Image};this.taskBatchData.add({msgType:D.FullWork,dataType:B.Local,toolsType:v.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===v.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:H,selectIds:[e],msgType:D.Select,dataType:B.Local,viewId:t,willSyncService:!0}),this.runAnimation()}blurSelector(e,t,i){this.taskBatchData.add({workId:i||H,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:Kt,dataType:B.Local,isRunSubWork:!0})),e==="ui"){t.add({msgType:D.PriorityMainThreadWorker,viewId:Kt,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 xy=Ge,Ly=function(){return xy.Date.now()},by=Ly,jy=/\s/;function Ay(r){for(var s=r.length;s--&&jy.test(r.charAt(s)););return s}var zy=Ay,Py=zy,Ey=/^\s+/;function Oy(r){return r&&r.slice(0,Py(r)+1).replace(Ey,"")}var Ry=Oy,Wy=yt,Yy=Ke,Uy="[object Symbol]";function By(r){return typeof r=="symbol"||Yy(r)&&Wy(r)==Uy}var Fy=By,Qy=Ry,so=lt,Vy=Fy,io=NaN,Zy=/^[-+]0x[0-9a-f]+$/i,Hy=/^0b[01]+$/i,Gy=/^0o[0-7]+$/i,$y=parseInt;function Xy(r){if(typeof r=="number")return r;if(Vy(r))return io;if(so(r)){var s=typeof r.valueOf=="function"?r.valueOf():r;r=so(s)?s+"":s}if(typeof r!="string")return r===0?r:+r;r=Qy(r);var e=Hy.test(r);return e||Gy.test(r)?$y(r.slice(2),e?2:8):Zy.test(r)?io:+r}var Jy=Xy,qy=lt,bs=by,oo=Jy,Ky="Expected a function",_y=Math.max,em=Math.min;function tm(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(Ky);s=oo(s)||0,qy(e)&&(u=!!e.leading,h="maxWait"in e,o=h?_y(oo(e.maxWait)||0,s):o,d="trailing"in e?!!e.trailing:d);function g(N){var x=t,L=i;return t=i=void 0,l=N,n=r.apply(L,x),n}function p(N){return l=N,a=setTimeout(w,s),u?g(N):n}function f(N){var x=N-c,L=N-l,b=s-x;return h?em(b,o-L):b}function m(N){var x=N-c,L=N-l;return c===void 0||x>=s||x<0||h&&L>=o}function w(){var N=bs();if(m(N))return I(N);a=setTimeout(w,f(N))}function I(N){return a=void 0,d&&t?g(N):(t=i=void 0,n)}function T(){a!==void 0&&clearTimeout(a),l=0,t=c=i=a=void 0}function C(){return a===void 0?n:I(bs())}function S(){var N=bs(),x=m(N);if(t=arguments,i=this,c=N,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=T,S.flush=C,S}var sm=tm,im=sm,om=lt,nm="Expected a function";function rm(r,s,e){var t=!0,i=!0;if(typeof r!="function")throw new TypeError(nm);return om(e)&&(t="leading"in e?!!e.leading:t,i="trailing"in e?!!e.trailing:i),im(r,s,{leading:t,maxWait:s,trailing:i})}var am=rm;const hn=jt(am);class cm{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)===v.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))&&ne.emitMethod(se.MainEngine,Q.DeleteNode,{workIds:[H],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:oe.pencil,useNewPencil:!0});break;case"changeToArrow":this.setMemberState({currentApplianceName:oe.arrow});break;case"changeToClick":this.setMemberState({currentApplianceName:oe.clicker});break;case"changeToEllipse":this.setMemberState({currentApplianceName:oe.ellipse});break;case"changeToEraser":this.setMemberState({currentApplianceName:oe.eraser,isLine:!0});break;case"changeToHand":this.setMemberState({currentApplianceName:oe.hand});break;case"changeToLaserPointer":this.setMemberState({currentApplianceName:oe.laserPointer});break;case"changeToSelector":this.setMemberState({currentApplianceName:oe.selector});break;case"changeToRectangle":this.setMemberState({currentApplianceName:oe.rectangle});break;case"changeToStraight":this.setMemberState({currentApplianceName:oe.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:oe.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(Q.CopyNode);if(!t||!this.collector||!i)return;const o=this.collector.transformKey(H),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(Q.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 lm{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:je.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:je.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:je.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:je.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:je.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:je.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:je.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:He.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=He.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=He.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:He.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:He.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 hm{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=ci(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 un{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 um{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 pt=class pt{constructor(s){M(this,"version",Yo);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($.toJS(s))});M(this,"onMemberChange",hn(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===v.Selector&&e!==v.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=$.isRoom(e)?e:void 0,this.play=$.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=Wi!=="worker",this.roomMember=new ay;const o={control:this,internalMsgEmitter:pt.InternalMsgEmitter,publicMsgEmitter:pt.PublicMsgEmitter};this.cursor=new ly(o),this.textEditorManager=new cy(o),this.worker=new Dy(o),this.hotkeyManager=new cm(o),this.renderControl=new lm(o),this.miniMapManager=new hm(o),this.pluginManager=new um(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:Wi==="worker"}bindPlugin(s){var e,t;this.plugin=s,this.collector&&(this.collector.removeStorageStateListener(),this.collector.removeAuthStateListener()),this.collector=new Us(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&&(pt.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)===v.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 oe.text:return s.textCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),v.Text;case oe.pencil:return s.useLaserPen?v.LaserPen:v.Pencil;case oe.eraser:return v.Eraser;case oe.pencilEraser:return((t=this.pluginOptions.pencilEraser)==null?void 0:t.useBitMap)===!1?v.PencilEraser:v.BitMapEraser;case oe.selector:return v.Selector;case oe.arrow:return s.arrowCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),v.Arrow;case oe.straight:return s.straightCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),v.Straight;case oe.ellipse:return s.ellipseCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),v.Ellipse;case oe.rectangle:return s.rectangleCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),v.Rectangle;case oe.shape:if(s.shapeCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),s.shapeType===Ve.Pentagram||s.shapeType===Ve.Star)return v.Star;if(s.shapeType===Ve.Polygon||s.shapeType===Ve.Triangle||s.shapeType===Ve.Rhombus)return v.Polygon;if(s.shapeType===Ve.SpeechBalloon)return v.SpeechBalloon;break}return v.Clicker}getToolsOpt(s,e){if(s===v.Clicker)return{toolsType:s,toolsOpt:{}};const t={strokeColor:at(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 v.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)&&at(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)&&at(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 v.Pencil:t.strokeType=(e==null?void 0:e.strokeType)||te.Normal;break;case v.PencilEraser:case v.BitMapEraser:case v.Eraser:t.thickness=Math.min(4,Math.max(1,Math.floor(e.pencilEraserSize||1)))-1,(s===v.BitMapEraser||s===v.PencilEraser)&&(t.eraserColor=e.eraserColor&&at(e.eraserColor[0],e.eraserColor[1],e.eraserColor[2],e.eraserOpacity||.3)||"rgba(136,136,136,0.3)");break;case v.LaserPen:t.duration=(e==null?void 0:e.duration)||1,e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===te.Stroke?t.strokeType=te.Normal:t.strokeType=(e==null?void 0:e.strokeType)||te.Normal;break;case v.Arrow:case v.Straight:e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===te.Stroke?t.strokeType=te.Normal:t.strokeType=(e==null?void 0:e.strokeType)||te.Normal;break;case v.Ellipse:case v.Rectangle:case v.Star:case v.Polygon:case v.SpeechBalloon:e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===te.Stroke?t.strokeType=te.Normal:t.strokeType=(e==null?void 0:e.strokeType)||te.Normal,s===v.Star&&(e.shapeType===Ve.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===v.Polygon&&(e.shapeType===Ve.Triangle?t.vertices=3:e.shapeType===Ve.Rhombus?t.vertices=4:e.vertices&&(t.vertices=e.vertices)),t.fillColor=(e==null?void 0:e.fillColor)&&at(e.fillColor[0],e.fillColor[1],e.fillColor[2],e==null?void 0:e.fillOpacity)||"transparent",s===v.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!==v.Text&&this.viewContainerManager.focuedViewId&&this.viewContainerManager.unActiveTextEditor(this.viewContainerManager.focuedViewId),s){case v.Text:case v.Pencil:case v.LaserPen:case v.Arrow:case v.Straight:case v.Rectangle:case v.Ellipse:case v.Star:case v.Polygon:case v.SpeechBalloon:case v.Triangle:case v.Rhombus:case v.Eraser:case v.PencilEraser:case v.BitMapEraser:case v.Selector:this.room.disableDeviceInputs=!0,(i=this.worker)==null||i.abled(),s===v.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:oe.text})}switchToSelector(){var s;(s=this.room)==null||s.setMemberState({currentApplianceName:oe.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=at(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(pt,"InternalMsgEmitter",new As),M(pt,"PublicMsgEmitter",new As);let Se=pt;const gt=class gt{constructor(s){M(this,"emitter",new As);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)}},gt.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(H);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>gt.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))===H&&!((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))===H&&!((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,T,C,S,N,x,L,b,E,A;let t;const{scenePath:i}=s,o=s.data;if(!o||!this.collector)return;const n=O.cloneDeep(this.collector.storage);for(const P of o.values()){const{dataType:R,data:z,key:X}=P,K=this.collector.getStorageData(this.viewId,i),F=K&&Object.keys(K)||[];switch(R){case 1:if(t=e?this.isDrawEffectiveScene(P,F):this.isDeleteEffectiveScene(P,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(X))===H&&((l=this.collector)!=null&&l.isOwn(P.key))){const G=z.selectIds;if(G){const _=F.filter(ee=>{var q,J;return((q=this.collector)==null?void 0:q.getLocalId(ee))===H&&!((J=this.collector)!=null&&J.isOwn(ee))}).map(ee=>{var q;return(q=this.collector)==null?void 0:q.storage[this.viewId][i][ee]});let ce=!1;for(const ee of _)for(let q=0;q<G.length;q++)(u=ee==null?void 0:ee.selectIds)!=null&&u.includes(G[q])&&(delete G[q],ce=!0);ce&&(z.selectIds=G.filter(ee=>!!ee))}}(h=this.collector)==null||h.updateValue(P.key,z,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}else!e&&!Array.isArray(P.data)&&((d=this.collector)==null||d.updateValue(P.key,void 0,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n}));break;case 2:if(t=e?this.isDeleteEffectiveScene(P,F,i):this.isDrawEffectiveScene(P,F),t){if(e&&!Array.isArray(z))(g=this.collector)==null||g.updateValue(X,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(P.key))===H&&((m=this.collector)!=null&&m.isOwn(P.key))){const G=z.selectIds;if(G){const _=F.filter(ee=>{var q,J;return((q=this.collector)==null?void 0:q.getLocalId(ee))===H&&!((J=this.collector)!=null&&J.isOwn(ee))}).map(ee=>{var q;return(q=this.collector)==null?void 0:q.storage[this.viewId][i][ee]});let ce=!1;for(const ee of _)for(let q=0;q<G.length;q++)(w=ee==null?void 0:ee.selectIds)!=null&&w.includes(G[q])&&(delete G[q],ce=!0);ce&&(z.selectIds=G.filter(ee=>!!ee))}}(I=this.collector)==null||I.updateValue(P.key,P.data,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}}break;case 3:if(t=e?this.isNewEffectiveScene(P,F):this.isOldEffectiveScene(P,F,i),t){if(e&&Array.isArray(z)&&z.length===2){const G=z[1];if((T=G.updateNodeOpt)!=null&&T.useAnimation&&(G.updateNodeOpt.useAnimation=!1),((C=this.collector)==null?void 0:C.getLocalId(P.key))===H&&((S=this.collector)!=null&&S.isOwn(P.key))){const _=G.selectIds;if(_){const ce=F.filter(q=>{var J,ue;return((J=this.collector)==null?void 0:J.getLocalId(q))===H&&!((ue=this.collector)!=null&&ue.isOwn(q))}).map(q=>{var J;return(J=this.collector)==null?void 0:J.storage[this.viewId][i][q]});let ee=!1;for(const q of ce)for(let J=0;J<_.length;J++)q!=null&&q.selectIds&&((N=q.selectIds)!=null&&N.includes(_[J]))&&(delete _[J],ee=!0);ee&&(G.selectIds=_.filter(q=>!!q))}}(x=this.collector)==null||x.updateValue(X,G,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}else if(!e&&Array.isArray(z)&&z.length===2){const G=z[0];if((L=G.updateNodeOpt)!=null&&L.useAnimation&&(G.updateNodeOpt.useAnimation=!1),((b=this.collector)==null?void 0:b.getLocalId(P.key))===H&&((E=this.collector)!=null&&E.isOwn(P.key))){const _=G.selectIds;if(_){const ce=F.filter(q=>{var J,ue;return((J=this.collector)==null?void 0:J.getLocalId(q))===H&&!((ue=this.collector)!=null&&ue.isOwn(q))}).map(q=>{var J;return(J=this.collector)==null?void 0:J.storage[this.viewId][i][q]});let ee=!1;for(const q of ce)for(let J=0;J<_.length;J++)q!=null&&q.selectIds&&q.selectIds.includes(_[J])&&(delete _[J],ee=!0);ee&&(G.selectIds=_.filter(q=>!!q))}}(A=this.collector)==null||A.updateValue(P.key,G,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}}break}}}};M(gt,"sdkCallBack"),M(gt,"MaxStackLength",20),M(gt,"waitTime",100);let ls=gt;function dm(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 xt(r){return dm(r)&&(r.touches&&r.touches.length===1||r.changedTouches&&r.changedTouches.length===1)}function dn(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 Lt{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!==ge&&this.appViews.has(s)}getView(s){var e;return s===ge?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===ge&&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===ge&&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===ge?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===v.Text&&this.activeTextEditor(s),this.control.cursor.onFocusViewChange(),this.focuedView&&this.focuedView.displayer.commiter.onFocusView()}setViewFocusScenePath(s,e){var i;let t;s===ge?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(ge),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 T of s){const{rect:C,imageBitmap:S,isClear:N,isUnClose:x,drawCanvas:L,clearCanvas:b,viewId:E}=T,A=(e=this.getView(E))==null?void 0:e.displayer;if(A&&C){const{dpr:P,canvasBgRef:R,canvasFloatRef:z,canvasServiceFloatRef:X,canvasTopRef:K}=A,F=Math.floor(C.w*P),G=Math.floor(C.h*P),_=C.x*P,ce=C.y*P;if(N){switch(b){case ye.TopFloat:(i=(t=K.current)==null?void 0:t.getContext("2d"))==null||i.clearRect(_,ce,F,G);break;case ye.Float:(n=(o=z.current)==null?void 0:o.getContext("2d"))==null||n.clearRect(_,ce,F,G);break;case ye.ServiceFloat:(c=(a=X.current)==null?void 0:a.getContext("2d"))==null||c.clearRect(_,ce,F,G);break;case ye.Bg:(u=(l=R.current)==null?void 0:l.getContext("2d"))==null||u.clearRect(_,ce,F,G);break}continue}if(L&&S)switch(L){case ye.TopFloat:(d=(h=K.current)==null?void 0:h.getContext("2d"))==null||d.drawImage(S,0,0,F,G,_,ce,F,G);break;case ye.Float:{(p=(g=z.current)==null?void 0:g.getContext("2d"))==null||p.drawImage(S,0,0,F,G,_,ce,F,G);break}case ye.ServiceFloat:{(m=(f=X.current)==null?void 0:f.getContext("2d"))==null||m.drawImage(S,0,0,F,G,_,ce,F,G);break}case ye.Bg:{(I=(w=R.current)==null?void 0:w.getContext("2d"))==null||I.drawImage(S,0,0,F,G,_,ce,F,G);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(Lt,"defaultCameraOpt",{centerX:0,centerY:0,scale:1}),M(Lt,"defaultScreenCanvasOpt",{autoRender:!1,contextType:"webgl2"}),M(Lt,"defaultLayerOpt",{offscreen:!0,handleEvent:!1,depth:!1});class pm{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(!xt(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(!xt(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(!xt(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 ls(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 v.Text:case v.Pencil:case v.LaserPen:case v.Arrow:case v.Straight:case v.Rectangle:case v.Ellipse:case v.Star:case v.Polygon:case v.SpeechBalloon:case v.Eraser:case v.PencilEraser:case v.BitMapEraser:case v.Selector:this.eventTragetElement&&(this.eventTragetElement.className=`netless-whiteboard ${s===v.Selector?"cursor-selector":s===v.Text?"cursor-text":s===v.Eraser||s===v.PencilEraser||s===v.BitMapEraser?"cursor-eraser":s===v.Pencil||s===v.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([se.Cursor,this.viewId])}getPoint(s){const e=dn(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",ds.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 pn{constructor(s,e){M(this,"viewId",ge);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(!xt(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(!xt(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(!xt(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 ls(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 v.Text:case v.Pencil:case v.LaserPen:case v.Arrow:case v.Straight:case v.Rectangle:case v.Ellipse:case v.Star:case v.Polygon:case v.SpeechBalloon:case v.Eraser:case v.PencilEraser:case v.BitMapEraser:case v.Selector:this.eventTragetElement&&(this.eventTragetElement.className=e&&t?`netless-whiteboard ${s===v.Selector?"cursor-selector":s===v.Text?"cursor-text":s===v.Eraser||s===v.PencilEraser||s===v.BitMapEraser?"cursor-eraser":s===v.Pencil||s===v.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([se.Cursor,this.viewId])}getPoint(s){const e=dn(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===v.Pencil&&this.control.pluginOptions.bezier&&s>this.control.pluginOptions.bezier.maxDrawCount?(this.stopEventHandler().finally(()=>{this.worker.publicMsgEmitter.emit("forceStop",ds.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 gm="index-module__Container__nLsM3",fm="index-module__CanvasBox__j2Xe-",Mm="index-module__FloatCanvas__d1YR7",ym="index-module__TopFloatCanvas__7IaCw",mm="index-module__CanvasBoxSub__hcMeK",wm="index-module__SnapshotBox__--eeE",Im="index-module__FloatBar__cm-EL",vm="index-module__RotateBtn__HSSkf",Tm="index-module__ResizeBtn__yjvda",Nm="index-module__CursorBox__2UHvI",Sm="index-module__TextEditorContainer__Qm8KC",Cm="index-module__ResizeTowBox__HOllX",km="index-module__FloatBarBtn__FJrOG",be={Container:gm,CanvasBox:fm,FloatCanvas:Mm,TopFloatCanvas:ym,CanvasBoxSub:mm,SnapshotBox:wm,FloatBar:Im,RotateBtn:vm,ResizeBtn:Tm,CursorBox:Nm,TextEditorContainer:Sm,ResizeTowBox:Cm,FloatBarBtn:km},Dm={delete:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIH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yIDcuMTAzIDcuMTAzIDAgMCAwIDEuNzY2IDQuODE1bDEuOTQ1LTEuNTg0IDIuMzk0IDcuMTgyLTcuMjIyLTIuNDA4IDEuNzkxLTEuNzlBOC44NDYgOC44NDYgMCAwIDEgMy4xMjUgMTJjMC0yLjI3MS44NjYtNC41NDMgMi42LTYuMjc2eiIgc3Ryb2tlPSIjRkZGIiBzdHJva2Utd2lkdGg9Ii41IiBmaWxsPSIjMDAwIiBmaWxsLXJ1bGU9Im5vbnplcm8iLz48L2c+PC9zdmc+","font-colors-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0ibTQgMTEgNC05IDQgOU02IDdoNCIgc3Ryb2tlPSIjMzM4MUZGIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","font-colors":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0ibTQgMTEgNC05IDQgOU02IDdoNCIgc3Ryb2tlPSIjNDQ0RTYwIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","to-bottom":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDEwdjhtMCAwLTItMm0yIDIgMi0ybS00IDZoMTJtLTYtNGg2bS02LTRoNm0tNi00aDYiIHN0cm9rZT0iIzQ0NEU2MCIgZmlsbD0ibm9uZSIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+PC9zdmc+","to-top":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDIydi04bTAgMC0yIDJtMi0yIDIgMm0tNC02aDEybS02IDRoNm0tNiA0aDZtLTYgNGg2IiBzdHJva2U9IiM0NDRFNjAiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==","bold-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTQuNSAySDhhMi41IDIuNSAwIDAgMSAwIDVINS41aDBtLTEgMGg0YTMgMyAwIDAgMSAwIDZoLTQgMG0wIDFWMiIgc3Ryb2tlPSIjMzM4MUZGIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=",bold:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTQuNSAySDhhMi41IDIuNSAwIDAgMSAwIDVINS41aDBtLTEgMGg0YTMgMyAwIDAgMSAwIDZoLTQgMG0wIDFWMiIgc3Ryb2tlPSIjNDQ0RTYwIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","underline-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N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LjIyNjY2NiA0NS4yMjY2NjcgODUuMzMzMzM0LTg1LjMzMzMzNC00NS4yMjY2NjctNDUuMjI2NjY2eiIgIGZpbGw9IiM0NDRFNjAiPjwvcGF0aD48L3N2Zz4="};function xe(r){return Dm[r]}const xm=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(),ne.emitMethod(se.MainEngine,Q.DeleteNode,{workIds:s||[H],viewId:e.viewId})}},y.createElement("img",{alt:"icon",src:xe("delete")}))},Lm=r=>{const{workIds:s,viewId:e}=r;return y.createElement("div",{className:"button normal-button",onPointerUp:t=>{t.stopPropagation(),ne.emitMethod(se.MainEngine,Q.CopyNode,{workIds:s||[H],viewId:e})}},y.createElement("img",{alt:"icon",src:xe("duplicate")}))},no=r=>{const{icon:s,onPointerUpHandler:e}=r;return y.createElement("div",{className:"button normal-button",onPointerUp:e},y.createElement("img",{src:xe(s)}))},bm=r=>{const{open:s,setOpen:e,floatBarRef:t}=r,{floatBarData:i,mananger:o}=y.useContext(ve),[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(no,{icon:"to-top",onPointerUpHandler:h=>{h.stopPropagation(),ne.emitMethod(se.MainEngine,Q.ZIndexNode,{workIds:[H],layer:Ft.Top,viewId:o==null?void 0:o.viewId})}}),y.createElement(no,{icon:"to-bottom",onPointerUpHandler:h=>{h.stopPropagation(),ne.emitMethod(se.MainEngine,Q.ZIndexNode,{workIds:[H],layer:Ft.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:xe(s?"layer-pressed":"layer")}))},Ts=r=>{r.stopPropagation(),r.nativeEvent.stopImmediatePropagation()},jm=()=>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"})),gn=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"}))},Ns=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:Ce(s,1)}}))},Ss=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, ${Ce(e,0)}, ${Ce(e,1)})`}}),y.createElement("div",{className:"range-opacity"},y.createElement(bt,{bounds:"parent",axis:"x",position:i,onDrag:c,onStart:l,onStop:u},y.createElement("div",{className:"circle",style:{backgroundColor:Ce(e,s)},onPointerUp:Ts}))))},Am=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(bt,{bounds:"parent",axis:"x",position:n,onDrag:u,onStart:h,onStop:d},y.createElement("div",{className:"circle",style:{backgroundColor:o},onPointerUp:Ts},y.createElement("div",{className:"range-opacity-data-icon"},t)))))},zm=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===te.Stroke&&"active"}`,style:{backgroundColor:e},onPointerUp:()=>{i(te.Stroke)}}),y.createElement("div",{className:`stroke-type-box-item Normal ${t===te.Normal&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(te.Normal)}}),y.createElement("div",{className:`stroke-type-box-item Dotted ${t===te.Dotted&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(te.Dotted)}}),y.createElement("div",{className:`stroke-type-box-item LongDotted ${t===te.LongDotted&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(te.LongDotted)}}))},Pm=r=>{var I,T;const{open:s,setOpen:e,floatBarRef:t}=r,{floatBarData:i,floatBarColors:o,mananger:n,setFloatBarData:a}=y.useContext(ve),[c,l]=y.useState(),[u,h]=y.useState(1);y.useEffect(()=>{if(i!=null&&i.strokeColor){const[C,S]=Is(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(Ss,{key:"strokeColors",opacity:u,activeColor:c,setCurOpacity:(C,S,N)=>{h(C);const x=Ce(S,C);i!=null&&i.strokeColor&&a({strokeColor:x}),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],strokeColor:x,workState:N,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(Am,{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:(N,x)=>{i!=null&&i.thickness&&a({thickness:N}),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],thickness:N,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,(T=n==null?void 0:n.control.pluginOptions.strokeWidth)==null?void 0:T.min,n==null?void 0:n.viewId,a]),f=y.useMemo(()=>c&&i&&(i!=null&&i.strokeType)?y.createElement(zm,{key:"strokeType",useStroke:i==null?void 0:i.useStroke,activeStrokeType:i.strokeType,setStrokeType:C=>{i.strokeType&&a({strokeType:C}),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],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 N=Gt(...C);return y.createElement(Ns,{key:S,color:N,activeColor:c,onPointerUpHandler:x=>{x.stopPropagation(),l(N);const L=Ce(N,u);i!=null&&i.strokeColor&&(i.strokeColor=L,a({strokeColor:L})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],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:Ce(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)},Em=r=>{const{open:s,setOpen:e,floatBarRef:t}=r,{floatBarData:i,floatBarColors:o,mananger:n,setFloatBarData:a}=y.useContext(ve),[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]||Is(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(Ss,{key:"fillColors",opacity:u||0,activeColor:c,setCurOpacity:(m,w,I)=>{h(m);const T=Ce(w,m);i!=null&&i.fillColor&&(i.fillColor=T,a({fillColor:T})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],fillColor:c&&Ce(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(gn,{activeColor:c,onPointerUpHandler:m=>{m.stopPropagation(),l("transparent");const w="transparent";i!=null&&i.fillColor&&(i.fillColor=w,a({fillColor:w})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],workState:j.Done,fillColor:w,viewId:n==null?void 0:n.viewId})}}),o.map((m,w)=>{const I=Gt(...m);return y.createElement(Ns,{key:w,color:I,activeColor:c,onPointerUpHandler:T=>{T.cancelable&&T.preventDefault(),T.stopPropagation(),l(I);const C=Ce(I,u);i!=null&&i.fillColor&&(i.fillColor=C,a({fillColor:C})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],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"&&Ce(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)},Om=r=>{const{open:s,setOpen:e,textOpt:t,workIds:i,floatBarRef:o}=r,{floatBarColors:n,mananger:a,setFloatBarData:c,floatBarData:l}=y.useContext(ve),[u,h]=y.useState(),[d,g]=y.useState(1);y.useEffect(()=>{if(t!=null&&t.fontColor){const[I,T]=(t==null?void 0:t.fontColor)==="transparent"&&["transparent",0]||Is(t.fontColor);h(I),g(T)}},[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(Ss,{key:"fontColors",opacity:d,activeColor:u,setCurOpacity:(I,T,C)=>{g(I);const S=Ce(T,I);l!=null&&l.textOpt&&(l.textOpt.fontColor=S,c({textOpt:l.textOpt})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:i||[H],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,T)=>{const C=Gt(...I);return y.createElement(Ns,{key:T,color:C,activeColor:u,onPointerUpHandler:S=>{S.stopPropagation(),h(C);const N=Ce(C,d);l!=null&&l.textOpt&&(l.textOpt.fontColor=N,c({textOpt:l.textOpt})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:i||[H],workState:j.Done,fontColor:N,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"&&Ce(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:xe("font-colors")}),w,m)},Rm=r=>{const{open:s,setOpen:e,textOpt:t,workIds:i,floatBarRef:o}=r,{floatBarColors:n,mananger:a,setFloatBarData:c,floatBarData:l}=y.useContext(ve),[u,h]=y.useState(),[d,g]=y.useState(1);y.useEffect(()=>{if(t!=null&&t.fontBgColor){const[I,T]=(t==null?void 0:t.fontBgColor)==="transparent"&&["transparent",1]||Is(t.fontBgColor);h(I),g(T)}},[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(Ss,{key:"fontBgColor",opacity:d||0,activeColor:u,setCurOpacity:(I,T,C)=>{g(I);const S=Ce(T,I);l!=null&&l.textOpt&&(l.textOpt.fontBgColor=S,c({textOpt:l.textOpt})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:i||[H],fontBgColor:u&&Ce(T,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(gn,{activeColor:u,onPointerUpHandler:I=>{I.stopPropagation();const T="transparent";h(T),l!=null&&l.textOpt&&(l.textOpt.fontBgColor=T,c({textOpt:l.textOpt})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:i||[H],workState:j.Done,fontBgColor:T,viewId:a==null?void 0:a.viewId})}}),n.map((I,T)=>{const C=Gt(...I);return y.createElement(Ns,{key:T,color:C,activeColor:u,onPointerUpHandler:S=>{S.stopPropagation(),h(C);const N=Ce(C,d);l!=null&&l.textOpt&&(l.textOpt.fontBgColor=N,c({textOpt:l.textOpt})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:i||[H],workState:j.Done,fontBgColor:Ce(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"&&Ce(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(jm,null),w,m)},Wm=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),ne.emitMethod(se.MainEngine,Q.SetFontStyle,{workIds:t,viewId:i,bold:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:xe(s==="bold"?"bold-active":"bold")}))},Ym=r=>{const{underline:s,setUnderline:e,workIds:t,viewId:i}=r,o=n=>{const a=!s;n==null||n.stopPropagation(),e(a),ne.emitMethod(se.MainEngine,Q.SetFontStyle,{workIds:t,viewId:i,underline:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:xe(s?"underline-active":"underline")}))},Um=r=>{const{lineThrough:s,setLineThrough:e,workIds:t,viewId:i}=r,o=n=>{const a=!s;n==null||n.stopPropagation(),e(a),ne.emitMethod(se.MainEngine,Q.SetFontStyle,{workIds:t,viewId:i,lineThrough:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:xe(s?"line-through-active":"line-through")}))},Bm=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),ne.emitMethod(se.MainEngine,Q.SetFontStyle,{workIds:t,viewId:i,italic:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:xe(s==="italic"?"italic-active":"italic")}))},Fm=r=>{const{open:s,setOpen:e,textOpt:t,workIds:i,style:o,floatBarRef:n}=r,{mananger:a,floatBarData:c}=y.useContext(ve),[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 T={};return T.top="inherit",T.bottom=50,T}else if(!n.current.offsetTop&&(a==null?void 0:a.height)-n.current.offsetTop-c.y<120){const T={};return T.top="inherit",T.bottom=50,T}}},[o,n==null?void 0:n.current,c,a]),I=y.useMemo(()=>s?y.createElement("div",{className:"font-style-menu",style:w,onPointerUp:T=>{T.stopPropagation(),T.nativeEvent.stopImmediatePropagation()}},y.createElement(Wm,{workIds:i||[H],bold:l,setBold:u,viewId:a==null?void 0:a.viewId}),y.createElement(Ym,{workIds:i||[H],underline:g,setUnderline:p,viewId:a==null?void 0:a.viewId}),y.createElement(Um,{workIds:i||[H],lineThrough:f,setLineThrough:m,viewId:a==null?void 0:a.viewId}),y.createElement(Bm,{workIds:i||[H],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:T=>{T.stopPropagation(),T.nativeEvent.stopImmediatePropagation(),e(!s)}},y.createElement("img",{alt:"icon",src:xe(s?"font-style-active":"font-style")}),I)},Xe=Object.freeze([12,14,18,24,36,48,64,80,144,288]),Tt=["top","topLeft","topRight","bottom","bottomLeft","bottomRight","left","leftTop","leftBottom","right","rightTop","rightBottom"],Yt=new Map([["selector","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAKeSURBVHgB3VTLi1JhFD86zlQ4ysxSXAy1GWYZzMxmYAhHagRB/QN8FLqPFq4FIQhXkS6kTQ4t2ilIKEWgSS0SmVpIm0BdaBJSaOP78XU+PXey6+saburAD+73uL/feX0H4H81GQdj7D7ilrCGFRonk3c6nXvhcJiFQiGWy+Xy/X7/WbPZ1K1KkBOsl0qlO36/n+3t7Q1hs9kYF+WC3W73MTpxc1lBmej7KuJaoVDInZ6eqsWXDw4OwGKxwPHx8Se1Wn1Wr9cjW1tbOTxi9D9bJCJHXEFslsvlR263+246nYZZptPpQK/Xg8lkSvZ6vbNGo5EgQRCLiSPhIqpoNHobo3keCARgkalUKjg5ORlGuL+/n8T6PVAqlefjYmKRdYQSsZ3P5z8aDAYVLGFarRbi8fhbhUKhx2VPEJGP3eEbfTrs4MUwr4EU49FYrVbweDy1SqXyipy95FaI7g8QXS6SyWReHx4e2ubVBc+HtTk6OjqvVqtvvF7vi0gkUiSByyyJ21BGwpswJ2Vmsxlw/0Kj0bxMJBJJl8vFPWkhGogLQoeyMhEJo2jGUzYRjcPh+Op0Oq2pVOoHkXE0SahF/w+E+3KYNEaX2pSyiSiKxeJTFPiGyyriO6FKEUgSESLp4ht4bzQaf4pFYrHYO/ysEXGNyJtjKRqM/zNNhFuf0B7vst3dXdjZ2Yn4fL4vRFwn8jaMGqYPU179LBEGf3bZcNNutwPOtScwKnCLPJ9KLMWEh7mNuIFdVsNXzbBNP+D6Ou1vwAqm8hqMWlmbzWYf4mz6HAwGzbjWwGgqrEklmucJT+UGCfG3wiPjueeNwGvB0zkAid7OMmF8CyOck/I6NJcR4KZYcM6J2vCbUGhv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:s,onClickHandler:e}=r;return y.createElement("div",{className:"font-size-menu",style:s,onPointerUp:t=>{t.stopPropagation(),t.nativeEvent.stopImmediatePropagation()}},Xe.map(t=>y.createElement("div",{className:"font-size-btn",key:t,onPointerUp:()=>{e(t)}},t)))},Vm=r=>{const s=y.useRef(null),{open:e,setOpen:t,textOpt:i,workIds:o,floatBarRef:n}=r,{mananger:a,floatBarData:c}=y.useContext(ve),[l,u]=y.useState(0),h=Xe.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>=Xe[0]&&w<=Xe[h]&&ne.emitMethod(se.MainEngine,Q.SetFontStyle,{workIds:o||[H],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(Qm,{onClickHandler:p,style:d}):null,[e,p,d]),m=w=>{w>Xe[h]&&(w=Xe[h]),w<Xe[0]&&(w=Xe[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(),T=I==null?void 0:I.getRangeAt(0);if(T!=null&&T.collapsed)return w.cancelable&&w.preventDefault(),document.execCommand("delete",!1),!1}return!1},onKeyUp:w=>{var I;if(s.current){const T=s.current.value,C=parseInt(T);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+Xe[0])}}),y.createElement("div",{className:"font-size-cut",onPointerUp:()=>{m(l-Xe[0])}})),f)},Zm=r=>{const{workIds:s,mananger:e,islocked:t}=r;return y.createElement("div",{className:"button normal-button",onPointerUp:i=>{i.stopPropagation(),ne.emitMethod(se.MainEngine,Q.SetLock,{workIds:s||[H],isLocked:!t,viewId:e==null?void 0:e.viewId})}},y.createElement("img",{alt:"icon",src:xe(t?"unlock-new":"lock-new")}))},Bs=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:xe(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)}})))},Hm=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:xe(s)}),y.createElement(Gm,{min:e,max:t,step:i,value:o,onInputHandler:n}))},Gm=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=()=>{console.log("onDragStartHandler")},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(bt,{bounds:"parent",axis:"x",position:o,onDrag:a,onStart:c,onStop:l},y.createElement("div",{className:"circle",onPointerUp:Ts}))))},$m=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>=Tt.length&&(g=0),g<0&&(g=Tt.length-1),n(g),t(Tt[g]),c(!1),l.current&&(l.current.value=Tt[g])},[t]),h=y.useMemo(()=>{if(i&&i.bottom){const g={};return g.top="inherit",g.bottom=50,g}},[i]);y.useEffect(()=>{e&&(n(Tt.indexOf(e)),l.current&&(l.current.value=e))},[e]);const d=y.useMemo(()=>a?y.createElement(Xm,{options:Tt,onClickHandler:u,style:h}):null,[a,u,h]);return y.createElement("div",{className:"button input-button"},y.createElement("img",{src:xe(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)},Xm=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)))},Jm=r=>{const{innerRatio:s,innerVerticeStep:e,vertices:t,mananger:i,setShapeOpt:o}=r,n=l=>{o({vertices:l}),ne.emitMethod(se.MainEngine,Q.SetShapeOpt,{workIds:[H],toolsType:v.Star,viewId:i.viewId,vertices:l})},a=l=>{o({innerVerticeStep:l}),ne.emitMethod(se.MainEngine,Q.SetShapeOpt,{workIds:[H],toolsType:v.Star,viewId:i.viewId,innerVerticeStep:l})},c=l=>{o({innerRatio:l}),ne.emitMethod(se.MainEngine,Q.SetShapeOpt,{workIds:[H],toolsType:v.Star,viewId:i.viewId,innerRatio:l})};return y.createElement(y.Fragment,null,y.createElement(Bs,{value:t,icon:"polygon-vertex",min:3,max:100,step:1,onInputHandler:n}),y.createElement(Bs,{value:e,icon:"star-innerVertex",min:1,max:100,step:1,onInputHandler:a}),y.createElement(Hm,{value:s,icon:"star-innerRatio",min:.1,max:1,step:.1,onInputHandler:c}))},qm=r=>{const{mananger:s,vertices:e,setShapeOpt:t}=r,i=o=>{t({vertices:o}),ne.emitMethod(se.MainEngine,Q.SetShapeOpt,{workIds:[H],toolsType:v.Polygon,viewId:s.viewId,vertices:o})};return y.createElement(Bs,{value:e,icon:"polygon-vertex",min:3,max:100,step:1,onInputHandler:i})},Km=r=>{const{mananger:s,placement:e,setShapeOpt:t}=r,i=o=>{t({placement:o}),ne.emitMethod(se.MainEngine,Q.SetShapeOpt,{workIds:[H],toolsType:v.SpeechBalloon,viewId:s.viewId,placement:o})};return y.createElement($m,{value:e,icon:"speechBallon-placement",onChangeHandler:i})},js=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:xe(s)}))},_m=r=>{const{toolsTypes:s,style:e,mananger:t,shapeOpt:i,setShapeOpt:o}=r,[n,a]=y.useState();y.useEffect(()=>{s.includes(v.Polygon)?a(v.Polygon):s.includes(v.Star)?a(v.Star):a(v.SpeechBalloon)},[s]);const c=d=>{a(d)},l=y.useMemo(()=>n===v.Polygon&&t&&i.vertices?y.createElement(qm,{vertices:i.vertices,mananger:t,setShapeOpt:o}):null,[t,n,i,o]),u=y.useMemo(()=>n===v.Star&&t&&i.vertices&&i.innerVerticeStep&&i.innerRatio?y.createElement(Jm,{mananger:t,vertices:i.vertices,innerVerticeStep:i.innerVerticeStep,innerRatio:i.innerRatio,setShapeOpt:o}):null,[t,n,i,o]),h=y.useMemo(()=>n===v.SpeechBalloon&&t&&i.placement?y.createElement(Km,{mananger:t,placement:i.placement,setShapeOpt:o}):null,[n,t,i.placement,o]);return y.createElement("div",{className:"shapeOpt-sub-menu",style:e,onPointerUp:Ts},y.createElement("div",{className:"shapeOpt-sub-menu-tabs"},s.includes(v.Polygon)&&y.createElement(js,{isActive:n===v.Polygon,icon:n===v.Polygon?"polygon-active":"polygon",onPointerUpHandler:c.bind(void 0,v.Polygon)})||null,s.includes(v.Star)&&y.createElement(js,{isActive:n===v.Star,icon:n===v.Star?"star-active":"star",onPointerUpHandler:c.bind(void 0,v.Star)})||null,s.includes(v.SpeechBalloon)&&y.createElement(js,{isActive:n===v.SpeechBalloon,icon:n===v.SpeechBalloon?"speechBallon-active":"speechBallon",onPointerUpHandler:c.bind(void 0,v.SpeechBalloon)})||null),y.createElement("div",{className:"shapeOpt-sub-menu-content"},l,u,h))},ew=r=>{const{open:s,setOpen:e,floatBarRef:t,toolsTypes:i,shapeOpt:o}=r,{floatBarData:n,mananger:a,setFloatBarData:c}=y.useContext(ve),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(_m,{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:xe(s?"shapes-active":"shapes")}))},fn=y.memo(r=>{const{textOpt:s,workIds:e,noLayer:t,position:i,noDelete:o,noCopy:n}=r,{floatBarData:a,mananger:c}=y.useContext(ve),[l,u]=y.useState(0),[h,d]=y.useState(),g=y.useRef(null);y.useEffect(()=>{var E,A,P,R;const x={},L=(a==null?void 0:a.w)||((E=s==null?void 0:s.boxSize)==null?void 0:E[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+(((P=g.current)==null?void 0:P.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(Em,{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(Pm,{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(Om,{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(Rm,{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(Fm,{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]),T=y.useMemo(()=>s&&(c!=null&&c.viewId)?y.createElement(Vm,{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(Zm,{workIds:e,mananger:c,islocked:a.isLocked}):null,[a,c,e]),N=y.useMemo(()=>c&&(c!=null&&c.viewId)&&h&&(a!=null&&a.shapeOpt)&&(a!=null&&a.toolsTypes)?y.createElement(ew,{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(xm,{workIds:e,mananger:c}),C,S,!!(c!=null&&c.viewId)&&!n&&y.createElement(Lm,{workIds:e,viewId:c.viewId}),N,I,T,m,w,f,p)}),tw=r=>{const{data:s,workId:e,updateOptInfo:t}=r,{opt:i,scale:o,translate:n,x:a,y:c}=s,l=y.useRef(null),{floatBarData:u}=y.useContext(ve),h=y.useMemo(()=>{const p=[];if(i.text){const f=wt(i.text);for(let m=0;m<f.length;m++){const w=f[m];w===""?p.push(y.createElement("div",{key:m},y.createElement("br",null))):p.push(y.createElement("div",{key:m},w))}}return p.length?p:null},[i.text]),d=y.useMemo(()=>{if(!u)return{};const p=`scale(${o||1}) ${n&&"translate("+n[0]+"px,"+n[1]+"px)"||""}`;return{left:`${a-u.x}px`,top:`${c-u.y}px`,zIndex:1,transform:p,transformOrigin:"left top",pointerEvents:"none",opacity:0}},[o,n,a,c,u]),g=y.useMemo(()=>{const{fontSize:p,fontFamily:f,underline:m,fontColor:w,lineThrough:I,textAlign:T,strokeColor:C,lineHeight:S,bold:N,italic:x}=i,L=S||p*1.2,b={fontSize:`${p}px`,lineHeight:`${L}px`,color:w,borderColor:C,minHeight:`${L}px`,pointerEvents:"none",paddingRight:`${x==="italic"?Math.round(p*.3):5}px`};return f&&(b.fontFamily=`${f}`),(I||m)&&(b.textDecoration=`${I&&"line-through"||""}${m&&" underline"||""}`),T&&(b.textAlign=`${T}`),N&&(b.fontWeight=`${N}`),x&&(b.fontStyle=`${x}`),b},[i]);return y.useEffect(()=>{var p,f;if((p=l.current)!=null&&p.offsetWidth&&((f=l.current)!=null&&f.offsetHeight)){const m=i.boxSize;if((m==null?void 0:m[0])!==l.current.offsetWidth||m[1]!==l.current.offsetHeight||!m){const w=[l.current.offsetWidth,l.current.offsetHeight];t({activeTextId:e,update:{boxSize:w,workState:j.Done}})}}},[i.fontSize,i.italic,i.bold,i.boxSize,e,t]),y.createElement("div",{className:"editor-box readonly",style:d},y.createElement("div",{className:"editor",ref:l,style:g},h))},sw=r=>{const{mananger:s}=y.useContext(ve),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(tw,{key:a,workId:a,data:n,updateOptInfo:t});o.push(c)}}),o}return null},[r.editors,r.selectIds,s]);return y.createElement(y.Fragment,null,e)},iw=r=>{const{data:s,workId:e,showFloatBtns:t,handleKeyUp:i,handleFocus:o,runAnimation:n}=r,[a,c]=y.useState(!1),{activeTextEditor:l,activeTextId:u,mananger:h}=y.useContext(ve),{opt:d,scale:g,translate:p,x:f,y:m}=s,{fontSize:w,fontFamily:I,underline:T,fontColor:C,lineThrough:S,textAlign:N,lineHeight:x,bold:L,italic:b}=d,E=y.useRef(null),A=y.useMemo(()=>u===e?"hover":d.workState===j.Doing||d.workState===j.Start?"editing":l?"active":"none",[u,e,d.workState,l]),P=y.useMemo(()=>{const V=`scale(${g||1}) ${p&&"translate("+p[0]+"px,"+p[1]+"px)"||""}`;return{left:`${f}px`,top:`${m}px`,zIndex:2,transform:V,transformOrigin:"left top",borderColor:A==="editing"||A==="hover"?C:"transparent"}},[g,p,f,m,C,A]),R=y.useMemo(()=>{const V=w,le=x||V*1.2,ie={fontSize:`${V}px`,lineHeight:`${le}px`,color:C,minHeight:`${le}px`,paddingRight:`${b==="italic"?Math.round(V*.3):5}px`,borderWidth:`${Math.max(Math.round(1/(g||1)),1)}px`};return I&&(ie.fontFamily=`${I}`),(S||T)&&(ie.textDecoration=`${S&&"line-through"||""} ${T&&" underline"||""}`),N&&(ie.textAlign=`${N}`),L&&(ie.fontWeight=`${L}`),b&&(ie.fontStyle=`${b}`),ie},[L,C,I,w,b,x,S,g,N,T]),z=y.useMemo(()=>{let V="";if(d.text){const le=wt(d.text);for(let ie=0;ie<le.length;ie++){const pe=le[ie];pe===""?V=V+"<div><br/></div>":V=V+`<div style="background-color:${d.fontBgColor}">${pe}</div>`}}else V=`<div style="background-color:${d.fontBgColor}"></div>`;return V},[d.fontBgColor,d.text]),X=y.useMemo(()=>{var V,le;return A==="hover"&&g&&t&&O.isNumber(f)&&O.isNumber(m)&&d.boxSize&&O.isNumber((V=d.boxSize)==null?void 0:V[0])&&O.isNumber((le=d.boxSize)==null?void 0:le[1])?y.createElement("div",{className:be.FloatBarBtn,style:{left:f,top:m,width:d.boxSize[0]*g,height:d.boxSize[1]*g}},y.createElement(fn,{position:{x:f,y:m},textOpt:d,workIds:[e],noLayer:!0,noCopy:!0,noDelete:!0})):null},[d,t,e,f,m,g,A]);y.useEffect(()=>{u===e&&K()},[u,A,e]);function K(){var V,le;if(E.current){const ie=window==null?void 0:window.getSelection(),pe=(V=E.current)==null?void 0:V.lastChild;if(ie&&pe){const de=document.createRange(),Me=((le=pe.textContent)==null?void 0:le.length)||0;(pe==null?void 0:pe.nodeName)==="#text"?de.setStart(pe,Me):de.setStart(pe,Me&&1||0),de.collapse(!0),ie.removeAllRanges(),ie.addRange(de)}E.current.focus()}}function F(V){if(V.key==="Backspace"){const le=window.getSelection(),ie=le==null?void 0:le.getRangeAt(0);if(ie!=null&&ie.collapsed)return V.cancelable&&V.preventDefault(),document.execCommand("delete",!1),!1}return n(),!1}function G(V,le){const ie=window==null?void 0:window.getSelection();if(ie!=null&&ie.rangeCount&&V&&ie&&ie.anchorNode){const pe=ie.anchorOffset,de=ie.anchorNode.textContent||"",Me=de.slice(0,pe)||"",ot=de.slice(pe)||"",nt=Me.concat(V)||"";_(nt,ot,le)}}function _(V,le,ie){const pe=window==null?void 0:window.getSelection();if(!(pe!=null&&pe.rangeCount)||!pe.anchorNode)return;const de=V.split(/\n/);let Me=pe.anchorNode.parentNode;Me===ie&&(Me=pe.anchorNode);const ot=[...ie.childNodes],nt=[];let _e,Cs=pe.anchorOffset;for(;ot.length;){const Ae=ot.pop();if(Ae){if(Ae===Me){let Qe=de[0];de.length===1&&(Cs=de[0].length,Qe=de[0].concat(le)),Me.nodeName==="#text"?(Me.textContent=Qe,_e=Me):Me.nodeName==="DIV"&&(Me.innerText=Qe,_e=Me.childNodes[0]);break}nt.push(Ae),ie.removeChild(Ae)}}if(de.length>1)for(let Ae=1;Ae<de.length;Ae++){let Qe=de[Ae];const Rt=document.createElement("div");d.fontBgColor&&(Rt.style.backgroundColor=d.fontBgColor),Ae===de.length-1&&(Cs=Qe.length,Qe=Qe.concat(le)),Qe===""?Rt.innerHTML="<br/>":Rt.innerText=Qe,ie.appendChild(Rt),Ae===de.length-1&&(_e=Rt.childNodes[0])}if(nt.length){nt.reverse();for(const Ae of nt)ie.appendChild(Ae)}if(_e&&_e.nodeName==="#text"){pe.deleteFromDocument();const Ae=document.createRange(),Qe=Math.min(Cs,(_e==null?void 0:_e.length)||0);Ae.setStart(_e,Qe),Ae.collapse(!0),pe.removeAllRanges(),pe.addRange(Ae)}}function ce(V){if(V.cancelable&&V.preventDefault(),V.stopPropagation(),E.current){const le=(V.clipboardData||window.clipboardData).getData("text"),ie=window==null?void 0:window.getSelection();if(!(ie!=null&&ie.rangeCount))return;le&&ie&&ie.anchorNode&&G(le,E.current),n()}}function ee(V){V.persist(),setTimeout(()=>{a||i(V)},0)}function q(){c(!0),n()}function J(V){c(!1),i(V)}const ue=y.useCallback(V=>{h&&(h.control.textEditorManager.checkEmptyTextBlur(),o(V),h==null||h.control.textEditorManager.active(e))},[o,h,e]),ze=y.useCallback(()=>{if(A==="active"&&E.current&&E.current.parentElement){const V=E.current.parentElement;V.style.borderColor=C}},[A,C]),Te=y.useCallback(()=>{if(A==="active"&&E.current&&E.current.parentElement){const V=E.current.parentElement;V.style.borderColor="transparent"}},[A]);return y.createElement(y.Fragment,null,X,y.createElement("div",{className:`editor-box ${A}`,style:P},y.createElement("div",{id:e,suppressContentEditableWarning:!0,contentEditable:!0,className:"editor",ref:E,style:R,onKeyDown:F,onFocus:ue,onMouseOver:ze,onMouseLeave:Te,onPaste:ce,onTouchEnd:()=>{document.activeElement!==E.current&&K()},onInput:ee,onCompositionStart:q,onCompositionEnd:J,dangerouslySetInnerHTML:{__html:z}})))},ow=r=>{const s=y.useRef(null),[e,t]=y.useState(),{mananger:i}=y.useContext(ve),o=y.useCallback(()=>{if(!e){const c=requestAnimationFrame(()=>{s!=null&&s.current&&(s==null||s.current.scrollTo({left:0,behavior:"instant"})),t(void 0)});t(c)}},[e]),n=y.useCallback(c=>{var g,p;const{activeTextId:l,update:u,syncData:h}=c;if(!i)return;const d=l&&O.cloneDeep(((g=i.control.textEditorManager)==null?void 0:g.get(l))||((p=r.editors)==null?void 0:p.get(l)));d&&d.opt&&(d.opt={...d.opt,...u},h&&(d.canSync=Object.keys(h).includes("canSync")&&h.canSync||d.canSync,d.canWorker=Object.keys(h).includes("canWorker")&&h.canWorker||d.canWorker),i.control.textEditorManager.updateForViewEdited(l,d))},[i,r.editors]),a=y.useMemo(()=>{var h;const c=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&&g.push(w);const I=m.pop();g.push(...m),I&&g.push(I)}}}return g},l=d=>{if(!i)return;const g=d.currentTarget.id,p=i.control.textEditorManager.get(g),f=j.Doing,m=[d.nativeEvent.target.offsetWidth,d.nativeEvent.target.offsetHeight];(!p||p&&(!O.isEqual(p.opt.boxSize,m)||!O.isEqual(p.opt.workState,f)))&&n({activeTextId:g,update:{boxSize:m,workState:f},syncData:{canSync:!0,canWorker:!0}})},u=d=>{var T,C;if(!i)return;const g=c(d.nativeEvent.target),p=d.nativeEvent.target.id,f=i.control.textEditorManager.get(p),m=We(g),w=j.Doing,I=[d.nativeEvent.target.offsetWidth,d.nativeEvent.target.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(((T=i.control.textEditorManager)==null?void 0:T.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,i.control.textEditorManager.updateForViewEdited(p,S)),i.control.textEditorManager.publicMsgEmitter.emit("textChange",p,d.nativeEvent.target,g,S)}};if((h=r.editors)!=null&&h.size){const d=[];return r.editors.forEach((g,p)=>{d.push(y.createElement(iw,{key:p,workId:p,data:g,showFloatBtns:r.showFloatBtns||!1,handleFocus:l,handleKeyUp:u,runAnimation:o}))}),d}return null},[r.editors,r.showFloatBtns,i,n,o]);return y.createElement("div",{className:`${r.className}`,ref:s},a)},nw=()=>{const{floatBarData:r}=y.useContext(ve);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}}))},rw=()=>{const{floatBarData:r,mananger:s}=y.useContext(ve),[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)},aw=()=>{const{floatBarData:r}=y.useContext(ve);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}}))},cw=()=>{const{floatBarData:r}=y.useContext(ve);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"}))},lw=r=>{const{className:s}=r,{floatBarData:e,angle:t,setAngle:i,setOperationType:o,mananger:n}=y.useContext(ve),[a,c]=y.useState(j.Pending),[l,u]=y.useState(),[h,d]=y.useState(!1),[g,p]=y.useState(new Z),[f,m]=y.useState(new Z),[w,I]=y.useState(!1),T=y.useRef(0),C=y.useRef(null),S=E=>{if(!E){I(!0),d(!1),o(Q.None),c(j.Pending);return}I(!1)},N=(E,A)=>{T.current&&(clearTimeout(T.current),T.current=0),c(j.Done),d(!1);const P=Math.round(Z.GetAngleByPoints(g,f,new Z(A.x,A.y)))||0;i(P),o(Q.None),ne.emitMethod(se.MainEngine,Q.RotateNode,{workIds:[H],angle:P,workState:j.Done,viewId:n==null?void 0:n.viewId})};y.useEffect(()=>(ne.activeListener(S),()=>{ne.unmountActiveListener(S)}),[]),y.useEffect(()=>{if(e&&(a===j.Pending||a===j.Done)){const E={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 Z(A.x,A.y)),p(new Z(E.x,E.y)),u({x:E.x,y:E.y})}},[e,a]);const x=(E,A)=>{if(n!=null&&n.control.worker.isBusy){I(!0),c(j.Pending);return}T.current&&(clearTimeout(T.current),T.current=0),c(j.Start),d(!0);const P=Math.round(Z.GetAngleByPoints(g,f,new Z(A.x,A.y)))||0;i(P),o(Q.RotateNode),ne.emitMethod(se.MainEngine,Q.RotateNode,{workIds:[H],angle:0,workState:j.Start,viewId:n==null?void 0:n.viewId})},L=(E,A)=>{if(n!=null&&n.control.worker.isBusy){I(!0),N(E,A);return}N(E,A)},b=(E,A)=>{if(n!=null&&n.control.worker.isBusy){I(!0),N(E,A);return}T.current||(u({x:A.x,y:A.y}),d(!0),T.current=setTimeout(()=>{T.current=0;const P=Math.round(Z.GetAngleByPoints(g,f,new Z(A.x,A.y)))||0;i(P),o(Q.RotateNode),c(j.Doing),ne.emitMethod(se.MainEngine,Q.RotateNode,{workIds:[H],angle:P,workState:j.Doing,viewId:n==null?void 0:n.viewId})},60))};return y.createElement(bt,{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:xe("rotation-button")})),y.createElement("div",{ref:C,className:`appliance-plugin-rotate-mouse-pointer ${h?"active":""}`},y.createElement("img",{alt:"icon",src:xe("rotation")}),y.createElement("div",{className:"angle-icon"},t,"°"))))},hw=()=>{const{floatBarData:r,setOperationType:s,mananger:e,isNoPointerEvents:t}=y.useContext(ve),[i,o]=y.useState(j.Pending),[n,a]=y.useState(),[c,l]=y.useState(!1),u=y.useRef(0),h=y.useMemo(()=>!!((r==null?void 0:r.scaleType)===re.none&&(r!=null&&r.canLock)),[r]),d=y.useMemo(()=>r&&r.w&&r.h?{position:"absolute",left:0,top:0,width:r.w,height:r.h,zIndex:2,pointerEvents:h||t?"none":"auto",touchAction:"none"}:{display:"none",pointerEvents:"none"},[r,h,t]),g=I=>{if(!I||r!=null&&r.isLocked){l(!0),o(j.Pending),s(Q.None);return}l(!1)},p=(I,T)=>{u.current&&(clearTimeout(u.current),u.current=0);const C={x:T.x,y:T.y};s(Q.None),o(j.Done),a(C),ne.emitMethod(se.MainEngine,Q.TranslateNode,{workIds:[H],position:C,workState:j.Done,viewId:e==null?void 0:e.viewId})};y.useEffect(()=>(ne.activeListener(g),()=>{ne.unmountActiveListener(g)}),[]),y.useEffect(()=>{if(r&&(r!=null&&r.isLocked)||e!=null&&e.control.worker.isBusy){l(!0);return}l(!1)},[r,e==null?void 0:e.control.worker.isBusy]),y.useEffect(()=>{O.isNumber(r==null?void 0:r.x)&&O.isNumber(r==null?void 0:r.y)&&(i===j.Pending||i===j.Done)&&a({x:r==null?void 0:r.x,y:r==null?void 0:r.y})},[r==null?void 0:r.x,r==null?void 0:r.y,i]);const f=()=>{if(e!=null&&e.control.worker.isBusy){l(!0);return}u.current&&(clearTimeout(u.current),u.current=0),O.isNumber(r==null?void 0:r.x)&&O.isNumber(r==null?void 0:r.y)&&(s(Q.TranslateNode),o(j.Start),ne.emitMethod(se.MainEngine,Q.TranslateNode,{workIds:[H],position:{x:r==null?void 0:r.x,y:r==null?void 0:r.y},workState:j.Start,viewId:e==null?void 0:e.viewId}))},m=(I,T)=>{e!=null&&e.control.worker.isBusy&&l(!0),p(I,T)},w=(I,T)=>{if(e!=null&&e.control.worker.isBusy){l(!0),p(I,T);return}if(u.current)return;const C={x:T.x,y:T.y};a(C),u.current=setTimeout(()=>{u.current=0,(C.x!==(n==null?void 0:n.x)||C.y!==(n==null?void 0:n.y))&&(o(j.Doing),ne.emitMethod(se.MainEngine,Q.TranslateNode,{workIds:[H],position:C,workState:j.Doing,viewId:e==null?void 0:e.viewId}))},60)};return y.createElement(bt,{disabled:c,position:n,onStart:f,onDrag:w,onStop:m},y.createElement("div",{style:d}))},uw=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(ve),[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 ne.activeListener(C),()=>{ne.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 T=()=>{if(I.current&&(clearTimeout(I.current),I.current=0),p){const{scale:A,translate:P}=p;g(Q.None),ne.emitMethod(se.MainEngine,Q.ScaleNode,{workIds:[H],scale:A,dir:c,translate:P,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]],N=(A,P)=>{switch(P){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,P,R,z)=>{let X=!1,K=!1;const F={x:e.x,y:e.y,w:e.w,h:e.h},G=[1,1],_=[0,0];switch(A){case"top":{const J=P.height+e.h;J<0?(K=!0,F.y=e.y+e.h,F.h=Math.abs(J)):(F.y=e.y-P.height,F.h=e.h+P.height);break}case"topLeft":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+e.w,F.w=Math.abs(J)):(F.x=e.x-P.width,F.w=e.w+P.width);const ue=P.height+e.h;ue<0?(K=!0,F.y=e.y+e.h,F.h=Math.abs(ue)):(F.y=e.y-P.height,F.h=e.h+P.height);break}case"topRight":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+J,F.w=Math.abs(J)):F.w=e.w+P.width;const ue=P.height+e.h;ue<0?(K=!0,F.y=e.y+e.h,F.h=Math.abs(ue)):(F.y=e.y-P.height,F.h=e.h+P.height);break}case"bottom":{const J=P.height+e.h;J<0?(K=!0,F.y=e.y+J,F.h=Math.abs(J)):F.h=e.h+P.height;break}case"bottomLeft":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+e.w,F.w=Math.abs(J)):(F.x=e.x-P.width,F.w=e.w+P.width);const ue=P.height+e.h;ue<0?(K=!0,F.y=e.y+ue,F.h=Math.abs(ue)):F.h=e.h+P.height;break}case"left":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+e.w,F.w=Math.abs(J)):(F.x=e.x-P.width,F.w=e.w+P.width);break}case"bottomRight":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+J,F.w=Math.abs(J)):F.w=e.w+P.width;const ue=P.height+e.h;ue<0?(K=!0,F.y=e.y+ue,F.h=Math.abs(ue)):F.h=e.h+P.height;break}case"right":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+J,F.w=Math.abs(J)):F.w=e.w+P.width;break}}G[0]=F.w/e.w,G[1]=F.h/e.h;const ee=S(F).map(J=>R.control.viewContainerManager.transformToScenePoint(J,R.viewId)),q=N(ee,A);return K&&(_[1]=q[1]-z[1]),X&&(_[0]=q[0]-z[0]),{scale:G,translate:_}},L=(A,P)=>{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),X=z.map(G=>h.control.viewContainerManager.transformToScenePoint(G,h.viewId)),K=N(z,P),F=N(X,P);t(R),o(K),a(F),l(P),g(Q.ScaleNode),ne.emitMethod(se.MainEngine,Q.ScaleNode,{workIds:[H],originPoint:K,scenePoint:F,workState:j.Start,viewId:h.viewId})}},b=(A,P,R,z)=>{if(!(!h||!i||!n)){if(h!=null&&h.control.worker.isBusy){w(!0),T();return}I.current||(I.current=setTimeout(()=>{I.current=0;const{scale:X,translate:K}=x(P,z,h,n);(!O.isEqual(X,p==null?void 0:p.scale)||!O.isEqual(K,p==null?void 0:p.translate))&&(f({scale:X,translate:K}),g(Q.ScaleNode),ne.emitMethod(se.MainEngine,Q.ScaleNode,{workIds:[H],scale:X,dir:P,translate:K,originPoint:i,scenePoint:n,workState:j.Doing,viewId:h.viewId}))},60))}},E=()=>{h!=null&&h.control.worker.isBusy&&w(!0),T()};return y.createElement(mn.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)===re.all&&!0||!1,right:(u==null?void 0:u.scaleType)===re.all&&!0||!1,bottom:(u==null?void 0:u.scaleType)===re.all&&!0||!1,left:(u==null?void 0:u.scaleType)===re.all&&!0||!1,topRight:!0,bottomRight:!0,bottomLeft:!0,topLeft:!0},lockAspectRatio:(u==null?void 0:u.scaleType)===re.proportional,onResizeStart:L,onResize:b,onResizeStop:E})},ro=r=>{const{id:s,pos:e,pointMap:t,type:i}=r,{setOperationType:o,mananger:n,floatBarData:a}=y.useContext(ve),[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(Q.None);return}g(!1)};y.useEffect(()=>(ne.activeListener(m),()=>{ne.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,N)=>{p.current&&(clearTimeout(p.current),p.current=0),o(Q.None),h(j.Done);const x={x:N.x,y:N.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),ne.emitMethod(se.MainEngine,Q.SetPoint,{workId:H,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(Q.SetPoint),h(j.Start),ne.emitMethod(se.MainEngine,Q.SetPoint,{workId:H,pointMap:t,workState:j.Start,viewId:n==null?void 0:n.viewId}))},T=(S,N)=>{if(n!=null&&n.control.worker.isBusy){g(!0),w(S,N);return}if(p.current)return;const x={x:N.x,y:N.y};l(x),p.current=setTimeout(()=>{if(p.current=0,(x.x!==(N==null?void 0:N.x)||x.y!==(N==null?void 0:N.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),ne.emitMethod(se.MainEngine,Q.SetPoint,{workId:H,pointMap:t,workState:j.Doing,viewId:n==null?void 0:n.viewId})}},60)},C=(S,N)=>{n!=null&&n.control.worker.isBusy&&g(!0),w(S,N)};return y.createElement(bt,{disabled:d,position:c,onStart:I,onDrag:T,onStop:C},y.createElement("div",{className:"appliance-plugin-point-draggable-btn",style:f}))},dw=r=>{const{className:s}=r,{floatBarData:e,mananger:t}=y.useContext(ve),[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(ro,{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(ro,{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)},pw=y.forwardRef((r,s)=>{const{floatBarData:e,operationType:t}=y.useContext(ve),i=y.useMemo(()=>(e==null?void 0:e.scaleType)!==re.all||t===Q.RotateNode?null:y.createElement(nw,null),[e,t]),o=y.useMemo(()=>(e==null?void 0:e.scaleType)!==re.both||t===Q.RotateNode?null:y.createElement(rw,null),[e,t]),n=y.useMemo(()=>(e==null?void 0:e.scaleType)!==re.proportional||t===Q.RotateNode?null:y.createElement(aw,null),[e,t]),a=y.useMemo(()=>(e==null?void 0:e.scaleType)===re.none&&(e!=null&&e.canLock)?y.createElement(cw,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)}),gw=y.forwardRef((r,s)=>{const{floatBarData:e,operationType:t,mananger:i}=y.useContext(ve),{editors:o,isHide:n}=r,a=y.useMemo(()=>{var d;return e!=null&&e.canRotate&&((d=e==null?void 0:e.selectIds)==null?void 0:d.length)===1&&(t===Q.None||t===Q.RotateNode)?y.createElement(lw,{className:be.RotateBtn}):null},[e,t]),c=y.useMemo(()=>((e==null?void 0:e.scaleType)===re.all||(e==null?void 0:e.scaleType)===re.proportional)&&(t===Q.None||t===Q.ScaleNode)&&O.isNumber(e==null?void 0:e.x)&&O.isNumber(e==null?void 0:e.y)?y.createElement(uw,{className:be.ResizeBtn}):null,[e==null?void 0:e.scaleType,t,e==null?void 0:e.x,e==null?void 0:e.y]),l=y.useMemo(()=>(e==null?void 0:e.scaleType)===re.both&&(t===Q.None||t===Q.SetPoint)?y.createElement(dw,{className:be.ResizeTowBox}):null,[e==null?void 0:e.scaleType,t]),u=y.useMemo(()=>o?y.createElement(sw,{editors:o,selectIds:(e==null?void 0:e.selectIds)||[]}):null,[o,e]),h=y.useMemo(()=>n&&t===Q.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:be.FloatBarBtn,style:{left:e==null?void 0:e.x,top:e==null?void 0:e.y,width:e.w,height:e.h}},y.createElement(fn,{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:be.FloatBar,onPointerOver:d=>(d.stopPropagation(),d.nativeEvent.stopImmediatePropagation(),i==null||i.control.worker.blurCursor(i.viewId),!1)},y.createElement(pw,{ref:s},y.createElement(y.Fragment,null,u)),y.createElement(hw,null),a,c,l,h)}),fw=y.memo(gw,(r,s)=>!!O.isEqual(r,s));class Mw 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 oe.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:Yt.get("pencil"),alt:"pencilCursor"}))));case oe.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:Yt.get("selector"),alt:"selectorCursor"}))));case oe.eraser:case oe.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:Yt.get("eraser"),alt:"eraserCursor"}))));case oe.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:Yt.get("text"),alt:"textCursor"}))));case oe.rectangle:case oe.arrow:case oe.straight:case oe.shape:case oe.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:Yt.get("shape"),alt:"shapeCursor"}))));default:return null}}}const yw=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(Mw,{roomMember:t}))},mw=r=>{const{className:s,manager:e}=r,[t,i]=y.useState();y.useEffect(()=>(e.internalMsgEmitter.on([se.Cursor,e.viewId],o),()=>{e.internalMsgEmitter.off([se.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(yw,{key:(l=c.roomMember)==null?void 0:l.memberId,className:s,info:c}):null});return y.createElement(y.Fragment,null,a)}return null},[t])},ww=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],T=[h.centerX,h.centerY],C=[I[0]-T[0],I[1]-T[1]],S=Math.min(h.scale*f,h.scale*f),N=[C[0]*S,C[1]*S,m,w,S];a(N)},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,T]=[(h.nativeEvent.offsetX-m)/n[4],(h.nativeEvent.offsetY-w)/n[4]],C=i.maps.get(s);if(C!=null&&C.viewCamera){const[S,N]=[C.miniMapCamera.centerX+I,C.miniMapCamera.centerY+T];(d=i.control.room)==null||d.moveCamera({centerX:S,centerY:N,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"}}))},Iw=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 us.createPortal(y.createElement(ww,{viewId:e,...l,highlightColor:u,miniMapManager:s}),l.contianer)}}}return null},[e,s]);return y.createElement("div",{className:t},i)},ve=y.createContext({mananger:void 0,floatBarColors:[],floatBarData:void 0,dpr:1,angle:0,operationType:Q.None,scale:[1,1],isNoPointerEvents:!1,activeTextEditor:!1,activeTextId:void 0,setAngle:()=>{},setOperationType:()=>{},setFloatBarData:()=>{}});class di extends y.Component{constructor(e){var t,i;super(e);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:Q.None,scale:[1,1],editors:this.editors,activeTextId:(t=this.props.mananger.control.textEditorManager)==null?void 0:t.activeId,activeMiniMapViewId:(i=this.props.mananger.control.miniMapManager)==null?void 0:i.activeViewId}}get editors(){return ke(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:be.Container},!this.props.mananger.control.hasOffscreenCanvas()&&y.createElement("div",{className:be.CanvasBox,ref:this.props.refs.canvasContainerRef})||y.createElement("div",{className:be.CanvasBox},y.createElement("canvas",{id:"bgCanvas",ref:this.props.refs.canvasBgRef,style:{width:"100%",height:"100%"}}),y.createElement("canvas",{id:"serviceCanvas",className:be.FloatCanvas,ref:this.props.refs.canvasServiceFloatRef,style:{width:"100%",height:"100%"}}),y.createElement("canvas",{id:"localCanvas",className:be.FloatCanvas,ref:this.props.refs.canvasFloatRef,style:{width:"100%",height:"100%"}}),y.createElement("div",{id:"subLocalCanvas",className:be.CanvasBoxSub,ref:this.props.refs.subLocalCanvasContainerRef}),y.createElement("canvas",{id:"topCanvas",className:be.TopFloatCanvas,ref:this.props.refs.canvasTopRef,style:{width:"100%",height:"100%"}})),!this.props.mananger.control.hasOffscreenCanvas()&&this.props.refs.snapshotContainerRef&&y.createElement("div",{className:be.SnapshotBox,ref:this.props.refs.snapshotContainerRef})||null,y.createElement(ve.Provider,{value:{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(fw,{ref:this.props.refs.floatBarRef,editors:this.state.editors,isHide:e&&this.state.showFloatBarBtn})||null,((c=this.state.editors)==null?void 0:c.size)&&y.createElement(ow,{className:be.TextEditorContainer,showFloatBtns:e&&this.state.showFloatBarBtn,editors:this.state.editors})||null),y.createElement(mw,{className:be.CursorBox,manager:this.props.mananger}),y.createElement(Iw,{className:be.MiniMapBox,active:this.state.activeMiniMapViewId,miniMapManager:this.props.mananger.control.miniMapManager}))}}class vw extends pn{constructor(e,t){super(e,t);M(this,"width",1e3);M(this,"height",1e3);M(this,"dpr",it());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=it();this.canvasBgRef.current&&(i=it(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(),us.render(y.createElement(di,{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 Tw extends pm{constructor(e,t,i){super(e,t,i);M(this,"dpr",it());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=it();if(this.canvasBgRef.current&&(e=it(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(),us.render(y.createElement(di,{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 Ue extends Lt{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(ge,!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 vw(this.control,Se.InternalMsgEmitter),n=e.size.width||o.width,a=e.size.height||o.height,l={dpr:o.dpr,originalPoint:[n/2,a/2],offscreenCanvasOpt:{...Ue.defaultScreenCanvasOpt,width:n,height:a},layerOpt:{...Ue.defaultLayerOpt,width:n,height:a},cameraOpt:{...Ue.defaultCameraOpt,width:n,height:a}},{scale:u,...h}=e.camera;l.cameraOpt={...l.cameraOpt,...h,scale:u===1/0?1:u},this.createMianView({id:ge,container:t,displayer:o,focusScenePath:e.focusScenePath,cameraOpt:l.cameraOpt,viewData:e}),this.setFocuedViewId(ge),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 Tw(t,this.control,Se.InternalMsgEmitter),c=i.size.width||a.width,l=i.size.height||a.height,h={dpr:a.dpr,originalPoint:[c/2,l/2],offscreenCanvasOpt:{...Ue.defaultScreenCanvasOpt,width:c,height:l},layerOpt:{...Ue.defaultLayerOpt,width:c,height:l},cameraOpt:{...Ue.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&&(Ue.defaultScreenCanvasOpt.contextType=this.control.pluginOptions.canvasOpt.contextType);const c={dpr:a,originalPoint:[o/2,n/2],offscreenCanvasOpt:{...Ue.defaultScreenCanvasOpt,width:o,height:n},layerOpt:{...Ue.defaultLayerOpt,width:o,height:n},cameraOpt:{...Ue.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||ge;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,ge)}),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 rt extends Se{constructor(e){super(e);M(this,"windowManager");M(this,"viewContainerManager");const t={control:this,internalMsgEmitter:Se.InternalMsgEmitter,publicMsgEmitter:Se.PublicMsgEmitter};this.viewContainerManager=new Ue(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(ge,!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())Se.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 $.InvisiblePlugin{constructor(){super(...arguments);M(this,"onPhaseChanged",e=>{var t;e===$.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)),!($.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;$.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:ci(f,m)},screenshotToCanvasAsync:async function(p,f,m,w,I,T){var b;U.logger.info("[ApplianceMultiPlugin] screenshotToCanvasAsync");let C=m,S=w,N=I.scale;C>this.maxScreenshotWidth&&(N=this.maxScreenshotWidth/C*N,C=this.maxScreenshotWidth),S>this.maxScreenshotHeight&&(N=Math.min(this.maxScreenshotHeight/S*N,N),S=this.maxScreenshotHeight),I.scale=N;const x=document.createElement("canvas"),L=x.getContext("2d");x.width=C*(T||1),x.height=S*(T||1),L&&((e.mainView||i).screenshotToCanvas(L,f,C,S,I,T),p.drawImage(x,Math.floor((m-C)/2),Math.floor((w-S)/2),C*(T||1),S*(T||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 T=document.createElement("img");T.className="appliance-plugin-fill-scene-snapshot-img",f.append(T),getComputedStyle(f).position||(f.style.position="relative"),U.currentManager&&await U.currentManager.scenePreview(p,T)},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 T=m||e.mainView.size.width,C=w||e.mainView.size.height;let S=await this.getBoundingRectAsync(p);S||(S={originX:0,originY:0,width:T,height:C});let N=Math.max(S==null?void 0:S.width,T),x=Math.max(S==null?void 0:S.height,C),L=1;const b=N>T&&Math.min(T/N,L)||L,E=x>C&&Math.min(C/x,L)||L;b<=E?(N=b<1&&T||N,x=Math.floor(x*b)+1,L=b):b>E&&(x=E<1&&C||x,N=Math.floor(N*E)+1,L=E);const A={scale:L,centerX:S.originX+S.width/2,centerY:S.originY+S.height/2},P=document.createElement("canvas"),R=P.getContext("2d");P.width=N,P.height=x,R&&await this.screenshotToCanvasAsync(R,p,N,x,A,devicePixelRatio);const z=document.createElement("img");z.className="appliance-plugin-fill-scene-snapshot-img",z.src=P.toDataURL(),z.onload=()=>{P.remove()},z.onerror=()=>{P.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")&&$.isRoom(i)&&i.isWritable?rt.InternalMsgEmitter.on(p,f):o.call(i.callbacks,p,f)},_callbacksOnce:function(p,f){U.logger.info(`[ApplianceMultiPlugin] callbacks ${p}`),(p==="onCanUndoStepsUpdate"||p==="onCanRedoStepsUpdate")&&$.isRoom(i)&&i.isWritable?rt.InternalMsgEmitter.on(p,f):a.call(i.callbacks,p,f)},_callbacksOff:function(p,f){U.logger.info(`[ApplianceMultiPlugin] callbacks ${p}`),(p==="onCanUndoStepsUpdate"||p==="onCanRedoStepsUpdate")&&$.isRoom(i)&&i.isWritable?rt.InternalMsgEmitter.off(p,f):n.call(i.callbacks,p,f)},canRedoSteps(){if(U.logger.info("[ApplianceMultiPlugin] canRedoSteps"),U.currentManager&&$.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&&$.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&&$.isRoom(i)&&!i.disableSerialization?U.currentManager.viewContainerManager.undo():0},redo:function(){return U.logger.info("[ApplianceMultiPlugin] redo"),U.currentManager&&$.isRoom(i)&&!i.disableSerialization?U.currentManager.viewContainerManager.redo():0},cleanCurrentScene:function(){U.logger.info("[ApplianceMultiPlugin] cleanCurrentScene"),U.currentManager&&$.isRoom(i)&&i.isWritable&&(U.currentManager.cleanCurrentScene(),c.call(e))},insertImage:function(p){U.logger.info("[ApplianceMultiPlugin] insertImage"),U.currentManager&&$.isRoom(i)&&i.isWritable&&U.currentManager.worker.insertImage(ge,p)},lockImage:function(p,f){U.logger.info("[ApplianceMultiPlugin] lockImage"),U.currentManager&&$.isRoom(i)&&i.isWritable&&U.currentManager.worker.lockImage(ge,p,f)},completeImageUpload:function(p,f){U.logger.info("[ApplianceMultiPlugin] completeImageUpload"),U.currentManager&&$.isRoom(i)&&i.isWritable&&U.currentManager.worker.completeImageUpload(ge,p,f)},getImagesInformation:function(p){return U.logger.info("[ApplianceMultiPlugin] completeImageUpload"),U.currentManager&&$.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($.isRoom(i)&&i.isWritable){f.includes("currentApplianceName")&&(p.currentApplianceName&&p.currentApplianceName===oe.laserPen?(p.currentApplianceName=oe.pencil,p.useLaserPen=!0):p.currentApplianceName&&p.currentApplianceName===oe.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&&$.isRoom(i)&&i.isWritable)return U.currentManager.createMiniMap(p,f)},destroyMiniMap:async function(p){if(U.logger.info("[ApplianceMultiPlugin] destroyeMiniMap"),U.currentManager&&$.isRoom(i)&&i.isWritable)return U.currentManager.destroyMiniMap(p)},filterRenderByUid(p,f,m){if(U.logger.info("[ApplianceMultiPlugin] filterRenderByUid"),U.currentManager&&$.isRoom(i)&&i.isWritable)return U.currentManager.filterRenderByUid(p,f,m)},cancelFilterRender(p,f){if(U.logger.info("[ApplianceMultiPlugin] filterRenderByUid"),U.currentManager&&$.isRoom(i)&&i.isWritable)return U.currentManager.cancelFilterRender(p,f)},addListener:(p,f)=>{U.logger.info(`[ApplianceMultiPlugin] addListener ${p}`),rt.PublicMsgEmitter.on(p,f)},removeListener:(p,f)=>{U.logger.info(`[ApplianceMultiPlugin] removeListener ${p}`),rt.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&&$.isRoom(i))return U.currentManager.disableDeviceInputs},setDisableDeviceInputs(p){U.logger.info(`[ApplianceMultiPlugin] setDisableDeviceInputs ${p}`),U.currentManager&&$.isRoom(i)&&(U.currentManager.disableDeviceInputs=p)},getDisableCameraTransform(){if(U.currentManager&&$.isRoom(i))return U.currentManager.disableCameraTransform},setDisableCameraTransform(p){U.logger.info(`[ApplianceMultiPlugin] setDisableCameraTransform ${p}`),U.currentManager&&$.isRoom(i)&&(U.currentManager.disableCameraTransform=p)},getDisableEraseImage(){if(U.currentManager&&$.isRoom(i))return U.currentManager.disableEraseImage},setDisableEraseImage(p){U.logger.info(`[ApplianceMultiPlugin] setDisableEraseImage ${p}`),U.currentManager&&$.isRoom(i)&&(U.currentManager.disableEraseImage=p)},setWritable:async function(p){var f;U.logger.info(`[ApplianceMultiPlugin] setWritable ${p}`),$.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 T=new MessageChannel;let C;const S=N=>{try{p({didTimeout:N,timeRemaining:()=>{const L=performance.now()-w;return Math.max(0,m-L)}})}catch(x){U.logger.error("[ApplianceMultiPlugin] requestIdleCallback error:",x)}finally{T.port1.close(),T.port2.close(),I!==void 0&&cancelAnimationFrame(I),C!==void 0&&clearTimeout(C)}};return T.port1.onmessage=()=>{I=requestAnimationFrame(()=>{m>0&&performance.now()-w>=m?S(!0):S(!1)})},T.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"),$.isRoom(i)&&d.injectMethodToObject(i,"setWritable"),Object.defineProperty(e,"canUndoSteps",{get(){return d.canUndoSteps()}}),Object.defineProperty(e,"canRedoSteps",{get(){return d.canRedoSteps()}}),rt.InternalMsgEmitter.on("onCanUndoStepsUpdate",p=>{e.emitter.emit("canUndoStepsChange",p)}),rt.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 $.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),$.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 rt(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 Fs=U;class Nw extends pn{constructor(e,t){super(e,t);M(this,"width",1e3);M(this,"height",1e3);M(this,"dpr",it());M(this,"vDom");M(this,"viewId",ge);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=it();this.canvasBgRef.current&&(i=it(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="",us.render(y.createElement(di,{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 et extends Lt{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 Nw(this.control,Se.InternalMsgEmitter),{width:t,height:i,dpr:o}=e,n={dpr:o,originalPoint:[t/2,i/2],offscreenCanvasOpt:{...et.defaultScreenCanvasOpt,width:t,height:i},layerOpt:{...et.defaultLayerOpt,width:t,height:i},cameraOpt:{...et.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:ge,displayer:e,focusScenePath:a.focusScenePath||a.scenePath,cameraOpt:n.cameraOpt,viewData:a}),this.setFocuedViewId(ge),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&&(et.defaultScreenCanvasOpt.contextType=this.control.pluginOptions.canvasOpt.contextType);const c={dpr:a,originalPoint:[o/2,n/2],offscreenCanvasOpt:{...et.defaultScreenCanvasOpt,width:o,height:n},layerOpt:{...et.defaultLayerOpt,width:o,height:n},cameraOpt:{...et.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 Be extends Se{constructor(e){super(e);M(this,"viewContainerManager");M(this,"divMainView");M(this,"onCameraChange",hn(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)},ai,{leading:!1}));const t={control:this,internalMsgEmitter:Be.InternalMsgEmitter,publicMsgEmitter:Be.PublicMsgEmitter};this.viewContainerManager=new et(t)}init(){Be.InternalMsgEmitter.on(se.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(ge,!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())Se.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 $.InvisiblePlugin{constructor(){super(...arguments);M(this,"onPhaseChanged",e=>{var t;e===$.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 Be&&(e.cameraState&&W.currentManager.onCameraChange(e.cameraState),e.sceneState&&W.currentManager.onSceneChange(e.sceneState.scenePath,ge)),e!=null&&e.roomMembers&&((t=W.currentManager)==null||t.onRoomMembersChange(e.roomMembers)),!($.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;$.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:ci(p,f)},screenshotToCanvasAsync:async function(g,p,f,m,w,I){var L;W.logger.info("[ApplianceSinglePlugin] screenshotToCanvasAsync");let T=f,C=m,S=w.scale;T>this.maxScreenshotWidth&&(S=this.maxScreenshotWidth/T*S,T=this.maxScreenshotWidth),C>this.maxScreenshotHeight&&(S=Math.min(this.maxScreenshotHeight/C*S,S),C=this.maxScreenshotHeight),w.scale=S;const N=document.createElement("canvas"),x=N.getContext("2d");N.width=T*(I||1),N.height=C*(I||1),x&&(e.screenshotToCanvas(x,p,T,C,w,I),g.drawImage(N,Math.floor((f-T)/2),Math.floor((m-C)/2),T*(I||1),C*(I||1),0,0,T,C),N.remove()),W.currentManager&&await((L=W.currentManager)==null?void 0:L.screenshotToCanvas(g,p,T,C,w,Math.floor((f-T)/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,X;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,T=m||((X=e.state.cameraState)==null?void 0:X.height)||0;let C=await this.getBoundingRectAsync(g);C||(C={originX:0,originY:0,width:I,height:T});let S=Math.max(C==null?void 0:C.width,I),N=Math.max(C==null?void 0:C.height,T),x=1;const L=S>I&&Math.min(I/S,x)||x,b=N>T&&Math.min(T/N,x)||x;L<=b?(S=L<1&&I||S,N=Math.floor(N*L)+1,x=L):L>b&&(N=b<1&&T||N,S=Math.floor(S*b)+1,x=b);const E={scale:x,centerX:C.originX+C.width/2,centerY:C.originY+C.height/2},A=document.createElement("canvas"),P=A.getContext("2d");A.width=S,A.height=N,P&&await this.screenshotToCanvasAsync(P,g,S,N,E,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")&&$.isRoom(e)&&e.isWritable?Be.InternalMsgEmitter.on(g,p):i.call(e.callbacks,g,p)},_callbacksOnce:function(g,p){W.logger.info(`[ApplianceSinglePlugin] callbacks ${g}`),(g==="onCanUndoStepsUpdate"||g==="onCanRedoStepsUpdate")&&$.isRoom(e)&&e.isWritable?Be.InternalMsgEmitter.on(g,p):n.call(e.callbacks,g,p)},_callbacksOff:function(g,p){W.logger.info(`[ApplianceSinglePlugin] callbacks ${g}`),(g==="onCanUndoStepsUpdate"||g==="onCanRedoStepsUpdate")&&$.isRoom(e)&&e.isWritable?Be.InternalMsgEmitter.off(g,p):o.call(e.callbacks,g,p)},canRedoSteps(){if(W.logger.info("[ApplianceSinglePlugin] canRedoSteps"),W.currentManager&&$.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&&$.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&&$.isRoom(e)&&!e.disableSerialization?W.currentManager.viewContainerManager.undo():0},redo:function(){return W.logger.info("[ApplianceSinglePlugin] redo"),W.currentManager&&$.isRoom(e)&&!e.disableSerialization?W.currentManager.viewContainerManager.redo():0},cleanCurrentScene:function(g){W.logger.info("[ApplianceSinglePlugin] cleanCurrentScene"),W.currentManager&&$.isRoom(e)&&e.isWritable&&(W.currentManager.cleanCurrentScene(),a.call(e,g))},insertImage:function(g){W.logger.info("[ApplianceSinglePlugin] insertImage"),W.currentManager&&$.isRoom(e)&&e.isWritable&&W.currentManager.worker.insertImage(ge,g)},lockImage:function(g,p){W.logger.info("[ApplianceSinglePlugin] lockImage"),W.currentManager&&$.isRoom(e)&&e.isWritable&&W.currentManager.worker.lockImage(ge,g,p)},completeImageUpload:function(g,p){W.logger.info("[ApplianceSinglePlugin] completeImageUpload"),W.currentManager&&$.isRoom(e)&&e.isWritable&&W.currentManager.worker.completeImageUpload(ge,g,p)},getImagesInformation:function(g){return W.logger.info("[ApplianceSinglePlugin] completeImageUpload"),W.currentManager&&$.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($.isRoom(e)&&e.isWritable){p.includes("currentApplianceName")&&(g.currentApplianceName&&g.currentApplianceName===oe.laserPen?(g.currentApplianceName=oe.pencil,g.useLaserPen=!0):g.currentApplianceName&&g.currentApplianceName===oe.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&&$.isRoom(e)&&e.isWritable)return W.currentManager.createMiniMap(g,p)},destroyMiniMap:async function(g){if(W.logger.info("[ApplianceMultiPlugin] destroyeMiniMap"),W.currentManager&&$.isRoom(e)&&e.isWritable)return W.currentManager.destroyMiniMap(g)},filterRenderByUid(g,p,f){if(W.logger.info("[ApplianceSinglePlugin] filterRenderByUid"),W.currentManager&&$.isRoom(e)&&e.isWritable)return W.currentManager.filterRenderByUid(g,p,f)},cancelFilterRender(g,p){if(W.logger.info("[ApplianceSinglePlugin] filterRenderByUid"),W.currentManager&&$.isRoom(e)&&e.isWritable)return W.currentManager.cancelFilterRender(g,p)},addListener:(g,p)=>{W.logger.info(`[ApplianceSinglePlugin] addListener ${g}`),Be.PublicMsgEmitter.on(g,p)},removeListener:(g,p)=>{W.logger.info(`[ApplianceSinglePlugin] removeListener ${g}`),Be.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&&$.isRoom(e))return W.currentManager.disableDeviceInputs},setDisableDeviceInputs(g){W.logger.info(`[ApplianceSinglePlugin] setDisableDeviceInputs ${g}`),W.currentManager&&$.isRoom(e)&&(W.currentManager.disableDeviceInputs=g)},getDisableCameraTransform(){if(W.currentManager&&$.isRoom(e))return W.currentManager.disableCameraTransform},setDisableCameraTransform(g){W.logger.info(`[ApplianceSinglePlugin] setDisableCameraTransform ${g}`),W.currentManager&&$.isRoom(e)&&(W.currentManager.disableCameraTransform=g)},getDisableEraseImage(){if(W.currentManager&&$.isRoom(e))return W.currentManager.disableEraseImage},setDisableEraseImage(g){W.logger.info(`[ApplianceSinglePlugin] setDisableEraseImage ${g}`),W.currentManager&&$.isRoom(e)&&(W.currentManager.disableEraseImage=g)},setWritable:async function(g){var p;W.logger.info(`[ApplianceSinglePlugin] setWritable ${g}`),$.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 T;const C=S=>{try{g({didTimeout:S,timeRemaining:()=>{const x=performance.now()-m;return Math.max(0,f-x)}})}catch(N){W.logger.error("[ApplianceSinglePlugin] requestIdleCallback error:",N)}finally{I.port1.close(),I.port2.close(),w!==void 0&&cancelAnimationFrame(w),T!==void 0&&clearTimeout(T)}};return I.port1.onmessage=()=>{w=requestAnimationFrame(()=>{f>0&&performance.now()-m>=f?C(!0):C(!1)})},I.port2.postMessage(null),f>0&&(T=setTimeout(()=>{C(!0)},f)),T||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"),$.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===oe.pencil||i.appliance===oe.shape||i.appliance===oe.text||i.appliance===oe.arrow||i.appliance===oe.straight||i.appliance===oe.rectangle||i.appliance===oe.ellipse||i.appliance===oe.eraser||i.appliance===oe.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 $.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),$.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 Be(o);if(n.init(),W.logger.info("[ApplianceSinglePlugin] refresh ApplianceSingleManager object"),W.currentManager=n,$.isRoom(e)){const a=n.hasOffscreenCanvas();e.logger.info(`[ApplianceSinglePlugin] use ${a?"worker":"mainThread"}`)}});let Qs=W;const Dt=class Dt extends y.Component{constructor(){super(...arguments);M(this,"mainViewRef",null)}componentDidMount(){Dt.emiter||(Dt.emiter=Be.InternalMsgEmitter),Dt.emiter.emit(se.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(Dt,"emiter");let Vs=Dt;class Sw extends un{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",ge);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===v.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)===v.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=he(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)===v.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=co;exports.ApplianceMultiPlugin=Fs;exports.ApplianceNames=oe;exports.ApplianceSigleWrapper=Vs;exports.ApplianceSinglePlugin=Qs;exports.AutoDrawPlugin=Sw;exports.Cursor_Hover_Id=uf;exports.DefaultAppliancePluginOptions=Ie;exports.ECanvasShowType=ye;exports.EDataType=B;exports.EForceStopReason=ds;exports.EImageType=Mt;exports.EMatrixrRelationType=ft;exports.EOperationType=je;exports.EPostMessageType=D;exports.ERenderFilterType=He;exports.EScaleType=re;exports.EStrokeType=te;exports.EToolsKey=v;exports.ElayerType=Ft;exports.EmitEventType=Q;exports.EventMessageType=Bt;exports.EvevtWorkState=j;exports.EvevtWorkType=lo;exports.InternalMsgEmitterType=se;exports.Main_View_Id=ge;exports.Plugin=un;exports.ShapeType=Ve;exports.Storage_Selector_key=H;exports.Storage_Splitter=Oe;exports.Storage_ViewId_ALL=Kt;exports.Task_Time_Interval=ai;exports.VNodeManager=en;exports.ViewContainerManager=Lt;exports.computRect=he;exports.fullWorker=wn;exports.getRectMatrixrRelation=ui;exports.getShapeInstance=vs;exports.isEqual=tt;exports.isIntersectForPoint=cn;exports.isNumber=De;exports.removeAllChildren=Pe;exports.removeTexture=Re;exports.subWorker=In;exports.transformToNormalData=wt;exports.transformToSerializableData=We;
1
+ "use strict";var Mn=Object.defineProperty;var yn=(r,s,e)=>s in r?Mn(r,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[s]=e;var M=(r,s,e)=>yn(r,typeof s!="symbol"?s+"":s,e);const $=require("white-web-sdk"),ae=require("spritejs"),ao=require("lz-string"),$e=require("clipper-lib"),Zs=require("lineclip"),As=require("eventemitter2"),O=require("lodash"),y=require("react"),us=require("react-dom"),bt=require("react-draggable"),mn=require("re-resizable"),wn="/fullWorker.js",In="/subWorker.js";var oe=(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))(oe||{}),te=(r=>(r.Normal="Normal",r.Stroke="Stroke",r.Dotted="Dotted",r.LongDotted="LongDotted",r))(te||{}),Ve=(r=>(r.Triangle="triangle",r.Rhombus="rhombus",r.Pentagram="pentagram",r.SpeechBalloon="speechBalloon",r.Star="star",r.Polygon="polygon",r))(Ve||{}),Q=(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))(Q||{}),se=(r=>(r.DisplayState="DisplayState",r.MainEngine="MainEngine",r.Cursor="Cursor",r.BindMainView="BindMainView",r))(se||{}),co=(r=>(r[r.MainView=0]="MainView",r[r.Plugin=1]="Plugin",r[r.Both=2]="Both",r))(co||{}),ds=(r=>(r.longPencil="longPencil",r))(ds||{}),v=(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))(v||{}),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||{}),ye=(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))(ye||{}),Bt=(r=>(r[r.Cursor=1]="Cursor",r[r.TextCreate=2]="TextCreate",r))(Bt||{}),Ft=(r=>(r[r.Top=1]="Top",r[r.Bottom=2]="Bottom",r))(Ft||{}),re=(r=>(r[r.none=1]="none",r[r.all=2]="all",r[r.both=3]="both",r[r.proportional=4]="proportional",r))(re||{}),lo=(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))(lo||{}),ft=(r=>(r[r.inside=0]="inside",r[r.outside=1]="outside",r[r.intersect=2]="intersect",r))(ft||{}),je=(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))(je||{}),He=(r=>(r.setAuth="setAuth",r.setShow="addShow",r.setHide="setHide",r.setClear="setClear",r))(He||{}),Mt=(r=>(r.Image="image",r.Iconify="iconify",r))(Mt||{});const vn={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=vn.easeInQuad(o/(t-1)),a=k.Lrp(s,e,n);a.z=Math.min(1,.5+Math.abs(.5-Tn(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 Tn=r=>r<.5?2*r*r:-1+(4-2*r)*r;class Z 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 Z(s,e,t,a,o,n)}distance(s){return Z.GetDistance(this,s)}isNear(s,e){return Z.IsNear(this,s,e)}getAngleByPoints(s,e){return Z.GetAngleByPoints(s,this,e)}static Sub(s,e){return new Z(s.x-e.x,s.y-e.y)}static Add(s,e){return new Z(s.x+e.x,s.y+e.y)}static GetDistance(s,e){return Z.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 Z.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 Z(u,h)}static GetDotStroke(s,e,t=16){const i=new k(1,1),o=Math.PI+.001,n=Z.Add(s,Z.Sub(s,i).uni().per().mul(-e)),a=[];for(let c=1/t,l=c;l<=1;l+=c)a.push(Z.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(Z.RotWith(e,s,o*c));return n}}var $t=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function jt(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var Nn=typeof $t=="object"&&$t&&$t.Object===Object&&$t,ho=Nn,Sn=ho,Cn=typeof self=="object"&&self&&self.Object===Object&&self,kn=Sn||Cn||Function("return this")(),Ge=kn,Dn=Ge,xn=Dn.Symbol,Zt=xn,pi=Zt,uo=Object.prototype,Ln=uo.hasOwnProperty,bn=uo.toString,Wt=pi?pi.toStringTag:void 0;function jn(r){var s=Ln.call(r,Wt),e=r[Wt];try{r[Wt]=void 0;var t=!0}catch{}var i=bn.call(r);return t&&(s?r[Wt]=e:delete r[Wt]),i}var An=jn,zn=Object.prototype,Pn=zn.toString;function En(r){return Pn.call(r)}var On=En,gi=Zt,Rn=An,Wn=On,Yn="[object Null]",Un="[object Undefined]",fi=gi?gi.toStringTag:void 0;function Bn(r){return r==null?r===void 0?Un:Yn:fi&&fi in Object(r)?Rn(r):Wn(r)}var yt=Bn;function Fn(r){return r!=null&&typeof r=="object"}var Ke=Fn,Qn=yt,Vn=Ke,Zn="[object Number]";function Hn(r){return typeof r=="number"||Vn(r)&&Qn(r)==Zn}var Gn=Hn;const De=jt(Gn);function $n(){this.__data__=[],this.size=0}var Xn=$n;function Jn(r,s){return r===s||r!==r&&s!==s}var Hs=Jn,qn=Hs;function Kn(r,s){for(var e=r.length;e--;)if(qn(r[e][0],s))return e;return-1}var ps=Kn,_n=ps,er=Array.prototype,tr=er.splice;function sr(r){var s=this.__data__,e=_n(s,r);if(e<0)return!1;var t=s.length-1;return e==t?s.pop():tr.call(s,e,1),--this.size,!0}var ir=sr,or=ps;function nr(r){var s=this.__data__,e=or(s,r);return e<0?void 0:s[e][1]}var rr=nr,ar=ps;function cr(r){return ar(this.__data__,r)>-1}var lr=cr,hr=ps;function ur(r,s){var e=this.__data__,t=hr(e,r);return t<0?(++this.size,e.push([r,s])):e[t][1]=s,this}var dr=ur,pr=Xn,gr=ir,fr=rr,Mr=lr,yr=dr;function At(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])}}At.prototype.clear=pr;At.prototype.delete=gr;At.prototype.get=fr;At.prototype.has=Mr;At.prototype.set=yr;var gs=At,mr=gs;function wr(){this.__data__=new mr,this.size=0}var Ir=wr;function vr(r){var s=this.__data__,e=s.delete(r);return this.size=s.size,e}var Tr=vr;function Nr(r){return this.__data__.get(r)}var Sr=Nr;function Cr(r){return this.__data__.has(r)}var kr=Cr;function Dr(r){var s=typeof r;return r!=null&&(s=="object"||s=="function")}var lt=Dr,xr=yt,Lr=lt,br="[object AsyncFunction]",jr="[object Function]",Ar="[object GeneratorFunction]",zr="[object Proxy]";function Pr(r){if(!Lr(r))return!1;var s=xr(r);return s==jr||s==Ar||s==br||s==zr}var po=Pr,Er=Ge,Or=Er["__core-js_shared__"],Rr=Or,ks=Rr,Mi=function(){var r=/[^.]+$/.exec(ks&&ks.keys&&ks.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""}();function Wr(r){return!!Mi&&Mi in r}var Yr=Wr,Ur=Function.prototype,Br=Ur.toString;function Fr(r){if(r!=null){try{return Br.call(r)}catch{}try{return r+""}catch{}}return""}var go=Fr,Qr=po,Vr=Yr,Zr=lt,Hr=go,Gr=/[\\^$.*+?()[\]{}|]/g,$r=/^\[object .+?Constructor\]$/,Xr=Function.prototype,Jr=Object.prototype,qr=Xr.toString,Kr=Jr.hasOwnProperty,_r=RegExp("^"+qr.call(Kr).replace(Gr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function ea(r){if(!Zr(r)||Vr(r))return!1;var s=Qr(r)?_r:$r;return s.test(Hr(r))}var ta=ea;function sa(r,s){return r==null?void 0:r[s]}var ia=sa,oa=ta,na=ia;function ra(r,s){var e=na(r,s);return oa(e)?e:void 0}var mt=ra,aa=mt,ca=Ge,la=aa(ca,"Map"),Gs=la,ha=mt,ua=ha(Object,"create"),fs=ua,yi=fs;function da(){this.__data__=yi?yi(null):{},this.size=0}var pa=da;function ga(r){var s=this.has(r)&&delete this.__data__[r];return this.size-=s?1:0,s}var fa=ga,Ma=fs,ya="__lodash_hash_undefined__",ma=Object.prototype,wa=ma.hasOwnProperty;function Ia(r){var s=this.__data__;if(Ma){var e=s[r];return e===ya?void 0:e}return wa.call(s,r)?s[r]:void 0}var va=Ia,Ta=fs,Na=Object.prototype,Sa=Na.hasOwnProperty;function Ca(r){var s=this.__data__;return Ta?s[r]!==void 0:Sa.call(s,r)}var ka=Ca,Da=fs,xa="__lodash_hash_undefined__";function La(r,s){var e=this.__data__;return this.size+=this.has(r)?0:1,e[r]=Da&&s===void 0?xa:s,this}var ba=La,ja=pa,Aa=fa,za=va,Pa=ka,Ea=ba;function zt(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])}}zt.prototype.clear=ja;zt.prototype.delete=Aa;zt.prototype.get=za;zt.prototype.has=Pa;zt.prototype.set=Ea;var Oa=zt,mi=Oa,Ra=gs,Wa=Gs;function Ya(){this.size=0,this.__data__={hash:new mi,map:new(Wa||Ra),string:new mi}}var Ua=Ya;function Ba(r){var s=typeof r;return s=="string"||s=="number"||s=="symbol"||s=="boolean"?r!=="__proto__":r===null}var Fa=Ba,Qa=Fa;function Va(r,s){var e=r.__data__;return Qa(s)?e[typeof s=="string"?"string":"hash"]:e.map}var Ms=Va,Za=Ms;function Ha(r){var s=Za(this,r).delete(r);return this.size-=s?1:0,s}var Ga=Ha,$a=Ms;function Xa(r){return $a(this,r).get(r)}var Ja=Xa,qa=Ms;function Ka(r){return qa(this,r).has(r)}var _a=Ka,ec=Ms;function tc(r,s){var e=ec(this,r),t=e.size;return e.set(r,s),this.size+=e.size==t?0:1,this}var sc=tc,ic=Ua,oc=Ga,nc=Ja,rc=_a,ac=sc;function Pt(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])}}Pt.prototype.clear=ic;Pt.prototype.delete=oc;Pt.prototype.get=nc;Pt.prototype.has=rc;Pt.prototype.set=ac;var fo=Pt,cc=gs,lc=Gs,hc=fo,uc=200;function dc(r,s){var e=this.__data__;if(e instanceof cc){var t=e.__data__;if(!lc||t.length<uc-1)return t.push([r,s]),this.size=++e.size,this;e=this.__data__=new hc(t)}return e.set(r,s),this.size=e.size,this}var pc=dc,gc=gs,fc=Ir,Mc=Tr,yc=Sr,mc=kr,wc=pc;function Et(r){var s=this.__data__=new gc(r);this.size=s.size}Et.prototype.clear=fc;Et.prototype.delete=Mc;Et.prototype.get=yc;Et.prototype.has=mc;Et.prototype.set=wc;var Mo=Et;function Ic(r,s){for(var e=-1,t=r==null?0:r.length;++e<t&&s(r[e],e,r)!==!1;);return r}var vc=Ic,Tc=mt,Nc=function(){try{var r=Tc(Object,"defineProperty");return r({},"",{}),r}catch{}}(),yo=Nc,wi=yo;function Sc(r,s,e){s=="__proto__"&&wi?wi(r,s,{configurable:!0,enumerable:!0,value:e,writable:!0}):r[s]=e}var mo=Sc,Cc=mo,kc=Hs,Dc=Object.prototype,xc=Dc.hasOwnProperty;function Lc(r,s,e){var t=r[s];(!(xc.call(r,s)&&kc(t,e))||e===void 0&&!(s in r))&&Cc(r,s,e)}var wo=Lc,bc=wo,jc=mo;function Ac(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?jc(e,a,c):bc(e,a,c)}return e}var ys=Ac;function zc(r,s){for(var e=-1,t=Array(r);++e<r;)t[e]=s(e);return t}var Pc=zc,Ec=yt,Oc=Ke,Rc="[object Arguments]";function Wc(r){return Oc(r)&&Ec(r)==Rc}var Yc=Wc,Ii=Yc,Uc=Ke,Io=Object.prototype,Bc=Io.hasOwnProperty,Fc=Io.propertyIsEnumerable,Qc=Ii(function(){return arguments}())?Ii:function(r){return Uc(r)&&Bc.call(r,"callee")&&!Fc.call(r,"callee")},vo=Qc,Vc=Array.isArray,Ht=Vc,_t={exports:{}};function Zc(){return!1}var Hc=Zc;_t.exports;(function(r,s){var e=Ge,t=Hc,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})(_t,_t.exports);var $s=_t.exports,Gc=9007199254740991,$c=/^(?:0|[1-9]\d*)$/;function Xc(r,s){var e=typeof r;return s=s??Gc,!!s&&(e=="number"||e!="symbol"&&$c.test(r))&&r>-1&&r%1==0&&r<s}var Jc=Xc,qc=9007199254740991;function Kc(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=qc}var To=Kc,_c=yt,el=To,tl=Ke,sl="[object Arguments]",il="[object Array]",ol="[object Boolean]",nl="[object Date]",rl="[object Error]",al="[object Function]",cl="[object Map]",ll="[object Number]",hl="[object Object]",ul="[object RegExp]",dl="[object Set]",pl="[object String]",gl="[object WeakMap]",fl="[object ArrayBuffer]",Ml="[object DataView]",yl="[object Float32Array]",ml="[object Float64Array]",wl="[object Int8Array]",Il="[object Int16Array]",vl="[object Int32Array]",Tl="[object Uint8Array]",Nl="[object Uint8ClampedArray]",Sl="[object Uint16Array]",Cl="[object Uint32Array]",we={};we[yl]=we[ml]=we[wl]=we[Il]=we[vl]=we[Tl]=we[Nl]=we[Sl]=we[Cl]=!0;we[sl]=we[il]=we[fl]=we[ol]=we[Ml]=we[nl]=we[rl]=we[al]=we[cl]=we[ll]=we[hl]=we[ul]=we[dl]=we[pl]=we[gl]=!1;function kl(r){return tl(r)&&el(r.length)&&!!we[_c(r)]}var Dl=kl;function xl(r){return function(s){return r(s)}}var ms=xl,es={exports:{}};es.exports;(function(r,s){var e=ho,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})(es,es.exports);var Xs=es.exports,Ll=Dl,bl=ms,vi=Xs,Ti=vi&&vi.isTypedArray,jl=Ti?bl(Ti):Ll,No=jl,Al=Pc,zl=vo,Pl=Ht,El=$s,Ol=Jc,Rl=No,Wl=Object.prototype,Yl=Wl.hasOwnProperty;function Ul(r,s){var e=Pl(r),t=!e&&zl(r),i=!e&&!t&&El(r),o=!e&&!t&&!i&&Rl(r),n=e||t||i||o,a=n?Al(r.length,String):[],c=a.length;for(var l in r)(s||Yl.call(r,l))&&!(n&&(l=="length"||i&&(l=="offset"||l=="parent")||o&&(l=="buffer"||l=="byteLength"||l=="byteOffset")||Ol(l,c)))&&a.push(l);return a}var So=Ul,Bl=Object.prototype;function Fl(r){var s=r&&r.constructor,e=typeof s=="function"&&s.prototype||Bl;return r===e}var Js=Fl;function Ql(r,s){return function(e){return r(s(e))}}var Co=Ql,Vl=Co,Zl=Vl(Object.keys,Object),Hl=Zl,Gl=Js,$l=Hl,Xl=Object.prototype,Jl=Xl.hasOwnProperty;function ql(r){if(!Gl(r))return $l(r);var s=[];for(var e in Object(r))Jl.call(r,e)&&e!="constructor"&&s.push(e);return s}var Kl=ql,_l=po,eh=To;function th(r){return r!=null&&eh(r.length)&&!_l(r)}var qs=th,sh=So,ih=Kl,oh=qs;function nh(r){return oh(r)?sh(r):ih(r)}var Ks=nh,rh=ys,ah=Ks;function ch(r,s){return r&&rh(s,ah(s),r)}var lh=ch;function hh(r){var s=[];if(r!=null)for(var e in Object(r))s.push(e);return s}var uh=hh,dh=lt,ph=Js,gh=uh,fh=Object.prototype,Mh=fh.hasOwnProperty;function yh(r){if(!dh(r))return gh(r);var s=ph(r),e=[];for(var t in r)t=="constructor"&&(s||!Mh.call(r,t))||e.push(t);return e}var mh=yh,wh=So,Ih=mh,vh=qs;function Th(r){return vh(r)?wh(r,!0):Ih(r)}var _s=Th,Nh=ys,Sh=_s;function Ch(r,s){return r&&Nh(s,Sh(s),r)}var kh=Ch,ts={exports:{}};ts.exports;(function(r,s){var e=Ge,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})(ts,ts.exports);var Dh=ts.exports;function xh(r,s){var e=-1,t=r.length;for(s||(s=Array(t));++e<t;)s[e]=r[e];return s}var Lh=xh;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 ko=bh;function jh(){return[]}var Do=jh,Ah=ko,zh=Do,Ph=Object.prototype,Eh=Ph.propertyIsEnumerable,Ni=Object.getOwnPropertySymbols,Oh=Ni?function(r){return r==null?[]:(r=Object(r),Ah(Ni(r),function(s){return Eh.call(r,s)}))}:zh,ei=Oh,Rh=ys,Wh=ei;function Yh(r,s){return Rh(r,Wh(r),s)}var Uh=Yh;function Bh(r,s){for(var e=-1,t=s.length,i=r.length;++e<t;)r[i+e]=s[e];return r}var ti=Bh,Fh=Co,Qh=Fh(Object.getPrototypeOf,Object),xo=Qh,Vh=ti,Zh=xo,Hh=ei,Gh=Do,$h=Object.getOwnPropertySymbols,Xh=$h?function(r){for(var s=[];r;)Vh(s,Hh(r)),r=Zh(r);return s}:Gh,Lo=Xh,Jh=ys,qh=Lo;function Kh(r,s){return Jh(r,qh(r),s)}var _h=Kh,eu=ti,tu=Ht;function su(r,s,e){var t=s(r);return tu(r)?t:eu(t,e(r))}var bo=su,iu=bo,ou=ei,nu=Ks;function ru(r){return iu(r,nu,ou)}var jo=ru,au=bo,cu=Lo,lu=_s;function hu(r){return au(r,lu,cu)}var uu=hu,du=mt,pu=Ge,gu=du(pu,"DataView"),fu=gu,Mu=mt,yu=Ge,mu=Mu(yu,"Promise"),wu=mu,Iu=mt,vu=Ge,Tu=Iu(vu,"Set"),Ao=Tu,Nu=mt,Su=Ge,Cu=Nu(Su,"WeakMap"),ku=Cu,zs=fu,Ps=Gs,Es=wu,Os=Ao,Rs=ku,zo=yt,Ot=go,Si="[object Map]",Du="[object Object]",Ci="[object Promise]",ki="[object Set]",Di="[object WeakMap]",xi="[object DataView]",xu=Ot(zs),Lu=Ot(Ps),bu=Ot(Es),ju=Ot(Os),Au=Ot(Rs),ht=zo;(zs&&ht(new zs(new ArrayBuffer(1)))!=xi||Ps&&ht(new Ps)!=Si||Es&&ht(Es.resolve())!=Ci||Os&&ht(new Os)!=ki||Rs&&ht(new Rs)!=Di)&&(ht=function(r){var s=zo(r),e=s==Du?r.constructor:void 0,t=e?Ot(e):"";if(t)switch(t){case xu:return xi;case Lu:return Si;case bu:return Ci;case ju:return ki;case Au:return Di}return s});var ws=ht,zu=Object.prototype,Pu=zu.hasOwnProperty;function Eu(r){var s=r.length,e=new r.constructor(s);return s&&typeof r[0]=="string"&&Pu.call(r,"index")&&(e.index=r.index,e.input=r.input),e}var Ou=Eu,Ru=Ge,Wu=Ru.Uint8Array,Po=Wu,Li=Po;function Yu(r){var s=new r.constructor(r.byteLength);return new Li(s).set(new Li(r)),s}var si=Yu,Uu=si;function Bu(r,s){var e=s?Uu(r.buffer):r.buffer;return new r.constructor(e,r.byteOffset,r.byteLength)}var Fu=Bu,Qu=/\w*$/;function Vu(r){var s=new r.constructor(r.source,Qu.exec(r));return s.lastIndex=r.lastIndex,s}var Zu=Vu,bi=Zt,ji=bi?bi.prototype:void 0,Ai=ji?ji.valueOf:void 0;function Hu(r){return Ai?Object(Ai.call(r)):{}}var Gu=Hu,$u=si;function Xu(r,s){var e=s?$u(r.buffer):r.buffer;return new r.constructor(e,r.byteOffset,r.length)}var Ju=Xu,qu=si,Ku=Fu,_u=Zu,ed=Gu,td=Ju,sd="[object Boolean]",id="[object Date]",od="[object Map]",nd="[object Number]",rd="[object RegExp]",ad="[object Set]",cd="[object String]",ld="[object Symbol]",hd="[object ArrayBuffer]",ud="[object DataView]",dd="[object Float32Array]",pd="[object Float64Array]",gd="[object Int8Array]",fd="[object Int16Array]",Md="[object Int32Array]",yd="[object Uint8Array]",md="[object Uint8ClampedArray]",wd="[object Uint16Array]",Id="[object Uint32Array]";function vd(r,s,e){var t=r.constructor;switch(s){case hd:return qu(r);case sd:case id:return new t(+r);case ud:return Ku(r,e);case dd:case pd:case gd:case fd:case Md:case yd:case md:case wd:case Id:return td(r,e);case od:return new t;case nd:case cd:return new t(r);case rd:return _u(r);case ad:return new t;case ld:return ed(r)}}var Td=vd,Nd=lt,zi=Object.create,Sd=function(){function r(){}return function(s){if(!Nd(s))return{};if(zi)return zi(s);r.prototype=s;var e=new r;return r.prototype=void 0,e}}(),Cd=Sd,kd=Cd,Dd=xo,xd=Js;function Ld(r){return typeof r.constructor=="function"&&!xd(r)?kd(Dd(r)):{}}var bd=Ld,jd=ws,Ad=Ke,zd="[object Map]";function Pd(r){return Ad(r)&&jd(r)==zd}var Ed=Pd,Od=Ed,Rd=ms,Pi=Xs,Ei=Pi&&Pi.isMap,Wd=Ei?Rd(Ei):Od,Yd=Wd,Ud=ws,Bd=Ke,Fd="[object Set]";function Qd(r){return Bd(r)&&Ud(r)==Fd}var Vd=Qd,Zd=Vd,Hd=ms,Oi=Xs,Ri=Oi&&Oi.isSet,Gd=Ri?Hd(Ri):Zd,Eo=Gd;const $d=jt(Eo);var Xd=Mo,Jd=vc,qd=wo,Kd=lh,_d=kh,ep=Dh,tp=Lh,sp=Uh,ip=_h,op=jo,np=uu,rp=ws,ap=Ou,cp=Td,lp=bd,hp=Ht,up=$s,dp=Yd,pp=lt,gp=Eo,fp=Ks,Mp=_s,yp=1,mp=2,wp=4,Oo="[object Arguments]",Ip="[object Array]",vp="[object Boolean]",Tp="[object Date]",Np="[object Error]",Ro="[object Function]",Sp="[object GeneratorFunction]",Cp="[object Map]",kp="[object Number]",Wo="[object Object]",Dp="[object RegExp]",xp="[object Set]",Lp="[object String]",bp="[object Symbol]",jp="[object WeakMap]",Ap="[object ArrayBuffer]",zp="[object DataView]",Pp="[object Float32Array]",Ep="[object Float64Array]",Op="[object Int8Array]",Rp="[object Int16Array]",Wp="[object Int32Array]",Yp="[object Uint8Array]",Up="[object Uint8ClampedArray]",Bp="[object Uint16Array]",Fp="[object Uint32Array]",me={};me[Oo]=me[Ip]=me[Ap]=me[zp]=me[vp]=me[Tp]=me[Pp]=me[Ep]=me[Op]=me[Rp]=me[Wp]=me[Cp]=me[kp]=me[Wo]=me[Dp]=me[xp]=me[Lp]=me[bp]=me[Yp]=me[Up]=me[Bp]=me[Fp]=!0;me[Np]=me[Ro]=me[jp]=!1;function qt(r,s,e,t,i,o){var n,a=s&yp,c=s&mp,l=s&wp;if(e&&(n=i?e(r,t,i,o):e(r)),n!==void 0)return n;if(!pp(r))return r;var u=hp(r);if(u){if(n=ap(r),!a)return tp(r,n)}else{var h=rp(r),d=h==Ro||h==Sp;if(up(r))return ep(r,a);if(h==Wo||h==Oo||d&&!i){if(n=c||d?{}:lp(r),!a)return c?ip(r,_d(n,r)):sp(r,Kd(n,r))}else{if(!me[h])return i?r:{};n=cp(r,h,a)}}o||(o=new Xd);var g=o.get(r);if(g)return g;o.set(r,n),gp(r)?r.forEach(function(m){n.add(qt(m,s,e,m,r,o))}):dp(r)&&r.forEach(function(m,w){n.set(w,qt(m,s,e,w,r,o))});var p=l?c?np:op:c?Mp:fp,f=u?void 0:p(r);return Jd(f||r,function(m,w){f&&(w=m,m=r[w]),qd(n,w,qt(m,s,e,w,r,o))}),n}var Qp=qt,Vp=Qp,Zp=1,Hp=4;function Gp(r){return Vp(r,Zp|Hp)}var $p=Gp;const ke=jt($p),Yo="1.1.17-beta.14",Xp="@netless/appliance-plugin",Wi=typeof OffscreenCanvas=="function"?"worker":"mainThread";if(typeof window<"u"){let r=window.__netlessUA||"";r+=` ${Xp}@${Yo}`,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}};function Je(r,s=!0){const e=r.length;if(e<2)return"";let t=r[0],i=r[1];if(e===2)return`M${It(t)}L${It(i)}`;let o="";for(let n=2,a=e-1;n<a;n++)t=r[n],i=r[n+1],o+=vt(t,i);return s?`M${vt(r[0],r[1])}Q${It(r[1])}${vt(r[1],r[2])}T${o}${vt(r[e-1],r[0])}${vt(r[0],r[1])}Z`:`M${It(r[0])}Q${It(r[1])}${vt(r[1],r[2])}${r.length>3?"T":""}${o}L${It(r[e-1])}`}const Ye=class Ye{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={};De(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=he(e,{x:Math.floor(p.x-Ye.SafeBorderPadding),y:Math.floor(p.y-Ye.SafeBorderPadding),w:Math.floor(p.width+Ye.SafeBorderPadding*2),h:Math.floor(p.height+Ye.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)return;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 T=w.parent;T.render();const C=w.renderer.canvasRenderer,S=C.context;if(!S)return;const N=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(ui(L,b)===ft.outside){Pe(I,T),f.removeChild(T),this.isDelete=!0;return}const A=ke(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 P=this.getGroupRect(A,N),R=P.x,z=P.y,X=P.w,K=P.h;let F=S.getImageData(R,z,X,K);if(this.isTransparentRectByCanvas(F)){Pe(I,T),f.removeChild(T),this.isDelete=!0,F=null;return}Pe(t,a);const _=this.createSpriteNode({imageData:F,safariRect:A,originRect:L,worldScaling:w.worldScaling});_&&t.append(_),Pe(I,T),f.removeChild(T),a.deleteTexture(F),F=null}createVmRenderNode(s,e,t,i,o){const{width:n,height:a}=t,c=`bitMap-${s}`,l=e.layer(c,t),u=new ae.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=Je(u,!0),d={pos:[0,0],d:h,fillColor:"rgba(0,0,0,1)"},g=new ae.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 ae.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 Z(s[0],s[1]);return Z.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 Z(s[a],s[a+1]);let l;if(a==s.length-2){const u=new Z(s[a-2],s[a-1]);l=k.Sub(c,u).uni(),o=c}else{a===0&&(n=c);const u=new Z(s[a+2],s[a+3]);l=k.Sub(u,c).uni()}if(l){const u=k.Per(l).mul(e);t.push(Z.Sub(c,u)),i.push(Z.Add(c,u))}}if(o&&n){const a=Z.GetSemicircleStroke(o,t[t.length-1],-1,8),c=Z.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?iy(t,n,s):(n.remove(),Re(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(),Re(a,(c=this.drawLayer)==null?void 0:c.parent)}):this.fullLayer.getElementsByName(e).forEach(a=>{a.remove(),Re(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(),Re(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&&ke(n)||i.get(e.name);if(!m)return;De(a)&&(e.setAttribute("zIndex",a),m.opt.zIndex=a);const w=e.parent;if(w){if(u&&d&&n){const T=[m.op[0],m.op[1]];li(m.op,h,d,c);const C=[m.op[0],m.op[1]],S=[C[0]-T[0],C[1]-T[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 N of Object.values(m.opt.eraserlines)){const{op:x,thickness:L}=N;N.thickness=L*Math.max(d[0],d[1]);for(let b=0;b<x.length;b++)hi(x[b],h,d,c)}}else if(c)if(e.setAttribute("translate",c),m.opt.translate=c,n){const T=[c[0]*w.worldScaling[0],c[1]*w.worldScaling[1]];f=Vt(m.rect,T),m.rect=f}else{const T=Ye.getRectFromLayer(w,e.name);m.rect=T||m.rect}else if(De(l))if(e.setAttribute("rotate",l),m.opt.rotate=l,n)f=rn(m.rect,l),m.rect=f;else{const T=Ye.getRectFromLayer(w,e.name);m.rect=T||m.rect}if(g){const T=g.get(e.name);if(T)for(let C=0,S=0;C<m.op.length;C+=3,S++)m.op[C]=T[S][0],m.op[C+1]=T[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 T=m.op.map((C,S)=>{const N=S%3;return N===0?C+c[0]:N===1?C+c[1]:C});if(m.op=T,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 N=0;N<S.length;N++){const x=S[N].map((L,b)=>b%2?L+c[1]:L+c[0]);C.op[N]=x}}}else if(De(l)){const T=m.op;if(JM(T,m.centerPos,l),m.op=T,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 N=0;N<S.length;N++)qM(S[N],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-Ye.SafeBorderPadding),y:Math.floor(i.y-Ye.SafeBorderPadding),w:Math.floor(i.width+Ye.SafeBorderPadding*2),h:Math.floor(i.height+Ye.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===v.Text&&(o.fontSize||o.translate||o.textInfos&&o.textInfos.get(i.name))||e===v.Image&&(o.angle||o.translate||o.scale||o.strokeColor&&o.type===Mt.Iconify)||e===o.toolsType&&o.willRefresh||t.eraserlines&&t.eraserlines.length&&(o.strokeColor||o.fillColor))}};M(Ye,"SafeBorderPadding",10);let Y=Ye;const ii=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 wt(r){return JSON.parse(ao.decompress(r))}function We(r){return ao.compress(JSON.stringify(r))}const Le=Object.keys;function Uo(r,s,e=.01){return Math.abs(r[0]-s[0])<e&&Math.abs(r[1]-s[1])<e}function Jp(r,s=.01){if(r.length===0)return[];const e=[[r[0][0],r[0][1]]];for(let t=1;t<r.length;t++)Uo([r[t][0],r[t][1]],e[e.length-1],s)||e.push([r[t][0],r[t][1]]);return e}function qp(r,s=.01){if(r.length<=2)return r;const e=r[0],t=r[r.length-1];return Uo(e,t,s)?r.slice(0,-1):r}function Kp(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 Yi(r,s){return Math.atan2(s[1]-r[1],s[0]-r[0])}function _p(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=Kp(e);return e.sort((i,o)=>{const n=Yi(t,i),a=Yi(t,o);return n-a})}function eg(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 tg(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 $e.ClipperOffset;n.AddPath(o(i,1e3),$e.JoinType.jtRound,$e.EndType.etOpenButt);const a=[];n.Execute(a,1);const c=new $e.Clipper;c.AddPaths(a,$e.PolyType.ptSubject,!0),s.forEach(h=>{c.AddPath(o(h,1e3),$e.PolyType.ptClip,!0)});const l=new $e.Paths;c.Execute($e.ClipType.ctDifference,l,$e.PolyFillType.pftNonZero,$e.PolyFillType.pftNonZero);const u=l.map(h=>qp(_p(Jp(h.map(d=>[d.X/1e3,d.Y/1e3]),e),e),e)).filter(h=>h.length>=2);return eg(u,r)}class Bo extends Y{constructor(e){super(e);M(this,"canRotate",!0);M(this,"scaleType",re.all);M(this,"toolsType",v.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:De(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 T=i?this.fullLayer:this.drawLayer||this.fullLayer;f=this.draw({attrs:p,tasks:h,effects:d,layer:T,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(T=>{I.push(T.x,T.y,this.computRadius(T.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===te.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=We(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 Z(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 Z(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 Z(p[w],p[w+1]);if(f.length>0){const T=f[f.length-1].point,C=k.Sub(I,T).uni();I.setv(C)}f.push({point:I,radius:n})}const{ps:m}=this.computStroke(f,!1);d.push(m.map(w=>w.XY))}tg(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 T=[],C=a.worldPosition,S=a.worldScaling;for(let x=0;x<i.length;x++){const{pos:L,points:b}=i[x],{ps:E,rect:A}=this.computDrawPoints(b);let P;const R=b.length===1;h===te.Stroke||R?P=Je(E,!0):P=Je(E,!1);const z={pos:L,d:P,fillColor:h===te.Stroke||R?u:void 0,lineDash:h===te.Dotted&&!R?[1,d*2]:h===te.LongDotted&&!R?[d,d*2]:void 0,strokeColor:u,lineCap:h===te.Stroke||R?void 0:"round",lineWidth:h===te.Stroke||R?0:d};I=he(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)}),T.push(z)}p&&(t.scale=p),f&&(t.rotate=f),m&&(t.translate=m);const N=new ae.Group;if(I){this.centerPos=Y.getCenterPos(I,a);const x=h===te.Stroke&&!w;N.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=T.map(b=>(b.pos=[b.pos[0]-this.centerPos[0],b.pos[1]-this.centerPos[1]],new ae.Path(b)));N.append(...L),x&&N.seal(),w&&(this.scaleType=re.proportional,this.drawEraserlines({group:N,eraserlines:w,pos:this.centerPos,layer:a},l)),this.replace(a,o,N)}if(p||f||m){const x=N==null?void 0:N.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&&N.setAttribute("opacity",0),I}computDrawPoints(e){return this.workOptions.strokeType===te.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:fe(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(Z.Sub(l,d)),o.push(Z.Add(l,d))}const n=e[e.length-1];if(t){const c=Z.GetSemicircleStroke(n.point,i[i.length-1],-1,8),l=Z.GetSemicircleStroke(e[0].point,o[0],-1,8),u=i.concat(c,o.reverse(),l);return{ps:u,rect:fe(u)}}const a=i.concat(o.reverse());return{ps:a,rect:fe(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:Z.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===te.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 Z(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 T=d.x-n,C=d.y-a;l=[{point:new Z(T,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 Z(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]),T=Math.max(this.tmpPoints[w].z-this.uniThickness*I,0);if(this.tmpPoints[w-1].z>=T)break;this.tmpPoints[w-1].setz(T),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 Z(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 Z(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"?sy(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 Fo extends Y{constructor(e){super(e);M(this,"toolsType",v.LaserPen);M(this,"canRotate",!1);M(this,"scaleType",re.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=fe(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===te.Dotted?[1,l*2]:u===te.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=fe(this.tmpPoints,u);const d={name:e==null?void 0:e.toString(),fillColor:c?l:void 0,opacity:1,lineDash:h===te.Dotted&&!c?[1,u*2]:h===te.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=We(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=fe(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=fe(this.tmpPoints,a);const g={name:(f=this.workId)==null?void 0:f.toString(),fillColor:d?n:void 0,opacity:1,lineDash:c===te.Dotted&&!d?[1,a*2]:c===te.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:Z.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 Z(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 ae.Path,{pos:u,points:h}=c;let d;o?d=Je(h,!0):d=Je(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 Z(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 Z(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=he(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 St=class St extends Y{constructor(e,t){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.none);M(this,"toolsType",v.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}=St.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}=St.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}=St.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&&Ys(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 Z(d.x,d.y))}const u=c.length&&fe(c)||n.rect;Ys(u,this.eraserRect)&&(l.length>1?Zs.polyline(l.map(d=>d.XY),this.eraserPolyline).length&&i.add(n.name):i.add(n.name),o=he(o,n.rect||u))}return i.forEach(n=>{var c;const a=this.fullLayer.getElementsByName(n);a[0]&&(a[0].remove(),Re(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=he(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(St,"eraserSizes",ii);let ss=St;const Oe="++",H="selector",Kt="all";var sg="__lodash_hash_undefined__";function ig(r){return this.__data__.set(r,sg),this}var og=ig;function ng(r){return this.__data__.has(r)}var rg=ng,ag=fo,cg=og,lg=rg;function is(r){var s=-1,e=r==null?0:r.length;for(this.__data__=new ag;++s<e;)this.add(r[s])}is.prototype.add=is.prototype.push=cg;is.prototype.has=lg;var oi=is;function hg(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 ug=hg;function dg(r,s){return r.has(s)}var ni=dg,pg=oi,gg=ug,fg=ni,Mg=1,yg=2;function mg(r,s,e,t,i,o){var n=e&Mg,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&yg?new pg: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(!gg(s,function(w,I){if(!fg(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 Qo=mg;function wg(r){var s=-1,e=Array(r.size);return r.forEach(function(t,i){e[++s]=[i,t]}),e}var Ig=wg;function vg(r){var s=-1,e=Array(r.size);return r.forEach(function(t){e[++s]=t}),e}var ri=vg,Ui=Zt,Bi=Po,Tg=Hs,Ng=Qo,Sg=Ig,Cg=ri,kg=1,Dg=2,xg="[object Boolean]",Lg="[object Date]",bg="[object Error]",jg="[object Map]",Ag="[object Number]",zg="[object RegExp]",Pg="[object Set]",Eg="[object String]",Og="[object Symbol]",Rg="[object ArrayBuffer]",Wg="[object DataView]",Fi=Ui?Ui.prototype:void 0,Ds=Fi?Fi.valueOf:void 0;function Yg(r,s,e,t,i,o,n){switch(e){case Wg:if(r.byteLength!=s.byteLength||r.byteOffset!=s.byteOffset)return!1;r=r.buffer,s=s.buffer;case Rg:return!(r.byteLength!=s.byteLength||!o(new Bi(r),new Bi(s)));case xg:case Lg:case Ag:return Tg(+r,+s);case bg:return r.name==s.name&&r.message==s.message;case zg:case Eg:return r==s+"";case jg:var a=Sg;case Pg:var c=t&kg;if(a||(a=Cg),r.size!=s.size&&!c)return!1;var l=n.get(r);if(l)return l==s;t|=Dg,n.set(r,s);var u=Ng(a(r),a(s),t,i,o,n);return n.delete(r),u;case Og:if(Ds)return Ds.call(r)==Ds.call(s)}return!1}var Ug=Yg,Qi=jo,Bg=1,Fg=Object.prototype,Qg=Fg.hasOwnProperty;function Vg(r,s,e,t,i,o){var n=e&Bg,a=Qi(r),c=a.length,l=Qi(s),u=l.length;if(c!=u&&!n)return!1;for(var h=c;h--;){var d=a[h];if(!(n?d in s:Qg.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 T=n?t(I,w,d,s,r,o):t(w,I,d,r,s,o);if(!(T===void 0?w===I||i(w,I,e,t,o):T)){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 Zg=Vg,xs=Mo,Hg=Qo,Gg=Ug,$g=Zg,Vi=ws,Zi=Ht,Hi=$s,Xg=No,Jg=1,Gi="[object Arguments]",$i="[object Array]",Xt="[object Object]",qg=Object.prototype,Xi=qg.hasOwnProperty;function Kg(r,s,e,t,i,o){var n=Zi(r),a=Zi(s),c=n?$i:Vi(r),l=a?$i:Vi(s);c=c==Gi?Xt:c,l=l==Gi?Xt:l;var u=c==Xt,h=l==Xt,d=c==l;if(d&&Hi(r)){if(!Hi(s))return!1;n=!0,u=!1}if(d&&!u)return o||(o=new xs),n||Xg(r)?Hg(r,s,e,t,i,o):Gg(r,s,c,e,t,i,o);if(!(e&Jg)){var g=u&&Xi.call(r,"__wrapped__"),p=h&&Xi.call(s,"__wrapped__");if(g||p){var f=g?r.value():r,m=p?s.value():s;return o||(o=new xs),i(f,m,e,t,o)}}return d?(o||(o=new xs),$g(r,s,e,t,i,o)):!1}var _g=Kg,ef=_g,Ji=Ke;function Vo(r,s,e,t,i){return r===s?!0:r==null||s==null||!Ji(r)&&!Ji(s)?r!==r&&s!==s:ef(r,s,e,t,Vo,i)}var tf=Vo,sf=tf;function of(r,s){return sf(r,s)}var nf=of;const tt=jt(nf);function Gt(r,s,e){return"#"+((r<<16)+(s<<8)+e).toString(16).padStart(6,"0")}function Ce(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 at(r,s,e,t=1){return`rgba(${r},${s},${e},${t})`}function Is(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[Gt(e,t,i),o]}function Ut(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 Jt(r){return r==="transparent"}const hs=class hs extends Y{constructor(e){super(e);M(this,"toolsType",v.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",re.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=fe(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 Z(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 ae.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 ae.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:hs.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 ae.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=re.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!==v.Pencil&&(o=!1),a.strokeType&&(this.strokeType=a.strokeType),u===v.SpeechBalloon&&(t.add(u),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.placement=a.placement),u===v.Polygon&&(t.add(u),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=a.vertices),u===v.Star&&(t.add(u),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=a.vertices,this.shapeOpt.innerRatio=a.innerRatio,this.shapeOpt.innerVerticeStep=a.innerVerticeStep),u===v.Text&&(this.textOpt=a),e.size===1&&(this.textOpt&&(this.canTextEdit=!0),this.canRotate=c,this.scaleType=l),u===v.Image&&(i=n),(l===re.proportional&&this.scaleType!==re.none||l===re.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=re.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===re.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&&tt(this.selectIds,n.selectIds))return{type:D.None};this.selectIds=n.selectIds;const a=n.intersectRect;this.getSelecteorInfo(n.subNodeMap),this.draw(H,this.fullLayer,n),this.oldSelectRect=a;const c=this.getChildrenPoints();return{type:D.Select,dataType:B.Local,rect:he(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,H,!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 Z(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=fe(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&&Ut(n)||[0,0,0,0],w={close:!0,normalize:!0,points:d,lineWidth:f,fillColor:at(m[0],m[1],m[2],.1),strokeColor:at(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 T=new ae.Group({name:t,id:t,pos:p,anchor:[.5,.5],size:[g.w,g.h],scale:a,rotate:c,translate:l}),C=new ae.Polyline({...w,pos:[0,0]});if(T.appendChild(C),this.replace(i,t,T),a||c||l){const S=T.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=fe(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 Z(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=he(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=H,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(_o(h).find(g=>g.isPointCollision(o,n))){a=u;break}}if(a){const u=a.name;if(!tt(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=he(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=he(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=he(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=he(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===v.Ellipse||e===v.Triangle||e===v.Rectangle||e===v.Polygon||e===v.Star||e===v.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||De(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 N=o.get(S);if(N){const{toolsType:x,opt:L}=N,b=(l==null?void 0:l.getElementsByName(S))[0];if(b){const E={...t};let A;const P=Y.isWillRefresh({toolsType:x,opt:L,updateOpt:E,vNodes:o,node:b,willSerializeData:n});if(x){A=I==null?void 0:I.get(S);const R=Ko(x);if(R==null||R.updateNodeOpt({node:b,opt:E,vNodes:o,willSerializeData:n,targetNode:A}),N&&a&&P){const z=a.createWorkShapeNode({workId:S,toolsType:x,toolsOpt:N.opt});z==null||z.setWorkId(S);let X;if(x===v.Image)X=await z.consumeServiceAsync({isFullWork:!0,replaceId:S,worker:a});else if(x===v.Text)X=await z.consumeServiceAsync({isFullWork:!0,replaceId:S});else try{X=z==null?void 0:z.consumeService({op:N.op,isFullWork:!0,replaceId:S,workState:g})}catch{continue}X&&(N.rect=X)}N&&(h.set(S,N),u=he(u,N.rect))}}}}I&&g===j.Done&&(o.deleteLastTarget(),I=void 0);const T=u;if(d&&f&&w&&m&&T&&!c){const S=[[T.x,T.y],[T.x+T.w,T.y],[T.x+T.w,T.y+T.h],[T.x,T.y+T.h]];let N;switch(m){case"top":case"topLeft":case"left":f[0]>0&&f[1]>0?N=S[0]:f[0]>0?N=S[3]:f[1]>0?N=S[1]:N=S[2];break;case"topRight":f[0]<0&&f[1]>0?N=S[1]:f[0]<0?N=S[2]:f[1]>0?N=S[0]:N=S[3];break;case"right":case"bottomRight":case"bottom":f[0]<0&&f[1]<0?N=S[2]:f[0]<0?N=S[1]:f[1]<0?N=S[3]:N=S[0];break;case"bottomLeft":f[0]>0&&f[1]<0?N=S[3]:f[0]>0?N=S[0]:f[1]<0?N=S[2]:N=S[1];break}const x=N&&[d[0]-N[0],d[1]-N[1]]||[0,0];if(!tt(x,[0,0]))return await this.updateSelector({...e,updateSelectorOpt:{workState:g},offset:x})}this.getSelecteorInfo(h),this.draw(H,l,{selectIds:i||[],subNodeMap:h,intersectRect:T});const C=he(this.oldSelectRect,T);return this.oldSelectRect=T,{type:D.Select,dataType:B.Local,selectRect:T,renderRect:u,rect:he(C,T),selectIds:i}}blurSelector(){const e=this.unSelectedAllIds();return{type:D.Select,dataType:B.Local,rect:e,selectIds:[],willSyncService:!0}}getRightServiceId(e){return e.replace(Oe,"-")}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=he(c,h.rect),l.set(u,h))}),this.getSelecteorInfo(l),this.draw(n,this.fullLayer,{intersectRect:c,selectIds:o||[],subNodeMap:l},i),he(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=he(e,n.rect),t.set(o,n))},this),this.getSelecteorInfo(t),this.draw(H,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=he(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&&!tt(t,this.oldSelectRect))return{type:D.CursorHover,dataType:B.Local,rect:he(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(hs,"selectorBorderId","selector-border");let os=hs;class Zo extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.both);M(this,"toolsType",v.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 Z(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=he(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=We(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:T,trianglePoints:C,trianglePos:S}=this.computDrawPoints(a),N=[I.x+I.w/2,I.y+I.h/2],x={pos:N,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 ae.Group(x),b={points:C,pos:[S[0]-N[0],S[1]-N[1]],fillColor:n,strokeColor:n,lineWidth:0,normalize:!1},E=new ae.Polyline(b);if(L.append(E),!T&&m&&w){const P={points:m,pos:[w[0]-N[0],w[1]-N[1]],fillColor:n,strokeColor:n,lineDash:d===te.Dotted&&!T?[1,a*2]:d===te.LongDotted&&!T?[a,a*2]:void 0,lineCap:d===te.Normal?void 0:"round",lineWidth:a,normalize:!1},R=new ae.Polyline(P);L.append(R)}g&&(this.scaleType=re.proportional,this.drawEraserlines({group:L,eraserlines:g,pos:N,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 P=L.getBoundingClientRect();A={x:Math.floor(P.x-Y.SafeBorderPadding),y:Math.floor(P.y-Y.SafeBorderPadding),w:Math.floor(P.width+Y.SafeBorderPadding*2),h:Math.floor(P.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=Z.Sub(this.tmpPoints[0],i),n=Z.Add(this.tmpPoints[0],i),a=k.Mul(t,this.arrowTipWidth),c=k.Sub(this.tmpPoints[1],a),l=Z.Sub(c,i),u=Z.Add(c,i),h=k.Per(t).mul(e*1.5),d=Z.Sub(c,h),g=Z.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=>Z.Sub(w,this.tmpPoints[1]).XY).flat(1),trianglePos:this.tmpPoints[1].XY,points:p.map(w=>Z.Sub(w,this.tmpPoints[0]).XY).flat(1),rect:fe(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=Z.Sub(this.tmpPoints[0],i),n=Z.Add(this.tmpPoints[0],i),a=[o,this.tmpPoints[1],n];return{trianglePoints:a.map(c=>Z.Sub(c,this.tmpPoints[1]).XY).flat(1),trianglePos:this.tmpPoints[1].XY,rect:fe(a),isTriangle:!0}}updateTempPoints(e){const t=e.slice(-2),i=new Z(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 Z(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 Ho extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.all);M(this,"toolsType",v.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 Z(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(ui(d,f)!==ft.outside){const w=he(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=We(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:T}=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===te.Dotted?[1,l*2]:p===te.LongDotted?[l,l*2]:void 0},S={name:t,id:t,zIndex:u,pos:T,anchor:[.5,.5],size:[I.w,I.h]};h&&(S.scale=h),d&&(S.rotate=d),g&&(S.translate=g);const N=new ae.Group(S);if(o){const b=new ae.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:a,lineWidth:1,scale:[1/m[0],1/m[1]]});N.append(b)}const x=new ae.Ellipse({...C,pos:[0,0]});N.append(x),f&&(this.scaleType=re.proportional,this.drawEraserlines({group:N,eraserlines:f,pos:T,layer:i},n)),this.replace(i,t,N);const L=N.getBoundingClientRect();return this.isDelete&&N.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=fe(this.tmpPoints),i=fe(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 Z(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 Z(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 Go extends Y{constructor(e){super(e);M(this,"canRotate",!0);M(this,"scaleType",re.all);M(this,"toolsType",v.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=fe(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=fe(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 Z(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=he(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=We(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,T=i.worldScaling,{points:C,rect:S,pos:N}=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===te.Dotted?[1,h*2]:m===te.LongDotted?[h,h*2]:void 0};let L={x:Math.floor(S.x*T[0]+I[0]-Y.SafeBorderPadding),y:Math.floor(S.y*T[1]+I[1]-Y.SafeBorderPadding),w:Math.floor(S.w*T[0]+2*Y.SafeBorderPadding),h:Math.floor(S.h*T[0]+2*Y.SafeBorderPadding)};const b=new ae.Group({name:t,id:t,zIndex:d,pos:N,anchor:[.5,.5],size:[S.w,S.h],scale:g,rotate:p,translate:f}),E=new ae.Polyline({...x,pos:[0,0]});if(b.appendChild(E),o){const A=new ae.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:l,lineWidth:1,scale:[1/T[0],1/T[1]]});b.appendChild(A)}if(w&&(this.scaleType=re.proportional,this.drawEraserlines({group:b,eraserlines:w,pos:N,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 Z(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 $o extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.all);M(this,"toolsType",v.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 Z(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=he(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=We(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,T=i.worldScaling,{rect:C,pos:S,points:N}=this.computDrawPoints(l,h,d,g),x={close:!0,points:N,lineWidth:l,fillColor:c!=="transparent"&&c||void 0,strokeColor:a,normalize:!0,lineJoin:"round",lineCap:"round",lineDash:w===te.Dotted?[1,l*2]:w===te.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 ae.Group(L);if(o){const P=new ae.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:a,lineWidth:1,scale:[1/T[0],1/T[1]]});b.append(P)}const E=new ae.Polyline({...x,pos:[0,0]});b.append(E),I&&(this.scaleType=re.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=fe(this.tmpPoints),a=[Math.floor(n.x+n.w/2),Math.floor(n.y+n.h/2)],c=ln(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:fe(this.tmpPoints,e),pos:a,points:h}}updateTempPoints(e){const t=e.slice(-2),i=new Z(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n)||Z.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 Z(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===v.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 Xo extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.all);M(this,"toolsType",v.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 Z(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=he(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=We(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:T,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===te.Dotted?[1,l*2]:f===te.LongDotted?[l,l*2]:void 0},N={name:t,id:t,zIndex:u,pos:T,anchor:[.5,.5],size:[I.w,I.h]};d&&(N.scale=d),g&&(N.rotate=g),p&&(N.translate=p);const x=new ae.Group(N);if(o){const E=new ae.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:a,lineWidth:1,scale:[1/w[0],1/w[1]]});x.append(E)}const L=new ae.Polyline({...S,pos:[0,0]});x.append(L),m&&(this.scaleType=re.proportional,this.drawEraserlines({group:x,eraserlines:m,pos:T,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=fe(this.tmpPoints),o=[Math.floor(i.x+i.w/2),Math.floor(i.y+i.h/2)],n=ln(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:fe(this.tmpPoints,e),pos:o,points:c}}updateTempPoints(e){const t=e.slice(-2),i=new Z(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n)||Z.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 Z(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===v.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 Ze{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(...Ze.getBezierPoints(s,o,n,a,c)):o&&n&&a?t.push(...Ze.getBezierPoints(s,o,n,a)):o&&n?t.push(...Ze.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=Ze.oneBezier:i&&!o?n=Ze.twoBezier:i&&o&&(n=Ze.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 Jo extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.all);M(this,"toolsType",v.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 Z(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=he(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=We(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),T={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===te.Dotted?[1,c*2]:p===te.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 ae.Group(C),N=new ae.Polyline({...T,pos:[0,0]});S.append(N),f&&(this.scaleType=re.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=fe(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=fe(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=Ze.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=Ze.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=Ze.getBezierPoints(10,f,o[2],m),I=k.Add(o[3],new k(n,0,0)),T=k.Sub(o[3],new k(0,a,0)),C=Ze.getBezierPoints(10,I,o[3],T),S=n*(1-this.ratio)*10,N=a*(1-this.ratio)*10;switch(t){case"bottom":{const b=k.Sub(o[2],new k(n*5-S/2,0,0)),E=k.Sub(o[2],new k(n*5,-N,0)),A=k.Sub(o[2],new k(n*5+S/2,0,0));c.push(E,A,...C,...h,...p,...w,b);break}case"bottomRight":{const b=k.Sub(o[2],new k(n*1.1,0,0)),E=k.Sub(o[2],new k(n*1.1+S/2,-N,0)),A=k.Sub(o[2],new k(n*1.1+S,0,0));c.push(E,A,...C,...h,...p,...w,b);break}case"bottomLeft":{const b=k.Add(o[3],new k(n*1.1+S,0,0)),E=k.Add(o[3],new k(n*1.1+S/2,N,0)),A=k.Add(o[3],new k(n*1.1,0,0));c.push(E,A,...C,...h,...p,...w,b);break}case"top":{const b=k.Sub(o[1],new k(n*5-S/2,0,0)),E=k.Sub(o[1],new k(n*5,N,0)),A=k.Sub(o[1],new k(n*5+S/2,0,0));c.push(E,b,...p,...w,...C,...h,A);break}case"topRight":{const b=k.Sub(o[1],new k(n*1.1,0,0)),E=k.Sub(o[1],new k(n*1.1+S/2,N,0)),A=k.Sub(o[1],new k(n*1.1+S,0,0));c.push(E,b,...p,...w,...C,...h,A);break}case"topLeft":{const b=k.Add(o[0],new k(n*1.1+S,0,0)),E=k.Add(o[0],new k(n*1.1+S/2,-N,0)),A=k.Add(o[0],new k(n*1.1,0,0));c.push(E,b,...p,...w,...C,...h,A);break}case"left":{const b=k.Add(o[0],new k(0,a*5-N/2,0)),E=k.Add(o[0],new k(-S,a*5,0)),A=k.Add(o[0],new k(0,a*5+N/2,0));c.push(E,b,...h,...p,...w,...C,A);break}case"leftTop":{const b=k.Add(o[0],new k(0,a*1.1,0)),E=k.Add(o[0],new k(-S,a*1.1+N/2,0)),A=k.Add(o[0],new k(0,a*1.1+N,0));c.push(E,b,...h,...p,...w,...C,A);break}case"leftBottom":{const b=k.Sub(o[3],new k(0,a*1.1+N,0)),E=k.Sub(o[3],new k(S,a*1.1+N/2,0)),A=k.Sub(o[3],new k(0,a*1.1,0));c.push(E,b,...h,...p,...w,...C,A);break}case"right":{const b=k.Add(o[1],new k(0,a*5-N/2,0)),E=k.Add(o[1],new k(S,a*5,0)),A=k.Add(o[1],new k(0,a*5+N/2,0));c.push(E,A,...w,...C,...h,...p,b);break}case"rightTop":{const b=k.Add(o[1],new k(0,a*1.1,0)),E=k.Add(o[1],new k(S,a*1.1+N/2,0)),A=k.Add(o[1],new k(0,a*1.1+N,0));c.push(E,A,...w,...C,...h,...p,b);break}case"rightBottom":{const b=k.Sub(o[2],new k(0,a*1.1+N,0)),E=k.Sub(o[2],new k(-S,a*1.1+N/2,0)),A=k.Sub(o[2],new k(0,a*1.1,0));c.push(E,A,...w,...C,...h,...p,b);break}}const x=fe(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 Z(t[0],t[1]),o=this.tmpPoints[0],{thickness:n}=this.workOptions;if(o.isNear(i,n)||Z.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 Z(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===v.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 rf=yt,af=Ke,cf="[object Boolean]";function lf(r){return r===!0||r===!1||af(r)&&rf(r)==cf}var hf=lf;const Nt=jt(hf);class qo extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.both);M(this,"toolsType",v.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 Z(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=he(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=We(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),T=[w.x+w.w/2,w.y+w.h/2],C=new ae.Group({pos:T,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===te.Dotted&&!I?[1,a*2]:d===te.LongDotted&&!I?[a,a*2]:void 0,lineCap:d===te.Normal||I?void 0:"round",lineWidth:d===te.Normal||I?0:a};l&&(S.scale=l),u&&(S.rotate=u),h&&(S.translate=h);const N=new ae.Path(S);C.append(N),g&&(this.scaleType=re.proportional,this.drawEraserlines({group:C,eraserlines:g,pos:T,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=N.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=Z.Sub(this.tmpPoints[0],o),a=Z.Add(this.tmpPoints[0],o),c=Z.Sub(this.tmpPoints[1],o),l=Z.Add(this.tmpPoints[1],o),u=Z.GetSemicircleStroke(this.tmpPoints[1],c,-1,8),h=Z.GetSemicircleStroke(this.tmpPoints[0],a,-1,8),d=[n,c,...u,l,a,...h];let g;return t!==te.Normal?g=Je(this.tmpPoints,!1):g=Je(d,!0),{d:g,rect:fe(d),isDot:!1,pos:this.tmpPoints[0].XY}}computDotPoints(e){const t=Z.GetDotStroke(this.tmpPoints[0],e/2,8);return{d:Je(t,!0),rect:fe(t),isDot:!0,pos:this.tmpPoints[0].XY}}updateTempPoints(e){const t=e.slice(-2),i=new Z(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 Z(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 ct=class ct extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.proportional);M(this,"toolsType",v.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 ae.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 ct.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),Nt(l)&&(d.opt.lineThrough=l),Nt(u)&&(d.opt.underline=u),De(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(ct.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=wt(e.text),h=u.length,{fontSize:d,lineHeight:g,bold:p,textAlign:f,italic:m,fontFamily:w,verticalAlign:I,fontColor:T,fontBgColor:C,underline:S,lineThrough:N}=e,x=ct.getSafetySnippetRatio(t)||1,L=Math.floor(d*x),b=ct.getSafetySnippetFontLength(L);let E=0;for(let P=0;P<h;P++){const R=u[P],z=g||L*1.5;if(R){const X=ny(R),K=[0,0],F=[0,d*1.2];I==="middle"&&(K[1]=P*d*1.2+5);const G=[0,-d*.15];K[0]=5;const _=Math.sin(Math.PI/180*20);let ce=0;const ee=[];let q=0;for(;q<X;){f==="left"&&(G[0]=ce),q===0&&m==="italic"&&(G[0]=G[0]-_/2*d);const ue=R.slice(q,q+b),ze={anchor:[0,0],pos:G,text:ue,fontFamily:w,fontSize:L,lineHeight:z,strokeColor:T,fontWeight:p,fillColor:T,textAlign:f,fontStyle:m,scale:[1/x,1/x]},Te=new ae.Label(ze),V=await Te.textImageReady;let le=!0;if(V){const ie=V.rect&&V.rect[2],pe=V.rect&&V.rect[3];if(ie&&pe){const de=ie/x,Me=pe/x;ce=de+ce,m==="italic"&&(p==="bold"?ce=ce-_*d*1.2:ce=ce-_*d),((G[0]+K[0]+de)*t.worldScaling[0]+n<=0||(G[0]+K[0])*t.worldScaling[0]+n>=c||(G[1]+K[1]+Me)*t.worldScaling[1]+a<=0||(G[1]+K[1])*t.worldScaling[1]+a>=l)&&(Te.disconnect(),le=!1),le&&ee.push(Te)}}q+=b}F[0]=ce,m==="italic"&&(F[0]=F[0]+_*d),E=Math.max(E,F[0]);let J=!0;if(((K[0]+F[0])*t.worldScaling[0]+n<=0||K[0]*t.worldScaling[0]+n>=c||(K[1]+F[1])*t.worldScaling[0]+a<=0||K[1]*t.worldScaling[1]+a>=l)&&(J=!1),J){if(S){const Te=Math.floor(d/10),V={normalize:!1,pos:[0,d*1.1+Te/2],lineWidth:Te,points:[0,0,Math.ceil(F[0]),0],strokeColor:T,className:"underline"},le=new ae.Polyline(V);ee.push(le)}if(N){const Te={normalize:!1,pos:[0,d*1.2/2],lineWidth:Math.floor(d/10),points:[0,0,Math.ceil(F[0]),0],strokeColor:T,className:"lineThrough"},V=new ae.Polyline(Te);ee.push(V)}const ue={pos:K,anchor:[0,0],size:F,bgcolor:C},ze=new ae.Group(ue);ze.append(...ee),o.push(ze)}}}return{labels:o,maxWidth:E}}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:T}=i,C=n&&ke(n)||o.get(t.name);if(!C||!t.parent)return;const N=C.opt;if(De(T)&&(t.setAttribute("zIndex",T),C.opt.zIndex=T),c&&N.fontColor&&(N.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&&N.fontBgColor&&(N.fontBgColor=a,t.children.forEach(x=>{x.tagName==="GROUP"&&x.setAttribute("bgcolor",a)})),g&&(N.bold=g),p&&(N.italic=p),Nt(f)&&(N.lineThrough=f),Nt(m)&&(N.underline=m),w&&(N.fontSize=w),u&&h&&d&&n&&N.boxPoint){const x=I==null?void 0:I.get(t.name);if(x){const{fontSize:A,boxSize:P}=x;N.boxSize=P||N.boxSize,N.fontSize=A||N.fontSize}const L=[N.boxPoint[0],N.boxPoint[1]];li(N.boxPoint,h,d,l);const b=[C.op[0],C.op[1]],E=[b[0]-L[0],b[1]-L[1]];if(C.centerPos=[C.centerPos[0]+E[0],C.centerPos[1]+E[1]],C.opt.eraserlines)for(const A of Object.values(C.opt.eraserlines)){const{op:P,thickness:R}=A;A.thickness=R*Math.max(d[0],d[1]);for(let z=0;z<P.length;z++)hi(P[z],h,d,l)}}else if(l&&N.boxPoint&&(N.boxPoint=[N.boxPoint[0]+l[0],N.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 E=L[b].map((A,P)=>P%2?A+l[1]:A+l[0]);x.op[b]=E}}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=he(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(ct,"textImageSnippetSize",1024*4),M(ct,"SafeBorderPadding",30);let ns=ct;const Ct=class Ct extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.none);M(this,"toolsType",v.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}=Ct.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 Z(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 Z(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=fe(this.tmpPoints,e);c=Vt(c,a),c=an(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!==v.Pencil)continue;let g=Vt(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)Zs.polyline(w,p,f);if(f.length&&d.opt)for(const w of f){const I=[];for(let T=0;T<w.length;T++)T!==0&&tt(w[T],w[T-1])||I.push(...w[T]);m.push(I)}if(m.length&&t){const w=t.createWorkShapeNode({workId:h,toolsType:v.Pencil,toolsOpt:d.opt});w.setWorkId(h);const I=w==null?void 0:w.computPencilPoints({op:d.op,eraserPolylines:m,eraserThickness:e});if(n=he(n,d.rect),o.add(h),t.removeNode(h),I.length)for(let T=0;T<I.length;T++){const C=`${h}_${Date.now()}_${T}`,S=C,x=t.setFullWork({workId:S,opt:d.opt,toolsType:v.Pencil}).consumeService({op:I[T],isFullWork:!0,replaceId:S});t.clearWorkShapeNodeCache(S),n=he(n,x),i.set(C,{...d,rect:x??d.rect,name:C,op:I[T]})}}}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}=Ct.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 T={name:this.workId,id:De(c)&&c.toString()||void 0},C=this.syncIndex;this.syncTimestamp===0&&(this.syncTimestamp=Date.now());let S=!1,N;const x=this.tmpPoints.slice(w);if(o||n){const b=i?this.fullLayer:this.drawLayer||this.fullLayer;N=this.draw({attrs:T,consumePoints:x,layer:b,removeDrawCount:a,thickness:p})}if(o)return w>10&&this.tmpPoints.splice(0,w-10),{rect:N,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:N,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=fe(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 ae.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,N,x,L)=>x>0&&L[x-1][0]===N[0]&&L[x-1][1]===N[1]?S:S.concat(N[0],N[1]),[]),w=this.computEraserPoints(m,p),I=Je(w,!0),T={pos:[0,0],d:I,fillColor:this.workOptions.eraserColor},C=new ae.Path(T);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}=Ct.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=We(h);return{...this.baseConsumeResult,type:D.FullWork,dataType:B.Local,rect:u,ops:d,willNewNodes:l,willDeleteNodes:c}}clearTmpPoints(){this.tmpPoints.length=0}};M(Ct,"eraserSizes",ii);let rs=Ct;const kt=class kt extends Y{constructor(e){super(e);M(this,"canRotate",!1);M(this,"scaleType",re.none);M(this,"toolsType",v.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}=kt.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 Z(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 Z(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=fe(this.tmpPoints,e);c=Vt(c,a),c=an(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===v.Text||d.toolsType===v.Image)continue;let g=Vt(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)Zs.polyline(I,p,f);if(f.length&&d.opt)for(const I of f){const T=[];for(let C=0;C<I.length;C++)C!==0&&tt(I[C],I[C-1])||T.push(...I[C]);m.push(T)}if(d.opt.eraserlines||(d.opt.eraserlines=[]),d.opt.eraserlines){if(d.opt.eraserlines.push({op:m,thickness:e}),t){const{toolsType:I}=d,T=t.createWorkShapeNode({workId:h,toolsType:I,toolsOpt:d.opt});T==null||T.setWorkId(h);const C=T==null?void 0:T.consumeService({op:d.op,isFullWork:!0,replaceId:h});if(n=he(n,C),T!=null&&T.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}=kt.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 T={name:this.workId,id:De(c)&&c.toString()||void 0},C=this.syncIndex;this.syncTimestamp===0&&(this.syncTimestamp=Date.now());let S=!1,N;const x=this.tmpPoints.slice(w);if(o||n){const b=i?this.fullLayer:this.drawLayer||this.fullLayer;N=this.draw({attrs:T,consumePoints:x,layer:b,removeDrawCount:a,thickness:p})}if(o)return w>10&&this.tmpPoints.splice(0,w-10),{rect:N,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:N,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=fe(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 ae.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,N,x,L)=>x>0&&L[x-1][0]===N[0]&&L[x-1][1]===N[1]?S:S.concat(N[0],N[1]),[]),w=this.computEraserPoints(m,p),I=Je(w,!0),T={pos:[0,0],d:I,fillColor:this.workOptions.eraserColor},C=new ae.Path(T);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}=kt.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=We(h);return{...this.baseConsumeResult,type:D.FullWork,dataType:B.Local,rect:u,ops:d,willUpdateNodes:l,willDeleteNodes:c}}clearTmpPoints(){this.tmpPoints.length=0}};M(kt,"eraserSizes",ii);let as=kt;function Ko(r){switch(r){case v.Arrow:return Zo;case v.Pencil:return Bo;case v.Straight:return qo;case v.Ellipse:return Ho;case v.Polygon:case v.Triangle:return Xo;case v.Star:case v.Rhombus:return $o;case v.Rectangle:return Go;case v.SpeechBalloon:return Jo;case v.Text:return ns;case v.LaserPen:return Fo;case v.Eraser:return ss;case v.PencilEraser:return rs;case v.BitMapEraser:return as;case v.Selector:return os;case v.Image:return Qt}}function vs(r,s){const{toolsType:e,...t}=r;switch(e){case v.Arrow:return new Zo(t);case v.Pencil:return new Bo(t);case v.Straight:return new qo(t);case v.Ellipse:return new Ho(t);case v.Polygon:case v.Triangle:return new Xo(t);case v.Star:case v.Rhombus:return new $o(t);case v.Rectangle:return new Go(t);case v.SpeechBalloon:return new Jo(t);case v.Text:return new ns(t);case v.LaserPen:return new Fo(t);case v.Eraser:return new ss(t,s);case v.BitMapEraser:return new as(t);case v.PencilEraser:return new rs(t);case v.Selector:return t.vNodes?new os({...t,vNodes:t.vNodes,drawLayer:t.fullLayer}):void 0;case v.Image:return new Qt(t);default:return}}function _o(r){const s=[],e=["PATH","SPRITE","POLYLINE","RECT","ELLIPSE","LABEL"];for(const t of r){if(t.tagName==="GROUP"&&t.children.length){const i=_o(t.children);s.push(...i)}t.tagName&&e.includes(t.tagName)&&s.push(t)}return s}const uf="cursorhover",ai=20,ge="mainView";class en{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===v.Image&&(o.opt.locked||e&&e.disableEraseImage)||o.toolsType===v.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=ke(e.rect)),e.op&&KM(e.op)&&(t.op=ke(e.op)),e.canRotate&&(t.canRotate=e.canRotate),e.scaleType&&(t.scaleType=e.scaleType),e.opt&&(t.opt=ke(e.opt)),e.toolsType&&(t.toolsType=e.toolsType),e.centerPos&&(t.centerPos=ke(e.centerPos)),Nt(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(Ys(s,a.rect)){if(e&&a.toolsType===v.Image&&a.opt.locked||t&&a.toolsType===v.Text&&(a.opt.workState===j.Doing||a.opt.workState===j.Start))continue;i=he(i,a.rect),o.set(n,a)}return{rectRange:i,nodeRange:o}}getNodeRectFormShape(s,e){const t=Ko(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,ke(i))}return this.targetNodeMap.push(ke(e)),this.targetNodeMap.length-1}setTarget(){return this.targetNodeMap.push(ke(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(Oe).length===1}isCanClearWorkId(s){if(this.canClearUids===void 0||this.canClearUids===!0)return!0;if($d(this.canClearUids)){const e=s.split(Oe);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 df{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 en(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===ge?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:De(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===v.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===Mt.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===Ws.Full&&this.viewId===ge&&(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 ae.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 ae.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()}),Pe(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(),Re(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===Ws.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 ae.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=he(d.rect,u.rect),h=!0),d.drawCanvas&&d.drawCanvas===u.drawCanvas&&(d.rect=he(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(tt(u,d)){h=!0;break}h||e.push(u)}De(l.fullWorkerDrawCount)&&(t=l.fullWorkerDrawCount),De(l.subWorkerDrawCount)&&(i=l.subWorkerDrawCount),De(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 pf{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 vs({...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 gf(r){return r}var tn=gf;function ff(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 Mf=ff,yf=Mf,qi=Math.max;function mf(r,s,e){return s=qi(s===void 0?r.length-1:s,0),function(){for(var t=arguments,i=-1,o=qi(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),yf(r,this,a)}}var wf=mf;function If(r){return function(){return r}}var vf=If,Tf=vf,Ki=yo,Nf=tn,Sf=Ki?function(r,s){return Ki(r,"toString",{configurable:!0,enumerable:!1,value:Tf(s),writable:!0})}:Nf,Cf=Sf,kf=800,Df=16,xf=Date.now;function Lf(r){var s=0,e=0;return function(){var t=xf(),i=Df-(t-e);if(e=t,i>0){if(++s>=kf)return arguments[0]}else s=0;return r.apply(void 0,arguments)}}var bf=Lf,jf=Cf,Af=bf,zf=Af(jf),Pf=zf,Ef=tn,Of=wf,Rf=Pf;function Wf(r,s){return Rf(Of(r,s,Ef),r+"")}var Yf=Wf;function Uf(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 Bf=Uf;function Ff(r){return r!==r}var Qf=Ff;function Vf(r,s,e){for(var t=e-1,i=r.length;++t<i;)if(r[t]===s)return t;return-1}var Zf=Vf,Hf=Bf,Gf=Qf,$f=Zf;function Xf(r,s,e){return s===s?$f(r,s,e):Hf(r,Gf,e)}var Jf=Xf,qf=Jf;function Kf(r,s){var e=r==null?0:r.length;return!!e&&qf(r,s,0)>-1}var sn=Kf;function _f(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 on=_f;function eM(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 tM=eM,sM=oi,iM=sn,oM=on,nM=tM,rM=ms,aM=ni,cM=200;function lM(r,s,e,t){var i=-1,o=iM,n=!0,a=r.length,c=[],l=s.length;if(!a)return c;e&&(s=nM(s,rM(e))),t?(o=oM,n=!1):s.length>=cM&&(o=aM,n=!1,s=new sM(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 hM=lM,_i=Zt,uM=vo,dM=Ht,eo=_i?_i.isConcatSpreadable:void 0;function pM(r){return dM(r)||uM(r)||!!(eo&&r&&r[eo])}var gM=pM,fM=ti,MM=gM;function nn(r,s,e,t,i){var o=-1,n=r.length;for(e||(e=MM),i||(i=[]);++o<n;){var a=r[o];s>0&&e(a)?s>1?nn(a,s-1,e,t,i):fM(i,a):t||(i[i.length]=a)}return i}var yM=nn;function mM(){}var wM=mM,Ls=Ao,IM=wM,vM=ri,TM=1/0,NM=Ls&&1/vM(new Ls([,-0]))[1]==TM?function(r){return new Ls(r)}:IM,SM=NM,CM=oi,kM=sn,DM=on,xM=ni,LM=SM,bM=ri,jM=200;function AM(r,s,e){var t=-1,i=kM,o=r.length,n=!0,a=[],c=a;if(e)n=!1,i=DM;else if(o>=jM){var l=s?null:LM(r);if(l)return bM(l);n=!1,i=xM,c=new CM}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 zM=AM,PM=hM,EM=yM,to=zM;function OM(r,s,e){var t=r.length;if(t<2)return t?to(r[0]):[];for(var i=-1,o=Array(t);++i<t;)for(var n=r[i],a=-1;++a<t;)a!=i&&(o[i]=PM(o[i]||n,r[a],s,e));return to(EM(o,1),s,e)}var RM=OM,WM=qs,YM=Ke;function UM(r){return YM(r)&&WM(r)}var BM=UM,FM=ko,QM=Yf,VM=RM,ZM=BM;QM(function(r){return VM(FM(r,ZM))});class HM extends pf{constructor(e){super(e);M(this,"drawWorkActiveId")}async runFullWork(e){var o;const t=this.setFullWork(e),i=e.ops&&wt(e.ops);if(t){let n,a;const c=(o=t.getWorkId())==null?void 0:o.toString();return t.toolsType===v.Image?n=await t.consumeServiceAsync({isFullWork:!0,worker:this.thread}):t.toolsType===v.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()),he(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);Pe(this.fullLayer,this.fullLayer.parent)}canUseSubWorker(e){const t=this.thread.getPriorityDraw();return t||!t&&e!==v.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!==H&&(this.drawWorkActiveId=n);const c=a.toolsType;De(o)&&(this.consumeCount=o);const l=a.consume({data:e,drawCount:this.drawCount,isFullWork:!0,isSubWorker:!0,removeDrawCount:i});switch(c){case v.Selector:l&&(this.drawCount++,await this.drawSelector(l));break;case v.Ellipse:case v.Arrow:case v.Straight:case v.Rectangle:case v.Star:case v.Polygon:case v.SpeechBalloon:{l&&(this.drawCount++,await this.drawShape(l));break}case v.Pencil:case v.PencilEraser:case v.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 v.Selector:this.drawCount=0,Pe(this.fullLayer,this.fullLayer.parent),this.clearWorkShapeNodeCache(i),this._post({render:[{isClearAll:!0,clearCanvas:ye.Float,viewId:this.viewId}]});break;case v.Arrow:case v.Straight:case v.Ellipse:case v.Pencil:case v.Rectangle:case v.Star:case v.Polygon:case v.SpeechBalloon:case v.BitMapEraser:case v.PencilEraser:this.drawCount=0,Pe(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:ut(o),clearCanvas:ye.Float,isClear:!0,viewId:this.viewId},{rect:ut(o),drawCanvas:ye.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=he(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(),Re(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:ye.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)&&ut(e.rect),isClear:!0,clearCanvas:ye.Float,viewId:this.viewId},{rect:(e==null?void 0:e.rect)&&ut(e.rect),drawCanvas:ye.Float,viewId:this.viewId}]})}async drawSelector(e){await this._post({subWorkerDrawCount:this.drawCount,consumeCount:this.consumeCount,render:[{rect:(e==null?void 0:e.rect)&&ut(e.rect),isClear:!0,clearCanvas:ye.Float,viewId:this.viewId},{rect:(e==null?void 0:e.rect)&&ut(e.rect),drawCanvas:ye.Float,viewId:this.viewId}]})}}class GM{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===v.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===v.LaserPen)return vs({...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=he(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=he(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=wt(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 v.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=he(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:ye.TopFloat,viewId:this.viewId}),t.push({rect:h.totalRect,drawCanvas:ye.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 v.LaserPen:{if(p&&(i.push({isClear:!0,rect:p,clearCanvas:ye.TopFloat,viewId:this.viewId}),t.push({rect:p,drawCanvas:ye.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(Oe)[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 Ws=(r=>(r.Full="full",r.Sub="sub",r))(Ws||{});class $M extends df{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 HM(n),this.topLayerWork=new GM(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=oy(ke(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 ye.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===v.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===ge?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===ge?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()}),Pe(this.topLayer,this.topLayer.parent)),await this.post({render:[{isClearAll:!0,clearCanvas:ye.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:ye.Float,viewId:this.viewId}),t&&o.push({isClearAll:!0,clearCanvas:ye.TopFloat,viewId:this.viewId}),o.length&&await this.post({render:o})}async updateCamera(e){const t=[],{cameraOpt:i}=e;if(i&&!tt(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:ye.Float,viewId:this.viewId}),o){t.push({isClearAll:!0,clearCanvas:ye.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=ut({x:h.x,y:h.y,w:h.width,h:h.height});l=he(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=ke(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=he(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:ye.None},!0,o);n&&(this._post({sp:[{type:D.Snapshot,scenePath:t,imageBitmap:n,viewId:this.viewId}]},[n]),n.close(),this.snapshotFullLayer&&Pe(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=ke(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=he(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,Pe(this.snapshotFullLayer,this.snapshotFullLayer.parent),this.setCameraOpt(n,this.fullLayer)}}}class Qt extends Y{constructor(e){super(e);M(this,"canRotate",!0);M(this,"scaleType",re.all);M(this,"toolsType",v.Image);M(this,"tmpPoints",[]);M(this,"workOptions");M(this,"oldRect");this.workOptions=e.toolsOpt,this.scaleType=Qt.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 ae.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 ae.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 $M});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?re.proportional:re.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&&ke(n)||o.get(t.name);if(!f)return;const m=t.parent;if(m){if(p&&(f.opt.strokeColor=p),De(g)&&(t.setAttribute("zIndex",g),f.opt.zIndex=g),Nt(d)&&(f.opt.locked=d),c&&l&&u&&a){const{centerX:w,centerY:I,width:T,height:C,uniformScale:S}=f.opt,N=S!==!1?[u[0],u[0]]:u,x=[w,I],L=[w,I];li(L,l,N,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(T*N[0]),f.opt.height=Math.round(C*N[1]),f.opt.centerX=L[0],f.opt.centerY=L[1],f.opt.eraserlines)for(const E of Object.values(f.opt.eraserlines)){const{op:A,thickness:P}=E;E.thickness=P*Math.max(u[0],u[1]);for(let R=0;R<A.length;R++)hi(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 T=0;T<I.length;T++){const C=I[T].map((S,N)=>N%2?S+a[1]:S+a[0]);w.op[T]=C}}}else if(De(h))if(f.opt.rotate=h,f.scaleType=Qt.getScaleType(f.opt),n){const w=rn(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 he(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 ci(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 fe(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 Ys(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 ut(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 Vt(r,s){return{x:r.x+s[0],y:r.y+s[1],w:r.w,h:r.h}}function XM(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 rn(r,s){const e=XM(r,s);return fe(e)}function an(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 fe([l,u,h,d])}function JM(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 qM(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 li(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 hi(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 cn(r,s){return r[0]>=s.x&&r[0]<=s.x+s.w&&r[1]>=s.y&&r[1]<=s.y+s.h}function ln(r,s){const e=r<=s?1:r/s,t=s<=r?1:s/r;return[e,t]}function KM(r){for(const s of r)if(isNaN(s)||s===1/0||s===-1/0)return!1;return!0}function _M(r){return r!==Math.floor(r)}function ey(r){const s=r.toString();return s.indexOf(".")!==-1?s.split(".")[1].length:0}function ty(r,s){for(;s!==0;)[r,s]=[s,r%s];return r}const sy=r=>{if(r.tagName==="GROUP"){const s=Object.getOwnPropertySymbols(r).find(e=>e.toString()==="Symbol(sealed)");if(s&&r[s])return!0}return!1},Re=(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)Re(e,s)},Pe=(r,s)=>{Re(r,s),r.removeAllChildren()},iy=(r,s,e)=>{const t=e.parent;if(s){const i=s.children;if(i){for(const o of i)if(Re(o,t),o.tagName==="GROUP")for(const n of o.children)Re(n,t)}}s.parent.replaceChild(r,s)},oy=(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)),_M(e)){const n=ey(e),a=Math.pow(10,n),c=ty(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 It(r){return`${cs(r.x)},${cs(r.y)} `}function vt(r,s){return`${cs((r.x+s.x)/2)},${cs((r.y+s.y)/2)} `}function cs(r){return+r.toFixed(4)}const st=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()})},it=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)},ui=(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?ft.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?ft.inside:ft.intersect;function ny(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 ry{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 $.toJS((s=this.plugin)==null?void 0:s.attributes[this.namespace])||{}}getAuthSpaceData(){var s;return $.toJS((s=this.plugin)==null?void 0:s.attributes[this.authSpace])||{}}getUidFromKey(s){return s.split(Oe).length===2&&s.split(Oe)[0]||this.uid}isLocalId(s){return s.split(Oe).length===1}getLocalId(s){return s.split(Oe)[1]}isSelector(s){return this.getLocalId(s)===H}}const Ne=class Ne extends ry{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=Ne.componentsLimits.indexOf(o),f=p>=0&&p<Ne.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,T,C,S;(T=(I=(w=this.control.room)==null?void 0:w.callbacks)==null?void 0:I.listeners)!=null&&T.map.onKickedWithReason&&((S=(C=this.control.room)==null?void 0:C.callbacks)==null||S.dispatch("onKickedWithReason",N=>N("kickByAdmin")))});return}console.warn(`exceeds the limit of ${o} components, current: ${i}`);const m=f?Ne.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)});Ne.syncInterval=(i||Ne.syncInterval)*.5,this.namespace=Ne.namespace,this.authSpace=Ne.authSpace,this.serviceStorage=this.getNamespaceData(),this.storage=O.cloneDeep(this.serviceStorage),this.authStorage=this.getAuthSpaceData(),this.getLimitNums()}getLimitNum(e){return e>=Ne.componentsLimits[0]?Ne.componentsLimits[1]:Ne.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)===H))}addStorageStateListener(e){this.stateDisposer=$.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=Le(e),o=Le(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=Le(e),n=Le(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=Le(e),a=Le(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+Oe+e}isOwn(e){return e.split(Oe)[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:""})),st(()=>{var S;this.control.pluginManager.dispatchPluginEvent("syncStorage",f,p),(S=this.control.miniMapManager)==null||S.updateMiniMapCamera(f),this.clearLimitComponents(f,p)},Ne.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,N=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][S]||void 0;if(N!=null&&N.ops||(N==null?void 0:N.type)===D.FullWork)return;const x=n?((N==null?void 0:N.op)||[]).slice(0,n).concat(h):h||(N==null?void 0:N.op),L=c||(N==null?void 0:N.toolsType),b=a||(N==null?void 0:N.opt),E=u||(N==null?void 0:N.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(),{...N,type:D.DrawWork,workId:i,updateNodeOpt:E,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,N=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][S]||void 0,x=u||(N==null?void 0:N.updateNodeOpt),L=c||(N==null?void 0:N.toolsType),b=a||(N==null?void 0:N.opt),E=o||(N==null?void 0:N.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:E},{isSync:g,viewId:f,scenePath:p}),st(()=>{var A;this.control.pluginManager.dispatchPluginEvent("syncStorage",f,p),(A=this.control.miniMapManager)==null||A.updateMiniMapCamera(f),this.limitComponents(f,p)},Ne.syncInterval))}break;case D.RemoveNode:if(p&&(l!=null&&l.length)){const S=l.map(N=>this.isLocalId(N+"")?this.transformKey(N):N);this.storage[f]&&this.storage[f][p]&&(Object.keys(this.storage[f][p]).map(N=>{S!=null&&S.includes(N)&&(this.control.renderControl.isUsePageAuth(f)&&this.control.renderControl.delRenderPageElementId({viewId:f,scenePath:p,elementId:N}),this.updateValue(N,void 0,{isSync:g,viewId:f,scenePath:p}))}),st(()=>{var N;this.control.pluginManager.dispatchPluginEvent("syncStorage",f,p),(N=this.control.miniMapManager)==null||N.updateMiniMapCamera(f)},Ne.syncInterval))}break;case D.UpdateNode:if(p&&i&&(u||o||a)){const S=this.isLocalId(i.toString())?this.transformKey(i):i,N=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][S]||void 0;N&&(N.updateNodeOpt=u,(o||h)&&(N.ops=o,N.op=h),a&&(N.opt=a),N.type=D.FullWork,this.updateValue(S.toString(),N,{isSync:g,viewId:f,scenePath:p}),st(()=>{var x;(x=this.control.miniMapManager)==null||x.updateMiniMapCamera(f)},Ne.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(H),T=this.storage[f]&&this.storage[f][p]&&this.storage[f][p][I]||void 0,C=a||(T==null?void 0:T.opt);w&&this.checkOtherSelector(I,w,{isSync:g,viewId:f,scenePath:p}),this.updateValue(I,w&&{type:D.Select,toolsType:v.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)===H){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=Le(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:Ne.syncInterval))}syncSerivice(e={storage:this.storage}){const{storage:t}=e,i=t||this.storage,o=Le(this.serviceStorage),n=Le(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=Le(this.serviceStorage[t]),o=Le(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=Le(this.serviceStorage[t][i]),n=Le(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(Oe);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,T,C,S,N,x,L,b,E,A,P,R,z,X,K,F,G,_,ce,ee,q,J,ue,ze,Te,V,le,ie,pe;const{operation:i,viewId:o,scenePath:n,pageId:a,pageData:c}=e;switch(i){case je.addPage:{if(!o||!n||!a)return;const de=[this.authSpace];Object.keys(this.authStorage).length&&de.push("pageAuth");const Me=this.authStorage.pageAuth||{};this.authStorage.pageAuth=Me,Object.keys(Me).length&&de.push(o),Me[o]=Me[o]||{},Object.keys(Me[o]).length&&de.push(n),Me[o][n]=Me[o][n]||{render:(c==null?void 0:c.render)||"localSelf",pages:{}},Object.keys(Me[o][n].pages).length&&de.push("pages",a);const ot={};if(c!=null&&c.elementIds)for(const nt of c.elementIds.keys())ot[nt]=!0;Me[o][n].pages[a]=ot,t&&(de.length===1?(l=this.plugin)==null||l.updateAttributes(de,O.cloneDeep(this.authStorage)):de.length===2?(u=this.plugin)==null||u.updateAttributes(de,O.cloneDeep(Me)):de.length===3?(h=this.plugin)==null||h.updateAttributes(de,O.cloneDeep(Me[o])):de.length===4?(d=this.plugin)==null||d.updateAttributes(de,O.cloneDeep(Me[o][n])):(g=this.plugin)==null||g.updateAttributes(de,O.cloneDeep(ot)));return}case je.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 je.deletePage:{if(!o||!n||!a)return;(T=(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&&T[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 je.clearPage:{if(!o||!n||!a)return;(b=(L=(x=(N=(S=this.authStorage)==null?void 0:S.pageAuth)==null?void 0:N[o])==null?void 0:x[n])==null?void 0:L.pages)!=null&&b[a]&&(delete this.authStorage.pageAuth[o][n].pages[a],t&&((E=this.plugin)==null||E.updateAttributes([this.authSpace,"pageAuth",o,n,"pages",a],{})));return}case je.addElement:{if(!o||!n||!a||!(c!=null&&c.elementId))return;(X=(z=(R=(P=(A=this.authStorage)==null?void 0:A.pageAuth)==null?void 0:P[o])==null?void 0:R[n])==null?void 0:z.pages)!=null&&X[a]&&(this.authStorage.pageAuth[o][n].pages[a][c.elementId]=!0,t&&((K=this.plugin)==null||K.updateAttributes([this.authSpace,"pageAuth",o,n,"pages",a,c.elementId],!0)));return}case je.deleteElement:{if(!o||!n||!a||!(c!=null&&c.elementId))return;(q=(ee=(ce=(_=(G=(F=this.authStorage)==null?void 0:F.pageAuth)==null?void 0:G[o])==null?void 0:_[n])==null?void 0:ce.pages)==null?void 0:ee[a])!=null&&q[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 je.clearViewScenePath:{if(!o||!n)return;(Te=(ze=(ue=this.authStorage)==null?void 0:ue.pageAuth)==null?void 0:ze[o])!=null&&Te[n]&&(delete this.authStorage.pageAuth[o][n],t&&((V=this.plugin)==null||V.updateAttributes([this.authSpace,"pageAuth",o,n],void 0)));return}case je.clearView:{if(!o)return;(ie=(le=this.authStorage)==null?void 0:le.pageAuth)!=null&&ie[o]&&(delete this.authStorage.pageAuth[o],t&&((pe=this.plugin)==null||pe.updateAttributes([this.authSpace,"pageAuth",o],void 0)));return}}}dispatchRenderAuth(e,t=!0){var l,u,h,d,g,p,f,m,w,I,T,C,S,N,x,L,b,E,A,P;const{operation:i,viewId:o,uid:n,renderData:a,isClear:c}=e;if(o)switch(i){case He.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:X,hide:K,clear:F}=a;if(X===!0)z[o].render=!0;else if(O.isSet(X)){z[o].render={};for(const G of X.keys())z[o].render[G]=!0}if(K===!0)z[o].hide=!0;else if(O.isSet(K)){z[o].hide={};for(const G of K.keys())z[o].hide[G]=!0}if(F===!0)z[o].clear=!0;else if(O.isSet(F)){z[o].clear={};for(const G of F.keys())z[o].clear[G]=!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 He.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 He.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&&((T=z[o].render)!=null&&T[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?(N=this.plugin)==null||N.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 He.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?(E=this.plugin)==null||E.updateAttributes(R,O.cloneDeep(z)):R.length===3?(A=this.plugin)==null||A.updateAttributes(R,O.cloneDeep(z[o])):(P=this.plugin)==null||P.updateAttributes(R,c?!0:void 0));return}}}addAuthStateListener(e){this.authDisposer=$.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=Le(e),o=Le(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=Le(e),o=Le(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(Ne,"namespace","PluginState"),M(Ne,"authSpace","PluginAuth"),M(Ne,"syncInterval",500),M(Ne,"componentsLimits",[500,1e3]);let Us=Ne;class ay{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 qe=(r=>(r[r.Text=1]="Text",r[r.Shape=2]="Shape",r))(qe||{});const Ee=class Ee{createProxy(s){const e=new Proxy(s,{get(t,i,o){const n=Ee.interceptors.hasOwnProperty(i)?Ee.interceptors:t;return Reflect.get(n,i,o)}});return Ee.proxyToRaw.set(e,s),e}};M(Ee,"proxyToRaw",new WeakMap),M(Ee,"interceptors",{entries(...s){return Ee.proxyToRaw.get(this).entries(...s)},forEach(...s){return Ee.proxyToRaw.get(this).forEach(...s)},size(){return Ee.proxyToRaw.get(this).size},get(s){return Ee.proxyToRaw.get(this).get(s)},set(s,e){return Ee.proxyToRaw.get(this).set(s,e)},delete(s,e){return Ee.proxyToRaw.get(this).delete(s)},clear(){return Ee.proxyToRaw.get(this).clear()}});let dt=Ee;class cy{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 dt;const n=this,a=dt.interceptors.set;dt.interceptors.set=function(l,u){return n.interceptors.set(l,u),a.call(this,l,u)};const c=dt.interceptors.delete;dt.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,T,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===v.Text&&(n&&(this.control.worker.queryTaskBatchData({workId:s,msgType:D.UpdateNode}).forEach(S=>{var N;(N=this.control.worker)==null||N.taskBatchData.delete(S)}),(T=this.control.worker)==null||T.taskBatchData.add({workId:s,msgType:D.UpdateNode,dataType:l||B.Local,toolsType:v.Text,opt:c,viewId:t,scenePath:i,willRefresh:!0}),(C=this.control.worker)==null||C.runAnimation()),o&&(st(()=>{var S;(S=this.collector)==null||S.dispatch({type:D.UpdateNode,workId:s,toolsType:v.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===qe.Text&&(o&&((m=this.collector)==null||m.dispatch({type:c.text&&D.FullWork||D.CreateWork,workId:s,toolsType:v.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:v.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:v.Text,msgType:D.RemoveNode,dataType:B.Local,viewId:t,scenePath:i,willRefresh:!0}),(c=this.control.worker)==null||c.runAnimation()),o&&st(()=>{var l;(l=this.collector)==null||l.dispatch({type:D.RemoveNode,removeIds:[s],toolsType:v.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:qe.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:qe.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 ly{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===Bt.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}${Oe}${e}`}getUidAndviewId(s){const[e,t]=s.split(Oe);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([se.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([se.Cursor,t],[])))}const n=this.doneRenderCursorInfoMap.get(t);O.isEqual(n,o)||(this.doneRenderCursorInfoMap.set(t,o),this.internalMsgEmitter.emit([se.Cursor,t],o))}else this.cursorInfoMap.delete(t),this.doneRenderCursorInfoMap.delete(t),this.internalMsgEmitter.emit([se.Cursor,t],[]);(this.willConsumeEventWorkers.size||this.cursorInfoMap.size)&&this.runAnimation()}sendEvent(s,e){if(this.displayer&&$.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&&$.isRoom(this.displayer)&&this.displayer.isWritable&&this.displayer.dispatchMagixEvent(this.eventName,{type:Bt.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&&$.isRoom(this.displayer)&&(this.willSendEventWorkers.length=0,this.displayer.dispatchMagixEvent(this.eventName,{type:Bt.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([se.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 Fe{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=Se.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){st(()=>{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=Se.InternalMsgEmitter)==null||s.emit(Q.ActiveMethod,!1)}}recover(){var s;this.useEmtMsg&&Se.InternalMsgEmitter.hasListeners(Q.ActiveMethod)&&((s=Se.InternalMsgEmitter)==null||s.emit(Q.ActiveMethod,!0))}}class hy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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===H){const p=g&&this.copySelector({viewId:i,store:g});p&&this.pasteSelector({...p,viewId:i,scenePath:n,undoTickerId:a});break}if(g.toolsType===v.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===v.Text&&o.opt){const I=o.opt;if(I&&I.boxPoint&&I.text){I.workState=j.Done;const T=I.boxPoint;I.boxPoint=[T[0]+g[0],T[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:qe.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,T,C,S,N,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())||((T=o.displayer.canvasContainerRef.current)==null?void 0:T.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=(N=this.serviceColloctor)==null?void 0:N.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,T]of t.entries()){const S=(this.serviceColloctor.isLocalId(I)?I:this.serviceColloctor.getLocalId(I.toString()))+"-"+a,N={useAnimation:!1};if(T.toolsType===v.Text&&T.opt){const L=T.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 E=this.control.viewContainerManager.transformToOriginPoint(L.boxPoint,o);this.control.textEditorManager.createTextForMasterController({workId:S,x:E[0],y:E[1],opt:L,scale:((m=c.cameraOpt)==null?void 0:m.scale)||1,type:qe.Text,isActive:!1,viewId:o,scenePath:n})}f.push({...T,opt:L,type:D.FullWork,workId:S,viewId:o,scenePath:n});continue}if(T.toolsType===v.Image&&(T.opt.uuid=S,T.opt.centerX=T.opt.centerX+g[0],T.opt.centerY=T.opt.centerY+g[1]),T.ops){const L=wt(T.ops).map((E,A)=>{const P=A%3;return P===0?E+g[0]:P===1?E+g[1]:E}),b=We(L);T.ops=b}const x=((w=T==null?void 0:T.opt)==null?void 0:w.eraserlines)??[];if(x.length)for(const L of Object.values(x)){const{op:b}=L;for(let E=0;E<b.length;E++){const A=b[E].map((P,R)=>R%2?P+g[1]:P+g[0]);L.op[E]=A}}f.push({...T,updateNodeOpt:N,type:D.FullWork,workId:S,viewId:o,scenePath:n}),p.push([{...T,updateNodeOpt:N,workId:S,msgType:D.FullWork,dataType:B.Local,emitEventType:Q.CopyNode,willSyncService:!1,willRefresh:!0,viewId:o},{workId:S,msgType:D.FullWork,emitEventType:Q.CopyNode}])}p.length&&this.collectForLocalWorker(p),f.length&&this.collectForServiceWorker(f)}}class uy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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,T;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(),N=this.serviceColloctor.isLocalId(S),x=N?this.serviceColloctor.transformKey(C):S;let L=S;!N&&this.serviceColloctor.isOwn(L)&&(L=this.serviceColloctor.getLocalId(L));const b=(T=(I=f==null?void 0:f[c])==null?void 0:I[g])==null?void 0:T[x];if(b){const E=b.updateNodeOpt||{};if(n||a){if(n){E.fontColor=n;const[P,R,z,X]=Ut(n);w.textColor=[P,R,z],w.textOpacity=X}if(a)if(E.fontBgColor=Jt(a)?"transparent":a,Jt(a))w.textBgColor=void 0,w.textBgOpacity=void 0;else{const[P,R,z,X]=Ut(a);w.textBgColor=[P,R,z],w.textBgOpacity=X}if(b.toolsType===v.Text&&b.opt&&l!==j.Start){this.setTextColor(L,ke(b),E,c),l===j.Done&&(this.undoTickerId=void 0);continue}}if(i){E.strokeColor=i;const[P,R,z,X]=Ut(i);w.strokeColor=[P,R,z],w.strokeOpacity=X}if(o)if(E.fillColor=Jt(o)?"transparent":o,Jt(o))w.fillColor=void 0,w.fillOpacity=void 0;else{const[P,R,z,X]=Ut(o);w.fillColor=[P,R,z],w.fillOpacity=X}u&&(E.thickness=u,w.strokeWidth=u),h&&(E.strokeType=h,w.strokeType=h);const A={workId:L,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:E,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 dy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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=ke(l[o][a][m]);let T;if(I&&w===H){if(I.selectIds){h.push(...I.selectIds),h.sort((x,L)=>{var A,P,R,z;const b=((P=(A=l[d(x,this.serviceColloctor)])==null?void 0:A.opt)==null?void 0:P.zIndex)||0,E=((z=(R=l[d(x,this.serviceColloctor)])==null?void 0:R.opt)==null?void 0:z.zIndex)||0;return b>E?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},N=new Map;i===Ft.Top?(this.addMaxLayer(o),T=this.getMaxZIndex(o)):(this.addMinLayer(o),T=this.getMinZIndex(o)),h.forEach(x=>{var A,P,R,z,X;const L=(A=this.serviceColloctor)==null?void 0:A.isLocalId(x);let b=L&&((P=this.serviceColloctor)==null?void 0:P.transformKey(x))||x;const E=(z=(R=l==null?void 0:l[o])==null?void 0:R[a])==null?void 0:z[b];E&&(!L&&((X=this.serviceColloctor)!=null&&X.isOwn(b))&&(b=this.serviceColloctor.getLocalId(b)),C.zIndex=T,E!=null&&E.opt&&(E.opt.zIndex=T),E!=null&&E.opt&&N.set(b,{updateNodeOpt:E.updateNodeOpt,opt:E.opt}))}),S.selectStore=N,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 py extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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(),T=this.serviceColloctor.isLocalId(I),C=T&&this.serviceColloctor.transformKey(w)||I;let S=I;!T&&this.serviceColloctor.isOwn(S)&&(S=this.serviceColloctor.getLocalId(S));const N=(m=(f=h==null?void 0:h[a])==null?void 0:f[l])==null?void 0:m[C];if(N&&S===H){if(N.selectIds){const x=this.control.viewContainerManager.transformToScenePoint([o.x,o.y],a);if(n===j.Start&&(this.cachePosition=x),this.cachePosition){const L=N.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 gy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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 T=f;if(!m&&this.serviceColloctor.isOwn(T)&&(T=this.serviceColloctor.getLocalId(T)),I.toolsType===v.Text){this.control.textEditorManager.delete(T,!0,!0);continue}u.push(T)}}u.length&&(l.push([{msgType:D.RemoveNode,emitEventType:Q.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 fy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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,T,C,S,N,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 E=b.toString(),A=this.serviceColloctor.isLocalId(E),P=A&&this.serviceColloctor.transformKey(b)||E;let R=E;!A&&this.serviceColloctor.isOwn(R)&&(R=this.serviceColloctor.getLocalId(R));const z=(C=(T=f==null?void 0:f[n])==null?void 0:T[g])==null?void 0:C[P];if(z&&R===H&&z.selectIds){const X=z.updateNodeOpt||{};if(X.dir=l,X.originPoint=a,X.scenePoint=c,X.workState=o,X.scale=u,X.translate=h,o===j.Start){this.cacheTextInfo.clear();for(const F of z.selectIds){const G=(S=this.serviceColloctor)==null?void 0:S.isLocalId(F),_=G&&((N=this.serviceColloctor)==null?void 0:N.transformKey(F))||F;let ce=_;!G&&((x=this.serviceColloctor)!=null&&x.isOwn(_))&&(ce=this.serviceColloctor.getLocalId(_));const ee=this.control.textEditorManager.get(ce);ee&&o===j.Start&&this.targetText.set(ce,ke(ee))}}if(this.targetText.size&&o!==j.Start&&u){const F=[];for(const[_,ce]of this.targetText.entries()){const{opt:ee}=ce,q=Math.floor(ee.fontSize*u[0]),J=this.cacheTextInfo.get(_),ue=!J&&ee.fontSize!==q||J&&J.fontSize!==q||!1,ze=(L=this.control.textEditorManager.get(_))==null?void 0:L.opt;if(ue&&ze&&ee.boxSize&&ee.boxPoint){const Te=this.setTextStyle(_,{...ze,fontSize:q},n);F.push(Te)}}const G=await Promise.all(F);for(const _ of G)if(_){const{key:ce,textInfo:ee}=_;this.cacheTextInfo.set(ce,{fontSize:ee.opt.fontSize,boxSize:ee.opt.boxSize,boxPoint:ee.opt.boxPoint})}X.textInfos=this.cacheTextInfo}const K={workId:b,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:X,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:n};o===j.Done&&(K.willSerializeData=!0,this.targetText.clear()),m.push([K,{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 My extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.RotateNode);M(this,"cacheOriginRotate",0)}collect(e,t){var p,f,m,w,I,T,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 N=S.toString(),x=this.serviceColloctor.isLocalId(N),L=x&&this.serviceColloctor.transformKey(S)||N;let b=N;!x&&this.serviceColloctor.isOwn(b)&&(b=this.serviceColloctor.getLocalId(b));const E=(m=(f=h==null?void 0:h[a])==null?void 0:f[l])==null?void 0:m[L];if(E&&b===H){if(((w=E.selectIds)==null?void 0:w.length)===1){const A=E.selectIds[0];if(n===j.Start){const X=((I=this.serviceColloctor)==null?void 0:I.isLocalId(A))&&((T=this.serviceColloctor)==null?void 0:T.transformKey(A))||A,K=h[a][l][X];this.cacheOriginRotate=((C=K==null?void 0:K.opt)==null?void 0:C.rotate)||0}const P=E.updateNodeOpt||{};P.angle=(o+this.cacheOriginRotate)%360,P.workState=n;const R={workId:S,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:P,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 yy(r){switch(r){case v.Text:return qe.Text;case v.SpeechBalloon:case v.Star:case v.Ellipse:case v.Rectangle:case v.Triangle:case v.Rhombus:case v.Polygon:return qe.Shape}}class my extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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&&yy(t.toolsType)===qe.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,T,C,S,N,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(),E=this.serviceColloctor.isLocalId(b),A=E?this.serviceColloctor.transformKey(L):b;let P=b;!E&&this.serviceColloctor.isOwn(P)&&(P=this.serviceColloctor.getLocalId(P));const R=(T=(I=g==null?void 0:g[c])==null?void 0:I[h])==null?void 0:T[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===v.Text&&R.opt){const X=this.setTextStyle(P,O.cloneDeep(R),z,c);m.push(X);continue}if(R&&P===H&&((C=R.selectIds)!=null&&C.length))for(const X of R.selectIds){const K=(S=this.serviceColloctor)==null?void 0:S.isLocalId(X);let F=K&&((N=this.serviceColloctor)==null?void 0:N.transformKey(X))||X;const G=g[c][h][F]||void 0;if(!K&&((x=this.serviceColloctor)!=null&&x.isOwn(F))&&(F=this.serviceColloctor.getLocalId(F)),G&&G.toolsType===v.Text&&R.opt){const _=this.setTextStyle(F,O.cloneDeep(G),z,c);m.push(_);continue}}}}const w=await Promise.all(m);for(const L of w)if(L){const{key:b,textInfo:E}=L;E&&(E.canSync=!0,E.canWorker=!0,this.control.textEditorManager.updateForViewEdited(b,E))}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 wy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.SetPoint);M(this,"undoTickerId")}collect(e){var I,T,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=(T=l==null?void 0:l[n])==null?void 0:T[c])==null?void 0:C[f];if(w&&m===H&&w.selectIds){const S=w.updateNodeOpt||{};S.pointMap=i,S.workState=o;const N={workId:d,msgType:D.UpdateNode,dataType:B.Local,updateNodeOpt:S,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:n};o===j.Done&&(N.undoTickerId=this.undoTickerId),u.push([N,{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 Iy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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 T=(g=(d=l==null?void 0:l[o])==null?void 0:d[a])==null?void 0:g[w];if(T){const C=T.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 vy extends Fe{constructor(){super(...arguments);M(this,"lastEmtData");M(this,"emitEventType",Q.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 T=(g=(d=l==null?void 0:l[i])==null?void 0:d[a])==null?void 0:g[w];if(T){const C={...T.updateNodeOpt,...o,willRefresh:!0};if(T&&I===H){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 ne{constructor(s){M(this,"builders",new Map);this.builders=new Map(s.map(e=>[e,this.build(e)]))}build(s){switch(s){case Q.TranslateNode:return new py;case Q.ZIndexNode:return new dy;case Q.CopyNode:return new hy;case Q.SetColorNode:return new uy;case Q.DeleteNode:return new gy;case Q.ScaleNode:return new fy;case Q.RotateNode:return new My;case Q.SetFontStyle:return new my;case Q.SetPoint:return new wy;case Q.SetLock:return new Iy;case Q.SetShapeOpt:return new vy}}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){Fe.dispatch(s,e,t)}static activeListener(s){Se.InternalMsgEmitter.on(Q.ActiveMethod,s)}static unmountActiveListener(s){Se.InternalMsgEmitter.off(Q.ActiveMethod,s)}}class Ty{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 Ny(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 Ny{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===ge?i:o,contextType:"2d"});const n={thread:this};this.subLocalWork=new Sy(n)}createScene(s){return new ae.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 ae.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()}),Pe(this.subLocalLayer,this.subLocalLayer.parent)),this.subLocalWork.clearAll()}destroy(){this.subLocalLayer.remove(),Re(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(),Re(t,this.subLocalLayer.parent)}}class Sy{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,Pe(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(){Pe(this.thread.subLocalLayer,this.thread.subLocalLayer.parent),this.workShapes.clear()}canUseSubWorkerLayer(s){return s===v.Pencil}setToolsOpt(s){var e;this.tmpOpt=s,(e=s.toolsOpt)!=null&&e.syncUnitTime&&(this.syncUnitTime=s.toolsOpt.syncUnitTime)}createWorkShapeNode(s){return vs({...s,fullLayer:this.thread.subLocalLayer,drawLayer:this.thread.subLocalLayer})}clearWorkShapeNodeCache(s){this.workShapes.delete(s)}getWorkShape(s){return this.workShapes.get(s)}}const Cy=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 ky{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 Dy extends ky{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===v.Pencil||e===v.PencilEraser||e===v.BitMapEraser||e===v.LaserPen||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Selector}get isCanDrawWork(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.LaserPen||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Triangle||e===v.Rhombus||e===v.BitMapEraser||e===v.PencilEraser}get isUseZIndex(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Text||e===v.Image}get isCanRecordUndoRedo(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.Eraser||e===v.PencilEraser||e===v.BitMapEraser||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Text||e===v.Image}get isCanSentCursor(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.Text||e===v.LaserPen||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Triangle||e===v.Rhombus||e===v.Eraser||e===v.PencilEraser||e===v.BitMapEraser||e===v.Selector}get isPostCountType(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.Arrow||e===v.Straight||e===v.Ellipse||e===v.Rectangle||e===v.Star||e===v.Polygon||e===v.SpeechBalloon||e===v.Triangle||e===v.Rhombus||e===v.Eraser||e===v.PencilEraser||e===v.BitMapEraser||e===v.Selector}get isCanPostDraw(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Pencil||e===v.PencilEraser||e===v.BitMapEraser}get isCanStartEventConsum(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===v.Selector||e===v.Eraser||e===v.PencilEraser||e===v.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-ZopisCqE.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 Ty(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:T,rect:C,op:S,canTextEdit:N,points:x,selectorColor:L,canRotate:b,scaleType:E,textOpt:A,toolsType:P,workId:R,viewId:z,dataType:X,canLock:K,isLocked:F,shapeOpt:G,toolsTypes:_,thickness:ce,strokeType:ee,useStroke:q,isgl:J,imageSrc:ue,isSubWorker:ze}=c;if(!z)return;const Te=c.scenePath||this.viewContainerManager.getCurScenePath(z);switch(l){case D.Select:{const V=u!=null&&u.length?{...d,selectIds:u,canvasHeight:I,canvasWidth:T,points:x}:void 0;V&&(h!=null&&h.strokeColor)&&(V.selectorColor=h.strokeColor),V&&L&&(V.selectorColor=L),V&&g&&(V.strokeColor=g),V&&(h!=null&&h.fillColor)&&(V.fillColor=h.fillColor),V&&p&&(V.fillColor=p),V&&O.isBoolean(b)&&(V.canRotate=b),V&&E&&(V.scaleType=E),V&&N&&(V.canTextEdit=N),V&&A&&(V.textOpt=A),V&&O.isBoolean(K)&&(V.canLock=K),V&&O.isBoolean(F)&&(V.isLocked=F),V&&G&&(V.shapeOpt=G),V&&_&&(V.toolsTypes=_),V&&ce&&(V.thickness=ce),V&&ee&&(V.strokeType=ee),V&&O.isBoolean(q)&&(V.useStroke=q),z&&this.viewContainerManager.showFloatBar(z,!!V,V),f&&((i=this.collector)==null||i.dispatch({type:l,selectIds:u,opt:h,isSync:m,viewId:z,scenePath:Te}));break}case D.Snapshot:if(w&&Te){const V=this.snapshotMap.get(Te);V&&V(w)}break;case D.BoundingBox:if(C&&Te){const V=this.boundingRectMap.get(Te);V&&V(C)}break;case D.Cursor:S&&this.control.cursor.collectServiceCursor({...c});break;case D.Clear:if(z){this.viewContainerManager.showFloatBar(z,!1);const V=(o=this.clearAllResolveMap.get(z))==null?void 0:o.resolve;V&&V(z)}break;case D.TextUpdate:if(P===v.Text&&R&&z){const V=this.viewContainerManager.transformToOriginPoint((h==null?void 0:h.boxPoint)||[0,0],z),le=(h==null?void 0:h.boxSize)||[0,0],ie=(n=this.viewContainerManager.getView(z))==null?void 0:n.cameraOpt;h?this.control.textEditorManager.updateTextForWorker({x:V[0],y:V[1],w:le[0],h:le[1],scale:(ie==null?void 0:ie.scale)||1,workId:R,opt:h,dataType:X,viewId:z,canSync:f||!1,canWorker:!1}):this.control.textEditorManager.delete(R,f||!1,!1)}break;case D.GetTextActive:P===v.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:ue&&z&&R&&Cy({src:ue,isgl:J}).then(V=>{var ie;const le=new Set;if(le.add({msgType:D.GetImageBitMap,dataType:B.Local,workId:R,viewId:z,imageSrc:ue,isSubWorker:ze,imageBitmap:V}),!this.control.hasOffscreenCanvas())(ie=this.mainThread)==null||ie.consume(le);else{const pe=ze?this.subWorker:this.fullWorker;V?pe.postMessage(le,[V]):pe.postMessage(le)}});break;case D.GetVNodeInfo:if(R){const V=R.toString(),le=(a=this.getVNodeInfoResolveMap.get(V))==null?void 0:a.resolve,ie={...c,uuid:V};le&&le(ie)}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:T,nextTasks:C}=a;if(!I){console.error("collectorAsyncData",a);return}const S=a.scenePath||this.viewContainerManager.getCurScenePath(I);switch(c){case D.None:{T&&st(()=>{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)===v.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:qe.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)===v.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===v.Selector?H: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!==v.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)===v.Selector;switch((u=this.currentToolsData)==null?void 0:u.toolsType){case v.Eraser:case v.PencilEraser:case v.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(st(()=>{this.control.pluginManager.dispatchPluginEvent("localEvent",i,e,t)},ai),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:Kt}),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,T;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))===H){this.collector.isOwn(l)?this.blurSelector(n,a):this.blurSelector(n,a,l);return}if(u=D.RemoveNode,o.toolsType===v.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===v.LaserPen&&(C.isRunSubWork=!0),C.dataType=B.Service,C.viewId=n,C.scenePath=a,C.selectIds&&(C.selectIds=C.selectIds.map(S=>{var N,x;return(N=this.collector)!=null&&N.isOwn(S)?(x=this.collector)==null?void 0:x.getLocalId(S):S})),C&&C.toolsType===v.Text||(o==null?void 0:o.toolsType)===v.Text){this.control.textEditorManager.onServiceDerive(C);return}this.taskBatchData.add(C)}this.runAnimation();const d=t.newValue&&((T=t.newValue.opt)==null?void 0:T.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(T=>{var C,S;return(C=this.collector)!=null&&C.isOwn(T)?(S=this.collector)==null?void 0:S.getLocalId(T):T})),I.toolsType===v.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),this.localPointsBatchData.clear(),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 ne([Q.CopyNode,Q.SetColorNode,Q.DeleteNode,Q.RotateNode,Q.ScaleNode,Q.TranslateNode,Q.ZIndexNode,Q.SetFontStyle,Q.SetPoint,Q.SetLock,Q.SetShapeOpt]).registerForMainEngine(se.MainEngine,this.control),this.zIndexNodeMethod=(e=this.methodBuilder)==null?void 0:e.getBuilder(Q.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)===v.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(cn(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)!==v.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===v.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 v.Eraser:case v.PencilEraser:case v.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))===H&&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))===H&&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();Se.InternalMsgEmitter.emit("addUndoTicker",c,e);const l={...t,type:Mt.Iconify};this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayer(e),l.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),this.taskBatchData.add({msgType:D.FullWork,dataType:B.Local,toolsType:v.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();Se.InternalMsgEmitter.emit("addUndoTicker",c,e);const l={...t,type:Mt.Image};this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayer(e),l.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),this.taskBatchData.add({msgType:D.FullWork,dataType:B.Local,toolsType:v.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===v.Image&&h.opt.uuid===t){const d=Date.now();Se.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:Mt.Image};this.taskBatchData.add({msgType:D.FullWork,dataType:B.Local,toolsType:v.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===v.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:H,selectIds:[e],msgType:D.Select,dataType:B.Local,viewId:t,willSyncService:!0}),this.runAnimation()}blurSelector(e,t,i){this.taskBatchData.add({workId:i||H,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:Kt,dataType:B.Local,isRunSubWork:!0})),e==="ui"){t.add({msgType:D.PriorityMainThreadWorker,viewId:Kt,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 xy=Ge,Ly=function(){return xy.Date.now()},by=Ly,jy=/\s/;function Ay(r){for(var s=r.length;s--&&jy.test(r.charAt(s)););return s}var zy=Ay,Py=zy,Ey=/^\s+/;function Oy(r){return r&&r.slice(0,Py(r)+1).replace(Ey,"")}var Ry=Oy,Wy=yt,Yy=Ke,Uy="[object Symbol]";function By(r){return typeof r=="symbol"||Yy(r)&&Wy(r)==Uy}var Fy=By,Qy=Ry,so=lt,Vy=Fy,io=NaN,Zy=/^[-+]0x[0-9a-f]+$/i,Hy=/^0b[01]+$/i,Gy=/^0o[0-7]+$/i,$y=parseInt;function Xy(r){if(typeof r=="number")return r;if(Vy(r))return io;if(so(r)){var s=typeof r.valueOf=="function"?r.valueOf():r;r=so(s)?s+"":s}if(typeof r!="string")return r===0?r:+r;r=Qy(r);var e=Hy.test(r);return e||Gy.test(r)?$y(r.slice(2),e?2:8):Zy.test(r)?io:+r}var Jy=Xy,qy=lt,bs=by,oo=Jy,Ky="Expected a function",_y=Math.max,em=Math.min;function tm(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(Ky);s=oo(s)||0,qy(e)&&(u=!!e.leading,h="maxWait"in e,o=h?_y(oo(e.maxWait)||0,s):o,d="trailing"in e?!!e.trailing:d);function g(N){var x=t,L=i;return t=i=void 0,l=N,n=r.apply(L,x),n}function p(N){return l=N,a=setTimeout(w,s),u?g(N):n}function f(N){var x=N-c,L=N-l,b=s-x;return h?em(b,o-L):b}function m(N){var x=N-c,L=N-l;return c===void 0||x>=s||x<0||h&&L>=o}function w(){var N=bs();if(m(N))return I(N);a=setTimeout(w,f(N))}function I(N){return a=void 0,d&&t?g(N):(t=i=void 0,n)}function T(){a!==void 0&&clearTimeout(a),l=0,t=c=i=a=void 0}function C(){return a===void 0?n:I(bs())}function S(){var N=bs(),x=m(N);if(t=arguments,i=this,c=N,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=T,S.flush=C,S}var sm=tm,im=sm,om=lt,nm="Expected a function";function rm(r,s,e){var t=!0,i=!0;if(typeof r!="function")throw new TypeError(nm);return om(e)&&(t="leading"in e?!!e.leading:t,i="trailing"in e?!!e.trailing:i),im(r,s,{leading:t,maxWait:s,trailing:i})}var am=rm;const hn=jt(am);class cm{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)===v.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))&&ne.emitMethod(se.MainEngine,Q.DeleteNode,{workIds:[H],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:oe.pencil,useNewPencil:!0});break;case"changeToArrow":this.setMemberState({currentApplianceName:oe.arrow});break;case"changeToClick":this.setMemberState({currentApplianceName:oe.clicker});break;case"changeToEllipse":this.setMemberState({currentApplianceName:oe.ellipse});break;case"changeToEraser":this.setMemberState({currentApplianceName:oe.eraser,isLine:!0});break;case"changeToHand":this.setMemberState({currentApplianceName:oe.hand});break;case"changeToLaserPointer":this.setMemberState({currentApplianceName:oe.laserPointer});break;case"changeToSelector":this.setMemberState({currentApplianceName:oe.selector});break;case"changeToRectangle":this.setMemberState({currentApplianceName:oe.rectangle});break;case"changeToStraight":this.setMemberState({currentApplianceName:oe.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:oe.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(Q.CopyNode);if(!t||!this.collector||!i)return;const o=this.collector.transformKey(H),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(Q.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 lm{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:je.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:je.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:je.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:je.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:je.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:je.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:je.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:He.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=He.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=He.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:He.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:He.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 hm{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=ci(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 un{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 um{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 pt=class pt{constructor(s){M(this,"version",Yo);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($.toJS(s))});M(this,"onMemberChange",hn(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===v.Selector&&e!==v.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=$.isRoom(e)?e:void 0,this.play=$.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=Wi!=="worker",this.roomMember=new ay;const o={control:this,internalMsgEmitter:pt.InternalMsgEmitter,publicMsgEmitter:pt.PublicMsgEmitter};this.cursor=new ly(o),this.textEditorManager=new cy(o),this.worker=new Dy(o),this.hotkeyManager=new cm(o),this.renderControl=new lm(o),this.miniMapManager=new hm(o),this.pluginManager=new um(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:Wi==="worker"}bindPlugin(s){var e,t;this.plugin=s,this.collector&&(this.collector.removeStorageStateListener(),this.collector.removeAuthStateListener()),this.collector=new Us(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&&(pt.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)===v.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 oe.text:return s.textCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),v.Text;case oe.pencil:return s.useLaserPen?v.LaserPen:v.Pencil;case oe.eraser:return v.Eraser;case oe.pencilEraser:return((t=this.pluginOptions.pencilEraser)==null?void 0:t.useBitMap)===!1?v.PencilEraser:v.BitMapEraser;case oe.selector:return v.Selector;case oe.arrow:return s.arrowCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),v.Arrow;case oe.straight:return s.straightCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),v.Straight;case oe.ellipse:return s.ellipseCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),v.Ellipse;case oe.rectangle:return s.rectangleCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),v.Rectangle;case oe.shape:if(s.shapeCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),s.shapeType===Ve.Pentagram||s.shapeType===Ve.Star)return v.Star;if(s.shapeType===Ve.Polygon||s.shapeType===Ve.Triangle||s.shapeType===Ve.Rhombus)return v.Polygon;if(s.shapeType===Ve.SpeechBalloon)return v.SpeechBalloon;break}return v.Clicker}getToolsOpt(s,e){if(s===v.Clicker)return{toolsType:s,toolsOpt:{}};const t={strokeColor:at(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 v.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)&&at(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)&&at(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 v.Pencil:t.strokeType=(e==null?void 0:e.strokeType)||te.Normal;break;case v.PencilEraser:case v.BitMapEraser:case v.Eraser:t.thickness=Math.min(4,Math.max(1,Math.floor(e.pencilEraserSize||1)))-1,(s===v.BitMapEraser||s===v.PencilEraser)&&(t.eraserColor=e.eraserColor&&at(e.eraserColor[0],e.eraserColor[1],e.eraserColor[2],e.eraserOpacity||.3)||"rgba(136,136,136,0.3)");break;case v.LaserPen:t.duration=(e==null?void 0:e.duration)||1,e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===te.Stroke?t.strokeType=te.Normal:t.strokeType=(e==null?void 0:e.strokeType)||te.Normal;break;case v.Arrow:case v.Straight:e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===te.Stroke?t.strokeType=te.Normal:t.strokeType=(e==null?void 0:e.strokeType)||te.Normal;break;case v.Ellipse:case v.Rectangle:case v.Star:case v.Polygon:case v.SpeechBalloon:e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===te.Stroke?t.strokeType=te.Normal:t.strokeType=(e==null?void 0:e.strokeType)||te.Normal,s===v.Star&&(e.shapeType===Ve.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===v.Polygon&&(e.shapeType===Ve.Triangle?t.vertices=3:e.shapeType===Ve.Rhombus?t.vertices=4:e.vertices&&(t.vertices=e.vertices)),t.fillColor=(e==null?void 0:e.fillColor)&&at(e.fillColor[0],e.fillColor[1],e.fillColor[2],e==null?void 0:e.fillOpacity)||"transparent",s===v.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!==v.Text&&this.viewContainerManager.focuedViewId&&this.viewContainerManager.unActiveTextEditor(this.viewContainerManager.focuedViewId),s){case v.Text:case v.Pencil:case v.LaserPen:case v.Arrow:case v.Straight:case v.Rectangle:case v.Ellipse:case v.Star:case v.Polygon:case v.SpeechBalloon:case v.Triangle:case v.Rhombus:case v.Eraser:case v.PencilEraser:case v.BitMapEraser:case v.Selector:this.room.disableDeviceInputs=!0,(i=this.worker)==null||i.abled(),s===v.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:oe.text})}switchToSelector(){var s;(s=this.room)==null||s.setMemberState({currentApplianceName:oe.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=at(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(pt,"InternalMsgEmitter",new As),M(pt,"PublicMsgEmitter",new As);let Se=pt;const gt=class gt{constructor(s){M(this,"emitter",new As);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)}},gt.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(H);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>gt.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))===H&&!((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))===H&&!((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,T,C,S,N,x,L,b,E,A;let t;const{scenePath:i}=s,o=s.data;if(!o||!this.collector)return;const n=O.cloneDeep(this.collector.storage);for(const P of o.values()){const{dataType:R,data:z,key:X}=P,K=this.collector.getStorageData(this.viewId,i),F=K&&Object.keys(K)||[];switch(R){case 1:if(t=e?this.isDrawEffectiveScene(P,F):this.isDeleteEffectiveScene(P,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(X))===H&&((l=this.collector)!=null&&l.isOwn(P.key))){const G=z.selectIds;if(G){const _=F.filter(ee=>{var q,J;return((q=this.collector)==null?void 0:q.getLocalId(ee))===H&&!((J=this.collector)!=null&&J.isOwn(ee))}).map(ee=>{var q;return(q=this.collector)==null?void 0:q.storage[this.viewId][i][ee]});let ce=!1;for(const ee of _)for(let q=0;q<G.length;q++)(u=ee==null?void 0:ee.selectIds)!=null&&u.includes(G[q])&&(delete G[q],ce=!0);ce&&(z.selectIds=G.filter(ee=>!!ee))}}(h=this.collector)==null||h.updateValue(P.key,z,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}else!e&&!Array.isArray(P.data)&&((d=this.collector)==null||d.updateValue(P.key,void 0,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n}));break;case 2:if(t=e?this.isDeleteEffectiveScene(P,F,i):this.isDrawEffectiveScene(P,F),t){if(e&&!Array.isArray(z))(g=this.collector)==null||g.updateValue(X,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(P.key))===H&&((m=this.collector)!=null&&m.isOwn(P.key))){const G=z.selectIds;if(G){const _=F.filter(ee=>{var q,J;return((q=this.collector)==null?void 0:q.getLocalId(ee))===H&&!((J=this.collector)!=null&&J.isOwn(ee))}).map(ee=>{var q;return(q=this.collector)==null?void 0:q.storage[this.viewId][i][ee]});let ce=!1;for(const ee of _)for(let q=0;q<G.length;q++)(w=ee==null?void 0:ee.selectIds)!=null&&w.includes(G[q])&&(delete G[q],ce=!0);ce&&(z.selectIds=G.filter(ee=>!!ee))}}(I=this.collector)==null||I.updateValue(P.key,P.data,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}}break;case 3:if(t=e?this.isNewEffectiveScene(P,F):this.isOldEffectiveScene(P,F,i),t){if(e&&Array.isArray(z)&&z.length===2){const G=z[1];if((T=G.updateNodeOpt)!=null&&T.useAnimation&&(G.updateNodeOpt.useAnimation=!1),((C=this.collector)==null?void 0:C.getLocalId(P.key))===H&&((S=this.collector)!=null&&S.isOwn(P.key))){const _=G.selectIds;if(_){const ce=F.filter(q=>{var J,ue;return((J=this.collector)==null?void 0:J.getLocalId(q))===H&&!((ue=this.collector)!=null&&ue.isOwn(q))}).map(q=>{var J;return(J=this.collector)==null?void 0:J.storage[this.viewId][i][q]});let ee=!1;for(const q of ce)for(let J=0;J<_.length;J++)q!=null&&q.selectIds&&((N=q.selectIds)!=null&&N.includes(_[J]))&&(delete _[J],ee=!0);ee&&(G.selectIds=_.filter(q=>!!q))}}(x=this.collector)==null||x.updateValue(X,G,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}else if(!e&&Array.isArray(z)&&z.length===2){const G=z[0];if((L=G.updateNodeOpt)!=null&&L.useAnimation&&(G.updateNodeOpt.useAnimation=!1),((b=this.collector)==null?void 0:b.getLocalId(P.key))===H&&((E=this.collector)!=null&&E.isOwn(P.key))){const _=G.selectIds;if(_){const ce=F.filter(q=>{var J,ue;return((J=this.collector)==null?void 0:J.getLocalId(q))===H&&!((ue=this.collector)!=null&&ue.isOwn(q))}).map(q=>{var J;return(J=this.collector)==null?void 0:J.storage[this.viewId][i][q]});let ee=!1;for(const q of ce)for(let J=0;J<_.length;J++)q!=null&&q.selectIds&&q.selectIds.includes(_[J])&&(delete _[J],ee=!0);ee&&(G.selectIds=_.filter(q=>!!q))}}(A=this.collector)==null||A.updateValue(P.key,G,{viewId:this.viewId,scenePath:i,isSync:!0,storage:n})}}break}}}};M(gt,"sdkCallBack"),M(gt,"MaxStackLength",20),M(gt,"waitTime",100);let ls=gt;function dm(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 xt(r){return dm(r)&&(r.touches&&r.touches.length===1||r.changedTouches&&r.changedTouches.length===1)}function dn(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 Lt{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!==ge&&this.appViews.has(s)}getView(s){var e;return s===ge?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===ge&&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===ge&&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===ge?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===v.Text&&this.activeTextEditor(s),this.control.cursor.onFocusViewChange(),this.focuedView&&this.focuedView.displayer.commiter.onFocusView()}setViewFocusScenePath(s,e){var i;let t;s===ge?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(ge),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 T of s){const{rect:C,imageBitmap:S,isClear:N,isUnClose:x,drawCanvas:L,clearCanvas:b,viewId:E}=T,A=(e=this.getView(E))==null?void 0:e.displayer;if(A&&C){const{dpr:P,canvasBgRef:R,canvasFloatRef:z,canvasServiceFloatRef:X,canvasTopRef:K}=A,F=Math.floor(C.w*P),G=Math.floor(C.h*P),_=C.x*P,ce=C.y*P;if(N){switch(b){case ye.TopFloat:(i=(t=K.current)==null?void 0:t.getContext("2d"))==null||i.clearRect(_,ce,F,G);break;case ye.Float:(n=(o=z.current)==null?void 0:o.getContext("2d"))==null||n.clearRect(_,ce,F,G);break;case ye.ServiceFloat:(c=(a=X.current)==null?void 0:a.getContext("2d"))==null||c.clearRect(_,ce,F,G);break;case ye.Bg:(u=(l=R.current)==null?void 0:l.getContext("2d"))==null||u.clearRect(_,ce,F,G);break}continue}if(L&&S)switch(L){case ye.TopFloat:(d=(h=K.current)==null?void 0:h.getContext("2d"))==null||d.drawImage(S,0,0,F,G,_,ce,F,G);break;case ye.Float:{(p=(g=z.current)==null?void 0:g.getContext("2d"))==null||p.drawImage(S,0,0,F,G,_,ce,F,G);break}case ye.ServiceFloat:{(m=(f=X.current)==null?void 0:f.getContext("2d"))==null||m.drawImage(S,0,0,F,G,_,ce,F,G);break}case ye.Bg:{(I=(w=R.current)==null?void 0:w.getContext("2d"))==null||I.drawImage(S,0,0,F,G,_,ce,F,G);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(Lt,"defaultCameraOpt",{centerX:0,centerY:0,scale:1}),M(Lt,"defaultScreenCanvasOpt",{autoRender:!1,contextType:"webgl2"}),M(Lt,"defaultLayerOpt",{offscreen:!0,handleEvent:!1,depth:!1});class pm{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(!xt(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(!xt(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(!xt(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 ls(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 v.Text:case v.Pencil:case v.LaserPen:case v.Arrow:case v.Straight:case v.Rectangle:case v.Ellipse:case v.Star:case v.Polygon:case v.SpeechBalloon:case v.Eraser:case v.PencilEraser:case v.BitMapEraser:case v.Selector:this.eventTragetElement&&(this.eventTragetElement.className=`netless-whiteboard ${s===v.Selector?"cursor-selector":s===v.Text?"cursor-text":s===v.Eraser||s===v.PencilEraser||s===v.BitMapEraser?"cursor-eraser":s===v.Pencil||s===v.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([se.Cursor,this.viewId])}getPoint(s){const e=dn(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",ds.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 pn{constructor(s,e){M(this,"viewId",ge);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(!xt(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(!xt(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(!xt(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 ls(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 v.Text:case v.Pencil:case v.LaserPen:case v.Arrow:case v.Straight:case v.Rectangle:case v.Ellipse:case v.Star:case v.Polygon:case v.SpeechBalloon:case v.Eraser:case v.PencilEraser:case v.BitMapEraser:case v.Selector:this.eventTragetElement&&(this.eventTragetElement.className=e&&t?`netless-whiteboard ${s===v.Selector?"cursor-selector":s===v.Text?"cursor-text":s===v.Eraser||s===v.PencilEraser||s===v.BitMapEraser?"cursor-eraser":s===v.Pencil||s===v.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([se.Cursor,this.viewId])}getPoint(s){const e=dn(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===v.Pencil&&this.control.pluginOptions.bezier&&s>this.control.pluginOptions.bezier.maxDrawCount?(this.stopEventHandler().finally(()=>{this.worker.publicMsgEmitter.emit("forceStop",ds.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 gm="index-module__Container__nLsM3",fm="index-module__CanvasBox__j2Xe-",Mm="index-module__FloatCanvas__d1YR7",ym="index-module__TopFloatCanvas__7IaCw",mm="index-module__CanvasBoxSub__hcMeK",wm="index-module__SnapshotBox__--eeE",Im="index-module__FloatBar__cm-EL",vm="index-module__RotateBtn__HSSkf",Tm="index-module__ResizeBtn__yjvda",Nm="index-module__CursorBox__2UHvI",Sm="index-module__TextEditorContainer__Qm8KC",Cm="index-module__ResizeTowBox__HOllX",km="index-module__FloatBarBtn__FJrOG",be={Container:gm,CanvasBox:fm,FloatCanvas:Mm,TopFloatCanvas:ym,CanvasBoxSub:mm,SnapshotBox:wm,FloatBar:Im,RotateBtn:vm,ResizeBtn:Tm,CursorBox:Nm,TextEditorContainer:Sm,ResizeTowBox:Cm,FloatBarBtn:km},Dm={delete:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDZ2NmEyIDIgMCAwIDEtMiAySDZhMiAyIDAgMCAxLTItMlY2aDBtMS0yYTIgMiAwIDAgMSAyLTJoMmEyIDIgMCAwIDEgMiAyaDBNMyA0aDEwIiBzdHJva2U9IiM0NDRFNjAiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2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1bGU9Im5vbnplcm8iLz48L2c+PC9zdmc+","font-colors-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0ibTQgMTEgNC05IDQgOU02IDdoNCIgc3Ryb2tlPSIjMzM4MUZGIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","font-colors":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0ibTQgMTEgNC05IDQgOU02IDdoNCIgc3Ryb2tlPSIjNDQ0RTYwIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","to-bottom":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDEwdjhtMCAwLTItMm0yIDIgMi0ybS00IDZoMTJtLTYtNGg2bS02LTRoNm0tNi00aDYiIHN0cm9rZT0iIzQ0NEU2MCIgZmlsbD0ibm9uZSIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+PC9zdmc+","to-top":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDIydi04bTAgMC0yIDJtMi0yIDIgMm0tNC02aDEybS02IDRoNm0tNiA0aDZtLTYgNGg2IiBzdHJva2U9IiM0NDRFNjAiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==","bold-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTQuNSAySDhhMi41IDIuNSAwIDAgMSAwIDVINS41aDBtLTEgMGg0YTMgMyAwIDAgMSAwIDZoLTQgMG0wIDFWMiIgc3Ryb2tlPSIjMzM4MUZGIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=",bold:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTQuNSAySDhhMi41IDIuNSAwIDAgMSAwIDVINS41aDBtLTEgMGg0YTMgMyAwIDAgMSAwIDZoLTQgMG0wIDFWMiIgc3Ryb2tlPSIjNDQ0RTYwIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","underline-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDJ2NWE0IDQgMCAxIDEtOCAwVjJoME0zIDE0aDEwIiBzdHJva2U9IiMzMzgxRkYiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==",underline:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRw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gc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==","italic-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTcgMTQgOSAyTTUgMTRoNE03IDJoNCIgc3Ryb2tlPSIjMzM4MUZGIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=",italic:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTcgMTQgOSAyTTUgMTRoNE03IDJoNCIgc3Ryb2tlPSIjNDQ0RTYwIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","unlock-new":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj48Y2lyY2xlIGZpbGw9IiMzMzgxRkYiIGN4PSIxNiIgY3k9IjE3IiByPSIxIi8+PHJlY3Qgc3Ryb2tlPSIjMzM4MUZGIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHg9IjExIiB5PSIxNCIgd2lkdGg9IjEwIiBoZWlnaHQ9IjgiIHJ4PSIyIi8+PHBhdGggZD0iTTEzIDE0di0xYTMgMyAwIDAgMSA2IDB2MWgwbS0zIDN2MyIgc3Ryb2tlPSIjMzM4MUZGIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0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NjcgMTM4LjY2NjY2NyAwIDAgMC0xMzguNjY2NjY2IDEzOC42NjY2NjZoNjR6TTIxMy4zMzMzMzMgNzE0LjY2NjY2N2M0MS4yMTYgMCA3NC42NjY2NjcgMzMuNDUwNjY3IDc0LjY2NjY2NyA3NC42NjY2NjZoNjRBMTM4LjY2NjY2NyAxMzguNjY2NjY3IDAgMCAwIDIxMy4zMzMzMzMgNjUwLjY2NjY2N3Y2NHogbTc0LjY2NjY2NyA3NC42NjY2NjZBNzQuNjY2NjY3IDc0LjY2NjY2NyAwIDAgMSAyMTMuMzMzMzMzIDg2NHY2NGExMzguNjY2NjY3IDEzOC42NjY2NjcgMCAwIDAgMTM4LjY2NjY2Ny0xMzguNjY2NjY3aC02NHpNMjEzLjMzMzMzMyA4NjRhNzQuNjY2NjY3IDc0LjY2NjY2NyAwIDAgMS03NC42NjY2NjYtNzQuNjY2NjY3aC02NEExMzguNjY2NjY3IDEzOC42NjY2NjcgMCAwIDAgMjEzLjMzMzMzMyA5Mjh2LTY0ek0yNDUuMzMzMzMzIDY4Mi42NjY2Njd2LTIzNC42NjY2NjdoLTY0VjY4Mi42NjY2NjdoNjR6IG0tNTQuNjEzMzMzLTIxMi4wNTMzMzRsODUuMzMzMzMzIDg1LjMzMzMzNCA0NS4yMjY2NjctNDUuMjI2NjY3LTg1LjMzMzMzMy04NS4zMzMzMzMtNDUuMjI2NjY3IDQ1LjIyNjY2NnogbTAtNDUuMjI2NjY2bC04NS4zMzMzMzMgODUuMzMzMzMzIDQ1LjIyNjY2NiA0NS4yMjY2NjcgODUuMzMzMzM0LTg1LjMzMzMzNC00NS4yMjY2NjctNDUuMjI2NjY2eiIgIGZpbGw9IiM0NDRFNjAiPjwvcGF0aD48L3N2Zz4="};function xe(r){return Dm[r]}const xm=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(),ne.emitMethod(se.MainEngine,Q.DeleteNode,{workIds:s||[H],viewId:e.viewId})}},y.createElement("img",{alt:"icon",src:xe("delete")}))},Lm=r=>{const{workIds:s,viewId:e}=r;return y.createElement("div",{className:"button normal-button",onPointerUp:t=>{t.stopPropagation(),ne.emitMethod(se.MainEngine,Q.CopyNode,{workIds:s||[H],viewId:e})}},y.createElement("img",{alt:"icon",src:xe("duplicate")}))},no=r=>{const{icon:s,onPointerUpHandler:e}=r;return y.createElement("div",{className:"button normal-button",onPointerUp:e},y.createElement("img",{src:xe(s)}))},bm=r=>{const{open:s,setOpen:e,floatBarRef:t}=r,{floatBarData:i,mananger:o}=y.useContext(ve),[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(no,{icon:"to-top",onPointerUpHandler:h=>{h.stopPropagation(),ne.emitMethod(se.MainEngine,Q.ZIndexNode,{workIds:[H],layer:Ft.Top,viewId:o==null?void 0:o.viewId})}}),y.createElement(no,{icon:"to-bottom",onPointerUpHandler:h=>{h.stopPropagation(),ne.emitMethod(se.MainEngine,Q.ZIndexNode,{workIds:[H],layer:Ft.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:xe(s?"layer-pressed":"layer")}))},Ts=r=>{r.stopPropagation(),r.nativeEvent.stopImmediatePropagation()},jm=()=>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"})),gn=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"}))},Ns=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:Ce(s,1)}}))},Ss=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, ${Ce(e,0)}, ${Ce(e,1)})`}}),y.createElement("div",{className:"range-opacity"},y.createElement(bt,{bounds:"parent",axis:"x",position:i,onDrag:c,onStart:l,onStop:u},y.createElement("div",{className:"circle",style:{backgroundColor:Ce(e,s)},onPointerUp:Ts}))))},Am=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(bt,{bounds:"parent",axis:"x",position:n,onDrag:u,onStart:h,onStop:d},y.createElement("div",{className:"circle",style:{backgroundColor:o},onPointerUp:Ts},y.createElement("div",{className:"range-opacity-data-icon"},t)))))},zm=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===te.Stroke&&"active"}`,style:{backgroundColor:e},onPointerUp:()=>{i(te.Stroke)}}),y.createElement("div",{className:`stroke-type-box-item Normal ${t===te.Normal&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(te.Normal)}}),y.createElement("div",{className:`stroke-type-box-item Dotted ${t===te.Dotted&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(te.Dotted)}}),y.createElement("div",{className:`stroke-type-box-item LongDotted ${t===te.LongDotted&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(te.LongDotted)}}))},Pm=r=>{var I,T;const{open:s,setOpen:e,floatBarRef:t}=r,{floatBarData:i,floatBarColors:o,mananger:n,setFloatBarData:a}=y.useContext(ve),[c,l]=y.useState(),[u,h]=y.useState(1);y.useEffect(()=>{if(i!=null&&i.strokeColor){const[C,S]=Is(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(Ss,{key:"strokeColors",opacity:u,activeColor:c,setCurOpacity:(C,S,N)=>{h(C);const x=Ce(S,C);i!=null&&i.strokeColor&&a({strokeColor:x}),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],strokeColor:x,workState:N,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(Am,{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:(N,x)=>{i!=null&&i.thickness&&a({thickness:N}),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],thickness:N,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,(T=n==null?void 0:n.control.pluginOptions.strokeWidth)==null?void 0:T.min,n==null?void 0:n.viewId,a]),f=y.useMemo(()=>c&&i&&(i!=null&&i.strokeType)?y.createElement(zm,{key:"strokeType",useStroke:i==null?void 0:i.useStroke,activeStrokeType:i.strokeType,setStrokeType:C=>{i.strokeType&&a({strokeType:C}),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],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 N=Gt(...C);return y.createElement(Ns,{key:S,color:N,activeColor:c,onPointerUpHandler:x=>{x.stopPropagation(),l(N);const L=Ce(N,u);i!=null&&i.strokeColor&&(i.strokeColor=L,a({strokeColor:L})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],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:Ce(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)},Em=r=>{const{open:s,setOpen:e,floatBarRef:t}=r,{floatBarData:i,floatBarColors:o,mananger:n,setFloatBarData:a}=y.useContext(ve),[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]||Is(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(Ss,{key:"fillColors",opacity:u||0,activeColor:c,setCurOpacity:(m,w,I)=>{h(m);const T=Ce(w,m);i!=null&&i.fillColor&&(i.fillColor=T,a({fillColor:T})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],fillColor:c&&Ce(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(gn,{activeColor:c,onPointerUpHandler:m=>{m.stopPropagation(),l("transparent");const w="transparent";i!=null&&i.fillColor&&(i.fillColor=w,a({fillColor:w})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],workState:j.Done,fillColor:w,viewId:n==null?void 0:n.viewId})}}),o.map((m,w)=>{const I=Gt(...m);return y.createElement(Ns,{key:w,color:I,activeColor:c,onPointerUpHandler:T=>{T.cancelable&&T.preventDefault(),T.stopPropagation(),l(I);const C=Ce(I,u);i!=null&&i.fillColor&&(i.fillColor=C,a({fillColor:C})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:[H],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"&&Ce(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)},Om=r=>{const{open:s,setOpen:e,textOpt:t,workIds:i,floatBarRef:o}=r,{floatBarColors:n,mananger:a,setFloatBarData:c,floatBarData:l}=y.useContext(ve),[u,h]=y.useState(),[d,g]=y.useState(1);y.useEffect(()=>{if(t!=null&&t.fontColor){const[I,T]=(t==null?void 0:t.fontColor)==="transparent"&&["transparent",0]||Is(t.fontColor);h(I),g(T)}},[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(Ss,{key:"fontColors",opacity:d,activeColor:u,setCurOpacity:(I,T,C)=>{g(I);const S=Ce(T,I);l!=null&&l.textOpt&&(l.textOpt.fontColor=S,c({textOpt:l.textOpt})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:i||[H],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,T)=>{const C=Gt(...I);return y.createElement(Ns,{key:T,color:C,activeColor:u,onPointerUpHandler:S=>{S.stopPropagation(),h(C);const N=Ce(C,d);l!=null&&l.textOpt&&(l.textOpt.fontColor=N,c({textOpt:l.textOpt})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:i||[H],workState:j.Done,fontColor:N,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"&&Ce(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:xe("font-colors")}),w,m)},Rm=r=>{const{open:s,setOpen:e,textOpt:t,workIds:i,floatBarRef:o}=r,{floatBarColors:n,mananger:a,setFloatBarData:c,floatBarData:l}=y.useContext(ve),[u,h]=y.useState(),[d,g]=y.useState(1);y.useEffect(()=>{if(t!=null&&t.fontBgColor){const[I,T]=(t==null?void 0:t.fontBgColor)==="transparent"&&["transparent",1]||Is(t.fontBgColor);h(I),g(T)}},[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(Ss,{key:"fontBgColor",opacity:d||0,activeColor:u,setCurOpacity:(I,T,C)=>{g(I);const S=Ce(T,I);l!=null&&l.textOpt&&(l.textOpt.fontBgColor=S,c({textOpt:l.textOpt})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:i||[H],fontBgColor:u&&Ce(T,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(gn,{activeColor:u,onPointerUpHandler:I=>{I.stopPropagation();const T="transparent";h(T),l!=null&&l.textOpt&&(l.textOpt.fontBgColor=T,c({textOpt:l.textOpt})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:i||[H],workState:j.Done,fontBgColor:T,viewId:a==null?void 0:a.viewId})}}),n.map((I,T)=>{const C=Gt(...I);return y.createElement(Ns,{key:T,color:C,activeColor:u,onPointerUpHandler:S=>{S.stopPropagation(),h(C);const N=Ce(C,d);l!=null&&l.textOpt&&(l.textOpt.fontBgColor=N,c({textOpt:l.textOpt})),ne.emitMethod(se.MainEngine,Q.SetColorNode,{workIds:i||[H],workState:j.Done,fontBgColor:Ce(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"&&Ce(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(jm,null),w,m)},Wm=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),ne.emitMethod(se.MainEngine,Q.SetFontStyle,{workIds:t,viewId:i,bold:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:xe(s==="bold"?"bold-active":"bold")}))},Ym=r=>{const{underline:s,setUnderline:e,workIds:t,viewId:i}=r,o=n=>{const a=!s;n==null||n.stopPropagation(),e(a),ne.emitMethod(se.MainEngine,Q.SetFontStyle,{workIds:t,viewId:i,underline:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:xe(s?"underline-active":"underline")}))},Um=r=>{const{lineThrough:s,setLineThrough:e,workIds:t,viewId:i}=r,o=n=>{const a=!s;n==null||n.stopPropagation(),e(a),ne.emitMethod(se.MainEngine,Q.SetFontStyle,{workIds:t,viewId:i,lineThrough:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:xe(s?"line-through-active":"line-through")}))},Bm=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),ne.emitMethod(se.MainEngine,Q.SetFontStyle,{workIds:t,viewId:i,italic:a})};return y.createElement("div",{className:"font-style-button",onPointerUp:o},y.createElement("img",{alt:"icon",src:xe(s==="italic"?"italic-active":"italic")}))},Fm=r=>{const{open:s,setOpen:e,textOpt:t,workIds:i,style:o,floatBarRef:n}=r,{mananger:a,floatBarData:c}=y.useContext(ve),[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 T={};return T.top="inherit",T.bottom=50,T}else if(!n.current.offsetTop&&(a==null?void 0:a.height)-n.current.offsetTop-c.y<120){const T={};return T.top="inherit",T.bottom=50,T}}},[o,n==null?void 0:n.current,c,a]),I=y.useMemo(()=>s?y.createElement("div",{className:"font-style-menu",style:w,onPointerUp:T=>{T.stopPropagation(),T.nativeEvent.stopImmediatePropagation()}},y.createElement(Wm,{workIds:i||[H],bold:l,setBold:u,viewId:a==null?void 0:a.viewId}),y.createElement(Ym,{workIds:i||[H],underline:g,setUnderline:p,viewId:a==null?void 0:a.viewId}),y.createElement(Um,{workIds:i||[H],lineThrough:f,setLineThrough:m,viewId:a==null?void 0:a.viewId}),y.createElement(Bm,{workIds:i||[H],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:T=>{T.stopPropagation(),T.nativeEvent.stopImmediatePropagation(),e(!s)}},y.createElement("img",{alt:"icon",src:xe(s?"font-style-active":"font-style")}),I)},Xe=Object.freeze([12,14,18,24,36,48,64,80,144,288]),Tt=["top","topLeft","topRight","bottom","bottomLeft","bottomRight","left","leftTop","leftBottom","right","rightTop","rightBottom"],Yt=new Map([["selector","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAKeSURBVHgB3VTLi1JhFD86zlQ4ysxSXAy1GWYZzMxmYAhHagRB/QN8FLqPFq4F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0MjQsMTkuNSAxOC41LDE5LjcyMzg1NzYgMTguNSwyMCBDMTguNSwyMC4yNDU0NTk5IDE4LjMyMzEyNDgsMjAuNDQ5NjA4NCAxOC4wODk4NzU2LDIwLjQ5MTk0NDMgTDE4LDIwLjUgTDEzLDIwLjUgQzEyLjcyMzg1NzYsMjAuNSAxMi41LDIwLjI3NjE0MjQgMTIuNSwyMCBDMTIuNSwxOS43NTQ1NDAxIDEyLjY3Njg3NTIsMTkuNTUwMzkxNiAxMi45MTAxMjQ0LDE5LjUwODA1NTcgTDEzLDE5LjUgTDE4LDE5LjUgWiBNMjAsMTIuNSBDMjAuMjQ1NDU5OSwxMi41IDIwLjQ0OTYwODQsMTIuNjc2ODc1MiAyMC40OTE5NDQzLDEyLjkxMDEyNDQgTDIwLjUsMTMgTDIwLjUsMTggQzIwLjUsMTguMjc2MTQyNCAyMC4yNzYxNDI0LDE4LjUgMjAsMTguNSBDMTkuNzU0NTQwMSwxOC41IDE5LjU1MDM5MTYsMTguMzIzMTI0OCAxOS41MDgwNTU3LDE4LjA4OTg3NTYgTDE5LjUsMTggTDE5LjUsMTMgQzE5LjUsMTIuNzIzODU3NiAxOS43MjM4NTc2LDEyLjUgMjAsMTIuNSBaIiBpZD0i5b2i54q257uT5ZCIIiBmaWxsPSIjMjEyMzI0IiBmaWxsLXJ1bGU9Im5vbnplcm8iPjwvcGF0aD4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+"]]),Qm=r=>{const{style:s,onClickHandler:e}=r;return y.createElement("div",{className:"font-size-menu",style:s,onPointerUp:t=>{t.stopPropagation(),t.nativeEvent.stopImmediatePropagation()}},Xe.map(t=>y.createElement("div",{className:"font-size-btn",key:t,onPointerUp:()=>{e(t)}},t)))},Vm=r=>{const s=y.useRef(null),{open:e,setOpen:t,textOpt:i,workIds:o,floatBarRef:n}=r,{mananger:a,floatBarData:c}=y.useContext(ve),[l,u]=y.useState(0),h=Xe.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>=Xe[0]&&w<=Xe[h]&&ne.emitMethod(se.MainEngine,Q.SetFontStyle,{workIds:o||[H],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(Qm,{onClickHandler:p,style:d}):null,[e,p,d]),m=w=>{w>Xe[h]&&(w=Xe[h]),w<Xe[0]&&(w=Xe[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(),T=I==null?void 0:I.getRangeAt(0);if(T!=null&&T.collapsed)return w.cancelable&&w.preventDefault(),document.execCommand("delete",!1),!1}return!1},onKeyUp:w=>{var I;if(s.current){const T=s.current.value,C=parseInt(T);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+Xe[0])}}),y.createElement("div",{className:"font-size-cut",onPointerUp:()=>{m(l-Xe[0])}})),f)},Zm=r=>{const{workIds:s,mananger:e,islocked:t}=r;return y.createElement("div",{className:"button normal-button",onPointerUp:i=>{i.stopPropagation(),ne.emitMethod(se.MainEngine,Q.SetLock,{workIds:s||[H],isLocked:!t,viewId:e==null?void 0:e.viewId})}},y.createElement("img",{alt:"icon",src:xe(t?"unlock-new":"lock-new")}))},Bs=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:xe(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)}})))},Hm=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:xe(s)}),y.createElement(Gm,{min:e,max:t,step:i,value:o,onInputHandler:n}))},Gm=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=()=>{console.log("onDragStartHandler")},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(bt,{bounds:"parent",axis:"x",position:o,onDrag:a,onStart:c,onStop:l},y.createElement("div",{className:"circle",onPointerUp:Ts}))))},$m=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>=Tt.length&&(g=0),g<0&&(g=Tt.length-1),n(g),t(Tt[g]),c(!1),l.current&&(l.current.value=Tt[g])},[t]),h=y.useMemo(()=>{if(i&&i.bottom){const g={};return g.top="inherit",g.bottom=50,g}},[i]);y.useEffect(()=>{e&&(n(Tt.indexOf(e)),l.current&&(l.current.value=e))},[e]);const d=y.useMemo(()=>a?y.createElement(Xm,{options:Tt,onClickHandler:u,style:h}):null,[a,u,h]);return y.createElement("div",{className:"button input-button"},y.createElement("img",{src:xe(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)},Xm=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)))},Jm=r=>{const{innerRatio:s,innerVerticeStep:e,vertices:t,mananger:i,setShapeOpt:o}=r,n=l=>{o({vertices:l}),ne.emitMethod(se.MainEngine,Q.SetShapeOpt,{workIds:[H],toolsType:v.Star,viewId:i.viewId,vertices:l})},a=l=>{o({innerVerticeStep:l}),ne.emitMethod(se.MainEngine,Q.SetShapeOpt,{workIds:[H],toolsType:v.Star,viewId:i.viewId,innerVerticeStep:l})},c=l=>{o({innerRatio:l}),ne.emitMethod(se.MainEngine,Q.SetShapeOpt,{workIds:[H],toolsType:v.Star,viewId:i.viewId,innerRatio:l})};return y.createElement(y.Fragment,null,y.createElement(Bs,{value:t,icon:"polygon-vertex",min:3,max:100,step:1,onInputHandler:n}),y.createElement(Bs,{value:e,icon:"star-innerVertex",min:1,max:100,step:1,onInputHandler:a}),y.createElement(Hm,{value:s,icon:"star-innerRatio",min:.1,max:1,step:.1,onInputHandler:c}))},qm=r=>{const{mananger:s,vertices:e,setShapeOpt:t}=r,i=o=>{t({vertices:o}),ne.emitMethod(se.MainEngine,Q.SetShapeOpt,{workIds:[H],toolsType:v.Polygon,viewId:s.viewId,vertices:o})};return y.createElement(Bs,{value:e,icon:"polygon-vertex",min:3,max:100,step:1,onInputHandler:i})},Km=r=>{const{mananger:s,placement:e,setShapeOpt:t}=r,i=o=>{t({placement:o}),ne.emitMethod(se.MainEngine,Q.SetShapeOpt,{workIds:[H],toolsType:v.SpeechBalloon,viewId:s.viewId,placement:o})};return y.createElement($m,{value:e,icon:"speechBallon-placement",onChangeHandler:i})},js=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:xe(s)}))},_m=r=>{const{toolsTypes:s,style:e,mananger:t,shapeOpt:i,setShapeOpt:o}=r,[n,a]=y.useState();y.useEffect(()=>{s.includes(v.Polygon)?a(v.Polygon):s.includes(v.Star)?a(v.Star):a(v.SpeechBalloon)},[s]);const c=d=>{a(d)},l=y.useMemo(()=>n===v.Polygon&&t&&i.vertices?y.createElement(qm,{vertices:i.vertices,mananger:t,setShapeOpt:o}):null,[t,n,i,o]),u=y.useMemo(()=>n===v.Star&&t&&i.vertices&&i.innerVerticeStep&&i.innerRatio?y.createElement(Jm,{mananger:t,vertices:i.vertices,innerVerticeStep:i.innerVerticeStep,innerRatio:i.innerRatio,setShapeOpt:o}):null,[t,n,i,o]),h=y.useMemo(()=>n===v.SpeechBalloon&&t&&i.placement?y.createElement(Km,{mananger:t,placement:i.placement,setShapeOpt:o}):null,[n,t,i.placement,o]);return y.createElement("div",{className:"shapeOpt-sub-menu",style:e,onPointerUp:Ts},y.createElement("div",{className:"shapeOpt-sub-menu-tabs"},s.includes(v.Polygon)&&y.createElement(js,{isActive:n===v.Polygon,icon:n===v.Polygon?"polygon-active":"polygon",onPointerUpHandler:c.bind(void 0,v.Polygon)})||null,s.includes(v.Star)&&y.createElement(js,{isActive:n===v.Star,icon:n===v.Star?"star-active":"star",onPointerUpHandler:c.bind(void 0,v.Star)})||null,s.includes(v.SpeechBalloon)&&y.createElement(js,{isActive:n===v.SpeechBalloon,icon:n===v.SpeechBalloon?"speechBallon-active":"speechBallon",onPointerUpHandler:c.bind(void 0,v.SpeechBalloon)})||null),y.createElement("div",{className:"shapeOpt-sub-menu-content"},l,u,h))},ew=r=>{const{open:s,setOpen:e,floatBarRef:t,toolsTypes:i,shapeOpt:o}=r,{floatBarData:n,mananger:a,setFloatBarData:c}=y.useContext(ve),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(_m,{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:xe(s?"shapes-active":"shapes")}))},fn=y.memo(r=>{const{textOpt:s,workIds:e,noLayer:t,position:i,noDelete:o,noCopy:n}=r,{floatBarData:a,mananger:c}=y.useContext(ve),[l,u]=y.useState(0),[h,d]=y.useState(),g=y.useRef(null);y.useEffect(()=>{var E,A,P,R;const x={},L=(a==null?void 0:a.w)||((E=s==null?void 0:s.boxSize)==null?void 0:E[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+(((P=g.current)==null?void 0:P.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(Em,{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(Pm,{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(Om,{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(Rm,{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(Fm,{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]),T=y.useMemo(()=>s&&(c!=null&&c.viewId)?y.createElement(Vm,{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(Zm,{workIds:e,mananger:c,islocked:a.isLocked}):null,[a,c,e]),N=y.useMemo(()=>c&&(c!=null&&c.viewId)&&h&&(a!=null&&a.shapeOpt)&&(a!=null&&a.toolsTypes)?y.createElement(ew,{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(xm,{workIds:e,mananger:c}),C,S,!!(c!=null&&c.viewId)&&!n&&y.createElement(Lm,{workIds:e,viewId:c.viewId}),N,I,T,m,w,f,p)}),tw=r=>{const{data:s,workId:e,updateOptInfo:t}=r,{opt:i,scale:o,translate:n,x:a,y:c}=s,l=y.useRef(null),{floatBarData:u}=y.useContext(ve),h=y.useMemo(()=>{const p=[];if(i.text){const f=wt(i.text);for(let m=0;m<f.length;m++){const w=f[m];w===""?p.push(y.createElement("div",{key:m},y.createElement("br",null))):p.push(y.createElement("div",{key:m},w))}}return p.length?p:null},[i.text]),d=y.useMemo(()=>{if(!u)return{};const p=`scale(${o||1}) ${n&&"translate("+n[0]+"px,"+n[1]+"px)"||""}`;return{left:`${a-u.x}px`,top:`${c-u.y}px`,zIndex:1,transform:p,transformOrigin:"left top",pointerEvents:"none",opacity:0}},[o,n,a,c,u]),g=y.useMemo(()=>{const{fontSize:p,fontFamily:f,underline:m,fontColor:w,lineThrough:I,textAlign:T,strokeColor:C,lineHeight:S,bold:N,italic:x}=i,L=S||p*1.2,b={fontSize:`${p}px`,lineHeight:`${L}px`,color:w,borderColor:C,minHeight:`${L}px`,pointerEvents:"none",paddingRight:`${x==="italic"?Math.round(p*.3):5}px`};return f&&(b.fontFamily=`${f}`),(I||m)&&(b.textDecoration=`${I&&"line-through"||""}${m&&" underline"||""}`),T&&(b.textAlign=`${T}`),N&&(b.fontWeight=`${N}`),x&&(b.fontStyle=`${x}`),b},[i]);return y.useEffect(()=>{var p,f;if((p=l.current)!=null&&p.offsetWidth&&((f=l.current)!=null&&f.offsetHeight)){const m=i.boxSize;if((m==null?void 0:m[0])!==l.current.offsetWidth||m[1]!==l.current.offsetHeight||!m){const w=[l.current.offsetWidth,l.current.offsetHeight];t({activeTextId:e,update:{boxSize:w,workState:j.Done}})}}},[i.fontSize,i.italic,i.bold,i.boxSize,e,t]),y.createElement("div",{className:"editor-box readonly",style:d},y.createElement("div",{className:"editor",ref:l,style:g},h))},sw=r=>{const{mananger:s}=y.useContext(ve),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(tw,{key:a,workId:a,data:n,updateOptInfo:t});o.push(c)}}),o}return null},[r.editors,r.selectIds,s]);return y.createElement(y.Fragment,null,e)},iw=r=>{const{data:s,workId:e,showFloatBtns:t,handleKeyUp:i,handleFocus:o,runAnimation:n}=r,[a,c]=y.useState(!1),{activeTextEditor:l,activeTextId:u,mananger:h}=y.useContext(ve),{opt:d,scale:g,translate:p,x:f,y:m}=s,{fontSize:w,fontFamily:I,underline:T,fontColor:C,lineThrough:S,textAlign:N,lineHeight:x,bold:L,italic:b}=d,E=y.useRef(null),A=y.useMemo(()=>u===e?"hover":d.workState===j.Doing||d.workState===j.Start?"editing":l?"active":"none",[u,e,d.workState,l]),P=y.useMemo(()=>{const V=`scale(${g||1}) ${p&&"translate("+p[0]+"px,"+p[1]+"px)"||""}`;return{left:`${f}px`,top:`${m}px`,zIndex:2,transform:V,transformOrigin:"left top",borderColor:A==="editing"||A==="hover"?C:"transparent"}},[g,p,f,m,C,A]),R=y.useMemo(()=>{const V=w,le=x||V*1.2,ie={fontSize:`${V}px`,lineHeight:`${le}px`,color:C,minHeight:`${le}px`,paddingRight:`${b==="italic"?Math.round(V*.3):5}px`,borderWidth:`${Math.max(Math.round(1/(g||1)),1)}px`};return I&&(ie.fontFamily=`${I}`),(S||T)&&(ie.textDecoration=`${S&&"line-through"||""} ${T&&" underline"||""}`),N&&(ie.textAlign=`${N}`),L&&(ie.fontWeight=`${L}`),b&&(ie.fontStyle=`${b}`),ie},[L,C,I,w,b,x,S,g,N,T]),z=y.useMemo(()=>{let V="";if(d.text){const le=wt(d.text);for(let ie=0;ie<le.length;ie++){const pe=le[ie];pe===""?V=V+"<div><br/></div>":V=V+`<div style="background-color:${d.fontBgColor}">${pe}</div>`}}else V=`<div style="background-color:${d.fontBgColor}"></div>`;return V},[d.fontBgColor,d.text]),X=y.useMemo(()=>{var V,le;return A==="hover"&&g&&t&&O.isNumber(f)&&O.isNumber(m)&&d.boxSize&&O.isNumber((V=d.boxSize)==null?void 0:V[0])&&O.isNumber((le=d.boxSize)==null?void 0:le[1])?y.createElement("div",{className:be.FloatBarBtn,style:{left:f,top:m,width:d.boxSize[0]*g,height:d.boxSize[1]*g}},y.createElement(fn,{position:{x:f,y:m},textOpt:d,workIds:[e],noLayer:!0,noCopy:!0,noDelete:!0})):null},[d,t,e,f,m,g,A]);y.useEffect(()=>{u===e&&K()},[u,A,e]);function K(){var V,le;if(E.current){const ie=window==null?void 0:window.getSelection(),pe=(V=E.current)==null?void 0:V.lastChild;if(ie&&pe){const de=document.createRange(),Me=((le=pe.textContent)==null?void 0:le.length)||0;(pe==null?void 0:pe.nodeName)==="#text"?de.setStart(pe,Me):de.setStart(pe,Me&&1||0),de.collapse(!0),ie.removeAllRanges(),ie.addRange(de)}E.current.focus()}}function F(V){if(V.key==="Backspace"){const le=window.getSelection(),ie=le==null?void 0:le.getRangeAt(0);if(ie!=null&&ie.collapsed)return V.cancelable&&V.preventDefault(),document.execCommand("delete",!1),!1}return n(),!1}function G(V,le){const ie=window==null?void 0:window.getSelection();if(ie!=null&&ie.rangeCount&&V&&ie&&ie.anchorNode){const pe=ie.anchorOffset,de=ie.anchorNode.textContent||"",Me=de.slice(0,pe)||"",ot=de.slice(pe)||"",nt=Me.concat(V)||"";_(nt,ot,le)}}function _(V,le,ie){const pe=window==null?void 0:window.getSelection();if(!(pe!=null&&pe.rangeCount)||!pe.anchorNode)return;const de=V.split(/\n/);let Me=pe.anchorNode.parentNode;Me===ie&&(Me=pe.anchorNode);const ot=[...ie.childNodes],nt=[];let _e,Cs=pe.anchorOffset;for(;ot.length;){const Ae=ot.pop();if(Ae){if(Ae===Me){let Qe=de[0];de.length===1&&(Cs=de[0].length,Qe=de[0].concat(le)),Me.nodeName==="#text"?(Me.textContent=Qe,_e=Me):Me.nodeName==="DIV"&&(Me.innerText=Qe,_e=Me.childNodes[0]);break}nt.push(Ae),ie.removeChild(Ae)}}if(de.length>1)for(let Ae=1;Ae<de.length;Ae++){let Qe=de[Ae];const Rt=document.createElement("div");d.fontBgColor&&(Rt.style.backgroundColor=d.fontBgColor),Ae===de.length-1&&(Cs=Qe.length,Qe=Qe.concat(le)),Qe===""?Rt.innerHTML="<br/>":Rt.innerText=Qe,ie.appendChild(Rt),Ae===de.length-1&&(_e=Rt.childNodes[0])}if(nt.length){nt.reverse();for(const Ae of nt)ie.appendChild(Ae)}if(_e&&_e.nodeName==="#text"){pe.deleteFromDocument();const Ae=document.createRange(),Qe=Math.min(Cs,(_e==null?void 0:_e.length)||0);Ae.setStart(_e,Qe),Ae.collapse(!0),pe.removeAllRanges(),pe.addRange(Ae)}}function ce(V){if(V.cancelable&&V.preventDefault(),V.stopPropagation(),E.current){const le=(V.clipboardData||window.clipboardData).getData("text"),ie=window==null?void 0:window.getSelection();if(!(ie!=null&&ie.rangeCount))return;le&&ie&&ie.anchorNode&&G(le,E.current),n()}}function ee(V){V.persist(),setTimeout(()=>{a||i(V)},0)}function q(){c(!0),n()}function J(V){c(!1),i(V)}const ue=y.useCallback(V=>{h&&(h.control.textEditorManager.checkEmptyTextBlur(),o(V),h==null||h.control.textEditorManager.active(e))},[o,h,e]),ze=y.useCallback(()=>{if(A==="active"&&E.current&&E.current.parentElement){const V=E.current.parentElement;V.style.borderColor=C}},[A,C]),Te=y.useCallback(()=>{if(A==="active"&&E.current&&E.current.parentElement){const V=E.current.parentElement;V.style.borderColor="transparent"}},[A]);return y.createElement(y.Fragment,null,X,y.createElement("div",{className:`editor-box ${A}`,style:P},y.createElement("div",{id:e,suppressContentEditableWarning:!0,contentEditable:!0,className:"editor",ref:E,style:R,onKeyDown:F,onFocus:ue,onMouseOver:ze,onMouseLeave:Te,onPaste:ce,onTouchEnd:()=>{document.activeElement!==E.current&&K()},onInput:ee,onCompositionStart:q,onCompositionEnd:J,dangerouslySetInnerHTML:{__html:z}})))},ow=r=>{const s=y.useRef(null),[e,t]=y.useState(),{mananger:i}=y.useContext(ve),o=y.useCallback(()=>{if(!e){const c=requestAnimationFrame(()=>{s!=null&&s.current&&(s==null||s.current.scrollTo({left:0,behavior:"instant"})),t(void 0)});t(c)}},[e]),n=y.useCallback(c=>{var g,p;const{activeTextId:l,update:u,syncData:h}=c;if(!i)return;const d=l&&O.cloneDeep(((g=i.control.textEditorManager)==null?void 0:g.get(l))||((p=r.editors)==null?void 0:p.get(l)));d&&d.opt&&(d.opt={...d.opt,...u},h&&(d.canSync=Object.keys(h).includes("canSync")&&h.canSync||d.canSync,d.canWorker=Object.keys(h).includes("canWorker")&&h.canWorker||d.canWorker),i.control.textEditorManager.updateForViewEdited(l,d))},[i,r.editors]),a=y.useMemo(()=>{var h;const c=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&&g.push(w);const I=m.pop();g.push(...m),I&&g.push(I)}}}return g},l=d=>{if(!i)return;const g=d.currentTarget.id,p=i.control.textEditorManager.get(g),f=j.Doing,m=[d.nativeEvent.target.offsetWidth,d.nativeEvent.target.offsetHeight];(!p||p&&(!O.isEqual(p.opt.boxSize,m)||!O.isEqual(p.opt.workState,f)))&&n({activeTextId:g,update:{boxSize:m,workState:f},syncData:{canSync:!0,canWorker:!0}})},u=d=>{var T,C;if(!i)return;const g=c(d.nativeEvent.target),p=d.nativeEvent.target.id,f=i.control.textEditorManager.get(p),m=We(g),w=j.Doing,I=[d.nativeEvent.target.offsetWidth,d.nativeEvent.target.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(((T=i.control.textEditorManager)==null?void 0:T.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,i.control.textEditorManager.updateForViewEdited(p,S)),i.control.textEditorManager.publicMsgEmitter.emit("textChange",p,d.nativeEvent.target,g,S)}};if((h=r.editors)!=null&&h.size){const d=[];return r.editors.forEach((g,p)=>{d.push(y.createElement(iw,{key:p,workId:p,data:g,showFloatBtns:r.showFloatBtns||!1,handleFocus:l,handleKeyUp:u,runAnimation:o}))}),d}return null},[r.editors,r.showFloatBtns,i,n,o]);return y.createElement("div",{className:`${r.className}`,ref:s},a)},nw=()=>{const{floatBarData:r}=y.useContext(ve);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}}))},rw=()=>{const{floatBarData:r,mananger:s}=y.useContext(ve),[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)},aw=()=>{const{floatBarData:r}=y.useContext(ve);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}}))},cw=()=>{const{floatBarData:r}=y.useContext(ve);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"}))},lw=r=>{const{className:s}=r,{floatBarData:e,angle:t,setAngle:i,setOperationType:o,mananger:n}=y.useContext(ve),[a,c]=y.useState(j.Pending),[l,u]=y.useState(),[h,d]=y.useState(!1),[g,p]=y.useState(new Z),[f,m]=y.useState(new Z),[w,I]=y.useState(!1),T=y.useRef(0),C=y.useRef(null),S=E=>{if(!E){I(!0),d(!1),o(Q.None),c(j.Pending);return}I(!1)},N=(E,A)=>{T.current&&(clearTimeout(T.current),T.current=0),c(j.Done),d(!1);const P=Math.round(Z.GetAngleByPoints(g,f,new Z(A.x,A.y)))||0;i(P),o(Q.None),ne.emitMethod(se.MainEngine,Q.RotateNode,{workIds:[H],angle:P,workState:j.Done,viewId:n==null?void 0:n.viewId})};y.useEffect(()=>(ne.activeListener(S),()=>{ne.unmountActiveListener(S)}),[]),y.useEffect(()=>{if(e&&(a===j.Pending||a===j.Done)){const E={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 Z(A.x,A.y)),p(new Z(E.x,E.y)),u({x:E.x,y:E.y})}},[e,a]);const x=(E,A)=>{if(n!=null&&n.control.worker.isBusy){I(!0),c(j.Pending);return}T.current&&(clearTimeout(T.current),T.current=0),c(j.Start),d(!0);const P=Math.round(Z.GetAngleByPoints(g,f,new Z(A.x,A.y)))||0;i(P),o(Q.RotateNode),ne.emitMethod(se.MainEngine,Q.RotateNode,{workIds:[H],angle:0,workState:j.Start,viewId:n==null?void 0:n.viewId})},L=(E,A)=>{if(n!=null&&n.control.worker.isBusy){I(!0),N(E,A);return}N(E,A)},b=(E,A)=>{if(n!=null&&n.control.worker.isBusy){I(!0),N(E,A);return}T.current||(u({x:A.x,y:A.y}),d(!0),T.current=setTimeout(()=>{T.current=0;const P=Math.round(Z.GetAngleByPoints(g,f,new Z(A.x,A.y)))||0;i(P),o(Q.RotateNode),c(j.Doing),ne.emitMethod(se.MainEngine,Q.RotateNode,{workIds:[H],angle:P,workState:j.Doing,viewId:n==null?void 0:n.viewId})},60))};return y.createElement(bt,{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:xe("rotation-button")})),y.createElement("div",{ref:C,className:`appliance-plugin-rotate-mouse-pointer ${h?"active":""}`},y.createElement("img",{alt:"icon",src:xe("rotation")}),y.createElement("div",{className:"angle-icon"},t,"°"))))},hw=()=>{const{floatBarData:r,setOperationType:s,mananger:e,isNoPointerEvents:t}=y.useContext(ve),[i,o]=y.useState(j.Pending),[n,a]=y.useState(),[c,l]=y.useState(!1),u=y.useRef(0),h=y.useMemo(()=>!!((r==null?void 0:r.scaleType)===re.none&&(r!=null&&r.canLock)),[r]),d=y.useMemo(()=>r&&r.w&&r.h?{position:"absolute",left:0,top:0,width:r.w,height:r.h,zIndex:2,pointerEvents:h||t?"none":"auto",touchAction:"none"}:{display:"none",pointerEvents:"none"},[r,h,t]),g=I=>{if(!I||r!=null&&r.isLocked){l(!0),o(j.Pending),s(Q.None);return}l(!1)},p=(I,T)=>{u.current&&(clearTimeout(u.current),u.current=0);const C={x:T.x,y:T.y};s(Q.None),o(j.Done),a(C),ne.emitMethod(se.MainEngine,Q.TranslateNode,{workIds:[H],position:C,workState:j.Done,viewId:e==null?void 0:e.viewId})};y.useEffect(()=>(ne.activeListener(g),()=>{ne.unmountActiveListener(g)}),[]),y.useEffect(()=>{if(r&&(r!=null&&r.isLocked)||e!=null&&e.control.worker.isBusy){l(!0);return}l(!1)},[r,e==null?void 0:e.control.worker.isBusy]),y.useEffect(()=>{O.isNumber(r==null?void 0:r.x)&&O.isNumber(r==null?void 0:r.y)&&(i===j.Pending||i===j.Done)&&a({x:r==null?void 0:r.x,y:r==null?void 0:r.y})},[r==null?void 0:r.x,r==null?void 0:r.y,i]);const f=()=>{if(e!=null&&e.control.worker.isBusy){l(!0);return}u.current&&(clearTimeout(u.current),u.current=0),O.isNumber(r==null?void 0:r.x)&&O.isNumber(r==null?void 0:r.y)&&(s(Q.TranslateNode),o(j.Start),ne.emitMethod(se.MainEngine,Q.TranslateNode,{workIds:[H],position:{x:r==null?void 0:r.x,y:r==null?void 0:r.y},workState:j.Start,viewId:e==null?void 0:e.viewId}))},m=(I,T)=>{e!=null&&e.control.worker.isBusy&&l(!0),p(I,T)},w=(I,T)=>{if(e!=null&&e.control.worker.isBusy){l(!0),p(I,T);return}if(u.current)return;const C={x:T.x,y:T.y};a(C),u.current=setTimeout(()=>{u.current=0,(C.x!==(n==null?void 0:n.x)||C.y!==(n==null?void 0:n.y))&&(o(j.Doing),ne.emitMethod(se.MainEngine,Q.TranslateNode,{workIds:[H],position:C,workState:j.Doing,viewId:e==null?void 0:e.viewId}))},60)};return y.createElement(bt,{disabled:c,position:n,onStart:f,onDrag:w,onStop:m},y.createElement("div",{style:d}))},uw=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(ve),[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 ne.activeListener(C),()=>{ne.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 T=()=>{if(I.current&&(clearTimeout(I.current),I.current=0),p){const{scale:A,translate:P}=p;g(Q.None),ne.emitMethod(se.MainEngine,Q.ScaleNode,{workIds:[H],scale:A,dir:c,translate:P,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]],N=(A,P)=>{switch(P){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,P,R,z)=>{let X=!1,K=!1;const F={x:e.x,y:e.y,w:e.w,h:e.h},G=[1,1],_=[0,0];switch(A){case"top":{const J=P.height+e.h;J<0?(K=!0,F.y=e.y+e.h,F.h=Math.abs(J)):(F.y=e.y-P.height,F.h=e.h+P.height);break}case"topLeft":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+e.w,F.w=Math.abs(J)):(F.x=e.x-P.width,F.w=e.w+P.width);const ue=P.height+e.h;ue<0?(K=!0,F.y=e.y+e.h,F.h=Math.abs(ue)):(F.y=e.y-P.height,F.h=e.h+P.height);break}case"topRight":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+J,F.w=Math.abs(J)):F.w=e.w+P.width;const ue=P.height+e.h;ue<0?(K=!0,F.y=e.y+e.h,F.h=Math.abs(ue)):(F.y=e.y-P.height,F.h=e.h+P.height);break}case"bottom":{const J=P.height+e.h;J<0?(K=!0,F.y=e.y+J,F.h=Math.abs(J)):F.h=e.h+P.height;break}case"bottomLeft":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+e.w,F.w=Math.abs(J)):(F.x=e.x-P.width,F.w=e.w+P.width);const ue=P.height+e.h;ue<0?(K=!0,F.y=e.y+ue,F.h=Math.abs(ue)):F.h=e.h+P.height;break}case"left":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+e.w,F.w=Math.abs(J)):(F.x=e.x-P.width,F.w=e.w+P.width);break}case"bottomRight":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+J,F.w=Math.abs(J)):F.w=e.w+P.width;const ue=P.height+e.h;ue<0?(K=!0,F.y=e.y+ue,F.h=Math.abs(ue)):F.h=e.h+P.height;break}case"right":{const J=P.width+e.w;J<0?(X=!0,F.x=e.x+J,F.w=Math.abs(J)):F.w=e.w+P.width;break}}G[0]=F.w/e.w,G[1]=F.h/e.h;const ee=S(F).map(J=>R.control.viewContainerManager.transformToScenePoint(J,R.viewId)),q=N(ee,A);return K&&(_[1]=q[1]-z[1]),X&&(_[0]=q[0]-z[0]),{scale:G,translate:_}},L=(A,P)=>{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),X=z.map(G=>h.control.viewContainerManager.transformToScenePoint(G,h.viewId)),K=N(z,P),F=N(X,P);t(R),o(K),a(F),l(P),g(Q.ScaleNode),ne.emitMethod(se.MainEngine,Q.ScaleNode,{workIds:[H],originPoint:K,scenePoint:F,workState:j.Start,viewId:h.viewId})}},b=(A,P,R,z)=>{if(!(!h||!i||!n)){if(h!=null&&h.control.worker.isBusy){w(!0),T();return}I.current||(I.current=setTimeout(()=>{I.current=0;const{scale:X,translate:K}=x(P,z,h,n);(!O.isEqual(X,p==null?void 0:p.scale)||!O.isEqual(K,p==null?void 0:p.translate))&&(f({scale:X,translate:K}),g(Q.ScaleNode),ne.emitMethod(se.MainEngine,Q.ScaleNode,{workIds:[H],scale:X,dir:P,translate:K,originPoint:i,scenePoint:n,workState:j.Doing,viewId:h.viewId}))},60))}},E=()=>{h!=null&&h.control.worker.isBusy&&w(!0),T()};return y.createElement(mn.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)===re.all&&!0||!1,right:(u==null?void 0:u.scaleType)===re.all&&!0||!1,bottom:(u==null?void 0:u.scaleType)===re.all&&!0||!1,left:(u==null?void 0:u.scaleType)===re.all&&!0||!1,topRight:!0,bottomRight:!0,bottomLeft:!0,topLeft:!0},lockAspectRatio:(u==null?void 0:u.scaleType)===re.proportional,onResizeStart:L,onResize:b,onResizeStop:E})},ro=r=>{const{id:s,pos:e,pointMap:t,type:i}=r,{setOperationType:o,mananger:n,floatBarData:a}=y.useContext(ve),[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(Q.None);return}g(!1)};y.useEffect(()=>(ne.activeListener(m),()=>{ne.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,N)=>{p.current&&(clearTimeout(p.current),p.current=0),o(Q.None),h(j.Done);const x={x:N.x,y:N.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),ne.emitMethod(se.MainEngine,Q.SetPoint,{workId:H,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(Q.SetPoint),h(j.Start),ne.emitMethod(se.MainEngine,Q.SetPoint,{workId:H,pointMap:t,workState:j.Start,viewId:n==null?void 0:n.viewId}))},T=(S,N)=>{if(n!=null&&n.control.worker.isBusy){g(!0),w(S,N);return}if(p.current)return;const x={x:N.x,y:N.y};l(x),p.current=setTimeout(()=>{if(p.current=0,(x.x!==(N==null?void 0:N.x)||x.y!==(N==null?void 0:N.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),ne.emitMethod(se.MainEngine,Q.SetPoint,{workId:H,pointMap:t,workState:j.Doing,viewId:n==null?void 0:n.viewId})}},60)},C=(S,N)=>{n!=null&&n.control.worker.isBusy&&g(!0),w(S,N)};return y.createElement(bt,{disabled:d,position:c,onStart:I,onDrag:T,onStop:C},y.createElement("div",{className:"appliance-plugin-point-draggable-btn",style:f}))},dw=r=>{const{className:s}=r,{floatBarData:e,mananger:t}=y.useContext(ve),[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(ro,{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(ro,{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)},pw=y.forwardRef((r,s)=>{const{floatBarData:e,operationType:t}=y.useContext(ve),i=y.useMemo(()=>(e==null?void 0:e.scaleType)!==re.all||t===Q.RotateNode?null:y.createElement(nw,null),[e,t]),o=y.useMemo(()=>(e==null?void 0:e.scaleType)!==re.both||t===Q.RotateNode?null:y.createElement(rw,null),[e,t]),n=y.useMemo(()=>(e==null?void 0:e.scaleType)!==re.proportional||t===Q.RotateNode?null:y.createElement(aw,null),[e,t]),a=y.useMemo(()=>(e==null?void 0:e.scaleType)===re.none&&(e!=null&&e.canLock)?y.createElement(cw,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)}),gw=y.forwardRef((r,s)=>{const{floatBarData:e,operationType:t,mananger:i}=y.useContext(ve),{editors:o,isHide:n}=r,a=y.useMemo(()=>{var d;return e!=null&&e.canRotate&&((d=e==null?void 0:e.selectIds)==null?void 0:d.length)===1&&(t===Q.None||t===Q.RotateNode)?y.createElement(lw,{className:be.RotateBtn}):null},[e,t]),c=y.useMemo(()=>((e==null?void 0:e.scaleType)===re.all||(e==null?void 0:e.scaleType)===re.proportional)&&(t===Q.None||t===Q.ScaleNode)&&O.isNumber(e==null?void 0:e.x)&&O.isNumber(e==null?void 0:e.y)?y.createElement(uw,{className:be.ResizeBtn}):null,[e==null?void 0:e.scaleType,t,e==null?void 0:e.x,e==null?void 0:e.y]),l=y.useMemo(()=>(e==null?void 0:e.scaleType)===re.both&&(t===Q.None||t===Q.SetPoint)?y.createElement(dw,{className:be.ResizeTowBox}):null,[e==null?void 0:e.scaleType,t]),u=y.useMemo(()=>o?y.createElement(sw,{editors:o,selectIds:(e==null?void 0:e.selectIds)||[]}):null,[o,e]),h=y.useMemo(()=>n&&t===Q.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:be.FloatBarBtn,style:{left:e==null?void 0:e.x,top:e==null?void 0:e.y,width:e.w,height:e.h}},y.createElement(fn,{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:be.FloatBar,onPointerOver:d=>(d.stopPropagation(),d.nativeEvent.stopImmediatePropagation(),i==null||i.control.worker.blurCursor(i.viewId),!1)},y.createElement(pw,{ref:s},y.createElement(y.Fragment,null,u)),y.createElement(hw,null),a,c,l,h)}),fw=y.memo(gw,(r,s)=>!!O.isEqual(r,s));class Mw 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 oe.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:Yt.get("pencil"),alt:"pencilCursor"}))));case oe.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:Yt.get("selector"),alt:"selectorCursor"}))));case oe.eraser:case oe.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:Yt.get("eraser"),alt:"eraserCursor"}))));case oe.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:Yt.get("text"),alt:"textCursor"}))));case oe.rectangle:case oe.arrow:case oe.straight:case oe.shape:case oe.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:Yt.get("shape"),alt:"shapeCursor"}))));default:return null}}}const yw=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(Mw,{roomMember:t}))},mw=r=>{const{className:s,manager:e}=r,[t,i]=y.useState();y.useEffect(()=>(e.internalMsgEmitter.on([se.Cursor,e.viewId],o),()=>{e.internalMsgEmitter.off([se.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(yw,{key:(l=c.roomMember)==null?void 0:l.memberId,className:s,info:c}):null});return y.createElement(y.Fragment,null,a)}return null},[t])},ww=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],T=[h.centerX,h.centerY],C=[I[0]-T[0],I[1]-T[1]],S=Math.min(h.scale*f,h.scale*f),N=[C[0]*S,C[1]*S,m,w,S];a(N)},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,T]=[(h.nativeEvent.offsetX-m)/n[4],(h.nativeEvent.offsetY-w)/n[4]],C=i.maps.get(s);if(C!=null&&C.viewCamera){const[S,N]=[C.miniMapCamera.centerX+I,C.miniMapCamera.centerY+T];(d=i.control.room)==null||d.moveCamera({centerX:S,centerY:N,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"}}))},Iw=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 us.createPortal(y.createElement(ww,{viewId:e,...l,highlightColor:u,miniMapManager:s}),l.contianer)}}}return null},[e,s]);return y.createElement("div",{className:t},i)},ve=y.createContext({mananger:void 0,floatBarColors:[],floatBarData:void 0,dpr:1,angle:0,operationType:Q.None,scale:[1,1],isNoPointerEvents:!1,activeTextEditor:!1,activeTextId:void 0,setAngle:()=>{},setOperationType:()=>{},setFloatBarData:()=>{}});class di extends y.Component{constructor(e){var t,i;super(e);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:Q.None,scale:[1,1],editors:this.editors,activeTextId:(t=this.props.mananger.control.textEditorManager)==null?void 0:t.activeId,activeMiniMapViewId:(i=this.props.mananger.control.miniMapManager)==null?void 0:i.activeViewId}}get editors(){return ke(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:be.Container},!this.props.mananger.control.hasOffscreenCanvas()&&y.createElement("div",{className:be.CanvasBox,ref:this.props.refs.canvasContainerRef})||y.createElement("div",{className:be.CanvasBox},y.createElement("canvas",{id:"bgCanvas",ref:this.props.refs.canvasBgRef,style:{width:"100%",height:"100%"}}),y.createElement("canvas",{id:"serviceCanvas",className:be.FloatCanvas,ref:this.props.refs.canvasServiceFloatRef,style:{width:"100%",height:"100%"}}),y.createElement("canvas",{id:"localCanvas",className:be.FloatCanvas,ref:this.props.refs.canvasFloatRef,style:{width:"100%",height:"100%"}}),y.createElement("div",{id:"subLocalCanvas",className:be.CanvasBoxSub,ref:this.props.refs.subLocalCanvasContainerRef}),y.createElement("canvas",{id:"topCanvas",className:be.TopFloatCanvas,ref:this.props.refs.canvasTopRef,style:{width:"100%",height:"100%"}})),!this.props.mananger.control.hasOffscreenCanvas()&&this.props.refs.snapshotContainerRef&&y.createElement("div",{className:be.SnapshotBox,ref:this.props.refs.snapshotContainerRef})||null,y.createElement(ve.Provider,{value:{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(fw,{ref:this.props.refs.floatBarRef,editors:this.state.editors,isHide:e&&this.state.showFloatBarBtn})||null,((c=this.state.editors)==null?void 0:c.size)&&y.createElement(ow,{className:be.TextEditorContainer,showFloatBtns:e&&this.state.showFloatBarBtn,editors:this.state.editors})||null),y.createElement(mw,{className:be.CursorBox,manager:this.props.mananger}),y.createElement(Iw,{className:be.MiniMapBox,active:this.state.activeMiniMapViewId,miniMapManager:this.props.mananger.control.miniMapManager}))}}class vw extends pn{constructor(e,t){super(e,t);M(this,"width",1e3);M(this,"height",1e3);M(this,"dpr",it());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=it();this.canvasBgRef.current&&(i=it(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(),us.render(y.createElement(di,{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 Tw extends pm{constructor(e,t,i){super(e,t,i);M(this,"dpr",it());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=it();if(this.canvasBgRef.current&&(e=it(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(),us.render(y.createElement(di,{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 Ue extends Lt{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(ge,!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 vw(this.control,Se.InternalMsgEmitter),n=e.size.width||o.width,a=e.size.height||o.height,l={dpr:o.dpr,originalPoint:[n/2,a/2],offscreenCanvasOpt:{...Ue.defaultScreenCanvasOpt,width:n,height:a},layerOpt:{...Ue.defaultLayerOpt,width:n,height:a},cameraOpt:{...Ue.defaultCameraOpt,width:n,height:a}},{scale:u,...h}=e.camera;l.cameraOpt={...l.cameraOpt,...h,scale:u===1/0?1:u},this.createMianView({id:ge,container:t,displayer:o,focusScenePath:e.focusScenePath,cameraOpt:l.cameraOpt,viewData:e}),this.setFocuedViewId(ge),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 Tw(t,this.control,Se.InternalMsgEmitter),c=i.size.width||a.width,l=i.size.height||a.height,h={dpr:a.dpr,originalPoint:[c/2,l/2],offscreenCanvasOpt:{...Ue.defaultScreenCanvasOpt,width:c,height:l},layerOpt:{...Ue.defaultLayerOpt,width:c,height:l},cameraOpt:{...Ue.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&&(Ue.defaultScreenCanvasOpt.contextType=this.control.pluginOptions.canvasOpt.contextType);const c={dpr:a,originalPoint:[o/2,n/2],offscreenCanvasOpt:{...Ue.defaultScreenCanvasOpt,width:o,height:n},layerOpt:{...Ue.defaultLayerOpt,width:o,height:n},cameraOpt:{...Ue.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||ge;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,ge)}),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 rt extends Se{constructor(e){super(e);M(this,"windowManager");M(this,"viewContainerManager");const t={control:this,internalMsgEmitter:Se.InternalMsgEmitter,publicMsgEmitter:Se.PublicMsgEmitter};this.viewContainerManager=new Ue(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(ge,!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())Se.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 $.InvisiblePlugin{constructor(){super(...arguments);M(this,"onPhaseChanged",e=>{var t;e===$.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)),!($.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;$.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:ci(f,m)},screenshotToCanvasAsync:async function(p,f,m,w,I,T){var b;U.logger.info("[ApplianceMultiPlugin] screenshotToCanvasAsync");let C=m,S=w,N=I.scale;C>this.maxScreenshotWidth&&(N=this.maxScreenshotWidth/C*N,C=this.maxScreenshotWidth),S>this.maxScreenshotHeight&&(N=Math.min(this.maxScreenshotHeight/S*N,N),S=this.maxScreenshotHeight),I.scale=N;const x=document.createElement("canvas"),L=x.getContext("2d");x.width=C*(T||1),x.height=S*(T||1),L&&((e.mainView||i).screenshotToCanvas(L,f,C,S,I,T),p.drawImage(x,Math.floor((m-C)/2),Math.floor((w-S)/2),C*(T||1),S*(T||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 T=document.createElement("img");T.className="appliance-plugin-fill-scene-snapshot-img",f.append(T),getComputedStyle(f).position||(f.style.position="relative"),U.currentManager&&await U.currentManager.scenePreview(p,T)},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 T=m||e.mainView.size.width,C=w||e.mainView.size.height;let S=await this.getBoundingRectAsync(p);S||(S={originX:0,originY:0,width:T,height:C});let N=Math.max(S==null?void 0:S.width,T),x=Math.max(S==null?void 0:S.height,C),L=1;const b=N>T&&Math.min(T/N,L)||L,E=x>C&&Math.min(C/x,L)||L;b<=E?(N=b<1&&T||N,x=Math.floor(x*b)+1,L=b):b>E&&(x=E<1&&C||x,N=Math.floor(N*E)+1,L=E);const A={scale:L,centerX:S.originX+S.width/2,centerY:S.originY+S.height/2},P=document.createElement("canvas"),R=P.getContext("2d");P.width=N,P.height=x,R&&await this.screenshotToCanvasAsync(R,p,N,x,A,devicePixelRatio);const z=document.createElement("img");z.className="appliance-plugin-fill-scene-snapshot-img",z.src=P.toDataURL(),z.onload=()=>{P.remove()},z.onerror=()=>{P.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")&&$.isRoom(i)&&i.isWritable?rt.InternalMsgEmitter.on(p,f):o.call(i.callbacks,p,f)},_callbacksOnce:function(p,f){U.logger.info(`[ApplianceMultiPlugin] callbacks ${p}`),(p==="onCanUndoStepsUpdate"||p==="onCanRedoStepsUpdate")&&$.isRoom(i)&&i.isWritable?rt.InternalMsgEmitter.on(p,f):a.call(i.callbacks,p,f)},_callbacksOff:function(p,f){U.logger.info(`[ApplianceMultiPlugin] callbacks ${p}`),(p==="onCanUndoStepsUpdate"||p==="onCanRedoStepsUpdate")&&$.isRoom(i)&&i.isWritable?rt.InternalMsgEmitter.off(p,f):n.call(i.callbacks,p,f)},canRedoSteps(){if(U.logger.info("[ApplianceMultiPlugin] canRedoSteps"),U.currentManager&&$.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&&$.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&&$.isRoom(i)&&!i.disableSerialization?U.currentManager.viewContainerManager.undo():0},redo:function(){return U.logger.info("[ApplianceMultiPlugin] redo"),U.currentManager&&$.isRoom(i)&&!i.disableSerialization?U.currentManager.viewContainerManager.redo():0},cleanCurrentScene:function(){U.logger.info("[ApplianceMultiPlugin] cleanCurrentScene"),U.currentManager&&$.isRoom(i)&&i.isWritable&&(U.currentManager.cleanCurrentScene(),c.call(e))},insertImage:function(p){U.logger.info("[ApplianceMultiPlugin] insertImage"),U.currentManager&&$.isRoom(i)&&i.isWritable&&U.currentManager.worker.insertImage(ge,p)},lockImage:function(p,f){U.logger.info("[ApplianceMultiPlugin] lockImage"),U.currentManager&&$.isRoom(i)&&i.isWritable&&U.currentManager.worker.lockImage(ge,p,f)},completeImageUpload:function(p,f){U.logger.info("[ApplianceMultiPlugin] completeImageUpload"),U.currentManager&&$.isRoom(i)&&i.isWritable&&U.currentManager.worker.completeImageUpload(ge,p,f)},getImagesInformation:function(p){return U.logger.info("[ApplianceMultiPlugin] completeImageUpload"),U.currentManager&&$.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($.isRoom(i)&&i.isWritable){f.includes("currentApplianceName")&&(p.currentApplianceName&&p.currentApplianceName===oe.laserPen?(p.currentApplianceName=oe.pencil,p.useLaserPen=!0):p.currentApplianceName&&p.currentApplianceName===oe.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&&$.isRoom(i)&&i.isWritable)return U.currentManager.createMiniMap(p,f)},destroyMiniMap:async function(p){if(U.logger.info("[ApplianceMultiPlugin] destroyeMiniMap"),U.currentManager&&$.isRoom(i)&&i.isWritable)return U.currentManager.destroyMiniMap(p)},filterRenderByUid(p,f,m){if(U.logger.info("[ApplianceMultiPlugin] filterRenderByUid"),U.currentManager&&$.isRoom(i)&&i.isWritable)return U.currentManager.filterRenderByUid(p,f,m)},cancelFilterRender(p,f){if(U.logger.info("[ApplianceMultiPlugin] filterRenderByUid"),U.currentManager&&$.isRoom(i)&&i.isWritable)return U.currentManager.cancelFilterRender(p,f)},addListener:(p,f)=>{U.logger.info(`[ApplianceMultiPlugin] addListener ${p}`),rt.PublicMsgEmitter.on(p,f)},removeListener:(p,f)=>{U.logger.info(`[ApplianceMultiPlugin] removeListener ${p}`),rt.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&&$.isRoom(i))return U.currentManager.disableDeviceInputs},setDisableDeviceInputs(p){U.logger.info(`[ApplianceMultiPlugin] setDisableDeviceInputs ${p}`),U.currentManager&&$.isRoom(i)&&(U.currentManager.disableDeviceInputs=p)},getDisableCameraTransform(){if(U.currentManager&&$.isRoom(i))return U.currentManager.disableCameraTransform},setDisableCameraTransform(p){U.logger.info(`[ApplianceMultiPlugin] setDisableCameraTransform ${p}`),U.currentManager&&$.isRoom(i)&&(U.currentManager.disableCameraTransform=p)},getDisableEraseImage(){if(U.currentManager&&$.isRoom(i))return U.currentManager.disableEraseImage},setDisableEraseImage(p){U.logger.info(`[ApplianceMultiPlugin] setDisableEraseImage ${p}`),U.currentManager&&$.isRoom(i)&&(U.currentManager.disableEraseImage=p)},setWritable:async function(p){var f;U.logger.info(`[ApplianceMultiPlugin] setWritable ${p}`),$.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 T=new MessageChannel;let C;const S=N=>{try{p({didTimeout:N,timeRemaining:()=>{const L=performance.now()-w;return Math.max(0,m-L)}})}catch(x){U.logger.error("[ApplianceMultiPlugin] requestIdleCallback error:",x)}finally{T.port1.close(),T.port2.close(),I!==void 0&&cancelAnimationFrame(I),C!==void 0&&clearTimeout(C)}};return T.port1.onmessage=()=>{I=requestAnimationFrame(()=>{m>0&&performance.now()-w>=m?S(!0):S(!1)})},T.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"),$.isRoom(i)&&d.injectMethodToObject(i,"setWritable"),Object.defineProperty(e,"canUndoSteps",{get(){return d.canUndoSteps()}}),Object.defineProperty(e,"canRedoSteps",{get(){return d.canRedoSteps()}}),rt.InternalMsgEmitter.on("onCanUndoStepsUpdate",p=>{e.emitter.emit("canUndoStepsChange",p)}),rt.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 $.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),$.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 rt(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 Fs=U;class Nw extends pn{constructor(e,t){super(e,t);M(this,"width",1e3);M(this,"height",1e3);M(this,"dpr",it());M(this,"vDom");M(this,"viewId",ge);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=it();this.canvasBgRef.current&&(i=it(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="",us.render(y.createElement(di,{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 et extends Lt{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 Nw(this.control,Se.InternalMsgEmitter),{width:t,height:i,dpr:o}=e,n={dpr:o,originalPoint:[t/2,i/2],offscreenCanvasOpt:{...et.defaultScreenCanvasOpt,width:t,height:i},layerOpt:{...et.defaultLayerOpt,width:t,height:i},cameraOpt:{...et.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:ge,displayer:e,focusScenePath:a.focusScenePath||a.scenePath,cameraOpt:n.cameraOpt,viewData:a}),this.setFocuedViewId(ge),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&&(et.defaultScreenCanvasOpt.contextType=this.control.pluginOptions.canvasOpt.contextType);const c={dpr:a,originalPoint:[o/2,n/2],offscreenCanvasOpt:{...et.defaultScreenCanvasOpt,width:o,height:n},layerOpt:{...et.defaultLayerOpt,width:o,height:n},cameraOpt:{...et.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 Be extends Se{constructor(e){super(e);M(this,"viewContainerManager");M(this,"divMainView");M(this,"onCameraChange",hn(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)},ai,{leading:!1}));const t={control:this,internalMsgEmitter:Be.InternalMsgEmitter,publicMsgEmitter:Be.PublicMsgEmitter};this.viewContainerManager=new et(t)}init(){Be.InternalMsgEmitter.on(se.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(ge,!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())Se.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 $.InvisiblePlugin{constructor(){super(...arguments);M(this,"onPhaseChanged",e=>{var t;e===$.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 Be&&(e.cameraState&&W.currentManager.onCameraChange(e.cameraState),e.sceneState&&W.currentManager.onSceneChange(e.sceneState.scenePath,ge)),e!=null&&e.roomMembers&&((t=W.currentManager)==null||t.onRoomMembersChange(e.roomMembers)),!($.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;$.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:ci(p,f)},screenshotToCanvasAsync:async function(g,p,f,m,w,I){var L;W.logger.info("[ApplianceSinglePlugin] screenshotToCanvasAsync");let T=f,C=m,S=w.scale;T>this.maxScreenshotWidth&&(S=this.maxScreenshotWidth/T*S,T=this.maxScreenshotWidth),C>this.maxScreenshotHeight&&(S=Math.min(this.maxScreenshotHeight/C*S,S),C=this.maxScreenshotHeight),w.scale=S;const N=document.createElement("canvas"),x=N.getContext("2d");N.width=T*(I||1),N.height=C*(I||1),x&&(e.screenshotToCanvas(x,p,T,C,w,I),g.drawImage(N,Math.floor((f-T)/2),Math.floor((m-C)/2),T*(I||1),C*(I||1),0,0,T,C),N.remove()),W.currentManager&&await((L=W.currentManager)==null?void 0:L.screenshotToCanvas(g,p,T,C,w,Math.floor((f-T)/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,X;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,T=m||((X=e.state.cameraState)==null?void 0:X.height)||0;let C=await this.getBoundingRectAsync(g);C||(C={originX:0,originY:0,width:I,height:T});let S=Math.max(C==null?void 0:C.width,I),N=Math.max(C==null?void 0:C.height,T),x=1;const L=S>I&&Math.min(I/S,x)||x,b=N>T&&Math.min(T/N,x)||x;L<=b?(S=L<1&&I||S,N=Math.floor(N*L)+1,x=L):L>b&&(N=b<1&&T||N,S=Math.floor(S*b)+1,x=b);const E={scale:x,centerX:C.originX+C.width/2,centerY:C.originY+C.height/2},A=document.createElement("canvas"),P=A.getContext("2d");A.width=S,A.height=N,P&&await this.screenshotToCanvasAsync(P,g,S,N,E,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")&&$.isRoom(e)&&e.isWritable?Be.InternalMsgEmitter.on(g,p):i.call(e.callbacks,g,p)},_callbacksOnce:function(g,p){W.logger.info(`[ApplianceSinglePlugin] callbacks ${g}`),(g==="onCanUndoStepsUpdate"||g==="onCanRedoStepsUpdate")&&$.isRoom(e)&&e.isWritable?Be.InternalMsgEmitter.on(g,p):n.call(e.callbacks,g,p)},_callbacksOff:function(g,p){W.logger.info(`[ApplianceSinglePlugin] callbacks ${g}`),(g==="onCanUndoStepsUpdate"||g==="onCanRedoStepsUpdate")&&$.isRoom(e)&&e.isWritable?Be.InternalMsgEmitter.off(g,p):o.call(e.callbacks,g,p)},canRedoSteps(){if(W.logger.info("[ApplianceSinglePlugin] canRedoSteps"),W.currentManager&&$.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&&$.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&&$.isRoom(e)&&!e.disableSerialization?W.currentManager.viewContainerManager.undo():0},redo:function(){return W.logger.info("[ApplianceSinglePlugin] redo"),W.currentManager&&$.isRoom(e)&&!e.disableSerialization?W.currentManager.viewContainerManager.redo():0},cleanCurrentScene:function(g){W.logger.info("[ApplianceSinglePlugin] cleanCurrentScene"),W.currentManager&&$.isRoom(e)&&e.isWritable&&(W.currentManager.cleanCurrentScene(),a.call(e,g))},insertImage:function(g){W.logger.info("[ApplianceSinglePlugin] insertImage"),W.currentManager&&$.isRoom(e)&&e.isWritable&&W.currentManager.worker.insertImage(ge,g)},lockImage:function(g,p){W.logger.info("[ApplianceSinglePlugin] lockImage"),W.currentManager&&$.isRoom(e)&&e.isWritable&&W.currentManager.worker.lockImage(ge,g,p)},completeImageUpload:function(g,p){W.logger.info("[ApplianceSinglePlugin] completeImageUpload"),W.currentManager&&$.isRoom(e)&&e.isWritable&&W.currentManager.worker.completeImageUpload(ge,g,p)},getImagesInformation:function(g){return W.logger.info("[ApplianceSinglePlugin] completeImageUpload"),W.currentManager&&$.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($.isRoom(e)&&e.isWritable){p.includes("currentApplianceName")&&(g.currentApplianceName&&g.currentApplianceName===oe.laserPen?(g.currentApplianceName=oe.pencil,g.useLaserPen=!0):g.currentApplianceName&&g.currentApplianceName===oe.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&&$.isRoom(e)&&e.isWritable)return W.currentManager.createMiniMap(g,p)},destroyMiniMap:async function(g){if(W.logger.info("[ApplianceMultiPlugin] destroyeMiniMap"),W.currentManager&&$.isRoom(e)&&e.isWritable)return W.currentManager.destroyMiniMap(g)},filterRenderByUid(g,p,f){if(W.logger.info("[ApplianceSinglePlugin] filterRenderByUid"),W.currentManager&&$.isRoom(e)&&e.isWritable)return W.currentManager.filterRenderByUid(g,p,f)},cancelFilterRender(g,p){if(W.logger.info("[ApplianceSinglePlugin] filterRenderByUid"),W.currentManager&&$.isRoom(e)&&e.isWritable)return W.currentManager.cancelFilterRender(g,p)},addListener:(g,p)=>{W.logger.info(`[ApplianceSinglePlugin] addListener ${g}`),Be.PublicMsgEmitter.on(g,p)},removeListener:(g,p)=>{W.logger.info(`[ApplianceSinglePlugin] removeListener ${g}`),Be.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&&$.isRoom(e))return W.currentManager.disableDeviceInputs},setDisableDeviceInputs(g){W.logger.info(`[ApplianceSinglePlugin] setDisableDeviceInputs ${g}`),W.currentManager&&$.isRoom(e)&&(W.currentManager.disableDeviceInputs=g)},getDisableCameraTransform(){if(W.currentManager&&$.isRoom(e))return W.currentManager.disableCameraTransform},setDisableCameraTransform(g){W.logger.info(`[ApplianceSinglePlugin] setDisableCameraTransform ${g}`),W.currentManager&&$.isRoom(e)&&(W.currentManager.disableCameraTransform=g)},getDisableEraseImage(){if(W.currentManager&&$.isRoom(e))return W.currentManager.disableEraseImage},setDisableEraseImage(g){W.logger.info(`[ApplianceSinglePlugin] setDisableEraseImage ${g}`),W.currentManager&&$.isRoom(e)&&(W.currentManager.disableEraseImage=g)},setWritable:async function(g){var p;W.logger.info(`[ApplianceSinglePlugin] setWritable ${g}`),$.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 T;const C=S=>{try{g({didTimeout:S,timeRemaining:()=>{const x=performance.now()-m;return Math.max(0,f-x)}})}catch(N){W.logger.error("[ApplianceSinglePlugin] requestIdleCallback error:",N)}finally{I.port1.close(),I.port2.close(),w!==void 0&&cancelAnimationFrame(w),T!==void 0&&clearTimeout(T)}};return I.port1.onmessage=()=>{w=requestAnimationFrame(()=>{f>0&&performance.now()-m>=f?C(!0):C(!1)})},I.port2.postMessage(null),f>0&&(T=setTimeout(()=>{C(!0)},f)),T||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"),$.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===oe.pencil||i.appliance===oe.shape||i.appliance===oe.text||i.appliance===oe.arrow||i.appliance===oe.straight||i.appliance===oe.rectangle||i.appliance===oe.ellipse||i.appliance===oe.eraser||i.appliance===oe.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 $.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),$.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 Be(o);if(n.init(),W.logger.info("[ApplianceSinglePlugin] refresh ApplianceSingleManager object"),W.currentManager=n,$.isRoom(e)){const a=n.hasOffscreenCanvas();e.logger.info(`[ApplianceSinglePlugin] use ${a?"worker":"mainThread"}`)}});let Qs=W;const Dt=class Dt extends y.Component{constructor(){super(...arguments);M(this,"mainViewRef",null)}componentDidMount(){Dt.emiter||(Dt.emiter=Be.InternalMsgEmitter),Dt.emiter.emit(se.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(Dt,"emiter");let Vs=Dt;class Sw extends un{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",ge);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===v.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)===v.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=he(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)===v.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=co;exports.ApplianceMultiPlugin=Fs;exports.ApplianceNames=oe;exports.ApplianceSigleWrapper=Vs;exports.ApplianceSinglePlugin=Qs;exports.AutoDrawPlugin=Sw;exports.Cursor_Hover_Id=uf;exports.DefaultAppliancePluginOptions=Ie;exports.ECanvasShowType=ye;exports.EDataType=B;exports.EForceStopReason=ds;exports.EImageType=Mt;exports.EMatrixrRelationType=ft;exports.EOperationType=je;exports.EPostMessageType=D;exports.ERenderFilterType=He;exports.EScaleType=re;exports.EStrokeType=te;exports.EToolsKey=v;exports.ElayerType=Ft;exports.EmitEventType=Q;exports.EventMessageType=Bt;exports.EvevtWorkState=j;exports.EvevtWorkType=lo;exports.InternalMsgEmitterType=se;exports.Main_View_Id=ge;exports.Plugin=un;exports.ShapeType=Ve;exports.Storage_Selector_key=H;exports.Storage_Splitter=Oe;exports.Storage_ViewId_ALL=Kt;exports.Task_Time_Interval=ai;exports.VNodeManager=en;exports.ViewContainerManager=Lt;exports.computRect=he;exports.fullWorker=wn;exports.getRectMatrixrRelation=ui;exports.getShapeInstance=vs;exports.isEqual=tt;exports.isIntersectForPoint=cn;exports.isNumber=De;exports.removeAllChildren=Pe;exports.removeTexture=Re;exports.subWorker=In;exports.transformToNormalData=wt;exports.transformToSerializableData=We;