@netless/appliance-plugin 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cdn/cdn.js +1 -1
- package/cdn/{fullWorker-CnB3KR.js → fullWorker-gIfxem.js} +111 -111
- package/cdn/{subWorker-1E_izA.js → subWorker-BA8EkW.js} +111 -111
- package/dist/appliance-plugin.js +1 -1
- package/dist/appliance-plugin.mjs +1 -1
- package/dist/core/mainEngine.d.ts +8 -0
- package/dist/core/mainThread/subLocalThread.d.ts +1 -2
- package/dist/core/tools/arrow.d.ts +1 -1
- package/dist/core/tools/ellipse.d.ts +1 -1
- package/dist/core/tools/pencil.d.ts +1 -1
- package/dist/core/tools/polygon.d.ts +1 -1
- package/dist/core/tools/rectangle.d.ts +1 -1
- package/dist/core/tools/speechBalloon.d.ts +1 -1
- package/dist/core/tools/star.d.ts +1 -1
- package/dist/core/tools/straight.d.ts +1 -1
- package/dist/core/types.d.ts +4 -0
- package/dist/core/vNodeManager.d.ts +5 -1
- package/dist/core/worker/fullWorkerLocal.d.ts +1 -0
- package/dist/fullWorker.js +111 -111
- package/dist/{index-Bd_LdZxD.mjs → index-0fBM84zK.mjs} +1987 -1914
- package/dist/{index-Db4VURLT.mjs → index-BbDR836g.mjs} +644 -618
- package/dist/index-BwLQzsnp.js +1 -0
- package/dist/index-Wi09G9p1.js +1 -0
- package/dist/plugin/baseApplianceManager.d.ts +3 -0
- package/dist/plugin/types.d.ts +2 -1
- package/dist/subWorker.js +111 -111
- package/package.json +1 -1
- package/dist/index-8E5yX5Xn.js +0 -1
- package/dist/index-qS7tU8QD.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var on=Object.defineProperty;var sn=(a,o,e)=>o in a?on(a,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[o]=e;var g=(a,o,e)=>sn(a,typeof o!="symbol"?o+"":o,e);const _=require("white-web-sdk"),he=require("spritejs"),Ji=require("lz-string"),Wo=require("lineclip"),Co=require("eventemitter2"),D=require("lodash"),M=require("react"),ro=require("react-dom"),Nt=require("react-draggable"),nn=require("re-resizable"),rn="/fullWorker.js",an="/subWorker.js";var se=(a=>(a.selector="selector",a.clicker="clicker",a.laserPointer="laserPointer",a.pencil="pencil",a.rectangle="rectangle",a.ellipse="ellipse",a.shape="shape",a.eraser="eraser",a.pencilEraser="pencilEraser",a.text="text",a.straight="straight",a.arrow="arrow",a.hand="hand",a.laserPen="laserPen",a))(se||{}),oe=(a=>(a.Normal="Normal",a.Stroke="Stroke",a.Dotted="Dotted",a.LongDotted="LongDotted",a))(oe||{}),$e=(a=>(a.Triangle="triangle",a.Rhombus="rhombus",a.Pentagram="pentagram",a.SpeechBalloon="speechBalloon",a.Star="star",a.Polygon="polygon",a))($e||{}),Y=(a=>(a.None="None",a.ShowFloatBar="ShowFloatBar",a.ZIndexFloatBar="ZIndexFloatBar",a.DeleteNode="DeleteNode",a.CopyNode="CopyNode",a.ZIndexActive="ZIndexActive",a.ZIndexNode="ZIndexNode",a.RotateNode="RotateNode",a.SetColorNode="SetColorNode",a.TranslateNode="TranslateNode",a.ScaleNode="ScaleNode",a.OriginalEvent="OriginalEvent",a.CreateScene="CreateScene",a.ActiveCursor="ActiveCursor",a.MoveCursor="MoveCursor",a.CommandEditor="CommandEditor",a.SetEditorData="SetEditorData",a.SetFontStyle="SetFontStyle",a.SetPoint="SetPoint",a.SetLock="SetLock",a.SetShapeOpt="SetShapeOpt",a.CameraChange="CameraChange",a.ActiveMethod="ActiveMethod",a))(Y||{}),q=(a=>(a.DisplayState="DisplayState",a.MainEngine="MainEngine",a.Cursor="Cursor",a.BindMainView="BindMainView",a))(q||{}),Ki=(a=>(a[a.MainView=0]="MainView",a[a.Plugin=1]="Plugin",a[a.Both=2]="Both",a))(Ki||{}),k=(a=>(a[a.Pencil=1]="Pencil",a[a.Eraser=2]="Eraser",a[a.PencilEraser=3]="PencilEraser",a[a.BitMapEraser=4]="BitMapEraser",a[a.Selector=5]="Selector",a[a.Clicker=6]="Clicker",a[a.Arrow=7]="Arrow",a[a.Hand=8]="Hand",a[a.LaserPen=9]="LaserPen",a[a.Text=10]="Text",a[a.Straight=11]="Straight",a[a.Rectangle=12]="Rectangle",a[a.Ellipse=13]="Ellipse",a[a.Star=14]="Star",a[a.Triangle=15]="Triangle",a[a.Rhombus=16]="Rhombus",a[a.Polygon=17]="Polygon",a[a.SpeechBalloon=18]="SpeechBalloon",a[a.Image=19]="Image",a))(k||{}),F=(a=>(a[a.Local=1]="Local",a[a.Service=2]="Service",a[a.Worker=3]="Worker",a))(F||{}),P=(a=>(a[a.Pending=0]="Pending",a[a.Start=1]="Start",a[a.Doing=2]="Doing",a[a.Done=3]="Done",a[a.Unwritable=4]="Unwritable",a))(P||{}),x=(a=>(a[a.None=0]="None",a[a.Init=1]="Init",a[a.UpdateCamera=2]="UpdateCamera",a[a.UpdateTools=3]="UpdateTools",a[a.CreateWork=4]="CreateWork",a[a.DrawWork=5]="DrawWork",a[a.FullWork=6]="FullWork",a[a.UpdateNode=7]="UpdateNode",a[a.RemoveNode=8]="RemoveNode",a[a.Clear=9]="Clear",a[a.Select=10]="Select",a[a.Destroy=11]="Destroy",a[a.Snapshot=12]="Snapshot",a[a.BoundingBox=13]="BoundingBox",a[a.Cursor=14]="Cursor",a[a.TextUpdate=15]="TextUpdate",a[a.GetTextActive=16]="GetTextActive",a[a.TasksQueue=17]="TasksQueue",a[a.CursorHover=18]="CursorHover",a[a.CursorBlur=19]="CursorBlur",a[a.Console=20]="Console",a[a.PriorityWorker=21]="PriorityWorker",a[a.PriorityMainThreadWorker=22]="PriorityMainThreadWorker",a[a.GetImageBitMap=23]="GetImageBitMap",a[a.AuthWriter=24]="AuthWriter",a[a.AuthReader=25]="AuthReader",a[a.AuthClear=26]="AuthClear",a[a.AuthPage=27]="AuthPage",a[a.GetVNodeInfo=28]="GetVNodeInfo",a[a.UpdateDpr=29]="UpdateDpr",a))(x||{}),ye=(a=>(a[a.None=0]="None",a[a.Bg=1]="Bg",a[a.ServiceFloat=2]="ServiceFloat",a[a.Float=3]="Float",a[a.TopFloat=4]="TopFloat",a))(ye||{}),At=(a=>(a[a.Cursor=1]="Cursor",a[a.TextCreate=2]="TextCreate",a))(At||{}),lt=(a=>(a[a.Top=1]="Top",a[a.Bottom=2]="Bottom",a))(lt||{}),re=(a=>(a[a.none=1]="none",a[a.all=2]="all",a[a.both=3]="both",a[a.proportional=4]="proportional",a))(re||{}),_i=(a=>(a[a.Pending=0]="Pending",a[a.Start=1]="Start",a[a.Doing=2]="Doing",a[a.Done=3]="Done",a[a.Unwritable=4]="Unwritable",a))(_i||{}),jt=(a=>(a[a.inside=0]="inside",a[a.outside=1]="outside",a[a.intersect=2]="intersect",a))(jt||{}),Pe=(a=>(a.renderPage="renderPage",a.addPage="addPage",a.deletePage="deletePage",a.addElement="addElement",a.deleteElement="deleteElement",a.clearPage="clearPage",a.clearViewScenePath="clearViewScenePath",a.clearView="clearView",a))(Pe||{}),Qe=(a=>(a.setAuth="setAuth",a.setShow="addShow",a.setHide="setHide",a.setClear="setClear",a))(Qe||{}),ht=(a=>(a.Image="image",a.Iconify="iconify",a))(ht||{});const cn={linear:a=>a,easeInQuad:a=>a*a,easeOutQuad:a=>a*(2-a),easeInOutQuad:a=>a<.5?2*a*a:-1+(4-2*a)*a,easeInCubic:a=>a*a*a,easeOutCubic:a=>--a*a*a+1,easeInOutCubic:a=>a<.5?4*a*a*a:(a-1)*(2*a-2)*(2*a-2)+1,easeInQuart:a=>a*a*a*a,easeOutQuart:a=>1- --a*a*a*a,easeInOutQuart:a=>a<.5?8*a*a*a*a:1-8*--a*a*a*a,easeInQuint:a=>a*a*a*a*a,easeOutQuint:a=>1+--a*a*a*a*a,easeInOutQuint:a=>a<.5?16*a*a*a*a*a:1+16*--a*a*a*a*a,easeInSine:a=>1-Math.cos(a*Math.PI/2),easeOutSine:a=>Math.sin(a*Math.PI/2),easeInOutSine:a=>-(Math.cos(Math.PI*a)-1)/2,easeInExpo:a=>a<=0?0:Math.pow(2,10*a-10),easeOutExpo:a=>a>=1?1:1-Math.pow(2,-10*a),easeInOutExpo:a=>a<=0?0:a>=1?1:a<.5?Math.pow(2,20*a-10)/2:(2-Math.pow(2,-20*a+10))/2};class C{constructor(o=0,e=0,t=1){this.x=o,this.y=e,this.z=t}get XY(){return[this.x,this.y]}setz(o){return this.z=o,this}setXY(o=this.x,e=this.y){return this.x=o,this.y=e,this}set(o=this.x,e=this.y,t=this.z){return this.x=o,this.y=e,this.z=t,this}setTo({x:o=0,y:e=0,z:t=1}){return this.x=o,this.y=e,this.z=t,this}rot(o){if(o===0)return this;const{x:e,y:t}=this,i=Math.sin(o),s=Math.cos(o);return this.x=e*s-t*i,this.y=e*i+t*s,this}rotWith(o,e){if(e===0)return this;const t=this.x-o.x,i=this.y-o.y,s=Math.sin(e),n=Math.cos(e);return this.x=o.x+(t*n-i*s),this.y=o.y+(t*s+i*n),this}clone(){const{x:o,y:e,z:t}=this;return new C(o,e,t)}sub(o){return this.x-=o.x,this.y-=o.y,this}subXY(o,e){return this.x-=o,this.y-=e,this}subScalar(o){return this.x-=o,this.y-=o,this}add(o){return this.x+=o.x,this.y+=o.y,this}addXY(o,e){return this.x+=o,this.y+=e,this}addScalar(o){return this.x+=o,this.y+=o,this}clamp(o,e){return this.x=Math.max(this.x,o),this.y=Math.max(this.y,o),e!==void 0&&(this.x=Math.min(this.x,e),this.y=Math.min(this.y,e)),this}div(o){return this.x/=o,this.y/=o,this}divV(o){return this.x/=o.x,this.y/=o.y,this}mul(o){return this.x*=o,this.y*=o,this}mulV(o){return this.x*=o.x,this.y*=o.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(o,e){const t=C.Tan(o,this);return this.add(t.mul(e))}neg(){return this.x*=-1,this.y*=-1,this}cross(o){return this.x=this.y*o.z-this.z*o.y,this.y=this.z*o.x-this.x*o.z,this}dpr(o){return C.Dpr(this,o)}cpr(o){return C.Cpr(this,o)}len2(){return C.Len2(this)}len(){return C.Len(this)}pry(o){return C.Pry(this,o)}per(){const{x:o,y:e}=this;return this.x=e,this.y=-o,this}uni(){return C.Uni(this)}tan(o){return C.Tan(this,o)}dist(o){return C.Dist(this,o)}distanceToLineSegment(o,e){return C.DistanceToLineSegment(o,e,this)}slope(o){return C.Slope(this,o)}snapToGrid(o){return this.x=Math.round(this.x/o)*o,this.y=Math.round(this.y/o)*o,this}angle(o){return C.Angle(this,o)}toAngle(){return C.ToAngle(this)}lrp(o,e){return this.x=this.x+(o.x-this.x)*e,this.y=this.y+(o.y-this.y)*e,this}equals(o,e){return C.Equals(this,o,e)}equalsXY(o,e){return C.EqualsXY(this,o,e)}norm(){const o=this.len();return this.x=o===0?0:this.x/o,this.y=o===0?0:this.y/o,this}toFixed(){return C.ToFixed(this)}toString(){return C.ToString(C.ToFixed(this))}toJson(){return C.ToJson(this)}toArray(){return C.ToArray(this)}static Add(o,e){return new C(o.x+e.x,o.y+e.y)}static AddXY(o,e,t){return new C(o.x+e,o.y+t)}static Sub(o,e){return new C(o.x-e.x,o.y-e.y)}static SubXY(o,e,t){return new C(o.x-e,o.y-t)}static AddScalar(o,e){return new C(o.x+e,o.y+e)}static SubScalar(o,e){return new C(o.x-e,o.y-e)}static Div(o,e){return new C(o.x/e,o.y/e)}static Mul(o,e){return new C(o.x*e,o.y*e)}static DivV(o,e){return new C(o.x/e.x,o.y/e.y)}static MulV(o,e){return new C(o.x*e.x,o.y*e.y)}static Neg(o){return new C(-o.x,-o.y)}static Per(o){return new C(o.y,-o.x)}static Dist2(o,e){return C.Sub(o,e).len2()}static Abs(o){return new C(Math.abs(o.x),Math.abs(o.y))}static Dist(o,e){return Math.hypot(o.y-e.y,o.x-e.x)}static Dpr(o,e){return o.x*e.x+o.y*e.y}static Cross(o,e){return new C(o.y*e.z-o.z*e.y,o.z*e.x-o.x*e.z)}static Cpr(o,e){return o.x*e.y-e.x*o.y}static Len2(o){return o.x*o.x+o.y*o.y}static Len(o){return Math.hypot(o.x,o.y)}static Pry(o,e){return C.Dpr(o,e)/C.Len(e)}static Uni(o){return C.Div(o,C.Len(o))}static Tan(o,e){return C.Uni(C.Sub(o,e))}static Min(o,e){return new C(Math.min(o.x,e.x),Math.min(o.y,e.y))}static Max(o,e){return new C(Math.max(o.x,e.x),Math.max(o.y,e.y))}static From(o){return new C().add(o)}static FromArray(o){return new C(o[0],o[1])}static Rot(o,e=0){const t=Math.sin(e),i=Math.cos(e);return new C(o.x*i-o.y*t,o.x*t+o.y*i)}static RotWith(o,e,t){const i=o.x-e.x,s=o.y-e.y,n=Math.sin(t),r=Math.cos(t);return new C(e.x+(i*r-s*n),e.y+(i*n+s*r))}static NearestPointOnLineThroughPoint(o,e,t){return C.Mul(e,C.Sub(t,o).pry(e)).add(o)}static NearestPointOnLineSegment(o,e,t,i=!0){const s=C.Tan(e,o),n=C.Add(o,C.Mul(s,C.Sub(t,o).pry(s)));if(i){if(n.x<Math.min(o.x,e.x))return C.Cast(o.x<e.x?o:e);if(n.x>Math.max(o.x,e.x))return C.Cast(o.x>e.x?o:e);if(n.y<Math.min(o.y,e.y))return C.Cast(o.y<e.y?o:e);if(n.y>Math.max(o.y,e.y))return C.Cast(o.y>e.y?o:e)}return n}static DistanceToLineThroughPoint(o,e,t){return C.Dist(t,C.NearestPointOnLineThroughPoint(o,e,t))}static DistanceToLineSegment(o,e,t,i=!0){return C.Dist(t,C.NearestPointOnLineSegment(o,e,t,i))}static Snap(o,e=1){return new C(Math.round(o.x/e)*e,Math.round(o.y/e)*e)}static Cast(o){return o instanceof C?o:C.From(o)}static Slope(o,e){return o.x===e.y?NaN:(o.y-e.y)/(o.x-e.x)}static Angle(o,e){return Math.atan2(e.y-o.y,e.x-o.x)}static Lrp(o,e,t){return C.Sub(e,o).mul(t).add(o)}static Med(o,e){return new C((o.x+e.x)/2,(o.y+e.y)/2)}static Equals(o,e,t=1e-4){return Math.abs(o.x-e.x)<t&&Math.abs(o.y-e.y)<t}static EqualsXY(o,e,t){return o.x===e&&o.y===t}static EqualsXYZ(o,e,t=1e-4){return C.Equals(o,e,t)&&Math.abs((o.z||0)-(e.z||0))<t}static Clockwise(o,e,t){return(t.x-o.x)*(e.y-o.y)-(e.x-o.x)*(t.y-o.y)<0}static Rescale(o,e){const t=C.Len(o);return new C(e*o.x/t,e*o.y/t)}static ScaleWithOrigin(o,e,t){return C.Sub(o,t).mul(e).add(t)}static ScaleWOrigin(o,e,t){return C.Sub(o,t).mulV(e).add(t)}static ToFixed(o,e=2){return new C(+o.x.toFixed(e),+o.y.toFixed(e),+o.z.toFixed(e))}static Nudge(o,e,t){return C.Add(o,C.Tan(e,o).mul(t))}static ToString(o){return`${o.x}, ${o.y}`}static ToAngle(o){let e=Math.atan2(o.y,o.x);return e<0&&(e+=Math.PI*2),e}static FromAngle(o,e=1){return new C(Math.cos(o)*e,Math.sin(o)*e)}static ToArray(o){return[o.x,o.y,o.z]}static ToJson(o){const{x:e,y:t,z:i}=o;return{x:e,y:t,z:i}}static Average(o){const e=o.length,t=new C(0,0);for(let i=0;i<e;i++)t.add(o[i]);return t.div(e)}static Clamp(o,e,t){return t===void 0?new C(Math.min(Math.max(o.x,e)),Math.min(Math.max(o.y,e))):new C(Math.min(Math.max(o.x,e),t),Math.min(Math.max(o.y,e),t))}static PointsBetween(o,e,t=6){const i=[];for(let s=0;s<t;s++){const n=cn.easeInQuad(s/(t-1)),r=C.Lrp(o,e,n);r.z=Math.min(1,.5+Math.abs(.5-ln(n))*.65),i.push(r)}return i}static SnapToGrid(o,e=8){return new C(Math.round(o.x/e)*e,Math.round(o.y/e)*e)}}const ln=a=>a<.5?2*a*a:-1+(4-2*a)*a;class V extends C{constructor(o=0,e=0,t=0,i={x:0,y:0},s=0,n=0){super(o,e,t),this.x=o,this.y=e,this.z=t,this.v=i,this.t=s,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(o){this.a=o}setT(o){this.t=o}setv(o){return this.v={x:o.x,y:o.y},this}set(o=this.x,e=this.y,t=this.z,i=this.v,s=this.t,n=this.a){return this.x=o,this.y=e,this.z=t,this.v=i,this.t=s,this.a=n,this}clone(){const{x:o,y:e,z:t,v:i,t:s,a:n}=this,r={x:i.x,y:i.y};return new V(o,e,t,r,s,n)}distance(o){return V.GetDistance(this,o)}isNear(o,e){return V.IsNear(this,o,e)}getAngleByPoints(o,e){return V.GetAngleByPoints(o,this,e)}static Sub(o,e){return new V(o.x-e.x,o.y-e.y)}static Add(o,e){return new V(o.x+e.x,o.y+e.y)}static GetDistance(o,e){return V.Len(o.clone().sub(e))}static GetAngleByPoints(o,e,t){const i=e.x-o.x,s=t.x-e.x,n=e.y-o.y,r=t.y-e.y;let c=0;const l=Math.sqrt(i*i+n*n),h=Math.sqrt(s*s+r*r);if(l&&h){const u=i*s+n*r;c=Math.acos(u/(l*h)),c=c/Math.PI*180;let d=i*r-n*s;d=d>0?1:-1,c=180+d*c}return c}static IsNear(o,e,t){return V.Len(o.clone().sub(e))<t}static RotWith(o,e,t,i=2){const s=o.x-e.x,n=o.y-e.y,r=Math.sin(t),c=Math.cos(t),l=Math.pow(10,i),h=Math.floor((e.x+(s*c-n*r))*l)/l,u=Math.floor((e.y+(s*r+n*c))*l)/l;return new V(h,u)}static GetDotStroke(o,e,t=16){const i=new C(1,1),s=Math.PI+.001,n=V.Add(o,V.Sub(o,i).uni().per().mul(-e)),r=[];for(let c=1/t,l=c;l<=1;l+=c)r.push(V.RotWith(n,o,s*2*l));return r}static GetSemicircleStroke(o,e,t=-1,i=8){const s=t*(Math.PI+.001),n=[];for(let r=1/i,c=r;c<=1;c+=r)n.push(V.RotWith(e,o,s*c));return n}}var Ft=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function St(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}var hn=typeof Ft=="object"&&Ft&&Ft.Object===Object&&Ft,es=hn,un=es,dn=typeof self=="object"&&self&&self.Object===Object&&self,pn=un||dn||Function("return this")(),Ge=pn,fn=Ge,gn=fn.Symbol,Wt=gn,ni=Wt,ts=Object.prototype,yn=ts.hasOwnProperty,Mn=ts.toString,zt=ni?ni.toStringTag:void 0;function mn(a){var o=yn.call(a,zt),e=a[zt];try{a[zt]=void 0;var t=!0}catch{}var i=Mn.call(a);return t&&(o?a[zt]=e:delete a[zt]),i}var wn=mn,vn=Object.prototype,In=vn.toString;function Nn(a){return In.call(a)}var Sn=Nn,ri=Wt,Tn=wn,kn=Sn,Cn="[object Null]",bn="[object Undefined]",ai=ri?ri.toStringTag:void 0;function xn(a){return a==null?a===void 0?bn:Cn:ai&&ai in Object(a)?Tn(a):kn(a)}var ut=xn;function Ln(a){return a!=null&&typeof a=="object"}var qe=Ln,zn=ut,Pn=qe,Dn="[object Number]";function An(a){return typeof a=="number"||Pn(a)&&zn(a)==Dn}var jn=An;const Oe=St(jn);function En(){this.__data__=[],this.size=0}var On=En;function Rn(a,o){return a===o||a!==a&&o!==o}var Uo=Rn,Yn=Uo;function Wn(a,o){for(var e=a.length;e--;)if(Yn(a[e][0],o))return e;return-1}var ao=Wn,Un=ao,Bn=Array.prototype,Fn=Bn.splice;function Vn(a){var o=this.__data__,e=Un(o,a);if(e<0)return!1;var t=o.length-1;return e==t?o.pop():Fn.call(o,e,1),--this.size,!0}var $n=Vn,Hn=ao;function Qn(a){var o=this.__data__,e=Hn(o,a);return e<0?void 0:o[e][1]}var Gn=Qn,Zn=ao;function qn(a){return Zn(this.__data__,a)>-1}var Xn=qn,Jn=ao;function Kn(a,o){var e=this.__data__,t=Jn(e,a);return t<0?(++this.size,e.push([a,o])):e[t][1]=o,this}var _n=Kn,er=On,tr=$n,or=Gn,ir=Xn,sr=_n;function Tt(a){var o=-1,e=a==null?0:a.length;for(this.clear();++o<e;){var t=a[o];this.set(t[0],t[1])}}Tt.prototype.clear=er;Tt.prototype.delete=tr;Tt.prototype.get=or;Tt.prototype.has=ir;Tt.prototype.set=sr;var co=Tt,nr=co;function rr(){this.__data__=new nr,this.size=0}var ar=rr;function cr(a){var o=this.__data__,e=o.delete(a);return this.size=o.size,e}var lr=cr;function hr(a){return this.__data__.get(a)}var ur=hr;function dr(a){return this.__data__.has(a)}var pr=dr;function fr(a){var o=typeof a;return a!=null&&(o=="object"||o=="function")}var ot=fr,gr=ut,yr=ot,Mr="[object AsyncFunction]",mr="[object Function]",wr="[object GeneratorFunction]",vr="[object Proxy]";function Ir(a){if(!yr(a))return!1;var o=gr(a);return o==mr||o==wr||o==Mr||o==vr}var os=Ir,Nr=Ge,Sr=Nr["__core-js_shared__"],Tr=Sr,vo=Tr,ci=function(){var a=/[^.]+$/.exec(vo&&vo.keys&&vo.keys.IE_PROTO||"");return a?"Symbol(src)_1."+a:""}();function kr(a){return!!ci&&ci in a}var Cr=kr,br=Function.prototype,xr=br.toString;function Lr(a){if(a!=null){try{return xr.call(a)}catch{}try{return a+""}catch{}}return""}var is=Lr,zr=os,Pr=Cr,Dr=ot,Ar=is,jr=/[\\^$.*+?()[\]{}|]/g,Er=/^\[object .+?Constructor\]$/,Or=Function.prototype,Rr=Object.prototype,Yr=Or.toString,Wr=Rr.hasOwnProperty,Ur=RegExp("^"+Yr.call(Wr).replace(jr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Br(a){if(!Dr(a)||Pr(a))return!1;var o=zr(a)?Ur:Er;return o.test(Ar(a))}var Fr=Br;function Vr(a,o){return a==null?void 0:a[o]}var $r=Vr,Hr=Fr,Qr=$r;function Gr(a,o){var e=Qr(a,o);return Hr(e)?e:void 0}var dt=Gr,Zr=dt,qr=Ge,Xr=Zr(qr,"Map"),Bo=Xr,Jr=dt,Kr=Jr(Object,"create"),lo=Kr,li=lo;function _r(){this.__data__=li?li(null):{},this.size=0}var ea=_r;function ta(a){var o=this.has(a)&&delete this.__data__[a];return this.size-=o?1:0,o}var oa=ta,ia=lo,sa="__lodash_hash_undefined__",na=Object.prototype,ra=na.hasOwnProperty;function aa(a){var o=this.__data__;if(ia){var e=o[a];return e===sa?void 0:e}return ra.call(o,a)?o[a]:void 0}var ca=aa,la=lo,ha=Object.prototype,ua=ha.hasOwnProperty;function da(a){var o=this.__data__;return la?o[a]!==void 0:ua.call(o,a)}var pa=da,fa=lo,ga="__lodash_hash_undefined__";function ya(a,o){var e=this.__data__;return this.size+=this.has(a)?0:1,e[a]=fa&&o===void 0?ga:o,this}var Ma=ya,ma=ea,wa=oa,va=ca,Ia=pa,Na=Ma;function kt(a){var o=-1,e=a==null?0:a.length;for(this.clear();++o<e;){var t=a[o];this.set(t[0],t[1])}}kt.prototype.clear=ma;kt.prototype.delete=wa;kt.prototype.get=va;kt.prototype.has=Ia;kt.prototype.set=Na;var Sa=kt,hi=Sa,Ta=co,ka=Bo;function Ca(){this.size=0,this.__data__={hash:new hi,map:new(ka||Ta),string:new hi}}var ba=Ca;function xa(a){var o=typeof a;return o=="string"||o=="number"||o=="symbol"||o=="boolean"?a!=="__proto__":a===null}var La=xa,za=La;function Pa(a,o){var e=a.__data__;return za(o)?e[typeof o=="string"?"string":"hash"]:e.map}var ho=Pa,Da=ho;function Aa(a){var o=Da(this,a).delete(a);return this.size-=o?1:0,o}var ja=Aa,Ea=ho;function Oa(a){return Ea(this,a).get(a)}var Ra=Oa,Ya=ho;function Wa(a){return Ya(this,a).has(a)}var Ua=Wa,Ba=ho;function Fa(a,o){var e=Ba(this,a),t=e.size;return e.set(a,o),this.size+=e.size==t?0:1,this}var Va=Fa,$a=ba,Ha=ja,Qa=Ra,Ga=Ua,Za=Va;function Ct(a){var o=-1,e=a==null?0:a.length;for(this.clear();++o<e;){var t=a[o];this.set(t[0],t[1])}}Ct.prototype.clear=$a;Ct.prototype.delete=Ha;Ct.prototype.get=Qa;Ct.prototype.has=Ga;Ct.prototype.set=Za;var ss=Ct,qa=co,Xa=Bo,Ja=ss,Ka=200;function _a(a,o){var e=this.__data__;if(e instanceof qa){var t=e.__data__;if(!Xa||t.length<Ka-1)return t.push([a,o]),this.size=++e.size,this;e=this.__data__=new Ja(t)}return e.set(a,o),this.size=e.size,this}var ec=_a,tc=co,oc=ar,ic=lr,sc=ur,nc=pr,rc=ec;function bt(a){var o=this.__data__=new tc(a);this.size=o.size}bt.prototype.clear=oc;bt.prototype.delete=ic;bt.prototype.get=sc;bt.prototype.has=nc;bt.prototype.set=rc;var ns=bt;function ac(a,o){for(var e=-1,t=a==null?0:a.length;++e<t&&o(a[e],e,a)!==!1;);return a}var cc=ac,lc=dt,hc=function(){try{var a=lc(Object,"defineProperty");return a({},"",{}),a}catch{}}(),rs=hc,ui=rs;function uc(a,o,e){o=="__proto__"&&ui?ui(a,o,{configurable:!0,enumerable:!0,value:e,writable:!0}):a[o]=e}var as=uc,dc=as,pc=Uo,fc=Object.prototype,gc=fc.hasOwnProperty;function yc(a,o,e){var t=a[o];(!(gc.call(a,o)&&pc(t,e))||e===void 0&&!(o in a))&&dc(a,o,e)}var cs=yc,Mc=cs,mc=as;function wc(a,o,e,t){var i=!e;e||(e={});for(var s=-1,n=o.length;++s<n;){var r=o[s],c=t?t(e[r],a[r],r,e,a):void 0;c===void 0&&(c=a[r]),i?mc(e,r,c):Mc(e,r,c)}return e}var uo=wc;function vc(a,o){for(var e=-1,t=Array(a);++e<a;)t[e]=o(e);return t}var Ic=vc,Nc=ut,Sc=qe,Tc="[object Arguments]";function kc(a){return Sc(a)&&Nc(a)==Tc}var Cc=kc,di=Cc,bc=qe,ls=Object.prototype,xc=ls.hasOwnProperty,Lc=ls.propertyIsEnumerable,zc=di(function(){return arguments}())?di:function(a){return bc(a)&&xc.call(a,"callee")&&!Lc.call(a,"callee")},hs=zc,Pc=Array.isArray,Ut=Pc,Zt={exports:{}};function Dc(){return!1}var Ac=Dc;Zt.exports;(function(a,o){var e=Ge,t=Ac,i=o&&!o.nodeType&&o,s=i&&!0&&a&&!a.nodeType&&a,n=s&&s.exports===i,r=n?e.Buffer:void 0,c=r?r.isBuffer:void 0,l=c||t;a.exports=l})(Zt,Zt.exports);var Fo=Zt.exports,jc=9007199254740991,Ec=/^(?:0|[1-9]\d*)$/;function Oc(a,o){var e=typeof a;return o=o??jc,!!o&&(e=="number"||e!="symbol"&&Ec.test(a))&&a>-1&&a%1==0&&a<o}var Rc=Oc,Yc=9007199254740991;function Wc(a){return typeof a=="number"&&a>-1&&a%1==0&&a<=Yc}var us=Wc,Uc=ut,Bc=us,Fc=qe,Vc="[object Arguments]",$c="[object Array]",Hc="[object Boolean]",Qc="[object Date]",Gc="[object Error]",Zc="[object Function]",qc="[object Map]",Xc="[object Number]",Jc="[object Object]",Kc="[object RegExp]",_c="[object Set]",el="[object String]",tl="[object WeakMap]",ol="[object ArrayBuffer]",il="[object DataView]",sl="[object Float32Array]",nl="[object Float64Array]",rl="[object Int8Array]",al="[object Int16Array]",cl="[object Int32Array]",ll="[object Uint8Array]",hl="[object Uint8ClampedArray]",ul="[object Uint16Array]",dl="[object Uint32Array]",Me={};Me[sl]=Me[nl]=Me[rl]=Me[al]=Me[cl]=Me[ll]=Me[hl]=Me[ul]=Me[dl]=!0;Me[Vc]=Me[$c]=Me[ol]=Me[Hc]=Me[il]=Me[Qc]=Me[Gc]=Me[Zc]=Me[qc]=Me[Xc]=Me[Jc]=Me[Kc]=Me[_c]=Me[el]=Me[tl]=!1;function pl(a){return Fc(a)&&Bc(a.length)&&!!Me[Uc(a)]}var fl=pl;function gl(a){return function(o){return a(o)}}var po=gl,qt={exports:{}};qt.exports;(function(a,o){var e=es,t=o&&!o.nodeType&&o,i=t&&!0&&a&&!a.nodeType&&a,s=i&&i.exports===t,n=s&&e.process,r=function(){try{var c=i&&i.require&&i.require("util").types;return c||n&&n.binding&&n.binding("util")}catch{}}();a.exports=r})(qt,qt.exports);var Vo=qt.exports,yl=fl,Ml=po,pi=Vo,fi=pi&&pi.isTypedArray,ml=fi?Ml(fi):yl,ds=ml,wl=Ic,vl=hs,Il=Ut,Nl=Fo,Sl=Rc,Tl=ds,kl=Object.prototype,Cl=kl.hasOwnProperty;function bl(a,o){var e=Il(a),t=!e&&vl(a),i=!e&&!t&&Nl(a),s=!e&&!t&&!i&&Tl(a),n=e||t||i||s,r=n?wl(a.length,String):[],c=r.length;for(var l in a)(o||Cl.call(a,l))&&!(n&&(l=="length"||i&&(l=="offset"||l=="parent")||s&&(l=="buffer"||l=="byteLength"||l=="byteOffset")||Sl(l,c)))&&r.push(l);return r}var ps=bl,xl=Object.prototype;function Ll(a){var o=a&&a.constructor,e=typeof o=="function"&&o.prototype||xl;return a===e}var $o=Ll;function zl(a,o){return function(e){return a(o(e))}}var fs=zl,Pl=fs,Dl=Pl(Object.keys,Object),Al=Dl,jl=$o,El=Al,Ol=Object.prototype,Rl=Ol.hasOwnProperty;function Yl(a){if(!jl(a))return El(a);var o=[];for(var e in Object(a))Rl.call(a,e)&&e!="constructor"&&o.push(e);return o}var Wl=Yl,Ul=os,Bl=us;function Fl(a){return a!=null&&Bl(a.length)&&!Ul(a)}var Ho=Fl,Vl=ps,$l=Wl,Hl=Ho;function Ql(a){return Hl(a)?Vl(a):$l(a)}var Qo=Ql,Gl=uo,Zl=Qo;function ql(a,o){return a&&Gl(o,Zl(o),a)}var Xl=ql;function Jl(a){var o=[];if(a!=null)for(var e in Object(a))o.push(e);return o}var Kl=Jl,_l=ot,eh=$o,th=Kl,oh=Object.prototype,ih=oh.hasOwnProperty;function sh(a){if(!_l(a))return th(a);var o=eh(a),e=[];for(var t in a)t=="constructor"&&(o||!ih.call(a,t))||e.push(t);return e}var nh=sh,rh=ps,ah=nh,ch=Ho;function lh(a){return ch(a)?rh(a,!0):ah(a)}var Go=lh,hh=uo,uh=Go;function dh(a,o){return a&&hh(o,uh(o),a)}var ph=dh,Xt={exports:{}};Xt.exports;(function(a,o){var e=Ge,t=o&&!o.nodeType&&o,i=t&&!0&&a&&!a.nodeType&&a,s=i&&i.exports===t,n=s?e.Buffer:void 0,r=n?n.allocUnsafe:void 0;function c(l,h){if(h)return l.slice();var u=l.length,d=r?r(u):new l.constructor(u);return l.copy(d),d}a.exports=c})(Xt,Xt.exports);var fh=Xt.exports;function gh(a,o){var e=-1,t=a.length;for(o||(o=Array(t));++e<t;)o[e]=a[e];return o}var yh=gh;function Mh(a,o){for(var e=-1,t=a==null?0:a.length,i=0,s=[];++e<t;){var n=a[e];o(n,e,a)&&(s[i++]=n)}return s}var gs=Mh;function mh(){return[]}var ys=mh,wh=gs,vh=ys,Ih=Object.prototype,Nh=Ih.propertyIsEnumerable,gi=Object.getOwnPropertySymbols,Sh=gi?function(a){return a==null?[]:(a=Object(a),wh(gi(a),function(o){return Nh.call(a,o)}))}:vh,Zo=Sh,Th=uo,kh=Zo;function Ch(a,o){return Th(a,kh(a),o)}var bh=Ch;function xh(a,o){for(var e=-1,t=o.length,i=a.length;++e<t;)a[i+e]=o[e];return a}var qo=xh,Lh=fs,zh=Lh(Object.getPrototypeOf,Object),Ms=zh,Ph=qo,Dh=Ms,Ah=Zo,jh=ys,Eh=Object.getOwnPropertySymbols,Oh=Eh?function(a){for(var o=[];a;)Ph(o,Ah(a)),a=Dh(a);return o}:jh,ms=Oh,Rh=uo,Yh=ms;function Wh(a,o){return Rh(a,Yh(a),o)}var Uh=Wh,Bh=qo,Fh=Ut;function Vh(a,o,e){var t=o(a);return Fh(a)?t:Bh(t,e(a))}var ws=Vh,$h=ws,Hh=Zo,Qh=Qo;function Gh(a){return $h(a,Qh,Hh)}var vs=Gh,Zh=ws,qh=ms,Xh=Go;function Jh(a){return Zh(a,Xh,qh)}var Kh=Jh,_h=dt,eu=Ge,tu=_h(eu,"DataView"),ou=tu,iu=dt,su=Ge,nu=iu(su,"Promise"),ru=nu,au=dt,cu=Ge,lu=au(cu,"Set"),Is=lu,hu=dt,uu=Ge,du=hu(uu,"WeakMap"),pu=du,bo=ou,xo=Bo,Lo=ru,zo=Is,Po=pu,Ns=ut,xt=is,yi="[object Map]",fu="[object Object]",Mi="[object Promise]",mi="[object Set]",wi="[object WeakMap]",vi="[object DataView]",gu=xt(bo),yu=xt(xo),Mu=xt(Lo),mu=xt(zo),wu=xt(Po),nt=Ns;(bo&&nt(new bo(new ArrayBuffer(1)))!=vi||xo&&nt(new xo)!=yi||Lo&&nt(Lo.resolve())!=Mi||zo&&nt(new zo)!=mi||Po&&nt(new Po)!=wi)&&(nt=function(a){var o=Ns(a),e=o==fu?a.constructor:void 0,t=e?xt(e):"";if(t)switch(t){case gu:return vi;case yu:return yi;case Mu:return Mi;case mu:return mi;case wu:return wi}return o});var fo=nt,vu=Object.prototype,Iu=vu.hasOwnProperty;function Nu(a){var o=a.length,e=new a.constructor(o);return o&&typeof a[0]=="string"&&Iu.call(a,"index")&&(e.index=a.index,e.input=a.input),e}var Su=Nu,Tu=Ge,ku=Tu.Uint8Array,Ss=ku,Ii=Ss;function Cu(a){var o=new a.constructor(a.byteLength);return new Ii(o).set(new Ii(a)),o}var Xo=Cu,bu=Xo;function xu(a,o){var e=o?bu(a.buffer):a.buffer;return new a.constructor(e,a.byteOffset,a.byteLength)}var Lu=xu,zu=/\w*$/;function Pu(a){var o=new a.constructor(a.source,zu.exec(a));return o.lastIndex=a.lastIndex,o}var Du=Pu,Ni=Wt,Si=Ni?Ni.prototype:void 0,Ti=Si?Si.valueOf:void 0;function Au(a){return Ti?Object(Ti.call(a)):{}}var ju=Au,Eu=Xo;function Ou(a,o){var e=o?Eu(a.buffer):a.buffer;return new a.constructor(e,a.byteOffset,a.length)}var Ru=Ou,Yu=Xo,Wu=Lu,Uu=Du,Bu=ju,Fu=Ru,Vu="[object Boolean]",$u="[object Date]",Hu="[object Map]",Qu="[object Number]",Gu="[object RegExp]",Zu="[object Set]",qu="[object String]",Xu="[object Symbol]",Ju="[object ArrayBuffer]",Ku="[object DataView]",_u="[object Float32Array]",ed="[object Float64Array]",td="[object Int8Array]",od="[object Int16Array]",id="[object Int32Array]",sd="[object Uint8Array]",nd="[object Uint8ClampedArray]",rd="[object Uint16Array]",ad="[object Uint32Array]";function cd(a,o,e){var t=a.constructor;switch(o){case Ju:return Yu(a);case Vu:case $u:return new t(+a);case Ku:return Wu(a,e);case _u:case ed:case td:case od:case id:case sd:case nd:case rd:case ad:return Fu(a,e);case Hu:return new t;case Qu:case qu:return new t(a);case Gu:return Uu(a);case Zu:return new t;case Xu:return Bu(a)}}var ld=cd,hd=ot,ki=Object.create,ud=function(){function a(){}return function(o){if(!hd(o))return{};if(ki)return ki(o);a.prototype=o;var e=new a;return a.prototype=void 0,e}}(),dd=ud,pd=dd,fd=Ms,gd=$o;function yd(a){return typeof a.constructor=="function"&&!gd(a)?pd(fd(a)):{}}var Md=yd,md=fo,wd=qe,vd="[object Map]";function Id(a){return wd(a)&&md(a)==vd}var Nd=Id,Sd=Nd,Td=po,Ci=Vo,bi=Ci&&Ci.isMap,kd=bi?Td(bi):Sd,Cd=kd,bd=fo,xd=qe,Ld="[object Set]";function zd(a){return xd(a)&&bd(a)==Ld}var Pd=zd,Dd=Pd,Ad=po,xi=Vo,Li=xi&&xi.isSet,jd=Li?Ad(Li):Dd,Ts=jd;const Ed=St(Ts);var Od=ns,Rd=cc,Yd=cs,Wd=Xl,Ud=ph,Bd=fh,Fd=yh,Vd=bh,$d=Uh,Hd=vs,Qd=Kh,Gd=fo,Zd=Su,qd=ld,Xd=Md,Jd=Ut,Kd=Fo,_d=Cd,ep=ot,tp=Ts,op=Qo,ip=Go,sp=1,np=2,rp=4,ks="[object Arguments]",ap="[object Array]",cp="[object Boolean]",lp="[object Date]",hp="[object Error]",Cs="[object Function]",up="[object GeneratorFunction]",dp="[object Map]",pp="[object Number]",bs="[object Object]",fp="[object RegExp]",gp="[object Set]",yp="[object String]",Mp="[object Symbol]",mp="[object WeakMap]",wp="[object ArrayBuffer]",vp="[object DataView]",Ip="[object Float32Array]",Np="[object Float64Array]",Sp="[object Int8Array]",Tp="[object Int16Array]",kp="[object Int32Array]",Cp="[object Uint8Array]",bp="[object Uint8ClampedArray]",xp="[object Uint16Array]",Lp="[object Uint32Array]",ge={};ge[ks]=ge[ap]=ge[wp]=ge[vp]=ge[cp]=ge[lp]=ge[Ip]=ge[Np]=ge[Sp]=ge[Tp]=ge[kp]=ge[dp]=ge[pp]=ge[bs]=ge[fp]=ge[gp]=ge[yp]=ge[Mp]=ge[Cp]=ge[bp]=ge[xp]=ge[Lp]=!0;ge[hp]=ge[Cs]=ge[mp]=!1;function Qt(a,o,e,t,i,s){var n,r=o&sp,c=o&np,l=o&rp;if(e&&(n=i?e(a,t,i,s):e(a)),n!==void 0)return n;if(!ep(a))return a;var h=Jd(a);if(h){if(n=Zd(a),!r)return Fd(a,n)}else{var u=Gd(a),d=u==Cs||u==up;if(Kd(a))return Bd(a,r);if(u==bs||u==ks||d&&!i){if(n=c||d?{}:Xd(a),!r)return c?$d(a,Ud(n,a)):Vd(a,Wd(n,a))}else{if(!ge[u])return i?a:{};n=qd(a,u,r)}}s||(s=new Od);var p=s.get(a);if(p)return p;s.set(a,n),tp(a)?a.forEach(function(m){n.add(Qt(m,o,e,m,a,s))}):_d(a)&&a.forEach(function(m,T){n.set(T,Qt(m,o,e,T,a,s))});var f=l?c?Qd:Hd:c?ip:op,y=h?void 0:f(a);return Rd(y||a,function(m,T){y&&(T=m,m=a[T]),Yd(n,T,Qt(m,o,e,T,a,s))}),n}var zp=Qt,Pp=zp,Dp=1,Ap=4;function jp(a){return Pp(a,Dp|Ap)}var Ep=jp;const Ce=St(Ep),xs="1.1.13",Op="@netless/appliance-plugin",Jo=typeof OffscreenCanvas=="function"?"worker":"mainThread";if(typeof window<"u"){let a=window.__netlessUA||"";a+=` ${Op}@${xs}`,window.__netlessUA=a}const be={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:{combineUnitTime:100},pencilEraser:{useBitMap:!0},strokeWidth:{min:1,max:10}};function tt(a,o=!0){const e=a.length;if(e<2)return"";let t=a[0],i=a[1];if(e===2)return`M${pt(t)}L${pt(i)}`;let s="";for(let n=2,r=e-1;n<r;n++)t=a[n],i=a[n+1],s+=ft(t,i);return o?`M${ft(a[0],a[1])}Q${pt(a[1])}${ft(a[1],a[2])}T${s}${ft(a[e-1],a[0])}${ft(a[0],a[1])}Z`:`M${pt(a[0])}Q${pt(a[1])}${ft(a[1],a[2])}${a.length>3?"T":""}${s}L${pt(a[e-1])}`}const Ee=class Ee{constructor(o){g(this,"syncUnitTime",be.syncOpt.interval);g(this,"vNodes");g(this,"drawLayer");g(this,"fullLayer");g(this,"workId");const{vNodes:e,fullLayer:t,drawLayer:i,workId:s,toolsOpt:n}=o;this.vNodes=e,this.fullLayer=t,this.drawLayer=i,this.workId=s,this.syncUnitTime=n.syncUnitTime||this.syncUnitTime}get baseConsumeResult(){return{workId:this.workId,toolsType:this.toolsType,opt:this.workOptions}}filterSamePoints(o,e=.01){return o.reduce((t,i)=>{const s=t[t.length-1];return(i&&!s||i&&s&&!i.isNear(s,e))&&t.push(i),t},[])}setWorkId(o){this.workId=o}getWorkId(){return this.workId}getWorkOptions(){return this.workOptions}setWorkOptions(o){var i,s,n;this.workOptions=o,this.syncUnitTime=o.syncUnitTime||this.syncUnitTime;const e=(i=this.workId)==null?void 0:i.toString(),t=e&&((s=this.vNodes)==null?void 0:s.get(e))||void 0;e&&t&&(t.opt=o,(n=this.vNodes)==null||n.setInfo(e,t))}updataOptService(o){var i,s;let e;const t=(i=this.workId)==null?void 0:i.toString();if(t&&o){const n=this.fullLayer.getElementsByName(t)||this.drawLayer&&this.drawLayer.getElementsByName(t)||[];if(n.length!==1)return;const r=n[0],{pos:c,zIndex:l,scale:h,angle:u,translate:d}=o,p={};Oe(l)&&(p.zIndex=l),c&&(p.pos=[c[0],c[1]]),h&&(p.scale=h),u&&(p.rotate=u),d&&(p.translate=d),r.attr(p);const f=r==null?void 0:r.getBoundingClientRect();return f&&(e=ae(e,{x:Math.floor(f.x-Ee.SafeBorderPadding),y:Math.floor(f.y-Ee.SafeBorderPadding),w:Math.floor(f.width+Ee.SafeBorderPadding*2),h:Math.floor(f.height+Ee.SafeBorderPadding*2)})),(s=this.vNodes)==null||s.setInfo(t,{rect:e,centerPos:c}),e}}drawEraserlines(o){const{group:e,eraserlines:t,pos:i,layer:s,isClear:n=!0}=o,r=!!s.parent.gl;for(const c of t){const{thickness:l,op:h}=c;for(const u of h){const d=u.map((T,w)=>w%2?T-i[1]:T-i[0]),p=this.computEraserPoints(d,l),f=tt(p,!0),y={pos:[0,0],d:f,fillColor:"rgba(0,0,0,1)"},m=new he.Path(y);n&&(m.addEventListener("beforerender",({detail:T})=>{const w=T.context;r?w.blendFuncSeparate(w.ZERO,w.ZERO,w.ZERO,w.ZERO):w.globalCompositeOperation="destination-out"}),m.addEventListener("afterrender",({detail:T})=>{const w=T.context;r?w.blendFuncSeparate(w.SRC_ALPHA,w.ONE_MINUS_SRC_ALPHA,w.ONE,w.ONE_MINUS_SRC_ALPHA):w.globalCompositeOperation="source-over"})),e.append(m)}}}computEraserPoints(o,e){const t=Math.ceil(e/2);return o.length===2?this.computDot(o,t):this.computLine(o,t)}computDot(o,e){const t=new V(o[0],o[1]);return V.GetDotStroke(t,e,8)}computLine(o,e){const t=[],i=[];let s,n;for(let r=0;r<o.length;r+=2){const c=new V(o[r],o[r+1]);let l;if(r==o.length-2){const h=new V(o[r-2],o[r-1]);l=C.Sub(c,h).uni(),s=c}else{r===0&&(n=c);const h=new V(o[r+2],o[r+3]);l=C.Sub(h,c).uni()}if(l){const h=C.Per(l).mul(e);t.push(V.Sub(c,h)),i.push(V.Add(c,h))}}if(s&&n){const r=V.GetSemicircleStroke(s,t[t.length-1],-1,8),c=V.GetSemicircleStroke(n,i[0],-1,8);return t.concat(r,i.reverse(),c)}return[]}replace(o,e,t){var r;const i=o.getElementsByName(e),s=i.length;if(s){if(s>1)for(let c=1;c<i.length;c++)o.removeChild(i[c]),i[c].disconnect();t?o.replaceChild(t,i[0]):o.removeChild(i[0]),i[0].disconnect()}else t&&o.append(t);this.fullLayer===o?(r=this.drawLayer)==null||r.getElementsByName(e).forEach(c=>{var l;(l=this.drawLayer)==null||l.removeChild(c),c.disconnect()}):this.fullLayer.getElementsByName(e).forEach(c=>{this.fullLayer.removeChild(c),c.disconnect()})}static updateNodeOpt(o){var w;const{node:e,opt:t,vNodes:i,willSerializeData:s,targetNode:n}=o,{zIndex:r,translate:c,angle:l,originPoint:h,scenePoint:u,scale:d,pointMap:p,thickness:f}=t;let y;const m=n&&Ce(n)||i.get(e.name);if(!m)return;Oe(r)&&(e.setAttribute("zIndex",r),m.opt.zIndex=r);const T=e.parent;if(T){if(h&&d&&n){const v=[m.op[0],m.op[1]];oi(m.op,u,d,c);const S=[m.op[0],m.op[1]],N=[S[0]-v[0],S[1]-v[1]];if(m.centerPos=[m.centerPos[0]+N[0],m.centerPos[1]+N[1]],m.opt.translate=void 0,m.opt.scale=void 0,m.opt.eraserlines)for(const I of Object.values(m.opt.eraserlines)){const{op:b,thickness:L}=I;I.thickness=L*Math.max(d[0],d[1]);for(let j=0;j<b.length;j++)ii(b[j],u,d,c)}}else if(c)if(e.setAttribute("translate",c),m.opt.translate=c,n){const v=[c[0]*T.worldScaling[0],c[1]*T.worldScaling[1]];y=Ao(m.rect,v),m.rect=y}else{const v=Ee.getRectFromLayer(T,e.name);m.rect=v||m.rect}else if(Oe(l))if(e.setAttribute("rotate",l),m.opt.rotate=l,n)y=Gs(m.rect,l),m.rect=y;else{const v=Ee.getRectFromLayer(T,e.name);m.rect=v||m.rect}if(p){const v=p.get(e.name);if(v)for(let S=0,N=0;S<m.op.length;S+=3,N++)m.op[S]=v[N][0],m.op[S+1]=v[N][1]}if(f&&((w=m==null?void 0:m.opt)!=null&&w.thickness)&&(m.opt.thickness=f),s&&!(h&&d&&n)){if(c){const v=m.op.map((S,N)=>{const I=N%3;return I===0?S+c[0]:I===1?S+c[1]:S});if(m.op=v,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 S of Object.values(m.opt.eraserlines)){const{op:N}=S;for(let I=0;I<N.length;I++){const b=N[I].map((L,j)=>j%2?L+c[1]:L+c[0]);S.op[I]=b}}}else if(Oe(l)){const v=m.op;if(dM(v,m.centerPos,l),m.op=v,m!=null&&m.opt&&(m.opt.rotate=void 0),m.opt.eraserlines)for(const S of Object.values(m.opt.eraserlines)){const{op:N}=S;for(let I=0;I<N.length;I++)pM(N[I],m.centerPos,l)}}}m&&i.setInfo(e.name,m)}}static getCenterPos(o,e){const{worldPosition:t,worldScaling:i}=e;return[(o.x+o.w/2-t[0])/i[0],(o.y+o.h/2-t[1])/i[1]]}static getRectFromLayer(o,e){const t=o.getElementsByName(e)[0];if(t){const i=t.getBoundingClientRect();return{x:Math.floor(i.x-Ee.SafeBorderPadding),y:Math.floor(i.y-Ee.SafeBorderPadding),w:Math.floor(i.width+Ee.SafeBorderPadding*2),h:Math.floor(i.height+Ee.SafeBorderPadding*2)}}}};g(Ee,"SafeBorderPadding",10);let U=Ee;function it(a){return JSON.parse(Ji.decompress(a))}function Re(a){return Ji.compress(JSON.stringify(a))}const Le=Object.keys;class Ls extends U{constructor(e){super(e);g(this,"canRotate",!0);g(this,"scaleType",re.all);g(this,"toolsType",k.Pencil);g(this,"syncTimestamp");g(this,"syncIndex",0);g(this,"tmpPoints",[]);g(this,"MAX_REPEAR",10);g(this,"uniThickness");g(this,"workOptions");g(this,"centerPos",[0,0]);this.workOptions=e.toolsOpt,this.uniThickness=this.MAX_REPEAR/this.workOptions.thickness/10,this.syncTimestamp=0}combineConsume(){var r;const e=(r=this.workId)==null?void 0:r.toString();if(this.tmpPoints.length<2)return{type:x.None};const t=this.transformDataAll(!0),i={name:e};let s;const n=this.drawLayer||this.fullLayer;return t.length&&(s=this.draw({attrs:i,tasks:t,replaceId:e,layer:n})),{rect:s,type:x.DrawWork,dataType:F.Local}}setWorkOptions(e){super.setWorkOptions(e),this.syncTimestamp=Date.now()}consume(e){const{data:t,isFullWork:i,isSubWorker:s,isMainThread:n,drawCount:r,replaceId:c}=e,{workId:l}=t,{tasks:h,effects:u,consumeIndex:d}=this.transformData(t,!1);this.syncIndex=Math.min(this.syncIndex,d,Math.max(0,this.tmpPoints.length-2));const p={name:l,id:r==null?void 0:r.toString()};let f,y=!1;const m=this.syncIndex;if(this.syncTimestamp===0&&(this.syncTimestamp=Date.now()),h.length&&(h[0].taskId-this.syncTimestamp>this.syncUnitTime&&(y=!0,this.syncTimestamp=h[0].taskId,this.syncIndex=this.tmpPoints.length),s||n)){const w=i?this.fullLayer:this.drawLayer||this.fullLayer;f=this.draw({attrs:p,tasks:h,effects:u,layer:w,replaceId:c})}if(s)return d>10&&this.tmpPoints.splice(0,d-10),{rect:f,type:x.DrawWork,dataType:F.Local};const T=[];return this.tmpPoints.slice(m).forEach(w=>{T.push(w.x,w.y,this.computRadius(w.z,this.workOptions.thickness))}),{...this.baseConsumeResult,type:x.DrawWork,dataType:F.Local,rect:f,op:y?T:void 0,index:y?m*3:void 0,updateNodeOpt:{useAnimation:!0}}}consumeAll(e){var h;const t=this.workId;if(e.data){const{op:u,workState:d}=e.data;u!=null&&u.length&&d===P.Done&&this.workOptions.strokeType===oe.Stroke&&this.updateTempPointsWithPressureWhenDone(u)}const i=this.transformDataAll(!0),s={name:t};let n;const r=this.fullLayer;if(i.length&&(n=this.draw({attrs:s,tasks:i,replaceId:t,layer:r})),this.tmpPoints.length<2)return this.replace(r,t),{type:x.RemoveNode,removeIds:[t],rect:n};const c=[];this.tmpPoints.map(u=>{c.push(u.x,u.y,u.z)}),this.syncTimestamp=0,delete this.workOptions.syncUnitTime;const l=Re(c);return(h=this.vNodes)==null||h.setInfo(t,{rect:n,op:c,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:n&&U.getCenterPos(n,r)}),{...this.baseConsumeResult,rect:n,type:x.FullWork,dataType:F.Local,ops:l,updateNodeOpt:{pos:this.centerPos,useAnimation:!0}}}clearTmpPoints(){this.tmpPoints.length=0,this.syncTimestamp=0,this.syncIndex=0}consumeService(e){var h,u;const{op:t,isFullWork:i,replaceId:s}=e;this.tmpPoints.length=0;for(let d=0;d<t.length;d+=3){const p=new V(t[d],t[d+1],t[d+2]);if(this.tmpPoints.length>0){const f=this.tmpPoints[this.tmpPoints.length-1],y=C.Sub(p,f).uni();p.setv(y)}this.tmpPoints.push(p)}if(this.tmpPoints.length<2)return;const n=this.transformDataAll(!0),r=(h=this.workId)==null?void 0:h.toString(),c={name:r};let l;if(r&&n.length){const d=i?this.fullLayer:this.drawLayer||this.fullLayer;l=this.draw({attrs:c,tasks:n,replaceId:s,layer:d}),(u=this.vNodes)==null||u.setInfo(r,{rect:l,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:l&&U.getCenterPos(l,d)})}return l}transformDataAll(e=!0){const t=this.filterSamePoints(this.tmpPoints,this.workOptions.thickness);return this.getTaskPoints(t,e&&this.workOptions.thickness||void 0)}draw(e){const{attrs:t,tasks:i,replaceId:s,effects:n,layer:r}=e,{strokeColor:c,strokeType:l,thickness:h,zIndex:u,scale:d,rotate:p,translate:f,eraserlines:y}=this.workOptions;n!=null&&n.size&&(n.forEach(N=>{var I;(I=r.getElementById(N+""))==null||I.remove()}),n.clear());let m;const T=[],w=r.worldPosition,v=r.worldScaling;for(let N=0;N<i.length;N++){const{pos:I,points:b}=i[N],{ps:L,rect:j}=this.computDrawPoints(b);let E;const A=b.length===1;l===oe.Stroke||A?E=tt(L,!0):E=tt(L,!1);const W={pos:I,d:E,fillColor:l===oe.Stroke||A?c:void 0,lineDash:l===oe.Dotted&&!A?[1,h*2]:l===oe.LongDotted&&!A?[h,h*2]:void 0,strokeColor:c,lineCap:l===oe.Stroke||A?void 0:"round",lineWidth:l===oe.Stroke||A?0:h};m=ae(m,{x:Math.floor((j.x+I[0])*v[0]+w[0]-U.SafeBorderPadding),y:Math.floor((j.y+I[1])*v[1]+w[1]-U.SafeBorderPadding),w:Math.floor(j.w*v[0]+2*U.SafeBorderPadding),h:Math.floor(j.h*v[1]+2*U.SafeBorderPadding)}),T.push(W)}d&&(t.scale=d),p&&(t.rotate=p),f&&(t.translate=f);const S=new he.Group;if(m){this.centerPos=U.getCenterPos(m,r);const N=l===oe.Stroke&&!y;S.attr({...t,normalize:!0,anchor:[.5,.5],bgcolor:N?c:void 0,pos:this.centerPos,size:[(m.w-2*U.SafeBorderPadding)/v[0],(m.h-2*U.SafeBorderPadding)/v[1]],zIndex:u});const I=T.map(b=>(b.pos=[b.pos[0]-this.centerPos[0],b.pos[1]-this.centerPos[1]],new he.Path(b)));S.append(...I),N&&S.seal(),y&&(this.scaleType=re.proportional,this.drawEraserlines({group:S,eraserlines:y,pos:this.centerPos,layer:r})),this.replace(r,s||t.workId,S)}if(d||p||f){const N=S==null?void 0:S.getBoundingClientRect();if(N)return{x:Math.floor(N.x-U.SafeBorderPadding),y:Math.floor(N.y-U.SafeBorderPadding),w:Math.floor(N.width+U.SafeBorderPadding*2),h:Math.floor(N.height+U.SafeBorderPadding*2)}}return m}computDrawPoints(e){return this.workOptions.strokeType===oe.Stroke||e.length===1?this.computStroke(e):this.computNomal(e)}computNomal(e){let t=this.workOptions.thickness;const i=e.map(s=>(t=Math.max(t,s.radius),s.point));return{ps:i,rect:pe(i,t)}}computStroke(e){return e.length===1?this.computDotStroke(e[0]):this.computLineStroke(e)}computLineStroke(e){const t=[],i=[];for(let l=0;l<e.length;l++){const{point:h,radius:u}=e[l];let d=h.v;l===0&&e.length>1&&(d=e[l+1].point.v);const p=C.Per(d).mul(u);t.push(V.Sub(h,p)),i.push(V.Add(h,p))}const s=e[e.length-1],n=V.GetSemicircleStroke(s.point,t[t.length-1],-1,8),r=V.GetSemicircleStroke(e[0].point,i[0],-1,8),c=t.concat(n,i.reverse(),r);return{ps:c,rect:pe(c)}}computDotStroke(e){const{point:t,radius:i}=e,s={x:t.x-i,y:t.y-i,w:i*2,h:i*2};return{ps:V.GetDotStroke(t,i,8),rect:s}}transformData(e,t){const{op:i,workState:s}=e;let n=this.tmpPoints.length-1,r=[];if(i!=null&&i.length&&s){const{strokeType:c,thickness:l}=this.workOptions,h=new Set;n=c===oe.Stroke?this.updateTempPointsWithPressure(i,l,h):this.updateTempPoints(i,l,h);const u=t?this.tmpPoints:this.tmpPoints.slice(n);return r=this.getTaskPoints(u,l),{tasks:r,effects:h,consumeIndex:n}}return{tasks:r,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 u;const i=[];if(e.length===0)return[];let s=0,n=e[0].x,r=e[0].y,c=[n,r],l=[],h=e[0].t;for(;s<e.length;){const d=e[s],p=d.x-n,f=d.y-r,y=d.z,m=t?this.computRadius(y,t):y;if(l.push({point:new V(p,f,y,e[s].v),radius:m}),s>0&&s<e.length-1){const T=e[s].getAngleByPoints(e[s-1],e[s+1]);if(T<90||T>270){const w=(u=l.pop())==null?void 0:u.point.clone();w&&i.push({taskId:h,pos:c,points:[...l,{point:w,radius:m}]}),n=e[s].x,r=e[s].y,c=[n,r];const v=d.x-n,S=d.y-r;l=[{point:new V(v,S,y),radius:m}],h=Date.now()}}s++}return i.push({taskId:h,pos:c,points:l}),i}updateTempPointsWithPressure(e,t,i){const s=Date.now(),n=this.tmpPoints.length;let r=n;for(let l=0;l<e.length;l+=2){r=Math.min(r,n);const h=this.tmpPoints.length,u=new V(e[l],e[l+1]);if(h===0){this.tmpPoints.push(u);continue}const d=h-1,p=this.tmpPoints[d],f=C.Sub(u,p).uni();if(u.isNear(p,t)){if(p.z<this.MAX_REPEAR){if(p.setz(Math.min(p.z+1,this.MAX_REPEAR)),r=Math.min(r,d),h>1){let T=h-1;for(;T>0;){const w=this.tmpPoints[T].distance(this.tmpPoints[T-1]),v=Math.max(this.tmpPoints[T].z-this.uniThickness*w,0);if(this.tmpPoints[T-1].z>=v)break;this.tmpPoints[T-1].setz(v),r=Math.min(r,T-1),T--}}}else r=1/0;continue}u.setv(f);const y=u.distance(p),m=Math.max(p.z-this.uniThickness*y,0);h>1&&C.Equals(f,p.v,.02)&&(m>0||p.z<=0)&&(i&&p.t&&i.add(p.t),this.tmpPoints.pop(),r=Math.min(d,r)),u.setz(m),this.tmpPoints.push(u)}if(r===1/0)return this.tmpPoints.length;let c=n;if(r===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=r;l>=0;){const h=this.tmpPoints[l].t;if(h&&(i==null||i.add(h),l<=r)){c=l,l=-1;break}l--}}return this.tmpPoints[c].setT(s),c}updateTempPoints(e,t,i){var l;const s=Date.now(),n=this.tmpPoints.length;let r=n;for(let h=0;h<e.length;h+=2){const u=this.tmpPoints.length,d=new V(e[h],e[h+1]);if(u===0){this.tmpPoints.push(d);continue}const p=u-1,f=this.tmpPoints[p],y=C.Sub(d,f).uni();if(d.isNear(f,t/2)){r=Math.min(p,r);continue}C.Equals(y,f.v,.02)&&(i&&f.t&&i.add(f.t),this.tmpPoints.pop(),r=Math.min(p,r)),d.setv(y),this.tmpPoints.push(d)}let c=n;if(r===n){c=Math.max(c-1,0);const h=this.tmpPoints[c].t;h&&(i==null||i.add(h))}else{let h=Math.min(n-1,r);for(c=r;h>=0;){const u=(l=this.tmpPoints[h])==null?void 0:l.t;if(u&&(i==null||i.add(u),h<=r)){c=h,h=-1;break}h--}}return this.tmpPoints[c].setT(s),c}updateTempPointsWithPressureWhenDone(e){const{thickness:t}=this.workOptions,i=e.length,s=this.getMinZ(t);for(let n=0;n<i;n+=2){const r=this.tmpPoints.length,c=new V(e[n],e[n+1]);if(r===0){this.tmpPoints.push(c);continue}const l=r-1,h=this.tmpPoints[l],u=C.Sub(c,h).uni(),d=c.distance(h);if(r>1&&h.z===s)break;if(c.isNear(h,t/2)){if(i<3&&h.z<this.MAX_REPEAR&&(h.setz(Math.min(h.z+1,this.MAX_REPEAR)),r>1)){let f=r-1;for(;f>0;){const y=this.tmpPoints[f].distance(this.tmpPoints[f-1]),m=Math.max(this.tmpPoints[f].z-this.uniThickness*y,-t/4);if(this.tmpPoints[f-1].z>=m)break;this.tmpPoints[f-1].setz(m),f--}}continue}c.setv(u);const p=Math.max(h.z-this.uniThickness*d,s);r>1&&C.Equals(u,h.v,.02)&&h.z<=0&&this.tmpPoints.pop(),c.setz(p),this.tmpPoints.push(c)}}static updateNodeOpt(e){var l,h;const{node:t,opt:i,vNodes:s}=e,{strokeColor:n,strokeType:r}=i,c=s.get(t.name);return n&&(t.tagName==="GROUP"?mM(t)?t.setAttribute("bgcolor",n):t.children.forEach(u=>{u.setAttribute("strokeColor",n),u.getAttribute("fillColor")&&u.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)),r&&(c!=null&&c.opt)&&((h=c.opt)!=null&&h.strokeType)&&(c.opt.strokeType=r),c&&s.setInfo(t.name,c),U.updateNodeOpt(e)}}class zs extends U{constructor(e){super(e);g(this,"toolsType",k.LaserPen);g(this,"canRotate",!1);g(this,"scaleType",re.none);g(this,"syncTimestamp");g(this,"syncIndex",0);g(this,"tmpPoints",[]);g(this,"workOptions");g(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:s,op:n}=t;if((n==null?void 0:n.length)===0)return{type:x.None};if(this.updateTempPoints(n||[]),this.consumeIndex>this.tmpPoints.length-4)return{type:x.None};const{strokeColor:r,thickness:c,strokeType:l}=this.workOptions,h=pe(this.tmpPoints,c);let u=!1;const d=this.syncIndex,p=this.tmpPoints.slice(this.consumeIndex);this.consumeIndex=this.tmpPoints.length-1,this.syncTimestamp===0&&(this.syncTimestamp=Date.now());const f={name:s==null?void 0:s.toString(),opacity:1,lineDash:l===oe.Dotted?[1,c*2]:l===oe.LongDotted?[c,c*2]:void 0,strokeColor:r,lineCap:"round",lineWidth:c,anchor:[.5,.5]},y=this.getTaskPoints(p);if(y.length){const T=Date.now();T-this.syncTimestamp>this.syncUnitTime&&(u=!0,this.syncTimestamp=T,this.syncIndex=this.tmpPoints.length),i&&this.draw({attrs:f,tasks:y,isDot:!1,layer:this.drawLayer||this.fullLayer})}const m=[];return this.tmpPoints.slice(d).forEach(T=>{m.push(T.x,T.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:x.DrawWork,dataType:F.Local,op:u?m:void 0,index:u?d*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 r=this.tmpPoints.slice(this.consumeIndex);const c=r.length===1,{strokeColor:l,thickness:h,strokeType:u}=this.workOptions;if(c){const f=this.computDotStroke({point:r[0],radius:h/2});r=f.ps,t=f.rect}else t=pe(this.tmpPoints,h);const d={name:e==null?void 0:e.toString(),fillColor:c?l:void 0,opacity:1,lineDash:u===oe.Dotted&&!c?[1,h*2]:u===oe.LongDotted&&!c?[h,h*2]:void 0,strokeColor:l,lineCap:c?void 0:"round",lineWidth:c?0:h,anchor:[.5,.5]},p=this.getTaskPoints(r);p.length&&this.draw({attrs:d,tasks:p,isDot:c,layer:this.drawLayer||this.fullLayer})}const i=[];this.tmpPoints.forEach(r=>{i.push(r.x,r.y)});const s=Re(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:x.FullWork,dataType:F.Local,ops:s,index:this.syncIndex*2,...this.baseConsumeResult}}clearTmpPoints(){this.tmpPoints.length=0,this.syncTimestamp=0,this.syncIndex=0}consumeService(e){var y;const{op:t,replaceId:i,isFullWork:s}=e,{strokeColor:n,thickness:r,strokeType:c}=this.workOptions;if(!t.length){const m=pe(this.tmpPoints,r);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 h,u=this.tmpPoints.slice(l);const d=u.length===1;if(d){const m=this.computDotStroke({point:u[0],radius:r/2});u=m.ps,h=m.rect}else h=pe(this.tmpPoints,r);const p={name:(y=this.workId)==null?void 0:y.toString(),fillColor:d?n:void 0,opacity:1,lineDash:c===oe.Dotted&&!d?[1,r*2]:c===oe.LongDotted&&!d?[r,r*2]:void 0,strokeColor:n,lineCap:d?void 0:"round",lineWidth:d?0:r,anchor:[.5,.5]},f=this.getTaskPoints(u);if(f.length){const m=s?this.fullLayer:this.drawLayer||this.fullLayer;this.draw({attrs:p,tasks:f,isDot:d,replaceId:i,layer:m})}return{x:h.x*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],y:h.y*this.fullLayer.worldScaling[1]+this.fullLayer.worldPosition[1],w:h.w*this.fullLayer.worldScaling[0],h:h.h*this.fullLayer.worldScaling[1]}}computDotStroke(e){const{point:t,radius:i}=e,s={x:t.x-i,y:t.y-i,w:i*2,h:i*2};return{ps:V.GetDotStroke(t,i,8),rect:s}}updateTempPoints(e){const t=this.tmpPoints.length;for(let i=0;i<e.length;i+=2){if(t){const s=this.tmpPoints.slice(-1)[0];s&&s.x===e[i]&&s.y===e[i+1]&&this.tmpPoints.pop()}this.tmpPoints.push(new V(e[i],e[i+1]))}}async draw(e){const{attrs:t,tasks:i,isDot:s,layer:n}=e,{duration:r}=this.workOptions;for(const c of i){const l=new he.Path,{pos:h,points:u}=c;let d;s?d=tt(u,!0):d=tt(u,!1),l.attr({...t,pos:h,d});const{vertex:p,fragment:f}=this.workOptions;if(p&&f){const y=n.renderer.createProgram({vertex:p,fragment:f}),{width:m,height:T}=n.getResolution();l.setUniforms({u_time:0,u_resolution:[m,T]}),l.setProgram(y)}n.appendChild(l),l.transition(r).attr({scale:s?[.1,.1]:[1,1],lineWidth:s?0:1}).then(()=>{l.remove()})}}getTaskPoints(e){var l;const t=[];if(e.length===0)return[];let i=0,s=e[0].x,n=e[0].y,r=[s,n],c=[];for(;i<e.length;){const h=e[i],u=h.x-s,d=h.y-n;if(c.push(new V(u,d)),i>0&&i<e.length-1){const p=e[i].getAngleByPoints(e[i-1],e[i+1]);if(p<90||p>270){const f=(l=c.pop())==null?void 0:l.clone();f&&t.push({pos:r,points:[...c,f]}),s=e[i].x,n=e[i].y,r=[s,n];const y=h.x-s,m=h.y-n;c=[new V(y,m)]}}i++}return t.push({pos:r,points:c}),t}removeLocal(){}removeService(e){let t;const i=[];return this.fullLayer.getElementsByName(e).forEach(s=>{if(s.name===e){const n=s.getBoundingClientRect();t=ae(t,{x:n.x,y:n.y,w:n.width,h:n.height}),i.push(s)}}),i.length&&i.forEach(s=>s.remove()),t}}const Mt=class Mt extends U{constructor(e,t){super(e);g(this,"canRotate",!1);g(this,"scaleType",re.none);g(this,"toolsType",k.Eraser);g(this,"serviceWork");g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"worldPosition");g(this,"worldScaling");g(this,"eraserRect");g(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:s,height:n}=Mt.eraserSizes[this.workOptions.thickness];this.eraserRect={x:t-s*.5,y:i-n*.5,w:s,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 C(this.tmpPoints[0],this.tmpPoints[1]),i=new C(this.tmpPoints[2],this.tmpPoints[3]),s=C.Sub(i,t).uni(),n=C.Dist(t,i),{width:r,height:c}=Mt.eraserSizes[this.workOptions.thickness],l=Math.min(r,c),h=Math.round(n/l);if(h>1){const u=[];for(let d=0;d<h;d++){const p=C.Mul(s,d*l);u.push(this.tmpPoints[0]+p.x,this.tmpPoints[1]+p.y)}return u.concat(e)}}return e}isNear(e,t){const i=new C(e[0],e[1]),s=new C(t[0],t[1]),{width:n,height:r}=Mt.eraserSizes[this.workOptions.thickness];return C.Dist(i,s)<Math.hypot(n,r)*.5}remove(e){const{curNodeMap:t,removeIds:i}=e;let s;for(const n of t.values())if(n.rect&&this.eraserRect&&this.eraserPolyline&&Yt(this.eraserRect,n.rect)){const{op:r}=n,c=[],l=[];for(let u=0;u<r.length;u+=3){const d=new C(r[u]*this.worldScaling[0]+this.worldPosition[0],r[u+1]*this.worldScaling[1]+this.worldPosition[1],r[u+2]);l.push(d),c.push(new V(d.x,d.y))}const h=c.length&&pe(c)||n.rect;Yt(h,this.eraserRect)&&(l.length>1?Wo.polyline(l.map(d=>d.XY),this.eraserPolyline).length&&i.add(n.name):i.add(n.name),s=ae(s,n.rect||h))}return i.forEach(n=>{var c;const r=this.fullLayer.getElementsByName(n);this.fullLayer.removeChild(r[0]),(c=this.vNodes)==null||c.delete(n)}),s&&(s.x-=U.SafeBorderPadding,s.y-=U.SafeBorderPadding,s.w+=U.SafeBorderPadding*2,s.h+=U.SafeBorderPadding*2),s}consume(e){const{op:t,disableEraseImage:i,disableEraseText:s}=e.data;if(!t||t.length===0)return{type:x.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:x.None,...this.baseConsumeResult};n<3?this.tmpPoints.push(t[0],t[1]):this.tmpPoints.splice(2,2,t[0],t[1]);const r=this.computRectCenterPoints();let c;const l=new Set;if(!this.vNodes)return{type:x.None,...this.baseConsumeResult};const h=this.getCanEraserNodeMap(this.vNodes.getCanEraserNodes(this.vNodes.curNodeMap,{disableEraseImage:i,disableEraseText:s}));for(let u=0;u<r.length-1;u+=2){this.createEraserRect(r.slice(u,u+2));const d=this.remove({curNodeMap:h,removeIds:l});c=ae(c,d)}return c&&l.size?{type:x.RemoveNode,rect:c,removeIds:[...l]}:{type:x.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),s=this.serviceWork.selectorWorkShapes,n=this.serviceWork.workShapes;for(const r of s.values())if((t=r.selectIds)!=null&&t.length)for(const c of r.selectIds)i.delete(c);for(const r of n.keys())i.delete(r);return i}return e}};g(Mt,"eraserSizes",Object.freeze([Object.freeze({width:18,height:26}),Object.freeze({width:26,height:34}),Object.freeze({width:34,height:50})]));let Jt=Mt;const Ae="++",H="selector",Gt="all";var Rp="__lodash_hash_undefined__";function Yp(a){return this.__data__.set(a,Rp),this}var Wp=Yp;function Up(a){return this.__data__.has(a)}var Bp=Up,Fp=ss,Vp=Wp,$p=Bp;function Kt(a){var o=-1,e=a==null?0:a.length;for(this.__data__=new Fp;++o<e;)this.add(a[o])}Kt.prototype.add=Kt.prototype.push=Vp;Kt.prototype.has=$p;var Ko=Kt;function Hp(a,o){for(var e=-1,t=a==null?0:a.length;++e<t;)if(o(a[e],e,a))return!0;return!1}var Qp=Hp;function Gp(a,o){return a.has(o)}var _o=Gp,Zp=Ko,qp=Qp,Xp=_o,Jp=1,Kp=2;function _p(a,o,e,t,i,s){var n=e&Jp,r=a.length,c=o.length;if(r!=c&&!(n&&c>r))return!1;var l=s.get(a),h=s.get(o);if(l&&h)return l==o&&h==a;var u=-1,d=!0,p=e&Kp?new Zp:void 0;for(s.set(a,o),s.set(o,a);++u<r;){var f=a[u],y=o[u];if(t)var m=n?t(y,f,u,o,a,s):t(f,y,u,a,o,s);if(m!==void 0){if(m)continue;d=!1;break}if(p){if(!qp(o,function(T,w){if(!Xp(p,w)&&(f===T||i(f,T,e,t,s)))return p.push(w)})){d=!1;break}}else if(!(f===y||i(f,y,e,t,s))){d=!1;break}}return s.delete(a),s.delete(o),d}var Ps=_p;function ef(a){var o=-1,e=Array(a.size);return a.forEach(function(t,i){e[++o]=[i,t]}),e}var tf=ef;function of(a){var o=-1,e=Array(a.size);return a.forEach(function(t){e[++o]=t}),e}var ei=of,zi=Wt,Pi=Ss,sf=Uo,nf=Ps,rf=tf,af=ei,cf=1,lf=2,hf="[object Boolean]",uf="[object Date]",df="[object Error]",pf="[object Map]",ff="[object Number]",gf="[object RegExp]",yf="[object Set]",Mf="[object String]",mf="[object Symbol]",wf="[object ArrayBuffer]",vf="[object DataView]",Di=zi?zi.prototype:void 0,Io=Di?Di.valueOf:void 0;function If(a,o,e,t,i,s,n){switch(e){case vf:if(a.byteLength!=o.byteLength||a.byteOffset!=o.byteOffset)return!1;a=a.buffer,o=o.buffer;case wf:return!(a.byteLength!=o.byteLength||!s(new Pi(a),new Pi(o)));case hf:case uf:case ff:return sf(+a,+o);case df:return a.name==o.name&&a.message==o.message;case gf:case Mf:return a==o+"";case pf:var r=rf;case yf:var c=t&cf;if(r||(r=af),a.size!=o.size&&!c)return!1;var l=n.get(a);if(l)return l==o;t|=lf,n.set(a,o);var h=nf(r(a),r(o),t,i,s,n);return n.delete(a),h;case mf:if(Io)return Io.call(a)==Io.call(o)}return!1}var Nf=If,Ai=vs,Sf=1,Tf=Object.prototype,kf=Tf.hasOwnProperty;function Cf(a,o,e,t,i,s){var n=e&Sf,r=Ai(a),c=r.length,l=Ai(o),h=l.length;if(c!=h&&!n)return!1;for(var u=c;u--;){var d=r[u];if(!(n?d in o:kf.call(o,d)))return!1}var p=s.get(a),f=s.get(o);if(p&&f)return p==o&&f==a;var y=!0;s.set(a,o),s.set(o,a);for(var m=n;++u<c;){d=r[u];var T=a[d],w=o[d];if(t)var v=n?t(w,T,d,o,a,s):t(T,w,d,a,o,s);if(!(v===void 0?T===w||i(T,w,e,t,s):v)){y=!1;break}m||(m=d=="constructor")}if(y&&!m){var S=a.constructor,N=o.constructor;S!=N&&"constructor"in a&&"constructor"in o&&!(typeof S=="function"&&S instanceof S&&typeof N=="function"&&N instanceof N)&&(y=!1)}return s.delete(a),s.delete(o),y}var bf=Cf,No=ns,xf=Ps,Lf=Nf,zf=bf,ji=fo,Ei=Ut,Oi=Fo,Pf=ds,Df=1,Ri="[object Arguments]",Yi="[object Array]",Vt="[object Object]",Af=Object.prototype,Wi=Af.hasOwnProperty;function jf(a,o,e,t,i,s){var n=Ei(a),r=Ei(o),c=n?Yi:ji(a),l=r?Yi:ji(o);c=c==Ri?Vt:c,l=l==Ri?Vt:l;var h=c==Vt,u=l==Vt,d=c==l;if(d&&Oi(a)){if(!Oi(o))return!1;n=!0,h=!1}if(d&&!h)return s||(s=new No),n||Pf(a)?xf(a,o,e,t,i,s):Lf(a,o,c,e,t,i,s);if(!(e&Df)){var p=h&&Wi.call(a,"__wrapped__"),f=u&&Wi.call(o,"__wrapped__");if(p||f){var y=p?a.value():a,m=f?o.value():o;return s||(s=new No),i(y,m,e,t,s)}}return d?(s||(s=new No),zf(a,o,e,t,i,s)):!1}var Ef=jf,Of=Ef,Ui=qe;function Ds(a,o,e,t,i){return a===o?!0:a==null||o==null||!Ui(a)&&!Ui(o)?a!==a&&o!==o:Of(a,o,e,t,Ds,i)}var Rf=Ds,Yf=Rf;function Wf(a,o){return Yf(a,o)}var Uf=Wf;const et=St(Uf),no=class no extends U{constructor(e){super(e);g(this,"toolsType",k.Selector);g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"vNodes");g(this,"selectIds");g(this,"selectorColor");g(this,"strokeColor");g(this,"fillColor");g(this,"oldSelectRect");g(this,"canRotate",!1);g(this,"canTextEdit",!1);g(this,"canLock",!1);g(this,"scaleType",re.all);g(this,"toolsTypes");g(this,"shapeOpt");g(this,"textOpt");g(this,"isLocked");g(this,"thickness");g(this,"strokeType");g(this,"useStroke");this.workOptions=e.toolsOpt,this.vNodes=e.vNodes}computSelector(e=!0){const t=pe(this.tmpPoints);if(t.w===0||t.h===0)return{selectIds:[],intersectRect:void 0,subNodeMap:new Map};const{rectRange:i,nodeRange:s}=this.vNodes.getRectIntersectRange(t,e);return{selectIds:[...s.keys()],intersectRect:i,subNodeMap:s}}updateTempPoints(e){const t=this.tmpPoints.length,i=e.length;if(i>1){const s=new V(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,s):this.tmpPoints.push(s)}}drawSelector(e){const{drawRect:t,subNodeMap:i,selectorId:s,layer:n,isService:r}=e,c=new he.Group({pos:[t.x,t.y],anchor:[0,0],size:[t.w,t.h],id:s,name:s,zIndex:9999}),l=[];if(r){const h=new he.Rect({normalize:!0,pos:[t.w/2,t.h/2],lineWidth:1,strokeColor:this.selectorColor||this.workOptions.strokeColor,width:t.w,height:t.h,name:no.selectorBorderId});l.push(h)}i.forEach((h,u)=>{const d=[h.rect.x+h.rect.w/2-t.x,h.rect.y+h.rect.h/2-t.y],p=new he.Rect({normalize:!0,pos:d,lineWidth:1,strokeColor:i.size>1?this.selectorColor||this.workOptions.strokeColor:void 0,width:h.rect.w,height:h.rect.h,id:`selector-${u}`,name:`selector-${u}`});l.push(p)}),l&&c.append(...l),(n==null?void 0:n.parent).appendChild(c)}draw(e,t,i,s=!1){var c,l;const{intersectRect:n,subNodeMap:r}=i;(l=(c=t.parent)==null?void 0:c.getElementById(e))==null||l.remove(),n&&this.drawSelector({drawRect:n,subNodeMap:r,selectorId:e,layer:t,isService:s})}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,s=!0;for(const n of e.values()){const{opt:r,canRotate:c,scaleType:l,toolsType:h}=n;this.selectorColor=this.workOptions.strokeColor,r.strokeColor&&(this.strokeColor=r.strokeColor),r.fillColor&&(this.fillColor=r.fillColor),r.textOpt&&(this.textOpt=r.textOpt),r.thickness&&(this.thickness=r.thickness),h!==k.Pencil&&(s=!1),r.strokeType&&(this.strokeType=r.strokeType),h===k.SpeechBalloon&&(t.add(h),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.placement=r.placement),h===k.Polygon&&(t.add(h),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=r.vertices),h===k.Star&&(t.add(h),this.shapeOpt||(this.shapeOpt={}),this.shapeOpt.vertices=r.vertices,this.shapeOpt.innerRatio=r.innerRatio,this.shapeOpt.innerVerticeStep=r.innerVerticeStep),h===k.Text&&(this.textOpt=r),e.size===1&&(this.textOpt&&(this.canTextEdit=!0),this.canRotate=c,this.scaleType=l),l===re.none&&(this.scaleType=l),h===k.Image&&(i=n)}s&&(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],s=(t=this.vNodes.get(i))==null?void 0:t.op;if(s){const n=[];for(let r=0;r<s.length;r+=3)n.push([s[r],s[r+1]]);return n}}}consume(e){const{op:t,workState:i}=e.data;let s=this.oldSelectRect;if(i===P.Start&&(s=this.unSelectedAllIds()),!(t!=null&&t.length)||!this.vNodes.curNodeMap.size)return{type:x.None};this.updateTempPoints(t);const n=this.computSelector();if(this.selectIds&&et(this.selectIds,n.selectIds))return{type:x.None};this.selectIds=n.selectIds;const r=n.intersectRect;this.getSelecteorInfo(n.subNodeMap),this.draw(H,this.fullLayer,n),this.oldSelectRect=r;const c=this.getChildrenPoints();return{type:x.Select,dataType:F.Local,rect:ae(r,s),selectIds:n.selectIds,selectRect:r,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 s=this.getChildrenPoints();return{type:x.Select,dataType:F.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:s,isLocked:this.isLocked,toolsTypes:this.toolsTypes,shapeOpt:this.shapeOpt,thickness:this.thickness,useStroke:this.useStroke,strokeType:this.strokeType,...this.baseConsumeResult}}return{type:x.None}}consumeService(){}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 s=e[0],n=e[1];let r;const{nodeRange:c}=this.vNodes.getRectIntersectRange({x:s,y:n,w:0,h:0},!1),l=[...c.values()].sort((h,u)=>(u.opt.zIndex||0)-(h.opt.zIndex||0));for(const h of l){const u=this.fullLayer.getElementsByName(h.name);if(Bs(u).find(p=>p.isPointCollision(s,n))){r=h;break}}if(r){const h=r.name;if(!et(this.oldSelectRect,r.rect)){const u=new Map([[h,r]]);this.getSelecteorInfo(u),this.draw(t,this.fullLayer,{intersectRect:r.rect,subNodeMap:u,selectIds:this.selectIds||[]},i)}this.selectIds=[h],this.oldSelectRect=r.rect}}}unSelectedAllIds(){let e;for(const[t,i]of this.vNodes.curNodeMap.entries())i.isSelected&&(e=ae(e,i.rect),this.vNodes.unSelected(t));return e}unSelectedByIds(e){let t;for(const i of e){const s=this.vNodes.get(i);s&&s.isSelected&&(t=ae(t,s.rect),this.vNodes.unSelected(i))}return t}selectedByIds(e){let t;for(const i of e){const s=this.vNodes.get(i);s&&(t=ae(t,s.rect),this.vNodes.selected(i))}return t}getSelectorRect(e,t){var r;let i;const s=(r=e.parent)==null?void 0:r.getElementById(t),n=s==null?void 0:s.getBoundingClientRect();return n&&(i=ae(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===k.Ellipse||e===k.Triangle||e===k.Rectangle||e===k.Polygon||e===k.Star||e===k.SpeechBalloon}async updateSelector(e){var N;const{updateSelectorOpt:t,selectIds:i,vNodes:s,willSerializeData:n,worker:r,offset:c}=e,l=this.fullLayer;if(!l)return;let h;const u=new Map,{originPoint:d,workState:p,angle:f,translate:y,dir:m,scale:T}=t;c&&(y?t.translate=[y[0]+c[0],y[1]+c[1]]:t.translate=c);let w;if(d||y||Oe(f)){if(p===P.Start&&i)return s.setTargetAssignKeys(i),{type:x.Select,dataType:F.Local,selectRect:this.oldSelectRect,rect:this.oldSelectRect};w=s.getLastTarget()}if(i)for(const I of i){const b=s.get(I);if(b){const{toolsType:L,opt:j}=b,E=(l==null?void 0:l.getElementsByName(I))[0];if(E){let A=!1,W=!1;const z={...t};let O;if(L){z.thickness&&b.opt.thickness&&(A=b.opt.thickness!==z.thickness),z.strokeType&&((N=b.opt)!=null&&N.strokeType)&&(W=b.opt.strokeType!==z.strokeType),O=w==null?void 0:w.get(I);const ne=Us(L);if(ne==null||ne.updateNodeOpt({node:E,opt:z,vNodes:s,willSerializeData:n,targetNode:O}),b&&r&&(n&&(z.angle||z.translate)||z.originPoint&&z.scenePoint&&z.scale||z.pointMap&&z.pointMap.has(I)||L===k.Text&&(z.fontSize||z.translate||z.textInfos&&z.textInfos.get(I))||L===k.Image&&(z.angle||z.translate||z.scale||z.strokeColor&&j.type===ht.Iconify)||L===z.toolsType&&z.willRefresh||A||W)){const te=r.createWorkShapeNode({workId:I,toolsType:L,toolsOpt:b.opt});te==null||te.setWorkId(I);let Q;if(L===k.Image)Q=await te.consumeServiceAsync({isFullWork:!0,replaceId:I,worker:r});else if(L===k.Text)Q=await te.consumeServiceAsync({isFullWork:!0,replaceId:I});else try{Q=te==null?void 0:te.consumeService({op:b.op,isFullWork:!0,replaceId:I})}catch{continue}Q&&(b.rect=Q)}b&&(u.set(I,b),h=ae(h,b.rect))}}}}w&&p===P.Done&&(s.deleteLastTarget(),w=void 0);const v=h;if(d&&y&&T&&m&&v&&!c){const I=[[v.x,v.y],[v.x+v.w,v.y],[v.x+v.w,v.y+v.h],[v.x,v.y+v.h]];let b;switch(m){case"top":case"topLeft":case"left":y[0]>0&&y[1]>0?b=I[0]:y[0]>0?b=I[3]:y[1]>0?b=I[1]:b=I[2];break;case"topRight":y[0]<0&&y[1]>0?b=I[1]:y[0]<0?b=I[2]:y[1]>0?b=I[0]:b=I[3];break;case"right":case"bottomRight":case"bottom":y[0]<0&&y[1]<0?b=I[2]:y[0]<0?b=I[1]:y[1]<0?b=I[3]:b=I[0];break;case"bottomLeft":y[0]>0&&y[1]<0?b=I[3]:y[0]>0?b=I[0]:y[1]<0?b=I[2]:b=I[1];break}const L=b&&[d[0]-b[0],d[1]-b[1]]||[0,0];if(!et(L,[0,0]))return await this.updateSelector({...e,updateSelectorOpt:{},offset:L})}this.getSelecteorInfo(u),this.draw(H,l,{selectIds:i||[],subNodeMap:u,intersectRect:v});const S=ae(this.oldSelectRect,v);return this.oldSelectRect=v,{type:x.Select,dataType:F.Local,selectRect:v,renderRect:h,rect:ae(S,v),selectIds:i}}blurSelector(){const e=this.unSelectedAllIds();return{type:x.Select,dataType:F.Local,rect:e,selectIds:[],willSyncService:!0}}getRightServiceId(e){return e.replace(Ae,"-")}selectServiceNode(e,t,i){const{selectIds:s}=t,n=this.getRightServiceId(e),r=this.getSelectorRect(this.fullLayer,n);let c;const l=new Map;return s==null||s.forEach(h=>{const u=this.vNodes.get(h);u&&(c=ae(c,u.rect),l.set(h,u))}),this.getSelecteorInfo(l),this.draw(n,this.fullLayer,{intersectRect:c,selectIds:s||[],subNodeMap:l},i),ae(c,r)}reRenderSelector(){var i;let e;const t=new Map;return(i=this.selectIds)==null||i.forEach(s=>{const n=this.vNodes.get(s);n&&(e=ae(e,n.rect),t.set(s,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(r=>!e.includes(r));if(i!=null&&i.length&&(t=this.unSelectedByIds(i)),e.length){const r=this.selectedByIds(e);t=ae(t,r)}this.selectIds=e;const s=this.reRenderSelector();return{bgRect:t,selectRect:s}}cursorHover(e){var n,r;const t=this.oldSelectRect;this.selectIds=[];const i=(n=this.workId)==null?void 0:n.toString(),s=[e[0]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[0],e[1]*this.fullLayer.worldScaling[0]+this.fullLayer.worldPosition[1]];if(this.selectSingleTool(s,i,!0),this.oldSelectRect&&!et(t,this.oldSelectRect))return{type:x.CursorHover,dataType:F.Local,rect:ae(t,this.oldSelectRect),selectorColor:this.selectorColor,willSyncService:!1};if((r=this.selectIds)!=null&&r.length||(this.oldSelectRect=void 0),t&&!this.oldSelectRect)return this.cursorBlur(),{type:x.CursorHover,dataType:F.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(s=>{s.name===e&&s.remove()})}};g(no,"selectorBorderId","selector-border");let _t=no;class As extends U{constructor(e){super(e);g(this,"canRotate",!1);g(this,"scaleType",re.both);g(this,"toolsType",k.Arrow);g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"oldRect");g(this,"arrowTipWidth");g(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:s,isMainThread:n}=e,r=this.workId,{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:x.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new V(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:x.None};let u;if(s||n){const p=i?this.fullLayer:this.drawLayer||this.fullLayer;u=this.draw({workId:r,layer:p})}if(!s){const p=Date.now();return p-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=p,{...this.baseConsumeResult,type:x.DrawWork,dataType:F.Local,op:this.tmpPoints.map(f=>[...f.XY,0]).flat(1),isSync:!0,index:0}):{type:x.None}}const d=ae(u,this.oldRect);return this.oldRect=u,{rect:d,...this.baseConsumeResult,type:x.DrawWork,dataType:F.Local}}consumeAll(){var r;const e=this.workId;if(this.tmpPoints.length<2)return{type:x.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t});this.oldRect=i;const s=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Re(s);return(r=this.vNodes)==null||r.setInfo(e,{rect:i,op:s,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:U.getCenterPos(i,t)}),{rect:i,...this.baseConsumeResult,type:x.FullWork,dataType:F.Local,ops:n,isSync:!0}}draw(e){const{workId:t,layer:i}=e,{strokeColor:s,thickness:n,zIndex:r,scale:c,rotate:l,translate:h,strokeType:u,eraserlines:d}=this.workOptions,p=i.worldPosition,f=i.worldScaling,{points:y,pos:m,rect:T,isTriangle:w,trianglePoints:v,trianglePos:S}=this.computDrawPoints(n),N=[T.x+T.w/2,T.y+T.h/2],I={pos:N,name:t,id:t,zIndex:r,anchor:[.5,.5],size:[T.w,T.h]};c&&(I.scale=c),l&&(I.rotate=l),h&&(I.translate=h);const b=new he.Group(I),L={points:v,pos:[S[0]-N[0],S[1]-N[1]],fillColor:s,strokeColor:s,lineWidth:0,normalize:!1},j=new he.Polyline(L);if(b.append(j),!w&&y&&m){const E={points:y,pos:[m[0]-N[0],m[1]-N[1]],fillColor:s,strokeColor:s,lineDash:u===oe.Dotted&&!w?[1,n*2]:u===oe.LongDotted&&!w?[n,n*2]:void 0,lineCap:u===oe.Normal?void 0:"round",lineWidth:n,normalize:!1},A=new he.Polyline(E);b.append(A)}if(d&&(this.scaleType=re.proportional,this.drawEraserlines({group:b,eraserlines:d,pos:N,layer:i})),this.replace(i,t,b),c||l||h){const E=b.getBoundingClientRect();return{x:Math.floor(E.x-U.SafeBorderPadding),y:Math.floor(E.y-U.SafeBorderPadding),w:Math.floor(E.width+U.SafeBorderPadding*2),h:Math.floor(E.height+U.SafeBorderPadding*2)}}return{x:Math.floor(T.x*f[0]+p[0]-U.SafeBorderPadding),y:Math.floor(T.y*f[1]+p[1]-U.SafeBorderPadding),w:Math.floor(T.w*f[0]+2*U.SafeBorderPadding),h:Math.floor(T.h*f[1]+2*U.SafeBorderPadding)}}computDrawPoints(e){return this.tmpPoints[1].distance(this.tmpPoints[0])>this.arrowTipWidth?this.computFullArrowPoints(e):this.computTrianglePoints()}computFullArrowPoints(e){const t=C.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),i=C.Per(t).mul(e/2),s=V.Sub(this.tmpPoints[0],i),n=V.Add(this.tmpPoints[0],i),r=C.Mul(t,this.arrowTipWidth),c=C.Sub(this.tmpPoints[1],r),l=V.Sub(c,i),h=V.Add(c,i),u=C.Per(t).mul(e*1.5),d=V.Sub(c,u),p=V.Add(c,u),f=[this.tmpPoints[0],c],y=[d,this.tmpPoints[1],p],m=[s,n,...y,l,h];return{trianglePoints:y.map(T=>V.Sub(T,this.tmpPoints[1]).XY).flat(1),trianglePos:this.tmpPoints[1].XY,points:f.map(T=>V.Sub(T,this.tmpPoints[0]).XY).flat(1),rect:pe(m),isTriangle:!1,pos:this.tmpPoints[0].XY}}computTrianglePoints(){const e=C.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),t=this.tmpPoints[1].distance(this.tmpPoints[0]),i=C.Per(e).mul(Math.floor(t*3/8)),s=V.Sub(this.tmpPoints[0],i),n=V.Add(this.tmpPoints[0],i),r=[s,this.tmpPoints[1],n];return{trianglePoints:r.map(c=>V.Sub(c,this.tmpPoints[1]).XY).flat(1),trianglePos:this.tmpPoints[1].XY,rect:pe(r),isTriangle:!0}}updateTempPoints(e){const t=e.slice(-2),i=new V(t[0],t[1]),s=this.tmpPoints[0],{thickness:n}=this.workOptions;if(s.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 c,l;const{op:t,isFullWork:i}=e,s=(c=this.workId)==null?void 0:c.toString();if(!s)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new V(t[h],t[h+1],t[h+2]));const n=i?this.fullLayer:this.drawLayer||this.fullLayer,r=this.draw({workId:s,layer:n});return this.oldRect=r,(l=this.vNodes)==null||l.setInfo(s,{rect:r,op:t,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:U.getCenterPos(r,n)}),r}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var l,h;const{node:t,opt:i,vNodes:s}=e,{strokeColor:n,strokeType:r}=i,c=s.get(t.name);return n&&(t.tagName==="GROUP"?t.children.forEach(u=>{u.setAttribute("strokeColor",n),u.getAttribute("fillColor")&&u.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)),r&&(c!=null&&c.opt)&&((h=c.opt)!=null&&h.strokeType)&&(c.opt.strokeType=r),c&&s.setInfo(t.name,c),U.updateNodeOpt(e)}}class js extends U{constructor(e){super(e);g(this,"canRotate",!1);g(this,"scaleType",re.all);g(this,"toolsType",k.Ellipse);g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"oldRect");g(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:i,isSubWorker:s,isMainThread:n}=e,r=this.workId,{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:x.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new V(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:x.None};let u;if(s||n){const p=i?this.fullLayer:this.drawLayer||this.fullLayer;u=this.draw({workId:r,layer:p,isDrawing:!0})}if(!s){const p=Date.now();return p-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=p,{type:x.DrawWork,dataType:F.Local,...this.baseConsumeResult,op:this.tmpPoints.map(f=>[...f.XY,0]).flat(1),isSync:!0,index:0}):{type:x.None}}const d=ae(u,this.oldRect);return this.oldRect=u,{rect:d,type:x.DrawWork,dataType:F.Local,...this.baseConsumeResult}}consumeAll(){var r;const e=this.workId;if(this.tmpPoints.length<2)return{type:x.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=i;const s=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Re(s);return(r=this.vNodes)==null||r.setInfo(e,{rect:i,op:s,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:i&&U.getCenterPos(i,t)}),{rect:i,type:x.FullWork,dataType:F.Local,...this.baseConsumeResult,ops:n,isSync:!0}}draw(e){const{workId:t,layer:i,isDrawing:s}=e,{strokeColor:n,fillColor:r,thickness:c,zIndex:l,scale:h,rotate:u,translate:d,strokeType:p,eraserlines:f}=this.workOptions,y=i.worldScaling,{radius:m,rect:T,pos:w}=this.computDrawPoints(c),v={pos:w,name:t,id:t,radius:m,lineWidth:c,fillColor:r!=="transparent"&&r||void 0,strokeColor:n,normalize:!0,lineJoin:"round",lineCap:"round",lineDash:p===oe.Dotted?[1,c*2]:p===oe.LongDotted?[c,c*2]:void 0},S={name:t,id:t,zIndex:l,pos:w,anchor:[.5,.5],size:[T.w,T.h]};h&&(S.scale=h),u&&(S.rotate=u),d&&(S.translate=d);const N=new he.Group(S);if(s){const L=new he.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:n,lineWidth:1,scale:[1/y[0],1/y[1]]});N.append(L)}const I=new he.Ellipse({...v,pos:[0,0]});N.append(I),f&&(this.scaleType=re.proportional,this.drawEraserlines({group:N,eraserlines:f,pos:w,layer:i})),this.replace(i,t,N);const b=N.getBoundingClientRect();return{x:Math.floor(b.x-U.SafeBorderPadding),y:Math.floor(b.y-U.SafeBorderPadding),w:Math.floor(b.width+U.SafeBorderPadding*2),h:Math.floor(b.height+U.SafeBorderPadding*2)}}computDrawPoints(e){const t=pe(this.tmpPoints),i=pe(this.tmpPoints,e),s=[Math.floor(t.x+t.w/2),Math.floor(t.y+t.h/2)];return{rect:i,pos:s,radius:[Math.floor(t.w/2),Math.floor(t.h/2)]}}updateTempPoints(e){const t=e.slice(-2),i=new V(t[0],t[1]),s=this.tmpPoints[0],{thickness:n}=this.workOptions;if(s.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 c,l;const{op:t,isFullWork:i}=e,s=(c=this.workId)==null?void 0:c.toString();if(!s)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new V(t[h],t[h+1],t[h+2]));const n=i?this.fullLayer:this.drawLayer||this.fullLayer,r=this.draw({workId:s,layer:n,isDrawing:!1});return this.oldRect=r,(l=this.vNodes)==null||l.setInfo(s,{rect:r,op:t,opt:this.workOptions,toolsType:this.toolsType,canRotate:this.canRotate,scaleType:this.scaleType,centerPos:U.getCenterPos(r,n)}),r}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var u,d,p;const{node:t,opt:i,vNodes:s}=e,{strokeColor:n,fillColor:r,strokeType:c}=i,l=s.get(t.name);let h=t;return t.tagName==="GROUP"&&(h=t.children[0]),n&&(h.setAttribute("strokeColor",n),(u=l==null?void 0:l.opt)!=null&&u.strokeColor&&(l.opt.strokeColor=n)),r&&(r==="transparent"?h.setAttribute("fillColor","rgba(0,0,0,0)"):h.setAttribute("fillColor",r),(d=l==null?void 0:l.opt)!=null&&d.fillColor&&(l.opt.fillColor=r)),c&&(l!=null&&l.opt)&&((p=l.opt)!=null&&p.strokeType)&&(l.opt.strokeType=c),l&&s.setInfo(t.name,l),U.updateNodeOpt(e)}}class Es extends U{constructor(e){super(e);g(this,"canRotate",!0);g(this,"scaleType",re.all);g(this,"toolsType",k.Rectangle);g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"oldRect");g(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}transformData(){const e=pe(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 r of e)i.push(new C(...r));const s=pe(i,t),n=[s.x+s.w/2,s.y+s.h/2];return{rect:s,pos:n,points:i.map(r=>r.XY).flat(1)}}consume(e){const{data:t,isFullWork:i,isSubWorker:s,isMainThread:n}=e,r=this.workId,{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:x.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new V(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:x.None};const u=this.transformData();let d;if(s||n){const f=i?this.fullLayer:this.drawLayer||this.fullLayer;d=this.draw({ps:u,workId:r,layer:f,isDrawing:!0})}if(!s){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:x.DrawWork,dataType:F.Local,op:u.flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:x.None}}const p=ae(d,this.oldRect);return this.oldRect=d,{rect:p,type:x.DrawWork,dataType:F.Local,...this.baseConsumeResult}}consumeAll(){var c;const e=this.workId;if(this.tmpPoints.length<2)return{type:x.RemoveNode,removeIds:[e]};const t=this.transformData(),i=this.fullLayer,s=this.draw({ps:t,workId:e,layer:i,isDrawing:!1});this.oldRect=s;const n=t.flat(1),r=Re(n);return(c=this.vNodes)==null||c.setInfo(e,{rect:s,op:n,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:s&&U.getCenterPos(s,i)}),{rect:s,type:x.FullWork,dataType:F.Local,ops:r,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:i,isDrawing:s,ps:n,replaceId:r}=e,{strokeColor:c,fillColor:l,thickness:h,zIndex:u,scale:d,rotate:p,translate:f,strokeType:y,eraserlines:m}=this.workOptions,T=i.worldPosition,w=i.worldScaling,{points:v,rect:S,pos:N}=this.computDrawPoints(n),I={close:!0,normalize:!0,points:v,lineWidth:h,fillColor:l!=="transparent"&&l||void 0,strokeColor:c,lineJoin:"round",lineCap:"round",lineDash:y===oe.Dotted?[1,h*2]:y===oe.LongDotted?[h,h*2]:void 0},b={x:Math.floor(S.x*w[0]+T[0]-U.SafeBorderPadding),y:Math.floor(S.y*w[1]+T[1]-U.SafeBorderPadding),w:Math.floor(S.w*w[0]+2*U.SafeBorderPadding),h:Math.floor(S.h*w[0]+2*U.SafeBorderPadding)},L=new he.Group({name:t,id:t,zIndex:u,pos:N,anchor:[.5,.5],size:[S.w,S.h],scale:d,rotate:p,translate:f}),j=new he.Polyline({...I,pos:[0,0]});if(L.appendChild(j),s){const E=new he.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:c,lineWidth:1,scale:[1/w[0],1/w[1]]});L.appendChild(E)}if(m&&(this.scaleType=re.proportional,this.drawEraserlines({group:L,eraserlines:m,pos:N,layer:i})),this.replace(i,r||t,L),d||p||f){const E=L.getBoundingClientRect();return{x:Math.floor(E.x-U.SafeBorderPadding),y:Math.floor(E.y-U.SafeBorderPadding),w:Math.floor(E.width+2*U.SafeBorderPadding),h:Math.floor(E.height+2*U.SafeBorderPadding)}}return b}updateTempPoints(e){const t=e.slice(-2),i=new V(t[0],t[1]),s=this.tmpPoints[0],{thickness:n}=this.workOptions;if(s.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,u;const{op:t,isFullWork:i,replaceId:s}=e,n=(h=this.workId)==null?void 0:h.toString();if(!n)return;const r=[];for(let d=0;d<t.length;d+=3)r.push([t[d],t[d+1],t[d+2]]);const c=i?this.fullLayer:this.drawLayer||this.fullLayer,l=this.draw({ps:r,workId:n,layer:c,isDrawing:!1,replaceId:s});return this.oldRect=l,(u=this.vNodes)==null||u.setInfo(n,{rect:l,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:l&&U.getCenterPos(l,c)}),l}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var u,d,p;const{node:t,opt:i,vNodes:s}=e,{strokeColor:n,fillColor:r,strokeType:c}=i,l=s.get(t.name);let h=t;return t.tagName==="GROUP"&&(h=t.children[0]),n&&(h.setAttribute("strokeColor",n),(u=l==null?void 0:l.opt)!=null&&u.strokeColor&&(l.opt.strokeColor=n)),r&&(r==="transparent"?h.setAttribute("fillColor","rgba(0,0,0,0)"):h.setAttribute("fillColor",r),(d=l==null?void 0:l.opt)!=null&&d.fillColor&&(l.opt.fillColor=r)),c&&(l!=null&&l.opt)&&((p=l.opt)!=null&&p.strokeType)&&(l.opt.strokeType=c),l&&s.setInfo(t.name,l),U.updateNodeOpt(e)}}class Os extends U{constructor(e){super(e);g(this,"canRotate",!1);g(this,"scaleType",re.all);g(this,"toolsType",k.Star);g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"oldRect");g(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:i,isSubWorker:s,isMainThread:n}=e,r=this.workId,{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:x.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new V(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:x.None};let u;if(s||n){const p=i?this.fullLayer:this.drawLayer||this.fullLayer;u=this.draw({workId:r,layer:p,isDrawing:!0})}if(!s){const p=Date.now();return p-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=p,{type:x.DrawWork,dataType:F.Local,op:this.tmpPoints.map(f=>[...f.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:x.None}}const d=ae(u,this.oldRect);return this.oldRect=u,{rect:d,type:x.DrawWork,dataType:F.Local,...this.baseConsumeResult}}consumeAll(){var r;const e=this.workId;if(this.tmpPoints.length<2)return{type:x.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=i;const s=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Re(s);return(r=this.vNodes)==null||r.setInfo(e,{rect:i,op:s,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:i&&U.getCenterPos(i,t)}),{rect:i,type:x.FullWork,dataType:F.Local,ops:n,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:i,isDrawing:s}=e,{strokeColor:n,fillColor:r,thickness:c,zIndex:l,vertices:h,innerVerticeStep:u,innerRatio:d,scale:p,rotate:f,translate:y,strokeType:m,eraserlines:T}=this.workOptions,w=i.worldScaling,{rect:v,pos:S,points:N}=this.computDrawPoints(c,h,u,d),I={close:!0,points:N,lineWidth:c,fillColor:r!=="transparent"&&r||void 0,strokeColor:n,normalize:!0,lineJoin:"round",lineCap:"round",lineDash:m===oe.Dotted?[1,c*2]:m===oe.LongDotted?[c,c*2]:void 0},b={name:t,id:t,zIndex:l,pos:S,anchor:[.5,.5],size:[v.w,v.h]};p&&(b.scale=p),f&&(b.rotate=f),y&&(b.translate=y);const L=new he.Group(b);if(s){const A=new he.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:n,lineWidth:1,scale:[1/w[0],1/w[1]]});L.append(A)}const j=new he.Polyline({...I,pos:[0,0]});L.append(j),T&&(this.scaleType=re.proportional,this.drawEraserlines({group:L,eraserlines:T,pos:S,layer:i})),this.replace(i,t,L);const E=L.getBoundingClientRect();return{x:Math.floor(E.x-U.SafeBorderPadding),y:Math.floor(E.y-U.SafeBorderPadding),w:Math.floor(E.width+U.SafeBorderPadding*2),h:Math.floor(E.height+U.SafeBorderPadding*2)}}computDrawPoints(e,t,i,s){const n=pe(this.tmpPoints),r=[Math.floor(n.x+n.w/2),Math.floor(n.y+n.h/2)],c=qs(n.w,n.h),l=Math.floor(Math.min(n.w,n.h)/2),h=s*l,u=[],d=2*Math.PI/t;for(let f=0;f<t;f++){const y=f*d-.5*Math.PI;let m,T;f%i===1?(m=h*c[0]*Math.cos(y),T=h*c[1]*Math.sin(y)):(m=l*c[0]*Math.cos(y),T=l*c[1]*Math.sin(y),u.push(m,T)),u.push(m,T)}return{rect:pe(this.tmpPoints,e),pos:r,points:u}}updateTempPoints(e){const t=e.slice(-2),i=new V(t[0],t[1]),s=this.tmpPoints[0],{thickness:n}=this.workOptions;if(s.isNear(i,n)||V.Sub(s,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 c,l;const{op:t,isFullWork:i}=e,s=(c=this.workId)==null?void 0:c.toString();if(!s)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new V(t[h],t[h+1],t[h+2]));const n=i?this.fullLayer:this.drawLayer||this.fullLayer,r=this.draw({workId:s,layer:n,isDrawing:!1});return this.oldRect=r,(l=this.vNodes)==null||l.setInfo(s,{rect:r,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:r&&U.getCenterPos(r,n)}),r}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var m;const{node:t,opt:i,vNodes:s}=e,{strokeColor:n,fillColor:r,toolsType:c,vertices:l,innerVerticeStep:h,innerRatio:u,strokeType:d}=i,p=s.get(t.name),f=p==null?void 0:p.opt;let y=t;return t.tagName==="GROUP"&&(y=t.children[0]),n&&(y.setAttribute("strokeColor",n),f!=null&&f.strokeColor&&(f.strokeColor=n)),r&&(r==="transparent"?y.setAttribute("fillColor","rgba(0,0,0,0)"):y.setAttribute("fillColor",r),f!=null&&f.fillColor&&(f.fillColor=r)),c===k.Star&&(l&&(f.vertices=l),h&&(f.innerVerticeStep=h),u&&(f.innerRatio=u)),d&&(p!=null&&p.opt)&&((m=p.opt)!=null&&m.strokeType)&&(p.opt.strokeType=d),p&&s.setInfo(t.name,{...p,opt:f}),U.updateNodeOpt(e)}}class Rs extends U{constructor(e){super(e);g(this,"canRotate",!1);g(this,"scaleType",re.all);g(this,"toolsType",k.Polygon);g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"oldRect");g(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){const{data:t,isFullWork:i,isSubWorker:s,isMainThread:n}=e,{op:r}=t,c=this.workId,l=r==null?void 0:r.length;if(!l||l<2)return{type:x.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new V(r[0],r[1])],h=!1):h=this.updateTempPoints(r),!h)return{type:x.None};let u;if(s||n){const p=i?this.fullLayer:this.drawLayer||this.fullLayer;u=this.draw({workId:c,layer:p,isDrawing:!0})}if(!s){const p=Date.now();return p-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=p,{type:x.DrawWork,dataType:F.Local,op:this.tmpPoints.map(f=>[...f.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:x.None}}const d=ae(u,this.oldRect);return this.oldRect=u,{rect:d,type:x.DrawWork,dataType:F.Local,...this.baseConsumeResult}}consumeAll(){var r;const e=this.workId;if(this.tmpPoints.length<2)return{type:x.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=i;const s=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Re(s);return(r=this.vNodes)==null||r.setInfo(e,{rect:i,op:s,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:i&&U.getCenterPos(i,t)}),{rect:i,type:x.FullWork,dataType:F.Local,ops:n,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:i,isDrawing:s}=e,{strokeColor:n,fillColor:r,thickness:c,zIndex:l,vertices:h,scale:u,rotate:d,translate:p,strokeType:f,eraserlines:y}=this.workOptions,m=i.worldScaling,{rect:T,pos:w,points:v}=this.computDrawPoints(c,h),S={close:!0,points:v,lineWidth:c,fillColor:r!=="transparent"&&r||void 0,strokeColor:n,normalize:!0,lineJoin:"round",lineCap:"round",lineDash:f===oe.Dotted?[1,c*2]:f===oe.LongDotted?[c,c*2]:void 0},N={name:t,id:t,zIndex:l,pos:w,anchor:[.5,.5],size:[T.w,T.h]};u&&(N.scale=u),d&&(N.rotate=d),p&&(N.translate=p);const I=new he.Group(N);if(s){const j=new he.Path({d:"M-4,0H4M0,-4V4",normalize:!0,pos:[0,0],strokeColor:n,lineWidth:1,scale:[1/m[0],1/m[1]]});I.append(j)}const b=new he.Polyline({...S,pos:[0,0]});I.append(b),y&&(this.scaleType=re.proportional,this.drawEraserlines({group:I,eraserlines:y,pos:w,layer:i})),this.replace(i,t,I);const L=I.getBoundingClientRect();return{x:Math.floor(L.x-U.SafeBorderPadding),y:Math.floor(L.y-U.SafeBorderPadding),w:Math.floor(L.width+U.SafeBorderPadding*2),h:Math.floor(L.height+U.SafeBorderPadding*2)}}computDrawPoints(e,t){const i=pe(this.tmpPoints),s=[Math.floor(i.x+i.w/2),Math.floor(i.y+i.h/2)],n=qs(i.w,i.h),r=Math.floor(Math.min(i.w,i.h)/2),c=[],l=2*Math.PI/t;for(let u=0;u<t;u++){const d=u*l-.5*Math.PI,p=r*n[0]*Math.cos(d),f=r*n[1]*Math.sin(d);c.push(p,f)}return{rect:pe(this.tmpPoints,e),pos:s,points:c}}updateTempPoints(e){const t=e.slice(-2),i=new V(t[0],t[1]),s=this.tmpPoints[0],{thickness:n}=this.workOptions;if(s.isNear(i,n)||V.Sub(s,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 c,l;const{op:t,isFullWork:i}=e,s=(c=this.workId)==null?void 0:c.toString();if(!s)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new V(t[h],t[h+1],t[h+2]));const n=i?this.fullLayer:this.drawLayer||this.fullLayer,r=this.draw({workId:s,layer:n,isDrawing:!1});return this.oldRect=r,(l=this.vNodes)==null||l.setInfo(s,{rect:r,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:r&&U.getCenterPos(r,n)}),r}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var f;const{node:t,opt:i,vNodes:s}=e,{strokeColor:n,fillColor:r,toolsType:c,vertices:l,strokeType:h}=i,u=s.get(t.name),d=u==null?void 0:u.opt;let p=t;return t.tagName==="GROUP"&&(p=t.children[0]),n&&(p.setAttribute("strokeColor",n),d!=null&&d.strokeColor&&(d.strokeColor=n)),r&&(r==="transparent"?p.setAttribute("fillColor","rgba(0,0,0,0)"):p.setAttribute("fillColor",r),d!=null&&d.fillColor&&(d.fillColor=r)),c===k.Polygon&&l&&(d.vertices=l),h&&(u!=null&&u.opt)&&((f=u.opt)!=null&&f.strokeType)&&(u.opt.strokeType=h),u&&s.setInfo(t.name,{...u,opt:d}),U.updateNodeOpt(e)}}class He{static bezier(o,e){const t=[];for(let i=0;i<e.length;i+=4){const s=e[i],n=e[i+1],r=e[i+2],c=e[i+3];s&&n&&r&&c?t.push(...He.getBezierPoints(o,s,n,r,c)):s&&n&&r?t.push(...He.getBezierPoints(o,s,n,r)):s&&n?t.push(...He.getBezierPoints(o,s,n)):s&&t.push(s)}return t}static getBezierPoints(o=10,e,t,i,s){let n=null;const r=[];!i&&!s?n=He.oneBezier:i&&!s?n=He.twoBezier:i&&s&&(n=He.threeBezier);for(let c=0;c<o;c++)n&&r.push(n(c/o,e,t,i,s));return s?r.push(s):i&&r.push(i),r}static oneBezier(o,e,t){const i=e.x+(t.x-e.x)*o,s=e.y+(t.y-e.y)*o;return new C(i,s)}static twoBezier(o,e,t,i){const s=(1-o)*(1-o)*e.x+2*o*(1-o)*t.x+o*o*i.x,n=(1-o)*(1-o)*e.y+2*o*(1-o)*t.y+o*o*i.y;return new C(s,n)}static threeBezier(o,e,t,i,s){const n=e.x*(1-o)*(1-o)*(1-o)+3*t.x*o*(1-o)*(1-o)+3*i.x*o*o*(1-o)+s.x*o*o*o,r=e.y*(1-o)*(1-o)*(1-o)+3*t.y*o*(1-o)*(1-o)+3*i.y*o*o*(1-o)+s.y*o*o*o;return new C(n,r)}}class Ys extends U{constructor(e){super(e);g(this,"canRotate",!1);g(this,"scaleType",re.all);g(this,"toolsType",k.SpeechBalloon);g(this,"ratio",.8);g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"oldRect");g(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.syncTimestamp=0,this.syncUnitTime=50}consume(e){var p;const{data:t,isFullWork:i,isSubWorker:s,isMainThread:n}=e,r=(p=t==null?void 0:t.workId)==null?void 0:p.toString();if(!r)return{type:x.None};const{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:x.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new V(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:x.None};let u;if(s||n){const f=i?this.fullLayer:this.drawLayer||this.fullLayer;u=this.draw({workId:r,layer:f,isDrawing:!0})}if(!s){const f=Date.now();return f-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=f,{type:x.DrawWork,dataType:F.Local,op:this.tmpPoints.map(y=>[...y.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:x.None}}const d=ae(u,this.oldRect);return this.oldRect=u,{rect:d,type:x.DrawWork,dataType:F.Local,...this.baseConsumeResult}}consumeAll(){var r;const e=this.workId;if(this.tmpPoints.length<2)return{type:x.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t,isDrawing:!1});this.oldRect=i;const s=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Re(s);return(r=this.vNodes)==null||r.setInfo(e,{rect:i,op:s,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:i&&U.getCenterPos(i,t)}),{rect:i,type:x.FullWork,dataType:F.Local,ops:n,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:i}=e,{strokeColor:s,fillColor:n,thickness:r,zIndex:c,placement:l,scale:h,rotate:u,translate:d,strokeType:p,eraserlines:f}=this.workOptions,{rect:y,pos:m,points:T}=this.computDrawPoints(r,l),w={points:T.map(b=>b.XY),lineWidth:r,fillColor:n!=="transparent"&&n||void 0,strokeColor:s,normalize:!0,className:`${m[0]},${m[1]}`,close:!0,lineJoin:"round",lineCap:"round",lineDash:p===oe.Dotted?[1,r*2]:p===oe.LongDotted?[r,r*2]:void 0},v={name:t,id:t,zIndex:c,pos:m,anchor:[.5,.5],size:[y.w,y.h]};h&&(v.scale=h),u&&(v.rotate=u),d&&(v.translate=d);const S=new he.Group(v),N=new he.Polyline({...w,pos:[0,0]});S.append(N),f&&(this.scaleType=re.proportional,this.drawEraserlines({group:S,eraserlines:f,pos:m,layer:i})),this.replace(i,t,S);const I=S.getBoundingClientRect();return{x:Math.floor(I.x-U.SafeBorderPadding),y:Math.floor(I.y-U.SafeBorderPadding),w:Math.floor(I.width+U.SafeBorderPadding*2),h:Math.floor(I.height+U.SafeBorderPadding*2)}}transformControlPoints(e){const t=pe(this.tmpPoints);switch(e){case"bottom":case"bottomLeft":case"bottomRight":{const i=t.y+t.h*this.ratio;return[new C(t.x,t.y,0),new C(t.x+t.w,t.y,0),new C(t.x+t.w,i,0),new C(t.x,i,0)]}case"top":case"topLeft":case"topRight":{const i=t.y+t.h*(1-this.ratio);return[new C(t.x,i,0),new C(t.x+t.w,i,0),new C(t.x+t.w,t.y+t.h,0),new C(t.x,t.y+t.h,0)]}case"left":case"leftBottom":case"leftTop":{const i=t.x+t.w*(1-this.ratio);return[new C(i,t.y,0),new C(t.x+t.w,t.y,0),new C(t.x+t.w,t.y+t.h,0),new C(i,t.y+t.h,0)]}case"right":case"rightBottom":case"rightTop":{const i=t.x+t.w*this.ratio;return[new C(t.x,t.y,0),new C(i,t.y,0),new C(i,t.y+t.h,0),new C(t.x,t.y+t.h,0)]}}}computDrawPoints(e,t){const i=pe(this.tmpPoints),s=this.transformControlPoints(t),n=Math.floor(i.w*.1),r=Math.floor(i.h*.1),c=[],l=C.Add(s[0],new C(0,r,0)),h=C.Add(s[0],new C(n,0,0)),u=He.getBezierPoints(10,l,s[0],h),d=C.Sub(s[1],new C(n,0,0)),p=C.Add(s[1],new C(0,r,0)),f=He.getBezierPoints(10,d,s[1],p),y=C.Sub(s[2],new C(0,r,0)),m=C.Sub(s[2],new C(n,0,0)),T=He.getBezierPoints(10,y,s[2],m),w=C.Add(s[3],new C(n,0,0)),v=C.Sub(s[3],new C(0,r,0)),S=He.getBezierPoints(10,w,s[3],v),N=n*(1-this.ratio)*10,I=r*(1-this.ratio)*10;switch(t){case"bottom":{const j=C.Sub(s[2],new C(n*5-N/2,0,0)),E=C.Sub(s[2],new C(n*5,-I,0)),A=C.Sub(s[2],new C(n*5+N/2,0,0));c.push(E,A,...S,...u,...f,...T,j);break}case"bottomRight":{const j=C.Sub(s[2],new C(n*1.1,0,0)),E=C.Sub(s[2],new C(n*1.1+N/2,-I,0)),A=C.Sub(s[2],new C(n*1.1+N,0,0));c.push(E,A,...S,...u,...f,...T,j);break}case"bottomLeft":{const j=C.Add(s[3],new C(n*1.1+N,0,0)),E=C.Add(s[3],new C(n*1.1+N/2,I,0)),A=C.Add(s[3],new C(n*1.1,0,0));c.push(E,A,...S,...u,...f,...T,j);break}case"top":{const j=C.Sub(s[1],new C(n*5-N/2,0,0)),E=C.Sub(s[1],new C(n*5,I,0)),A=C.Sub(s[1],new C(n*5+N/2,0,0));c.push(E,j,...f,...T,...S,...u,A);break}case"topRight":{const j=C.Sub(s[1],new C(n*1.1,0,0)),E=C.Sub(s[1],new C(n*1.1+N/2,I,0)),A=C.Sub(s[1],new C(n*1.1+N,0,0));c.push(E,j,...f,...T,...S,...u,A);break}case"topLeft":{const j=C.Add(s[0],new C(n*1.1+N,0,0)),E=C.Add(s[0],new C(n*1.1+N/2,-I,0)),A=C.Add(s[0],new C(n*1.1,0,0));c.push(E,j,...f,...T,...S,...u,A);break}case"left":{const j=C.Add(s[0],new C(0,r*5-I/2,0)),E=C.Add(s[0],new C(-N,r*5,0)),A=C.Add(s[0],new C(0,r*5+I/2,0));c.push(E,j,...u,...f,...T,...S,A);break}case"leftTop":{const j=C.Add(s[0],new C(0,r*1.1,0)),E=C.Add(s[0],new C(-N,r*1.1+I/2,0)),A=C.Add(s[0],new C(0,r*1.1+I,0));c.push(E,j,...u,...f,...T,...S,A);break}case"leftBottom":{const j=C.Sub(s[3],new C(0,r*1.1+I,0)),E=C.Sub(s[3],new C(N,r*1.1+I/2,0)),A=C.Sub(s[3],new C(0,r*1.1,0));c.push(E,j,...u,...f,...T,...S,A);break}case"right":{const j=C.Add(s[1],new C(0,r*5-I/2,0)),E=C.Add(s[1],new C(N,r*5,0)),A=C.Add(s[1],new C(0,r*5+I/2,0));c.push(E,A,...T,...S,...u,...f,j);break}case"rightTop":{const j=C.Add(s[1],new C(0,r*1.1,0)),E=C.Add(s[1],new C(N,r*1.1+I/2,0)),A=C.Add(s[1],new C(0,r*1.1+I,0));c.push(E,A,...T,...S,...u,...f,j);break}case"rightBottom":{const j=C.Sub(s[2],new C(0,r*1.1+I,0)),E=C.Sub(s[2],new C(-N,r*1.1+I/2,0)),A=C.Sub(s[2],new C(0,r*1.1,0));c.push(E,A,...T,...S,...u,...f,j);break}}const b=pe(this.tmpPoints,e),L=[Math.floor(b.x+b.w/2),Math.floor(b.y+b.h/2)];return{rect:b,pos:L,points:c}}updateTempPoints(e){const t=e.slice(-2),i=new V(t[0],t[1]),s=this.tmpPoints[0],{thickness:n}=this.workOptions;if(s.isNear(i,n)||V.Sub(s,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 c,l;const{op:t,isFullWork:i}=e,s=(c=this.workId)==null?void 0:c.toString();if(!s)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new V(t[h],t[h+1],t[h+2]));const n=i?this.fullLayer:this.drawLayer||this.fullLayer,r=this.draw({workId:s,layer:n,isDrawing:!1});return this.oldRect=r,(l=this.vNodes)==null||l.setInfo(s,{rect:r,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:r&&U.getCenterPos(r,n)}),r}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var f;const{node:t,opt:i,vNodes:s}=e,{strokeColor:n,fillColor:r,toolsType:c,placement:l,strokeType:h}=i,u=s.get(t.name),d=u==null?void 0:u.opt;let p=t;return t.tagName==="GROUP"&&(p=t.children[0]),n&&(p.setAttribute("strokeColor",n),d!=null&&d.strokeColor&&(d.strokeColor=n)),r&&(r==="transparent"?p.setAttribute("fillColor","rgba(0,0,0,0)"):p.setAttribute("fillColor",r),d!=null&&d.fillColor&&(d.fillColor=r)),c===k.SpeechBalloon&&l&&(d.placement=l),h&&(u!=null&&u.opt)&&((f=u.opt)!=null&&f.strokeType)&&(u.opt.strokeType=h),u&&s.setInfo(t.name,{...u,opt:d}),U.updateNodeOpt(e)}}var Bf=ut,Ff=qe,Vf="[object Boolean]";function $f(a){return a===!0||a===!1||Ff(a)&&Bf(a)==Vf}var Hf=$f;const yt=St(Hf);class Ws extends U{constructor(e){super(e);g(this,"canRotate",!1);g(this,"scaleType",re.both);g(this,"toolsType",k.Straight);g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"oldRect");g(this,"straightTipWidth");g(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:s,isMainThread:n}=e,r=this.workId,{op:c}=t,l=c==null?void 0:c.length;if(!l||l<2)return{type:x.None};let h;if(this.tmpPoints.length===0?(this.tmpPoints=[new V(c[0],c[1])],h=!1):h=this.updateTempPoints(c),!h)return{type:x.None};let u;if(s||n){const p=i?this.fullLayer:this.drawLayer||this.fullLayer;u=this.draw({workId:r,layer:p})}if(!s){const p=Date.now();return p-this.syncTimestamp>this.syncUnitTime?(this.syncTimestamp=p,{type:x.DrawWork,dataType:F.Local,op:this.tmpPoints.map(f=>[...f.XY,0]).flat(1),isSync:!0,index:0,...this.baseConsumeResult}):{type:x.None}}const d=ae(u,this.oldRect);return this.oldRect=u,{rect:d,type:x.DrawWork,dataType:F.Local,...this.baseConsumeResult}}consumeAll(){var r;const e=this.workId;if(this.tmpPoints.length<2)return{type:x.RemoveNode,removeIds:[e]};const t=this.fullLayer,i=this.draw({workId:e,layer:t});this.oldRect=i;const s=this.tmpPoints.map(c=>[...c.XY,0]).flat(1),n=Re(s);return(r=this.vNodes)==null||r.setInfo(e,{rect:i,op:s,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:i&&U.getCenterPos(i,t)}),{rect:i,type:x.FullWork,dataType:F.Local,ops:n,isSync:!0,...this.baseConsumeResult}}draw(e){const{workId:t,layer:i}=e,{strokeColor:s,thickness:n,zIndex:r,scale:c,rotate:l,translate:h,strokeType:u,eraserlines:d}=this.workOptions,p=i.worldPosition,f=i.worldScaling,{d:y,rect:m,isDot:T}=this.computDrawPoints(n,u),w=[m.x+m.w/2,m.y+m.h/2],v=new he.Group({pos:w,anchor:[.5,.5],size:[m.w,m.h],name:t,id:t,normalize:!0,zIndex:r}),S={pos:[0,0],normalize:!0,d:y,fillColor:s,strokeColor:s,lineDash:u===oe.Dotted&&!T?[1,n*2]:u===oe.LongDotted&&!T?[n,n*2]:void 0,lineCap:u===oe.Normal||T?void 0:"round",lineWidth:u===oe.Normal||T?0:n};c&&(S.scale=c),l&&(S.rotate=l),h&&(S.translate=h);const N=new he.Path(S);if(v.append(N),d&&(this.scaleType=re.proportional,this.drawEraserlines({group:v,eraserlines:d,pos:w,layer:i})),this.replace(i,t,v),l||c||h){const b=N.getBoundingClientRect();return{x:Math.floor(b.x-U.SafeBorderPadding),y:Math.floor(b.y-U.SafeBorderPadding),w:Math.floor(b.width+U.SafeBorderPadding*2),h:Math.floor(b.height+U.SafeBorderPadding*2)}}return{x:Math.floor(m.x*f[0]+p[0]-U.SafeBorderPadding),y:Math.floor(m.y*f[1]+p[1]-U.SafeBorderPadding),w:Math.floor(m.w*f[0]+2*U.SafeBorderPadding),h:Math.floor(m.h*f[1]+2*U.SafeBorderPadding)}}computDrawPoints(e,t){return this.tmpPoints[1].distance(this.tmpPoints[0])>this.straightTipWidth?this.computFullPoints(e,t):this.computDotPoints(e)}computFullPoints(e,t){const i=C.Sub(this.tmpPoints[1],this.tmpPoints[0]).uni(),s=C.Per(i).mul(e/2),n=V.Sub(this.tmpPoints[0],s),r=V.Add(this.tmpPoints[0],s),c=V.Sub(this.tmpPoints[1],s),l=V.Add(this.tmpPoints[1],s),h=V.GetSemicircleStroke(this.tmpPoints[1],c,-1,8),u=V.GetSemicircleStroke(this.tmpPoints[0],r,-1,8),d=[n,c,...h,l,r,...u];let p;return t!==oe.Normal?p=tt(this.tmpPoints,!1):p=tt(d,!0),{d:p,rect:pe(d),isDot:!1,pos:this.tmpPoints[0].XY}}computDotPoints(e){const t=V.GetDotStroke(this.tmpPoints[0],e/2,8);return{d:tt(t,!0),rect:pe(t),isDot:!0,pos:this.tmpPoints[0].XY}}updateTempPoints(e){const t=e.slice(-2),i=new V(t[0],t[1]),s=this.tmpPoints[0],{thickness:n}=this.workOptions;if(s.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 c,l;const{op:t,isFullWork:i}=e,s=(c=this.workId)==null?void 0:c.toString();if(!s)return;this.tmpPoints.length=0;for(let h=0;h<t.length;h+=3)this.tmpPoints.push(new V(t[h],t[h+1],t[h+2]));const n=i?this.fullLayer:this.drawLayer||this.fullLayer,r=this.draw({workId:s,layer:n});return this.oldRect=r,(l=this.vNodes)==null||l.setInfo(s,{rect:r,op:t,opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:r&&U.getCenterPos(r,n)}),r}clearTmpPoints(){this.tmpPoints.length=0}static updateNodeOpt(e){var l,h;const{node:t,opt:i,vNodes:s}=e,{strokeColor:n,strokeType:r}=i,c=s.get(t.name);return n&&(t.tagName==="GROUP"?t.children.forEach(u=>{u.setAttribute("strokeColor",n),u.getAttribute("fillColor")&&u.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)),r&&(c!=null&&c.opt)&&((h=c.opt)!=null&&h.strokeType)&&(c.opt.strokeType=r),c&&s.setInfo(t.name,c),U.updateNodeOpt(e)}}const _e=class _e extends U{constructor(e){super(e);g(this,"canRotate",!1);g(this,"scaleType",re.proportional);g(this,"toolsType",k.Text);g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"oldRect");this.workOptions=e.toolsOpt}consume(){return{type:x.None}}consumeAll(){return{type:x.None}}consumeService(){}async draw(e){const{workId:t,layer:i,isDrawLabel:s}=e,{boxSize:n,boxPoint:r,zIndex:c}=this.workOptions,l=i.worldPosition,h=i.worldScaling;if(!r||!n)return;const u={name:t,id:t,pos:[r[0],r[1]],anchor:[0,0],size:n,zIndex:c},d=new he.Group(u),p={x:r[0],y:r[1],w:n[0],h:n[1]},f={x:Math.floor(p.x*h[0]+l[0]),y:Math.floor(p.y*h[1]+l[1]),w:Math.floor(p.w*h[0])+2,h:Math.floor(p.h*h[1])+2};if(this.replace(i,t,d),s&&i&&this.workOptions.text){const y=await _e.createLabels(this.workOptions,i,f),{labels:m,maxWidth:T}=y;d.append(...m),f.w=Math.ceil(Math.max(T*i.worldScaling[0],f.w))}return f}async consumeServiceAsync(e){var l,h,u,d;const t=(l=this.workId)==null?void 0:l.toString();if(!t)return;const{isFullWork:i,replaceId:s,isDrawLabel:n}=e;this.oldRect=s&&((u=(h=this.vNodes)==null?void 0:h.get(s))==null?void 0:u.rect)||void 0;const r=i?this.fullLayer:this.drawLayer||this.fullLayer,c=await this.draw({workId:t,layer:r,isDrawLabel:typeof n>"u"&&this.workOptions.workState===P.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&&U.getCenterPos(c,r)}),c}updataOptService(){}async updataOptServiceAsync(e,t){var f,y;if(!this.workId)return;const i=this.workId.toString(),{fontColor:s,fontBgColor:n,bold:r,italic:c,lineThrough:l,underline:h,zIndex:u}=e,d=(f=this.vNodes)==null?void 0:f.get(i);if(!d)return;s&&(d.opt.fontColor=s),n&&(d.opt.fontBgColor=n),r&&(d.opt.bold=r),c&&(d.opt.italic=c),yt(l)&&(d.opt.lineThrough=l),yt(h)&&(d.opt.underline=h),Oe(u)&&(d.opt.zIndex=u),this.oldRect=d.rect;const p=await this.draw({workId:i,layer:this.fullLayer,isDrawLabel:typeof t>"u"&&this.workOptions.workState===P.Done||t});return(y=this.vNodes)==null||y.setInfo(i,{rect:p,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:p&&U.getCenterPos(p,this.fullLayer)}),p}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 s=i;return i>=.2&&i<1?s=i*t:i<=2&&i>=1?s=i*t*1.6:i>2&&i<=3?s=i*t*1.4:i>3&&i<=4?s=i*t*.8:i>4&&(s=i*t*.6),Math.floor(s*1e3)/1e3}static getSafetySnippetFontLength(e){return Math.floor(_e.textImageSnippetSize*3/4/e)||1}static async createLabels(e,t,i){var A;const s=[],{x:n,y:r}=i,{width:c,height:l}=(A=t.parent)==null?void 0:A.parent,h=it(e.text),u=h.length,{fontSize:d,lineHeight:p,bold:f,textAlign:y,italic:m,fontFamily:T,verticalAlign:w,fontColor:v,fontBgColor:S,underline:N,lineThrough:I}=e,b=_e.getSafetySnippetRatio(t)||1,L=Math.floor(d*b),j=_e.getSafetySnippetFontLength(L);let E=0;for(let W=0;W<u;W++){const z=h[W],O=p||L*1.5;if(z){const ne=vM(z),te=[0,0],Q=[0,d*1.2];w==="middle"&&(te[1]=W*d*1.2+5);const X=[0,-d*.15];te[0]=5;const G=Math.sin(Math.PI/180*20);let Z=0;const K=[];let ce=0;for(;ce<ne;){y==="left"&&(X[0]=Z),ce===0&&m==="italic"&&(X[0]=X[0]-G/2*d);const ie=z.slice(ce,ce+j),le={anchor:[0,0],pos:X,text:ie,fontFamily:T,fontSize:L,lineHeight:O,strokeColor:v,fontWeight:f,fillColor:v,textAlign:y,fontStyle:m,scale:[1/b,1/b]},J=new he.Label(le),$=await J.textImageReady;let ue=!0;if($){const fe=$.rect&&$.rect[2],je=$.rect&&$.rect[3];if(fe&&je){const ve=fe/b,me=je/b;Z=ve+Z,m==="italic"&&(f==="bold"?Z=Z-G*d*1.2:Z=Z-G*d),((X[0]+te[0]+ve)*t.worldScaling[0]+n<=0||(X[0]+te[0])*t.worldScaling[0]+n>=c||(X[1]+te[1]+me)*t.worldScaling[1]+r<=0||(X[1]+te[1])*t.worldScaling[1]+r>=l)&&(J.disconnect(),ue=!1),ue&&K.push(J)}}ce+=j}Q[0]=Z,m==="italic"&&(Q[0]=Q[0]+G*d),E=Math.max(E,Q[0]);let Te=!0;if(((te[0]+Q[0])*t.worldScaling[0]+n<=0||te[0]*t.worldScaling[0]+n>=c||(te[1]+Q[1])*t.worldScaling[0]+r<=0||te[1]*t.worldScaling[1]+r>=l)&&(Te=!1),Te){if(N){const J=Math.floor(d/10),$={normalize:!1,pos:[0,d*1.1+J/2],lineWidth:J,points:[0,0,Math.ceil(Q[0]),0],strokeColor:v,className:"underline"},ue=new he.Polyline($);K.push(ue)}if(I){const J={normalize:!1,pos:[0,d*1.2/2],lineWidth:Math.floor(d/10),points:[0,0,Math.ceil(Q[0]),0],strokeColor:v,className:"lineThrough"},$=new he.Polyline(J);K.push($)}const ie={pos:te,anchor:[0,0],size:Q,bgcolor:S},le=new he.Group(ie);le.append(...K),s.push(le)}}}return{labels:s,maxWidth:E}}static updateNodeOpt(e){const{node:t,opt:i,vNodes:s,targetNode:n}=e,{fontBgColor:r,fontColor:c,translate:l,originPoint:h,scenePoint:u,scale:d,bold:p,italic:f,lineThrough:y,underline:m,fontSize:T,textInfos:w,zIndex:v}=i,S=n&&Ce(n)||s.get(t.name);if(!S||!t.parent)return;const I=S.opt;if(Oe(v)&&(t.setAttribute("zIndex",v),S.opt.zIndex=v),c&&I.fontColor&&(I.fontColor=c,t.children.forEach(b=>{b.tagName==="GROUP"&&b.children.forEach(L=>{L.tagName==="LABEL"?(L.setAttribute("fillColor",c),L.setAttribute("strokeColor",c)):L.tagName==="POLYLINE"&&L.setAttribute("strokeColor",c)})})),r&&I.fontBgColor&&(I.fontBgColor=r,t.children.forEach(b=>{b.tagName==="GROUP"&&b.setAttribute("bgcolor",r)})),p&&(I.bold=p),f&&(I.italic=f),yt(y)&&(I.lineThrough=y),yt(m)&&(I.underline=m),T&&(I.fontSize=T),h&&u&&d&&n&&I.boxPoint){const b=w==null?void 0:w.get(t.name);if(b){const{fontSize:A,boxSize:W}=b;I.boxSize=W||I.boxSize,I.fontSize=A||I.fontSize}const L=[I.boxPoint[0],I.boxPoint[1]];oi(I.boxPoint,u,d,l);const j=[S.op[0],S.op[1]],E=[j[0]-L[0],j[1]-L[1]];if(S.centerPos=[S.centerPos[0]+E[0],S.centerPos[1]+E[1]],S.opt.eraserlines)for(const A of Object.values(S.opt.eraserlines)){const{op:W,thickness:z}=A;A.thickness=z*Math.max(d[0],d[1]);for(let O=0;O<W.length;O++)ii(W[O],u,d,l)}}else if(l&&I.boxPoint&&(I.boxPoint=[I.boxPoint[0]+l[0],I.boxPoint[1]+l[1]],S.centerPos=[S.centerPos[0]+l[0],S.centerPos[1]+l[1]],S.opt.eraserlines))for(const b of Object.values(S.opt.eraserlines)){const{op:L}=b;for(let j=0;j<L.length;j++){const E=L[j].map((A,W)=>W%2?A+l[1]:A+l[0]);b.op[j]=E}}return S&&s.setInfo(t.name,S),S==null?void 0:S.rect}static getRectFromLayer(e,t){const i=e.getElementsByName(t)[0];if(i){const s=i.getBoundingClientRect();let n={x:Math.floor(s.x),y:Math.floor(s.y),w:Math.floor(s.width+2),h:Math.floor(s.height+2)};return i.children.forEach(r=>{if(r.tagName==="GROUP"){const c=i.getBoundingClientRect();n=ae(n,{x:Math.floor(c.x),y:Math.floor(c.y),w:Math.floor(c.width+2),h:Math.floor(c.height+2)})}}),n}}};g(_e,"textImageSnippetSize",1024*4),g(_e,"SafeBorderPadding",30);let eo=_e;const mt=class mt extends U{constructor(e,t){super(e);g(this,"canRotate",!1);g(this,"scaleType",re.none);g(this,"toolsType",k.PencilEraser);g(this,"serviceWork");g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"worldPosition");g(this,"worldScaling");g(this,"eraserRect");g(this,"eraserPolyline");this.serviceWork=t,this.workOptions=e.toolsOpt,this.worldPosition=this.fullLayer.worldPosition,this.worldScaling=this.fullLayer.worldScaling}consumeService(){}createEraserRect(e){const t=e[0]*this.worldScaling[0]+this.worldPosition[0],i=e[1]*this.worldScaling[1]+this.worldPosition[1],{width:s,height:n}=mt.eraserSizes[this.workOptions.thickness];this.eraserRect={x:t-s*.5,y:i-n*.5,w:s,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 C(this.tmpPoints[0],this.tmpPoints[1]),i=new C(this.tmpPoints[2],this.tmpPoints[3]),s=C.Sub(i,t).uni(),n=C.Dist(t,i),{width:r,height:c}=mt.eraserSizes[this.workOptions.thickness],l=Math.min(r,c),h=Math.round(n/l);if(h>1){const u=[];for(let d=0;d<h;d++){const p=C.Mul(s,d*l);u.push(this.tmpPoints[0]+p.x,this.tmpPoints[1]+p.y)}return u.concat(e)}}return e}isNear(e,t){const i=new C(e[0],e[1]),s=new C(t[0],t[1]),{width:n,height:r}=mt.eraserSizes[this.workOptions.thickness];return C.Dist(i,s)<Math.hypot(n,r)*.5}cutPolyline(e,t){let i=[t],s=0;for(;s<e.length;){const c=e[s];if(c.length<2)break;i=n(i,c),s++}return i;function n(c,l){const h=c;for(let u=0;u<c.length;u++){const d=c[u],p=d.findIndex((f,y)=>y<d.length-1?r([f,d[y+1]],[l[0],l[1]]):!1);if(p!==-1&&p>-1){const f=[],y=d.slice(0,p+1);if(C.Equals(d[p],l[0])||y.push(l[0].clone().setz(d[p].z)),y.length>1&&f.push(y),p+l.length-1<d.length-1){const m=p+l.length-1,T=d.slice(m),w=l[l.length-1];C.Equals(d[m],w)||T.unshift(w.clone().setz(d[m].z)),T.length>1&&f.push(T)}return h.splice(u,1,...f),h}}return h}function r(c,l){const h=C.Sub(c[1],c[0]),u=C.Sub(l[1],l[0]),d=C.Sub(l[0],c[0]);return Math.abs(C.Cpr(h,u))<.1&&Math.abs(C.Cpr(h,d))<.1}}isSamePoint(e,t){return e[0]===t[0]&&e[1]===t[1]}translateIntersect(e){const t=[];for(let i=0;i<e.length;i++){const s=e[i].filter((c,l,h)=>!(l>0&&this.isSamePoint(c,h[l-1]))),n=[];let r=0;for(;r<s.length;){const c=s[r],l=new C(c[0],c[1]);n.push(l),r++}t.push(n)}return t}isLineEraser(e,t){return!(e===k.Pencil&&!t)}remove(e){const{curNodeMap:t,removeIds:i,newWorkDatas:s}=e;let n;for(const[r,c]of t.entries())if(c.rect&&this.eraserRect&&this.eraserPolyline&&Yt(this.eraserRect,c.rect)){const{op:l,toolsType:h}=c,u=this.isLineEraser(h,!1),d=[],p=[];for(let y=0;y<l.length;y+=3){const m=new C(l[y]*this.worldScaling[0]+this.worldPosition[0],l[y+1]*this.worldScaling[1]+this.worldPosition[1],l[y+2]);p.push(m),d.push(new V(m.x,m.y))}const f=d.length&&pe(d)||c.rect;if(Yt(f,this.eraserRect)){if(p.length>1){const y=Wo.polyline(p.map(m=>m.XY),this.eraserPolyline);if(y.length&&(i.add(c.name),!u)){const m=this.translateIntersect(y),T=this.cutPolyline(m,p);for(let w=0;w<T.length;w++){const v=`${r}_s_${w}`,S=[];T[w].forEach(N=>{S.push((N.x-this.worldPosition[0])/this.worldScaling[0],(N.y-this.worldPosition[1])/this.worldScaling[1],N.z)}),c.opt&&c.toolsType&&this.vNodes&&(this.vNodes.setInfo(v,{rect:f,op:S,opt:c.opt,canRotate:c.canRotate,scaleType:c.scaleType,toolsType:c.toolsType}),s.set(v,{workId:v,op:S,opt:c.opt,toolsType:c.toolsType}))}}}else i.add(c.name);n=ae(n,f)}}return i.forEach(r=>{var c;return(c=this.vNodes)==null?void 0:c.delete(r)}),n&&(n.x-=U.SafeBorderPadding,n.y-=U.SafeBorderPadding,n.w+=U.SafeBorderPadding*2,n.h+=U.SafeBorderPadding*2),n}consume(e){const{op:t,disableEraseImage:i,disableEraseText:s}=e.data;if(!t||t.length===0)return{type:x.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:x.None,...this.baseConsumeResult};n<3?this.tmpPoints.push(t[0],t[1]):this.tmpPoints.splice(2,2,t[0],t[1]);const r=this.computRectCenterPoints();let c;const l=new Set,h=new Map;if(!this.vNodes)return{type:x.None,...this.baseConsumeResult};this.vNodes.setTarget();const u=this.getCanEraserNodeMap(this.vNodes.getCanEraserNodes(this.vNodes.getLastTarget(),{disableEraseImage:i,disableEraseText:s}));for(let d=0;d<r.length-1;d+=2){this.createEraserRect(r.slice(d,d+2));const p=this.remove({curNodeMap:u,removeIds:l,newWorkDatas:h});c=ae(c,p)}if(this.vNodes.deleteLastTarget(),c&&l.size){for(const d of h.keys())l.has(d)&&h.delete(d);return{type:x.RemoveNode,rect:c,removeIds:[...l],newWorkDatas:h}}return{type:x.None,...this.baseConsumeResult}}consumeAll(e){return this.consume(e)}clearTmpPoints(){this.tmpPoints.length=0}getCanEraserNodeMap(e){var t;if(this.serviceWork){const i=Ce(e),s=this.serviceWork.selectorWorkShapes,n=this.serviceWork.workShapes;for(const r of s.values())if((t=r.selectIds)!=null&&t.length)for(const c of r.selectIds)i.delete(c);for(const r of n.keys())i.delete(r);return i}return e}};g(mt,"eraserSizes",Object.freeze([Object.freeze({width:18,height:26}),Object.freeze({width:26,height:34}),Object.freeze({width:34,height:50})]));let to=mt;const Et=class Et extends U{constructor(e){super(e);g(this,"canRotate",!1);g(this,"scaleType",re.none);g(this,"toolsType",k.BitMapEraser);g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"worldPosition");g(this,"worldScaling");g(this,"eraserRect");g(this,"eraserPolyline");g(this,"syncUnitTime",be.syncOpt.interval);g(this,"syncIndex",0);g(this,"syncTimestamp");this.workOptions=e.toolsOpt,this.worldPosition=this.fullLayer.worldPosition,this.worldScaling=this.fullLayer.worldScaling,this.syncTimestamp=0}consumeService(e){const{op:t,isFullWork:i}=e;this.tmpPoints.length=0;for(let c=0;c<t.length;c+=3){const l=new V(t[c],t[c+1],t[c+2]);if(this.tmpPoints.length>0){const h=this.tmpPoints[this.tmpPoints.length-1],u=C.Sub(l,h).uni();l.setv(u)}this.tmpPoints.push(l)}if(this.tmpPoints.length<2)return;const s=this.tmpPoints[0].z*2,n=i?this.fullLayer:this.drawLayer||this.fullLayer;return this.draw({consumePoints:this.tmpPoints,layer:n,thickness:s,isClear:!1})}updateTempPoints(e,t){let i=this.tmpPoints.length-1;const s=Date.now();for(let n=0;n<e.length;n+=2){const r=this.tmpPoints.length,c=new V(e[n],e[n+1]);if(r===0){this.tmpPoints.push(c);continue}const l=r-1,h=this.tmpPoints[l],u=C.Sub(c,h).uni();c.isNear(h,t/2)||(C.Equals(u,h.v,.02)&&(this.tmpPoints.pop(),i--),c.setv(u),c.setT(s),this.tmpPoints.push(c))}return Math.max(i,0)}getChangeNodes(e){const t=new Map,i=new Set;if(!this.vNodes)return{willDeleteNodes:i,willUpdateNodes:t};const s=this.worldPosition;let n=pe(this.tmpPoints,e);n=Ao(n,s),n=uM(n,this.worldScaling,s);const{nodeRange:r}=this.vNodes.getRectIntersectRange(n);if(!r.size)return{willDeleteNodes:i,willUpdateNodes:t};let c=this.draw({consumePoints:this.tmpPoints,layer:this.fullLayer,thickness:e,isClear:!0});this.fullLayer.parent.render();const l=[];let h=0;for(let d=1;d<this.tmpPoints.length;d++){const p=this.tmpPoints[d-1],f=this.tmpPoints[d];if(d===1&&h===0&&(l[h]=[p.XY]),l[h].push(f.XY),d<this.tmpPoints.length-1){const y=f.getAngleByPoints(p,this.tmpPoints[d+1]);(y<90||y>270)&&(h++,l[h]=[f.XY])}}this.tmpPoints.length===1&&l.length===0&&l.push([this.tmpPoints[0].XY,this.tmpPoints[0].XY]);for(const[d,p]of r.entries()){if(p.toolsType===k.Text||p.toolsType===k.Image)continue;if(this.isTransparentRect(p.rect)){i.add(d);continue}let y=Ao(p.rect,[-s[0],-s[1]]);y={x:y.x/this.worldScaling[0],y:y.y/this.worldScaling[1],w:y.w/this.worldScaling[0],h:y.h/this.worldScaling[1]};const m=[y.x,y.y,y.x+y.w,y.y+y.h],T=[],w=[];for(const S of l)Wo.polyline(S,m,T);if(T.length&&p.opt)for(const S of T){const N=[];for(let I=0;I<S.length;I++)I!==0&&et(S[I],S[I-1])||N.push(...S[I]);w.push(N)}p.opt.eraserlines||(p.opt.eraserlines=[]),p.opt.eraserlines&&(p.opt.eraserlines.push({op:w,thickness:e}),t.set(d,p))}const u=this.fullLayer.getElementsByName(this.workId);if(u.length){const d=U.getRectFromLayer(this.fullLayer,this.workId);c=ae(c,d)}return u.forEach(d=>{d.remove(),d.disconnect()}),{willUpdateNodes:t,willDeleteNodes:i,rect:c}}async reRenderEffectNodes(e){var r;let t;const{willUpdateNodes:i,willDeleteNodes:s,worker:n}=e;if(s!=null&&s.size)for(const c of s.keys())this.replace(this.fullLayer,c),(r=this.vNodes)==null||r.delete(c);if(i!=null&&i.size)for(const[c,l]of i.entries()){const{toolsType:h}=l,u=n.createWorkShapeNode({workId:c,toolsType:h,toolsOpt:l.opt});u==null||u.setWorkId(c);let d;try{d=u==null?void 0:u.consumeService({op:l.op,isFullWork:!0,replaceId:c})}catch{continue}d&&(t=ae(t,d))}return t}consume(e){const{op:t}=e.data;if(!t||t.length===0)return{type:x.None,...this.baseConsumeResult};const{thickness:i}=this.workOptions,{width:s,height:n}=Et.eraserSizes[i],r=Math.max(s,n)/this.worldScaling[0],c=this.tmpPoints.length,l=this.tmpPoints[this.tmpPoints.length-1],h=this.updateTempPoints(t,r),u=this.tmpPoints[this.tmpPoints.length-1];if(c===this.tmpPoints.length&&u.equalsXY(l.x,l.y))return{type:x.None,...this.baseConsumeResult};this.syncIndex=Math.min(this.syncIndex,h,Math.max(0,this.tmpPoints.length-2));const d=this.syncIndex;this.syncTimestamp===0&&(this.syncTimestamp=Date.now());let p=!1;const f=this.tmpPoints.slice(h),y=this.draw({consumePoints:f,layer:this.fullLayer,thickness:r,isClear:!1});f[0].t-this.syncTimestamp>this.syncUnitTime&&(p=!0,this.syncTimestamp=f[0].t,this.syncIndex=this.tmpPoints.length);const m=[];return this.tmpPoints.slice(d).forEach(T=>{m.push(T.x,T.y,r/2)}),{...this.baseConsumeResult,type:x.DrawWork,dataType:F.Local,rect:y,op:p?m:void 0,index:p?d*3:void 0,updateNodeOpt:{useAnimation:!0}}}draw(e){const{consumePoints:t,layer:i,thickness:s,isClear:n}=e,r=this.workId;let c=i.getElementsByName(this.workId)[0],l=pe(t,s);const u=[{op:[t.map(d=>[d.x,d.y]).flat(1)],thickness:s}];return c||(c=new he.Group({normalize:!0,name:r,pos:[0,0],anchor:[.5,.5],bgcolor:"rgba(0,0,0,0.3)",zIndex:9999}),i.appendChild(c)),this.drawEraserlines({group:c,eraserlines:u,pos:[0,0],layer:i,isClear:n}),n||c.seal(),l={x:Math.floor(l.x*this.worldScaling[0]+this.worldPosition[0]-U.SafeBorderPadding),y:Math.floor(l.y*this.worldScaling[1]+this.worldPosition[1]-U.SafeBorderPadding),w:Math.floor(l.w*this.worldScaling[0]+2*U.SafeBorderPadding),h:Math.floor(l.h*this.worldScaling[1]+2*U.SafeBorderPadding)},l}isTransparentRectByGL(e,t){const{x:i,y:s,w:n,h:r}=t,c=new Uint8Array(n*r*4);e.readPixels(i,e.drawingBufferHeight-s-r,n,r,e.RGBA,e.UNSIGNED_BYTE,c);let l=!0;for(let h=0;h<c.length;h+=4)if(c[h+3]!==0){l=!1;break}return l}isTransparentRectByCanvas(e,t){const i=e.getContext("2d",{willReadFrequently:!0});if(!i)return!1;const{x:s,y:n,w:r,h:c}=t,l=i.getImageData(s,n,r,c);let h=!0;for(let u=0;u<l.data.length;u+=4)if(l.data[u+3]!==0){h=!1;break}return h}isTransparentRect(e){const t=this.fullLayer.parent.displayRatio||1,i=Math.floor(e.x*t),s=Math.floor(e.y*t),n=Math.floor(e.w*t),r=Math.floor(e.h*t),c=this.fullLayer.renderer.glRenderer;if(c&&c.gl)return this.isTransparentRectByGL(c.gl,{x:i,y:s,w:n,h:r});const l=this.fullLayer.renderer.canvas;return l&&this.isTransparentRectByCanvas(l,{x:i,y:s,w:n,h:r})||!1}consumeAll(){let e;const t=this.fullLayer.getElementsByName(this.workId);if(t.length&&(e=U.getRectFromLayer(this.fullLayer,this.workId)),t.forEach(p=>{p.remove(),p.disconnect()}),!this.tmpPoints.length)return{type:x.None,...this.baseConsumeResult};const{thickness:i}=this.workOptions,{width:s,height:n}=Et.eraserSizes[i],r=Math.max(s,n)/this.worldScaling[0],{willDeleteNodes:c,willUpdateNodes:l,rect:h}=this.getChangeNodes(r);if(e=ae(e,h),c.size===0&&l.size===0)return{type:x.FullWork,...this.baseConsumeResult,rect:e};const u=[];this.tmpPoints.map(p=>{u.push(p.x,p.y,r/2)});const d=Re(u);return{...this.baseConsumeResult,type:x.FullWork,dataType:F.Local,rect:e,ops:d,willUpdateNodes:l,willDeleteNodes:c}}clearTmpPoints(){this.tmpPoints.length=0}};g(Et,"eraserSizes",Object.freeze([Object.freeze({width:18,height:26}),Object.freeze({width:26,height:34}),Object.freeze({width:34,height:50})]));let oo=Et;function Us(a){switch(a){case k.Arrow:return As;case k.Pencil:return Ls;case k.Straight:return Ws;case k.Ellipse:return js;case k.Polygon:case k.Triangle:return Rs;case k.Star:case k.Rhombus:return Os;case k.Rectangle:return Es;case k.SpeechBalloon:return Ys;case k.Text:return eo;case k.LaserPen:return zs;case k.Eraser:return Jt;case k.PencilEraser:return to;case k.BitMapEraser:return oo;case k.Selector:return _t;case k.Image:return Rt}}function go(a,o){const{toolsType:e,...t}=a;switch(e){case k.Arrow:return new As(t);case k.Pencil:return new Ls(t);case k.Straight:return new Ws(t);case k.Ellipse:return new js(t);case k.Polygon:case k.Triangle:return new Rs(t);case k.Star:case k.Rhombus:return new Os(t);case k.Rectangle:return new Es(t);case k.SpeechBalloon:return new Ys(t);case k.Text:return new eo(t);case k.LaserPen:return new zs(t);case k.Eraser:return new Jt(t,o);case k.BitMapEraser:return new oo(t);case k.PencilEraser:return new to(t,o);case k.Selector:return t.vNodes?new _t({...t,vNodes:t.vNodes,drawLayer:t.fullLayer}):void 0;case k.Image:return new Rt(t);default:return}}function Bs(a){const o=[],e=["PATH","SPRITE","POLYLINE","RECT","ELLIPSE","LABEL"];for(const t of a){if(t.tagName==="GROUP"&&t.children.length)return Bs(t.children);t.tagName&&e.includes(t.tagName)&&o.push(t)}return o}const Qf="cursorhover",yo=20,de="mainView";class Fs{constructor(o,e){g(this,"viewId");g(this,"scene");g(this,"fullLayer");g(this,"curNodeMap",new Map);g(this,"targetNodeMap",[]);g(this,"highLevelIds");g(this,"canClearUids");g(this,"localUid");this.viewId=o,this.scene=e}init(o){this.fullLayer=o}get(o){return this.curNodeMap.get(o)}setLocalUid(o){this.localUid=o}getLocalUid(){return this.localUid}setCanClearUids(o){this.canClearUids=o}getCanClearUids(){return this.canClearUids}getCanEraserNodes(o,e){const t=new Map;for(const[i,s]of o.entries())s.toolsType===k.Image&&(s.opt.locked||e&&e.disableEraseImage)||s.toolsType===k.Text&&(s.opt.workState===P.Doing||s.opt.workState===P.Start||e&&e.disableEraseText)||this.isCanClearWorkId(i)&&t.set(i,s);return t}getNodesByType(o){const e=new Map;return this.curNodeMap.forEach((t,i)=>{t.toolsType===o&&e.set(i,t)}),e}gethasEraserNodes(){const o=new Map;return this.curNodeMap.forEach((e,t)=>{var i;(i=e.opt.eraserlines)!=null&&i.length&&o.set(t,e)}),o}hasRenderNodes(){return!0}has(o){return this.curNodeMap.has(o)}setInfo(o,e){const t=this.curNodeMap.get(o)||{name:o,rect:e.rect};e.rect&&(t.rect=Ce(e.rect)),e.op&&fM(e.op)&&(t.op=Ce(e.op)),e.canRotate&&(t.canRotate=e.canRotate),e.scaleType&&(t.scaleType=e.scaleType),e.opt&&(t.opt=Ce(e.opt)),e.toolsType&&(t.toolsType=e.toolsType),e.centerPos&&(t.centerPos=Ce(e.centerPos)),yt(e.isSelected)&&(t.isSelected=e.isSelected),t.rect?this.curNodeMap.set(o,t):this.curNodeMap.delete(o)}selected(o){this.setInfo(o,{isSelected:!0})}unSelected(o){this.setInfo(o,{isSelected:!1})}delete(o){this.curNodeMap.delete(o)}clear(){this.curNodeMap.clear(),this.targetNodeMap.length=0}getRectIntersectRange(o,e=!0,t=!0){let i;const s=new Map;for(const[n,r]of this.curNodeMap.entries())if(Yt(o,r.rect)){if(e&&r.toolsType===k.Image&&r.opt.locked||t&&r.toolsType===k.Text&&(r.opt.workState===P.Doing||r.opt.workState===P.Start))continue;i=ae(i,r.rect),s.set(n,r)}return{rectRange:i,nodeRange:s}}getNodeRectFormShape(o,e){const t=Us(e.toolsType);return this.fullLayer&&(t==null?void 0:t.getRectFromLayer(this.fullLayer,o))}updateNodeRect(o){const e=this.curNodeMap.get(o);if(e){const t=this.getNodeRectFormShape(o,e);if(!t){this.curNodeMap.delete(o);return}e.rect=t,this.curNodeMap.set(o,e)}}updateHighLevelNodesRect(o){this.highLevelIds=o;for(const e of this.highLevelIds.keys())this.updateNodeRect(e)}updateLowLevelNodesRect(){var o;for(const e of this.curNodeMap.keys())(o=this.highLevelIds)!=null&&o.has(e)||this.updateNodeRect(e)}clearHighLevelIds(){this.highLevelIds=void 0}setTargetAssignKeys(o){const e=new Map;for(const t of o){const i=this.curNodeMap.get(t);i&&e.set(t,Ce(i))}return this.targetNodeMap.push(Ce(e)),this.targetNodeMap.length-1}setTarget(){return this.targetNodeMap.push(Ce(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(o){return this.targetNodeMap[o]}deleteTarget(o){this.targetNodeMap.length=o}clearTarget(){this.targetNodeMap.length=0}isLocalWorkId(o){return o.split(Ae).length===1}isCanClearWorkId(o){if(this.canClearUids===void 0||this.canClearUids===!0)return!0;if(Ed(this.canClearUids)){const e=o.split(Ae);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 Gf{constructor(o,e,t){g(this,"viewId");g(this,"scene");g(this,"fullLayer");g(this,"vNodes");g(this,"dpr");g(this,"contextType");g(this,"opt");g(this,"cameraOpt");g(this,"isSafari",!1);g(this,"combinePostMsg",new Set);g(this,"workerTaskId");g(this,"protectedTask");g(this,"hasPriorityDraw",!0);g(this,"delayPostDoneResolve");g(this,"cacheImages",new Map);g(this,"imageResolveMap",new Map);var i,s;if(this.viewId=o,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",(s=this.scene)==null||s.disconnect(),this.createRenderLayer(e);else throw new Error(`Sorry, your browser doesn't support canvas context type ${this.contextType}`)}this.vNodes=new Fs(o,this.scene)}createRenderLayer(o){this.scene=this.createScene(o.offscreenCanvasOpt);const e=be.bufferSize.full,t=be.bufferSize.sub;this.fullLayer=this.createLayer("fullLayer",this.scene,{...o.layerOpt,bufferSize:this.viewId===de?e:t*2})}async updateDpr(o){this.dpr=o,this.scene.displayRatio=o}getCachedImages(o){var e;return(e=this.cacheImages.get(o))==null?void 0:e.imageBitmap}getCachedImagesByWorkId(o){for(const[e,t]of this.cacheImages.entries())if(e===o&&t.imageBitmap)return t.imageBitmap}deleteCachedImagesByWorkId(o,e){for(const[t,i]of this.cacheImages.entries())e&&t===e||i.workId===o&&(i.imageBitmap.close(),this.cacheImages.delete(t))}clearCacheImages(){this.cacheImages.forEach(o=>o.imageBitmap.close()),this.cacheImages.clear()}clearImageResolveMap(){this.imageResolveMap.forEach(({timer:o})=>{o&&clearTimeout(o)}),this.imageResolveMap.clear()}setHasPriorityDraw(o){this.hasPriorityDraw=o}getPriorityDraw(){return this.hasPriorityDraw}setIsSafari(o){this.isSafari=o}async on(o){const{msgType:e,toolsType:t,opt:i,imageSrc:s,imageBitmap:n,workId:r,dpr:c}=o;switch(e){case x.UpdateDpr:Oe(c)&&await this.updateDpr(c);break;case x.UpdateCamera:await this.updateCamera(o);break;case x.Destroy:this.destroy();break;case x.Clear:await this.clearAll();break;case x.UpdateTools:if(t&&i){const l={toolsType:t,toolsOpt:i};this.localWork.setToolsOpt(l)}break;case x.GetImageBitMap:if(s&&n&&r){const l=r.toString();this.cacheImages.set(s,{imageBitmap:n,workId:l});const h=this.imageResolveMap.get(s);if(h){const{resolve:u,timer:d}=h;d&&clearTimeout(d),u&&u(s)}this.deleteCachedImagesByWorkId(l,s)}break}}getIconSize(o,e,t){const i=o*t,s=e*t;return i<=50||s<=50?[50,50]:i<=100||s<=100?[100,100]:i<=200||s<=200?[200,200]:i<=400||s<=400?[400,400]:i<=800||s<=800?[800,800]:[1600,1600]}async loadImageBitMap(o){const{toolsType:e,opt:t,workId:i,isSubWorker:s}=o;if(e===k.Image&&t&&i){const n=i.toString(),{src:r,type:c,width:l,height:h,strokeColor:u}=t;if(!r||!c||!l||!h)return;let d=r;if(c===ht.Iconify){const[m,T]=this.getIconSize(l,h,this.dpr);d=`${r}?width=${m}&height=${T}&color=${u}`}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 y=await new Promise(m=>{const T=this.imageResolveMap.get(d)||{resolve:void 0,timer:void 0};T.timer&&clearTimeout(T.timer),T.resolve=m,T.timer=setTimeout(()=>{const w=this.imageResolveMap.get(d);w!=null&&w.resolve&&w.resolve(d)},5e3),this.imageResolveMap.set(d,T),this._post({sp:[{imageSrc:d,workId:n,viewId:this.viewId,isgl:!!this.fullLayer.parent.gl,isSubWorker:s,type:x.GetImageBitMap}]})});return this.imageResolveMap.delete(y),this.getCachedImages(d)}}createLocalWork(o){const{workId:e,opt:t,toolsType:i}=o;e&&t&&(!this.localWork.getToolsOpt()&&i&&this.setToolsOpt({toolsType:i,toolsOpt:t}),this.setWorkOpt({workId:e,toolsOpt:t}))}updateScene(o){this.scene.attr({...o});const{width:e,height:t}=o;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(o){const{width:e,height:t}=o;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(o,e){const t=new OffscreenCanvas(100,100);let i=["2d"];o===Do.Full&&this.viewId===de&&(i=["webgl2","webgl","2d"],e&&i.unshift(e));for(const s of i)try{if(t.getContext(s))return s}catch{continue}}createScene(o){const{width:e,height:t}=o,i=new OffscreenCanvas(e,t);o.contextType&&delete o.contextType;const s=new he.Scene({container:i,displayRatio:this.dpr,depth:!1,desynchronized:!0,failIfMajorPerformanceCaveat:!0,...o,contextType:this.contextType,id:this.viewId});return s.setAttribute("id",this.viewId),s}createLayer(o,e,t){const{width:i,height:s}=t,n=`offscreen-${o}`,r=e.layer(n,t),c=new he.Group({anchor:[.5,.5],pos:[i*.5,s*.5],size:[i,s],name:"viewport",id:o});return r.append(c),c}async clearAll(){var o;this.fullLayer&&(this.fullLayer.parent.children.forEach(e=>{e.name!=="viewport"&&e.remove()}),this.fullLayer.removeAllChildren()),this.clearCacheImages(),this.clearImageResolveMap(),this.localWork.destroy(),(o=this.serviceWork)==null||o.destroy()}setToolsOpt(o){this.localWork.setToolsOpt(o)}setWorkOpt(o){const{workId:e,toolsOpt:t}=o;e&&t&&this.localWork.setWorkOptions(e.toString(),t)}destroy(){var o;this.vNodes.clear(),this.fullLayer.remove(),this.clearCacheImages(),this.clearImageResolveMap(),this.scene.remove(),this.localWork.destroy(),(o=this.serviceWork)==null||o.destroy()}async post(o){this.combinePostMsg.add(o),await this.runBatchPostData()}async runBatchPostData(){this.workerTaskId||(this.workerTaskId=setTimeout(()=>{this.workerTaskId=void 0,this.combinePost()},16)),this.type===Do.Full&&!this.delayPostDoneResolve&&await new Promise(e=>{this.delayPostDoneResolve=e})&&(this.delayPostDoneResolve=void 0)}combinePostData(){var n,r;this.workerTaskId=void 0;const o=[],e=[];let t,i;const s=new Set;for(const c of this.combinePostMsg.values()){if((n=c.render)!=null&&n.length)for(const l of c.render){let h=!1;if(l.workId&&s.add(l.workId),l.isClearAll&&(l.rect=this.getSceneRect(),l.isClear=!0,delete l.isClearAll),l.drawCanvas){const u=this.getLayer(l.drawCanvas);if(!u||!(u.parent instanceof he.Layer))continue;if(u.parent.render(),l.isDrawAll){const d=this.getSceneRect();l.rect=d,delete l.isDrawAll}}for(const u of o)if(l.viewId===u.viewId){l.isClear&&u.clearCanvas&&u.isClear&&u.clearCanvas===l.clearCanvas&&(u.rect=ae(u.rect,l.rect),h=!0),u.drawCanvas&&u.drawCanvas===l.drawCanvas&&(u.rect=ae(u.rect,l.rect),h=!0);continue}h||(l.isClear&&!l.drawCanvas?o.unshift(l):o.push(l))}if((r=c.sp)!=null&&r.length)for(const l of c.sp){let h=!1;for(const u of e)if(et(l,u)){h=!0;break}h||e.push(l)}Oe(c.drawCount)&&(t=c.drawCount),Oe(c.consumeCount)&&(i=c.consumeCount)}return this.combinePostMsg.clear(),{render:o,sp:e,drawCount:t,consumeCount:i,workIds:s,viewId:this.viewId}}safariFixRect(o,e){if(o.w+o.x<=0||o.h+o.y<=0||o.w<=0||o.h<=0)return;const t=this.scene.width,i=this.scene.height,s={x:Math.floor(Math.max(0,o.x)),y:Math.floor(Math.max(0,o.y)),w:Math.floor(Math.min(t,o.w)),h:Math.floor(Math.min(i,o.h))};if(s.x+s.w>t&&(s.w=Math.floor(t-s.x)),s.y+s.h>i&&(s.h=Math.floor(i-s.y)),gM(e)){const n=yM(e),r=Math.pow(10,n),c=MM(r,e*r),l=s.x%c,h=s.x-l;h>=0?(s.x=h,s.w=s.w+l):(s.x=0,s.w=s.w+l-h);const u=s.y%c,d=s.y-u;d>=0?(s.y=d,s.h=s.h+u):(s.y=0,s.h=s.h+u-d)}return s}getSceneRect(){const{width:o,height:e}=this.scene;return{x:0,y:0,w:Math.floor(o),h:Math.floor(e)}}}class Zf{constructor(o){g(this,"viewId");g(this,"vNodes");g(this,"thread");g(this,"fullLayer");g(this,"drawLayer");g(this,"_post");g(this,"tmpOpt");g(this,"workShapes",new Map);g(this,"drawCount",0);g(this,"syncUnitTime",be.syncOpt.interval);this.thread=o.thread,this.viewId=o.viewId,this.vNodes=o.vNodes,this.fullLayer=o.fullLayer,this.drawLayer=o.drawLayer,this._post=this.thread.post.bind(o.thread)}destroy(){this.workShapes.clear()}getWorkShapes(){return this.workShapes}getWorkShape(o){return this.workShapes.get(o)}createWorkShape(o,e){if(o&&this.tmpOpt){const t={toolsType:this.tmpOpt.toolsType,toolsOpt:e||this.tmpOpt.toolsOpt},i=this.createWorkShapeNode({...t,workId:o});i&&this.workShapes.set(o,i)}}setWorkOptions(o,e){const t=this.getWorkShape(o);t||this.createWorkShape(o,e),t==null||t.setWorkOptions(e)}createWorkShapeNode(o){var e;return go({...o,vNodes:this.vNodes,fullLayer:this.fullLayer,drawLayer:this.drawLayer},(e=this.thread)==null?void 0:e.serviceWork)}setToolsOpt(o){var e,t,i;((e=this.tmpOpt)==null?void 0:e.toolsType)!==o.toolsType&&(t=this.tmpOpt)!=null&&t.toolsType&&this.clearAllWorkShapesCache(),this.tmpOpt=o,(i=o.toolsOpt)!=null&&i.syncUnitTime&&(this.syncUnitTime=o.toolsOpt.syncUnitTime)}getToolsOpt(){return this.tmpOpt}clearWorkShapeNodeCache(o){var e;(e=this.getWorkShape(o))==null||e.clearTmpPoints(),this.workShapes.delete(o)}clearAllWorkShapesCache(){this.workShapes.forEach(o=>o.clearTmpPoints()),this.workShapes.clear()}setFullWork(o){const{workId:e,opt:t,toolsType:i}=o;if(e&&t&&i){const s=e.toString();let n;return e&&this.workShapes.has(s)?(n=this.workShapes.get(s),n==null||n.setWorkOptions(t)):n=this.createWorkShapeNode({toolsOpt:t,toolsType:i,workId:s}),n?(this.workShapes.set(s,n),n):void 0}}}var qf=Ge,Xf=function(){return qf.Date.now()},Jf=Xf,Kf=/\s/;function _f(a){for(var o=a.length;o--&&Kf.test(a.charAt(o)););return o}var eg=_f,tg=eg,og=/^\s+/;function ig(a){return a&&a.slice(0,tg(a)+1).replace(og,"")}var sg=ig,ng=ut,rg=qe,ag="[object Symbol]";function cg(a){return typeof a=="symbol"||rg(a)&&ng(a)==ag}var lg=cg,hg=sg,Bi=ot,ug=lg,Fi=NaN,dg=/^[-+]0x[0-9a-f]+$/i,pg=/^0b[01]+$/i,fg=/^0o[0-7]+$/i,gg=parseInt;function yg(a){if(typeof a=="number")return a;if(ug(a))return Fi;if(Bi(a)){var o=typeof a.valueOf=="function"?a.valueOf():a;a=Bi(o)?o+"":o}if(typeof a!="string")return a===0?a:+a;a=hg(a);var e=pg.test(a);return e||fg.test(a)?gg(a.slice(2),e?2:8):dg.test(a)?Fi:+a}var Mg=yg,mg=ot,So=Jf,Vi=Mg,wg="Expected a function",vg=Math.max,Ig=Math.min;function Ng(a,o,e){var t,i,s,n,r,c,l=0,h=!1,u=!1,d=!0;if(typeof a!="function")throw new TypeError(wg);o=Vi(o)||0,mg(e)&&(h=!!e.leading,u="maxWait"in e,s=u?vg(Vi(e.maxWait)||0,o):s,d="trailing"in e?!!e.trailing:d);function p(I){var b=t,L=i;return t=i=void 0,l=I,n=a.apply(L,b),n}function f(I){return l=I,r=setTimeout(T,o),h?p(I):n}function y(I){var b=I-c,L=I-l,j=o-b;return u?Ig(j,s-L):j}function m(I){var b=I-c,L=I-l;return c===void 0||b>=o||b<0||u&&L>=s}function T(){var I=So();if(m(I))return w(I);r=setTimeout(T,y(I))}function w(I){return r=void 0,d&&t?p(I):(t=i=void 0,n)}function v(){r!==void 0&&clearTimeout(r),l=0,t=c=i=r=void 0}function S(){return r===void 0?n:w(So())}function N(){var I=So(),b=m(I);if(t=arguments,i=this,c=I,b){if(r===void 0)return f(c);if(u)return clearTimeout(r),r=setTimeout(T,o),p(c)}return r===void 0&&(r=setTimeout(T,o)),n}return N.cancel=v,N.flush=S,N}var Sg=Ng,Tg=Sg,kg=ot,Cg="Expected a function";function bg(a,o,e){var t=!0,i=!0;if(typeof a!="function")throw new TypeError(Cg);return kg(e)&&(t="leading"in e?!!e.leading:t,i="trailing"in e?!!e.trailing:i),Tg(a,o,{leading:t,maxWait:o,trailing:i})}var xg=bg;const Ot=St(xg);function Lg(a){return a}var Vs=Lg;function zg(a,o,e){switch(e.length){case 0:return a.call(o);case 1:return a.call(o,e[0]);case 2:return a.call(o,e[0],e[1]);case 3:return a.call(o,e[0],e[1],e[2])}return a.apply(o,e)}var Pg=zg,Dg=Pg,$i=Math.max;function Ag(a,o,e){return o=$i(o===void 0?a.length-1:o,0),function(){for(var t=arguments,i=-1,s=$i(t.length-o,0),n=Array(s);++i<s;)n[i]=t[o+i];i=-1;for(var r=Array(o+1);++i<o;)r[i]=t[i];return r[o]=e(n),Dg(a,this,r)}}var jg=Ag;function Eg(a){return function(){return a}}var Og=Eg,Rg=Og,Hi=rs,Yg=Vs,Wg=Hi?function(a,o){return Hi(a,"toString",{configurable:!0,enumerable:!1,value:Rg(o),writable:!0})}:Yg,Ug=Wg,Bg=800,Fg=16,Vg=Date.now;function $g(a){var o=0,e=0;return function(){var t=Vg(),i=Fg-(t-e);if(e=t,i>0){if(++o>=Bg)return arguments[0]}else o=0;return a.apply(void 0,arguments)}}var Hg=$g,Qg=Ug,Gg=Hg,Zg=Gg(Qg),qg=Zg,Xg=Vs,Jg=jg,Kg=qg;function _g(a,o){return Kg(Jg(a,o,Xg),a+"")}var ey=_g;function ty(a,o,e,t){for(var i=a.length,s=e+(t?1:-1);t?s--:++s<i;)if(o(a[s],s,a))return s;return-1}var oy=ty;function iy(a){return a!==a}var sy=iy;function ny(a,o,e){for(var t=e-1,i=a.length;++t<i;)if(a[t]===o)return t;return-1}var ry=ny,ay=oy,cy=sy,ly=ry;function hy(a,o,e){return o===o?ly(a,o,e):ay(a,cy,e)}var uy=hy,dy=uy;function py(a,o){var e=a==null?0:a.length;return!!e&&dy(a,o,0)>-1}var $s=py;function fy(a,o,e){for(var t=-1,i=a==null?0:a.length;++t<i;)if(e(o,a[t]))return!0;return!1}var Hs=fy;function gy(a,o){for(var e=-1,t=a==null?0:a.length,i=Array(t);++e<t;)i[e]=o(a[e],e,a);return i}var yy=gy,My=Ko,my=$s,wy=Hs,vy=yy,Iy=po,Ny=_o,Sy=200;function Ty(a,o,e,t){var i=-1,s=my,n=!0,r=a.length,c=[],l=o.length;if(!r)return c;e&&(o=vy(o,Iy(e))),t?(s=wy,n=!1):o.length>=Sy&&(s=Ny,n=!1,o=new My(o));e:for(;++i<r;){var h=a[i],u=e==null?h:e(h);if(h=t||h!==0?h:0,n&&u===u){for(var d=l;d--;)if(o[d]===u)continue e;c.push(h)}else s(o,u,t)||c.push(h)}return c}var ky=Ty,Qi=Wt,Cy=hs,by=Ut,Gi=Qi?Qi.isConcatSpreadable:void 0;function xy(a){return by(a)||Cy(a)||!!(Gi&&a&&a[Gi])}var Ly=xy,zy=qo,Py=Ly;function Qs(a,o,e,t,i){var s=-1,n=a.length;for(e||(e=Py),i||(i=[]);++s<n;){var r=a[s];o>0&&e(r)?o>1?Qs(r,o-1,e,t,i):zy(i,r):t||(i[i.length]=r)}return i}var Dy=Qs;function Ay(){}var jy=Ay,To=Is,Ey=jy,Oy=ei,Ry=1/0,Yy=To&&1/Oy(new To([,-0]))[1]==Ry?function(a){return new To(a)}:Ey,Wy=Yy,Uy=Ko,By=$s,Fy=Hs,Vy=_o,$y=Wy,Hy=ei,Qy=200;function Gy(a,o,e){var t=-1,i=By,s=a.length,n=!0,r=[],c=r;if(e)n=!1,i=Fy;else if(s>=Qy){var l=o?null:$y(a);if(l)return Hy(l);n=!1,i=Vy,c=new Uy}else c=o?[]:r;e:for(;++t<s;){var h=a[t],u=o?o(h):h;if(h=e||h!==0?h:0,n&&u===u){for(var d=c.length;d--;)if(c[d]===u)continue e;o&&c.push(u),r.push(h)}else i(c,u,e)||(c!==r&&c.push(u),r.push(h))}return r}var Zy=Gy,qy=ky,Xy=Dy,Zi=Zy;function Jy(a,o,e){var t=a.length;if(t<2)return t?Zi(a[0]):[];for(var i=-1,s=Array(t);++i<t;)for(var n=a[i],r=-1;++r<t;)r!=i&&(s[i]=qy(s[i]||n,a[r],o,e));return Zi(Xy(s,1),o,e)}var Ky=Jy,_y=Ho,eM=qe;function tM(a){return eM(a)&&_y(a)}var oM=tM,iM=gs,sM=ey,nM=Ky,rM=oM;sM(function(a){return nM(iM(a,rM))});class aM extends Zf{constructor(e){super(e);g(this,"drawWorkActiveId")}async runFullWork(e){var s;const t=this.setFullWork(e),i=e.ops&&it(e.ops);if(t){let n,r;const c=(s=t.getWorkId())==null?void 0:s.toString();return t.toolsType===k.Image?n=await t.consumeServiceAsync({isFullWork:!0,worker:this.thread}):t.toolsType===k.Text?n=await t.consumeServiceAsync({isFullWork:!0,replaceId:c,isDrawLabel:!0}):(n=t.consumeService({op:i,isFullWork:!0,replaceId:c}),r=(e==null?void 0:e.updateNodeOpt)&&t.updataOptService(e.updateNodeOpt)),e.workId&&this.workShapes.delete(e.workId.toString()),ae(n,r)}}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);this.fullLayer.removeAllChildren()}canUseSubWorker(e){const t=this.thread.getPriorityDraw();return t||!t&&e!==k.Pencil}async consumeDraw(e){const{workId:t}=e,i=t==null?void 0:t.toString(),s=i&&this.workShapes.get(i);if(!s)return;this.drawWorkActiveId&&this.drawWorkActiveId!==i&&(await this.consumeDrawAll({workId:this.drawWorkActiveId,viewId:this.viewId,msgType:x.DrawWork,dataType:F.Local}),this.drawWorkActiveId=void 0),!this.drawWorkActiveId&&i!==H&&(this.drawWorkActiveId=i);const n=s.toolsType,r=s.consume({data:e,drawCount:this.drawCount,isFullWork:!0,isSubWorker:!0});switch(n){case k.Arrow:case k.Straight:case k.Ellipse:case k.Rectangle:case k.Star:case k.Polygon:case k.SpeechBalloon:{r&&(this.drawCount++,await this.drawShape(r));break}case k.Pencil:{r&&(this.drawCount++,await this.drawPencil(r,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 s=this.workShapes.get(i);if(!s)return;switch(s.toolsType){case k.Arrow:case k.Straight:case k.Ellipse:case k.Pencil:case k.Rectangle:case k.Star:case k.Polygon:case k.SpeechBalloon:this.drawCount=0,this.fullLayer.removeAllChildren(),this.clearWorkShapeNodeCache(i);break}}}async removeWork(e){const{workId:t}=e,i=t==null?void 0:t.toString();if(i){const s=this.removeNode(i);if(s){const n=[];n.push({rect:Dt(s),clearCanvas:ye.Float,isClear:!0,viewId:this.viewId},{rect:Dt(s),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(s=>{const n=s.getBoundingClientRect();i=ae(i,{x:n.x-U.SafeBorderPadding,y:n.y-U.SafeBorderPadding,w:n.width+U.SafeBorderPadding*2,h:n.height+U.SafeBorderPadding*2}),s.remove()}),i&&this.clearWorkShapeNodeCache(e)),i}async drawPencil(e,t){await this._post({drawCount:this.drawCount,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({drawCount:this.drawCount,render:[{rect:(e==null?void 0:e.rect)&&Dt(e.rect),isClear:!0,clearCanvas:ye.Float,viewId:this.viewId},{rect:(e==null?void 0:e.rect)&&Dt(e.rect),drawCanvas:ye.Float,viewId:this.viewId}]})}}class cM{constructor(o){g(this,"viewId");g(this,"vNodes");g(this,"topLayer");g(this,"thread");g(this,"post");g(this,"serviceWorkShapes",new Map);g(this,"localWorkShapes",new Map);g(this,"tmpOpt");g(this,"syncUnitTime",be.syncOpt.interval);g(this,"animationId");this.viewId=o.viewId,this.vNodes=o.vNodes,this.topLayer=o.topLayer,this.thread=o.thread,this.post=o.thread.post.bind(o.thread)}canUseTopLayer(o){return o===k.LaserPen}getWorkShape(o){return this.localWorkShapes.get(o)}createWorkShape(o,e){if(o&&this.tmpOpt){const t={toolsType:this.tmpOpt.toolsType,toolsOpt:e||this.tmpOpt.toolsOpt},i=this.createWorkShapeNode({...t,workId:o});return i&&this.localWorkShapes.set(o,{node:i,toolsType:i.toolsType,workState:P.Start}),i}}setWorkOptions(o,e){var i;const t=(i=this.localWorkShapes.get(o))==null?void 0:i.node;t||this.createWorkShape(o,e),t==null||t.setWorkOptions(e)}createWorkShapeNode(o){const{toolsType:e}=o;if(e===k.LaserPen)return go({...o,vNodes:this.vNodes,fullLayer:this.topLayer,drawLayer:this.topLayer})}clearAllWorkShapesCache(){this.localWorkShapes.forEach(o=>{var e;return(e=o.node)==null?void 0:e.clearTmpPoints()}),this.localWorkShapes.clear()}setToolsOpt(o){var e;this.tmpOpt=o,(e=o.toolsOpt)!=null&&e.syncUnitTime&&(this.syncUnitTime=o.toolsOpt.syncUnitTime)}getToolsOpt(){return this.tmpOpt}consumeDraw(o){const{workId:e,dataType:t}=o;if(t===F.Service)this.activeServiceWorkShape(o);else{const i=e==null?void 0:e.toString(),s=i&&this.localWorkShapes.get(i);if(!s)return;const n=s.node.consume({data:o,isFullWork:!1,isSubWorker:!0});n.rect&&(s.totalRect=ae(n.rect,s.totalRect),s.result=n,s.workState=P.Doing,i&&this.localWorkShapes.set(i,s))}this.runAnimation()}consumeDrawAll(o){const{workId:e,dataType:t}=o;if(t===F.Service)this.activeServiceWorkShape(o);else{const i=e==null?void 0:e.toString(),s=i&&this.localWorkShapes.get(i);if(!s)return;const n=s.node.consumeAll({data:o});s.totalRect=ae(n.rect,s.totalRect),s.result=n,s.workState=P.Done,i&&this.localWorkShapes.set(i,s)}this.runAnimation()}destroy(){this.serviceWorkShapes.clear(),this.localWorkShapes.clear()}setNodeKey(o,e,t,i){return e.toolsType=t,e.node=this.createWorkShapeNode({workId:o,toolsType:t,toolsOpt:i}),e}activeServiceWorkShape(o){var d,p;const{workId:e,opt:t,toolsType:i,type:s,updateNodeOpt:n,ops:r,op:c}=o;if(!e)return;const l=e.toString(),h=(d=this.vNodes.get(l))==null?void 0:d.rect;if(!((p=this.serviceWorkShapes)!=null&&p.has(l))){let f={toolsType:i,animationWorkData:c||[],animationIndex:0,type:s,updateNodeOpt:n,ops:r,oldRect:h};i&&t&&(f=this.setNodeKey(l,f,i,t)),this.serviceWorkShapes.set(l,f)}const u=this.serviceWorkShapes.get(l);s&&(u.type=s),r&&(u.animationWorkData=it(r),u.ops=r),n&&(u.updateNodeOpt=n),c&&(u.animationWorkData=c),u.node&&u.node.getWorkId()!==l&&u.node.setWorkId(l),h&&(u.oldRect=h),i&&t&&(u.toolsType!==i&&i&&t&&this.setNodeKey(l,u,i,t),u.node&&u.node.setWorkOptions(t))}computNextAnimationIndex(o,e){const t=Math.floor((o.animationWorkData||[]).slice(o.animationIndex).length*32/e/this.syncUnitTime)*e;return Math.min((o.animationIndex||0)+(t||e),(o.animationWorkData||[]).length)}async animationDraw(){var n,r,c,l;this.animationId=void 0;let o=!1;const e=new Map,t=[],i=[],s=[];for(const[h,u]of this.serviceWorkShapes.entries())switch(u.toolsType){case k.LaserPen:{const p=this.computNextAnimationIndex(u,8),f=Math.max(0,u.animationIndex||0),y=(u.animationWorkData||[]).slice(f,p);if((u.animationIndex||0)<p){const m=(n=u.node)==null?void 0:n.consumeService({op:y,isFullWork:!1});u.totalRect=ae(u.totalRect,m),u.animationIndex=p,y.length&&e.set(h,{workState:f===0?P.Start:p===((r=u.animationWorkData)==null?void 0:r.length)?P.Done:P.Doing,op:y.slice(-2)})}if(i.push({isClear:!0,rect:u.totalRect,clearCanvas:ye.TopFloat,viewId:this.viewId}),t.push({rect:u.totalRect,drawCanvas:ye.TopFloat,viewId:this.viewId}),u.isDel){(c=u.node)==null||c.clearTmpPoints(),this.serviceWorkShapes.delete(h);break}u.ops&&u.animationIndex===((l=u.animationWorkData)==null?void 0:l.length)&&!u.isDel&&(this.topLayer.getElementsByName(h.toString())[0]||(u.isDel=!0,this.serviceWorkShapes.set(h,u))),o=!0;break}}for(const[h,u]of this.localWorkShapes.entries()){const{result:d,toolsType:p,totalRect:f,isDel:y,workState:m}=u;switch(p){case k.LaserPen:{if(f&&(i.push({isClear:!0,rect:f,clearCanvas:ye.TopFloat,viewId:this.viewId}),t.push({rect:f,drawCanvas:ye.TopFloat,viewId:this.viewId})),y){u.node.clearTmpPoints(),this.localWorkShapes.delete(h),s.push({removeIds:[h.toString()],viewId:this.viewId,type:x.RemoveNode});break}d&&((d.op||d.ops)&&s.push(d),u.result=void 0),!this.topLayer.getElementsByName(h.toString())[0]&&m===P.Done&&(u.isDel=!0,this.localWorkShapes.set(h,u)),o=!0;break}}}o&&this.runAnimation(),e.size&&e.forEach((h,u)=>{s.push({type:x.Cursor,uid:u.split(Ae)[0],op:h.op,workState:h.workState,viewId:this.viewId})}),(t.length||i.length||s.length)&&this.post({render:[...i,...t],sp:s})}runAnimation(){this.animationId||(this.animationId=setTimeout(()=>{this.animationId=void 0,this.animationDraw()},16))}}var Do=(a=>(a.Full="full",a.Sub="sub",a))(Do||{});class lM extends Gf{constructor(e,t,i){super(e,t,"sub");g(this,"type","sub");g(this,"_post");g(this,"topLayer");g(this,"snapshotFullLayer");g(this,"serviceWork");g(this,"localWork");g(this,"topLayerWork");this._post=i;const s=be.bufferSize.sub;this.topLayer=this.createLayer("topLayer",this.scene,{...t.layerOpt,bufferSize:s,contextType:"2d"});const n={thread:this,viewId:this.viewId,vNodes:this.vNodes,fullLayer:this.fullLayer,topLayer:this.topLayer};this.localWork=new aM(n),this.topLayerWork=new cM(n),this.vNodes.init(this.fullLayer)}async combinePost(){var n,r,c;const{render:e,...t}=this.combinePostData();let i;if((n=t.workIds)!=null&&n.size&&t.drawCount){const l=[];for(const h of t.workIds.values())this.fullLayer.getElementsByName(h).forEach(u=>{u.id&&t.drawCount&&Number(u.id)<t.drawCount&&l.push(u)});for(const h of l)h.remove(),h.disconnect()}if(e!=null&&e.length){const l=[];for(const h of e)if(h.rect){if(h.rect=this.safariFixRect(Ce(h.rect),this.dpr),!h.rect)continue;if(h.drawCanvas&&h.rect&&h.rect.w>0&&h.rect.h>0){const u=await this.getRectImageBitmap(h);h.imageBitmap=u,i||(i=[]),i.push(u)}l.push(h)}t.render=l}const s=(r=t.sp)==null?void 0:r.filter(l=>l.type!==x.None);s!=null&&s.length?t.sp=s.map(l=>({...l,viewId:this.viewId})):delete t.sp,t.drawCount===void 0&&delete t.drawCount,(s!=null&&s.length||t.drawCount||(c=t==null?void 0:t.render)!=null&&c.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:s,dataType:n,workState:r}=e;switch(t){case x.UpdateTools:if(i&&this.topLayerWork.canUseTopLayer(i)&&s){const c={toolsType:i,toolsOpt:s};this.topLayerWork.setToolsOpt(c);return}break;case x.CreateWork:this.createLocalWork(e);return;case x.DrawWork:r===P.Done&&n===F.Local?await this.consumeDrawAll(n,e):this.consumeDraw(n,e);return;case x.RemoveNode:await this.removeNode(e);return;case x.FullWork:i&&this.topLayerWork.canUseTopLayer(i)&&await this.consumeDrawAll(n,e);return;case x.Snapshot:this.snapshotFullLayer=this.createLayer("snapshotFullLayer",this.scene,{...this.opt.layerOpt,bufferSize:this.viewId===de?6e3:3e3,contextType:"2d"}),this.snapshotFullLayer&&(await this.getSnapshot(e),this.snapshotFullLayer=void 0);return;case x.BoundingBox:this.snapshotFullLayer=this.createLayer("snapshotFullLayer",this.scene,{...this.opt.layerOpt,bufferSize:this.viewId===de?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:s}=e;if(i&&this.topLayerWork.canUseTopLayer(i)&&t&&s){this.topLayerWork.getToolsOpt()||this.topLayerWork.setToolsOpt({toolsType:i,toolsOpt:s}),this.topLayerWork.setWorkOptions(t.toString(),s);return}i&&this.localWork.canUseSubWorker(i)&&super.createLocalWork(e)}async removeNode(e){const{dataType:t}=e;t===F.Local&&await this.localWork.removeWork(e)}getOffscreen(e,t){return this.getLayer(e,t).parent.canvas}async consumeDraw(e,t){const{workId:i,toolsType:s}=t;if(i){if(s&&this.topLayerWork.canUseTopLayer(s)){e===F.Local&&(this.topLayerWork.getWorkShape(i.toString())||this.createLocalWork(t)),this.topLayerWork.consumeDraw(t);return}s&&this.localWork.canUseSubWorker(s)&&(this.localWork.getWorkShape(i.toString())||this.createLocalWork(t),await this.localWork.consumeDraw(t));return}}async consumeDrawAll(e,t){const{workId:i,toolsType:s,dataType:n}=t;if(i){const r=i.toString();if(s&&this.topLayerWork.canUseTopLayer(s)){n===F.Local&&(this.topLayerWork.getWorkShape(r)||this.createLocalWork(t)),this.topLayerWork.consumeDrawAll(t);return}s&&this.localWork.canUseSubWorker(s)&&(this.localWork.getWorkShape(r)||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()}),this.topLayer.removeAllChildren()),await this.post({render:[{isClearAll:!0,clearCanvas:ye.TopFloat,viewId:this.viewId}],sp:[{type:x.Clear}]})}getRectImageBitmap(e,t=!1,i){const{rect:s,drawCanvas:n}=e,r=Math.floor(s.x*this.dpr),c=Math.floor(s.y*this.dpr),l=Math.floor(s.w*this.dpr||1),h=Math.floor(s.h*this.dpr||1);return createImageBitmap(this.getOffscreen(n,t),r,c,l,h,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,s=[];i&&s.push({isClearAll:!0,clearCanvas:ye.Float,viewId:this.viewId}),t&&s.push({isClearAll:!0,clearCanvas:ye.TopFloat,viewId:this.viewId}),s.length&&await this.post({render:s})}async updateCamera(e){const t=[],{cameraOpt:i}=e;if(i&&!et(this.cameraOpt,i)){const s=!!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}),s){t.push({isClearAll:!0,clearCanvas:ye.TopFloat,viewId:this.viewId});for(const[r,c]of this.topLayerWork.localWorkShapes.entries())if(c.totalRect){let l;this.topLayer.getElementsByName(r.toString()).forEach(h=>{const u=h.getBoundingClientRect(),d=Dt({x:u.x,y:u.y,w:u.width,h:u.height});l=ae(l,d)}),c.totalRect=l,this.topLayerWork.localWorkShapes.set(r,c)}}t.length&&await this.post({render:t})}}setCameraOpt(e,t){this.cameraOpt=e;const{scale:i,centerX:s,centerY:n,width:r,height:c}=e;(r!==this.scene.width||c!==this.scene.height)&&this.updateScene({width:r,height:c}),t?(t.setAttribute("scale",[i,i]),t.setAttribute("translate",[-s,-n])):(this.fullLayer.setAttribute("scale",[i,i]),this.fullLayer.setAttribute("translate",[-s,-n]),this.topLayer.setAttribute("scale",[i,i]),this.topLayer.setAttribute("translate",[-s,-n]))}async getSnapshot(e){const{scenePath:t,scenes:i,cameraOpt:s,w:n,h:r}=e;if(t&&i&&s&&this.snapshotFullLayer){const c=Ce(this.cameraOpt);this.setCameraOpt(s,this.snapshotFullLayer),this.localWork.fullLayer=this.snapshotFullLayer,this.localWork.drawLayer=void 0;let l;for(const[u,d]of Object.entries(i))if(d!=null&&d.type)switch(d==null?void 0:d.type){case x.UpdateNode:case x.FullWork:{const{opt:p}=d,f={...d,opt:p,workId:u,msgType:x.FullWork,dataType:F.Service,viewId:this.viewId},y=await this.localWork.runFullWork(f);l=ae(l,y);break}}let h;n&&r&&(h={resizeWidth:n,resizeHeight:r}),await this.getSnapshotRender({scenePath:t,curCameraOpt:c,options:h}),this.localWork.fullLayer=this.fullLayer,this.localWork.drawLayer=void 0}}async getSnapshotRender(e){var r,c;const{scenePath:t,curCameraOpt:i,options:s}=e;((r=this.snapshotFullLayer)==null?void 0:r.parent).render();const n=await this.getRectImageBitmap({rect:this.getSceneRect(),drawCanvas:ye.None},!0,s);n&&(this._post({sp:[{type:x.Snapshot,scenePath:t,imageBitmap:n,viewId:this.viewId}]},[n]),n.close(),(c=this.snapshotFullLayer)==null||c.removeAllChildren(),this.setCameraOpt(i,this.fullLayer))}async getBoundingRect(e){const{scenePath:t,scenes:i,cameraOpt:s}=e;if(t&&i&&s&&this.snapshotFullLayer){const n=Ce(this.cameraOpt);this.setCameraOpt(s,this.snapshotFullLayer),this.localWork.fullLayer=this.snapshotFullLayer,this.localWork.drawLayer=void 0;let r;for(const[c,l]of Object.entries(i))if(l!=null&&l.type)switch(l==null?void 0:l.type){case x.UpdateNode:case x.FullWork:{const h=await this.localWork.runFullWork({...l,workId:c,msgType:x.FullWork,dataType:F.Service,viewId:this.viewId});r=ae(r,h);break}}r&&await this.post({sp:[{type:x.BoundingBox,scenePath:t,rect:r}]}),this.localWork.fullLayer=this.fullLayer,this.localWork.drawLayer=void 0,this.snapshotFullLayer.removeAllChildren(),this.setCameraOpt(n,this.fullLayer)}}}class Rt extends U{constructor(e){super(e);g(this,"canRotate",!0);g(this,"scaleType",re.all);g(this,"toolsType",k.Image);g(this,"tmpPoints",[]);g(this,"workOptions");g(this,"oldRect");this.workOptions=e.toolsOpt,this.scaleType=Rt.getScaleType(this.workOptions)}consume(){return{type:x.None}}consumeAll(){return{type:x.None}}draw(e){const{layer:t,workId:i,replaceId:s,imageBitmap:n}=e,{centerX:r,centerY:c,width:l,height:h,rotate:u,zIndex:d,eraserlines:p}=this.workOptions,f=new he.Group({anchor:[.5,.5],pos:[r,c],name:i,size:[l,h],zIndex:d,rotate:u}),y={anchor:[.5,.5],pos:[0,0],size:[l,h],texture:n};n||(y.bgcolor="rgba(0,0,0,0.3)");const m=new he.Sprite(y);f.append(m),p&&this.drawEraserlines({group:f,eraserlines:p,pos:[r,c],layer:t}),this.replace(t,s||i,f);const T=f.getBoundingClientRect();if(T)return{x:Math.floor(T.x-U.SafeBorderPadding),y:Math.floor(T.y-U.SafeBorderPadding),w:Math.floor(T.width+U.SafeBorderPadding*2),h:Math.floor(T.height+U.SafeBorderPadding*2)}}consumeService(){}async consumeServiceAsync(e){var h,u,d,p;const{isFullWork:t,replaceId:i,worker:s}=e,{src:n,uuid:r}=this.workOptions,c=((h=this.workId)==null?void 0:h.toString())||r,l=t?this.fullLayer:this.drawLayer||this.fullLayer;if(n){const f=await s.loadImageBitMap({toolsType:this.toolsType,opt:this.workOptions,workId:c,isSubWorker:s instanceof lM});if(f){const y=this.draw({workId:c,layer:l,replaceId:i,imageBitmap:f});return this.oldRect=c&&((d=(u=this.vNodes)==null?void 0:u.get(c))==null?void 0:d.rect)||void 0,(p=this.vNodes)==null||p.setInfo(c,{rect:y,op:[],opt:this.workOptions,toolsType:this.toolsType,scaleType:this.scaleType,canRotate:this.canRotate,centerPos:y&&U.getCenterPos(y,l)}),y}}}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:s,targetNode:n}=e,{translate:r,originPoint:c,scenePoint:l,scale:h,angle:u,isLocked:d,zIndex:p,strokeColor:f}=i,y=n&&Ce(n)||s.get(t.name);if(!y)return;const m=t.parent;if(m){if(f&&(y.opt.strokeColor=f),Oe(p)&&(t.setAttribute("zIndex",p),y.opt.zIndex=p),yt(d)&&(y.opt.locked=d),c&&l&&h&&r){const{centerX:T,centerY:w,width:v,height:S,uniformScale:N}=y.opt,I=N!==!1?[h[0],h[0]]:h,b=[T,w],L=[T,w];oi(L,l,I,r);const j=[L[0]-b[0],L[1]-b[1]];if(y.centerPos=[y.centerPos[0]+j[0],y.centerPos[1]+j[1]],y.opt.width=Math.round(v*I[0]),y.opt.height=Math.round(S*I[1]),y.opt.centerX=L[0],y.opt.centerY=L[1],y.opt.eraserlines)for(const E of Object.values(y.opt.eraserlines)){const{op:A,thickness:W}=E;E.thickness=W*Math.max(h[0],h[1]);for(let z=0;z<A.length;z++)ii(A[z],l,h,r)}}else if(r){if(y.opt.centerX=y.opt.centerX+r[0],y.opt.centerY=y.opt.centerY+r[1],y.centerPos=[y.centerPos[0]+r[0],y.centerPos[1]+r[1]],y.opt.eraserlines)for(const T of Object.values(y.opt.eraserlines)){const{op:w}=T;for(let v=0;v<w.length;v++){const S=w[v].map((N,I)=>I%2?N+r[1]:N+r[0]);T.op[v]=S}}}else if(Oe(u))if(y.opt.rotate=u,y.scaleType=Rt.getScaleType(y.opt),n){const T=Gs(y.rect,u);y.rect=T}else{const T=U.getRectFromLayer(m,t.name);y.rect=T||y.rect}return y&&s.setInfo(t.name,y),y==null?void 0:y.rect}}}function ae(a,o){if(a&&o){const e=Math.min(a.x,o.x),t=Math.min(a.y,o.y),i=Math.max(a.x+a.w,o.x+o.w),s=Math.max(a.y+a.h,o.y+o.h),n=i-e,r=s-t;return{x:e,y:t,w:n,h:r}}return o||a}function ti(a,o){if(a&&o){const e=Math.min(a.originX,o.originX),t=Math.min(a.originY,o.originY),i=Math.max(a.originX+a.width,o.originX+o.width),s=Math.max(a.originY+a.height,o.originY+o.height),n=i-e,r=s-t;return{originX:e,originY:t,width:n,height:r}}return o||a}function pe(a,o=0){const e={x:0,y:0,w:0,h:0};let t=1/0,i=1/0,s=-1/0,n=-1/0;return a.forEach(r=>{const[c,l]=r.XY;t=Math.min(t,c-o),i=Math.min(i,l-o),s=Math.max(s,c+o),n=Math.max(n,l+o)}),e.x=t,e.y=i,e.w=s-t,e.h=n-i,e}function Yt(a,o){return!(a.x+a.w<o.x||a.x>o.x+o.w||a.y+a.h<o.y||a.y>o.y+o.h)}function Dt(a,o=10){return{x:Math.floor(a.x-o),y:Math.floor(a.y-o),w:Math.ceil(a.w+o*2),h:Math.ceil(a.h+o*2)}}function Ao(a,o){return{x:a.x+o[0],y:a.y+o[1],w:a.w,h:a.h}}function hM(a,o){const e=new C(a.x,a.y),t=new C(a.x+a.w,a.y),i=new C(a.x+a.w,a.y+a.h),s=new C(a.x,a.y+a.h),n=new C(a.x+a.w/2,a.y+a.h/2),r=Math.PI*o/180,c=C.RotWith(e,n,r),l=C.RotWith(t,n,r),h=C.RotWith(i,n,r),u=C.RotWith(s,n,r);return[c,l,h,u]}function Gs(a,o){const e=hM(a,o);return pe(e)}function uM(a,o,e){const t=new C(a.x,a.y),i=new C(a.x+a.w,a.y),s=new C(a.x+a.w,a.y+a.h),n=new C(a.x,a.y+a.h),r=new C(e[0],e[1]),c=new C(o[0],o[1]),l=C.ScaleWOrigin(t,c,r),h=C.ScaleWOrigin(i,c,r),u=C.ScaleWOrigin(s,c,r),d=C.ScaleWOrigin(n,c,r);return pe([l,h,u,d])}function dM(a,o,e){const t=new C(o[0],o[1]);for(let i=0;i<a.length;i+=3){const s=new C(a[i],a[i+1]),n=Math.PI*e/180,r=C.RotWith(s,t,n);a[i]=r.x,a[i+1]=r.y}}function pM(a,o,e){const t=new C(o[0],o[1]);for(let i=0;i<a.length;i+=2){const s=new C(a[i],a[i+1]),n=Math.PI*e/180,r=C.RotWith(s,t,n);a[i]=r.x,a[i+1]=r.y}}function oi(a,o,e,t=[0,0]){const i=new C(o[0],o[1]);for(let s=0;s<a.length;s+=3){const n=new C(a[s],a[s+1]),r=new C(e[0],e[1]),c=C.ScaleWOrigin(n,r,i);a[s]=c.x+t[0],a[s+1]=c.y+t[1]}}function ii(a,o,e,t=[0,0]){const i=new C(o[0],o[1]);for(let s=0;s<a.length;s+=2){const n=new C(a[s],a[s+1]),r=new C(e[0],e[1]),c=C.ScaleWOrigin(n,r,i);a[s]=c.x+t[0],a[s+1]=c.y+t[1]}}function Zs(a,o){return a[0]>=o.x&&a[0]<=o.x+o.w&&a[1]>=o.y&&a[1]<=o.y+o.h}function qs(a,o){const e=a<=o?1:a/o,t=o<=a?1:o/a;return[e,t]}function fM(a){for(const o of a)if(isNaN(o)||o===1/0||o===-1/0)return!1;return!0}function gM(a){return a!==Math.floor(a)}function yM(a){const o=a.toString();return o.indexOf(".")!==-1?o.split(".")[1].length:0}function MM(a,o){for(;o!==0;)[a,o]=[o,a%o];return a}const mM=a=>{if(a.tagName==="GROUP"){const o=Object.getOwnPropertySymbols(a).find(e=>e.toString()==="Symbol(sealed)");if(o&&a[o])return!0}return!1};function pt(a){return`${io(a.x)},${io(a.y)} `}function ft(a,o){return`${io((a.x+o.x)/2)},${io((a.y+o.y)/2)} `}function io(a){return+a.toFixed(4)}const Be=(a,o)=>new Promise(function(e){window.requestIdleCallback?requestIdleCallback(()=>{e(1)},{timeout:o}):setTimeout(()=>{e(2)},o)}).then(function(){a()},()=>{a()}),Je=a=>{const o=(a==null?void 0:a.webkitBackingStorePixelRatio)||(a==null?void 0:a.mozBackingStorePixelRatio)||(a==null?void 0:a.msBackingStorePixelRatio)||(a==null?void 0:a.oBackingStorePixelRatio)||(a==null?void 0:a.backingStorePixelRatio)||1;return Math.max(1,(window.devicePixelRatio||1)/o)},wM=(a,o)=>a.x+a.w<o.x||a.x>o.x+o.w||a.y+a.h<o.y||a.y>o.y+o.h?jt.outside:a.x>=o.x&&a.y>=o.y&&a.x+a.w<=o.x+o.w&&a.y+a.h<=o.y+o.h?jt.inside:jt.intersect;function vM(a){let o=0;for(let e=0;e<a.length;e++){const t=a.charCodeAt(e);t>=1&&t<=126||65376<=t&&t<=65439?o++:o+=2}return o}class IM{constructor(o,e){g(this,"plugin");g(this,"uid");g(this,"control");this.control=o,this.plugin=e,this.uid=e.displayer.uid}getNamespaceData(){var o;return _.toJS((o=this.plugin)==null?void 0:o.attributes[this.namespace])||{}}getAuthSpaceData(){var o;return _.toJS((o=this.plugin)==null?void 0:o.attributes[this.authSpace])||{}}getUidFromKey(o){return o.split(Ae).length===2&&o.split(Ae)[0]||this.uid}isLocalId(o){return o.split(Ae).length===1}getLocalId(o){return o.split(Ae)[1]}isSelector(o){return this.getLocalId(o)===H}}const Ie=class Ie extends IM{constructor(e,t,i){super(e,t);g(this,"authSpace");g(this,"namespace");g(this,"serviceStorage",{});g(this,"storage",{});g(this,"authStorage",{});g(this,"stateDisposer");g(this,"authDisposer");g(this,"asyncClockState",!1);g(this,"limitNums",new Map);g(this,"limitComponents",D.debounce((e,t)=>{var n,r,c,l,h,u,d,p;const i=((r=(n=this.storage)==null?void 0:n[e])==null?void 0:r[t])&&Object.keys(this.storage[e][t]).length||0;if(i===0)return;let s=this.limitNums.get(`${e}/${t}`);if(!s){const f=this.getLimitNum(i);this.limitNums.set(`${e}/${t}`,f),s=f}if(s>0&&i>=s){const f=Ie.componentsLimits.indexOf(s),y=f>=0&&f<Ie.componentsLimits.length-1;if((h=(l=(c=this.control.room)==null?void 0:c.callbacks)==null?void 0:l.listeners)!=null&&h.map.onObjectsLimit&&((d=(u=this.control.room)==null?void 0:u.callbacks)==null||d.dispatch("onObjectsLimit",T=>T(s,y))),!y){this.control.room.logger.error(`exceeds the limit of ${s} components, current: ${i}`),(p=this.control.room)==null||p.disconnect().then(()=>{var T,w,v,S,N;(v=(w=(T=this.control.room)==null?void 0:T.callbacks)==null?void 0:w.listeners)!=null&&v.map.onKickedWithReason&&((N=(S=this.control.room)==null?void 0:S.callbacks)==null||N.dispatch("onKickedWithReason",I=>I("kickByAdmin")))});return}console.warn(`exceeds the limit of ${s} components, current: ${i}`);const m=y?Ie.componentsLimits[f+1]:0;this.limitNums.set(`${e}/${t}`,m)}},2e3,{maxWait:5e3}));g(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)});Ie.syncInterval=(i||Ie.syncInterval)*.5,this.namespace=Ie.namespace,this.authSpace=Ie.authSpace,this.serviceStorage=this.getNamespaceData(),this.storage=D.cloneDeep(this.serviceStorage),this.authStorage=this.getAuthSpaceData(),this.getLimitNums()}getLimitNum(e){return e>=Ie.componentsLimits[0]?Ie.componentsLimits[1]:Ie.componentsLimits[0]}getLimitNums(){for(const[e,t]of Object.entries(this.storage))if(e&&t){for(const[i,s]of Object.entries(t))if(i&&s){const n=this.getLimitNum(Object.keys(s).length);this.limitNums.set(`${e}/${i}`,n)}}}getViewIdBySecenPath(e){const t=this.getNamespaceData();for(const[i,s]of Object.entries(t))if(s){for(const n of Object.keys(s))if(n===e)return i}}getScenePathData(e){const t=this.getNamespaceData();for(const i of Object.values(t))if(i){for(const s of Object.keys(i))if(s===e)return D.cloneDeep(i[s])}}getStorageData(e,t){const i=this.getNamespaceData();return i&&i[e]&&D.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(s=>this.isOwn(s)&&this.getLocalId(s)===H))}addStorageStateListener(e){this.stateDisposer=_.autorun(async()=>{var c;const t=this.getNamespaceData(),{diffView:i,diffScenePath:s,diffData:n}=this.diffFunByView(this.serviceStorage,t);this.serviceStorage=t;const r={};if(Object.keys(i).length>0){r.diffView=i;for(const[l,h]of Object.entries(i)){if(h&&h.newValue===void 0&&this.storage[l]){delete this.storage[l];continue}if(h&&h.newValue){this.storage[l]=D.cloneDeep(h.newValue);continue}}}if(Object.keys(s).length>0){r.diffScenePath=s;for(const[l,h]of Object.entries(s))if(h){const{viewId:u,newValue:d}=h;let p=this.storage[u];if(p&&p[l]&&d===void 0){delete p[l];continue}if(d&&u){p===void 0&&(this.storage[u]={},p=this.storage[u]),p[l]=D.cloneDeep(d);continue}}}if(Object.keys(n).length>0){r.diffData=n;for(const[l,h]of Object.entries(n))if(h){const{viewId:u,scenePath:d,newValue:p}=h;if(u&&d){let f=this.storage[u],y=(c=this.storage[u])==null?void 0:c[d];if(f||(this.storage[u]={},f=this.storage[u],f[d]={},y=f[d]),y){if(y[l]&&p===void 0){delete y[l];continue}if(p&&u){y[l]=D.cloneDeep(p);continue}}}}}Object.keys(r).length>0&&e(r)})}removeStorageStateListener(){this.stateDisposer&&this.stateDisposer()}diffFunByView(e,t){const i=Le(e),s=Le(t),n={},r={},c={};for(const l of s)if(!i.includes(l)||e[l]===void 0){n[l]={newValue:t[l],oldValue:void 0};continue}for(const l of i){if(D.isEqual(e[l],t[l]))continue;if(!s.includes(l)||t[l]===void 0){n[l]={newValue:void 0,oldValue:e[l]};continue}const h=this.diffFunByScenePath(e[l],t[l],l);Object.assign(r,h.diffScenePath),Object.assign(c,h.diffData)}return{diffData:c,diffScenePath:r,diffView:n}}diffFunByScenePath(e,t,i){const s=Le(e),n=Le(t),r={},c={};for(const l of n)if(!s.includes(l)||e[l]===void 0){r[l]={newValue:t[l],oldValue:void 0,viewId:i};continue}for(const l of s){if(D.isEqual(e[l],t[l]))continue;if(!n.includes(l)||t[l]===void 0){r[l]={newValue:void 0,oldValue:e[l],viewId:i};continue}const h=this.diffFunByKeys(e[l],t[l],l,i);Object.assign(c,h)}return{diffScenePath:r,diffData:c}}diffFunByKeys(e,t,i,s){const n=Le(e),r=Le(t),c={};for(const l of r)(!n.includes(l)||e[l]===void 0)&&(c[l]={oldValue:void 0,newValue:t[l],viewId:s,scenePath:i});for(const l of n)if(!D.isEqual(e[l],t[l])){if(!r.includes(l)||t[l]===void 0){c[l]={newValue:void 0,oldValue:e[l],viewId:s,scenePath:i};continue}r.includes(l)&&(c[l]={oldValue:e[l],newValue:t[l],viewId:s,scenePath:i})}return c}transformKey(e){return this.uid+Ae+e}isOwn(e){return e.split(Ae)[0]===this.uid}dispatch(e){const{type:t,workId:i,ops:s,index:n,opt:r,toolsType:c,removeIds:l,updateNodeOpt:h,op:u,selectIds:d,isSync:p,scenePath:f,viewId:y}=e;if(y)switch(t){case x.Clear:const m={};f&&this.storage[y]&&this.storage[y][f]?(delete this.storage[y][f],this.setState(m,{isSync:p,viewId:y,scenePath:f})):this.storage[y]&&(delete this.storage[y],this.setState(m,{isSync:p,viewId:y,scenePath:""})),Be(()=>{var N;this.control.pluginManager.dispatchPluginEvent("syncStorage",y,f),(N=this.control.miniMapManager)==null||N.updateMiniMapCamera(y),this.clearLimitComponents(y,f)},Ie.syncInterval);break;case x.CreateWork:if(f&&i&&c&&r){const N=this.isLocalId(i.toString())?this.transformKey(i):i;this.control.renderControl.isUsePageAuth(y)&&this.control.renderControl.addRenderPageElementId({viewId:y,scenePath:f,elementId:N.toString()}),this.updateValue(N.toString(),{type:x.CreateWork,workId:i,toolsType:c,opt:r},{isSync:p,viewId:y,scenePath:f})}break;case x.DrawWork:if(f&&i&&typeof n=="number"&&(u!=null&&u.length)){const N=this.isLocalId(i.toString())?this.transformKey(i):i,I=this.storage[y]&&this.storage[y][f]&&this.storage[y][f][N]||void 0;if(I!=null&&I.ops||(I==null?void 0:I.type)===x.FullWork)return;const b=n?((I==null?void 0:I.op)||[]).slice(0,n).concat(u):u||(I==null?void 0:I.op),L=c||(I==null?void 0:I.toolsType),j=r||(I==null?void 0:I.opt),E=h||(I==null?void 0:I.updateNodeOpt);i&&L&&j&&b&&(this.control.renderControl.isUsePageAuth(y)&&this.control.renderControl.addRenderPageElementId({viewId:y,scenePath:f,elementId:N.toString()}),this.updateValue(N.toString(),{...I,type:x.DrawWork,workId:i,updateNodeOpt:E,toolsType:L,opt:j,op:b,index:n},{isSync:p,viewId:y,scenePath:f}))}break;case x.FullWork:if(f&&i){const N=this.isLocalId(i.toString())?this.transformKey(i):i,I=this.storage[y]&&this.storage[y][f]&&this.storage[y][f][N]||void 0,b=h||(I==null?void 0:I.updateNodeOpt),L=c||(I==null?void 0:I.toolsType),j=r||(I==null?void 0:I.opt),E=s||(I==null?void 0:I.ops);L&&j&&(this.control.renderControl.isUsePageAuth(y)&&this.control.renderControl.addRenderPageElementId({viewId:y,scenePath:f,elementId:N.toString()}),this.updateValue(N.toString(),{type:x.FullWork,updateNodeOpt:b,workId:N,toolsType:L,opt:j,ops:E},{isSync:p,viewId:y,scenePath:f}),Be(()=>{var A;this.control.pluginManager.dispatchPluginEvent("syncStorage",y,f),(A=this.control.miniMapManager)==null||A.updateMiniMapCamera(y),this.limitComponents(y,f)},Ie.syncInterval))}break;case x.RemoveNode:if(f&&(l!=null&&l.length)){const N=l.map(I=>this.isLocalId(I+"")?this.transformKey(I):I);this.storage[y]&&this.storage[y][f]&&(Object.keys(this.storage[y][f]).map(I=>{N!=null&&N.includes(I)&&(this.control.renderControl.isUsePageAuth(y)&&this.control.renderControl.delRenderPageElementId({viewId:y,scenePath:f,elementId:I}),this.updateValue(I,void 0,{isSync:p,viewId:y,scenePath:f}))}),Be(()=>{var I;this.control.pluginManager.dispatchPluginEvent("syncStorage",y,f),(I=this.control.miniMapManager)==null||I.updateMiniMapCamera(y)},Ie.syncInterval))}break;case x.UpdateNode:if(f&&i&&(h||s||r)){const N=this.isLocalId(i.toString())?this.transformKey(i):i,I=this.storage[y]&&this.storage[y][f]&&this.storage[y][f][N]||void 0;I&&(I.updateNodeOpt=h,(s||u)&&(I.ops=s,I.op=u),r&&(I.opt=r),I.type=x.FullWork,this.updateValue(N.toString(),I,{isSync:p,viewId:y,scenePath:f}),Be(()=>{var b;(b=this.control.miniMapManager)==null||b.updateMiniMapCamera(y)},Ie.syncInterval))}break;case x.Select:if(!f)return;let T;d!=null&&d.length&&(T=d.map(N=>this.isLocalId(N+"")?this.transformKey(N):N));const w=this.transformKey(H),v=this.storage[y]&&this.storage[y][f]&&this.storage[y][f][w]||void 0,S=r||(v==null?void 0:v.opt);T&&this.checkOtherSelector(w,T,{isSync:p,viewId:y,scenePath:f}),this.updateValue(w,T&&{type:x.Select,toolsType:k.Selector,opt:S,selectIds:T},{isSync:p,viewId:y,scenePath:f});break}}checkOtherSelector(e,t,i){const{viewId:s,scenePath:n}=i;for(const r of Object.keys(this.storage[s][n]))if(r!==e&&this.getLocalId(r)===H){const c=this.storage[s][n][r];if(c&&c.selectIds){const l=c.selectIds.filter(h=>!t.includes(h));l.length>0&&(c.selectIds=l),this.updateValue(r,l.length&&c||void 0,i)}}}setState(e,t){const{viewId:i,scenePath:s}=t,n=Le(e);for(let r=0;r<n.length;r++){const c=n[r],l=e[c];typeof l<"u"?(this.storage[i]||(this.storage[i]={}),this.storage[i][s]||(this.storage[i][s]={}),this.storage[i][s][c]=l):delete this.storage[i][s][c]}this.runSyncService(t)}updateValue(e,t,i){const{viewId:s,scenePath:n}=i;t===void 0?delete this.storage[s][n][e]:(this.storage[s]||(this.storage[s]={}),this.storage[s][n]||(this.storage[s][n]={}),this.storage[s][n][e]=t),this.runSyncService(i)}runSyncService(e){this.asyncClockState||(this.asyncClockState=!0,setTimeout(()=>{e.isSync?(this.asyncClockState=!1,this.syncSerivice(e.isAfterUpdate)):Be(()=>{this.asyncClockState=!1,this.syncSerivice(e.isAfterUpdate)},Ie.syncInterval)},e!=null&&e.isSync?0:Ie.syncInterval))}syncSerivice(e=!1){const t=Le(this.serviceStorage),i=Le(this.storage),s=new Map;for(const n of t){if(!i.includes(n)){s.set(n,void 0);continue}D.isEqual(this.serviceStorage[n],this.storage[n])||this.syncViewData(n,e)}for(const n of i)t.includes(n)||s.set(n,this.storage[n]);if(s.size>5)this.syncStorageView(this.storage,e);else for(const[n,r]of s.entries())this.syncUpdataView(n,r,e)}syncViewData(e,t=!1){const i=Le(this.serviceStorage[e]),s=Le(this.storage[e]),n=new Map;for(const r of i){if(!s.includes(r)){n.set(r,void 0);continue}D.isEqual(this.serviceStorage[e][r],this.storage[e][r])||this.syncScenePathData(e,r,t)}for(const r of s)i.includes(r)||n.set(r,this.storage[e][r]);if(n.size>5)this.syncStorageScenePath(e,this.storage[e],t);else for(const[r,c]of n.entries())this.syncUpdataScenePath(e,r,c,t)}syncScenePathData(e,t,i=!1){const s=Le(this.serviceStorage[e][t]),n=Le(this.storage[e][t]),r=new Map;for(const c of s){if(!n.includes(c)){r.set(c,void 0);continue}D.isEqual(this.serviceStorage[e][t][c],this.storage[e][t][c])||r.set(c,this.storage[e][t][c])}for(const c of n)s.includes(c)||r.set(c,this.storage[e][t][c]);if(r.size>5)this.syncStorageKey(e,t,this.storage[e][t],i);else for(const[c,l]of r.entries())this.syncUpdataKey(e,t,c,l,i)}syncUpdataView(e,t,i=!1){var n;Object.keys(this.serviceStorage).length?(i||(t===void 0?delete this.serviceStorage[e]:this.serviceStorage[e]=D.cloneDeep(t)),(n=this.plugin)==null||n.updateAttributes([this.namespace,e],t)):this.syncStorageView(this.storage,i)}syncStorageView(e,t=!1){var i;t||e&&(this.serviceStorage=D.cloneDeep(e)),(i=this.plugin)==null||i.updateAttributes([this.namespace],e)}syncUpdataScenePath(e,t,i,s=!1){var r;Object.keys(this.serviceStorage[e]).length?(s||(i===void 0?delete this.serviceStorage[e][t]:this.serviceStorage[e][t]=i),(r=this.plugin)==null||r.updateAttributes([this.namespace,e,t],i)):this.syncStorageScenePath(e,this.storage[e],s)}syncStorageScenePath(e,t,i=!1){var s;i||t&&(this.serviceStorage[e]=t),(s=this.plugin)==null||s.updateAttributes([this.namespace,e],t)}syncUpdataKey(e,t,i,s,n=!1){var c;Object.keys(this.serviceStorage[e][t]).length?(n||(s===void 0?delete this.serviceStorage[e][t][i]:this.serviceStorage[e][t][i]=s),(c=this.plugin)==null||c.updateAttributes([this.namespace,e,t,i],s)):this.syncStorageKey(e,t,this.storage[e][t],n)}syncStorageKey(e,t,i,s=!1){var n;s||(this.serviceStorage[e][t]=i),(n=this.plugin)==null||n.updateAttributes([this.namespace,e,t],i)}keyTransformWorkId(e){const t=e.split(Ae);return t.length===2?t[1]:e}destroy(){this.removeStorageStateListener(),this.serviceStorage={},this.storage={},this.removeAuthStateListener(),this.authStorage={}}dispatchPageAuth(e,t=!0){var l,h,u,d,p,f,y,m,T,w,v,S,N,I,b,L,j,E,A,W,z,O,ne,te,Q,X,G,Z,K,ce,Te,ie,le,J,$,ue,fe,je;const{operation:i,viewId:s,scenePath:n,pageId:r,pageData:c}=e;switch(i){case Pe.addPage:{if(!s||!n||!r)return;const ve=[this.authSpace];Object.keys(this.authStorage).length&&ve.push("pageAuth");const me=this.authStorage.pageAuth||{};this.authStorage.pageAuth=me,Object.keys(me).length&&ve.push(s),me[s]=me[s]||{},Object.keys(me[s]).length&&ve.push(n),me[s][n]=me[s][n]||{render:(c==null?void 0:c.render)||"localSelf",pages:{}},Object.keys(me[s][n].pages).length&&ve.push("pages",r);const st={};if(c!=null&&c.elementIds)for(const ke of c.elementIds.keys())st[ke]=!0;me[s][n].pages[r]=st,t&&(ve.length===1?(l=this.plugin)==null||l.updateAttributes(ve,D.cloneDeep(this.authStorage)):ve.length===2?(h=this.plugin)==null||h.updateAttributes(ve,D.cloneDeep(me)):ve.length===3?(u=this.plugin)==null||u.updateAttributes(ve,D.cloneDeep(me[s])):ve.length===4?(d=this.plugin)==null||d.updateAttributes(ve,D.cloneDeep(me[s][n])):(p=this.plugin)==null||p.updateAttributes(ve,D.cloneDeep(st)));return}case Pe.renderPage:{if(!s||!n||!(c!=null&&c.render))return;this.authStorage.pageAuth&&this.authStorage.pageAuth[s]&&this.authStorage.pageAuth[s][n]&&c.render!==this.authStorage.pageAuth[s][n].render&&(this.authStorage.pageAuth[s][n].render=c.render,t&&((f=this.plugin)==null||f.updateAttributes([this.authSpace,"pageAuth",s,n,"render"],c.render)));return}case Pe.deletePage:{if(!s||!n||!r)return;(v=(w=(T=(m=(y=this.authStorage)==null?void 0:y.pageAuth)==null?void 0:m[s])==null?void 0:T[n])==null?void 0:w.pages)!=null&&v[r]&&(delete this.authStorage.pageAuth[s][n].pages[r],t&&((S=this.plugin)==null||S.updateAttributes([this.authSpace,"pageAuth",s,n,"pages",r],void 0)));return}case Pe.clearPage:{if(!s||!n||!r)return;(j=(L=(b=(I=(N=this.authStorage)==null?void 0:N.pageAuth)==null?void 0:I[s])==null?void 0:b[n])==null?void 0:L.pages)!=null&&j[r]&&(delete this.authStorage.pageAuth[s][n].pages[r],t&&((E=this.plugin)==null||E.updateAttributes([this.authSpace,"pageAuth",s,n,"pages",r],{})));return}case Pe.addElement:{if(!s||!n||!r||!(c!=null&&c.elementId))return;(ne=(O=(z=(W=(A=this.authStorage)==null?void 0:A.pageAuth)==null?void 0:W[s])==null?void 0:z[n])==null?void 0:O.pages)!=null&&ne[r]&&(this.authStorage.pageAuth[s][n].pages[r][c.elementId]=!0,t&&((te=this.plugin)==null||te.updateAttributes([this.authSpace,"pageAuth",s,n,"pages",r,c.elementId],!0)));return}case Pe.deleteElement:{if(!s||!n||!r||!(c!=null&&c.elementId))return;(ce=(K=(Z=(G=(X=(Q=this.authStorage)==null?void 0:Q.pageAuth)==null?void 0:X[s])==null?void 0:G[n])==null?void 0:Z.pages)==null?void 0:K[r])!=null&&ce[c.elementId]&&(delete this.authStorage.pageAuth[s][n].pages[r][c.elementId],t&&((Te=this.plugin)==null||Te.updateAttributes([this.authSpace,"pageAuth",s,n,"pages",r,c.elementId],void 0)));return}case Pe.clearViewScenePath:{if(!s||!n)return;(J=(le=(ie=this.authStorage)==null?void 0:ie.pageAuth)==null?void 0:le[s])!=null&&J[n]&&(delete this.authStorage.pageAuth[s][n],t&&(($=this.plugin)==null||$.updateAttributes([this.authSpace,"pageAuth",s,n],void 0)));return}case Pe.clearView:{if(!s)return;(fe=(ue=this.authStorage)==null?void 0:ue.pageAuth)!=null&&fe[s]&&(delete this.authStorage.pageAuth[s],t&&((je=this.plugin)==null||je.updateAttributes([this.authSpace,"pageAuth",s],void 0)));return}}}dispatchRenderAuth(e,t=!0){var l,h,u,d,p,f,y,m,T,w,v,S,N,I,b,L,j,E,A,W;const{operation:i,viewId:s,uid:n,renderData:r,isClear:c}=e;if(s)switch(i){case Qe.setAuth:{if(!r||r.render===void 0&&r.hide===void 0&&r.clear===void 0){this.authStorage.renderAuth&&this.authStorage.renderAuth[s]&&(delete this.authStorage.renderAuth[s],t&&((l=this.plugin)==null||l.updateAttributes([this.authSpace,"renderAuth",s],void 0)));return}const z=[this.authSpace];Object.keys(this.authStorage).length&&z.push("renderAuth");const O=this.authStorage.renderAuth||{};Object.keys(O).length&&z.push(s),O[s]={},this.authStorage.renderAuth=O;const{render:ne,hide:te,clear:Q}=r;if(ne===!0)O[s].render=!0;else if(D.isSet(ne)){O[s].render={};for(const X of ne.keys())O[s].render[X]=!0}if(te===!0)O[s].hide=!0;else if(D.isSet(te)){O[s].hide={};for(const X of te.keys())O[s].hide[X]=!0}if(Q===!0)O[s].clear=!0;else if(D.isSet(Q)){O[s].clear={};for(const X of Q.keys())O[s].clear[X]=!0}t&&(z.length===1?(h=this.plugin)==null||h.updateAttributes(z,D.cloneDeep(this.authStorage)):z.length===2?(u=this.plugin)==null||u.updateAttributes(z,D.cloneDeep(O)):(d=this.plugin)==null||d.updateAttributes(z,D.cloneDeep(O[s])));return}case Qe.setShow:{if(!n)return;const z=[this.authSpace];Object.keys(this.authStorage).length&&z.push("renderAuth");const O=this.authStorage.renderAuth||{};Object.keys(O).length&&z.push(s),O[s]=O[s]||{},this.authStorage.renderAuth=O,Object.keys(O[s]).length&&z.push("render"),O[s].render=O[s].render||{},O[s].render!==!0&&(Object.keys(O[s].render).length&&z.push(n),O[s].render[n]=!0),O[s].hide!==!0&&((p=O[s].hide)!=null&&p[n])&&(delete O[s].hide[n],t&&((f=this.plugin)==null||f.updateAttributes([this.authSpace,"renderAuth",s,"hide",n],void 0))),t&&(z.length===1?(y=this.plugin)==null||y.updateAttributes(z,D.cloneDeep(this.authStorage)):z.length===2?(m=this.plugin)==null||m.updateAttributes(z,D.cloneDeep(O)):z.length===3?(T=this.plugin)==null||T.updateAttributes(z,D.cloneDeep(O[s])):(w=this.plugin)==null||w.updateAttributes(z,!0));return}case Qe.setHide:{if(!n)return;const z=[this.authSpace];Object.keys(this.authStorage).length&&z.push("renderAuth");const O=this.authStorage.renderAuth||{};Object.keys(O).length&&z.push(s),O[s]=O[s]||{},this.authStorage.renderAuth=O,Object.keys(O[s]).length&&z.push("hide"),O[s].hide=O[s].hide||{},O[s].hide!==!0&&(Object.keys(O[s].hide).length&&z.push(n),O[s].hide[n]=!0),O[s].render!==!0&&((v=O[s].render)!=null&&v[n])&&(delete O[s].render[n],t&&((S=this.plugin)==null||S.updateAttributes([this.authSpace,"renderAuth",s,"render",n],void 0))),t&&(z.length===1?(N=this.plugin)==null||N.updateAttributes(z,D.cloneDeep(this.authStorage)):z.length===2?(I=this.plugin)==null||I.updateAttributes(z,D.cloneDeep(O)):z.length===3?(b=this.plugin)==null||b.updateAttributes(z,D.cloneDeep(O[s])):(L=this.plugin)==null||L.updateAttributes(z,!0));return}case Qe.setClear:{if(!n)return;const z=[this.authSpace];Object.keys(this.authStorage).length&&z.push("renderAuth");const O=this.authStorage.renderAuth||{};Object.keys(O).length&&z.push(s),O[s]=O[s]||{},this.authStorage.renderAuth=O,Object.keys(O[s]).length&&z.push("clear"),O[s].clear=O[s].clear||{},O[s].clear!==!0&&(Object.keys(O[s].clear).length&&z.push(n),c?O[s].clear[n]=!0:delete O[s].clear[n]),t&&(z.length===1?(j=this.plugin)==null||j.updateAttributes(z,D.cloneDeep(this.authStorage)):z.length===2?(E=this.plugin)==null||E.updateAttributes(z,D.cloneDeep(O)):z.length===3?(A=this.plugin)==null||A.updateAttributes(z,D.cloneDeep(O[s])):(W=this.plugin)==null||W.updateAttributes(z,c?!0:void 0));return}}}addAuthStateListener(e){this.authDisposer=_.autorun(async()=>{const t=this.getAuthSpaceData(),{renderAuth:i,pageAuth:s}=t;let n,r;D.isEqual(i,this.authStorage.renderAuth)||(n=this.diffAuthFun(this.authStorage.renderAuth||{},i||{}),this.authStorage.renderAuth=i),D.isEqual(s,this.authStorage.pageAuth)||(r=this.diffAuthPageFun(this.authStorage.pageAuth||{},s||{}),this.authStorage.pageAuth=s),(n||r)&&e(n,r)})}removeAuthStateListener(){this.authDisposer&&this.authDisposer()}diffAuthFun(e,t){const i=Le(e),s=Le(t),n={};for(const r of s)if(!i.includes(r)||e[r]===void 0){n[r]={newValue:t[r],oldValue:void 0};continue}for(const r of i)if(!D.isEqual(e[r],t[r])){if(!s.includes(r)||t[r]===void 0){n[r]={newValue:void 0,oldValue:e[r]};continue}n[r]={newValue:t[r],oldValue:e[r]}}return n}diffAuthPageFun(e,t){const i=Le(e),s=Le(t),n={};for(const r of s)if(!i.includes(r)||e[r]===void 0){n[r]={newValue:t[r],oldValue:void 0};continue}for(const r of i)if(!D.isEqual(e[r],t[r])){if(!s.includes(r)||t[r]===void 0){n[r]={newValue:void 0,oldValue:e[r]};continue}n[r]={newValue:t[r],oldValue:e[r]}}return n}};g(Ie,"namespace","PluginState"),g(Ie,"authSpace","PluginAuth"),g(Ie,"syncInterval",500),g(Ie,"componentsLimits",[500,1e3]);let jo=Ie;class NM{constructor(){g(this,"roomMembers",[]);g(this,"onChangeHooks",new Set)}setRoomMembers(o){this.executChangeUidHook(this.roomMembers,o),this.roomMembers=o}executChangeUidHook(o,e){const t={online:e.map(i=>{var s;return((s=i.payload)==null?void 0:s.uid)||i.session}),offline:o.map(i=>{var s;return((s=i.payload)==null?void 0:s.uid)||i.session})};this.onChangeHooks.forEach(i=>i(t))}getAllRoomMembers(){return this.roomMembers}getRoomMember(o){return this.roomMembers.find(e=>{var t;return((t=e.payload)==null?void 0:t.uid)===o})}isOnLine(o){return!this.getRoomMember(o)}onUidChangeHook(o){this.onChangeHooks.add(o)}destroy(){this.onChangeHooks.clear()}}var Ze=(a=>(a[a.Text=1]="Text",a[a.Shape=2]="Shape",a))(Ze||{});const De=class De{createProxy(o){const e=new Proxy(o,{get(t,i,s){const n=De.interceptors.hasOwnProperty(i)?De.interceptors:t;return Reflect.get(n,i,s)}});return De.proxyToRaw.set(e,o),e}};g(De,"proxyToRaw",new WeakMap),g(De,"interceptors",{entries(...o){return De.proxyToRaw.get(this).entries(...o)},forEach(...o){return De.proxyToRaw.get(this).forEach(...o)},size(){return De.proxyToRaw.get(this).size},get(o){return De.proxyToRaw.get(this).get(o)},set(o,e){return De.proxyToRaw.get(this).set(o,e)},delete(o,e){return De.proxyToRaw.get(this).delete(o)},clear(){return De.proxyToRaw.get(this).clear()}});let rt=De;class SM{constructor(o){g(this,"internalMsgEmitter");g(this,"control");g(this,"editors");g(this,"activeId");g(this,"proxyMap");g(this,"taskqueue",new Map);const{control:e,internalMsgEmitter:t}=o;this.control=e,this.internalMsgEmitter=t;const i=new Map;this.proxyMap=new rt;const s=this,n=rt.interceptors.set;rt.interceptors.set=function(c,l){return s.interceptors.set(c,l),n.call(this,c,l)};const r=rt.interceptors.delete;rt.interceptors.delete=function(c,l){return s.interceptors.delete(c,l),r.call(this,c)},this.editors=this.proxyMap.createProxy(i)}get collector(){return this.control.collector}filterEditor(o){const e=new Map;return this.editors.forEach((t,i)=>{t.viewId===o&&e.set(i,t)}),e}get interceptors(){return{set:(o,e)=>{var p,f,y,m,T,w,v,S;if(!this.collector)return!0;const{viewId:t,scenePath:i,canSync:s,canWorker:n,type:r,opt:c,dataType:l}=e;if(!n&&!s)return!0;const u=((p=this.collector)==null?void 0:p.isLocalId(o))?(f=this.collector)==null?void 0:f.transformKey(o):o,d=((y=this.collector)==null?void 0:y.storage[t])&&this.collector.storage[t][i]&&this.collector.storage[t][i][u]||void 0;d?d.toolsType===k.Text&&(n&&(this.control.worker.queryTaskBatchData({workId:o,msgType:x.UpdateNode}).forEach(N=>{var I;(I=this.control.worker)==null||I.taskBatchData.delete(N)}),(v=this.control.worker)==null||v.taskBatchData.add({workId:o,msgType:x.UpdateNode,dataType:l||F.Local,toolsType:k.Text,opt:c,viewId:t,scenePath:i,willRefresh:!0}),(S=this.control.worker)==null||S.runAnimation()),s&&Be(()=>{var N;(N=this.collector)==null||N.dispatch({type:x.UpdateNode,workId:o,toolsType:k.Text,opt:c,viewId:t,scenePath:i})},this.control.worker.maxLastSyncTime)):r===Ze.Text&&(s&&((m=this.collector)==null||m.dispatch({type:c.text&&x.FullWork||x.CreateWork,workId:o,toolsType:k.Text,opt:c,isSync:!0,viewId:t,scenePath:i})),n&&((T=this.control.worker)==null||T.taskBatchData.add({workId:o,msgType:c.text&&x.FullWork||x.CreateWork,dataType:l||F.Local,toolsType:k.Text,opt:c,viewId:t,scenePath:i,willRefresh:!0}),(w=this.control.worker)==null||w.runAnimation()))},delete:o=>{var r,c;if(!this.collector)return!0;const e=this.editors.get(o);if(!e)return!0;const{viewId:t,scenePath:i,canSync:s,canWorker:n}=e;if(!n&&!s)return!0;n&&((r=this.control.worker)==null||r.taskBatchData.add({workId:o,toolsType:k.Text,msgType:x.RemoveNode,dataType:F.Local,viewId:t,scenePath:i,willRefresh:!0}),(c=this.control.worker)==null||c.runAnimation()),s&&Be(()=>{var l;(l=this.collector)==null||l.dispatch({type:x.RemoveNode,removeIds:[o],toolsType:k.Text,viewId:t,scenePath:i})},this.control.worker.maxLastSyncTime)},clear(){return!0}}}computeTextActive(o,e){var s,n,r,c;const t=(s=this.control.viewContainerManager)==null?void 0:s.transformToScenePoint(o,e),i=(n=this.control.viewContainerManager)==null?void 0:n.getCurScenePath(e);e&&i&&((r=this.control.worker)==null||r.taskBatchData.add({msgType:x.GetTextActive,dataType:F.Local,op:t,viewId:e,scenePath:i}),(c=this.control.worker)==null||c.runAnimation())}checkEmptyTextBlur(){var e;let o=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)){o=t;break}if(o){const t=this.editors.get(o);(t==null?void 0:t.opt.text)&&(t==null?void 0:t.opt.text.replace(/\s*,/g,""))?this.unActive(o):this.delete(o,!0,!0)}}onCameraChange(o,e){var t,i;for(const[s,n]of this.editors.entries())if(n.viewId===e){const{boxPoint:r,boxSize:c}=n.opt,l=r&&((t=this.control.viewContainerManager)==null?void 0:t.transformToOriginPoint(r,n.viewId)),h=(i=this.control.viewContainerManager)==null?void 0:i.getCurScenePath(e);if(h&&e){const u={x:l&&l[0]||0,y:l&&l[1]||0,w:c&&c[0]||0,h:c&&c[1]||0,opt:n.opt,scale:o.scale,type:Ze.Text,viewId:e,scenePath:h,canWorker:!1,canSync:!1};this.editors.set(s,u),this.control.viewContainerManager.setActiveTextEditor(e,this.activeId)}}}onServiceDerive(o){var f,y;const{workId:e,opt:t,msgType:i,viewId:s,scenePath:n,dataType:r}=o;if(!e||!s||!n)return;const c=e.toString();if(i===x.RemoveNode){this.delete(c,!0,!0);return}const{boxPoint:l,boxSize:h}=t,u=l&&((f=this.control.viewContainerManager)==null?void 0:f.transformToOriginPoint(l,s)),d=this.control.viewContainerManager.getView(s),p={x:u&&u[0]||0,y:u&&u[1]||0,w:h&&h[0]||0,h:h&&h[1]||0,opt:t,type:Ze.Text,canWorker:!0,canSync:!1,dataType:r,scale:((y=d==null?void 0:d.cameraOpt)==null?void 0:y.scale)||1,viewId:s,scenePath:n};this.editors.set(c,p),r===F.Service&&t.workState===P.Done&&this.activeId===c&&(this.activeId=void 0),this.control.viewContainerManager.setActiveTextEditor(s,this.activeId)}updateForViewEdited(o,e){var i;this.editors.set(o,e);const t=(i=this.taskqueue.get(o))==null?void 0:i.resolve;t&&t(e)}active(o){var t;const e=this.editors.get(o);e&&e.viewId&&(e.opt.workState=P.Start,e.opt.uid=(t=this.collector)==null?void 0:t.uid,this.activeId=o,e.canWorker=!0,e.canSync=!0,this.editors.set(o,e),this.control.viewContainerManager.setActiveTextEditor(e.viewId,this.activeId))}unActive(o){const e=this.editors.get(o);e&&e.viewId&&(e.opt.workState=P.Done,e.opt.uid=void 0,e.canWorker=!0,e.canSync=!0,this.editors.set(o,e),this.activeId=void 0,this.control.viewContainerManager.setActiveTextEditor(e.viewId,this.activeId))}createTextForMasterController(o,e){var n;const{workId:t,isActive:i,...s}=o;e&&this.internalMsgEmitter.emit("addUndoTicker",e,s.viewId),s.opt.uid=(n=this.collector)==null?void 0:n.uid,i&&(this.activeId=t),s.dataType=F.Local,s.canWorker=!0,s.canSync=!0,this.editors.set(t,s),this.control.viewContainerManager.setActiveTextEditor(s.viewId,this.activeId)}updateTextForMasterController(o,e){var n;const{workId:t,...i}=o;e&&this.internalMsgEmitter.emit("addUndoTicker",e,i.viewId);const s=this.editors.get(t)||{};i.opt&&(i.opt.uid=(n=this.collector)==null?void 0:n.uid),i.dataType=F.Local,this.editors.set(t,{...s,...i}),this.control.viewContainerManager.setActiveTextEditor(i.viewId,this.activeId)}async updateTextControllerWithEffectAsync(o,e){var h;const{workId:t,...i}=o;e&&this.internalMsgEmitter.emit("addUndoTicker",e,i.viewId);const s=this.editors.get(t)||{};i.opt&&(i.opt.uid=(h=this.collector)==null?void 0:h.uid),i.dataType=F.Local;const n={...s,...i};if(this.editors.set(t,n),this.control.viewContainerManager.setActiveTextEditor(i.viewId,this.activeId),this.taskqueue.has(t)){const u=this.taskqueue.get(t);return u&&(u.clocker&&clearTimeout(u.clocker),this.taskqueue.delete(t)),await this.updateTextControllerWithEffectAsync(o)}const r=setTimeout(()=>{var d;const u=(d=this.taskqueue.get(t))==null?void 0:d.resolve;u&&u(n)},50),c=await new Promise(u=>{this.taskqueue.set(t,{resolve:u,clocker:r})}),l=this.taskqueue.get(t);return l&&(l.clocker&&clearTimeout(l.clocker),this.taskqueue.delete(t)),c}updateTextForWorker(o,e){const{workId:t,isActive:i,...s}=o,r={...this.editors.get(t)||{},...s};if(i){r.canWorker=!1,r.canSync=!1,this.editors.set(t,r),this.active(t);return}this.editors.set(t,r),this.control.viewContainerManager.setActiveTextEditor(s.viewId,this.activeId),e&&this.internalMsgEmitter.emit("addUndoTicker",e,s.viewId)}get(o){return this.editors.get(o)}delete(o,e,t){const i=this.editors.get(o);if(i){const s=i.viewId;i.canSync=e,i.canWorker=t,this.editors.delete(o),this.activeId===o&&(this.activeId=void 0),this.control.viewContainerManager.setActiveTextEditor(s,this.activeId)}}deleteBatch(o,e,t){const i=new Set;for(const s of o){const n=this.editors.get(s);if(n){const r=n.viewId;n.canSync=e,n.canWorker=t,this.editors.delete(s),this.activeId===s&&(this.activeId=void 0),i.add(r)}}for(const s of i)this.control.viewContainerManager.setActiveTextEditor(s,this.activeId)}clear(o,e){this.editors.forEach((t,i)=>{t.viewId===o&&(e&&(t.canSync=!1),t.canWorker=!1,this.editors.delete(i))}),this.activeId=void 0,this.control.viewContainerManager.setActiveTextEditor(o,this.activeId)}destory(){this.editors.clear(),this.activeId=void 0}}class TM{constructor(o){g(this,"expirationTime",be.cursor.expirationTime);g(this,"internalMsgEmitter");g(this,"control");g(this,"eventName","applianc-cursor");g(this,"displayer");g(this,"roomMember");g(this,"animationId");g(this,"maxLastSyncTime",be.syncOpt.interval);g(this,"willSendEventWorkers",[]);g(this,"willConsumeEventWorkers",new Map);g(this,"sendEventTimerId");g(this,"animationDrawWorkers",new Map);g(this,"animationEventWorkers",new Map);g(this,"cursorInfoMap",new Map);g(this,"doneRenderCursorInfoMap",new Map);g(this,"eventCollector");var i,s;const{control:e,internalMsgEmitter:t}=o;this.internalMsgEmitter=t,this.control=e,this.roomMember=e.roomMember,this.maxLastSyncTime=((s=(i=this.control.pluginOptions)==null?void 0:i.syncOpt)==null?void 0:s.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(o){var r;const{event:e,payload:t}=o;if(e!==this.eventName)return;const{uid:i,op:s,type:n}=t;if(((r=this.control.collector)==null?void 0:r.uid)!==i&&n===At.Cursor&&(s!=null&&s.length)){const c=this.willConsumeEventWorkers.get(i)||[];for(const l of s){const{viewId:h}=l;D.isNumber(l.consumPoint[0])&&D.isNumber(l.consumPoint[1])&&(l.consumPoint=this.control.viewContainerManager.transformToOriginPoint(l.consumPoint,h)),this.control.renderControl.isFilterCursor(h)&&c.unshift({...l,timestamp:Date.now()})}this.willConsumeEventWorkers.set(i,c),this.runAnimation()}}onFocusViewChange(){this.checkDrawWorks(),this.runAnimation()}updateRoomMembers(o){const{offline:e}=o;for(const t of this.cursorInfoMap.keys())t&&e.includes(t)&&this.cursorInfoMap.delete(t)}getKey(o,e){return`${o}${Ae}${e}`}getUidAndviewId(o){const[e,t]=o.split(Ae);return{uid:e,viewId:t}}runAnimation(){this.animationId||(this.animationId=requestAnimationFrame(this.animationCursor.bind(this)))}checkDrawWorks(){var e;const o=this.control.viewContainerManager.focuedViewId;for(const[t,i]of this.animationDrawWorkers.entries()){const{viewId:s,uid:n}=this.getUidAndviewId(t);n!==((e=this.control.collector)==null?void 0:e.uid)&&s!==o&&i.workState===P.Done&&(i.consumPoint=[void 0,void 0])}}animationCursor(){this.animationId=void 0;const o=Date.now();for(const[t,i]of this.animationDrawWorkers.entries()){const{uid:s,viewId:n}=this.getUidAndviewId(t),r=this.roomMember.getRoomMember(s);if(!r){this.animationDrawWorkers.delete(t);continue}const{consumPoint:c,timestamp:l,workState:h}=i,u=this.cursorInfoMap.get(n)||new Map;c&&D.isNumber(c[0])&&D.isNumber(c[1])&&l+this.expirationTime>o?u.set(r.memberId,{x:c[0],y:c[1],roomMember:r,timestamp:l,type:1,workState:h}):u.delete(r.memberId),u.size?this.cursorInfoMap.set(n,u):this.cursorInfoMap.delete(n),this.animationDrawWorkers.delete(t)}const e=new Set;for(const[t,i]of this.cursorInfoMap.entries())if(i)for(const[s,n]of i.entries())n.type===1&&n.workState!==P.Done&&e.add(s);else this.cursorInfoMap.delete(t);for(const[t,i]of this.willConsumeEventWorkers.entries()){const s=this.roomMember.getRoomMember(t);if(D.isNumber(s==null?void 0:s.memberId)&&!e.has(s.memberId)){const n=i.pop();n?this.animationEventWorkers.set(t,n):this.willConsumeEventWorkers.delete(t)}}for(const[t,i]of this.animationEventWorkers.entries()){const s=this.roomMember.getRoomMember(t);if(!s){this.animationEventWorkers.delete(t);continue}const{viewId:n,consumPoint:r,timestamp:c}=i,l=this.cursorInfoMap.get(n)||new Map;r&&D.isNumber(r[0])&&D.isNumber(r[1])&&c+this.expirationTime>o?l.set(s.memberId,{x:r[0],y:r[1],roomMember:s,timestamp:c,type:0}):l.delete(s.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([q.Cursor,t],[]));for(const[t,i]of this.cursorInfoMap.entries())if(i!=null&&i.size){const s=[];for(const[r,c]of i.entries()){const{timestamp:l,...h}=c;l+this.expirationTime>o?s.push(h):(i.delete(r),i.size===0&&(this.cursorInfoMap.delete(t),this.doneRenderCursorInfoMap.delete(t),this.internalMsgEmitter.emit([q.Cursor,t],[])))}const n=this.doneRenderCursorInfoMap.get(t);D.isEqual(n,s)||(this.doneRenderCursorInfoMap.set(t,s),this.internalMsgEmitter.emit([q.Cursor,t],s))}else this.cursorInfoMap.delete(t),this.doneRenderCursorInfoMap.delete(t),this.internalMsgEmitter.emit([q.Cursor,t],[]);(this.willConsumeEventWorkers.size||this.cursorInfoMap.size)&&this.runAnimation()}sendEvent(o,e){if(this.displayer&&_.isRoom(this.displayer)){const t=D.isNumber(o[0])&&D.isNumber(o[1])&&this.control.viewContainerManager.transformToScenePoint(o,e)||[void 0,void 0];this.willSendEventWorkers.push({consumPoint:t,viewId:e}),this.sendEventTimerId||(this.sendEventTimerId=setTimeout(()=>{this.dispatchMagixEvent()},this.maxLastSyncTime))}}dispatchMagixEvent(){var o;this.displayer.dispatchMagixEvent(this.eventName,{type:At.Cursor,op:D.cloneDeep(this.willSendEventWorkers),uid:(o=this.control.collector)==null?void 0:o.uid}),this.willSendEventWorkers.length=0,this.sendEventTimerId&&(clearTimeout(this.sendEventTimerId),this.sendEventTimerId=void 0)}collectServiceCursor(o){var n;const{op:e,uid:t,workState:i,viewId:s}=o;if(t&&e&&i&&s){const r=this.roomMember.getRoomMember(t);if(!r||t===((n=this.control.collector)==null?void 0:n.uid))return;const c=this.getKey(t,s);let l=[void 0,void 0];if(D.isNumber(e[0])&&D.isNumber(e[1])){const[u,d]=this.control.viewContainerManager.transformToOriginPoint(e,s);l=[u,d]}if(i===P.Start){for(const u of this.cursorInfoMap.values())if(u!=null&&u.size)for(const d of u.keys())d===r.memberId&&u.delete(d)}const h={consumPoint:l,workState:i,viewId:s,timestamp:Date.now()};if(i===P.Start||i===P.Done){const u=this.willConsumeEventWorkers.get(t);i===P.Start&&u&&this.willConsumeEventWorkers.delete(t),u&&i===P.Done&&(h.timestamp=h.timestamp-this.expirationTime)}this.animationDrawWorkers.set(c,h),this.runAnimation()}}unabled(){var o;this.displayer&&_.isRoom(this.displayer)&&(this.willSendEventWorkers.length=0,this.displayer.dispatchMagixEvent(this.eventName,{type:At.Cursor,op:[{viewId:this.control.viewContainerManager.focuedViewId,consumPoint:[void 0,void 0]}],uid:(o=this.control.collector)==null?void 0:o.uid}),this.sendEventTimerId&&(clearTimeout(this.sendEventTimerId),this.sendEventTimerId=void 0))}clearViewCursor(o){var e,t,i;for(const[s]of this.animationDrawWorkers.entries()){const{uid:n}=this.getUidAndviewId(s);n===((e=this.control.collector)==null?void 0:e.uid)&&o===o&&this.animationDrawWorkers.delete(s)}for(const[s]of this.willConsumeEventWorkers.entries())s===((t=this.control.collector)==null?void 0:t.uid)&&this.willConsumeEventWorkers.delete(s);for(const[s]of this.animationEventWorkers.entries())s===((i=this.control.collector)==null?void 0:i.uid)&&this.animationEventWorkers.delete(s);for(const[s]of this.cursorInfoMap.entries())s===s&&(this.cursorInfoMap.delete(s),this.doneRenderCursorInfoMap.delete(s),this.internalMsgEmitter.emit([q.Cursor,s],[]))}stopAnimation(){this.animationDrawWorkers.clear(),this.willConsumeEventWorkers.clear(),this.cursorInfoMap.clear()}destroy(){var o;(o=this.displayer)==null||o.removeMagixEventListener(this.eventName),this.stopAnimation()}}class Fe{constructor(){g(this,"useEmtMsg");g(this,"emtType");g(this,"control");g(this,"mainEngine")}static dispatch(o,e,t){var i;(i=Se.InternalMsgEmitter)==null||i.emit([o,e],t)}get serviceColloctor(){return this.control.collector}registerForMainEngine(o,e){return this.emtType=o,this.control=e,this.mainEngine=e.worker,this.mainEngine.internalMsgEmitter.on([this.emtType,this.emitEventType],this.collect.bind(this)),this}destroy(){this.emtType&&this.mainEngine&&this.mainEngine.internalMsgEmitter.off([this.emtType,this.emitEventType],this.collect.bind(this))}collectForLocalWorker(o,e){var t,i,s;for(const[n,r]of o)(t=this.mainEngine)==null||t.queryTaskBatchData(r).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}(s=this.mainEngine)==null||s.runAnimation()}collectForServiceWorker(o){Be(()=>{o.forEach(e=>{var t;(t=this.serviceColloctor)==null||t.dispatch(e)})},this.mainEngine.maxLastSyncTime)}pause(){var o;if(this.lastEmtData){this.useEmtMsg=!0;const e={...this.lastEmtData,workState:P.Done};this.collect(e,!0),(o=Se.InternalMsgEmitter)==null||o.emit(Y.ActiveMethod,!1)}}recover(){var o;this.useEmtMsg&&Se.InternalMsgEmitter.hasListeners(Y.ActiveMethod)&&((o=Se.InternalMsgEmitter)==null||o.emit(Y.ActiveMethod,!0))}}class kM extends Fe{constructor(){super(...arguments);g(this,"lastEmtData");g(this,"emitEventType",Y.CopyNode)}collect(e){var c;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,viewId:i}=e,s=this.control.viewContainerManager.getView(i);if(!(s!=null&&s.displayer))return;const n=s.focusScenePath,r=Date.now();this.mainEngine.internalMsgEmitter.emit("addUndoTicker",r,i);for(const l of t){const h=l.toString(),d=this.serviceColloctor.isLocalId(h)?this.serviceColloctor.transformKey(l):h,p=(c=this.serviceColloctor.getStorageData(i,n))==null?void 0:c[d];if(p){if(l===H){const f=p&&this.copySelector({viewId:i,store:p});f&&this.pasteSelector({...f,viewId:i,scenePath:n,undoTickerId:r});break}if(p.toolsType===k.Text&&p.opt&&p.opt.workState&&p.opt.workState!==P.Done){const f=p&&this.copyText({viewId:i,store:p});f&&this.pasteText({...f,viewId:i,scenePath:n,key:d,store:p,undoTickerId:r});break}}}}copyText(e){const{viewId:t,store:i}=e,s=this.control.viewContainerManager.getView(t);if(!this.serviceColloctor||!s)return;const n=s==null?void 0:s.cameraOpt,r=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:r,textCenter:l}}pasteText(e){var m,T;const{bgCenter:t,textCenter:i,store:s,key:n,viewId:r,scenePath:c,undoTickerId:l}=e,h=this.control.viewContainerManager.getView(r);if(!this.serviceColloctor||!h)return;const u=Math.floor(Math.random()*30+1),d=((m=h.cameraOpt)==null?void 0:m.scale)||1,p=t&&i&&[t[0]-i[0]+u,t[1]-i[1]+u]||[u/d,u/d],y=(this.serviceColloctor.isLocalId(n)?n:this.serviceColloctor.getLocalId(n.toString()))+"-"+l;if(s.toolsType===k.Text&&s.opt){const w=s.opt;if(w&&w.boxPoint&&w.text){w.workState=P.Done;const v=w.boxPoint;w.boxPoint=[v[0]+p[0],v[1]+p[1]],w.workState=P.Done;const S=this.control.viewContainerManager.transformToOriginPoint(w.boxPoint,r);this.control.textEditorManager.createTextForMasterController({workId:y,x:S[0],y:S[1],opt:w,scale:((T=h.cameraOpt)==null?void 0:T.scale)||1,type:Ze.Text,isActive:!1,viewId:r,scenePath:c}),this.collectForServiceWorker([{...s,opt:w,type:x.FullWork,workId:y,viewId:r,scenePath:c}])}}}copySelector(e){var y,m,T,w,v,S,N,I,b;const{viewId:t,store:i}=e,s=this.control.viewContainerManager.getView(t),n=i.selectIds;if(!this.serviceColloctor||!(n!=null&&n.length)||!s)return;const r=new Map,c={offset:{x:0,y:0},cameraOpt:{centerX:((y=s.cameraOpt)==null?void 0:y.centerX)||0,centerY:((m=s.cameraOpt)==null?void 0:m.centerY)||0,scale:((T=s.cameraOpt)==null?void 0:T.scale)||1}},l=this.control.hasOffscreenCanvas()&&((w=s.displayer.canvasBgRef.current)==null?void 0:w.getBoundingClientRect())||((v=s.displayer.canvasContainerRef.current)==null?void 0:v.getBoundingClientRect()),h=(N=(S=s.displayer)==null?void 0:S.floatBarRef.current)==null?void 0:N.getBoundingClientRect(),u=l&&[l.x+l.width/2,l.y+l.height/2],d=h&&[h.x+h.width/2,h.y+h.height/2],p=u&&s.viewData&&s.viewData.convertToPointInWorld({x:u[0],y:u[1]}),f=d&&s.viewData&&s.viewData.convertToPointInWorld({x:d[0],y:d[1]});p&&f&&(c.offset={x:p.x-f.x,y:p.y-f.y});for(const L of n){const j=(b=(I=this.serviceColloctor)==null?void 0:I.getStorageData(s.id,s.focusScenePath))==null?void 0:b[L];j&&r.set(L,j)}return{copyStores:r,copyCoordInfo:c}}pasteSelector(e){var m;const{copyStores:t,copyCoordInfo:i,viewId:s,scenePath:n,undoTickerId:r}=e,c=this.control.viewContainerManager.getView(s);if(!t.size||!this.serviceColloctor||!c)return;const{offset:l,cameraOpt:h}=i,{scale:u}=h,d=Math.floor(Math.random()*30+1),p=l&&[l.x+d,l.y+d]||[d/u,d/u],f=[],y=[];for(const[T,w]of t.entries()){const S=(this.serviceColloctor.isLocalId(T)?T:this.serviceColloctor.getLocalId(T.toString()))+"-"+r,N={useAnimation:!1};if(w.toolsType===k.Text&&w.opt){const I=w.opt;if(I&&I.boxPoint&&I.text){I.workState=P.Done;const b=I.boxPoint;I.boxPoint=[b[0]+p[0],b[1]+p[1]],I.workState=P.Done;const L=this.control.viewContainerManager.transformToOriginPoint(I.boxPoint,s);this.control.textEditorManager.createTextForMasterController({workId:S,x:L[0],y:L[1],opt:I,scale:((m=c.cameraOpt)==null?void 0:m.scale)||1,type:Ze.Text,isActive:!1,viewId:s,scenePath:n})}y.push({...w,opt:I,type:x.FullWork,workId:S,viewId:s,scenePath:n});continue}if(w.toolsType===k.Image&&(w.opt.uuid=S,w.opt.centerX=w.opt.centerX+p[0],w.opt.centerY=w.opt.centerY+p[1]),w.ops){const I=it(w.ops).map((L,j)=>{const E=j%3;return E===0?L+p[0]:E===1?L+p[1]:L}),b=Re(I);w.ops=b}y.push({...w,updateNodeOpt:N,type:x.FullWork,workId:S,viewId:s,scenePath:n}),f.push([{...w,updateNodeOpt:N,workId:S,msgType:x.FullWork,dataType:F.Local,emitEventType:Y.CopyNode,willSyncService:!1,willRefresh:!0,viewId:s},{workId:S,msgType:x.FullWork,emitEventType:Y.CopyNode}])}f.length&&this.collectForLocalWorker(f),y.length&&this.collectForServiceWorker(y)}}function Bt(a,o,e){return"#"+((a<<16)+(o<<8)+e).toString(16).padStart(6,"0")}function we(a,o=1){return"rgba("+parseInt("0x"+a.slice(1,3))+","+parseInt("0x"+a.slice(3,5))+","+parseInt("0x"+a.slice(5,7))+","+o+")"}function Pt(a,o,e,t=1){return`rgba(${a},${o},${e},${t})`}function Mo(a){const o=a.split(","),e=parseInt(o[0].split("(")[1]),t=parseInt(o[1]),i=parseInt(o[2]),s=Number(o[3].split(")")[0]);return[Bt(e,t,i),s]}function $t(a){const o=a.split(","),e=parseInt(o[0].split("(")[1]),t=parseInt(o[1]),i=parseInt(o[2]),s=Number(o[3].split(")")[0]);return[e,t,i,s]}function Ht(a){return a==="transparent"}class CM extends Fe{constructor(){super(...arguments);g(this,"lastEmtData");g(this,"emitEventType",Y.SetColorNode);g(this,"undoTickerId")}setTextColor(e,t,i,s){const{fontColor:n,fontBgColor:r}=i;t.opt&&(n&&(t.opt.fontColor=n),r&&(t.opt.fontBgColor=r),this.control.textEditorManager.updateTextForMasterController({workId:e,opt:t.opt,viewId:s,canSync:!0,canWorker:!0}))}collect(e){if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,strokeColor:i,fillColor:s,fontColor:n,fontBgColor:r,viewId:c,workState:l,thickness:h,strokeType:u}=e,d=this.control.viewContainerManager.getView(c);if(!(d!=null&&d.displayer))return;const p=d.focusScenePath,f=[...t],y=this.serviceColloctor.storage,m=[],T={};for((l===P.Start||!this.undoTickerId&&l===P.Done)&&(this.undoTickerId=Date.now(),this.mainEngine.internalMsgEmitter.emit("addUndoTicker",this.undoTickerId,c));f.length;){const w=f.pop();if(!w)continue;const v=w.toString(),S=this.serviceColloctor.isLocalId(v),N=S?this.serviceColloctor.transformKey(w):v;let I=v;!S&&this.serviceColloctor.isOwn(I)&&(I=this.serviceColloctor.getLocalId(I));const b=y[c][p][N]||void 0;if(b){const L=b.updateNodeOpt||{};if(n||r){if(n){L.fontColor=n;const[E,A,W,z]=$t(n);T.textColor=[E,A,W],T.textOpacity=z}if(r)if(L.fontBgColor=Ht(r)?"transparent":r,Ht(r))T.textBgColor=void 0,T.textBgOpacity=void 0;else{const[E,A,W,z]=$t(r);T.textBgColor=[E,A,W],T.textBgOpacity=z}if(b.toolsType===k.Text&&b.opt&&l!==P.Start){this.setTextColor(I,Ce(b),L,c),l===P.Done&&(this.undoTickerId=void 0);continue}}if(i){L.strokeColor=i;const[E,A,W,z]=$t(i);T.strokeColor=[E,A,W],T.strokeOpacity=z}if(s)if(L.fillColor=Ht(s)?"transparent":s,Ht(s))T.fillColor=void 0,T.fillOpacity=void 0;else{const[E,A,W,z]=$t(s);T.fillColor=[E,A,W],T.fillOpacity=z}h&&(L.thickness=h,T.strokeWidth=h),u&&(L.strokeType=u,T.strokeType=u);const j={workId:I,msgType:x.UpdateNode,dataType:F.Local,updateNodeOpt:L,emitEventType:this.emitEventType,willRefresh:!0,willRefreshSelector:!0,willSyncService:!0,textUpdateForWoker:!0,viewId:c};m.push([j,{workId:I,msgType:x.UpdateNode,emitEventType:this.emitEventType}])}}m.length&&(l===P.Done&&(this.undoTickerId=void 0),this.collectForLocalWorker(m)),Object.keys(T).length&&setTimeout(()=>{var w;(w=this.control.room)==null||w.setMemberState(T)},0)}}class bM extends Fe{constructor(){super(...arguments);g(this,"lastEmtData");g(this,"emitEventType",Y.ZIndexNode);g(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,s)=>i[1]-s[1]);for(let i=1;i<t.length;i++){const s=t[i][1],n=t[i-1][1];s<=n&&(t[i][1]=n+1)}return t}collect(e){if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,layer:i,viewId:s}=e,n=this.control.viewContainerManager.getView(s);if(!(n!=null&&n.displayer))return;const r=n.focusScenePath,c=[...t],l=this.serviceColloctor.storage,h=[],u=[];for(;c.length;){const p=c.pop();if(!p)continue;const f=p.toString(),y=this.serviceColloctor.isLocalId(f),m=y?this.serviceColloctor.transformKey(p):f;let T=f;!y&&this.serviceColloctor.isOwn(T)&&(T=this.serviceColloctor.getLocalId(T));const w=Ce(l[s][r][m]);let v;if(w&&T===H){if(w.selectIds){u.push(...w.selectIds),u.sort((b,L)=>{var A,W,z,O;const j=((W=(A=l[d(b,this.serviceColloctor)])==null?void 0:A.opt)==null?void 0:W.zIndex)||0,E=((O=(z=l[d(b,this.serviceColloctor)])==null?void 0:z.opt)==null?void 0:O.zIndex)||0;return j>E?1:b<L?-1:0});const S=w.updateNodeOpt||{};S.zIndexLayer=i;const N={workId:p,msgType:x.UpdateNode,dataType:F.Local,updateNodeOpt:S,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:s},I=new Map;i===lt.Top?(this.addMaxLayer(s),v=this.getMaxZIndex(s)):(this.addMinLayer(s),v=this.getMinZIndex(s)),u.forEach(b=>{var A,W,z;const L=(A=this.serviceColloctor)==null?void 0:A.isLocalId(b);let j=L&&((W=this.serviceColloctor)==null?void 0:W.transformKey(b))||b;const E=l[s][r][j];!L&&((z=this.serviceColloctor)!=null&&z.isOwn(j))&&(j=this.serviceColloctor.getLocalId(j)),S.zIndex=v,E!=null&&E.opt&&(E.opt.zIndex=v),E!=null&&E.opt&&I.set(j,{updateNodeOpt:E.updateNodeOpt,opt:E.opt})}),N.selectStore=I,N.willSerializeData=!0,h.push([N,{workId:p,msgType:x.UpdateNode,emitEventType:this.emitEventType}])}continue}}h.length&&this.collectForLocalWorker(h);function d(p,f){return f.isLocalId(p)&&f.transformKey(p)||p}}}class xM extends Fe{constructor(){super(...arguments);g(this,"lastEmtData");g(this,"emitEventType",Y.TranslateNode);g(this,"cachePosition")}collect(e,t){var f;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:i,position:s,workState:n,viewId:r}=e;this.lastEmtData=e;const c=this.control.viewContainerManager.getView(r);if(!(c!=null&&c.displayer))return;const l=c.focusScenePath,h=[...i],u=(f=this.serviceColloctor)==null?void 0:f.storage,d=[],p=n===P.Start&&Date.now()||void 0;for(p&&this.mainEngine.internalMsgEmitter.emit("addUndoTicker",p,r);h.length;){const y=h.pop();if(!y)continue;const m=y.toString(),T=this.serviceColloctor.isLocalId(m),w=T&&this.serviceColloctor.transformKey(y)||m;let v=m;!T&&this.serviceColloctor.isOwn(v)&&(v=this.serviceColloctor.getLocalId(v));const S=u[r][l][w];if(S&&v===H){if(S.selectIds){const N=this.control.viewContainerManager.transformToScenePoint([s.x,s.y],r);if(n===P.Start&&(this.cachePosition=N),this.cachePosition){const I=S.updateNodeOpt||{};I.translate=[N[0]-this.cachePosition[0],N[1]-this.cachePosition[1]],I.workState=n;const b={workId:y,msgType:x.UpdateNode,dataType:F.Local,updateNodeOpt:I,emitEventType:this.emitEventType,willSyncService:!0,textUpdateForWoker:!0,viewId:r};n===P.Done&&(b.textUpdateForWoker=!0,b.willSerializeData=!0,this.cachePosition=void 0),d.push([b,{workId:y,msgType:x.UpdateNode,emitEventType:this.emitEventType}])}}continue}}n===P.Start?this.mainEngine.unWritable():n===P.Done&&(this.mainEngine.abled(),this.lastEmtData=void 0),d.length&&this.collectForLocalWorker(d,t)}}class LM extends Fe{constructor(){super(...arguments);g(this,"lastEmtData");g(this,"emitEventType",Y.DeleteNode)}collect(e){if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,viewId:i}=e,s=this.control.viewContainerManager.getView(i);if(!(s!=null&&s.displayer))return;const n=s.focusScenePath,r=this.serviceColloctor.storage,c=[...t],l=[],h=[],u=Date.now();for(;c.length;){const d=c.pop();if(!d)continue;const p=d.toString(),f=this.serviceColloctor.isLocalId(p),y=f?this.serviceColloctor.transformKey(d):p,m=r[i][n][y];if(m){let T=p;if(!f&&this.serviceColloctor.isOwn(T)&&(T=this.serviceColloctor.getLocalId(T)),m.toolsType===k.Text){this.control.textEditorManager.delete(T,!0,!0);continue}h.push(T)}}h.length&&(l.push([{msgType:x.RemoveNode,emitEventType:Y.DeleteNode,removeIds:h,dataType:F.Local,willSyncService:!0,willRefresh:!0,viewId:i},void 0]),this.mainEngine.internalMsgEmitter.emit("addUndoTicker",u,i),this.collectForLocalWorker(l))}}class zM extends Fe{constructor(){super(...arguments);g(this,"lastEmtData");g(this,"emitEventType",Y.ScaleNode);g(this,"targetText",new Map);g(this,"cacheTextInfo",new Map)}async setTextStyle(e,t,i){const s=await this.control.textEditorManager.updateTextControllerWithEffectAsync({workId:e,opt:t,viewId:i,canSync:!1,canWorker:!1});return{key:e,textInfo:s}}async collect(e,t){var w,v,S,N,I;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:i,workState:s,viewId:n,originPoint:r,scenePoint:c,dir:l,scale:h,translate:u}=e;this.lastEmtData=e;const d=this.control.viewContainerManager.getView(n);if(!(d!=null&&d.displayer))return;const p=d.focusScenePath,f=[...i],y=(w=this.serviceColloctor)==null?void 0:w.storage,m=[],T=s===P.Start&&Date.now()||void 0;for(T&&this.mainEngine.internalMsgEmitter.emit("addUndoTicker",T,n);f.length;){const b=f.pop();if(!b)continue;const L=b.toString(),j=this.serviceColloctor.isLocalId(L),E=j&&this.serviceColloctor.transformKey(b)||L;let A=L;!j&&this.serviceColloctor.isOwn(A)&&(A=this.serviceColloctor.getLocalId(A));const W=y[n][p][E];if(W&&A===H&&W.selectIds){const z=W.updateNodeOpt||{};if(z.dir=l,z.originPoint=r,z.scenePoint=c,z.workState=s,z.scale=h,z.translate=u,s===P.Start){this.cacheTextInfo.clear();for(const ne of W.selectIds){const te=(v=this.serviceColloctor)==null?void 0:v.isLocalId(ne),Q=te&&((S=this.serviceColloctor)==null?void 0:S.transformKey(ne))||ne;let X=Q;!te&&((N=this.serviceColloctor)!=null&&N.isOwn(Q))&&(X=this.serviceColloctor.getLocalId(Q));const G=this.control.textEditorManager.get(X);G&&s===P.Start&&this.targetText.set(X,Ce(G))}}if(this.targetText.size&&s!==P.Start&&h){const ne=[];for(const[Q,X]of this.targetText.entries()){const{opt:G}=X,Z=Math.floor(G.fontSize*h[0]),K=this.cacheTextInfo.get(Q),ce=!K&&G.fontSize!==Z||K&&K.fontSize!==Z||!1,Te=(I=this.control.textEditorManager.get(Q))==null?void 0:I.opt;if(ce&&Te&&G.boxSize&&G.boxPoint){const ie=this.setTextStyle(Q,{...Te,fontSize:Z},n);ne.push(ie)}}const te=await Promise.all(ne);for(const Q of te)if(Q){const{key:X,textInfo:G}=Q;this.cacheTextInfo.set(X,{fontSize:G.opt.fontSize,boxSize:G.opt.boxSize,boxPoint:G.opt.boxPoint})}z.textInfos=this.cacheTextInfo}const O={workId:b,msgType:x.UpdateNode,dataType:F.Local,updateNodeOpt:z,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:n};s===P.Done&&(O.willSerializeData=!0,this.targetText.clear()),m.push([O,{workId:b,msgType:x.UpdateNode,emitEventType:this.emitEventType}]);continue}}s===P.Start?this.mainEngine.unWritable():s===P.Done&&(this.mainEngine.abled(),this.lastEmtData=void 0),m.length&&this.collectForLocalWorker(m,t)}}class PM extends Fe{constructor(){super(...arguments);g(this,"lastEmtData");g(this,"emitEventType",Y.RotateNode);g(this,"cacheOriginRotate",0)}collect(e,t){var f,y,m,T,w;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:i,angle:s,workState:n,viewId:r}=e;this.lastEmtData=e;const c=this.control.viewContainerManager.getView(r);if(!(c!=null&&c.displayer))return;const l=c.focusScenePath,h=[...i],u=(f=this.serviceColloctor)==null?void 0:f.storage,d=[],p=n===P.Start&&Date.now()||void 0;for(p&&this.mainEngine.internalMsgEmitter.emit("addUndoTicker",p,r);h.length;){const v=h.pop();if(!v)continue;const S=v.toString(),N=this.serviceColloctor.isLocalId(S),I=N&&this.serviceColloctor.transformKey(v)||S;let b=S;!N&&this.serviceColloctor.isOwn(b)&&(b=this.serviceColloctor.getLocalId(b));const L=u[r][l][I];if(L&&b===H){if(((y=L.selectIds)==null?void 0:y.length)===1){const j=L.selectIds[0];if(n===P.Start){const z=((m=this.serviceColloctor)==null?void 0:m.isLocalId(j))&&((T=this.serviceColloctor)==null?void 0:T.transformKey(j))||j,O=u[r][l][z];this.cacheOriginRotate=((w=O==null?void 0:O.opt)==null?void 0:w.rotate)||0}const E=L.updateNodeOpt||{};E.angle=(s+this.cacheOriginRotate)%360,E.workState=n;const A={workId:v,msgType:x.UpdateNode,dataType:F.Local,updateNodeOpt:E,emitEventType:this.emitEventType,willRefreshSelector:!1,willSyncService:!0,viewId:r};n===P.Done&&(A.willRefreshSelector=!0,A.willSerializeData=!0,this.cacheOriginRotate=0),d.push([A,{workId:v,msgType:x.UpdateNode,emitEventType:this.emitEventType}])}continue}}n===P.Start?this.mainEngine.unWritable():n===P.Done&&(this.mainEngine.abled(),this.lastEmtData=void 0),d.length&&this.collectForLocalWorker(d,t)}}function DM(a){switch(a){case k.Text:return Ze.Text;case k.SpeechBalloon:case k.Star:case k.Ellipse:case k.Rectangle:case k.Triangle:case k.Rhombus:case k.Polygon:return Ze.Shape}}class AM extends Fe{constructor(){super(...arguments);g(this,"lastEmtData");g(this,"emitEventType",Y.SetFontStyle);g(this,"timerId")}async setTextStyle(e,t,i,s){const{bold:n,underline:r,lineThrough:c,italic:l,fontSize:h}=i;if(t.toolsType&&DM(t.toolsType)===Ze.Text){t.opt&&(n&&(t.opt.bold=n),D.isBoolean(r)&&(t.opt.underline=r),D.isBoolean(c)&&(t.opt.lineThrough=c),l&&(t.opt.italic=l),h&&(t.opt.fontSize=h));const d=await this.control.textEditorManager.updateTextControllerWithEffectAsync({workId:e,opt:t.opt,viewId:s,canSync:!1,canWorker:!1});return{key:e,textInfo:d}}}async collect(e){var w,v,S,N;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,bold:i,italic:s,lineThrough:n,underline:r,viewId:c,fontSize:l}=e,h=this.control.viewContainerManager.getView(c);if(!(h!=null&&h.displayer))return;const u=h.focusScenePath,d=[...t],p=this.serviceColloctor.storage,f={},y=Date.now();this.mainEngine.internalMsgEmitter.emit("addUndoTicker",y,c);const m=[];for(;d.length;){const I=d.pop();if(!I)continue;const b=I.toString(),L=this.serviceColloctor.isLocalId(b),j=L?this.serviceColloctor.transformKey(I):b;let E=b;!L&&this.serviceColloctor.isOwn(E)&&(E=this.serviceColloctor.getLocalId(E));const A=p[c][u][j]||void 0;if(A){const W=A.updateNodeOpt||{};if(i&&(W.bold=i,f.bold=i==="bold"),s&&(W.italic=s,f.italic=s==="italic"),D.isBoolean(n)&&(W.lineThrough=n,f.lineThrough=n),D.isBoolean(r)&&(W.underline=r,f.underline=r),l&&(W.fontSize=l,f.textSize=l),A.toolsType===k.Text&&A.opt){const z=this.setTextStyle(E,D.cloneDeep(A),W,c);m.push(z);continue}if(A&&E===H&&((w=A.selectIds)!=null&&w.length))for(const z of A.selectIds){const O=(v=this.serviceColloctor)==null?void 0:v.isLocalId(z);let ne=O&&((S=this.serviceColloctor)==null?void 0:S.transformKey(z))||z;const te=p[c][u][ne]||void 0;if(!O&&((N=this.serviceColloctor)!=null&&N.isOwn(ne))&&(ne=this.serviceColloctor.getLocalId(ne)),te&&te.toolsType===k.Text&&A.opt){const Q=this.setTextStyle(ne,D.cloneDeep(te),W,c);m.push(Q);continue}}}}const T=await Promise.all(m);for(const I of T)if(I){const{key:b,textInfo:L}=I;L&&(L.canSync=!0,L.canWorker=!0,this.control.textEditorManager.updateForViewEdited(b,L))}Object.keys(f).length&&(this.timerId&&(clearTimeout(this.timerId),this.timerId=void 0),this.timerId=setTimeout(()=>{var I;this.timerId=void 0,(I=this.control.room)==null||I.setMemberState(f)},0))}}class jM extends Fe{constructor(){super(...arguments);g(this,"lastEmtData");g(this,"emitEventType",Y.SetPoint);g(this,"undoTickerId")}collect(e){var w;if(!this.serviceColloctor||!this.mainEngine)return;const{workId:t,pointMap:i,workState:s,viewId:n}=e,r=this.control.viewContainerManager.getView(n);if(!(r!=null&&r.displayer))return;const c=r.focusScenePath,l=(w=this.serviceColloctor)==null?void 0:w.storage,h=[],u=s===P.Start&&Date.now()||void 0;u&&(this.undoTickerId=u,this.mainEngine.internalMsgEmitter.emit("addUndoTicker",u,n));const d=t;if(!d)return;const p=d.toString(),f=this.serviceColloctor.isLocalId(p),y=f&&this.serviceColloctor.transformKey(d)||p;let m=p;!f&&this.serviceColloctor.isOwn(m)&&(m=this.serviceColloctor.getLocalId(m));const T=l[n][c][y];if(T&&m===H&&T.selectIds){const v=T.updateNodeOpt||{};v.pointMap=i,v.workState=s;const S={workId:d,msgType:x.UpdateNode,dataType:F.Local,updateNodeOpt:v,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:n};s===P.Done&&(S.undoTickerId=this.undoTickerId),h.push([S,{workId:d,msgType:x.UpdateNode,emitEventType:this.emitEventType}])}s===P.Start?this.mainEngine.unWritable():s===P.Done&&this.mainEngine.abled(),h.length&&this.collectForLocalWorker(h)}}class EM extends Fe{constructor(){super(...arguments);g(this,"lastEmtData");g(this,"emitEventType",Y.SetLock)}collect(e){if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,isLocked:i,viewId:s}=e,n=this.control.viewContainerManager.getView(s);if(!(n!=null&&n.displayer))return;const r=n.focusScenePath,c=[...t],l=this.serviceColloctor.storage,h=[],u=Date.now();for(;c.length;){const d=c.pop();if(!d)continue;const p=d.toString(),f=this.serviceColloctor.isLocalId(p),y=f?this.serviceColloctor.transformKey(d):p;let m=p;!f&&this.serviceColloctor.isOwn(m)&&(m=this.serviceColloctor.getLocalId(m));const T=l[s][r][y]||void 0;if(T){const w=T.updateNodeOpt||{};w.isLocked=i;const v={workId:m,msgType:x.UpdateNode,dataType:F.Local,updateNodeOpt:w,emitEventType:this.emitEventType,willRefresh:!0,willRefreshSelector:!0,willSyncService:!0,viewId:s};h.push([v,{workId:m,msgType:x.UpdateNode,emitEventType:this.emitEventType}])}}this.mainEngine.internalMsgEmitter.emit("addUndoTicker",u,s),h.length&&this.collectForLocalWorker(h)}}class OM extends Fe{constructor(){super(...arguments);g(this,"lastEmtData");g(this,"emitEventType",Y.SetShapeOpt)}collect(e){if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,viewId:i,...s}=e,n=this.control.viewContainerManager.getView(i);if(!(n!=null&&n.displayer))return;const r=n.focusScenePath,c=[...t],l=this.serviceColloctor.storage,h=[],u=Date.now();for(;c.length;){const d=c.pop();if(!d)continue;const p=d.toString(),f=this.serviceColloctor.isLocalId(p),y=f?this.serviceColloctor.transformKey(d):p;let m=p;!f&&this.serviceColloctor.isOwn(m)&&(m=this.serviceColloctor.getLocalId(m));const T=l[i][r][y]||void 0;if(T){const w={...T.updateNodeOpt,...s,willRefresh:!0};if(T&&m===H){const v={workId:m,msgType:x.UpdateNode,dataType:F.Local,updateNodeOpt:w,emitEventType:this.emitEventType,willRefresh:!0,willRefreshSelector:!0,willSyncService:!0,viewId:i};h.push([v,{workId:m,msgType:x.UpdateNode,emitEventType:this.emitEventType}])}}}h.length&&(this.mainEngine.internalMsgEmitter.emit("addUndoTicker",u,i),this.collectForLocalWorker(h))}}class ee{constructor(o){g(this,"builders",new Map);this.builders=new Map(o.map(e=>[e,this.build(e)]))}build(o){switch(o){case Y.TranslateNode:return new xM;case Y.ZIndexNode:return new bM;case Y.CopyNode:return new kM;case Y.SetColorNode:return new CM;case Y.DeleteNode:return new LM;case Y.ScaleNode:return new zM;case Y.RotateNode:return new PM;case Y.SetFontStyle:return new AM;case Y.SetPoint:return new jM;case Y.SetLock:return new EM;case Y.SetShapeOpt:return new OM}}getBuilder(o){return this.builders.get(o)}registerForMainEngine(o,e){return this.builders.forEach(t=>{t&&t.registerForMainEngine(o,e)}),this}destroy(){this.builders.forEach(o=>{o&&o.destroy()}),this.builders.clear()}pause(){return this.builders.forEach(o=>{o&&o.pause()}),this}recover(){return this.builders.forEach(o=>{o&&o.recover()}),this}static emitMethod(o,e,t){Fe.dispatch(o,e,t)}static activeListener(o){Se.InternalMsgEmitter.on(Y.ActiveMethod,o)}static unmountActiveListener(o){Se.InternalMsgEmitter.off(Y.ActiveMethod,o)}}class RM{constructor(o){g(this,"master");g(this,"mainThreadWorkerMap",new Map);this.master=o}updateCamera(){for(const[o,e]of this.mainThreadWorkerMap.entries()){const t=this.master.control.viewContainerManager.getView(o);if(t){const{cameraOpt:i}=t;e.updateCamera({cameraOpt:i,viewId:t.viewId,msgType:x.UpdateCamera,dataType:F.Local})}}}notifyDrawCount(o){const e=this.master.getWorkDrawCount(),t=this.mainThreadWorkerMap.get(o);t&&t.clearDrawLayer(e)}clearDrawCount(o){const e=this.mainThreadWorkerMap.get(o);e&&e.clearDrawLayer(1/0)}createMainThreadWorker(o,e){return new YM(o,e,this)}consume(o){var e;for(const t of o.values()){const{msgType:i,viewId:s,layerOpt:n,offscreenCanvasOpt:r,cameraOpt:c}=t;if(i===x.Console){console.log(this);continue}if(i===x.Init){const h=(e=this.master.control.viewContainerManager.getView(s))==null?void 0:e.displayer,u=h==null?void 0:h.subLocalCanvasContainerRef.current;if(h&&u&&n&&r){const d=this.createMainThreadWorker(s,{displayer:h,container:u,layerOpt:n,master:this.master,canvasOpt:r,post:this.post.bind(this)});this.mainThreadWorkerMap.set(s,d),d&&c&&d.setCameraOpt(c)}continue}if(i===x.TasksQueue)continue;const l=this.mainThreadWorkerMap.get(s);l&&(l.on(t),i===x.Destroy&&(l.destroy(),this.mainThreadWorkerMap.delete(s)))}}post(o){const{sp:e}=o;e&&this.master.collectorSyncData(e)}destroy(){for(const o of this.mainThreadWorkerMap.values())o.destroy();this.mainThreadWorkerMap.clear()}active(){}}class YM{constructor(o,e,t){g(this,"viewId");g(this,"opt");g(this,"manager");g(this,"subLocalLayer");g(this,"subLocalWork");g(this,"scene");g(this,"cameraOpt");this.viewId=o,this.opt=e,this.manager=t,this.scene=this.createScene({...e.canvasOpt,container:e.container});const i=be.bufferSize.full,s=be.bufferSize.sub;this.subLocalLayer=this.createLayer("subLocalLayer",this.scene,{...e.layerOpt,bufferSize:this.viewId===de?i:s,contextType:"2d"});const n={thread:this};this.subLocalWork=new WM(n)}createScene(o){return new he.Scene({displayRatio:this.opt.displayer.dpr,depth:!1,desynchronized:!0,...o,contextType:"2d",autoRender:!0,id:this.viewId})}createLayer(o,e,t){const{width:i,height:s}=t,n=`canvas-${o}`,r=e.layer(n,{...t,offscreen:!1}),c=new he.Group({anchor:[.5,.5],pos:[i*.5,s*.5],size:[i,s],name:"viewport",id:o});return r.append(c),c}updateScene(o){this.scene.attr({...o});const{width:e,height:t}=o;this.scene.width=e,this.scene.height=t,this.updateLayer({width:e,height:t})}updateLayer(o){const{width:e,height:t}=o;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(o){this.scene.displayRatio=o}on(o){const{msgType:e,toolsType:t,opt:i,dataType:s,workId:n,workState:r}=o,c=n==null?void 0:n.toString();switch(e){case x.Destroy:this.destroy();break;case x.Clear:this.clearAll();break;case x.UpdateDpr:D.isNumber(o.dpr)&&this.updateDpr(o.dpr);break;case x.UpdateCamera:this.updateCamera(o);break;case x.UpdateTools:if(t&&this.subLocalWork.canUseSubWorkerLayer(t)&&i){const l={toolsType:t,toolsOpt:i};this.subLocalWork.setToolsOpt(l)}break;case x.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 x.DrawWork:t&&this.subLocalWork.canUseSubWorkerLayer(t)&&(r===P.Done&&s===F.Local?this.subLocalWork.consumeDrawAll(o):this.subLocalWork.consumeDraw(o));break;case x.RemoveNode:this.subLocalWork.removeNode(o);return}}setCameraOpt(o){this.cameraOpt=o;const{scale:e,centerX:t,centerY:i,width:s,height:n}=o;(s!==this.scene.width||n!==this.scene.height)&&this.updateScene({width:s,height:n}),this.subLocalLayer&&(this.subLocalLayer.setAttribute("scale",[e,e]),this.subLocalLayer.setAttribute("translate",[-t,-i]))}updateCamera(o){const{cameraOpt:e}=o;e&&!D.isEqual(this.cameraOpt,e)&&(this.subLocalWork.workShapes.size&&this.clearAll(),this.setCameraOpt(e))}clearAll(){this.subLocalLayer.children.length&&(this.subLocalLayer.parent.children.forEach(o=>{o.name!=="viewport"&&o.remove()}),this.subLocalLayer.removeAllChildren()),this.subLocalWork.clearAll()}destroy(){this.subLocalLayer.remove(),this.scene.remove(),this.subLocalWork.destroy()}clearDrawLayer(o){if(o===1/0){this.clearAll();return}const e=this.subLocalLayer.children.filter(t=>t.id&&D.isNumber(parseInt(t.id))&&parseInt(t.id)<o);for(const t of e)t.disconnect(),this.subLocalLayer.removeChild(t)}}class WM{constructor(o){g(this,"thread");g(this,"workShapes",new Map);g(this,"tmpOpt");g(this,"syncUnitTime",be.syncOpt.interval);g(this,"drawCount",0);this.thread=o.thread}getToolsOpt(){return this.tmpOpt}consumeDrawAll(o){const{workId:e}=o,t=e==null?void 0:e.toString();t&&this.workShapes.get(t)&&(this.drawCount=0,this.thread.subLocalLayer.removeAllChildren(),this.clearWorkShapeNodeCache(t))}consumeDraw(o){const{workId:e,toolsType:t,postCount:i}=o;e&&t&&this.canUseSubWorkerLayer(t)&&(this.getWorkShape(e.toString())||this.createLocalWork(o));const s=e==null?void 0:e.toString(),n=s&&this.workShapes.get(s);if(!n)return;n.consume({data:o,drawCount:this.drawCount,isFullWork:!1,isSubWorker:!0}),this.drawCount++;const r=this.thread.manager.master;r.setSubWorkerDrawCount(this.drawCount);const c=Math.max(r.getMaxDrawCount(),this.drawCount);r.setMaxDrawCount(c),D.isNumber(i)&&r.setConsumeCount(i)}removeNode(o){const{workId:e}=o,t=e==null?void 0:e.toString();t&&this.workShapes.has(t)&&(this.thread.subLocalLayer.getElementsByName(t).forEach(s=>{s.remove()}),this.clearWorkShapeNodeCache(t))}createLocalWork(o){const{workId:e,toolsType:t,opt:i}=o,s=e==null?void 0:e.toString();t&&this.canUseSubWorkerLayer(t)&&s&&i&&(this.getToolsOpt()||this.setToolsOpt({toolsType:t,toolsOpt:i}),this.setWorkOptions(s,i))}setWorkOptions(o,e){let t=this.workShapes.get(o);if(!t&&this.tmpOpt){const{toolsType:i}=this.tmpOpt;this.tmpOpt.toolsOpt=e,t=this.createWorkShapeNode({workId:o,toolsType:i,toolsOpt:e}),t&&this.workShapes.set(o,t),this.setToolsOpt(this.tmpOpt)}e!=null&&e.syncUnitTime||(e.syncUnitTime=this.syncUnitTime),t&&t.setWorkOptions(e)}destroy(){this.clearAll()}clearAll(){this.thread.subLocalLayer.removeAllChildren(),this.workShapes.clear()}canUseSubWorkerLayer(o){return o===k.Pencil}setToolsOpt(o){var e;this.tmpOpt=o,(e=o.toolsOpt)!=null&&e.syncUnitTime&&(this.syncUnitTime=o.toolsOpt.syncUnitTime)}createWorkShapeNode(o){return go({...o,fullLayer:this.thread.subLocalLayer,drawLayer:this.thread.subLocalLayer})}clearWorkShapeNodeCache(o){this.workShapes.delete(o)}getWorkShape(o){return this.workShapes.get(o)}}const UM=async(a,o)=>{const{src:e,isgl:t,isCache:i}=a;if(typeof Image=="function"){const s=new Image;return typeof e=="string"&&(s.crossOrigin="anonymous"),new Promise(n=>{s.onload=function(){createImageBitmap(s,{imageOrientation:t?"flipY":"none"}).then(r=>{n(r)})},s.onerror=function(){n(void 0)},s.src=e})}else return fetch(e,{method:"GET",mode:"cors",cache:"default"}).then(s=>s.blob()).then(s=>createImageBitmap(s,{imageOrientation:t?"flipY":"none"}).then(n=>n))};class BM{constructor(){g(this,"maxLastSyncTime",be.syncOpt.interval)}setCurrentToolsData(o){this.currentToolsData=o}getCurrentToolsData(){return this.currentToolsData}setCurrentLocalWorkData(o){this.currentLocalWorkData=o}getWorkId(){return this.currentLocalWorkData.workId}getWorkState(){return this.currentLocalWorkData.workState}}class FM extends BM{constructor(e){var s,n;super();g(this,"isActive",!1);g(this,"currentToolsData");g(this,"currentLocalWorkData");g(this,"control");g(this,"internalMsgEmitter");g(this,"taskBatchData",new Set);g(this,"fullWorker");g(this,"subWorker");g(this,"fullWorkerUrl");g(this,"subWorkerUrl");g(this,"methodBuilder");g(this,"zIndexNodeMethod");g(this,"subWorkerDrawCount",0);g(this,"wokerDrawCount",0);g(this,"maxDrawCount",0);g(this,"_consumeCount",0);g(this,"_postCount",0);g(this,"reRenders",new Map);g(this,"localWorkViewId");g(this,"localPointsBatchData",new Map);g(this,"tasksqueue",new Map);g(this,"useTasksqueue",!1);g(this,"useTasksClockId");g(this,"mainTasksqueueCount");g(this,"workerTasksqueueCount");g(this,"snapshotMap",new Map);g(this,"boundingRectMap",new Map);g(this,"clearAllResolveMap",new Map);g(this,"delayWorkStateToDoneResolve");g(this,"animationId");g(this,"tmpImageConfigMap",new Map);g(this,"mainThread");g(this,"willSelectorWorkId");g(this,"isLockSentEventCursor",!1);g(this,"subMainThreadWorker");g(this,"getVNodeInfoResolveMap",new Map);const{control:t,internalMsgEmitter:i}=e;this.control=t,this.maxLastSyncTime=((n=(s=this.control.pluginOptions)==null?void 0:s.syncOpt)==null?void 0:n.interval)||this.maxLastSyncTime,this.fullWorkerUrl=this.control.pluginOptions.cdn.fullWorkerUrl,this.subWorkerUrl=this.control.pluginOptions.cdn.subWorkerUrl,this.internalMsgEmitter=i,this.currentLocalWorkData={workState:P.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===k.Pencil||e===k.LaserPen||e===k.Arrow||e===k.Straight||e===k.Ellipse||e===k.Rectangle||e===k.Star||e===k.Polygon||e===k.SpeechBalloon}get isCanDrawWork(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===k.Pencil||e===k.LaserPen||e===k.Arrow||e===k.Straight||e===k.Ellipse||e===k.Rectangle||e===k.Star||e===k.Polygon||e===k.SpeechBalloon||e===k.Triangle||e===k.Rhombus||e===k.BitMapEraser}get isUseZIndex(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===k.Pencil||e===k.Arrow||e===k.Straight||e===k.Ellipse||e===k.Rectangle||e===k.Star||e===k.Polygon||e===k.SpeechBalloon||e===k.Text||e===k.Image}get isCanRecordUndoRedo(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===k.Pencil||e===k.Eraser||e===k.BitMapEraser||e===k.Arrow||e===k.Straight||e===k.Ellipse||e===k.Rectangle||e===k.Star||e===k.Polygon||e===k.SpeechBalloon||e===k.Text||e===k.Image}get isCanSentCursor(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===k.Pencil||e===k.Text||e===k.LaserPen||e===k.Arrow||e===k.Straight||e===k.Ellipse||e===k.Rectangle||e===k.Star||e===k.Polygon||e===k.SpeechBalloon||e===k.Triangle||e===k.Rhombus||e===k.Eraser||e===k.PencilEraser||e===k.BitMapEraser}get isPostCountType(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===k.Eraser||e===k.PencilEraser||e===k.BitMapEraser}get isCanStartEventConsum(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===k.Selector||e===k.Eraser||e===k.PencilEraser||e===k.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-BwLQzsnp.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 RM(this),this.fullWorker.onmessage=e=>{var t,i;if(e.data){const{render:s,sp:n,drawCount:r,workerTasksqueueCount:c,viewId:l,consumeCount:h}=e.data;h&&(console.log("====>consumeCount",h),this.consumeCount=h),this.isBusy&&c&&this.setWorkerTasksqueueCount(c),n!=null&&n.length&&this.collectorSyncData(n);const u=(s==null?void 0:s.length)&&s||[];if(r&&l){if(this.setWorkDrawCount(r),this.wokerDrawCount<1/0){const d=Math.max(this.maxDrawCount,this.wokerDrawCount);this.setMaxDrawCount(d),this.control.priority==="ui"?(t=this.subMainThreadWorker)==null||t.notifyDrawCount(l):this.clearReRenders(this.wokerDrawCount)}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())u.push(...d)}u.length&&this.viewContainerManager.render(u)}},this.subWorker.onmessage=e=>{if(e.data){const{render:t,sp:i,drawCount:s}=e.data;i!=null&&i.length&&this.collectorSyncData(i);const n=(t==null?void 0:t.length)&&t||[];if(this.control.priority==="cpu"&&D.isNumber(s)){if(this.setSubWorkerDrawCount(s),this.wokerDrawCount<1/0){const r=Math.max(this.maxDrawCount,this.subWorkerDrawCount);this.setMaxDrawCount(r)}if(t!=null&&t.length)if(this.subWorkerDrawCount>this.wokerDrawCount){const r=[];for(const c of t)c.imageBitmap&&(c.isUnClose=!0,r.push(c));this.reRenders.set(this.subWorkerDrawCount,r)}else this.reRenders.size&&this.clearReRenders(this.subWorkerDrawCount)}n.length&&this.viewContainerManager.render(n)}}}clearReRenders(e=1/0){for(const t of this.reRenders.keys())if(D.isNumber(Number(t))&&Number(t)<=e){const i=this.reRenders.get(Number(t));i==null||i.forEach(s=>{var n;(n=s.imageBitmap)==null||n.close()}),this.reRenders.delete(t)}}get isBusy(){return this.getTasksqueueState()===P.Doing}getLockSentEventCursor(){return this.isLockSentEventCursor}setLockSentEventCursor(e){this.isLockSentEventCursor=e}getTasksqueueState(){return this.useTasksqueue&&P.Doing||P.Done}setMaxDrawCount(e){this.maxDrawCount=e}getWorkDrawCount(){return this.wokerDrawCount}getSubWorkerDrawCount(){return this.subWorkerDrawCount}getMaxDrawCount(){return this.maxDrawCount}setWorkDrawCount(e){this.wokerDrawCount=e}setSubWorkerDrawCount(e){this.subWorkerDrawCount=e}setConsumeCount(e){this.consumeCount=e}setWorkerTasksqueueCount(e){const t=Math.max(this.workerTasksqueueCount||0,e);this.workerTasksqueueCount=t}collectorSyncData(e){var i,s,n,r;let t=!1;for(const c of e){const{type:l,selectIds:h,opt:u,selectRect:d,strokeColor:p,fillColor:f,willSyncService:y,isSync:m,imageBitmap:T,canvasHeight:w,canvasWidth:v,rect:S,op:N,canTextEdit:I,points:b,selectorColor:L,canRotate:j,scaleType:E,textOpt:A,toolsType:W,workId:z,viewId:O,dataType:ne,canLock:te,isLocked:Q,shapeOpt:X,toolsTypes:G,thickness:Z,strokeType:K,useStroke:ce,isgl:Te,imageSrc:ie,isSubWorker:le}=c;if(!O)return;const J=c.scenePath||this.viewContainerManager.getCurScenePath(O);switch(l){case x.Select:{const $=h!=null&&h.length?{...d,selectIds:h,canvasHeight:w,canvasWidth:v,points:b}:void 0;$&&(u!=null&&u.strokeColor)&&($.selectorColor=u.strokeColor),$&&L&&($.selectorColor=L),$&&p&&($.strokeColor=p),$&&(u!=null&&u.fillColor)&&($.fillColor=u.fillColor),$&&f&&($.fillColor=f),$&&D.isBoolean(j)&&($.canRotate=j),$&&E&&($.scaleType=E),$&&I&&($.canTextEdit=I),$&&A&&($.textOpt=A),$&&D.isBoolean(te)&&($.canLock=te),$&&D.isBoolean(Q)&&($.isLocked=Q),$&&X&&($.shapeOpt=X),$&&G&&($.toolsTypes=G),$&&Z&&($.thickness=Z),$&&K&&($.strokeType=K),$&&D.isBoolean(ce)&&($.useStroke=ce),O&&this.viewContainerManager.showFloatBar(O,!!$,$),y&&((i=this.collector)==null||i.dispatch({type:l,selectIds:h,opt:u,isSync:m,viewId:O,scenePath:J}));break}case x.Snapshot:if(T&&J){const $=this.snapshotMap.get(J);$&&$(T)}break;case x.BoundingBox:if(S&&J){const $=this.boundingRectMap.get(J);$&&$(S)}break;case x.Cursor:N&&this.control.cursor.collectServiceCursor({...c});break;case x.Clear:if(O){this.viewContainerManager.showFloatBar(O,!1);const $=(s=this.clearAllResolveMap.get(O))==null?void 0:s.resolve;$&&$(O)}break;case x.TextUpdate:if(W===k.Text&&z&&O){const $=this.viewContainerManager.transformToOriginPoint((u==null?void 0:u.boxPoint)||[0,0],O),ue=(u==null?void 0:u.boxSize)||[0,0],fe=(n=this.viewContainerManager.getView(O))==null?void 0:n.cameraOpt;u?this.control.textEditorManager.updateTextForWorker({x:$[0],y:$[1],w:ue[0],h:ue[1],scale:(fe==null?void 0:fe.scale)||1,workId:z,opt:u,dataType:ne,viewId:O,canSync:y||!1,canWorker:!1}):this.control.textEditorManager.delete(z,y||!1,!1)}break;case x.GetTextActive:W===k.Text&&z&&O&&this.control.textEditorManager.updateTextForWorker({workId:z,isActive:!0,viewId:O,dataType:F.Local,canWorker:!1,canSync:!0},Date.now());break;case x.GetImageBitMap:ie&&O&&z&&UM({src:ie,isgl:Te}).then($=>{var fe;const ue=new Set;if(ue.add({msgType:x.GetImageBitMap,dataType:F.Local,workId:z,viewId:O,imageSrc:ie,isSubWorker:le,imageBitmap:$}),!this.control.hasOffscreenCanvas())(fe=this.mainThread)==null||fe.consume(ue);else{const je=le?this.subWorker:this.fullWorker;$?je.postMessage(ue,[$]):je.postMessage(ue)}});break;case x.GetVNodeInfo:if(z){const $=z.toString(),ue=(r=this.getVNodeInfoResolveMap.get($))==null?void 0:r.resolve,fe={...c,uuid:$};ue&&ue(fe)}break;default:t=!0;break}}t&&Be(()=>{this.collectorAsyncData(e)},this.maxLastSyncTime)}collectorAsyncData(e){var t,i,s,n;for(const r of e){const{type:c,op:l,workId:h,index:u,removeIds:d,ops:p,opt:f,updateNodeOpt:y,toolsType:m,isSync:T,viewId:w,isLockSentEventCursor:v,nextTasks:S}=r;if(!w){console.error("collectorAsyncData",r);return}const N=r.scenePath||this.viewContainerManager.getCurScenePath(w);switch(c){case x.None:{v&&Be(()=>{this.setLockSentEventCursor(!1)},this.maxLastSyncTime);break}case x.DrawWork:{(t=this.collector)==null||t.dispatch({type:c,op:l,opt:f,toolsType:m,workId:h,index:u,isSync:T,viewId:w,scenePath:N,updateNodeOpt:y});break}case x.FullWork:{(i=this.collector)==null||i.dispatch({type:c,ops:p,workId:h,updateNodeOpt:y,opt:f,toolsType:m,isSync:T,viewId:w,scenePath:N}),this.willSelectorWorkId&&h&&h.toString()===this.willSelectorWorkId&&this.control.runEffectWork(()=>{this.setShapeSelectorByWorkId(this.willSelectorWorkId,w),this.willSelectorWorkId=void 0});break}case x.UpdateNode:{(s=this.collector)==null||s.dispatch({type:c,updateNodeOpt:y,workId:h,opt:f,ops:p,op:l,isSync:T,viewId:w,scenePath:N});break}case x.RemoveNode:{d&&this.control.textEditorManager.deleteBatch(d,!1,!1),(n=this.collector)==null||n.dispatch({type:c,removeIds:d,isSync:T,viewId:w,scenePath:N}),this.willSelectorWorkId&&(d!=null&&d.includes(this.willSelectorWorkId))&&(this.willSelectorWorkId=void 0);break}}S&&Be(()=>{this.collectorAsyncData(S)},this.maxLastSyncTime)}}async onLocalEventEnd(e,t){var l;const i=this.viewContainerManager.getView(t);if(!i)return;const{focusScenePath:s,cameraOpt:n}=i,r=this.viewContainerManager.transformToScenePoint(e,t),c=[];for(const h of this.localPointsBatchData.keys())if(((l=this.currentToolsData)==null?void 0:l.toolsType)===k.Text){const u=this.getLocalPointInfo(h),d=u==null?void 0:u.state;if(d&&d===P.Start){const p=this.currentLocalWorkData.toolsOpt;p.workState=P.Doing,p.boxPoint=r,p.boxSize=[p.fontSize,p.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:p,type:Ze.Text,isActive:!0,viewId:t,scenePath:s},Date.now())}this.deleteLocalPoint(h);continue}else this.pushLocalPoint(h,r,P.Done,t),c.push(h);if(c.length){try{if(await new Promise(u=>{setTimeout(async()=>{c.forEach(d=>{this.setLocalPointIsFullWork(d)}),this.delayWorkStateToDoneResolve=u,this.consume()},0)})&&c[0]){const u=c[0];c.forEach(d=>{this.deleteLocalPoint(d)}),this.willSelectorWorkId=u.toString()}}catch(h){console.log("error",h)}this.delayWorkStateToDoneResolve=void 0,c.length=0}}onLocalEventDoing(e,t){var s;if(((s=this.currentToolsData)==null?void 0:s.toolsType)===k.Text)return;this.currentLocalWorkData.workState===P.Start&&this.setCurrentLocalWorkData({...this.currentLocalWorkData,workState:P.Doing});let i=!1;for(const[n,{state:r}]of this.localPointsBatchData.entries())if(this.isAbled()&&r!==P.Pending){const c=this.viewContainerManager.transformToScenePoint(e,t);this.pushLocalPoint(n,c,r===P.Start?P.Doing:r,t),i=!0}if(i){this.runAnimation();return}this.useTasksqueue||this.hoverCursor(e,t)}onLocalEventStart(e,t){var c,l,h;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,s=i===k.Selector?H:Date.now(),n=this.setZIndex(t);this.setCurrentLocalWorkData({workState:P.Start,toolsOpt:n,viewId:t});const r=this.viewContainerManager.transformToScenePoint(e,t);if(this.pushLocalPoint(s,r,P.Start,t,n),i!==k.Text){if(this.control.textEditorManager.checkEmptyTextBlur(),this.isCanRecordUndoRedo&&this.internalMsgEmitter.emit("addUndoTicker",s,t),s&&n&&i&&this.isCanStartEventConsum&&this.prepareOnceWork({workId:s,toolsOpt:n,viewId:t},i),this.consumeCount=0,this.postCount=0,this.maxDrawCount=0,this.wokerDrawCount=0,this.subWorkerDrawCount=0,this.clearReRenders(1/0),(l=this.subMainThreadWorker)==null||l.clearDrawCount(t),this.isCanDrawWork){const u=this.viewContainerManager.getCurScenePath(t);u&&((h=this.collector)!=null&&h.hasSelector(t,u))&&this.blurSelector(t,u)}this.consume()}}setLocalPointIsFullWork(e){const t=this.getLocalPointInfo(e);t&&(t.isFullWork=!0,this.localPointsBatchData.set(e,t))}pushLocalPoint(e,t,i,s,n){let r=this.getLocalPointInfo(e);i===P.Start?r={state:P.Start,points:t,opt:n||this.currentLocalWorkData.toolsOpt,isFullWork:!1,viewId:s}:r&&(r.state=i,r.points.push(t[0],t[1])),r&&this.localPointsBatchData.set(e,r)}deleteLocalPoint(e){this.localPointsBatchData.delete(e)}getLocalPointInfo(e){return this.localPointsBatchData.get(e)}getLocalPointsInfo(){return this.localPointsBatchData}correctStorage(e,t,i){var c;const s=new Map,n=[];Object.keys(e).forEach(l=>{var u,d;const h=(d=(u=e[l])==null?void 0:u.opt)==null?void 0:d.zIndex;D.isNumber(h)&&n.push([l,h])});const r=n.length&&((c=this.zIndexNodeMethod)==null?void 0:c.correct(n))||[];this.zIndexNodeMethod&&r.length&&(this.zIndexNodeMethod.setMinZIndex(r[0][1]||0,t),this.zIndexNodeMethod.setMaxZIndex(r[r.length-1][1]||0,t));for(const[l,h]of r){if(!e[l])continue;const u=e[l];u.opt&&D.isNumber(u.opt.zIndex)&&u.opt.zIndex!==h&&(u.opt.zIndex=h,s.set(l,u))}return s.size&&s.forEach((l,h)=>{var u;(u=this.collector)==null||u.updateValue(h,l,{viewId:t,scenePath:i,isSync:!0}),e[h]=l}),e}async originalEventLintener(e,t,i){var r,c;if(!this.isAbled())return;const s=(r=this.collector)==null?void 0:r.uid,n=this.viewContainerManager.getCurScenePath(i);if(!(s&&!this.control.renderControl.isWriteable())){switch((c=this.currentToolsData)==null?void 0:c.toolsType){case k.Eraser:case k.PencilEraser:case k.BitMapEraser:{if(s&&!this.control.renderControl.isClearAble({uid:s,viewId:i,scenePath:n}))return;break}default:{if(s&&!this.control.renderControl.isRenderAble({uid:s,viewId:i,scenePath:n}))return;break}}switch(Be(()=>{this.control.pluginManager.dispatchPluginEvent("localEvent",i,e,t)},yo),e){case P.Start:this.setLocalWorkViewId(i),i&&this.onLocalEventStart(t,i);break;case P.Doing:i&&i===this.getLocalWorkViewId()&&this.onLocalEventDoing(t,i);break;case P.Done:i&&i===this.getLocalWorkViewId()&&await this.onLocalEventEnd(t,i);break}}}getLocalWorkViewId(){return this.localWorkViewId}setLocalWorkViewId(e){this.localWorkViewId=e}setCurrentToolsData(e){var s,n,r;const t=e.toolsType,i=((s=this.currentToolsData)==null?void 0:s.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:h,focusScenePath:u}=l;i&&h&&u&&((r=this.collector)!=null&&r.hasSelector(h,u)&&this.blurSelector(h,u),this.control.textEditorManager.checkEmptyTextBlur())}this.taskBatchData.add({msgType:x.UpdateTools,dataType:F.Local,toolsType:t,opt:{...e.toolsOpt,syncUnitTime:this.maxLastSyncTime},isRunSubWork:this.isRunSubWork,viewId:Gt}),this.runAnimation()}}prepareOnceWork(e,t){const{workId:i,toolsOpt:s,viewId:n}=e,r={msgType:x.CreateWork,dataType:F.Local,viewId:n,toolsType:t};this.queryTaskBatchData(r).forEach(c=>{this.taskBatchData.delete(c)}),this.taskBatchData.add({...r,workId:i,opt:{...s,syncUnitTime:this.maxLastSyncTime},dataType:F.Local,isRunSubWork:this.isRunSubWork}),this.runAnimation()}createViewWorker(e,t){const{offscreenCanvasOpt:i,layerOpt:s,dpr:n,cameraOpt:r}=t;this.taskBatchData.add({msgType:x.Init,dataType:F.Local,viewId:e,offscreenCanvasOpt:i,layerOpt:s,dpr:n,cameraOpt:r,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:x.Destroy,dataType:F.Local,viewId:e,isRunSubWork:!0}),this.consume(),t||(i=this.collector)==null||i.dispatch({type:x.Clear,viewId:e}),this.control.renderControl.destoryByViewId(e,t)}onServiceDerive(e,t){var p,f,y,m,T;const{newValue:i,oldValue:s,viewId:n,scenePath:r}=t,c=D.cloneDeep(i)||{},l=e;let h=c.type;if(!i&&s){if(l&&((p=this.collector)==null?void 0:p.getLocalId(l))===H){this.collector.isOwn(l)?this.blurSelector(n,r):this.blurSelector(n,r,l);return}if(h=x.RemoveNode,s.toolsType===k.LaserPen)return}const u=(f=this.viewContainerManager.getView(n))==null?void 0:f.focusScenePath;if(u&&u!==r)return;if(h&&l){if(!this.control.renderControl.isFilterAble({viewId:n,elementId:e,scenePath:r},h))return;const w=c;if(w.workId=(y=this.collector)!=null&&y.isOwn(l)?(m=this.collector)==null?void 0:m.getLocalId(l):l,w.msgType=h,w.toolsType===k.LaserPen&&(w.isRunSubWork=!0),w.dataType=F.Service,w.viewId=n,w.scenePath=r,w.selectIds&&(w.selectIds=w.selectIds.map(v=>{var S,N;return(S=this.collector)!=null&&S.isOwn(v)?(N=this.collector)==null?void 0:N.getLocalId(v):v})),w&&w.toolsType===k.Text||(s==null?void 0:s.toolsType)===k.Text){this.control.textEditorManager.onServiceDerive(w);return}this.taskBatchData.add(w)}this.runAnimation();const d=t.newValue&&((T=t.newValue.opt)==null?void 0:T.zIndex);if(this.zIndexNodeMethod&&D.isNumber(d)){const w=this.zIndexNodeMethod.getMinZIndex(n);this.zIndexNodeMethod.getMaxZIndex(n)<d&&this.zIndexNodeMethod.setMaxZIndex(d,n),w>d&&this.zIndexNodeMethod.setMinZIndex(d,n)}}pullServiceData(e,t,i={isAsync:!1,useAnimation:!1}){var c,l,h,u;let s=(c=this.collector)==null?void 0:c.getStorageData(e,t);const{isAsync:n,useAnimation:r}=i;if(s){this.control.renderControl.isWriteable()&&(s=this.correctStorage(s,e,t));const d=Object.keys(s);for(const p of d){const f=(l=s[p])==null?void 0:l.type;if(f&&p){if(!this.control.renderControl.isFilterAble({viewId:e,elementId:p,scenePath:t},f))continue;const y=s[p];if(y.workId=(h=this.collector)!=null&&h.isOwn(p)?(u=this.collector)==null?void 0:u.getLocalId(p):p,y.msgType=f,y.dataType=F.Service,y.viewId=e,y.scenePath=t,y.useAnimation=!!r,y.selectIds&&(y.selectIds=y.selectIds.map(m=>{var T,w;return(T=this.collector)!=null&&T.isOwn(m)?(w=this.collector)==null?void 0:w.getLocalId(m):m})),y.toolsType===k.Text){this.control.textEditorManager.onServiceDerive(y);continue}this.taskBatchData.add(y)}this.internalMsgEmitter.emit("excludeIds",d,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(),s=!!i.size;if(this.taskBatchData.size)for(const n of this.taskBatchData.values())n.dataType===F.Service&&(i.add(n),this.taskBatchData.delete(n));i.size?(this.post(i),s&&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:s,isFullWork:n,points:r,opt:c}]of this.localPointsBatchData.entries()){if(s===P.Done&&!n||s===P.Start&&!this.isCanStartEventConsum)continue;const l=r.map(h=>h);if(l.length){if(this.isPostCountType&&s===P.Doing){if(this.postCount>this.consumeCount)continue;this.postCount++}this.delayWorkStateToDoneResolve&&s===P.Done&&(this.delayWorkStateToDoneResolve(!0),this.setLockSentEventCursor(!0)),this.taskBatchData.add({op:l,workState:s,workId:i,dataType:F.Local,msgType:x.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}),r.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:P.Unwritable,workId:void 0})}abled(){this.setCurrentLocalWorkData({workState:P.Pending,workId:void 0})}isAbled(){return this.currentLocalWorkData.workState!==P.Unwritable}post(e){var i;if(!this.control.hasOffscreenCanvas()){if(!this.mainThread){let s=[];s=D.cloneDeep([...e]),setTimeout(()=>{for(const n of s)this.taskBatchData.add(n)},0);return}this.mainThread.consume(e);return}this.fullWorker.postMessage(e);const t=new Set;for(const s of e.values()){const n=s.msgType;(n===x.Init||n===x.Clear||n===x.Destroy||n===x.UpdateCamera||s.isRunSubWork)&&t.add(s)}t.size&&(this.subWorker.postMessage(t),this.control.priority==="ui"&&((i=this.subMainThreadWorker)==null||i.consume(t)))}updateNode(e,t,i,s){this.taskBatchData.add({msgType:x.UpdateNode,workId:e,updateNodeOpt:t,viewId:i,scenePath:s,dataType:F.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:x.UpdateDpr,dataType:F.Local,viewId:e}).forEach(i=>{this.taskBatchData.delete(i)}),this.taskBatchData.add({dataType:F.Local,msgType:x.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:x.UpdateCamera,dataType:F.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:x.TasksQueue,dataType:F.Local,isRunSubWork:!0,mainTasksqueueCount:this.mainTasksqueueCount,tasksqueue:this.tasksqueue,viewId:""});for(const[i,s]of this.tasksqueue.entries())s.cameraOpt&&this.control.textEditorManager.onCameraChange(s.cameraOpt,i)}return e}async clearViewScenePath(e,t,i){var n,r;const s=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:s}))return}this.control.textEditorManager.clear(e,t),this.queryTaskBatchData({msgType:x.Clear,dataType:F.Local,viewId:e}).forEach(c=>{this.taskBatchData.delete(c)}),this.taskBatchData.add({dataType:F.Local,msgType:x.Clear,viewId:e}),this.runAnimation(),t||(this.control.renderControl.isUsePageAuth(e)&&s?this.control.renderControl.clearRenderPage(e,s):(r=this.collector)==null||r.dispatch({type:x.Clear,viewId:e,scenePath:s})),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 h=this.clearAllResolveMap.get(e);h!=null&&h.resolve&&h.resolve(e)},this.maxLastSyncTime),this.clearAllResolveMap.set(e,l)}).then(c=>{this.clearAllResolveMap.delete(c)})}internalMsgEmitterListener(){var e;this.methodBuilder=new ee([Y.CopyNode,Y.SetColorNode,Y.DeleteNode,Y.RotateNode,Y.ScaleNode,Y.TranslateNode,Y.ZIndexNode,Y.RotateNode,Y.SetFontStyle,Y.SetPoint,Y.SetLock,Y.SetShapeOpt]).registerForMainEngine(q.MainEngine,this.control),this.zIndexNodeMethod=(e=this.methodBuilder)==null?void 0:e.getBuilder(Y.ZIndexNode)}setZIndex(e){const t=this.currentToolsData&&D.cloneDeep(this.currentToolsData.toolsOpt);return t&&this.zIndexNodeMethod&&this.isUseZIndex&&(this.zIndexNodeMethod.addMaxLayer(e),t.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),t}checkDrawingWork(e){var s,n,r;let t=!1;const i=[];for(const[c,{state:l,viewId:h,points:u,opt:d}]of this.localPointsBatchData.entries())if(e===h&&l===P.Start||l===P.Doing){if(l===P.Doing&&this.isCanDrawWork){Number(c)&&Number(c)+60>Date.now()&&(i.push(c.toString()),this.taskBatchData.add({msgType:x.RemoveNode,workId:c,viewId:h,dataType:F.Local,isRunSubWork:!0}));const p=u.map(f=>f);this.taskBatchData.add({op:p,workState:P.Done,workId:c,dataType:F.Local,msgType:x.DrawWork,isRunSubWork:this.isRunSubWork,toolsType:(s=this.currentToolsData)==null?void 0:s.toolsType,viewId:h,opt:d,scenePath:h&&this.viewContainerManager.getCurScenePath(h)}),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;(r=this.collector)==null||r.dispatch({type:x.RemoveNode,removeIds:i,viewId:e,scenePath:c})}}removeDrawingWork(e){var i,s;const t=[];for(const[n,{state:r,viewId:c}]of this.localPointsBatchData.entries())(e===c&&r===P.Start||r===P.Doing)&&(this.deleteLocalPoint(n),r===P.Doing&&this.isCanDrawWork&&(t.push(n.toString()),this.taskBatchData.add({msgType:x.RemoveNode,workId:n,viewId:c,dataType:F.Local,isRunSubWork:!0})));if(t.length){this.consume();const n=(i=this.viewContainerManager.getView(e))==null?void 0:i.focusScenePath;(s=this.collector)==null||s.dispatch({type:x.RemoveNode,removeIds:t,viewId:e,scenePath:n})}}removeNodes(e,t){var s,n;const i=(s=this.viewContainerManager.getView(e))==null?void 0:s.focusScenePath;if(i&&t.length){for(const r of t)this.taskBatchData.add({msgType:x.RemoveNode,workId:r,viewId:e,dataType:F.Local,isRunSubWork:!1});this.consume(),(n=this.collector)==null||n.dispatch({type:x.RemoveNode,removeIds:t,viewId:e,scenePath:i})}}hoverCursor(e,t){var i;if(((i=this.currentToolsData)==null?void 0:i.toolsType)===k.Selector){const s=this.viewContainerManager.getView(t);if(s&&s.displayer&&s.displayer.vDom){const c=s.displayer.vDom.state.floatBarData;if(c){const{x:l,y:h,w:u,h:d}=c;if(Zs(e,{x:l,y:h,w:u,h:d}))return}}const n=this.viewContainerManager.transformToScenePoint(e,t),r={msgType:x.CursorHover,dataType:F.Local,point:n,toolsType:this.currentToolsData.toolsType,opt:this.currentToolsData.toolsOpt,isRunSubWork:!1,viewId:t};this.queryTaskBatchData({msgType:x.CursorHover,dataType:F.Local,toolsType:this.currentToolsData.toolsType,viewId:t}).forEach(c=>{this.taskBatchData.delete(c)}),this.taskBatchData.add(r),this.runAnimation()}}blurCursor(e){var i;if(((i=this.currentToolsData)==null?void 0:i.toolsType)!==k.Selector)return;const t={msgType:x.CursorBlur,dataType:F.Local,isRunSubWork:!1,viewId:e};this.queryTaskBatchData({msgType:x.CursorHover,dataType:F.Local,viewId:e}).forEach(s=>{this.taskBatchData.delete(s)}),this.taskBatchData.add(t),this.consume()}sendCursorEvent(e,t){var r,c;if(!this.currentLocalWorkData||this.currentLocalWorkData.workState===P.Unwritable||!this.currentToolsData||!this.isCanSentCursor)return;const i=(r=this.collector)==null?void 0:r.uid,s=this.viewContainerManager.getCurScenePath(t);switch((c=this.currentToolsData)==null?void 0:c.toolsType){case k.Eraser:case k.PencilEraser:case k.BitMapEraser:{if(i&&!this.control.renderControl.isClearAble({uid:i,viewId:t,filterLocalSelf:!1,scenePath:s}))return;break}default:if(i&&!this.control.renderControl.isWriteable()||i&&!this.control.renderControl.isRenderAble({uid:i,viewId:t,filterLocalSelf:!1,scenePath:s}))return;break}let n=[void 0,void 0];this.currentToolsData&&this.isCanSentCursor&&!this.localPointsBatchData.size&&!this.getLockSentEventCursor()&&(n=e,this.control.cursor.sendEvent(n,t))}getBoundingRect(e){var i,s;if(!((i=this.boundingRectMap)==null?void 0:i.get(e))){const n=(s=this.collector)==null?void 0:s.getScenePathData(e);if(!n)return;if(Object.keys(n).forEach(r=>{var c;((c=this.collector)==null?void 0:c.getLocalId(r))===H&&delete n[r]}),Object.keys(n).length&&this.viewContainerManager.mainView&&this.viewContainerManager.mainView.cameraOpt){const r={msgType:x.BoundingBox,dataType:F.Local,scenePath:e,scenes:n,cameraOpt:{...this.viewContainerManager.mainView.cameraOpt},isRunSubWork:!0,viewId:this.viewContainerManager.mainView.id};return this.taskBatchData.add(r),this.runAnimation(),new Promise(c=>{this.boundingRectMap.set(e,c)}).then(c=>(this.boundingRectMap.delete(e),c))}}}getSnapshot(e,t,i,s){var r,c,l,h,u;if(!((r=this.snapshotMap)==null?void 0:r.get(e))){const d=(c=this.collector)==null?void 0:c.getViewIdBySecenPath(e);if(!d)return;const p=(l=this.collector)==null?void 0:l.getStorageData(d,e);if(!p)return;if(Object.keys(p).forEach(f=>{var y;((y=this.collector)==null?void 0:y.getLocalId(f))===H&&delete p[f]}),Object.keys(p).length){const f=this.viewContainerManager.mainView;if(!f)return;const y=t||((h=f.cameraOpt)==null?void 0:h.width),m=i||((u=f.cameraOpt)==null?void 0:u.height),T={msgType:x.Snapshot,dataType:F.Local,scenePath:e,scenes:p,w:y,h:m,cameraOpt:s&&{...s,width:y,height:m}||f.cameraOpt,isRunSubWork:!0,viewId:f.id};return this.taskBatchData.add(T),this.runAnimation(),new Promise(w=>{this.snapshotMap.set(e,w)}).then(w=>(this.snapshotMap.delete(e),w))}}}queryTaskBatchData(e){const t=[];if(e)for(const i of this.taskBatchData.values()){let s=!0;for(const[n,r]of Object.entries(e))if(i[n]!==r){s=!1;break}s&&t.push(i)}return t}insertIconify(e,t){var r;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=(r=this.currentLocalWorkData.toolsOpt)==null?void 0:r.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:ht.Iconify};this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayer(e),l.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),this.taskBatchData.add({msgType:x.FullWork,dataType:F.Local,toolsType:k.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 s=i==null?void 0:i.focusScenePath;if(e&&s){const{src:n,uuid:r}=t;if(r&&!n){this.tmpImageConfigMap.set(r,t);return}const c=Date.now();Se.InternalMsgEmitter.emit("addUndoTicker",c,e);const l={...t,type:ht.Image};this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayer(e),l.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),this.taskBatchData.add({msgType:x.FullWork,dataType:F.Local,toolsType:k.Image,workId:t.uuid,opt:l,viewId:e,willRefresh:!0,willSyncService:!0}),this.runAnimation()}}lockImage(e,t,i){var r,c;const s=this.viewContainerManager.getView(e);if(!s)throw new Error("insertImage viewId is not exist");const n=s==null?void 0:s.focusScenePath;if(e&&n&&this.collector){const l=this.collector.getStorageData(e,n);if(!l)return;for(const[h,u]of Object.entries(l))if(u&&u.toolsType===k.Image&&u.opt.uuid===t){const d=Date.now();Se.InternalMsgEmitter.emit("addUndoTicker",d,e);const p=(r=this.collector)!=null&&r.isOwn(h)?(c=this.collector)==null?void 0:c.getLocalId(h):h,f={...u.opt,locked:i,type:ht.Image};this.taskBatchData.add({msgType:x.FullWork,dataType:F.Local,toolsType:k.Image,workId:p,opt:f,viewId:e,willRefresh:!0,willSyncService:!0}),this.runAnimation();return}}}completeImageUpload(e,t,i){const s=this.viewContainerManager.getView(e);if(!s)throw new Error("insertImage viewId is not exist");const n=s==null?void 0:s.focusScenePath;if(e&&n){const r=this.tmpImageConfigMap.get(t);r&&(r.src=i,this.insertImage(e,r),this.tmpImageConfigMap.delete(t));return}}getImagesInformation(e){const t=[];if(this.collector){const i=this.collector.getScenePathData(e);if(!i)return t;for(const s of Object.values(i))if(s&&s.toolsType===k.Image){const n=s.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:x.Select,dataType:F.Local,viewId:t,willSyncService:!0}),this.runAnimation()}blurSelector(e,t,i){this.taskBatchData.add({workId:i||H,selectIds:[],msgType:x.Select,dataType:F.Service,viewId:e,scenePath:t}),this.runAnimation()}consoleWorkerInfo(){this.taskBatchData.add({msgType:x.Console,dataType:F.Local,isRunSubWork:!0,viewId:""}),this.consume()}setPriority(e){var s,n;const t=new Set,i=new Set;if(e==="cpu"&&((s=this.subMainThreadWorker)==null||s.destroy(),t.add({msgType:x.PriorityWorker,viewId:Gt,dataType:F.Local,isRunSubWork:!0})),e==="ui"){t.add({msgType:x.PriorityMainThreadWorker,viewId:Gt,dataType:F.Local,isRunSubWork:!0});const r=this.viewContainerManager.mainView;if(r){const l=this.viewContainerManager.getViewInitData(r.id);if(l){const{offscreenCanvasOpt:h,layerOpt:u,dpr:d,cameraOpt:p}=l;i.add({msgType:x.Init,dataType:F.Local,viewId:r.id,offscreenCanvasOpt:h,layerOpt:u,dpr:d,cameraOpt:p,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 h=this.viewContainerManager.getViewInitData(l);if(h){const{offscreenCanvasOpt:u,layerOpt:d,dpr:p,cameraOpt:f}=h;i.add({msgType:x.Init,dataType:F.Local,viewId:l,offscreenCanvasOpt:u,layerOpt:d,dpr:p,cameraOpt:f,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 s,n;const i=new Set;i.add({msgType:x.AuthClear,dataType:F.Local,viewId:e,clearUids:t,localUid:(s=this.collector)==null?void 0:s.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:x.GetVNodeInfo,dataType:F.Local,isRunSubWork:!0,viewId:t,workIds:i,workId:e}),this.consume(),await new Promise(s=>{const n=this.getVNodeInfoResolveMap.get(e)||{resolve:void 0,timer:void 0};n.timer&&clearTimeout(n.timer),n.resolve=s,n.timer=setTimeout(()=>{const r=this.getVNodeInfoResolveMap.get(e);r!=null&&r.resolve&&r.resolve({uuid:e})},this.maxLastSyncTime*5),this.getVNodeInfoResolveMap.set(e,n)}).then(s=>{const{uuid:n}=s;return this.getVNodeInfoResolveMap.delete(n),s})}}class VM{constructor(o){g(this,"internalMsgEmitter");g(this,"control");g(this,"roomHotkeyCheckers");g(this,"tmpCopyStore",new Map);g(this,"tmpCopyCoordInfo");var i;const{control:e,internalMsgEmitter:t}=o;this.control=e,this.internalMsgEmitter=t,this.roomHotkeyCheckers=((i=this.control.room)==null?void 0:i.viewsParams.hotKeys.nodes)||[]}get isUseSelf(){var o;return((o=this.control.room)==null?void 0:o.disableDeviceInputs)||!1}get isSelector(){var o;return((o=this.control.worker.currentToolsData)==null?void 0:o.toolsType)===k.Selector}get collector(){return this.control.collector}get mainEngine(){return this.control.worker}get keyboardKind(){return/^Mac/i.test(navigator.platform)?"mac":"windows"}getEventKey(o){switch(o.type){case"keydown":return"KeyDown"}return"KeyUp"}onActiveHotkey(o){var i,s,n;const e=this.control.viewContainerManager.focuedViewId,t=(i=this.control.viewContainerManager.focuedView)==null?void 0:i.focusScenePath;if(e&&t)switch(o){case"delete":this.isSelector&&((s=this.collector)!=null&&s.hasSelector(e,t))&&ee.emitMethod(q.MainEngine,Y.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}(o==="changeToPencil"||o==="redo"||o==="undo")&&this.onSelfActiveHotkey(o)}colloctHotkey(o){if(this.isUseSelf){const e=this.checkHotkey(o);e&&this.onSelfActiveHotkey(e)}}onSelfActiveHotkey(o){switch(o){case"changeToPencil":this.setMemberState({currentApplianceName:se.pencil,useNewPencil:!0});break;case"changeToArrow":this.setMemberState({currentApplianceName:se.arrow});break;case"changeToClick":this.setMemberState({currentApplianceName:se.clicker});break;case"changeToEllipse":this.setMemberState({currentApplianceName:se.ellipse});break;case"changeToEraser":this.setMemberState({currentApplianceName:se.eraser,isLine:!0});break;case"changeToHand":this.setMemberState({currentApplianceName:se.hand});break;case"changeToLaserPointer":this.setMemberState({currentApplianceName:se.laserPointer});break;case"changeToSelector":this.setMemberState({currentApplianceName:se.selector});break;case"changeToRectangle":this.setMemberState({currentApplianceName:se.rectangle});break;case"changeToStraight":this.setMemberState({currentApplianceName:se.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:se.text});break}}checkHotkey(o){for(const e of this.roomHotkeyCheckers){const{kind:t,checker:i}=e;if(i({nativeEvent:o,kind:this.getEventKey(o),key:o.key,altKey:o.altKey,ctrlKey:o.ctrlKey,shiftKey:o.shiftKey},this.keyboardKind))return t}}copySelectorToTemp(o,e){var l,h;const t=this.control.viewContainerManager.getView(o),i=(h=(l=this.mainEngine)==null?void 0:l.methodBuilder)==null?void 0:h.getBuilder(Y.CopyNode);if(!t||!this.collector||!i)return;const s=this.collector.transformKey(H),n=this.collector.getStorageData(o,e);if(!n)return;const r=n[s],c=r&&i.copySelector({viewId:o,store:r});c&&(this.tmpCopyCoordInfo=c==null?void 0:c.copyCoordInfo,this.tmpCopyStore=c==null?void 0:c.copyStores)}pasteTempToFocusView(o,e){var s,n;const t=this.control.viewContainerManager.getView(o),i=(n=(s=this.mainEngine)==null?void 0:s.methodBuilder)==null?void 0:n.getBuilder(Y.CopyNode);if(!(!t||!this.tmpCopyCoordInfo||!this.tmpCopyStore.size||!this.collector||!i)&&t.viewData&&this.tmpCopyCoordInfo){const r=D.cloneDeep(this.tmpCopyCoordInfo.offset),c=this.tmpCopyCoordInfo.cameraOpt,l=t.viewData.camera;r.x=r.x+l.centerX-c.centerX,r.y=r.y+l.centerY-c.centerY;const h=Date.now();this.control.worker.internalMsgEmitter.emit("addUndoTicker",h,o),i.pasteSelector({viewId:o,scenePath:e,copyStores:D.cloneDeep(this.tmpCopyStore),copyCoordInfo:{offset:r,cameraOpt:l},undoTickerId:h})}}setMemberState(o){var e;(e=this.control.room)==null||e.setMemberState(o)}}class $M{constructor(o){g(this,"control");g(this,"roomMemberManager");g(this,"worker");g(this,"publicMsgEmitter");g(this,"renderUids",new Map);g(this,"pageAuth",new Map);g(this,"isLocalRender",!1);g(this,"isCurWritable",!1);var i;const{control:e,publicMsgEmitter:t}=o;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}onWritableChange(o){this.isCurWritable=o}addPage(o,e=!0){var l,h;const{viewId:t,render:i="localSelf",elementIds:s,pageId:n=(l=this.control.collector)==null?void 0:l.uid}=o,r=this.pageAuth.get(t)||new Map,c=this.control.viewContainerManager.getCurScenePath(t);if(c&&n){const u=r.get(c)||{render:"localSelf",pages:new Map};e&&(u.render=i);const d=s&&this.cloneElementIds(t,c,s,n)||new Set;u.pages.set(n,d),r.set(c,u),this.pageAuth.set(t,r),e&&this.pageAuthEffect(t),this.isLocalRender=!1,(h=this.control.collector)==null||h.dispatchPageAuth({operation:Pe.addPage,viewId:t,scenePath:c,pageId:n,pageData:{render:i,elementIds:d}},!0)}}delPage(o,e){var n,r;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(o))});if(!i)return;const s=t.get(i);if(s){const{render:c,pages:l}=s,h=c==="localSelf"?(n=this.control.collector)==null?void 0:n.uid:c,u=l.get(o);u!=null&&u.size&&this.delElementIds(e,i,u),l.delete(o),h===o&&this.pageAuthEffect(e)}(r=this.control.collector)==null||r.dispatchPageAuth({operation:Pe.deletePage,viewId:e,scenePath:i,pageId:o},!0)}delViewPage(o,e=!0){var i;this.pageAuth.get(o)&&(this.pageAuth.delete(o),e&&((i=this.control.collector)==null||i.dispatchPageAuth({operation:Pe.clearView,viewId:o},e)))}clearRenderPage(o,e,t=!0){var r,c;const i=this.pageAuth.get(o);if(!i)return;const s=i.get(e);let n;if(s){const{render:l,pages:h}=s,u=l==="localSelf"?(r=this.control.collector)==null?void 0:r.uid:l;if(u){if(t){const d=h.get(u);d&&this.delElementIds(o,e,d)}h.set(u,new Set),n=u}}t&&n&&((c=this.control.collector)==null||c.dispatchPageAuth({operation:Pe.clearPage,viewId:o,scenePath:e,pageId:n},t))}hasPage(o,e,t){const i=this.pageAuth.get(e);if(!i)return!1;const s=i.get(t);return s?s.pages.has(o):!1}getPageInfo(o,e,t){const i=this.pageAuth.get(e);if(!i)return;const s=i.get(t);if(s)return s.pages.get(o)}addRenderPageElementId(o,e=!0,t=!1){var h,u;const{viewId:i,elementId:s,scenePath:n}=o,r=this.pageAuth.get(i);if(!r)throw new Error(`no view info in viewId: ${i}`);const c=r.get(n);let l;if(c){const{render:d,pages:p}=c,f=d==="localSelf"?(h=this.control.collector)==null?void 0:h.uid:d;if(f&&p.has(f)){const y=p.get(f)||new Set;y.add(s),p.set(f,y),l=f}}t&&this.pageAuthEffect(i),e&&l&&((u=this.control.collector)==null||u.dispatchPageAuth({operation:Pe.addElement,viewId:i,scenePath:n,pageId:l,pageData:{elementId:s}},e))}delRenderPageElementId(o,e=!0,t=!1){var h,u;const{viewId:i,elementId:s,scenePath:n}=o,r=this.pageAuth.get(i);if(!r)throw new Error(`no view info in viewId: ${i}`);const c=r.get(n);let l;if(c){const{render:d,pages:p}=c,f=d==="localSelf"?(h=this.control.collector)==null?void 0:h.uid:d;if(f&&p.has(f)){const y=p.get(f);y&&(y.delete(s),p.set(f,y),l=f)}}t&&this.pageAuthEffect(i),e&&l&&((u=this.control.collector)==null||u.dispatchPageAuth({operation:Pe.deleteElement,viewId:i,scenePath:n,pageId:l,pageData:{elementId:s}},e))}setPageRender(o,e,t,i=!0){var r;const s=this.pageAuth.get(o);if(!s)throw new Error(`no view info in viewId: ${o}`);const n=s.get(e);n&&(n.render=t),e===this.control.viewContainerManager.getCurScenePath(o)&&this.pageAuthEffect(o),i||(this.isLocalRender=!0),i&&(this.isLocalRender=!1,(r=this.control.collector)==null||r.dispatchPageAuth({operation:Pe.renderPage,viewId:o,scenePath:e,pageData:{render:t}},i))}isWriteable(){return this.isCurWritable}isRenderAble(o){var c,l;const{uid:e,viewId:t,filterLocalSelf:i=!0,scenePath:s}=o,n=this.renderUids.get(t);if(n){const{render:h,hide:u}=n;if(h===void 0&&u===void 0)return!0;if(D.isSet(h)){if(h.has(e)||i&&((c=this.control.collector)==null?void 0:c.uid)===e&&h.has("localSelf"))return!0}else if(h===!0&&(!u||D.isSet(u)&&!u.has(e)&&!(i&&u.has("localSelf")&&((l=this.control.collector)==null?void 0:l.uid)===e)))return!0;return!1}const r=this.pageAuth.get(t);if(r&&s){const h=r.get(s);if(h){const{render:u}=h;if(u)return!(u==="localSelf"&&!i)}}return!0}isClearAble(o){var c;const{uid:e,viewId:t,filterLocalSelf:i=!0,scenePath:s}=o,n=this.renderUids.get(t);if(n){const{clear:l}=n;return!!(l===void 0||l===!0||D.isSet(l)&&(l.has(e)||i&&((c=this.control.collector)==null?void 0:c.uid)===e&&l.has("localSelf")))}const r=this.pageAuth.get(t);if(r&&s){const l=r.get(s);if(l){const{render:h}=l;if(h)return!(h==="localSelf"&&!i)}}return!0}isFilterAble(o,e){var c,l,h,u;const{viewId:t,scenePath:i,elementId:s}=o,n=this.renderUids.get(t);if(n&&s){const{render:d,hide:p}=n;if(d===void 0&&p===void 0)return!0;const f=(c=this.control.collector)==null?void 0:c.getUidFromKey(s);return f?!!(D.isSet(d)&&(d.has(f)||d.has("localSelf")&&((l=this.control.collector)==null?void 0:l.uid)===f)||d===!0&&(!p||D.isSet(p)&&!p.has(f)&&!(p.has("localSelf")&&((h=this.control.collector)==null?void 0:h.uid)===f))):!1}const r=this.pageAuth.get(t);if(r&&i&&s){const d=r.get(i);if(d){const{render:p,pages:f}=d;if(!p)return!0;const y=(u=this.control.collector)==null?void 0:u.uid,m=p==="localSelf"?y:p,T=m&&f.get(m)||void 0;if(T)switch(e){case x.RemoveNode:return!0;default:return T.has(s)}return!1}}return!0}isFilterCursor(o){if(this.isUsePageAuth(o)){const e=this.control.viewContainerManager.getCurScenePath(o),t=this.pageAuth.get(o);if(e&&t){const i=t.get(e);if(i){const{render:s}=i;return s!=="localSelf"}}}return!0}isUsePageAuth(o){var i;if(!this.pageAuth.has(o))return!1;const t=this.control.viewContainerManager.getCurScenePath(o);return t&&((i=this.pageAuth.get(o))==null?void 0:i.has(t))||!1}publishRender(o){var n;const{viewId:e,option:t,isSync:i=!0}=o,s={};if(t){const{render:r,hide:c,clear:l}=t;r&&(s.render=r===!0&&!0||new Set(r)),c&&(s.hide=c===!0&&!0||new Set(c)),l&&(s.clear=l===!0&&!0||new Set(l)),this.renderUids.set(e,s)}else this.renderUids.delete(e);i&&((n=this.control.collector)==null||n.dispatchRenderAuth({operation:Qe.setAuth,viewId:e,renderData:s},i)),this.renderEffect(e)}publishOneRender(o,e,t,i=!0){var r;const s=this.renderUids.get(o);let n;switch(t){case"show":s?(s.render||(s.render=new Set),D.isSet(s.render)&&s.render.add(e),D.isSet(s.hide)&&s.hide.delete(e)):this.renderUids.set(o,{render:new Set([e])}),n=Qe.setShow;break;case"hide":s?(s.hide||(s.hide=new Set),D.isSet(s.hide)&&s.hide.add(e),D.isSet(s.render)&&s.render.delete(e)):this.renderUids.set(o,{hide:new Set([e])}),n=Qe.setHide;break}s?this.renderUids.set(o,s):this.renderUids.delete(o),i&&n&&((r=this.control.collector)==null||r.dispatchRenderAuth({operation:n,viewId:o,uid:e},i)),this.renderEffect(o)}publishOneClear(o,e,t,i=!0){var n;const s=this.renderUids.get(o);t?s?(s.clear||(s.clear=new Set),D.isSet(s.clear)&&s.clear.add(e)):this.renderUids.set(o,{clear:new Set([e])}):s&&D.isSet(s.clear)&&s.clear.has(e)&&s.clear.delete(e),s?this.renderUids.set(o,s):this.renderUids.delete(o),i&&((n=this.control.collector)==null||n.dispatchRenderAuth({operation:Qe.setClear,viewId:o,uid:e,isClear:t},i)),this.renderEffect(o)}syncRenderUids(o,e,t,i){const s=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,r=i===!0?!0:i&&Object.keys(i)?new Set(Object.keys(i)):void 0;s||n||r?this.renderUids.set(o,{render:s,hide:n,clear:r}):this.renderUids.delete(o),this.renderEffect(o),this.publicMsgEmitter.emit("syncRenderUids",o,{render:s,hide:n,clear:r})}syncPageAuth(o,e,t=!1){let i=!1;if(!e)this.pageAuth.delete(o);else{const s=this.pageAuth.get(o)||new Map;for(const[n,r]of Object.entries(e)){const{render:c,pages:l}=r,h=s.get(n),u=this.isLocalRender?h==null?void 0:h.render:c;if(u){u!==(h==null?void 0:h.render)&&(i=!0);const d=new Map;for(const[f,y]of Object.entries(l))d.set(f,new Set(Object.keys(y)));const p={render:u,pages:d};d.size&&s.set(n,p)}}s.size&&(this.pageAuth.set(o,s),this.publicMsgEmitter.emit("syncPageAuth",o,s))}(t||i)&&this.pageAuthEffect(o)}destoryByViewId(o,e=!1){var t;this.renderUids.has(o)&&(this.renderUids.delete(o),e||(t=this.control.collector)==null||t.dispatchRenderAuth({operation:Qe.setAuth,viewId:o})),this.pageAuth.has(o)&&this.control.renderControl.delViewPage(o,!e)}renderEffect(o){var t;const e=(t=this.control.viewContainerManager.getView(o))==null?void 0:t.focusScenePath;e&&this.worker.clearViewScenePath(o,!0).then(()=>{var i;this.worker.pullServiceData(o,e,{isAsync:!0,useAnimation:!1}),this.worker.sendClearUids(o,(i=this.renderUids.get(o))==null?void 0:i.clear)})}pageAuthEffect(o){var t;const e=(t=this.control.viewContainerManager.getView(o))==null?void 0:t.focusScenePath;e&&this.worker.clearViewScenePath(o,!0).then(()=>{this.worker.pullServiceData(o,e,{isAsync:!0,useAnimation:!1}),this.worker.sendClearUids(o,!0)})}cloneElementIds(o,e,t,i){var r,c;const s=(r=this.control.collector)==null?void 0:r.getStorageData(o,e),n=new Set;if(s){for(const l of Object.keys(s))if(t.has(l)){const h=`${l}_${i}`;if(n.add(h),!Object.keys(s).includes(h)){const u=D.cloneDeep(s[l]);(c=this.control.collector)==null||c.updateValue(h,{type:x.FullWork,...u,workId:h},{isSync:!0,viewId:o,scenePath:e})}}}return n}delElementIds(o,e,t){var s,n;const i=(s=this.control.collector)==null?void 0:s.getStorageData(o,e);if(i)for(const r of Object.keys(i))t.has(r)&&Object.keys(i).includes(r)&&((n=this.control.collector)==null||n.updateValue(r,void 0,{isSync:!0,viewId:o,scenePath:e}))}}class HM{constructor(o){g(this,"internalMsgEmitter");g(this,"control");g(this,"maps",new Map);g(this,"showId");g(this,"color");g(this,"timer");g(this,"updateMiniMapCamera",D.debounce(async o=>{const e=this.maps.get(o);if(e){const t=await this.getMiniMapCamera(o);if(t){const i=t.width/t.scale,s=t.height/t.scale,n=e.miniMapCamera.width/e.miniMapCamera.scale,r=e.miniMapCamera.height/e.miniMapCamera.scale;(i>=n||s>=r)&&(e.miniMapCamera=t);const c=e.miniMapCanvas.current;if(c){const l=c.getContext("2d");if(l){const h=this.control.viewContainerManager.getView(o);if(!(h!=null&&h.focusScenePath))return;const{miniMapCamera:u,contianer:d}=e,{width:p,height:f}=d.getBoundingClientRect(),y=Math.min(p/u.width,f/u.height);l.clearRect(0,0,c.width,c.height),c.width=u.width,c.height=u.height,c.style.width=`${u.width*y}px`,c.style.height=`${u.height*y}px`,await this.control.screenshotToCanvas(l,h.focusScenePath,u.width,u.height,u),this.listener.emitAsync([o,"viewCameraUpate"],1)}}}}},2e3,{maxWait:5e3}));var i;const{control:e,internalMsgEmitter:t}=o;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(o){this.color=o}async createMiniMap(o,e,t){const i=this.control.viewContainerManager.getView(o);if(!i)throw new Error("view not found");const s=i.cameraOpt;if(!s)throw new Error("view camera not found");const{width:n,height:r}=e.getBoundingClientRect();if(!n||!r)throw new Error("contianer width or height is 0");const c=M.createRef();this.maps.set(o,{contianer:e,miniMapCanvas:c,miniMapCamera:t,viewCamera:s}),this.showId=o,this.control.viewContainerManager.setActiveMiniMap(this.showId,!0);const l=Math.min(n/t.width,r/t.height),h=await new Promise(u=>{this.listener.once([o,"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`),u(!0)}),this.timer=setTimeout(()=>{u(!1)},2e3)});return this.timer&&clearTimeout(this.timer),h}async getMiniMapCamera(o){const e=this.control.viewContainerManager.getView(o);if(!e)return;const{cameraOpt:t,focusScenePath:i}=e;if(!t||!i)return;const s={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)||s;n=ti(n,s)||s;let r=n.width,c=n.height,l=1;const h=r>t.width&&Math.min(t.width/r,l)||l,u=c>t.height&&Math.min(t.height/c,l)||l;return h<=u?(r=h<1&&t.width||r,c=Math.floor(c*h)+1,l=h):h>u&&(c=u<1&&t.height||c,r=Math.floor(r*u)+1,l=u),{scale:l,centerX:n.originX+n.width/2,centerY:n.originY+n.height/2,width:r,height:c}}getMiniMapCanvas(o){const e=this.maps.get(o);return(e==null?void 0:e.miniMapCanvas.current)||null}updateViewCamera(o,e){const t=this.maps.get(o);t&&(t.viewCamera=e,this.listener.emitAsync([o,"viewCameraUpate"],1))}destroyMiniMap(o){const e=o||this.showId;e&&(this.maps.delete(e),this.control.viewContainerManager.setActiveMiniMap(e,!1))}}class Xs{constructor(){g(this,"control");g(this,"_listeners",{})}_inject(o){this.control=o}_onEvent(o,e){this._listeners[o]&&this._listeners[o](...e)}callbacks(o,e){this._listeners[o]=e}removeCallback(o){delete this._listeners[o]}}class QM{constructor(o){g(this,"control");g(this,"worker");g(this,"publicMsgEmitter");g(this,"plugins",new Map);const{control:e,publicMsgEmitter:t}=o;this.control=e,this.publicMsgEmitter=t,this.worker=e.worker}use(o){this.plugins.set(o.kind,o),o._inject(this.control),o.onCreate()}destroy(){this.plugins.forEach(o=>{this.plugins.delete(o.kind),o.onDestroy()})}dispatchPluginEvent(o,...e){this.plugins.forEach(t=>{t._onEvent(o,e)})}}const at=class at{constructor(o){g(this,"version",xs);g(this,"plugin");g(this,"room");g(this,"play");g(this,"collector");g(this,"hasSwitchToSelectorEffect");g(this,"snapshootStateMap");g(this,"_disableDeviceInputs");g(this,"_disableEraseImage");g(this,"_disableEraseText");g(this,"priority","cpu");g(this,"effectResolve");g(this,"hotkeyManager");g(this,"pluginOptions");g(this,"roomMember");g(this,"cursor");g(this,"textEditorManager");g(this,"worker");g(this,"renderControl");g(this,"miniMapManager");g(this,"pluginManager");g(this,"onSceneChange",async(o,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 s=o;s&&this.viewContainerManager.setViewScenePath(e,s),i==null||i.setActive(!0)});g(this,"onRoomMembersChange",o=>{this.roomMember.setRoomMembers(_.toJS(o))});g(this,"onMemberChange",Ot(o=>{if(!this.room||!this.worker||!o||!this.room.isWritable)return;const e=this.getToolsKey(o),t=this.getToolsOpt(e,o);this.worker.setCurrentToolsData(t),this.pluginManager.dispatchPluginEvent("setToolkey",e),this.effectViewContainer(e),this.effectResolve&&this.effectResolve(!0)},100,{leading:!1}));g(this,"internalSceneChange",(o,e)=>{var i;this.miniMapManager.activeViewId===o&&this.miniMapManager.destroyMiniMap(o),this.pluginManager.dispatchPluginEvent("sceneChange",o,e),(i=this.worker)==null||i.clearViewScenePath(o,!0).then(()=>{var s;(s=this.worker)==null||s.pullServiceData(o,e,{isAsync:!0,useAnimation:!1})})});g(this,"internalCameraChange",(o,e)=>{var t;(t=this.worker)==null||t.updateCamera(o,e),this.miniMapManager.updateViewCamera(o,e)});const{displayer:e,plugin:t,options:i}=o;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,this.roomMember=new NM;const s={control:this,internalMsgEmitter:at.InternalMsgEmitter,publicMsgEmitter:at.PublicMsgEmitter};this.cursor=new TM(s),this.textEditorManager=new SM(s),this.worker=new FM(s),this.hotkeyManager=new VM(s),this.renderControl=new $M(s),this.miniMapManager=new HM(s),this.pluginManager=new QM(s)}get disableEraseText(){return this._disableEraseText||!1}set disableEraseText(o){this._disableEraseText=o}get disableEraseImage(){return this._disableEraseImage||!1}set disableEraseImage(o){this._disableEraseImage=o}get disableDeviceInputs(){return this._disableDeviceInputs||!1}set disableDeviceInputs(o){var t;this._disableDeviceInputs=o;const e=(t=this.worker.getCurrentToolsData())==null?void 0:t.toolsType;e&&this.effectViewContainer(e)}setPriority(o){var e;this.priority=o,this.hasOffscreenCanvas()&&((e=this.worker)==null||e.setPriority(o))}hasOffscreenCanvas(){return Jo==="worker"}bindPlugin(o){var e,t;this.plugin=o,this.collector&&(this.collector.removeStorageStateListener(),this.collector.removeAuthStateListener()),this.collector=new jo(this,o,(t=(e=this.pluginOptions)==null?void 0:e.syncOpt)==null?void 0:t.interval),this.activePlugin()}destroy(){var o,e,t,i,s,n;this.roomMember.destroy(),(o=this.collector)==null||o.destroy(),(e=this.worker)==null||e.destroy(),(t=this.viewContainerManager)==null||t.destroy(),(i=this.cursor)==null||i.destroy(),(s=this.textEditorManager)==null||s.destory(),(n=this.pluginManager)==null||n.destroy()}cleanCurrentScene(){const o=Date.now(),e=this.worker.getLocalWorkViewId()||this.viewContainerManager.focuedViewId;e&&(at.InternalMsgEmitter.emit("addUndoTicker",o,e),this.worker.clearViewScenePath(e,!1,!0))}onWritableChange(o){var t,i;o?(i=this.worker)==null||i.abled():(t=this.worker)==null||t.unWritable(),this.renderControl.onWritableChange(o),this.viewContainerManager.getAllViews().forEach(s=>{s!=null&&s.displayer&&s.displayer.bindToolsClass()})}getToolsKey(o){var t;const e=o.currentApplianceName;switch(this.hasSwitchToSelectorEffect=!1,e){case se.text:return o.textCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),k.Text;case se.pencil:return o.useLaserPen?k.LaserPen:k.Pencil;case se.eraser:return k.Eraser;case se.pencilEraser:return((t=this.pluginOptions.pencilEraser)==null?void 0:t.useBitMap)===!1?k.PencilEraser:k.BitMapEraser;case se.selector:return k.Selector;case se.arrow:return o.arrowCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),k.Arrow;case se.straight:return o.straightCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),k.Straight;case se.ellipse:return o.ellipseCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),k.Ellipse;case se.rectangle:return o.rectangleCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),k.Rectangle;case se.shape:if(o.shapeCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),o.shapeType===$e.Pentagram||o.shapeType===$e.Star)return k.Star;if(o.shapeType===$e.Polygon||o.shapeType===$e.Triangle||o.shapeType===$e.Rhombus)return k.Polygon;if(o.shapeType===$e.SpeechBalloon)return k.SpeechBalloon;break}return k.Clicker}getToolsOpt(o,e){if(o===k.Clicker)return{toolsType:o,toolsOpt:{}};const t={strokeColor:Pt(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(o){case k.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)&&Pt(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)&&Pt(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 k.Pencil:t.strokeType=(e==null?void 0:e.strokeType)||oe.Normal;break;case k.PencilEraser:case k.BitMapEraser:case k.Eraser:t.thickness=Math.min(3,Math.max(1,Math.floor(e.pencilEraserSize||1)))-1;break;case k.LaserPen:t.duration=(e==null?void 0:e.duration)||1,e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===oe.Stroke?t.strokeType=oe.Normal:t.strokeType=(e==null?void 0:e.strokeType)||oe.Normal;break;case k.Arrow:case k.Straight:e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===oe.Stroke?t.strokeType=oe.Normal:t.strokeType=(e==null?void 0:e.strokeType)||oe.Normal;break;case k.Ellipse:case k.Rectangle:case k.Star:case k.Polygon:case k.SpeechBalloon:e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===oe.Stroke?t.strokeType=oe.Normal:t.strokeType=(e==null?void 0:e.strokeType)||oe.Normal,o===k.Star&&(e.shapeType===$e.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)),o===k.Polygon&&(e.shapeType===$e.Triangle?t.vertices=3:e.shapeType===$e.Rhombus?t.vertices=4:e.vertices&&(t.vertices=e.vertices)),t.fillColor=(e==null?void 0:e.fillColor)&&Pt(e.fillColor[0],e.fillColor[1],e.fillColor[2],e==null?void 0:e.fillOpacity)||"transparent",o===k.SpeechBalloon&&(t.placement=e.placement||"bottomLeft");break}return{toolsType:o,toolsOpt:t}}effectViewContainer(o){var e,t,i,s,n,r,c;if(this.disableDeviceInputs===!0)this.room.disableDeviceInputs=!0,(e=this.worker)==null||e.unWritable(),(t=this.cursor)==null||t.unabled();else switch(o){case k.Text:case k.Pencil:case k.LaserPen:case k.Arrow:case k.Straight:case k.Rectangle:case k.Ellipse:case k.Star:case k.Polygon:case k.SpeechBalloon:case k.Triangle:case k.Rhombus:case k.Eraser:case k.PencilEraser:case k.BitMapEraser:this.room.disableDeviceInputs=!0,(i=this.worker)==null||i.abled();break;case k.Selector:this.room.disableDeviceInputs=!1,(s=this.cursor)==null||s.unabled(),(n=this.worker)==null||n.abled();break;default:this.room.disableDeviceInputs=!1,(r=this.worker)==null||r.unWritable(),(c=this.cursor)==null||c.unabled();break}setTimeout(()=>{this.viewContainerManager.getAllViews().forEach(h=>{h!=null&&h.displayer&&h.displayer.bindToolsClass()})},0)}async getBoundingRect(o){var t,i,s,n,r;const e=await((t=this.worker)==null?void 0:t.getBoundingRect(o));if(e){const c=((s=(i=this.viewContainerManager.mainView)==null?void 0:i.viewData)==null?void 0:s.convertToPointInWorld({x:e.x,y:e.y}))||{x:e.x,y:e.y},l=((r=(n=this.viewContainerManager.mainView)==null?void 0:n.viewData)==null?void 0:r.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(o,e,t,i,s,n,r){const c=await this.worker.getSnapshot(e,t,i,s);c&&(o.drawImage(c,n||0,r||0),c.close())}async scenePreview(o,e){var n,r,c,l;const t=(n=this.collector)==null?void 0:n.getViewIdBySecenPath(o);if(!t)return;const i=this.viewContainerManager.getView(t);if(!i||!((r=i.cameraOpt)!=null&&r.width)||!((c=i.cameraOpt)!=null&&c.height))return;const s=await((l=this.worker)==null?void 0:l.getSnapshot(o));if(s&&this.worker){const h=document.createElement("canvas"),u=h.getContext("2d"),{width:d,height:p}=i.cameraOpt;h.width=d,h.height=p,u&&(u.drawImage(s,0,0),e.crossOrigin="anonymous",e.src=h.toDataURL(),e.onload=()=>{h.remove()},e.onerror=()=>{h.remove(),e.remove()}),s.close()}}switchToText(){var o;(o=this.room)==null||o.setMemberState({currentApplianceName:se.text})}switchToSelector(){var o;(o=this.room)==null||o.setMemberState({currentApplianceName:se.selector})}async runEffectWork(o){if(this.hasSwitchToSelectorEffect){const e=await new Promise(t=>{this.switchToSelector(),this.effectResolve=t});this.effectResolve=void 0,e&&o&&o()}}setSnapshootData(){var o;this.room&&(this.snapshootStateMap=new Map,this.snapshootStateMap.set("memberState",(o=this.room)==null?void 0:o.state.memberState))}getSnapshootData(o){var e;return(e=this.snapshootStateMap)==null?void 0:e.get(o)}clearSnapshootData(){var o;(o=this.snapshootStateMap)==null||o.clear(),this.snapshootStateMap=void 0}useBitMapEraser(o){var e;if(((e=this.pluginOptions.pencilEraser)==null?void 0:e.useBitMap)===void 0){this.pluginOptions.pencilEraser={useBitMap:o};return}this.pluginOptions.pencilEraser.useBitMap=o}consoleWorkerInfo(){var o;(o=this.worker)==null||o.consoleWorkerInfo()}filterRenderByUid(o,e,t=!0){var s;this.viewContainerManager.getView(o)&&((s=this.renderControl)==null||s.publishRender({viewId:o,option:e,isSync:t}))}cancelFilterRender(o,e=!0){var t;(t=this.renderControl)==null||t.publishRender({viewId:o,isSync:e})}async createMiniMap(o,e){const t=await this.miniMapManager.getMiniMapCamera(o);if(t&&await this.miniMapManager.createMiniMap(o,e,t)){const s=this.miniMapManager.getMiniMapCanvas(o);if(s){const n=s.getContext("2d");if(n){const r=this.viewContainerManager.getView(o);r!=null&&r.focusScenePath&&this.screenshotToCanvas(n,r.focusScenePath,t.width,t.height,t)}}}}async destroyMiniMap(o){this.miniMapManager.destroyMiniMap(o)}insertIconify(o,e){var i;if(this.viewContainerManager.getView(o)&&this.room){const s=this.room.state.memberState,n=Pt(s.strokeColor[0],s.strokeColor[1],s.strokeColor[2],s.strokeOpacity||1);(i=this.worker)==null||i.insertIconify(o,{...e,strokeColor:n})}}usePlugin(o){return this.pluginManager.use(o)}};g(at,"InternalMsgEmitter",new Co),g(at,"PublicMsgEmitter",new Co);let Se=at;const ct=class ct{constructor(o){g(this,"emitter",new Co);g(this,"undoStack");g(this,"redoStack");g(this,"worker");g(this,"control");g(this,"room");g(this,"isTicking");g(this,"undoTickerId");g(this,"viewId");g(this,"scenePath");g(this,"tickStartStorerCache");g(this,"excludeIds",new Set);g(this,"onChangeScene",D.debounce(()=>{const o=this.control.viewContainerManager.getCurScenePath(this.viewId);if(o){let e=this.undoStack.filter(i=>i.scenePath===o).length;const t=this.redoStack.filter(i=>i.scenePath===o).length;e===0&&t===0&&this.tickStartStorerCache&&this.scenePath===o&&(e=1),this.emitter.emit("onCanUndoStepsUpdate",e),this.emitter.emit("onCanRedoStepsUpdate",t)}},ct.waitTime));const{control:e,internalMsgEmitter:t,viewId:i}=o;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(o){if(this.isTicking)for(const e of o)this.excludeIds.add(e)}undoTickerStart(o,e){if(this.collector&&(this.undoTickerId!==o||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 t=this.collector.transformKey(H);this.excludeIds.add(t),this.undoTickerId=o,this.scenePath=e;const i=this.collector.getStorageData(this.viewId,e)||{};this.tickStartStorerCache=new Map(Object.entries(D.cloneDeep(i)))}}undoTickerEndSync(o,e,t){var i,s;if(o===this.undoTickerId&&t===this.scenePath&&e===this.viewId&&this.tickStartStorerCache){const n=((i=this.collector)==null?void 0:i.storage[e])&&((s=this.collector)==null?void 0:s.storage[e][t])||{},r=this.diffFun(this.tickStartStorerCache,new Map(Object.entries(n)));r.size&&(this.undoStack.push({id:o,type:2,data:D.cloneDeep(r),scenePath:t}),this.undoStack.length>ct.MaxStackLength&&this.undoStack.shift(),this.emitter.emit("onCanUndoStepsUpdate",this.undoStack.length)),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(o){this.undoTickerId&&this.tickStartStorerCache&&this.scenePath&&this.undoTickerEndSync(this.undoTickerId,this.viewId,this.scenePath);let e=this.undoStack.length-1;for(;e>=0;){if(this.undoStack[e].scenePath===o){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(s=>s.scenePath===o).length,i=this.redoStack.filter(s=>s.scenePath===o).length;return this.emitter.emit("onCanUndoStepsUpdate",t),this.emitter.emit("onCanRedoStepsUpdate",i),t}redo(o){let e=this.redoStack.length-1;for(;e>=0;){if(this.redoStack[e].scenePath===o){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(s=>s.scenePath===o).length,i=this.redoStack.filter(s=>s.scenePath===o).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 o=this.control.viewContainerManager.getCurScenePath(this.viewId);if(o){let e=this.undoStack.filter(i=>i.scenePath===o).length;const t=this.redoStack.filter(i=>i.scenePath===o).length;e===0&&t===0&&this.tickStartStorerCache&&this.scenePath===o&&(e=1),this.emitter.emit("onCanUndoStepsUpdate",e),this.emitter.emit("onCanRedoStepsUpdate",t)}}diffFun(o,e){const t=new Set,i=o.keys(),s=e.keys();for(const n of i){if(this.excludeIds.has(n))continue;const r=o.get(n),c=e.get(n);if(r&&c){if(D.isEqual(c,r))continue;t.add({dataType:3,key:n,data:[r,c]});continue}r&&t.add({dataType:2,key:n,data:r})}for(const n of s){if(this.excludeIds.has(n))continue;const r=e.get(n);r&&!o.has(n)&&t.add({dataType:1,key:n,data:r})}return t}isDrawEffectiveScene(o,e){const{key:t}=o;return!e.includes(t)}isDeleteEffectiveScene(o,e,t){var n;const{key:i}=o;if(!e.includes(i))return!1;const s=e.filter(r=>{var c,l;return((c=this.collector)==null?void 0:c.getLocalId(r))===H&&!((l=this.collector)!=null&&l.isOwn(r))}).map(r=>{var c;return(c=this.collector)==null?void 0:c.storage[this.viewId][t][r]});for(const r of s)if((n=r==null?void 0:r.selectIds)!=null&&n.includes(i))return!1;return!0}isOldEffectiveScene(o,e,t){var n;const{key:i}=o;if(!e.includes(i))return!1;const s=e.filter(r=>{var c,l;return((c=this.collector)==null?void 0:c.getLocalId(r))===H&&!((l=this.collector)!=null&&l.isOwn(r))}).map(r=>{var c;return(c=this.collector)==null?void 0:c.storage[this.viewId][t][r]});for(const r of s)if((n=r==null?void 0:r.selectIds)!=null&&n.includes(i))return!1;return!0}isNewEffectiveScene(o,e){const{key:t}=o;return!!e.includes(t)}refreshPlugin(o,e=!1){var n,r,c,l,h,u,d,p,f,y,m,T,w,v,S,N,I,b,L,j,E;let t;const{scenePath:i}=o,s=o.data;if(!(!s||!this.collector))for(const A of s.values()){const{dataType:W,data:z,key:O}=A,ne=this.collector.getStorageData(this.viewId,i),te=ne&&Object.keys(ne)||[];switch(W){case 1:if(t=e?this.isDrawEffectiveScene(A,te):this.isDeleteEffectiveScene(A,te,i),t)if(e&&!Array.isArray(z)){if((n=z.updateNodeOpt)!=null&&n.useAnimation&&(z.updateNodeOpt.useAnimation=!1),((r=this.collector)==null?void 0:r.getLocalId(O))===H&&((c=this.collector)!=null&&c.isOwn(A.key))){const Q=z.selectIds;if(Q){const X=te.filter(Z=>{var K,ce;return((K=this.collector)==null?void 0:K.getLocalId(Z))===H&&!((ce=this.collector)!=null&&ce.isOwn(Z))}).map(Z=>{var K;return(K=this.collector)==null?void 0:K.storage[this.viewId][i][Z]});let G=!1;for(const Z of X)for(let K=0;K<Q.length;K++)(l=Z==null?void 0:Z.selectIds)!=null&&l.includes(Q[K])&&(delete Q[K],G=!0);G&&(z.selectIds=Q.filter(Z=>!!Z))}}(h=this.collector)==null||h.updateValue(A.key,z,{isAfterUpdate:!0,viewId:this.viewId,scenePath:i,isSync:!0})}else!e&&!Array.isArray(A.data)&&((u=this.collector)==null||u.updateValue(A.key,void 0,{isAfterUpdate:!0,viewId:this.viewId,scenePath:i,isSync:!0}));break;case 2:if(t=e?this.isDeleteEffectiveScene(A,te,i):this.isDrawEffectiveScene(A,te),t){if(e&&!Array.isArray(z))(d=this.collector)==null||d.updateValue(O,void 0,{isAfterUpdate:!0,viewId:this.viewId,scenePath:i,isSync:!0});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(A.key))===H&&((y=this.collector)!=null&&y.isOwn(A.key))){const Q=z.selectIds;if(Q){const X=te.filter(Z=>{var K,ce;return((K=this.collector)==null?void 0:K.getLocalId(Z))===H&&!((ce=this.collector)!=null&&ce.isOwn(Z))}).map(Z=>{var K;return(K=this.collector)==null?void 0:K.storage[this.viewId][i][Z]});let G=!1;for(const Z of X)for(let K=0;K<Q.length;K++)(m=Z==null?void 0:Z.selectIds)!=null&&m.includes(Q[K])&&(delete Q[K],G=!0);G&&(z.selectIds=Q.filter(Z=>!!Z))}}(T=this.collector)==null||T.updateValue(A.key,A.data,{isAfterUpdate:!0,viewId:this.viewId,scenePath:i,isSync:!0})}}break;case 3:if(t=e?this.isNewEffectiveScene(A,te):this.isOldEffectiveScene(A,te,i),t){if(e&&Array.isArray(z)&&z.length===2){const Q=z[1];if((w=Q.updateNodeOpt)!=null&&w.useAnimation&&(Q.updateNodeOpt.useAnimation=!1),((v=this.collector)==null?void 0:v.getLocalId(A.key))===H&&((S=this.collector)!=null&&S.isOwn(A.key))){const X=Q.selectIds;if(X){const G=te.filter(K=>{var ce,Te;return((ce=this.collector)==null?void 0:ce.getLocalId(K))===H&&!((Te=this.collector)!=null&&Te.isOwn(K))}).map(K=>{var ce;return(ce=this.collector)==null?void 0:ce.storage[this.viewId][i][K]});let Z=!1;for(const K of G)for(let ce=0;ce<X.length;ce++)K!=null&&K.selectIds&&((N=K.selectIds)!=null&&N.includes(X[ce]))&&(delete X[ce],Z=!0);Z&&(Q.selectIds=X.filter(K=>!!K))}}(I=this.collector)==null||I.updateValue(O,Q,{isAfterUpdate:!0,viewId:this.viewId,scenePath:i,isSync:!0})}else if(!e&&Array.isArray(z)&&z.length===2){const Q=z[0];if((b=Q.updateNodeOpt)!=null&&b.useAnimation&&(Q.updateNodeOpt.useAnimation=!1),((L=this.collector)==null?void 0:L.getLocalId(A.key))===H&&((j=this.collector)!=null&&j.isOwn(A.key))){const X=Q.selectIds;if(X){const G=te.filter(K=>{var ce,Te;return((ce=this.collector)==null?void 0:ce.getLocalId(K))===H&&!((Te=this.collector)!=null&&Te.isOwn(K))}).map(K=>{var ce;return(ce=this.collector)==null?void 0:ce.storage[this.viewId][i][K]});let Z=!1;for(const K of G)for(let ce=0;ce<X.length;ce++)K!=null&&K.selectIds&&K.selectIds.includes(X[ce])&&(delete X[ce],Z=!0);Z&&(Q.selectIds=X.filter(K=>!!K))}}(E=this.collector)==null||E.updateValue(A.key,Q,{isAfterUpdate:!0,viewId:this.viewId,scenePath:i,isSync:!0})}}break}}}};g(ct,"sdkCallBack"),g(ct,"MaxStackLength",20),g(ct,"waitTime",100);let so=ct;function GM(a){return a instanceof TouchEvent||a instanceof window.TouchEvent||(a==null?void 0:a.touches)&&(a==null?void 0:a.touches.length)||(a==null?void 0:a.changedTouches)&&(a==null?void 0:a.changedTouches.length)}function vt(a){return GM(a)&&(a.touches&&a.touches.length===1||a.changedTouches&&a.changedTouches.length===1)}function Js(a){return a.touches&&a.touches.length?{x:a.touches[0].pageX,y:a.touches[0].pageY}:a.changedTouches&&a.changedTouches.length?{x:a.changedTouches[0].pageX,y:a.changedTouches[0].pageY}:{x:a.pageX,y:a.pageY}}class It{constructor(o){g(this,"internalMsgEmitter");g(this,"control");g(this,"mainView");g(this,"appViews",new Map);const{control:e,internalMsgEmitter:t}=o;this.control=e,this.internalMsgEmitter=t,this.internalMsgEmitter.on("addUndoTicker",this.undoTickerStart.bind(this)),this.internalMsgEmitter.on("excludeIds",this.addExcludeIds.bind(this))}undoTickerStart(o,e){const t=this.getView(e);t&&t.displayer&&t.focusScenePath&&t.displayer.commiter.undoTickerStart(o,t.focusScenePath)}addExcludeIds(o,e){const t=this.getView(e);t&&t.displayer&&t.focusScenePath&&t.displayer.commiter.addExcludeIds(o)}undo(){const o=this.focuedView;let e=0;if(o){const t=o.focusScenePath;e=o.displayer.commiter.undo(t)||0}return e}redo(){const o=this.focuedView;let e=0;if(o){const t=o.focusScenePath;e=o.displayer.commiter.redo(t)||0}return e}validator(o,e,t){var n;const i=D.clone(o[e]),s=D.clone(t);e==="focusScenePath"&&t&&!D.isEqual(i,s)&&(this.control.internalSceneChange(o.id,s),(n=this.focuedView)==null||n.displayer.commiter.onChangeScene()),e==="cameraOpt"&&!D.isEqual(i,s)&&this.control.internalCameraChange(o.id,s)}destroyAppView(o,e=!1){const t=this.appViews.get(o);t&&(this.control.textEditorManager.clear(o,e),t.displayer.destroy(),this.appViews.delete(o))}createMianView(o){this.mainView=new Proxy(o,{set:(e,t,i)=>(this.control.worker.isActive&&this.validator(e,t,i),e[t]=i,!0)})}createAppView(o){const e=o.id,t=new Proxy(o,{set:(i,s,n)=>(this.control.worker.isActive&&this.validator(i,s,n),i[s]=n,!0)});this.appViews.set(e,t)}isAppView(o){return o!==de&&this.appViews.has(o)}getView(o){var e;return o===de?this.mainView:(e=this.appViews)==null?void 0:e.get(o)}getCurScenePath(o){const e=this.getView(o);if(e)return e.focusScenePath}getAllViews(){return[this.mainView,...this.appViews.values()]}setViewScenePath(o,e){var t;if(o===de&&this.mainView)this.mainView.focusScenePath=e;else{const i=o&&((t=this.appViews)==null?void 0:t.get(o))||void 0;i&&(i.focusScenePath=e)}}setViewData(o,e){var t;if(o===de&&this.mainView)this.mainView.viewData=e;else{const i=o&&((t=this.appViews)==null?void 0:t.get(o))||void 0;i&&(i.viewData=e)}}setFocuedViewId(o){var e;this.focuedViewId=o,o===de?this.focuedView=this.mainView:this.focuedView=o&&((e=this.appViews)==null?void 0:e.get(o))||void 0,this.control.cursor.onFocusViewChange(),this.focuedView&&this.focuedView.displayer.commiter.onFocusView()}setViewFocusScenePath(o,e){var i;let t;o===de?t=this.mainView:t=(i=this.appViews)==null?void 0:i.get(o),t&&(t.focusScenePath=e)}destroy(){var o;this.internalMsgEmitter.removeAllListeners("addUndoTicker"),this.internalMsgEmitter.removeAllListeners("excludeIds"),(o=this.mainView)==null||o.displayer.destroy(),this.control.destroyMiniMap(de),this.appViews.forEach(e=>{this.destroyAppView(e.id,!0),this.control.worker.destroyViewWorker(e.id),this.control.destroyMiniMap(e.id)})}setFocuedViewCameraOpt(o){if(this.focuedView){const e=this.focuedView.cameraOpt;D.isEqual(e,o)||(this.focuedView.cameraOpt=o)}}transformToOriginPoint(o,e){const t=this.getView(e);if(t!=null&&t.viewData){const i=t.viewData.convertToPointOnScreen(o[0],o[1]);return[i.x,i.y]}return o}transformToScenePoint(o,e){const t=this.getView(e);if(t!=null&&t.viewData){const i=t.viewData.convertToPointInWorld({x:o[0],y:o[1]});return[i.x,i.y]}return o}render(o){var e,t,i,s,n,r,c,l,h,u,d,p,f,y,m,T,w;for(const v of o){const{rect:S,imageBitmap:N,isClear:I,isUnClose:b,drawCanvas:L,clearCanvas:j,viewId:E}=v,A=(e=this.getView(E))==null?void 0:e.displayer;if(A&&S){const{dpr:W,canvasBgRef:z,canvasFloatRef:O,canvasServiceFloatRef:ne,canvasTopRef:te}=A,Q=Math.floor(S.w*W),X=Math.floor(S.h*W),G=S.x*W,Z=S.y*W;if(I){switch(j){case ye.TopFloat:(i=(t=te.current)==null?void 0:t.getContext("2d"))==null||i.clearRect(G,Z,Q,X);break;case ye.Float:(n=(s=O.current)==null?void 0:s.getContext("2d"))==null||n.clearRect(G,Z,Q,X);break;case ye.ServiceFloat:(c=(r=ne.current)==null?void 0:r.getContext("2d"))==null||c.clearRect(G,Z,Q,X);break;case ye.Bg:(h=(l=z.current)==null?void 0:l.getContext("2d"))==null||h.clearRect(G,Z,Q,X);break}continue}if(L&&N)switch(L){case ye.TopFloat:(d=(u=te.current)==null?void 0:u.getContext("2d"))==null||d.drawImage(N,0,0,Q,X,G,Z,Q,X);break;case ye.Float:{(f=(p=O.current)==null?void 0:p.getContext("2d"))==null||f.drawImage(N,0,0,Q,X,G,Z,Q,X);break}case ye.ServiceFloat:{(m=(y=ne.current)==null?void 0:y.getContext("2d"))==null||m.drawImage(N,0,0,Q,X,G,Z,Q,X);break}case ye.Bg:{(w=(T=z.current)==null?void 0:T.getContext("2d"))==null||w.drawImage(N,0,0,Q,X,G,Z,Q,X);break}}if(b)continue;N==null||N.close()}}}showFloatBar(o,e,t){const i=this.getView(o),s=i==null?void 0:i.displayer.vDom;s&&s.showFloatBar(e,t)}setActiveTextEditor(o,e){const t=this.getView(o),i=t==null?void 0:t.displayer.vDom;i&&i.setActiveTextEditor(e)}setActiveMiniMap(o,e){const t=this.getView(o),i=t==null?void 0:t.displayer.vDom;i&&i.setActiveMiniMap(e&&o||void 0)}}g(It,"defaultCameraOpt",{centerX:0,centerY:0,scale:1}),g(It,"defaultScreenCanvasOpt",{autoRender:!1,contextType:"webgl2"}),g(It,"defaultLayerOpt",{offscreen:!0,handleEvent:!1,depth:!1});class ZM{constructor(o,e,t){g(this,"viewId");g(this,"control");g(this,"internalMsgEmitter");g(this,"commiter");g(this,"cachePoint");g(this,"cacheCursorPoint");g(this,"active",!0);g(this,"mousedown",o=>{if(this.active&&o.button===0&&this.viewId){this.control.worker.checkDrawingWork(this.viewId),this.reflashContainerOffset();const e=this.getPoint(o);this.cachePoint=e,e&&this.control.worker.originalEventLintener(P.Start,e,this.viewId)}});g(this,"mousemove",o=>{if(this.active&&this.viewId){const e=this.getPoint(o);this.cachePoint=e,e&&this.control.worker.originalEventLintener(P.Doing,e,this.viewId)}});g(this,"mouseup",o=>{if(this.active&&o.button===0&&this.viewId){const e=this.getPoint(o)||this.cachePoint;e&&this.control.worker.originalEventLintener(P.Done,e,this.viewId),this.cachePoint=void 0}});g(this,"touchstart",o=>{var e;if(this.active){if(!vt(o)){this.control.worker.unWritable(),this.viewId&&this.control.worker.removeDrawingWork(this.viewId);return}if(this.viewId){if(!this.control.worker.isAbled()){const i=(e=this.control.worker.getCurrentToolsData())==null?void 0:e.toolsType;i&&this.control.effectViewContainer(i)}this.control.worker.checkDrawingWork(this.viewId),this.reflashContainerOffset();const t=this.getPoint(o);this.cachePoint=t,t&&this.control.worker.originalEventLintener(P.Start,t,this.viewId)}}});g(this,"touchmove",o=>{if(this.active){if(!vt(o)){this.control.worker.unWritable(),this.control.worker.removeDrawingWork(this.viewId);return}if(this.viewId){const e=this.getPoint(o);this.cachePoint=e,e&&this.control.worker.originalEventLintener(P.Doing,e,this.viewId)}}});g(this,"touchend",o=>{if(this.active){if(!vt(o)||!this.control.worker.isAbled()){this.control.worker.unWritable(),this.control.worker.removeDrawingWork(this.viewId);return}if(this.viewId){const e=this.getPoint(o)||this.cachePoint;e&&this.control.worker.originalEventLintener(P.Done,e,this.viewId),this.cachePoint=void 0}}});g(this,"cursorMouseMove",D.throttle(o=>{const e=this.getPoint(o);this.cacheCursorPoint&&D.isEqual(e,this.cacheCursorPoint)||!this.viewId||(this.cacheCursorPoint=e,e&&this.control.worker.sendCursorEvent(e,this.viewId))},30,{leading:!1}));g(this,"cursorMouseLeave",D.throttle(()=>{this.viewId&&(this.cacheCursorPoint=[void 0,void 0],this.control.worker.sendCursorEvent(this.cacheCursorPoint,this.viewId))},30,{leading:!1}));g(this,"keydown",o=>{this.control.hotkeyManager.colloctHotkey(o)});this.viewId=o,this.control=e,this.internalMsgEmitter=t;const i={control:this.control,internalMsgEmitter:this.internalMsgEmitter,viewId:this.viewId};this.commiter=new so(i)}bindToolsClass(){var e,t;const o=(t=(e=this.control.worker)==null?void 0:e.currentToolsData)==null?void 0:t.toolsType;switch(o){case k.Text:case k.Pencil:case k.LaserPen:case k.Arrow:case k.Straight:case k.Rectangle:case k.Ellipse:case k.Star:case k.Polygon:case k.SpeechBalloon:case k.Eraser:case k.PencilEraser:case k.BitMapEraser:this.eventTragetElement&&(this.eventTragetElement.className=`netless-whiteboard ${o===k.Text?"cursor-text":o===k.Eraser||o===k.PencilEraser||o===k.BitMapEraser?"cursor-eraser":o===k.Pencil||o===k.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(o){this.viewId=o}destroy(){this.eventTragetElement&&this.removeDisplayerEvent(this.eventTragetElement),this.vDom=void 0,this.control.cursor.clearViewCursor(this.viewId),this.internalMsgEmitter.removeAllListeners([q.Cursor,this.viewId])}getPoint(o){const e=Js(o);if(e&&D.isNumber(e.x)&&D.isNumber(e.y))return[e.x-this.containerOffset.x,e.y-this.containerOffset.y]}setActive(o){this.active=o}async stopEventHandler(){this.cachePoint&&(await this.control.worker.originalEventLintener(P.Done,this.cachePoint,this.viewId),this.cachePoint=void 0)}getTranslate(o){const t=(o.style.WebkitTransform||getComputedStyle(o,"").getPropertyValue("-webkit-transform")||o.style.transform||getComputedStyle(o,"").getPropertyValue("transform")).match(/-?[0-9]+\.?[0-9]*/g),i=t&&parseInt(t[0])||0,s=t&&parseInt(t[1])||0;return[i,s]}getContainerOffset(o,e){var s;const t=this.getTranslate(o);let i={x:e.x+o.offsetLeft+t[0],y:e.y+o.offsetTop+t[1]};return(s=o.offsetParent)!=null&&s.nodeName&&o.offsetParent.nodeName!=="BODY"&&(i=this.getContainerOffset(o.offsetParent,i)),i}bindDisplayerEvent(o){o.addEventListener("mousedown",this.mousedown,!1),o.addEventListener("touchstart",this.touchstart,{capture:!0,passive:!1}),window.addEventListener("mouseleave",this.mouseup,!1),window.addEventListener("mousemove",this.mousemove,{capture:!0,passive:!1}),window.addEventListener("mouseup",this.mouseup,!1),window.addEventListener("touchmove",this.touchmove,{capture:!0,passive:!1}),window.addEventListener("touchend",this.touchend,{capture:!0,passive:!1}),o.addEventListener("mousemove",this.cursorMouseMove,!1),o.addEventListener("mouseleave",this.cursorMouseLeave,!1),o.addEventListener("keydown",this.keydown,!0)}removeDisplayerEvent(o){o.removeEventListener("mousedown",this.mousedown),o.removeEventListener("touchstart",this.touchstart),window.removeEventListener("mouseleave",this.mouseup),window.removeEventListener("mousemove",this.mousemove),window.removeEventListener("mouseup",this.mouseup),window.removeEventListener("touchmove",this.touchmove),window.removeEventListener("touchend",this.touchend),o.removeEventListener("mousemove",this.cursorMouseMove),o.removeEventListener("mouseleave",this.cursorMouseLeave),o.removeEventListener("keydown",this.keydown)}}class Ks{constructor(o,e){g(this,"viewId",de);g(this,"control");g(this,"internalMsgEmitter");g(this,"commiter");g(this,"cachePoint");g(this,"cacheCursorPoint");g(this,"active",!0);g(this,"mousedown",o=>{if(this.active&&o.button===0){this.control.worker.checkDrawingWork(this.viewId),this.reflashContainerOffset();const e=this.getPoint(o);this.cachePoint=e,e&&this.control.worker.originalEventLintener(P.Start,e,this.viewId)}});g(this,"mousemove",o=>{if(!this.active)return;const e=this.getPoint(o);this.cachePoint=e,e&&this.control.worker.originalEventLintener(P.Doing,e,this.viewId)});g(this,"mouseup",o=>{if(this.active&&o.button===0){const e=this.getPoint(o)||this.cachePoint;e&&this.control.worker.originalEventLintener(P.Done,e,this.viewId),this.cachePoint=void 0}});g(this,"touchstart",o=>{var t;if(!this.active)return;if(!vt(o)){this.control.worker.unWritable(),this.viewId&&this.control.worker.removeDrawingWork(this.viewId);return}if(!this.control.worker.isAbled()){const i=(t=this.control.worker.getCurrentToolsData())==null?void 0:t.toolsType;i&&this.control.effectViewContainer(i)}this.control.worker.checkDrawingWork(this.viewId),this.reflashContainerOffset();const e=this.getPoint(o);this.cachePoint=e,e&&this.control.worker.originalEventLintener(P.Start,e,this.viewId)});g(this,"touchmove",o=>{if(!this.active)return;if(!vt(o)){this.control.worker.unWritable(),this.viewId&&this.control.worker.removeDrawingWork(this.viewId);return}const e=this.getPoint(o);this.cachePoint=e,e&&this.control.worker.originalEventLintener(P.Doing,e,this.viewId)});g(this,"touchend",o=>{if(!this.active)return;if(!vt(o)||!this.control.worker.isAbled()){this.control.worker.removeDrawingWork(this.viewId);return}const e=this.getPoint(o)||this.cachePoint;e&&this.control.worker.originalEventLintener(P.Done,e,this.viewId),this.cachePoint=void 0});g(this,"cursorMouseMove",D.throttle(o=>{const e=this.getPoint(o);this.cacheCursorPoint&&D.isEqual(e,this.cacheCursorPoint)||(this.cacheCursorPoint=e,e&&this.control.worker.sendCursorEvent(e,this.viewId))},30,{leading:!1}));g(this,"cursorMouseLeave",D.throttle(()=>{this.cacheCursorPoint=[void 0,void 0],this.control.worker.sendCursorEvent(this.cacheCursorPoint,this.viewId)},30,{leading:!1}));g(this,"keydown",o=>{this.control.hotkeyManager.colloctHotkey(o)});this.control=o,this.internalMsgEmitter=e;const t={control:this.control,internalMsgEmitter:this.internalMsgEmitter,viewId:this.viewId};this.commiter=new so(t)}bindToolsClass(){var i,s;const o=(s=(i=this.control.worker)==null?void 0:i.currentToolsData)==null?void 0:s.toolsType,e=this.control.renderControl.isWriteable(),t=this.control.worker.isAbled();switch(o){case k.Text:case k.Pencil:case k.LaserPen:case k.Arrow:case k.Straight:case k.Rectangle:case k.Ellipse:case k.Star:case k.Polygon:case k.SpeechBalloon:case k.Eraser:case k.PencilEraser:case k.BitMapEraser:this.eventTragetElement&&(this.eventTragetElement.className=e&&t?`netless-whiteboard ${o===k.Text?"cursor-text":o===k.Eraser||o===k.PencilEraser||o===k.BitMapEraser?"cursor-eraser":o===k.Pencil||o===k.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}))}destroy(){this.eventTragetElement&&this.removeDisplayerEvent(this.eventTragetElement),this.vDom=void 0,this.control.cursor.destroy(),this.internalMsgEmitter.removeAllListeners([q.Cursor,this.viewId])}getPoint(o){const e=Js(o);if(e&&D.isNumber(e.x)&&D.isNumber(e.y))return[e.x-this.containerOffset.x,e.y-this.containerOffset.y]}setActive(o){this.active=o}async stopEventHandler(){this.cachePoint&&(await this.control.worker.originalEventLintener(P.Done,this.cachePoint,this.viewId),this.cachePoint=void 0)}getTranslate(o){const t=(o.style.WebkitTransform||getComputedStyle(o,"").getPropertyValue("-webkit-transform")||o.style.transform||getComputedStyle(o,"").getPropertyValue("transform")).match(/-?[0-9]+\.?[0-9]*/g),i=t&&parseInt(t[0])||0,s=t&&parseInt(t[1])||0;return[i,s]}getContainerOffset(o,e){var s;const t=this.getTranslate(o);let i={x:e.x+o.offsetLeft+t[0],y:e.y+o.offsetTop+t[1]};return(s=o.offsetParent)!=null&&s.nodeName&&o.offsetParent.nodeName!=="BODY"&&(i=this.getContainerOffset(o.offsetParent,i)),i}bindDisplayerEvent(o){o.addEventListener("mousedown",this.mousedown,!1),window.addEventListener("mouseleave",this.mouseup,!1),window.addEventListener("mousemove",this.mousemove,{capture:!1,passive:!1}),window.addEventListener("mouseup",this.mouseup,!1),o.addEventListener("touchstart",this.touchstart,{capture:!0,passive:!1}),window.addEventListener("touchmove",this.touchmove,{capture:!0,passive:!1}),window.addEventListener("touchend",this.touchend,{capture:!0,passive:!1}),o.addEventListener("mousemove",this.cursorMouseMove,!0),o.addEventListener("mouseleave",this.cursorMouseLeave,!0),o.addEventListener("keydown",this.keydown,!0)}removeDisplayerEvent(o){o.removeEventListener("mousedown",this.mousedown),o.removeEventListener("touchstart",this.touchstart),window.removeEventListener("mouseleave",this.mouseup),window.removeEventListener("mousemove",this.mousemove),window.removeEventListener("mouseup",this.mouseup),window.removeEventListener("touchmove",this.touchmove),window.removeEventListener("touchend",this.touchend),o.removeEventListener("mousemove",this.cursorMouseMove),o.removeEventListener("mouseleave",this.cursorMouseLeave),o.removeEventListener("keydown",this.keydown)}}const qM="index-module__Container__nLsM3",XM="index-module__CanvasBox__j2Xe-",JM="index-module__FloatCanvas__d1YR7",KM="index-module__TopFloatCanvas__7IaCw",_M="index-module__CanvasBoxSub__hcMeK",em="index-module__SnapshotBox__--eeE",tm="index-module__FloatBar__cm-EL",om="index-module__RotateBtn__HSSkf",im="index-module__ResizeBtn__yjvda",sm="index-module__CursorBox__2UHvI",nm="index-module__TextEditorContainer__Qm8KC",rm="index-module__ResizeTowBox__HOllX",am="index-module__FloatBarBtn__FJrOG",ze={Container:qM,CanvasBox:XM,FloatCanvas:JM,TopFloatCanvas:KM,CanvasBoxSub:_M,SnapshotBox:em,FloatBar:tm,RotateBtn:om,ResizeBtn:im,CursorBox:sm,TextEditorContainer:nm,ResizeTowBox:rm,FloatBarBtn:am},cm={delete:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDZ2NmEyIDIgMCAwIDEtMiAySDZhMiAyIDAgMCAxLTItMlY2aDBtMS0yYTIgMiAwIDAgMSAyLTJoMmEyIDIgMCAwIDEgMiAyaDBNMyA0aDEwIiBzdHJva2U9IiM0NDRFNjAiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==",duplicate:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgc3Ryb2t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TEgNC05IDQgOU02IDdoNCIgc3Ryb2tlPSIjMzM4MUZGIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","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,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHR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NjRBMTM4LjY2NjY2NyAxMzguNjY2NjY3IDAgMCAwIDIxMy4zMzMzMzMgNjUwLjY2NjY2N3Y2NHogbTc0LjY2NjY2NyA3NC42NjY2NjZBNzQuNjY2NjY3IDc0LjY2NjY2NyAwIDAgMSAyMTMuMzMzMzMzIDg2NHY2NGExMzguNjY2NjY3IDEzOC42NjY2NjcgMCAwIDAgMTM4LjY2NjY2Ny0xMzguNjY2NjY3aC02NHpNMjEzLjMzMzMzMyA4NjRhNzQuNjY2NjY3IDc0LjY2NjY2NyAwIDAgMS03NC42NjY2NjYtNzQuNjY2NjY3aC02NEExMzguNjY2NjY3IDEzOC42NjY2NjcgMCAwIDAgMjEzLjMzMzMzMyA5Mjh2LTY0ek0yNDUuMzMzMzMzIDY4Mi42NjY2Njd2LTIzNC42NjY2NjdoLTY0VjY4Mi42NjY2NjdoNjR6IG0tNTQuNjEzMzMzLTIxMi4wNTMzMzRsODUuMzMzMzMzIDg1LjMzMzMzNCA0NS4yMjY2NjctNDUuMjI2NjY3LTg1LjMzMzMzMy04NS4zMzMzMzMtNDUuMjI2NjY3IDQ1LjIyNjY2NnogbTAtNDUuMjI2NjY2bC04NS4zMzMzMzMgODUuMzMzMzMzIDQ1LjIyNjY2NiA0NS4yMjY2NjcgODUuMzMzMzM0LTg1LjMzMzMzNC00NS4yMjY2NjctNDUuMjI2NjY2eiIgIGZpbGw9IiM0NDRFNjAiPjwvcGF0aD48L3N2Zz4="};function xe(a){return cm[a]}const lm=a=>{const{workIds:o,mananger:e}=a;return M.createElement("div",{className:"button normal-button",style:{touchAction:"none"},onClick:t=>{t.cancelable&&t.preventDefault(),t.stopPropagation(),ee.emitMethod(q.MainEngine,Y.DeleteNode,{workIds:o||[H],viewId:e.viewId})},onTouchEnd:t=>{t.cancelable&&t.preventDefault(),t.stopPropagation(),ee.emitMethod(q.MainEngine,Y.DeleteNode,{workIds:o||[H],viewId:e.viewId})}},M.createElement("img",{alt:"icon",src:xe("delete")}))},hm=a=>{const{workIds:o,viewId:e}=a;return M.createElement("div",{className:"button normal-button",onClick:t=>{t.cancelable&&t.preventDefault(),t.stopPropagation(),ee.emitMethod(q.MainEngine,Y.CopyNode,{workIds:o||[H],viewId:e})},onTouchEnd:t=>{t.stopPropagation(),ee.emitMethod(q.MainEngine,Y.CopyNode,{workIds:o||[H],viewId:e})}},M.createElement("img",{alt:"icon",src:xe("duplicate")}))},qi=a=>{const{icon:o,onClickHandler:e,onTouchEndHandler:t}=a;return M.createElement("div",{className:"button normal-button",onClick:e,onTouchEnd:t},M.createElement("img",{src:xe(o)}))},um=a=>{const{open:o,setOpen:e,floatBarRef:t}=a,{floatBarData:i,mananger:s}=M.useContext(Ne),[n,r]=M.useState([]),c=M.useMemo(()=>{if(t!=null&&t.current&&D.isNumber(i==null?void 0:i.y)&&(s!=null&&s.height)){if(t.current.offsetTop&&t.current.offsetTop+i.y>180){const d={};return d.top="inherit",d.bottom=50,d}else if(!t.current.offsetTop&&(s==null?void 0:s.height)-t.current.offsetTop-i.y<120){const d={};return d.top="inherit",d.bottom=50,d}}},[t==null?void 0:t.current,i,s]),l=M.useMemo(()=>o?M.createElement("div",{className:"image-layer-menu",style:c},M.createElement(qi,{icon:"to-top",onClickHandler:d=>{d.cancelable&&d.preventDefault(),d.stopPropagation(),ee.emitMethod(q.MainEngine,Y.ZIndexNode,{workIds:[H],layer:lt.Top,viewId:s==null?void 0:s.viewId})},onTouchEndHandler:d=>{d.stopPropagation(),ee.emitMethod(q.MainEngine,Y.ZIndexNode,{workIds:[H],layer:lt.Top,viewId:s==null?void 0:s.viewId})}}),M.createElement(qi,{icon:"to-bottom",onClickHandler:d=>{d.cancelable&&d.preventDefault(),d.stopPropagation(),ee.emitMethod(q.MainEngine,Y.ZIndexNode,{workIds:[H],layer:lt.Bottom,viewId:s==null?void 0:s.viewId})},onTouchEndHandler:d=>{d.stopPropagation(),ee.emitMethod(q.MainEngine,Y.ZIndexNode,{workIds:[H],layer:lt.Bottom,viewId:s==null?void 0:s.viewId})}})):null,[o,c]),h=d=>{d.cancelable&&d.preventDefault(),d.stopPropagation(),d.nativeEvent.stopImmediatePropagation(),e(!o)},u=d=>{d.stopPropagation(),d.nativeEvent.stopImmediatePropagation(),e(!o)};return M.useEffect(()=>{D.isEqual(i==null?void 0:i.selectIds,n)||i!=null&&i.selectIds&&!D.isEqual(i==null?void 0:i.selectIds,n)&&(r(i==null?void 0:i.selectIds),e(!1))},[o,i,n,e]),M.createElement("div",{className:`button normal-button ${o&&"active"}`,onClick:h,onTouchEnd:u},l,M.createElement("img",{alt:"icon",src:xe(o?"layer-pressed":"layer")}))},dm=()=>M.createElement("svg",{style:{marginLeft:"2px"},viewBox:"0 0 1025 1024",width:"14",height:"14"},M.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"})),_s=a=>{const{activeColor:o,onClickHandler:e,onTouchEndHandler:t}=a;return M.createElement("div",{className:`font-color-button ${o==="transparent"?"active":""}`,onClick:e,onTouchEnd:t},M.createElement("div",{className:"circle none"}))},mo=a=>{const{color:o,activeColor:e,onClickHandler:t,onTouchEndHandler:i}=a;return M.createElement("div",{className:`font-color-button ${o===e?"active":""}`,onClick:t,onTouchEnd:i},M.createElement("div",{className:"circle",style:{backgroundColor:we(o,1)}}))},wo=a=>{const{opacity:o,activeColor:e,setCurOpacity:t}=a,[i,s]=M.useState({x:108,y:0});if(M.useEffect(()=>{s({x:o*100+8,y:0})},[]),!e)return null;const n=D.throttle((l,h)=>{l.cancelable&&l.preventDefault(),l.stopPropagation(),h.x!==(i==null?void 0:i.x)&&s({x:h.x,y:0});const u=Math.min(Math.max(h.x-8,0),100)/100;o!==u&&t(u,e,P.Doing)},100,{leading:!1}),r=l=>{l.cancelable&&l.preventDefault(),l.stopPropagation(),t(o,e,P.Start)},c=D.throttle((l,h)=>{l.cancelable&&l.preventDefault(),l.stopPropagation(),h.x!==(i==null?void 0:i.x)&&s({x:h.x,y:0});const u=Math.min(Math.max(h.x-8,0),100)/100;t(u,e,P.Done)},100,{leading:!1});return M.createElement("div",{className:"font-color-opacity",style:{marginLeft:"10px"},onClick:l=>{const h=l.nativeEvent.offsetX,u=Math.min(Math.max(h-12,0),100)/100;s({x:u*100+8,y:0}),t(u,e,P.Done)}},M.createElement("div",{className:"range-color",style:{background:`linear-gradient(to right, ${we(e,0)}, ${we(e,1)})`}}),M.createElement("div",{className:"range-opacity"},M.createElement(Nt,{bounds:"parent",axis:"x",position:i,onDrag:n,onStart:r,onStop:c},M.createElement("div",{className:"circle",style:{backgroundColor:we(e,o)},onClick:l=>{l.cancelable&&l.preventDefault(),l.stopPropagation()}}))))},pm=a=>{const{min:o,max:e,activeNumber:t,setActiveNumber:i,color:s}=a,[n,r]=M.useState({x:108,y:0});if(M.useEffect(()=>{const u=Math.ceil((t-o)/(e-o)*100)+8;r({x:u,y:0})},[]),!t)return null;const c=D.throttle((u,d)=>{u.cancelable&&u.preventDefault(),u.stopPropagation(),d.x!==(n==null?void 0:n.x)&&r({x:d.x,y:0});const p=Math.ceil(Math.max(d.x-8,0)/100*(e-o)+o);t!==p&&i(p,P.Doing)},100,{leading:!1}),l=u=>{u.cancelable&&u.preventDefault(),u.stopPropagation(),i(t,P.Start)},h=D.throttle((u,d)=>{u.cancelable&&u.preventDefault(),u.stopPropagation(),d.x!==(n==null?void 0:n.x)&&r({x:d.x,y:0});const p=Math.ceil(Math.max(d.x-8,0)/100*(e-o)+o);i(p,P.Done)},100,{leading:!1});return M.createElement("div",{className:"font-color-opacity",style:{marginLeft:"10px"},onClick:u=>{const d=u.nativeEvent.offsetX,p=Math.ceil(Math.max(d-12,0)/100*(e-o)+o),f=Math.ceil((p-o)/(e-o)*100)+8;r({x:f,y:0}),i(p,P.Done)}},M.createElement("div",{className:"range-color",style:{backgroundColor:s}}),M.createElement("div",{className:"range-opacity"},M.createElement(Nt,{bounds:"parent",axis:"x",position:n,onDrag:c,onStart:l,onStop:h},M.createElement("div",{className:"circle",style:{backgroundColor:s},onClick:u=>{u.cancelable&&u.preventDefault(),u.stopPropagation()}},M.createElement("div",{className:"range-opacity-data-icon"},t)))))},fm=a=>{const{useStroke:o,color:e,activeStrokeType:t,setStrokeType:i}=a;return M.createElement("div",{className:"stroke-type-box"},!!o&&M.createElement("div",{className:`stroke-type-box-item Stroke ${t===oe.Stroke&&"active"}`,style:{backgroundColor:e},onClick:()=>{i(oe.Stroke)},onTouchEnd:()=>{i(oe.Stroke)}}),M.createElement("div",{className:`stroke-type-box-item Normal ${t===oe.Normal&&"active"}`,style:{borderColor:e},onClick:()=>{i(oe.Normal)},onTouchEnd:()=>{i(oe.Normal)}}),M.createElement("div",{className:`stroke-type-box-item Dotted ${t===oe.Dotted&&"active"}`,style:{borderColor:e},onClick:()=>{i(oe.Dotted)},onTouchEnd:()=>{i(oe.Dotted)}}),M.createElement("div",{className:`stroke-type-box-item LongDotted ${t===oe.LongDotted&&"active"}`,style:{borderColor:e},onClick:()=>{i(oe.LongDotted)},onTouchEnd:()=>{i(oe.LongDotted)}}))},gm=a=>{const{open:o,setOpen:e,floatBarRef:t}=a,{floatBarData:i,floatBarColors:s,mananger:n,setFloatBarData:r}=M.useContext(Ne),[c,l]=M.useState(),[h,u]=M.useState(1);M.useEffect(()=>{if(i!=null&&i.strokeColor){const[w,v]=Mo(i.strokeColor);l(w),u(v)}},[i]);const d=M.useMemo(()=>{if(t!=null&&t.current&&D.isNumber(i==null?void 0:i.y)&&(n!=null&&n.height)){if(t.current.offsetTop&&t.current.offsetTop+i.y>180){const w={};return w.top="inherit",w.bottom=50,w}else if(!t.current.offsetTop&&(n==null?void 0:n.height)-t.current.offsetTop-i.y<120){const w={};return w.top="inherit",w.bottom=50,w}}},[(t==null?void 0:t.current)&&i,n==null?void 0:n.height]),p=M.useMemo(()=>M.createElement(wo,{key:"strokeColors",opacity:h,activeColor:c,setCurOpacity:(w,v,S)=>{S===P.Start&&(n!=null&&n.control.room)&&(n.control.room.disableDeviceInputs=!0),S===P.Done&&(n!=null&&n.control.room)&&(n.control.room.disableDeviceInputs=!1),u(w);const N=we(v,w);i!=null&&i.strokeColor&&r({strokeColor:N}),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:[H],strokeColor:N,workState:S,viewId:n==null?void 0:n.viewId})}}),[h,c,n==null?void 0:n.control.room,n==null?void 0:n.viewId,i]),f=M.useMemo(()=>{var w,v;return c&&(i!=null&&i.thickness)?M.createElement(pm,{key:"strokeThickness",min:Math.min(i.thickness,((w=n==null?void 0:n.control.pluginOptions.strokeWidth)==null?void 0:w.min)||1),max:Math.max(i.thickness,((v=n==null?void 0:n.control.pluginOptions.strokeWidth)==null?void 0:v.max)||10),activeNumber:i.thickness,setActiveNumber:(S,N)=>{N===P.Start&&(n!=null&&n.control.room)&&(n.control.room.disableDeviceInputs=!0),N===P.Done&&(n!=null&&n.control.room)&&(n.control.room.disableDeviceInputs=!1),i!=null&&i.thickness&&r({thickness:S}),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:[H],thickness:S,workState:N,viewId:n==null?void 0:n.viewId})},color:c}):null},[c,i==null?void 0:i.thickness,n==null?void 0:n.control.room,n==null?void 0:n.viewId]),y=M.useMemo(()=>c&&(i!=null&&i.strokeType)?M.createElement(fm,{key:"strokeType",useStroke:i==null?void 0:i.useStroke,activeStrokeType:i.strokeType,setStrokeType:w=>{i.strokeType&&r({strokeType:w}),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:[H],strokeType:w,workState:P.Done,viewId:n==null?void 0:n.viewId})},color:c}):null,[c,i==null?void 0:i.strokeType,n==null?void 0:n.control.room,n==null?void 0:n.viewId,i==null?void 0:i.useStroke]),m=M.useMemo(()=>o?M.createElement("div",{className:"font-colors-menu",style:d,onTouchEnd:w=>{w.stopPropagation(),w.nativeEvent.stopImmediatePropagation()},onClick:w=>{w.cancelable&&w.preventDefault(),w.stopPropagation(),w.nativeEvent.stopImmediatePropagation()}},y,f,M.createElement("div",{className:"font-colors-line"}),s.concat().map((w,v)=>{const S=Bt(...w);return M.createElement(mo,{key:v,color:S,activeColor:c,onTouchEndHandler:N=>{N.stopPropagation(),l(S);const I=we(S,h);i!=null&&i.strokeColor&&(i.strokeColor=I,r({strokeColor:I})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:[H],workState:P.Done,strokeColor:I,viewId:n==null?void 0:n.viewId})},onClickHandler:N=>{N.cancelable&&N.preventDefault(),N.stopPropagation(),l(S);const I=we(S,h);i!=null&&i.strokeColor&&(i.strokeColor=I,r({strokeColor:I})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:[H],workState:P.Done,strokeColor:I,viewId:n==null?void 0:n.viewId})}})}),p):null,[o,s,p,c,h,i,n==null?void 0:n.viewId,d]),T=M.useMemo(()=>c?M.createElement("div",{className:"color-bar-ring",style:{backgroundColor:we(c,h)}},M.createElement("div",{className:"circle"})):null,[c,h]);return M.createElement("div",{className:`button normal-button font-colors-icon ${o&&"active"}`,onTouchEnd:w=>{w.stopPropagation(),w.nativeEvent.stopImmediatePropagation(),e(!o)},onClick:w=>{w.cancelable&&w.preventDefault(),w.stopPropagation(),w.nativeEvent.stopImmediatePropagation(),e(!o)}},T,m)},ym=a=>{const{open:o,setOpen:e,floatBarRef:t}=a,{floatBarData:i,floatBarColors:s,mananger:n,setFloatBarData:r}=M.useContext(Ne),[c,l]=M.useState(),[h,u]=M.useState(1);M.useEffect(()=>{if(i!=null&&i.fillColor){const[m,T]=(i==null?void 0:i.fillColor)==="transparent"&&["transparent",1]||Mo(i.fillColor);l(m),u(T)}},[i]);const d=M.useMemo(()=>{if(t!=null&&t.current&&D.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==null?void 0:t.current,i,n==null?void 0:n.height]),p=M.useMemo(()=>c&&c!=="transparent"?M.createElement(wo,{key:"fillColors",opacity:h||0,activeColor:c,setCurOpacity:(m,T,w)=>{w===P.Start&&(n!=null&&n.control.room)&&(n.control.room.disableDeviceInputs=!0),w===P.Done&&(n!=null&&n.control.room)&&(n.control.room.disableDeviceInputs=!1),u(m);const v=we(T,m);i!=null&&i.fillColor&&(i.fillColor=v,r({fillColor:v})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:[H],fillColor:c&&we(T,m),workState:w,viewId:n==null?void 0:n.viewId})}}):null,[c,h,n==null?void 0:n.control.room,n==null?void 0:n.viewId,i]),f=M.useMemo(()=>o?M.createElement("div",{className:"font-colors-menu",style:d,onTouchEnd:m=>{m.stopPropagation(),m.nativeEvent.stopImmediatePropagation()},onClick:m=>{m.cancelable&&m.preventDefault(),m.stopPropagation(),m.nativeEvent.stopImmediatePropagation()}},M.createElement(_s,{activeColor:c,onTouchEndHandler:m=>{m.stopPropagation(),l("transparent");const T="transparent";i!=null&&i.fillColor&&(i.fillColor=T,r({fillColor:T})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:[H],workState:P.Done,fillColor:T,viewId:n==null?void 0:n.viewId})},onClickHandler:m=>{m.cancelable&&m.preventDefault(),m.stopPropagation(),l("transparent");const T="transparent";i!=null&&i.fillColor&&(i.fillColor=T,r({fillColor:T})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:[H],workState:P.Done,fillColor:T,viewId:n==null?void 0:n.viewId})}}),s.map((m,T)=>{const w=Bt(...m);return M.createElement(mo,{key:T,color:w,activeColor:c,onTouchEndHandler:v=>{v.cancelable&&v.preventDefault(),v.stopPropagation(),l(w);const S=we(w,h);i!=null&&i.fillColor&&(i.fillColor=S,r({fillColor:S})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:[H],workState:P.Done,fillColor:S,viewId:n==null?void 0:n.viewId})},onClickHandler:v=>{v.cancelable&&v.preventDefault(),v.stopPropagation(),l(w);const S=we(w,h);i!=null&&i.fillColor&&(i.fillColor=S,r({fillColor:S})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:[H],workState:P.Done,fillColor:S,viewId:n==null?void 0:n.viewId})}})}),p):null,[o,c,s,p,i,n==null?void 0:n.viewId,h,d]),y=M.useMemo(()=>{const m=c&&c!=="transparent"&&we(c,h)||"transparent";return M.createElement("div",{className:"color-bar-fill"},M.createElement("div",{className:"circle",style:{backgroundColor:m}}))},[c,h]);return M.createElement("div",{className:`button normal-button font-colors-icon ${o&&"active"}`,onTouchEnd:m=>{m.stopPropagation(),m.nativeEvent.stopImmediatePropagation(),e(!o)},onClick:m=>{m.cancelable&&m.preventDefault(),m.stopPropagation(),m.nativeEvent.stopImmediatePropagation(),e(!o)}},y,f)},Mm=a=>{const{open:o,setOpen:e,textOpt:t,workIds:i,floatBarRef:s}=a,{floatBarColors:n,mananger:r,setFloatBarData:c,floatBarData:l}=M.useContext(Ne),[h,u]=M.useState(),[d,p]=M.useState(1);M.useEffect(()=>{if(t!=null&&t.fontColor){const[w,v]=(t==null?void 0:t.fontColor)==="transparent"&&["transparent",0]||Mo(t.fontColor);u(w),p(v)}},[t==null?void 0:t.fontColor]);const f=M.useMemo(()=>{if(s!=null&&s.current&&D.isNumber(l==null?void 0:l.y)&&(r!=null&&r.height)){if(s.current.offsetTop&&s.current.offsetTop+l.y>180){const w={};return w.top="inherit",w.bottom=50,w}else if(!s.current.offsetTop&&(r==null?void 0:r.height)-s.current.offsetTop-l.y<120){const w={};return w.top="inherit",w.bottom=50,w}}},[s==null?void 0:s.current,l,r]),y=M.useMemo(()=>h&&h!=="transparent"?M.createElement(wo,{key:"fontColors",opacity:d,activeColor:h,setCurOpacity:(w,v,S)=>{S===P.Start&&(r!=null&&r.control.room)&&(r.control.room.disableDeviceInputs=!0),S===P.Done&&(r!=null&&r.control.room)&&(r.control.room.disableDeviceInputs=!1),p(w);const N=we(v,w);l!=null&&l.textOpt&&(l.textOpt.fontColor=N,c({textOpt:l.textOpt})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:i||[H],fontColor:h&&N,workState:S,viewId:r==null?void 0:r.viewId})}}):null,[h,d,r==null?void 0:r.control.room,r==null?void 0:r.viewId,l==null?void 0:l.textOpt,i]),m=M.useMemo(()=>o?M.createElement("div",{className:"font-colors-menu",style:f,onTouchEnd:w=>{w.stopPropagation(),w.nativeEvent.stopImmediatePropagation()},onClick:w=>{w.cancelable&&w.preventDefault(),w.stopPropagation(),w.nativeEvent.stopImmediatePropagation()}},n.map((w,v)=>{const S=Bt(...w);return M.createElement(mo,{key:v,color:S,activeColor:h,onTouchEndHandler:N=>{N.stopPropagation(),u(S);const I=we(S,d);l!=null&&l.textOpt&&(l.textOpt.fontColor=I,c({textOpt:l.textOpt})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:i||[H],workState:P.Done,fontColor:I,viewId:r==null?void 0:r.viewId})},onClickHandler:N=>{N.cancelable&&N.preventDefault(),N.stopPropagation(),u(S);const I=we(S,d);l!=null&&l.textOpt&&(l.textOpt.fontColor=I,c({textOpt:l.textOpt})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:i||[H],workState:P.Done,fontColor:I,viewId:r==null?void 0:r.viewId})}})}),y):null,[o,n,y,h,d,l==null?void 0:l.textOpt,i,r==null?void 0:r.viewId,f]),T=M.useMemo(()=>{const w=h&&h!=="transparent"&&we(h,d)||"transparent";return M.createElement("div",{className:"color-bar"},M.createElement("div",{className:"color-bar-color",style:{backgroundColor:w}}))},[h,d]);return M.createElement("div",{className:`button normal-button font-colors-icon ${o&&"active"}`,onTouchEnd:w=>{w.stopPropagation(),w.nativeEvent.stopImmediatePropagation(),e(!o)},onClick:w=>{w.cancelable&&w.preventDefault(),w.stopPropagation(),w.nativeEvent.stopImmediatePropagation(),e(!o)}},M.createElement("img",{alt:"icon",src:xe("font-colors")}),T,m)},mm=a=>{const{open:o,setOpen:e,textOpt:t,workIds:i,floatBarRef:s}=a,{floatBarColors:n,mananger:r,setFloatBarData:c,floatBarData:l}=M.useContext(Ne),[h,u]=M.useState(),[d,p]=M.useState(1);M.useEffect(()=>{if(t!=null&&t.fontBgColor){const[w,v]=(t==null?void 0:t.fontBgColor)==="transparent"&&["transparent",1]||Mo(t.fontBgColor);u(w),p(v)}},[t==null?void 0:t.fontBgColor]);const f=M.useMemo(()=>{if(s!=null&&s.current&&D.isNumber(l==null?void 0:l.y)&&(r!=null&&r.height)){if(s.current.offsetTop&&s.current.offsetTop+l.y>180){const w={};return w.top="inherit",w.bottom=50,w}else if(!s.current.offsetTop&&(r==null?void 0:r.height)-s.current.offsetTop-l.y<120){const w={};return w.top="inherit",w.bottom=50,w}}},[s==null?void 0:s.current,l,r]),y=M.useMemo(()=>h&&h!=="transparent"?M.createElement(wo,{key:"fontBgColor",opacity:d||0,activeColor:h,setCurOpacity:(w,v,S)=>{S===P.Start&&(r!=null&&r.control.room)&&(r.control.room.disableDeviceInputs=!0),S===P.Done&&(r!=null&&r.control.room)&&(r.control.room.disableDeviceInputs=!1),p(w);const N=we(v,w);l!=null&&l.textOpt&&(l.textOpt.fontBgColor=N,c({textOpt:l.textOpt})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:i||[H],fontBgColor:h&&we(v,w),workState:S,viewId:r==null?void 0:r.viewId})}}):null,[h,d,r==null?void 0:r.control.room,r==null?void 0:r.viewId,l==null?void 0:l.textOpt,i]),m=M.useMemo(()=>o?M.createElement("div",{className:"font-colors-menu",style:f,onTouchEnd:w=>{w.stopPropagation(),w.nativeEvent.stopImmediatePropagation()},onClick:w=>{w.cancelable&&w.preventDefault(),w.stopPropagation(),w.nativeEvent.stopImmediatePropagation()}},M.createElement(_s,{activeColor:h,onTouchEndHandler:w=>{w.stopPropagation();const v="transparent";u(v),l!=null&&l.textOpt&&(l.textOpt.fontBgColor=v,c({textOpt:l.textOpt})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:i||[H],workState:P.Done,fontBgColor:v,viewId:r==null?void 0:r.viewId})},onClickHandler:w=>{w.cancelable&&w.preventDefault(),w.stopPropagation();const v="transparent";u(v),l!=null&&l.textOpt&&(l.textOpt.fontBgColor=v,c({textOpt:l.textOpt})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:i||[H],workState:P.Done,fontBgColor:v,viewId:r==null?void 0:r.viewId})}}),n.map((w,v)=>{const S=Bt(...w);return M.createElement(mo,{key:v,color:S,activeColor:h,onTouchEndHandler:N=>{N.stopPropagation(),u(S);const I=we(S,d);l!=null&&l.textOpt&&(l.textOpt.fontBgColor=I,c({textOpt:l.textOpt})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:i||[H],workState:P.Done,fontBgColor:we(S,d),viewId:r==null?void 0:r.viewId})},onClickHandler:N=>{N.cancelable&&N.preventDefault(),N.stopPropagation(),u(S);const I=we(S,d);l!=null&&l.textOpt&&(l.textOpt.fontBgColor=I,c({textOpt:l.textOpt})),ee.emitMethod(q.MainEngine,Y.SetColorNode,{workIds:i||[H],workState:P.Done,fontBgColor:we(S,d),viewId:r==null?void 0:r.viewId})}})}),y):null,[o,n,y,d,h,l==null?void 0:l.textOpt,i,r==null?void 0:r.viewId,f]),T=M.useMemo(()=>{const w=h&&h!=="transparent"&&we(h,d)||"transparent";return M.createElement("div",{className:"color-bar",style:{marginTop:0}},M.createElement("div",{className:"color-bar-color",style:{backgroundColor:w}}))},[h,d]);return M.createElement("div",{className:`button normal-button font-colors-icon ${o&&"active"}`,onTouchEnd:w=>{w.stopPropagation(),w.nativeEvent.stopImmediatePropagation(),e(!o)},onClick:w=>{w.cancelable&&w.preventDefault(),w.stopPropagation(),w.nativeEvent.stopImmediatePropagation(),e(!o)}},M.createElement(dm,null),T,m)},wm=a=>{const{bold:o,setBold:e,workIds:t,viewId:i}=a,s=n=>{const r=o==="bold"?"normal":"bold";n.cancelable&&n.preventDefault(),n==null||n.stopPropagation(),e(r),ee.emitMethod(q.MainEngine,Y.SetFontStyle,{workIds:t,viewId:i,bold:r})};return M.createElement("div",{className:"font-style-button",onClick:s,onTouchEnd:s},M.createElement("img",{alt:"icon",src:xe(o==="bold"?"bold-active":"bold")}))},vm=a=>{const{underline:o,setUnderline:e,workIds:t,viewId:i}=a,s=n=>{const r=!o;n.cancelable&&n.preventDefault(),n==null||n.stopPropagation(),e(r),ee.emitMethod(q.MainEngine,Y.SetFontStyle,{workIds:t,viewId:i,underline:r})};return M.createElement("div",{className:"font-style-button",onClick:s,onTouchEnd:s},M.createElement("img",{alt:"icon",src:xe(o?"underline-active":"underline")}))},Im=a=>{const{lineThrough:o,setLineThrough:e,workIds:t,viewId:i}=a,s=n=>{const r=!o;n.cancelable&&n.preventDefault(),n==null||n.stopPropagation(),e(r),ee.emitMethod(q.MainEngine,Y.SetFontStyle,{workIds:t,viewId:i,lineThrough:r})};return M.createElement("div",{className:"font-style-button",onClick:s,onTouchEnd:s},M.createElement("img",{alt:"icon",src:xe(o?"line-through-active":"line-through")}))},Nm=a=>{const{italic:o,setItalic:e,workIds:t,viewId:i}=a,s=n=>{const r=o==="italic"?"normal":"italic";n.cancelable&&n.preventDefault(),n==null||n.stopPropagation(),e(r),ee.emitMethod(q.MainEngine,Y.SetFontStyle,{workIds:t,viewId:i,italic:r})};return M.createElement("div",{className:"font-style-button",onClick:s,onTouchEnd:s},M.createElement("img",{alt:"icon",src:xe(o==="italic"?"italic-active":"italic")}))},Sm=a=>{const{open:o,setOpen:e,textOpt:t,workIds:i,style:s,floatBarRef:n}=a,{mananger:r,floatBarData:c}=M.useContext(Ne),[l,h]=M.useState("normal"),[u,d]=M.useState("normal"),[p,f]=M.useState(!1),[y,m]=M.useState(!1);M.useEffect(()=>{t!=null&&t.bold&&h(t.bold),D.isBoolean(t==null?void 0:t.underline)&&f(t.underline||!1),D.isBoolean(t==null?void 0:t.lineThrough)&&m(t.lineThrough||!1),t!=null&&t.italic&&d(t.italic)},[t]);const T=M.useMemo(()=>{if(s&&(n!=null&&n.current)&&D.isNumber(c==null?void 0:c.y)&&(r!=null&&r.height)){if(n.current.offsetTop&&n.current.offsetTop+c.y>180){const v={};return v.top="inherit",v.bottom=50,v}else if(!n.current.offsetTop&&(r==null?void 0:r.height)-n.current.offsetTop-c.y<120){const v={};return v.top="inherit",v.bottom=50,v}}},[s,n==null?void 0:n.current,c,r]),w=M.useMemo(()=>o?M.createElement("div",{className:"font-style-menu",style:T,onTouchEnd:v=>{v.stopPropagation(),v.nativeEvent.stopImmediatePropagation()},onClick:v=>{v.cancelable&&v.preventDefault(),v.stopPropagation(),v.nativeEvent.stopImmediatePropagation()}},M.createElement(wm,{workIds:i||[H],bold:l,setBold:h,viewId:r==null?void 0:r.viewId}),M.createElement(vm,{workIds:i||[H],underline:p,setUnderline:f,viewId:r==null?void 0:r.viewId}),M.createElement(Im,{workIds:i||[H],lineThrough:y,setLineThrough:m,viewId:r==null?void 0:r.viewId}),M.createElement(Nm,{workIds:i||[H],italic:u,setItalic:d,viewId:r==null?void 0:r.viewId})):null,[o,i,l,r==null?void 0:r.viewId,p,y,u,T]);return M.createElement("div",{className:`button normal-button ${o&&"active"}`,onTouchEnd:v=>{v.stopPropagation(),v.nativeEvent.stopImmediatePropagation(),e(!o)},onClick:v=>{v.cancelable&&v.preventDefault(),v.stopPropagation(),v.nativeEvent.stopImmediatePropagation(),e(!o)}},M.createElement("img",{alt:"icon",src:xe(o?"font-style-active":"font-style")}),w)},Ye=Object.freeze([12,14,18,24,36,48,64,80,144,288]),gt=["top","topLeft","topRight","bottom","bottomLeft","bottomRight","left","leftTop","leftBottom","right","rightTop","rightBottom"],Tm=a=>{const{style:o,onClickHandler:e}=a;return M.createElement("div",{className:"font-size-menu",style:o,onTouchEnd:t=>{t.stopPropagation(),t.nativeEvent.stopImmediatePropagation()},onClick:t=>{t.cancelable&&t.preventDefault(),t.stopPropagation(),t.nativeEvent.stopImmediatePropagation()}},Ye.map(t=>M.createElement("div",{className:"font-size-btn",key:t,onClick:()=>{e(t)},onTouchEnd:()=>{e(t)}},t)))},km=a=>{const o=M.useRef(null),{open:e,setOpen:t,textOpt:i,workIds:s,floatBarRef:n}=a,{mananger:r,floatBarData:c}=M.useContext(Ne),[l,h]=M.useState(0),[u,d]=M.useState(),p=Ye.length-1;M.useEffect(()=>{i!=null&&i.fontSize&&(h(i.fontSize),o.current&&(o.current.value=i.fontSize.toString()))},[i==null?void 0:i.fontSize]);const f=M.useMemo(()=>{if(n!=null&&n.current&&D.isNumber(c==null?void 0:c.y)&&(r!=null&&r.height)){if(n.current.offsetTop&&n.current.offsetTop+c.y>180){const v={};return v.top="inherit",v.bottom=35,v}else if(!n.current.offsetTop&&(r==null?void 0:r.height)-n.current.offsetTop-c.y<120){const v={};return v.top="inherit",v.bottom=35,v}}},[n==null?void 0:n.current,c,r]);function y(v){h(v),v&&v>=Ye[0]&&v<=Ye[p]&&ee.emitMethod(q.MainEngine,Y.SetFontStyle,{workIds:s||[H],fontSize:v,viewId:r==null?void 0:r.viewId})}const m=v=>{var S;(S=o.current)==null||S.blur(),t(!1),w(v)},T=M.useMemo(()=>e?M.createElement(Tm,{onClickHandler:m,style:f}):null,[e,m,f]),w=v=>{v>Ye[p]&&(v=Ye[p]),v<Ye[0]&&(v=Ye[0]),y(v)};return M.useEffect(()=>()=>{r!=null&&r.control.room&&D.isBoolean(u)&&(r.control.room.disableDeviceInputs=u)},[r,u]),M.createElement("div",{className:"button normal-button font-size-barBtn",style:{width:50},onTouchEnd:v=>{v.stopPropagation(),v.nativeEvent.stopImmediatePropagation()},onClick:v=>{v.cancelable&&v.preventDefault(),v.stopPropagation(),v.nativeEvent.stopImmediatePropagation()}},M.createElement("input",{className:"font-size-input",ref:o,onTouchEnd:()=>{o.current&&o.current.focus()},onClick:()=>{t(!e),o.current&&o.current.focus()},onKeyDown:v=>{if(v.key==="Backspace"){const S=window.getSelection(),N=S==null?void 0:S.getRangeAt(0);if(N!=null&&N.collapsed)return v.cancelable&&v.preventDefault(),document.execCommand("delete",!1),!1}return!1},onKeyUp:v=>{var S;if(o.current){const N=o.current.value,I=parseInt(N);isNaN(I)?o.current.value="0":o.current.value=I.toString(),I&&v.key==="Enter"&&(w(I),(S=o.current)==null||S.blur(),t(!1))}},onFocus:()=>{r!=null&&r.control.room&&!r.control.room.disableDeviceInputs&&(d(r.control.room.disableDeviceInputs),r.control.room.disableDeviceInputs=!0)},onBlur:()=>{r!=null&&r.control.room&&D.isBoolean(u)&&(r.control.room.disableDeviceInputs=u)}}),M.createElement("div",{className:"font-size-btns"},M.createElement("div",{className:"font-size-add",onClick:()=>{w(l+Ye[0])},onTouchEnd:()=>{w(l+Ye[0])}}),M.createElement("div",{className:"font-size-cut",onClick:()=>{w(l-Ye[0])},onTouchEnd:()=>{w(l-Ye[0])}})),T)},Cm=a=>{const{workIds:o,mananger:e,islocked:t}=a;return M.createElement("div",{className:"button normal-button",onClick:i=>{i.cancelable&&i.preventDefault(),i.stopPropagation(),ee.emitMethod(q.MainEngine,Y.SetLock,{workIds:o||[H],isLocked:!t,viewId:e==null?void 0:e.viewId})},onTouchEnd:i=>{i.stopPropagation(),ee.emitMethod(q.MainEngine,Y.SetLock,{workIds:o||[H],isLocked:!t,viewId:e==null?void 0:e.viewId})}},M.createElement("img",{alt:"icon",src:xe(t?"unlock-new":"lock-new")}))},Eo=a=>{const{icon:o,min:e,max:t,step:i,value:s,onInputHandler:n}=a,[r,c]=M.useState(0),l=M.useRef(null),h=u=>{u>t&&(u=t),u<e&&(u=e),c(u),n(u),l.current&&(l.current.value=u.toString())};return M.useEffect(()=>{s&&(c(s),l.current&&(l.current.value=s.toString()))},[s]),M.createElement("div",{className:"button input-button",onTouchEnd:u=>{u.stopPropagation(),u.nativeEvent.stopImmediatePropagation()},onClick:u=>{u.cancelable&&u.preventDefault(),u.stopPropagation(),u.nativeEvent.stopImmediatePropagation()}},M.createElement("img",{src:xe(o)}),M.createElement("input",{className:"input-number",type:"text",ref:l,onTouchEnd:()=>{l.current&&l.current.focus()},onClick:()=>{l.current&&l.current.focus()},onKeyDown:u=>{if(u.key==="Backspace"){const d=window.getSelection(),p=d==null?void 0:d.getRangeAt(0);if(p!=null&&p.collapsed)return u.cancelable&&u.preventDefault(),document.execCommand("delete",!1),!1}},onKeyUp:()=>{if(l.current){const u=l.current.value,d=parseInt(u);isNaN(d)?l.current.value="0":l.current.value=d.toString()}},onChange:u=>{const d=u.target.value,p=parseInt(d);p&&p&&p>=e&&p<=t&&h(p)}}),M.createElement("div",{className:"input-number-btns"},M.createElement("div",{className:"input-number-add",onClick:()=>{h(r+i)},onTouchEnd:()=>{h(r+i)}}),M.createElement("div",{className:"input-number-cut",onClick:()=>{h(r-i)},onTouchEnd:()=>{h(r-i)}})))},bm=a=>{const{icon:o,min:e,max:t,step:i,value:s,onInputHandler:n}=a;return M.createElement("div",{className:"button input-button"},M.createElement("img",{src:xe(o)}),M.createElement(xm,{min:e,max:t,step:i,value:s,onInputHandler:n}))},xm=a=>{const{value:o,min:e,max:t,onInputHandler:i}=a,[s,n]=M.useState({x:0,y:0});M.useEffect(()=>{n({x:o*100,y:0})},[]);const r=D.throttle((h,u)=>{h.cancelable&&h.preventDefault(),h.stopPropagation();let d=Math.floor(Math.max(u.x,e*100));d=Math.floor(Math.min(d,t*100)),u.x!==(s==null?void 0:s.x)&&n({x:d,y:0});const p=d/100;o!==p&&i(p)},100,{leading:!1}),c=h=>{h.cancelable&&h.preventDefault(),h.stopPropagation()},l=D.throttle((h,u)=>{h.cancelable&&h.preventDefault(),h.stopPropagation();let d=Math.floor(Math.max(u.x,e*100));d=Math.floor(Math.min(d,t*100)),u.x!==(s==null?void 0:s.x)&&n({x:d,y:0});const p=d/100;o!==p&&i(p)},100,{leading:!1});return M.createElement("div",{className:"range-number-container",onClick:h=>{const u=h.nativeEvent.offsetX-6;let d=Math.floor(Math.max(u,e*100));d=Math.floor(Math.min(d,t*100)),n({x:d,y:0});const p=d/100;o!==p&&i(p)}},M.createElement("div",{className:"range-number-color"}),M.createElement("div",{className:"range-number"},M.createElement(Nt,{bounds:"parent",axis:"x",position:s,onDrag:r,onStart:c,onStop:l},M.createElement("div",{className:"circle",onClick:c}))))},Lm=a=>{const{icon:o,value:e,onChangeHandler:t,style:i}=a,[s,n]=M.useState(0),[r,c]=M.useState(),l=M.useRef(null),h=M.useCallback(p=>{p>=gt.length&&(p=0),p<0&&(p=gt.length-1),n(p),t(gt[p]),c(!1),l.current&&(l.current.value=gt[p])},[t]),u=M.useMemo(()=>{if(i&&i.bottom){const p={};return p.top="inherit",p.bottom=50,p}},[i]);M.useEffect(()=>{e&&(n(gt.indexOf(e)),l.current&&(l.current.value=e))},[e]);const d=M.useMemo(()=>r?M.createElement(zm,{options:gt,onClickHandler:h,style:u}):null,[r,h,u]);return M.createElement("div",{className:"button input-button"},M.createElement("img",{src:xe(o)}),M.createElement("input",{readOnly:!0,className:"input-number",type:"text",ref:l,onTouchEnd:p=>{p.cancelable&&p.preventDefault(),p.stopPropagation(),l.current&&l.current.focus()},onClick:p=>{p.cancelable&&p.preventDefault(),p.stopPropagation(),l.current&&(l.current.focus(),c(!r))}}),M.createElement("div",{className:"input-number-btns"},M.createElement("div",{className:"input-number-add",onClick:p=>{p.cancelable&&p.preventDefault(),p.stopPropagation(),h(s+1)},onTouchEnd:p=>{p.cancelable&&p.preventDefault(),p.stopPropagation(),h(s+1)}}),M.createElement("div",{className:"input-number-cut",onClick:p=>{p.cancelable&&p.preventDefault(),p.stopPropagation(),h(s-1)},onTouchEnd:p=>{p.cancelable&&p.preventDefault(),p.stopPropagation(),h(s-1)}})),d)},zm=a=>{const{options:o,style:e,onClickHandler:t}=a;return M.createElement("div",{className:"select-option-menu",style:e,onTouchEnd:i=>{i.cancelable&&i.preventDefault(),i.stopPropagation(),i.nativeEvent.stopImmediatePropagation()},onClick:i=>{i.cancelable&&i.preventDefault(),i.stopPropagation(),i.nativeEvent.stopImmediatePropagation()}},o.map((i,s)=>M.createElement("div",{className:"select-option-btn",key:i,onClick:n=>{n.cancelable&&n.preventDefault(),n.stopPropagation(),t(s)},onTouchEnd:n=>{n.cancelable&&n.preventDefault(),n.stopPropagation(),t(s)}},i)))},Pm=a=>{const{mananger:o,innerRatio:e,innerVerticeStep:t,vertices:i}=a,s=c=>{ee.emitMethod(q.MainEngine,Y.SetShapeOpt,{workIds:[H],toolsType:k.Star,viewId:o.viewId,vertices:c})},n=c=>{ee.emitMethod(q.MainEngine,Y.SetShapeOpt,{workIds:[H],toolsType:k.Star,viewId:o.viewId,innerVerticeStep:c})},r=c=>{ee.emitMethod(q.MainEngine,Y.SetShapeOpt,{workIds:[H],toolsType:k.Star,viewId:o.viewId,innerRatio:c})};return M.createElement(M.Fragment,null,M.createElement(Eo,{value:i,icon:"polygon-vertex",min:3,max:100,step:1,onInputHandler:s}),M.createElement(Eo,{value:t,icon:"star-innerVertex",min:1,max:100,step:1,onInputHandler:n}),M.createElement(bm,{value:e,icon:"star-innerRatio",min:.1,max:1,step:.1,onInputHandler:r}))},Dm=a=>{const{mananger:o,vertices:e}=a,t=i=>{ee.emitMethod(q.MainEngine,Y.SetShapeOpt,{workIds:[H],toolsType:k.Polygon,viewId:o.viewId,vertices:i})};return M.createElement(Eo,{value:e,icon:"polygon-vertex",min:3,max:100,step:1,onInputHandler:t})},Am=a=>{const{mananger:o,placement:e}=a,t=i=>{ee.emitMethod(q.MainEngine,Y.SetShapeOpt,{workIds:[H],toolsType:k.SpeechBalloon,viewId:o.viewId,placement:i})};return M.createElement(Lm,{value:e,icon:"speechBallon-placement",onChangeHandler:t})},ko=a=>{const{icon:o,isActive:e,onClickHandler:t,onTouchEndHandler:i}=a;return M.createElement("div",{className:`button tab-button ${e?"active":""}`,onClick:t,onTouchEnd:i},M.createElement("img",{src:xe(o)}))},jm=a=>{const{toolsTypes:o,style:e,mananger:t,shapeOpt:i}=a,[s,n]=M.useState();M.useEffect(()=>{o.includes(k.Polygon)?n(k.Polygon):o.includes(k.Star)?n(k.Star):n(k.SpeechBalloon)},[o]);const r=(u,d)=>{d.cancelable&&d.preventDefault(),d==null||d.stopPropagation(),n(u)},c=M.useMemo(()=>s===k.Polygon&&t&&i.vertices?M.createElement(Dm,{vertices:i.vertices,mananger:t}):null,[t,s,i]),l=M.useMemo(()=>s===k.Star&&t&&i.vertices&&i.innerVerticeStep&&i.innerRatio?M.createElement(Pm,{mananger:t,vertices:i.vertices,innerVerticeStep:i.innerVerticeStep,innerRatio:i.innerRatio}):null,[t,s,i]),h=M.useMemo(()=>s===k.SpeechBalloon&&t&&i.placement?M.createElement(Am,{mananger:t,placement:i.placement}):null,[t,s,i]);return M.createElement("div",{className:"shapeOpt-sub-menu",style:e,onClick:u=>{u.stopPropagation(),u.nativeEvent.stopImmediatePropagation(),u.cancelable&&u.preventDefault()}},M.createElement("div",{className:"shapeOpt-sub-menu-tabs"},o.includes(k.Polygon)&&M.createElement(ko,{isActive:s===k.Polygon,icon:s===k.Polygon?"polygon-active":"polygon",onClickHandler:r.bind(void 0,k.Polygon),onTouchEndHandler:r.bind(void 0,k.Polygon)})||null,o.includes(k.Star)&&M.createElement(ko,{isActive:s===k.Star,icon:s===k.Star?"star-active":"star",onClickHandler:r.bind(void 0,k.Star),onTouchEndHandler:r.bind(void 0,k.Star)})||null,o.includes(k.SpeechBalloon)&&M.createElement(ko,{isActive:s===k.SpeechBalloon,icon:s===k.SpeechBalloon?"speechBallon-active":"speechBallon",onClickHandler:r.bind(void 0,k.SpeechBalloon),onTouchEndHandler:r.bind(void 0,k.SpeechBalloon)})||null),M.createElement("div",{className:"shapeOpt-sub-menu-content"},c,l,h))},Em=a=>{const{open:o,setOpen:e,floatBarRef:t,toolsTypes:i,shapeOpt:s}=a,{floatBarData:n,mananger:r}=M.useContext(Ne),[c,l]=M.useState([]),[h,u]=M.useState(),d=M.useMemo(()=>{if(t!=null&&t.current&&D.isNumber(n==null?void 0:n.x)&&D.isNumber(n==null?void 0:n.y)&&(r!=null&&r.height)){if(t.current.offsetTop&&t.current.offsetTop+n.y>200){const m={};return m.top="inherit",m.bottom=50,m}else if(!t.current.offsetTop&&(r==null?void 0:r.height)-t.current.offsetTop-(n==null?void 0:n.y)<140){const m={};return m.top="inherit",m.bottom=50,m}}},[t,n==null?void 0:n.x,n==null?void 0:n.y,r==null?void 0:r.height]),p=M.useMemo(()=>o&&i&&r&&s?(r.control.room&&!r.control.room.disableDeviceInputs&&(u(r.control.room.disableDeviceInputs),r.control.room.disableDeviceInputs=!0),M.createElement(jm,{shapeOpt:s,style:d,toolsTypes:i,mananger:r})):(r!=null&&r.control.room&&D.isBoolean(h)&&(r.control.room.disableDeviceInputs=h),null),[o,d,i,r,s]),f=m=>{m.cancelable&&m.preventDefault(),m.stopPropagation(),m.nativeEvent.stopImmediatePropagation(),e(!o)},y=m=>{m.stopPropagation(),m.nativeEvent.stopImmediatePropagation(),e(!o)};return M.useEffect(()=>{D.isEqual(n==null?void 0:n.selectIds,c)||n!=null&&n.selectIds&&!D.isEqual(n==null?void 0:n.selectIds,c)&&(l(n==null?void 0:n.selectIds),e(!1))},[o,n,c,e]),M.useEffect(()=>()=>{o&&r!=null&&r.control.room&&D.isBoolean(h)&&(r.control.room.disableDeviceInputs=h)},[o,r,h]),M.createElement("div",{className:`button normal-button ${o&&"active"}`,onClick:f,onTouchEnd:y},p,M.createElement("img",{alt:"icon",src:xe(o?"shapes-active":"shapes")}))},en=M.memo(a=>{const{textOpt:o,workIds:e,noLayer:t,position:i}=a,{floatBarData:s,mananger:n}=M.useContext(Ne),[r,c]=M.useState(0),[l,h]=M.useState(),u=M.useRef(null);M.useEffect(()=>{var L,j,E,A;const N={},I=(s==null?void 0:s.w)||((L=o==null?void 0:o.boxSize)==null?void 0:L[0])||0,b=(s==null?void 0:s.h)||((j=o==null?void 0:o.boxSize)==null?void 0:j[1])||0;if(i&&I&&b&&(n!=null&&n.width)&&(n!=null&&n.height)){if(i.y<60?i.y+b<n.height-60?N.bottom=-120:i.y+b<n.height?N.bottom=-58:i.y>0?N.top=62:N.top=-i.y+62:N.top=0,i.x<0)N.left=-i.x+3;else if(i.x+(((E=u.current)==null?void 0:E.offsetWidth)||I)>n.width){const W=n.width-(((A=u.current)==null?void 0:A.offsetWidth)||I)-i.x;N.left=W}h(N);return}h(void 0)},[u,i,s==null?void 0:s.w,s==null?void 0:s.h,n==null?void 0:n.width,n==null?void 0:n.height,o==null?void 0:o.boxSize]);const d=M.useMemo(()=>s!=null&&s.fillColor?M.createElement(ym,{floatBarRef:u,open:r===3,setOpen:N=>{c(N===!0?3:0)}}):null,[s==null?void 0:s.fillColor,r,u]),p=M.useMemo(()=>s!=null&&s.strokeColor?M.createElement(gm,{floatBarRef:u,open:r===2,setOpen:N=>{c(N===!0?2:0)}}):null,[s==null?void 0:s.strokeColor,r,u]),f=M.useMemo(()=>o!=null&&o.fontColor&&(n!=null&&n.viewId)?M.createElement(Mm,{floatBarRef:u,open:r===4,setOpen:N=>{c(N===!0?4:0)},textOpt:o,workIds:e}):null,[o,r,e,n,u]),y=M.useMemo(()=>o!=null&&o.fontBgColor&&(n!=null&&n.viewId)?M.createElement(mm,{floatBarRef:u,open:r===5,setOpen:N=>{c(N===!0?5:0)},textOpt:o,workIds:e}):null,[o,r,e,n,u]),m=M.useMemo(()=>o&&(n!=null&&n.viewId)?M.createElement(Sm,{floatBarRef:u,open:r===6,setOpen:N=>{c(N===!0?6:0)},textOpt:o,workIds:e,style:l}):null,[o,r,e,n,l,u]),T=M.useMemo(()=>o&&(n!=null&&n.viewId)?M.createElement(km,{open:r===7,setOpen:N=>{c(N===!0?7:0)},textOpt:o,workIds:e,floatBarRef:u}):null,[o,r,e,n,u]),w=M.useMemo(()=>t?null:M.createElement(um,{open:r===1,setOpen:N=>{c(N===!0?1:0)},floatBarRef:u}),[t,r,u]),v=M.useMemo(()=>s!=null&&s.canLock&&n?M.createElement(Cm,{workIds:e,mananger:n,islocked:s.isLocked}):null,[s,n,e]),S=M.useMemo(()=>n&&(n!=null&&n.viewId)&&l&&(s!=null&&s.shapeOpt)&&(s!=null&&s.toolsTypes)?M.createElement(Em,{open:r===8,setOpen:N=>{c(N===!0?8:0)},floatBarRef:u,workIds:e,toolsTypes:s.toolsTypes,shapeOpt:s.shapeOpt}):null,[s,n,r,l,e,u]);return M.createElement("div",{className:"appliance-plugin-floatbtns",style:l,ref:u,onMouseOver:N=>(N.stopPropagation(),N.cancelable&&N.preventDefault(),n==null||n.control.worker.blurCursor(n.viewId),!1),onMouseMove:N=>(N.stopPropagation(),N.cancelable&&N.preventDefault(),!1)},n&&M.createElement(lm,{workIds:e,mananger:n}),w,v,!!(n!=null&&n.viewId)&&M.createElement(hm,{workIds:e,viewId:n.viewId}),S,T,m,f,y,p,d)}),Om=a=>{const{data:o,isActive:e,manager:t,workId:i}=a,{opt:s,scale:n,translate:r,x:c,y:l}=o,h=`scale(${n||1}) ${r&&"translate("+r[0]+"px,"+r[1]+"px)"||""}`,{fontSize:u,fontFamily:d,underline:p,fontColor:f,lineThrough:y,textAlign:m,strokeColor:T,lineHeight:w,bold:v,italic:S,uid:N,workState:I}=s,b=u,L=w||b*1.2,j={fontSize:`${b}px`,lineHeight:`${L}px`,color:f,borderColor:T,minHeight:`${L}px`,paddingRight:`${S==="italic"?Math.round(b*.3):5}px`};d&&(j.fontFamily=`${d}`),(y||p)&&(j.textDecoration=`${y&&"line-through"||""}${p&&" underline"||""}`),v&&(j.fontWeight=`${v}`),S&&(j.fontStyle=`${S}`),m&&(j.textAlign=`${m}`);function E(){var W;e&&(N&&N===((W=t.control.collector)==null?void 0:W.uid)||!N)&&t.control.textEditorManager.active(i)}const A=M.useMemo(()=>{const W=[];if(s.text){const z=it(s.text);for(let O=0;O<z.length;O++){const ne=z[O];ne===""?W.push(M.createElement("div",{style:{backgroundColor:s.fontBgColor},key:O},M.createElement("br",null))):W.push(M.createElement("div",{style:{backgroundColor:s.fontBgColor},key:O},ne))}}return W.length?W:null},[s.fontBgColor,s.text]);return M.createElement("div",{className:"editor-box",style:{left:`${c}px`,top:`${l}px`,transform:h,transformOrigin:"left top",pointerEvents:"none",opacity:I===P.Done?0:1}},M.createElement("div",{className:`editor ${e?"":"readOnly"}`,style:j,onClick:E},A))},Rm=M.memo(a=>{const{data:o,left:e,top:t,workId:i,updateOptInfo:s}=a,{opt:n,scale:r,translate:c}=o,l=M.useRef(null);M.useEffect(()=>{var j,E;if((j=l.current)!=null&&j.offsetWidth&&((E=l.current)!=null&&E.offsetHeight)){const A=n.boxSize;if((A==null?void 0:A[0])!==l.current.offsetWidth||A[1]!==l.current.offsetHeight||!A){const W=[l.current.offsetWidth,l.current.offsetHeight];s({activeTextId:i,update:{boxSize:W,workState:P.Done}})}}},[n.fontSize,n.italic,n.bold,n.boxSize,i]);const h=`scale(${r||1}) ${c&&"translate("+c[0]+"px,"+c[1]+"px)"||""}`,{fontSize:u,fontFamily:d,underline:p,fontColor:f,lineThrough:y,textAlign:m,strokeColor:T,lineHeight:w,bold:v,italic:S}=n,N=u,I=w||N*1.2,b={fontSize:`${N}px`,lineHeight:`${I}px`,color:f,borderColor:T,minHeight:`${I}px`,pointerEvents:"none",paddingRight:`${S==="italic"?Math.round(N*.3):5}px`};d&&(b.fontFamily=`${d}`),(y||p)&&(b.textDecoration=`${y&&"line-through"||""}${p&&" underline"||""}`),m&&(b.textAlign=`${m}`),v&&(b.fontWeight=`${v}`),S&&(b.fontStyle=`${S}`);const L=M.useMemo(()=>{const j=[];if(n.text){const E=it(n.text);for(let A=0;A<E.length;A++){const W=E[A];W===""?j.push(M.createElement("div",{key:A},M.createElement("br",null))):j.push(M.createElement("div",{key:A},W))}}return j.length?j:null},[n.text]);return M.createElement("div",{className:"editor-box",style:{left:`${e}`,top:`${t}`,transform:h,transformOrigin:"left top",zIndex:1,pointerEvents:"none",opacity:0}},M.createElement("div",{className:"editor readOnly",ref:l,style:b},L))},(a,o)=>!(a.workId!==o.workId||a.left!==o.left||a.top!==o.top||!D.isEqual(a.data,o.data))),Ym=a=>{const{data:o,workId:e,isSelect:t,showFloatBtns:i,handleKeyUp:s,handleFocus:n,updateOptInfo:r,manager:c,runAnimation:l}=a,[h,u]=M.useState(),{opt:d,scale:p,translate:f,x:y,y:m}=o,{fontSize:T,fontFamily:w,underline:v,fontColor:S,lineThrough:N,textAlign:I,strokeColor:b,lineHeight:L,bold:j,italic:E,boxSize:A}=d,W=M.useRef(null),z=M.useMemo(()=>{const ie=T,le=L||ie*1.2,J={fontSize:`${ie}px`,lineHeight:`${le}px`,color:S,borderColor:b,minHeight:`${le}px`,paddingRight:`${E==="italic"?Math.round(ie*.3):5}px`,borderWidth:`${Math.max(Math.round(1/(p||1)),1)}px`};return w&&(J.fontFamily=`${w}`),(N||v)&&(J.textDecoration=`${N&&"line-through"||""} ${v&&" underline"||""}`),I&&(J.textAlign=`${I}`),j&&(J.fontWeight=`${j}`),E&&(J.fontStyle=`${E}`),J},[j,S,w,T,E,L,N,p,b,I,v]),O=M.useMemo(()=>{const ie=`scale(${p||1}) ${f&&"translate("+f[0]+"px,"+f[1]+"px)"||""}`;return{left:`${y}px`,top:`${m}px`,zIndex:2,pointerEvents:"none",transform:ie,transformOrigin:"left top"}},[p,f,y,m]),ne=M.useMemo(()=>{var ie,le;return!t&&p&&i&&D.isNumber(y)&&D.isNumber(m)&&d.boxSize&&D.isNumber((ie=d.boxSize)==null?void 0:ie[0])&&D.isNumber((le=d.boxSize)==null?void 0:le[1])?M.createElement("div",{className:ze.FloatBarBtn,style:{left:y,top:m,width:d.boxSize[0]*p,height:d.boxSize[1]*p}},M.createElement(en,{position:{x:y,y:m},textOpt:d,workIds:[e],noLayer:!0})):null},[t,d,i,e,y,m,p]),te=M.useMemo(()=>{let ie="";if(d.text){const le=it(d.text);for(let J=0;J<le.length;J++){const $=le[J];$===""?ie=ie+"<div><br/></div>":ie=ie+`<div style="background-color:${d.fontBgColor}">${$}</div>`}}else ie=`<div style="background-color:${d.fontBgColor}"></div>`;return ie},[d.fontBgColor,d.text]),Q=M.useMemo(()=>typeof te=="string"?M.createElement("div",{id:e,suppressContentEditableWarning:!0,contentEditable:!0,className:"editor",ref:W,style:z,onKeyDown:G,onKeyUp:s,onClick:X,onTouchEnd:X,onFocus:n,onPaste:ce,onInput:Te,dangerouslySetInnerHTML:{__html:te}}):null,[te,z,e]);M.useEffect(()=>{Q&&W.current&&(W.current.click(),setTimeout(()=>{var ie;if(W.current){const le=window==null?void 0:window.getSelection(),J=W.current.lastChild;if(le&&J){const $=document.createRange(),ue=((ie=J.textContent)==null?void 0:ie.length)||0;(J==null?void 0:J.nodeName)==="#text"?$.setStart(J,ue):$.setStart(J,ue&&1||0),$.collapse(!0),le.removeAllRanges(),le.addRange($)}}},yo))},[Q,W.current]),M.useEffect(()=>{var ie,le,J,$;if(Q&&((ie=W.current)!=null&&ie.offsetWidth||(le=W.current)!=null&&le.offsetHeight||(J=W.current)!=null&&J.offsetLeft||($=W.current)!=null&&$.offsetTop)){const ue=[W.current.offsetWidth,W.current.offsetHeight];(A&&A[0]!==ue[0]&&A[1]!==ue[1]||!A)&&r({activeTextId:e,update:{boxSize:ue,workState:P.Doing}})}},[A,Q,z,e]);function X(){W.current&&W.current.focus(),l()}function G(ie){if(ie.key==="Backspace"){const le=window.getSelection(),J=le==null?void 0:le.getRangeAt(0);if(J!=null&&J.collapsed)return ie.cancelable&&ie.preventDefault(),document.execCommand("delete",!1),!1}return l(),!1}function Z(ie,le){const J=window==null?void 0:window.getSelection();if(J!=null&&J.rangeCount&&ie&&J&&J.anchorNode){const $=J.anchorOffset,ue=J.anchorNode.textContent||"",fe=ue.slice(0,$)||"",je=ue.slice($)||"",ve=fe.concat(ie)||"";K(ve,je,le)}}function K(ie,le,J){const $=window==null?void 0:window.getSelection();if(!($!=null&&$.rangeCount)||!$.anchorNode)return;const ue=ie.split(/\n/);let fe=$.anchorNode.parentNode;fe===J&&(fe=$.anchorNode);const je=[...J.childNodes],ve=[];let me,st=$.anchorOffset;for(;je.length;){const ke=je.pop();if(ke){if(ke===fe){let Ve=ue[0];ue.length===1&&(st=ue[0].length,Ve=ue[0].concat(le)),fe.nodeName==="#text"?(fe.textContent=Ve,me=fe):fe.nodeName==="DIV"&&(fe.innerText=Ve,me=fe.childNodes[0]);break}ve.push(ke),J.removeChild(ke)}}if(ue.length>1)for(let ke=1;ke<ue.length;ke++){let Ve=ue[ke];const Lt=document.createElement("div");d.fontBgColor&&(Lt.style.backgroundColor=d.fontBgColor),ke===ue.length-1&&(st=Ve.length,Ve=Ve.concat(le)),Ve===""?Lt.innerHTML="<br/>":Lt.innerText=Ve,J.appendChild(Lt),ke===ue.length-1&&(me=Lt.childNodes[0])}if(ve.length){ve.reverse();for(const ke of ve)J.appendChild(ke)}if(me&&me.nodeName==="#text"){$.deleteFromDocument();const ke=document.createRange(),Ve=Math.min(st,(me==null?void 0:me.length)||0);ke.setStart(me,Ve),ke.collapse(!0),$.removeAllRanges(),$.addRange(ke)}}function ce(ie){if(ie.cancelable&&ie.preventDefault(),ie.stopPropagation(),W.current){const le=(ie.clipboardData||window.clipboardData).getData("text"),J=window==null?void 0:window.getSelection();if(!(J!=null&&J.rangeCount))return;le&&J&&J.anchorNode&&Z(le,W.current),l()}}function Te(ie){s(ie),l()}return M.createElement(M.Fragment,null,ne,M.createElement("div",{className:"editor-box",style:O,onFocus:()=>{c.control.room&&!c.control.room.disableDeviceInputs&&(u(c.control.room.disableDeviceInputs),c.control.room.disableDeviceInputs=!0)},onBlur:()=>{c!=null&&c.control.room&&D.isBoolean(h)&&(c.control.room.disableDeviceInputs=h)}},Q))};class tn extends M.Component{constructor(o){super(o)}getInnerText(o){const e=[];for(let t=0;t<o.childNodes.length;t++){const i=o.childNodes[t];if(i.nodeName==="#text"&&t===0){const s=i.textContent.split(/\n/),n=s.pop();e.push(...s),n&&e.push(n)}else if(i.nodeName==="DIV"){const s=i.innerText.split(/\n/);if(s.length===2&&s[0]===""&&s[1]==="")e.push("");else{const n=s.shift();n&&e.push(n);const r=s.pop();e.push(...s),r&&e.push(r)}}}return e}updateOptInfo(o){var n,r;const{activeTextId:e,update:t,syncData:i}=o,s=e&&D.cloneDeep(((n=this.props.manager.control.textEditorManager)==null?void 0:n.get(e))||((r=this.props.editors)==null?void 0:r.get(e)));s&&s.opt&&(s.opt={...s.opt,...t},i&&(s.canSync=Object.keys(i).includes("canSync")&&i.canSync||s.canSync,s.canWorker=Object.keys(i).includes("canWorker")&&i.canWorker||s.canWorker),this.props.manager.control.textEditorManager.updateForViewEdited(e,s))}get editorUI(){var o;if((o=this.props.editors)!=null&&o.size){const e=[];return this.props.editors.forEach((t,i)=>{if(this.props.selectIds.includes(i)&&!(this.props.activeTextId==i)&&this.props.box){const{x:n,y:r}=this.props.box,{x:c,y:l}=t,h=`${c-n}px`,u=`${l-r}px`,d=M.createElement(Rm,{left:h,top:u,key:i,data:t,workId:i,isSelect:!0,updateOptInfo:this.updateOptInfo.bind(this),manager:this.props.manager});e.push(d)}}),e}return null}render(){return M.createElement(M.Fragment,null,this.editorUI)}}class Wm extends tn{constructor(e){super(e);g(this,"ref");g(this,"isRunAnimation");this.ref=M.createRef(),this.isRunAnimation=void 0}runAnimation(){this.isRunAnimation||(this.isRunAnimation=requestAnimationFrame(()=>{var e,t;(e=this.ref)!=null&&e.current&&((t=this.ref)==null||t.current.scrollTo({left:0,behavior:"instant"})),this.isRunAnimation=void 0}))}handleKeyUp(e){const t=this.getInnerText(e.nativeEvent.target),i=this.props.activeTextId;if(i){const s=this.props.manager.control.textEditorManager.get(i),n=Re(t),r=P.Doing,c=[e.nativeEvent.target.offsetWidth,e.nativeEvent.target.offsetHeight];(!s||s&&(s.opt.text!==n||!D.isEqual(s.opt.boxSize,c)||!D.isEqual(s.opt.workState,r)))&&this.updateOptInfo({activeTextId:i,update:{text:n,boxSize:c,workState:r},syncData:{canSync:!0,canWorker:!0}})}}handleFocus(e){const t=this.props.activeTextId;if(t){const i=this.props.manager.control.textEditorManager.get(t),s=P.Doing,n=[e.nativeEvent.target.offsetWidth,e.nativeEvent.target.offsetHeight];(!i||i&&(!D.isEqual(i.opt.boxSize,n)||!D.isEqual(i.opt.workState,s)))&&this.updateOptInfo({activeTextId:t,update:{boxSize:n,workState:s},syncData:{canSync:!0,canWorker:!0}})}}get editorUI(){var e;if((e=this.props.editors)!=null&&e.size){const t=[];return this.props.editors.forEach((i,s)=>{if(!(this.props.selectIds.includes(s)&&this.props.activeTextId!==s)){const c=this.props.activeTextId==s?M.createElement(Ym,{key:s,data:i,workId:s,showFloatBtns:this.props.showFloatBtns||!1,handleFocus:this.handleFocus.bind(this),handleKeyUp:this.handleKeyUp.bind(this),updateOptInfo:this.updateOptInfo.bind(this),manager:this.props.manager,runAnimation:this.runAnimation.bind(this)}):M.createElement(Om,{manager:this.props.manager,isActive:i.opt.workState===P.Doing||i.opt.workState===P.Start||!1,key:s,data:i,workId:s});t.push(c)}}),t}return null}render(){return M.createElement("div",{className:`${this.props.className}`,ref:this.ref},this.editorUI)}}const Um=()=>{const{floatBarData:a}=M.useContext(Ne);return M.createElement("div",{className:"appliance-plugin-hightlight-box",style:{borderColor:a==null?void 0:a.selectorColor}},M.createElement("div",{className:"point LT nwse-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}),M.createElement("div",{className:"point LC ew-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}),M.createElement("div",{className:"point LB nesw-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}),M.createElement("div",{className:"point TC ns-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}),M.createElement("div",{className:"point RT nesw-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}),M.createElement("div",{className:"point RC ew-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}),M.createElement("div",{className:"point RB nwse-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}),M.createElement("div",{className:"point BC ns-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}))},Bm=()=>{const{floatBarData:a,mananger:o}=M.useContext(Ne),[e,t]=M.useState(),[i,s]=M.useState();M.useEffect(()=>{const c=[];if(o&&D.isNumber(a==null?void 0:a.x)&&D.isNumber(a==null?void 0:a.y)&&(a!=null&&a.points)){const l=o.viewId;if(o.control.viewContainerManager.getView(l))for(const u of a.points){const d=o.control.viewContainerManager.transformToOriginPoint(u,l);c.push(d)}c[0]&&t({x:c[0][0]-((a==null?void 0:a.x)||0),y:c[0][1]-((a==null?void 0:a.y)||0)}),c[1]&&s({x:c[1][0]-((a==null?void 0:a.x)||0),y:c[1][1]-((a==null?void 0:a.y)||0)})}},[o,a==null?void 0:a.points,a==null?void 0:a.x,a==null?void 0:a.y]);const n=M.useMemo(()=>e?M.createElement("div",{className:"point point-dot",style:{borderColor:a==null?void 0:a.selectorColor,left:e.x,top:e.y}}):null,[a==null?void 0:a.selectorColor,e]),r=M.useMemo(()=>i?M.createElement("div",{className:"point point-dot",style:{borderColor:a==null?void 0:a.selectorColor,left:i.x,top:i.y}}):null,[i,a==null?void 0:a.selectorColor]);return M.createElement("div",{className:"appliance-plugin-hightlight-box",style:{borderColor:a==null?void 0:a.selectorColor}},n,r)},Fm=()=>{const{floatBarData:a}=M.useContext(Ne);return M.createElement("div",{className:"appliance-plugin-hightlight-box",style:{borderColor:a==null?void 0:a.selectorColor}},M.createElement("div",{className:"point LT nwse-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}),M.createElement("div",{className:"point LB nesw-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}),M.createElement("div",{className:"point RT nesw-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}),M.createElement("div",{className:"point RB nwse-resize",style:{backgroundColor:a==null?void 0:a.selectorColor}}))},Vm=()=>{const{floatBarData:a}=M.useContext(Ne);return M.createElement("div",{className:"appliance-plugin-hightlight-box",style:{borderColor:a==null?void 0:a.selectorColor}},M.createElement("img",{className:"lock",alt:"lock",src:"https://sdk.netless.link/resource/icons/lock.svg"}))},$m=a=>{const{className:o}=a,{floatBarData:e,angle:t,setAngle:i,setOperationType:s,mananger:n}=M.useContext(Ne),[r,c]=M.useState(!1),[l,h]=M.useState(new V),[u,d]=M.useState(new V),[p,f]=M.useState(!1);M.useEffect(()=>(ee.activeListener(y),()=>{ee.unmountActiveListener(y)}),[]);const y=v=>{var S;if(!v){f(!0),c(!1),s(Y.None);return}f(!1),(S=n==null?void 0:n.control.room)!=null&&S.disableDeviceInputs&&(n.control.room.disableDeviceInputs=!1)};M.useEffect(()=>{if(e){const v=Math.floor(e.w/2),S=Math.floor(-e.h/2);d(new V(v,S)),h(new V)}},[e]);const m=(v,S)=>{if(v.cancelable&&v.preventDefault(),v.stopPropagation(),n!=null&&n.control.worker.isBusy){f(!0);return}c(!0);const N=Math.round(V.GetAngleByPoints(l,u,new V(S.x,S.y)))||0;i(N),s(Y.RotateNode),n!=null&&n.control.room&&(n.control.room.disableDeviceInputs=!0),ee.emitMethod(q.MainEngine,Y.RotateNode,{workIds:[H],angle:N,workState:P.Start,viewId:n==null?void 0:n.viewId})},T=Ot((v,S)=>{if(v.cancelable&&v.preventDefault(),v.stopPropagation(),n!=null&&n.control.worker.isBusy){f(!0);return}c(!1);const N=Math.round(V.GetAngleByPoints(l,u,new V(S.x,S.y)))||0;i(N),s(Y.None),n!=null&&n.control.room&&(n.control.room.disableDeviceInputs=!1),ee.emitMethod(q.MainEngine,Y.RotateNode,{workIds:[H],angle:N,workState:P.Done,viewId:n==null?void 0:n.viewId})},100,{leading:!1}),w=Ot((v,S)=>{if(v.cancelable&&v.preventDefault(),v.stopPropagation(),n!=null&&n.control.worker.isBusy){f(!0);return}c(!0);const N=Math.round(V.GetAngleByPoints(l,u,new V(S.x,S.y)))||0;i(N),s(Y.RotateNode),ee.emitMethod(q.MainEngine,Y.RotateNode,{workIds:[H],angle:N,workState:P.Doing,viewId:n==null?void 0:n.viewId})},100,{leading:!1});return M.createElement(Nt,{disabled:p,handle:".appliance-plugin-rotate-mouse-pointer",onStart:m,onDrag:w,onStop:T},M.createElement("div",{className:`${o}`,style:e?{left:e.x-30,top:e.y+e.h+20,touchAction:"none"}:void 0},!r&&M.createElement("div",{className:"appliance-plugin-rotate-btn",style:{backgroundColor:e==null?void 0:e.selectorColor}},M.createElement("img",{alt:"icon",src:xe("rotation-button")})),M.createElement("div",{className:`appliance-plugin-rotate-mouse-pointer ${r?"active":""}`},M.createElement("img",{alt:"icon",src:xe("rotation")}),M.createElement("div",{className:"angle-icon"},t,"°"))))},Hm=a=>{const{floatBarData:o,setOperationType:e,mananger:t}=M.useContext(Ne),{onClickHandle:i}=a,[s,n]=M.useState(P.Pending),[r,c]=M.useState(),[l,h]=M.useState(),[u,d]=M.useState(!1);M.useEffect(()=>(ee.activeListener(p),()=>{ee.unmountActiveListener(p)}),[]);const p=v=>{var S;if(!v||o!=null&&o.isLocked){d(!0),n(P.Pending),e(Y.None);return}d(!1),(S=t==null?void 0:t.control.room)!=null&&S.disableDeviceInputs&&(t.control.room.disableDeviceInputs=!1)};M.useEffect(()=>{if(o!=null&&o.isLocked||t!=null&&t.control.worker.isBusy){d(!0),n(P.Pending);return}d(!1)},[o==null?void 0:o.isLocked]),M.useEffect(()=>{D.isNumber(o==null?void 0:o.x)&&D.isNumber(o==null?void 0:o.y)&&(s===P.Pending||s===P.Done)&&h({x:o==null?void 0:o.x,y:o==null?void 0:o.y})},[s,o==null?void 0:o.x,o==null?void 0:o.y]);const f=v=>{if(v.cancelable&&v.preventDefault(),v.stopPropagation(),t!=null&&t.control.worker.isBusy){d(!0),n(P.Pending);return}D.isNumber(o==null?void 0:o.x)&&D.isNumber(o==null?void 0:o.y)&&(e(Y.TranslateNode),n(P.Start),c({x:o==null?void 0:o.x,y:o==null?void 0:o.y}),t!=null&&t.control.room&&(t.control.room.disableDeviceInputs=!0),ee.emitMethod(q.MainEngine,Y.TranslateNode,{workIds:[H],position:{x:o==null?void 0:o.x,y:o==null?void 0:o.y},workState:P.Start,viewId:t==null?void 0:t.viewId}))},y=D.throttle((v,S)=>{if(v.cancelable&&v.preventDefault(),t!=null&&t.control.worker.isBusy){d(!0),n(P.Pending);return}v.stopPropagation();const N={x:S.x,y:S.y};e(Y.None),n(P.Done),t!=null&&t.control.room&&(t.control.room.disableDeviceInputs=!1),ee.emitMethod(q.MainEngine,Y.TranslateNode,{workIds:[H],position:N,workState:P.Done,viewId:t==null?void 0:t.viewId})},100,{leading:!1}),m=D.throttle((v,S)=>{if(v.cancelable&&v.preventDefault(),v.stopPropagation(),t!=null&&t.control.worker.isBusy){d(!0),n(P.Pending);return}const N={x:S.x,y:S.y};(S.x!==(o==null?void 0:o.x)||S.y!==(o==null?void 0:o.y))&&(n(P.Doing),ee.emitMethod(q.MainEngine,Y.TranslateNode,{workIds:[H],position:N,workState:P.Doing,viewId:t==null?void 0:t.viewId}))},100,{leading:!1}),T=M.useMemo(()=>!!((o==null?void 0:o.scaleType)===re.none&&(o!=null&&o.canLock)),[o]),w=D.throttle(v=>(v.stopPropagation(),v.cancelable&&v.preventDefault(),(r==null?void 0:r.x)===(o==null?void 0:o.x)&&(r==null?void 0:r.y)===(o==null?void 0:o.y)&&i(v),!1),100,{leading:!1});return M.createElement(Nt,{disabled:u,position:l,onStart:f,onDrag:m,onStop:y},M.createElement("div",{style:o?{position:"absolute",left:0,top:0,width:o.w,height:o.h,zIndex:2,pointerEvents:T?"none":"auto",touchAction:"none"}:void 0,onClick:v=>{v.persist(),w(v)},onTouchEnd:v=>{v.persist(),w(v)}}))},Qm=a=>{const{className:o}=a,[e,t]=M.useState({x:0,y:0,h:0,w:0}),[i,s]=M.useState(),[n,r]=M.useState(),[c,l]=M.useState(),{floatBarData:h,mananger:u}=M.useContext(Ne),[d,p]=M.useState(),[f,y]=M.useState(!1);M.useEffect(()=>{if(h&&u){const b={x:h.x,y:h.y,w:h.w,h:h.h};t(b)}return ee.activeListener(m),()=>{ee.unmountActiveListener(m)}},[]);const m=b=>{var L;if(!b){y(!0);return}y(!1),(L=u==null?void 0:u.control.room)!=null&&L.disableDeviceInputs&&(u.control.room.disableDeviceInputs=!1)},T=b=>[[b.x,b.y],[b.x+b.w,b.y],[b.x+b.w,b.y+b.h],[b.x,b.y+b.h]],w=(b,L)=>{switch(L){case"top":case"topLeft":case"left":return b[2];case"topRight":return b[3];case"right":case"bottomRight":case"bottom":return b[0];case"bottomLeft":return b[1]}},v=(b,L,j,E)=>{let A=!1,W=!1;const z={x:e.x,y:e.y,w:e.w,h:e.h},O=[1,1],ne=[0,0];switch(b){case"top":{const G=L.height+e.h;G<0?(W=!0,z.y=e.y+e.h,z.h=Math.abs(G)):(z.y=e.y-L.height,z.h=e.h+L.height);break}case"topLeft":{const G=L.width+e.w;G<0?(A=!0,z.x=e.x+e.w,z.w=Math.abs(G)):(z.x=e.x-L.width,z.w=e.w+L.width);const Z=L.height+e.h;Z<0?(W=!0,z.y=e.y+e.h,z.h=Math.abs(Z)):(z.y=e.y-L.height,z.h=e.h+L.height);break}case"topRight":{const G=L.width+e.w;G<0?(A=!0,z.x=e.x+G,z.w=Math.abs(G)):z.w=e.w+L.width;const Z=L.height+e.h;Z<0?(W=!0,z.y=e.y+e.h,z.h=Math.abs(Z)):(z.y=e.y-L.height,z.h=e.h+L.height);break}case"bottom":{const G=L.height+e.h;G<0?(W=!0,z.y=e.y+G,z.h=Math.abs(G)):z.h=e.h+L.height;break}case"bottomLeft":{const G=L.width+e.w;G<0?(A=!0,z.x=e.x+e.w,z.w=Math.abs(G)):(z.x=e.x-L.width,z.w=e.w+L.width);const Z=L.height+e.h;Z<0?(W=!0,z.y=e.y+Z,z.h=Math.abs(Z)):z.h=e.h+L.height;break}case"left":{const G=L.width+e.w;G<0?(A=!0,z.x=e.x+e.w,z.w=Math.abs(G)):(z.x=e.x-L.width,z.w=e.w+L.width);break}case"bottomRight":{const G=L.width+e.w;G<0?(A=!0,z.x=e.x+G,z.w=Math.abs(G)):z.w=e.w+L.width;const Z=L.height+e.h;Z<0?(W=!0,z.y=e.y+Z,z.h=Math.abs(Z)):z.h=e.h+L.height;break}case"right":{const G=L.width+e.w;G<0?(A=!0,z.x=e.x+G,z.w=Math.abs(G)):z.w=e.w+L.width;break}}O[0]=z.w/e.w,O[1]=z.h/e.h;const Q=T(z).map(G=>j.control.viewContainerManager.transformToScenePoint(G,j.viewId)),X=w(Q,b);return W&&(ne[1]=X[1]-E[1]),A&&(ne[0]=X[0]-E[0]),{scale:O,translate:ne}},S=(b,L)=>{if(b.cancelable&&b.preventDefault(),b.stopPropagation(),u!=null&&u.control.worker.isBusy){y(!0);return}if(h!=null&&h.w&&(h!=null&&h.h)&&u){const j={x:h.x,y:h.y,w:h.w,h:h.h},E=T(j),A=E.map(O=>u.control.viewContainerManager.transformToScenePoint(O,u.viewId)),W=w(E,L),z=w(A,L);t(j),s(W),r(z),l(L),u!=null&&u.control.room&&(u.control.room.disableDeviceInputs=!0),ee.emitMethod(q.MainEngine,Y.ScaleNode,{workIds:[H],originPoint:W,scenePoint:z,workState:P.Start,viewId:u.viewId})}},N=D.throttle((b,L,j,E)=>{if(b.cancelable&&b.preventDefault(),b.stopPropagation(),!u||!i||!n)return;if(u!=null&&u.control.worker.isBusy){y(!0);return}const{scale:A,translate:W}=v(L,E,u,n);(!D.isEqual(A,d==null?void 0:d.scale)||!D.isEqual(W,d==null?void 0:d.translate))&&(p({scale:A,translate:W}),ee.emitMethod(q.MainEngine,Y.ScaleNode,{workIds:[H],scale:A,dir:L,translate:W,originPoint:i,scenePoint:n,workState:P.Doing,viewId:u.viewId}))},100,{leading:!1}),I=D.throttle(b=>{if(b.cancelable&&b.preventDefault(),b.stopPropagation(),!(!u||!i||!n)){if(u!=null&&u.control.worker.isBusy){y(!0);return}if(u!=null&&u.control.room&&(u.control.room.disableDeviceInputs=!1),d){const{scale:L,translate:j}=d;ee.emitMethod(q.MainEngine,Y.ScaleNode,{workIds:[H],scale:L,dir:c,translate:j,originPoint:i,scenePoint:n,workState:P.Done,viewId:u.viewId})}}},100,{leading:!1});return M.createElement(nn.Resizable,{className:`${o}`,boundsByDirection:!0,minWidth:-(((h==null?void 0:h.x)||0)+((h==null?void 0:h.w)||0)),minHeight:-(((h==null?void 0:h.y)||0)+((h==null?void 0:h.h)||0)),size:{width:(h==null?void 0:h.w)||0,height:(h==null?void 0:h.h)||0},style:{position:"absolute",pointerEvents:"auto",left:h==null?void 0:h.x,top:h==null?void 0:h.y},enable:f?!1:{top:(h==null?void 0:h.scaleType)===re.all&&!0||!1,right:(h==null?void 0:h.scaleType)===re.all&&!0||!1,bottom:(h==null?void 0:h.scaleType)===re.all&&!0||!1,left:(h==null?void 0:h.scaleType)===re.all&&!0||!1,topRight:!0,bottomRight:!0,bottomLeft:!0,topLeft:!0},lockAspectRatio:(h==null?void 0:h.scaleType)===re.proportional,onResizeStart:S,onResize:N,onResizeStop:I})},Xi=a=>{const{id:o,pos:e,pointMap:t,type:i}=a,{setOperationType:s,mananger:n,floatBarData:r}=M.useContext(Ne),[c,l]=M.useState({x:0,y:0}),[h,u]=M.useState(P.Pending),[d,p]=M.useState(!1);M.useEffect(()=>(ee.activeListener(f),()=>{ee.unmountActiveListener(f)}),[]);const f=w=>{var v;if(!w||r!=null&&r.isLocked){p(!0),u(P.Pending),s(Y.None);return}p(!1),(v=n==null?void 0:n.control.room)!=null&&v.disableDeviceInputs&&(n.control.room.disableDeviceInputs=!1)};M.useEffect(()=>{D.isNumber(e.x)&&D.isNumber(e.y)&&(h===P.Pending||h===P.Done)&&l({x:e.x,y:e.y})},[e,h]);const y=w=>{if(w.cancelable&&w.preventDefault(),w.stopPropagation(),n!=null&&n.control.worker.isBusy){p(!0),u(P.Pending);return}D.isNumber(e.x)&&D.isNumber(e.y)&&(s(Y.SetPoint),u(P.Start),n!=null&&n.control.room&&(n.control.room.disableDeviceInputs=!0),ee.emitMethod(q.MainEngine,Y.SetPoint,{workId:H,pointMap:t,workState:P.Start,viewId:n==null?void 0:n.viewId}))},m=D.throttle((w,v)=>{if(w.cancelable&&w.preventDefault(),w.stopPropagation(),n!=null&&n.control.worker.isBusy){p(!0),u(P.Pending);return}const S={x:v.x,y:v.y};if((S.x!==(e==null?void 0:e.x)||S.y!==(e==null?void 0:e.y))&&(n!=null&&n.control.viewContainerManager)){const N=n.control.viewContainerManager.transformToScenePoint([S.x,S.y],n.viewId),I=t.get(o);I&&i==="start"?I[0]=N:I&&i==="end"&&(I[1]=N),u(P.Doing),ee.emitMethod(q.MainEngine,Y.SetPoint,{workId:H,pointMap:t,workState:P.Doing,viewId:n==null?void 0:n.viewId})}},100,{leading:!1}),T=D.throttle((w,v)=>{if(w.cancelable&&w.preventDefault(),n!=null&&n.control.worker.isBusy){p(!0),u(P.Pending);return}w.stopPropagation(),s(Y.None),u(P.Done);const S={x:v.x,y:v.y};if(n!=null&&n.control.viewContainerManager){const N=n.control.viewContainerManager.transformToScenePoint([S.x,S.y],n.viewId),I=t.get(o);I&&i==="start"?I[0]=N:I&&i==="end"&&(I[1]=N),n!=null&&n.control.room&&(n.control.room.disableDeviceInputs=!1),ee.emitMethod(q.MainEngine,Y.SetPoint,{workId:H,pointMap:t,workState:P.Done,viewId:n==null?void 0:n.viewId})}},100,{leading:!1});return M.createElement(Nt,{disabled:d,position:c,onStart:y,onDrag:m,onStop:T},M.createElement("div",{className:"appliance-plugin-point-draggable-btn",style:r?{left:0,top:0}:void 0}))},Gm=a=>{const{className:o}=a,{floatBarData:e,mananger:t}=M.useContext(Ne),[i,s]=M.useState(),[n,r]=M.useState(),[c,l]=M.useState(new Map);M.useEffect(()=>{const d=[];if(t&&(e!=null&&e.points)){const p=t.viewId;if(t.control.viewContainerManager.getView(p))for(const y of e.points){const m=t.control.viewContainerManager.transformToOriginPoint(y,p);d.push(m)}e!=null&&e.selectIds&&e.selectIds.length===1&&(c.set(e.selectIds[0],e.points),l(c))}d[0]&&s({x:d[0][0],y:d[0][1]}),d[1]&&r({x:d[1][0],y:d[1][1]})},[t,e==null?void 0:e.points,e==null?void 0:e.selectIds,c]);const h=M.useMemo(()=>i&&(e!=null&&e.selectIds)?M.createElement(Xi,{pos:i,type:"start",id:e.selectIds[0],pointMap:c}):null,[i,e==null?void 0:e.selectIds,c]),u=M.useMemo(()=>n&&(e!=null&&e.selectIds)?M.createElement(Xi,{pos:n,type:"end",id:e.selectIds[0],pointMap:c}):null,[n,e==null?void 0:e.selectIds,c]);return M.createElement("div",{className:`${o}`},h,u)},Zm=M.forwardRef((a,o)=>{const{floatBarData:e,operationType:t}=M.useContext(Ne),i=M.useMemo(()=>(e==null?void 0:e.scaleType)!==re.all||t===Y.RotateNode?null:M.createElement(Um,null),[e,t]),s=M.useMemo(()=>(e==null?void 0:e.scaleType)!==re.both||t===Y.RotateNode?null:M.createElement(Bm,null),[e,t]),n=M.useMemo(()=>(e==null?void 0:e.scaleType)!==re.proportional||t===Y.RotateNode?null:M.createElement(Fm,null),[e,t]),r=M.useMemo(()=>(e==null?void 0:e.scaleType)===re.none&&(e!=null&&e.canLock)?M.createElement(Vm,null):null,[e]);return M.createElement("div",{ref:o,style:e?{transform:`translate(${e.x}px,${e.y}px)`,width:e.w,height:e.h,pointerEvents:"none"}:void 0},r,i,s,n,a.children)}),qm=M.forwardRef((a,o)=>{var p;const{floatBarData:e,operationType:t,mananger:i}=M.useContext(Ne),{editors:s,activeTextId:n,isHide:r}=a,c=M.useMemo(()=>{var f;return e!=null&&e.canRotate&&((f=e==null?void 0:e.selectIds)==null?void 0:f.length)===1&&(t===Y.None||t===Y.RotateNode)?M.createElement($m,{className:ze.RotateBtn}):null},[e==null?void 0:e.canRotate,(p=e==null?void 0:e.selectIds)==null?void 0:p.length,t]),l=M.useMemo(()=>((e==null?void 0:e.scaleType)===re.all||(e==null?void 0:e.scaleType)===re.proportional)&&(t===Y.None||t===Y.ScaleNode)&&D.isNumber(e==null?void 0:e.x)&&D.isNumber(e==null?void 0:e.y)?M.createElement(Qm,{className:ze.ResizeBtn}):null,[e==null?void 0:e.scaleType,t,e==null?void 0:e.x,e==null?void 0:e.y]),h=M.useMemo(()=>(e==null?void 0:e.scaleType)===re.both&&(t===Y.None||t===Y.SetPoint)?M.createElement(Gm,{className:ze.ResizeTowBox}):null,[e==null?void 0:e.scaleType,t]),u=M.useMemo(()=>{const f=(e==null?void 0:e.selectIds)||[];return s&&i&&f&&D.isNumber(e==null?void 0:e.x)&&D.isNumber(e==null?void 0:e.y)&&D.isNumber(e==null?void 0:e.w)&&D.isNumber(e==null?void 0:e.h)?M.createElement(tn,{box:{x:e==null?void 0:e.x,y:e==null?void 0:e.y,w:e==null?void 0:e.w,h:e==null?void 0:e.h},manager:i,selectIds:f,activeTextId:n,editors:s}):null},[e==null?void 0:e.selectIds,e==null?void 0:e.x,e==null?void 0:e.y,e==null?void 0:e.w,e==null?void 0:e.h,s,i,n]),d=M.useMemo(()=>r&&t===Y.None&&D.isNumber(e==null?void 0:e.x)&&D.isNumber(e==null?void 0:e.y)&&D.isNumber(e==null?void 0:e.w)&&D.isNumber(e==null?void 0:e.h)?M.createElement("div",{className:ze.FloatBarBtn,style:{left:e==null?void 0:e.x,top:e==null?void 0:e.y,width:e.w,height:e.h}},M.createElement(en,{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,r]);return M.createElement("div",{className:ze.FloatBar,onMouseOver:()=>{i==null||i.control.worker.blurCursor(i.viewId)}},M.createElement(Zm,{ref:o},M.createElement(M.Fragment,null,u)),M.createElement(Hm,{onClickHandle:f=>{if(i&&(s!=null&&s.size)){const y=i.getPoint(f.nativeEvent);y&&i.control.textEditorManager.computeTextActive(y,i.viewId)}}}),c,l,h,d)}),Xm=M.memo(qm,(a,o)=>!!D.isEqual(a,o)),Jm="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADQAAAA0CAYAAADFeBvrAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAYISURBVHgB7ZpNSCtXFIBPEuvz+dMGpYUKD/sWFX+Qti6kK7Hqpm6e9q0rIoIUFUShPLV10VZx4+JZqa9v20LBhdq9fyBUCtKNPH8qYl2IOw3G38Rkek4y15y5uTOZJDOWggcOSSYzN/ebc+45554JwIM8iBCPyTEP+86T4vyMfsRN4b+nQTKIJp0vzuGvlpID7os8EQNEIBD4oKio6Bm9DwaDv/v9/n/076JgbtWUYPchwrW8qD7UnOvr6wFNkpubm+/wu7f0c7y6mrnlvQufxB0Iau7V1dX3BDA/P6/V1dVpzc3N2uLiIofK1c8VYHys/wRKBUN3/hGHqaysNOjc3FwMis6hc0FtLTHuvYLxCCZgci8uLn4wg5Gh6Fy8Jk+/NkcCAlAAuUkoW4g0B+d5tLS05O/r67O8eGxsDNra2uDy8nKsoKCAwCIQDxQa0yTxgrvCYXyTk5Ml+Orf2dlJeeHIyAigFSE/P38ELfUNqNdSkjgF5FF89jL1TU1NlQwODl5gZPujp6cHWltbUw7Koc7Pz8mkZpHPFeFrJuZeqLnoMoPoZqe0JjDP/IZgnyLUG/o8NDRkuo5Ua2pjY6MC4oFCFf1cA0oKzRSOp6enRfTaGh0d/QxBt+1CUVgnOTs7+xrHfQzGyOcKkK3QTJMnQffZ6e/v/xwttmsHqqmpKXbd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wVAN82y7vOjKOZXSBhJdHNiT3TYWD8OY2PTUJkdd7MkJMnT5wZVQF2RFX6yBMUdzPMvvfqxz3sXHF+GNT9ANXit/10O1sgHkZvdQAOKvs9B5L7ARELGAAXLSTvM8QExTE+YbHe+HURhZp1aRyF4CJXClbbWwGketgkW9VsY+YaiBCVhfgE+XvxRwgZSM4jUVCDZFQ9pytmXR8hUTB2gnidx4XffVWydN0yQjwmx/jkAZJBrIBI5J7ZvQGZWUgVSuU/EqmOAzicKNMVu816DdRWUV1/7xAP8n+SfwF3Du3NF2sYhwAAAABJRU5ErkJggg==",Km="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3csvg%20width='40px'%20height='40px'%20viewBox='0%200%2040%2040'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3c!--%20Generator:%20Sketch%2060.1%20(88133)%20-%20https://sketch.com%20--%3e%3ctitle%3eshape-cursor%3c/title%3e%3cdesc%3eCreated%20with%20Sketch.%3c/desc%3e%3cdefs%3e%3cpath%20d='M20,21.5%20C20.2454599,21.5%2020.4496084,21.6768752%2020.4919443,21.9101244%20L20.5,22%20L20.5,27%20C20.5,27.2761424%2020.2761424,27.5%2020,27.5%20C19.7545401,27.5%2019.5503916,27.3231248%2019.5080557,27.0898756%20L19.5,27%20L19.5,22%20C19.5,21.7238576%2019.7238576,21.5%2020,21.5%20Z%20M27,19.5%20C27.2761424,19.5%2027.5,19.7238576%2027.5,20%20C27.5,20.2454599%2027.3231248,20.4496084%2027.0898756,20.4919443%20L27,20.5%20L22,20.5%20C21.7238576,20.5%2021.5,20.2761424%2021.5,20%20C21.5,19.7545401%2021.6768752,19.5503916%2021.9101244,19.5080557%20L22,19.5%20L27,19.5%20Z%20M18,19.5%20C18.2761424,19.5%2018.5,19.7238576%2018.5,20%20C18.5,20.2454599%2018.3231248,20.4496084%2018.0898756,20.4919443%20L18,20.5%20L13,20.5%20C12.7238576,20.5%2012.5,20.2761424%2012.5,20%20C12.5,19.7545401%2012.6768752,19.5503916%2012.9101244,19.5080557%20L13,19.5%20L18,19.5%20Z%20M20,12.5%20C20.2454599,12.5%2020.4496084,12.6768752%2020.4919443,12.9101244%20L20.5,13%20L20.5,18%20C20.5,18.2761424%2020.2761424,18.5%2020,18.5%20C19.7545401,18.5%2019.5503916,18.3231248%2019.5080557,18.0898756%20L19.5,18%20L19.5,13%20C19.5,12.7238576%2019.7238576,12.5%2020,12.5%20Z'%20id='path-1'%3e%3c/path%3e%3cfilter%20x='-64.6%25'%20y='-59.5%25'%20width='229.3%25'%20height='246.1%25'%20filterUnits='objectBoundingBox'%20id='filter-2'%3e%3cfeMorphology%20radius='1'%20operator='dilate'%20in='SourceAlpha'%20result='shadowSpreadOuter1'%3e%3c/feMorphology%3e%3cfeOffset%20dx='0'%20dy='2'%20in='shadowSpreadOuter1'%20result='shadowOffsetOuter1'%3e%3c/feOffset%3e%3cfeGaussianBlur%20stdDeviation='3'%20in='shadowOffsetOuter1'%20result='shadowBlurOuter1'%3e%3c/feGaussianBlur%3e%3cfeComposite%20in='shadowBlurOuter1'%20in2='SourceAlpha'%20operator='out'%20result='shadowBlurOuter1'%3e%3c/feComposite%3e%3cfeColorMatrix%20values='0%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200.16%200'%20type='matrix'%20in='shadowBlurOuter1'%3e%3c/feColorMatrix%3e%3c/filter%3e%3c/defs%3e%3cg%20id='页面-4'%20stroke='none'%20stroke-width='1'%20fill='none'%20fill-rule='evenodd'%3e%3cg%20id='Whiteboard-Guidelines'%20transform='translate(-344.000000,%20-751.000000)'%3e%3cg%20id='shape-cursor'%20transform='translate(344.000000,%20751.000000)'%3e%3crect%20id='矩形备份-44'%20fill='%23FFFFFF'%20opacity='0.01'%20x='0'%20y='0'%20width='40'%20height='40'%20rx='2'%3e%3c/rect%3e%3cg%20id='形状结合'%20fill-rule='nonzero'%3e%3cuse%20fill='black'%20fill-opacity='1'%20filter='url(%23filter-2)'%20xlink:href='%23path-1'%3e%3c/use%3e%3cpath%20stroke='%23FFFFFF'%20stroke-width='1'%20d='M20,21%20C20.4854103,21%2020.898085,21.3479993%2020.9899479,21.8654877%20L21,22%20L21,27%20C21,27.5522847%2020.5522847,28%2020,28%20C19.5145897,28%2019.101915,27.6520007%2019.0100521,27.1345123%20L19,27%20L19,22%20C19,21.4477153%2019.4477153,21%2020,21%20Z%20M27,19%20C27.5522847,19%2028,19.4477153%2028,20%20C28,20.4854103%2027.6520007,20.898085%2027.1345123,20.9899479%20L27,21%20L22,21%20C21.4477153,21%2021,20.5522847%2021,20%20C21,19.5145897%2021.3479993,19.101915%2021.8654877,19.0100521%20L22,19%20L27,19%20Z%20M18,19%20C18.5522847,19%2019,19.4477153%2019,20%20C19,20.4854103%2018.6520007,20.898085%2018.1345123,20.9899479%20L18,21%20L13,21%20C12.4477153,21%2012,20.5522847%2012,20%20C12,19.5145897%2012.3479993,19.101915%2012.8654877,19.0100521%20L13,19%20L18,19%20Z%20M20,12%20C20.4854103,12%2020.898085,12.3479993%2020.9899479,12.8654877%20L21,13%20L21,18%20C21,18.5522847%2020.5522847,19%2020,19%20C19.5145897,19%2019.101915,18.6520007%2019.0100521,18.1345123%20L19,18%20L19,13%20C19,12.4477153%2019.4477153,12%2020,12%20Z'%20fill='%23212324'%20fill-rule='evenodd'%3e%3c/path%3e%3c/g%3e%3crect%20id='矩形'%20fill='%23FFFFFF'%20x='18.5'%20y='17'%20width='3'%20height='6'%3e%3c/rect%3e%3crect%20id='矩形'%20fill='%23FFFFFF'%20x='17'%20y='18.5'%20width='6'%20height='3'%3e%3c/rect%3e%3cpath%20d='M20,21.5%20C20.2454599,21.5%2020.4496084,21.6768752%2020.4919443,21.9101244%20L20.5,22%20L20.5,27%20C20.5,27.2761424%2020.2761424,27.5%2020,27.5%20C19.7545401,27.5%2019.5503916,27.3231248%2019.5080557,27.0898756%20L19.5,27%20L19.5,22%20C19.5,21.7238576%2019.7238576,21.5%2020,21.5%20Z%20M27,19.5%20C27.2761424,19.5%2027.5,19.7238576%2027.5,20%20C27.5,20.2454599%2027.3231248,20.4496084%2027.0898756,20.4919443%20L27,20.5%20L22,20.5%20C21.7238576,20.5%2021.5,20.2761424%2021.5,20%20C21.5,19.7545401%2021.6768752,19.5503916%2021.9101244,19.5080557%20L22,19.5%20L27,19.5%20Z%20M18,19.5%20C18.2761424,19.5%2018.5,19.7238576%2018.5,20%20C18.5,20.2454599%2018.3231248,20.4496084%2018.0898756,20.4919443%20L18,20.5%20L13,20.5%20C12.7238576,20.5%2012.5,20.2761424%2012.5,20%20C12.5,19.7545401%2012.6768752,19.5503916%2012.9101244,19.5080557%20L13,19.5%20L18,19.5%20Z%20M20,12.5%20C20.2454599,12.5%2020.4496084,12.6768752%2020.4919443,12.9101244%20L20.5,13%20L20.5,18%20C20.5,18.2761424%2020.2761424,18.5%2020,18.5%20C19.7545401,18.5%2019.5503916,18.3231248%2019.5080557,18.0898756%20L19.5,18%20L19.5,13%20C19.5,12.7238576%2019.7238576,12.5%2020,12.5%20Z'%20id='形状结合'%20fill='%23212324'%20fill-rule='nonzero'%3e%3c/path%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e",_m="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3csvg%20width='47px'%20height='40px'%20viewBox='0%200%2047%2040'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3c!--%20Generator:%20Sketch%2060.1%20(88133)%20-%20https://sketch.com%20--%3e%3ctitle%3etext-cursor%3c/title%3e%3cdesc%3eCreated%20with%20Sketch.%3c/desc%3e%3cdefs%3e%3cpath%20d='M16,26.5%20C15.7238576,26.5%2015.5,26.2761424%2015.5,26%20C15.5,25.7545401%2015.6768752,25.5503916%2015.9101244,25.5080557%20L16,25.5%20L19.5,25.5%20L19.5,14.5%20L16,14.5%20C15.7238576,14.5%2015.5,14.2761424%2015.5,14%20C15.5,13.7545401%2015.6768752,13.5503916%2015.9101244,13.5080557%20L16,13.5%20L24,13.5%20C24.2761424,13.5%2024.5,13.7238576%2024.5,14%20C24.5,14.2454599%2024.3231248,14.4496084%2024.0898756,14.4919443%20L24,14.5%20L20.5,14.5%20L20.5,25.5%20L24,25.5%20C24.2761424,25.5%2024.5,25.7238576%2024.5,26%20C24.5,26.2454599%2024.3231248,26.4496084%2024.0898756,26.4919443%20L24,26.5%20L16,26.5%20Z'%20id='path-1'%3e%3c/path%3e%3cfilter%20x='-284.0%25'%20y='-81.5%25'%20width='668.1%25'%20height='293.9%25'%20filterUnits='objectBoundingBox'%20id='filter-2'%3e%3cfeMorphology%20radius='1'%20operator='dilate'%20in='SourceAlpha'%20result='shadowSpreadOuter1'%3e%3c/feMorphology%3e%3cfeOffset%20dx='0'%20dy='2'%20in='shadowSpreadOuter1'%20result='shadowOffsetOuter1'%3e%3c/feOffset%3e%3cfeGaussianBlur%20stdDeviation='3'%20in='shadowOffsetOuter1'%20result='shadowBlurOuter1'%3e%3c/feGaussianBlur%3e%3cfeComposite%20in='shadowBlurOuter1'%20in2='SourceAlpha'%20operator='out'%20result='shadowBlurOuter1'%3e%3c/feComposite%3e%3cfeColorMatrix%20values='0%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200.16%200'%20type='matrix'%20in='shadowBlurOuter1'%3e%3c/feColorMatrix%3e%3c/filter%3e%3c/defs%3e%3cg%20id='页面-4'%20stroke='none'%20stroke-width='1'%20fill='none'%20fill-rule='evenodd'%3e%3cg%20id='Whiteboard-Guidelines'%20transform='translate(-388.000000,%20-672.000000)'%3e%3cg%20id='text-cursor'%20transform='translate(392.000000,%20672.000000)'%3e%3crect%20id='矩形备份-40'%20fill='%23FFFFFF'%20opacity='0.01'%20x='0'%20y='0'%20width='40'%20height='40'%20rx='2'%3e%3c/rect%3e%3cg%20id='形状结合'%20fill-rule='nonzero'%3e%3cuse%20fill='black'%20fill-opacity='1'%20filter='url(%23filter-2)'%20xlink:href='%23path-1'%3e%3c/use%3e%3cpath%20stroke='%23FFFFFF'%20stroke-width='1'%20d='M19,25%20L19,15%20L16,15%20C15.4477153,15%2015,14.5522847%2015,14%20C15,13.5145897%2015.3479993,13.101915%2015.8654877,13.0100521%20L16,13%20L24,13%20C24.5522847,13%2025,13.4477153%2025,14%20C25,14.4854103%2024.6520007,14.898085%2024.1345123,14.9899479%20L24,15%20L21,15%20L21,25%20L24,25%20C24.5522847,25%2025,25.4477153%2025,26%20C25,26.4854103%2024.6520007,26.898085%2024.1345123,26.9899479%20L24,27%20L16,27%20C15.4477153,27%2015,26.5522847%2015,26%20C15,25.5145897%2015.3479993,25.101915%2015.8654877,25.0100521%20L16,25%20L19,25%20Z'%20fill='%23212324'%20fill-rule='evenodd'%3e%3c/path%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/g%3e%3c/svg%3e",ew="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADQAAAA0CAYAAADFeBvrAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAgrSURBVHgB7ZprTBRXFIDP7gIt8lQppTwE5V0KaAn6o1pqNGkDDTEmTUhsgKRp+gNJw68CFkLbVC2QkDS+gD8KJdWmARvbFBNNWpuIRGPFWBXQRMPDqIki+KLATs+ZnTvcvXtnX8w2beJJToaduTP3fHPOPffcOwC8kP+2WCDwIvahGFxTuN8KmNSZmULPNjLeqF9F8rdPkIEGEn+r+vjx46LQ0NA8/Dsader58+e/h4WFDWntFO7ot6fMFAt3JLWi2lCDpqamCux2+2+KROj82NhYGrXT2lu5Z/DP/deFByElA4Pv3LlTiHY/nJ6eVnbv3q1s2bJFyc7OVrZu3arU1dUp4+PjxPUQoT+g9tp9PkMFgpo9kxljHRoaWp2Xl3duYmIiurKyEvDoclNCQgIcPnxYPc7MzHwcGRnZhaft4Ag7O9fUbRhaITCie4lgcnNzT7qDIaHz27dvh+vXr0NEREQneq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ChCBD6R2JwHge80TIQRQLjt7e8DTkGZgfX8cUMZTDAteFDkveaIlzjX9ySQs8X18r2t2VHUURPKoICmDR+eCO9aSdmOIub3/w9RgpgUpiJhvraXpa6jZKHGEqyusw0GLFzX+5RhN/8kYnMSNMMfyH/V/kHST6OYVElTPAAAAAASUVORK5CYII=";class tw extends M.Component{constructor(e){super(e);g(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 s=this.getCursorName(e);return M.createElement("img",{className:"cursor-selector-avatar",style:{width:s?19:28,height:s?19:28,position:s?"initial":"absolute",borderColor:s?"white":t,marginRight:s?4:0},src:(i=e.payload)==null?void 0:i.avatar,alt:"avatar"})}else return null});g(this,"getOpacity",e=>{const t=this.getCursorName(e),i=this.detectAvatar(e);return t===void 0&&i===void 0?0:1});g(this,"getCursorName",e=>{if(e.payload)return e.payload.nickName||e.payload.cursorName||e.payload.uid});g(this,"getThemeClass",e=>e.payload&&e.payload.theme?"cursor-inner-mellow":"cursor-inner");g(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});g(this,"getCursorTextColor",e=>e.payload&&e.payload.cursorTextColor?e.payload.cursorTextColor:"#FFFFFF");g(this,"getCursorTagBackgroundColor",e=>e.payload&&e.payload.cursorTagBackgroundColor?e.payload.cursorTagBackgroundColor:this.getCursorBackgroundColor(e));g(this,"detectAvatar",e=>!!(e.payload&&e.payload.avatar));g(this,"renderTag",e=>{if(e.payload&&e.payload.cursorTagName)return M.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 se.pencil:return M.createElement("div",{className:"cursor-box"},M.createElement("div",{className:"cursor-mid cursor-pencil-offset",style:{transform:"translate(-50%, -90%)",marginLeft:"10px"}},M.createElement("div",{className:"cursor-name"},M.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),t,this.renderTag(e))),M.createElement("div",null,M.createElement("img",{className:"cursor-pencil-image",src:Jm,alt:"pencilCursor"}))));case se.eraser:case se.pencilEraser:return M.createElement("div",{className:"cursor-box"},M.createElement("div",{className:"cursor-mid cursor-pencil-offset",style:{transform:"translate(-50%, -90%)",marginLeft:"0px"}},M.createElement("div",{className:"cursor-name"},M.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),t,this.renderTag(e))),M.createElement("div",null,M.createElement("img",{className:"cursor-pencil-image",src:ew,alt:"pencilEraser"}))));case se.text:return M.createElement("div",{className:"cursor-box"},M.createElement("div",{className:"cursor-mid cursor-pencil-offset",style:{transform:"translate(-50%, -65%)",marginLeft:"0px"}},M.createElement("div",{className:"cursor-name"},M.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),t,this.renderTag(e))),M.createElement("div",null,M.createElement("img",{className:"cursor-arrow-image",src:_m,alt:"textCursor"}))));case se.rectangle:case se.arrow:case se.straight:case se.shape:case se.ellipse:return M.createElement("div",{className:"cursor-box"},M.createElement("div",{className:"cursor-mid cursor-pencil-offset",style:{transform:"translate(-50%, -65%)",marginLeft:"0px"}},M.createElement("div",{className:"cursor-name"},M.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),t,this.renderTag(e))),M.createElement("div",null,M.createElement("img",{className:"cursor-arrow-image",src:Km,alt:"shapeCursor"}))));default:return null}}}const ow=a=>{const{className:o,info:e}=a,{roomMember:t,...i}=e||{};return M.createElement("div",{className:`${o}`,style:i?{transform:`translate(${i.x}px, ${i.y}px)`}:{display:"none"}},t&&M.createElement(tw,{roomMember:t}))},iw=a=>{const{className:o,manager:e}=a,[t,i]=M.useState();M.useEffect(()=>(e.internalMsgEmitter.on([q.Cursor,e.viewId],s),()=>{e.internalMsgEmitter.off([q.Cursor,e.viewId],s)}),[e]);function s(r){i(r)}return M.useMemo(()=>{if(t!=null&&t.length){const r=t.map(c=>{var l;return c.roomMember?M.createElement(ow,{key:(l=c.roomMember)==null?void 0:l.memberId,className:o,info:c}):null});return M.createElement(M.Fragment,null,r)}return null},[t])},sw=a=>{const{viewId:o,miniMapCanvas:e,highlightColor:t,miniMapManager:i,contianer:s}=a,[n,r]=M.useState();M.useEffect(()=>(c(),i.listener.addListener([o,"viewCameraUpate"],c),i.listener.emitAsync([o,"miniMapCreate"],!0),()=>{i.listener.removeListener([o,"viewCameraUpate"],c)}),[]);const c=()=>{const u=i.maps.get(o);u&&l(u.miniMapCamera,u.viewCamera)},l=(u,d)=>{const{width:p,height:f}=s.getBoundingClientRect(),y=Math.min(p/u.width,f/u.height),m=d.width/d.scale,T=d.height/d.scale,w=[d.centerX,d.centerY],v=[u.centerX,u.centerY],S=[w[0]-v[0],w[1]-v[1]],N=Math.min(u.scale*y,u.scale*y),I=[S[0]*N,S[1]*N,m,T,N];r(I)},h=u=>{var d;if(i.control.renderControl.isWriteable()){const p=u.nativeEvent.target||u.nativeEvent.srcElement;if(p&&u.nativeEvent&&n){const{width:f,height:y}=p.getBoundingClientRect(),[m,T]=[f/2,y/2],[w,v]=[(u.nativeEvent.offsetX-m)/n[4],(u.nativeEvent.offsetY-T)/n[4]],S=i.maps.get(o);if(S!=null&&S.viewCamera){const[N,I]=[S.miniMapCamera.centerX+w,S.miniMapCamera.centerY+v];(d=i.control.room)==null||d.moveCamera({centerX:N,centerY:I,animationMode:"immediately"})}}}};return M.createElement("div",{style:{position:"relative",width:"100%",height:"100%",overflow:"hidden",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",pointerEvents:"auto"},onClick:h},M.createElement("canvas",{style:{pointerEvents:"none"},ref:e}),n&&M.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"}}))},nw=a=>{const{miniMapManager:o,active:e,className:t}=a,i=M.useMemo(()=>{const s=o.maps;if(e){const n=s.get(e);if(n){const{miniMapCamera:r,viewCamera:c,...l}=n;if(l.contianer&&r&&c){const h=o.highlightColor;return ro.createPortal(M.createElement(sw,{viewId:e,...l,highlightColor:h,miniMapManager:o}),l.contianer)}}}return null},[e,o]);return M.createElement("div",{className:t},i)},Ne=M.createContext({mananger:void 0,floatBarColors:[],floatBarData:void 0,dpr:1,angle:0,operationType:Y.None,scale:[1,1],setAngle:()=>{},setOperationType:()=>{},setFloatBarData:()=>{}});class si extends M.Component{constructor(e){var t,i;super(e);g(this,"setAngle",e=>{this.setState({angle:e})});g(this,"setOperationType",e=>{this.setState({operationType:e})});this.state={floatBarData:void 0,showFloatBar:!1,dpr:1,angle:0,operationType:Y.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 Ce(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})}showFloatBar(e,t){const i=e&&t&&{...this.state.floatBarData,...t}||void 0;this.setState({showFloatBar:e,floatBarData:i,angle:0})}setActiveTextEditor(e){this.setState({activeTextId:e,editors:this.editors})}setFloatBarData(e){this.state.floatBarData&&this.setState({floatBarData:{...this.state.floatBarData,...e}})}render(){var t,i,s,n,r,c,l;const e=!!((i=(t=this.props.mananger.control)==null?void 0:t.room)!=null&&i.floatBarOptions);return M.createElement("div",{className:ze.Container},!this.props.mananger.control.hasOffscreenCanvas()&&M.createElement("div",{className:ze.CanvasBox,ref:this.props.refs.canvasContainerRef})||M.createElement("div",{className:ze.CanvasBox,onMouseDown:h=>{h.cancelable&&h.preventDefault(),h.stopPropagation()},onTouchStart:h=>{h.stopPropagation()},onMouseMove:h=>{this.props.mananger.cursorMouseMove(h)}},M.createElement("canvas",{id:"bgCanvas",ref:this.props.refs.canvasBgRef,style:{width:"100%",height:"100%"}}),M.createElement("canvas",{id:"serviceCanvas",className:ze.FloatCanvas,ref:this.props.refs.canvasServiceFloatRef,style:{width:"100%",height:"100%"}}),M.createElement("canvas",{id:"localCanvas",className:ze.FloatCanvas,ref:this.props.refs.canvasFloatRef,style:{width:"100%",height:"100%"}}),M.createElement("div",{id:"subLocalCanvas",className:ze.CanvasBoxSub,ref:this.props.refs.subLocalCanvasContainerRef}),M.createElement("canvas",{id:"topCanvas",className:ze.TopFloatCanvas,ref:this.props.refs.canvasTopRef,style:{width:"100%",height:"100%"}})),!this.props.mananger.control.hasOffscreenCanvas()&&this.props.refs.snapshotContainerRef&&M.createElement("div",{className:ze.SnapshotBox,ref:this.props.refs.snapshotContainerRef})||null,M.createElement(Ne.Provider,{value:{mananger:this.props.mananger,floatBarColors:e&&((r=(n=(s=this.props.mananger.control)==null?void 0:s.room)==null?void 0:n.floatBarOptions)==null?void 0:r.colors)||[],floatBarData:this.state.floatBarData,dpr:this.state.dpr,angle:this.state.angle,operationType:this.state.operationType,scale:this.state.scale,setAngle:this.setAngle.bind(this),setOperationType:this.setOperationType.bind(this),setFloatBarData:this.setFloatBarData.bind(this)}},this.state.showFloatBar&&M.createElement(Xm,{ref:this.props.refs.floatBarRef,editors:this.state.editors,activeTextId:this.state.activeTextId,isHide:e})||null,((c=this.state.editors)==null?void 0:c.size)&&M.createElement(Wm,{className:ze.TextEditorContainer,showFloatBtns:e,manager:this.props.mananger,selectIds:((l=this.state.floatBarData)==null?void 0:l.selectIds)||[],editors:this.state.editors,activeTextId:this.state.activeTextId})||null),M.createElement(iw,{className:ze.CursorBox,manager:this.props.mananger}),M.createElement(nw,{className:ze.MiniMapBox,active:this.state.activeMiniMapViewId,miniMapManager:this.props.mananger.control.miniMapManager}))}}class rw extends Ks{constructor(e,t){super(e,t);g(this,"width",1e3);g(this,"height",1e3);g(this,"dpr",Je());g(this,"vDom");g(this,"eventTragetElement");g(this,"snapshotContainerRef");g(this,"canvasContainerRef",M.createRef());g(this,"subLocalCanvasContainerRef",M.createRef());g(this,"canvasTopRef",M.createRef());g(this,"canvasServiceFloatRef",M.createRef());g(this,"canvasFloatRef",M.createRef());g(this,"canvasBgRef",M.createRef());g(this,"floatBarRef",M.createRef());g(this,"containerOffset",{x:0,y:0});this.control.hasOffscreenCanvas()||(this.snapshotContainerRef=M.createRef())}setCanvassStyle(){if(this.eventTragetElement){const e=this.eventTragetElement.offsetWidth||this.width,t=this.eventTragetElement.offsetHeight||this.height;let i=Je();this.canvasBgRef.current&&(i=Je(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(),ro.render(M.createElement(si,{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 aw extends ZM{constructor(e,t,i){super(e,t,i);g(this,"dpr",Je());g(this,"width",1e3);g(this,"height",1e3);g(this,"vDom");g(this,"eventTragetElement");g(this,"canvasContainerRef",M.createRef());g(this,"subLocalCanvasContainerRef",M.createRef());g(this,"canvasTopRef",M.createRef());g(this,"canvasServiceFloatRef",M.createRef());g(this,"canvasFloatRef",M.createRef());g(this,"canvasBgRef",M.createRef());g(this,"floatBarRef",M.createRef());g(this,"containerOffset",{x:0,y:0})}setCanvassStyle(){if(this.eventTragetElement){let e=Je();if(this.canvasBgRef.current&&(e=Je(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(),ro.render(M.createElement(si,{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 We extends It{constructor(e){super(e);g(this,"focuedViewId");g(this,"focuedView");g(this,"control");g(this,"tmpFocusedViewId");g(this,"checkScaleTimer");g(this,"onMainViewRelease",async e=>{this.control.textEditorManager.clear(de,!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()});g(this,"mainViewDestroy",e=>{var t;if(this.mainView&&this.mainView.displayer){this.mainView.displayer.destroy();const i=e.divElement;if(i){const s=i.getElementsByClassName("appliance-plugin-main-view-displayer");for(const n of s)n.remove()}if(this.mainView.container&&i!==this.mainView.container){const s=this.mainView.container.getElementsByClassName("appliance-plugin-main-view-displayer");for(const n of s)n.remove()}(t=this.control.worker)==null||t.destroyViewWorker(this.mainView.id,!0),this.mainView.displayer.destroy(),this.mainView=void 0}});g(this,"onMainViewMounted",e=>{const t=e.divElement;if(!t||!e.focusScenePath||!(e.focusScenePath||e.scenePath))return;const s=new rw(this.control,Se.InternalMsgEmitter),n=e.size.width||s.width,r=e.size.height||s.height,l={dpr:s.dpr,originalPoint:[n/2,r/2],offscreenCanvasOpt:{...We.defaultScreenCanvasOpt,width:n,height:r},layerOpt:{...We.defaultLayerOpt,width:n,height:r},cameraOpt:{...We.defaultCameraOpt,width:n,height:r}},{scale:h,...u}=e.camera;l.cameraOpt={...l.cameraOpt,...u,scale:h===1/0?1:h},this.focuedViewId=de,this.createMianView({id:de,container:t,displayer:s,focusScenePath:e.focusScenePath,cameraOpt:l.cameraOpt,viewData:e}),this.focuedView=this.mainView,s.createMainViewDisplayer(t),e.callbacks.on("onSizeUpdated",this.onMainViewSizeUpdated),e.callbacks.on("onCameraUpdated",this.onMainViewCameraUpdated),e.callbacks.on("onActiveHotkey",this.onActiveHotkeyChange.bind(this))});g(this,"onMainViewSizeUpdated",async()=>{await new Promise(e=>{setTimeout(()=>{e(!0)},0)}),this.mainView&&this.mainView.viewData&&this.updateMainViewCamera()});g(this,"onMainViewCameraUpdated",async()=>{await new Promise(e=>{setTimeout(()=>{e(!0)},0)}),this.updateMainViewCamera()});g(this,"updateMainViewCamera",()=>{if(this.mainView&&this.mainView.viewData){const e=this.mainView.viewData.camera,t=this.mainView.cameraOpt;if(t){const i=t.width,s=t.height,{width:n,height:r}=this.mainView.viewData.size;(n!==i||r!==s)&&this.mainView.displayer.updateSize();const c=e.scale===1/0?1:e.scale,l=e.centerX||0,h=e.centerY||0,u={...t,scale:c,centerX:l,centerY:h,width:n,height:r};D.isEqual(t,u)||(this.mainView.cameraOpt=u),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,p;(p=(d=this.mainView)==null?void 0:d.viewData)==null||p.moveCamera({scale:c,centerX:l,centerY:h,animationMode:"immediately"}),this.checkScaleTimer=void 0},500))}}});g(this,"onAppViewMounted",async e=>{var d;const{appId:t,view:i}=e,s=i.divElement;if(!s||!i.focusScenePath)return;const n=this.appViews.get(t);if(n&&n.displayer){let p=s.getElementsByClassName("appliance-plugin-app-view-displayer");for(const f of p)f.remove();if(n.container&&n.container!==s){p=n.container.getElementsByClassName("appliance-plugin-app-view-displayer");for(const f of p)f.remove()}this.destroyAppView(e.appId,!0),(d=this.control.worker)==null||d.destroyViewWorker(t,!0),await new Promise(f=>{setTimeout(()=>{f(!0)},0)})}const r=new aw(t,this.control,Se.InternalMsgEmitter),c=i.size.width||r.width,l=i.size.height||r.height,u={dpr:r.dpr,originalPoint:[c/2,l/2],offscreenCanvasOpt:{...We.defaultScreenCanvasOpt,width:c,height:l},layerOpt:{...We.defaultLayerOpt,width:c,height:l},cameraOpt:{...We.defaultCameraOpt,...i.camera,width:c,height:l}};if(this.createAppView({id:t,container:s,displayer:r,cameraOpt:u.cameraOpt,focusScenePath:i.focusScenePath,viewData:i}),r.createAppViewDisplayer(t,s),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 p=this.control.worker.getLocalWorkViewId();p&&p!==t?this.setFocuedViewId(p):this.setFocuedViewId(t),this.tmpFocusedViewId=void 0}setTimeout(()=>{this.onAppViewCameraUpdated(t)},0)});g(this,"onAppViewSizeUpdated",async e=>{await new Promise(i=>{setTimeout(()=>{i(!0)},0)});const t=this.appViews.get(e);t&&t.viewData&&this.updateAppCamera(e)});g(this,"onAppViewCameraUpdated",async e=>{await new Promise(t=>{setTimeout(()=>{t(!0)},0)}),this.updateAppCamera(e)});g(this,"updateAppCamera",e=>{const t=this.appViews.get(e);if(t&&t.viewData){const i=t.viewData.camera,s=t.cameraOpt;if(s){const{width:n,height:r}=t.viewData.size,c=s.width,l=s.height;(n!==c||r!==l)&&t.displayer.updateSize();const h=i.scale===1/0?1:i.scale,u=i.centerX||0,d=i.centerY||0,p={...s,scale:h,centerX:u,centerY:d,width:n,height:r};D.isEqual(p,s)||(t.cameraOpt=p)}}});this.control=e.control}getViewInitData(e){var i;const t=this.getView(e);if(t){const{width:s,height:n,dpr:r}=t.displayer;(i=this.control.pluginOptions.canvasOpt)!=null&&i.contextType&&(We.defaultScreenCanvasOpt.contextType=this.control.pluginOptions.canvasOpt.contextType);const c={dpr:r,originalPoint:[s/2,n/2],offscreenCanvasOpt:{...We.defaultScreenCanvasOpt,width:s,height:n},layerOpt:{...We.defaultLayerOpt,width:s,height:n},cameraOpt:{...We.defaultCameraOpt,width:s,height:n}};if(t.viewData){const{scale:l,...h}=t.viewData.camera;c.cameraOpt={...c.cameraOpt,...h,scale:l===1/0?1:l}}return c}}async mountView(e){var i,s;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&&((s=this.control.worker)==null||s.createViewWorker(e,n)),t.focusScenePath&&this.control.collector){if(this.control.collector.authStorage){const{renderAuth:r,pageAuth:c}=this.control.collector.authStorage;if(r){const l=r[e];if(l){const{render:h,hide:u,clear:d}=l;this.control.renderControl.syncRenderUids(e,h,u,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||de;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,de)}),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:s}=t;this.control.onSceneChange(s.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 Ke extends Se{constructor(e){super(e);g(this,"windowManager");g(this,"viewContainerManager");const t={control:this,internalMsgEmitter:Se.InternalMsgEmitter,publicMsgEmitter:Se.PublicMsgEmitter};this.viewContainerManager=new We(t)}init(){}activePlugin(){this.collector&&(this.collector.addAuthStateListener((e,t)=>{e&&Object.keys(e).forEach(i=>{var n;const s=(n=e[i])==null?void 0:n.newValue;this.renderControl.syncRenderUids(i,s==null?void 0:s.render,s==null?void 0:s.hide,s==null?void 0:s.clear)}),t&&Object.keys(t).forEach(i=>{var n;const s=(n=t[i])==null?void 0:n.newValue;this.renderControl.syncPageAuth(i,s)})}),this.collector.addStorageStateListener(e=>{var r,c;if((r=this.collector)!=null&&r.storage&&Object.keys(this.collector.storage).length===0){(c=this.worker)==null||c.clearViewScenePath(de,!0);return}const{diffView:t,diffScenePath:i,diffData:s}=e,n=new Map;if(t){let l;Object.keys(t).forEach(h=>{var d;const u=t[h];if(u&&!u.newValue)(d=this.worker)==null||d.clearViewScenePath(h,!0),u.oldValue&&(l=u.oldValue);else if(u&&u.newValue){for(const p of Object.keys(u.newValue))this.worker.pullServiceData(h,p,{isAsync:!1,useAnimation:!0});l=u.newValue}if(l)for(const p of Object.values(l)){const f=new Set;for(const y of Object.keys(p))y&&f.add(y);n.set(h,f)}})}if(i){let l;Object.keys(i).forEach(h=>{var d;const u=i[h];if(u&&u.viewId&&!u.newValue?((d=this.worker)==null||d.clearViewScenePath(u.viewId,!0),u.oldValue&&(l=u.oldValue)):u&&u.viewId&&u.newValue&&(this.worker.pullServiceData(u.viewId,h,{isAsync:!1,useAnimation:!0}),l=u.newValue),u!=null&&u.viewId&&l){const p=new Set;for(const f of Object.keys(l))f&&p.add(f),n.set(u.viewId,p)}})}s&&Object.keys(s).forEach(l=>{var u,d;const h=s[l];if(h){const{viewId:p}=h,f=n.get(p)||new Set;f.add(l),n.set(p,f),(u=this.worker)==null||u.onServiceDerive(l,h),(d=this.miniMapManager)==null||d.updateMiniMapCamera(p)}});for(const[l,h]of n.entries())Se.InternalMsgEmitter.emit("excludeIds",[...h],l)}),this.room&&this.roomMember.onUidChangeHook(e=>{var t,i;if((t=this.collector)!=null&&t.serviceStorage){const s=[];this.viewContainerManager.getAllViews().forEach(n=>{var r;if(n&&n.focusScenePath&&((r=this.collector)!=null&&r.serviceStorage[n.id])&&this.collector.serviceStorage[n.id][n.focusScenePath]){const c=Object.keys(this.collector.serviceStorage[n.id][n.focusScenePath]).filter(l=>{var h;return(h=this.collector)==null?void 0:h.isSelector(l)}).map(l=>({viewId:n.id,scenePath:n.focusScenePath,key:l}));c.length&&s.push(...c)}}),s.forEach(({key:n,viewId:r,scenePath:c})=>{var h,u;const l=(h=this.collector)==null?void 0:h.getUidFromKey(n);l&&!e.online.includes(l)&&((u=this.collector)==null||u.updateValue(n,void 0,{isAfterUpdate:!0,viewId:r,scenePath:c}))})}(i=this.cursor)==null||i.updateRoomMembers(e)}),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()}setWindowManager(e){var t,i,s,n,r;this.windowManager=e,(i=(t=this.windowManager)==null?void 0:t.mainView)!=null&&i.divElement&&this.viewContainerManager.onMainViewMounted(this.windowManager.mainView),(r=(n=(s=this.windowManager.appManager)==null?void 0:s.viewManager)==null?void 0:n.views)!=null&&r.size&&this.windowManager.appManager.viewManager.views.forEach((c,l)=>{this.viewContainerManager.onAppViewMounted({appId:l,view:c})}),this.viewContainerManager.listenerWindowManager(this.windowManager)}}const B=class B extends _.InvisiblePlugin{constructor(){super(...arguments);g(this,"onPhaseChanged",e=>{var t;e===_.RoomPhase.Reconnecting&&((t=B.currentManager)==null||t.setSnapshootData())});g(this,"updateRoomWritable",()=>{var e;(e=B.currentManager)==null||e.onWritableChange(this.displayer.isWritable)});g(this,"roomStateChangeListener",async e=>{var t,i;e!=null&&e.roomMembers&&((t=B.currentManager)==null||t.onRoomMembersChange(e.roomMembers)),!(_.isRoom(this.displayer)&&!this.displayer.isWritable)&&e.memberState&&((i=B.currentManager)==null||i.onMemberChange(e.memberState))})}static async getInstance(e,t){!t.options.cdn.fullWorkerUrl&&!t.options.cdn.subWorkerUrl&&B.logger.error("[ApplianceMultiPlugin] you must adaptor options cdn fullWorkerUrl and subWorkerUrl");const i=e.displayer,s=i.callbacks.on,n=i.callbacks.off,r=i.callbacks.once,c=e.cleanCurrentScene,l=e.mainView.setMemberState;t!=null&&t.logger&&(B.logger=t.logger),t.options&&(B.options={...be,...t.options});let h=i.getInvisiblePlugin(B.kind);h||(h=await B.createApplianceMultiPlugin(i,B.kind)),i&&h&&B.createCurrentManager(e,B.options,h),h&&B.currentManager&&(B.currentManager.bindPlugin(h),h.init(i));const u={displayer:i,windowManager:e,currentManager:B.currentManager,maxScreenshotWidth:10*1024,maxScreenshotHeight:10*1024,getBoundingRectAsync:async function(f){var T;B.logger.info("[ApplianceMultiPlugin] getBoundingRectAsync");const y=(e.mainView||i).getBoundingRect(f),m=await((T=B.currentManager)==null?void 0:T.getBoundingRect(f));return!y.width||!y.height?m:ti(y,m)},screenshotToCanvasAsync:async function(f,y,m,T,w,v){var j;B.logger.info("[ApplianceMultiPlugin] screenshotToCanvasAsync");let S=m,N=T,I=w.scale;S>this.maxScreenshotWidth&&(I=this.maxScreenshotWidth/S*I,S=this.maxScreenshotWidth),N>this.maxScreenshotHeight&&(I=Math.min(this.maxScreenshotHeight/N*I,I),N=this.maxScreenshotHeight),w.scale=I;const b=document.createElement("canvas"),L=b.getContext("2d");b.width=S*(v||1),b.height=N*(v||1),L&&((e.mainView||i).screenshotToCanvas(L,y,S,N,w,v),f.drawImage(b,Math.floor((m-S)/2),Math.floor((T-N)/2),S*(v||1),N*(v||1),0,0,S,N),b.remove()),B.currentManager&&await((j=B.currentManager)==null?void 0:j.screenshotToCanvas(f,y,S,N,w,Math.floor((m-S)/2),Math.floor((T-N)/2)))},scenePreviewAsync:async function(f,y,m,T,w){B.logger.info("[ApplianceMultiPlugin] scenePreviewAsync"),(e.mainView||i).scenePreview(f,y,m,T,w);const v=document.createElement("img");v.className="appliance-plugin-fill-scene-snapshot-img",y.append(v),getComputedStyle(y).position||(y.style.position="relative"),B.currentManager&&await B.currentManager.scenePreview(f,v)},fillSceneSnapshotAsync:async function(f,y,m,T,w){B.logger.info("[ApplianceMultiPlugin] fillSceneSnapshotAsync"),y.innerHTML="",(e.mainView||i).fillSceneSnapshot(f,y,m,T,w);const v=m||e.mainView.size.width,S=T||e.mainView.size.height;let N=await this.getBoundingRectAsync(f);N||(N={originX:0,originY:0,width:v,height:S});let I=Math.max(N==null?void 0:N.width,v),b=Math.max(N==null?void 0:N.height,S),L=1;const j=I>v&&Math.min(v/I,L)||L,E=b>S&&Math.min(S/b,L)||L;j<=E?(I=j<1&&v||I,b=Math.floor(b*j)+1,L=j):j>E&&(b=E<1&&S||b,I=Math.floor(I*E)+1,L=E);const A={scale:L,centerX:N.originX+N.width/2,centerY:N.originY+N.height/2},W=document.createElement("canvas"),z=W.getContext("2d");W.width=I,W.height=b,z&&await this.screenshotToCanvasAsync(z,f,I,b,A,devicePixelRatio);const O=document.createElement("img");O.className="appliance-plugin-fill-scene-snapshot-img",O.src=W.toDataURL(),O.onload=()=>{W.remove()},O.onerror=()=>{W.remove(),O.remove()},y.append(O),getComputedStyle(y).position||(y.style.position="relative")},_callbacksOn:function(f,y){B.logger.info(`[ApplianceMultiPlugin] callbacks ${f}`),(f==="onCanUndoStepsUpdate"||f==="onCanRedoStepsUpdate")&&_.isRoom(i)&&i.isWritable?Ke.InternalMsgEmitter.on(f,y):s.call(i.callbacks,f,y)},_callbacksOnce:function(f,y){B.logger.info(`[ApplianceMultiPlugin] callbacks ${f}`),(f==="onCanUndoStepsUpdate"||f==="onCanRedoStepsUpdate")&&_.isRoom(i)&&i.isWritable?Ke.InternalMsgEmitter.on(f,y):r.call(i.callbacks,f,y)},_callbacksOff:function(f,y){B.logger.info(`[ApplianceMultiPlugin] callbacks ${f}`),(f==="onCanUndoStepsUpdate"||f==="onCanRedoStepsUpdate")&&_.isRoom(i)&&i.isWritable?Ke.InternalMsgEmitter.off(f,y):n.call(i.callbacks,f,y)},canRedoSteps(){if(B.logger.info("[ApplianceMultiPlugin] canRedoSteps"),B.currentManager&&_.isRoom(i)&&!i.disableSerialization){const f=B.currentManager.viewContainerManager.focuedView,y=f==null?void 0:f.focusScenePath;if(f&&y)return f.displayer.commiter.redoStack.filter(m=>m.scenePath===y).length}return 0},canUndoSteps(){if(B.logger.info("[ApplianceMultiPlugin] canUndoSteps"),B.currentManager&&_.isRoom(i)&&!i.disableSerialization){const f=B.currentManager.viewContainerManager.focuedView,y=f==null?void 0:f.focusScenePath;if(f&&y)return f.displayer.commiter.undoStack.filter(m=>m.scenePath===y).length}return 0},undo:function(){return B.logger.info("[ApplianceMultiPlugin] undo"),B.currentManager&&_.isRoom(i)&&!i.disableSerialization?B.currentManager.viewContainerManager.undo():0},redo:function(){return B.logger.info("[ApplianceMultiPlugin] redo"),B.currentManager&&_.isRoom(i)&&!i.disableSerialization?B.currentManager.viewContainerManager.redo():0},cleanCurrentScene:function(){B.logger.info("[ApplianceMultiPlugin] cleanCurrentScene"),B.currentManager&&_.isRoom(i)&&i.isWritable&&(B.currentManager.cleanCurrentScene(),c.call(e))},insertImage:function(f){B.logger.info("[ApplianceMultiPlugin] insertImage"),B.currentManager&&_.isRoom(i)&&i.isWritable&&B.currentManager.worker.insertImage(de,f)},lockImage:function(f,y){B.logger.info("[ApplianceMultiPlugin] lockImage"),B.currentManager&&_.isRoom(i)&&i.isWritable&&B.currentManager.worker.lockImage(de,f,y)},completeImageUpload:function(f,y){B.logger.info("[ApplianceMultiPlugin] completeImageUpload"),B.currentManager&&_.isRoom(i)&&i.isWritable&&B.currentManager.worker.completeImageUpload(de,f,y)},getImagesInformation:function(f){return B.logger.info("[ApplianceMultiPlugin] completeImageUpload"),B.currentManager&&_.isRoom(i)&&i.isWritable?B.currentManager.worker.getImagesInformation(f):[]},callbacks:()=>(B.logger.info("[ApplianceMultiPlugin] callbacks bind"),{...i.callbacks,on:u._callbacksOn.bind(u),once:u._callbacksOnce.bind(u),off:u._callbacksOff.bind(u)}),destroy(){B.currentManager&&(B.logger.info("[ApplianceMultiPlugin] destroy"),B.currentManager.destroy(),B.currentManager=void 0)},setMemberState(f){B.logger.info(`[ApplianceMultiPlugin] setMemberState ${JSON.stringify(f)}`);const y=Object.keys(f);if(_.isRoom(i)&&i.isWritable){y.includes("currentApplianceName")&&(f.currentApplianceName&&f.currentApplianceName===se.laserPen?(f.currentApplianceName=se.pencil,f.useLaserPen=!0):f.currentApplianceName&&f.currentApplianceName===se.pencil&&(f.useLaserPen=!1)),l.call(e.mainView,f);return}throw new Error("[ApplianceMultiPlugin] setMemberState must be called in writable room")},setPerformancePriority(f){B.logger.info("[ApplianceMultiPlugin] setPriority"),B.currentManager&&B.currentManager.setPriority(f)},createMiniMap:async function(f,y){if(B.logger.info("[ApplianceMultiPlugin] createMiniMap"),B.currentManager&&_.isRoom(i)&&i.isWritable)return B.currentManager.createMiniMap(f,y)},destroyMiniMap:async function(f){if(B.logger.info("[ApplianceMultiPlugin] destroyeMiniMap"),B.currentManager&&_.isRoom(i)&&i.isWritable)return B.currentManager.destroyMiniMap(f)},filterRenderByUid(f,y,m){if(B.logger.info("[ApplianceMultiPlugin] filterRenderByUid"),B.currentManager&&_.isRoom(i)&&i.isWritable)return B.currentManager.filterRenderByUid(f,y,m)},cancelFilterRender(f,y){if(B.logger.info("[ApplianceMultiPlugin] filterRenderByUid"),B.currentManager&&_.isRoom(i)&&i.isWritable)return B.currentManager.cancelFilterRender(f,y)},addListener:(f,y)=>{B.logger.info(`[ApplianceMultiPlugin] addListener ${f}`),Ke.PublicMsgEmitter.on(f,y)},removeListener:(f,y)=>{B.logger.info(`[ApplianceMultiPlugin] removeListener ${f}`),Ke.PublicMsgEmitter.off(f,y)},usePlugin:f=>{var y;B.logger.info("[ApplianceMultiPlugin] usePlugin"),(y=B.currentManager)==null||y.usePlugin(f)},getDisableDeviceInputs(){if(B.logger.info("[ApplianceMultiPlugin] getDisableDeviceInputs"),B.currentManager&&_.isRoom(i))return B.currentManager.disableDeviceInputs},setDisableDeviceInputs(f){B.logger.info("[ApplianceMultiPlugin] setDisableDeviceInputs"),B.currentManager&&_.isRoom(i)&&(B.currentManager.disableDeviceInputs=f)},getDisableEraseImage(){if(B.logger.info("[ApplianceMultiPlugin] getDisableEraseImage"),B.currentManager&&_.isRoom(i))return B.currentManager.disableEraseImage},setDisableEraseImage(f){B.logger.info("[ApplianceMultiPlugin] setDisableEraseImage"),B.currentManager&&_.isRoom(i)&&(B.currentManager.disableEraseImage=f)}},d=(f,y)=>{if(B.logger.info(`[ApplianceMultiPlugin] injectMethodToObject ${y}`),typeof f[y]=="function"||typeof f[y]>"u"){f[y]=u[y];return}y==="callbacks"&&(f.callbacks.on=u._callbacksOn.bind(u),f.callbacks.off=u._callbacksOff.bind(u),f.callbacks.once=u._callbacksOnce.bind(u))};d(e,"undo"),d(e,"redo"),d(e,"cleanCurrentScene"),d(e,"insertImage"),d(e,"completeImageUpload"),d(e,"lockImage"),d(i,"getImagesInformation"),d(i,"callbacks"),d(i,"screenshotToCanvasAsync"),d(i,"getBoundingRectAsync"),d(i,"scenePreviewAsync"),d(i,"fillSceneSnapshotAsync"),d(e.mainView,"setMemberState"),Object.defineProperty(e,"canUndoSteps",{get(){return u.canUndoSteps()}}),Object.defineProperty(e,"canRedoSteps",{get(){return u.canRedoSteps()}}),Ke.InternalMsgEmitter.on("onCanUndoStepsUpdate",f=>{e.emitter.emit("canUndoStepsChange",f)}),Ke.InternalMsgEmitter.on("onCanRedoStepsUpdate",f=>{e.emitter.emit("canRedoStepsChange",f)});const p={...u,callbacks:u.callbacks()};return Object.defineProperty(p,"disableDeviceInputs",{set(f){u.setDisableDeviceInputs(f)},get(){return u.getDisableDeviceInputs()}}),Object.defineProperty(p,"disableEraseImage",{set(f){u.setDisableEraseImage(f)},get(){return u.getDisableEraseImage()}}),e._appliancePlugin=p,e._appliancePlugin}static onCreate(e){e&&B.currentManager&&(B.currentManager.bindPlugin(e),e.init(e.displayer))}static async createApplianceMultiPlugin(e,t){try{await e.createInvisiblePlugin(B,{})}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 B.createApplianceMultiPlugin(e,t)),i}get isReplay(){return _.isPlayer(this.displayer)}get callbackName(){return this.isReplay?"onPlayerStateChanged":"onRoomStateChanged"}init(e){var i,s;const t=e.state;(i=B.currentManager)==null||i.onRoomMembersChange(t.roomMembers),_.isRoom(e)&&((s=B.currentManager)==null||s.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;B.logger.info("[ApplianceMultiPlugin] passive destroy"),(e=B.currentManager)==null||e.destroy(),B.currentManager=void 0}};g(B,"kind","appliance-multi-plugin"),g(B,"currentManager"),g(B,"logger",{info:console.log,warn:console.warn,error:console.error}),g(B,"options",be),g(B,"createCurrentManager",(e,t,i)=>{B.currentManager&&B.currentManager.destroy();const s={plugin:i,displayer:e.displayer,options:t},n=new Ke(s);B.logger.info("[ApplianceMultiPlugin] refresh ApplianceMultiManager object"),n.setWindowManager(e),B.currentManager=n,e.room&&e.room.logger.info(`[ApplianceMultiPlugin] use ${Jo}`)});let Oo=B;class cw extends Ks{constructor(e,t){super(e,t);g(this,"width",1e3);g(this,"height",1e3);g(this,"dpr",Je());g(this,"vDom");g(this,"viewId",de);g(this,"eventTragetElement");g(this,"snapshotContainerRef");g(this,"canvasContainerRef",M.createRef());g(this,"subLocalCanvasContainerRef",M.createRef());g(this,"canvasTopRef",M.createRef());g(this,"canvasServiceFloatRef",M.createRef());g(this,"canvasFloatRef",M.createRef());g(this,"canvasBgRef",M.createRef());g(this,"floatBarRef",M.createRef());g(this,"containerOffset",{x:0,y:0});this.control.hasOffscreenCanvas()||(this.snapshotContainerRef=M.createRef())}setCanvassStyle(){if(this.eventTragetElement){const e=this.eventTragetElement.offsetWidth,t=this.eventTragetElement.offsetHeight;let i=Je();this.canvasBgRef.current&&(i=Je(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="",ro.render(M.createElement(si,{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 Xe extends It{constructor(e){super(e);g(this,"focuedViewId");g(this,"control");g(this,"focuedView");this.control=e.control}bindMainView(){if(!this.control.divMainView)return;const e=new cw(this.control,Se.InternalMsgEmitter);this.focuedViewId=de;const{width:t,height:i,dpr:s}=e,n={dpr:s,originalPoint:[t/2,i/2],offscreenCanvasOpt:{...Xe.defaultScreenCanvasOpt,width:t,height:i},layerOpt:{...Xe.defaultLayerOpt,width:t,height:i},cameraOpt:{...Xe.defaultCameraOpt,width:t,height:i}},r=this.control.room&&this.control.room.mainView||this.control.play&&this.control.play.mainView;if(r){const{scale:c,...l}=r.camera;n.cameraOpt={...n.cameraOpt,...l,scale:c===1/0?1:c},this.createMianView({id:de,displayer:e,focusScenePath:r.focusScenePath||r.scenePath,cameraOpt:n.cameraOpt,viewData:r}),this.focuedView=this.mainView,e.createMainViewDisplayer(this.control.divMainView)}}getViewInitData(e){var i;const t=this.getView(e);if(t){const{width:s,height:n,dpr:r}=t.displayer;(i=this.control.pluginOptions.canvasOpt)!=null&&i.contextType&&(Xe.defaultScreenCanvasOpt.contextType=this.control.pluginOptions.canvasOpt.contextType);const c={dpr:r,originalPoint:[s/2,n/2],offscreenCanvasOpt:{...Xe.defaultScreenCanvasOpt,width:s,height:n},layerOpt:{...Xe.defaultLayerOpt,width:s,height:n},cameraOpt:{...Xe.defaultCameraOpt,width:s,height:n}};if(t.viewData){const{scale:l,...h}=t.viewData.camera;c.cameraOpt={...c.cameraOpt,...h,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 s=this.getViewInitData(e);s&&((i=this.control.worker)==null||i.createViewWorker(e,s)),t.focusScenePath&&this.control.collector&&this.control.worker.pullServiceData(e,t.focusScenePath,{isAsync:!0,useAnimation:!1})}}}class Ue extends Se{constructor(e){super(e);g(this,"viewContainerManager");g(this,"divMainView");g(this,"onCameraChange",Ot(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)},yo,{leading:!1}));const t={control:this,internalMsgEmitter:Ue.InternalMsgEmitter,publicMsgEmitter:Ue.PublicMsgEmitter};this.viewContainerManager=new Xe(t)}init(){Ue.InternalMsgEmitter.on(q.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 r,c;if((r=this.collector)!=null&&r.storage&&Object.keys(this.collector.storage).length===0){(c=this.worker)==null||c.clearViewScenePath(de,!0);return}const{diffView:t,diffScenePath:i,diffData:s}=e,n=new Map;if(t){let l;Object.keys(t).forEach(h=>{var d;const u=t[h];if(u&&!u.newValue)(d=this.worker)==null||d.clearViewScenePath(h,!0),u.oldValue&&(l=u.oldValue);else if(u&&u.newValue){for(const p of Object.keys(u.newValue))this.worker.pullServiceData(h,p,{isAsync:!1,useAnimation:!0});l=u.newValue}if(l)for(const p of Object.values(l)){const f=new Set;for(const y of Object.keys(p))y&&f.add(y);n.set(h,f)}})}if(i){let l;Object.keys(i).forEach(h=>{var d;const u=i[h];if(u&&u.viewId&&!u.newValue?((d=this.worker)==null||d.clearViewScenePath(u.viewId,!0),u.oldValue&&(l=u.oldValue)):u&&u.viewId&&u.newValue&&(this.worker.pullServiceData(u.viewId,h,{isAsync:!1,useAnimation:!0}),l=u.newValue),u!=null&&u.viewId&&l){const p=new Set;for(const f of Object.keys(l))f&&p.add(f),n.set(u.viewId,p)}})}s&&Object.keys(s).forEach(l=>{var u,d;const h=s[l];if(h){const{viewId:p}=h,f=n.get(p)||new Set;f.add(l),n.set(p,f),(u=this.worker)==null||u.onServiceDerive(l,h),(d=this.miniMapManager)==null||d.updateMiniMapCamera(p)}});for(const[l,h]of n.entries())Se.InternalMsgEmitter.emit("excludeIds",[...h],l)}),this.room&&(this.roomMember.onUidChangeHook(e=>{var t,i,s,n;if((t=this.collector)!=null&&t.serviceStorage){const r=[];this.viewContainerManager.getAllViews().forEach(c=>{var l,h,u;if(c&&c.focusScenePath&&((l=this.collector)!=null&&l.serviceStorage[c.id])&&((h=this.collector)!=null&&h.serviceStorage[c.id][c.focusScenePath])){const d=Object.keys((u=this.collector)==null?void 0:u.serviceStorage[c.id][c.focusScenePath]).filter(p=>{var f;return(f=this.collector)==null?void 0:f.isSelector(p)}).map(p=>({viewId:c.id,scenePath:c.focusScenePath,key:p}));d.length&&r.push(...d)}}),r.forEach(({key:c,viewId:l,scenePath:h})=>{var d,p;const u=(d=this.collector)==null?void 0:d.getUidFromKey(c);u&&!e.online.includes(u)&&((p=this.collector)==null||p.updateValue(c,void 0,{isAfterUpdate:!0,viewId:l,scenePath:h}))})}(s=(i=this.cursor)==null?void 0:i.eventCollector)!=null&&s.serviceStorage&&Object.keys((n=this.cursor)==null?void 0:n.eventCollector.serviceStorage).forEach(c=>{var l,h;e.online.includes(c)||(h=(l=this.cursor)==null?void 0:l.eventCollector)==null||h.clearValue(c)})}),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 R=class R extends _.InvisiblePlugin{constructor(){super(...arguments);g(this,"onPhaseChanged",e=>{var t;e===_.RoomPhase.Reconnecting&&((t=R.currentManager)==null||t.setSnapshootData())});g(this,"updateRoomWritable",()=>{var e;(e=R.currentManager)==null||e.onWritableChange(this.displayer.isWritable)});g(this,"roomStateChangeListener",async e=>{var t,i;R.currentManager instanceof Ue&&(e.cameraState&&R.currentManager.onCameraChange(e.cameraState),e.sceneState&&R.currentManager.onSceneChange(e.sceneState.scenePath,de)),e!=null&&e.roomMembers&&((t=R.currentManager)==null||t.onRoomMembersChange(e.roomMembers)),!(_.isRoom(this.displayer)&&!this.displayer.isWritable)&&e.memberState&&((i=R.currentManager)==null||i.onMemberChange(e.memberState))})}static async getInstance(e,t){const i=e.callbacks.on,s=e.callbacks.off,n=e.callbacks.once,r=e.cleanCurrentScene.bind(e),c=e.setMemberState.bind(e);t!=null&&t.logger&&(R.logger=t.logger),t.options&&(R.options={...be,...t.options});let l=e.getInvisiblePlugin(R.kind);l||(l=await R.createAppliancePlugin(e,R.kind)),e&&l&&R.createCurrentManager(e,R.options,l),l&&R.currentManager&&(R.currentManager.bindPlugin(l),l.init(e)),t!=null&&t.cursorAdapter&&(R.cursorAdapter=t.cursorAdapter),R.effectInstance();const h={displayer:e,currentManager:R.currentManager,maxScreenshotWidth:10*1024,maxScreenshotHeight:10*1024,_injectTargetObject:void 0,getBoundingRectAsync:async function(p){var m;R.logger.info("[ApplianceSinglePlugin] getBoundingRectAsync");const f=e.getBoundingRect(p),y=await((m=R.currentManager)==null?void 0:m.getBoundingRect(p));return!f.width||!f.height?y:ti(f,y)},screenshotToCanvasAsync:async function(p,f,y,m,T,w){var L;R.logger.info("[ApplianceSinglePlugin] screenshotToCanvasAsync");let v=y,S=m,N=T.scale;v>this.maxScreenshotWidth&&(N=this.maxScreenshotWidth/v*N,v=this.maxScreenshotWidth),S>this.maxScreenshotHeight&&(N=Math.min(this.maxScreenshotHeight/S*N,N),S=this.maxScreenshotHeight),T.scale=N;const I=document.createElement("canvas"),b=I.getContext("2d");I.width=v*(w||1),I.height=S*(w||1),b&&(e.screenshotToCanvas(b,f,v,S,T,w),p.drawImage(I,Math.floor((y-v)/2),Math.floor((m-S)/2),v*(w||1),S*(w||1),0,0,v,S),I.remove()),R.currentManager&&await((L=R.currentManager)==null?void 0:L.screenshotToCanvas(p,f,v,S,T,Math.floor((y-v)/2),Math.floor((m-S)/2)))},scenePreviewAsync:async function(p,f,y,m,T){R.logger.info("[ApplianceSinglePlugin] scenePreviewAsync"),e.scenePreview(p,f,y,m,T);const w=document.createElement("img");w.className="appliance-plugin-fill-scene-snapshot-img",f.append(w),getComputedStyle(f).position||(f.style.position="relative"),R.currentManager&&await R.currentManager.scenePreview(p,w)},fillSceneSnapshotAsync:async function(p,f,y,m,T){var O,ne;R.logger.info("[ApplianceSinglePlugin] fillSceneSnapshotAsync"),f.innerHTML="",e.fillSceneSnapshot(p,f,y,m,T);const w=y||((O=e.state.cameraState)==null?void 0:O.width)||0,v=m||((ne=e.state.cameraState)==null?void 0:ne.height)||0;let S=await this.getBoundingRectAsync(p);S||(S={originX:0,originY:0,width:w,height:v});let N=Math.max(S==null?void 0:S.width,w),I=Math.max(S==null?void 0:S.height,v),b=1;const L=N>w&&Math.min(w/N,b)||b,j=I>v&&Math.min(v/I,b)||b;L<=j?(N=L<1&&w||N,I=Math.floor(I*L)+1,b=L):L>j&&(I=j<1&&v||I,N=Math.floor(N*j)+1,b=j);const E={scale:b,centerX:S.originX+S.width/2,centerY:S.originY+S.height/2},A=document.createElement("canvas"),W=A.getContext("2d");A.width=N,A.height=I,W&&await this.screenshotToCanvasAsync(W,p,N,I,E,devicePixelRatio);const z=document.createElement("img");z.className="appliance-plugin-fill-scene-snapshot-img",z.src=A.toDataURL(),z.onload=()=>{A.remove()},z.onerror=()=>{A.remove(),z.remove()},f.append(z),getComputedStyle(f).position||(f.style.position="relative")},_callbacksOn:function(p,f){R.logger.info(`[ApplianceSinglePlugin] callbacks ${p}`),(p==="onCanUndoStepsUpdate"||p==="onCanRedoStepsUpdate")&&_.isRoom(e)&&e.isWritable?Ue.InternalMsgEmitter.on(p,f):i.call(e.callbacks,p,f)},_callbacksOnce:function(p,f){R.logger.info(`[ApplianceSinglePlugin] callbacks ${p}`),(p==="onCanUndoStepsUpdate"||p==="onCanRedoStepsUpdate")&&_.isRoom(e)&&e.isWritable?Ue.InternalMsgEmitter.on(p,f):n.call(e.callbacks,p,f)},_callbacksOff:function(p,f){R.logger.info(`[ApplianceSinglePlugin] callbacks ${p}`),(p==="onCanUndoStepsUpdate"||p==="onCanRedoStepsUpdate")&&_.isRoom(e)&&e.isWritable?Ue.InternalMsgEmitter.off(p,f):s.call(e.callbacks,p,f)},canRedoSteps(){if(R.logger.info("[ApplianceSinglePlugin] canRedoSteps"),R.currentManager&&_.isRoom(e)&&!e.disableSerialization){const p=R.currentManager.viewContainerManager.focuedView,f=p==null?void 0:p.focusScenePath;if(p&&f)return p.displayer.commiter.redoStack.filter(y=>y.scenePath===f).length}return 0},canUndoSteps(){if(R.logger.info("[ApplianceSinglePlugin] canUndoSteps"),R.currentManager&&_.isRoom(e)&&!e.disableSerialization){const p=R.currentManager.viewContainerManager.focuedView,f=p==null?void 0:p.focusScenePath;if(p&&f)return p.displayer.commiter.undoStack.filter(y=>y.scenePath===f).length}return 0},undo:function(){return R.logger.info("[ApplianceSinglePlugin] undo"),R.currentManager&&_.isRoom(e)&&!e.disableSerialization?R.currentManager.viewContainerManager.undo():0},redo:function(){return R.logger.info("[ApplianceSinglePlugin] redo"),R.currentManager&&_.isRoom(e)&&!e.disableSerialization?R.currentManager.viewContainerManager.redo():0},cleanCurrentScene:function(p){R.logger.info("[ApplianceSinglePlugin] cleanCurrentScene"),R.currentManager&&_.isRoom(e)&&e.isWritable&&(R.currentManager.cleanCurrentScene(),r.call(e,p))},insertImage:function(p){R.logger.info("[ApplianceSinglePlugin] insertImage"),R.currentManager&&_.isRoom(e)&&e.isWritable&&R.currentManager.worker.insertImage(de,p)},lockImage:function(p,f){R.logger.info("[ApplianceSinglePlugin] lockImage"),R.currentManager&&_.isRoom(e)&&e.isWritable&&R.currentManager.worker.lockImage(de,p,f)},completeImageUpload:function(p,f){R.logger.info("[ApplianceSinglePlugin] completeImageUpload"),R.currentManager&&_.isRoom(e)&&e.isWritable&&R.currentManager.worker.completeImageUpload(de,p,f)},getImagesInformation:function(p){return R.logger.info("[ApplianceSinglePlugin] completeImageUpload"),R.currentManager&&_.isRoom(e)&&e.isWritable?R.currentManager.worker.getImagesInformation(p):[]},callbacks:()=>({...e.callbacks,on:h._callbacksOn.bind(h),once:h._callbacksOnce.bind(h),off:h._callbacksOff.bind(h)}),destroy(){R.currentManager&&(R.logger.info("[ApplianceSinglePlugin] destroy"),R.currentManager.destroy(),R.currentManager=void 0,R.cursorAdapter=void 0)},setMemberState(p){R.logger.info(`[ApplianceSinglePlugin] setMemberState ${JSON.stringify(p)}`);const f=Object.keys(p);if(_.isRoom(e)&&e.isWritable){f.includes("currentApplianceName")&&(p.currentApplianceName&&p.currentApplianceName===se.laserPen?(p.currentApplianceName=se.pencil,p.useLaserPen=!0):p.currentApplianceName&&p.currentApplianceName===se.pencil&&(p.useLaserPen=!1)),c(p);return}throw new Error("setMemberState must be called in writable room")},setPerformancePriority(p){R.logger.info("[ApplianceSinglePlugin] setPriority"),R.currentManager&&R.currentManager.setPriority(p)},createMiniMap:async function(p,f){if(R.logger.info("[ApplianceSinglePlugin] createMiniMap"),R.currentManager&&_.isRoom(e)&&e.isWritable)return R.currentManager.createMiniMap(p,f)},destroyMiniMap:async function(p){if(R.logger.info("[ApplianceMultiPlugin] destroyeMiniMap"),R.currentManager&&_.isRoom(e)&&e.isWritable)return R.currentManager.destroyMiniMap(p)},filterRenderByUid(p,f,y){if(R.logger.info("[ApplianceSinglePlugin] filterRenderByUid"),R.currentManager&&_.isRoom(e)&&e.isWritable)return R.currentManager.filterRenderByUid(p,f,y)},cancelFilterRender(p,f){if(R.logger.info("[ApplianceSinglePlugin] filterRenderByUid"),R.currentManager&&_.isRoom(e)&&e.isWritable)return R.currentManager.cancelFilterRender(p,f)},addListener:(p,f)=>{R.logger.info(`[ApplianceSinglePlugin] addListener ${p}`),Ue.PublicMsgEmitter.on(p,f)},removeListener:(p,f)=>{R.logger.info(`[ApplianceSinglePlugin] removeListener ${p}`),Ue.PublicMsgEmitter.off(p,f)},usePlugin:p=>{var f;R.logger.info("[ApplianceSinglePlugin] usePlugin"),(f=R.currentManager)==null||f.usePlugin(p)},getDisableDeviceInputs(){if(R.logger.info("[ApplianceSinglePlugin] getDisableDeviceInputs"),R.currentManager&&_.isRoom(e))return R.currentManager.disableDeviceInputs},setDisableDeviceInputs(p){R.logger.info("[ApplianceSinglePlugin] setDisableDeviceInputs"),R.currentManager&&_.isRoom(e)&&(R.currentManager.disableDeviceInputs=p)},getDisableEraseImage(){if(R.logger.info("[ApplianceSinglePlugin] getDisableEraseImage"),R.currentManager&&_.isRoom(e))return R.currentManager.disableEraseImage},setDisableEraseImage(p){R.logger.info("[ApplianceSinglePlugin] setDisableEraseImage"),R.currentManager&&_.isRoom(e)&&(R.currentManager.disableEraseImage=p)}},u=(p,f)=>{if(R.logger.info(`[ApplianceSinglePlugin] injectMethodToObject ${f}`),typeof p[f]=="function"||typeof p[f]>"u"){p[f]=h[f];return}f==="callbacks"&&(p.callbacks.on=h._callbacksOn.bind(h),p.callbacks.off=h._callbacksOff.bind(h),p.callbacks.once=h._callbacksOnce.bind(h))};u(e,"undo"),u(e,"redo"),u(e,"cleanCurrentScene"),u(e,"insertImage"),u(e,"completeImageUpload"),u(e,"lockImage"),u(e,"getImagesInformation"),u(e,"callbacks"),u(e,"screenshotToCanvasAsync"),u(e,"getBoundingRectAsync"),u(e,"scenePreviewAsync"),u(e,"fillSceneSnapshotAsync"),u(e,"setMemberState"),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(p){h.setDisableDeviceInputs(p)},get(){return h.getDisableDeviceInputs()}}),Object.defineProperty(d,"disableEraseImage",{set(p){h.setDisableEraseImage(p)},get(){return h.getDisableEraseImage()}}),e._appliancePlugin=d,e._appliancePlugin}static onCreate(e){e&&R.currentManager&&(R.currentManager.bindPlugin(e),e.init(e.displayer))}static async createAppliancePlugin(e,t){try{await e.createInvisiblePlugin(R,{})}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 R.createAppliancePlugin(e,t)),i}static effectInstance(){if(R.cursorAdapter){const e=R.cursorAdapter.onAddedCursor;R.cursorAdapter.onAddedCursor=function(t){t.onCursorMemberChanged=i=>{try{i.appliance===se.pencil||i.appliance===se.shape||i.appliance===se.text||i.appliance===se.arrow||i.appliance===se.straight||i.appliance===se.rectangle||i.appliance===se.ellipse||i.appliance===se.eraser?t!=null&&t.divElement&&(t.divElement.style.display="none"):t!=null&&t.divElement&&(t.divElement.style.display="block")}catch{}},e.call(R.cursorAdapter,t)}}}get isReplay(){return _.isPlayer(this.displayer)}get callbackName(){return this.isReplay?"onPlayerStateChanged":"onRoomStateChanged"}init(e){var i,s;const t=e.state;(i=R.currentManager)==null||i.onRoomMembersChange(t.roomMembers),_.isRoom(e)&&t!=null&&t.memberState&&((s=R.currentManager)==null||s.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;R.logger.info("[ApplianceSinglePlugin] passive destroy"),(e=R.currentManager)==null||e.destroy(),R.currentManager=void 0,R.cursorAdapter=void 0}};g(R,"kind","appliance-aids-single-plugin"),g(R,"cursorAdapter"),g(R,"currentManager"),g(R,"logger",{info:console.log,warn:console.warn,error:console.error}),g(R,"options",be),g(R,"createCurrentManager",(e,t,i)=>{R.currentManager&&R.currentManager.destroy();const s={plugin:i,displayer:e,options:t},n=new Ue(s);n.init(),R.logger.info("[ApplianceSinglePlugin] refresh ApplianceSingleManager object"),R.currentManager=n,_.isRoom(e)&&e.logger.info(`[ApplianceSinglePlugin] use ${Jo}`)});let Ro=R;const wt=class wt extends M.Component{constructor(){super(...arguments);g(this,"mainViewRef",null)}componentDidMount(){wt.emiter||(wt.emiter=Ue.InternalMsgEmitter),wt.emiter.emit(q.BindMainView,this.mainViewRef)}render(){return M.createElement(M.Fragment,null,this.props.children,M.createElement("div",{className:"appliance-plugin-main-view-displayer",ref:e=>this.mainViewRef=e}))}};g(wt,"emiter");let Yo=wt;class lw extends Xs{constructor(e){super();g(this,"kind","autoDraw");g(this,"localStorage",[]);g(this,"excludeStorage",[]);g(this,"timer");g(this,"hostServer");g(this,"iconsContainer");g(this,"icons",[]);g(this,"iconRect");g(this,"isActive",!1);g(this,"viewId",de);g(this,"scenePath");g(this,"delay",2e3);const{container:t,hostServer:i,delay:s}=e;this.hostServer=i,this.iconsContainer=t,this.delay=s||2e3}get collector(){return this.control.collector}onDestroy(){this.unMount()}onCreate(){}onSetToolkey(e){e===k.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(s=>{var n;return((n=this.collector)==null?void 0:n.getLocalId(s))||s})}getOwnStorage(e,t){var n,r;if(!e||!t)return[];const i=(r=(n=this.collector)==null?void 0:n.storage[e])==null?void 0:r[t];return i?Object.keys(i).filter(c=>{var l,h;return((l=this.collector)==null?void 0:l.isOwn(c))&&((h=i[c])==null?void 0:h.toolsType)===k.Pencil&&!this.excludeStorage.includes(c)}):[]}async batchLocalDraw(){var r;if(this.localStorage.length===0||!this.scenePath||!((r=this.collector)==null?void 0:r.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:s,uuid:n}=i;if(n===t&&s){const c={rect:{centerX:0,centerY:0,width:0,height:0},ink:[]};let l;const h=[];for(const{rect:u,op:d}of s){l=ae(l,u);const p=[],f=[];for(let y=0;y<d.length;y+=3){p.push(d[y]),f.push(d[y+1]);const m=h.length&&h[h.length-1]||0;y===0?h.length===0?h.push(0):h.push(m+100):h.push(m+15)}c.ink.push([p,f,h])}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 s=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=s||[]}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(s=>{const n=document.createElement("img");n.src=`https://api.iconify.design/${s}.svg?color=${t}`,n.onclick=()=>{this.onClickIcon(s)},n.onload=()=>{e.appendChild(n)}}),this.iconsContainer.appendChild(e)}onClickIcon(e){var t,i;if(this.iconRect){const s=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 r=Date.now().toString();this.control.worker.removeNodes(this.viewId,this.localStorage),this.localStorage.length=0,this.control.insertIconify(this.viewId,{uuid:r,centerX:s[0],centerY:s[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)===k.Pencil)switch(t){case P.Start:this.timer&&(clearTimeout(this.timer),this.timer=void 0);break;case P.Done:this.timer&&clearTimeout(this.timer),this.timer=setTimeout(async()=>{this.timer=void 0;const s=await this.batchLocalDraw();s&&(await this.computAutoDraw(s),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=Ki;exports.ApplianceMultiPlugin=Oo;exports.ApplianceNames=se;exports.ApplianceSigleWrapper=Yo;exports.ApplianceSinglePlugin=Ro;exports.AutoDrawPlugin=lw;exports.Cursor_Hover_Id=Qf;exports.DefaultAppliancePluginOptions=be;exports.ECanvasShowType=ye;exports.EDataType=F;exports.EImageType=ht;exports.EMatrixrRelationType=jt;exports.EOperationType=Pe;exports.EPostMessageType=x;exports.ERenderFilterType=Qe;exports.EScaleType=re;exports.EStrokeType=oe;exports.EToolsKey=k;exports.ElayerType=lt;exports.EmitEventType=Y;exports.EventMessageType=At;exports.EvevtWorkState=P;exports.EvevtWorkType=_i;exports.InternalMsgEmitterType=q;exports.Main_View_Id=de;exports.Plugin=Xs;exports.ShapeType=$e;exports.Storage_Selector_key=H;exports.Storage_Splitter=Ae;exports.Storage_ViewId_ALL=Gt;exports.Task_Time_Interval=yo;exports.VNodeManager=Fs;exports.ViewContainerManager=It;exports.computRect=ae;exports.fullWorker=rn;exports.getRectMatrixrRelation=wM;exports.getShapeInstance=go;exports.isEqual=et;exports.isIntersectForPoint=Zs;exports.isNumber=Oe;exports.subWorker=an;exports.throttle=Ot;exports.transformToNormalData=it;exports.transformToSerializableData=Re;
|