@netless/appliance-plugin 1.1.36-beta.0 → 1.1.36-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/READMA.zh-CN.md +36 -0
  2. package/README.md +6 -0
  3. package/cdn/cdn.js +1 -1
  4. package/cdn/{fullWorker-Cu37fr.js → fullWorker-uAwmRi.js} +110 -110
  5. package/cdn/{subWorker-le1nnC.js → subWorker-BVNpAC.js} +110 -110
  6. package/dist/appliance-plugin.js +1 -1
  7. package/dist/appliance-plugin.mjs +1 -1
  8. package/dist/assets/fullWorker-B_mvkoeW.js +593 -0
  9. package/dist/assets/subWorker-CRdsidWT.js +593 -0
  10. package/dist/{bridge-DskXXarZ.mjs → bridge-DYkH1J6p.mjs} +6 -6
  11. package/dist/{bridge-DO3A2FRh.js → bridge-enxPG6qf.js} +1 -1
  12. package/dist/bridge.js +1 -1
  13. package/dist/bridge.mjs +1 -1
  14. package/dist/collector/collector.d.ts +1 -0
  15. package/dist/collector/types.d.ts +5 -1
  16. package/dist/component/textEditor/manager.d.ts +9 -1
  17. package/dist/component/textEditor/types.d.ts +5 -0
  18. package/dist/component/textEditor/utils.d.ts +21 -0
  19. package/dist/component/textEditor/view.d.ts +0 -4
  20. package/dist/core/enum.d.ts +3 -1
  21. package/dist/core/mainEngine.d.ts +4 -1
  22. package/dist/core/msgEvent/copyNode/forMain.d.ts +3 -0
  23. package/dist/core/msgEvent/copyNode/utils.d.ts +9 -0
  24. package/dist/core/msgEvent/deleteNode/forMain.d.ts +1 -0
  25. package/dist/core/msgEvent/setColor/forMain.d.ts +2 -0
  26. package/dist/core/msgEvent/setFont/forMain.d.ts +1 -0
  27. package/dist/core/msgEvent/setLock/forMain.d.ts +1 -0
  28. package/dist/core/msgEvent/setShape/forMain.d.ts +1 -0
  29. package/dist/core/msgEvent/setZIndex/forMain.d.ts +2 -0
  30. package/dist/core/tools/pencil.d.ts +1 -0
  31. package/dist/core/tools/selector.d.ts +4 -0
  32. package/dist/core/types.d.ts +6 -0
  33. package/dist/core/worker/fullWorkerLocal.d.ts +4 -4
  34. package/dist/core/worker/simpleWorker.d.ts +2 -2
  35. package/dist/displayer/floatBar/dragBox/activateSelectorText.d.ts +13 -0
  36. package/dist/displayer/floatBar/dragBox/selectorSwitch.d.ts +19 -0
  37. package/dist/fullWorker.js +110 -110
  38. package/dist/index-2On9v0Ff.mjs +19693 -0
  39. package/dist/index-BSD0B_eV.js +1 -0
  40. package/dist/{index-BBcEMXkc.mjs → index-BZql6xgR.mjs} +1 -1
  41. package/dist/index-Bm90lQii.js +1 -0
  42. package/dist/{index-B4Npl8dw.mjs → index-BrJL-fin.mjs} +3253 -3069
  43. package/dist/{index-vfn-RVQz.js → index-CIjmeY9J.js} +1 -1
  44. package/dist/{index-CqQPnW7_.js → index-CcS9cKSp.js} +1 -1
  45. package/dist/index-D4z0hSjm.js +1 -0
  46. package/dist/{index-BVkfyJQn.mjs → index-D8SnD90W.mjs} +1 -1
  47. package/dist/index-DbI0V6BY.mjs +19719 -0
  48. package/dist/{index-DDULymwD.mjs → index-K9QVPOhV.mjs} +3253 -3069
  49. package/dist/index-W9Jz9E04.js +1 -0
  50. package/dist/plugin/baseApplianceManager.d.ts +7 -0
  51. package/dist/plugin/baseViewContainerManager.d.ts +23 -9
  52. package/dist/plugin/displayerView.d.ts +4 -1
  53. package/dist/plugin/elementCapability.d.ts +29 -0
  54. package/dist/plugin/multi/displayer/appViewDisplayerManager.d.ts +1 -0
  55. package/dist/plugin/multi/displayer/mainViewDisplayerManager.d.ts +1 -0
  56. package/dist/plugin/selectorApi.d.ts +135 -0
  57. package/dist/plugin/single/displayer/mainViewDisplayerManager.d.ts +1 -0
  58. package/dist/plugin/types.d.ts +334 -5
  59. package/dist/plugin/utils.d.ts +9 -0
  60. package/dist/style.css +1 -1
  61. package/dist/subWorker.js +110 -110
  62. package/dist/undo/index.d.ts +45 -4
  63. package/dist/undo/timing.d.ts +50 -0
  64. package/package.json +12 -1
  65. package/dist/assets/fullWorker-C_pHxd3d.js +0 -593
  66. package/dist/assets/subWorker-mLNCeIEX.js +0 -593
  67. package/dist/bridge-white-web-sdk.d.ts +0 -1
  68. package/dist/index-B00mKJ2E.js +0 -1
  69. package/dist/index-BAT55jp1.mjs +0 -16599
  70. package/dist/index-D50QxS0c.js +0 -1
  71. package/dist/index-DTMQbvIh.mjs +0 -16625
  72. package/dist/index-DlkXPynh.js +0 -1
  73. package/dist/index-DoKk1ccL.js +0 -1
@@ -0,0 +1 @@
1
+ "use strict";var No=Object.defineProperty;var Co=(o,n,e)=>n in o?No(o,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[n]=e;var I=(o,n,e)=>Co(o,typeof n!="symbol"?n+"":n,e);const Sr=require("./bridge-enxPG6qf.js");require("spritejs");const vr=require("lz-string");require("clipper-lib");require("lineclip");const Bn=require("xss"),z=require("lodash"),Wn=require("eventemitter2"),f=require("react"),pn=require("react-dom"),Ot=require("react-draggable"),ko=require("re-resizable");var re=(o=>(o.selector="selector",o.clicker="clicker",o.laserPointer="laserPointer",o.pencil="pencil",o.rectangle="rectangle",o.ellipse="ellipse",o.shape="shape",o.eraser="eraser",o.pencilEraser="pencilEraser",o.text="text",o.straight="straight",o.arrow="arrow",o.hand="hand",o.laserPen="laserPen",o))(re||{}),ce=(o=>(o.Normal="Normal",o.Stroke="Stroke",o.Dotted="Dotted",o.LongDotted="LongDotted",o))(ce||{}),Be=(o=>(o.Triangle="triangle",o.Rhombus="rhombus",o.Pentagram="pentagram",o.SpeechBalloon="speechBalloon",o.Star="star",o.Polygon="polygon",o))(Be||{}),R=(o=>(o.None="None",o.ShowFloatBar="ShowFloatBar",o.ZIndexFloatBar="ZIndexFloatBar",o.DeleteNode="DeleteNode",o.CopyNode="CopyNode",o.ZIndexNode="ZIndexNode",o.ZIndexBackgroundSVG="ZIndexBackgroundSVG",o.RotateNode="RotateNode",o.SetColorNode="SetColorNode",o.TranslateNode="TranslateNode",o.ScaleNode="ScaleNode",o.OriginalEvent="OriginalEvent",o.CreateScene="CreateScene",o.ActiveCursor="ActiveCursor",o.MoveCursor="MoveCursor",o.CommandEditor="CommandEditor",o.SetEditorData="SetEditorData",o.SetFontStyle="SetFontStyle",o.SetPoint="SetPoint",o.SetLock="SetLock",o.SetShapeOpt="SetShapeOpt",o.CameraChange="CameraChange",o.ActiveMethod="ActiveMethod",o.HidFloatBarBtn="HidFloatBarBtn",o.SelectMethod="SelectMethod",o))(R||{}),te=(o=>(o.MainEngine="MainEngine",o.Cursor="Cursor",o.BindMainView="BindMainView",o))(te||{}),Nr=(o=>(o[o.MainView=0]="MainView",o[o.Plugin=1]="Plugin",o[o.Both=2]="Both",o))(Nr||{}),ri=(o=>(o.longPencil="longPencil",o))(ri||{}),T=(o=>(o[o.Pencil=1]="Pencil",o[o.Eraser=2]="Eraser",o[o.PencilEraser=3]="PencilEraser",o[o.BitMapEraser=4]="BitMapEraser",o[o.Selector=5]="Selector",o[o.Clicker=6]="Clicker",o[o.Arrow=7]="Arrow",o[o.Hand=8]="Hand",o[o.LaserPen=9]="LaserPen",o[o.Text=10]="Text",o[o.Straight=11]="Straight",o[o.Rectangle=12]="Rectangle",o[o.Ellipse=13]="Ellipse",o[o.Star=14]="Star",o[o.Triangle=15]="Triangle",o[o.Rhombus=16]="Rhombus",o[o.Polygon=17]="Polygon",o[o.SpeechBalloon=18]="SpeechBalloon",o[o.Image=19]="Image",o[o.BackgroundSVG=20]="BackgroundSVG",o))(T||{}),J=(o=>(o[o.Local=1]="Local",o[o.Service=2]="Service",o[o.Worker=3]="Worker",o))(J||{}),E=(o=>(o[o.Pending=0]="Pending",o[o.Start=1]="Start",o[o.Doing=2]="Doing",o[o.Done=3]="Done",o[o.Unwritable=4]="Unwritable",o))(E||{}),W=(o=>(o[o.None=0]="None",o[o.Init=1]="Init",o[o.UpdateCamera=2]="UpdateCamera",o[o.UpdateTools=3]="UpdateTools",o[o.CreateWork=4]="CreateWork",o[o.DrawWork=5]="DrawWork",o[o.FullWork=6]="FullWork",o[o.UpdateNode=7]="UpdateNode",o[o.RemoveNode=8]="RemoveNode",o[o.Clear=9]="Clear",o[o.Select=10]="Select",o[o.Destroy=11]="Destroy",o[o.Snapshot=12]="Snapshot",o[o.BoundingBox=13]="BoundingBox",o[o.Cursor=14]="Cursor",o[o.TextUpdate=15]="TextUpdate",o[o.GetTextActive=16]="GetTextActive",o[o.TasksQueue=17]="TasksQueue",o[o.CursorHover=18]="CursorHover",o[o.CursorBlur=19]="CursorBlur",o[o.Console=20]="Console",o[o.GetImageBitMap=23]="GetImageBitMap",o[o.AuthWriter=24]="AuthWriter",o[o.AuthReader=25]="AuthReader",o[o.AuthClear=26]="AuthClear",o[o.AuthPage=27]="AuthPage",o[o.GetVNodeInfo=28]="GetVNodeInfo",o[o.UpdateDpr=29]="UpdateDpr",o[o.SetFontFace=30]="SetFontFace",o[o.ReportError=31]="ReportError",o[o.ReportLog=32]="ReportLog",o[o.BackgroundSVGUpdate=33]="BackgroundSVGUpdate",o[o.BackgroundSVGDelete=34]="BackgroundSVGDelete",o[o.SelectorTransform=35]="SelectorTransform",o))(W||{}),Ze=(o=>(o[o.None=0]="None",o[o.Bg=1]="Bg",o[o.ServiceFloat=2]="ServiceFloat",o[o.Float=3]="Float",o[o.TopFloat=4]="TopFloat",o))(Ze||{}),Kt=(o=>(o[o.Cursor=1]="Cursor",o[o.TextCreate=2]="TextCreate",o))(Kt||{}),st=(o=>(o[o.Top=1]="Top",o[o.Bottom=2]="Bottom",o))(st||{}),Oe=(o=>(o[o.none=1]="none",o[o.all=2]="all",o[o.both=3]="both",o[o.proportional=4]="proportional",o))(Oe||{}),jt=(o=>(o[o.inside=0]="inside",o[o.outside=1]="outside",o[o.intersect=2]="intersect",o))(jt||{}),je=(o=>(o.renderPage="renderPage",o.addPage="addPage",o.deletePage="deletePage",o.addElement="addElement",o.deleteElement="deleteElement",o.clearPage="clearPage",o.clearViewScenePath="clearViewScenePath",o.clearView="clearView",o.syncUndoStack="syncUndoStack",o.syncRedoStack="syncRedoStack",o))(je||{}),He=(o=>(o.setAuth="setAuth",o.setShow="addShow",o.setHide="setHide",o.setClear="setClear",o))(He||{}),At=(o=>(o.Image="image",o.Iconify="iconify",o))(At||{}),Et=(o=>(o.url="url",o.markmap="markmap",o))(Et||{});const Cr="cursorhover",Mn=20,ie="mainView",xo=Sr.getWhiteWebSdkBridgeRuntime(),{toJS:cn,autorun:jn,isRoom:Q,isPlayer:oi,InvisiblePlugin:kr,RoomPhase:xr}=xo,bo={linear:o=>o,easeInQuad:o=>o*o,easeOutQuad:o=>o*(2-o),easeInOutQuad:o=>o<.5?2*o*o:-1+(4-2*o)*o,easeInCubic:o=>o*o*o,easeOutCubic:o=>--o*o*o+1,easeInOutCubic:o=>o<.5?4*o*o*o:(o-1)*(2*o-2)*(2*o-2)+1,easeInQuart:o=>o*o*o*o,easeOutQuart:o=>1- --o*o*o*o,easeInOutQuart:o=>o<.5?8*o*o*o*o:1-8*--o*o*o*o,easeInQuint:o=>o*o*o*o*o,easeOutQuint:o=>1+--o*o*o*o*o,easeInOutQuint:o=>o<.5?16*o*o*o*o*o:1+16*--o*o*o*o*o,easeInSine:o=>1-Math.cos(o*Math.PI/2),easeOutSine:o=>Math.sin(o*Math.PI/2),easeInOutSine:o=>-(Math.cos(Math.PI*o)-1)/2,easeInExpo:o=>o<=0?0:Math.pow(2,10*o-10),easeOutExpo:o=>o>=1?1:1-Math.pow(2,-10*o),easeInOutExpo:o=>o<=0?0:o>=1?1:o<.5?Math.pow(2,20*o-10)/2:(2-Math.pow(2,-20*o+10))/2};class F{constructor(n=0,e=0,t=1){this.x=n,this.y=e,this.z=t}get XY(){return[this.x,this.y]}setz(n){return this.z=n,this}setXY(n=this.x,e=this.y){return this.x=n,this.y=e,this}set(n=this.x,e=this.y,t=this.z){return this.x=n,this.y=e,this.z=t,this}setTo({x:n=0,y:e=0,z:t=1}){return this.x=n,this.y=e,this.z=t,this}rot(n){if(n===0)return this;const{x:e,y:t}=this,i=Math.sin(n),r=Math.cos(n);return this.x=e*r-t*i,this.y=e*i+t*r,this}rotWith(n,e){if(e===0)return this;const t=this.x-n.x,i=this.y-n.y,r=Math.sin(e),s=Math.cos(e);return this.x=n.x+(t*s-i*r),this.y=n.y+(t*r+i*s),this}clone(){const{x:n,y:e,z:t}=this;return new F(n,e,t)}sub(n){return this.x-=n.x,this.y-=n.y,this}subXY(n,e){return this.x-=n,this.y-=e,this}subScalar(n){return this.x-=n,this.y-=n,this}add(n){return this.x+=n.x,this.y+=n.y,this}addXY(n,e){return this.x+=n,this.y+=e,this}addScalar(n){return this.x+=n,this.y+=n,this}clamp(n,e){return this.x=Math.max(this.x,n),this.y=Math.max(this.y,n),e!==void 0&&(this.x=Math.min(this.x,e),this.y=Math.min(this.y,e)),this}div(n){return this.x/=n,this.y/=n,this}divV(n){return this.x/=n.x,this.y/=n.y,this}mul(n){return this.x*=n,this.y*=n,this}mulV(n){return this.x*=n.x,this.y*=n.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(n,e){const t=F.Tan(n,this);return this.add(t.mul(e))}neg(){return this.x*=-1,this.y*=-1,this}cross(n){return this.x=this.y*n.z-this.z*n.y,this.y=this.z*n.x-this.x*n.z,this}dpr(n){return F.Dpr(this,n)}cpr(n){return F.Cpr(this,n)}len2(){return F.Len2(this)}len(){return F.Len(this)}pry(n){return F.Pry(this,n)}per(){const{x:n,y:e}=this;return this.x=e,this.y=-n,this}uni(){return F.Uni(this)}tan(n){return F.Tan(this,n)}dist(n){return F.Dist(this,n)}distanceToLineSegment(n,e){return F.DistanceToLineSegment(n,e,this)}slope(n){return F.Slope(this,n)}snapToGrid(n){return this.x=Math.round(this.x/n)*n,this.y=Math.round(this.y/n)*n,this}angle(n){return F.Angle(this,n)}toAngle(){return F.ToAngle(this)}lrp(n,e){return this.x=this.x+(n.x-this.x)*e,this.y=this.y+(n.y-this.y)*e,this}equals(n,e){return F.Equals(this,n,e)}equalsXY(n,e){return F.EqualsXY(this,n,e)}norm(){const n=this.len();return this.x=n===0?0:this.x/n,this.y=n===0?0:this.y/n,this}toFixed(){return F.ToFixed(this)}toString(){return F.ToString(F.ToFixed(this))}toJson(){return F.ToJson(this)}toArray(){return F.ToArray(this)}static Add(n,e){return new F(n.x+e.x,n.y+e.y)}static AddXY(n,e,t){return new F(n.x+e,n.y+t)}static Sub(n,e){return new F(n.x-e.x,n.y-e.y)}static SubXY(n,e,t){return new F(n.x-e,n.y-t)}static AddScalar(n,e){return new F(n.x+e,n.y+e)}static SubScalar(n,e){return new F(n.x-e,n.y-e)}static Div(n,e){return new F(n.x/e,n.y/e)}static Mul(n,e){return new F(n.x*e,n.y*e)}static DivV(n,e){return new F(n.x/e.x,n.y/e.y)}static MulV(n,e){return new F(n.x*e.x,n.y*e.y)}static Neg(n){return new F(-n.x,-n.y)}static Per(n){return new F(n.y,-n.x)}static Dist2(n,e){return F.Sub(n,e).len2()}static Abs(n){return new F(Math.abs(n.x),Math.abs(n.y))}static Dist(n,e){return Math.hypot(n.y-e.y,n.x-e.x)}static Dpr(n,e){return n.x*e.x+n.y*e.y}static Cross(n,e){return new F(n.y*e.z-n.z*e.y,n.z*e.x-n.x*e.z)}static Cpr(n,e){return n.x*e.y-e.x*n.y}static Len2(n){return n.x*n.x+n.y*n.y}static Len(n){return Math.hypot(n.x,n.y)}static Pry(n,e){return F.Dpr(n,e)/F.Len(e)}static Uni(n){return F.Div(n,F.Len(n))}static Tan(n,e){return F.Uni(F.Sub(n,e))}static Min(n,e){return new F(Math.min(n.x,e.x),Math.min(n.y,e.y))}static Max(n,e){return new F(Math.max(n.x,e.x),Math.max(n.y,e.y))}static From(n){return new F().add(n)}static FromArray(n){return new F(n[0],n[1])}static Rot(n,e=0){const t=Math.sin(e),i=Math.cos(e);return new F(n.x*i-n.y*t,n.x*t+n.y*i)}static RotWith(n,e,t){const i=n.x-e.x,r=n.y-e.y,s=Math.sin(t),a=Math.cos(t);return new F(e.x+(i*a-r*s),e.y+(i*s+r*a))}static NearestPointOnLineThroughPoint(n,e,t){return F.Mul(e,F.Sub(t,n).pry(e)).add(n)}static NearestPointOnLineSegment(n,e,t,i=!0){const r=F.Tan(e,n),s=F.Add(n,F.Mul(r,F.Sub(t,n).pry(r)));if(i){if(s.x<Math.min(n.x,e.x))return F.Cast(n.x<e.x?n:e);if(s.x>Math.max(n.x,e.x))return F.Cast(n.x>e.x?n:e);if(s.y<Math.min(n.y,e.y))return F.Cast(n.y<e.y?n:e);if(s.y>Math.max(n.y,e.y))return F.Cast(n.y>e.y?n:e)}return s}static DistanceToLineThroughPoint(n,e,t){return F.Dist(t,F.NearestPointOnLineThroughPoint(n,e,t))}static DistanceToLineSegment(n,e,t,i=!0){return F.Dist(t,F.NearestPointOnLineSegment(n,e,t,i))}static Snap(n,e=1){return new F(Math.round(n.x/e)*e,Math.round(n.y/e)*e)}static Cast(n){return n instanceof F?n:F.From(n)}static Slope(n,e){return n.x===e.y?NaN:(n.y-e.y)/(n.x-e.x)}static Angle(n,e){return Math.atan2(e.y-n.y,e.x-n.x)}static Lrp(n,e,t){return F.Sub(e,n).mul(t).add(n)}static Med(n,e){return new F((n.x+e.x)/2,(n.y+e.y)/2)}static Equals(n,e,t=1e-4){return Math.abs(n.x-e.x)<t&&Math.abs(n.y-e.y)<t}static EqualsXY(n,e,t){return n.x===e&&n.y===t}static EqualsXYZ(n,e,t=1e-4){return F.Equals(n,e,t)&&Math.abs((n.z||0)-(e.z||0))<t}static Clockwise(n,e,t){return(t.x-n.x)*(e.y-n.y)-(e.x-n.x)*(t.y-n.y)<0}static Rescale(n,e){const t=F.Len(n);return new F(e*n.x/t,e*n.y/t)}static ScaleWithOrigin(n,e,t){return F.Sub(n,t).mul(e).add(t)}static ScaleWOrigin(n,e,t){return F.Sub(n,t).mulV(e).add(t)}static ToFixed(n,e=2){return new F(+n.x.toFixed(e),+n.y.toFixed(e),+n.z.toFixed(e))}static Nudge(n,e,t){return F.Add(n,F.Tan(e,n).mul(t))}static ToString(n){return`${n.x}, ${n.y}`}static ToAngle(n){let e=Math.atan2(n.y,n.x);return e<0&&(e+=Math.PI*2),e}static FromAngle(n,e=1){return new F(Math.cos(n)*e,Math.sin(n)*e)}static ToArray(n){return[n.x,n.y,n.z]}static ToJson(n){const{x:e,y:t,z:i}=n;return{x:e,y:t,z:i}}static Average(n){const e=n.length,t=new F(0,0);for(let i=0;i<e;i++)t.add(n[i]);return t.div(e)}static Clamp(n,e,t){return t===void 0?new F(Math.min(Math.max(n.x,e)),Math.min(Math.max(n.y,e))):new F(Math.min(Math.max(n.x,e),t),Math.min(Math.max(n.y,e),t))}static PointsBetween(n,e,t=6){const i=[];for(let r=0;r<t;r++){const s=bo.easeInQuad(r/(t-1)),a=F.Lrp(n,e,s);a.z=Math.min(1,.5+Math.abs(.5-Do(s))*.65),i.push(a)}return i}static SnapToGrid(n,e=8){return new F(Math.round(n.x/e)*e,Math.round(n.y/e)*e)}}const Do=o=>o<.5?2*o*o:-1+(4-2*o)*o;class Me extends F{constructor(n=0,e=0,t=0,i={x:0,y:0},r=0,s=0){super(n,e,t),this.x=n,this.y=e,this.z=t,this.v=i,this.t=r,this.a=s}get timestamp(){return this.t}get pressure(){return this.z}get angleNum(){return this.a}get XY(){return[this.x,this.y]}setA(n){this.a=n}setT(n){this.t=n}setv(n){return this.v={x:n.x,y:n.y},this}set(n=this.x,e=this.y,t=this.z,i=this.v,r=this.t,s=this.a){return this.x=n,this.y=e,this.z=t,this.v=i,this.t=r,this.a=s,this}clone(){const{x:n,y:e,z:t,v:i,t:r,a:s}=this,a={x:i.x,y:i.y};return new Me(n,e,t,a,r,s)}distance(n){return Me.GetDistance(this,n)}isNear(n,e){return Me.IsNear(this,n,e)}getAngleByPoints(n,e){return Me.GetAngleByPoints(n,this,e)}static Sub(n,e){return new Me(n.x-e.x,n.y-e.y)}static Add(n,e){return new Me(n.x+e.x,n.y+e.y)}static GetDistance(n,e){return Me.Len(n.clone().sub(e))}static GetAngleByPoints(n,e,t){const i=e.x-n.x,r=t.x-e.x,s=e.y-n.y,a=t.y-e.y;let c=0;const l=Math.sqrt(i*i+s*s),u=Math.sqrt(r*r+a*a);if(l&&u){const h=i*r+s*a;c=Math.acos(h/(l*u)),c=c/Math.PI*180;let g=i*a-s*r;g=g>0?1:-1,c=180+g*c}return c}static IsNear(n,e,t){return Me.Len(n.clone().sub(e))<t}static RotWith(n,e,t,i=2){const r=n.x-e.x,s=n.y-e.y,a=Math.sin(t),c=Math.cos(t),l=Math.pow(10,i),u=Math.floor((e.x+(r*c-s*a))*l)/l,h=Math.floor((e.y+(r*a+s*c))*l)/l;return new Me(u,h)}static GetDotStroke(n,e,t=16){const i=new F(1,1),r=Math.PI+.001,s=Me.Add(n,Me.Sub(n,i).uni().per().mul(-e)),a=[];for(let c=1/t,l=c;l<=1;l+=c)a.push(Me.RotWith(s,n,r*2*l));return a}static GetSemicircleStroke(n,e,t=-1,i=8){const r=t*(Math.PI+.001),s=[];for(let a=1/i,c=a;c<=1;c+=a)s.push(Me.RotWith(e,n,r*c));return s}}var sn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function yn(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var jo=typeof sn=="object"&&sn&&sn.Object===Object&&sn,br=jo,Ao=br,Eo=typeof self=="object"&&self&&self.Object===Object&&self,zo=Ao||Eo||Function("return this")(),Je=zo,Lo=Je,Po=Lo.Symbol,Xt=Po,bi=Xt,Dr=Object.prototype,Oo=Dr.hasOwnProperty,Ro=Dr.toString,Qt=bi?bi.toStringTag:void 0;function Uo(o){var n=Oo.call(o,Qt),e=o[Qt];try{o[Qt]=void 0;var t=!0}catch{}var i=Ro.call(o);return t&&(n?o[Qt]=e:delete o[Qt]),i}var Yo=Uo,Bo=Object.prototype,Wo=Bo.toString;function Vo(o){return Wo.call(o)}var Fo=Vo,Di=Xt,$o=Yo,Go=Fo,Qo="[object Null]",Zo="[object Undefined]",ji=Di?Di.toStringTag:void 0;function Ho(o){return o==null?o===void 0?Zo:Qo:ji&&ji in Object(o)?$o(o):Go(o)}var Rt=Ho;function qo(o){return o!=null&&typeof o=="object"}var ct=qo;function Ko(){this.__data__=[],this.size=0}var Jo=Ko;function Xo(o,n){return o===n||o!==o&&n!==n}var si=Xo,_o=si;function es(o,n){for(var e=o.length;e--;)if(_o(o[e][0],n))return e;return-1}var mn=es,ts=mn,ns=Array.prototype,is=ns.splice;function rs(o){var n=this.__data__,e=ts(n,o);if(e<0)return!1;var t=n.length-1;return e==t?n.pop():is.call(n,e,1),--this.size,!0}var os=rs,ss=mn;function as(o){var n=this.__data__,e=ss(n,o);return e<0?void 0:n[e][1]}var cs=as,ls=mn;function us(o){return ls(this.__data__,o)>-1}var hs=us,ds=mn;function gs(o,n){var e=this.__data__,t=ds(e,o);return t<0?(++this.size,e.push([o,n])):e[t][1]=n,this}var fs=gs,ps=Jo,Ms=os,ys=cs,ms=hs,Is=fs;function Ut(o){var n=-1,e=o==null?0:o.length;for(this.clear();++n<e;){var t=o[n];this.set(t[0],t[1])}}Ut.prototype.clear=ps;Ut.prototype.delete=Ms;Ut.prototype.get=ys;Ut.prototype.has=ms;Ut.prototype.set=Is;var In=Ut,ws=In;function Ts(){this.__data__=new ws,this.size=0}var Ss=Ts;function vs(o){var n=this.__data__,e=n.delete(o);return this.size=n.size,e}var Ns=vs;function Cs(o){return this.__data__.get(o)}var ks=Cs;function xs(o){return this.__data__.has(o)}var bs=xs;function Ds(o){var n=typeof o;return o!=null&&(n=="object"||n=="function")}var lt=Ds,js=Rt,As=lt,Es="[object AsyncFunction]",zs="[object Function]",Ls="[object GeneratorFunction]",Ps="[object Proxy]";function Os(o){if(!As(o))return!1;var n=js(o);return n==zs||n==Ls||n==Es||n==Ps}var jr=Os,Rs=Je,Us=Rs["__core-js_shared__"],Ys=Us,An=Ys,Ai=function(){var o=/[^.]+$/.exec(An&&An.keys&&An.keys.IE_PROTO||"");return o?"Symbol(src)_1."+o:""}();function Bs(o){return!!Ai&&Ai in o}var Ws=Bs,Vs=Function.prototype,Fs=Vs.toString;function $s(o){if(o!=null){try{return Fs.call(o)}catch{}try{return o+""}catch{}}return""}var Ar=$s,Gs=jr,Qs=Ws,Zs=lt,Hs=Ar,qs=/[\\^$.*+?()[\]{}|]/g,Ks=/^\[object .+?Constructor\]$/,Js=Function.prototype,Xs=Object.prototype,_s=Js.toString,ea=Xs.hasOwnProperty,ta=RegExp("^"+_s.call(ea).replace(qs,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function na(o){if(!Zs(o)||Qs(o))return!1;var n=Gs(o)?ta:Ks;return n.test(Hs(o))}var ia=na;function ra(o,n){return o==null?void 0:o[n]}var oa=ra,sa=ia,aa=oa;function ca(o,n){var e=aa(o,n);return sa(e)?e:void 0}var Nt=ca,la=Nt,ua=Je,ha=la(ua,"Map"),ai=ha,da=Nt,ga=da(Object,"create"),wn=ga,Ei=wn;function fa(){this.__data__=Ei?Ei(null):{},this.size=0}var pa=fa;function Ma(o){var n=this.has(o)&&delete this.__data__[o];return this.size-=n?1:0,n}var ya=Ma,ma=wn,Ia="__lodash_hash_undefined__",wa=Object.prototype,Ta=wa.hasOwnProperty;function Sa(o){var n=this.__data__;if(ma){var e=n[o];return e===Ia?void 0:e}return Ta.call(n,o)?n[o]:void 0}var va=Sa,Na=wn,Ca=Object.prototype,ka=Ca.hasOwnProperty;function xa(o){var n=this.__data__;return Na?n[o]!==void 0:ka.call(n,o)}var ba=xa,Da=wn,ja="__lodash_hash_undefined__";function Aa(o,n){var e=this.__data__;return this.size+=this.has(o)?0:1,e[o]=Da&&n===void 0?ja:n,this}var Ea=Aa,za=pa,La=ya,Pa=va,Oa=ba,Ra=Ea;function Yt(o){var n=-1,e=o==null?0:o.length;for(this.clear();++n<e;){var t=o[n];this.set(t[0],t[1])}}Yt.prototype.clear=za;Yt.prototype.delete=La;Yt.prototype.get=Pa;Yt.prototype.has=Oa;Yt.prototype.set=Ra;var Ua=Yt,zi=Ua,Ya=In,Ba=ai;function Wa(){this.size=0,this.__data__={hash:new zi,map:new(Ba||Ya),string:new zi}}var Va=Wa;function Fa(o){var n=typeof o;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?o!=="__proto__":o===null}var $a=Fa,Ga=$a;function Qa(o,n){var e=o.__data__;return Ga(n)?e[typeof n=="string"?"string":"hash"]:e.map}var Tn=Qa,Za=Tn;function Ha(o){var n=Za(this,o).delete(o);return this.size-=n?1:0,n}var qa=Ha,Ka=Tn;function Ja(o){return Ka(this,o).get(o)}var Xa=Ja,_a=Tn;function ec(o){return _a(this,o).has(o)}var tc=ec,nc=Tn;function ic(o,n){var e=nc(this,o),t=e.size;return e.set(o,n),this.size+=e.size==t?0:1,this}var rc=ic,oc=Va,sc=qa,ac=Xa,cc=tc,lc=rc;function Bt(o){var n=-1,e=o==null?0:o.length;for(this.clear();++n<e;){var t=o[n];this.set(t[0],t[1])}}Bt.prototype.clear=oc;Bt.prototype.delete=sc;Bt.prototype.get=ac;Bt.prototype.has=cc;Bt.prototype.set=lc;var Er=Bt,uc=In,hc=ai,dc=Er,gc=200;function fc(o,n){var e=this.__data__;if(e instanceof uc){var t=e.__data__;if(!hc||t.length<gc-1)return t.push([o,n]),this.size=++e.size,this;e=this.__data__=new dc(t)}return e.set(o,n),this.size=e.size,this}var pc=fc,Mc=In,yc=Ss,mc=Ns,Ic=ks,wc=bs,Tc=pc;function Wt(o){var n=this.__data__=new Mc(o);this.size=n.size}Wt.prototype.clear=yc;Wt.prototype.delete=mc;Wt.prototype.get=Ic;Wt.prototype.has=wc;Wt.prototype.set=Tc;var zr=Wt;function Sc(o,n){for(var e=-1,t=o==null?0:o.length;++e<t&&n(o[e],e,o)!==!1;);return o}var vc=Sc,Nc=Nt,Cc=function(){try{var o=Nc(Object,"defineProperty");return o({},"",{}),o}catch{}}(),Lr=Cc,Li=Lr;function kc(o,n,e){n=="__proto__"&&Li?Li(o,n,{configurable:!0,enumerable:!0,value:e,writable:!0}):o[n]=e}var Pr=kc,xc=Pr,bc=si,Dc=Object.prototype,jc=Dc.hasOwnProperty;function Ac(o,n,e){var t=o[n];(!(jc.call(o,n)&&bc(t,e))||e===void 0&&!(n in o))&&xc(o,n,e)}var Or=Ac,Ec=Or,zc=Pr;function Lc(o,n,e,t){var i=!e;e||(e={});for(var r=-1,s=n.length;++r<s;){var a=n[r],c=t?t(e[a],o[a],a,e,o):void 0;c===void 0&&(c=o[a]),i?zc(e,a,c):Ec(e,a,c)}return e}var Sn=Lc;function Pc(o,n){for(var e=-1,t=Array(o);++e<o;)t[e]=n(e);return t}var Oc=Pc,Rc=Rt,Uc=ct,Yc="[object Arguments]";function Bc(o){return Uc(o)&&Rc(o)==Yc}var Wc=Bc,Pi=Wc,Vc=ct,Rr=Object.prototype,Fc=Rr.hasOwnProperty,$c=Rr.propertyIsEnumerable,Gc=Pi(function(){return arguments}())?Pi:function(o){return Vc(o)&&Fc.call(o,"callee")&&!$c.call(o,"callee")},Ur=Gc,Qc=Array.isArray,_t=Qc,un={exports:{}};function Zc(){return!1}var Hc=Zc;un.exports;(function(o,n){var e=Je,t=Hc,i=n&&!n.nodeType&&n,r=i&&!0&&o&&!o.nodeType&&o,s=r&&r.exports===i,a=s?e.Buffer:void 0,c=a?a.isBuffer:void 0,l=c||t;o.exports=l})(un,un.exports);var ci=un.exports,qc=9007199254740991,Kc=/^(?:0|[1-9]\d*)$/;function Jc(o,n){var e=typeof o;return n=n??qc,!!n&&(e=="number"||e!="symbol"&&Kc.test(o))&&o>-1&&o%1==0&&o<n}var Xc=Jc,_c=9007199254740991;function el(o){return typeof o=="number"&&o>-1&&o%1==0&&o<=_c}var Yr=el,tl=Rt,nl=Yr,il=ct,rl="[object Arguments]",ol="[object Array]",sl="[object Boolean]",al="[object Date]",cl="[object Error]",ll="[object Function]",ul="[object Map]",hl="[object Number]",dl="[object Object]",gl="[object RegExp]",fl="[object Set]",pl="[object String]",Ml="[object WeakMap]",yl="[object ArrayBuffer]",ml="[object DataView]",Il="[object Float32Array]",wl="[object Float64Array]",Tl="[object Int8Array]",Sl="[object Int16Array]",vl="[object Int32Array]",Nl="[object Uint8Array]",Cl="[object Uint8ClampedArray]",kl="[object Uint16Array]",xl="[object Uint32Array]",ve={};ve[Il]=ve[wl]=ve[Tl]=ve[Sl]=ve[vl]=ve[Nl]=ve[Cl]=ve[kl]=ve[xl]=!0;ve[rl]=ve[ol]=ve[yl]=ve[sl]=ve[ml]=ve[al]=ve[cl]=ve[ll]=ve[ul]=ve[hl]=ve[dl]=ve[gl]=ve[fl]=ve[pl]=ve[Ml]=!1;function bl(o){return il(o)&&nl(o.length)&&!!ve[tl(o)]}var Dl=bl;function jl(o){return function(n){return o(n)}}var vn=jl,hn={exports:{}};hn.exports;(function(o,n){var e=br,t=n&&!n.nodeType&&n,i=t&&!0&&o&&!o.nodeType&&o,r=i&&i.exports===t,s=r&&e.process,a=function(){try{var c=i&&i.require&&i.require("util").types;return c||s&&s.binding&&s.binding("util")}catch{}}();o.exports=a})(hn,hn.exports);var li=hn.exports,Al=Dl,El=vn,Oi=li,Ri=Oi&&Oi.isTypedArray,zl=Ri?El(Ri):Al,Br=zl,Ll=Oc,Pl=Ur,Ol=_t,Rl=ci,Ul=Xc,Yl=Br,Bl=Object.prototype,Wl=Bl.hasOwnProperty;function Vl(o,n){var e=Ol(o),t=!e&&Pl(o),i=!e&&!t&&Rl(o),r=!e&&!t&&!i&&Yl(o),s=e||t||i||r,a=s?Ll(o.length,String):[],c=a.length;for(var l in o)(n||Wl.call(o,l))&&!(s&&(l=="length"||i&&(l=="offset"||l=="parent")||r&&(l=="buffer"||l=="byteLength"||l=="byteOffset")||Ul(l,c)))&&a.push(l);return a}var Wr=Vl,Fl=Object.prototype;function $l(o){var n=o&&o.constructor,e=typeof n=="function"&&n.prototype||Fl;return o===e}var ui=$l;function Gl(o,n){return function(e){return o(n(e))}}var Vr=Gl,Ql=Vr,Zl=Ql(Object.keys,Object),Hl=Zl,ql=ui,Kl=Hl,Jl=Object.prototype,Xl=Jl.hasOwnProperty;function _l(o){if(!ql(o))return Kl(o);var n=[];for(var e in Object(o))Xl.call(o,e)&&e!="constructor"&&n.push(e);return n}var eu=_l,tu=jr,nu=Yr;function iu(o){return o!=null&&nu(o.length)&&!tu(o)}var hi=iu,ru=Wr,ou=eu,su=hi;function au(o){return su(o)?ru(o):ou(o)}var di=au,cu=Sn,lu=di;function uu(o,n){return o&&cu(n,lu(n),o)}var hu=uu;function du(o){var n=[];if(o!=null)for(var e in Object(o))n.push(e);return n}var gu=du,fu=lt,pu=ui,Mu=gu,yu=Object.prototype,mu=yu.hasOwnProperty;function Iu(o){if(!fu(o))return Mu(o);var n=pu(o),e=[];for(var t in o)t=="constructor"&&(n||!mu.call(o,t))||e.push(t);return e}var wu=Iu,Tu=Wr,Su=wu,vu=hi;function Nu(o){return vu(o)?Tu(o,!0):Su(o)}var gi=Nu,Cu=Sn,ku=gi;function xu(o,n){return o&&Cu(n,ku(n),o)}var bu=xu,dn={exports:{}};dn.exports;(function(o,n){var e=Je,t=n&&!n.nodeType&&n,i=t&&!0&&o&&!o.nodeType&&o,r=i&&i.exports===t,s=r?e.Buffer:void 0,a=s?s.allocUnsafe:void 0;function c(l,u){if(u)return l.slice();var h=l.length,g=a?a(h):new l.constructor(h);return l.copy(g),g}o.exports=c})(dn,dn.exports);var Du=dn.exports;function ju(o,n){var e=-1,t=o.length;for(n||(n=Array(t));++e<t;)n[e]=o[e];return n}var Au=ju;function Eu(o,n){for(var e=-1,t=o==null?0:o.length,i=0,r=[];++e<t;){var s=o[e];n(s,e,o)&&(r[i++]=s)}return r}var Fr=Eu;function zu(){return[]}var $r=zu,Lu=Fr,Pu=$r,Ou=Object.prototype,Ru=Ou.propertyIsEnumerable,Ui=Object.getOwnPropertySymbols,Uu=Ui?function(o){return o==null?[]:(o=Object(o),Lu(Ui(o),function(n){return Ru.call(o,n)}))}:Pu,fi=Uu,Yu=Sn,Bu=fi;function Wu(o,n){return Yu(o,Bu(o),n)}var Vu=Wu;function Fu(o,n){for(var e=-1,t=n.length,i=o.length;++e<t;)o[i+e]=n[e];return o}var pi=Fu,$u=Vr,Gu=$u(Object.getPrototypeOf,Object),Gr=Gu,Qu=pi,Zu=Gr,Hu=fi,qu=$r,Ku=Object.getOwnPropertySymbols,Ju=Ku?function(o){for(var n=[];o;)Qu(n,Hu(o)),o=Zu(o);return n}:qu,Qr=Ju,Xu=Sn,_u=Qr;function eh(o,n){return Xu(o,_u(o),n)}var th=eh,nh=pi,ih=_t;function rh(o,n,e){var t=n(o);return ih(o)?t:nh(t,e(o))}var Zr=rh,oh=Zr,sh=fi,ah=di;function ch(o){return oh(o,ah,sh)}var Hr=ch,lh=Zr,uh=Qr,hh=gi;function dh(o){return lh(o,hh,uh)}var gh=dh,fh=Nt,ph=Je,Mh=fh(ph,"DataView"),yh=Mh,mh=Nt,Ih=Je,wh=mh(Ih,"Promise"),Th=wh,Sh=Nt,vh=Je,Nh=Sh(vh,"Set"),qr=Nh,Ch=Nt,kh=Je,xh=Ch(kh,"WeakMap"),bh=xh,Vn=yh,Fn=ai,$n=Th,Gn=qr,Qn=bh,Kr=Rt,Vt=Ar,Yi="[object Map]",Dh="[object Object]",Bi="[object Promise]",Wi="[object Set]",Vi="[object WeakMap]",Fi="[object DataView]",jh=Vt(Vn),Ah=Vt(Fn),Eh=Vt($n),zh=Vt(Gn),Lh=Vt(Qn),mt=Kr;(Vn&&mt(new Vn(new ArrayBuffer(1)))!=Fi||Fn&&mt(new Fn)!=Yi||$n&&mt($n.resolve())!=Bi||Gn&&mt(new Gn)!=Wi||Qn&&mt(new Qn)!=Vi)&&(mt=function(o){var n=Kr(o),e=n==Dh?o.constructor:void 0,t=e?Vt(e):"";if(t)switch(t){case jh:return Fi;case Ah:return Yi;case Eh:return Bi;case zh:return Wi;case Lh:return Vi}return n});var Nn=mt,Ph=Object.prototype,Oh=Ph.hasOwnProperty;function Rh(o){var n=o.length,e=new o.constructor(n);return n&&typeof o[0]=="string"&&Oh.call(o,"index")&&(e.index=o.index,e.input=o.input),e}var Uh=Rh,Yh=Je,Bh=Yh.Uint8Array,Jr=Bh,$i=Jr;function Wh(o){var n=new o.constructor(o.byteLength);return new $i(n).set(new $i(o)),n}var Mi=Wh,Vh=Mi;function Fh(o,n){var e=n?Vh(o.buffer):o.buffer;return new o.constructor(e,o.byteOffset,o.byteLength)}var $h=Fh,Gh=/\w*$/;function Qh(o){var n=new o.constructor(o.source,Gh.exec(o));return n.lastIndex=o.lastIndex,n}var Zh=Qh,Gi=Xt,Qi=Gi?Gi.prototype:void 0,Zi=Qi?Qi.valueOf:void 0;function Hh(o){return Zi?Object(Zi.call(o)):{}}var qh=Hh,Kh=Mi;function Jh(o,n){var e=n?Kh(o.buffer):o.buffer;return new o.constructor(e,o.byteOffset,o.length)}var Xh=Jh,_h=Mi,ed=$h,td=Zh,nd=qh,id=Xh,rd="[object Boolean]",od="[object Date]",sd="[object Map]",ad="[object Number]",cd="[object RegExp]",ld="[object Set]",ud="[object String]",hd="[object Symbol]",dd="[object ArrayBuffer]",gd="[object DataView]",fd="[object Float32Array]",pd="[object Float64Array]",Md="[object Int8Array]",yd="[object Int16Array]",md="[object Int32Array]",Id="[object Uint8Array]",wd="[object Uint8ClampedArray]",Td="[object Uint16Array]",Sd="[object Uint32Array]";function vd(o,n,e){var t=o.constructor;switch(n){case dd:return _h(o);case rd:case od:return new t(+o);case gd:return ed(o,e);case fd:case pd:case Md:case yd:case md:case Id:case wd:case Td:case Sd:return id(o,e);case sd:return new t;case ad:case ud:return new t(o);case cd:return td(o);case ld:return new t;case hd:return nd(o)}}var Nd=vd,Cd=lt,Hi=Object.create,kd=function(){function o(){}return function(n){if(!Cd(n))return{};if(Hi)return Hi(n);o.prototype=n;var e=new o;return o.prototype=void 0,e}}(),xd=kd,bd=xd,Dd=Gr,jd=ui;function Ad(o){return typeof o.constructor=="function"&&!jd(o)?bd(Dd(o)):{}}var Ed=Ad,zd=Nn,Ld=ct,Pd="[object Map]";function Od(o){return Ld(o)&&zd(o)==Pd}var Rd=Od,Ud=Rd,Yd=vn,qi=li,Ki=qi&&qi.isMap,Bd=Ki?Yd(Ki):Ud,Wd=Bd,Vd=Nn,Fd=ct,$d="[object Set]";function Gd(o){return Fd(o)&&Vd(o)==$d}var Qd=Gd,Zd=Qd,Hd=vn,Ji=li,Xi=Ji&&Ji.isSet,qd=Xi?Hd(Xi):Zd,Xr=qd;const Kd=yn(Xr);var Jd=zr,Xd=vc,_d=Or,eg=hu,tg=bu,ng=Du,ig=Au,rg=Vu,og=th,sg=Hr,ag=gh,cg=Nn,lg=Uh,ug=Nd,hg=Ed,dg=_t,gg=ci,fg=Wd,pg=lt,Mg=Xr,yg=di,mg=gi,Ig=1,wg=2,Tg=4,_r="[object Arguments]",Sg="[object Array]",vg="[object Boolean]",Ng="[object Date]",Cg="[object Error]",eo="[object Function]",kg="[object GeneratorFunction]",xg="[object Map]",bg="[object Number]",to="[object Object]",Dg="[object RegExp]",jg="[object Set]",Ag="[object String]",Eg="[object Symbol]",zg="[object WeakMap]",Lg="[object ArrayBuffer]",Pg="[object DataView]",Og="[object Float32Array]",Rg="[object Float64Array]",Ug="[object Int8Array]",Yg="[object Int16Array]",Bg="[object Int32Array]",Wg="[object Uint8Array]",Vg="[object Uint8ClampedArray]",Fg="[object Uint16Array]",$g="[object Uint32Array]",Se={};Se[_r]=Se[Sg]=Se[Lg]=Se[Pg]=Se[vg]=Se[Ng]=Se[Og]=Se[Rg]=Se[Ug]=Se[Yg]=Se[Bg]=Se[xg]=Se[bg]=Se[to]=Se[Dg]=Se[jg]=Se[Ag]=Se[Eg]=Se[Wg]=Se[Vg]=Se[Fg]=Se[$g]=!0;Se[Cg]=Se[eo]=Se[zg]=!1;function ln(o,n,e,t,i,r){var s,a=n&Ig,c=n&wg,l=n&Tg;if(e&&(s=i?e(o,t,i,r):e(o)),s!==void 0)return s;if(!pg(o))return o;var u=dg(o);if(u){if(s=lg(o),!a)return ig(o,s)}else{var h=cg(o),g=h==eo||h==kg;if(gg(o))return ng(o,a);if(h==to||h==_r||g&&!i){if(s=c||g?{}:hg(o),!a)return c?og(o,tg(s,o)):rg(o,eg(s,o))}else{if(!Se[h])return i?o:{};s=ug(o,h,a)}}r||(r=new Jd);var p=r.get(o);if(p)return p;r.set(o,s),Mg(o)?o.forEach(function(w){s.add(ln(w,n,e,w,o,r))}):fg(o)&&o.forEach(function(w,m){s.set(m,ln(w,n,e,m,o,r))});var d=l?c?ag:sg:c?mg:yg,M=u?void 0:d(o);return Xd(M||o,function(w,m){M&&(m=w,w=o[m]),_d(s,m,ln(w,n,e,m,o,r))}),s}var Gg=ln,Qg=Gg,Zg=1,Hg=4;function qg(o){return Qg(o,Zg|Hg)}var Kg=qg;const en=yn(Kg),no="1.1.36-beta.1",Jg="@netless/appliance-plugin",_i=typeof OffscreenCanvas=="function"?"worker":"mainThread";if(typeof window<"u"){let o=window.__netlessUA||"";o+=` ${Jg}@${no}`,window.__netlessUA=o}const we={useWorker:"auto",useSimple:!0,useBackgroundThread:!1,syncOpt:{interval:300,smoothSync:!0},cursor:{enable:!0,expirationTime:5e3,moveDelayTime:40},bufferSize:{full:2e4,sub:600},bezier:{enable:!1,maxDrawCount:1/0,combineUnitTime:300},pencilEraser:{useBitMap:!0,maxImageWidth:1920,maxImageHeight:1920,maxCombineTime:500},strokeWidth:{min:1,max:10},textEditor:{showFloatBar:!0,canSelectorSwitch:!0,rightBoundBreak:!0,extendFontFaces:[],loadFontFacesTimeout:2e4},longDottedStroke:{lineCap:"round",segment:1,gap:2},dottedStroke:{lineCap:"round",segment:1,gap:2},normalStroke:{lineCap:"round"},undoRedo:{enableGlobal:!1,maxStackLength:20,timingFix:!0,ackTimeout:5e3,gracePeriodTimeout:3e3,doingFallbackTimeout:3e4},markmap:{enable:!0,timeout:1e4,options:{autoFit:!0,duration:0,zoom:!1,pan:!1,maxInitialScale:10}},overwriteSelectorStyles:{}};function zt(o){return JSON.parse(vr.decompress(o))}function St(o){return vr.compress(JSON.stringify(o))}const Ae=Object.keys,Ve="++",Z="selector",io="all";var Xg="__lodash_hash_undefined__";function _g(o){return this.__data__.set(o,Xg),this}var ef=_g;function tf(o){return this.__data__.has(o)}var nf=tf,rf=Er,of=ef,sf=nf;function gn(o){var n=-1,e=o==null?0:o.length;for(this.__data__=new rf;++n<e;)this.add(o[n])}gn.prototype.add=gn.prototype.push=of;gn.prototype.has=sf;var yi=gn;function af(o,n){for(var e=-1,t=o==null?0:o.length;++e<t;)if(n(o[e],e,o))return!0;return!1}var cf=af;function lf(o,n){return o.has(n)}var mi=lf,uf=yi,hf=cf,df=mi,gf=1,ff=2;function pf(o,n,e,t,i,r){var s=e&gf,a=o.length,c=n.length;if(a!=c&&!(s&&c>a))return!1;var l=r.get(o),u=r.get(n);if(l&&u)return l==n&&u==o;var h=-1,g=!0,p=e&ff?new uf:void 0;for(r.set(o,n),r.set(n,o);++h<a;){var d=o[h],M=n[h];if(t)var w=s?t(M,d,h,n,o,r):t(d,M,h,o,n,r);if(w!==void 0){if(w)continue;g=!1;break}if(p){if(!hf(n,function(m,y){if(!df(p,y)&&(d===m||i(d,m,e,t,r)))return p.push(y)})){g=!1;break}}else if(!(d===M||i(d,M,e,t,r))){g=!1;break}}return r.delete(o),r.delete(n),g}var ro=pf;function Mf(o){var n=-1,e=Array(o.size);return o.forEach(function(t,i){e[++n]=[i,t]}),e}var yf=Mf;function mf(o){var n=-1,e=Array(o.size);return o.forEach(function(t){e[++n]=t}),e}var Ii=mf,er=Xt,tr=Jr,If=si,wf=ro,Tf=yf,Sf=Ii,vf=1,Nf=2,Cf="[object Boolean]",kf="[object Date]",xf="[object Error]",bf="[object Map]",Df="[object Number]",jf="[object RegExp]",Af="[object Set]",Ef="[object String]",zf="[object Symbol]",Lf="[object ArrayBuffer]",Pf="[object DataView]",nr=er?er.prototype:void 0,En=nr?nr.valueOf:void 0;function Of(o,n,e,t,i,r,s){switch(e){case Pf:if(o.byteLength!=n.byteLength||o.byteOffset!=n.byteOffset)return!1;o=o.buffer,n=n.buffer;case Lf:return!(o.byteLength!=n.byteLength||!r(new tr(o),new tr(n)));case Cf:case kf:case Df:return If(+o,+n);case xf:return o.name==n.name&&o.message==n.message;case jf:case Ef:return o==n+"";case bf:var a=Tf;case Af:var c=t&vf;if(a||(a=Sf),o.size!=n.size&&!c)return!1;var l=s.get(o);if(l)return l==n;t|=Nf,s.set(o,n);var u=wf(a(o),a(n),t,i,r,s);return s.delete(o),u;case zf:if(En)return En.call(o)==En.call(n)}return!1}var Rf=Of;function tn(o,n,e){return"#"+((o<<16)+(n<<8)+e).toString(16).padStart(6,"0")}function Ee(o,n=1){return"rgba("+parseInt("0x"+o.slice(1,3))+","+parseInt("0x"+o.slice(3,5))+","+parseInt("0x"+o.slice(5,7))+","+n+")"}function bt(o,n,e,t=1){return`rgba(${o},${n},${e},${t})`}function Cn(o){const n=o.split(","),e=parseInt(n[0].split("(")[1]),t=parseInt(n[1]),i=parseInt(n[2]),r=Number(n[3].split(")")[0]);return[tn(e,t,i),r]}function qt(o){const n=o.split(","),e=parseInt(n[0].split("(")[1]),t=parseInt(n[1]),i=parseInt(n[2]),r=Number(n[3].split(")")[0]);return[e,t,i,r]}function an(o){return o==="transparent"}var Ke=(o=>(o[o.Text=1]="Text",o[o.Shape=2]="Shape",o))(Ke||{});const Ye=class Ye{createProxy(n){const e=new Proxy(n,{get(t,i,r){const s=Ye.interceptors.hasOwnProperty(i)?Ye.interceptors:t;return Reflect.get(s,i,r)}});return Ye.proxyToRaw.set(e,n),e}};I(Ye,"proxyToRaw",new WeakMap),I(Ye,"interceptors",{entries(...n){return Ye.proxyToRaw.get(this).entries(...n)},forEach(...n){return Ye.proxyToRaw.get(this).forEach(...n)},size(){return Ye.proxyToRaw.get(this).size},get(n){return Ye.proxyToRaw.get(this).get(n)},set(n,e){return Ye.proxyToRaw.get(this).set(n,e)},delete(n){return Ye.proxyToRaw.get(this).delete(n)},clear(){return Ye.proxyToRaw.get(this).clear()}});let It=Ye;const Zn=5;class Uf{constructor(n){I(this,"internalMsgEmitter");I(this,"publicMsgEmitter");I(this,"control");I(this,"editors");I(this,"activeId");I(this,"proxyMap");I(this,"taskqueue",new Map);I(this,"undoTickerId");I(this,"checkLocalTextBlur",z.debounce(()=>{if(this.collector)for(const[n,e]of this.editors.entries())e.opt.workState!==E.Done&&this.collector.isLocalId(n)&&this.activeId!==n&&(e.opt.text&&e.opt.text.replace(/\s*,/g,"")?this.unActive(n):this.delete(n,!0,!0))},100));const{control:e,internalMsgEmitter:t,publicMsgEmitter:i}=n;this.control=e,this.internalMsgEmitter=t,this.publicMsgEmitter=i;const r=new Map;this.proxyMap=new It;const s=this,a=It.interceptors.set;It.interceptors.set=function(l,u){return s.interceptors.set(l,u),a.call(this,l,u)};const c=It.interceptors.delete;It.interceptors.delete=function(l){return s.interceptors.delete(l),c.call(this,l)},this.editors=this.proxyMap.createProxy(r)}get collector(){return this.control.collector}logTextUndo(n,e){console.info("[appliance-plugin]",{target:`text-undo.${n}`,...e})}set UndoTickerId(n){this.undoTickerId=n}get UndoTickerId(){return this.undoTickerId}getDoneUndoTicker(n,e,t){const i=t??e,r=this.control.viewContainerManager.getUndoTickerId(n);if(this.logTextUndo("getDoneUndoTicker",{viewId:n,workState:e,updateNodeWorkState:t,effectiveWorkState:i,currentUndoTicker:r,managerUndoTickerId:this.undoTickerId}),i===E.Done)return this.undoTickerId&&r===this.undoTickerId?this.undoTickerId:r}ackDoneRender(n,e,t,i,r){if(!n){this.logTextUndo("ackDoneRender.skip",{viewId:e,scenePath:t,requestId:i,emitEventType:r});return}this.logTextUndo("ackDoneRender.emit",{undoTickerId:n,viewId:e,scenePath:t,requestId:i,emitEventType:r}),this.internalMsgEmitter.emit("ackRenderUndoTicker",n,e,t,{requestId:i,emitEventType:r}),this.undoTickerId=void 0}filterEditor(n){const e=new Map;return this.editors.forEach((t,i)=>{t.viewId===n&&e.set(i,t)}),e}get interceptors(){return{set:(n,e)=>{var y,S,v,k,C,x,O,Y,A;if(!this.collector)return!0;const{viewId:t,scenePath:i,canSync:r,canWorker:s,type:a,opt:c,dataType:l,updateNodeOpt:u,requestId:h,emitEventType:g,skipStorageDispatch:p}=e,d=this.getDoneUndoTicker(t,c==null?void 0:c.workState,u==null?void 0:u.workState);if(this.logTextUndo("interceptor.set.begin",{workId:n,viewId:t,scenePath:i,type:a,workState:c==null?void 0:c.workState,updateNodeWorkState:u==null?void 0:u.workState,canSync:r,canWorker:s,doneUndoTickerId:d,skipStorageDispatch:p}),!s&&!r)return!0;const w=((y=this.collector)==null?void 0:y.isLocalId(n))?(S=this.collector)==null?void 0:S.transformKey(n):n,m=((v=this.collector)==null?void 0:v.storage[t])&&this.collector.storage[t][i]&&this.collector.storage[t][i][w]||void 0;m?m.toolsType===T.Text&&(s&&(this.logTextUndo("interceptor.set.worker.update",{workId:n,viewId:t,scenePath:i}),this.control.worker.queryTaskBatchData({workId:n,msgType:W.UpdateNode}).forEach(b=>{var N;(N=this.control.worker)==null||N.taskBatchData.delete(b)}),(O=this.control.worker)==null||O.taskBatchData.add({workId:n,msgType:W.UpdateNode,dataType:l||J.Local,toolsType:T.Text,opt:c,viewId:t,scenePath:i,willRefresh:!0}),(Y=this.control.worker)==null||Y.runAnimation()),r&&!p&&(this.logTextUndo("interceptor.set.dispatch.update",{workId:n,viewId:t,scenePath:i,doneUndoTickerId:d,workState:c==null?void 0:c.workState,updateNodeWorkState:u==null?void 0:u.workState}),(A=this.collector)==null||A.dispatch({type:W.UpdateNode,workId:n,toolsType:T.Text,opt:c,viewId:t,scenePath:i,updateNodeOpt:u,requestId:h,emitEventType:g,needUndoTicker:d}),this.ackDoneRender(d,t,i,h,g),c.workState===E.Done&&this.control.runEffectWork(()=>{this.control.worker.setShapeSelectorByWorkId(n,t)}))):a===Ke.Text&&(r&&!p&&(this.logTextUndo("interceptor.set.dispatch.createOrFull",{workId:n,viewId:t,scenePath:i,msgType:c.text&&W.FullWork||W.CreateWork,doneUndoTickerId:d}),(k=this.collector)==null||k.dispatch({type:c.text&&W.FullWork||W.CreateWork,workId:n,toolsType:T.Text,opt:c,isSync:!0,viewId:t,scenePath:i,updateNodeOpt:u,requestId:h,emitEventType:g,needUndoTicker:d}),this.ackDoneRender(d,t,i,h,g)),s&&(this.logTextUndo("interceptor.set.worker.createOrFull",{workId:n,viewId:t,scenePath:i,msgType:c.text&&W.FullWork||W.CreateWork}),(C=this.control.worker)==null||C.taskBatchData.add({workId:n,msgType:c.text&&W.FullWork||W.CreateWork,dataType:l||J.Local,toolsType:T.Text,opt:c,viewId:t,scenePath:i,willRefresh:!0}),(x=this.control.worker)==null||x.runAnimation()))},delete:n=>{var c,l,u;if(!this.collector)return!0;const e=this.editors.get(n);if(!e)return!0;const{viewId:t,scenePath:i,canSync:r,canWorker:s}=e,a=this.getDoneUndoTicker(t,E.Done);if(this.logTextUndo("interceptor.delete.begin",{workId:n,viewId:t,scenePath:i,doneUndoTickerId:a,canSync:r,canWorker:s}),!s&&!r)return!0;s&&(this.logTextUndo("interceptor.delete.worker.remove",{workId:n,viewId:t,scenePath:i}),(c=this.control.worker)==null||c.taskBatchData.add({workId:n,toolsType:T.Text,msgType:W.RemoveNode,dataType:J.Local,viewId:t,scenePath:i,willRefresh:!0}),(l=this.control.worker)==null||l.runAnimation()),r&&(this.logTextUndo("interceptor.delete.dispatch.remove",{workId:n,viewId:t,scenePath:i,doneUndoTickerId:a}),(u=this.collector)==null||u.dispatch({type:W.RemoveNode,removeIds:[n],toolsType:T.Text,viewId:t,scenePath:i,needUndoTicker:a}),this.ackDoneRender(a,t,i))},clear(){return!0}}}computeTextActive(n,e){var r,s,a,c;const t=(r=this.control.viewContainerManager)==null?void 0:r.transformToScenePoint(n,e),i=(s=this.control.viewContainerManager)==null?void 0:s.getCurScenePath(e);e&&i&&((a=this.control.worker)==null||a.taskBatchData.add({msgType:W.GetTextActive,dataType:J.Local,op:t,viewId:e,scenePath:i}),(c=this.control.worker)==null||c.runAnimation())}checkEmptyTextBlur(){var e;let n=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)){n=t;break}if(n){const t=this.editors.get(n);(t==null?void 0:t.opt.text)&&(t==null?void 0:t.opt.text.replace(/\s*,/g,""))?this.unActive(n):this.delete(n,!0,!0)}this.checkLocalTextBlur()}onCameraChange(n,e){var t,i;for(const[r,s]of this.editors.entries())if(s.viewId===e){const{boxPoint:a,boxSize:c}=s.opt,l=a&&((t=this.control.viewContainerManager)==null?void 0:t.transformToOriginPoint(a,s.viewId)),u=(i=this.control.viewContainerManager)==null?void 0:i.getCurScenePath(e);if(u&&e){const h={x:l&&l[0]||0,y:l&&l[1]||0,w:c&&c[0]||0,h:c&&c[1]||0,opt:s.opt,scale:n.scale,type:Ke.Text,viewId:e,scenePath:u,canWorker:!1,canSync:!1};this.editors.set(r,h),this.control.viewContainerManager.updateTextEditorInfo(e,this.activeId)}}}onServiceDerive(n){var w,m,y,S,v,k,C,x,O,Y,A,b;const{workId:e,opt:t,msgType:i,viewId:r,scenePath:s,dataType:a,updateNodeOpt:c}=n;if(!e||!r||!s)return;const l=e.toString();if(i===W.RemoveNode){this.delete(l,!0,!0);return}const{boxPoint:u,boxSize:h}=t,g=u&&((w=this.control.viewContainerManager)==null?void 0:w.transformToOriginPoint(u,r)),p=this.control.viewContainerManager.getView(r),d=this.editors.get(l);this.logTextUndo("onServiceDerive.begin",{workId:l,viewId:r,scenePath:s,msgType:i,dataType:a,incomingWorkState:t==null?void 0:t.workState,incomingBoxSize:t==null?void 0:t.boxSize,incomingTextLength:(m=t==null?void 0:t.text)==null?void 0:m.length,previousWorkState:(y=d==null?void 0:d.opt)==null?void 0:y.workState,previousBoxSize:(S=d==null?void 0:d.opt)==null?void 0:S.boxSize,previousTextLength:(k=(v=d==null?void 0:d.opt)==null?void 0:v.text)==null?void 0:k.length,activeId:this.activeId});const M={x:g&&g[0]||0,y:g&&g[1]||0,w:h&&h[0]||0,h:h&&h[1]||0,opt:t,type:Ke.Text,canWorker:!0,canSync:!1,dataType:a,scale:((C=p==null?void 0:p.cameraOpt)==null?void 0:C.scale)||1,viewId:r,scenePath:s};if(t&&t.workState===E.Done&&!this.control.cursor.isEnableCursor&&u&&h){let D=c==null?void 0:c.uid;if(!D){const j=this.editors.get(l);D=j&&((x=j.opt)==null?void 0:x.uid)}D&&this.control.cursor.collectServiceCursor({op:u&&[u[0]+h[0],u[1]+h[1]],uid:D,workState:E.Done,viewId:r,type:W.Cursor})}this.editors.set(l,M),this.logTextUndo("onServiceDerive.applied",{workId:l,viewId:r,scenePath:s,appliedWorkState:(O=M.opt)==null?void 0:O.workState,appliedBoxSize:(Y=M.opt)==null?void 0:Y.boxSize,appliedTextLength:(b=(A=M.opt)==null?void 0:A.text)==null?void 0:b.length,activeId:this.activeId}),a===J.Service&&t.workState===E.Done&&this.activeId===l&&(this.activeId=void 0),this.control.viewContainerManager.updateTextEditorInfo(r,this.activeId)}updateForViewEdited(n,e){var i;this.editors.set(n,e);const t=(i=this.taskqueue.get(n))==null?void 0:i.resolve;t&&t(e)}active(n,e){var i,r,s;const t=this.editors.get(n);t&&t.viewId&&(this.logTextUndo("active.begin",{workId:n,viewId:t.viewId,scenePath:t.scenePath,incomingUndoTickerId:e,previousWorkState:t.opt.workState,previousBoxSize:t.opt.boxSize,previousTextLength:(i=t.opt.text)==null?void 0:i.length,currentManagerUndoTickerId:this.undoTickerId}),t.opt.workState=E.Start,t.opt.uid=(r=this.collector)==null?void 0:r.uid,this.activeId=n,t.canWorker=!0,t.canSync=!0,e&&t.viewId&&this.addUndoTicker(e,t.viewId),t.undoTickerId=e||t.undoTickerId||this.undoTickerId,this.editors.set(n,t),this.logTextUndo("active.applied",{workId:n,viewId:t.viewId,scenePath:t.scenePath,appliedWorkState:t.opt.workState,appliedBoxSize:t.opt.boxSize,appliedTextLength:(s=t.opt.text)==null?void 0:s.length,undoTickerId:t.undoTickerId}),this.control.viewContainerManager.updateTextEditorInfo(t.viewId,this.activeId))}unActive(n){var t;const e=this.editors.get(n);if(e&&e.viewId){const i=e.undoTickerId||this.control.viewContainerManager.getUndoTickerId(e.viewId)||this.undoTickerId;this.logTextUndo("unActive.begin",{blurId:n,viewId:e.viewId,scenePath:e.scenePath,infoUndoTickerId:e.undoTickerId,managerUndoTickerId:this.undoTickerId,finalizeUndoTickerId:i,currentViewUndoTickerId:this.control.viewContainerManager.getUndoTickerId(e.viewId),previousWorkState:e.opt.workState}),i&&(this.logTextUndo("unActive.finalizeRequested",{blurId:n,viewId:e.viewId,scenePath:e.scenePath,finalizeUndoTickerId:i}),this.internalMsgEmitter.emit("finalizeRequested",i,e.viewId,[n],e.scenePath)),e.opt.workState=E.Done,e.opt.uid=void 0,e.canWorker=!0,e.canSync=!0,this.editors.set(n,e),this.activeId=void 0;const r=(t=this.control.viewContainerManager.getView(e.viewId))==null?void 0:t.container;if(r){const s=CSS.escape(n),a=r.querySelector(`.editor-box #${s}`);a&&a.blur()}this.control.viewContainerManager.updateTextEditorInfo(e.viewId,this.activeId)}}addUndoTicker(n,e){this.logTextUndo("addUndoTicker",{undoTickerId:n,viewId:e,previousManagerUndoTickerId:this.undoTickerId}),this.internalMsgEmitter.emit("addUndoTicker",n,e,{render:!0,storage:!0}),this.undoTickerId=n}createTextForMasterController(n,e){var s;const{workId:t,isActive:i,...r}=n;this.logTextUndo("create.begin",{workId:t,viewId:r.viewId,scenePath:r.scenePath,undoTickerId:e,isActive:i,workState:r.opt.workState}),e&&this.addUndoTicker(e,r.viewId),r.opt.uid=(s=this.collector)==null?void 0:s.uid,r.undoTickerId=e||r.undoTickerId||this.undoTickerId,i&&(this.activeId=t),r.dataType=J.Local,r.canWorker=!0,r.canSync=!0,this.editors.set(t,r),this.control.viewContainerManager.updateTextEditorInfo(r.viewId,this.activeId)}updateTextForMasterController(n,e){var s,a;const{workId:t,...i}=n;this.logTextUndo("updateMaster.begin",{workId:t,viewId:i.viewId,scenePath:i.scenePath,undoTickerId:e,needUndoTicker:i.needUndoTicker,workState:(s=i.opt)==null?void 0:s.workState}),e&&this.addUndoTicker(e,i.viewId);const r=this.editors.get(t)||{};i.opt&&(i.opt.uid=(a=this.collector)==null?void 0:a.uid),i.undoTickerId=e||r.undoTickerId||this.undoTickerId,i.dataType=J.Local,this.editors.set(t,{...r,...i}),this.control.viewContainerManager.updateTextEditorInfo(i.viewId,this.activeId)}async updateTextControllerWithEffectAsync(n,e){var u,h;const{workId:t,...i}=n;this.logTextUndo("updateWithEffect.begin",{workId:t,viewId:i.viewId,scenePath:i.scenePath,undoTickerId:e,needUndoTicker:i.needUndoTicker,workState:(u=i.opt)==null?void 0:u.workState}),e&&this.addUndoTicker(e,i.viewId);const r=this.editors.get(t)||{};i.opt&&(i.opt.uid=(h=this.collector)==null?void 0:h.uid),i.undoTickerId=e||r.undoTickerId||this.undoTickerId,i.dataType=J.Local;const s={...r,...i};if(this.editors.set(t,s),this.control.viewContainerManager.updateTextEditorInfo(i.viewId,this.activeId),this.taskqueue.has(t)){const g=this.taskqueue.get(t);return g&&(g.clocker&&clearTimeout(g.clocker),this.taskqueue.delete(t)),await this.updateTextControllerWithEffectAsync(n)}const a=setTimeout(()=>{var p;const g=(p=this.taskqueue.get(t))==null?void 0:p.resolve;g&&g(s)},50),c=await new Promise(g=>{this.taskqueue.set(t,{resolve:g,clocker:a})}),l=this.taskqueue.get(t);return l&&(l.clocker&&clearTimeout(l.clocker),this.taskqueue.delete(t)),c}updateTextForWorker(n,e){var c;const{workId:t,isActive:i,...r}=n;this.logTextUndo("updateWorker.begin",{workId:t,viewId:r.viewId,scenePath:r.scenePath,undoTickerId:e,workState:(c=r.opt)==null?void 0:c.workState,isActive:i});const s=this.editors.get(t)||{},a={...s,...r};if(e&&this.addUndoTicker(e,r.viewId),a.undoTickerId=e||s.undoTickerId||this.undoTickerId,i){a.canWorker=!1,a.canSync=!1,this.editors.set(t,a),this.active(t);return}this.editors.set(t,a),this.control.viewContainerManager.updateTextEditorInfo(r.viewId,this.activeId)}get(n){return this.editors.get(n)}delete(n,e,t){const i=this.editors.get(n);if(i){const r=i.viewId;i.canSync=e,i.canWorker=t,this.editors.delete(n),this.activeId===n&&(this.activeId=void 0),this.control.viewContainerManager.updateTextEditorInfo(r,this.activeId)}}deleteBatch(n,e,t){const i=new Set;for(const r of n){const s=this.editors.get(r);if(s){const a=s.viewId;s.canSync=e,s.canWorker=t,this.editors.delete(r),this.activeId===r&&(this.activeId=void 0),i.add(a)}}for(const r of i)this.control.viewContainerManager.updateTextEditorInfo(r,this.activeId)}clear(n,e){this.editors.forEach((t,i)=>{t.viewId===n&&(e&&(t.canSync=!1),t.canWorker=!1,this.editors.delete(i))}),this.activeId=void 0,this.control.viewContainerManager.updateTextEditorInfo(n,this.activeId)}destory(){this.editors.clear(),this.activeId=void 0}insertText(n,e,t,i){var d,M;const r=(d=this.control.room)==null?void 0:d.state.memberState;if(!r)return;const s=this.control.viewContainerManager.getView(n);if(!(s!=null&&s.focusScenePath))return;const a=s==null?void 0:s.cameraOpt,c=this.control.getToolsOpt(T.Text,r);if(!c)return;const l=(M=this.control.viewContainerManager)==null?void 0:M.transformToOriginPoint([e,t],n),h=Bn(i,{whiteList:{},stripIgnoreTag:!0,stripIgnoreTagBody:["script"]}).split(/\n/),g=c.toolsOpt;g.text=St(h),g.workState=E.Doing,g.boxPoint=[Math.round(e),Math.round(t)],g.boxSize=[g.fontSize,g.fontSize];const p=this.control.worker.now;return this.control.textEditorManager.checkEmptyTextBlur(),this.control.textEditorManager.createTextForMasterController({workId:p.toString(),x:l&&l[0]||0,y:l&&l[1]||0,scale:(a==null?void 0:a.scale)||1,opt:g,type:Ke.Text,isActive:!0,viewId:n,scenePath:s.focusScenePath},p),p.toString()}updateText(n,e){const t=this.editors.get(n.toString());if(!t)return;const r=Bn(e,{whiteList:{},stripIgnoreTag:!0,stripIgnoreTagBody:["script"]}).split(/\n/);t.opt.text=St(r),this.control.textEditorManager.updateTextForMasterController({workId:n,opt:t.opt,viewId:t.viewId,canSync:!0,canWorker:!0},this.control.worker.now)}}function Yf(o){return o}var oo=Yf;function Bf(o,n,e){switch(e.length){case 0:return o.call(n);case 1:return o.call(n,e[0]);case 2:return o.call(n,e[0],e[1]);case 3:return o.call(n,e[0],e[1],e[2])}return o.apply(n,e)}var Wf=Bf,Vf=Wf,ir=Math.max;function Ff(o,n,e){return n=ir(n===void 0?o.length-1:n,0),function(){for(var t=arguments,i=-1,r=ir(t.length-n,0),s=Array(r);++i<r;)s[i]=t[n+i];i=-1;for(var a=Array(n+1);++i<n;)a[i]=t[i];return a[n]=e(s),Vf(o,this,a)}}var $f=Ff;function Gf(o){return function(){return o}}var Qf=Gf,Zf=Qf,rr=Lr,Hf=oo,qf=rr?function(o,n){return rr(o,"toString",{configurable:!0,enumerable:!1,value:Zf(n),writable:!0})}:Hf,Kf=qf,Jf=800,Xf=16,_f=Date.now;function ep(o){var n=0,e=0;return function(){var t=_f(),i=Xf-(t-e);if(e=t,i>0){if(++n>=Jf)return arguments[0]}else n=0;return o.apply(void 0,arguments)}}var tp=ep,np=Kf,ip=tp,rp=ip(np),op=rp,sp=oo,ap=$f,cp=op;function lp(o,n){return cp(ap(o,n,sp),o+"")}var up=lp;function hp(o,n,e,t){for(var i=o.length,r=e+(t?1:-1);t?r--:++r<i;)if(n(o[r],r,o))return r;return-1}var dp=hp;function gp(o){return o!==o}var fp=gp;function pp(o,n,e){for(var t=e-1,i=o.length;++t<i;)if(o[t]===n)return t;return-1}var Mp=pp,yp=dp,mp=fp,Ip=Mp;function wp(o,n,e){return n===n?Ip(o,n,e):yp(o,mp,e)}var Tp=wp,Sp=Tp;function vp(o,n){var e=o==null?0:o.length;return!!e&&Sp(o,n,0)>-1}var so=vp;function Np(o,n,e){for(var t=-1,i=o==null?0:o.length;++t<i;)if(e(n,o[t]))return!0;return!1}var ao=Np;function Cp(o,n){for(var e=-1,t=o==null?0:o.length,i=Array(t);++e<t;)i[e]=n(o[e],e,o);return i}var kp=Cp,xp=yi,bp=so,Dp=ao,jp=kp,Ap=vn,Ep=mi,zp=200;function Lp(o,n,e,t){var i=-1,r=bp,s=!0,a=o.length,c=[],l=n.length;if(!a)return c;e&&(n=jp(n,Ap(e))),t?(r=Dp,s=!1):n.length>=zp&&(r=Ep,s=!1,n=new xp(n));e:for(;++i<a;){var u=o[i],h=e==null?u:e(u);if(u=t||u!==0?u:0,s&&h===h){for(var g=l;g--;)if(n[g]===h)continue e;c.push(u)}else r(n,h,t)||c.push(u)}return c}var Pp=Lp,or=Xt,Op=Ur,Rp=_t,sr=or?or.isConcatSpreadable:void 0;function Up(o){return Rp(o)||Op(o)||!!(sr&&o&&o[sr])}var Yp=Up,Bp=pi,Wp=Yp;function co(o,n,e,t,i){var r=-1,s=o.length;for(e||(e=Wp),i||(i=[]);++r<s;){var a=o[r];n>0&&e(a)?n>1?co(a,n-1,e,t,i):Bp(i,a):t||(i[i.length]=a)}return i}var Vp=co;function Fp(){}var $p=Fp,zn=qr,Gp=$p,Qp=Ii,Zp=1/0,Hp=zn&&1/Qp(new zn([,-0]))[1]==Zp?function(o){return new zn(o)}:Gp,qp=Hp,Kp=yi,Jp=so,Xp=ao,_p=mi,eM=qp,tM=Ii,nM=200;function iM(o,n,e){var t=-1,i=Jp,r=o.length,s=!0,a=[],c=a;if(e)s=!1,i=Xp;else if(r>=nM){var l=n?null:eM(o);if(l)return tM(l);s=!1,i=_p,c=new Kp}else c=n?[]:a;e:for(;++t<r;){var u=o[t],h=n?n(u):u;if(u=e||u!==0?u:0,s&&h===h){for(var g=c.length;g--;)if(c[g]===h)continue e;n&&c.push(h),a.push(u)}else i(c,h,e)||(c!==a&&c.push(h),a.push(u))}return a}var rM=iM,oM=Pp,sM=Vp,ar=rM;function aM(o,n,e){var t=o.length;if(t<2)return t?ar(o[0]):[];for(var i=-1,r=Array(t);++i<t;)for(var s=o[i],a=-1;++a<t;)a!=i&&(r[i]=oM(r[i]||s,o[a],n,e));return ar(sM(r,1),n,e)}var cM=aM,lM=hi,uM=ct;function hM(o){return uM(o)&&lM(o)}var dM=hM,gM=Fr,fM=up,pM=cM,MM=dM;fM(function(o){return pM(gM(o,MM))});function yM(o,n){if(o&&n){const e=Math.min(o.x,n.x),t=Math.min(o.y,n.y),i=Math.max(o.x+o.w,n.x+n.w),r=Math.max(o.y+o.h,n.y+n.h),s=i-e,a=r-t;return{x:e,y:t,w:s,h:a}}return n||o}function wi(o,n){if(o&&n){const e=Math.min(o.originX,n.originX),t=Math.min(o.originY,n.originY),i=Math.max(o.originX+o.width,n.originX+n.width),r=Math.max(o.originY+o.height,n.originY+n.height),s=i-e,a=r-t;return{originX:e,originY:t,width:s,height:a}}return n||o}function Ti(o,n=0){const e={x:0,y:0,w:0,h:0};let t=1/0,i=1/0,r=-1/0,s=-1/0;return o.forEach(a=>{const[c,l]=a.XY;t=Math.min(t,c-n),i=Math.min(i,l-n),r=Math.max(r,c+n),s=Math.max(s,l+n)}),e.x=t,e.y=i,e.w=r-t,e.h=s-i,e}function mM(o,n){return!(o.x+o.w<n.x||o.x>n.x+n.w||o.y+o.h<n.y||o.y>n.y+n.h)}function IM(o,n=10){return{x:Math.floor(o.x-n),y:Math.floor(o.y-n),w:Math.ceil(o.w+n*2),h:Math.ceil(o.h+n*2)}}function wM(o,n){return{x:o.x+n[0],y:o.y+n[1],w:o.w,h:o.h}}function TM(o,n){const e=new F(o.x,o.y),t=new F(o.x+o.w,o.y),i=new F(o.x+o.w,o.y+o.h),r=new F(o.x,o.y+o.h),s=new F(o.x+o.w/2,o.y+o.h/2),a=Math.PI*n/180,c=F.RotWith(e,s,a),l=F.RotWith(t,s,a),u=F.RotWith(i,s,a),h=F.RotWith(r,s,a);return[c,l,u,h]}function SM(o,n){const e=TM(o,n);return Ti(e)}function vM(o,n,e){const t=new F(o.x,o.y),i=new F(o.x+o.w,o.y),r=new F(o.x+o.w,o.y+o.h),s=new F(o.x,o.y+o.h),a=new F(e[0],e[1]),c=new F(n[0],n[1]),l=F.ScaleWOrigin(t,c,a),u=F.ScaleWOrigin(i,c,a),h=F.ScaleWOrigin(r,c,a),g=F.ScaleWOrigin(s,c,a);return Ti([l,u,h,g])}function NM(o,n,e){const t=new F(n[0],n[1]);for(let i=0;i<o.length;i+=3){const r=new F(o[i],o[i+1]),s=Math.PI*e/180,a=F.RotWith(r,t,s);o[i]=a.x,o[i+1]=a.y}}function CM(o,n,e){const t=new F(n[0],n[1]);for(let i=0;i<o.length;i+=2){const r=new F(o[i],o[i+1]),s=Math.PI*e/180,a=F.RotWith(r,t,s);o[i]=a.x,o[i+1]=a.y}}function kM(o,n,e,t=[0,0]){const i=new F(n[0],n[1]);for(let r=0;r<o.length;r+=3){const s=new F(o[r],o[r+1]),a=new F(e[0],e[1]),c=F.ScaleWOrigin(s,a,i);o[r]=c.x+t[0],o[r+1]=c.y+t[1]}}function xM(o,n,e,t=[0,0]){const i=new F(n[0],n[1]);for(let r=0;r<o.length;r+=2){const s=new F(o[r],o[r+1]),a=new F(e[0],e[1]),c=F.ScaleWOrigin(s,a,i);o[r]=c.x+t[0],o[r+1]=c.y+t[1]}}function lo(o,n){return o[0]>=n.x&&o[0]<=n.x+n.w&&o[1]>=n.y&&o[1]<=n.y+n.h}function bM(o,n){const e=o<=n?1:o/n,t=n<=o?1:n/o;return[e,t]}function DM(o){for(const n of o)if(isNaN(n)||n===1/0||n===-1/0)return!1;return!0}function jM(o){return o!==Math.floor(o)}function AM(o){const n=o.toString();return n.indexOf(".")!==-1?n.split(".")[1].length:0}function EM(o,n){for(;n!==0;)[o,n]=[n,o%n];return o}function zM(o){return`${fn(o.x)},${fn(o.y)} `}function LM(o,n){return`${fn((o.x+n.x)/2)},${fn((o.y+n.y)/2)} `}function fn(o){return+o.toFixed(4)}const qe=async(o,n,e=!1)=>{let t,i;return new Promise(function(r){if(e&&requestIdleCallback)requestIdleCallback(()=>{r(1)},{timeout:n});else{if(typeof window.requestIdleCallback=="function"){const s=typeof n=="number"&&!isNaN(n)&&n>0?n:0;i=window.requestIdleCallback(()=>{clearTimeout(t),r(1)},{timeout:s})}t=setTimeout(()=>{i&&window.cancelIdleCallback(i),r(1)},n||0)}}).then(function(){o()}).catch(function(){o()})},Pt=o=>Math.max(1,(window.devicePixelRatio||1)/1),PM=(o,n)=>o.x+o.w<n.x||o.x>n.x+n.w||o.y+o.h<n.y||o.y>n.y+n.h?jt.outside:o.x>=n.x&&o.y>=n.y&&o.x+o.w<=n.x+n.w&&o.y+o.h<=n.y+n.h?jt.inside:jt.intersect;function OM(o){let n=0;for(let e=0;e<o.length;e++){const t=o.charCodeAt(e);t>=1&&t<=126||65376<=t&&t<=65439?n++:n+=2}return n}function RM(o){if(!o||typeof o!="string")return!1;const n=o.trim();if(!n)return!1;const e=[/^\s*#{1,6}\s+.+/m,/^\s*[-*+]\s+.+/m,/^\s*\d+\.\s+.+/m,/\[([^\]]+)\]\(([^)]+)\)/,/\[([^\]]+)\]\[([^\]]+)\]/,/```[\s\S]*?```/,/`[^`]+`/,/^\s*\|.+\|/m,/!\[([^\]]*)\]\(([^)]+)\)/,/\*\*[^*]+\*\*/,/__[^_]+__/,/\*[^*]+\*/,/_[^_]+_/,/~~[^~]+~~/,/==[^=]+==/,/^\s*[-*+]\s+\[[ xX]\]\s+.+/m,/^\s*>\s+.+/m,/^\s*[-*]{3,}\s*$/m];let t=0;for(const s of e)s.test(n)&&t++;const r=[/^\s*#{1,6}\s+/m,/^\s*[-*+]\s+/m,/^\s*\d+\.\s+/m,/```[\s\S]*?```/,/^\s*\|.+\|/m].some(s=>s.test(n));return t>=2||r}class UM{constructor(n,e){I(this,"plugin");I(this,"uid");I(this,"control");this.control=n,this.plugin=e,this.uid=e.displayer.uid}getNamespaceData(){var n;return cn((n=this.plugin)==null?void 0:n.attributes[this.namespace])||{}}getAuthSpaceData(){var n;return cn((n=this.plugin)==null?void 0:n.attributes[this.authSpace])||{}}getGlobalUndoRedoStackData(){var n;return cn((n=this.plugin)==null?void 0:n.attributes[this.globalUndoRedoStackSpace])||{}}getUidFromKey(n){return n.split(Ve).length===2&&n.split(Ve)[0]||this.uid}isLocalId(n){return n.split(Ve).length===1}getLocalId(n){return n.split(Ve)[1]}isSelector(n){return this.getLocalId(n)===Z}}const Re=class Re extends UM{constructor(e,t,i){super(e,t);I(this,"namespace");I(this,"authSpace");I(this,"globalUndoRedoStackSpace");I(this,"serviceStorage",{});I(this,"storage",{});I(this,"authStorage",{});I(this,"globalUndoRedoStackStorage",{});I(this,"stateDisposer");I(this,"authDisposer");I(this,"asyncClockState",!1);I(this,"limitNums",new Map);I(this,"syncInterval");I(this,"limitComponents",z.debounce((e,t)=>{var s,a,c,l,u,h,g,p;const i=((a=(s=this.storage)==null?void 0:s[e])==null?void 0:a[t])&&Object.keys(this.storage[e][t]).length||0;if(i===0)return;let r=this.limitNums.get(`${e}/${t}`);if(!r){const d=this.getLimitNum(i);this.limitNums.set(`${e}/${t}`,d),r=d}if(r>0&&i>=r){const d=Re.componentsLimits.indexOf(r),M=d>=0&&d<Re.componentsLimits.length-1;if((u=(l=(c=this.control.room)==null?void 0:c.callbacks)==null?void 0:l.listeners)!=null&&u.map.onObjectsLimit&&((g=(h=this.control.room)==null?void 0:h.callbacks)==null||g.dispatch("onObjectsLimit",m=>m(r,M))),!M){this.Logger.error(`[Appliance]: exceeds the limit of ${r} components, current: ${i}`),(p=this.control.room)==null||p.disconnect().then(()=>{var m,y,S,v,k;(S=(y=(m=this.control.room)==null?void 0:m.callbacks)==null?void 0:y.listeners)!=null&&S.map.onKickedWithReason&&(this.Logger.info("[Appliance]: onKickedWithReason callback is called"),(k=(v=this.control.room)==null?void 0:v.callbacks)==null||k.dispatch("onKickedWithReason",C=>C("kickByAdmin")))});return}console.warn(`exceeds the limit of ${r} components, current: ${i}`);const w=M?Re.componentsLimits[d+1]:0;this.limitNums.set(`${e}/${t}`,w)}},2e3,{maxWait:5e3}));I(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)});this.syncInterval=i,this.namespace=Re.namespace,this.authSpace=Re.authSpace,this.globalUndoRedoStackSpace=Re.globalUndoRedoStackSpace,this.serviceStorage=this.getNamespaceData(),this.storage=z.cloneDeep(this.serviceStorage),this.authStorage=this.getAuthSpaceData(),this.globalUndoRedoStackStorage={},this.getLimitNums()}get Logger(){return this.control.logger}hasId(e,t,i){const r=this.getLocalId(i)?this.transformKey(i):i;return!!(this.storage[e]&&this.storage[e][t]&&this.storage[e][t][r])}getLimitNum(e){return e>=Re.componentsLimits[0]?Re.componentsLimits[1]:Re.componentsLimits[0]}getLimitNums(){for(const[e,t]of Object.entries(this.storage))if(e&&t){for(const[i,r]of Object.entries(t))if(i&&r){const s=this.getLimitNum(Object.keys(r).length);this.limitNums.set(`${e}/${i}`,s)}}}getViewIdBySecenPath(e){const t=this.getNamespaceData();for(const[i,r]of Object.entries(t))if(r){for(const s of Object.keys(r))if(s===e)return i}}getScenePathData(e){const t=this.getNamespaceData();for(const i of Object.values(t))if(i){for(const r of Object.keys(i))if(r===e)return z.cloneDeep(i[r])}}hasTargetDataByViewId(e,t){const i=this.getNamespaceData();if(i&&i[e]){for(const r of Object.values(i[e]))for(const s of Object.keys(r))if(s===t)return!0}}getTargetDataByViewId(e,t){const i=this.getNamespaceData();let r,s;if(i&&i[e])for(const[a,c]of Object.entries(i[e]))for(const l of Object.keys(c))l===t&&(r=z.cloneDeep(c[l]),s=a);return{data:r,scenePath:s}}getStorageData(e,t){const i=this.getNamespaceData();return i&&i[e]&&z.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(r=>this.isOwn(r)&&this.getLocalId(r)===Z))}hasIncludeSelector(e,t,i){for(const r of Object.keys(this.storage))if(!(t&&r!==t)){for(const s of Object.keys(this.storage[r]))if(!(i&&s!==i)){for(const a of Object.keys(this.storage[r][s]))if(this.getLocalId(a)===Z){const c=this.storage[r][s][a],l=this.isLocalId(e)?this.transformKey(e):e;if(c&&c.selectIds&&c.selectIds.length&&c.selectIds.includes(l))return!0}}}return!1}addStorageStateListener(e){this.stateDisposer=jn(async()=>{var c,l,u,h,g,p;const t=this.getNamespaceData(),{diffView:i,diffScenePath:r,diffData:s}=this.diffFunByView(this.serviceStorage,t);this.serviceStorage=t;const a={};if(Object.keys(i).length>0)for(const[d,M]of Object.entries(i))M&&!z.isEqual((c=this.storage)==null?void 0:c[d],M.newValue)&&(a.diffView||(a.diffView={}),a.diffView[d]=M,this.storage||(this.storage={}),M.newValue===void 0?delete this.storage[d]:this.storage[d]=z.cloneDeep(M.newValue));if(Object.keys(r).length>0){for(const[d,M]of Object.entries(r))if(M){const{viewId:w,newValue:m}=M;M&&!z.isEqual((u=(l=this.storage)==null?void 0:l[w])==null?void 0:u[d],m)&&(a.diffScenePath||(a.diffScenePath={}),a.diffScenePath[d]=M,this.storage||(this.storage={}),this.storage[w]||(this.storage[w]={}),M.newValue===void 0?delete this.storage[w][d]:this.storage[w][d]=z.cloneDeep(M.newValue))}}if(Object.keys(s).length>0){for(const[d,M]of Object.entries(s))if(M){const{viewId:w,scenePath:m,newValue:y}=M;M&&!z.isEqual((p=(g=(h=this.storage)==null?void 0:h[w])==null?void 0:g[m])==null?void 0:p[d],y)&&(a.diffData||(a.diffData={}),a.diffData[d]=M,this.storage||(this.storage={}),this.storage[w]||(this.storage[w]={}),this.storage[w][m]||(this.storage[w][m]={}),M.newValue===void 0?delete this.storage[w][m][d]:this.storage[w][m][d]=z.cloneDeep(M.newValue))}}Object.keys(a).length>0&&e(a),this.control.worker.publicMsgEmitter.emit("syncStorageChange",this.serviceStorage)})}removeStorageStateListener(){this.stateDisposer&&this.stateDisposer()}diffFunByView(e,t){const i=Ae(e),r=Ae(t),s={},a={},c={};for(const l of r)if(!i.includes(l)||e[l]===void 0){s[l]={newValue:t[l],oldValue:void 0};continue}for(const l of i){if(z.isEqual(e[l],t[l]))continue;if(!r.includes(l)||t[l]===void 0){s[l]={newValue:void 0,oldValue:e[l]};continue}const u=this.diffFunByScenePath(e[l],t[l],l);Object.assign(a,u.diffScenePath),Object.assign(c,u.diffData)}return{diffData:c,diffScenePath:a,diffView:s}}diffFunByScenePath(e,t,i){const r=Ae(e),s=Ae(t),a={},c={};for(const l of s)if(!r.includes(l)||e[l]===void 0){a[l]={newValue:t[l],oldValue:void 0,viewId:i};continue}for(const l of r){if(z.isEqual(e[l],t[l]))continue;if(!s.includes(l)||t[l]===void 0){a[l]={newValue:void 0,oldValue:e[l],viewId:i};continue}const u=this.diffFunByKeys(e[l],t[l],l,i);Object.assign(c,u)}return{diffScenePath:a,diffData:c}}diffFunByKeys(e,t,i,r){const s=Ae(e),a=Ae(t),c={};for(const l of a)(!s.includes(l)||e[l]===void 0)&&(c[l]={oldValue:void 0,newValue:t[l],viewId:r,scenePath:i});for(const l of s)if(!z.isEqual(e[l],t[l])){if(!a.includes(l)||t[l]===void 0){c[l]={newValue:void 0,oldValue:e[l],viewId:r,scenePath:i};continue}a.includes(l)&&(c[l]={oldValue:e[l],newValue:t[l],viewId:r,scenePath:i})}return c}transformKey(e){return this.uid+Ve+e}isOwn(e){return e.split(Ve)[0]===this.uid}dispatch(e){var y,S,v,k;const{type:t,workId:i,ops:r,index:s,opt:a,toolsType:c,removeIds:l,updateNodeOpt:u,op:h,selectIds:g,isSync:p,scenePath:d,viewId:M}=e;if(!M)return;const w=Number(e.needUndoTicker??e.collectUndoTicker??void 0),m=C=>{w?this.control.internalMsgEmitter.emit("ackStorageUndoTicker",w,M,d,C,{requestId:e.requestId,emitEventType:e.emitEventType}):e.emitEventType===R.TranslateNode||(e.emitEventType,R.CopyNode)};switch(t){case W.Clear:const C={};d&&this.storage[M]&&this.storage[M][d]?(delete this.storage[M][d],this.setState(C,{isSync:p,viewId:M,scenePath:d})):this.storage[M]&&(delete this.storage[M],this.setState(C,{isSync:p,viewId:M,scenePath:""})),qe(()=>{var b,N;(b=this.control.pluginManager)==null||b.dispatchPluginEvent("syncStorage",M,d),this.control.isUseSimple||(N=this.control.miniMapManager)==null||N.updateMiniMapCamera(M),this.clearLimitComponents(M,d)},this.syncInterval,this.control.hasPolyfillMethod("requestIdleCallback"));break;case W.CreateWork:if(d&&i&&c&&a){const b=this.isLocalId(i.toString())?this.transformKey(i):i;this.control.renderControl.isUsePageAuth(M)&&this.control.renderControl.addRenderPageElementId({viewId:M,scenePath:d,elementId:b.toString()}),this.updateValue(b.toString(),{type:W.CreateWork,workId:i,toolsType:c,opt:a},{isSync:p,viewId:M,scenePath:d,onApplied:()=>m(b.toString())})}break;case W.DrawWork:if(d&&i&&typeof s=="number"&&(h!=null&&h.length)){const b=this.isLocalId(i.toString())?this.transformKey(i):i,N=this.storage[M]&&this.storage[M][d]&&this.storage[M][d][b]||void 0;if(N!=null&&N.ops||(N==null?void 0:N.type)===W.FullWork)return;const D=s?((N==null?void 0:N.op)||[]).slice(0,s).concat(h):h||(N==null?void 0:N.op),j=c||(N==null?void 0:N.toolsType),B=a||(N==null?void 0:N.opt),V=u||(N==null?void 0:N.updateNodeOpt);i&&j&&B&&D&&(this.control.renderControl.isUsePageAuth(M)&&this.control.renderControl.addRenderPageElementId({viewId:M,scenePath:d,elementId:b.toString()}),this.updateValue(b.toString(),{...N,type:W.DrawWork,workId:i,updateNodeOpt:V,toolsType:j,opt:B,op:D,index:s},{isSync:p,viewId:M,scenePath:d,onApplied:()=>m(b.toString())}))}break;case W.FullWork:if(d&&i){const b=this.isLocalId(i.toString())?this.transformKey(i):i,N=this.storage[M]&&this.storage[M][d]&&this.storage[M][d][b]||void 0;(c===T.Image||(N==null?void 0:N.toolsType)===T.Image)&&console.info("[appliance-plugin]",{target:"image-undo.collector.full.begin",viewId:M,scenePath:d,workId:((y=i==null?void 0:i.toString)==null?void 0:y.call(i))||i,key:b.toString(),needUndoTicker:e.needUndoTicker,hasOld:!!N,incomingToolsType:c});const D=u||(N==null?void 0:N.updateNodeOpt),j=c||(N==null?void 0:N.toolsType),B=a||(N==null?void 0:N.opt),V=r||(N==null?void 0:N.ops);j===T.Image&&console.info("[appliance-plugin]",{target:"image-undo.collector.full.resolved",viewId:M,scenePath:d,workId:((S=i==null?void 0:i.toString)==null?void 0:S.call(i))||i,key:b.toString(),needUndoTicker:e.needUndoTicker,hasOld:!!N,hasOpt:!!B,hasOps:!!V}),j&&B&&(this.control.renderControl.isUsePageAuth(M)&&this.control.renderControl.addRenderPageElementId({viewId:M,scenePath:d,elementId:b.toString()}),this.updateValue(b.toString(),{type:W.FullWork,updateNodeOpt:D,workId:b,toolsType:j,opt:B,ops:V},{isSync:p,viewId:M,scenePath:d,onApplied:()=>{var U;j===T.Image&&console.info("[appliance-plugin]",{target:"image-undo.collector.full.applied",viewId:M,scenePath:d,workId:((U=i==null?void 0:i.toString)==null?void 0:U.call(i))||i,key:b.toString(),needUndoTicker:e.needUndoTicker}),m(b.toString())}}),qe(()=>{var U,H;(U=this.control.pluginManager)==null||U.dispatchPluginEvent("syncStorage",M,d),this.control.isUseSimple||(H=this.control.miniMapManager)==null||H.updateMiniMapCamera(M),this.limitComponents(M,d)},this.syncInterval,this.control.hasPolyfillMethod("requestIdleCallback")))}break;case W.RemoveNode:if(d&&(l!=null&&l.length)){const b=l.map(j=>this.isLocalId(j+"")?this.transformKey(j):j);let N=0;const D=(v=this.storage[M])==null?void 0:v[d];D&&(Object.keys(D).map(j=>{b!=null&&b.includes(j)&&(N++,this.control.renderControl.isUsePageAuth(M)&&this.control.renderControl.delRenderPageElementId({viewId:M,scenePath:d,elementId:j}),this.updateValue(j,void 0,{isSync:p,viewId:M,scenePath:d,onApplied:()=>m(j)}))}),(k=this.control.pluginManager)==null||k.dispatchPluginEvent("syncStorage",M,d),this.control.isUseSimple||qe(()=>{var j;(j=this.control.miniMapManager)==null||j.updateMiniMapCamera(M)},this.syncInterval,this.control.hasPolyfillMethod("requestIdleCallback"))),w&&N===0&&m()}break;case W.UpdateNode:if(d&&i&&(u||r||a)){const b=this.isLocalId(i.toString())?this.transformKey(i):i,N=this.storage[M]&&this.storage[M][d]&&this.storage[M][d][b]||void 0;N&&(N.updateNodeOpt=u,(r||h)&&(N.ops=r,N.op=h),a&&(N.opt=a),N.type=W.FullWork,this.updateValue(b.toString(),N,{isSync:p,viewId:M,scenePath:d,onApplied:()=>m(b.toString())}),this.control.isUseSimple||qe(()=>{var D;(D=this.control.miniMapManager)==null||D.updateMiniMapCamera(M)},this.syncInterval,this.control.hasPolyfillMethod("requestIdleCallback")))}break;case W.Select:if(!d)return;let x;g!=null&&g.length&&(x=g.map(b=>this.isLocalId(b+"")?this.transformKey(b):b));const O=this.transformKey(Z),Y=this.storage[M]&&this.storage[M][d]&&this.storage[M][d][O]||void 0,A=a||(Y==null?void 0:Y.opt);x&&this.checkOtherSelector(O,x,{isSync:p,viewId:M,scenePath:d}),this.updateValue(O,x&&{type:W.Select,toolsType:T.Selector,opt:A,selectIds:x},{isSync:p,viewId:M,scenePath:d,onApplied:()=>m(O)});break}}checkOtherSelector(e,t,i){const{viewId:r,scenePath:s}=i;for(const a of Object.keys(this.storage[r][s]))if(a!==e&&this.getLocalId(a)===Z){const c=this.storage[r][s][a];if(c&&c.selectIds){const l=c.selectIds.filter(u=>!t.includes(u));l.length>0&&(c.selectIds=l),this.updateValue(a,l.length&&c||void 0,i)}}}setState(e,t){const{viewId:i,scenePath:r}=t,s=Ae(e);for(let a=0;a<s.length;a++){const c=s[a],l=e[c];typeof l<"u"?(this.storage[i]||(this.storage[i]={}),this.storage[i][r]||(this.storage[i][r]={}),this.storage[i][r][c]=l):delete this.storage[i][r][c]}this.runSyncService(t)}updateValue(e,t,i){var l;const{viewId:r,scenePath:s,storage:a}=i,c=a||this.storage;t===void 0?delete c[r][s][e]:(c[r]||(c[r]={}),c[r][s]||(c[r][s]={}),c[r][s][e]=t),i.onApplied,(l=i.onApplied)==null||l.call(i),this.runSyncService(i)}runSyncService(e){if(!this.control.renderControl.isWritable){this.Logger.error("[Appliance]: The current state is not writable and synchronization cannot be synchronized");return}this.asyncClockState||(this.asyncClockState=!0,e.isSync?(this.asyncClockState=!1,this.syncSerivice(e)):qe(()=>{this.asyncClockState=!1,this.syncSerivice(e)},this.syncInterval,this.control.hasPolyfillMethod("requestIdleCallback")))}syncSerivice(e={storage:this.storage}){const{storage:t}=e,i=t||this.storage,r=Ae(this.serviceStorage),s=Ae(i),a=new Map;for(const c of r){if(!s.includes(c)){a.set(c,void 0);continue}z.isEqual(this.serviceStorage[c],i[c])||this.syncViewData(i,c)}for(const c of s)r.includes(c)||a.set(c,i[c]);if(a.size>=s.length||a.size>5&&s.length<20)this.syncStorageView(i);else for(const[c,l]of a.entries())this.syncUpdataView(i,c,l)}syncViewData(e,t){const i=Ae(this.serviceStorage[t]),r=Ae(e[t]),s=new Map;for(const a of i){if(!r.includes(a)){s.set(a,void 0);continue}z.isEqual(this.serviceStorage[t][a],e[t][a])||this.syncScenePathData(e,t,a)}for(const a of r)i.includes(a)||s.set(a,e[t][a]);if(s.size>=r.length||s.size>5&&r.length<20)this.syncStorageScenePath(t,e[t]);else for(const[a,c]of s.entries())this.syncUpdataScenePath(e,t,a,c)}syncScenePathData(e,t,i){const r=Ae(this.serviceStorage[t][i]),s=Ae(e[t][i]),a=new Map;for(const c of r){if(!s.includes(c)){a.set(c,void 0);continue}z.isEqual(this.serviceStorage[t][i][c],e[t][i][c])||a.set(c,e[t][i][c])}for(const c of s)r.includes(c)||a.set(c,e[t][i][c]);if(a.size>=s.length||a.size>5&&s.length<50)this.syncStorageKey(t,i,e[t][i]);else for(const[c,l]of a.entries())this.syncUpdataKey(e,t,i,c,l)}syncUpdataView(e,t,i){var s;Object.keys(this.serviceStorage).length?(s=this.plugin)==null||s.updateAttributes([this.namespace,t],i):this.syncStorageView(e)}syncStorageView(e){var t;(t=this.plugin)==null||t.updateAttributes([this.namespace],e)}syncUpdataScenePath(e,t,i,r){var a;Object.keys(this.serviceStorage[t]).length?(a=this.plugin)==null||a.updateAttributes([this.namespace,t,i],r):this.syncStorageScenePath(t,e[t])}syncStorageScenePath(e,t){var i;(i=this.plugin)==null||i.updateAttributes([this.namespace,e],t)}syncUpdataKey(e,t,i,r,s){var c;Object.keys(this.serviceStorage[t][i]).length?(c=this.plugin)==null||c.updateAttributes([this.namespace,t,i,r],s):this.syncStorageKey(t,i,e[t][i])}syncStorageKey(e,t,i){var r;(r=this.plugin)==null||r.updateAttributes([this.namespace,e,t],i)}keyTransformWorkId(e){const t=e.split(Ve);return t.length===2?t[1]:e}destroy(){this.removeStorageStateListener(),this.serviceStorage={},this.storage={},this.removeAuthStateListener(),this.authStorage={},this.globalUndoRedoStackStorage={}}transformToSerializableUndoStackItemData(e){const{data:t,scenePath:i}=e,r={};for(const s of t)r[s.key]={dataType:s.dataType,data:s.data};return{data:r,scenePath:i}}dispatchUndoTicker(e){const{viewId:t,undoTickerId:i,data:r,syncType:s,operation:a}=e,c=a===je.syncUndoStack?"undoStack":"redoStack",l=s==="delete"?void 0:this.transformToSerializableUndoStackItemData(r);if(this.plugin){if(s==="delete"){const u=this.globalUndoRedoStackStorage[t]&&this.globalUndoRedoStackStorage[t][c];if(!u)return;delete u[i],this.plugin.updateAttributes([this.globalUndoRedoStackSpace,t,c,i],void 0);return}if(this.plugin.getAttributesValue([this.globalUndoRedoStackSpace]))if(this.plugin.getAttributesValue([this.globalUndoRedoStackSpace,t]))if(this.plugin.getAttributesValue([this.globalUndoRedoStackSpace,t,c]))this.globalUndoRedoStackStorage[t][c][i]=l,this.plugin.updateAttributes([this.globalUndoRedoStackSpace,t,c,i],l);else{const u={[i]:l};this.globalUndoRedoStackStorage[t][c]=u,this.plugin.updateAttributes([this.globalUndoRedoStackSpace,t,c],u)}else{const u={[c]:{[i]:l}};this.globalUndoRedoStackStorage[t]=u,this.plugin.updateAttributes([this.globalUndoRedoStackSpace,t],u)}else{const u={[t]:{[c]:{[i]:l}}};this.globalUndoRedoStackStorage=u,this.plugin.updateAttributes(this.globalUndoRedoStackSpace,u)}}}addGlobalUndoRedoStackListener(e){this.authDisposer=jn(async()=>{const t=this.getGlobalUndoRedoStackData();if(z.isEqual(this.globalUndoRedoStackStorage,t))return;const i=this.diffGlobalUndoRedoStackFun(this.globalUndoRedoStackStorage,t);this.globalUndoRedoStackStorage=t,e(i)})}diffGlobalUndoRedoStackFun(e,t){const i=Ae(e),r=Ae(t),s={};for(const a of r)if(!i.includes(a)||e[a]===void 0){s[a]={newValue:t[a],oldValue:void 0};continue}for(const a of i)if(!z.isEqual(e[a],t[a])){if(!r.includes(a)||t[a]===void 0){s[a]={newValue:void 0,oldValue:e[a]};continue}s[a]={newValue:t[a],oldValue:e[a]}}return s}dispatchPageAuth(e,t=!0){var l,u,h,g,p,d,M,w,m,y,S,v,k,C,x,O,Y,A,b,N,D,j,B,V,U,H,G,$,X,Te,se,fe,le,nt,ut,ht,dt,gt;const{operation:i,viewId:r,scenePath:s,pageId:a,pageData:c}=e;switch(i){case je.addPage:{if(!r||!s||!a)return;const De=[this.authSpace];Object.keys(this.authStorage).length&&De.push("pageAuth");const Pe=this.authStorage.pageAuth||{};this.authStorage.pageAuth=Pe,Object.keys(Pe).length&&De.push(r),Pe[r]=Pe[r]||{},Object.keys(Pe[r]).length&&De.push(s),Pe[r][s]=Pe[r][s]||{render:(c==null?void 0:c.render)||"localSelf",pages:{}},Object.keys(Pe[r][s].pages).length&&De.push("pages",a);const it={};if(c!=null&&c.elementIds)for(const Ft of c.elementIds.keys())it[Ft]=!0;Pe[r][s].pages[a]=it,t&&(De.length===1?(l=this.plugin)==null||l.updateAttributes(De,z.cloneDeep(this.authStorage)):De.length===2?(u=this.plugin)==null||u.updateAttributes(De,z.cloneDeep(Pe)):De.length===3?(h=this.plugin)==null||h.updateAttributes(De,z.cloneDeep(Pe[r])):De.length===4?(g=this.plugin)==null||g.updateAttributes(De,z.cloneDeep(Pe[r][s])):(p=this.plugin)==null||p.updateAttributes(De,z.cloneDeep(it)));return}case je.renderPage:{if(!r||!s||!(c!=null&&c.render))return;this.authStorage.pageAuth&&this.authStorage.pageAuth[r]&&this.authStorage.pageAuth[r][s]&&c.render!==this.authStorage.pageAuth[r][s].render&&(this.authStorage.pageAuth[r][s].render=c.render,t&&((d=this.plugin)==null||d.updateAttributes([this.authSpace,"pageAuth",r,s,"render"],c.render)));return}case je.deletePage:{if(!r||!s||!a)return;(S=(y=(m=(w=(M=this.authStorage)==null?void 0:M.pageAuth)==null?void 0:w[r])==null?void 0:m[s])==null?void 0:y.pages)!=null&&S[a]&&(delete this.authStorage.pageAuth[r][s].pages[a],t&&((v=this.plugin)==null||v.updateAttributes([this.authSpace,"pageAuth",r,s,"pages",a],void 0)));return}case je.clearPage:{if(!r||!s||!a)return;(Y=(O=(x=(C=(k=this.authStorage)==null?void 0:k.pageAuth)==null?void 0:C[r])==null?void 0:x[s])==null?void 0:O.pages)!=null&&Y[a]&&(delete this.authStorage.pageAuth[r][s].pages[a],t&&((A=this.plugin)==null||A.updateAttributes([this.authSpace,"pageAuth",r,s,"pages",a],{})));return}case je.addElement:{if(!r||!s||!a||!(c!=null&&c.elementId))return;(B=(j=(D=(N=(b=this.authStorage)==null?void 0:b.pageAuth)==null?void 0:N[r])==null?void 0:D[s])==null?void 0:j.pages)!=null&&B[a]&&(this.authStorage.pageAuth[r][s].pages[a][c.elementId]=!0,t&&((V=this.plugin)==null||V.updateAttributes([this.authSpace,"pageAuth",r,s,"pages",a,c.elementId],!0)));return}case je.deleteElement:{if(!r||!s||!a||!(c!=null&&c.elementId))return;(Te=(X=($=(G=(H=(U=this.authStorage)==null?void 0:U.pageAuth)==null?void 0:H[r])==null?void 0:G[s])==null?void 0:$.pages)==null?void 0:X[a])!=null&&Te[c.elementId]&&(delete this.authStorage.pageAuth[r][s].pages[a][c.elementId],t&&((se=this.plugin)==null||se.updateAttributes([this.authSpace,"pageAuth",r,s,"pages",a,c.elementId],void 0)));return}case je.clearViewScenePath:{if(!r||!s)return;(nt=(le=(fe=this.authStorage)==null?void 0:fe.pageAuth)==null?void 0:le[r])!=null&&nt[s]&&(delete this.authStorage.pageAuth[r][s],t&&((ut=this.plugin)==null||ut.updateAttributes([this.authSpace,"pageAuth",r,s],void 0)));return}case je.clearView:{if(!r)return;(dt=(ht=this.authStorage)==null?void 0:ht.pageAuth)!=null&&dt[r]&&(delete this.authStorage.pageAuth[r],t&&((gt=this.plugin)==null||gt.updateAttributes([this.authSpace,"pageAuth",r],void 0)));return}}}dispatchRenderAuth(e,t=!0){var l,u,h,g,p,d,M,w,m,y,S,v,k,C,x,O,Y,A,b,N;const{operation:i,viewId:r,uid:s,renderData:a,isClear:c}=e;if(r)switch(i){case He.setAuth:{if(!a||a.render===void 0&&a.hide===void 0&&a.clear===void 0){this.authStorage.renderAuth&&this.authStorage.renderAuth[r]&&(delete this.authStorage.renderAuth[r],t&&((l=this.plugin)==null||l.updateAttributes([this.authSpace,"renderAuth",r],void 0)));return}const D=[this.authSpace];Object.keys(this.authStorage).length&&D.push("renderAuth");const j=this.authStorage.renderAuth||{};Object.keys(j).length&&D.push(r),j[r]={},this.authStorage.renderAuth=j;const{render:B,hide:V,clear:U}=a;if(B===!0)j[r].render=!0;else if(z.isSet(B)){j[r].render={};for(const H of B.keys())j[r].render[H]=!0}if(V===!0)j[r].hide=!0;else if(z.isSet(V)){j[r].hide={};for(const H of V.keys())j[r].hide[H]=!0}if(U===!0)j[r].clear=!0;else if(z.isSet(U)){j[r].clear={};for(const H of U.keys())j[r].clear[H]=!0}t&&(D.length===1?(u=this.plugin)==null||u.updateAttributes(D,z.cloneDeep(this.authStorage)):D.length===2?(h=this.plugin)==null||h.updateAttributes(D,z.cloneDeep(j)):(g=this.plugin)==null||g.updateAttributes(D,z.cloneDeep(j[r])));return}case He.setShow:{if(!s)return;const D=[this.authSpace];Object.keys(this.authStorage).length&&D.push("renderAuth");const j=this.authStorage.renderAuth||{};Object.keys(j).length&&D.push(r),j[r]=j[r]||{},this.authStorage.renderAuth=j,Object.keys(j[r]).length&&D.push("render"),j[r].render=j[r].render||{},j[r].render!==!0&&(Object.keys(j[r].render).length&&D.push(s),j[r].render[s]=!0),j[r].hide!==!0&&((p=j[r].hide)!=null&&p[s])&&(delete j[r].hide[s],t&&((d=this.plugin)==null||d.updateAttributes([this.authSpace,"renderAuth",r,"hide",s],void 0))),t&&(D.length===1?(M=this.plugin)==null||M.updateAttributes(D,z.cloneDeep(this.authStorage)):D.length===2?(w=this.plugin)==null||w.updateAttributes(D,z.cloneDeep(j)):D.length===3?(m=this.plugin)==null||m.updateAttributes(D,z.cloneDeep(j[r])):(y=this.plugin)==null||y.updateAttributes(D,!0));return}case He.setHide:{if(!s)return;const D=[this.authSpace];Object.keys(this.authStorage).length&&D.push("renderAuth");const j=this.authStorage.renderAuth||{};Object.keys(j).length&&D.push(r),j[r]=j[r]||{},this.authStorage.renderAuth=j,Object.keys(j[r]).length&&D.push("hide"),j[r].hide=j[r].hide||{},j[r].hide!==!0&&(Object.keys(j[r].hide).length&&D.push(s),j[r].hide[s]=!0),j[r].render!==!0&&((S=j[r].render)!=null&&S[s])&&(delete j[r].render[s],t&&((v=this.plugin)==null||v.updateAttributes([this.authSpace,"renderAuth",r,"render",s],void 0))),t&&(D.length===1?(k=this.plugin)==null||k.updateAttributes(D,z.cloneDeep(this.authStorage)):D.length===2?(C=this.plugin)==null||C.updateAttributes(D,z.cloneDeep(j)):D.length===3?(x=this.plugin)==null||x.updateAttributes(D,z.cloneDeep(j[r])):(O=this.plugin)==null||O.updateAttributes(D,!0));return}case He.setClear:{if(!s)return;const D=[this.authSpace];Object.keys(this.authStorage).length&&D.push("renderAuth");const j=this.authStorage.renderAuth||{};Object.keys(j).length&&D.push(r),j[r]=j[r]||{},this.authStorage.renderAuth=j,Object.keys(j[r]).length&&D.push("clear"),j[r].clear=j[r].clear||{},j[r].clear!==!0&&(Object.keys(j[r].clear).length&&D.push(s),c?j[r].clear[s]=!0:delete j[r].clear[s]),t&&(D.length===1?(Y=this.plugin)==null||Y.updateAttributes(D,z.cloneDeep(this.authStorage)):D.length===2?(A=this.plugin)==null||A.updateAttributes(D,z.cloneDeep(j)):D.length===3?(b=this.plugin)==null||b.updateAttributes(D,z.cloneDeep(j[r])):(N=this.plugin)==null||N.updateAttributes(D,c?!0:void 0));return}}}addAuthStateListener(e){this.authDisposer=jn(async()=>{const t=this.getAuthSpaceData(),{renderAuth:i,pageAuth:r}=t;let s,a;z.isEqual(i,this.authStorage.renderAuth)||(s=this.diffAuthFun(this.authStorage.renderAuth||{},i||{}),this.authStorage.renderAuth=i),z.isEqual(r,this.authStorage.pageAuth)||(a=this.diffAuthPageFun(this.authStorage.pageAuth||{},r||{}),this.authStorage.pageAuth=r),(s||a)&&e(s,a)})}removeAuthStateListener(){this.authDisposer&&this.authDisposer()}diffAuthFun(e,t){const i=Ae(e),r=Ae(t),s={};for(const a of r)if(!i.includes(a)||e[a]===void 0){s[a]={newValue:t[a],oldValue:void 0};continue}for(const a of i)if(!z.isEqual(e[a],t[a])){if(!r.includes(a)||t[a]===void 0){s[a]={newValue:void 0,oldValue:e[a]};continue}s[a]={newValue:t[a],oldValue:e[a]}}return s}diffAuthPageFun(e,t){const i=Ae(e),r=Ae(t),s={};for(const a of r)if(!i.includes(a)||e[a]===void 0){s[a]={newValue:t[a],oldValue:void 0};continue}for(const a of i)if(!z.isEqual(e[a],t[a])){if(!r.includes(a)||t[a]===void 0){s[a]={newValue:void 0,oldValue:e[a]};continue}s[a]={newValue:t[a],oldValue:e[a]}}return s}};I(Re,"namespace","PluginState"),I(Re,"authSpace","PluginAuth"),I(Re,"globalUndoRedoStackSpace","GlobalUndoRedoStack"),I(Re,"componentsLimits",[500,1e3]);let et=Re;var Ue=(o=>(o[o.Draw=1]="Draw",o[o.Delete=2]="Delete",o[o.Update=3]="Update",o))(Ue||{});class YM{constructor(){I(this,"roomMembers",[]);I(this,"onChangeHooks",new Set)}setRoomMembers(n){this.executChangeUidHook(this.roomMembers,n),this.roomMembers=n}executChangeUidHook(n,e){const t={online:e.map(i=>{var r;return((r=i.payload)==null?void 0:r.uid)||i.session}),offline:n.map(i=>{var r;return((r=i.payload)==null?void 0:r.uid)||i.session})};this.onChangeHooks.forEach(i=>i(t))}getAllRoomMembers(){return this.roomMembers}getRoomMember(n){return this.roomMembers.find(e=>{var t;return((t=e.payload)==null?void 0:t.uid)===n})}isOnLine(n){return!!this.getRoomMember(n)}onUidChangeHook(n){this.onChangeHooks.add(n)}destroy(){this.onChangeHooks.clear()}}class BM{constructor(n){I(this,"expirationTime",we.cursor.expirationTime);I(this,"isEnableCursor");I(this,"internalMsgEmitter");I(this,"publicMsgEmitter");I(this,"control");I(this,"eventName","applianc-cursor");I(this,"displayer");I(this,"roomMember");I(this,"animationId");I(this,"maxLastSyncTime");I(this,"willSendEventWorkers",[]);I(this,"willConsumeEventWorkers",new Map);I(this,"sendEventTimerId");I(this,"animationDrawWorkers",new Map);I(this,"animationEventWorkers",new Map);I(this,"cursorInfoMap",new Map);I(this,"doneRenderCursorInfoMap",new Map);const{control:e,internalMsgEmitter:t,publicMsgEmitter:i}=n;this.internalMsgEmitter=t,this.publicMsgEmitter=i,this.expirationTime=z.isNumber(e.pluginOptions.extras.cursor.expirationTime)?e.pluginOptions.extras.cursor.expirationTime:this.expirationTime,this.control=e,this.roomMember=e.roomMember,this.maxLastSyncTime=this.control.pluginOptions.extras.syncOpt.interval,this.isEnableCursor=this.control.pluginOptions.extras.cursor.enable}activeCollector(){this.control.plugin&&this.isEnableCursor&&(this.displayer=this.control.room||this.control.play,this.displayer.addMagixEventListener(this.eventName,this.mainMagixEventListener.bind(this)))}mainMagixEventListener(n){var a;const{event:e,payload:t}=n;if(e!==this.eventName)return;const{uid:i,op:r,type:s}=t;if(((a=this.control.collector)==null?void 0:a.uid)!==i&&s===Kt.Cursor&&(r!=null&&r.length)){const c=this.willConsumeEventWorkers.get(i)||[];for(const l of r){const{viewId:u}=l;z.isNumber(l.consumPoint[0])&&z.isNumber(l.consumPoint[1])&&(l.consumPoint=this.control.viewContainerManager.transformToOriginPoint(l.consumPoint,u)),this.control.renderControl.isFilterCursor(u)&&c.unshift({...l,timestamp:this.control.worker.now})}this.willConsumeEventWorkers.set(i,c),this.runAnimation()}}onFocusViewChange(){this.isEnableCursor&&(this.checkDrawWorks(),this.runAnimation())}updateRoomMembers(n){const{offline:e}=n;for(const t of this.cursorInfoMap.keys())t&&e.includes(t)&&this.cursorInfoMap.delete(t)}getKey(n,e){return`${n}${Ve}${e}`}getUidAndviewId(n){const[e,t]=n.split(Ve);return{uid:e,viewId:t}}runAnimation(){this.animationId||(this.animationId=requestAnimationFrame(this.animationCursor.bind(this)))}checkDrawWorks(){var e;const n=this.control.viewContainerManager.focuedViewId;for(const[t,i]of this.animationDrawWorkers.entries()){const{viewId:r,uid:s}=this.getUidAndviewId(t);s!==((e=this.control.collector)==null?void 0:e.uid)&&r!==n&&i.workState===E.Done&&(i.consumPoint=[void 0,void 0])}}animationCursor(){this.animationId=void 0;const n=this.control.worker.now;for(const[t,i]of this.animationDrawWorkers.entries()){const{uid:r,viewId:s}=this.getUidAndviewId(t),a=this.roomMember.getRoomMember(r);if(!a){this.animationDrawWorkers.delete(t);continue}const{consumPoint:c,timestamp:l,workState:u}=i,h=this.cursorInfoMap.get(s)||new Map;c&&z.isNumber(c[0])&&z.isNumber(c[1])&&l+this.expirationTime>n?h.set(a.memberId,{x:c[0],y:c[1],roomMember:a,timestamp:l,type:1,workState:u}):h.delete(a.memberId),h.size?this.cursorInfoMap.set(s,h):this.cursorInfoMap.delete(s),this.animationDrawWorkers.delete(t)}const e=new Set;for(const[t,i]of this.cursorInfoMap.entries())if(i)for(const[r,s]of i.entries())s.type===1&&s.workState!==E.Done&&e.add(r);else this.cursorInfoMap.delete(t);for(const[t,i]of this.willConsumeEventWorkers.entries()){const r=this.roomMember.getRoomMember(t);if(z.isNumber(r==null?void 0:r.memberId)&&!e.has(r.memberId)){const s=i.pop();s?this.animationEventWorkers.set(t,s):this.willConsumeEventWorkers.delete(t)}}for(const[t,i]of this.animationEventWorkers.entries()){const r=this.roomMember.getRoomMember(t);if(!r){this.animationEventWorkers.delete(t);continue}const{viewId:s,consumPoint:a,timestamp:c}=i,l=this.cursorInfoMap.get(s)||new Map;a&&z.isNumber(a[0])&&z.isNumber(a[1])&&c+this.expirationTime>n?l.set(r.memberId,{x:a[0],y:a[1],roomMember:r,timestamp:c,type:0}):l.delete(r.memberId),l.size?this.cursorInfoMap.set(s,l):this.cursorInfoMap.delete(s),this.animationEventWorkers.delete(t)}for(const t of this.doneRenderCursorInfoMap.keys())this.cursorInfoMap.has(t)||(this.doneRenderCursorInfoMap.delete(t),this.internalMsgEmitter.emit([te.Cursor,t],[]));for(const[t,i]of this.cursorInfoMap.entries())if(i!=null&&i.size){const r=[];for(const[a,c]of i.entries()){const{timestamp:l,...u}=c;l+this.expirationTime>n?r.push(u):(i.delete(a),i.size===0&&(this.cursorInfoMap.delete(t),this.doneRenderCursorInfoMap.delete(t),this.internalMsgEmitter.emit([te.Cursor,t],[])))}const s=this.doneRenderCursorInfoMap.get(t);z.isEqual(s,r)||(this.doneRenderCursorInfoMap.set(t,r),this.internalMsgEmitter.emit([te.Cursor,t],r))}else this.cursorInfoMap.delete(t),this.doneRenderCursorInfoMap.delete(t),this.internalMsgEmitter.emit([te.Cursor,t],[]);(this.willConsumeEventWorkers.size||this.cursorInfoMap.size)&&this.runAnimation()}sendEvent(n,e){if(this.displayer&&Q(this.displayer)){const t=z.isNumber(n[0])&&z.isNumber(n[1])&&this.control.viewContainerManager.transformToScenePoint(n,e)||[void 0,void 0];this.willSendEventWorkers.push({consumPoint:t,viewId:e}),this.sendEventTimerId||(this.sendEventTimerId=setTimeout(()=>{this.dispatchMagixEvent()},this.maxLastSyncTime))}}dispatchMagixEvent(){var n;this.displayer&&Q(this.displayer)&&this.displayer.isWritable&&this.displayer.dispatchMagixEvent(this.eventName,{type:Kt.Cursor,op:z.cloneDeep(this.willSendEventWorkers),uid:(n=this.control.collector)==null?void 0:n.uid}),this.willSendEventWorkers.length=0,this.sendEventTimerId&&(clearTimeout(this.sendEventTimerId),this.sendEventTimerId=void 0)}collectServiceCursor(n){var s;if(!this.isEnableCursor&&!this.control.renderControl.isWritable)return;const{op:e,uid:t,workState:i,viewId:r}=n;if(t&&e&&i&&r){const a=this.roomMember.getRoomMember(t);if(!a||t===((s=this.control.collector)==null?void 0:s.uid))return;const c=this.getKey(t,r);let l=[void 0,void 0];if(z.isNumber(e[0])&&z.isNumber(e[1])){const[h,g]=this.control.viewContainerManager.transformToOriginPoint(e,r);l=[h,g]}if(i===E.Start){for(const h of this.cursorInfoMap.values())if(h!=null&&h.size)for(const g of h.keys())g===a.memberId&&h.delete(g)}const u={consumPoint:l,workState:i,viewId:r,timestamp:this.control.worker.now};if(i===E.Start||i===E.Done){const h=this.willConsumeEventWorkers.get(t);i===E.Start&&h&&this.willConsumeEventWorkers.delete(t),h&&i===E.Done&&(u.timestamp=u.timestamp-this.expirationTime)}this.animationDrawWorkers.set(c,u),this.runAnimation()}}unabled(){var n;this.displayer&&Q(this.displayer)&&(this.willSendEventWorkers.length=0,this.displayer.dispatchMagixEvent(this.eventName,{type:Kt.Cursor,op:[{viewId:this.control.viewContainerManager.focuedViewId,consumPoint:[void 0,void 0]}],uid:(n=this.control.collector)==null?void 0:n.uid}),this.sendEventTimerId&&(clearTimeout(this.sendEventTimerId),this.sendEventTimerId=void 0)),this.isEnableCursor||this.stopAnimation()}clearViewCursor(n){var e,t,i;for(const[r]of this.animationDrawWorkers.entries()){const{uid:s}=this.getUidAndviewId(r);s===((e=this.control.collector)==null?void 0:e.uid)&&n===n&&this.animationDrawWorkers.delete(r)}for(const[r]of this.willConsumeEventWorkers.entries())r===((t=this.control.collector)==null?void 0:t.uid)&&this.willConsumeEventWorkers.delete(r);for(const[r]of this.animationEventWorkers.entries())r===((i=this.control.collector)==null?void 0:i.uid)&&this.animationEventWorkers.delete(r);for(const[r]of this.cursorInfoMap.entries())r===r&&(this.cursorInfoMap.delete(r),this.doneRenderCursorInfoMap.delete(r),this.internalMsgEmitter.emit([te.Cursor,r],[]))}stopAnimation(){this.animationDrawWorkers.clear(),this.willConsumeEventWorkers.clear(),this.cursorInfoMap.clear()}destroy(){var n;(n=this.displayer)==null||n.removeMagixEventListener(this.eventName),this.stopAnimation()}}class Qe{constructor(){I(this,"useEmtMsg");I(this,"emtType");I(this,"control");I(this,"mainEngine");I(this,"collectListener",(n,e)=>{this.collect(n,e)})}static dispatch(n,e,t){var i;(i=ye.InternalMsgEmitter)==null||i.emit([n,e],t)}get serviceColloctor(){return this.control.collector}registerForMainEngine(n,e){return this.emtType=n,this.control=e,this.mainEngine=e.worker,this.mainEngine.internalMsgEmitter.on([this.emtType,this.emitEventType],this.collectListener),this}destroy(){this.emtType&&this.mainEngine&&this.mainEngine.internalMsgEmitter.off([this.emtType,this.emitEventType],this.collectListener)}collectForLocalWorker(n,e){var t,i,r;for(const[s,a]of n)(t=this.mainEngine)==null||t.queryTaskBatchData(a).forEach(c=>{var l;(l=this.mainEngine)==null||l.taskBatchData.delete(c)}),(i=this.mainEngine)==null||i.taskBatchData.add(s);if(e){this.mainEngine.consume();return}(r=this.mainEngine)==null||r.runAnimation()}collectForServiceWorker(n){qe(()=>{n.forEach(e=>{var t;(t=this.serviceColloctor)==null||t.dispatch(e)})},this.mainEngine.maxLastSyncTime,this.control.hasPolyfillMethod("requestIdleCallback"))}pause(){var n;if(this.lastEmtData){this.useEmtMsg=!0;const e={...this.lastEmtData,workState:E.Done};this.collect(e,!0),(n=ye.InternalMsgEmitter)==null||n.emit(R.ActiveMethod,!1)}}recover(){var n;this.useEmtMsg&&ye.InternalMsgEmitter.hasListeners(R.ActiveMethod)&&((n=ye.InternalMsgEmitter)==null||n.emit(R.ActiveMethod,!0))}}function uo(o,n,e){return`${e.isLocalId(o)?o:e.getLocalId(o)}-${n}`}function WM(o,n,e){const t=new Map,i=[];for(const r of o){const s=uo(r,n,e);t.set(r,s),i.push(s)}return{copyNodeKeyBySourceKey:t,expectedWorkIds:i}}class VM extends Qe{constructor(){super(...arguments);I(this,"lastEmtData");I(this,"emitEventType",R.CopyNode)}collect(e){var l;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,viewId:i,requestId:r}=e,s=this.control.viewContainerManager.getView(i);if(!(s!=null&&s.displayer))return;const a=s.focusScenePath,c=this.mainEngine.now;this.mainEngine.internalMsgEmitter.emit("addUndoTicker",c,i,{render:!0,storage:!0,copyAck:!0});for(const u of t){const h=u.toString(),p=this.serviceColloctor.isLocalId(h)?this.serviceColloctor.transformKey(u):h,d=(l=this.serviceColloctor.getStorageData(i,a))==null?void 0:l[p];if(d){if(u===Z){const M=d&&this.copySelector({viewId:i,store:d});M&&this.pasteSelector({...M,viewId:i,scenePath:a,undoTickerId:c,requestId:r});break}if(d.toolsType===T.Text&&d.opt&&d.opt.workState&&d.opt.workState!==E.Done){const M=d&&this.copyText({viewId:i,store:d});M&&this.pasteText({...M,viewId:i,scenePath:a,key:p,store:d,undoTickerId:c,requestId:r});break}}}}copyText(e){const{viewId:t,store:i}=e,r=this.control.viewContainerManager.getView(t);if(!this.serviceColloctor||!r)return;const s=r==null?void 0:r.cameraOpt,a=s&&[s.centerX,s.centerY],c=i.opt,l=c.boxPoint&&c.boxSize&&[c.boxPoint[0]+c.boxSize[0]/2,c.boxPoint[1]+c.boxSize[1]/2];return{bgCenter:a,textCenter:l}}pasteText(e){var w,m;const{bgCenter:t,textCenter:i,store:r,key:s,viewId:a,scenePath:c,undoTickerId:l,requestId:u}=e,h=this.control.viewContainerManager.getView(a);if(!this.serviceColloctor||!h)return;const g=Math.floor(Math.random()*30+1),p=((w=h.cameraOpt)==null?void 0:w.scale)||1,d=t&&i&&[t[0]-i[0]+g,t[1]-i[1]+g]||[g/p,g/p],M=uo(s,l,this.serviceColloctor);if(r.toolsType===T.Text&&r.opt){const y=r.opt;if(y&&y.boxPoint&&y.text){y.workState=E.Done;const S=y.boxPoint;y.boxPoint=[Math.round(S[0]+d[0]),Math.round(S[1]+d[1])],y.workState=E.Done;const v=this.control.viewContainerManager.transformToOriginPoint(y.boxPoint,a);this.control.textEditorManager.createTextForMasterController({workId:M,x:v[0],y:v[1],opt:y,scale:((m=h.cameraOpt)==null?void 0:m.scale)||1,type:Ke.Text,isActive:!1,viewId:a,scenePath:c,requestId:u,emitEventType:R.CopyNode}),this.collectForServiceWorker([{...r,opt:y,type:W.FullWork,workId:M,viewId:a,scenePath:c,needUndoTicker:l,requestId:u,emitEventType:R.CopyNode}]),l&&this.mainEngine.internalMsgEmitter.emit("finalizeRequested",l,a,[M],c)}}}copySelector(e){var M,w,m,y,S,v,k,C,x;const{viewId:t,store:i}=e,r=this.control.viewContainerManager.getView(t),s=i.selectIds;if(!this.serviceColloctor||!(s!=null&&s.length)||!r)return;const a=new Map,c={offset:{x:0,y:0},cameraOpt:{centerX:((M=r.cameraOpt)==null?void 0:M.centerX)||0,centerY:((w=r.cameraOpt)==null?void 0:w.centerY)||0,scale:((m=r.cameraOpt)==null?void 0:m.scale)||1}},l=this.control.hasOffscreenCanvas&&((y=r.displayer.canvasBgRef.current)==null?void 0:y.getBoundingClientRect())||((S=r.displayer.canvasContainerRef.current)==null?void 0:S.getBoundingClientRect()),u=(k=(v=r.displayer)==null?void 0:v.floatBarRef.current)==null?void 0:k.getBoundingClientRect(),h=l&&[l.x+l.width/2,l.y+l.height/2],g=u&&[u.x+u.width/2,u.y+u.height/2],p=h&&r.viewData&&r.viewData.convertToPointInWorld({x:h[0],y:h[1]}),d=g&&r.viewData&&r.viewData.convertToPointInWorld({x:g[0],y:g[1]});p&&d&&(c.offset={x:p.x-d.x,y:p.y-d.y});for(const O of s){const Y=this.serviceColloctor.isLocalId(O)?this.serviceColloctor.transformKey(O):O,A=(x=(C=this.serviceColloctor)==null?void 0:C.getStorageData(r.id,r.focusScenePath))==null?void 0:x[Y];A&&a.set(O,A)}return{copyStores:a,copyCoordInfo:c}}pasteSelector(e){var S,v,k,C;const{copyStores:t,copyCoordInfo:i,viewId:r,scenePath:s,undoTickerId:a,requestId:c}=e,l=this.control.viewContainerManager.getView(r);if(!t.size||!this.serviceColloctor||!l)return;const{offset:u,cameraOpt:h}=i,{scale:g}=h,p=Math.floor(Math.random()*30+1),d=u&&[u.x+p,u.y+p]||[p/g,p/g],M=[],w=[],{copyNodeKeyBySourceKey:m,expectedWorkIds:y}=WM(t.keys(),a,this.serviceColloctor);a&&y.length&&this.mainEngine.internalMsgEmitter.emit("finalizeRequested",a,r,y,s);for(const[x,O]of t.entries()){const Y=m.get(x);if(!Y)continue;const A={useAnimation:!1};if(O.toolsType===T.Text&&O.opt){const b=O.opt;if(b&&b.boxPoint&&b.text){b.workState=E.Done;const N=b.boxPoint;b.boxPoint=[Math.round(N[0]+d[0]),Math.round(N[1]+d[1])],b.workState=E.Done;const D=this.control.viewContainerManager.transformToOriginPoint(b.boxPoint,r);this.control.textEditorManager.createTextForMasterController({workId:Y,x:D[0],y:D[1],opt:b,scale:((S=l.cameraOpt)==null?void 0:S.scale)||1,type:Ke.Text,isActive:!1,viewId:r,scenePath:s,requestId:c,emitEventType:R.CopyNode})}w.push({...O,opt:b,type:W.FullWork,workId:Y,viewId:r,scenePath:s,requestId:c,needUndoTicker:a,emitEventType:R.CopyNode});continue}if((O.toolsType===T.Image||O.toolsType===T.BackgroundSVG)&&(O.opt.uuid=Y,O.opt.centerX=O.opt.centerX+d[0],O.opt.centerY=O.opt.centerY+d[1]),O.ops){const b=zt(O.ops).map((D,j)=>{const B=j%3;return B===0?D+d[0]:B===1?D+d[1]:D}),N=St(b);O.ops=N}if((v=O==null?void 0:O.opt)!=null&&v.eraserlines&&(k=O==null?void 0:O.opt)!=null&&k.eraserlines.length)for(const b of(C=O==null?void 0:O.opt)==null?void 0:C.eraserlines){const{op:N}=b;for(let D=0;D<N.length;D++){const j=N[D].map((B,V)=>V%2?B+d[1]:B+d[0]);b.op[D]=j}}w.push({...O,updateNodeOpt:A,type:W.FullWork,workId:Y,viewId:r,scenePath:s,requestId:c,needUndoTicker:a,emitEventType:R.CopyNode}),M.push([{...O,updateNodeOpt:A,workId:Y,msgType:W.FullWork,dataType:J.Local,emitEventType:R.CopyNode,willSyncService:!1,willRefresh:!0,viewId:r,requestId:c,needUndoTicker:this.control.viewContainerManager.getUndoTickerId(r),isRunBackgroundThread:this.control.isUseBackgroundThread},{workId:Y,msgType:W.FullWork,emitEventType:R.CopyNode}])}M.length&&this.collectForLocalWorker(M),w.length&&this.collectForServiceWorker(w)}}class FM extends Qe{constructor(){super(...arguments);I(this,"lastEmtData");I(this,"emitEventType",R.SetColorNode);I(this,"undoTickerId")}ensureUndoTicker(e,t,i,r){if(!(i===E.Start||i===E.Done&&!this.undoTickerId))return this.undoTickerId;const a=this.mainEngine.now;return this.undoTickerId=a,this.mainEngine.internalMsgEmitter.emit("addUndoTicker",a,e,{render:!0,storage:!0}),a}setTextColor(e,t,i,r,s,a){const{fontColor:c,fontBgColor:l}=i;t.opt&&(c&&(t.opt.fontColor=c),l&&(t.opt.fontBgColor=l),this.control.textEditorManager.updateTextForMasterController({workId:e,opt:t.opt,viewId:r,canSync:!0,canWorker:!0,requestId:s,needUndoTicker:a}))}collect(e){var k,C;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,strokeColor:i,fillColor:r,fontColor:s,fontBgColor:a,viewId:c,workState:l,thickness:u,strokeType:h,requestId:g}=e,p=this.control.viewContainerManager.getView(c);if(!(p!=null&&p.displayer))return;const d=p.focusScenePath,M=[...t],w=this.serviceColloctor.storage,m=[],y={},S=this.ensureUndoTicker(c,d,l,t);this.undoTickerId&&(this.control.textEditorManager.UndoTickerId=this.undoTickerId);const v=new Set;for(;M.length;){const x=M.pop();if(!x)continue;const O=x.toString(),Y=this.serviceColloctor.isLocalId(O),A=Y?this.serviceColloctor.transformKey(x):O;let b=O;!Y&&this.serviceColloctor.isOwn(b)&&(b=this.serviceColloctor.getLocalId(b));const N=(C=(k=w==null?void 0:w[c])==null?void 0:k[d])==null?void 0:C[A];if(N){const D=N.updateNodeOpt||{};if(s||a){if(s){D.fontColor=s;const[B,V,U,H]=qt(s);y.textColor=[B,V,U],y.textOpacity=H}if(a)if(D.fontBgColor=an(a)?"transparent":a,an(a))y.textBgColor=void 0,y.textBgOpacity=void 0;else{const[B,V,U,H]=qt(a);y.textBgColor=[B,V,U],y.textBgOpacity=H}if(N.toolsType===T.Text&&N.opt&&l!==E.Start){b&&l===E.Done&&v.add(b.toString()),this.setTextColor(b,en(N),D,c,g,l===E.Done&&S||void 0);continue}}if(i){D.strokeColor=i;const[B,V,U,H]=qt(i);y.strokeColor=[B,V,U],y.strokeOpacity=H}if(r)if(D.fillColor=an(r)?"transparent":r,an(r))y.fillColor=void 0,y.fillOpacity=void 0;else{const[B,V,U,H]=qt(r);y.fillColor=[B,V,U],y.fillOpacity=H}u&&(D.thickness=u,y.strokeWidth=u),h&&(y.strokeType=h,D.strokeType=h,D.lineCap=this.control.getLineCap(h),D.lineDash=this.control.getLineDash(h));const j={workId:b,msgType:W.UpdateNode,dataType:J.Local,updateNodeOpt:D,emitEventType:this.emitEventType,willRefresh:!0,willRefreshSelector:!0,willSyncService:!0,textUpdateForWoker:!0,viewId:c,requestId:g,needUndoTicker:l===E.Done&&S||void 0};b&&l===E.Done&&v.add(b.toString()),m.push([j,{workId:b,msgType:W.UpdateNode,emitEventType:this.emitEventType}])}}if(l===E.Done&&S){const x=[...v];x.length&&this.mainEngine.internalMsgEmitter.emit("finalizeRequested",S,c,x,d)}m.length?(l===E.Done&&(this.undoTickerId=void 0,this.control.textEditorManager.UndoTickerId=void 0),this.collectForLocalWorker(m)):l===E.Done&&(this.undoTickerId=void 0,this.control.textEditorManager.UndoTickerId=void 0),Object.keys(y).length&&setTimeout(()=>{var x;(x=this.control.room)==null||x.setMemberState(y)},0)}}class $M extends Qe{constructor(){super(...arguments);I(this,"lastEmtData");I(this,"emitEventType",R.ZIndexNode);I(this,"zIndexMap",new Map);I(this,"zIndexMapForBackgroundSVG",new Map)}clearZIndex(e){this.zIndexMap.delete(e),this.zIndexMapForBackgroundSVG.delete(e)}getMinZIndex(e){var t;return((t=this.zIndexMap.get(e))==null?void 0:t.min)||0}getMinZIndexForBackgroundSVG(e){var t;return((t=this.zIndexMapForBackgroundSVG.get(e))==null?void 0:t.min)||0}getMaxZIndex(e){var t;return((t=this.zIndexMap.get(e))==null?void 0:t.max)||0}getMaxZIndexForBackgroundSVG(e){var t;return((t=this.zIndexMapForBackgroundSVG.get(e))==null?void 0:t.max)||0}setMaxZIndex(e,t){const i=this.getMinZIndex(t);this.zIndexMap.set(t,{min:i,max:e})}setMaxZIndexForBackgroundSVG(e,t){const i=this.getMinZIndexForBackgroundSVG(t);this.zIndexMapForBackgroundSVG.set(t,{min:i,max:e})}setMinZIndex(e,t){const i=this.getMaxZIndex(t);this.zIndexMap.set(t,{min:e,max:i})}setMinZIndexForBackgroundSVG(e,t){const i=this.getMaxZIndexForBackgroundSVG(t);this.zIndexMapForBackgroundSVG.set(t,{min:e,max:i})}addMaxLayer(e){const t=this.getMaxZIndex(e)+1;this.setMaxZIndex(t,e)}addMaxLayerForBackgroundSVG(e){const t=this.getMaxZIndexForBackgroundSVG(e)+1;this.setMaxZIndexForBackgroundSVG(t,e)}addMinLayer(e){const t=this.getMinZIndex(e)-1;this.setMinZIndex(t,e)}addMinLayerForBackgroundSVG(e){const t=this.getMinZIndexForBackgroundSVG(e)-1;this.setMinZIndexForBackgroundSVG(t,e)}correct(e){const t=e.sort((i,r)=>i[1]-r[1]);for(let i=1;i<t.length;i++){const r=t[i][1],s=t[i-1][1];r<=s&&(t[i][1]=s+1)}return t}collect(e){var w,m;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,layer:i,viewId:r,requestId:s}=e,a=this.control.viewContainerManager.getView(r);if(!(a!=null&&a.displayer))return;const c=a.focusScenePath,l=[...t],u=this.serviceColloctor.storage,h=[],g=[],p=[],d=this.mainEngine.now;for(this.mainEngine.internalMsgEmitter.emit("addUndoTicker",d,r,{render:!0,storage:!0});l.length;){const y=l.pop();if(!y)continue;const S=y.toString(),v=this.serviceColloctor.isLocalId(S),k=v?this.serviceColloctor.transformKey(y):S;let C=S;!v&&this.serviceColloctor.isOwn(C)&&(C=this.serviceColloctor.getLocalId(C));const x=en(u[r][c][k]);let O,Y;if(x&&C===Z){if(x.selectIds){for(const N of x.selectIds){const D=M(N,this.serviceColloctor),j=(m=(w=u==null?void 0:u[r])==null?void 0:w[c])==null?void 0:m[D];j&&j.toolsType===T.BackgroundSVG?(p.push(N),p.sort((B,V)=>{var G,$,X,Te;const U=(($=(G=u[M(B,this.serviceColloctor)])==null?void 0:G.opt)==null?void 0:$.zIndex)||0,H=((Te=(X=u[M(B,this.serviceColloctor)])==null?void 0:X.opt)==null?void 0:Te.zIndex)||0;return U>H?1:B<V?-1:0})):(g.push(N),g.sort((B,V)=>{var G,$,X,Te;const U=(($=(G=u[M(B,this.serviceColloctor)])==null?void 0:G.opt)==null?void 0:$.zIndex)||0,H=((Te=(X=u[M(B,this.serviceColloctor)])==null?void 0:X.opt)==null?void 0:Te.zIndex)||0;return U>H?1:B<V?-1:0}))}const A=x.updateNodeOpt||{};A.zIndexLayer=i;const b={workId:y,msgType:W.UpdateNode,dataType:J.Local,updateNodeOpt:A,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:r,requestId:s,needUndoTicker:this.control.viewContainerManager.getUndoTickerId(r)};g.length&&(i===st.Top?(this.addMaxLayer(r),O=this.getMaxZIndex(r)):(this.addMinLayer(r),O=this.getMinZIndex(r)),g.forEach(N=>{var V,U,H,G,$;const D=(V=this.serviceColloctor)==null?void 0:V.isLocalId(N);let j=D&&((U=this.serviceColloctor)==null?void 0:U.transformKey(N))||N;const B=(G=(H=u==null?void 0:u[r])==null?void 0:H[c])==null?void 0:G[j];B&&(!D&&(($=this.serviceColloctor)!=null&&$.isOwn(j))&&(j=this.serviceColloctor.getLocalId(j)),A.zIndex=O,B!=null&&B.opt&&(B.opt.zIndex=O))})),p.length&&(i===st.Top?(this.addMaxLayerForBackgroundSVG(r),Y=this.getMaxZIndexForBackgroundSVG(r)):(this.addMinLayerForBackgroundSVG(r),Y=this.getMinZIndexForBackgroundSVG(r)),p.forEach(N=>{var V,U,H,G,$;const D=(V=this.serviceColloctor)==null?void 0:V.isLocalId(N);let j=D&&((U=this.serviceColloctor)==null?void 0:U.transformKey(N))||N;const B=(G=(H=u==null?void 0:u[r])==null?void 0:H[c])==null?void 0:G[j];B&&(!D&&(($=this.serviceColloctor)!=null&&$.isOwn(j))&&(j=this.serviceColloctor.getLocalId(j)),A.zIndexForBackgroundSVG=Y,B!=null&&B.opt&&(B.opt.zIndex=Y))})),b.willSerializeData=!0,h.push([b,{workId:y,msgType:W.UpdateNode,emitEventType:this.emitEventType}])}continue}}h.length&&(this.mainEngine.internalMsgEmitter.emit("finalizeRequested",d,r,h.map(([y])=>{var S;return(S=y.workId)==null?void 0:S.toString()}).filter(Boolean),c),this.collectForLocalWorker(h));function M(y,S){return S.isLocalId(y)&&S.transformKey(y)||y}}}class GM extends Qe{constructor(){super(...arguments);I(this,"lastEmtData");I(this,"emitEventType",R.TranslateNode);I(this,"cachePosition")}collect(e,t){var M,w,m;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:i,position:r,workState:s,viewId:a}=e;this.lastEmtData=e;const c=this.control.viewContainerManager.getView(a);if(!(c!=null&&c.displayer))return;const l=c.focusScenePath,u=[...i],h=(M=this.serviceColloctor)==null?void 0:M.storage,g=[],p=new Set,d=s===E.Start&&this.mainEngine.now||void 0;for(d&&this.mainEngine.internalMsgEmitter.emit("addUndoTicker",d,a,{render:!0,storage:!0,isWritable:!0});u.length;){const y=u.pop();if(!y)continue;const S=y.toString(),v=this.serviceColloctor.isLocalId(S),k=v&&this.serviceColloctor.transformKey(y)||S;let C=S;!v&&this.serviceColloctor.isOwn(C)&&(C=this.serviceColloctor.getLocalId(C));const x=(m=(w=h==null?void 0:h[a])==null?void 0:w[l])==null?void 0:m[k];if(x&&C===Z){if(x.selectIds){s===E.Done&&x.selectIds.forEach(Y=>{p.add(Y.toString())});const O=this.control.viewContainerManager.transformToScenePoint([r.x,r.y],a);if(s===E.Start&&(this.cachePosition=O),this.cachePosition){const Y=x.updateNodeOpt||{};Y.translate=[O[0]-this.cachePosition[0],O[1]-this.cachePosition[1]],Y.workState=s,this.control.cursor.isEnableCursor?Y.useAnimation=!1:(Y.uid=this.serviceColloctor.uid,s===E.Start?Y.useAnimation=!1:s===E.Done&&(Y.useAnimation=!0));const A={workId:y,msgType:W.UpdateNode,dataType:J.Local,updateNodeOpt:Y,emitEventType:this.emitEventType,willSyncService:!0,textUpdateForWoker:!0,viewId:a,smoothSync:this.mainEngine.smoothSync};s===E.Done&&(A.textUpdateForWoker=!0,A.willSerializeData=!0,this.cachePosition=void 0,A.needUndoTicker=this.control.viewContainerManager.getUndoTickerId(a)),g.push([A,{workId:y,msgType:W.UpdateNode,emitEventType:this.emitEventType,workState:s}])}}continue}}if(s===E.Start?this.mainEngine.unWritable():s===E.Done&&(this.mainEngine.abled(),this.lastEmtData=void 0),g.length){if(s===E.Done){const y=this.control.viewContainerManager.getUndoTickerId(a);if(y){const S=[...p];this.mainEngine.internalMsgEmitter.emit("finalizeRequested",y,a,S,l)}}this.collectForLocalWorker(g,t)}}}class QM extends Qe{constructor(){super(...arguments);I(this,"lastEmtData");I(this,"emitEventType",R.DeleteNode)}collect(e){var p,d;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,viewId:i,requestId:r}=e,s=this.control.viewContainerManager.getView(i);if(!(s!=null&&s.displayer))return;const a=s.focusScenePath,c=this.serviceColloctor.storage,l=[...t],u=[],h=[],g=this.mainEngine.now;for(this.control.textEditorManager.UndoTickerId=g;l.length;){const M=l.pop();if(!M)continue;const w=M.toString(),m=this.serviceColloctor.isLocalId(w),y=m?this.serviceColloctor.transformKey(M):w,S=(d=(p=c==null?void 0:c[i])==null?void 0:p[a])==null?void 0:d[y];if(S){let v=w;if(!m&&this.serviceColloctor.isOwn(v)&&(v=this.serviceColloctor.getLocalId(v)),S.toolsType===T.Text){this.control.textEditorManager.delete(v,!0,!0);continue}h.push(v)}}h.length&&(this.mainEngine.internalMsgEmitter.emit("addUndoTicker",g,i,{render:!0,storage:!0}),this.mainEngine.internalMsgEmitter.emit("finalizeRequested",g,i,h.slice(),a),u.push([{msgType:W.RemoveNode,emitEventType:R.DeleteNode,removeIds:h,dataType:J.Local,willSyncService:!0,willRefresh:!0,viewId:i,requestId:r,isRunBackgroundThread:this.control.isUseBackgroundThread,needUndoTicker:this.control.viewContainerManager.getUndoTickerId(i)},void 0]),this.collectForLocalWorker(u))}}class ZM extends Qe{constructor(){super(...arguments);I(this,"lastEmtData");I(this,"emitEventType",R.ScaleNode);I(this,"targetText",new Map);I(this,"cacheTextInfo",new Map)}async setTextStyle(e,t,i){const r=await this.control.textEditorManager.updateTextControllerWithEffectAsync({workId:e,opt:t,viewId:i,canSync:!1,canWorker:!1});return{key:e,textInfo:r}}async collect(e,t){var y,S,v,k,C,x,O;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:i,workState:r,viewId:s,originPoint:a,scenePoint:c,dir:l,scale:u,translate:h}=e;this.lastEmtData=e;const g=this.control.viewContainerManager.getView(s);if(!(g!=null&&g.displayer))return;const p=g.focusScenePath,d=[...i],M=(y=this.serviceColloctor)==null?void 0:y.storage,w=[],m=r===E.Start&&this.mainEngine.now||void 0;for(m&&(this.mainEngine.internalMsgEmitter.emit("addUndoTicker",m,s,{render:!0,storage:!0,isWritable:!0}),this.control.textEditorManager.UndoTickerId=m);d.length;){const Y=d.pop();if(!Y)continue;const A=Y.toString(),b=this.serviceColloctor.isLocalId(A),N=b&&this.serviceColloctor.transformKey(Y)||A;let D=A;!b&&this.serviceColloctor.isOwn(D)&&(D=this.serviceColloctor.getLocalId(D));const j=(v=(S=M==null?void 0:M[s])==null?void 0:S[p])==null?void 0:v[N];if(j&&D===Z&&j.selectIds){const B=j.updateNodeOpt||{};if(B.dir=l,B.originPoint=a,B.scenePoint=c,B.workState=r,B.scale=u,B.translate=h,r===E.Start){this.cacheTextInfo.clear();for(const U of j.selectIds){const H=(k=this.serviceColloctor)==null?void 0:k.isLocalId(U),G=H&&((C=this.serviceColloctor)==null?void 0:C.transformKey(U))||U;let $=G;!H&&((x=this.serviceColloctor)!=null&&x.isOwn(G))&&($=this.serviceColloctor.getLocalId(G));const X=this.control.textEditorManager.get($);X&&r===E.Start&&this.targetText.set($,en(X))}}if(this.targetText.size&&r!==E.Start&&u){const U=[];for(const[G,$]of this.targetText.entries()){const{opt:X}=$,Te=Math.floor(X.fontSize*u[0]),se=this.cacheTextInfo.get(G),fe=!se&&X.fontSize!==Te||se&&se.fontSize!==Te||!1,le=(O=this.control.textEditorManager.get(G))==null?void 0:O.opt;if(fe&&le&&X.boxSize&&X.boxPoint){const nt=this.setTextStyle(G,{...le,fontSize:Te},s);U.push(nt)}}const H=await Promise.all(U);for(const G of H)if(G){const{key:$,textInfo:X}=G;this.cacheTextInfo.set($,{fontSize:X.opt.fontSize,boxSize:X.opt.boxSize,boxPoint:X.opt.boxPoint})}B.textInfos=this.cacheTextInfo}this.control.cursor.isEnableCursor?B.useAnimation=!1:(B.uid=this.serviceColloctor.uid,r===E.Start?B.useAnimation=!1:r===E.Done&&(B.useAnimation=!0));const V={workId:Y,msgType:W.UpdateNode,dataType:J.Local,updateNodeOpt:B,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:s,smoothSync:this.mainEngine.smoothSync};r===E.Done&&(V.willSerializeData=!0,this.targetText.clear(),V.needUndoTicker=this.control.viewContainerManager.getUndoTickerId(s)),w.push([V,{workId:Y,msgType:W.UpdateNode,emitEventType:this.emitEventType,workState:r}]);continue}}if(r===E.Start?this.mainEngine.unWritable():r===E.Done&&(this.mainEngine.abled(),this.lastEmtData=void 0),w.length){if(r===E.Done){const Y=this.control.viewContainerManager.getUndoTickerId(s);Y&&this.mainEngine.internalMsgEmitter.emit("finalizeRequested",Y,s,w.map(([A])=>{var b;return(b=A.workId)==null?void 0:b.toString()}).filter(Boolean),p)}this.collectForLocalWorker(w,t)}}}class HM extends Qe{constructor(){super(...arguments);I(this,"lastEmtData");I(this,"emitEventType",R.RotateNode);I(this,"cacheOriginRotate",0)}collect(e,t){var M,w,m,y,S,v,k;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:i,angle:r,workState:s,viewId:a}=e;this.lastEmtData=e;const c=this.control.viewContainerManager.getView(a);if(!(c!=null&&c.displayer))return;const l=c.focusScenePath,u=[...i],h=(M=this.serviceColloctor)==null?void 0:M.storage,g=[],p=new Set,d=s===E.Start&&this.mainEngine.now||void 0;for(d&&this.mainEngine.internalMsgEmitter.emit("addUndoTicker",d,a,{render:!0,storage:!0,isWritable:!0});u.length;){const C=u.pop();if(!C)continue;const x=C.toString(),O=this.serviceColloctor.isLocalId(x),Y=O&&this.serviceColloctor.transformKey(C)||x;let A=x;!O&&this.serviceColloctor.isOwn(A)&&(A=this.serviceColloctor.getLocalId(A));const b=(m=(w=h==null?void 0:h[a])==null?void 0:w[l])==null?void 0:m[Y];if(b&&A===Z){if(((y=b.selectIds)==null?void 0:y.length)===1){const N=b.selectIds[0];if(s===E.Done&&p.add(N.toString()),s===E.Start){const V=((S=this.serviceColloctor)==null?void 0:S.isLocalId(N))&&((v=this.serviceColloctor)==null?void 0:v.transformKey(N))||N,U=h[a][l][V];this.cacheOriginRotate=((k=U==null?void 0:U.opt)==null?void 0:k.rotate)||0}const D=b.updateNodeOpt||{};D.angle=(r+this.cacheOriginRotate)%360,D.workState=s,this.control.cursor.isEnableCursor?D.useAnimation=!1:(D.uid=this.serviceColloctor.uid,s===E.Start?D.useAnimation=!1:s===E.Done&&(D.useAnimation=!0));const j={workId:C,msgType:W.UpdateNode,dataType:J.Local,updateNodeOpt:D,emitEventType:this.emitEventType,willRefreshSelector:!1,willSyncService:!0,viewId:a,smoothSync:this.mainEngine.smoothSync};s===E.Done&&(j.willRefreshSelector=!0,j.willSerializeData=!0,this.cacheOriginRotate=0,j.needUndoTicker=this.control.viewContainerManager.getUndoTickerId(a)),g.push([j,{workId:C,msgType:W.UpdateNode,emitEventType:this.emitEventType,workState:s}])}continue}}if(s===E.Start?this.mainEngine.unWritable():s===E.Done&&(this.mainEngine.abled(),this.lastEmtData=void 0),g.length){if(s===E.Done){const C=this.control.viewContainerManager.getUndoTickerId(a);if(C){const x=[...p];this.mainEngine.internalMsgEmitter.emit("finalizeRequested",C,a,x,l)}}this.collectForLocalWorker(g,t)}}}function qM(o){switch(o){case T.Text:return Ke.Text;case T.SpeechBalloon:case T.Star:case T.Ellipse:case T.Rectangle:case T.Triangle:case T.Rhombus:case T.Polygon:return Ke.Shape}}function KM(o){const n=o.lastChild;if(!n){const i=document.createElement("div"),r=document.createTextNode("");return i.appendChild(r),o.appendChild(i),r}if(n.nodeType===Node.TEXT_NODE)return n;const e=n;if(!e.lastChild){const i=document.createTextNode("");return e.appendChild(i),i}if(e.lastChild.nodeType===Node.TEXT_NODE)return e.lastChild;const t=document.createTextNode("");return e.appendChild(t),t}function JM(o,n){var i;const e=document.createRange(),t=KM(n);t.nodeType===Node.TEXT_NODE?e.setStart(t,((i=t.textContent)==null?void 0:i.length)||0):e.setStart(t,0),e.collapse(!0),o.removeAllRanges(),o.addRange(e)}function cr(o,n){return!!(o!=null&&o.anchorNode)&&n.contains(o.anchorNode)}function lr(o){let n=null,e=!1;for(const i of Array.from(o.childNodes)){if(i instanceof HTMLDivElement){n=i;continue}i.nodeType===Node.TEXT_NODE&&(n||(n=document.createElement("div"),o.insertBefore(n,i),e=!0),n.appendChild(i),e=!0)}const t=Array.from(o.childNodes).reverse().find(i=>i instanceof HTMLDivElement);return{changed:e,lastLine:t||null}}function XM(o){const n=document.createTreeWalker(o,NodeFilter.SHOW_TEXT,null),e=[];let t;for(;(t=n.nextNode())!==null;)e.push(t);return{textContent:e.map(i=>i.textContent||"").join(""),textNodes:e}}function ho(o){const n=[];for(let e=0;e<o.childNodes.length;e++){const t=o.childNodes[e];if(t.nodeName==="#text"&&e===0){const i=t.textContent.split(/\n/),r=i.pop();n.push(...i),r&&n.push(r)}else if(t.nodeName==="DIV"){const r=(t.innerText??t.textContent??"").split(/\n/);if(r.length===2&&r[0]===""&&r[1]==="")n.push("");else{const s=r.shift();(s||s==="")&&n.push(s);const a=r.pop();n.push(...r),a&&n.push(a)}}}return n}function go(o){return St(ho(o))}function Zt(o,n){var i,r;if(!o.length)return;let e=Math.max(0,n);for(const s of o){const a=((i=s.textContent)==null?void 0:i.length)||0;if(e<=a)return{node:s,offset:e};e-=a}const t=o[o.length-1];return{node:t,offset:((r=t.textContent)==null?void 0:r.length)||0}}function _M(o){const{hasPoint:n,previousByPoint:e,hasSelectionInEditor:t,rangeCount:i,isCollapsed:r}=o;return!n&&e&&t&&i>0&&r}class ey extends Qe{constructor(){super(...arguments);I(this,"lastEmtData");I(this,"emitEventType",R.SetFontStyle);I(this,"timerId")}async setTextStyle(e,t,i,r,s,a){const{bold:c,underline:l,lineThrough:u,italic:h,fontSize:g}=i;if(t.toolsType&&qM(t.toolsType)===Ke.Text){t.opt&&(c&&(t.opt.bold=c),z.isBoolean(l)&&(t.opt.underline=l),z.isBoolean(u)&&(t.opt.lineThrough=u),h&&(t.opt.italic=h),g&&(t.opt.fontSize=g));const d=await this.control.textEditorManager.updateTextControllerWithEffectAsync({workId:e,opt:t.opt,viewId:r,canSync:!1,canWorker:!1,requestId:s,needUndoTicker:a});return{key:e,textInfo:d}}}async collect(e){var v,k,C,x,O,Y;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,bold:i,italic:r,lineThrough:s,underline:a,viewId:c,fontSize:l,requestId:u}=e,h=this.control.viewContainerManager.getView(c);if(!(h!=null&&h.displayer))return;const g=h.focusScenePath,p=[...t],d=this.serviceColloctor.storage,M={},w=this.mainEngine.now;this.mainEngine.internalMsgEmitter.emit("addUndoTicker",w,c,{render:!0,storage:!0}),this.control.textEditorManager.UndoTickerId=w;const m=[],y=[];for(;p.length;){const A=p.pop();if(!A)continue;const b=A.toString(),N=this.serviceColloctor.isLocalId(b),D=N?this.serviceColloctor.transformKey(A):b;let j=b;!N&&this.serviceColloctor.isOwn(j)&&(j=this.serviceColloctor.getLocalId(j));const B=(k=(v=d==null?void 0:d[c])==null?void 0:v[g])==null?void 0:k[D];if(B){const V=B.updateNodeOpt||{};if(i&&(V.bold=i,M.bold=i==="bold"),r&&(V.italic=r,M.italic=r==="italic"),z.isBoolean(s)&&(V.lineThrough=s,M.lineThrough=s),z.isBoolean(a)&&(V.underline=a,M.underline=a),l&&(V.fontSize=l,M.textSize=l),B.toolsType===T.Text&&B.opt){const U=this.setTextStyle(j,z.cloneDeep(B),V,c,u,w);m.push(j),y.push(U);continue}if(B&&j===Z&&((C=B.selectIds)!=null&&C.length))for(const U of B.selectIds){const H=(x=this.serviceColloctor)==null?void 0:x.isLocalId(U);let G=H&&((O=this.serviceColloctor)==null?void 0:O.transformKey(U))||U;const $=d[c][g][G]||void 0;if(!H&&((Y=this.serviceColloctor)!=null&&Y.isOwn(G))&&(G=this.serviceColloctor.getLocalId(G)),$&&$.toolsType===T.Text&&B.opt){const X=this.setTextStyle(G,z.cloneDeep($),V,c,u,w);m.push(G),y.push(X);continue}}}}const S=await Promise.all(y);for(const A of S)if(A){const{key:b,textInfo:N}=A;N&&(N.canSync=!0,N.canWorker=!0,this.control.textEditorManager.updateForViewEdited(b,N))}Object.keys(M).length&&(this.timerId&&(clearTimeout(this.timerId),this.timerId=void 0),this.timerId=setTimeout(()=>{var A;this.timerId=void 0,(A=this.control.room)==null||A.setMemberState(M)},0)),m.length&&this.mainEngine.internalMsgEmitter.emit("finalizeRequested",w,c,m,g)}}class ty extends Qe{constructor(){super(...arguments);I(this,"lastEmtData");I(this,"emitEventType",R.SetPoint);I(this,"undoTickerId")}collect(e){var y,S,v;if(!this.serviceColloctor||!this.mainEngine)return;const{workId:t,pointMap:i,workState:r,viewId:s}=e,a=this.control.viewContainerManager.getView(s);if(!(a!=null&&a.displayer))return;const c=a.focusScenePath,l=(y=this.serviceColloctor)==null?void 0:y.storage,u=[],h=r===E.Start&&this.mainEngine.now||void 0;h&&(this.undoTickerId=h,this.mainEngine.internalMsgEmitter.emit("addUndoTicker",h,s,{render:!0,storage:!0,isWritable:!0}));const g=t;if(!g)return;const p=g.toString(),d=this.serviceColloctor.isLocalId(p),M=d&&this.serviceColloctor.transformKey(g)||p;let w=p;!d&&this.serviceColloctor.isOwn(w)&&(w=this.serviceColloctor.getLocalId(w));const m=(v=(S=l==null?void 0:l[s])==null?void 0:S[c])==null?void 0:v[M];if(m&&w===Z&&m.selectIds){const k=m.updateNodeOpt||{};k.pointMap=i,k.workState=r;const C={workId:g,msgType:W.UpdateNode,dataType:J.Local,updateNodeOpt:k,emitEventType:this.emitEventType,willRefreshSelector:!0,willSyncService:!0,viewId:s,needUndoTicker:r===E.Done&&this.control.viewContainerManager.getUndoTickerId(s)||void 0};u.push([C,{workId:g,msgType:W.UpdateNode,emitEventType:this.emitEventType}])}r===E.Start?this.mainEngine.unWritable():r===E.Done&&this.mainEngine.abled(),u.length&&(r===E.Done&&this.undoTickerId&&this.mainEngine.internalMsgEmitter.emit("finalizeRequested",this.undoTickerId,s,u.map(([k])=>{var C;return(C=k.workId)==null?void 0:C.toString()}).filter(Boolean),c),this.collectForLocalWorker(u))}}class ny extends Qe{constructor(){super(...arguments);I(this,"lastEmtData");I(this,"emitEventType",R.SetLock)}collect(e){var p,d;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,isLocked:i,viewId:r,requestId:s}=e,a=this.control.viewContainerManager.getView(r);if(!(a!=null&&a.displayer))return;const c=a.focusScenePath,l=[...t],u=this.serviceColloctor.storage,h=[],g=this.mainEngine.now;for(this.mainEngine.internalMsgEmitter.emit("addUndoTicker",g,r,{render:!0,storage:!0});l.length;){const M=l.pop();if(!M)continue;const w=M.toString(),m=this.serviceColloctor.isLocalId(w),y=m?this.serviceColloctor.transformKey(M):w;let S=w;!m&&this.serviceColloctor.isOwn(S)&&(S=this.serviceColloctor.getLocalId(S));const v=(d=(p=u==null?void 0:u[r])==null?void 0:p[c])==null?void 0:d[y];if(v){const k=v.updateNodeOpt||{};k.isLocked=i;const C={workId:S,msgType:W.UpdateNode,dataType:J.Local,updateNodeOpt:k,emitEventType:this.emitEventType,willRefresh:!0,willRefreshSelector:!0,willSyncService:!0,viewId:r,requestId:s,needUndoTicker:this.control.viewContainerManager.getUndoTickerId(r)};h.push([C,{workId:S,msgType:W.UpdateNode,emitEventType:this.emitEventType}])}}h.length&&(this.mainEngine.internalMsgEmitter.emit("finalizeRequested",g,r,h.map(([M])=>{var w;return(w=M.workId)==null?void 0:w.toString()}).filter(Boolean),c),this.collectForLocalWorker(h))}}class iy extends Qe{constructor(){super(...arguments);I(this,"lastEmtData");I(this,"emitEventType",R.SetShapeOpt)}collect(e){var p,d;if(!this.serviceColloctor||!this.mainEngine)return;const{workIds:t,viewId:i,requestId:r,...s}=e,a=this.control.viewContainerManager.getView(i);if(!(a!=null&&a.displayer))return;const c=a.focusScenePath,l=[...t],u=this.serviceColloctor.storage,h=[],g=this.mainEngine.now;for(this.mainEngine.internalMsgEmitter.emit("addUndoTicker",g,i,{render:!0,storage:!0});l.length;){const M=l.pop();if(!M)continue;const w=M.toString(),m=this.serviceColloctor.isLocalId(w),y=m?this.serviceColloctor.transformKey(M):w;let S=w;!m&&this.serviceColloctor.isOwn(S)&&(S=this.serviceColloctor.getLocalId(S));const v=(d=(p=u==null?void 0:u[i])==null?void 0:p[c])==null?void 0:d[y];if(v){const k={...v.updateNodeOpt,...s,willRefresh:!0};if(v&&S===Z){const C={workId:S,msgType:W.UpdateNode,dataType:J.Local,updateNodeOpt:k,emitEventType:this.emitEventType,willRefresh:!0,willRefreshSelector:!0,willSyncService:!0,viewId:i,requestId:r,needUndoTicker:this.control.viewContainerManager.getUndoTickerId(i)};h.push([C,{workId:S,msgType:W.UpdateNode,emitEventType:this.emitEventType}])}}}h.length&&(this.mainEngine.internalMsgEmitter.emit("finalizeRequested",g,i,h.map(([M])=>{var w;return(w=M.workId)==null?void 0:w.toString()}).filter(Boolean),c),this.collectForLocalWorker(h))}}class ee{constructor(n){I(this,"builders",new Map);this.builders=new Map(n.map(e=>[e,this.build(e)]))}build(n){switch(n){case R.TranslateNode:return new GM;case R.ZIndexNode:return new $M;case R.CopyNode:return new VM;case R.SetColorNode:return new FM;case R.DeleteNode:return new QM;case R.ScaleNode:return new ZM;case R.RotateNode:return new HM;case R.SetFontStyle:return new ey;case R.SetPoint:return new ty;case R.SetLock:return new ny;case R.SetShapeOpt:return new iy}}getBuilder(n){return this.builders.get(n)}registerForMainEngine(n,e){return this.builders.forEach(t=>{t&&t.registerForMainEngine(n,e)}),this}destroy(){this.builders.forEach(n=>{n&&n.destroy()}),this.builders.clear()}pause(){return this.builders.forEach(n=>{n&&n.pause()}),this}recover(){return this.builders.forEach(n=>{n&&n.recover()}),this}static emitMethod(n,e,t){Qe.dispatch(n,e,t)}static activeListener(n){ye.InternalMsgEmitter.on(R.ActiveMethod,n)}static unmountActiveListener(n){ye.InternalMsgEmitter.off(R.ActiveMethod,n)}}const ry=async(o,n)=>{const{src:e,isgl:t}=o;if(typeof Image=="function"){const i=new Image;return typeof e=="string"&&(i.crossOrigin="anonymous"),new Promise(r=>{i.onload=function(){createImageBitmap(i,{imageOrientation:t?"flipY":"none"}).then(s=>{r(s)})},i.onerror=function(){r(void 0)},i.src=e})}else return fetch(e,{method:"GET",mode:"cors",cache:"default"}).then(i=>i.blob()).then(i=>createImageBitmap(i,{imageOrientation:t?"flipY":"none"}).then(r=>r))},Tt=class Tt{constructor(){I(this,"fontDB");I(this,"FONT_DB_NAME","__APPLIANCE_PLUGIN_FONT_DB");I(this,"FONT_STORE_NAME","fonts");I(this,"FONT_DB_VERSION",1)}static getInstance(){return Tt.instance||(Tt.instance=new Tt),Tt.instance}async initFontDB(){return this.fontDB?this.fontDB:new Promise((n,e)=>{const t=indexedDB.open(this.FONT_DB_NAME,this.FONT_DB_VERSION);t.onerror=()=>{e(new Error(`Failed to open font database: ${t.error}`))},t.onsuccess=()=>{this.fontDB=t.result,n(t.result)},t.onupgradeneeded=i=>{const r=i.target.result;r.objectStoreNames.contains(this.FONT_STORE_NAME)||r.createObjectStore(this.FONT_STORE_NAME,{keyPath:"fontFamily"}).createIndex("url","url",{unique:!1})}})}async getFontFromDB(n){try{return this.fontDB||(this.fontDB=await this.initFontDB()),new Promise((e,t)=>{const s=this.fontDB.transaction([this.FONT_STORE_NAME],"readonly").objectStore(this.FONT_STORE_NAME).get(n);s.onsuccess=()=>{s.result&&s.result.buffer?e(s.result.buffer):e(null)},s.onerror=()=>{t(s.error)}})}catch(e){return console.error(`Failed to get font from database for ${n}:`,e),null}}async saveFontToDB(n,e,t){try{return this.fontDB||(this.fontDB=await this.initFontDB()),new Promise((i,r)=>{const a=this.fontDB.transaction([this.FONT_STORE_NAME],"readwrite").objectStore(this.FONT_STORE_NAME),c={fontFamily:n,url:e,buffer:t,timestamp:Date.now()},l=a.put(c);l.onsuccess=()=>{i(!0)},l.onerror=()=>{r(l.error)}})}catch(i){return console.error(`Failed to save font to database for ${n}:`,i),!1}}async clearFontCache(){try{return this.fontDB||(this.fontDB=await this.initFontDB()),new Promise((n,e)=>{const r=this.fontDB.transaction([this.FONT_STORE_NAME],"readwrite").objectStore(this.FONT_STORE_NAME).clear();r.onsuccess=()=>{console.log("Font cache cleared successfully"),n(!0)},r.onerror=()=>{e(r.error)}})}catch(n){return console.error("Failed to clear font cache:",n),!1}}async getFontCacheStatus(){try{return this.fontDB||(this.fontDB=await this.initFontDB()),new Promise((n,e)=>{const r=this.fontDB.transaction([this.FONT_STORE_NAME],"readonly").objectStore(this.FONT_STORE_NAME).getAll();r.onsuccess=()=>{const s=r.result||[],a=s.reduce((c,l)=>c+(l.buffer?l.buffer.byteLength:0),0);n({count:s.length,totalSize:a})},r.onerror=()=>{e(r.error)}})}catch(n){return console.error("Failed to get font cache status:",n),{count:0,totalSize:0}}}};I(Tt,"instance");let Hn=Tt;function oy(o){return o===ce.Stroke?ce.Normal:o}function Ct(o){const{pencilOptions:n}=o,e=oy(n.strokeType);return{strokeColor:n.strokeColor,thickness:n.thickness,isOpacity:n.isOpacity,zIndex:n.zIndex,scale:n.scale,rotate:n.rotate,translate:n.translate,eraserlines:n.eraserlines,strokeType:e,lineCap:e===ce.Normal?void 0:n.lineCap,lineDash:e===ce.Normal?void 0:n.lineDash}}function fo(o){return[o.start[0],o.start[1],0,o.end[0],o.end[1],0]}function kn(o){const{minX:n,minY:e,maxX:t,maxY:i}=o.bbox;return[n,e,0,t,i,0]}function sy(o){const{minX:n,minY:e,maxX:t,maxY:i}=o.bbox;return[n,e,0,t,e,0,t,i,0,n,i,0]}const ay=(o,n)=>({toolsType:T.Straight,opt:Ct(n),op:fo(o)}),cy=(o,n)=>({toolsType:T.Arrow,opt:Ct(n),op:fo(o)}),ly=(o,n)=>({toolsType:T.Rectangle,opt:{...Ct(n),fillColor:"transparent"},op:sy(o)}),uy=(o,n)=>({toolsType:T.Ellipse,opt:{...Ct(n),fillColor:"transparent"},op:kn(o)}),hy=(o,n)=>({toolsType:T.Polygon,opt:{...Ct(n),fillColor:"transparent",vertices:3,shapeType:Be.Triangle},op:kn(o)}),dy=(o,n)=>({toolsType:T.Polygon,opt:{...Ct(n),fillColor:"transparent",vertices:4,shapeType:Be.Rhombus},op:kn(o)}),gy=(o,n)=>({toolsType:T.Star,opt:{...Ct(n),fillColor:"transparent",vertices:10,innerVerticeStep:2,innerRatio:.4,shapeType:Be.Pentagram},op:kn(o)}),Mt={straight:ay,arrow:cy,rectangle:ly,ellipse:uy,triangle:hy,rhombus:dy,star:gy};function fy(o){return St(o.op)}function at(o){if(!o.length)return o;const[n,e]=o[0],[t,i]=o[o.length-1];return n===t&&e===i?o:[...o,o[0]]}function py(o,n){const e=at(o).slice(0,-1),t=(n%e.length+e.length)%e.length;return at(e.slice(t).concat(e.slice(0,t)))}function Si(o){return[...o].reverse()}function kt(o,n,e,t,i){const r=[];for(let s=0;s<i;s++){const a=py(e,s),c=Si(a);r.push({id:`${n}-cw-${s}`,semanticKind:o,points:a,threshold:t},{id:`${n}-ccw-${s}`,semanticKind:o,points:c,threshold:t})}return r}function My(o,n,e,t){const i=[];return e.forEach((r,s)=>{i.push({id:`${n}-forward-${s}`,semanticKind:o,points:r,threshold:t},{id:`${n}-reverse-${s}`,semanticKind:o,points:Si(r),threshold:t})}),i}const ur=[[0,.5],[.25,.5],[.5,.5],[.75,.5],[1,.5]],yy=[[.05,.5],[.3,.5],[.55,.5],[.78,.5],[1,.5],[.8,.32],[1,.5],[.8,.68]],my=[[.05,.5],[.3,.5],[.55,.5],[.78,.5],[1,.5],[.8,.68],[1,.5],[.8,.32]],Iy=at([[.15,.2],[.85,.2],[.85,.8],[.15,.8]]),wy=at([[.5,.12],[.88,.82],[.12,.82]]),Ty=at([[.5,.08],[.92,.5],[.5,.92],[.08,.5]]),Sy=at([[.5,.04],[.62,.34],[.95,.36],[.68,.56],[.78,.9],[.5,.7],[.22,.9],[.32,.56],[.05,.36],[.38,.34]]),vy=at([[.5,.04],[.74,.88],[.08,.34],[.92,.34],[.26,.88]]),Ny=Array.from({length:24},(o,n)=>{const e=Math.PI*2*n/24;return[.5+Math.cos(e)*.42,.5+Math.sin(e)*.3]}),yt=[{id:"straight-base",semanticKind:"straight",points:ur,threshold:.72},{id:"straight-reverse",semanticKind:"straight",points:Si(ur),threshold:.72},...My("arrow","arrow",[yy,my],.71),...kt("rectangle","rectangle",Iy,.68,4),...kt("ellipse","ellipse",at(Ny),.64,12),...kt("triangle","triangle",wy,.68,3),...kt("rhombus","rhombus",Ty,.66,4),...kt("star","star",Sy,.7,5),...kt("star","pentagram",vy,.68,5)];function Ht(o,n,e,t){const{metrics:i}=n;return i.closureRatio>.24||i.cornerCount<e||i.cornerCount>t?null:o}const Cy=[{kind:"straight",templates:yt.filter(o=>o.semanticKind==="straight"),postProcessor(o,n){const{metrics:e}=n;return e.bboxDiagonal<8||e.closureRatio<.75||e.straightness<.94&&o.score<.8?null:o},mapper:Mt.straight,enabledInV1:!0},{kind:"arrow",templates:yt.filter(o=>o.semanticKind==="arrow"),postProcessor(o,n){const{metrics:e}=n;return e.closureRatio<.12||e.cornerCount<4||e.cornerCount>7||e.straightness>.93?null:o.score>=Math.max(o.threshold,.71)?o:null},mapper:Mt.arrow,enabledInV1:!0},{kind:"rectangle",templates:yt.filter(o=>o.semanticKind==="rectangle"),postProcessor(o,n){const e=Ht(o,n,4,6);return!e||n.metrics.bboxCornerCloseness>.15||n.metrics.bboxCornerCloseness>=n.metrics.diamondCloseness?null:e},mapper:Mt.rectangle,enabledInV1:!0},{kind:"ellipse",templates:yt.filter(o=>o.semanticKind==="ellipse"),postProcessor(o,n){const e=Ht(o,n,6,12);return!e||n.metrics.radialVariance>.5?null:e},mapper:Mt.ellipse,enabledInV1:!0},{kind:"triangle",templates:yt.filter(o=>o.semanticKind==="triangle"),postProcessor(o,n){return Ht(o,n,3,4)},mapper:Mt.triangle,enabledInV1:!0},{kind:"rhombus",templates:yt.filter(o=>o.semanticKind==="rhombus"),postProcessor(o,n){const e=Ht(o,n,4,5);return!e||n.metrics.diamondCloseness>=n.metrics.bboxCornerCloseness?null:e},mapper:Mt.rhombus,enabledInV1:!0},{kind:"star",templates:yt.filter(o=>o.semanticKind==="star"),postProcessor(o,n){const e=o.templateId.startsWith("pentagram"),t=Ht(o,n,e?5:8,12);if(!t)return null;if(e){if(n.metrics.bboxCornerCloseness<.22||n.metrics.angleVariance<35)return null}else if(n.metrics.radialVariance<.34)return null;return t},mapper:Mt.star,enabledInV1:!0}];function vi(){return Cy}const ky=64,qn=250;function tt(o,n){const e=o[0]-n[0],t=o[1]-n[1];return Math.hypot(e,t)}function xy(o){const n=[];for(const e of o){const t=n[n.length-1];(!t||tt(t,e)>.5)&&n.push(e)}return n}function po(o){let n=0;for(let e=1;e<o.length;e++)n+=tt(o[e-1],o[e]);return n}function Mo(o){let n=Number.POSITIVE_INFINITY,e=Number.POSITIVE_INFINITY,t=Number.NEGATIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(const[r,s]of o)n=Math.min(n,r),e=Math.min(e,s),t=Math.max(t,r),i=Math.max(i,s);return{minX:n,minY:e,maxX:t,maxY:i}}function by(o,n=ky){if(o.length<=1)return o;const e=po(o)/Math.max(n-1,1),t=[o[0]];let i=0,r=o[0],s=1;const a=[...o];for(;s<a.length;){const c=a[s],l=tt(r,c);if(l===0){s++;continue}if(i+l>=e){const u=(e-i)/l,h=[r[0]+u*(c[0]-r[0]),r[1]+u*(c[1]-r[1])];t.push(h),a.splice(s,0,h),i=0,r=h,s++}else i+=l,r=c,s++}for(;t.length<n;)t.push(a[a.length-1]);return t}function xn(o){const n=o.reduce((e,t)=>[e[0]+t[0],e[1]+t[1]],[0,0]);return[n[0]/o.length,n[1]/o.length]}function Dy(o,n){const e=xn(o),t=Math.cos(n),i=Math.sin(n);return o.map(([r,s])=>{const a=r-e[0],c=s-e[1];return[a*t-c*i+e[0],a*i+c*t+e[1]]})}function jy(o){const n=xn(o);return Math.atan2(n[1]-o[0][1],n[0]-o[0][0])}function Ay(o,n=qn){const e=Mo(o),t=Math.max(e.maxX-e.minX,1),i=Math.max(e.maxY-e.minY,1);return o.map(([r,s])=>[(r-e.minX)/t*n,(s-e.minY)/i*n])}function Ey(o){const n=xn(o);return o.map(([e,t])=>[e-n[0],t-n[1]])}function yo(o){const n=by(o),e=Dy(n,-jy(n)),t=Ay(e);return Ey(t)}function zy(o,n){let e=0;const t=Math.min(o.length,n.length);for(let i=0;i<t;i++)e+=tt(o[i],n[i]);return e/Math.max(t,1)}function Ly(o,n,e){const[t,i]=o,[r,s]=n,[a,c]=e,l=Math.abs((c-s)*t-(a-r)*i+a*s-c*r),u=Math.hypot(c-s,a-r)||1;return l/u}function Kn(o,n){if(o.length<=2)return o;let e=0,t=0;for(let s=1;s<o.length-1;s++){const a=Ly(o[s],o[0],o[o.length-1]);a>e&&(e=a,t=s)}if(e<=n)return[o[0],o[o.length-1]];const i=Kn(o.slice(0,t+1),n),r=Kn(o.slice(t),n);return i.slice(0,-1).concat(r)}function Py(o){if(o.length<3)return[];const n=[];for(let e=0;e<o.length;e++){const t=o[(e-1+o.length)%o.length],i=o[e],r=o[(e+1)%o.length],s=[t[0]-i[0],t[1]-i[1]],a=[r[0]-i[0],r[1]-i[1]],c=s[0]*a[0]+s[1]*a[1],l=Math.hypot(s[0],s[1])*Math.hypot(a[0],a[1])||1,u=Math.acos(Math.max(-1,Math.min(1,c/l)));n.push(u*180/Math.PI)}return n}function Oy(o){const n=Mo(o),e=Math.max(n.maxX-n.minX,1),t=Math.max(n.maxY-n.minY,1),i=Math.hypot(e,t)||1,r=po(o),s=tt(o[0],o[o.length-1]),a=tt(o[0],o[o.length-1]),c=a/i,l=i*.045,h=c<.24&&o.length>2?o.slice(0,tt(o[0],o[o.length-1])<.5?-1:o.length):o,g=Kn(h,l),p=Py(g),d=p.length>0?Math.max(...p.map(x=>Math.abs(x-90))):90,M=g.map(([x,O])=>[(x-n.minX)/e,(O-n.minY)/t]),w=[[0,0],[1,0],[1,1],[0,1]],m=[[.5,0],[1,.5],[.5,1],[0,.5]],y=(x,O)=>x.reduce((Y,A)=>{const b=Math.min(...O.map(N=>tt(A,N)));return Y+b},0)/Math.max(x.length,1),S=xn(o),v=o.map(x=>tt(x,S)),k=v.reduce((x,O)=>x+O,0)/Math.max(v.length,1),C=k>0?v.reduce((x,O)=>x+Math.abs(O-k)/k,0)/Math.max(v.length,1):0;return{bbox:n,metrics:{pathLength:r,chordLength:s,straightness:s/Math.max(r,1),closureDistance:a,closureRatio:c,bboxWidth:e,bboxHeight:t,bboxDiagonal:i,aspectRatio:e/t,cornerCount:Math.max(0,g.length),angleVariance:d,radialVariance:C,bboxCornerCloseness:y(M,w),diamondCloseness:y(M,m)}}}function Ry(o){return o.map(n=>({template:n,normalized:yo(n.points)}))}const Uy=Ry(vi().flatMap(o=>o.templates));function Yy(o){const n=xy(o.rawPoints);if(n.length<2)return null;const{bbox:e,metrics:t}=Oy(n);return{rawPoints:o.rawPoints,points:n,pencilOptions:o.pencilOptions,viewId:o.viewId,scenePath:o.scenePath,start:n[0],end:n[n.length-1],bbox:e,metrics:t}}function By(o){const n=yo(o.points),e=new Map;for(const{template:t,normalized:i}of Uy){const r=zy(n,i),s=Math.max(0,1-r/(.5*Math.sqrt(2*qn*qn))),a={kind:t.semanticKind,templateId:t.id,threshold:t.threshold||.7,distance:r,score:s},c=e.get(t.semanticKind);(!c||a.score>c.score)&&e.set(t.semanticKind,a)}return[...e.values()].sort((t,i)=>i.score-t.score)}function Wy(o){const n=vi(),e=By(o);if(o.metrics.bboxDiagonal>=8&&o.metrics.straightness>.975&&o.metrics.closureRatio>.75){const i=e.find(r=>r.kind==="straight")||{templateId:"straight-heuristic",score:.99,threshold:.72};return{kind:"straight",score:i.score,threshold:i.threshold,recognized:!0,bbox:o.bbox,start:o.start,end:o.end,points:o.points,templateId:i.templateId,metrics:o.metrics,candidates:e}}for(const i of e){const r=n.find(a=>a.kind===i.kind);if(!r||i.score<i.threshold)continue;const s=r.postProcessor?r.postProcessor(i,o):i;if(s)return{kind:r.kind,score:s.score,threshold:s.threshold,recognized:!0,bbox:o.bbox,start:o.start,end:o.end,points:o.points,templateId:s.templateId,metrics:o.metrics,candidates:e}}const t=e[0];return{kind:"none",score:(t==null?void 0:t.score)||0,threshold:(t==null?void 0:t.threshold)||1,recognized:!1,bbox:o.bbox,start:o.start,end:o.end,points:o.points,templateId:t==null?void 0:t.templateId,metrics:o.metrics,candidates:e}}function Vy(o){return Yy(o)}function Fy(o){return Wy(o)}function hr(o,n){if(!o.recognized||o.kind==="none")return null;const e=vi().find(t=>t.kind===o.kind);return(e==null?void 0:e.mapper(o,n))||null}const $y=new Set([T.Eraser,T.PencilEraser,T.BitMapEraser]),Gy=new Set([T.Pencil,T.Arrow,T.Straight,T.Ellipse,T.Rectangle,T.Star,T.Polygon,T.SpeechBalloon]),Ln=o=>typeof o=="number"&&$y.has(o),Qy=o=>o===W.FullWork||o===W.UpdateNode||o===W.RemoveNode||o===W.DrawWork;class Zy{get now(){var n;return((n=this.control.room)==null?void 0:n.calibrationTimestamp)||Date.now()}get newWorkId(){return this.now.toString()}setCurrentToolsData(n){this.currentToolsData=n}getCurrentToolsData(){return this.currentToolsData}setCurrentLocalWorkData(n){this.currentLocalWorkData=n}getWorkId(){return this.currentLocalWorkData.workId}get workState(){return this.currentLocalWorkData.workState}}class Hy extends Zy{constructor(e){super();I(this,"maxLastSyncTime",we.syncOpt.interval);I(this,"combineUnitTime",we.bezier.combineUnitTime);I(this,"maxCombineEraserTime",we.pencilEraser.maxCombineTime);I(this,"smoothSync",we.syncOpt.smoothSync);I(this,"isActive",!1);I(this,"currentToolsData");I(this,"currentLocalWorkData");I(this,"control");I(this,"internalMsgEmitter");I(this,"publicMsgEmitter");I(this,"taskBatchData",new Set);I(this,"fullWorker");I(this,"subWorker");I(this,"fullWorkerUrl");I(this,"subWorkerUrl");I(this,"methodBuilder");I(this,"zIndexNodeMethod");I(this,"subWorkerDrawCount",0);I(this,"fullWorkerDrawCount",0);I(this,"maxDrawCount",0);I(this,"_consumeCount",0);I(this,"_postCount",0);I(this,"reRenders",new Map);I(this,"localWorkViewId");I(this,"localPointsBatchData",new Map);I(this,"tasksqueue",new Map);I(this,"useTasksqueue",!1);I(this,"useTasksClockId");I(this,"mainTasksqueueCount");I(this,"workerTasksqueueCount");I(this,"snapshotMap",new Map);I(this,"boundingRectMap",new Map);I(this,"clearAllResolveMap",new Map);I(this,"delayWorkStateToDoneResolve");I(this,"animationId");I(this,"tmpImageConfigMap",new Map);I(this,"mainThread");I(this,"backgroundThreadManager");I(this,"willSelectorWorkId");I(this,"isLockSentEventCursor",!1);I(this,"getVNodeInfoResolveMap",new Map);I(this,"setFontFacesResolve",{});I(this,"isLocalWorkActive",!1);I(this,"indexDBUtils",Hn.getInstance());I(this,"markmapIdResolveMap",new Map);const{control:t,internalMsgEmitter:i,publicMsgEmitter:r}=e;this.control=t,this.maxLastSyncTime=this.control.pluginOptions.extras.syncOpt.interval,this.combineUnitTime=this.control.pluginOptions.extras.bezier.combineUnitTime||this.combineUnitTime,this.smoothSync=z.isBoolean(this.control.pluginOptions.extras.syncOpt.smoothSync)?this.control.pluginOptions.extras.syncOpt.smoothSync:this.smoothSync,this.maxCombineEraserTime=this.control.pluginOptions.extras.pencilEraser.maxCombineTime||this.maxCombineEraserTime,this.fullWorkerUrl=this.control.pluginOptions.cdn.fullWorkerUrl||"",this.subWorkerUrl=this.control.pluginOptions.cdn.subWorkerUrl||"",this.internalMsgEmitter=i,this.publicMsgEmitter=r,this.currentLocalWorkData={workState:E.Pending}}get isBezier(){return this.control.pluginOptions.extras.bezier.enable}get Logger(){return this.control.logger}destroy(){var e,t,i,r,s;(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.mainThread)==null||t.destroy(),this.mainThread=void 0,(i=this.backgroundThreadManager)==null||i.destroy(),this.backgroundThreadManager=void 0,(r=this.fullWorker)==null||r.terminate(),this.fullWorker=void 0,(s=this.subWorker)==null||s.terminate(),this.subWorker=void 0}get consumeCount(){return this._consumeCount}set consumeCount(e){this._consumeCount=e}get postCount(){return this._postCount}set postCount(e){this._postCount=e}get viewContainerManager(){return this.control.viewContainerManager}get collector(){return this.control.collector}get isRunSubWork(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.PencilEraser||e===T.BitMapEraser||e===T.LaserPen||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Selector}get isCanDrawWork(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.LaserPen||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Triangle||e===T.Rhombus||e===T.BitMapEraser||e===T.PencilEraser}get isUseZIndex(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Text||e===T.Image}get isCanRecordUndoRedo(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.Eraser||e===T.PencilEraser||e===T.BitMapEraser||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Text||e===T.Image}get isCanSentCursor(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.Text||e===T.LaserPen||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Triangle||e===T.Rhombus||e===T.Eraser||e===T.PencilEraser||e===T.BitMapEraser||e===T.Selector}get isPostCountType(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.Arrow||e===T.Straight||e===T.Ellipse||e===T.Rectangle||e===T.Star||e===T.Polygon||e===T.SpeechBalloon||e===T.Triangle||e===T.Rhombus||e===T.Eraser||e===T.PencilEraser||e===T.BitMapEraser||e===T.Selector}get isCanPostDraw(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Pencil||e===T.PencilEraser||e===T.BitMapEraser}get isCanStartEventConsum(){var t;const e=(t=this.currentToolsData)==null?void 0:t.toolsType;return e===T.Selector||e===T.Eraser||e===T.PencilEraser||e===T.BitMapEraser}async init(){this.destroy();try{this.Logger.info(`[Appliance]: [plugin-options] ${JSON.stringify(this.control.pluginOptions.extras)}`)}catch(e){this.Logger.warn(`[Appliance]: [plugin-options] stringify failed: ${(e==null?void 0:e.message)||e}`)}await this.on(),this.internalMsgEmitterListener(),this.isActive=!0}async useBackgroundThread(){console.info("use background thread");const{BackgroundThreadManagerImpl:e}=await Promise.resolve().then(()=>require("./index-CcS9cKSp.js"));this.backgroundThreadManager=new e(this)}async useMainThread(){console.info("no OffscreenCanvas"),this.control.hasExtendFontFaces&&await document.fonts.ready.then(()=>{this.Logger.info("[Appliance]: set font faces in main thread success")});const{MainThreadManagerImpl:e}=await Promise.resolve().then(()=>require("./index-Bm90lQii.js"));this.mainThread=new e(this)}async on(){if(this.control.isUseBackgroundThread&&await this.useBackgroundThread(),!this.control.hasOffscreenCanvas){await this.useMainThread();return}if(!this.fullWorkerUrl||!this.subWorkerUrl){console.error("no worker url config");return}if(this.fullWorker=new Worker(this.fullWorkerUrl,{type:"classic"}),this.control.isUseSimple||(this.subWorker=new Worker(this.subWorkerUrl,{type:"classic"})),this.fullWorker.onmessage=e=>{if(e.data){const{render:t,sp:i,fullWorkerDrawCount:r,workerTasksqueueCount:s,viewId:a,consumeCount:c}=e.data;if(c&&(this.consumeCount=c),this.isBusy&&s&&this.setWorkerTasksqueueCount(s),i!=null&&i.length&&this.collectorSyncData(i),this.control.isUseSimple){if(this.control.isUseOffscreenTransfer)return;t&&(t!=null&&t.length)&&this.viewContainerManager.render(t);return}const l=(t==null?void 0:t.length)&&t||[];if(r&&a){if(this.fullWorkerDrawCount=r,this.fullWorkerDrawCount<1/0){const u=Math.max(this.maxDrawCount,this.fullWorkerDrawCount);this.setMaxDrawCount(u),this.clearReRenders(this.fullWorkerDrawCount)}else this.setMaxDrawCount(0),this.clearReRenders(1/0);if(this.reRenders.size)for(const u of this.reRenders.values())l.push(...u)}l.length&&this.viewContainerManager.render(l)}},this.subWorker&&(this.subWorker.onmessage=e=>{if(e.data){const{render:t,sp:i,subWorkerDrawCount:r,consumeCount:s}=e.data;s&&(this.consumeCount=s),i!=null&&i.length&&this.collectorSyncData(i);const a=(t==null?void 0:t.length)&&t||[];if(z.isNumber(r)){if(this.subWorkerDrawCount=r,this.fullWorkerDrawCount<1/0){const c=Math.max(this.maxDrawCount,this.subWorkerDrawCount);this.setMaxDrawCount(c)}if(t!=null&&t.length)if(this.subWorkerDrawCount>this.fullWorkerDrawCount){const c=[];for(const l of t)l.imageBitmap&&(l.isUnClose=!0,c.push(l));this.reRenders.set(this.subWorkerDrawCount,c)}else this.reRenders.size&&this.clearReRenders(this.subWorkerDrawCount)}a.length&&this.viewContainerManager.render(a)}}),this.control.hasExtendFontFaces){const e=this.control.extendFontFaces,t=[],i=[];this.control.room&&this.Logger.info(`[Appliance]: load before font faces ${JSON.stringify(e)}`),await new Promise(async r=>{this.setFontFacesResolve.resolve=r,this.setFontFacesResolve.timer=setTimeout(()=>{this.setFontFacesResolve.resolve&&(this.Logger.warn("[Appliance]: set font faces timeout"),this.setFontFacesResolve.resolve(!1))},this.control.loadFontFacesTimeout);try{for(const s of e){let a;a=await this.indexDBUtils.getFontFromDB(s.fontFamily)||void 0,a||(a=await this.loadFontInMainThread(s.src),a&&a.byteLength>0&&(await this.indexDBUtils.saveFontToDB(s.fontFamily,s.src,a)||this.Logger.warn(`[Appliance]: Failed to save font ${s.fontFamily} to IndexedDB, but continuing with font loading`))),a&&a.byteLength>0?(i.push({fontFamily:s.fontFamily,buffer:a}),t.push(a)):this.Logger.warn(`[Appliance]: Font ${s.fontFamily} could not be loaded from any source`)}this.Logger.info("[Appliance]: load end font faces"),i.length?this.fullWorker.postMessage(new Set([{type:W.SetFontFace,fontBuffers:i}]),t):this.setFontFacesResolve.resolve(!0)}catch(s){this.setFontFacesResolve.timer&&(clearTimeout(this.setFontFacesResolve.timer),this.setFontFacesResolve.timer=void 0),this.setFontFacesResolve.resolve&&(this.setFontFacesResolve.resolve(!1),this.Logger.error(`[Appliance]: set font faces error: ${s}`))}}).then(r=>{this.setFontFacesResolve.resolve=void 0,this.setFontFacesResolve.timer=void 0,r?this.Logger.info("[Appliance]: set font faces in web worker success"):this.Logger.error("[Appliance]: set font faces in web worker error")})}}async clearFontCache(){return await this.indexDBUtils.clearFontCache()}async getFontCacheStatus(){return await this.indexDBUtils.getFontCacheStatus()}async loadFontInMainThread(e){try{const t=await fetch(e);if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);const i=await t.arrayBuffer();if(!i||i.byteLength===0)throw new Error("Empty font data received");const r=new Uint8Array(i);if(!this.validateFontData(r))throw new Error("Invalid font data format: not a valid font file");return i}catch(t){this.Logger.error(`[Appliance]: Failed to load font from ${e}: ${t instanceof Error?t.message:String(t)}`);return}}validateFontData(e){return e.length<4?!1:e[0]===119&&e[1]===79&&e[2]===70&&e[3]===50||e[0]===119&&e[1]===79&&e[2]===70&&e[3]===70||e[0]===0&&e[1]===1&&e[2]===0&&e[3]===0||e[0]===79&&e[1]===84&&e[2]===84&&e[3]===79||e.length>36&&e[36]===0&&e[37]===1&&e[38]===0&&e[39]===0}buildPropertyAppliedData(e,t,i){switch(e){case R.SetColorNode:return{strokeColor:t==null?void 0:t.strokeColor,fillColor:t==null?void 0:t.fillColor,fontColor:t==null?void 0:t.fontColor,fontBgColor:t==null?void 0:t.fontBgColor,thickness:t==null?void 0:t.thickness,strokeType:t==null?void 0:t.strokeType};case R.SetFontStyle:return{fontSize:t==null?void 0:t.fontSize,bold:t==null?void 0:t.bold,italic:t==null?void 0:t.italic,underline:t==null?void 0:t.underline,lineThrough:t==null?void 0:t.lineThrough};case R.SetLock:return{isLocked:i==null?void 0:i.isLocked};case R.SetShapeOpt:return{vertices:t==null?void 0:t.vertices,innerVerticeStep:t==null?void 0:t.innerVerticeStep,innerRatio:t==null?void 0:t.innerRatio,placement:t==null?void 0:t.placement};case R.ZIndexNode:return{zIndexLayer:i==null?void 0:i.zIndexLayer};default:return{}}}clearReRenders(e=1/0){for(const t of this.reRenders.keys())if(z.isNumber(Number(t))&&Number(t)<=e){const i=this.reRenders.get(Number(t));i==null||i.forEach(r=>{var s;(s=r.imageBitmap)==null||s.close()}),this.reRenders.delete(t)}}get isBusy(){return this.getTasksqueueState()===E.Doing}getLockSentEventCursor(){return this.isLockSentEventCursor}setLockSentEventCursor(e){this.isLockSentEventCursor=e}getTasksqueueState(){return this.useTasksqueue&&E.Doing||E.Done}setMaxDrawCount(e){this.maxDrawCount=e}getFullWorkDrawCount(){return this.fullWorkerDrawCount}getMaxDrawCount(){return this.maxDrawCount}setSubWorkerDrawCount(e){this.subWorkerDrawCount=e}setConsumeCount(e){this.consumeCount=e}getConsumeCount(){return this.consumeCount}setWorkerTasksqueueCount(e){const t=Math.max(this.workerTasksqueueCount||0,e);this.workerTasksqueueCount=t}collectorSyncData(e){var i,r,s,a,c,l,u,h,g,p,d,M,w,m,y;let t=!1;for(const S of e){const{type:v,selectIds:k,opt:C,selectRect:x,strokeColor:O,fillColor:Y,willSyncService:A,isSync:b,imageBitmap:N,canvasHeight:D,canvasWidth:j,rect:B,op:V,canTextEdit:U,points:H,selectorColor:G,canRotate:$,scaleType:X,textOpt:Te,toolsType:se,workId:fe,viewId:le,dataType:nt,canLock:ut,isLocked:ht,shapeOpt:dt,toolsTypes:gt,thickness:De,strokeType:Pe,useStroke:it,isgl:Ft,imageSrc:$t,isSubWorker:rn,updateNodeOpt:q,emitEventType:_,requestId:ne,setFontFaceResult:ae,failedFonts:me,reportString:pe,index:Ce,imageElement:Ie,workState:xe,isSelecting:ze,needUndoTicker:he}=S;if(v===W.SetFontFace){ae&&this.setFontFacesResolve.resolve&&(me&&me.length>0&&this.Logger.info("[Appliance]: set font face has failed fonts: "+me.join(", ")),this.setFontFacesResolve.resolve(ae));return}if(!le)return;const ge=S.scenePath||this.viewContainerManager.getCurScenePath(le);switch(v){case W.SelectorTransform:{if(_&&xe)try{(i=this.control.selectorApi)==null||i.onSelectorTransform({viewId:le,emitEventType:_,workState:xe})}catch(K){(s=(r=this.Logger)==null?void 0:r.error)==null||s.call(r,`[Appliance]: [selector] onSelectorTransform failed: ${K==null?void 0:K.message}`)}break}case W.Select:{const K=k!=null&&k.length?{...x,selectIds:k,canvasHeight:D,canvasWidth:j,points:H}:void 0;if(K&&(C!=null&&C.strokeColor)&&(K.selectorColor=C.strokeColor),K&&G&&(K.selectorColor=G),K&&O&&(K.strokeColor=O),K&&(C!=null&&C.fillColor)&&(K.fillColor=C.fillColor),K&&Y&&(K.fillColor=Y),K&&z.isBoolean($)&&(K.canRotate=$),K&&X&&(K.scaleType=X),K&&U&&(K.canTextEdit=U),K&&Te&&(K.textOpt=Te),K&&z.isBoolean(ut)&&(K.canLock=ut),K&&z.isBoolean(ht)&&(K.isLocked=ht),K&&dt&&(K.shapeOpt=dt),K&&gt&&(K.toolsTypes=gt),K&&De&&(K.thickness=De),K&&Pe&&(K.strokeType=Pe),K&&z.isBoolean(it)&&(K.useStroke=it),le&&this.viewContainerManager.showFloatBar(le,!!K,K),A&&((a=this.collector)==null||a.dispatch({type:v,selectIds:k,opt:C,isSync:b,viewId:le,scenePath:ge,needUndoTicker:he,requestId:ne,emitEventType:_})),ze)break;try{(c=this.control.selectorApi)==null||c.onSelectorSync({viewId:le,scenePath:ge,selectIds:k,selectRect:x,selectorInfo:K})}catch(de){(u=(l=this.Logger)==null?void 0:l.error)==null||u.call(l,`[Appliance]: [selector] onSelectorSync failed: ${de==null?void 0:de.message}`)}break}case W.Snapshot:if((N||Ie)&&ge){const K=this.snapshotMap.get(ge);if(K){const{resolve:de,value:ke}=K;if(ke&&de){const We=Ce||0;ke[We]=N||Ie,ke.every(on=>on!==void 0)&&de(ke)}}}break;case W.BoundingBox:if(B&&ge){const K=this.boundingRectMap.get(ge);K&&K(B)}break;case W.Cursor:V&&this.control.cursor.collectServiceCursor({...S});break;case W.Clear:if(le){this.viewContainerManager.showFloatBar(le,!1);const K=(h=this.clearAllResolveMap.get(le))==null?void 0:h.resolve;K&&K(le);try{(g=this.control.selectorApi)==null||g.onSelectorCleared({viewId:le,scenePath:ge})}catch(de){(d=(p=this.Logger)==null?void 0:p.error)==null||d.call(p,`[Appliance]: [selector] onSelectorCleared failed: ${de==null?void 0:de.message}`)}}break;case W.BackgroundSVGDelete:this.backgroundThreadManager&&le&&this.backgroundThreadManager.consumeTargetOne(le,{...S,msgType:W.BackgroundSVGDelete,viewId:le,dataType:J.Local});break;case W.BackgroundSVGUpdate:this.backgroundThreadManager&&le&&this.backgroundThreadManager.consumeTargetOne(le,{...S,msgType:W.BackgroundSVGUpdate,viewId:le,dataType:J.Local});break;case W.TextUpdate:if(se===T.Text&&fe&&le){_&&[R.SetColorNode,R.SetFontStyle,R.SetLock,R.SetShapeOpt,R.ZIndexNode].includes(_)&&((M=this.control.selectorApi)==null||M.onPropertyApplied({type:_,viewId:le,scenePath:ge,requestId:ne,data:this.buildPropertyAppliedData(_,C,q)}));const K=this.viewContainerManager.transformToOriginPoint((C==null?void 0:C.boxPoint)||[0,0],le),de=(C==null?void 0:C.boxSize)||[0,0],ke=(w=this.viewContainerManager.getView(le))==null?void 0:w.cameraOpt;C?this.control.textEditorManager.updateTextForWorker({x:K[0],y:K[1],w:de[0],h:de[1],scale:(ke==null?void 0:ke.scale)||1,workId:fe,opt:C,dataType:nt,viewId:le,canSync:A||!1,canWorker:!1,updateNodeOpt:q,skipStorageDispatch:!0}):this.control.textEditorManager.delete(fe,A||!1,!1),he&&((m=this.collector)==null||m.dispatch({type:W.UpdateNode,workId:fe,toolsType:T.Text,opt:C,updateNodeOpt:q,isSync:A||!1,viewId:le,scenePath:ge,needUndoTicker:he,requestId:ne,emitEventType:_}))}break;case W.GetTextActive:se===T.Text&&fe&&le&&this.control.textEditorManager.updateTextForWorker({workId:fe,isActive:!0,viewId:le,dataType:J.Local,canWorker:!1,canSync:!0},this.now);break;case W.GetImageBitMap:$t&&le&&fe&&ry({src:$t,isgl:Ft}).then(K=>{var ke;const de=new Set;if(de.add({msgType:W.GetImageBitMap,dataType:J.Local,workId:fe,viewId:le,imageSrc:$t,isSubWorker:rn,imageBitmap:K}),!this.control.hasOffscreenCanvas)(ke=this.mainThread)==null||ke.consume(de);else{const We=rn&&this.subWorker?this.subWorker:this.fullWorker;K?We.postMessage(de,[K]):We.postMessage(de)}});break;case W.GetVNodeInfo:if(fe){const K=fe.toString(),de=(y=this.getVNodeInfoResolveMap.get(K))==null?void 0:y.resolve,ke={...S,uuid:K};de&&de(ke)}break;case W.ReportError:case W.ReportLog:pe&&(v===W.ReportError?this.Logger.error(`[Appliance]: [MasterControlForWorker] reportError ${pe}`):this.Logger.info(`[Appliance]: [MasterControlForWorker] reportLog ${pe}`));break;default:t=!0;break}}t&&this.collectorAsyncData(e)}collectorAsyncData(e){var t,i,r,s,a,c,l;for(const u of e){const{type:h,op:g,workId:p,index:d,removeIds:M,ops:w,opt:m,updateNodeOpt:y,emitEventType:S,requestId:v,toolsType:k,isSync:C,viewId:x,isLockSentEventCursor:O,nextTasks:Y,needUndoTicker:A,collectUndoTicker:b,undoScopeIds:N,undoScopePhase:D}=u;if(!x){console.error("[MasterControlForWorker] collectorAsyncData on viewId in",u);return}const j=u.scenePath||this.viewContainerManager.getCurScenePath(x),B=Number(b??A??void 0);switch(B&&(N!=null&&N.length)&&(D==="collect"||D==="finalize")&&this.internalMsgEmitter.emit("collectExpectedWorkIds",B,x,N,j),A&&Number(A)&&Qy(h)&&(N!=null&&N.length)&&this.internalMsgEmitter.emit("reopenStorageAck",Number(A),x,N,j),h){case W.None:{O&&qe(()=>{this.setLockSentEventCursor(!1)},this.maxLastSyncTime,this.control.hasPolyfillMethod("requestIdleCallback")),A&&Number(A)&&qe(()=>{this.internalMsgEmitter.emit("ackRenderUndoTicker",Number(A),x,j,{requestId:v,emitEventType:S})},0,this.control.hasPolyfillMethod("requestIdleCallback"));break}case W.DrawWork:{(t=this.collector)==null||t.dispatch({type:h,op:g,opt:m,toolsType:k,workId:p,index:d,isSync:C,viewId:x,scenePath:j,updateNodeOpt:y,needUndoTicker:A,collectUndoTicker:b,requestId:v,emitEventType:S});break}case W.FullWork:{if(k===T.Image&&console.info("[appliance-plugin]",{target:"image-undo.collectorAsync.full",viewId:x,scenePath:j,workId:((i=p==null?void 0:p.toString)==null?void 0:i.call(p))||p,toolsType:k,needUndoTicker:A,requestId:v,emitEventType:S}),(r=this.collector)==null||r.dispatch({type:h,ops:w,workId:p,updateNodeOpt:y,opt:m,toolsType:k,isSync:C,viewId:x,scenePath:j,needUndoTicker:A,collectUndoTicker:b,requestId:v,emitEventType:S}),u.autoShapeResult&&console.info("[autoShape][sync]",{viewId:x,scenePath:j,workId:p==null?void 0:p.toString(),toolsType:k,kind:u.autoShapeResult.kind,score:u.autoShapeResult.score,threshold:u.autoShapeResult.threshold}),k===T.BackgroundSVG&&p&&this.markmapIdResolveMap.has(p.toString())){const V=this.markmapIdResolveMap.get(p.toString());V!=null&&V.timer&&(clearTimeout(V.timer),V.timer=void 0),V!=null&&V.resolve&&V.resolve(p.toString()),this.markmapIdResolveMap.delete(p.toString())}this.willSelectorWorkId&&p&&p.toString()===this.willSelectorWorkId&&this.control.runEffectWork(()=>{this.setShapeSelectorByWorkId(this.willSelectorWorkId,x),this.willSelectorWorkId=void 0});break}case W.UpdateNode:{S&&[R.SetColorNode,R.SetFontStyle,R.SetLock,R.SetShapeOpt,R.ZIndexNode].includes(S)&&((s=this.control.selectorApi)==null||s.onPropertyApplied({type:S,viewId:x,scenePath:j,requestId:v,data:this.buildPropertyAppliedData(S,m,y)})),(a=this.collector)==null||a.dispatch({type:h,updateNodeOpt:y,workId:p,opt:m,ops:w,op:g,isSync:C,viewId:x,scenePath:j,needUndoTicker:A,collectUndoTicker:b,requestId:v,emitEventType:S});break}case W.RemoveNode:{S===R.DeleteNode&&((c=this.control.selectorApi)==null||c.onRemoveNodeApplied({viewId:x,requestId:v,removeIds:M})),M&&this.control.textEditorManager.deleteBatch(M,!1,!1),(l=this.collector)==null||l.dispatch({type:h,removeIds:M,isSync:C,viewId:x,scenePath:j,needUndoTicker:A,collectUndoTicker:b,requestId:v,emitEventType:S}),this.willSelectorWorkId&&(M!=null&&M.includes(this.willSelectorWorkId))&&(this.willSelectorWorkId=void 0);break}}Y&&this.collectorAsyncData(Y)}}async onLocalEventEnd(e,t){var u,h,g,p;const i=this.viewContainerManager.getView(t);if(!i)return;const{focusScenePath:r,cameraOpt:s}=i,a=this.viewContainerManager.transformToScenePoint(e,t),c=[],l=[];(u=this.currentToolsData)==null||u.toolsType,T.Pencil;for(const d of this.localPointsBatchData.keys())if(((h=this.currentToolsData)==null?void 0:h.toolsType)===T.Text){const M=this.getLocalPointInfo(d),w=M==null?void 0:M.state;if(w&&w===E.Start){const m=this.currentLocalWorkData.toolsOpt;m.workState=E.Doing,m.boxPoint=[Math.round(a[0]),Math.round(a[1])],m.boxSize=[m.fontSize,m.fontSize],this.control.textEditorManager.checkEmptyTextBlur(),this.control.textEditorManager.createTextForMasterController({workId:this.newWorkId,x:e[0],y:e[1],scale:(s==null?void 0:s.scale)||1,opt:m,type:Ke.Text,isActive:!0,viewId:t,scenePath:r},this.now)}this.deleteLocalPoint(d);continue}else{this.pushLocalPoint(d,a,E.Done,t);const M=this.getLocalPointInfo(d);if(M){const w=this.createAutoShapeTask({workId:d,viewId:t,scenePath:r,points:[...M.rawPoints],opt:M.opt});w&&l.push(w)}c.push(d)}if(c.length){if(Ln((g=this.currentToolsData)==null?void 0:g.toolsType)){const d=this.currentLocalWorkData.undoTickerId;d&&r&&this.internalMsgEmitter.emit("finalizeRequested",d,t,[],r)}(p=this.currentToolsData)==null||p.toolsType,T.Pencil;try{if(await new Promise(M=>{setTimeout(async()=>{const w=new Set(l.map(m=>{var y;return(y=m.workId)==null?void 0:y.toString()}).filter(Boolean));c.forEach(m=>{if(w.has(m.toString())){this.deleteLocalPoint(m);return}this.setLocalPointIsFullWork(m)}),l.forEach(m=>{this.taskBatchData.add(m)}),this.delayWorkStateToDoneResolve=M,l.length&&w.size===c.length&&this.delayWorkStateToDoneResolve(!0),this.consume()},0)})&&c[0]){const M=c[0];c.forEach(w=>{this.deleteLocalPoint(w)}),this.willSelectorWorkId=M.toString()}}catch(d){this.Logger.error(`[Appliance]: [MasterControlForWorker] onLocalEventEnd error: ${d instanceof Error?d.message:String(d)}`)}this.delayWorkStateToDoneResolve=void 0,c.length=0}}onLocalEventDoing(e,t){var r;if(((r=this.currentToolsData)==null?void 0:r.toolsType)===T.Text)return;this.currentLocalWorkData.workState===E.Start&&this.setCurrentLocalWorkData({...this.currentLocalWorkData,workState:E.Doing});let i=!1;for(const[s,{state:a}]of this.localPointsBatchData.entries())if(this.isAbled()&&a!==E.Pending){const c=this.viewContainerManager.transformToScenePoint(e,t);this.pushLocalPoint(s,c,a===E.Start?E.Doing:a,t),i=!0}if(i){this.runAnimation();return}}onLocalEventStart(e,t){var c,l;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,r=i===T.Selector?Z:this.newWorkId,s=this.setZIndex(t);T.Pencil,this.setCurrentLocalWorkData({workState:E.Start,toolsOpt:s,viewId:t});const a=this.viewContainerManager.transformToScenePoint(e,t);if(this.pushLocalPoint(r,a,E.Start,t,s),i!==T.Text){if(this.control.textEditorManager.checkEmptyTextBlur(),this.isCanRecordUndoRedo){const u=this.now,h=Ln(i)?{render:!0,storage:!0,scopeMode:"dynamic"}:{render:!0,storage:!0};T.Pencil,this.internalMsgEmitter.emit("addUndoTicker",u,t,h),this.setCurrentLocalWorkData({...this.currentLocalWorkData,undoTickerId:u})}if(r&&s&&i&&this.isCanStartEventConsum&&this.prepareOnceWork({workId:r,toolsOpt:s,viewId:t},i),this.consumeCount=0,this.postCount=0,this.maxDrawCount=0,this.fullWorkerDrawCount=0,this.subWorkerDrawCount=0,this.clearReRenders(1/0),this.isCanDrawWork){const u=this.viewContainerManager.getCurScenePath(t);u&&((l=this.collector)!=null&&l.hasSelector(t,u))&&(T.Pencil,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,r,s){let a=this.getLocalPointInfo(e);i===E.Start?a={state:E.Start,points:[...t],rawPoints:[...t],opt:s||this.currentLocalWorkData.toolsOpt,isFullWork:!1,viewId:r,undoTickerId:this.currentLocalWorkData.undoTickerId}:a&&(a.state=i,a.points.push(t[0],t[1]),a.rawPoints.push(t[0],t[1]),this.currentLocalWorkData.undoTickerId!==void 0&&(a.undoTickerId=this.currentLocalWorkData.undoTickerId)),a&&this.localPointsBatchData.set(e,a)}deleteLocalPoint(e){this.localPointsBatchData.delete(e)}getLocalPointInfo(e){return this.localPointsBatchData.get(e)}getLocalPointsInfo(){return this.localPointsBatchData}shouldUseAutoShape(e){var t;return((t=this.currentToolsData)==null?void 0:t.toolsType)===T.Pencil&&!!(e!=null&&e.autoShape)}toAutoShapePoints(e){const t=[];for(let i=0;i<e.length-1;i+=2)t.push([e[i],e[i+1]]);return t}logAutoShapeResult(e){}emitAutoShapeResult(e){const{viewId:t,workId:i,scenePath:r,result:s,recognized:a,mappedToolsType:c}=e,l=s.candidates[0],u={workId:i.toString(),viewId:t,scenePath:r,recognized:a,fallbackToPencil:!a,kind:s.kind,score:s.score,threshold:s.threshold,templateId:s.templateId,mappedToolsType:c,topCandidate:l?{kind:l.kind,score:l.score,threshold:l.threshold,templateId:l.templateId}:void 0,metrics:{cornerCount:s.metrics.cornerCount,straightness:s.metrics.straightness,closureRatio:s.metrics.closureRatio,radialVariance:s.metrics.radialVariance,bboxCornerCloseness:s.metrics.bboxCornerCloseness,diamondCloseness:s.metrics.diamondCloseness}};this.publicMsgEmitter.emit("autoShape",u)}createAutoShapeTask(e){const{workId:t,viewId:i,scenePath:r,points:s,opt:a}=e;if(!this.shouldUseAutoShape(a))return;const c=Vy({rawPoints:this.toAutoShapePoints(s),pencilOptions:z.cloneDeep(a),viewId:i,scenePath:r});if(!c)return;const l=Fy(c),u=hr(l,c)||this.mapAutoShapeFallback(l,c);if(this.logAutoShapeResult({viewId:i,workId:t,result:l,recognized:!!u}),this.emitAutoShapeResult({viewId:i,workId:t,scenePath:r,result:l,recognized:!!u,mappedToolsType:u==null?void 0:u.toolsType}),!!u)return{msgType:W.FullWork,dataType:J.Local,workId:t,viewId:i,scenePath:r,toolsType:u.toolsType,opt:u.opt,ops:fy(u),willRefresh:!0,willSyncService:!0,isRunSubWork:!0,clearPreviewLocalWork:!0,isLockSentEventCursor:!0,autoShapeResult:l,needUndoTicker:this.viewContainerManager.getUndoTickerId(i)}}mapAutoShapeFallback(e,t){const{metrics:i}=e;if(e.recognized||i.closureRatio>.1)return null;let r;return i.cornerCount>=4&&i.cornerCount<=6&&i.bboxCornerCloseness<=.15&&i.diamondCloseness>i.bboxCornerCloseness+.15?r="rectangle":i.cornerCount===3&&i.radialVariance<.28?r="triangle":i.cornerCount>=8&&i.cornerCount<=12&&i.radialVariance>.28?r="star":i.cornerCount>=5&&i.radialVariance<.22&&i.bboxCornerCloseness>.2&&(r="ellipse"),r?hr({...e,kind:r,recognized:!0},t):null}correctStorage(e,t,i){var h,g;const r=new Map,s=[],a=new Map,c=[];Object.keys(e).forEach(p=>{var w,m,y;const d=(m=(w=e[p])==null?void 0:w.opt)==null?void 0:m.zIndex,M=(y=e[p])==null?void 0:y.toolsType;z.isNumber(d)&&(M&&M===T.BackgroundSVG?c.push([p,d]):s.push([p,d]))});const l=s.length&&((h=this.zIndexNodeMethod)==null?void 0:h.correct(s))||[],u=c.length&&((g=this.zIndexNodeMethod)==null?void 0:g.correct(c))||[];this.zIndexNodeMethod&&l.length&&(this.zIndexNodeMethod.setMinZIndex(l[0][1]||0,t),this.zIndexNodeMethod.setMaxZIndex(l[l.length-1][1]||0,t)),this.zIndexNodeMethod&&u.length&&(this.zIndexNodeMethod.setMinZIndexForBackgroundSVG(u[0][1]||0,t),this.zIndexNodeMethod.setMaxZIndexForBackgroundSVG(u[u.length-1][1]||0,t));for(const[p,d]of l){if(!e[p])continue;const M=e[p];M.opt&&z.isNumber(M.opt.zIndex)&&M.opt.zIndex!==d&&(M.opt.zIndex=d,r.set(p,M))}r.size&&r.forEach((p,d)=>{var M;(M=this.collector)==null||M.updateValue(d,p,{viewId:t,scenePath:i,isSync:!0}),e[d]=p});for(const[p,d]of u){if(!e[p])continue;const M=e[p];M.opt&&z.isNumber(M.opt.zIndex)&&M.opt.zIndex!==d&&(M.opt.zIndex=d,a.set(p,M))}return a.size&&a.forEach((p,d)=>{var M;(M=this.collector)==null||M.updateValue(d,p,{viewId:t,scenePath:i,isSync:!0}),e[d]=p}),e}async originalEventLintener(e,t,i){var c,l,u;if(!this.isAbled())return;const r=(c=this.collector)==null?void 0:c.uid,s=this.viewContainerManager.getCurScenePath(i);if(r&&!this.control.renderControl.isWritable)return;const a=((l=this.currentToolsData)==null?void 0:l.toolsType)===T.Selector;switch((u=this.currentToolsData)==null?void 0:u.toolsType){case T.Eraser:case T.PencilEraser:case T.BitMapEraser:{if(r&&!this.control.renderControl.isClearAble({uid:r,viewId:i,scenePath:s}))return;break}default:{if(r&&!this.control.renderControl.isRenderAble({uid:r,viewId:i,scenePath:s}))return;break}}switch(e){case E.Start:this.isLocalWorkActive=!0,this.setLocalWorkViewId(i),i&&this.onLocalEventStart(t,i),a&&this.viewContainerManager.showFloatBarBtn(i,!1);break;case E.Doing:i&&i===this.getLocalWorkViewId()&&this.onLocalEventDoing(t,i);break;case E.Done:i&&i===this.getLocalWorkViewId()&&(this.setCurrentLocalWorkData({...this.currentLocalWorkData,workState:E.Done}),await this.onLocalEventEnd(t,i),setTimeout(()=>{this.isLocalWorkActive=!1,this.setCurrentLocalWorkData({workState:E.Pending}),a&&this.viewContainerManager.showFloatBarBtn(i,!0),this.setLocalWorkViewId(void 0)},0));break}this.isLocalWorkActive&&this.viewContainerManager.focuedViewId===i&&this.publicMsgEmitter.emit("workState",e,i),qe(()=>{var h;(h=this.control.pluginManager)==null||h.dispatchPluginEvent("localEvent",i,e,t)},Mn,this.control.hasPolyfillMethod("requestIdleCallback"))}getLocalWorkViewId(){return this.localWorkViewId}setLocalWorkViewId(e){this.localWorkViewId=e}setCurrentToolsData(e){var r,s,a;const t=e.toolsType,i=((r=this.currentToolsData)==null?void 0:r.toolsType)!==e.toolsType;if(super.setCurrentToolsData(e),i){const c=(s=this.viewContainerManager)==null?void 0:s.getAllViews();for(const l of c)if(l){const{id:u,focusScenePath:h}=l;i&&u&&h&&((a=this.collector)!=null&&a.hasSelector(u,h)&&this.blurSelector(u,h),this.control.textEditorManager.checkEmptyTextBlur())}this.taskBatchData.add({msgType:W.UpdateTools,dataType:J.Local,toolsType:t,opt:{...e.toolsOpt,syncUnitTime:this.maxLastSyncTime},combineUnitTime:this.isBezier?this.combineUnitTime:1/0,maxCombineEraserTime:this.maxCombineEraserTime,isRunSubWork:this.isRunSubWork,viewId:io,isRunBackgroundThread:this.control.isUseBackgroundThread}),this.runAnimation()}}prepareOnceWork(e,t){const{workId:i,toolsOpt:r,viewId:s}=e,a={msgType:W.CreateWork,dataType:J.Local,viewId:s,toolsType:t};this.queryTaskBatchData(a).forEach(c=>{this.taskBatchData.delete(c)}),this.taskBatchData.add({...a,workId:i,opt:{...r,syncUnitTime:this.maxLastSyncTime},dataType:J.Local,isRunSubWork:this.isRunSubWork}),this.runAnimation()}createViewWorker(e,t,i){const{offscreenCanvasOpt:r,layerOpt:s,dpr:a,cameraOpt:c}=t,l={msgType:W.Init,dataType:J.Local,viewId:e,offscreenCanvasOpt:r,layerOpt:s,dpr:a,cameraOpt:c,isRunSubWork:!0,isSafari:navigator.userAgent.indexOf("Safari")!==-1&&navigator.userAgent.indexOf("Chrome")===-1,combineUnitTime:this.isBezier?this.combineUnitTime:1/0,maxCombineEraserTime:this.maxCombineEraserTime,syncUnitTime:this.maxLastSyncTime,isUseSimple:this.control.isUseSimple,offscreenCanvas:i.transferControlToOffscreenCanvas};this.isBusy&&this.destroyTaskQueue(),this.post(new Set([l])),this.taskBatchData.size&&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:W.Destroy,dataType:J.Local,viewId:e,isRunSubWork:!0}),this.consume(),t||(i=this.collector)==null||i.dispatch({type:W.Clear,viewId:e}),this.control.renderControl.destoryByViewId(e,t)}onServiceDerive(e,t){var d,M,w,m,y,S,v,k,C,x,O,Y,A,b,N;const{newValue:i,oldValue:r,viewId:s,scenePath:a}=t,c=z.cloneDeep(i)||{},l=e;let u=c.type;if(!i&&r){if(l&&((d=this.collector)==null?void 0:d.getLocalId(l))===Z){this.collector.isOwn(l)?this.blurSelector(s,a):this.blurSelector(s,a,l);return}if(u=W.RemoveNode,r.toolsType===T.LaserPen)return}const h=(M=this.viewContainerManager.getView(s))==null?void 0:M.focusScenePath;if(h&&h!==a)return;if((w=this.collector)!=null&&w.isSelector(e)){const D=(m=this.collector)==null?void 0:m.getUidFromKey(e);if(D&&!this.control.roomMember.isOnLine(D))return}if(u&&l){if(!this.control.renderControl.isFilterAble({viewId:s,elementId:e,scenePath:a},u))return;const D=c;if(D.workId=(y=this.collector)!=null&&y.isOwn(l)?(S=this.collector)==null?void 0:S.getLocalId(l):l,D.msgType=u,D.toolsType===T.LaserPen&&(D.isRunSubWork=!0),D.toolsType===T.BackgroundSVG){if(!this.control.isUseBackgroundThread)return;D.isRunBackgroundThread=!0}if(D.dataType=J.Service,D.viewId=s,D.scenePath=a,D.useAnimation=this.smoothSync&&((v=D.updateNodeOpt)==null?void 0:v.useAnimation)||!1,D.selectIds&&(D.selectIds=D.selectIds.map(j=>{var B,V;return(B=this.collector)!=null&&B.isOwn(j)?(V=this.collector)==null?void 0:V.getLocalId(j):j})),D&&D.toolsType===T.Text||(r==null?void 0:r.toolsType)===T.Text){console.info("[appliance-plugin]",{target:"text-box.undo-derive.text",key:e,viewId:s,scenePath:a,msgType:D.msgType,workId:D.workId,dataType:D.dataType,newTextLength:(C=(k=i==null?void 0:i.opt)==null?void 0:k.text)==null?void 0:C.length,newBoxSize:(x=i==null?void 0:i.opt)==null?void 0:x.boxSize,oldTextLength:(Y=(O=r==null?void 0:r.opt)==null?void 0:O.text)==null?void 0:Y.length,oldBoxSize:(A=r==null?void 0:r.opt)==null?void 0:A.boxSize}),this.control.textEditorManager.onServiceDerive(D);return}D.isEnableCursor=this.control.cursor.isEnableCursor,this.taskBatchData.add(D)}this.runAnimation();const g=t.newValue&&((b=t.newValue)==null?void 0:b.toolsType),p=t.newValue&&((N=t.newValue.opt)==null?void 0:N.zIndex);if(g&&g===T.BackgroundSVG){if(this.zIndexNodeMethod&&z.isNumber(p)){const D=this.zIndexNodeMethod.getMinZIndexForBackgroundSVG(s);this.zIndexNodeMethod.getMaxZIndexForBackgroundSVG(s)<p&&this.zIndexNodeMethod.setMaxZIndexForBackgroundSVG(p,s),D>p&&this.zIndexNodeMethod.setMinZIndexForBackgroundSVG(p,s)}}else if(this.zIndexNodeMethod&&z.isNumber(p)){const D=this.zIndexNodeMethod.getMinZIndex(s);this.zIndexNodeMethod.getMaxZIndex(s)<p&&this.zIndexNodeMethod.setMaxZIndex(p,s),D>p&&this.zIndexNodeMethod.setMinZIndex(p,s)}}pullServiceData(e,t,i={isAsync:!1,useAnimation:!1}){var c,l,u,h,g,p,d;let r=(c=this.collector)==null?void 0:c.getStorageData(e,t);const{isAsync:s,useAnimation:a}=i;if(r){this.control.renderControl.isWritable&&(r=this.correctStorage(r,e,t));const M=Object.keys(r);for(const w of M){if((l=this.collector)!=null&&l.isSelector(w)){const y=(u=this.collector)==null?void 0:u.getUidFromKey(w);if(y&&!this.control.roomMember.isOnLine(y))continue}const m=(h=r[w])==null?void 0:h.type;if(m&&w){if(!this.control.renderControl.isFilterAble({viewId:e,elementId:w,scenePath:t},m))continue;const y=r[w];if(y.workId=(g=this.collector)!=null&&g.isOwn(w)?(p=this.collector)==null?void 0:p.getLocalId(w):w,y.msgType=m,y.dataType=J.Service,y.viewId=e,y.scenePath=t,y.useAnimation=this.smoothSync&&(y.ops?!!a:(d=y.updateNodeOpt)==null?void 0:d.useAnimation)||!1,y.selectIds&&(y.selectIds=y.selectIds.map(S=>{var v,k;return(v=this.collector)!=null&&v.isOwn(S)?(k=this.collector)==null?void 0:k.getLocalId(S):S})),y.toolsType===T.Text){this.control.textEditorManager.onServiceDerive(y);continue}if(y.toolsType===T.BackgroundSVG){if(!this.control.isUseBackgroundThread)continue;y.isRunBackgroundThread=!0}s&&y.updateNodeOpt&&y.updateNodeOpt.useAnimation&&(y.updateNodeOpt.useAnimation=!1),y.isEnableCursor=this.control.cursor.isEnableCursor,this.taskBatchData.add(y)}this.internalMsgEmitter.emit("excludeIds",M,e)}s?this.consume():this.runAnimation()}}runAnimation(){!this.animationId&&!this.isBusy&&(this.animationId=requestAnimationFrame(this.consume.bind(this)))}consume(){var t,i,r,s,a;this.animationId=void 0;const{viewId:e}=this.currentLocalWorkData;if(this.tasksqueue.size){const c=this.consumeQueue(),l=!!c.size;if(this.taskBatchData.size)for(const u of this.taskBatchData.values())u.dataType===J.Service&&(c.add(u),this.taskBatchData.delete(u));c.size?(this.post(c),l&&this.tasksqueue.clear()):this.tasksqueue.size&&(this.animationId=requestAnimationFrame(this.consume.bind(this)));return}if(this.isAbled()&&this.localPointsBatchData.size&&e)for(const[c,{state:l,isFullWork:u,points:h,opt:g,undoTickerId:p}]of this.localPointsBatchData.entries()){if(l===E.Done&&!u||l===E.Start&&!this.isCanStartEventConsum)continue;const d=h.map(M=>M);if(d.length){if(this.isPostCountType&&l===E.Doing){if(this.postCount>this.consumeCount)continue;this.postCount++}this.delayWorkStateToDoneResolve&&l===E.Done&&(this.delayWorkStateToDoneResolve(!0),this.setLockSentEventCursor(!0));const M=e&&this.viewContainerManager.getCurScenePath(e);l===E.Done&&p&&M&&Gy.has((t=this.currentToolsData)==null?void 0:t.toolsType)&&(console.info("[appliance-plugin]",{target:"undo-static.finalize-dispatch",viewId:e,scenePath:M,workId:((i=c==null?void 0:c.toString)==null?void 0:i.call(c))||c,undoTickerId:p}),this.internalMsgEmitter.emit("finalizeRequested",p,e,[c.toString()],M)),this.taskBatchData.add({op:d,workState:l,workId:c,dataType:J.Local,msgType:W.DrawWork,isRunSubWork:this.isRunSubWork,toolsType:(r=this.currentToolsData)==null?void 0:r.toolsType,viewId:e,scenePath:M,opt:g,smoothSync:this.smoothSync,isLockSentEventCursor:this.getLockSentEventCursor(),syncUnitTime:this.maxLastSyncTime,disableEraseImage:this.control.disableEraseImage,disableEraseText:this.control.disableEraseText,postCount:this.isPostCountType&&this.postCount||void 0,fullWorkerDrawCount:this.isCanPostDraw&&this.fullWorkerDrawCount||void 0,needUndoTicker:l===E.Done&&p||void 0,collectUndoTicker:l!==E.Done&&Ln((s=this.currentToolsData)==null?void 0:s.toolsType)&&p||void 0}),(a=this.currentToolsData)==null||a.toolsType,T.Pencil,h.length=0}}if(this.taskBatchData.size){const c=new Set(this.taskBatchData);this.post(c),this.taskBatchData.clear()}this.taskBatchData.size&&(this.animationId=requestAnimationFrame(this.consume.bind(this)))}unWritable(){this.setCurrentLocalWorkData({workState:E.Unwritable}),this.setLockSentEventCursor(!0)}abled(){this.setCurrentLocalWorkData({workState:E.Pending}),this.setLockSentEventCursor(!1)}isAbled(){return this.currentLocalWorkData.workState!==E.Unwritable}postMainThread(e){if(!this.control.hasOffscreenCanvas&&this.mainThread){this.mainThread.consume(e);return}}postWebWorker(e){if(this.control.isUseSimple){const t=[...e].find(i=>i.msgType===W.Init&&i.offscreenCanvas);t!=null&&t.offscreenCanvas?this.fullWorker.postMessage(e,[t.offscreenCanvas.bgCanvas,t.offscreenCanvas.localCanvas,t.offscreenCanvas.serviceCanvas]):this.fullWorker.postMessage(e);return}else if(this.subWorker){this.fullWorker.postMessage(e);const t=new Set;for(const i of e.values()){const r=i.msgType;(r===W.Init||r===W.Clear||r===W.Destroy||r===W.UpdateCamera||r===W.Console||i.isRunSubWork)&&t.add(i)}t.size&&this.subWorker.postMessage(t)}}post(e){if(this.control.isUseBackgroundThread){if(!this.backgroundThreadManager){let i=[];i=z.cloneDeep([...e]),setTimeout(()=>{for(const r of i)this.taskBatchData.add(r)},0);return}const t=new Set;for(const i of e.values()){const r=i.msgType;(r===W.Init||r===W.Clear||r===W.Destroy||r===W.Console||i.isRunBackgroundThread)&&t.add(i)}t.size&&this.backgroundThreadManager.consume(t)}if(!this.control.hasOffscreenCanvas){if(!this.mainThread){let t=[];t=z.cloneDeep([...e]),setTimeout(()=>{for(const i of t)this.taskBatchData.add(i)},0);return}this.postMainThread(e);return}this.postWebWorker(e)}updateNode(e,t,i,r){this.taskBatchData.add({msgType:W.UpdateNode,workId:e,updateNodeOpt:t,viewId:i,scenePath:r,dataType:J.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:W.UpdateDpr,dataType:J.Local,viewId:e}).forEach(i=>{this.taskBatchData.delete(i)}),this.taskBatchData.add({dataType:J.Local,msgType:W.UpdateDpr,viewId:e,dpr:t,isRunSubWork:!0}),this.runAnimation()}updateCamera(e,t){var i,r,s,a;if(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:W.UpdateCamera,dataType:J.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();try{(r=this.control.selectorApi)==null||r.onCameraChange(e)}catch(c){(a=(s=this.Logger)==null?void 0:s.error)==null||a.call(s,`[Appliance]: [selector] onCameraChange failed: ${c==null?void 0:c.message}`)}}}updateCameraDone(){this.useTasksClockId=setTimeout(()=>{var e;this.useTasksClockId=void 0,this.mainTasksqueueCount===this.workerTasksqueueCount?(this.tasksqueue.size&&this.consume(),this.useTasksqueue=!1,this.mainTasksqueueCount=void 0,this.workerTasksqueueCount=void 0,(e=this.methodBuilder)==null||e.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:W.TasksQueue,dataType:J.Local,isRunSubWork:!0,isRunBackgroundThread:this.control.isUseBackgroundThread,mainTasksqueueCount:this.mainTasksqueueCount,tasksqueue:this.tasksqueue,viewId:""});for(const[i,r]of this.tasksqueue.entries())r.cameraOpt&&this.control.textEditorManager.onCameraChange(r.cameraOpt,i)}return e}async clearViewScenePath(e,t,i){var s,a;const r=this.viewContainerManager.getCurScenePath(e);if(i){const c=(s=this.collector)==null?void 0:s.uid;if(c&&!this.control.renderControl.isClearAble({uid:c,viewId:e,scenePath:r}))return}this.control.textEditorManager.clear(e,t),this.queryTaskBatchData({msgType:W.Clear,dataType:J.Local,viewId:e}).forEach(c=>{this.taskBatchData.delete(c)}),this.taskBatchData.add({dataType:J.Local,msgType:W.Clear,viewId:e}),this.runAnimation(),t||(this.control.renderControl.isUsePageAuth(e)&&r?this.control.renderControl.clearRenderPage(e,r):(a=this.collector)==null||a.dispatch({type:W.Clear,viewId:e,scenePath:r})),this.zIndexNodeMethod&&this.zIndexNodeMethod.clearZIndex(e);for(const[c,l]of this.localPointsBatchData.entries())l.viewId===e&&this.localPointsBatchData.delete(c);await new Promise(c=>{const l=this.clearAllResolveMap.get(e)||{resolve:void 0,timer:void 0};l.timer&&clearTimeout(l.timer),l.resolve=c,l.timer=setTimeout(()=>{const u=this.clearAllResolveMap.get(e);u!=null&&u.resolve&&u.resolve(e)},this.maxLastSyncTime),this.clearAllResolveMap.set(e,l)}).then(c=>{this.clearAllResolveMap.delete(c)})}internalMsgEmitterListener(){var e;this.methodBuilder=new ee([R.CopyNode,R.SetColorNode,R.DeleteNode,R.RotateNode,R.ScaleNode,R.TranslateNode,R.ZIndexNode,R.SetFontStyle,R.SetPoint,R.SetLock,R.SetShapeOpt]).registerForMainEngine(te.MainEngine,this.control),this.zIndexNodeMethod=(e=this.methodBuilder)==null?void 0:e.getBuilder(R.ZIndexNode)}setZIndex(e){const t=this.currentToolsData&&z.cloneDeep(this.currentToolsData.toolsOpt);return t&&this.zIndexNodeMethod&&this.isUseZIndex&&(this.zIndexNodeMethod.addMaxLayer(e),t.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),t}checkDrawingWork(e){var r,s,a,c,l;let t=!1;const i=[];for(const[u,{state:h,viewId:g,points:p,opt:d}]of this.localPointsBatchData.entries())if(e===g&&h===E.Start||h===E.Doing){if(h===E.Doing&&this.isCanDrawWork){Number(u)&&Number(u)+60>this.now&&(i.push(u.toString()),this.taskBatchData.add({msgType:W.RemoveNode,workId:u,viewId:g,dataType:J.Local,isRunSubWork:!0}));const M=p.map(w=>w);this.taskBatchData.add({op:M,workState:E.Done,workId:u,dataType:J.Local,msgType:W.DrawWork,isRunSubWork:this.isRunSubWork,toolsType:(r=this.currentToolsData)==null?void 0:r.toolsType,viewId:g,opt:d,scenePath:g&&this.viewContainerManager.getCurScenePath(g)}),t=!0}this.deleteLocalPoint(u)}if((t||i.length)&&((s=this.currentToolsData)==null||s.toolsType,T.Pencil,this.consume(),i.length)){const u=(a=this.viewContainerManager.getView(e))==null?void 0:a.focusScenePath;(c=this.currentToolsData)==null||c.toolsType,T.Pencil,(l=this.collector)==null||l.dispatch({type:W.RemoveNode,removeIds:i,viewId:e,scenePath:u})}}removeDrawingWork(e){var i,r,s,a;const t=[];for(const[c,{state:l,viewId:u}]of this.localPointsBatchData.entries())(e===u&&l===E.Start||l===E.Doing)&&(this.deleteLocalPoint(c),l===E.Doing&&this.isCanDrawWork&&(t.push(c.toString()),this.taskBatchData.add({msgType:W.RemoveNode,workId:c,viewId:u,dataType:J.Local,isRunSubWork:!0})));if(t.length){(i=this.currentToolsData)==null||i.toolsType,T.Pencil,this.consume();const c=(r=this.viewContainerManager.getView(e))==null?void 0:r.focusScenePath;(s=this.currentToolsData)==null||s.toolsType,T.Pencil,(a=this.collector)==null||a.dispatch({type:W.RemoveNode,removeIds:t,viewId:e,scenePath:c})}}removeNodes(e,t){var r,s;const i=(r=this.viewContainerManager.getView(e))==null?void 0:r.focusScenePath;if(i&&t.length){for(const a of t)this.taskBatchData.add({msgType:W.RemoveNode,workId:a,viewId:e,dataType:J.Local,isRunSubWork:!1});this.consume(),(s=this.collector)==null||s.dispatch({type:W.RemoveNode,removeIds:t,viewId:e,scenePath:i})}}hoverCursor(e,t){var i;if(((i=this.currentToolsData)==null?void 0:i.toolsType)===T.Selector&&!this.isBusy){const r=this.viewContainerManager.getView(t);if(r&&r.displayer&&r.displayer.vDom){const c=r.displayer.vDom.state.floatBarData;if(c){const{x:l,y:u,w:h,h:g}=c;if(lo(e,{x:l,y:u,w:h,h:g}))return}}const s=this.viewContainerManager.transformToScenePoint(e,t),a={msgType:W.CursorHover,dataType:J.Local,point:s,toolsType:this.currentToolsData.toolsType,opt:this.currentToolsData.toolsOpt,isRunSubWork:!1,viewId:t};this.queryTaskBatchData({msgType:W.CursorHover,dataType:J.Local,toolsType:this.currentToolsData.toolsType,viewId:t}).forEach(c=>{this.taskBatchData.delete(c)}),this.taskBatchData.add(a),this.runAnimation()}}blurCursor(e){var i;if(((i=this.currentToolsData)==null?void 0:i.toolsType)!==T.Selector)return;const t={msgType:W.CursorBlur,dataType:J.Local,isRunSubWork:!1,viewId:e};this.queryTaskBatchData({msgType:W.CursorHover,dataType:J.Local,viewId:e}).forEach(r=>{this.taskBatchData.delete(r)}),this.taskBatchData.add(t),this.consume()}sendCursorEvent(e,t){var c,l,u;if(!this.currentLocalWorkData||this.currentLocalWorkData.workState===E.Unwritable||this.isBusy)return;const i=(c=this.currentToolsData)==null?void 0:c.toolsType;if(!this.useTasksqueue&&this.workState===E.Pending&&i===T.Selector&&(z.isNumber(e[0])&&z.isNumber(e[1])?this.hoverCursor(e,t):e[0]===void 0&&e[1]===void 0&&this.blurCursor(t)),!this.currentToolsData||!this.isCanSentCursor||!this.control.pluginOptions.extras.cursor.enable)return;const r=(l=this.collector)==null?void 0:l.uid,s=this.viewContainerManager.getCurScenePath(t);switch((u=this.currentToolsData)==null?void 0:u.toolsType){case T.Eraser:case T.PencilEraser:case T.BitMapEraser:{if(r&&!this.control.renderControl.isClearAble({uid:r,viewId:t,filterLocalSelf:!1,scenePath:s}))return;break}default:if(r&&!this.control.renderControl.isWritable||r&&!this.control.renderControl.isRenderAble({uid:r,viewId:t,filterLocalSelf:!1,scenePath:s}))return;break}let a=[void 0,void 0];this.currentToolsData&&this.isCanSentCursor&&!this.localPointsBatchData.size&&!this.getLockSentEventCursor()&&(a=e,this.control.cursor.sendEvent(a,t))}getBoundingRect(e){var i,r;if(!((i=this.boundingRectMap)==null?void 0:i.get(e))){const s=(r=this.collector)==null?void 0:r.getScenePathData(e);if(!s)return;if(Object.keys(s).forEach(a=>{var c;((c=this.collector)==null?void 0:c.getLocalId(a))===Z&&delete s[a]}),Object.keys(s).length&&this.viewContainerManager.mainView&&this.viewContainerManager.mainView.cameraOpt){const a={msgType:W.BoundingBox,dataType:J.Local,scenePath:e,scenes:s,cameraOpt:{...this.viewContainerManager.mainView.cameraOpt},isRunSubWork:!0,viewId:this.viewContainerManager.mainView.id};return this.taskBatchData.add(a),this.runAnimation(),new Promise(c=>{this.boundingRectMap.set(e,c)}).then(c=>(this.boundingRectMap.delete(e),c))}}}getSnapshot(e,t,i,r){var a,c,l,u,h;if(!((a=this.snapshotMap)==null?void 0:a.get(e))){const g=(c=this.collector)==null?void 0:c.getViewIdBySecenPath(e);if(!g)return;const p=(l=this.collector)==null?void 0:l.getStorageData(g,e);if(!p)return;if(Object.keys(p).forEach(d=>{var M;((M=this.collector)==null?void 0:M.getLocalId(d))===Z&&delete p[d]}),Object.keys(p).length){const d=this.viewContainerManager.mainView;if(!d)return;const M=t||((u=d.cameraOpt)==null?void 0:u.width),w=i||((h=d.cameraOpt)==null?void 0:h.height),m={msgType:W.Snapshot,dataType:J.Local,scenePath:e,scenes:p,w:M,h:w,cameraOpt:r&&{...r,width:M,height:w}||d.cameraOpt,isRunSubWork:!0,isRunBackgroundThread:this.control.isUseBackgroundThread,viewId:g};return this.taskBatchData.add(m),this.runAnimation(),new Promise(y=>{this.snapshotMap.set(e,{resolve:y,value:this.control.isUseBackgroundThread?[void 0,void 0]:[void 0]})}).then(y=>(this.snapshotMap.delete(e),y.reverse()))}}}queryTaskBatchData(e){const t=[];if(e)for(const i of this.taskBatchData.values()){let r=!0;for(const[s,a]of Object.entries(e))if(i[s]!==a){r=!1;break}r&&t.push(i)}return t}insertIconify(e,t){var a;const i=this.viewContainerManager.getView(e);if(!i)throw new Error("insertIconify viewId is not exist");if(!t.src)throw new Error("iconify src must be required");if(!/^(http|https):\/\//.test(t.src))throw new Error("iconify src must be http or https");t.strokeColor||(t.strokeColor=(a=this.currentLocalWorkData.toolsOpt)==null?void 0:a.strokeColor);const s=i==null?void 0:i.focusScenePath;if(e&&s){const c=this.now;ye.InternalMsgEmitter.emit("addUndoTicker",c,e,{render:!0,storage:!0}),ye.InternalMsgEmitter.emit("finalizeRequested",c,e,[t.uuid],s);const l={...t,type:At.Iconify};this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayer(e),l.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),this.taskBatchData.add({msgType:W.FullWork,dataType:J.Local,toolsType:T.Image,workId:t.uuid,opt:l,viewId:e,willRefresh:!0,willSyncService:!0,needUndoTicker:c}),this.runAnimation()}}insertBackgroundSVG(e,t){if(!this.control.isUseBackgroundThread)throw new Error("useBackgroundThread of pluginOptions should be true");const i=this.viewContainerManager.getView(e);if(!i)throw new Error("insertBackgroundSVG viewId is not exist");if(!t.src)throw new Error("src must be required");if(t.src&&!/^(http|https):\/\//.test(t.src))throw new Error("iconify src must be http or https");const r=i==null?void 0:i.focusScenePath;if(e&&r){const s=this.now;ye.InternalMsgEmitter.emit("addUndoTicker",s,e,{render:!0,storage:!0}),ye.InternalMsgEmitter.emit("finalizeRequested",s,e,[t.uuid],r);const a={...t,type:Et.url};this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayerForBackgroundSVG(e),a.zIndex=this.zIndexNodeMethod.getMaxZIndexForBackgroundSVG(e)),this.taskBatchData.add({msgType:W.FullWork,dataType:J.Local,toolsType:T.BackgroundSVG,workId:t.uuid,opt:a,viewId:e,willRefresh:!0,willSyncService:!0,needUndoTicker:s,isRunBackgroundThread:!0}),this.runAnimation()}}async insertBackgroundMarkMap(e,t){var s;if(!this.control.isUseBackgroundThread)throw new Error("useBackgroundThread of pluginOptions should be true");const i=this.viewContainerManager.getView(e);if(!i)throw new Error("instertBackgroundMarkMap viewId is not exist");if(!t.data)throw new Error("data must be required");if(t.data&&!RM(t.data))throw new Error("data must be markdown string");const r=i==null?void 0:i.focusScenePath;if(e&&r){const a=t.uuid.toString();if((s=this.collector)!=null&&s.hasId(e,r,a))throw new Error("instertBackgroundMarkMap svgInfo.uuid is already exist");if(this.markmapIdResolveMap.has(a))throw new Error("instertBackgroundMarkMap svgInfo.uuid is already resolving");const c=this.now;ye.InternalMsgEmitter.emit("addUndoTicker",c,e,{render:!0,storage:!0}),ye.InternalMsgEmitter.emit("finalizeRequested",c,e,[a],r);const l={...t,type:Et.markmap};return this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayerForBackgroundSVG(e),l.zIndex=this.zIndexNodeMethod.getMaxZIndexForBackgroundSVG(e)),this.taskBatchData.add({msgType:W.FullWork,dataType:J.Local,toolsType:T.BackgroundSVG,workId:a,opt:l,viewId:e,willRefresh:!0,willSyncService:!0,needUndoTicker:c,isRunBackgroundThread:!0}),this.runAnimation(),new Promise((u,h)=>{this.markmapIdResolveMap.set(a,{resolve:u,timer:setTimeout(()=>{const g=this.markmapIdResolveMap.get(a);g!=null&&g.timer&&(g.timer=void 0),h(a)},this.control.pluginOptions.extras.markmap.timeout)})}).then(u=>{if(u)return this.markmapIdResolveMap.delete(u),u}).catch(u=>{throw this.markmapIdResolveMap.delete(u),ye.InternalMsgEmitter.emit("ackRenderUndoTicker",c,e,r),ye.InternalMsgEmitter.emit("ackStorageUndoTicker",c,e,r),new Error(`instertBackgroundMarkMap svgInfo.uuid ${u} insert timeout`)})}}async updateBackgroundMarkMap(e,t,i){var l;const r=this.viewContainerManager.getView(e);if(!r)throw new Error("updateBackgroundMarkMap viewId is not exist");const s=r==null?void 0:r.focusScenePath;if(!s)throw new Error("updateBackgroundMarkMap scenePath is not exist");if((l=this.collector)!=null&&l.hasId(e,s,t))throw new Error("instertBackgroundMarkMap svgInfo.uuid is already exist");if(this.markmapIdResolveMap.has(t))throw new Error("instertBackgroundMarkMap svgInfo.uuid is already resolving");const a=this.now;ye.InternalMsgEmitter.emit("addUndoTicker",a,e,{render:!0,storage:!0}),ye.InternalMsgEmitter.emit("finalizeRequested",a,e,[t],s);const c={...i,type:Et.markmap};this.taskBatchData.add({msgType:W.UpdateNode,dataType:J.Local,toolsType:T.BackgroundSVG,workId:t,opt:c,viewId:e,willRefresh:!0,willSyncService:!0,needUndoTicker:a,isRunBackgroundThread:!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 r=i==null?void 0:i.focusScenePath;if(e&&r){const{src:s,uuid:a}=t;if(a&&!s){this.tmpImageConfigMap.set(a,t);return}const c=this.now;console.info("[appliance-plugin]",{target:"image-undo.insert.begin",viewId:e,scenePath:r,workId:t.uuid,hasSrc:!!t.src,undoTickerId:c}),ye.InternalMsgEmitter.emit("addUndoTicker",c,e,{render:!0,storage:!0});const l={...t,type:At.Image};this.zIndexNodeMethod&&(this.zIndexNodeMethod.addMaxLayer(e),l.zIndex=this.zIndexNodeMethod.getMaxZIndex(e)),this.taskBatchData.add({msgType:W.FullWork,dataType:J.Local,toolsType:T.Image,workId:t.uuid,opt:l,viewId:e,willRefresh:!0,willSyncService:!0,needUndoTicker:c}),console.info("[appliance-plugin]",{target:"image-undo.insert.enqueue",viewId:e,scenePath:r,workId:t.uuid,msgType:W.FullWork,toolsType:T.Image,needUndoTicker:c}),this.runAnimation(),ye.InternalMsgEmitter.emit("finalizeRequested",c,e,[t.uuid],r),console.info("[appliance-plugin]",{target:"image-undo.insert.finalize",viewId:e,scenePath:r,workId:t.uuid,undoTickerId:c})}}lockImage(e,t,i){var a,c;const r=this.viewContainerManager.getView(e);if(!r)throw new Error("insertImage viewId is not exist");const s=r==null?void 0:r.focusScenePath;if(e&&s&&this.collector){const l=this.collector.getStorageData(e,s);if(!l)return;for(const[u,h]of Object.entries(l))if(h&&h.toolsType===T.Image&&h.opt.uuid===t){const g=this.now,p=(a=this.collector)!=null&&a.isOwn(u)?(c=this.collector)==null?void 0:c.getLocalId(u):u;ye.InternalMsgEmitter.emit("addUndoTicker",g,e,{render:!0,storage:!0});const d={...h.opt,locked:i,type:At.Image};this.taskBatchData.add({msgType:W.FullWork,dataType:J.Local,toolsType:T.Image,workId:p,opt:d,viewId:e,willRefresh:!0,willSyncService:!0,needUndoTicker:g}),this.runAnimation(),ye.InternalMsgEmitter.emit("finalizeRequested",g,e,[p],s);return}}}completeImageUpload(e,t,i){const r=this.viewContainerManager.getView(e);if(!r)throw new Error("insertImage viewId is not exist");const s=r==null?void 0:r.focusScenePath;if(e&&s){const a=this.tmpImageConfigMap.get(t);console.info("[appliance-plugin]",{target:"image-undo.complete-upload",viewId:e,scenePath:s,workId:t,hasPendingImageInfo:!!a}),a&&(a.src=i,this.insertImage(e,a),this.tmpImageConfigMap.delete(t));return}}getImagesInformation(e){const t=[];if(this.collector){const i=this.collector.getScenePathData(e);if(!i)return t;for(const r of Object.values(i))if(r&&r.toolsType===T.Image){const s=r.opt;t.push({uuid:s.uuid,centerX:s.centerX,centerY:s.centerY,width:s.width,height:s.height,locked:s.locked,uniformScale:s.uniformScale,crossOrigin:s.crossOrigin})}}return t}setShapeSelectorByWorkId(e,t){this.taskBatchData.add({workId:Z,selectIds:[e],msgType:W.Select,dataType:J.Local,viewId:t,willSyncService:!0}),this.runAnimation()}blurSelector(e,t,i){this.taskBatchData.add({workId:i||Z,selectIds:[],msgType:W.Select,dataType:J.Service,viewId:e,scenePath:t}),this.runAnimation()}consoleWorkerInfo(){this.taskBatchData.add({msgType:W.Console,dataType:J.Local,isRunSubWork:!0,viewId:""}),this.consume()}sendClearUids(e,t){var r,s;const i=new Set;i.add({msgType:W.AuthClear,dataType:J.Local,viewId:e,clearUids:t,localUid:(r=this.collector)==null?void 0:r.uid}),this.control.hasOffscreenCanvas?this.fullWorker.postMessage(i):(s=this.mainThread)==null||s.consume(i)}async getVNodeInfo(e,t,i){if(!this.getVNodeInfoResolveMap.has(e))return this.taskBatchData.add({msgType:W.GetVNodeInfo,dataType:J.Local,isRunSubWork:!0,viewId:t,workIds:i,workId:e}),this.consume(),await new Promise(r=>{const s=this.getVNodeInfoResolveMap.get(e)||{resolve:void 0,timer:void 0};s.timer&&clearTimeout(s.timer),s.resolve=r,s.timer=setTimeout(()=>{const a=this.getVNodeInfoResolveMap.get(e);a!=null&&a.resolve&&a.resolve({uuid:e})},this.maxLastSyncTime*5),this.getVNodeInfoResolveMap.set(e,s)}).then(r=>{const{uuid:s}=r;return this.getVNodeInfoResolveMap.delete(s),r})}}class qy{constructor(n){I(this,"internalMsgEmitter");I(this,"control");I(this,"roomHotkeyCheckers");I(this,"tmpCopyStore",new Map);I(this,"tmpCopyCoordInfo");var i;const{control:e,internalMsgEmitter:t}=n;this.control=e,this.internalMsgEmitter=t,this.roomHotkeyCheckers=((i=this.control.room)==null?void 0:i.viewsParams.hotKeys.nodes)||[]}get isUseSelf(){var n,e;return((e=(n=this.control)==null?void 0:n.room)==null?void 0:e.disableDeviceInputs)||!1}get isSelector(){var n;return((n=this.control.worker.currentToolsData)==null?void 0:n.toolsType)===T.Selector}get collector(){return this.control.collector}get mainEngine(){return this.control.worker}get keyboardKind(){return/^Mac/i.test(navigator.platform)?"mac":"windows"}getEventKey(n){switch(n.type){case"keydown":return"KeyDown"}return"KeyUp"}onActiveHotkey(n){var i,r,s;const e=this.control.viewContainerManager.focuedViewId,t=(i=this.control.viewContainerManager.focuedView)==null?void 0:i.focusScenePath;if(e&&t)switch(n){case"delete":this.isSelector&&((r=this.collector)!=null&&r.hasSelector(e,t))&&ee.emitMethod(te.MainEngine,R.DeleteNode,{workIds:[Z],viewId:e});break;case"copy":this.isSelector&&((s=this.collector)!=null&&s.hasSelector(e,t))&&this.copySelectorToTemp(e,t);break;case"paste":this.tmpCopyStore.size&&this.pasteTempToFocusView(e,t);break}(n==="changeToPencil"||n==="redo"||n==="undo")&&this.onSelfActiveHotkey(n)}colloctHotkey(n){if(this.isUseSelf){const e=this.checkHotkey(n);e&&this.onSelfActiveHotkey(e)}}onSelfActiveHotkey(n){switch(n){case"changeToPencil":this.setMemberState({currentApplianceName:re.pencil,useNewPencil:!0});break;case"changeToArrow":this.setMemberState({currentApplianceName:re.arrow});break;case"changeToClick":this.setMemberState({currentApplianceName:re.clicker});break;case"changeToEllipse":this.setMemberState({currentApplianceName:re.ellipse});break;case"changeToEraser":this.setMemberState({currentApplianceName:re.eraser});break;case"changeToHand":this.setMemberState({currentApplianceName:re.hand});break;case"changeToLaserPointer":this.setMemberState({currentApplianceName:re.laserPointer});break;case"changeToSelector":this.setMemberState({currentApplianceName:re.selector});break;case"changeToRectangle":this.setMemberState({currentApplianceName:re.rectangle});break;case"changeToStraight":this.setMemberState({currentApplianceName:re.straight});break;case"redo":this.control.room&&!this.control.room.disableSerialization&&this.control.viewContainerManager.redo();break;case"undo":this.control.room&&!this.control.room.disableSerialization&&this.control.viewContainerManager.undo();break;case"changeToText":this.setMemberState({currentApplianceName:re.text});break;case"changeToPencilEraser":this.setMemberState({currentApplianceName:re.pencilEraser});break;case"delete":case"copy":case"paste":this.onActiveHotkey(n);break}}checkHotkey(n){for(const e of this.roomHotkeyCheckers){const{kind:t,checker:i}=e;if(i({nativeEvent:n,kind:this.getEventKey(n),key:n.key,altKey:n.altKey,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey},this.keyboardKind))return t}}copySelectorToTemp(n,e){var l,u;const t=this.control.viewContainerManager.getView(n),i=(u=(l=this.mainEngine)==null?void 0:l.methodBuilder)==null?void 0:u.getBuilder(R.CopyNode);if(!t||!this.collector||!i)return;const r=this.collector.transformKey(Z),s=this.collector.getStorageData(n,e);if(!s)return;const a=s[r],c=a&&i.copySelector({viewId:n,store:a});c&&(this.tmpCopyCoordInfo=c==null?void 0:c.copyCoordInfo,this.tmpCopyStore=c==null?void 0:c.copyStores)}pasteTempToFocusView(n,e){var r,s;const t=this.control.viewContainerManager.getView(n),i=(s=(r=this.mainEngine)==null?void 0:r.methodBuilder)==null?void 0:s.getBuilder(R.CopyNode);if(!(!t||!this.tmpCopyCoordInfo||!this.tmpCopyStore.size||!this.collector||!i)&&t.viewData&&this.tmpCopyCoordInfo){const a=z.cloneDeep(this.tmpCopyCoordInfo.offset),c=this.tmpCopyCoordInfo.cameraOpt,l=t.viewData.camera;a.x=a.x+l.centerX-c.centerX,a.y=a.y+l.centerY-c.centerY;const u=this.control.worker.now;this.control.worker.internalMsgEmitter.emit("addUndoTicker",u,n,{render:!0,storage:!0,copyAck:!0}),i.pasteSelector({viewId:n,scenePath:e,copyStores:z.cloneDeep(this.tmpCopyStore),copyCoordInfo:{offset:a,cameraOpt:l},undoTickerId:u})}}setMemberState(n){var e;(e=this.control.room)==null||e.setMemberState(n)}}class Ky{constructor(n){I(this,"control");I(this,"roomMemberManager");I(this,"worker");I(this,"publicMsgEmitter");I(this,"renderUids",new Map);I(this,"pageAuth",new Map);I(this,"isLocalRender",!1);I(this,"isCurWritable",!1);var i;const{control:e,publicMsgEmitter:t}=n;this.control=e,this.publicMsgEmitter=t,this.roomMemberManager=e.roomMember,this.worker=e.worker,this.isCurWritable=((i=this.control.room)==null?void 0:i.isWritable)||!1}get isWritable(){return this.isCurWritable}onWritableChange(n){this.isCurWritable=n}addPage(n,e=!0){var l,u;const{viewId:t,render:i="localSelf",elementIds:r,pageId:s=(l=this.control.collector)==null?void 0:l.uid}=n,a=this.pageAuth.get(t)||new Map,c=this.control.viewContainerManager.getCurScenePath(t);if(c&&s){const h=a.get(c)||{render:"localSelf",pages:new Map};e&&(h.render=i);const g=r&&this.cloneElementIds(t,c,r,s)||new Set;h.pages.set(s,g),a.set(c,h),this.pageAuth.set(t,a),e&&this.pageAuthEffect(t),this.isLocalRender=!1,(u=this.control.collector)==null||u.dispatchPageAuth({operation:je.addPage,viewId:t,scenePath:c,pageId:s,pageData:{render:i,elementIds:g}},!0)}}delPage(n,e){var s,a;const t=this.pageAuth.get(e);if(!t)return;const i=[...t.keys()].find(c=>{const l=t.get(c);return!!(l&&l.pages.has(n))});if(!i)return;const r=t.get(i);if(r){const{render:c,pages:l}=r,u=c==="localSelf"?(s=this.control.collector)==null?void 0:s.uid:c,h=l.get(n);h!=null&&h.size&&this.delElementIds(e,i,h),l.delete(n),u===n&&this.pageAuthEffect(e)}(a=this.control.collector)==null||a.dispatchPageAuth({operation:je.deletePage,viewId:e,scenePath:i,pageId:n},!0)}delViewPage(n,e=!0){var i;this.pageAuth.get(n)&&(this.pageAuth.delete(n),e&&((i=this.control.collector)==null||i.dispatchPageAuth({operation:je.clearView,viewId:n},e)))}clearRenderPage(n,e,t=!0){var a,c;const i=this.pageAuth.get(n);if(!i)return;const r=i.get(e);let s;if(r){const{render:l,pages:u}=r,h=l==="localSelf"?(a=this.control.collector)==null?void 0:a.uid:l;if(h){if(t){const g=u.get(h);g&&this.delElementIds(n,e,g)}u.set(h,new Set),s=h}}t&&s&&((c=this.control.collector)==null||c.dispatchPageAuth({operation:je.clearPage,viewId:n,scenePath:e,pageId:s},t))}hasPage(n,e,t){const i=this.pageAuth.get(e);if(!i)return!1;const r=i.get(t);return r?r.pages.has(n):!1}getPageInfo(n,e,t){const i=this.pageAuth.get(e);if(!i)return;const r=i.get(t);if(r)return r.pages.get(n)}addRenderPageElementId(n,e=!0,t=!1){var u,h;const{viewId:i,elementId:r,scenePath:s}=n,a=this.pageAuth.get(i);if(!a)throw new Error(`no view info in viewId: ${i}`);const c=a.get(s);let l;if(c){const{render:g,pages:p}=c,d=g==="localSelf"?(u=this.control.collector)==null?void 0:u.uid:g;if(d&&p.has(d)){const M=p.get(d)||new Set;M.add(r),p.set(d,M),l=d}}t&&this.pageAuthEffect(i),e&&l&&((h=this.control.collector)==null||h.dispatchPageAuth({operation:je.addElement,viewId:i,scenePath:s,pageId:l,pageData:{elementId:r}},e))}delRenderPageElementId(n,e=!0,t=!1){var u,h;const{viewId:i,elementId:r,scenePath:s}=n,a=this.pageAuth.get(i);if(!a)throw new Error(`no view info in viewId: ${i}`);const c=a.get(s);let l;if(c){const{render:g,pages:p}=c,d=g==="localSelf"?(u=this.control.collector)==null?void 0:u.uid:g;if(d&&p.has(d)){const M=p.get(d);M&&(M.delete(r),p.set(d,M),l=d)}}t&&this.pageAuthEffect(i),e&&l&&((h=this.control.collector)==null||h.dispatchPageAuth({operation:je.deleteElement,viewId:i,scenePath:s,pageId:l,pageData:{elementId:r}},e))}setPageRender(n,e,t,i=!0){var a;const r=this.pageAuth.get(n);if(!r)throw new Error(`no view info in viewId: ${n}`);const s=r.get(e);s&&(s.render=t),e===this.control.viewContainerManager.getCurScenePath(n)&&this.pageAuthEffect(n),i||(this.isLocalRender=!0),i&&(this.isLocalRender=!1,(a=this.control.collector)==null||a.dispatchPageAuth({operation:je.renderPage,viewId:n,scenePath:e,pageData:{render:t}},i))}isRenderAble(n){var c,l;const{uid:e,viewId:t,filterLocalSelf:i=!0,scenePath:r}=n,s=this.renderUids.get(t);if(s){const{render:u,hide:h}=s;if(u===void 0&&h===void 0)return!0;if(z.isSet(u)){if(u.has(e)||i&&((c=this.control.collector)==null?void 0:c.uid)===e&&u.has("localSelf"))return!0}else if(u===!0&&(!h||z.isSet(h)&&!h.has(e)&&!(i&&h.has("localSelf")&&((l=this.control.collector)==null?void 0:l.uid)===e)))return!0;return!1}const a=this.pageAuth.get(t);if(a&&r){const u=a.get(r);if(u){const{render:h}=u;if(h)return!(h==="localSelf"&&!i)}}return!0}isClearAble(n){var c;const{uid:e,viewId:t,filterLocalSelf:i=!0,scenePath:r}=n,s=this.renderUids.get(t);if(s){const{clear:l}=s;return!!(l===void 0||l===!0||z.isSet(l)&&(l.has(e)||i&&((c=this.control.collector)==null?void 0:c.uid)===e&&l.has("localSelf")))}const a=this.pageAuth.get(t);if(a&&r){const l=a.get(r);if(l){const{render:u}=l;if(u)return!(u==="localSelf"&&!i)}}return!0}isFilterAble(n,e){var c,l,u,h;const{viewId:t,scenePath:i,elementId:r}=n,s=this.renderUids.get(t);if(s&&r){const{render:g,hide:p}=s;if(g===void 0&&p===void 0)return!0;const d=(c=this.control.collector)==null?void 0:c.getUidFromKey(r);return d?!!(z.isSet(g)&&(g.has(d)||g.has("localSelf")&&((l=this.control.collector)==null?void 0:l.uid)===d)||g===!0&&(!p||z.isSet(p)&&!p.has(d)&&!(p.has("localSelf")&&((u=this.control.collector)==null?void 0:u.uid)===d))):!1}const a=this.pageAuth.get(t);if(a&&i&&r){const g=a.get(i);if(g){const{render:p,pages:d}=g;if(!p)return!0;const M=(h=this.control.collector)==null?void 0:h.uid,w=p==="localSelf"?M:p,m=w&&d.get(w)||void 0;if(m)switch(e){case W.RemoveNode:return!0;default:return m.has(r)}return!1}}return!0}isFilterCursor(n){if(this.isUsePageAuth(n)){const e=this.control.viewContainerManager.getCurScenePath(n),t=this.pageAuth.get(n);if(e&&t){const i=t.get(e);if(i){const{render:r}=i;return r!=="localSelf"}}}return!0}isUsePageAuth(n){var i;if(!this.pageAuth.has(n))return!1;const t=this.control.viewContainerManager.getCurScenePath(n);return t&&((i=this.pageAuth.get(n))==null?void 0:i.has(t))||!1}publishRender(n){var s;const{viewId:e,option:t,isSync:i=!0}=n,r={};if(t){const{render:a,hide:c,clear:l}=t;a&&(r.render=a===!0&&!0||new Set(a)),c&&(r.hide=c===!0&&!0||new Set(c)),l&&(r.clear=l===!0&&!0||new Set(l)),this.renderUids.set(e,r)}else this.renderUids.delete(e);i&&((s=this.control.collector)==null||s.dispatchRenderAuth({operation:He.setAuth,viewId:e,renderData:r},i)),this.renderEffect(e)}publishOneRender(n,e,t,i=!0){var a;const r=this.renderUids.get(n);let s;switch(t){case"show":r?(r.render||(r.render=new Set),z.isSet(r.render)&&r.render.add(e),z.isSet(r.hide)&&r.hide.delete(e)):this.renderUids.set(n,{render:new Set([e])}),s=He.setShow;break;case"hide":r?(r.hide||(r.hide=new Set),z.isSet(r.hide)&&r.hide.add(e),z.isSet(r.render)&&r.render.delete(e)):this.renderUids.set(n,{hide:new Set([e])}),s=He.setHide;break}r?this.renderUids.set(n,r):this.renderUids.delete(n),i&&s&&((a=this.control.collector)==null||a.dispatchRenderAuth({operation:s,viewId:n,uid:e},i)),this.renderEffect(n)}publishOneClear(n,e,t,i=!0){var s;const r=this.renderUids.get(n);t?r?(r.clear||(r.clear=new Set),z.isSet(r.clear)&&r.clear.add(e)):this.renderUids.set(n,{clear:new Set([e])}):r&&z.isSet(r.clear)&&r.clear.has(e)&&r.clear.delete(e),r?this.renderUids.set(n,r):this.renderUids.delete(n),i&&((s=this.control.collector)==null||s.dispatchRenderAuth({operation:He.setClear,viewId:n,uid:e,isClear:t},i)),this.renderEffect(n)}syncRenderUids(n,e,t,i){const r=e===!0?!0:e&&Object.keys(e)?new Set(Object.keys(e)):void 0,s=t===!0?!0:t&&Object.keys(t)?new Set(Object.keys(t)):void 0,a=i===!0?!0:i&&Object.keys(i)?new Set(Object.keys(i)):void 0;r||s||a?this.renderUids.set(n,{render:r,hide:s,clear:a}):this.renderUids.delete(n),this.renderEffect(n),this.publicMsgEmitter.emit("syncRenderUids",n,{render:r,hide:s,clear:a})}syncPageAuth(n,e,t=!1){let i=!1;if(!e)this.pageAuth.delete(n);else{const r=this.pageAuth.get(n)||new Map;for(const[s,a]of Object.entries(e)){const{render:c,pages:l}=a,u=r.get(s),h=this.isLocalRender?u==null?void 0:u.render:c;if(h){h!==(u==null?void 0:u.render)&&(i=!0);const g=new Map;for(const[d,M]of Object.entries(l))g.set(d,new Set(Object.keys(M)));const p={render:h,pages:g};g.size&&r.set(s,p)}}r.size&&(this.pageAuth.set(n,r),this.publicMsgEmitter.emit("syncPageAuth",n,r))}(t||i)&&this.pageAuthEffect(n)}destoryByViewId(n,e=!1){var t;this.renderUids.has(n)&&(this.renderUids.delete(n),e||(t=this.control.collector)==null||t.dispatchRenderAuth({operation:He.setAuth,viewId:n})),this.pageAuth.has(n)&&this.control.renderControl.delViewPage(n,!e)}renderEffect(n){var t;const e=(t=this.control.viewContainerManager.getView(n))==null?void 0:t.focusScenePath;e&&this.worker.clearViewScenePath(n,!0).then(()=>{var i;this.worker.pullServiceData(n,e,{isAsync:!0,useAnimation:!1}),this.worker.sendClearUids(n,(i=this.renderUids.get(n))==null?void 0:i.clear)})}pageAuthEffect(n){var t;const e=(t=this.control.viewContainerManager.getView(n))==null?void 0:t.focusScenePath;e&&this.worker.clearViewScenePath(n,!0).then(()=>{this.worker.pullServiceData(n,e,{isAsync:!0,useAnimation:!1}),this.worker.sendClearUids(n,!0)})}cloneElementIds(n,e,t,i){var a,c;const r=(a=this.control.collector)==null?void 0:a.getStorageData(n,e),s=new Set;if(r){for(const l of Object.keys(r))if(t.has(l)){const u=`${l}_${i}`;if(s.add(u),!Object.keys(r).includes(u)){const h=z.cloneDeep(r[l]);(c=this.control.collector)==null||c.updateValue(u,{type:W.FullWork,...h,workId:u},{isSync:!0,viewId:n,scenePath:e})}}}return s}delElementIds(n,e,t){var r,s;const i=(r=this.control.collector)==null?void 0:r.getStorageData(n,e);if(i)for(const a of Object.keys(i))t.has(a)&&Object.keys(i).includes(a)&&((s=this.control.collector)==null||s.updateValue(a,void 0,{isSync:!0,viewId:n,scenePath:e}))}}class Jy{constructor(n){I(this,"internalMsgEmitter");I(this,"control");I(this,"maps",new Map);I(this,"showId");I(this,"color");I(this,"timer");I(this,"updateMiniMapCamera",z.debounce(async n=>{const e=this.maps.get(n);if(e){const t=await this.getMiniMapCamera(n);if(t){const i=t.width/t.scale,r=t.height/t.scale,s=e.miniMapCamera.width/e.miniMapCamera.scale,a=e.miniMapCamera.height/e.miniMapCamera.scale;(i>=s||r>=a)&&(e.miniMapCamera=t);const c=e.miniMapCanvas.current;if(c){const l=c.getContext("2d");if(l){const u=this.control.viewContainerManager.getView(n);if(!(u!=null&&u.focusScenePath))return;const{miniMapCamera:h,contianer:g}=e,{width:p,height:d}=g.getBoundingClientRect(),M=Math.min(p/h.width,d/h.height);l.clearRect(0,0,c.width,c.height),c.width=h.width,c.height=h.height,c.style.width=`${h.width*M}px`,c.style.height=`${h.height*M}px`,await this.control.screenshotToCanvas(l,u.focusScenePath,h.width,h.height,h),this.listener.emitAsync([n,"viewCameraUpate"],1)}}}}},2e3,{maxWait:5e3}));var i;const{control:e,internalMsgEmitter:t}=n;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(n){this.color=n}async createMiniMap(n,e,t){const i=this.control.viewContainerManager.getView(n);if(!i)throw new Error("view not found");const r=i.cameraOpt;if(!r)throw new Error("view camera not found");const{width:s,height:a}=e.getBoundingClientRect();if(!s||!a)throw new Error("contianer width or height is 0");const c=f.createRef();this.maps.set(n,{contianer:e,miniMapCanvas:c,miniMapCamera:t,viewCamera:r}),this.showId=n,this.control.viewContainerManager.setActiveMiniMap(this.showId,!0);const l=Math.min(s/t.width,a/t.height),u=await new Promise(h=>{this.listener.once([n,"miniMapCreate"],()=>{const g=c.current;g&&(g.width=t.width,g.height=t.height,g.style.width=`${t.width*l}px`,g.style.height=`${t.height*l}px`),h(!0)}),this.timer=setTimeout(()=>{h(!1)},2e3)});return this.timer&&clearTimeout(this.timer),u}async getMiniMapCamera(n){const e=this.control.viewContainerManager.getView(n);if(!e)return;const{cameraOpt:t,focusScenePath:i}=e;if(!t||!i)return;const r={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 s=await this.control.getBoundingRect(i)||r;s=wi(s,r)||r;let a=s.width,c=s.height,l=1;const u=a>t.width&&Math.min(t.width/a,l)||l,h=c>t.height&&Math.min(t.height/c,l)||l;return u<=h?(a=u<1&&t.width||a,c=Math.floor(c*u)+1,l=u):u>h&&(c=h<1&&t.height||c,a=Math.floor(a*h)+1,l=h),{scale:l,centerX:s.originX+s.width/2,centerY:s.originY+s.height/2,width:a,height:c}}getMiniMapCanvas(n){const e=this.maps.get(n);return(e==null?void 0:e.miniMapCanvas.current)||null}updateViewCamera(n,e){const t=this.maps.get(n);t&&(t.viewCamera=e,this.listener.emitAsync([n,"viewCameraUpate"],1))}destroyMiniMap(n){const e=n||this.showId;e&&(this.maps.delete(e),this.control.viewContainerManager.setActiveMiniMap(e,!1))}}const Pn=200;function Xy(o){return o instanceof TouchEvent||o instanceof window.TouchEvent||(o==null?void 0:o.touches)&&(o==null?void 0:o.touches.length)||(o==null?void 0:o.changedTouches)&&(o==null?void 0:o.changedTouches.length)}function _y(o){return Xy(o)&&(o.touches&&o.touches.length===1||o.changedTouches&&o.changedTouches.length===1)}function mo(o){return o.touches&&o.touches.length?{x:o.touches[0].pageX,y:o.touches[0].pageY}:o.changedTouches&&o.changedTouches.length?{x:o.changedTouches[0].pageX,y:o.changedTouches[0].pageY}:{x:o.pageX,y:o.pageY}}class Ni{constructor(n){I(this,"_logger");I(this,"pendingArgsByChannel",new Map);I(this,"flushTimerByChannel",new Map);this._logger=n}emit(n,e){if(this._logger){this._logger[n](...e);return}(n==="info"?console.info:n==="warn"?console.warn:console.error)(...e)}flush(n,e){this.flushTimerByChannel.set(e,null);const t=this.pendingArgsByChannel.get(e)||null;this.pendingArgsByChannel.set(e,null),t&&this.emit(n,t)}debounce(n,e,t,i){this.pendingArgsByChannel.set(e,t);const r=this.flushTimerByChannel.get(e);r!=null&&clearTimeout(r),this.flushTimerByChannel.set(e,setTimeout(()=>this.flush(n,e),i))}error(...n){this.emit("error",n)}info(...n){this.emit("info",n)}warn(...n){this.emit("warn",n)}errorDebounced(n,...e){this.debounce("error",n,e,Pn)}infoDebounced(n,...e){this.debounce("info",n,e,Pn)}warnDebounced(n,...e){this.debounce("warn",n,e,Pn)}destroy(){for(const n of this.flushTimerByChannel.keys()){const e=this.flushTimerByChannel.get(n);e!=null&&clearTimeout(e),this.flushTimerByChannel.set(n,null),this.pendingArgsByChannel.set(n,null)}}}const em=new Set([T.Image,T.BackgroundSVG]),dr={"shape.vertices":new Set([T.Polygon,T.Star]),"shape.innerVerticeStep":new Set([T.Star]),"shape.innerRatio":new Set([T.Star]),"shape.placement":new Set([T.SpeechBalloon])},tm=new Set(["fontColor","fontBgColor","fontSize","bold","italic","underline","lineThrough"]),nm=new Set(["strokeColor","thickness","strokeType"]),im=new Set(["fillColor"]),rm=new Set(["zIndexLayer"]),om=new Set([T.Pencil,T.LaserPen,T.Arrow,T.Straight]),gr=new Set([T.Rectangle,T.Ellipse,T.Triangle,T.Rhombus,T.Polygon,T.Star,T.SpeechBalloon]),sm=new Set([T.Pencil]),am=new Set([T.LaserPen,T.Arrow,T.Straight,T.Rectangle,T.Ellipse,T.Star,T.Polygon,T.SpeechBalloon]);function Io(o){return o===ce.Normal||o===ce.Stroke||o===ce.Dotted||o===ce.LongDotted}function Jt(o,n){return o?rm.has(n)?!0:n==="isLocked"?em.has(o):tm.has(n)?o===T.Text:n in dr?dr[n].has(o):im.has(n)?gr.has(o):nm.has(n)?om.has(o)||gr.has(o):!1:!1}function cm(o){return["strokeColor","fillColor","thickness","strokeType","fontColor","fontBgColor","fontSize","bold","italic","underline","lineThrough","isLocked","zIndexLayer","shape.vertices","shape.innerVerticeStep","shape.innerRatio","shape.placement"].filter(e=>Jt(o,e))}function fr(o){var e,t,i,r;const n=[];return o.strokeColor!==void 0&&n.push("strokeColor"),o.fillColor!==void 0&&n.push("fillColor"),o.thickness!==void 0&&n.push("thickness"),o.strokeType!==void 0&&n.push("strokeType"),o.fontColor!==void 0&&n.push("fontColor"),o.fontBgColor!==void 0&&n.push("fontBgColor"),o.fontSize!==void 0&&n.push("fontSize"),o.bold!==void 0&&n.push("bold"),o.italic!==void 0&&n.push("italic"),o.underline!==void 0&&n.push("underline"),o.lineThrough!==void 0&&n.push("lineThrough"),o.isLocked!==void 0&&n.push("isLocked"),o.zIndexLayer!==void 0&&n.push("zIndexLayer"),((e=o.shape)==null?void 0:e.vertices)!==void 0&&n.push("shape.vertices"),((t=o.shape)==null?void 0:t.innerVerticeStep)!==void 0&&n.push("shape.innerVerticeStep"),((i=o.shape)==null?void 0:i.innerRatio)!==void 0&&n.push("shape.innerRatio"),((r=o.shape)==null?void 0:r.placement)!==void 0&&n.push("shape.placement"),n}function pr(o,n){return!o||n===void 0||!Jt(o,"strokeType")?!1:sm.has(o)?Io(n):am.has(o)?n===ce.Normal||n===ce.Dotted||n===ce.LongDotted:!1}const oe="[Appliance]: [selector]",lm=["bold","normal"],um=["italic","normal"],hm=["top","left","right","bottom","topLeft","topRight","bottomLeft","bottomRight","leftTop","leftBottom","rightTop","rightBottom"];class dm{constructor(n){I(this,"control");I(this,"logger");I(this,"lastSelectedIdsByView",new Map);I(this,"lastViewRectByView",new Map);I(this,"updateResolveMap",new Map);I(this,"clearResolveMap",new Map);I(this,"copyResolveMap",new Map);I(this,"deleteResolveMap",new Map);I(this,"lastRemoteSelectorByView",new Map);I(this,"cameraEmitThrottleByView",new Map);I(this,"pendingCameraChangeByView",new Map);I(this,"pendingPropertyGeometryByKey",new Map);I(this,"publicStorageHandler");I(this,"onUndoAckApplied",n=>{var a,c;const{viewId:e,scenePath:t,requestId:i,emitEventType:r}=n;if(!i)return;const s=this.copyResolveMap.get(i);!s||s.viewId!==e||r===R.CopyNode&&(this.copyResolveMap.delete(i),s.timer&&clearTimeout(s.timer),(c=(a=this.logger)==null?void 0:a.info)==null||c.call(a,`${oe} copySelectedElements done requestId=${i} viewId=${e} scenePath=${t} sourceCount=${s.sourceSelectedIds.length}`),s.resolve({ok:!0,requestId:i,sourceSelectedIds:s.sourceSelectedIds,createdIds:[]}))});this.control=n,this.logger=n.logger,this.bindPublicStorageListener(),this.control.internalMsgEmitter.on("undoAckApplied",this.onUndoAckApplied)}cancelUndoTicker(n,e,t){var r,s,a;if(!n)return;const i=t||((r=this.control.viewContainerManager)==null?void 0:r.getCurScenePath(e));i&&((a=(s=this.control.worker)==null?void 0:s.internalMsgEmitter)==null||a.emit("cancelUndoTicker",n,e,i))}resolveCancelableUndoTickerId(n,e){var t,i;return n??((i=(t=this.control.viewContainerManager)==null?void 0:t.getUndoTickerId)==null?void 0:i.call(t,e))}captureUndoTickerDuringDispatch(n){var i,r;let e;const t=(s,a)=>{a===n&&e===void 0&&(e=s)};return(r=(i=this.control.internalMsgEmitter)==null?void 0:i.on)==null||r.call(i,"addUndoTicker",t),{getUndoTickerId:()=>e,dispose:()=>{var s,a;(a=(s=this.control.internalMsgEmitter)==null?void 0:s.off)==null||a.call(s,"addUndoTicker",t)}}}destroy(){for(const[,n]of this.updateResolveMap)n.timer&&clearTimeout(n.timer),n.resolve({requestId:"",ok:!1,viewId:n.viewId,reason:"busy",selectedIds:n.selectedIds,skippedIds:n.skippedIds.length?n.skippedIds:void 0,warnings:n.warnings.length?n.warnings:void 0,geometryChanged:n.geometryChanged});this.updateResolveMap.clear();for(const[,n]of this.clearResolveMap)n.timer&&clearTimeout(n.timer),n.resolve({ok:!1,requestId:"",reason:"busy"});this.clearResolveMap.clear();for(const[,n]of this.copyResolveMap)n.timer&&clearTimeout(n.timer),n.resolve({ok:!1,requestId:"",reason:"busy"});this.copyResolveMap.clear();for(const[,n]of this.deleteResolveMap)n.timer&&clearTimeout(n.timer),n.resolve({ok:!1,requestId:"",reason:"busy"});this.deleteResolveMap.clear();for(const[,n]of this.pendingPropertyGeometryByKey)n.timer&&clearTimeout(n.timer);this.pendingPropertyGeometryByKey.clear(),this.control.internalMsgEmitter.off("undoAckApplied",this.onUndoAckApplied),this.unbindPublicStorageListener()}resolveViewId(n){const e=this.control.viewContainerManager;return n||(e==null?void 0:e.focuedViewId)||ie}getSelectedElements(n){var u,h,g;const e=this.resolveViewId(n);if(!e)return;const t=this.control.viewContainerManager,i=t==null?void 0:t.getView(e);if(!i)return;const r=(g=(h=(u=i.displayer)==null?void 0:u.vDom)==null?void 0:h.state)==null?void 0:g.floatBarData,s=(r==null?void 0:r.selectIds)??[],a=r&&z.isNumber(r.x)&&z.isNumber(r.y)&&z.isNumber(r.w)&&z.isNumber(r.h)?{x:r.x,y:r.y,w:r.w,h:r.h}:void 0,c=i.focusScenePath,l=[];for(const p of s){const d=this.buildSelectedElementInfo(e,c,p,r);d&&l.push(d)}return{viewId:e,scenePath:c,viewRect:a,selectedIds:s,selectedElements:l}}isElementPropertySupported(n,e){return Jt(n,e)}async blurSelector(n){var c,l,u,h,g,p,d,M,w;const e=this.genRequestId("clear"),t=this.resolveViewId(n);if(!t)return(l=(c=this.logger)==null?void 0:c.warn)==null||l.call(c,`${oe} blurSelector rejected: no-view requestId=${e}`),{ok:!1,requestId:e,reason:"no-selection"};const i=this.getSelectedElements(t),r=(i==null?void 0:i.selectedIds)??[];if(!r.length)return(h=(u=this.logger)==null?void 0:u.warn)==null||h.call(u,`${oe} blurSelector rejected: no-selection requestId=${e} viewId=${t}`),{ok:!1,requestId:e,reason:"no-selection"};const s=this.detectSelectorTransforming(t);if(s)return(p=(g=this.logger)==null?void 0:g.warn)==null||p.call(g,`${oe} blurSelector rejected: ${s} requestId=${e} viewId=${t}`),{ok:!1,requestId:e,reason:s};(M=(d=this.logger)==null?void 0:d.info)==null||M.call(d,`${oe} blurSelector request requestId=${e} viewId=${t} selectedCount=${r.length}`);const a=(i==null?void 0:i.scenePath)||((w=this.control.viewContainerManager)==null?void 0:w.getCurScenePath(t));return new Promise(m=>{var S,v,k;const y=setTimeout(()=>{var C,x;this.clearResolveMap.has(e)&&(this.clearResolveMap.delete(e),(x=(C=this.logger)==null?void 0:C.warn)==null||x.call(C,`${oe} blurSelector timeout requestId=${e} viewId=${t}`),m({ok:!1,requestId:e,reason:"busy"}))},5e3);this.clearResolveMap.set(e,{timer:y,resolve:m,viewId:t});try{(S=this.control.worker)==null||S.blurSelector(t,a||"",Z)}catch(C){this.clearResolveMap.delete(e),clearTimeout(y),(k=(v=this.logger)==null?void 0:v.error)==null||k.call(v,`${oe} blurSelector failed requestId=${e} viewId=${t} err=${C==null?void 0:C.message}`),m({ok:!1,requestId:e,reason:"busy"})}})}async updateSelectedElements(n,e){var w,m,y,S,v,k,C,x,O,Y,A,b,N,D;const t=this.genRequestId("update"),i=this.resolveViewId(n),r=e||{};if(!i)return(m=(w=this.logger)==null?void 0:w.warn)==null||m.call(w,`${oe} updateSelectedElements rejected: no-view requestId=${t}`),{requestId:t,viewId:"",ok:!1,reason:"no-selection"};const s=this.getSelectedElements(i),a=(s==null?void 0:s.selectedIds)??[];if(!a.length)return(S=(y=this.logger)==null?void 0:y.warn)==null||S.call(y,`${oe} updateSelectedElements rejected: no-selection requestId=${t} viewId=${i}`),{requestId:t,viewId:i,ok:!1,reason:"no-selection",selectedIds:a};const c=this.detectSelectorTransforming(i);if(c)return(k=(v=this.logger)==null?void 0:v.warn)==null||k.call(v,`${oe} updateSelectedElements rejected: ${c} requestId=${t} viewId=${i}`),{requestId:t,viewId:i,ok:!1,reason:c,selectedIds:a};if(!Object.keys(r).some(j=>r[j]!==void 0))return(x=(C=this.logger)==null?void 0:C.warn)==null||x.call(C,`${oe} updateSelectedElements rejected: unsupported-change requestId=${t} viewId=${i}`),{requestId:t,viewId:i,ok:!1,reason:"unsupported-change",selectedIds:a};const u=[],h=[],g=[];let p={...r};for(const j of a){const B=this.lookupToolsType(i,s==null?void 0:s.scenePath,j);if(!B){h.push(j);continue}const V=this.validateStrokeTypeForChanges(j,p,B,u);V.strokeType!==p.strokeType&&(p=V)}if(p.strokeType!==void 0){const j=a.map(V=>this.lookupToolsType(i,s==null?void 0:s.scenePath,V)).filter(V=>!!V&&Jt(V,"strokeType"));j.length>0?p.strokeType===ce.Stroke&&(j.every(U=>U===T.Pencil)||(delete p.strokeType,u.push({id:a.join(","),field:"strokeType",code:"unsupported-by-toolsType",message:"strokeType=Stroke requires all strokeType-capable selected elements to be Pencil"}))):delete p.strokeType}if(!this.collectPendingMethods(p).size)return this.flushUpdateSelectedElementsWarnings(i,t,u),(Y=(O=this.logger)==null?void 0:O.warn)==null||Y.call(O,`${oe} updateSelectedElements no-valid-fields requestId=${t} viewId=${i} warnings=${u.length}`),{requestId:t,viewId:i,ok:!1,reason:"unsupported-change",selectedIds:a,skippedIds:h.length?h:void 0,warnings:u.length?u:void 0};const M=fr(p);for(const j of a){const B=this.lookupToolsType(i,s==null?void 0:s.scenePath,j);this.hasSupportedChangesForToolsType(p,B)?g.push(j):h.includes(j)||(h.push(j),B&&M.length&&u.push({id:j,field:M.join(","),code:"unsupported-by-toolsType",toolsType:B,message:`selected element id=${j} toolsType=${B} does not support requested fields=[${M.join(",")}]`}))}return g.length?((D=(N=this.logger)==null?void 0:N.info)==null||D.call(N,`${oe} updateSelectedElements request requestId=${t} viewId=${i} scenePath=${(s==null?void 0:s.scenePath)||"-"} selectedCount=${a.length} fields=[${Object.keys(r).join("/")}]`),this.flushUpdateSelectedElementsWarnings(i,t,u),new Promise(j=>{var U,H;const B=setTimeout(()=>{var $,X;const G=this.updateResolveMap.get(t);G&&(this.updateResolveMap.delete(t),(X=($=this.logger)==null?void 0:$.warn)==null||X.call($,`${oe} updateSelectedElements timeout requestId=${t} viewId=${i}`),j({requestId:t,viewId:i,ok:!1,reason:"worker-failed",selectedIds:G.selectedIds,skippedIds:G.skippedIds.length?G.skippedIds:void 0,warnings:G.warnings.length?G.warnings:void 0,geometryChanged:G.geometryChanged}))},8e3);this.updateResolveMap.set(t,{timer:B,resolve:j,viewId:i,selectedIds:a,appliedIds:g,skippedIds:h,warnings:u,geometryChanged:!1});const V=this.captureUndoTickerDuringDispatch(i);try{this.dispatchUpdate(i,[Z],p,T.Selector,t)}catch(G){this.updateResolveMap.delete(t),clearTimeout(B),this.cancelUndoTicker(this.resolveCancelableUndoTickerId(V.getUndoTickerId(),i),i,s==null?void 0:s.scenePath),(H=(U=this.logger)==null?void 0:U.error)==null||H.call(U,`${oe} updateSelectedElements dispatch failed requestId=${t} viewId=${i} err=${G==null?void 0:G.message}`),j({requestId:t,viewId:i,ok:!1,reason:"worker-failed",selectedIds:a,skippedIds:h.length?h:void 0,warnings:u.length?u:void 0})}finally{V.dispose()}})):(this.flushUpdateSelectedElementsWarnings(i,t,u),(b=(A=this.logger)==null?void 0:A.warn)==null||b.call(A,`${oe} updateSelectedElements rejected: no-applicable-selection requestId=${t} viewId=${i}`),{requestId:t,viewId:i,ok:!1,reason:"unsupported-change",selectedIds:a,skippedIds:h.length?h:void 0,warnings:u.length?u:void 0})}async copySelectedElements(n){var a,c,l,u,h,g,p,d;const e=this.genRequestId("copy"),t=this.resolveViewId(n);if(!t)return(c=(a=this.logger)==null?void 0:a.warn)==null||c.call(a,`${oe} copySelectedElements rejected: no-view requestId=${e}`),{ok:!1,requestId:e,reason:"no-selection"};const i=this.getSelectedElements(t),r=(i==null?void 0:i.selectedIds)??[];if(!r.length)return(u=(l=this.logger)==null?void 0:l.warn)==null||u.call(l,`${oe} copySelectedElements rejected: no-selection requestId=${e} viewId=${t}`),{ok:!1,requestId:e,reason:"no-selection"};const s=this.detectSelectorTransforming(t);return s?((g=(h=this.logger)==null?void 0:h.warn)==null||g.call(h,`${oe} copySelectedElements rejected: ${s} requestId=${e} viewId=${t}`),{ok:!1,requestId:e,reason:s}):((d=(p=this.logger)==null?void 0:p.info)==null||d.call(p,`${oe} copySelectedElements request requestId=${e} viewId=${t} scenePath=${(i==null?void 0:i.scenePath)||"-"} selectedCount=${r.length}`),new Promise(M=>{var y,S;const w=setTimeout(()=>{var v,k;this.copyResolveMap.has(e)&&(this.copyResolveMap.delete(e),(k=(v=this.logger)==null?void 0:v.warn)==null||k.call(v,`${oe} copySelectedElements timeout requestId=${e} viewId=${t}`),M({ok:!1,requestId:e,reason:"busy"}))},5e3);this.copyResolveMap.set(e,{timer:w,resolve:M,viewId:t,sourceSelectedIds:r});const m=this.captureUndoTickerDuringDispatch(t);try{ee.emitMethod(te.MainEngine,R.CopyNode,{workIds:[Z],viewId:t,requestId:e})}catch(v){this.copyResolveMap.delete(e),clearTimeout(w),this.cancelUndoTicker(this.resolveCancelableUndoTickerId(m.getUndoTickerId(),t),t,i==null?void 0:i.scenePath),(S=(y=this.logger)==null?void 0:y.error)==null||S.call(y,`${oe} copySelectedElements failed requestId=${e} viewId=${t} err=${v==null?void 0:v.message}`),M({ok:!1,requestId:e,reason:"busy"})}finally{m.dispose()}}))}async deleteSelectedElements(n){var a,c,l,u,h,g,p,d;const e=this.genRequestId("delete"),t=this.resolveViewId(n);if(!t)return(c=(a=this.logger)==null?void 0:a.warn)==null||c.call(a,`${oe} deleteSelectedElements rejected: no-view requestId=${e}`),{ok:!1,requestId:e,reason:"no-selection"};const i=this.getSelectedElements(t),r=(i==null?void 0:i.selectedIds)??[];if(!r.length)return(u=(l=this.logger)==null?void 0:l.warn)==null||u.call(l,`${oe} deleteSelectedElements rejected: no-selection requestId=${e} viewId=${t}`),{ok:!1,requestId:e,reason:"no-selection"};const s=this.detectSelectorTransforming(t);return s?((g=(h=this.logger)==null?void 0:h.warn)==null||g.call(h,`${oe} deleteSelectedElements rejected: ${s} requestId=${e} viewId=${t}`),{ok:!1,requestId:e,reason:s}):((d=(p=this.logger)==null?void 0:p.info)==null||d.call(p,`${oe} deleteSelectedElements request requestId=${e} viewId=${t} scenePath=${(i==null?void 0:i.scenePath)||"-"} selectedCount=${r.length}`),new Promise(M=>{var y,S;const w=setTimeout(()=>{var v,k;this.deleteResolveMap.has(e)&&(this.deleteResolveMap.delete(e),(k=(v=this.logger)==null?void 0:v.warn)==null||k.call(v,`${oe} deleteSelectedElements timeout requestId=${e} viewId=${t}`),M({ok:!1,requestId:e,reason:"busy"}))},5e3);this.deleteResolveMap.set(e,{timer:w,resolve:M,viewId:t,removedIds:r.slice()});const m=this.captureUndoTickerDuringDispatch(t);try{ee.emitMethod(te.MainEngine,R.DeleteNode,{workIds:[Z],viewId:t,requestId:e})}catch(v){this.deleteResolveMap.delete(e),clearTimeout(w),this.cancelUndoTicker(this.resolveCancelableUndoTickerId(m.getUndoTickerId(),t),t,i==null?void 0:i.scenePath),(S=(y=this.logger)==null?void 0:y.error)==null||S.call(y,`${oe} deleteSelectedElements failed requestId=${e} viewId=${t} err=${v==null?void 0:v.message}`),M({ok:!1,requestId:e,reason:"busy"})}finally{m.dispose()}}))}async updateElement(n,e,t,i,r=!0){var d,M,w,m,y,S,v,k,C,x,O,Y,A;const s=this.control.collector,a=this.control.worker;if(!s||!a||!n||!e||!t||!i)return(M=(d=this.logger)==null?void 0:d.warn)==null||M.call(d,`${oe} updateElement ignored: invalid-args viewId=${t||"-"} scenePath=${e||"-"} elementId=${n||"-"}`),!1;const c=(w=s.isLocalId)!=null&&w.call(s,n)&&typeof s.transformKey=="function"?s.transformKey(n):n;if((m=s.isSelector)!=null&&m.call(s,c))return(S=(y=this.logger)==null?void 0:y.warn)==null||S.call(y,`${oe} updateElement ignored: selector-not-allowed viewId=${t} scenePath=${e}`),!1;let l=(C=(k=(v=s.storage)==null?void 0:v[t])==null?void 0:k[e])==null?void 0:C[c];if(!l)return(O=(x=this.logger)==null?void 0:x.warn)==null||O.call(x,`${oe} updateElement ignored: not-found viewId=${t} scenePath=${e} elementId=${n}`),!1;const u=l.toolsType;if(!u||i.toolsType!==u)return(A=(Y=this.logger)==null?void 0:Y.warn)==null||A.call(Y,`${oe} updateElement ignored: toolsType-mismatch viewId=${t} scenePath=${e} elementId=${n} declared=${i.toolsType} actual=${u}`),!1;const h=this.normalizeUpdateElementInfo(i,u),g=this.buildUpdatedElementValue(l,h),p=a.now;return r&&(a.internalMsgEmitter.emit("addUndoTicker",p,t,{render:!0,storage:!0}),a.internalMsgEmitter.emit("finalizeRequested",p,t,[c],e)),await new Promise(b=>{qe(()=>{var D,j;const N=s.plugin;N==null||N.updateAttributes([et.namespace,t,e,c],g),r&&(a.internalMsgEmitter.emit("ackRenderUndoTicker",p,t,e),a.internalMsgEmitter.emit("ackStorageUndoTicker",p,t,e,c)),b(!0),(j=(D=this.logger)==null?void 0:D.info)==null||j.call(D,`${oe} updateElement notify viewId=${t} scenePath=${e} elementId=${n} toolsType=${u} fields=[${Object.keys(h).join("/")}]`)},0,this.control.hasPolyfillMethod("requestIdleCallback")).catch(N=>{var D,j;this.cancelUndoTicker(p,t,e),(j=(D=this.logger)==null?void 0:D.warn)==null||j.call(D,`${oe} updateElement err: ${N.message??"has unknown error"} viewId=${t} scenePath=${e} elementId=${n}`),b(!1)})})}onSelectorTransform(n){var a,c;const{viewId:e,emitEventType:t,workState:i}=n;this.control.publicMsgEmitter.emit("selectorTransformChange",n);const r=`${oe} selectorTransformChange viewId=${e} emitEventType=${t} workState=${i}`,s=this.getDebounceLogger();s!=null&&s.infoDebounced?s.infoDebounced(`selector-transform-change:${e}`,r):(c=(a=this.logger)==null?void 0:a.info)==null||c.call(a,r)}onSelectorSync(n){var M,w,m,y;const{viewId:e,scenePath:t,selectIds:i,selectRect:r,selectorInfo:s}=n,a=i&&i.slice().sort()||[],c=this.lastSelectedIdsByView.get(e)||[],l=!this.isArrayEqual(a,c),u=r&&z.isNumber(r.x)&&z.isNumber(r.y)&&z.isNumber(r.w)&&z.isNumber(r.h)?{x:r.x,y:r.y,w:r.w,h:r.h}:void 0,g=!!this.pendingCameraChangeByView.get(e)&&!l&&!!(i!=null&&i.length);if(l){const S=this.getSelectedElements(e),v={viewId:e,scenePath:t,selectorId:Z,reason:i!=null&&i.length?"select":"clear",viewRect:u,selectedIds:(S==null?void 0:S.selectedIds)??i??[],selectorInfo:s};this.lastSelectedIdsByView.set(e,a),this.control.publicMsgEmitter.emit("selectedElementsChange",v);const k=`${oe} selectedElementsChange reason=${v.reason} viewId=${e} count=${v.selectedIds.length}`,C=this.getDebounceLogger();C!=null&&C.infoDebounced?C.infoDebounced(`selected-elements-change:${e}`,k):(w=(M=this.logger)==null?void 0:M.info)==null||w.call(M,k)}const p=this.lastViewRectByView.get(e),d=!this.isRectEqual(p,u);if(d||l){let S="selector-action",v=i!=null&&i.length?"select":"clear";g&&d?(S="camera-change",v="cameraTransform"):d&&!l&&(i!=null&&i.length)&&(v="selectorTransform"),this.lastViewRectByView.set(e,u);const k={viewId:e,scenePath:t,selectorId:Z,source:S,action:v,viewRect:u};this.control.publicMsgEmitter.emit("selectorGeometryChange",k),this.logGeometry(e,v,(i==null?void 0:i.length)||0),S==="camera-change"&&this.clearPendingCameraChange(e)}if(!(i!=null&&i.length)&&l)for(const[S,v]of this.clearResolveMap.entries())v.viewId===e&&(this.clearResolveMap.delete(S),v.timer&&clearTimeout(v.timer),(y=(m=this.logger)==null?void 0:m.info)==null||y.call(m,`${oe} blurSelector done requestId=${S} viewId=${e}`),v.resolve({ok:!0,requestId:S}))}onSelectorCleared(n){var a,c,l,u;const{viewId:e,scenePath:t,requestId:i}=n;if((this.lastSelectedIdsByView.get(e)||[]).length){const h={viewId:e,scenePath:t,selectorId:Z,reason:"clear",viewRect:void 0,selectedIds:[]};this.lastSelectedIdsByView.set(e,[]),this.control.publicMsgEmitter.emit("selectedElementsChange",h);const g=`${oe} selectedElementsChange reason=clear viewId=${e} requestId=${i||"-"}`,p=this.logger;p!=null&&p.infoDebounced?p.infoDebounced(`selected-elements-change:${e}`,g):(c=(a=this.logger)==null?void 0:a.info)==null||c.call(a,g)}if(this.lastViewRectByView.get(e)){const h={viewId:e,scenePath:t,selectorId:Z,source:"selector-action",action:"clear",viewRect:void 0,requestId:i};this.lastViewRectByView.set(e,void 0),this.control.publicMsgEmitter.emit("selectorGeometryChange",h),this.logGeometry(e,"clear",0)}if(i&&this.clearResolveMap.has(i)){const h=this.clearResolveMap.get(i);this.clearResolveMap.delete(i),h.timer&&clearTimeout(h.timer),(u=(l=this.logger)==null?void 0:l.info)==null||u.call(l,`${oe} blurSelector done requestId=${i} viewId=${e}`),h.resolve({ok:!0,requestId:i})}}onCameraChange(n){const e=this.getSelectedElements(n);if(!(e!=null&&e.selectedIds.length)){this.clearPendingCameraChange(n);return}this.setPendingCameraChange(n,{ts:Date.now(),viewRect:e.viewRect,selectedIds:e.selectedIds.slice()});let t=this.cameraEmitThrottleByView.get(n);t||(t=z.throttle(i=>this.emitCameraGeometry(i),60,{leading:!0,trailing:!0}),this.cameraEmitThrottleByView.set(n,t)),t(n)}emitCameraGeometry(n){const e=this.getSelectedElements(n);if(!e||!e.selectedIds.length||!e.viewRect){this.clearPendingCameraChange(n);return}const t=this.lastViewRectByView.get(n);if(this.isRectEqual(t,e.viewRect))return;this.lastViewRectByView.set(n,e.viewRect);const i={viewId:n,scenePath:e.scenePath,selectorId:Z,source:"camera-change",action:"cameraTransform",viewRect:e.viewRect};this.control.publicMsgEmitter.emit("selectorGeometryChange",i),this.logGeometry(n,"cameraTransform",e.selectedIds.length),this.clearPendingCameraChange(n)}bindPublicStorageListener(){this.publicStorageHandler||(this.publicStorageHandler=n=>this.onSyncStorageChange(n),this.control.publicMsgEmitter.on("syncStorageChange",this.publicStorageHandler))}unbindPublicStorageListener(){this.publicStorageHandler&&(this.control.publicMsgEmitter.off("syncStorageChange",this.publicStorageHandler),this.publicStorageHandler=void 0)}tryResolveUpdateElements(n,e,t,i){var s,a;if(!e)return;const r=this.updateResolveMap.get(e);!r||r.viewId!==n||(r.geometryChanged=r.geometryChanged||i,this.updateResolveMap.delete(e),r.timer&&clearTimeout(r.timer),(a=(s=this.logger)==null?void 0:s.info)==null||a.call(s,`${oe} updateSelectedElements done requestId=${e} viewId=${n} type=${t} geometryChanged=${r.geometryChanged} applied=${r.appliedIds.length}`),r.resolve({requestId:e,viewId:n,ok:!0,selectedIds:r.selectedIds,appliedIds:r.appliedIds,skippedIds:r.skippedIds.length?r.skippedIds:void 0,warnings:r.warnings.length?r.warnings:void 0,geometryChanged:r.geometryChanged}))}onRemoveNodeApplied(n){var r,s;const{viewId:e,requestId:t,removeIds:i}=n;if(t){const a=this.deleteResolveMap.get(t);if(a&&a.viewId===e){const c=i!=null&&i.length?i:a.removedIds;this.deleteResolveMap.delete(t),a.timer&&clearTimeout(a.timer),(s=(r=this.logger)==null?void 0:r.info)==null||s.call(r,`${oe} deleteSelectedElements done requestId=${t} viewId=${e} removedCount=${c.length}`),a.resolve({ok:!0,requestId:t,removedIds:c});return}}}onSyncStorageChange(n){var i,r,s;if(!n||typeof n!="object")return;const e=this.control.collector;if(!e)return;const t=e.uid;for(const[a,c]of Object.entries(n)){if(!c)continue;let l=this.lastRemoteSelectorByView.get(a);l||(l=new Map,this.lastRemoteSelectorByView.set(a,l));const u=new Set;for(const[h,g]of Object.entries(c))if(g)for(const[p,d]of Object.entries(g)){if(((i=e.isLocalId)!=null&&i.call(e,p)?p:((r=e.getLocalId)==null?void 0:r.call(e,p))??p)!==Z)continue;const w=((s=e.getUidFromKey)==null?void 0:s.call(e,p))??(p.split(Ve)[0]||"");!w||w===t||(u.add(w),this.handleRemoteSelectorState(a,h,w,p,d,l))}for(const h of[...l.keys()]){if(u.has(h))continue;const g=l.get(h);if(!g||!g.selectedIds.length){l.delete(h);continue}this.handleRemoteSelectorState(a,"",h,`${h}${Ve}${Z}`,void 0,l)}}}handleRemoteSelectorState(n,e,t,i,r,s){var d;const a=s.get(t)||{selectedIds:[]};let c="update",l=[],u;if(r){const M=r,w=(M.selectIds||[]).slice().sort(),m=a.selectedIds,y=!this.isArrayEqual(w,m);!m.length&&w.length?c="select":y&&!w.length?c="clear":c=y?"select":"update",l=M.selectIds||[];const S=M.selectRect||M.rect||((d=M.updateNodeOpt)==null?void 0:d.rect);S&&z.isNumber(S.x)&&z.isNumber(S.y)&&z.isNumber(S.w)&&z.isNumber(S.h)&&(u={x:S.x,y:S.y,w:S.w,h:S.h})}else{if(!a.selectedIds.length)return;c="clear",l=[],u=void 0}const h=!this.isRectEqual(a.viewRect,u);if(!!this.isArrayEqual(a.selectedIds,l)&&!h)return;s.set(t,{selectedIds:l,viewRect:u});const p={viewId:n,scenePath:e,uid:t,selectorId:i,source:"sync",action:c,viewRect:u,selectedIds:l,selectedElements:this.buildRemoteSelectedElements(n,e,t,l)};this.control.publicMsgEmitter.emit("remoteSelectorChange",p),this.logRemoteSelector(n,t,c,l.length)}logRemoteSelector(n,e,t,i){var a,c;const r=`${oe} remoteSelectorChange uid=${e} action=${t} viewId=${n} count=${i}`,s=this.getDebounceLogger();if(s!=null&&s.infoDebounced){s.infoDebounced(`remote-selector:${n}@${e}`,r);return}(c=(a=this.logger)==null?void 0:a.info)==null||c.call(a,r)}genRequestId(n){return`${n}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}setPendingCameraChange(n,e){this.clearPendingCameraChange(n);const t=setTimeout(()=>{const i=this.pendingCameraChangeByView.get(n);(i==null?void 0:i.ts)===e.ts&&this.pendingCameraChangeByView.delete(n)},400);this.pendingCameraChangeByView.set(n,{...e,timer:t})}clearPendingCameraChange(n){const e=this.pendingCameraChangeByView.get(n);e!=null&&e.timer&&clearTimeout(e.timer),this.pendingCameraChangeByView.delete(n)}getDebounceLogger(){return this.logger}detectSelectorTransforming(n){var l,u,h,g,p;const e=this.control.worker;if(!e)return null;const t=(l=e.getLocalWorkViewId)==null?void 0:l.call(e),i=e.isLocalWorkActive===!0&&t===n,r=(u=e.currentLocalWorkData)==null?void 0:u.workState,s=(p=(g=(h=this.control.viewContainerManager.getView(n))==null?void 0:h.displayer)==null?void 0:g.vDom)==null?void 0:p.state,a=s==null?void 0:s.operationType,c=a===R.TranslateNode||a===R.ScaleNode||a===R.RotateNode||a===R.SetPoint;return i&&c&&r&&r!==E.Pending&&r!==E.Done||i&&c?"selector-transforming":e.isBusy===!0?"busy":null}isArrayEqual(n,e){if(n.length!==e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!==e[t])return!1;return!0}isRectEqual(n,e){return!n&&!e?!0:!n||!e?!1:n.x===e.x&&n.y===e.y&&n.w===e.w&&n.h===e.h}onPropertyApplied(n){const{type:e,viewId:t,requestId:i,data:r}=n,s=e===R.SetFontStyle&&r.fontSize!==void 0||e===R.SetColorNode&&r.thickness!==void 0;this.tryResolveUpdateElements(t,i,e,s),s&&this.schedulePropertyGeometryEmit(t,e,i)}schedulePropertyGeometryEmit(n,e,t){const i=t?`property-geometry:${n}:${e}:${t}`:`property-geometry:${n}:${e}`,r=this.pendingPropertyGeometryByKey.get(i);r!=null&&r.timer&&clearTimeout(r.timer);const s=setTimeout(()=>{this.pendingPropertyGeometryByKey.delete(i);const a=this.getSelectedElements(n);if(!a||!a.selectedIds.length)return;const c=e===R.SetFontStyle?"setFontStyle":"setStyle",l={viewId:n,scenePath:a.scenePath,selectorId:Z,source:"property-change",action:c,viewRect:a.viewRect,requestId:t};this.lastViewRectByView.set(n,a.viewRect),this.control.publicMsgEmitter.emit("selectorGeometryChange",l),this.logGeometry(n,c,a.selectedIds.length)},0);this.pendingPropertyGeometryByKey.set(i,{timer:s,viewId:n,type:e,requestId:t})}lookupToolsType(n,e,t){var a,c,l,u;const i=this.control.collector;if(!i)return;const r=(a=i.isLocalId)!=null&&a.call(i,t)&&typeof i.transformKey=="function"?i.transformKey(t):t,s=(u=(l=(c=i.storage)==null?void 0:c[n])==null?void 0:l[e||""])==null?void 0:u[r];return s==null?void 0:s.toolsType}validateStrokeTypeForChanges(n,e,t,i){return e.strokeType===void 0?e:Io(e.strokeType)?(pr(t,e.strokeType)||i.push({id:n,field:"strokeType",code:"unsupported-by-toolsType",toolsType:t,message:`strokeType not supported by toolsType=${t} for id=${n}, skipped`}),e):(i.push({id:n,field:"strokeType",code:"unsupported-value",toolsType:t,message:`strokeType=${e.strokeType} is not a valid EStrokeType for id=${n}, skipped`}),e)}flushUpdateSelectedElementsWarnings(n,e,t){var s,a,c,l;if(!t.length)return;const i=new Map,r=new Map;for(const u of t)if(u.code==="unsupported-by-toolsType"){const h=i.get(u.field)||{ids:[],toolsTypes:[]};h.ids.push(u.id),h.toolsTypes.push(u.toolsType),i.set(u.field,h)}else if(u.code==="unsupported-value"){const h=r.get(u.field)||[];h.push(u.id),r.set(u.field,h)}for(const[u,h]of i.entries()){const g=[...new Set(h.toolsTypes.filter(Boolean))].join(","),p=[...new Set(h.ids)].join(",");(a=(s=this.logger)==null?void 0:s.warn)==null||a.call(s,`${oe} updateSelectedElements warn unsupported-by-toolsType requestId=${e} viewId=${n} field=${u} toolsTypes=[${g}] ids=[${p}]`)}for(const[u,h]of r.entries())(l=(c=this.logger)==null?void 0:c.warn)==null||l.call(c,`${oe} updateSelectedElements warn unsupported-value requestId=${e} viewId=${n} field=${u} ids=[${[...new Set(h)].join(",")}]`)}collectPendingMethods(n){var t,i,r,s;const e=new Set;return(n.strokeColor!==void 0||n.fillColor!==void 0||n.fontColor!==void 0||n.fontBgColor!==void 0||n.thickness!==void 0||n.strokeType!==void 0)&&e.add(R.SetColorNode),(n.fontSize!==void 0||n.bold!==void 0||n.italic!==void 0||n.underline!==void 0||n.lineThrough!==void 0)&&e.add(R.SetFontStyle),n.isLocked!==void 0&&e.add(R.SetLock),n.zIndexLayer!==void 0&&e.add(R.ZIndexNode),(((t=n.shape)==null?void 0:t.vertices)!==void 0||((i=n.shape)==null?void 0:i.innerVerticeStep)!==void 0||((r=n.shape)==null?void 0:r.innerRatio)!==void 0||((s=n.shape)==null?void 0:s.placement)!==void 0)&&e.add(R.SetShapeOpt),e}hasSupportedChangesForToolsType(n,e){return e?fr(n).some(t=>Jt(e,t)):!1}buildUpdatedElementValue(n,e){var s,a,c,l;const t=e,i={...n,opt:n.opt?{...n.opt}:void 0},r=i.opt||{};return t.strokeColor!==void 0&&(r.strokeColor=t.strokeColor),t.fillColor!==void 0&&(r.fillColor=t.fillColor),t.thickness!==void 0&&(r.thickness=t.thickness),t.strokeType!==void 0&&(r.strokeType=t.strokeType),t.fontColor!==void 0&&(r.fontColor=t.fontColor),t.fontBgColor!==void 0&&(r.fontBgColor=t.fontBgColor),t.fontSize!==void 0&&(r.fontSize=t.fontSize),t.bold!==void 0&&(r.bold=t.bold),t.italic!==void 0&&(r.italic=t.italic),t.underline!==void 0&&(r.underline=t.underline),t.lineThrough!==void 0&&(r.lineThrough=t.lineThrough),t.isLocked!==void 0&&(r.locked=t.isLocked),((s=t.shape)==null?void 0:s.vertices)!==void 0&&(r.vertices=t.shape.vertices),((a=t.shape)==null?void 0:a.innerVerticeStep)!==void 0&&(r.innerVerticeStep=t.shape.innerVerticeStep),((c=t.shape)==null?void 0:c.innerRatio)!==void 0&&(r.innerRatio=t.shape.innerRatio),((l=t.shape)==null?void 0:l.placement)!==void 0&&(r.placement=t.shape.placement),i.opt=r,t.zIndexLayer!==void 0&&(i.updateNodeOpt={...i.updateNodeOpt||{},zIndexLayer:t.zIndexLayer}),i}normalizeUpdateElementInfo(n,e){var g,p;const t={...n},i=[],r=d=>{var M,w;d in t&&(delete t[d],i.push(d),(w=(M=this.logger)==null?void 0:M.warn)==null||w.call(M,`${oe} updateElement warn unsupported-by-toolsType toolsType=${e} field=${d}`))},s=d=>{var M,w;t.shape&&d in t.shape&&(delete t.shape[d],i.push(`shape.${d}`),(w=(M=this.logger)==null?void 0:M.warn)==null||w.call(M,`${oe} updateElement warn unsupported-by-toolsType toolsType=${e} field=shape.${d}`)),t.shape&&!Object.keys(t.shape).length&&delete t.shape},a=d=>{var M,w;d in t&&(i.push(d),(w=(M=this.logger)==null?void 0:M.warn)==null||w.call(M,`${oe} updateElement warn invalid-format toolsType=${e} field=${d} value=${JSON.stringify(t[d])}`),delete t[d])},c=d=>{var M,w;!t.shape||!(d in t.shape)||(i.push(`shape.${d}`),(w=(M=this.logger)==null?void 0:M.warn)==null||w.call(M,`${oe} updateElement warn invalid-format toolsType=${e} field=shape.${d} value=${JSON.stringify(t.shape[d])}`),delete t.shape[d],Object.keys(t.shape).length||delete t.shape)};"strokeColor"in t&&typeof t.strokeColor!="string"&&a("strokeColor"),"fillColor"in t&&typeof t.fillColor!="string"&&a("fillColor"),"fontColor"in t&&typeof t.fontColor!="string"&&a("fontColor"),"fontBgColor"in t&&typeof t.fontBgColor!="string"&&a("fontBgColor"),"thickness"in t&&!Number.isFinite(t.thickness)&&a("thickness"),"fontSize"in t&&!Number.isFinite(t.fontSize)&&a("fontSize"),"strokeType"in t&&!Object.values(ce).includes(t.strokeType)&&a("strokeType"),"strokeType"in t&&t.strokeType!==void 0&&!pr(e,t.strokeType)&&r("strokeType"),"bold"in t&&!lm.includes(t.bold)&&a("bold"),"italic"in t&&!um.includes(t.italic)&&a("italic"),"underline"in t&&typeof t.underline!="boolean"&&a("underline"),"lineThrough"in t&&typeof t.lineThrough!="boolean"&&a("lineThrough"),"isLocked"in t&&typeof t.isLocked!="boolean"&&a("isLocked"),"zIndexLayer"in t&&![st.Top,st.Bottom].includes(t.zIndexLayer)&&a("zIndexLayer"),t.shape&&("vertices"in t.shape&&!Number.isFinite(t.shape.vertices)&&c("vertices"),"innerVerticeStep"in t.shape&&!Number.isFinite(t.shape.innerVerticeStep)&&c("innerVerticeStep"),"innerRatio"in t.shape&&!Number.isFinite(t.shape.innerRatio)&&c("innerRatio"),"placement"in t.shape&&!hm.includes(t.shape.placement)&&c("placement"));const l=new Set(cm(e));return["strokeColor","fillColor","thickness","strokeType","fontColor","fontBgColor","fontSize","bold","italic","underline","lineThrough","isLocked","zIndexLayer"].forEach(d=>{l.has(d)||r(d)}),["vertices","innerVerticeStep","innerRatio","placement"].forEach(d=>{l.has(`shape.${d}`)||s(d)}),i.length&&((p=(g=this.logger)==null?void 0:g.info)==null||p.call(g,`${oe} updateElement filtered toolsType=${e} dropped=[${i.join(",")}]`)),t}dispatchUpdate(n,e,t,i,r){const s=te.MainEngine,a={};t.strokeColor!==void 0&&(a.strokeColor=t.strokeColor),t.fillColor!==void 0&&(a.fillColor=t.fillColor),t.fontColor!==void 0&&(a.fontColor=t.fontColor),t.fontBgColor!==void 0&&(a.fontBgColor=t.fontBgColor),t.thickness!==void 0&&(a.thickness=t.thickness),t.strokeType!==void 0&&(a.strokeType=t.strokeType),Object.keys(a).length&&ee.emitMethod(s,R.SetColorNode,{workIds:e,viewId:n,requestId:r,workState:E.Done,...a});const c={};if(t.fontSize!==void 0&&(c.fontSize=t.fontSize),t.bold!==void 0&&(c.bold=t.bold),t.italic!==void 0&&(c.italic=t.italic),t.underline!==void 0&&(c.underline=t.underline),t.lineThrough!==void 0&&(c.lineThrough=t.lineThrough),Object.keys(c).length&&ee.emitMethod(s,R.SetFontStyle,{workIds:e,viewId:n,requestId:r,workState:E.Done,...c}),t.isLocked!==void 0&&ee.emitMethod(s,R.SetLock,{workIds:e,viewId:n,requestId:r,workState:E.Done,isLocked:t.isLocked}),t.zIndexLayer!==void 0&&ee.emitMethod(s,R.ZIndexNode,{workIds:e,viewId:n,requestId:r,workState:E.Done,layer:t.zIndexLayer}),t.shape){const l={};t.shape.vertices!==void 0&&(l.vertices=t.shape.vertices),t.shape.innerVerticeStep!==void 0&&(l.innerVerticeStep=t.shape.innerVerticeStep),t.shape.innerRatio!==void 0&&(l.innerRatio=t.shape.innerRatio),t.shape.placement!==void 0&&(l.placement=t.shape.placement),Object.keys(l).length&&ee.emitMethod(s,R.SetShapeOpt,{workIds:e,viewId:n,toolsType:i,requestId:r,workState:E.Done,...l})}}buildSelectedElementInfo(n,e,t,i){var M,w,m;const r=this.control.collector,s=r&&r.isLocalId(t)?r.transformKey(t):t,a=(m=(w=(M=r==null?void 0:r.storage)==null?void 0:M[n])==null?void 0:w[e||""])==null?void 0:m[s];if(!a)return;const c=a.toolsType,l=a.opt,u=a.updateNodeOpt||{},h={};(l==null?void 0:l.strokeColor)!==void 0&&(h.strokeColor=l.strokeColor),(l==null?void 0:l.fillColor)!==void 0&&(h.fillColor=l.fillColor),(l==null?void 0:l.thickness)!==void 0&&(h.thickness=l.thickness),(l==null?void 0:l.strokeType)!==void 0&&(h.strokeType=l.strokeType),(l==null?void 0:l.fontColor)!==void 0&&(h.fontColor=l.fontColor),(l==null?void 0:l.fontBgColor)!==void 0&&(h.fontBgColor=l.fontBgColor),(l==null?void 0:l.zIndex)!==void 0&&(h.zIndex=l.zIndex);const g={id:t,toolsType:c,style:h};if(i&&(z.isBoolean(i.canRotate)&&(g.canRotate=i.canRotate),z.isBoolean(i.canLock)&&(g.canLock=i.canLock),i.scaleType&&(g.scaleType=i.scaleType),z.isBoolean(i.isLocked)&&(g.isLocked=i.isLocked)),c===T.Text&&l){const y=l,S={text:y.text,fontSize:y.fontSize,fontFamily:y.fontFamily,bold:y.bold,italic:y.italic,underline:y.underline,lineThrough:y.lineThrough,textAlign:y.textAlign,verticalAlign:y.verticalAlign,boxPoint:y.boxPoint,boxSize:y.boxSize};g.text=S}if(c===T.Polygon){const y=l;g.shape={vertices:y.vertices}}else if(c===T.Star){const y=l;g.shape={vertices:y.vertices,innerVerticeStep:y.innerVerticeStep,innerRatio:y.innerRatio}}else if(c===T.SpeechBalloon){const y=l;g.shape={placement:y.placement}}const p=u.rect;p&&(g.rect={x:p.x,y:p.y,w:p.w,h:p.h});const d=u.centerPos;return d&&(g.centerPos=d),g}buildRemoteSelectedElements(n,e,t,i){if(!i.length)return[];const r=[];for(const s of i){const a=this.buildSelectedElementInfo(n,e,`${t}${Ve}${s}`,void 0);a&&(a.id=s,r.push(a))}return r}logGeometry(n,e,t){var a,c;const i=`${oe} selectorGeometryChange action=${e} viewId=${n} count=${t}`,r=this.getDebounceLogger();if((e==="select"||e==="selectorTransform"||e==="cameraTransform")&&r!=null&&r.infoDebounced){r.infoDebounced(`selector-geometry:${n}:${e}`,i);return}(c=(a=this.logger)==null?void 0:a.info)==null||c.call(a,i)}}const vt="__undo_scope_clear_all__";function gm(o){const{viewId:n,scenePath:e,expectedAcks:t,fallbackTimer:i}=o;return{viewId:n,scenePath:e,expectedRender:t.render,expectedStorage:t.storage,gotRender:!t.render,gotStorage:!t.storage,scopeMode:t.scopeMode||"static",finalizeRequested:!1,collectedScopeKeys:new Set,scopeKeys:new Set,ackedStorageKeys:new Set,meta:{copyAck:t.copyAck,isWritable:t.isWritable},fallbackTimer:i}}function fm(o,n){n&&(o.meta={...o.meta,...n})}function pm(o){return(!o.expectedRender||o.gotRender)&&(!o.expectedStorage||o.gotStorage)}function Mm(o){return!o.ackTimer&&(o.gotRender||o.gotStorage)}function ym(o,n){return o.size>0?o.has(vt)?n===vt:!!n&&o.has(n):!n||o.has(n)}function On(o,n){const e=n.toString();return o.isLocalId(e)?o.transformKey(e):e}function Rn(o,n,e,t){var s,a;const i=new Set;if(!o)return i;const r=o.getStorageData(n,e);for(const c of t){if(c==null)continue;if(c===vt){i.add(vt);continue}const l=On(o,c),u=r==null?void 0:r[l];if(o.getLocalId(l)===Z){(s=u==null?void 0:u.selectIds)==null||s.forEach(h=>{i.add(On(o,h))});continue}i.add(l),(a=u==null?void 0:u.selectIds)==null||a.forEach(h=>{i.add(On(o,h))})}return i}function Mr(o,n,e){return e!=null&&e.has(vt)?!n.has(o):e!=null&&e.size?e.has(o):!n.has(o)}const Fe=class Fe{constructor(n){I(this,"version",no);I(this,"plugin");I(this,"logger");I(this,"room");I(this,"play");I(this,"collector");I(this,"hasSwitchToSelectorEffect");I(this,"snapshootStateMap");I(this,"_disableDeviceInputs");I(this,"_disableEraseImage");I(this,"_disableEraseText");I(this,"_disableCameraTransform");I(this,"_disableUseWorker",!1);I(this,"effectResolve");I(this,"hotkeyManager");I(this,"pluginOptions");I(this,"roomMember");I(this,"cursor");I(this,"textEditorManager");I(this,"worker");I(this,"renderControl");I(this,"miniMapManager");I(this,"pluginManager");I(this,"selectorApi");I(this,"_isPolyfill",{requestIdleCallback:!1,cancelIdleCallback:!1});I(this,"onSceneChange",async(n,e)=>{var s;const t=this.viewContainerManager.getView(e);t!=null&&t.focusScenePath&&(s=this.collector)!=null&&s.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 r=n;r&&this.viewContainerManager.setViewScenePath(e,r),i==null||i.setActive(!0)});I(this,"onRoomMembersChange",n=>{this.roomMember.setRoomMembers(cn(n))});I(this,"onMemberChange",z.throttle(n=>{var s,a;if(!this.room||!this.worker||!n||!this.room.isWritable)return;const e=this.getToolsKey(n),t=(s=this.worker.getCurrentToolsData())==null?void 0:s.toolsType,i=this.viewContainerManager.focuedViewId;i&&t===T.Selector&&e!==T.Selector&&this.worker.blurCursor(i);const r=this.getToolsOpt(e,n);this.worker.setCurrentToolsData(r),(a=this.pluginManager)==null||a.dispatchPluginEvent("setToolkey",e),this.effectViewContainer(e),this.effectResolve&&this.effectResolve(!0)},100,{leading:!1}));I(this,"internalSceneChange",(n,e)=>{var t,i,r,s;this.isUseSimple||((t=this.miniMapManager)==null?void 0:t.activeViewId)===n&&((i=this.miniMapManager)==null||i.destroyMiniMap(n)),(r=this.pluginManager)==null||r.dispatchPluginEvent("sceneChange",n,e),(s=this.worker)==null||s.clearViewScenePath(n,!0).then(()=>{var a;(a=this.worker)==null||a.pullServiceData(n,e,{isAsync:!0,useAnimation:!1})})});I(this,"internalCameraChange",(n,e)=>{var t,i;(t=this.worker)==null||t.updateCamera(n,e),this.isUseSimple||(i=this.miniMapManager)==null||i.updateViewCamera(n,e)});var a,c;const{displayer:e,plugin:t,options:i}=n;this.plugin=t,this.room=Q(e)?e:void 0,this.play=oi(e)?e:void 0;let r;this.room&&(r=(a=this.room)==null?void 0:a.logger,this._disableDeviceInputs=this.room.disableDeviceInputs,this._disableEraseImage=this.room.disableEraseImage,this._disableEraseText=!1),this.pluginOptions=i,((c=i.extras)==null?void 0:c.useWorker)==="mainThread"?this._disableUseWorker=!0:this._disableUseWorker=_i!=="worker",this.roomMember=new YM;const s={control:this,internalMsgEmitter:Fe.InternalMsgEmitter,publicMsgEmitter:Fe.PublicMsgEmitter};this.cursor=new BM(s),this.textEditorManager=new Uf(s),this.worker=new Hy(s),this.hotkeyManager=new qy(s),this.renderControl=new Ky(s),this.pluginManager=new Sr.PluginManager(s),this.isUseSimple||(this.miniMapManager=new Jy(s)),this.logger=new Ni(r)}get publicMsgEmitter(){return Fe.PublicMsgEmitter}get internalMsgEmitter(){return Fe.InternalMsgEmitter}hasPolyfillMethod(n){return this._isPolyfill[n]}registerPolyfillMethod(n){this._isPolyfill[n]=!0}get hasExtendFontFaces(){return this.extendFontFaces.length>0}get extendFontFaces(){var n;return((n=this.pluginOptions.extras.textEditor)==null?void 0:n.extendFontFaces)??we.textEditor.extendFontFaces}get loadFontFacesTimeout(){var n;return((n=this.pluginOptions.extras.textEditor)==null?void 0:n.loadFontFacesTimeout)??we.textEditor.loadFontFacesTimeout}get disableEraseText(){return this._disableEraseText||!1}set disableEraseText(n){this._disableEraseText=n}get disableEraseImage(){return this._disableEraseImage||!1}set disableEraseImage(n){this._disableEraseImage=n,this.room.disableEraseImage=n}get disableDeviceInputs(){return this._disableDeviceInputs||!1}set disableDeviceInputs(n){var t;this._disableDeviceInputs=n;const e=(t=this.worker.getCurrentToolsData())==null?void 0:t.toolsType;e&&this.effectViewContainer(e)}get disableCameraTransform(){return this._disableCameraTransform||!1}set disableCameraTransform(n){this._disableCameraTransform=n,this.room.disableCameraTransform=n}get disableUseWorker(){return this._disableUseWorker||!1}set disableUseWorker(n){this._disableUseWorker=n}get hasOffscreenCanvas(){return this._disableUseWorker?!1:_i==="worker"}get canUseTransferControlToOffscreen(){return this._disableUseWorker?!1:!!HTMLCanvasElement.prototype.transferControlToOffscreen}get isUseOffscreenTransfer(){return this.isUseSimple&&this.hasOffscreenCanvas&&this.canUseTransferControlToOffscreen}get isUseSimple(){return this.pluginOptions.extras.useSimple}get isUseBackgroundThread(){return this.pluginOptions.extras.useBackgroundThread}bindPlugin(n){this.plugin=n,this.collector&&(this.collector.removeStorageStateListener(),this.collector.removeAuthStateListener()),this.collector=new et(this,n,this.pluginOptions.extras.syncOpt.interval),this.activePlugin(),this.selectorApi&&this.selectorApi.destroy(),this.selectorApi=new dm(this)}destroy(){var n,e,t,i,r,s,a,c;this.roomMember.destroy(),(n=this.collector)==null||n.destroy(),(e=this.worker)==null||e.destroy(),(t=this.viewContainerManager)==null||t.destroy(),(i=this.cursor)==null||i.destroy(),(r=this.textEditorManager)==null||r.destory(),(s=this.pluginManager)==null||s.destroy(),(a=this.miniMapManager)==null||a.destroyMiniMap(),(c=this.selectorApi)==null||c.destroy(),this.selectorApi=void 0}cleanCurrentScene(){var t,i;const n=this.worker.now,e=this.worker.getLocalWorkViewId()||this.viewContainerManager.focuedViewId;if(e){const r=this.viewContainerManager.getCurScenePath(e),s=(r&&((i=(t=this.collector)==null?void 0:t.storage[e])!=null&&i[r])?Object.keys(this.collector.storage[e][r]):[])||[];Fe.InternalMsgEmitter.emit("addUndoTicker",n,e,{render:!0,storage:!0}),s.length&&Fe.InternalMsgEmitter.emit("finalizeRequested",n,e,[vt],r),this.worker.clearViewScenePath(e,!1,!0).then(()=>{Fe.InternalMsgEmitter.emit("ackRenderUndoTicker",n,e,r),Fe.InternalMsgEmitter.emit("ackStorageUndoTicker",n,e,r,vt)})}}async setWritable(n){var e,t;if(!n){(e=this.cursor)==null||e.unabled(),this.textEditorManager.checkEmptyTextBlur();const i=this.viewContainerManager.getAllViews();for(const r of i){r!=null&&r.focusScenePath&&(t=this.collector)!=null&&t.hasSelector(r.id,r.focusScenePath)&&this.worker.blurSelector(r.id,r.focusScenePath);const s=r==null?void 0:r.displayer;s&&(s.setActive(!1),await s.stopEventHandler())}}await new Promise(i=>{setTimeout(()=>{i()},500)})}onWritableChange(n){var i;n?this.worker.abled():this.worker.unWritable(),((i=this.worker.getCurrentToolsData())==null?void 0:i.toolsType)===T.Text&&this.viewContainerManager.focuedViewId&&(n?this.viewContainerManager.activeTextEditor(this.viewContainerManager.focuedViewId):this.viewContainerManager.unActiveTextEditor(this.viewContainerManager.focuedViewId)),this.renderControl.onWritableChange(n),this.viewContainerManager.getAllViews().forEach(r=>{const s=r==null?void 0:r.displayer;s&&(s.bindToolsClass(),n?s.setActive(!0):s.setActive(!1))})}getToolsKey(n){const e=n.currentApplianceName;switch(this.hasSwitchToSelectorEffect=!1,e){case re.text:return n.textCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),T.Text;case re.pencil:return n.useLaserPen?T.LaserPen:T.Pencil;case re.eraser:return T.Eraser;case re.pencilEraser:return this.pluginOptions.extras.pencilEraser.useBitMap===!1?T.PencilEraser:T.BitMapEraser;case re.selector:return T.Selector;case re.arrow:return n.arrowCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),T.Arrow;case re.straight:return n.straightCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),T.Straight;case re.ellipse:return n.ellipseCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),T.Ellipse;case re.rectangle:return n.rectangleCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),T.Rectangle;case re.shape:if(n.shapeCompleteToSelector&&(this.hasSwitchToSelectorEffect=!0),n.shapeType===Be.Pentagram||n.shapeType===Be.Star)return T.Star;if(n.shapeType===Be.Polygon||n.shapeType===Be.Triangle||n.shapeType===Be.Rhombus)return T.Polygon;if(n.shapeType===Be.SpeechBalloon)return T.SpeechBalloon;break}return T.Clicker}getToolsOpt(n,e){if(n===T.Clicker)return{toolsType:n,toolsOpt:{}};const t={strokeColor:bt(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(n){case T.Text:t.fontFamily=window.getComputedStyle(document.documentElement).getPropertyValue("font-family"),t.fontSize=(e==null?void 0:e.textSizeOverride)||(e==null?void 0:e.textSize)||Number(window.getComputedStyle(document.body).fontSize),t.textAlign=(e==null?void 0:e.textAlign)||"left",t.verticalAlign=(e==null?void 0:e.verticalAlign)||"middle",t.fontColor=(e==null?void 0:e.textColor)&&bt(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)&&bt(e.textBgColor[0],e.textBgColor[1],e.textBgColor[2],e.textBgOpacity||1)||"transparent",t.bold=(e==null?void 0:e.bold)&&"bold"||void 0,t.italic=(e==null?void 0:e.italic)&&"italic"||void 0,t.underline=(e==null?void 0:e.underline)||void 0,t.lineThrough=(e==null?void 0:e.lineThrough)||void 0,t.text="",t.strokeColor=void 0;break;case T.Pencil:{const i=(e==null?void 0:e.strokeType)||ce.Normal;t.strokeType=i,t.autoShape=!!(e!=null&&e.autoShape),t.previewLocalOnly=!!(e!=null&&e.autoShape),t.lineCap=this.getLineCap(i),t.lineDash=this.getLineDash(i);break}case T.PencilEraser:case T.BitMapEraser:case T.Eraser:t.thickness=Math.min(4,Math.max(1,Math.floor(e.pencilEraserSize||1)))-1;break;case T.LaserPen:{t.duration=(e==null?void 0:e.duration)||1,e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===ce.Stroke?t.strokeType=ce.Normal:t.strokeType=(e==null?void 0:e.strokeType)||ce.Normal;const i=t.strokeType;t.lineCap=this.getLineCap(i),t.lineDash=this.getLineDash(i);break}case T.Arrow:case T.Straight:{e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===ce.Stroke?t.strokeType=ce.Normal:t.strokeType=(e==null?void 0:e.strokeType)||ce.Normal;const i=t.strokeType;t.strokeType=i,t.lineCap=this.getLineCap(i),t.lineDash=this.getLineDash(i);break}case T.Ellipse:case T.Rectangle:case T.Star:case T.Polygon:case T.SpeechBalloon:{e!=null&&e.strokeType&&(e==null?void 0:e.strokeType)===ce.Stroke?t.strokeType=ce.Normal:t.strokeType=(e==null?void 0:e.strokeType)||ce.Normal;const i=t.strokeType;t.lineCap=this.getLineCap(i),t.lineDash=this.getLineDash(i),n===T.Star&&(e.shapeType===Be.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)),n===T.Polygon&&(e.shapeType===Be.Triangle?t.vertices=3:e.shapeType===Be.Rhombus?t.vertices=4:e.vertices&&(t.vertices=e.vertices)),t.fillColor=(e==null?void 0:e.fillColor)&&bt(e.fillColor[0],e.fillColor[1],e.fillColor[2],e==null?void 0:e.fillOpacity)||"transparent",n===T.SpeechBalloon&&(t.placement=e.placement||"bottomLeft");break}}return{toolsType:n,toolsOpt:t}}getLineCap(n){switch(n){case ce.Normal:return this.pluginOptions.extras.normalStroke.lineCap||we.normalStroke.lineCap;case ce.Dotted:return this.pluginOptions.extras.dottedStroke.lineCap||we.dottedStroke.lineCap;case ce.LongDotted:return this.pluginOptions.extras.longDottedStroke.lineCap||we.longDottedStroke.lineCap;default:return}}getLineDash(n){switch(n){case ce.Normal:return;case ce.Dotted:{const{segment:e,gap:t}=this.pluginOptions.extras.dottedStroke||we.dottedStroke;return[e,t]}case ce.LongDotted:{const{segment:e,gap:t}=this.pluginOptions.extras.longDottedStroke||we.longDottedStroke;return[e,t]}default:return}}effectViewContainer(n){var e,t,i,r,s;if(this.disableDeviceInputs===!0)this.room.disableDeviceInputs=!0,(e=this.worker)==null||e.unWritable(),(t=this.cursor)==null||t.unabled();else switch(n!==T.Text&&this.viewContainerManager.focuedViewId&&this.viewContainerManager.unActiveTextEditor(this.viewContainerManager.focuedViewId),n){case T.Text:case T.Pencil:case T.LaserPen:case T.Arrow:case T.Straight:case T.Rectangle:case T.Ellipse:case T.Star:case T.Polygon:case T.SpeechBalloon:case T.Triangle:case T.Rhombus:case T.Eraser:case T.PencilEraser:case T.BitMapEraser:case T.Selector:this.room.disableDeviceInputs=!0,(i=this.worker)==null||i.abled(),n===T.Text&&this.viewContainerManager.focuedViewId&&this.viewContainerManager.activeTextEditor(this.viewContainerManager.focuedViewId);break;default:this.room.disableDeviceInputs=!1,(r=this.worker)==null||r.unWritable(),(s=this.cursor)==null||s.unabled();break}setTimeout(()=>{this.viewContainerManager.getAllViews().forEach(c=>{c!=null&&c.displayer&&c.displayer.bindToolsClass()})},0)}async getBoundingRect(n){var t,i,r,s,a;const e=await((t=this.worker)==null?void 0:t.getBoundingRect(n));if(e){const c=((r=(i=this.viewContainerManager.mainView)==null?void 0:i.viewData)==null?void 0:r.convertToPointInWorld({x:e.x,y:e.y}))||{x:e.x,y:e.y},l=((a=(s=this.viewContainerManager.mainView)==null?void 0:s.viewData)==null?void 0:a.camera.scale)||1;return{width:Math.floor(e.w/l)+1,height:Math.floor(e.h/l)+1,originX:c.x,originY:c.y}}}async screenshotToCanvas(n,e,t,i,r,s,a){const c=await this.worker.getSnapshot(e,t,i,r);c&&c.forEach(l=>{if(l)try{console.log("[screenshotToCanvas] Drawing ImageBitmap:",l.width,l.height),n.drawImage(l,s||0,a||0)}catch(u){console.error("[screenshotToCanvas] Failed to draw ImageBitmap:",u)}l instanceof ImageBitmap?l.close():l instanceof HTMLImageElement&&l.remove()})}async scenePreview(n,e){var s,a,c,l;const t=(s=this.collector)==null?void 0:s.getViewIdBySecenPath(n);if(!t)return;const i=this.viewContainerManager.getView(t);if(!i||!((a=i.cameraOpt)!=null&&a.width)||!((c=i.cameraOpt)!=null&&c.height))return;const r=await((l=this.worker)==null?void 0:l.getSnapshot(n));if(r&&this.worker){const u=document.createElement("canvas"),h=u.getContext("2d"),{width:g,height:p}=i.cameraOpt;u.width=g,u.height=p,h&&(r.forEach(d=>{d&&(h.drawImage(d,0,0),d instanceof ImageBitmap?d.close():d instanceof HTMLImageElement&&d.remove())}),e.crossOrigin="anonymous",e.src=u.toDataURL(),e.onload=()=>{u.remove()},e.onerror=()=>{u.remove(),e.remove()})}}switchToText(){var n;(n=this.room)==null||n.setMemberState({currentApplianceName:re.text})}switchToSelector(){var n;(n=this.room)==null||n.setMemberState({currentApplianceName:re.selector})}async runEffectWork(n){if(this.hasSwitchToSelectorEffect){const e=await new Promise(t=>{this.switchToSelector(),this.effectResolve=t});this.effectResolve=void 0,e&&n&&n()}}setSnapshootData(){var n;this.room&&(this.snapshootStateMap=new Map,this.snapshootStateMap.set("memberState",(n=this.room)==null?void 0:n.state.memberState))}getSnapshootData(n){var e;return(e=this.snapshootStateMap)==null?void 0:e.get(n)}clearSnapshootData(){var n;(n=this.snapshootStateMap)==null||n.clear(),this.snapshootStateMap=void 0}useBitMapEraser(n){this.pluginOptions.extras.pencilEraser.useBitMap=n}consoleWorkerInfo(){var n;(n=this.worker)==null||n.consoleWorkerInfo()}filterRenderByUid(n,e,t=!0){var r;this.viewContainerManager.getView(n)&&((r=this.renderControl)==null||r.publishRender({viewId:n,option:e,isSync:t}))}cancelFilterRender(n,e=!0){var t;(t=this.renderControl)==null||t.publishRender({viewId:n,isSync:e})}async createMiniMap(n,e){var i,r,s;if(this.isUseSimple)throw new Error("simple mode not support createMiniMap");const t=await((i=this.miniMapManager)==null?void 0:i.getMiniMapCamera(n));if(t&&await((r=this.miniMapManager)==null?void 0:r.createMiniMap(n,e,t))){const c=(s=this.miniMapManager)==null?void 0:s.getMiniMapCanvas(n);if(c){const l=c.getContext("2d");if(l){const u=this.viewContainerManager.getView(n);u!=null&&u.focusScenePath&&this.screenshotToCanvas(l,u.focusScenePath,t.width,t.height,t)}}}}async destroyMiniMap(n){var e;(e=this.miniMapManager)==null||e.destroyMiniMap(n)}insertIconify(n,e){var i;if(this.viewContainerManager.getView(n)&&this.room){const r=this.room.state.memberState,s=bt(r.strokeColor[0],r.strokeColor[1],r.strokeColor[2],r.strokeOpacity||1);(i=this.worker)==null||i.insertIconify(n,{...e,strokeColor:s})}}insertBackgroundSVG(n,e){var t;if(!this.isUseBackgroundThread)throw new Error("useBackgroundThread of pluginOptions should be true");(t=this.worker)==null||t.insertBackgroundSVG(n,e)}async insertBackgroundMarkMap(n,e){var t;if(!this.isUseBackgroundThread)throw new Error("useBackgroundThread of pluginOptions should be true");return await((t=this.worker)==null?void 0:t.insertBackgroundMarkMap(n,e))}updateBackgroundMarkMap(n,e,t){var r;const i=this.viewContainerManager.getView(n);if(i&&this.collector&&this.collector.hasTargetDataByViewId(n,e)){const{data:s,scenePath:a}=this.collector.getTargetDataByViewId(n,e);if(!a)throw new Error("updateBackgroundMarkMap scenePath is not exist");const c=i.focusScenePath;if(c&&c!==a)throw new Error("updateBackgroundMarkMap scenePath is not the focus scene path");if(s&&a)(r=this.worker)==null||r.updateBackgroundMarkMap(n,e,t);else throw new Error("updateBackgroundMarkMap data or scenePath is not exist")}}usePlugin(n){var e;return(e=this.pluginManager)==null?void 0:e.use(n)}async stopDraw(n){var t;const e=this.viewContainerManager.getView(n);e&&await((t=e.displayer)==null?void 0:t.stopEventHandler())}async setViewLocalScenePathChange(n,e){this.viewContainerManager.getView(n)&&await this.onSceneChange(e,n)}};I(Fe,"InternalMsgEmitter",new Wn),I(Fe,"PublicMsgEmitter",new Wn);let ye=Fe;var Jn=(o=>(o.Undo="undo",o.Redo="redo",o))(Jn||{});const ue=class ue{createProxy(n,e,t){const i=new Proxy(n,{get(r,s,a){if(typeof s=="string"&&/^\d+$/.test(s))return Reflect.get(r,s,a);const c=ue.interceptors.hasOwnProperty(s)?ue.interceptors:r,l=Reflect.get(c,s,a);return typeof l=="function"&&c===ue.interceptors?l.bind(i):l},set(r,s,a,c){const l=ue.proxyCallbacks.get(c),u=(l==null?void 0:l.arrayType)||"undo";if(s==="length"){const h=r.length,g=[];if(a<h)for(let d=a;d<h;d++)g.push(r[d]);const p=Reflect.set(r,s,a,c);if(l!=null&&l.callback)for(let d=0;d<g.length;d++)l.callback({operation:"delete",index:a+d,oldValue:g[d],arrayType:u});return p}return typeof s=="string"&&/^\d+$/.test(s),Reflect.set(r,s,a,c)},deleteProperty(r,s){const a=ue.proxyCallbacks.get(i),c=(a==null?void 0:a.arrayType)||"undo";if(typeof s=="string"&&/^\d+$/.test(s)){const l=parseInt(s,10),u=r[l],h=Reflect.deleteProperty(r,s);return a!=null&&a.callback&&u!==void 0&&a.callback({operation:"delete",index:l,oldValue:u,arrayType:c}),h}return Reflect.deleteProperty(r,s)}});return ue.proxyToRaw.set(i,n),ue.proxyCallbacks.set(i,{callback:e,arrayType:t}),i}};I(ue,"proxyToRaw",new WeakMap),I(ue,"proxyCallbacks",new WeakMap),I(ue,"interceptors",{entries(...n){return ue.proxyToRaw.get(this).entries(...n)},forEach(...n){return ue.proxyToRaw.get(this).forEach(...n)},map(...n){return ue.proxyToRaw.get(this).map(...n)},filter(...n){return ue.proxyToRaw.get(this).filter(...n)},find(...n){return ue.proxyToRaw.get(this).find(...n)},findIndex(...n){return ue.proxyToRaw.get(this).findIndex(...n)},includes(...n){return ue.proxyToRaw.get(this).includes(...n)},indexOf(...n){return ue.proxyToRaw.get(this).indexOf(...n)},slice(...n){return ue.proxyToRaw.get(this).slice(...n)},concat(...n){return ue.proxyToRaw.get(this).concat(...n)},push(...n){const e=ue.proxyToRaw.get(this),t=this,i=ue.proxyCallbacks.get(t),r=(i==null?void 0:i.arrayType)||"undo",s=e.length,a=e.push(...n);if(i!=null&&i.callback)for(let c=s;c<e.length;c++)i.callback({operation:"add",index:c,newValue:e[c],arrayType:r});return a},customPush(...n){return ue.proxyToRaw.get(this).push(...n)},pop(){const n=ue.proxyToRaw.get(this),e=this,t=ue.proxyCallbacks.get(e),i=(t==null?void 0:t.arrayType)||"undo",r=n.length,s=n[r-1],a=n.pop();return t!=null&&t.callback&&r>0&&t.callback({operation:"delete",index:r-1,oldValue:s,arrayType:i}),a},shift(){const n=ue.proxyToRaw.get(this),e=this,t=ue.proxyCallbacks.get(e),i=(t==null?void 0:t.arrayType)||"undo",r=n[0],s=n.shift();return t!=null&&t.callback&&n.length>0&&t.callback({operation:"delete",index:0,oldValue:r,arrayType:i}),s},unshift(...n){const e=ue.proxyToRaw.get(this),t=this,i=ue.proxyCallbacks.get(t),r=(i==null?void 0:i.arrayType)||"undo",s=e.unshift(...n);if(i!=null&&i.callback)for(let a=0;a<n.length;a++)i.callback({operation:"add",index:a,newValue:e[a],arrayType:r});return s},splice(n,e,...t){const i=ue.proxyToRaw.get(this),r=this,s=ue.proxyCallbacks.get(r),a=(s==null?void 0:s.arrayType)||"undo",c=e??i.length-n,l=i.slice(n,n+c),u=i.splice(n,c,...t);if(s!=null&&s.callback){for(let h=0;h<l.length;h++)s.callback({operation:"delete",index:n+h,oldValue:l[h],arrayType:a});for(let h=0;h<t.length;h++)s.callback({operation:"add",index:n+h,newValue:i[n+h],arrayType:a})}return u},customSplice(n,e,...t){const i=ue.proxyToRaw.get(this),r=e??i.length-n;return i.splice(n,r,...t)},get length(){return ue.proxyToRaw.get(this).length},set length(n){const e=ue.proxyToRaw.get(this),t=this,i=ue.proxyCallbacks.get(t),r=(i==null?void 0:i.arrayType)||"undo",s=e.length,a=[];if(n<s)for(let c=n;c<s;c++)a.push(e[c]);if(e.length=n,i!=null&&i.callback)for(let c=0;c<a.length;c++)i.callback({operation:"delete",index:n+c,oldValue:a[c],arrayType:r})}});let Xn=ue;const _e=class _e{constructor(n){I(this,"emitter",new Wn);I(this,"undoStack");I(this,"redoStack");I(this,"worker");I(this,"control");I(this,"room");I(this,"viewId");I(this,"enableGlobal");I(this,"isTicking");I(this,"_undoTickerId");I(this,"scenePath");I(this,"tickStartStorerCache");I(this,"excludeIds",new Set);I(this,"pendingState",new Map);I(this,"tickStartCaches",new Map);I(this,"tickStartExcludeIds",new Map);I(this,"timingFix");I(this,"ackTimeout");I(this,"gracePeriodTimeout");I(this,"doingFallbackTimeout");I(this,"isGlobalStackTransaction",!1);I(this,"pendingGlobalServiceData");I(this,"pendingArrayChanges",[]);I(this,"onChangeScene",z.debounce(()=>{const n=this.control.viewContainerManager.getCurScenePath(this.viewId);if(n){const e=this.undoStack.filter(i=>i.scenePath===n).length,t=this.redoStack.filter(i=>i.scenePath===n).length;this.emitUndoStepsUpdate(e),this.emitRedoStepsUpdate(t)}},_e.waitTime));const{control:e,internalMsgEmitter:t,viewId:i,enableGlobal:r}=n;this.control=e,this.emitter=t;const s=this.control.pluginOptions.extras.undoRedo;_e.MaxStackLength=s.maxStackLength||we.undoRedo.maxStackLength,this.timingFix=s.timingFix??we.undoRedo.timingFix,this.ackTimeout=s.ackTimeout||we.undoRedo.ackTimeout,this.gracePeriodTimeout=s.gracePeriodTimeout||we.undoRedo.gracePeriodTimeout,this.doingFallbackTimeout=s.doingFallbackTimeout||we.undoRedo.doingFallbackTimeout;const a=new Xn,c=[],l=[];this.undoStack=a.createProxy(c,u=>{this.control.renderControl.isWritable&&this.handleArrayChange(u,je.syncUndoStack)},Jn.Undo),this.redoStack=a.createProxy(l,u=>{this.control.renderControl.isWritable&&this.handleArrayChange(u,je.syncRedoStack)},Jn.Redo),this.room=e.room,this.worker=e.worker,this.isTicking=!1,this.viewId=i,this.enableGlobal=r}reportStackLength(n,e=this.undoStack.length,t=this.redoStack.length){var i,r,s;(s=(r=(i=this.room)==null?void 0:i.logger)==null?void 0:r.info)==null||s.call(r,`[Appliance]: [undo-stack] ${n} viewId=${this.viewId} undoLength=${e} redoLength=${t}`)}emitUndoStepsUpdate(n){this.emitter.emitAsync("onCanUndoStepsUpdate",n,this.viewId)}emitRedoStepsUpdate(n){this.emitter.emitAsync("onCanRedoStepsUpdate",n,this.viewId)}beginGlobalStackTransaction(){this.enableGlobal&&(this.isGlobalStackTransaction=!0)}flushPendingArrayChanges(){if(!this.enableGlobal||!this.pendingArrayChanges.length)return;const n=this.pendingArrayChanges.splice(0);for(const e of n)this.handleArrayChange(e.params,e.operation)}endGlobalStackTransaction(){if(!this.enableGlobal)return;const n=this.pendingGlobalServiceData;this.isGlobalStackTransaction=!1,this.pendingGlobalServiceData=void 0,this.flushPendingArrayChanges(),n&&this.pullServiceData(n)}ackRender(n,e,t){if(!this.timingFix){this.undoTickerEnd(n,e);return}const i=this.pendingState.get(n);!i||i.scenePath!==e||(i.gotRender=!0,this.mergeMeta(i,t),i.finalizeRequested&&(this.armAckTimeout(n,i),this.tryEnd(n)))}ackStorage(n,e,t,i){if(!this.timingFix)return;const r=this.pendingState.get(n);!r||r.scenePath!==e||(t&&(r.scopeMode==="dynamic"||r.finalizeRequested)&&r.ackedStorageKeys.add(t),ym(r.scopeKeys,t)&&r.finalizeRequested&&(r.scopeKeys.size?r.gotStorage=[...r.scopeKeys].every(a=>r.ackedStorageKeys.has(a)):r.gotStorage=!0),this.mergeMeta(r,i),!r.finalizeRequested)||(this.armAckTimeout(n,r),this.tryEnd(n))}collectExpectedWorkIds(n,e,t){const i=this.pendingState.get(n);if(!i||i.scenePath!==e||!t.length)return;Rn(this.collector,this.viewId,e,t).forEach(s=>i.collectedScopeKeys.add(s)),i.scopeMode==="dynamic"&&i.finalizeRequested&&(i.scopeKeys.clear(),i.collectedScopeKeys.forEach(s=>i.scopeKeys.add(s)),i.expectedStorage&&i.scopeKeys.size?i.gotStorage=[...i.scopeKeys].every(s=>i.ackedStorageKeys.has(s)):i.expectedStorage&&!i.scopeKeys.size&&(i.gotStorage=!1),i.ackTimer&&clearTimeout(i.ackTimer),i.ackTimer=void 0,this.armAckTimeout(n,i),this.tryEnd(n))}reopenStorageAck(n,e,t){const i=this.pendingState.get(n);if(!i||i.scenePath!==e||!t.length)return;const r=Rn(this.collector,this.viewId,e,t);r.size&&(r.forEach(s=>i.ackedStorageKeys.delete(s)),i.finalizeRequested&&(i.expectedStorage&&i.scopeKeys.size?i.gotStorage=[...i.scopeKeys].every(s=>i.ackedStorageKeys.has(s)):i.expectedStorage&&!i.scopeKeys.size&&(i.gotStorage=i.scopeMode==="static"),i.ackTimer&&clearTimeout(i.ackTimer),i.ackTimer=void 0,this.armAckTimeout(n,i)))}finalizeRequested(n,e,t){const i=this.pendingState.get(n);if(!i||i.scenePath!==e)return;const r=Rn(this.collector,this.viewId,e,t);i.scopeMode==="dynamic"?(r.forEach(s=>i.collectedScopeKeys.add(s)),i.scopeKeys.clear(),i.collectedScopeKeys.forEach(s=>i.scopeKeys.add(s))):r.forEach(s=>i.scopeKeys.add(s)),i.finalizeRequested=!0,i.expectedStorage&&i.scopeKeys.size?i.gotStorage=[...i.scopeKeys].every(s=>i.ackedStorageKeys.has(s)):i.expectedStorage&&!i.scopeKeys.size&&i.scopeMode==="static"?i.gotStorage=!0:i.expectedStorage&&!i.scopeKeys.size&&i.scopeMode==="dynamic"&&(i.gotStorage=!1),this.armAckTimeout(n,i),this.tryEnd(n)}mergeMeta(n,e){fm(n,e)}armAckTimeout(n,e){e.finalizeRequested&&Mm(e)&&(e.ackTimer=setTimeout(()=>{this.forceFlushPending(n)},this.ackTimeout))}tryEnd(n){const e=this.pendingState.get(n);if(!e||!pm(e))return;const t=e.meta;this.undoTickerEndSync(n,e.viewId,e.scenePath,!0),t.copyAck&&t.emitEventType&&t.requestId&&this.emitter.emit("undoAckApplied",{viewId:e.viewId,scenePath:e.scenePath,requestId:t.requestId,emitEventType:t.emitEventType}),t.isWritable&&this.worker.abled()}forceFlushPending(n){const e=this.pendingState.get(n);e&&(e.gotRender=e.expectedRender,e.gotStorage=e.expectedStorage,this.tryEnd(n))}hasAnyAck(n){return n.gotRender||n.gotStorage||n.ackedStorageKeys.size>0||!!n.ackTimer}clearPendingState(n){const e=this.pendingState.get(n);e&&(e.ackTimer&&clearTimeout(e.ackTimer),e.graceTimer&&clearTimeout(e.graceTimer),e.fallbackTimer&&clearTimeout(e.fallbackTimer),this.pendingState.delete(n)),this.tickStartCaches.delete(n),this.tickStartExcludeIds.delete(n)}cancelUndoTicker(n,e,t){const i=this.pendingState.has(n),r=this.undoTickerId===n&&this.viewId===e&&this.scenePath===t;!i&&!r||(r&&(this.isTicking=!1,this.scenePath=void 0,this.tickStartStorerCache=void 0,this._undoTickerId=void 0,this.excludeIds.clear()),this.clearPendingState(n))}getStartCache(n){return this.tickStartCaches.get(n)||this.tickStartStorerCache}getExcludeIds(n){return this.tickStartExcludeIds.get(n)||this.excludeIds}resetLegacyTicker(){this.isTicking=!1,this.scenePath=void 0,this.tickStartStorerCache=void 0,this._undoTickerId=void 0,this.excludeIds.clear()}handleArrayChange(n,e){if(!this.collector||!this.enableGlobal){this.collector;return}if(this.isGlobalStackTransaction){this.pendingArrayChanges.push({operation:e,params:{...n}});return}const{operation:t,oldValue:i,newValue:r}=n;let s,a;t==="delete"&&i?(s=i,a=i.id):t==="add"&&r&&(s=r,a=r.id),s&&a&&this.collector.dispatchUndoTicker({operation:e,syncType:t,viewId:this.viewId,undoTickerId:a,data:s})}get collector(){return this.control.collector}get undoTickerId(){return this._undoTickerId}get tmpTickStartStorerCache(){return this.tickStartStorerCache}get uid(){var n;return((n=this.control.collector)==null?void 0:n.uid)||""}addExcludeIds(n){const e=this.undoTickerId!==void 0?this.pendingState.get(this.undoTickerId):void 0;if(!(this.timingFix&&(e!=null&&e.scopeKeys.size))){if(this.timingFix&&this.undoTickerId!==void 0){const t=this.tickStartExcludeIds.get(this.undoTickerId);if(t)for(const i of n)t.add(i);return}if(this.isTicking)for(const t of n)this.excludeIds.add(t)}}undoTickerStart(n,e,t){var i,r,s;if(!this.timingFix){this.legacyUndoTickerStart(n,e);return}if(!t)throw new Error("[appliance-plugin] addUndoTicker expectedAcks is required");if(this.collector&&(this.undoTickerId!==n||this.scenePath!==e)){if(this.undoTickerId&&this.viewId&&this.scenePath){const g=this.undoTickerId,p=this.pendingState.get(g);p&&!this.hasAnyAck(p)?this.clearPendingState(g):p&&!p.graceTimer?p.graceTimer=setTimeout(()=>{this.forceFlushPending(g)},this.gracePeriodTimeout):p||this.undoTickerEndSync(g,this.viewId,this.scenePath)}this.isTicking=!0;const a=this.collector.transformKey(Z);this.excludeIds.add(a),this._undoTickerId=n,this.scenePath=e;const c=((i=this.collector)==null?void 0:i.storage[this.viewId])&&((r=this.collector)==null?void 0:r.storage[this.viewId][this.scenePath])||{},l=new Map(Object.entries(z.cloneDeep(c))),u=new Set([a]);this.tickStartStorerCache=l,this.tickStartCaches.set(n,l),this.tickStartExcludeIds.set(n,u);const h=setTimeout(()=>{this.forceFlushPending(n)},this.doingFallbackTimeout);this.pendingState.set(n,gm({viewId:this.viewId,scenePath:e,expectedAcks:t,fallbackTimer:h})),(s=t.workIds)!=null&&s.length&&this.finalizeRequested(n,e,t.workIds.map(String))}}legacyUndoTickerStart(n,e){var t,i;if(this.collector&&(this.undoTickerId!==n||this.scenePath!==e)){this.undoTickerId&&this.viewId&&this.scenePath&&this.undoTickerEndSync(this.undoTickerId,this.viewId,this.scenePath),this.isTicking=!0;const r=this.collector.transformKey(Z);this.excludeIds.add(r),this._undoTickerId=n,this.scenePath=e;const s=((t=this.collector)==null?void 0:t.storage[this.viewId])&&((i=this.collector)==null?void 0:i.storage[this.viewId][this.scenePath])||{};this.tickStartStorerCache=new Map(Object.entries(z.cloneDeep(s)))}}undoTickerEnd(n,e,t){if(this.timingFix){this.forceFlushPending(n);return}this.undoTickerId&&n===this.undoTickerId&&e===this.scenePath?this.undoTickerEndSync(n,this.viewId,e,!0,t):this.resetLegacyTicker()}undoTickerEndSync(n,e,t,i=!0,r){var c,l;if(r&&r.length)for(const u of r)this.excludeIds.delete(u);const s=n===this.undoTickerId&&e===this.viewId&&t===this.scenePath,a=this.pendingState.has(n)&&e===this.viewId&&!!this.getStartCache(n);if((s||a)&&this.getStartCache(n)){const u=((c=this.collector)==null?void 0:c.storage[e])&&((l=this.collector)==null?void 0:l.storage[e][t])||{},h=this.pendingState.get(n),g=this.diffFun(this.getStartCache(n),new Map(Object.entries(u)),!0,this.getExcludeIds(n),h==null?void 0:h.scopeKeys);g.size&&(this.undoStack.push({id:`${n}-${this.uid}`,data:z.cloneDeep(g),scenePath:t}),this.undoStack.length>_e.MaxStackLength&&this.undoStack.shift(),i&&this.emitUndoStepsUpdate(this.undoStack.length),this.redoStack.length&&(this.redoStack.length=0,i&&this.emitRedoStepsUpdate(this.redoStack.length))),s&&(this.isTicking=!1,this.scenePath=void 0,this.tickStartStorerCache=void 0,this._undoTickerId=void 0,this.excludeIds.clear()),this.clearPendingState(n),this.reportStackLength("undo-ticker-end")}}transformToUndoStackItem(n){const e=[];for(const[t,i]of Object.entries(n)){if(!(i!=null&&i.data))continue;const r=new Set;for(const[s,a]of Object.entries(i.data))r.add({key:s,dataType:a.dataType,data:a.data});e.push({id:t,scenePath:i.scenePath,data:r})}return e}pullServiceData(n){if(this.enableGlobal&&this.isGlobalStackTransaction){this.pendingGlobalServiceData=n;return}if(n){const{undoStack:e,redoStack:t}=n;if(e){const i=this.transformToUndoStackItem(e);for(let r=this.undoStack.length-1;r>=0;r--){const s=this.undoStack[r];i.findIndex(c=>c.id===s.id)===-1&&this.undoStack.customSplice(r,1)}for(const r of i){const s=this.undoStack.findIndex(a=>a.id===r.id);s!==-1?this.undoStack[s]=r:this.undoStack.customPush(r)}this.undoStack.sort((r,s)=>{const a=parseInt(r.id.split("-")[0]),c=parseInt(s.id.split("-")[0]);return a-c}),this.emitUndoStepsUpdate(this.undoStack.length)}if(t){const i=this.transformToUndoStackItem(t);for(let r=this.redoStack.length-1;r>=0;r--){const s=this.redoStack[r];i.findIndex(c=>c.id===s.id)===-1&&this.redoStack.customSplice(r,1)}for(const r of i){const s=this.redoStack.findIndex(a=>a.id===r.id);s!==-1?this.redoStack[s]=r:this.redoStack.customPush(r)}this.redoStack.sort((r,s)=>{const a=parseInt(r.id.split("-")[0]);return parseInt(s.id.split("-")[0])-a}),this.emitRedoStepsUpdate(this.redoStack.length)}}else this.clear()}undo(n){var t,i;let e;this.beginGlobalStackTransaction();try{if(this.undoTickerId&&this.tickStartStorerCache&&this.scenePath){const a=this.undoTickerId;this.timingFix&&this.forceFlushPending(a)}if(this.undoTickerId&&this.tickStartStorerCache&&this.scenePath){const a=this.undoTickerId,c=this.scenePath,l=this.getStartCache(a),u=this.pendingState.get(a);if(!l)return this.resetLegacyTicker(),this.undo(n);const h=((t=this.collector)==null?void 0:t.storage[this.viewId])&&((i=this.collector)==null?void 0:i.storage[this.viewId][c])||{},g=this.diffFun(l,new Map(Object.entries(h)),!1,this.getExcludeIds(a),u==null?void 0:u.scopeKeys),p=this.diffFun(l,new Map(Object.entries(h)),!0,this.getExcludeIds(a),u==null?void 0:u.scopeKeys);g.size===p.size?(this.undoStack.push({id:`${a}-${this.uid}`,data:z.cloneDeep(g),scenePath:c}),this.undoStack.length>_e.MaxStackLength&&this.undoStack.shift()):g.size&&!p.size&&(e={id:`${a}-${this.uid}`,data:z.cloneDeep(g),scenePath:c}),this.isTicking=!1,this.scenePath=void 0,this.tickStartStorerCache=void 0,this._undoTickerId=void 0,this.excludeIds.clear(),this.clearPendingState(a)}if(e)this.refreshPlugin(e);else{let a=this.undoStack.length-1;for(;a>=0;){const c=this.undoStack[a];if(c.scenePath===n){const l=c.id;c&&(this.redoStack.push(c),c.data&&this.refreshPlugin(c));const u=this.undoStack.findIndex(h=>h.id===l);u!==-1&&this.undoStack.splice(u,1);break}a--}}const r=this.undoStack.filter(a=>a.scenePath===n).length,s=this.redoStack.filter(a=>a.scenePath===n).length;return this.emitUndoStepsUpdate(r),this.emitRedoStepsUpdate(s),this.reportStackLength("undo-final",r,s),r}finally{this.endGlobalStackTransaction()}}redo(n){this.beginGlobalStackTransaction();try{let e=this.redoStack.length-1;for(;e>=0;){const r=this.redoStack[e];if(r.scenePath===n){const s=r.id;r&&(this.undoStack.push(r),r.data&&this.refreshPlugin(r,!0));const a=this.redoStack.findIndex(c=>c.id===s);a!==-1&&this.redoStack.splice(a,1);break}e--}const t=this.undoStack.filter(r=>r.scenePath===n).length,i=this.redoStack.filter(r=>r.scenePath===n).length;return this.emitUndoStepsUpdate(t),this.emitRedoStepsUpdate(i),this.reportStackLength("redo-final",t,i),i}finally{this.endGlobalStackTransaction()}}clear(){this.clearUndo(),this.clearRedo()}clearUndo(){this.undoStack.length=0,this.emitUndoStepsUpdate(this.undoStack.length)}clearRedo(){this.redoStack.length=0,this.emitRedoStepsUpdate(this.redoStack.length)}canUndo(){return!!this.undoStack.length}canRedo(){return!!this.redoStack.length}onFocusView(){const n=this.control.viewContainerManager.getCurScenePath(this.viewId);if(n){const e=this.undoStack.filter(i=>i.scenePath===n).length,t=this.redoStack.filter(i=>i.scenePath===n).length;this.emitUndoStepsUpdate(e),this.emitRedoStepsUpdate(t)}}especialDiff(n,e,t,i){if(e===Ue.Update)switch(t==null?void 0:t.toolsType){case T.Text:{if(i!=null&&i.opt&&(t!=null&&t.opt)){const s=z.omit(i.opt,["uid","workState"]),a=z.omit(t.opt,["uid","workState"]);if(n&&z.isEqual(s,a))return!0;i.opt.workState!==E.Done&&(i.opt.workState=E.Done),t.opt.workState!==E.Done&&(t.opt.workState=E.Done)}break}}else if(e===Ue.Draw||e===Ue.Delete)switch(t==null?void 0:t.toolsType){case T.Text:{if(t!=null&&t.opt){const s=t.opt.text;if(n&&!s)return!0;t.opt.workState!==E.Done&&(t.opt.workState=E.Done)}break}}return!1}normalizeUndoSnapshotValue(n,e){var r,s,a;if(!e)return e;const t=z.cloneDeep(e);if(((s=(r=this.collector)==null?void 0:r.getLocalId)==null?void 0:s.call(r,n))===Z||t.toolsType===T.Selector)return;if(t.toolsType===T.Text)return((a=t.opt)==null?void 0:a.workState)!==E.Done&&(t.opt.workState=E.Done),t;const i=new Set([T.Pencil,T.Arrow,T.Straight,T.Rectangle,T.Ellipse,T.Polygon,T.Star,T.SpeechBalloon]);return t.type===W.DrawWork&&i.has(t.toolsType)&&!t.ops&&Array.isArray(t.op)&&t.op.length&&(t.type=W.FullWork,t.ops=St(t.op)),t}getTextDebugOpt(n){var t;if(!n||n.toolsType!==T.Text)return;const e=n.opt;return{workState:e==null?void 0:e.workState,boxSize:e==null?void 0:e.boxSize,textLength:(t=e==null?void 0:e.text)==null?void 0:t.length}}diffFun(n,e,t=!0,i=this.excludeIds,r){const s=new Set,a=n.keys(),c=e.keys();for(const l of a){if(!Mr(l,i,r))continue;const u=this.normalizeUndoSnapshotValue(l,n.get(l)),h=this.normalizeUndoSnapshotValue(l,e.get(l));if(!(!u&&!h)){if(u&&h){if(z.isEqual(h,u)||this.especialDiff(t,Ue.Update,h,u))continue;s.add({dataType:Ue.Update,key:l,data:[u,h]});continue}this.especialDiff(t,Ue.Delete,u)||u&&s.add({dataType:Ue.Delete,key:l,data:u})}}for(const l of c){if(!Mr(l,i,r))continue;const u=this.normalizeUndoSnapshotValue(l,e.get(l));if(u&&!n.has(l)){if(this.especialDiff(t,Ue.Draw,u))continue;s.add({dataType:Ue.Draw,key:l,data:u})}}return s}isDrawEffectiveScene(n,e){const{key:t}=n;return!e.includes(t)}isDeleteEffectiveScene(n,e){const{key:t}=n;return!!e.includes(t)}isOldEffectiveScene(n,e){const{key:t}=n;return!!e.includes(t)}isNewEffectiveScene(n,e){const{key:t}=n;return!!e.includes(t)}refreshPlugin(n,e=!1){var l,u,h,g,p,d,M,w,m,y,S,v,k,C,x,O,Y;let t;const{scenePath:i}=n,r=n.data;if(!r||!this.collector)return;console.info("[appliance-plugin]",{target:"text-box.undo-refresh.begin",scenePath:i,isRedo:e,diffSize:r.size,textItems:[...r.values()].filter(A=>{var b,N,D;return A.dataType===Ue.Update&&Array.isArray(A.data)?((b=A.data[0])==null?void 0:b.toolsType)===T.Text||((N=A.data[1])==null?void 0:N.toolsType)===T.Text:!Array.isArray(A.data)&&((D=A.data)==null?void 0:D.toolsType)===T.Text}).map(A=>({key:A.key,dataType:A.dataType,data:Array.isArray(A.data)?A.data.map(b=>this.getTextDebugOpt(b)):this.getTextDebugOpt(A.data)}))});const a={...this.collector.getStorageData(this.viewId,i)||{}};let c=!1;for(const A of r.values()){const{dataType:b,data:N,key:D}=A,j=this.collector.getStorageData(this.viewId,i),B=j&&Object.keys(j)||[];switch(b){case Ue.Draw:if(t=e?this.isDrawEffectiveScene(A,B):this.isDeleteEffectiveScene(A,B),t)if(e&&!Array.isArray(N)){if((l=N.updateNodeOpt)!=null&&l.useAnimation&&(N.updateNodeOpt.useAnimation=!1),((u=this.collector)==null?void 0:u.getLocalId(D))===Z&&((h=this.collector)!=null&&h.isOwn(A.key))){const V=N.selectIds;if(V){const U=B.filter(G=>{var $,X;return(($=this.collector)==null?void 0:$.getLocalId(G))===Z&&!((X=this.collector)!=null&&X.isOwn(G))}).map(G=>{var $;return($=this.collector)==null?void 0:$.storage[this.viewId][i][G]});let H=!1;for(const G of U)for(let $=0;$<V.length;$++)(g=G==null?void 0:G.selectIds)!=null&&g.includes(V[$])&&(delete V[$],H=!0);H&&(N.selectIds=V.filter(G=>!!G))}}a[A.key]=N,c=!0}else!e&&!Array.isArray(A.data)&&(delete a[A.key],c=!0);break;case Ue.Delete:if(t=e?this.isDeleteEffectiveScene(A,B):this.isDrawEffectiveScene(A,B),t){if(e&&!Array.isArray(N))delete a[D],c=!0;else if(!e&&!Array.isArray(N)){if((p=N.updateNodeOpt)!=null&&p.useAnimation&&(N.updateNodeOpt.useAnimation=!1),((d=this.collector)==null?void 0:d.getLocalId(A.key))===Z&&((M=this.collector)!=null&&M.isOwn(A.key))){const V=N.selectIds;if(V){const U=B.filter(G=>{var $,X;return(($=this.collector)==null?void 0:$.getLocalId(G))===Z&&!((X=this.collector)!=null&&X.isOwn(G))}).map(G=>{var $;return($=this.collector)==null?void 0:$.storage[this.viewId][i][G]});let H=!1;for(const G of U)for(let $=0;$<V.length;$++)(w=G==null?void 0:G.selectIds)!=null&&w.includes(V[$])&&(delete V[$],H=!0);H&&(N.selectIds=V.filter(G=>!!G))}}a[A.key]=N,c=!0}}break;case Ue.Update:if(t=e?this.isNewEffectiveScene(A,B):this.isOldEffectiveScene(A,B),t){if(e&&Array.isArray(N)&&N.length===2){const V=N[1];if((m=V.updateNodeOpt)!=null&&m.useAnimation&&(V.updateNodeOpt.useAnimation=!1),((y=this.collector)==null?void 0:y.getLocalId(A.key))===Z&&((S=this.collector)!=null&&S.isOwn(A.key))){const U=V.selectIds;if(U){const H=B.filter($=>{var X,Te;return((X=this.collector)==null?void 0:X.getLocalId($))===Z&&!((Te=this.collector)!=null&&Te.isOwn($))}).map($=>{var X;return(X=this.collector)==null?void 0:X.storage[this.viewId][i][$]});let G=!1;for(const $ of H)for(let X=0;X<U.length;X++)$!=null&&$.selectIds&&((v=$.selectIds)!=null&&v.includes(U[X]))&&(delete U[X],G=!0);G&&(V.selectIds=U.filter($=>!!$))}}a[D]=V,c=!0}else if(!e&&Array.isArray(N)&&N.length===2){const V=N[0];if((k=V.updateNodeOpt)!=null&&k.useAnimation&&(V.updateNodeOpt.useAnimation=!1),((C=this.collector)==null?void 0:C.getLocalId(A.key))===Z&&((x=this.collector)!=null&&x.isOwn(A.key))){const U=V.selectIds;if(U){const H=B.filter($=>{var X,Te;return((X=this.collector)==null?void 0:X.getLocalId($))===Z&&!((Te=this.collector)!=null&&Te.isOwn($))}).map($=>{var X;return(X=this.collector)==null?void 0:X.storage[this.viewId][i][$]});let G=!1;for(const $ of H)for(let X=0;X<U.length;X++)$!=null&&$.selectIds&&$.selectIds.includes(U[X])&&(delete U[X],G=!0);G&&(V.selectIds=U.filter($=>!!$))}}a[A.key]=V,c=!0}}break}}if(c){console.info("[appliance-plugin]",{target:"text-box.undo-refresh.applyScene",scenePath:i,isRedo:e,textEntries:Object.entries(a).filter(([,D])=>(D==null?void 0:D.toolsType)===T.Text).map(([D,j])=>({key:D,...this.getTextDebugOpt(j)}))});const A=this.collector.plugin,b=(O=A==null?void 0:A.getAttributesValue)==null?void 0:O.call(A,[et.namespace]),N=(Y=A==null?void 0:A.getAttributesValue)==null?void 0:Y.call(A,[et.namespace,this.viewId]);b?N?A==null||A.updateAttributes([et.namespace,this.viewId,i],a):A==null||A.updateAttributes([et.namespace,this.viewId],{[i]:a}):A==null||A.updateAttributes([et.namespace],{[this.viewId]:{[i]:a}})}}};I(_e,"sdkCallBack"),I(_e,"MaxStackLength",we.undoRedo.maxStackLength),I(_e,"waitTime",100);let _n=_e;class Lt{constructor(n){I(this,"internalMsgEmitter");I(this,"control");I(this,"mainView");I(this,"appViews",new Map);I(this,"undoTickerStart",(n,e,t)=>{const i=this.getView(e);i&&i.displayer&&i.focusScenePath&&i.displayer.commiter.undoTickerStart(n,i.focusScenePath,t)});I(this,"addExcludeIds",(n,e)=>{const t=this.getView(e);t&&t.displayer&&t.focusScenePath&&t.displayer.commiter.addExcludeIds(n)});I(this,"onAckRenderUndoTicker",(n,e,t,i)=>{const r=this.getView(e);if(!(r!=null&&r.displayer)||!r.focusScenePath)return;const s=t||r.focusScenePath;r.displayer.commiter.ackRender(n,s,i)});I(this,"onAckStorageUndoTicker",(n,e,t,i,r)=>{const s=this.getView(e);if(!(s!=null&&s.displayer)||!s.focusScenePath)return;const a=t||s.focusScenePath;s.displayer.commiter.ackStorage(n,a,i,r)});I(this,"onCollectExpectedWorkIds",(n,e,t,i)=>{const r=this.getView(e);if(!(r!=null&&r.displayer)||!r.focusScenePath)return;const s=i||r.focusScenePath;r.displayer.commiter.collectExpectedWorkIds(n,s,t)});I(this,"onFinalizeRequested",(n,e,t,i)=>{const r=this.getView(e);if(!(r!=null&&r.displayer)||!r.focusScenePath)return;const s=i||r.focusScenePath;r.displayer.commiter.finalizeRequested(n,s,t)});I(this,"onReopenStorageAck",(n,e,t,i)=>{const r=this.getView(e);if(!(r!=null&&r.displayer)||!r.focusScenePath)return;const s=i||r.focusScenePath;r.displayer.commiter.reopenStorageAck(n,s,t)});I(this,"onCancelUndoTicker",(n,e,t)=>{const i=this.getView(e);if(!(i!=null&&i.displayer)||!i.focusScenePath)return;const r=t||i.focusScenePath;i.displayer.commiter.cancelUndoTicker(n,e,r)});const{control:e,internalMsgEmitter:t}=n;this.control=e,this.internalMsgEmitter=t,this.internalMsgEmitter.on("addUndoTicker",this.undoTickerStart),this.internalMsgEmitter.on("excludeIds",this.addExcludeIds),this.internalMsgEmitter.on("ackRenderUndoTicker",this.onAckRenderUndoTicker),this.internalMsgEmitter.on("ackStorageUndoTicker",this.onAckStorageUndoTicker),this.internalMsgEmitter.on("collectExpectedWorkIds",this.onCollectExpectedWorkIds),this.internalMsgEmitter.on("reopenStorageAck",this.onReopenStorageAck),this.internalMsgEmitter.on("finalizeRequested",this.onFinalizeRequested),this.internalMsgEmitter.on("cancelUndoTicker",this.onCancelUndoTicker)}get worker(){return this.control.worker}getUndoTickerId(n){const e=this.getView(n);if(e&&e.displayer&&e.focusScenePath)return e.displayer.commiter.undoTickerId}undo(){const n=this.focuedView;let e=0;if(n){const t=n.focusScenePath;e=n.displayer.commiter.undo(t)||0}return e}redo(){const n=this.focuedView;let e=0;if(n){const t=n.focusScenePath;e=n.displayer.commiter.redo(t)||0}return e}validator(n,e,t){var s;const i=z.clone(n[e]),r=z.clone(t);e==="focusScenePath"&&t&&!z.isEqual(i,r)&&(this.control.internalSceneChange(n.id,r),(s=this.focuedView)==null||s.displayer.commiter.onChangeScene()),e==="cameraOpt"&&!z.isEqual(i,r)&&this.control.internalCameraChange(n.id,r)}destroyAppView(n,e=!1){const t=this.appViews.get(n);t&&(this.control.textEditorManager.clear(n,e),t.displayer.destroy(),this.appViews.delete(n))}createMianView(n){this.mainView=new Proxy(n,{set:(e,t,i)=>(this.worker.isActive&&this.validator(e,t,i),e[t]=i,!0)})}createAppView(n){const e=n.id,t=new Proxy(n,{set:(i,r,s)=>(this.worker.isActive&&this.validator(i,r,s),i[r]=s,!0)});this.appViews.set(e,t)}isAppView(n){return n!==ie&&this.appViews.has(n)}getView(n){var e;return n===ie?this.mainView:(e=this.appViews)==null?void 0:e.get(n)}resolveView(n){const e=n||this.focuedViewId||ie,t=this.getView(e);return!n&&!t&&e!==ie?{viewId:ie,view:this.getView(ie)}:{viewId:e,view:t}}getViewElement(n){var e;return((e=n.viewData)==null?void 0:e.divElement)||n.container||n.displayer.eventTragetElement}getFloatbarContainer(n){const{view:e}=this.resolveView(n);return(e==null?void 0:e.displayer.customFloatbarContainerRef.current)||void 0}getViewOffsetToContainer(n,e){if(!n)return;const{viewId:t,view:i}=this.resolveView(e);if(!i)return;const r=this.getViewElement(i);if(!r)return;const s=r.getBoundingClientRect(),a=n.getBoundingClientRect();return{x:s.left-a.left,y:s.top-a.top,viewId:t}}getCurScenePath(n){const e=this.getView(n);if(e)return e.focusScenePath}getAllViews(){return[this.mainView,...this.appViews.values()]}setViewScenePath(n,e){var t;if(n===ie&&this.mainView)this.mainView.focusScenePath=e;else{const i=n&&((t=this.appViews)==null?void 0:t.get(n))||void 0;i&&(i.focusScenePath=e)}}setViewData(n,e){var t;if(n===ie&&this.mainView)this.mainView.viewData=e;else{const i=n&&((t=this.appViews)==null?void 0:t.get(n))||void 0;i&&(i.viewData=e)}}setFocuedViewId(n){var e;this.focuedViewId=n,n===ie?this.focuedView=this.mainView:this.focuedView=n&&((e=this.appViews)==null?void 0:e.get(n))||void 0,this.worker.currentToolsData&&this.worker.currentToolsData.toolsType===T.Text&&this.activeTextEditor(n),this.control.cursor.onFocusViewChange(),this.focuedView&&this.focuedView.displayer.commiter.onFocusView()}setViewFocusScenePath(n,e){var i;let t;n===ie?t=this.mainView:t=(i=this.appViews)==null?void 0:i.get(n),t&&(t.focusScenePath=e)}destroy(){var n;this.internalMsgEmitter.off("addUndoTicker",this.undoTickerStart),this.internalMsgEmitter.off("excludeIds",this.addExcludeIds),this.internalMsgEmitter.off("ackRenderUndoTicker",this.onAckRenderUndoTicker),this.internalMsgEmitter.off("ackStorageUndoTicker",this.onAckStorageUndoTicker),this.internalMsgEmitter.off("collectExpectedWorkIds",this.onCollectExpectedWorkIds),this.internalMsgEmitter.off("reopenStorageAck",this.onReopenStorageAck),this.internalMsgEmitter.off("finalizeRequested",this.onFinalizeRequested),this.internalMsgEmitter.off("cancelUndoTicker",this.onCancelUndoTicker),(n=this.mainView)==null||n.displayer.destroy(),this.control.destroyMiniMap(ie),this.appViews.forEach(e=>{this.destroyAppView(e.id,!0),this.worker.destroyViewWorker(e.id),this.control.destroyMiniMap(e.id)})}setFocuedViewCameraOpt(n){if(this.focuedView){const e=this.focuedView.cameraOpt;z.isEqual(e,n)||(this.focuedView.cameraOpt=n)}}transformToOriginPoint(n,e){const t=this.getView(e);if(t!=null&&t.viewData){const i=t.viewData.convertToPointOnScreen(n[0],n[1]);return[i.x,i.y]}return n}transformToScenePoint(n,e){const t=this.getView(e);if(t!=null&&t.viewData){const i=t.viewData.convertToPointInWorld({x:n[0],y:n[1]});return[i.x,i.y]}return n}render(n){var e,t,i,r,s,a,c,l,u,h,g,p,d,M,w,m,y;for(const S of n){const{rect:v,imageBitmap:k,isClear:C,isUnClose:x,drawCanvas:O,clearCanvas:Y,viewId:A}=S,b=(e=this.getView(A))==null?void 0:e.displayer;if(b&&v){const{dpr:N,canvasBgRef:D,canvasFloatRef:j,canvasServiceFloatRef:B,canvasTopRef:V}=b,U=Math.floor(v.w*N),H=Math.floor(v.h*N),G=v.x*N,$=v.y*N;if(C){switch(Y){case Ze.TopFloat:(i=(t=V==null?void 0:V.current)==null?void 0:t.getContext("2d"))==null||i.clearRect(G,$,U,H);break;case Ze.Float:(s=(r=j.current)==null?void 0:r.getContext("2d"))==null||s.clearRect(G,$,U,H);break;case Ze.ServiceFloat:(c=(a=B.current)==null?void 0:a.getContext("2d"))==null||c.clearRect(G,$,U,H);break;case Ze.Bg:(u=(l=D.current)==null?void 0:l.getContext("2d"))==null||u.clearRect(G,$,U,H);break}continue}if(O&&k)switch(O){case Ze.TopFloat:(g=(h=V==null?void 0:V.current)==null?void 0:h.getContext("2d"))==null||g.drawImage(k,0,0,U,H,G,$,U,H);break;case Ze.Float:{(d=(p=j.current)==null?void 0:p.getContext("2d"))==null||d.drawImage(k,0,0,U,H,G,$,U,H);break}case Ze.ServiceFloat:{(w=(M=B.current)==null?void 0:M.getContext("2d"))==null||w.drawImage(k,0,0,U,H,G,$,U,H);break}case Ze.Bg:{(y=(m=D.current)==null?void 0:m.getContext("2d"))==null||y.drawImage(k,0,0,U,H,G,$,U,H);break}}if(x)continue;k==null||k.close()}}}showFloatBar(n,e,t){const i=this.getView(n),r=i==null?void 0:i.displayer.vDom;r&&r.showFloatBar(e,t)}activeTextEditor(n){const e=this.getView(n),t=e==null?void 0:e.displayer.vDom;t&&t.activeTextEditor()}unActiveTextEditor(n){const e=this.getView(n),t=e==null?void 0:e.displayer.vDom;t&&t.unActiveTextEditor()}showFloatBarBtn(n,e){const t=this.getView(n),i=t==null?void 0:t.displayer.vDom;i&&i.showFloatBarBtn(e)}updateTextEditorInfo(n,e){const t=this.getView(n),i=t==null?void 0:t.displayer.vDom;i&&i.updateTextEditorInfo(e)}setActiveMiniMap(n,e){const t=this.getView(n),i=t==null?void 0:t.displayer.vDom;i&&i.setActiveMiniMap(e&&n||void 0)}}I(Lt,"defaultCameraOpt",{centerX:0,centerY:0,scale:1}),I(Lt,"defaultScreenCanvasOpt",{autoRender:!1,contextType:"2d"}),I(Lt,"defaultLayerOpt",{offscreen:!0,handleEvent:!1,depth:!1});class wo{constructor(n,e,t){I(this,"control");I(this,"internalMsgEmitter");I(this,"commiter");I(this,"cachePoint");I(this,"cacheCursorPoint");I(this,"active",!0);I(this,"toolsKey");I(this,"activePointers",new Set);I(this,"currentDrawingPointerId");I(this,"cursorMouseMove");I(this,"cursorMouseMoveDebounced");I(this,"cursorMouseMoveThrottled");I(this,"cursorMouseMoveFun");I(this,"_transferControlToOffscreenCanvas");I(this,"cursorMouseLeave",()=>{this.control.pluginOptions.extras.cursor.enable?this.cursorMouseMoveThrottled.cancel():this.cursorMouseMoveDebounced.cancel(),this.cacheCursorPoint=[void 0,void 0],this.worker.sendCursorEvent(this.cacheCursorPoint,this.viewId)});I(this,"keydown",n=>{n.stopPropagation(),n.stopImmediatePropagation(),this.control.hotkeyManager.colloctHotkey(n)});I(this,"pointerdown",n=>{var e;if(this.active){if(n.pointerType==="touch"&&(this.activePointers.add(n.pointerId),this.activePointers.size>1)){this.worker.unWritable(),this.viewId&&this.worker.removeDrawingWork(this.viewId),document.removeEventListener("pointermove",this.pointermove,!1),document.removeEventListener("pointerup",this.pointerup,!1),document.removeEventListener("pointercancel",this.pointerup,!1),this.currentDrawingPointerId=void 0,this.cachePoint=void 0,this.activePointers.clear();return}if(n.button===0&&this.viewId){this.toolsKey=(e=this.worker.getCurrentToolsData())==null?void 0:e.toolsType,!this.worker.isAbled()&&this.toolsKey&&this.control.effectViewContainer(this.toolsKey),this.worker.checkDrawingWork(this.viewId),this.reflashContainerOffset();const t=this.getPoint(n);this.cachePoint=t,t&&(this.currentDrawingPointerId=n.pointerId,this.worker.originalEventLintener(E.Start,t,this.viewId),document.addEventListener("pointermove",this.pointermove,!1),document.addEventListener("pointerup",this.pointerup,!1),document.addEventListener("pointercancel",this.pointerup,!1))}}});I(this,"pointermove",n=>{if(this.active){if(n.pointerType==="touch"){if(this.activePointers.size>1){this.worker.unWritable(),this.worker.removeDrawingWork(this.viewId);return}if(this.currentDrawingPointerId!==void 0&&n.pointerId!==this.currentDrawingPointerId)return;if(!this.worker.isAbled()){this.worker.unWritable(),this.worker.removeDrawingWork(this.viewId);return}}if(this.viewId){const e=this.getPoint(n);if(this.cachePoint=e,this.checkConsumeCount())return;e&&this.worker.originalEventLintener(E.Doing,e,this.viewId)}}});I(this,"pointerup",n=>{if(this.active&&(n.pointerType==="touch"&&this.activePointers.delete(n.pointerId),!(this.currentDrawingPointerId!==void 0&&n.pointerId!==this.currentDrawingPointerId))){if(this.currentDrawingPointerId===void 0){document.removeEventListener("pointermove",this.pointermove,!1),document.removeEventListener("pointerup",this.pointerup,!1),document.removeEventListener("pointercancel",this.pointerup,!1);return}if(n.pointerType==="touch"&&(this.activePointers.size>0||!this.worker.isAbled())){this.worker.unWritable(),this.worker.removeDrawingWork(this.viewId),document.removeEventListener("pointermove",this.pointermove,!1),document.removeEventListener("pointerup",this.pointerup,!1),document.removeEventListener("pointercancel",this.pointerup,!1),this.cachePoint=void 0,this.currentDrawingPointerId=void 0;return}if(n.button===0&&this.viewId){const e=this.getPoint(n)||this.cachePoint;e?(this.worker.originalEventLintener(E.Done,e,this.viewId).finally(()=>{document.removeEventListener("pointermove",this.pointermove,!1),document.removeEventListener("pointerup",this.pointerup,!1),document.removeEventListener("pointercancel",this.pointerup,!1)}),this.cachePoint=void 0,this.currentDrawingPointerId=void 0):(document.removeEventListener("pointermove",this.pointermove,!1),document.removeEventListener("pointerup",this.pointerup,!1),document.removeEventListener("pointercancel",this.pointerup,!1),this.currentDrawingPointerId=void 0)}n.pointerType==="touch"&&this.activePointers.size===0&&this.activePointers.clear()}});this.control=n,this.internalMsgEmitter=e;const i={control:this.control,internalMsgEmitter:this.internalMsgEmitter,viewId:t,enableGlobal:!!this.control.pluginOptions.extras.undoRedo.enableGlobal};this.commiter=new _n(i),this.cursorMouseMoveFun=r=>{const s=this.getPoint(r);this.cacheCursorPoint&&z.isEqual(s,this.cacheCursorPoint)||(this.cacheCursorPoint=s,s&&this.worker.sendCursorEvent(s,this.viewId))},this.cursorMouseMoveDebounced=z.debounce(this.cursorMouseMoveFun,this.moveDelayTime,{trailing:!0}),this.cursorMouseMoveThrottled=z.throttle(this.cursorMouseMoveFun,this.moveDelayTime,{leading:!0}),this.cursorMouseMove=r=>{this.control.pluginOptions.extras.cursor.enable?this.cursorMouseMoveThrottled(r):this.cursorMouseMoveDebounced(r)},this.setActive(n.renderControl.isWritable)}get moveDelayTime(){var n,e;return((e=(n=this.control.pluginOptions.extras)==null?void 0:n.cursor)==null?void 0:e.moveDelayTime)??we.cursor.moveDelayTime}setTransferControlToOffscreenCanvas(n){this._transferControlToOffscreenCanvas={bgCanvas:n.bgCanvas.transferControlToOffscreen(),serviceCanvas:n.serviceCanvas.transferControlToOffscreen(),localCanvas:n.localCanvas.transferControlToOffscreen()}}get transferControlToOffscreenCanvas(){return this._transferControlToOffscreenCanvas}get worker(){return this.control.worker}bindToolsClass(){var i,r;const n=(r=(i=this.worker)==null?void 0:i.currentToolsData)==null?void 0:r.toolsType,e=this.control.renderControl.isWritable,t=this.worker.isAbled();switch(n){case T.Text:case T.Pencil:case T.LaserPen:case T.Arrow:case T.Straight:case T.Rectangle:case T.Ellipse:case T.Star:case T.Polygon:case T.SpeechBalloon:case T.Eraser:case T.PencilEraser:case T.BitMapEraser:case T.Selector:this.eventTragetElement&&(this.eventTragetElement.className=e&&t?`netless-whiteboard ${n===T.Selector?"cursor-selector":n===T.Text?"cursor-text":n===T.Eraser||n===T.PencilEraser||n===T.BitMapEraser?"cursor-eraser":n===T.Pencil||n===T.LaserPen?"cursor-pencil":"cursor-arrow"}`:"netless-whiteboard");break}}mountView(){this.setCanvassStyle(),this.control.viewContainerManager.mountView(this.viewId)}updateSize(){this.setCanvassStyle(),this.reflashContainerOffset()}reflashContainerOffset(){this.eventTragetElement&&(this.containerOffset=this.getContainerOffset(this.eventTragetElement,{x:0,y:0}))}get parentElement(){var n;return(n=this.eventTragetElement)==null?void 0:n.parentElement}destroy(){this.eventTragetElement&&this.removeDisplayerEvent(this.eventTragetElement),this.vDom=void 0,this.control.cursor.clearViewCursor(this.viewId),this.internalMsgEmitter.removeAllListeners([te.Cursor,this.viewId])}getPoint(n){const e=mo(n);if(e&&z.isNumber(e.x)&&z.isNumber(e.y))return[e.x-this.containerOffset.x,e.y-this.containerOffset.y]}getActive(){return this.active}setActive(n){this.active=n,this.control.isUseBackgroundThread&&this.backgroundContainerRef&&this.backgroundContainerRef.current&&this.backgroundContainerRef.current.classList.toggle("appliance-plugin-background-isWritable",n)}focusElement(){var n;(n=this.eventTragetElement)==null||n.focus()}async stopEventHandler(){this.cachePoint&&(await this.worker.originalEventLintener(E.Done,this.cachePoint,this.viewId).finally(()=>{document.removeEventListener("pointermove",this.pointermove,!1),document.removeEventListener("pointerup",this.pointerup,!1),document.removeEventListener("pointercancel",this.pointerup,!1)}),this.cachePoint=void 0,this.activePointers.clear(),this.currentDrawingPointerId=void 0)}getTranslate(n){const t=(n.style.WebkitTransform||getComputedStyle(n,"").getPropertyValue("-webkit-transform")||n.style.transform||getComputedStyle(n,"").getPropertyValue("transform")).match(/-?[0-9]+\.?[0-9]*/g),i=t&&parseInt(t[0])||0,r=t&&parseInt(t[1])||0;return[i,r]}getContainerOffset(n,e){var r;const t=this.getTranslate(n);let i={x:e.x+n.offsetLeft-n.scrollLeft+t[0],y:e.y+n.offsetTop-n.scrollTop+t[1]};return(r=n.offsetParent)!=null&&r.nodeName&&n.offsetParent.nodeName!=="BODY"&&(i=this.getContainerOffset(n.offsetParent,i)),i}bindDisplayerEvent(n){n.addEventListener("pointerdown",this.pointerdown,!1),n.addEventListener("mousemove",this.cursorMouseMove,!1),n.addEventListener("mouseleave",this.cursorMouseLeave,!1),n.addEventListener("keydown",this.keydown,!0)}removeDisplayerEvent(n){n.removeEventListener("pointerdown",this.pointerdown,!1),document.removeEventListener("pointermove",this.pointermove,!1),document.removeEventListener("pointerup",this.pointerup,!1),document.removeEventListener("pointerleave",this.pointerup,!1),n.removeEventListener("mousemove",this.cursorMouseMove,!1),n.removeEventListener("mouseleave",this.cursorMouseLeave,!1),n.removeEventListener("keydown",this.keydown,!0)}get isBezier(){return this.control.pluginOptions.extras.bezier.enable}get maxDrawCount(){return this.control.pluginOptions.extras.bezier.maxDrawCount||we.bezier.maxDrawCount}checkConsumeCount(){const n=this.worker.getConsumeCount();return this.cachePoint&&this.toolsKey&&this.toolsKey===T.Pencil&&n>this.maxDrawCount?(this.stopEventHandler().finally(()=>{this.worker.publicMsgEmitter.emit("forceStop",ri.longPencil,this.viewId)}),!0):!1}}class mm extends wo{constructor(e,t,i){super(t,i,e);I(this,"_viewId");this._viewId=e}get viewId(){return this._viewId}setViewId(e){this._viewId=e}}class To extends wo{constructor(n,e){super(n,e,ie)}get viewId(){return ie}updateSize(){this.setCanvassStyle()}destroy(){super.destroy(),this.control.cursor.destroy()}}const Im="index-module__Container__nLsM3",wm="index-module__BackgroundBox__zfthZ",Tm="index-module__BackgroundSvgBox__Fv1ay",Sm="index-module__BackgroundSnapshotContent__NFLAl",vm="index-module__BackgroundSnapshotBox__NEM-C",Nm="index-module__CanvasBox__j2Xe-",Cm="index-module__FloatCanvas__d1YR7",km="index-module__TopFloatCanvas__7IaCw",xm="index-module__CanvasBoxSub__hcMeK",bm="index-module__SnapshotBox__--eeE",Dm="index-module__FloatBar__cm-EL",jm="index-module__RotateBtn__HSSkf",Am="index-module__ResizeBtn__yjvda",Em="index-module__CursorBox__2UHvI",zm="index-module__TextEditorContainer__Qm8KC",Lm="index-module__ResizeTowBox__HOllX",Pm="index-module__FloatBarBtn__FJrOG",be={Container:Im,BackgroundBox:wm,BackgroundSvgBox:Tm,BackgroundSnapshotContent:Sm,BackgroundSnapshotBox:vm,CanvasBox:Nm,FloatCanvas:Cm,TopFloatCanvas:km,CanvasBoxSub:xm,SnapshotBox:bm,FloatBar:Dm,RotateBtn:jm,ResizeBtn:Am,CursorBox:Em,TextEditorContainer:zm,ResizeTowBox:Lm,FloatBarBtn:Pm},Om={delete:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDZ2NmEyIDIgMCAwIDEtMiAySDZhMiAyIDAgMCAxLTItMlY2aDBtMS0yYTIgMiAwIDAgMSAyLTJoMmEyIDIgMCAwIDEgMiAyaDBNMyA0aDEwIiBzdHJva2U9IiM0NDRFNjAiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==",duplicate:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgc3Ryb2tlPSIjNDQ0RTYwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIHN0cm9rZS1saW5lam9pbj0icm91bmQ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HN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","font-colors":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0ibTQgMTEgNC05IDQgOU02IDdoNCIgc3Ryb2tlPSIjNDQ0RTYwIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","to-bottom":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDEwdjhtMCAwLTItMm0yIDIgMi0ybS00IDZoMTJtLTYtNGg2bS02LTRoNm0tNi00aDYiIHN0cm9rZT0iIzQ0NEU2MCIgZmlsbD0ibm9uZSIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+PC9zdmc+","to-top":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDIydi04bTAgMC0yIDJtMi0yIDIgMm0tNC02aDEybS02IDRoNm0tNiA0aDZtLTYgNGg2IiBzdHJva2U9IiM0NDRFNjAiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==","bold-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTQuNSAySDhhMi41IDIuNSAwIDAgMSAwIDVINS41aDBtLTEgMGg0YTMgMyAwIDAgMSAwIDZoLTQgMG0wIDFWMiIgc3Ryb2tlPSIjMzM4MUZGIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=",bold:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTQuNSAySDhhMi41IDIuNSAwIDAgMSAwIDVINS41aDBtLTEgMGg0YTMgMyAwIDAgMSAwIDZoLTQgMG0wIDFWMiIgc3Ryb2tlPSIjNDQ0RTYwIiBmaWxsPSJub25lIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz48L3N2Zz4=","underline-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDJ2NWE0IDQgMCAxIDEtOCAwVjJoME0zIDE0aDEwIiBzdHJva2U9IiMzMzgxRkYiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==",underline:"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDJ2NWE0IDQgMCAxIDEtOCAwVjJoME0zIDE0aDEwIiBzdHJva2U9IiM0NDRFNjAiIGZpbGw9Im5vbmUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==","line-through-active":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD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Y2NyA3NC42NjY2NjZBNzQuNjY2NjY3IDc0LjY2NjY2NyAwIDAgMSAyMTMuMzMzMzMzIDg2NHY2NGExMzguNjY2NjY3IDEzOC42NjY2NjcgMCAwIDAgMTM4LjY2NjY2Ny0xMzguNjY2NjY3aC02NHpNMjEzLjMzMzMzMyA4NjRhNzQuNjY2NjY3IDc0LjY2NjY2NyAwIDAgMS03NC42NjY2NjYtNzQuNjY2NjY3aC02NEExMzguNjY2NjY3IDEzOC42NjY2NjcgMCAwIDAgMjEzLjMzMzMzMyA5Mjh2LTY0ek0yNDUuMzMzMzMzIDY4Mi42NjY2Njd2LTIzNC42NjY2NjdoLTY0VjY4Mi42NjY2NjdoNjR6IG0tNTQuNjEzMzMzLTIxMi4wNTMzMzRsODUuMzMzMzMzIDg1LjMzMzMzNCA0NS4yMjY2NjctNDUuMjI2NjY3LTg1LjMzMzMzMy04NS4zMzMzMzMtNDUuMjI2NjY3IDQ1LjIyNjY2NnogbTAtNDUuMjI2NjY2bC04NS4zMzMzMzMgODUuMzMzMzMzIDQ1LjIyNjY2NiA0NS4yMjY2NjcgODUuMzMzMzM0LTg1LjMzMzMzNC00NS4yMjY2NjctNDUuMjI2NjY2eiIgIGZpbGw9IiM0NDRFNjAiPjwvcGF0aD48L3N2Zz4="};function Le(o){return Om[o]}const Rm=o=>{const{workIds:n,mananger:e}=o;return f.createElement("div",{className:"button normal-button",style:{touchAction:"none"},onPointerUp:t=>{t.cancelable&&t.preventDefault(),t.stopPropagation(),t.nativeEvent.stopImmediatePropagation(),ee.emitMethod(te.MainEngine,R.DeleteNode,{workIds:n||[Z],viewId:e.viewId})}},f.createElement("img",{alt:"icon",src:Le("delete")}))},Um=o=>{const{workIds:n,viewId:e}=o;return f.createElement("div",{className:"button normal-button",onPointerUp:t=>{t.stopPropagation(),ee.emitMethod(te.MainEngine,R.CopyNode,{workIds:n||[Z],viewId:e})}},f.createElement("img",{alt:"icon",src:Le("duplicate")}))},yr=o=>{const{icon:n,onPointerUpHandler:e}=o;return f.createElement("div",{className:"button normal-button",onPointerUp:e},f.createElement("img",{src:Le(n)}))},Ym=o=>{const{open:n,setOpen:e,floatBarRef:t}=o,{floatBarData:i,mananger:r}=f.useContext(Ne),[s,a]=f.useState([]),c=f.useMemo(()=>{if(t!=null&&t.current&&z.isNumber(i==null?void 0:i.y)&&(r!=null&&r.height)){if(t.current.offsetTop&&t.current.offsetTop+i.y>180){const h={};return h.top="inherit",h.bottom=50,h}else if(!t.current.offsetTop&&(r==null?void 0:r.height)-t.current.offsetTop-i.y<120){const h={};return h.top="inherit",h.bottom=50,h}}},[t==null?void 0:t.current,i,r]),l=f.useMemo(()=>n?f.createElement("div",{className:"image-layer-menu",style:c},f.createElement(yr,{icon:"to-top",onPointerUpHandler:h=>{h.stopPropagation(),ee.emitMethod(te.MainEngine,R.ZIndexNode,{workIds:[Z],layer:st.Top,viewId:r==null?void 0:r.viewId})}}),f.createElement(yr,{icon:"to-bottom",onPointerUpHandler:h=>{h.stopPropagation(),ee.emitMethod(te.MainEngine,R.ZIndexNode,{workIds:[Z],layer:st.Bottom,viewId:r==null?void 0:r.viewId})}})):null,[n,c]),u=h=>{h.stopPropagation(),h.nativeEvent.stopImmediatePropagation(),e(!n)};return f.useEffect(()=>{z.isEqual(i==null?void 0:i.selectIds,s)||i!=null&&i.selectIds&&!z.isEqual(i==null?void 0:i.selectIds,s)&&(a(i==null?void 0:i.selectIds),e(!1))},[n,i,s,e]),f.createElement("div",{className:`button normal-button ${n&&"active"}`,onPointerUp:u},l,f.createElement("img",{alt:"icon",src:Le(n?"layer-pressed":"layer")}))},nn=o=>{o.stopPropagation(),o.nativeEvent.stopImmediatePropagation()},Bm=()=>f.createElement("svg",{style:{marginLeft:"2px"},viewBox:"0 0 1025 1024",width:"14",height:"14"},f.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"})),So=o=>{const{activeColor:n,onPointerUpHandler:e}=o;return f.createElement("div",{className:`font-color-button ${n==="transparent"?"active":""}`,onPointerUp:e},f.createElement("div",{className:"circle none"}))},bn=o=>{const{color:n,activeColor:e,onPointerUpHandler:t}=o;return f.createElement("div",{className:`font-color-button ${n===e?"active":""}`,onPointerUp:t},f.createElement("div",{className:"circle",style:{backgroundColor:Ee(n,1)}}))},Dn=o=>{const{opacity:n,activeColor:e,setCurOpacity:t}=o,[i,r]=f.useState({x:108,y:0}),s=f.useRef(0);if(f.useEffect(()=>{r({x:n*100+8,y:0})},[]),!e)return null;const a=(h,g)=>{const p=Math.min(Math.max(h-8,0),100)/100;(n!==p||g===E.Done)&&t(p,e,g)},c=(h,g)=>{g.x!==(i==null?void 0:i.x)&&r({x:g.x,y:0}),!s.current&&(s.current=setTimeout(()=>{s.current=0,a(g.x,E.Doing)},100))},l=()=>{t(n,e,E.Start)},u=(h,g)=>{g.x!==(i==null?void 0:i.x)&&r({x:g.x,y:0}),s.current&&(clearTimeout(s.current),s.current=0),a(g.x,E.Done)};return f.createElement("div",{className:"font-color-opacity",style:{marginLeft:"10px"},onPointerUp:h=>{s.current&&(clearTimeout(s.current),s.current=0);const g=h.nativeEvent.offsetX,p=Math.min(Math.max(g-12,0),100)/100;r({x:p*100+8,y:0}),t(p,e,E.Done)}},f.createElement("div",{className:"range-color",style:{background:`linear-gradient(to right, ${Ee(e,0)}, ${Ee(e,1)})`}}),f.createElement("div",{className:"range-opacity"},f.createElement(Ot,{bounds:"parent",axis:"x",position:i,onDrag:c,onStart:l,onStop:u},f.createElement("div",{className:"circle",style:{backgroundColor:Ee(e,n)},onPointerUp:nn}))))},Wm=o=>{const{min:n,max:e,activeNumber:t,setActiveNumber:i,color:r}=o,[s,a]=f.useState({x:108,y:0}),c=f.useRef(0);if(f.useEffect(()=>{const p=Math.ceil((t-n)/(e-n)*100)+8;a({x:p,y:0})},[]),!t)return null;const l=(p,d)=>{const M=Math.ceil(Math.max(p-8,0)/100*(e-n)+n);(t!==M||d===E.Done)&&i(M,d)},u=(p,d)=>{d.x!==(s==null?void 0:s.x)&&a({x:d.x,y:0}),!c.current&&(c.current=setTimeout(()=>{c.current=0,l(d.x,E.Doing)},100))},h=()=>{i(t,E.Start)},g=(p,d)=>{d.x!==(s==null?void 0:s.x)&&a({x:d.x,y:0}),c.current&&(clearTimeout(c.current),c.current=0),l(d.x,E.Done)};return f.createElement("div",{className:"font-color-opacity",style:{marginLeft:"10px"},onPointerUp:p=>{c.current&&(clearTimeout(c.current),c.current=0);const d=p.nativeEvent.offsetX,M=Math.ceil(Math.max(d-12,0)/100*(e-n)+n),w=Math.ceil((M-n)/(e-n)*100)+8;a({x:w,y:0}),i(M,E.Done)}},f.createElement("div",{className:"range-color",style:{backgroundColor:r}}),f.createElement("div",{className:"range-opacity"},f.createElement(Ot,{bounds:"parent",axis:"x",position:s,onDrag:u,onStart:h,onStop:g},f.createElement("div",{className:"circle",style:{backgroundColor:r},onPointerUp:nn},f.createElement("div",{className:"range-opacity-data-icon"},t)))))},Vm=o=>{const{useStroke:n,color:e,activeStrokeType:t,setStrokeType:i}=o;return f.createElement("div",{className:"stroke-type-box"},!!n&&f.createElement("div",{className:`stroke-type-box-item Stroke ${t===ce.Stroke&&"active"}`,style:{backgroundColor:e},onPointerUp:()=>{i(ce.Stroke)}}),f.createElement("div",{className:`stroke-type-box-item Normal ${t===ce.Normal&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(ce.Normal)}}),f.createElement("div",{className:`stroke-type-box-item Dotted ${t===ce.Dotted&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(ce.Dotted)}}),f.createElement("div",{className:`stroke-type-box-item LongDotted ${t===ce.LongDotted&&"active"}`,style:{borderColor:e},onPointerUp:()=>{i(ce.LongDotted)}}))},Fm=o=>{const{open:n,setOpen:e,floatBarRef:t}=o,{floatBarData:i,floatBarColors:r,mananger:s,setFloatBarData:a}=f.useContext(Ne),[c,l]=f.useState(),[u,h]=f.useState(1);f.useEffect(()=>{if(i!=null&&i.strokeColor){const[y,S]=Cn(i.strokeColor);l(y),h(S)}},[i]);const g=f.useMemo(()=>{if(t!=null&&t.current&&i&&z.isNumber(i==null?void 0:i.y)&&(s!=null&&s.height)){if(t.current.offsetTop&&t.current.offsetTop+i.y>180){const y={};return y.top="inherit",y.bottom=50,y}else if(!t.current.offsetTop&&(s==null?void 0:s.height)-t.current.offsetTop-i.y<120){const y={};return y.top="inherit",y.bottom=50,y}}},[i,t,s==null?void 0:s.height]),p=f.useMemo(()=>f.createElement(Dn,{key:"strokeColors",opacity:u,activeColor:c,setCurOpacity:(y,S,v)=>{h(y);const k=Ee(S,y);i!=null&&i.strokeColor&&a({strokeColor:k}),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:[Z],strokeColor:k,workState:v,viewId:s==null?void 0:s.viewId})}}),[u,c,i==null?void 0:i.strokeColor,s==null?void 0:s.viewId,a]),d=f.useMemo(()=>c&&i&&i.thickness?f.createElement(Wm,{key:"strokeThickness",min:Math.min(i.thickness,(s==null?void 0:s.control.pluginOptions.extras.strokeWidth.min)||we.strokeWidth.min),max:Math.max(i.thickness,(s==null?void 0:s.control.pluginOptions.extras.strokeWidth.max)||we.strokeWidth.max),activeNumber:i.thickness,setActiveNumber:(y,S)=>{i!=null&&i.thickness&&a({thickness:y}),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:[Z],thickness:y,workState:S,viewId:s==null?void 0:s.viewId})},color:c}):null,[c,i,s==null?void 0:s.control.pluginOptions.extras.strokeWidth.max,s==null?void 0:s.control.pluginOptions.extras.strokeWidth.min,s==null?void 0:s.viewId,a]),M=f.useMemo(()=>c&&i&&(i!=null&&i.strokeType)?f.createElement(Vm,{key:"strokeType",useStroke:i==null?void 0:i.useStroke,activeStrokeType:i.strokeType,setStrokeType:y=>{i.strokeType&&a({strokeType:y}),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:[Z],strokeType:y,workState:E.Done,viewId:s==null?void 0:s.viewId})},color:c}):null,[c,i,s==null?void 0:s.viewId,a]),w=f.useMemo(()=>n?f.createElement("div",{className:"font-colors-menu",style:g,onPointerUp:y=>{y.stopPropagation(),y.nativeEvent.stopImmediatePropagation()}},M,d,f.createElement("div",{className:"font-colors-line"}),r.concat().map((y,S)=>{const v=tn(...y);return f.createElement(bn,{key:S,color:v,activeColor:c,onPointerUpHandler:k=>{k.stopPropagation(),l(v);const C=Ee(v,u);i!=null&&i.strokeColor&&(i.strokeColor=C,a({strokeColor:C})),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:[Z],workState:E.Done,strokeColor:C,viewId:s==null?void 0:s.viewId})}})}),p):null,[n,g,M,d,r,p,c,u,i,s==null?void 0:s.viewId,a]),m=f.useMemo(()=>c?f.createElement("div",{className:"color-bar-ring",style:{backgroundColor:Ee(c,u)}},f.createElement("div",{className:"circle"})):null,[c,u]);return f.createElement("div",{className:`button normal-button font-colors-icon ${n&&"active"}`,onPointerUp:y=>{y.stopPropagation(),y.nativeEvent.stopImmediatePropagation(),e(!n)}},m,w)},$m=o=>{const{open:n,setOpen:e,floatBarRef:t}=o,{floatBarData:i,floatBarColors:r,mananger:s,setFloatBarData:a}=f.useContext(Ne),[c,l]=f.useState(),[u,h]=f.useState(1);f.useEffect(()=>{if(i!=null&&i.fillColor){const[w,m]=(i==null?void 0:i.fillColor)==="transparent"&&["transparent",1]||Cn(i.fillColor);l(w),h(m)}},[i]);const g=f.useMemo(()=>{if(t!=null&&t.current&&z.isNumber(i==null?void 0:i.y)&&(s!=null&&s.height)){if(t.current.offsetTop&&t.current.offsetTop+i.y>200){const w={};return w.top="inherit",w.bottom=50,w}else if(!t.current.offsetTop&&(s==null?void 0:s.height)-t.current.offsetTop-i.y<140){const w={};return w.top="inherit",w.bottom=50,w}}},[t,i,s==null?void 0:s.height]),p=f.useMemo(()=>c&&c!=="transparent"?f.createElement(Dn,{key:"fillColors",opacity:u||0,activeColor:c,setCurOpacity:(w,m,y)=>{h(w);const S=Ee(m,w);i!=null&&i.fillColor&&(i.fillColor=S,a({fillColor:S})),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:[Z],fillColor:c&&Ee(m,w),workState:y,viewId:s==null?void 0:s.viewId})}}):null,[c,u,i,s==null?void 0:s.viewId,a]),d=f.useMemo(()=>n?f.createElement("div",{className:"font-colors-menu",style:g,onPointerUp:w=>{w.stopPropagation(),w.nativeEvent.stopImmediatePropagation()}},f.createElement(So,{activeColor:c,onPointerUpHandler:w=>{w.stopPropagation(),l("transparent");const m="transparent";i!=null&&i.fillColor&&(i.fillColor=m,a({fillColor:m})),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:[Z],workState:E.Done,fillColor:m,viewId:s==null?void 0:s.viewId})}}),r.map((w,m)=>{const y=tn(...w);return f.createElement(bn,{key:m,color:y,activeColor:c,onPointerUpHandler:S=>{S.cancelable&&S.preventDefault(),S.stopPropagation(),l(y);const v=Ee(y,u);i!=null&&i.fillColor&&(i.fillColor=v,a({fillColor:v})),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:[Z],workState:E.Done,fillColor:v,viewId:s==null?void 0:s.viewId})}})}),p):null,[n,g,c,r,p,i,s==null?void 0:s.viewId,a,u]),M=f.useMemo(()=>{const w=c&&c!=="transparent"&&Ee(c,u)||"transparent";return f.createElement("div",{className:"color-bar-fill"},f.createElement("div",{className:"circle",style:{backgroundColor:w}}))},[c,u]);return f.createElement("div",{className:`button normal-button font-colors-icon ${n&&"active"}`,onPointerUp:w=>{w.stopPropagation(),w.nativeEvent.stopImmediatePropagation(),e(!n)}},M,d)},Gm=o=>{const{open:n,setOpen:e,textOpt:t,workIds:i,floatBarRef:r}=o,{floatBarColors:s,mananger:a,setFloatBarData:c,floatBarData:l}=f.useContext(Ne),[u,h]=f.useState(),[g,p]=f.useState(1);f.useEffect(()=>{if(t!=null&&t.fontColor){const[y,S]=(t==null?void 0:t.fontColor)==="transparent"&&["transparent",0]||Cn(t.fontColor);h(y),p(S)}},[t==null?void 0:t.fontColor]);const d=f.useMemo(()=>{if(r!=null&&r.current&&l&&z.isNumber(l==null?void 0:l.y)&&(a!=null&&a.height)){if(r.current.offsetTop&&r.current.offsetTop+l.y>180){const y={};return y.top="inherit",y.bottom=50,y}else if(!r.current.offsetTop&&(a==null?void 0:a.height)-r.current.offsetTop-l.y<120){const y={};return y.top="inherit",y.bottom=50,y}}},[r,l,a==null?void 0:a.height]),M=f.useMemo(()=>u&&u!=="transparent"?f.createElement(Dn,{key:"fontColors",opacity:g,activeColor:u,setCurOpacity:(y,S,v)=>{p(y);const k=Ee(S,y);l!=null&&l.textOpt&&(l.textOpt.fontColor=k,c({textOpt:l.textOpt})),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:i||[Z],fontColor:u&&k,workState:v,viewId:a==null?void 0:a.viewId})}}):null,[c,u,g,a==null?void 0:a.control.room,a==null?void 0:a.viewId,l==null?void 0:l.textOpt,i]),w=f.useMemo(()=>n?f.createElement("div",{className:"font-colors-menu",style:d,onPointerUp:y=>{y.stopPropagation(),y.nativeEvent.stopImmediatePropagation()}},s.map((y,S)=>{const v=tn(...y);return f.createElement(bn,{key:S,color:v,activeColor:u,onPointerUpHandler:k=>{k.stopPropagation(),h(v);const C=Ee(v,g);l!=null&&l.textOpt&&(l.textOpt.fontColor=C,c({textOpt:l.textOpt})),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:i||[Z],workState:E.Done,fontColor:C,viewId:a==null?void 0:a.viewId})}})}),M):null,[c,n,s,M,u,g,l==null?void 0:l.textOpt,i,a==null?void 0:a.viewId,d]),m=f.useMemo(()=>{const y=u&&u!=="transparent"&&Ee(u,g)||"transparent";return f.createElement("div",{className:"color-bar"},f.createElement("div",{className:"color-bar-color",style:{backgroundColor:y}}))},[u,g]);return f.createElement("div",{className:`button normal-button font-colors-icon ${n&&"active"}`,onPointerUp:y=>{y.stopPropagation(),y.nativeEvent.stopImmediatePropagation(),e(!n)}},f.createElement("img",{alt:"icon",src:Le("font-colors")}),m,w)},Qm=o=>{const{open:n,setOpen:e,textOpt:t,workIds:i,floatBarRef:r}=o,{floatBarColors:s,mananger:a,setFloatBarData:c,floatBarData:l}=f.useContext(Ne),[u,h]=f.useState(),[g,p]=f.useState(1);f.useEffect(()=>{if(t!=null&&t.fontBgColor){const[y,S]=(t==null?void 0:t.fontBgColor)==="transparent"&&["transparent",1]||Cn(t.fontBgColor);h(y),p(S)}},[t==null?void 0:t.fontBgColor]);const d=f.useMemo(()=>{if(r!=null&&r.current&&l&&z.isNumber(l==null?void 0:l.y)&&(a!=null&&a.height)){if(r.current.offsetTop&&r.current.offsetTop+l.y>180){const y={};return y.top="inherit",y.bottom=50,y}else if(!r.current.offsetTop&&(a==null?void 0:a.height)-r.current.offsetTop-l.y<120){const y={};return y.top="inherit",y.bottom=50,y}}},[r,l,a==null?void 0:a.height]),M=f.useMemo(()=>u&&u!=="transparent"?f.createElement(Dn,{key:"fontBgColor",opacity:g||0,activeColor:u,setCurOpacity:(y,S,v)=>{p(y);const k=Ee(S,y);l!=null&&l.textOpt&&(l.textOpt.fontBgColor=k,c({textOpt:l.textOpt})),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:i||[Z],fontBgColor:u&&Ee(S,y),workState:v,viewId:a==null?void 0:a.viewId})}}):null,[u,g,l==null?void 0:l.textOpt,i,a==null?void 0:a.viewId,c]),w=f.useMemo(()=>n?f.createElement("div",{className:"font-colors-menu",style:d,onPointerUp:y=>{y.stopPropagation(),y.nativeEvent.stopImmediatePropagation()}},f.createElement(So,{activeColor:u,onPointerUpHandler:y=>{y.stopPropagation();const S="transparent";h(S),l!=null&&l.textOpt&&(l.textOpt.fontBgColor=S,c({textOpt:l.textOpt})),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:i||[Z],workState:E.Done,fontBgColor:S,viewId:a==null?void 0:a.viewId})}}),s.map((y,S)=>{const v=tn(...y);return f.createElement(bn,{key:S,color:v,activeColor:u,onPointerUpHandler:k=>{k.stopPropagation(),h(v);const C=Ee(v,g);l!=null&&l.textOpt&&(l.textOpt.fontBgColor=C,c({textOpt:l.textOpt})),ee.emitMethod(te.MainEngine,R.SetColorNode,{workIds:i||[Z],workState:E.Done,fontBgColor:Ee(v,g),viewId:a==null?void 0:a.viewId})}})}),M):null,[c,n,s,M,g,u,l==null?void 0:l.textOpt,i,a==null?void 0:a.viewId,d]),m=f.useMemo(()=>{const y=u&&u!=="transparent"&&Ee(u,g)||"transparent";return f.createElement("div",{className:"color-bar",style:{marginTop:0}},f.createElement("div",{className:"color-bar-color",style:{backgroundColor:y}}))},[u,g]);return f.createElement("div",{className:`button normal-button font-colors-icon ${n&&"active"}`,onPointerUp:y=>{y.stopPropagation(),y.nativeEvent.stopImmediatePropagation(),e(!n)}},f.createElement(Bm,null),m,w)},Zm=o=>{const{bold:n,setBold:e,workIds:t,viewId:i}=o,r=s=>{const a=n==="bold"?"normal":"bold";s==null||s.stopPropagation(),e(a),ee.emitMethod(te.MainEngine,R.SetFontStyle,{workIds:t,viewId:i,bold:a})};return f.createElement("div",{className:"font-style-button",onPointerUp:r},f.createElement("img",{alt:"icon",src:Le(n==="bold"?"bold-active":"bold")}))},Hm=o=>{const{underline:n,setUnderline:e,workIds:t,viewId:i}=o,r=s=>{const a=!n;s==null||s.stopPropagation(),e(a),ee.emitMethod(te.MainEngine,R.SetFontStyle,{workIds:t,viewId:i,underline:a})};return f.createElement("div",{className:"font-style-button",onPointerUp:r},f.createElement("img",{alt:"icon",src:Le(n?"underline-active":"underline")}))},qm=o=>{const{lineThrough:n,setLineThrough:e,workIds:t,viewId:i}=o,r=s=>{const a=!n;s==null||s.stopPropagation(),e(a),ee.emitMethod(te.MainEngine,R.SetFontStyle,{workIds:t,viewId:i,lineThrough:a})};return f.createElement("div",{className:"font-style-button",onPointerUp:r},f.createElement("img",{alt:"icon",src:Le(n?"line-through-active":"line-through")}))},Km=o=>{const{italic:n,setItalic:e,workIds:t,viewId:i}=o,r=s=>{const a=n==="italic"?"normal":"italic";s==null||s.stopPropagation(),e(a),ee.emitMethod(te.MainEngine,R.SetFontStyle,{workIds:t,viewId:i,italic:a})};return f.createElement("div",{className:"font-style-button",onPointerUp:r},f.createElement("img",{alt:"icon",src:Le(n==="italic"?"italic-active":"italic")}))},Jm=o=>{const{open:n,setOpen:e,textOpt:t,workIds:i,style:r,floatBarRef:s}=o,{mananger:a,floatBarData:c}=f.useContext(Ne),[l,u]=f.useState("normal"),[h,g]=f.useState("normal"),[p,d]=f.useState(!1),[M,w]=f.useState(!1);f.useEffect(()=>{t!=null&&t.bold&&u(t.bold),z.isBoolean(t==null?void 0:t.underline)&&d(t.underline||!1),z.isBoolean(t==null?void 0:t.lineThrough)&&w(t.lineThrough||!1),t!=null&&t.italic&&g(t.italic)},[t]);const m=f.useMemo(()=>{if(r&&(s!=null&&s.current)&&z.isNumber(c==null?void 0:c.y)&&(a!=null&&a.height)){if(s.current.offsetTop&&s.current.offsetTop+c.y>180){const S={};return S.top="inherit",S.bottom=50,S}else if(!s.current.offsetTop&&(a==null?void 0:a.height)-s.current.offsetTop-c.y<120){const S={};return S.top="inherit",S.bottom=50,S}}},[r,s==null?void 0:s.current,c,a]),y=f.useMemo(()=>n?f.createElement("div",{className:"font-style-menu",style:m,onPointerUp:S=>{S.stopPropagation(),S.nativeEvent.stopImmediatePropagation()}},f.createElement(Zm,{workIds:i||[Z],bold:l,setBold:u,viewId:a==null?void 0:a.viewId}),f.createElement(Hm,{workIds:i||[Z],underline:p,setUnderline:d,viewId:a==null?void 0:a.viewId}),f.createElement(qm,{workIds:i||[Z],lineThrough:M,setLineThrough:w,viewId:a==null?void 0:a.viewId}),f.createElement(Km,{workIds:i||[Z],italic:h,setItalic:g,viewId:a==null?void 0:a.viewId})):null,[n,i,l,a==null?void 0:a.viewId,p,M,h,m]);return f.createElement("div",{className:`button normal-button ${n&&"active"}`,onPointerUp:S=>{S.stopPropagation(),S.nativeEvent.stopImmediatePropagation(),e(!n)}},f.createElement("img",{alt:"icon",src:Le(n?"font-style-active":"font-style")}),y)},Xe=Object.freeze([12,14,18,24,36,48,64,80,144,288]),xt=["top","topLeft","topRight","bottom","bottomLeft","bottomRight","left","leftTop","leftBottom","right","rightTop","rightBottom"],Xm=new Map([["selector","data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAKeSURBVHgB3VTLi1JhFD86zlQ4ysxSXAy1GWYZzMxmYAhHagRB/QN8FLqPFq4FIQhXkS6kTQ4t2ilIKEWgSS0SmVpIm0BdaBJSaOP78XU+PXey6+saburAD+73uL/feX0H4H81GQdj7D7ilrCGFRonk3c6nXvhcJiFQiGWy+Xy/X7/WbPZ1K1KkBOsl0qlO36/n+3t7Q1hs9kYF+WC3W73MTpxc1lBmej7KuJaoVDInZ6eqsWXDw4OwGKxwPHx8Se1Wn1Wr9cjW1tbOTxi9D9bJCJHXEFslsvlR263+246nYZZptPpQK/Xg8lkSvZ6vbNGo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iAxMi45MTAxMjQ0LDE5LjUwODA1NTcgTDEzLDE5LjUgTDE4LDE5LjUgWiBNMjAsMTIuNSBDMjAuMjQ1NDU5OSwxMi41IDIwLjQ0OTYwODQsMTIuNjc2ODc1MiAyMC40OTE5NDQzLDEyLjkxMDEyNDQgTDIwLjUsMTMgTDIwLjUsMTggQzIwLjUsMTguMjc2MTQyNCAyMC4yNzYxNDI0LDE4LjUgMjAsMTguNSBDMTkuNzU0NTQwMSwxOC41IDE5LjU1MDM5MTYsMTguMzIzMTI0OCAxOS41MDgwNTU3LDE4LjA4OTg3NTYgTDE5LjUsMTggTDE5LjUsMTMgQzE5LjUsMTIuNzIzODU3NiAxOS43MjM4NTc2LDEyLjUgMjAsMTIuNSBaIiBpZD0i5b2i54q257uT5ZCIIiBmaWxsPSIjMjEyMzI0IiBmaWxsLXJ1bGU9Im5vbnplcm8iPjwvcGF0aD4KICAgICAgICAgICAgPC9nPgogICAgICAgIDwvZz4KICAgIDwvZz4KPC9zdmc+"]]),_m=o=>{const{style:n,onClickHandler:e}=o;return f.createElement("div",{className:"font-size-menu",style:n,onPointerUp:t=>{t.stopPropagation(),t.nativeEvent.stopImmediatePropagation()}},Xe.map(t=>f.createElement("div",{className:"font-size-btn",key:t,onPointerUp:()=>{e(t)}},t)))},eI=o=>{const n=f.useRef(null),{open:e,setOpen:t,textOpt:i,workIds:r,floatBarRef:s}=o,{mananger:a,floatBarData:c}=f.useContext(Ne),[l,u]=f.useState(0),h=Xe.length-1;f.useEffect(()=>{i!=null&&i.fontSize&&(u(i.fontSize),n.current&&(n.current.value=i.fontSize.toString()))},[i==null?void 0:i.fontSize]);const g=f.useMemo(()=>{if(s!=null&&s.current&&z.isNumber(c==null?void 0:c.y)&&(a!=null&&a.height)){if(s.current.offsetTop&&s.current.offsetTop+c.y>180){const m={};return m.top="inherit",m.bottom=35,m}else if(!s.current.offsetTop&&(a==null?void 0:a.height)-s.current.offsetTop-c.y<120){const m={};return m.top="inherit",m.bottom=35,m}}},[s==null?void 0:s.current,c,a]);function p(m){u(m),m&&m>=Xe[0]&&m<=Xe[h]&&ee.emitMethod(te.MainEngine,R.SetFontStyle,{workIds:r||[Z],fontSize:m,viewId:a==null?void 0:a.viewId})}const d=m=>{var y;(y=n.current)==null||y.blur(),t(!1),w(m)},M=f.useMemo(()=>e?f.createElement(_m,{onClickHandler:d,style:g}):null,[e,d,g]),w=m=>{m>Xe[h]&&(m=Xe[h]),m<Xe[0]&&(m=Xe[0]),p(m)};return f.createElement("div",{className:"button normal-button font-size-barBtn",style:{width:50},onPointerUp:m=>{m.stopPropagation(),m.nativeEvent.stopImmediatePropagation()}},f.createElement("input",{className:"font-size-input",ref:n,onTouchEnd:()=>{n.current&&n.current.focus()},onClick:()=>{t(!e),n.current&&n.current.focus()},onKeyDown:m=>{if(m.stopPropagation(),m.nativeEvent.stopImmediatePropagation(),m.key==="Backspace"){const y=window.getSelection(),S=y==null?void 0:y.getRangeAt(0);if(S!=null&&S.collapsed)return m.cancelable&&m.preventDefault(),document.execCommand("delete",!1),!1}return!1},onKeyUp:m=>{var y;if(m.stopPropagation(),m.nativeEvent.stopImmediatePropagation(),n.current){const S=n.current.value,v=parseInt(S);isNaN(v)?n.current.value="0":n.current.value=v.toString(),v&&m.key==="Enter"&&(w(v),(y=n.current)==null||y.blur(),t(!1))}}}),f.createElement("div",{className:"font-size-btns"},f.createElement("div",{className:"font-size-add",onPointerUp:()=>{w(l+Xe[0])}}),f.createElement("div",{className:"font-size-cut",onPointerUp:()=>{w(l-Xe[0])}})),M)},tI=o=>{const{workIds:n,mananger:e,islocked:t}=o;return f.createElement("div",{className:"button normal-button",onPointerUp:i=>{i.stopPropagation(),ee.emitMethod(te.MainEngine,R.SetLock,{workIds:n||[Z],isLocked:!t,viewId:e==null?void 0:e.viewId})}},f.createElement("img",{alt:"icon",src:Le(t?"unlock-new":"lock-new")}))},ei=o=>{const{icon:n,min:e,max:t,step:i,value:r,onInputHandler:s}=o,[a,c]=f.useState(0),l=f.useRef(null),u=h=>{h>t&&(h=t),h<e&&(h=e),c(h),s(h),l.current&&(l.current.value=h.toString())};return f.useEffect(()=>{r&&(c(r),l.current&&(l.current.value=r.toString()))},[r]),f.createElement("div",{className:"button input-button"},f.createElement("img",{src:Le(n)}),f.createElement("input",{className:"input-number",type:"text",ref:l,onPointerUp:()=>{l.current&&l.current.focus()},onKeyDown:h=>{if(h.stopPropagation(),h.nativeEvent.stopImmediatePropagation(),h.key==="Backspace"){const g=window.getSelection(),p=g==null?void 0:g.getRangeAt(0);if(p!=null&&p.collapsed)return h.cancelable&&h.preventDefault(),document.execCommand("delete",!1),!1}},onKeyUp:h=>{if(h.stopPropagation(),h.nativeEvent.stopImmediatePropagation(),l.current){const g=l.current.value,p=parseInt(g);isNaN(p)?l.current.value="0":l.current.value=p.toString()}},onChange:h=>{const g=h.target.value,p=parseInt(g);p&&p&&p>=e&&p<=t&&u(p)}}),f.createElement("div",{className:"input-number-btns"},f.createElement("div",{className:"input-number-add",onPointerUp:()=>{u(a+i)}}),f.createElement("div",{className:"input-number-cut",onPointerUp:()=>{u(a-i)}})))},nI=o=>{const{icon:n,min:e,max:t,step:i,value:r,onInputHandler:s}=o;return f.createElement("div",{className:"button input-button"},f.createElement("img",{src:Le(n)}),f.createElement(iI,{min:e,max:t,step:i,value:r,onInputHandler:s}))},iI=o=>{const{value:n,min:e,max:t,onInputHandler:i}=o,[r,s]=f.useState({x:0,y:0});f.useEffect(()=>{s({x:n*100,y:0})},[]);const a=(u,h)=>{let g=Math.floor(Math.max(h.x,e*100));g=Math.floor(Math.min(g,t*100)),h.x!==(r==null?void 0:r.x)&&s({x:g,y:0});const p=g/100;n!==p&&i(p)},c=()=>{},l=(u,h)=>{let g=Math.floor(Math.max(h.x,e*100));g=Math.floor(Math.min(g,t*100)),h.x!==(r==null?void 0:r.x)&&s({x:g,y:0});const p=g/100;n!==p&&i(p)};return f.createElement("div",{className:"range-number-container",onPointerUp:u=>{const h=u.nativeEvent.offsetX-6;let g=Math.floor(Math.max(h,e*100));g=Math.floor(Math.min(g,t*100)),s({x:g,y:0});const p=g/100;n!==p&&i(p)}},f.createElement("div",{className:"range-number-color"}),f.createElement("div",{className:"range-number"},f.createElement(Ot,{bounds:"parent",axis:"x",position:r,onDrag:a,onStart:c,onStop:l},f.createElement("div",{className:"circle",onPointerUp:nn}))))},rI=o=>{const{icon:n,value:e,onChangeHandler:t,style:i}=o,[r,s]=f.useState(0),[a,c]=f.useState(),l=f.useRef(null),u=f.useCallback(p=>{p>=xt.length&&(p=0),p<0&&(p=xt.length-1),s(p),t(xt[p]),c(!1),l.current&&(l.current.value=xt[p])},[t]),h=f.useMemo(()=>{if(i&&i.bottom){const p={};return p.top="inherit",p.bottom=50,p}},[i]);f.useEffect(()=>{e&&(s(xt.indexOf(e)),l.current&&(l.current.value=e))},[e]);const g=f.useMemo(()=>a?f.createElement(oI,{options:xt,onClickHandler:u,style:h}):null,[a,u,h]);return f.createElement("div",{className:"button input-button"},f.createElement("img",{src:Le(n)}),f.createElement("input",{readOnly:!0,className:"input-number",type:"text",ref:l,onPointerUp:()=>{l.current&&(l.current.focus(),c(!a))}}),f.createElement("div",{className:"input-number-btns"},f.createElement("div",{className:"input-number-add",onPointerUp:()=>{u(r+1)}}),f.createElement("div",{className:"input-number-cut",onPointerUp:()=>{u(r-1)}})),g)},oI=o=>{const{options:n,style:e,onClickHandler:t}=o;return f.createElement("div",{className:"select-option-menu",style:e},n.map((i,r)=>f.createElement("div",{className:"select-option-btn",key:i,onPointerUp:()=>{t(r)}},i)))},sI=o=>{const{innerRatio:n,innerVerticeStep:e,vertices:t,mananger:i,setShapeOpt:r}=o,s=l=>{r({vertices:l}),ee.emitMethod(te.MainEngine,R.SetShapeOpt,{workIds:[Z],toolsType:T.Star,viewId:i.viewId,vertices:l})},a=l=>{r({innerVerticeStep:l}),ee.emitMethod(te.MainEngine,R.SetShapeOpt,{workIds:[Z],toolsType:T.Star,viewId:i.viewId,innerVerticeStep:l})},c=l=>{r({innerRatio:l}),ee.emitMethod(te.MainEngine,R.SetShapeOpt,{workIds:[Z],toolsType:T.Star,viewId:i.viewId,innerRatio:l})};return f.createElement(f.Fragment,null,f.createElement(ei,{value:t,icon:"polygon-vertex",min:3,max:100,step:1,onInputHandler:s}),f.createElement(ei,{value:e,icon:"star-innerVertex",min:1,max:100,step:1,onInputHandler:a}),f.createElement(nI,{value:n,icon:"star-innerRatio",min:.1,max:1,step:.1,onInputHandler:c}))},aI=o=>{const{mananger:n,vertices:e,setShapeOpt:t}=o,i=r=>{t({vertices:r}),ee.emitMethod(te.MainEngine,R.SetShapeOpt,{workIds:[Z],toolsType:T.Polygon,viewId:n.viewId,vertices:r})};return f.createElement(ei,{value:e,icon:"polygon-vertex",min:3,max:100,step:1,onInputHandler:i})},cI=o=>{const{mananger:n,placement:e,setShapeOpt:t}=o,i=r=>{t({placement:r}),ee.emitMethod(te.MainEngine,R.SetShapeOpt,{workIds:[Z],toolsType:T.SpeechBalloon,viewId:n.viewId,placement:r})};return f.createElement(rI,{value:e,icon:"speechBallon-placement",onChangeHandler:i})},Un=o=>{const{icon:n,isActive:e,onPointerUpHandler:t}=o;return f.createElement("div",{className:`button tab-button ${e?"active":""}`,onPointerUp:t},f.createElement("img",{src:Le(n)}))},lI=o=>{const{toolsTypes:n,style:e,mananger:t,shapeOpt:i,setShapeOpt:r}=o,[s,a]=f.useState();f.useEffect(()=>{n.includes(T.Polygon)?a(T.Polygon):n.includes(T.Star)?a(T.Star):a(T.SpeechBalloon)},[n]);const c=g=>{a(g)},l=f.useMemo(()=>s===T.Polygon&&t&&i.vertices?f.createElement(aI,{vertices:i.vertices,mananger:t,setShapeOpt:r}):null,[t,s,i,r]),u=f.useMemo(()=>s===T.Star&&t&&i.vertices&&i.innerVerticeStep&&i.innerRatio?f.createElement(sI,{mananger:t,vertices:i.vertices,innerVerticeStep:i.innerVerticeStep,innerRatio:i.innerRatio,setShapeOpt:r}):null,[t,s,i,r]),h=f.useMemo(()=>s===T.SpeechBalloon&&t&&i.placement?f.createElement(cI,{mananger:t,placement:i.placement,setShapeOpt:r}):null,[s,t,i.placement,r]);return f.createElement("div",{className:"shapeOpt-sub-menu",style:e,onPointerUp:nn},f.createElement("div",{className:"shapeOpt-sub-menu-tabs"},n.includes(T.Polygon)&&f.createElement(Un,{isActive:s===T.Polygon,icon:s===T.Polygon?"polygon-active":"polygon",onPointerUpHandler:c.bind(void 0,T.Polygon)})||null,n.includes(T.Star)&&f.createElement(Un,{isActive:s===T.Star,icon:s===T.Star?"star-active":"star",onPointerUpHandler:c.bind(void 0,T.Star)})||null,n.includes(T.SpeechBalloon)&&f.createElement(Un,{isActive:s===T.SpeechBalloon,icon:s===T.SpeechBalloon?"speechBallon-active":"speechBallon",onPointerUpHandler:c.bind(void 0,T.SpeechBalloon)})||null),f.createElement("div",{className:"shapeOpt-sub-menu-content"},l,u,h))},uI=o=>{const{open:n,setOpen:e,floatBarRef:t,toolsTypes:i,shapeOpt:r}=o,{floatBarData:s,mananger:a,setFloatBarData:c}=f.useContext(Ne),l=f.useRef(null),u=f.useMemo(()=>{if(t!=null&&t.current&&z.isNumber(s==null?void 0:s.x)&&z.isNumber(s==null?void 0:s.y)&&(a!=null&&a.height)){if(t.current.offsetTop&&t.current.offsetTop+s.y>200){const d={};return d.top="inherit",d.bottom=50,d}else if(!t.current.offsetTop&&(a==null?void 0:a.height)-t.current.offsetTop-(s==null?void 0:s.y)<140){const d={};return d.top="inherit",d.bottom=50,d}}},[t,s==null?void 0:s.x,s==null?void 0:s.y,a==null?void 0:a.height]),h=f.useCallback(d=>{c({shapeOpt:{...r,...d}})},[c,r]),g=f.useMemo(()=>n&&i&&a&&r?f.createElement(lI,{shapeOpt:r,style:u,toolsTypes:i,mananger:a,setShapeOpt:h}):null,[n,u,i,a,r,h]),p=()=>{e(!n)};return f.createElement("div",{ref:l,className:`button normal-button ${n&&"active"}`,onPointerUp:p},g,f.createElement("img",{alt:"icon",src:Le(n?"shapes-active":"shapes")}))},vo=f.memo(o=>{const{textOpt:n,workIds:e,noLayer:t,position:i,noDelete:r,noCopy:s}=o,{floatBarData:a,mananger:c}=f.useContext(Ne),[l,u]=f.useState(0),[h,g]=f.useState(),p=f.useRef(null);f.useEffect(()=>{var A,b,N,D;const x={},O=(a==null?void 0:a.w)||((A=n==null?void 0:n.boxSize)==null?void 0:A[0])||0,Y=(a==null?void 0:a.h)||((b=n==null?void 0:n.boxSize)==null?void 0:b[1])||0;if(i&&O&&Y&&(c!=null&&c.width)&&(c!=null&&c.height)){if(i.y<60?i.y+Y<c.height-60?x.bottom=-120:i.y+Y<c.height?x.bottom=-58:i.y>0?x.top=62:x.top=-i.y+62:x.top=0,i.x<0)x.left=-i.x+3;else if(i.x+(((N=p.current)==null?void 0:N.offsetWidth)||O)>c.width){const j=c.width-(((D=p.current)==null?void 0:D.offsetWidth)||O)-i.x;x.left=j}g(x);return}g(void 0)},[p,i,a==null?void 0:a.w,a==null?void 0:a.h,c==null?void 0:c.width,c==null?void 0:c.height,n==null?void 0:n.boxSize]);const d=f.useMemo(()=>a!=null&&a.fillColor?f.createElement($m,{floatBarRef:p,open:l===3,setOpen:x=>{u(x===!0?3:0)}}):null,[a==null?void 0:a.fillColor,l,p]),M=f.useMemo(()=>a!=null&&a.strokeColor?f.createElement(Fm,{floatBarRef:p,open:l===2,setOpen:x=>{u(x===!0?2:0)}}):null,[a==null?void 0:a.strokeColor,l,p]),w=f.useMemo(()=>n!=null&&n.fontColor&&(c!=null&&c.viewId)?f.createElement(Gm,{floatBarRef:p,open:l===4,setOpen:x=>{u(x===!0?4:0)},textOpt:n,workIds:e}):null,[n,l,e,c,p]),m=f.useMemo(()=>n!=null&&n.fontBgColor&&(c!=null&&c.viewId)?f.createElement(Qm,{floatBarRef:p,open:l===5,setOpen:x=>{u(x===!0?5:0)},textOpt:n,workIds:e}):null,[n,l,e,c,p]),y=f.useMemo(()=>n&&(c!=null&&c.viewId)?f.createElement(Jm,{floatBarRef:p,open:l===6,setOpen:x=>{u(x===!0?6:0)},textOpt:n,workIds:e,style:h}):null,[n,l,e,c,h,p]),S=f.useMemo(()=>n&&(c!=null&&c.viewId)?f.createElement(eI,{open:l===7,setOpen:x=>{u(x===!0?7:0)},textOpt:n,workIds:e,floatBarRef:p}):null,[n,l,e,c,p]),v=f.useMemo(()=>t?null:f.createElement(Ym,{open:l===1,setOpen:x=>{u(x===!0?1:0)},floatBarRef:p}),[t,l,p]),k=f.useMemo(()=>a!=null&&a.canLock&&c?f.createElement(tI,{workIds:e,mananger:c,islocked:a.isLocked}):null,[a,c,e]),C=f.useMemo(()=>c&&(c!=null&&c.viewId)&&h&&(a!=null&&a.shapeOpt)&&(a!=null&&a.toolsTypes)?f.createElement(uI,{open:l===8,setOpen:x=>{u(x===!0?8:0)},floatBarRef:p,workIds:e,toolsTypes:a.toolsTypes,shapeOpt:a.shapeOpt}):null,[a,c,l,h,e,p]);return f.createElement("div",{className:"appliance-plugin-floatbtns",style:h,ref:p},c&&!r&&f.createElement(Rm,{workIds:e,mananger:c}),v,k,!!(c!=null&&c.viewId)&&!s&&f.createElement(Um,{workIds:e,viewId:c.viewId}),C,y,S,w,m,M,d)}),hI=o=>{const{data:n,workId:e,updateOptInfo:t}=o,{opt:i,scale:r,translate:s,x:a,y:c}=n,l=f.useRef(null),{floatBarData:u}=f.useContext(Ne),h=f.useMemo(()=>{const{fontSize:d,fontFamily:M,underline:w,fontColor:m,lineThrough:y,textAlign:S,strokeColor:v,lineHeight:k,bold:C,italic:x}=i,O=k||d*1.2,Y={fontSize:`${d}px`,lineHeight:`${O}px`,color:"transparent",caretColor:m,borderColor:v,minHeight:`${O}px`,pointerEvents:"none",paddingRight:`${x==="italic"?Math.round(d*.3):5}px`};return M&&(Y.fontFamily=`${M}`),(y||w)&&(Y.textDecoration=`${y&&"line-through"||""}${w&&" underline"||""}`),S&&(Y.textAlign=`${S}`),C&&(Y.fontWeight=`${C}`),x&&(Y.fontStyle=`${x}`),Y},[i]),g=f.useMemo(()=>{const d=[];if(i.text){const M=zt(i.text);for(let w=0;w<M.length;w++){const m=M[w];m===""?d.push(f.createElement("div",{key:w})):d.push(f.createElement("div",{key:w},m))}}return d.length?d:f.createElement("div",null)},[i.text]),p=f.useMemo(()=>{if(!u)return{};const d=`scale(${r||1}) ${s&&"translate("+s[0]+"px,"+s[1]+"px)"||""}`;return{left:`${a-u.x}px`,top:`${c-u.y}px`,zIndex:1,transform:d,transformOrigin:"left top",opacity:0,pointerEvents:"auto"}},[r,s,a,c,u]);return f.useEffect(()=>{if(!l.current)return;const d=l.current.offsetWidth,M=l.current.offsetHeight;if(!d||!M)return;const w=i.boxSize;if((w==null?void 0:w[0])!==d||w[1]!==M||!w){t({activeTextId:e,update:{boxSize:[d,M],workState:E.Done}});return}},[i.fontSize,i.italic,i.bold,i.boxSize,e,t]),f.createElement("div",{className:"editor-box readonly","data-text-work-id":e,style:p},f.createElement("div",{className:"editor",ref:l,style:h},g))},dI=o=>{const{mananger:n}=f.useContext(Ne),e=f.useMemo(()=>{var i;const t=r=>{var u,h;if(!n)return;const{activeTextId:s,update:a,syncData:c}=r,l=s&&z.cloneDeep(((u=n.control.textEditorManager)==null?void 0:u.get(s))||((h=o.editors)==null?void 0:h.get(s)));l&&l.opt&&(l.opt={...l.opt,...a},c&&(l.canSync=Object.keys(c).includes("canSync")&&c.canSync||l.canSync,l.canWorker=Object.keys(c).includes("canWorker")&&c.canWorker||l.canWorker),n.control.textEditorManager.updateForViewEdited(s,l))};if((i=o.editors)!=null&&i.size){const r=[];return o.editors.forEach((s,a)=>{if(o.selectIds&&o.selectIds.includes(a)){const c=f.createElement(hI,{key:a,workId:a,data:s,updateOptInfo:t});r.push(c)}}),r}return null},[o.editors,o.selectIds,n]);return f.createElement(f.Fragment,null,e)},gI=o=>{const{position:n,textOpt:e,workIds:t,noLayer:i,noCopy:r,noDelete:s,style:a}=o,c=f.useRef(null);return f.createElement("div",{className:be.FloatBarBtn,ref:c,style:a},f.createElement(vo,{position:n,textOpt:e,workIds:t,noLayer:i,noCopy:r,noDelete:s}))},fI=o=>{const{data:n,workId:e,showFloatBtns:t,handleKeyUp:i,handleFocus:r,runAnimation:s,updateSize:a,rightBoundBreak:c}=o,{activeTextEditor:l,activeTextId:u,mananger:h}=f.useContext(Ne),{opt:g,scale:p,translate:d,x:M,y:w}=n,{fontSize:m,fontFamily:y,underline:S,fontColor:v,lineThrough:k,textAlign:C,lineHeight:x,bold:O,italic:Y}=g,A=f.useRef(null),b=f.useMemo(()=>{const q=m,_=x||q*1.2,ne={fontSize:`${q}px`,lineHeight:`${_}px`,caretColor:v,color:"transparent",minHeight:`${_}px`,paddingRight:`${Y==="italic"?Math.round(q*.3):5}px`,borderWidth:0};return y&&(ne.fontFamily=`${y}`),(k||S)&&(ne.textDecoration=`${k&&"line-through"||""} ${S&&" underline"||""}`),C&&(ne.textAlign=`${C}`),O&&(ne.fontWeight=`${O}`),Y&&(ne.fontStyle=`${Y}`),ne},[O,v,y,m,Y,x,k,p,C,S]),N=f.useRef(!1),D=f.useRef(6),j=f.useRef(),B=f.useRef(),V=f.useRef(!1),U=f.useRef(!1),H=f.useRef({fontSize:b.fontSize,lineHeight:b.lineHeight,fontStyle:b.fontStyle,fontWeight:b.fontWeight,fontFamily:b.fontFamily}),G=f.useMemo(()=>typeof window>"u"?!1:navigator.maxTouchPoints>0||"ontouchstart"in window,[]),$=f.useMemo(()=>u===e?"hover":g.workState===E.Doing||g.workState===E.Start?"editing":l?"active":"none",[u,e,g.workState,l]);function X(q){if(!A.current)return;const ne=q&&_y(q.nativeEvent)?mo(q.nativeEvent):void 0,ae=()=>{j.current&&(cancelAnimationFrame(j.current),j.current=void 0),B.current&&(window.clearTimeout(B.current),B.current=void 0)},me=pe=>{const Ce=A.current,Ie=window==null?void 0:window.getSelection();if(!(!Ce||!Ie||!V.current)){if(document.activeElement!==Ce)try{Ce.focus({preventScroll:!0})}catch{Ce.focus()}if(pe){const{x:xe,y:ze}=pe;if(document.caretPositionFromPoint){const he=document.caretPositionFromPoint(xe,ze);if(he){const ge=document.createRange();ge.setStart(he.offsetNode,he.offset),ge.collapse(!0),Ie.removeAllRanges(),Ie.addRange(ge),U.current=!0;return}}else if(document.caretRangeFromPoint){const he=document.caretRangeFromPoint(xe,ze);if(he){Ie.removeAllRanges(),Ie.addRange(he),U.current=!0;return}}}_M({hasPoint:!!pe,previousByPoint:U.current,hasSelectionInEditor:cr(Ie,Ce),rangeCount:Ie.rangeCount,isCollapsed:Ie.isCollapsed})||(JM(Ie,Ce),U.current=!1)}};ae(),me(ne),G&&(j.current=requestAnimationFrame(()=>{me(),B.current=window.setTimeout(()=>{me(),B.current=void 0},32),j.current=void 0}))}const Te=f.useMemo(()=>{const q=`scale(${p||1}) ${d&&"translate("+d[0]+"px,"+d[1]+"px)"||""}`;return{left:`${M-Zn*(p||1)}px`,top:`${w-Zn*(p||1)}px`,zIndex:2,transform:q,transformOrigin:"left top",borderColor:$==="editing"||$==="hover"?v:"transparent"}},[p,d,M,w,v,$]),se=f.useMemo(()=>{let q="";const _="<div></div>";if(g.text){const ne=zt(g.text);for(let ae=0;ae<ne.length;ae++){const me=ne[ae];if(me==="")q=q+_;else{const pe=me.replace(/[<>&]/g,Ce=>({"<":"&lt;",">":"&gt;","&":"&amp;"})[Ce]);q=q+`<div>${pe}</div>`}}}else q=_;return q},[g.fontBgColor,g.text]),fe=f.useMemo(()=>{var q,_;if($==="hover"){if(p&&t&&z.isNumber(M)&&z.isNumber(w)&&g.boxSize&&z.isNumber((q=g.boxSize)==null?void 0:q[0])&&z.isNumber((_=g.boxSize)==null?void 0:_[1])){const ne={x:M,y:w},ae={left:M,top:w,width:g.boxSize[0]*p,height:g.boxSize[1]*p};return f.createElement(gI,{position:ne,style:ae,textOpt:g,workIds:[e],noLayer:!0,noCopy:!0,noDelete:!0})}return null}return null},[g,t,e,M,w,p,$]);f.useEffect(()=>{V.current=u===e,u!==e&&(j.current&&(cancelAnimationFrame(j.current),j.current=void 0),B.current&&(window.clearTimeout(B.current),B.current=void 0),U.current=!1)},[u,e]),f.useEffect(()=>{if(u===e&&A.current){const q=window==null?void 0:window.getSelection(),_=cr(q,A.current);(document.activeElement!==A.current||!_)&&X(),r(A.current)}},[u,r,e,G]),f.useEffect(()=>{var ae,me,pe,Ce,Ie,xe;const q=A.current;if(!q)return;const _=go(q),ne=g.text||"";_!==ne&&(u===e&&N.current||(console.info("[appliance-plugin]",{target:"text-box.sync-dom-from-props",workId:e,activeTextId:u,workState:g.workState,currentTextLength:(pe=(me=(ae=zt(_))==null?void 0:ae.join)==null?void 0:me.call(ae,""))==null?void 0:pe.length,expectedTextLength:(xe=(Ie=(Ce=zt(ne))==null?void 0:Ce.join)==null?void 0:Ie.call(Ce,""))==null?void 0:xe.length,currentBoxSize:[q.offsetWidth,q.offsetHeight],expectedBoxSize:g.boxSize}),q.innerHTML=se))},[u,se,g.boxSize,g.text,g.workState,e]),f.useEffect(()=>()=>{j.current&&cancelAnimationFrame(j.current),B.current&&window.clearTimeout(B.current)},[]),f.useEffect(()=>{if(A.current){const q=parseInt(getComputedStyle(A.current).paddingRight,10)+parseInt(getComputedStyle(A.current).borderWidth,10);D.current=Number(q)}},[]),f.useEffect(()=>{if(A.current){const q={fontSize:b.fontSize,lineHeight:b.lineHeight,fontStyle:b.fontStyle,fontWeight:b.fontWeight,fontFamily:b.fontFamily};if(!z.isEqual(H.current,q)){H.current=q;const _=[A.current.offsetWidth,A.current.offsetHeight];a(e,_)}}},[b,e,a,$,l,u]);const le=f.useCallback(q=>{const _=h==null?void 0:h.parentElement,ne=A.current;if(!_||!ne||!c)return!1;const{lastLine:ae}=lr(ne);if(!ae||ae instanceof Text)return!1;const me=ae==null?void 0:ae.getBoundingClientRect(),pe=_==null?void 0:_.getBoundingClientRect();if(!me||!pe)return!1;if(me.right+q>pe.right){const{textContent:Ce,textNodes:Ie}=XM(ae);if(!Ie.length)return!1;const xe=Ce.length,ze=Zt(Ie,0);if(!ze)return!1;let he=0,ge=0,K=xe;for(;ge<K;){const de=Math.floor((ge+K)/2),ke=Zt(Ie,de);if(!ke)break;const We=document.createRange();We.setStart(ze.node,ze.offset),We.setEnd(ke.node,ke.offset);const on=We.getBoundingClientRect(),ki=pe.right-on.right;if(ki<q){if(de>0){const ft=Zt(Ie,de-1);if(!ft)break;const pt=document.createRange();pt.setStart(ze.node,ze.offset),pt.setEnd(ft.node,ft.offset);const Gt=pt.getBoundingClientRect();if(pe.right-Gt.right>=q){he=de-1;break}}K=de}else{const ft=de+1;if(ft<xe){const pt=Zt(Ie,ft);if(!pt)break;const Gt=document.createRange();Gt.setStart(ze.node,ze.offset),Gt.setEnd(pt.node,pt.offset);const xi=Gt.getBoundingClientRect();if(pe.right-xi.right<=q&&ki>q){he=de;break}}ge=ft}}if(!he){const de=Zt(Ie,ge);if(!de)return!1;const ke=document.createRange();ke.setStart(ze.node,ze.offset),ke.setEnd(de.node,de.offset);const We=ke.getBoundingClientRect();pe.right-We.right>q?he=ge:ge>0&&(he=ge-1)}if(he>0){const de=Ce.slice(0,he),ke=Ce.slice(he);ae.textContent=de;const We=document.createElement("div");return ke&&(We.textContent=ke),A.current.appendChild(We),le(q),!0}}return!1},[h==null?void 0:h.parentElement,g.fontBgColor,c,e]);function nt(q){if(q.stopPropagation(),q.nativeEvent.stopImmediatePropagation(),q.key==="Backspace"){const _=window.getSelection(),ne=_==null?void 0:_.getRangeAt(0);if(ne!=null&&ne.collapsed)return q.cancelable&&q.preventDefault(),document.execCommand("delete",!1),!1}return!1}function ut(q,_){const ne=window==null?void 0:window.getSelection();if(ne!=null&&ne.rangeCount&&q&&ne&&ne.anchorNode){const ae=ne.anchorOffset,me=ne.anchorNode.textContent||"",pe=me.slice(0,ae)||"",Ce=me.slice(ae)||"",Ie=pe.concat(q)||"";ht(Ie,Ce,_)}}function ht(q,_,ne){const ae=window==null?void 0:window.getSelection();if(!(ae!=null&&ae.rangeCount)||!ae.anchorNode)return;const me=q.split(/\n/);let pe=ae.anchorNode.parentNode;pe===ne&&(pe=ae.anchorNode);const Ce=[...ne.childNodes],Ie=[];let xe,ze=ae.anchorOffset;for(;Ce.length;){const he=Ce.pop();if(he){if(he===pe){let ge=me[0];me.length===1&&(ze=me[0].length,ge=me[0].concat(_)),pe.nodeName==="#text"?(pe.textContent=ge,xe=pe):pe.nodeName==="DIV"&&(pe.innerText=ge,xe=pe.childNodes[0]);break}Ie.push(he),ne.removeChild(he)}}if(me.length>1)for(let he=1;he<me.length;he++){let ge=me[he];const K=document.createElement("div");he===me.length-1&&(ze=ge.length,ge=ge.concat(_)),K.innerText=ge,ne.appendChild(K),he===me.length-1&&(xe=K.childNodes[0])}if(Ie.length){Ie.reverse();for(const he of Ie)ne.appendChild(he)}if(xe&&xe.nodeName==="#text"){ae.deleteFromDocument();const he=document.createRange(),ge=Math.min(ze,(xe==null?void 0:xe.length)||0);he.setStart(xe,ge),he.collapse(!0),ae.removeAllRanges(),ae.addRange(he)}}function dt(q){if(q.cancelable&&q.preventDefault(),q.stopPropagation(),q.nativeEvent.stopImmediatePropagation(),A.current){const _=(q.clipboardData||window.clipboardData).getData("text"),ne=window==null?void 0:window.getSelection();if(!(ne!=null&&ne.rangeCount))return;if(_&&ne&&ne.anchorNode){const ae=Bn(_,{whiteList:{},stripIgnoreTag:!0,stripIgnoreTagBody:["script"]});ut(ae,A.current),le((p||1)*D.current),i(A.current)}s()}return!1}function gt(q){lr(q)}const De=f.useCallback(()=>{const q=A.current;s(()=>{if(q){if(gt(q),!N.current&&le((p||1)*D.current)){const _=window.getSelection();if(!(_!=null&&_.rangeCount))return!1;const ne=document.createRange(),ae=A.current.lastChild;ne.selectNodeContents(ae),ne.collapse(!1),_.removeAllRanges(),_.addRange(ne)}i(q)}})},[s,i,le,p]);function Pe(){N.current=!0,s()}function it(){N.current=!1,De()}function Ft(){De(),s()}const $t=f.useCallback(()=>{if($==="active"&&A.current&&A.current.parentElement){const q=A.current.parentElement;q.style.borderColor=v}},[$,v]),rn=f.useCallback(()=>{if($==="active"&&A.current&&A.current.parentElement){const q=A.current.parentElement;q.style.borderColor="transparent"}},[$]);return f.createElement(f.Fragment,null,fe,f.createElement("div",{className:`editor-box ${$}`,style:Te,onPointerUp:()=>{var q;if($==="editing"){s(()=>{var _;(_=document.activeElement)==null||_.blur(),h==null||h.control.textEditorManager.checkEmptyTextBlur()});return}if($==="active"&&h){if((q=h.control.collector)!=null&&q.hasIncludeSelector(e)){s(()=>{var _;(_=document.activeElement)==null||_.blur(),h==null||h.control.textEditorManager.checkEmptyTextBlur()});return}if(h&&u!==e){h.control.textEditorManager.checkEmptyTextBlur(),h.control.textEditorManager.active(e,h.worker.now);return}}},onMouseOver:$t,onMouseLeave:rn},f.createElement("div",{id:e,suppressContentEditableWarning:!0,contentEditable:!0,className:"editor",ref:A,style:b,onKeyDown:nt,onPaste:dt,onTouchEnd:X,onInput:De,onCompositionStart:Pe,onCompositionUpdate:Ft,onCompositionEnd:it,dangerouslySetInnerHTML:{__html:se}})))},pI=o=>{const n=f.useRef(null),{mananger:e}=f.useContext(Ne),t=f.useRef(),i=f.useCallback(s=>{var h,g;const{activeTextId:a,update:c,syncData:l}=s;if(!e)return;const u=a&&z.cloneDeep(((h=e.control.textEditorManager)==null?void 0:h.get(a))||((g=o.editors)==null?void 0:g.get(a)));u&&u.opt&&(u.opt={...u.opt,...c},l&&(u.canSync=Object.keys(l).includes("canSync")&&l.canSync||u.canSync,u.canWorker=Object.keys(l).includes("canWorker")&&l.canWorker||u.canWorker),e.control.textEditorManager.updateForViewEdited(a,u))},[e,o.editors]),r=f.useMemo(()=>{var u;const s=h=>{var w,m,y,S,v;if(!e)return;const g=h.id,p=e.control.textEditorManager.get(g),d=E.Doing,M=[h.offsetWidth,h.offsetHeight];console.info("[appliance-plugin]",{target:"text-box.handleFocus",workId:g,oldWorkState:(w=p==null?void 0:p.opt)==null?void 0:w.workState,oldBoxSize:(m=p==null?void 0:p.opt)==null?void 0:m.boxSize,oldTextLength:(S=(y=p==null?void 0:p.opt)==null?void 0:y.text)==null?void 0:S.length,measuredBoxSize:M,domTextLength:(v=h.innerText)==null?void 0:v.length}),(!p||p&&(!z.isEqual(p.opt.boxSize,M)||!z.isEqual(p.opt.workState,d)))&&i({activeTextId:g,update:{boxSize:M,workState:d},syncData:{canSync:!0,canWorker:!0}})},a=h=>{var y,S;if(!e)return;const g=ho(h),p=h.id,d=e.control.textEditorManager.get(p),M=go(h),w=E.Doing,m=[h.offsetWidth,h.offsetHeight];if(!d||d&&(d.opt.text!==M||!z.isEqual(d.opt.boxSize,m)||!z.isEqual(d.opt.workState,w))){const v=p&&z.cloneDeep(((y=e.control.textEditorManager)==null?void 0:y.get(p))||((S=o.editors)==null?void 0:S.get(p)));v&&v.opt&&(v.opt={...v.opt,text:M,boxSize:m,workState:w},v.canSync=!0,v.canWorker=!0,e.control.textEditorManager.updateForViewEdited(p,v)),e.control.textEditorManager.publicMsgEmitter.emit("textChange",p,h,g,v)}},c=(h,g)=>{var M;if(!e)return;const p=h,d=e.control.textEditorManager.get(p);if(d&&(console.info("[appliance-plugin]",{target:"text-box.updateSize",workId:p,oldBoxSize:d.opt.boxSize,oldTextLength:(M=d.opt.text)==null?void 0:M.length,measuredBoxSize:g}),!(!g[0]||!g[1])&&!z.isEqual(d.opt.boxSize,g))){const w=z.cloneDeep(d);w.opt={...w.opt,boxSize:g},w.canSync=!1,w.canWorker=!1,e.control.textEditorManager.updateForViewEdited(p,w)}},l=h=>{t.current&&cancelAnimationFrame(t.current),t.current=requestAnimationFrame(()=>{n!=null&&n.current&&(n==null||n.current.scrollTo({left:0,behavior:"instant"}),h&&h(),t.current=void 0)})};if((u=o.editors)!=null&&u.size){const h=[];return o.editors.forEach((g,p)=>{h.push(f.createElement(fI,{key:p,workId:p,data:g,showFloatBtns:o.showFloatBtns||!1,handleFocus:s,handleKeyUp:a,updateSize:c,runAnimation:l,rightBoundBreak:o.rightBoundBreak||!1}))}),h}return null},[o.editors,o.showFloatBtns,o.rightBoundBreak,e,i]);return f.createElement("div",{className:`${o.className}`,ref:n},r)},$e=(o,n,e)=>({...o,...e==null?void 0:e[n]}),MI=()=>{const{floatBarData:o,overwriteSelectorStyles:n}=f.useContext(Ne),e={borderColor:o==null?void 0:o.selectorColor,...n.highlightBox},t={backgroundColor:o==null?void 0:o.selectorColor,...n.highlightBoxPoint};return f.createElement("div",{className:"appliance-plugin-highlight-box",style:e},f.createElement("div",{className:"point LT nwse-resize",style:$e(t,"LT",n.highlightBoxPoints)}),f.createElement("div",{className:"point LC ew-resize",style:$e(t,"LC",n.highlightBoxPoints)}),f.createElement("div",{className:"point LB nesw-resize",style:$e(t,"LB",n.highlightBoxPoints)}),f.createElement("div",{className:"point TC ns-resize",style:$e(t,"TC",n.highlightBoxPoints)}),f.createElement("div",{className:"point RT nesw-resize",style:$e(t,"RT",n.highlightBoxPoints)}),f.createElement("div",{className:"point RC ew-resize",style:$e(t,"RC",n.highlightBoxPoints)}),f.createElement("div",{className:"point RB nwse-resize",style:$e(t,"RB",n.highlightBoxPoints)}),f.createElement("div",{className:"point BC ns-resize",style:$e(t,"BC",n.highlightBoxPoints)}))},yI=()=>{const{floatBarData:o,mananger:n,overwriteSelectorStyles:e}=f.useContext(Ne),[t,i]=f.useState(),[r,s]=f.useState();f.useEffect(()=>{const l=[];if(n&&z.isNumber(o==null?void 0:o.x)&&z.isNumber(o==null?void 0:o.y)&&(o!=null&&o.points)){const u=n.viewId;if(n.control.viewContainerManager.getView(u))for(const g of o.points){const p=n.control.viewContainerManager.transformToOriginPoint(g,u);l.push(p)}l[0]&&i({x:l[0][0]-((o==null?void 0:o.x)||0),y:l[0][1]-((o==null?void 0:o.y)||0)}),l[1]&&s({x:l[1][0]-((o==null?void 0:o.x)||0),y:l[1][1]-((o==null?void 0:o.y)||0)})}},[n,o==null?void 0:o.points,o==null?void 0:o.x,o==null?void 0:o.y]);const a=f.useMemo(()=>t?f.createElement("div",{className:"point point-dot",style:{borderColor:o==null?void 0:o.selectorColor,...e.highlightBoxPoint,...e.highlightBoxPointDot,left:t.x,top:t.y}}):null,[o==null?void 0:o.selectorColor,t]),c=f.useMemo(()=>r?f.createElement("div",{className:"point point-dot",style:{borderColor:o==null?void 0:o.selectorColor,...e.highlightBoxPoint,...e.highlightBoxPointDot,left:r.x,top:r.y}}):null,[r,o==null?void 0:o.selectorColor]);return f.createElement("div",{className:"appliance-plugin-highlight-box",style:{borderColor:o==null?void 0:o.selectorColor,...e.highlightBox}},a,c)},mI=()=>{const{floatBarData:o,overwriteSelectorStyles:n}=f.useContext(Ne),e={borderColor:o==null?void 0:o.selectorColor,...n.highlightBox},t={backgroundColor:o==null?void 0:o.selectorColor,...n.highlightBoxPoint};return f.createElement("div",{className:"appliance-plugin-highlight-box",style:e},f.createElement("div",{className:"point LT nwse-resize",style:$e(t,"LT",n.highlightBoxPoints)}),f.createElement("div",{className:"point LB nesw-resize",style:$e(t,"LB",n.highlightBoxPoints)}),f.createElement("div",{className:"point RT nesw-resize",style:$e(t,"RT",n.highlightBoxPoints)}),f.createElement("div",{className:"point RB nwse-resize",style:$e(t,"RB",n.highlightBoxPoints)}))},II=()=>{const{floatBarData:o,overwriteSelectorStyles:n}=f.useContext(Ne);return f.createElement("div",{className:"appliance-plugin-highlight-box",style:{borderColor:o==null?void 0:o.selectorColor,...n.highlightBox}},f.createElement("img",{className:"lock",alt:"lock",src:"https://sdk.netless.link/resource/icons/lock.svg",style:n.highlightBoxLock}))},wI=o=>{const{className:n}=o,{floatBarData:e,angle:t,setAngle:i,setOperationType:r,mananger:s}=f.useContext(Ne),[a,c]=f.useState(E.Pending),[l,u]=f.useState(),[h,g]=f.useState(!1),[p,d]=f.useState(new Me),[M,w]=f.useState(new Me),[m,y]=f.useState(!1),S=f.useRef(0),v=f.useRef(null),k=(b,N)=>{i(b),r(N===E.Done?R.None:R.RotateNode),c(N),N===E.Done?(g(!1),s==null||s.focusElement()):g(!0),ee.emitMethod(te.MainEngine,R.RotateNode,{workIds:[Z],angle:N===E.Start?0:b,workState:N,viewId:s==null?void 0:s.viewId})},C=b=>{if(!b){y(!0),g(!1),r(R.None),c(E.Pending);return}y(!1)},x=(b,N)=>{S.current&&(clearTimeout(S.current),S.current=0),c(E.Done),g(!1);const D=Math.round(Me.GetAngleByPoints(p,M,new Me(N.x,N.y)))||0;k(D,E.Done)};f.useEffect(()=>(ee.activeListener(C),()=>{ee.unmountActiveListener(C)}),[]),f.useEffect(()=>{if(window.__selectorE2E__)return window.__selectorRotateE2E__={start:(b=p.x,N=p.y)=>{if(s!=null&&s.control.worker.isBusy){y(!0),c(E.Pending);return}const D=Math.round(Me.GetAngleByPoints(p,M,new Me(b,N)))||0;k(D,E.Start)},doing:(b,N)=>{if(s!=null&&s.control.worker.isBusy){y(!0);return}const D=Math.round(Me.GetAngleByPoints(p,M,new Me(b,N)))||0;u({x:b,y:N}),k(D,E.Doing)},done:(b,N)=>{const D=Math.round(Me.GetAngleByPoints(p,M,new Me(b,N)))||0;u({x:b,y:N}),k(D,E.Done)}},()=>{window.__selectorRotateE2E__&&delete window.__selectorRotateE2E__}},[M,s,p]),f.useEffect(()=>{if(e&&(a===E.Pending||a===E.Done)){const b={x:(e==null?void 0:e.x)-20,y:(e==null?void 0:e.y)+(e==null?void 0:e.h)},N={x:(e==null?void 0:e.x)+(e==null?void 0:e.w)/2,y:(e==null?void 0:e.y)+(e==null?void 0:e.h)/2};w(new Me(N.x,N.y)),d(new Me(b.x,b.y)),u({x:b.x,y:b.y})}},[e,a]);const O=(b,N)=>{if(s!=null&&s.control.worker.isBusy){y(!0),c(E.Pending);return}S.current&&(clearTimeout(S.current),S.current=0),c(E.Start),g(!0);const D=Math.round(Me.GetAngleByPoints(p,M,new Me(N.x,N.y)))||0;k(D,E.Start)},Y=(b,N)=>{if(s!=null&&s.control.worker.isBusy){y(!0),x(b,N);return}x(b,N)},A=(b,N)=>{if(s!=null&&s.control.worker.isBusy){y(!0),x(b,N);return}S.current||(u({x:N.x,y:N.y}),g(!0),S.current=setTimeout(()=>{S.current=0;const D=Math.round(Me.GetAngleByPoints(p,M,new Me(N.x,N.y)))||0;k(D,E.Doing)},60))};return f.createElement(Ot,{disabled:m,position:l,onStart:O,onDrag:A,onStop:Y},f.createElement("div",{className:`${n}`,style:e?{left:0,top:0,touchAction:"none"}:void 0},!h&&f.createElement("div",{className:"appliance-plugin-rotate-btn",style:{backgroundColor:e==null?void 0:e.selectorColor}},f.createElement("img",{alt:"icon",src:Le("rotation-button")})),f.createElement("div",{ref:v,className:`appliance-plugin-rotate-mouse-pointer ${h?"active":""}`},f.createElement("img",{alt:"icon",src:Le("rotation")}),f.createElement("div",{className:"angle-icon"},t,"°"))))};function TI(o){const n=o==null?void 0:o.viewId;if(!n)return;const e=o.control.viewContainerManager.getView(n),t=e==null?void 0:e.focusScenePath,i=o.control.viewContainerManager.getUndoTickerId(n);!i||!t||(o.control.internalMsgEmitter.emit("cancelUndoTicker",i,n,t),o.control.worker.abled())}function SI(o,n){const e=o.control.worker.now;return o.control.textEditorManager.active(n,e),e}const vI="data-text-work-id";function NI(o){var n,e;if(o instanceof HTMLElement)return((e=(n=o.closest(`[${vI}]`))==null?void 0:n.dataset)==null?void 0:e.textWorkId)||void 0}const CI=f.memo(o=>{const{editors:n,canSelectorSwitch:e}=o,{floatBarData:t,setOperationType:i,mananger:r,isNoPointerEvents:s}=f.useContext(Ne),[a,c]=f.useState(),[l,u]=f.useState(!1),h=f.useRef(0),g=f.useRef(),p=f.useRef(E.Pending),d=f.useMemo(()=>!!((t==null?void 0:t.scaleType)===Oe.none&&(t!=null&&t.canLock)),[t]),M=f.useMemo(()=>t&&t.w&&t.h?{position:"absolute",left:0,top:0,width:t.w,height:t.h,zIndex:2,pointerEvents:d||s?"none":"auto",touchAction:"none"}:{display:"none",pointerEvents:"none"},[t,d,s]),w=k=>{if(!k||t!=null&&t.isLocked){u(!0),p.current=E.Pending,i(R.None);return}u(!1)},m=(k,C)=>{h.current&&(clearTimeout(h.current),h.current=0);const x={x:C.x,y:C.y};i(R.None),p.current=E.Done,c(x),ee.emitMethod(te.MainEngine,R.TranslateNode,{workIds:[Z],position:x,workState:E.Done,viewId:r==null?void 0:r.viewId})};f.useEffect(()=>(ee.activeListener(w),()=>{ee.unmountActiveListener(w)}),[]),f.useEffect(()=>{if(t&&(t!=null&&t.isLocked)||r!=null&&r.control.worker.isBusy){u(!0);return}u(!1)},[t,r==null?void 0:r.control.worker.isBusy]),f.useEffect(()=>{(p.current===E.Pending||p.current===E.Done)&&z.isNumber(t==null?void 0:t.x)&&z.isNumber(t==null?void 0:t.y)&&c({x:t==null?void 0:t.x,y:t==null?void 0:t.y})},[t==null?void 0:t.x,t==null?void 0:t.y]);const y=k=>{const C=k&&"target"in k?k.target:null,x=e?NI(C):void 0;if(r!=null&&r.control.worker.isBusy){u(!0);return}h.current&&(clearTimeout(h.current),h.current=0),g.current=x,z.isNumber(t==null?void 0:t.x)&&z.isNumber(t==null?void 0:t.y)&&(i(R.TranslateNode),p.current=E.Start,ee.emitMethod(te.MainEngine,R.TranslateNode,{workIds:[Z],position:{x:t==null?void 0:t.x,y:t==null?void 0:t.y},workState:E.Start,viewId:r==null?void 0:r.viewId}))},S=(k,C)=>{var A,b;r!=null&&r.control.worker.isBusy&&u(!0);const x=p.current,O=g.current;if(!!O&&x===E.Start&&r&&e){TI(r),SI(r,O),g.current=void 0,p.current=E.Pending,i(R.None);const N=(A=r.control.viewContainerManager.getView(r.viewId))==null?void 0:A.focusScenePath;N&&r.control.worker.blurSelector(r.viewId,N);return}if(m(k,C),g.current&&(g.current=void 0),x===E.Start&&(n!=null&&n.size)&&O){const N=(b=r==null?void 0:r.control.viewContainerManager.getView(r.viewId))==null?void 0:b.focusScenePath;N&&(r==null||r.control.worker.blurSelector(r.viewId,N))}r==null||r.focusElement()},v=(k,C)=>{if(r!=null&&r.control.worker.isBusy){u(!0),m(k,C);return}if(h.current)return;const x={x:C.x,y:C.y};c(x),h.current=setTimeout(()=>{h.current=0,(x.x!==(a==null?void 0:a.x)||x.y!==(a==null?void 0:a.y))&&(g.current&&(g.current=void 0),p.current=E.Doing,ee.emitMethod(te.MainEngine,R.TranslateNode,{workIds:[Z],position:x,workState:E.Doing,viewId:r==null?void 0:r.viewId}))},60)};return f.createElement(Ot,{disabled:l,position:a,onStart:y,onDrag:v,onStop:S},f.createElement("div",{style:M},f.createElement(kI,{editors:n,selectIds:(t==null?void 0:t.selectIds)||[]})))},(o,n)=>!!z.isEqual(o,n)),kI=f.memo(o=>{const{editors:n,selectIds:e}=o;return n?f.createElement(dI,{editors:n,selectIds:e||[]}):null},(o,n)=>!(!z.isEqual(o.editors,n.editors)||!z.isEqual(o.selectIds,n.selectIds))),xI=o=>{const{className:n}=o,[e,t]=f.useState({x:0,y:0,h:0,w:0}),[i,r]=f.useState(),[s,a]=f.useState(),[c,l]=f.useState(),{floatBarData:u,mananger:h,isNoPointerEvents:g,setOperationType:p}=f.useContext(Ne),[d,M]=f.useState(),[w,m]=f.useState(!1),y=f.useRef(0);f.useEffect(()=>{if(u&&h){const b={x:u.x,y:u.y,w:u.w,h:u.h};t(b)}return ee.activeListener(v),()=>{ee.unmountActiveListener(v)}},[]),f.useEffect(()=>{if(h!=null&&h.control.worker.isBusy){m(!0);return}m(!1)},[h==null?void 0:h.control.worker.isBusy]);const S=()=>{if(y.current&&(clearTimeout(y.current),y.current=0),d){const{scale:b,translate:N}=d;p(R.None),ee.emitMethod(te.MainEngine,R.ScaleNode,{workIds:[Z],scale:b,dir:c,translate:N,originPoint:i,scenePoint:s,workState:E.Done,viewId:h==null?void 0:h.viewId})}h==null||h.focusElement()},v=b=>{if(!b){m(!0);return}m(!1)},k=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]],C=(b,N)=>{switch(N){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]}},x=(b,N,D,j)=>{let B=!1,V=!1;const U={x:e.x,y:e.y,w:e.w,h:e.h},H=[1,1],G=[0,0];switch(b){case"top":{const se=N.height+e.h;se<0?(V=!0,U.y=e.y+e.h,U.h=Math.abs(se)):(U.y=e.y-N.height,U.h=e.h+N.height);break}case"topLeft":{const se=N.width+e.w;se<0?(B=!0,U.x=e.x+e.w,U.w=Math.abs(se)):(U.x=e.x-N.width,U.w=e.w+N.width);const fe=N.height+e.h;fe<0?(V=!0,U.y=e.y+e.h,U.h=Math.abs(fe)):(U.y=e.y-N.height,U.h=e.h+N.height);break}case"topRight":{const se=N.width+e.w;se<0?(B=!0,U.x=e.x+se,U.w=Math.abs(se)):U.w=e.w+N.width;const fe=N.height+e.h;fe<0?(V=!0,U.y=e.y+e.h,U.h=Math.abs(fe)):(U.y=e.y-N.height,U.h=e.h+N.height);break}case"bottom":{const se=N.height+e.h;se<0?(V=!0,U.y=e.y+se,U.h=Math.abs(se)):U.h=e.h+N.height;break}case"bottomLeft":{const se=N.width+e.w;se<0?(B=!0,U.x=e.x+e.w,U.w=Math.abs(se)):(U.x=e.x-N.width,U.w=e.w+N.width);const fe=N.height+e.h;fe<0?(V=!0,U.y=e.y+fe,U.h=Math.abs(fe)):U.h=e.h+N.height;break}case"left":{const se=N.width+e.w;se<0?(B=!0,U.x=e.x+e.w,U.w=Math.abs(se)):(U.x=e.x-N.width,U.w=e.w+N.width);break}case"bottomRight":{const se=N.width+e.w;se<0?(B=!0,U.x=e.x+se,U.w=Math.abs(se)):U.w=e.w+N.width;const fe=N.height+e.h;fe<0?(V=!0,U.y=e.y+fe,U.h=Math.abs(fe)):U.h=e.h+N.height;break}case"right":{const se=N.width+e.w;se<0?(B=!0,U.x=e.x+se,U.w=Math.abs(se)):U.w=e.w+N.width;break}}H[0]=U.w/e.w,H[1]=U.h/e.h;const X=k(U).map(se=>D.control.viewContainerManager.transformToScenePoint(se,D.viewId)),Te=C(X,b);return V&&(G[1]=Te[1]-j[1]),B&&(G[0]=Te[0]-j[0]),{scale:H,translate:G}},O=(b,N)=>{if(y.current&&(clearTimeout(y.current),y.current=0),h!=null&&h.control.worker.isBusy){m(!0);return}if(u!=null&&u.w&&(u!=null&&u.h)&&h){const D={x:u.x,y:u.y,w:u.w,h:u.h},j=k(D),B=j.map(H=>h.control.viewContainerManager.transformToScenePoint(H,h.viewId)),V=C(j,N),U=C(B,N);t(D),r(V),a(U),l(N),p(R.ScaleNode),ee.emitMethod(te.MainEngine,R.ScaleNode,{workIds:[Z],originPoint:V,scenePoint:U,workState:E.Start,viewId:h.viewId})}},Y=(b,N,D,j)=>{if(!(!h||!i||!s)){if(h!=null&&h.control.worker.isBusy){m(!0),S();return}y.current||(y.current=setTimeout(()=>{y.current=0;const{scale:B,translate:V}=x(N,j,h,s);(!z.isEqual(B,d==null?void 0:d.scale)||!z.isEqual(V,d==null?void 0:d.translate))&&(M({scale:B,translate:V}),p(R.ScaleNode),ee.emitMethod(te.MainEngine,R.ScaleNode,{workIds:[Z],scale:B,dir:N,translate:V,originPoint:i,scenePoint:s,workState:E.Doing,viewId:h.viewId}))},60))}},A=()=>{h!=null&&h.control.worker.isBusy&&m(!0),S()};return f.createElement(ko.Resizable,{className:`${n}`,boundsByDirection:!0,minWidth:-(((u==null?void 0:u.x)||0)+((u==null?void 0:u.w)||0)),minHeight:-(((u==null?void 0:u.y)||0)+((u==null?void 0:u.h)||0)),size:{width:(u==null?void 0:u.w)||0,height:(u==null?void 0:u.h)||0},style:{position:"absolute",left:u==null?void 0:u.x,top:u==null?void 0:u.y,pointerEvents:g?"none":"auto"},enable:w?!1:{top:(u==null?void 0:u.scaleType)===Oe.all&&!0||!1,right:(u==null?void 0:u.scaleType)===Oe.all&&!0||!1,bottom:(u==null?void 0:u.scaleType)===Oe.all&&!0||!1,left:(u==null?void 0:u.scaleType)===Oe.all&&!0||!1,topRight:!0,bottomRight:!0,bottomLeft:!0,topLeft:!0},lockAspectRatio:(u==null?void 0:u.scaleType)===Oe.proportional,onResizeStart:O,onResize:Y,onResizeStop:A})},mr=o=>{const{id:n,pos:e,pointMap:t,type:i}=o,{setOperationType:r,mananger:s,floatBarData:a}=f.useContext(Ne),[c,l]=f.useState({x:0,y:0}),[u,h]=f.useState(E.Pending),[g,p]=f.useState(!1),d=f.useRef(0),M=f.useMemo(()=>a?{left:0,top:0}:{},[a]),w=k=>{if(!k||a!=null&&a.isLocked){p(!0),h(E.Pending),r(R.None);return}p(!1)};f.useEffect(()=>(ee.activeListener(w),()=>{ee.unmountActiveListener(w)}),[]),f.useEffect(()=>{z.isNumber(e.x)&&z.isNumber(e.y)&&(u===E.Pending||u===E.Done)&&l({x:e.x,y:e.y})},[e,u]),f.useEffect(()=>{if(a&&(a!=null&&a.isLocked)||s!=null&&s.control.worker.isBusy){p(!0);return}p(!1)},[a,s==null?void 0:s.control.worker.isBusy]);const m=(k,C)=>{d.current&&(clearTimeout(d.current),d.current=0),r(R.None),h(E.Done);const x={x:C.x,y:C.y};if(l(x),s!=null&&s.control.viewContainerManager){const O=s.control.viewContainerManager.transformToScenePoint([x.x,x.y],s.viewId),Y=t.get(n);Y&&i==="start"?Y[0]=O:Y&&i==="end"&&(Y[1]=O),ee.emitMethod(te.MainEngine,R.SetPoint,{workId:Z,pointMap:t,workState:E.Done,viewId:s==null?void 0:s.viewId})}s==null||s.focusElement()},y=()=>{if(d.current&&(clearTimeout(d.current),d.current=0),s!=null&&s.control.worker.isBusy){p(!0);return}z.isNumber(e.x)&&z.isNumber(e.y)&&(r(R.SetPoint),h(E.Start),ee.emitMethod(te.MainEngine,R.SetPoint,{workId:Z,pointMap:t,workState:E.Start,viewId:s==null?void 0:s.viewId}))},S=(k,C)=>{if(s!=null&&s.control.worker.isBusy){p(!0),m(k,C);return}if(d.current)return;const x={x:C.x,y:C.y};l(x),d.current=setTimeout(()=>{if(d.current=0,s!=null&&s.control.viewContainerManager){const O=s.control.viewContainerManager.transformToScenePoint([x.x,x.y],s.viewId),Y=t.get(n);Y&&i==="start"?Y[0]=O:Y&&i==="end"&&(Y[1]=O),h(E.Doing),ee.emitMethod(te.MainEngine,R.SetPoint,{workId:Z,pointMap:t,workState:E.Doing,viewId:s==null?void 0:s.viewId})}},60)},v=(k,C)=>{s!=null&&s.control.worker.isBusy&&p(!0),m(k,C)};return f.createElement(Ot,{disabled:g,position:c,onStart:y,onDrag:S,onStop:v},f.createElement("div",{className:"appliance-plugin-point-draggable-btn",style:M}))},bI=o=>{const{className:n}=o,{floatBarData:e,mananger:t}=f.useContext(Ne),[i,r]=f.useState(),[s,a]=f.useState(),[c,l]=f.useState(new Map);f.useEffect(()=>{const g=[];if(t&&(e!=null&&e.points)){const p=t.viewId;if(t.control.viewContainerManager.getView(p))for(const M of e.points){const w=t.control.viewContainerManager.transformToOriginPoint(M,p);g.push(w)}e!=null&&e.selectIds&&e.selectIds.length===1&&(c.set(e.selectIds[0],e.points),l(c))}g[0]&&r({x:g[0][0],y:g[0][1]}),g[1]&&a({x:g[1][0],y:g[1][1]})},[t,e==null?void 0:e.points,e==null?void 0:e.selectIds,c]);const u=f.useMemo(()=>i&&(e!=null&&e.selectIds)?f.createElement(mr,{pos:i,type:"start",id:e.selectIds[0],pointMap:c}):null,[i,e==null?void 0:e.selectIds,c]),h=f.useMemo(()=>s&&(e!=null&&e.selectIds)?f.createElement(mr,{pos:s,type:"end",id:e.selectIds[0],pointMap:c}):null,[s,e==null?void 0:e.selectIds,c]);return f.createElement("div",{className:`${n}`},u,h)},DI=f.forwardRef((o,n)=>{const{floatBarData:e,operationType:t}=f.useContext(Ne),i=f.useMemo(()=>(e==null?void 0:e.scaleType)!==Oe.all||t===R.RotateNode?null:f.createElement(MI,null),[e,t]),r=f.useMemo(()=>(e==null?void 0:e.scaleType)!==Oe.both||t===R.RotateNode?null:f.createElement(yI,null),[e,t]),s=f.useMemo(()=>(e==null?void 0:e.scaleType)!==Oe.proportional||t===R.RotateNode?null:f.createElement(mI,null),[e,t]),a=f.useMemo(()=>(e==null?void 0:e.scaleType)===Oe.none&&(e!=null&&e.canLock)?f.createElement(II,null):null,[e]);return f.createElement("div",{ref:n,style:e?{transform:`translate(${e.x}px,${e.y}px)`,width:e.w,height:e.h,pointerEvents:"none"}:void 0},a,i,r,s,o.children)}),jI=f.memo(o=>{const{isHide:n,operationType:e,floatBarData:t}=o;return n&&e===R.None&&z.isNumber(t==null?void 0:t.x)&&z.isNumber(t==null?void 0:t.y)&&z.isNumber(t==null?void 0:t.w)&&z.isNumber(t==null?void 0:t.h)?f.createElement("div",{className:be.FloatBarBtn,style:{left:t==null?void 0:t.x,top:t==null?void 0:t.y,width:t.w,height:t.h}},f.createElement(vo,{position:{x:t.x,y:t.y},textOpt:t==null?void 0:t.textOpt,noLayer:t==null?void 0:t.isLocked})):null},(o,n)=>!!z.isEqual(o,n)),AI=f.forwardRef((o,n)=>{const{floatBarData:e,operationType:t,mananger:i}=f.useContext(Ne),{editors:r,isHide:s,canSelectorSwitch:a}=o,c=f.useRef(null);f.useEffect(()=>{const g=c.current;if(!g)return;const p=d=>{d.stopPropagation(),d.stopImmediatePropagation(),i==null||i.control.worker.blurCursor(i.viewId)};return g.addEventListener("pointerdown",p,!1),()=>{g.removeEventListener("pointerdown",p,!1)}},[i]);const l=f.useMemo(()=>{var g;return e!=null&&e.canRotate&&((g=e==null?void 0:e.selectIds)==null?void 0:g.length)===1&&(t===R.None||t===R.RotateNode)?f.createElement(wI,{className:be.RotateBtn}):null},[e,t]),u=f.useMemo(()=>((e==null?void 0:e.scaleType)===Oe.all||(e==null?void 0:e.scaleType)===Oe.proportional)&&(t===R.None||t===R.ScaleNode)&&z.isNumber(e==null?void 0:e.x)&&z.isNumber(e==null?void 0:e.y)?f.createElement(xI,{className:be.ResizeBtn}):null,[e==null?void 0:e.scaleType,t,e==null?void 0:e.x,e==null?void 0:e.y]),h=f.useMemo(()=>(e==null?void 0:e.scaleType)===Oe.both&&(t===R.None||t===R.SetPoint)?f.createElement(bI,{className:be.ResizeTowBox}):null,[e==null?void 0:e.scaleType,t]);return f.createElement("div",{ref:c,className:be.FloatBar,onPointerOver:g=>(nn(g),i==null||i.control.worker.blurCursor(i.viewId),!1)},f.createElement(DI,{ref:n}),f.createElement(CI,{editors:r,canSelectorSwitch:a}),l,u,h,f.createElement(jI,{isHide:s,operationType:t,floatBarData:e}))}),EI=f.memo(AI,(o,n)=>!!z.isEqual(o,n));class zI extends f.Component{constructor(e){super(e);I(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 r=this.getCursorName(e);return f.createElement("img",{className:"cursor-selector-avatar",style:{width:r?19:28,height:r?19:28,position:r?"initial":"absolute",borderColor:r?"white":t,marginRight:r?4:0},src:(i=e.payload)==null?void 0:i.avatar,alt:"avatar"})}else return null});I(this,"getOpacity",e=>{const t=this.getCursorName(e),i=this.detectAvatar(e);return t===void 0&&i===void 0?0:1});I(this,"getCursorName",e=>{if(e.payload)return e.payload.nickName||e.payload.cursorName||e.payload.uid});I(this,"getThemeClass",e=>e.payload&&e.payload.theme?"cursor-inner-mellow":"cursor-inner");I(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});I(this,"getCursorTextColor",e=>e.payload&&e.payload.cursorTextColor?e.payload.cursorTextColor:"#FFFFFF");I(this,"getCursorTagBackgroundColor",e=>e.payload&&e.payload.cursorTagBackgroundColor?e.payload.cursorTagBackgroundColor:this.getCursorBackgroundColor(e));I(this,"detectAvatar",e=>!!(e.payload&&e.payload.avatar));I(this,"renderTag",e=>{if(e.payload&&e.payload.cursorTagName)return f.createElement("span",{className:"cursor-tag-name",style:{backgroundColor:this.getCursorTagBackgroundColor(e)}},e.payload.cursorTagName)});I(this,"renderCursor",e=>{const t=Xm.get(e);return t&&this.props.isEnableCursor?f.createElement("img",{className:`cursor-${e}-image`,src:t,alt:`${e}Cursor`}):null})}render(){const{roomMember:e}=this.props,t=this.getCursorName(e);switch(e.memberState.currentApplianceName){case re.pencil:return f.createElement("div",{className:"cursor-box"},f.createElement("div",{className:"cursor-mid cursor-pencil-offset",style:{transform:"translate(-50%, -100%)",marginLeft:"5px",marginTop:"4px"}},f.createElement("div",{className:"cursor-name"},f.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),f.createElement("span",{className:"cursor-name-text"},t),this.renderTag(e))),f.createElement("div",null,this.renderCursor("pencil"))));case re.selector:return f.createElement("div",{className:"cursor-box"},f.createElement("div",{className:"cursor-mid cursor-selector-offset",style:{transform:"translate(-50%, -100%)",marginLeft:"3px",marginTop:"17px"}},f.createElement("div",{className:"cursor-name"},f.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),f.createElement("span",{className:"cursor-name-text"},t),this.renderTag(e))),f.createElement("div",null,this.renderCursor("selector"))));case re.eraser:case re.pencilEraser:return f.createElement("div",{className:"cursor-box"},f.createElement("div",{className:"cursor-mid cursor-eraser-offset",style:{transform:"translate(-50%, -100%)",marginLeft:"2px",marginTop:"8px"}},f.createElement("div",{className:"cursor-name"},f.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),f.createElement("span",{className:"cursor-name-text"},t),this.renderTag(e))),f.createElement("div",null,this.renderCursor("eraser"))));case re.text:return f.createElement("div",{className:"cursor-box"},f.createElement("div",{className:"cursor-mid cursor-text-offset",style:{transform:"translate(-50%, -100%)",marginLeft:"0px"}},f.createElement("div",{className:"cursor-name"},f.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),f.createElement("span",{className:"cursor-name-text"},t),this.renderTag(e))),f.createElement("div",null,this.renderCursor("text"))));case re.rectangle:case re.arrow:case re.straight:case re.shape:case re.ellipse:return f.createElement("div",{className:"cursor-box"},f.createElement("div",{className:"cursor-mid cursor-shape-offset",style:{transform:"translate(-50%, -100%)",marginLeft:"-3px",marginTop:"19px"}},f.createElement("div",{className:"cursor-name"},f.createElement("div",{style:{opacity:this.getOpacity(e),backgroundColor:this.getCursorBackgroundColor(e),color:this.getCursorTextColor(e)},className:this.getThemeClass(e)},this.renderAvatar(e),f.createElement("span",{className:"cursor-name-text"},t),this.renderTag(e))),f.createElement("div",null,this.renderCursor("shape"))));default:return null}}}const LI=o=>{var s;const{className:n,info:e,isEnableCursor:t}=o,{roomMember:i,...r}=e||{};return f.createElement("div",{"data-cursor-uid":(s=i==null?void 0:i.payload)==null?void 0:s.uid,className:`${n}`,style:r?{transform:`translate(${r.x}px, ${r.y}px)`}:{display:"none"}},i&&f.createElement(zI,{roomMember:i,isEnableCursor:t}))},PI=o=>{const{className:n,manager:e}=o,[t,i]=f.useState();f.useEffect(()=>(e.internalMsgEmitter.on([te.Cursor,e.viewId],r),()=>{e.internalMsgEmitter.off([te.Cursor,e.viewId],r)}),[e]);function r(a){i(a)}return f.useMemo(()=>{if(t!=null&&t.length){const a=t.map(c=>{var l;return c.roomMember?f.createElement(LI,{key:(l=c.roomMember)==null?void 0:l.memberId,className:n,info:c,isEnableCursor:e.control.cursor.isEnableCursor}):null});return f.createElement(f.Fragment,null,a)}return null},[t])},OI=o=>{const{viewId:n,miniMapCanvas:e,highlightColor:t,miniMapManager:i,contianer:r}=o,[s,a]=f.useState();f.useEffect(()=>(c(),i.listener.addListener([n,"viewCameraUpate"],c),i.listener.emitAsync([n,"miniMapCreate"],!0),()=>{i.listener.removeListener([n,"viewCameraUpate"],c)}),[]);const c=()=>{const h=i.maps.get(n);h&&l(h.miniMapCamera,h.viewCamera)},l=(h,g)=>{const{width:p,height:d}=r.getBoundingClientRect(),M=Math.min(p/h.width,d/h.height),w=g.width/g.scale,m=g.height/g.scale,y=[g.centerX,g.centerY],S=[h.centerX,h.centerY],v=[y[0]-S[0],y[1]-S[1]],k=Math.min(h.scale*M,h.scale*M),C=[v[0]*k,v[1]*k,w,m,k];a(C)},u=h=>{var g;if(i.control.renderControl.isWritable){const p=h.nativeEvent.target||h.nativeEvent.srcElement;if(p&&h.nativeEvent&&s){const{width:d,height:M}=p.getBoundingClientRect(),[w,m]=[d/2,M/2],[y,S]=[(h.nativeEvent.offsetX-w)/s[4],(h.nativeEvent.offsetY-m)/s[4]],v=i.maps.get(n);if(v!=null&&v.viewCamera){const[k,C]=[v.miniMapCamera.centerX+y,v.miniMapCamera.centerY+S];(g=i.control.room)==null||g.moveCamera({centerX:k,centerY:C,animationMode:"immediately"})}}}};return f.createElement("div",{style:{position:"relative",width:"100%",height:"100%",overflow:"hidden",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",pointerEvents:"auto"},onClick:u},f.createElement("canvas",{style:{pointerEvents:"none"},ref:e}),s&&f.createElement("div",{className:"minimap-highlightBox",style:{position:"absolute",top:"50%",left:"50%",width:s[2]*s[4],height:s[3]*s[4],boxSizing:"content-box",border:`2px solid ${t}`,transform:`translate(calc(-50% + ${s[0]}px), calc(-50% + ${s[1]}px))`,pointerEvents:"none"}}))},RI=o=>{const{miniMapManager:n,active:e,className:t}=o,i=f.useMemo(()=>{const r=n.maps;if(e){const s=r.get(e);if(s){const{miniMapCamera:a,viewCamera:c,...l}=s;if(l.contianer&&a&&c){const u=n.highlightColor;return pn.createPortal(f.createElement(OI,{viewId:e,...l,highlightColor:u,miniMapManager:n}),l.contianer)}}}return null},[e,n]);return f.createElement("div",{className:t},i)},Ne=f.createContext({viewId:"",mananger:void 0,floatBarColors:[],overwriteSelectorStyles:{},floatBarData:void 0,dpr:1,angle:0,operationType:R.None,scale:[1,1],isNoPointerEvents:!1,activeTextEditor:!1,activeTextId:void 0,setAngle:()=>{},setOperationType:()=>{},setFloatBarData:()=>{}});class Ci extends f.Component{constructor(e){var i,r;super(e);I(this,"showTextFloatBar");I(this,"canSelectorSwitch");I(this,"rightBoundBreak");I(this,"setAngle",e=>{this.setState({angle:e})});I(this,"setOperationType",e=>{this.setState({operationType:e})});this.state={floatBarData:void 0,showFloatBar:!1,showFloatBarBtn:!0,dpr:1,angle:0,operationType:R.None,scale:[1,1],editors:this.editors,activeTextId:(i=this.props.mananger.control.textEditorManager)==null?void 0:i.activeId,activeMiniMapViewId:(r=this.props.mananger.control.miniMapManager)==null?void 0:r.activeViewId};const t=this.props.mananger.control.pluginOptions.extras.textEditor;this.showTextFloatBar=z.isBoolean(t.showFloatBar)?t.showFloatBar:we.textEditor.showFloatBar,this.canSelectorSwitch=z.isBoolean(t==null?void 0:t.canSelectorSwitch)?t.canSelectorSwitch:we.textEditor.canSelectorSwitch,this.rightBoundBreak=z.isBoolean(t==null?void 0:t.rightBoundBreak)?t.rightBoundBreak:we.textEditor.rightBoundBreak}get editors(){return en(this.props.mananger.control.textEditorManager.filterEditor(this.props.mananger.viewId))}componentDidMount(){this.props.mananger.vDom=this,this.props.mananger.mountView(),this.setState({dpr:this.props.mananger.dpr})}componentWillUnmount(){}setActiveMiniMap(e){this.setState({activeMiniMapViewId:e})}showFloatBarBtn(e){this.setState({showFloatBarBtn:e})}showFloatBar(e,t){const i=e&&t&&{...this.state.floatBarData,...t}||void 0;this.setState({showFloatBar:e,floatBarData:i,angle:0})}activeTextEditor(){this.setState({activeTextEditor:!0})}unActiveTextEditor(){this.setState({activeTextEditor:!1})}updateTextEditorInfo(e){this.setState({activeTextId:e,editors:this.editors})}setFloatBarData(e){this.state.floatBarData&&this.setState({floatBarData:{...this.state.floatBarData,...e}})}render(){var t,i,r,s,a,c;const e=!!((i=(t=this.props.mananger.control)==null?void 0:t.room)!=null&&i.floatBarOptions);return f.createElement("div",{className:be.Container},!this.props.mananger.control.hasOffscreenCanvas&&f.createElement("div",{className:be.CanvasBox,ref:this.props.refs.canvasContainerRef})||f.createElement("div",{className:be.CanvasBox},f.createElement("canvas",{id:"bgCanvas",ref:this.props.refs.canvasBgRef,style:{width:"100%",height:"100%"}}),f.createElement("canvas",{id:"serviceCanvas",className:be.FloatCanvas,ref:this.props.refs.canvasServiceFloatRef,style:{width:"100%",height:"100%"}}),f.createElement("canvas",{id:"localCanvas",className:be.FloatCanvas,ref:this.props.refs.canvasFloatRef,style:{width:"100%",height:"100%"}}),!this.props.mananger.control.isUseSimple&&f.createElement("div",{id:"subLocalCanvas",className:be.CanvasBoxSub,ref:this.props.refs.subLocalCanvasContainerRef}),!this.props.mananger.control.isUseSimple&&f.createElement("canvas",{id:"topCanvas",className:be.TopFloatCanvas,ref:this.props.refs.canvasTopRef,style:{width:"100%",height:"100%"}})),!this.props.mananger.control.hasOffscreenCanvas&&this.props.refs.snapshotContainerRef&&f.createElement("div",{className:be.SnapshotBox,ref:this.props.refs.snapshotContainerRef})||null,this.props.mananger.control.isUseBackgroundThread&&!!this.props.refs.backgroundContainerRef&&f.createElement("div",{className:be.BackgroundBox},f.createElement("div",{className:be.BackgroundSvgBox,ref:this.props.refs.backgroundContainerRef}),!!this.props.refs.backgroundSnapshotContainerRef&&f.createElement("div",{className:be.BackgroundSnapshotBox},f.createElement("div",{className:be.BackgroundSnapshotContent,ref:this.props.refs.backgroundSnapshotContainerRef})))||null,f.createElement(Ne.Provider,{value:{viewId:this.props.viewId,mananger:this.props.mananger,floatBarColors:e&&((a=(s=(r=this.props.mananger.control)==null?void 0:r.room)==null?void 0:s.floatBarOptions)==null?void 0:a.colors)||[],overwriteSelectorStyles:this.props.mananger.control.pluginOptions.extras.overwriteSelectorStyles||{},isNoPointerEvents:!this.state.showFloatBarBtn,floatBarData:this.state.floatBarData,dpr:this.state.dpr,angle:this.state.angle,operationType:this.state.operationType,scale:this.state.scale,activeTextEditor:this.state.activeTextEditor,activeTextId:this.state.activeTextId,setAngle:this.setAngle.bind(this),setOperationType:this.setOperationType.bind(this),setFloatBarData:this.setFloatBarData.bind(this)}},this.state.showFloatBar&&f.createElement(EI,{ref:this.props.refs.floatBarRef,editors:this.state.editors,isHide:e&&this.state.showFloatBarBtn,canSelectorSwitch:this.canSelectorSwitch})||null,((c=this.state.editors)==null?void 0:c.size)&&f.createElement(pI,{className:be.TextEditorContainer,showFloatBtns:this.showTextFloatBar&&e&&this.state.showFloatBarBtn||!1,editors:this.state.editors,rightBoundBreak:this.rightBoundBreak})||null),f.createElement("div",{className:"appliance-plugin-custom-floatbar-container","data-view-id":this.props.viewId,ref:this.props.refs.customFloatbarContainerRef}),f.createElement(PI,{className:be.CursorBox,manager:this.props.mananger}),!this.props.mananger.control.isUseSimple&&f.createElement(RI,{className:be.MiniMapBox,active:this.state.activeMiniMapViewId,miniMapManager:this.props.mananger.control.miniMapManager}))}}class UI extends To{constructor(e,t){super(e,t);I(this,"width",1e3);I(this,"height",1e3);I(this,"dpr",Pt());I(this,"vDom");I(this,"eventTragetElement");I(this,"snapshotContainerRef");I(this,"backgroundSnapshotContainerRef");I(this,"canvasContainerRef",f.createRef());I(this,"subLocalCanvasContainerRef");I(this,"canvasTopRef");I(this,"canvasServiceFloatRef",f.createRef());I(this,"canvasFloatRef",f.createRef());I(this,"canvasBgRef",f.createRef());I(this,"backgroundContainerRef");I(this,"floatBarRef",f.createRef());I(this,"customFloatbarContainerRef",f.createRef());I(this,"containerOffset",{x:0,y:0});this.control.hasOffscreenCanvas||(this.snapshotContainerRef=f.createRef()),this.control.isUseSimple||(this.canvasTopRef=f.createRef(),this.subLocalCanvasContainerRef=f.createRef()),this.control.isUseBackgroundThread&&(this.backgroundContainerRef=f.createRef(),this.backgroundSnapshotContainerRef=f.createRef())}setCanvassStyle(){var e,t;if(this.eventTragetElement){const i=this.eventTragetElement.offsetWidth||this.width,r=this.eventTragetElement.offsetHeight||this.height,s=Pt();s!==this.dpr&&(this.dpr=s,this.control.worker.updateDpr(this.viewId,this.dpr)),i&&r&&this.canvasContainerRef.current&&(i!==this.width||r!==this.height)&&(this.width=i,this.height=r,this.canvasContainerRef.current.style.width=`${i}px`,this.canvasContainerRef.current.style.height=`${r}px`),i&&r&&this.snapshotContainerRef&&this.snapshotContainerRef.current&&(i!==this.width||r!==this.height)&&(this.width=i,this.height=r),i&&r&&this.canvasBgRef.current&&(i!==this.width||r!==this.height)&&(this.width=i,this.height=r,this.control.isUseOffscreenTransfer||(this.canvasBgRef.current.width=i*this.dpr,this.canvasBgRef.current.height=r*this.dpr,this.canvasFloatRef.current&&(this.canvasFloatRef.current.width=i*this.dpr,this.canvasFloatRef.current.height=r*this.dpr),this.canvasServiceFloatRef.current&&(this.canvasServiceFloatRef.current.width=i*this.dpr,this.canvasServiceFloatRef.current.height=r*this.dpr),(e=this.canvasTopRef)!=null&&e.current&&(this.canvasTopRef.current.width=i*this.dpr,this.canvasTopRef.current.height=r*this.dpr))),i&&r&&this.backgroundContainerRef&&((t=this.backgroundContainerRef)!=null&&t.current)&&(i!==this.width||r!==this.height)&&(this.backgroundContainerRef.current.style.width=`${i}px`,this.backgroundContainerRef.current.style.height=`${r}px`,this.backgroundContainerRef.current.classList.toggle("appliance-plugin-background-isWritable",this.control.renderControl.isWritable))}}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(),pn.render(f.createElement(Ci,{viewId:this.viewId,mananger:this,refs:{canvasServiceFloatRef:this.canvasServiceFloatRef,canvasFloatRef:this.canvasFloatRef,canvasBgRef:this.canvasBgRef,floatBarRef:this.floatBarRef,customFloatbarContainerRef:this.customFloatbarContainerRef,canvasTopRef:this.canvasTopRef,canvasContainerRef:this.canvasContainerRef,snapshotContainerRef:this.snapshotContainerRef,subLocalCanvasContainerRef:this.subLocalCanvasContainerRef,backgroundContainerRef:this.backgroundContainerRef,backgroundSnapshotContainerRef:this.backgroundSnapshotContainerRef}}),t),this.control.room&&this.bindDisplayerEvent(this.eventTragetElement),this}}class YI extends mm{constructor(e,t,i){super(e,t,i);I(this,"dpr",Pt());I(this,"width",1e3);I(this,"height",1e3);I(this,"vDom");I(this,"eventTragetElement");I(this,"canvasContainerRef",f.createRef());I(this,"subLocalCanvasContainerRef");I(this,"canvasTopRef");I(this,"canvasServiceFloatRef",f.createRef());I(this,"canvasFloatRef",f.createRef());I(this,"canvasBgRef",f.createRef());I(this,"backgroundContainerRef");I(this,"floatBarRef",f.createRef());I(this,"customFloatbarContainerRef",f.createRef());I(this,"containerOffset",{x:0,y:0});this.control.isUseSimple||(this.canvasTopRef=f.createRef(),this.subLocalCanvasContainerRef=f.createRef()),this.control.isUseBackgroundThread&&(this.backgroundContainerRef=f.createRef())}setCanvassStyle(){var e,t;if(this.eventTragetElement){const i=Pt();if(i!==this.dpr&&(this.dpr=i,this.control.worker.updateDpr(this.viewId,this.dpr)),this.canvasContainerRef.current){const r=this.eventTragetElement.offsetWidth||this.width,s=this.eventTragetElement.offsetHeight||this.height;r&&s&&(r!==this.width||s!==this.height)&&(this.width=r,this.height=s,this.canvasContainerRef.current.style.width=`${r}px`,this.canvasContainerRef.current.style.height=`${s}px`)}if(this.canvasBgRef.current){const r=this.eventTragetElement.offsetWidth||this.width,s=this.eventTragetElement.offsetHeight||this.height;r&&s&&(r!==this.width||s!==this.height)&&(this.width=r,this.height=s,this.control.isUseOffscreenTransfer||(this.canvasBgRef.current.width=r*this.dpr,this.canvasBgRef.current.height=s*this.dpr,this.canvasFloatRef.current&&(this.canvasFloatRef.current.width=r*this.dpr,this.canvasFloatRef.current.height=s*this.dpr),this.canvasServiceFloatRef.current&&(this.canvasServiceFloatRef.current.width=r*this.dpr,this.canvasServiceFloatRef.current.height=s*this.dpr),(e=this.canvasTopRef)!=null&&e.current&&(this.canvasTopRef.current.width=r*this.dpr,this.canvasTopRef.current.height=s*this.dpr)))}if(this.backgroundContainerRef&&((t=this.backgroundContainerRef)!=null&&t.current)){const r=this.eventTragetElement.offsetWidth||this.width,s=this.eventTragetElement.offsetHeight||this.height;r&&s&&(r!==this.width||s!==this.height)&&(this.backgroundContainerRef.current.style.width=`${r}px`,this.backgroundContainerRef.current.style.height=`${s}px`,this.backgroundContainerRef.current.classList.toggle("appliance-plugin-background-isWritable",this.control.renderControl.isWritable))}}}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(),pn.render(f.createElement(Ci,{viewId:e,mananger:this,refs:{canvasServiceFloatRef:this.canvasServiceFloatRef,canvasFloatRef:this.canvasFloatRef,canvasBgRef:this.canvasBgRef,floatBarRef:this.floatBarRef,customFloatbarContainerRef:this.customFloatbarContainerRef,canvasTopRef:this.canvasTopRef,canvasContainerRef:this.canvasContainerRef,subLocalCanvasContainerRef:this.subLocalCanvasContainerRef,backgroundContainerRef:this.backgroundContainerRef}}),i),this.control.room&&this.bindDisplayerEvent(this.eventTragetElement),this}}class ot extends Lt{constructor(e){super(e);I(this,"focuedViewId");I(this,"focuedView");I(this,"control");I(this,"tmpFocusedViewId");I(this,"checkScaleTimer");I(this,"mainViewHotkeyListener",e=>{this.onActiveHotkeyChange(e)});I(this,"appViewListeners",new Map);I(this,"onMainViewRelease",async e=>{this.control.textEditorManager.clear(ie,!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()});I(this,"mainViewDestroy",e=>{var t;if(this.mainView&&this.mainView.displayer){this.removeMainViewListeners(this.mainView.viewData),this.mainView.displayer.destroy();const i=e.divElement;if(i){const r=i.getElementsByClassName("appliance-plugin-main-view-displayer");for(const s of r)s.remove()}if(this.mainView.container&&i!==this.mainView.container){const r=this.mainView.container.getElementsByClassName("appliance-plugin-main-view-displayer");for(const s of r)s.remove()}(t=this.control.worker)==null||t.destroyViewWorker(this.mainView.id,!0),this.mainView=void 0}});I(this,"onMainViewMounted",e=>{const t=e.divElement;if(!t||!e.focusScenePath||!(e.focusScenePath||e.scenePath))return;const r=new UI(this.control,ye.InternalMsgEmitter),s=e.size.width||r.width,a=e.size.height||r.height;r.dpr;const c={cameraOpt:{...ot.defaultCameraOpt,width:s,height:a}},{scale:l,...u}=e.camera;c.cameraOpt={...c.cameraOpt,...u,scale:l===1/0?1:l},this.createMianView({id:ie,container:t,displayer:r,focusScenePath:e.focusScenePath,cameraOpt:c.cameraOpt,viewData:e}),this.setFocuedViewId(ie),r.createMainViewDisplayer(t),e.callbacks.on("onSizeUpdated",this.onMainViewSizeUpdated),e.callbacks.on("onCameraUpdated",this.onMainViewCameraUpdated),e.callbacks.on("onActiveHotkey",this.mainViewHotkeyListener)});I(this,"onMainViewSizeUpdated",async()=>{await new Promise(e=>{setTimeout(()=>{e(!0)},0)}),this.mainView&&this.mainView.viewData&&this.updateMainViewCamera()});I(this,"onMainViewCameraUpdated",async()=>{await new Promise(e=>{setTimeout(()=>{e(!0)},0)}),this.updateMainViewCamera()});I(this,"updateMainViewCamera",()=>{if(this.mainView&&this.mainView.viewData){const e=this.mainView.viewData.camera;if(!z.isNumber(e.scale)||e.scale===1/0)return;const t=this.mainView.cameraOpt;if(t){const i=t.width,r=t.height,{width:s,height:a}=this.mainView.viewData.size;(s!==i||a!==r)&&this.mainView.displayer.updateSize();const c=e.scale===1/0?1:e.scale,l=e.centerX||0,u=e.centerY||0,h={...t,scale:c,centerX:l,centerY:u,width:s,height:a};z.isEqual(t,h)||(this.mainView.cameraOpt=h),this.checkScaleTimer&&e.scale==1/0&&(clearTimeout(this.checkScaleTimer),this.checkScaleTimer=void 0),!this.checkScaleTimer&&e.scale===1/0&&this.mainView.viewData&&this.mainView.viewData.camera.scale===1/0&&(this.checkScaleTimer=setTimeout(()=>{var g,p;(p=(g=this.mainView)==null?void 0:g.viewData)==null||p.moveCamera({scale:c,centerX:l,centerY:u,animationMode:"immediately"}),this.checkScaleTimer=void 0},500))}}});I(this,"onAppViewMounted",async e=>{var g;const{appId:t,view:i}=e,r=i.divElement;if(!r||!i.focusScenePath)return;const s=this.appViews.get(t);if(s&&s.displayer){let p=r.getElementsByClassName("appliance-plugin-app-view-displayer");for(const d of p)d.remove();if(s.container&&s.container!==r){p=s.container.getElementsByClassName("appliance-plugin-app-view-displayer");for(const d of p)d.remove()}this.destroyAppView(e.appId,!0),(g=this.control.worker)==null||g.destroyViewWorker(t,!0),await new Promise(d=>{setTimeout(()=>{d(!0)},0)})}const a=new YI(t,this.control,ye.InternalMsgEmitter),c=i.size.width||a.width,l=i.size.height||a.height;a.dpr;const u={cameraOpt:{...ot.defaultCameraOpt,...i.camera,width:c,height:l}};this.createAppView({id:t,container:r,displayer:a,cameraOpt:u.cameraOpt,focusScenePath:i.focusScenePath,viewData:i}),a.createAppViewDisplayer(t,r);const h=this.getAppViewListeners(t);if(i.callbacks.on("onSizeUpdated",h.onSizeUpdated),i.callbacks.on("onCameraUpdated",h.onCameraUpdated),i.callbacks.on("onActiveHotkey",h.onActiveHotkey),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)});I(this,"onAppViewSizeUpdated",async e=>{await new Promise(i=>{setTimeout(()=>{i(!0)},0)});const t=this.appViews.get(e);t&&t.viewData&&this.updateAppCamera(e)});I(this,"onAppViewCameraUpdated",async e=>{await new Promise(t=>{setTimeout(()=>{t(!0)},0)}),this.updateAppCamera(e)});I(this,"updateAppCamera",e=>{const t=this.appViews.get(e);if(t&&t.viewData){const i=t.viewData.camera,r=t.cameraOpt;if(r){const{width:s,height:a}=t.viewData.size,c=r.width,l=r.height;(s!==c||a!==l)&&t.displayer.updateSize();const u=i.scale===1/0?1:i.scale,h=i.centerX||0,g=i.centerY||0,p={...r,scale:u,centerX:h,centerY:g,width:s,height:a};z.isEqual(p,r)||(t.cameraOpt=p)}}});this.control=e.control}getAppViewListeners(e){let t=this.appViewListeners.get(e);return t||(t={onSizeUpdated:()=>{this.onAppViewSizeUpdated(e)},onCameraUpdated:()=>{this.onAppViewCameraUpdated(e)},onActiveHotkey:i=>{this.onActiveHotkeyChange(i)}},this.appViewListeners.set(e,t)),t}removeMainViewListeners(e){e&&(e.callbacks.off("onSizeUpdated",this.onMainViewSizeUpdated),e.callbacks.off("onCameraUpdated",this.onMainViewCameraUpdated),e.callbacks.off("onActiveHotkey",this.mainViewHotkeyListener))}removeAppViewListeners(e,t){const i=this.appViewListeners.get(e);t&&i&&(t.callbacks.off("onSizeUpdated",i.onSizeUpdated),t.callbacks.off("onCameraUpdated",i.onCameraUpdated),t.callbacks.off("onActiveHotkey",i.onActiveHotkey)),this.appViewListeners.delete(e)}destroyAppView(e,t=!1){const i=this.appViews.get(e);this.removeAppViewListeners(e,i==null?void 0:i.viewData),super.destroyAppView(e,t)}destroy(){var e;this.removeMainViewListeners((e=this.mainView)==null?void 0:e.viewData);for(const[t,i]of this.appViews.entries())this.removeAppViewListeners(t,i.viewData);super.destroy(),this.appViewListeners.clear()}getViewInitData(e){var i;const t=this.getView(e);if(t){const{width:r,height:s,dpr:a}=t.displayer;(i=this.control.pluginOptions.extras.canvasOpt)!=null&&i.contextType&&(ot.defaultScreenCanvasOpt.contextType=this.control.pluginOptions.extras.canvasOpt.contextType);const c={dpr:a,originalPoint:[r/2,s/2],offscreenCanvasOpt:{...ot.defaultScreenCanvasOpt,width:r,height:s},layerOpt:{...ot.defaultLayerOpt,width:r,height:s},cameraOpt:{...ot.defaultCameraOpt,width:r,height:s}};if(t.viewData){const{scale:l,...u}=t.viewData.camera;c.cameraOpt={...c.cameraOpt,...u,scale:l===1/0?1:l}}return c}}async mountView(e){var i,r,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()),this.control.isUseOffscreenTransfer&&t.displayer.canvasBgRef.current&&t.displayer.canvasServiceFloatRef.current&&t.displayer.canvasFloatRef.current&&t.displayer.setTransferControlToOffscreenCanvas({bgCanvas:t.displayer.canvasBgRef.current,serviceCanvas:t.displayer.canvasServiceFloatRef.current,localCanvas:t.displayer.canvasFloatRef.current});const a=this.getViewInitData(e);if(a&&((r=this.control.worker)==null||r.createViewWorker(e,a,t.displayer)),t.focusScenePath&&this.control.collector){if(this.control.collector.authStorage){const{renderAuth:c,pageAuth:l}=this.control.collector.authStorage;if(c){const u=c[e];if(u){const{render:h,hide:g,clear:p}=u;this.control.renderControl.syncRenderUids(e,h,g,p);return}}if(l){const u=l[e];if(u){this.control.renderControl.syncPageAuth(e,u,!0);return}}}this.control.worker.pullServiceData(e,t.focusScenePath,{isAsync:!0,useAnimation:!1}),this.control.pluginOptions.extras.undoRedo.enableGlobal&&t.displayer.commiter&&((s=this.control.collector)!=null&&s.globalUndoRedoStackStorage[t.id])&&t.displayer.commiter.pullServiceData(this.control.collector.globalUndoRedoStackStorage[t.id])}}}listenerWindowManager(e){e.emitter.on("focusedChange",t=>{const i=t||ie;if(this.focuedViewId!==i)if(this.getView(i)){const s=this.control.worker.getLocalWorkViewId();s&&s!==i?this.setFocuedViewId(s):this.setFocuedViewId(i)}else this.tmpFocusedViewId=i}),e.emitter.on("mainViewScenePathChange",t=>{this.control.onSceneChange(t,ie)}),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:r}=t;this.control.onSceneChange(r.focusScenePath,i)}),e.emitter.on("appsChange",t=>{for(const i of this.appViews.keys())t.includes(i)||(this.destroyAppView(i),this.control.worker.destroyViewWorker(i,!0))})}onActiveHotkeyChange(e){this.control.hotkeyManager.onActiveHotkey(e)}}class rt extends ye{constructor(e){super(e);I(this,"windowManager");I(this,"viewContainerManager");const t={control:this,internalMsgEmitter:ye.InternalMsgEmitter,publicMsgEmitter:ye.PublicMsgEmitter};this.viewContainerManager=new ot(t)}init(){}activePlugin(){this.collector&&(this.collector.addAuthStateListener((e,t)=>{e&&Object.keys(e).forEach(i=>{var s;const r=(s=e[i])==null?void 0:s.newValue;this.renderControl.syncRenderUids(i,r==null?void 0:r.render,r==null?void 0:r.hide,r==null?void 0:r.clear)}),t&&Object.keys(t).forEach(i=>{var s;const r=(s=t[i])==null?void 0:s.newValue;this.renderControl.syncPageAuth(i,r)})}),this.collector.addStorageStateListener(e=>{var a,c;if((a=this.collector)!=null&&a.storage&&Object.keys(this.collector.storage).length===0){(c=this.worker)==null||c.clearViewScenePath(ie,!0);return}const{diffView:t,diffScenePath:i,diffData:r}=e,s=new Map;if(t){let l;Object.keys(t).forEach(u=>{var g;const h=t[u];if(h&&!h.newValue)(g=this.worker)==null||g.clearViewScenePath(u,!0),h.oldValue&&(l=h.oldValue);else if(h&&h.newValue){for(const p of Object.keys(h.newValue))this.worker.pullServiceData(u,p,{isAsync:!1,useAnimation:!1});l=h.newValue}if(l)for(const p of Object.values(l)){const d=new Set;for(const M of Object.keys(p))M&&d.add(M);s.set(u,d)}})}if(i){let l;Object.keys(i).forEach(u=>{var g;const h=i[u];if(h&&h.viewId&&!h.newValue?((g=this.worker)==null||g.clearViewScenePath(h.viewId,!0),h.oldValue&&(l=h.oldValue)):h&&h.viewId&&h.newValue&&(this.worker.pullServiceData(h.viewId,u,{isAsync:!1,useAnimation:!1}),l=h.newValue),h!=null&&h.viewId&&l){const p=new Set;for(const d of Object.keys(l))d&&p.add(d),s.set(h.viewId,p)}})}r&&Object.keys(r).forEach(l=>{var h,g;const u=r[l];if(u){const{viewId:p}=u,d=s.get(p)||new Set;d.add(l),s.set(p,d),(h=this.worker)==null||h.onServiceDerive(l,u),(g=this.miniMapManager)==null||g.updateMiniMapCamera(p)}});for(const[l,u]of s.entries())ye.InternalMsgEmitter.emit("excludeIds",[...u],l)}),this.pluginOptions.extras.undoRedo.enableGlobal&&this.collector.addGlobalUndoRedoStackListener(e=>{Object.keys(e).forEach(t=>{var s;const i=e[t],r=(s=this.viewContainerManager.getView(t))==null?void 0:s.displayer.commiter;r&&r.pullServiceData(i==null?void 0:i.newValue)})}),this.worker.isActive&&this.viewContainerManager.getAllViews().forEach(e=>{e&&e.focusScenePath&&this.worker.pullServiceData(e.id,e.focusScenePath,{isAsync:!0,useAnimation:!1})}),this.room&&this.roomMember.onUidChangeHook(e=>{var t,i;(t=this.collector)!=null&&t.serviceStorage&&this.viewContainerManager.getAllViews().forEach(r=>{var s,a,c,l;if(r&&r.focusScenePath&&((s=this.collector)!=null&&s.serviceStorage[r.id])&&this.collector.serviceStorage[r.id][r.focusScenePath]){const u=Object.keys(this.collector.serviceStorage[r.id][r.focusScenePath]);for(const h of u){const g=(a=this.collector)==null?void 0:a.getUidFromKey(h);if(g&&!e.online.includes(g))if((c=this.collector)!=null&&c.isSelector(h))this.renderControl.isWritable&&((l=this.collector)==null||l.updateValue(h,void 0,{viewId:r.id,scenePath:r.focusScenePath,isSync:!0})),this.worker.blurSelector(r.id,r.focusScenePath,h);else{const p=this.textEditorManager.editors.get(h);p&&p.opt&&(p.opt.workState===E.Doing||p.opt.workState===E.Start)&&(p.opt.text&&p.opt.text.replace(/\s*,/g,"")?this.textEditorManager.unActive(h):this.textEditorManager.delete(h))}}}}),(i=this.cursor)==null||i.updateRoomMembers(e)}))}async activeWorker(){await this.worker.init()}setWindowManager(e){var t,i,r,s,a;this.windowManager=e,(i=(t=this.windowManager)==null?void 0:t.mainView)!=null&&i.divElement&&this.viewContainerManager.onMainViewMounted(this.windowManager.mainView),(a=(s=(r=this.windowManager.appManager)==null?void 0:r.viewManager)==null?void 0:s.views)!=null&&a.size&&this.windowManager.appManager.viewManager.views.forEach((c,l)=>{this.viewContainerManager.onAppViewMounted({appId:l,view:c})}),this.viewContainerManager.listenerWindowManager(this.windowManager)}}const L=class L extends kr{constructor(){super(...arguments);I(this,"onPhaseChanged",e=>{var t;e===xr.Reconnecting&&((t=L.currentManager)==null||t.setSnapshootData())});I(this,"updateRoomWritable",()=>{var e;(e=L.currentManager)==null||e.onWritableChange(this.displayer.isWritable)});I(this,"roomStateChangeListener",async e=>{var t,i;e!=null&&e.roomMembers&&((t=L.currentManager)==null||t.onRoomMembersChange(e.roomMembers)),!(Q(this.displayer)&&!this.displayer.isWritable)&&e.memberState&&((i=L.currentManager)==null||i.onMemberChange(e.memberState))})}static async getInstance(e,t){var w;t.options&&(((w=t.options.extras)==null?void 0:w.useWorker)==="mainThread"&&(t.options.cdn.fullWorkerUrl="",t.options.cdn.subWorkerUrl=""),(t.options.extras&&t.options.extras.useWorker!=="mainThread"||!t.options.extras)&&!t.options.cdn.fullWorkerUrl&&!t.options.cdn.subWorkerUrl&&L.logger.error("[Appliance]: [ApplianceMultiPlugin] you must adaptor options cdn fullWorkerUrl and subWorkerUrl"));const i=e.displayer,r=i.callbacks.on,s=i.callbacks.off,a=i.callbacks.once,c=e.cleanCurrentScene,l=e.mainView.setMemberState;let u;Q(i)&&(u=i.setWritable),t!=null&&t.logger&&(L.logger=new Ni(t.logger));let h=i.getInvisiblePlugin(L.kind);h||(h=await L.createApplianceMultiPlugin(i,L.kind)),i&&h&&L.createCurrentManager(e,{cdn:t.options.cdn,extras:{...we,...t.options.extras}},h);const g={displayer:i,windowManager:e,currentManager:L.currentManager,maxScreenshotWidth:10*1024,maxScreenshotHeight:10*1024,getBoundingRectAsync:async function(m){var v;L.logger.info("[ApplianceMultiPlugin] getBoundingRectAsync");const y=(e.mainView||i).getBoundingRect(m),S=await((v=L.currentManager)==null?void 0:v.getBoundingRect(m));return!y.width||!y.height?S:wi(y,S)},screenshotToCanvasAsync:async function(m,y,S,v,k,C){var N;L.logger.info("[ApplianceMultiPlugin] screenshotToCanvasAsync");let x=S,O=v,Y=k.scale;x>this.maxScreenshotWidth&&(Y=this.maxScreenshotWidth/x*Y,x=this.maxScreenshotWidth),O>this.maxScreenshotHeight&&(Y=Math.min(this.maxScreenshotHeight/O*Y,Y),O=this.maxScreenshotHeight),k.scale=Y;const A=document.createElement("canvas"),b=A.getContext("2d");A.width=x*(C||1),A.height=O*(C||1),b&&((e.mainView||i).screenshotToCanvas(b,y,x,O,k,C),m.drawImage(A,Math.floor((S-x)/2),Math.floor((v-O)/2),x*(C||1),O*(C||1),0,0,x,O),A.remove()),L.currentManager&&await((N=L.currentManager)==null?void 0:N.screenshotToCanvas(m,y,x,O,k,Math.floor((S-x)/2),Math.floor((v-O)/2)))},scenePreviewAsync:async function(m,y,S,v,k){L.logger.info("[ApplianceMultiPlugin] scenePreviewAsync"),(e.mainView||i).scenePreview(m,y,S,v,k);const C=document.createElement("img");C.className="appliance-plugin-fill-scene-snapshot-img",y.append(C),getComputedStyle(y).position||(y.style.position="relative"),L.currentManager&&await L.currentManager.scenePreview(m,C)},fillSceneSnapshotAsync:async function(m,y,S,v,k){L.logger.info("[ApplianceMultiPlugin] fillSceneSnapshotAsync"),y.innerHTML="",(e.mainView||i).fillSceneSnapshot(m,y,S,v,k);const C=S||e.mainView.size.width,x=v||e.mainView.size.height;let O=await this.getBoundingRectAsync(m);O||(O={originX:0,originY:0,width:C,height:x});let Y=Math.max(O==null?void 0:O.width,C),A=Math.max(O==null?void 0:O.height,x),b=1;const N=Y>C&&Math.min(C/Y,b)||b,D=A>x&&Math.min(x/A,b)||b;N<=D?(Y=N<1&&C||Y,A=Math.floor(A*N)+1,b=N):N>D&&(A=D<1&&x||A,Y=Math.floor(Y*D)+1,b=D);const j={scale:b,centerX:O.originX+O.width/2,centerY:O.originY+O.height/2},B=document.createElement("canvas"),V=B.getContext("2d");B.width=Y,B.height=A,V&&await this.screenshotToCanvasAsync(V,m,Y,A,j,devicePixelRatio);const U=document.createElement("img");U.className="appliance-plugin-fill-scene-snapshot-img",U.src=B.toDataURL(),U.onload=()=>{B.remove()},U.onerror=()=>{B.remove(),U.remove()},y.append(U),getComputedStyle(y).position||(y.style.position="relative")},_callbacksOn:function(m,y){L.logger.info(`[ApplianceMultiPlugin] callbacks ${m}`),(m==="onCanUndoStepsUpdate"||m==="onCanRedoStepsUpdate")&&Q(i)&&i.isWritable?rt.InternalMsgEmitter.on(m,y):r.call(i.callbacks,m,y)},_callbacksOnce:function(m,y){L.logger.info(`[ApplianceMultiPlugin] callbacks ${m}`),(m==="onCanUndoStepsUpdate"||m==="onCanRedoStepsUpdate")&&Q(i)&&i.isWritable?rt.InternalMsgEmitter.on(m,y):a.call(i.callbacks,m,y)},_callbacksOff:function(m,y){L.logger.info(`[ApplianceMultiPlugin] callbacks ${m}`),(m==="onCanUndoStepsUpdate"||m==="onCanRedoStepsUpdate")&&Q(i)&&i.isWritable?rt.InternalMsgEmitter.off(m,y):s.call(i.callbacks,m,y)},canRedoSteps(){if(L.logger.info("[ApplianceMultiPlugin] canRedoSteps"),L.currentManager&&Q(i)&&!i.disableSerialization){const m=L.currentManager.viewContainerManager.focuedView,y=m==null?void 0:m.focusScenePath;if(m&&y)return m.displayer.commiter.redoStack.filter(S=>S.scenePath===y).length}return 0},canUndoSteps(){if(L.logger.info("[ApplianceMultiPlugin] canUndoSteps"),L.currentManager&&Q(i)&&!i.disableSerialization){const m=L.currentManager.viewContainerManager.focuedView,y=m==null?void 0:m.focusScenePath;if(m&&y)return m.displayer.commiter.undoStack.filter(k=>k.scenePath===y).length}return 0},undo:function(){return L.logger.info("[ApplianceMultiPlugin] undo"),L.currentManager&&Q(i)&&!i.disableSerialization&&i.isWritable?L.currentManager.viewContainerManager.undo():0},redo:function(){return L.logger.info("[ApplianceMultiPlugin] redo"),L.currentManager&&Q(i)&&!i.disableSerialization&&i.isWritable?L.currentManager.viewContainerManager.redo():0},cleanCurrentScene:function(){L.logger.info("[ApplianceMultiPlugin] cleanCurrentScene"),L.currentManager&&Q(i)&&i.isWritable&&(L.currentManager.logger.info("[Appliance]: cleanCurrentScene"),L.currentManager.cleanCurrentScene(),c.call(e))},insertImage:function(m){if(L.logger.info("[ApplianceMultiPlugin] insertImage"),L.currentManager&&Q(i)&&i.isWritable){const y=L.currentManager.viewContainerManager.focuedViewId||ie;L.currentManager.worker.insertImage(y,m)}},lockImage:function(m,y){if(L.logger.info("[ApplianceMultiPlugin] lockImage"),L.currentManager&&Q(i)&&i.isWritable){const S=L.currentManager.viewContainerManager.focuedViewId||ie;L.currentManager.worker.lockImage(S,m,y)}},completeImageUpload:function(m,y){if(L.logger.info("[ApplianceMultiPlugin] completeImageUpload"),L.currentManager&&Q(i)&&i.isWritable){const S=L.currentManager.viewContainerManager.focuedViewId||ie;L.currentManager.worker.completeImageUpload(S,m,y)}},getImagesInformation:function(m){return L.logger.info("[ApplianceMultiPlugin] completeImageUpload"),L.currentManager&&Q(i)&&i.isWritable?L.currentManager.worker.getImagesInformation(m):[]},insertText:function(m,y,S){if(L.logger.info("[ApplianceMultiPlugin] insertText"),L.currentManager&&Q(i)&&i.isWritable){const v=L.currentManager.viewContainerManager.focuedViewId||ie;return L.currentManager.textEditorManager.insertText(v,m,y,S)}},updateText:function(m,y){L.logger.info("[ApplianceMultiPlugin] updateText"),L.currentManager&&Q(i)&&i.isWritable&&L.currentManager.textEditorManager.updateText(m,y)},callbacks:()=>(L.logger.info("[ApplianceMultiPlugin] callbacks bind"),{...i.callbacks,on:g._callbacksOn.bind(g),once:g._callbacksOnce.bind(g),off:g._callbacksOff.bind(g)}),destroy(){L.currentManager&&(L.currentManager.logger.info("[Appliance]: [ApplianceMultiPlugin] destroy"),L.currentManager.destroy(),L.currentManager=void 0)},setMemberState(m){if(L.currentManager){L.currentManager.logger.info(`[Appliance]: setMemberState ${JSON.stringify(m)}`);const y=Object.keys(m);if(Q(i)&&i.isWritable){if(y.includes("currentApplianceName"))if(m.currentApplianceName&&m.currentApplianceName===re.laserPen){if(L.currentManager.isUseSimple)throw L.currentManager.logger.error("[Appliance]: [ApplianceMultiPlugin] laserPen must be not support in simple mode"),new Error("[Appliance]: [ApplianceMultiPlugin] laserPen must be not support in simple mode");m.currentApplianceName=re.pencil,m.useLaserPen=!0}else m.currentApplianceName&&m.currentApplianceName===re.pencil&&(m.useLaserPen=!1);l.call(e.mainView,m);return}}throw L.logger.error("[Appliance]: [ApplianceMultiPlugin] setMemberState must be called in writable room"),new Error("[Appliance]: [ApplianceMultiPlugin] setMemberState must be called in writable room")},createMiniMap:async function(m,y){if(L.logger.info("[ApplianceMultiPlugin] createMiniMap"),L.currentManager&&Q(i)&&i.isWritable)return L.currentManager.logger.info("[Appliance]: [ApplianceMultiPlugin] createMiniMap"),L.currentManager.createMiniMap(m,y)},destroyMiniMap:async function(m){if(L.logger.info("[ApplianceMultiPlugin] destroyeMiniMap"),L.currentManager&&Q(i)&&i.isWritable)return L.currentManager.logger.info("[Appliance]: [ApplianceMultiPlugin] destroyeMiniMap"),L.currentManager.destroyMiniMap(m)},filterRenderByUid(m,y,S){if(L.logger.info("[ApplianceMultiPlugin] filterRenderByUid"),L.currentManager&&Q(i)&&i.isWritable)return L.currentManager.filterRenderByUid(m,y,S)},cancelFilterRender(m,y){if(L.logger.info("[ApplianceMultiPlugin] filterRenderByUid"),L.currentManager&&Q(i)&&i.isWritable)return L.currentManager.cancelFilterRender(m,y)},addListener:(m,y)=>{L.logger.info(`[ApplianceMultiPlugin] addListener ${m}`),rt.PublicMsgEmitter.on(m,y)},removeListener:(m,y)=>{L.logger.info(`[ApplianceMultiPlugin] removeListener ${m}`),rt.PublicMsgEmitter.off(m,y)},usePlugin:m=>{var y;L.logger.info("[ApplianceMultiPlugin] usePlugin",m.kind),(y=L.currentManager)==null||y.usePlugin(m)},getDisableDeviceInputs(){if(L.currentManager&&Q(i))return L.currentManager.disableDeviceInputs},setDisableDeviceInputs(m){L.logger.info(`[ApplianceMultiPlugin] setDisableDeviceInputs ${m}`),L.currentManager&&Q(i)&&(L.currentManager.disableDeviceInputs=m)},getDisableCameraTransform(){if(L.currentManager&&Q(i))return L.currentManager.disableCameraTransform},setDisableCameraTransform(m){L.logger.info(`[ApplianceMultiPlugin] setDisableCameraTransform ${m}`),L.currentManager&&Q(i)&&(L.currentManager.disableCameraTransform=m)},getDisableEraseImage(){if(L.currentManager&&Q(i))return L.currentManager.disableEraseImage},setDisableEraseImage(m){L.logger.info(`[ApplianceMultiPlugin] setDisableEraseImage ${m}`),L.currentManager&&Q(i)&&(L.currentManager.disableEraseImage=m)},setWritable:async function(m){var y;L.logger.info(`[ApplianceMultiPlugin] setWritable ${m}`),Q(i)&&u&&(await((y=L.currentManager)==null?void 0:y.setWritable(m)),await u.call(i,m))},requestIdleCallback:(m,y)=>{const S=(y==null?void 0:y.timeout)||0,v=performance.now();let k;const C=new MessageChannel;let x;const O=Y=>{try{m({didTimeout:Y,timeRemaining:()=>{const b=performance.now()-v;return Math.max(0,S-b)}})}catch(A){L.logger.error("[ApplianceMultiPlugin] requestIdleCallback error:",A)}finally{C.port1.close(),C.port2.close(),k!==void 0&&cancelAnimationFrame(k),x!==void 0&&clearTimeout(x)}};return C.port1.onmessage=()=>{k=requestAnimationFrame(()=>{S>0&&performance.now()-v>=S?O(!0):O(!1)})},C.port2.postMessage(null),S>0&&(x=setTimeout(()=>{O(!0)},S)),x||k||0},cancelIdleCallback:m=>{try{clearTimeout(m),cancelAnimationFrame(m)}catch(y){L.logger.error("[ApplianceMultiPlugin] cancelIdleCallback error:",y)}},injectMethodToObject:(m,y)=>{if(L.logger.info(`[ApplianceMultiPlugin] injectMethodToObject ${y}`),typeof m[y]=="function"||typeof m[y]>"u"){(y==="requestIdleCallback"||y==="cancelIdleCallback")&&L.currentManager&&L.currentManager.registerPolyfillMethod(y),m[y]=g[y];return}y==="callbacks"&&(m.callbacks.on=g._callbacksOn.bind(g),m.callbacks.off=g._callbacksOff.bind(g),m.callbacks.once=g._callbacksOnce.bind(g))},blurText:()=>{L.logger.info("[ApplianceMultiPlugin] blurText"),L.currentManager&&Q(i)&&i.isWritable&&L.currentManager.textEditorManager.checkEmptyTextBlur()},hasElements:(m,y)=>{var S;if(L.logger.info(`[ApplianceMultiPlugin] hasElements ${m}`),L.currentManager&&Q(i)&&i.isWritable){let v=m;if(!v){const k=L.currentManager.viewContainerManager.focuedView;v=k==null?void 0:k.focusScenePath}if(v){const k=(S=L.currentManager.collector)==null?void 0:S.getScenePathData(v);if(k){const C=Object.values(k);return C.length>0?y?C.some(x=>y(x.toolsType)):!0:!1}return!1}return!1}},getElements:(m,y)=>{var S;if(L.logger.info(`[ApplianceMultiPlugin] getElements ${m}`),L.currentManager&&Q(i)&&i.isWritable){let v=m;if(!v){const k=L.currentManager.viewContainerManager.focuedView;v=k==null?void 0:k.focusScenePath}if(v){const k=(S=L.currentManager.collector)==null?void 0:S.getScenePathData(v),C=k&&Object.values(k)||[];return k&&C.length>0&&y?C.filter(x=>y(x.toolsType)):C}return[]}},stopDraw:m=>{if(L.logger.info(`[ApplianceMultiPlugin] stopDraw ${m}`),L.currentManager&&Q(i))return L.currentManager.stopDraw(m)},setViewLocalScenePathChange:async(m,y)=>{L.logger.info(`[ApplianceMultiPlugin] setViewLocalScenePathChange ${m} ${y}`),L.currentManager&&await L.currentManager.setViewLocalScenePathChange(y,m)},insertMarkmap:async(m,y)=>{if(L.logger.info(`[ApplianceMultiPlugin] insertMarkmap: ${m}, info: ${JSON.stringify(y)}`),L.currentManager&&L.currentManager.isUseBackgroundThread)return L.currentManager.worker.insertBackgroundMarkMap(m,y)},updateMarkmap:async(m,y,S)=>{if(L.logger.info(`[ApplianceMultiPlugin] updateMarkmap: ${m}, markmapId: ${y}, info: ${JSON.stringify(S)}`),L.currentManager&&L.currentManager.isUseBackgroundThread)return L.currentManager.worker.updateBackgroundMarkMap(m,y,S)},insertBackgroundImage:async(m,y)=>{if(L.logger.info(`[ApplianceMultiPlugin] insertBackgroundImage: ${m}, info: ${JSON.stringify(y)}`),L.currentManager&&L.currentManager.isUseBackgroundThread)return L.currentManager.worker.insertBackgroundSVG(m,y)},getSelectedElements:m=>{var y,S;return(S=(y=L.currentManager)==null?void 0:y.selectorApi)==null?void 0:S.getSelectedElements(m)},isElementPropertySupported:(m,y)=>{var S,v;return((v=(S=L.currentManager)==null?void 0:S.selectorApi)==null?void 0:v.isElementPropertySupported(m,y))||!1},blurSelector:m=>{var y;if(L.currentManager&&Q(i)&&i.isWritable){const S=(y=L.currentManager)==null?void 0:y.selectorApi;return S?S.blurSelector(m):Promise.resolve({ok:!1,requestId:`clear-${Date.now().toString(36)}`,viewId:m||ie,reason:"no-selection"})}return Promise.resolve({ok:!1,requestId:`clear-${Date.now().toString(36)}`,viewId:m||ie,reason:"no-selection"})},updateSelectedElements:(m,y)=>{var S;if(L.currentManager&&Q(i)&&i.isWritable){const v=(S=L.currentManager)==null?void 0:S.selectorApi;return v?v.updateSelectedElements(m,y):Promise.resolve({requestId:`update-${Date.now().toString(36)}`,viewId:m,ok:!1,reason:"no-selection"})}return Promise.resolve({requestId:`update-${Date.now().toString(36)}`,viewId:m,ok:!1,reason:"no-writable permission"})},updateElement:(m,y,S,v,k=!0)=>{var C;if(L.currentManager&&Q(i)&&i.isWritable){const x=(C=L.currentManager)==null?void 0:C.selectorApi;return x?x.updateElement(m,y,S,v,k):Promise.resolve(!1)}return Promise.resolve(!1)},copySelectedElements:m=>{var y;if(L.currentManager&&Q(i)&&i.isWritable){const S=(y=L.currentManager)==null?void 0:y.selectorApi;return S?S.copySelectedElements(m):Promise.resolve({ok:!1,requestId:`copy-${Date.now().toString(36)}`,viewId:m||ie,reason:"no-selection"})}return Promise.resolve({ok:!1,requestId:`copy-${Date.now().toString(36)}`,viewId:m||ie,reason:"no-selection"})},deleteSelectedElements:m=>{var y;if(L.currentManager&&Q(i)&&i.isWritable){const S=(y=L.currentManager)==null?void 0:y.selectorApi;return S?S.deleteSelectedElements(m):Promise.resolve({ok:!1,requestId:`delete-${Date.now().toString(36)}`,viewId:m||ie,reason:"no-selection"})}return Promise.resolve({ok:!1,requestId:`delete-${Date.now().toString(36)}`,viewId:m||ie,reason:"no-selection"})},getFloatbarContainer:m=>{var y;return(y=L.currentManager)==null?void 0:y.viewContainerManager.getFloatbarContainer(m)},getViewOffsetToContainer:(m,y)=>{var S;return(S=L.currentManager)==null?void 0:S.viewContainerManager.getViewOffsetToContainer(m,y)}};g.injectMethodToObject(e,"undo"),g.injectMethodToObject(e,"redo"),g.injectMethodToObject(e,"cleanCurrentScene"),g.injectMethodToObject(e,"blurSelector"),g.injectMethodToObject(e,"updateElement"),g.injectMethodToObject(e,"insertImage"),g.injectMethodToObject(e,"completeImageUpload"),g.injectMethodToObject(e,"lockImage"),g.injectMethodToObject(e,"insertText"),g.injectMethodToObject(e,"updateText"),g.injectMethodToObject(i,"getImagesInformation"),g.injectMethodToObject(i,"callbacks"),g.injectMethodToObject(i,"screenshotToCanvasAsync"),g.injectMethodToObject(i,"getBoundingRectAsync"),g.injectMethodToObject(i,"scenePreviewAsync"),g.injectMethodToObject(i,"fillSceneSnapshotAsync"),g.injectMethodToObject(i,"blurSelector"),g.injectMethodToObject(i,"updateElement"),g.injectMethodToObject(e.mainView,"setMemberState"),Q(i)&&g.injectMethodToObject(i,"setWritable"),Object.defineProperty(e,"canUndoSteps",{get(){return g.canUndoSteps()}}),Object.defineProperty(e,"canRedoSteps",{get(){return g.canRedoSteps()}});const p=(m,y,S=3)=>{const v=e.focused||ie;S>0&&v!==m?setTimeout(()=>{p(m,y,S-1)},100):e.emitter.emit("canUndoStepsChange",y)};rt.InternalMsgEmitter.on("onCanUndoStepsUpdate",(m,y)=>{p(y,m)});const d=(m,y,S=3)=>{const v=e.focused||ie;S>0&&v!==m?setTimeout(()=>{d(m,y,S-1)},100):e.emitter.emit("canRedoStepsChange",y)};rt.InternalMsgEmitter.on("onCanRedoStepsUpdate",(m,y)=>{d(y,m)});const M={...g,callbacks:g.callbacks()};return Object.defineProperty(M,"disableDeviceInputs",{set(m){g.setDisableDeviceInputs(m)},get(){return g.getDisableDeviceInputs()}}),Object.defineProperty(M,"disableCameraTransform",{set(m){g.setDisableCameraTransform(m)},get(){return g.getDisableCameraTransform()}}),Object.defineProperty(M,"disableEraseImage",{set(m){g.setDisableEraseImage(m)},get(){return g.getDisableEraseImage()}}),h&&L.currentManager&&(L.currentManager.bindPlugin(h),h.init(i)),e._appliancePlugin=M,e._appliancePlugin}static onCreate(e){e&&L.currentManager&&(L.currentManager.bindPlugin(e),e.init(e.displayer))}static async createApplianceMultiPlugin(e,t){try{await e.createInvisiblePlugin(L,{})}catch(r){if(!e.isWritable){await e.setWritable(!0);const s=await this.createApplianceMultiPlugin(e,t);return await e.setWritable(!1),s}throw r}let i=e.getInvisiblePlugin(t);return i||(i=await L.createApplianceMultiPlugin(e,t)),i}get isReplay(){return oi(this.displayer)}get callbackName(){return this.isReplay?"onPlayerStateChanged":"onRoomStateChanged"}init(e){var i,r;const t=e.state;(i=L.currentManager)==null||i.onRoomMembersChange(t.roomMembers),Q(e)&&((r=L.currentManager)==null||r.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;L.logger.info("[ApplianceMultiPlugin] passive destroy"),(e=L.currentManager)==null||e.destroy(),L.currentManager=void 0}};I(L,"kind","appliance-multi-plugin"),I(L,"currentManager"),I(L,"logger",{info:console.log,warn:console.warn,error:console.error}),I(L,"createCurrentManager",(e,t,i)=>{L.currentManager&&L.currentManager.destroy();const r={plugin:i,displayer:e.displayer,options:t},s=new rt(r);if(L.logger.info("[ApplianceMultiPlugin] refresh ApplianceMultiManager object"),s.setWindowManager(e),L.currentManager=s,e.room){const a=s.hasOffscreenCanvas;e.room.logger.info(`[Appliance]: [ApplianceMultiPlugin] use ${a?"worker":"mainThread"}`)}});let ti=L;var BI=Je,WI=function(){return BI.Date.now()},VI=WI,FI=/\s/;function $I(o){for(var n=o.length;n--&&FI.test(o.charAt(n)););return n}var GI=$I,QI=GI,ZI=/^\s+/;function HI(o){return o&&o.slice(0,QI(o)+1).replace(ZI,"")}var qI=HI,KI=Rt,JI=ct,XI="[object Symbol]";function _I(o){return typeof o=="symbol"||JI(o)&&KI(o)==XI}var ew=_I,tw=qI,Ir=lt,nw=ew,wr=NaN,iw=/^[-+]0x[0-9a-f]+$/i,rw=/^0b[01]+$/i,ow=/^0o[0-7]+$/i,sw=parseInt;function aw(o){if(typeof o=="number")return o;if(nw(o))return wr;if(Ir(o)){var n=typeof o.valueOf=="function"?o.valueOf():o;o=Ir(n)?n+"":n}if(typeof o!="string")return o===0?o:+o;o=tw(o);var e=rw.test(o);return e||ow.test(o)?sw(o.slice(2),e?2:8):iw.test(o)?wr:+o}var cw=aw,lw=lt,Yn=VI,Tr=cw,uw="Expected a function",hw=Math.max,dw=Math.min;function gw(o,n,e){var t,i,r,s,a,c,l=0,u=!1,h=!1,g=!0;if(typeof o!="function")throw new TypeError(uw);n=Tr(n)||0,lw(e)&&(u=!!e.leading,h="maxWait"in e,r=h?hw(Tr(e.maxWait)||0,n):r,g="trailing"in e?!!e.trailing:g);function p(C){var x=t,O=i;return t=i=void 0,l=C,s=o.apply(O,x),s}function d(C){return l=C,a=setTimeout(m,n),u?p(C):s}function M(C){var x=C-c,O=C-l,Y=n-x;return h?dw(Y,r-O):Y}function w(C){var x=C-c,O=C-l;return c===void 0||x>=n||x<0||h&&O>=r}function m(){var C=Yn();if(w(C))return y(C);a=setTimeout(m,M(C))}function y(C){return a=void 0,g&&t?p(C):(t=i=void 0,s)}function S(){a!==void 0&&clearTimeout(a),l=0,t=c=i=a=void 0}function v(){return a===void 0?s:y(Yn())}function k(){var C=Yn(),x=w(C);if(t=arguments,i=this,c=C,x){if(a===void 0)return d(c);if(h)return clearTimeout(a),a=setTimeout(m,n),p(c)}return a===void 0&&(a=setTimeout(m,n)),s}return k.cancel=S,k.flush=v,k}var fw=gw,pw=fw,Mw=lt,yw="Expected a function";function mw(o,n,e){var t=!0,i=!0;if(typeof o!="function")throw new TypeError(yw);return Mw(e)&&(t="leading"in e?!!e.leading:t,i="trailing"in e?!!e.trailing:i),pw(o,n,{leading:t,maxWait:n,trailing:i})}var Iw=mw;const ww=yn(Iw);class Tw extends To{constructor(e,t){super(e,t);I(this,"width",1e3);I(this,"height",1e3);I(this,"dpr",Pt());I(this,"vDom");I(this,"eventTragetElement");I(this,"snapshotContainerRef");I(this,"backgroundContainerRef");I(this,"backgroundSnapshotContainerRef");I(this,"canvasContainerRef",f.createRef());I(this,"subLocalCanvasContainerRef");I(this,"canvasTopRef");I(this,"canvasServiceFloatRef",f.createRef());I(this,"canvasFloatRef",f.createRef());I(this,"canvasBgRef",f.createRef());I(this,"floatBarRef",f.createRef());I(this,"customFloatbarContainerRef",f.createRef());I(this,"containerOffset",{x:0,y:0});this.control.hasOffscreenCanvas||(this.snapshotContainerRef=f.createRef()),this.control.isUseSimple||(this.canvasTopRef=f.createRef(),this.subLocalCanvasContainerRef=f.createRef()),this.control.isUseBackgroundThread&&(this.backgroundContainerRef=f.createRef(),this.backgroundSnapshotContainerRef=f.createRef())}setCanvassStyle(){var e;if(this.eventTragetElement){const t=this.eventTragetElement.offsetWidth,i=this.eventTragetElement.offsetHeight,r=Pt();r!==this.dpr&&(this.dpr=r,this.control.worker.updateDpr(this.viewId,this.dpr)),t&&i&&this.canvasContainerRef.current&&(t!==this.width||i!==this.height)&&(this.width=t,this.height=i),t&&i&&this.backgroundContainerRef&&this.backgroundContainerRef.current&&(t!==this.width||i!==this.height)&&(this.width=t,this.height=i,this.backgroundContainerRef.current.style.width=`${t}px`,this.backgroundContainerRef.current.style.height=`${i}px`,this.backgroundContainerRef.current.classList.toggle("appliance-plugin-background-isWritable",this.control.renderControl.isWritable)),t&&i&&this.canvasBgRef.current&&(t!==this.width||i!==this.height)&&(this.width=t,this.height=i,this.control.isUseOffscreenTransfer||(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),(e=this.canvasTopRef)!=null&&e.current&&(this.canvasTopRef.current.width=t*this.dpr,this.canvasTopRef.current.height=i*this.dpr)))}}createMainViewDisplayer(e){return this.vDom||(this.containerOffset=this.getContainerOffset(e,this.containerOffset),this.eventTragetElement=e.parentElement.children[0],e.innerHTML="",pn.render(f.createElement(Ci,{viewId:this.viewId,mananger:this,refs:{canvasServiceFloatRef:this.canvasServiceFloatRef,canvasFloatRef:this.canvasFloatRef,canvasBgRef:this.canvasBgRef,floatBarRef:this.floatBarRef,customFloatbarContainerRef:this.customFloatbarContainerRef,canvasTopRef:this.canvasTopRef,canvasContainerRef:this.canvasContainerRef,snapshotContainerRef:this.snapshotContainerRef,subLocalCanvasContainerRef:this.subLocalCanvasContainerRef,backgroundContainerRef:this.backgroundContainerRef,backgroundSnapshotContainerRef:this.backgroundSnapshotContainerRef}}),e),this.control.room&&this.bindDisplayerEvent(this.eventTragetElement)),this}}class wt extends Lt{constructor(e){super(e);I(this,"focuedViewId");I(this,"control");I(this,"focuedView");this.control=e.control}bindMainView(){if(!this.control.divMainView)return;const e=new Tw(this.control,ye.InternalMsgEmitter),{width:t,height:i,dpr:r}=e,s={cameraOpt:{...wt.defaultCameraOpt,width:t,height:i}},a=this.control.room&&this.control.room.mainView||this.control.play&&this.control.play.mainView;if(a){const{scale:c,...l}=a.camera;s.cameraOpt={...s.cameraOpt,...l,scale:c===1/0?1:c},this.createMianView({id:ie,displayer:e,focusScenePath:a.focusScenePath||a.scenePath,cameraOpt:s.cameraOpt,viewData:a}),this.setFocuedViewId(ie),e.createMainViewDisplayer(this.control.divMainView)}}getViewInitData(e){var i;const t=this.getView(e);if(t){const{width:r,height:s,dpr:a}=t.displayer;(i=this.control.pluginOptions.extras.canvasOpt)!=null&&i.contextType&&(wt.defaultScreenCanvasOpt.contextType=this.control.pluginOptions.extras.canvasOpt.contextType);const c={dpr:a,originalPoint:[r/2,s/2],offscreenCanvasOpt:{...wt.defaultScreenCanvasOpt,width:r,height:s},layerOpt:{...wt.defaultLayerOpt,width:r,height:s},cameraOpt:{...wt.defaultCameraOpt,width:r,height:s}};if(t.viewData){const{scale:l,...u}=t.viewData.camera;c.cameraOpt={...c.cameraOpt,...u,scale:l===1/0?1:l}}return c}}async mountView(e){var i;const t=this.getView(e);if(t){this.control.worker.isActive||(this.control.cursor.activeCollector(),this.control.isUseOffscreenTransfer&&t.displayer.canvasBgRef.current&&t.displayer.canvasServiceFloatRef.current&&t.displayer.canvasFloatRef.current&&t.displayer.setTransferControlToOffscreenCanvas({bgCanvas:t.displayer.canvasBgRef.current,serviceCanvas:t.displayer.canvasServiceFloatRef.current,localCanvas:t.displayer.canvasFloatRef.current}),await this.control.activeWorker());const r=this.getViewInitData(e);r&&((i=this.control.worker)==null||i.createViewWorker(e,r,t.displayer)),t.focusScenePath&&this.control.collector&&this.control.worker.pullServiceData(e,t.focusScenePath,{isAsync:!0,useAnimation:!1})}}}class Ge extends ye{constructor(e){super(e);I(this,"viewContainerManager");I(this,"divMainView");I(this,"onCameraChange",ww(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)},Mn,{leading:!1}));const t={control:this,internalMsgEmitter:Ge.InternalMsgEmitter,publicMsgEmitter:Ge.PublicMsgEmitter};this.viewContainerManager=new wt(t)}init(){Ge.InternalMsgEmitter.on(te.BindMainView,e=>{this.divMainView=e,this.plugin&&!this.viewContainerManager.mainView&&this.viewContainerManager.bindMainView()})}activePlugin(){this.plugin&&this.divMainView&&!this.viewContainerManager.mainView&&this.viewContainerManager.bindMainView(),this.collector&&(this.collector.addStorageStateListener(e=>{var a,c;if((a=this.collector)!=null&&a.storage&&Object.keys(this.collector.storage).length===0){(c=this.worker)==null||c.clearViewScenePath(ie,!0);return}const{diffView:t,diffScenePath:i,diffData:r}=e,s=new Map;if(t){let l;Object.keys(t).forEach(u=>{var g;const h=t[u];if(h&&!h.newValue)(g=this.worker)==null||g.clearViewScenePath(u,!0),h.oldValue&&(l=h.oldValue);else if(h&&h.newValue){for(const p of Object.keys(h.newValue))this.worker.pullServiceData(u,p,{isAsync:!1,useAnimation:!0});l=h.newValue}if(l)for(const p of Object.values(l)){const d=new Set;for(const M of Object.keys(p))M&&d.add(M);s.set(u,d)}})}if(i){let l;Object.keys(i).forEach(u=>{var g;const h=i[u];if(h&&h.viewId&&!h.newValue?((g=this.worker)==null||g.clearViewScenePath(h.viewId,!0),h.oldValue&&(l=h.oldValue)):h&&h.viewId&&h.newValue&&(this.worker.pullServiceData(h.viewId,u,{isAsync:!1,useAnimation:!0}),l=h.newValue),h!=null&&h.viewId&&l){const p=new Set;for(const d of Object.keys(l))d&&p.add(d),s.set(h.viewId,p)}})}r&&Object.keys(r).forEach(l=>{var h,g;const u=r[l];if(u){const{viewId:p}=u,d=s.get(p)||new Set;d.add(l),s.set(p,d),(h=this.worker)==null||h.onServiceDerive(l,u),(g=this.miniMapManager)==null||g.updateMiniMapCamera(p)}});for(const[l,u]of s.entries())ye.InternalMsgEmitter.emit("excludeIds",[...u],l)}),this.room&&(this.roomMember.onUidChangeHook(e=>{var t;(t=this.collector)!=null&&t.serviceStorage&&this.viewContainerManager.getAllViews().forEach(i=>{var r,s,a,c,l,u;if(i&&i.focusScenePath&&((r=this.collector)!=null&&r.serviceStorage[i.id])&&((s=this.collector)!=null&&s.serviceStorage[i.id][i.focusScenePath])){const h=Object.keys((a=this.collector)==null?void 0:a.serviceStorage[i.id][i.focusScenePath]);for(const g of h){const p=(c=this.collector)==null?void 0:c.getUidFromKey(g);if(p&&!e.online.includes(p))if((l=this.collector)!=null&&l.isSelector(g))this.renderControl.isWritable&&((u=this.collector)==null||u.updateValue(g,void 0,{viewId:i.id,scenePath:i.focusScenePath,isSync:!0})),this.worker.blurSelector(i.id,i.focusScenePath,g);else{const d=this.textEditorManager.editors.get(g);d&&d.opt&&(d.opt.workState===E.Doing||d.opt.workState===E.Start)&&(d.opt.text&&d.opt.text.replace(/\s*,/g,"")?this.textEditorManager.unActive(g):this.textEditorManager.delete(g))}}}})}),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 P=class P extends kr{constructor(){super(...arguments);I(this,"onPhaseChanged",e=>{var t;e===xr.Reconnecting&&((t=P.currentManager)==null||t.setSnapshootData())});I(this,"updateRoomWritable",()=>{var e;(e=P.currentManager)==null||e.onWritableChange(this.displayer.isWritable)});I(this,"roomStateChangeListener",async e=>{var t,i;P.currentManager instanceof Ge&&(e.cameraState&&P.currentManager.onCameraChange(e.cameraState),e.sceneState&&P.currentManager.onSceneChange(e.sceneState.scenePath,ie)),e!=null&&e.roomMembers&&((t=P.currentManager)==null||t.onRoomMembersChange(e.roomMembers)),!(Q(this.displayer)&&!this.displayer.isWritable)&&e.memberState&&((i=P.currentManager)==null||i.onMemberChange(e.memberState))})}static async getInstance(e,t){var p;t.options&&(((p=t.options.extras)==null?void 0:p.useWorker)==="mainThread"&&(t.options.cdn.fullWorkerUrl="",t.options.cdn.subWorkerUrl=""),(t.options.extras&&t.options.extras.useWorker!=="mainThread"||!t.options.extras)&&!t.options.cdn.fullWorkerUrl&&!t.options.cdn.subWorkerUrl&&P.logger.error("[ApplianceSinglePlugin] you must adaptor options cdn fullWorkerUrl and subWorkerUrl"));const i=e.callbacks.on,r=e.callbacks.off,s=e.callbacks.once,a=e.cleanCurrentScene.bind(e),c=e.setMemberState.bind(e);let l;Q(e)&&(l=e.setWritable),t!=null&&t.logger&&(P.logger=new Ni(t.logger));let u=e.getInvisiblePlugin(P.kind);u||(u=await P.createAppliancePlugin(e,P.kind)),e&&u&&P.createCurrentManager(e,{cdn:t.options.cdn,extras:{...we,...t.options.extras}},u),u&&P.currentManager&&(P.currentManager.bindPlugin(u),u.init(e)),t!=null&&t.cursorAdapter&&(P.cursorAdapter=t.cursorAdapter),P.effectInstance();const h={displayer:e,currentManager:P.currentManager,maxScreenshotWidth:10*1024,maxScreenshotHeight:10*1024,_injectTargetObject:void 0,getBoundingRectAsync:async function(d){var m;P.logger.info("[ApplianceSinglePlugin] getBoundingRectAsync");const M=e.getBoundingRect(d),w=await((m=P.currentManager)==null?void 0:m.getBoundingRect(d));return!M.width||!M.height?w:wi(M,w)},screenshotToCanvasAsync:async function(d,M,w,m,y,S){var Y;P.logger.info("[ApplianceSinglePlugin] screenshotToCanvasAsync");let v=w,k=m,C=y.scale;v>this.maxScreenshotWidth&&(C=this.maxScreenshotWidth/v*C,v=this.maxScreenshotWidth),k>this.maxScreenshotHeight&&(C=Math.min(this.maxScreenshotHeight/k*C,C),k=this.maxScreenshotHeight),y.scale=C;const x=document.createElement("canvas"),O=x.getContext("2d");x.width=v*(S||1),x.height=k*(S||1),O&&(e.screenshotToCanvas(O,M,v,k,y,S),d.drawImage(x,Math.floor((w-v)/2),Math.floor((m-k)/2),v*(S||1),k*(S||1),0,0,v,k),x.remove()),P.currentManager&&await((Y=P.currentManager)==null?void 0:Y.screenshotToCanvas(d,M,v,k,y,Math.floor((w-v)/2),Math.floor((m-k)/2)))},scenePreviewAsync:async function(d,M,w,m,y){P.logger.info("[ApplianceSinglePlugin] scenePreviewAsync"),e.scenePreview(d,M,w,m,y);const S=document.createElement("img");S.className="appliance-plugin-fill-scene-snapshot-img",M.append(S),getComputedStyle(M).position||(M.style.position="relative"),P.currentManager&&await P.currentManager.scenePreview(d,S)},fillSceneSnapshotAsync:async function(d,M,w,m,y){var B,V;P.logger.info("[ApplianceSinglePlugin] fillSceneSnapshotAsync"),M.innerHTML="",e.fillSceneSnapshot(d,M,w,m,y);const S=w||((B=e.state.cameraState)==null?void 0:B.width)||0,v=m||((V=e.state.cameraState)==null?void 0:V.height)||0;let k=await this.getBoundingRectAsync(d);k||(k={originX:0,originY:0,width:S,height:v});let C=Math.max(k==null?void 0:k.width,S),x=Math.max(k==null?void 0:k.height,v),O=1;const Y=C>S&&Math.min(S/C,O)||O,A=x>v&&Math.min(v/x,O)||O;Y<=A?(C=Y<1&&S||C,x=Math.floor(x*Y)+1,O=Y):Y>A&&(x=A<1&&v||x,C=Math.floor(C*A)+1,O=A);const b={scale:O,centerX:k.originX+k.width/2,centerY:k.originY+k.height/2},N=document.createElement("canvas"),D=N.getContext("2d");N.width=C,N.height=x,D&&await this.screenshotToCanvasAsync(D,d,C,x,b,devicePixelRatio);const j=document.createElement("img");j.className="appliance-plugin-fill-scene-snapshot-img",j.src=N.toDataURL(),j.onload=()=>{N.remove()},j.onerror=()=>{N.remove(),j.remove()},M.append(j),getComputedStyle(M).position||(M.style.position="relative")},_callbacksOn:function(d,M){P.logger.info(`[ApplianceSinglePlugin] callbacks ${d}`),(d==="onCanUndoStepsUpdate"||d==="onCanRedoStepsUpdate")&&Q(e)&&e.isWritable?Ge.InternalMsgEmitter.on(d,M):i.call(e.callbacks,d,M)},_callbacksOnce:function(d,M){P.logger.info(`[ApplianceSinglePlugin] callbacks ${d}`),(d==="onCanUndoStepsUpdate"||d==="onCanRedoStepsUpdate")&&Q(e)&&e.isWritable?Ge.InternalMsgEmitter.on(d,M):s.call(e.callbacks,d,M)},_callbacksOff:function(d,M){P.logger.info(`[ApplianceSinglePlugin] callbacks ${d}`),(d==="onCanUndoStepsUpdate"||d==="onCanRedoStepsUpdate")&&Q(e)&&e.isWritable?Ge.InternalMsgEmitter.off(d,M):r.call(e.callbacks,d,M)},canRedoSteps(){if(P.logger.info("[ApplianceSinglePlugin] canRedoSteps"),P.currentManager&&Q(e)&&!e.disableSerialization){const d=P.currentManager.viewContainerManager.focuedView,M=d==null?void 0:d.focusScenePath;if(d&&M)return d.displayer.commiter.redoStack.filter(w=>w.scenePath===M).length}return 0},canUndoSteps(){if(P.logger.info("[ApplianceSinglePlugin] canUndoSteps"),P.currentManager&&Q(e)&&!e.disableSerialization){const d=P.currentManager.viewContainerManager.focuedView,M=d==null?void 0:d.focusScenePath;if(d&&M)return d.displayer.commiter.undoStack.filter(w=>w.scenePath===M).length}return 0},undo:function(){return P.logger.info("[ApplianceSinglePlugin] undo"),P.currentManager&&Q(e)&&!e.disableSerialization?P.currentManager.viewContainerManager.undo():0},redo:function(){return P.logger.info("[ApplianceSinglePlugin] redo"),P.currentManager&&Q(e)&&!e.disableSerialization?P.currentManager.viewContainerManager.redo():0},cleanCurrentScene:function(d){P.logger.info("[ApplianceSinglePlugin] cleanCurrentScene"),P.currentManager&&Q(e)&&e.isWritable&&(P.currentManager.cleanCurrentScene(),a.call(e,d))},insertImage:function(d){P.logger.info("[ApplianceSinglePlugin] insertImage"),P.currentManager&&Q(e)&&e.isWritable&&P.currentManager.worker.insertImage(ie,d)},lockImage:function(d,M){P.logger.info("[ApplianceSinglePlugin] lockImage"),P.currentManager&&Q(e)&&e.isWritable&&P.currentManager.worker.lockImage(ie,d,M)},completeImageUpload:function(d,M){P.logger.info("[ApplianceSinglePlugin] completeImageUpload"),P.currentManager&&Q(e)&&e.isWritable&&P.currentManager.worker.completeImageUpload(ie,d,M)},getImagesInformation:function(d){return P.logger.info("[ApplianceSinglePlugin] completeImageUpload"),P.currentManager&&Q(e)&&e.isWritable?P.currentManager.worker.getImagesInformation(d):[]},insertText:function(d,M,w){if(P.logger.info("[ApplianceSinglePlugin] insertText"),P.currentManager&&Q(e)&&e.isWritable)return P.currentManager.textEditorManager.insertText(ie,d,M,w)},updateText:function(d,M){P.logger.info("[ApplianceMultiPlugin] updateText"),P.currentManager&&Q(e)&&e.isWritable&&P.currentManager.textEditorManager.updateText(d,M)},callbacks:()=>({...e.callbacks,on:h._callbacksOn.bind(h),once:h._callbacksOnce.bind(h),off:h._callbacksOff.bind(h)}),destroy(){P.currentManager&&(P.logger.info("[ApplianceSinglePlugin] destroy"),P.currentManager.destroy(),P.currentManager=void 0,P.cursorAdapter=void 0)},setMemberState(d){var w;P.logger.info(`[ApplianceSinglePlugin] setMemberState ${JSON.stringify(d)}`);const M=Object.keys(d);if(Q(e)&&e.isWritable){if(M.includes("currentApplianceName"))if(d.currentApplianceName&&d.currentApplianceName===re.laserPen){if((w=P.currentManager)!=null&&w.isUseSimple)throw new Error("[ApplianceMultiPlugin] laserPen must be not support in simple mode");d.currentApplianceName=re.pencil,d.useLaserPen=!0}else d.currentApplianceName&&d.currentApplianceName===re.pencil&&(d.useLaserPen=!1);c(d);return}throw new Error("setMemberState must be called in writable room")},createMiniMap:async function(d,M){if(P.logger.info("[ApplianceSinglePlugin] createMiniMap"),P.currentManager&&Q(e)&&e.isWritable)return P.currentManager.createMiniMap(d,M)},destroyMiniMap:async function(d){if(P.logger.info("[ApplianceMultiPlugin] destroyeMiniMap"),P.currentManager&&Q(e)&&e.isWritable)return P.currentManager.destroyMiniMap(d)},filterRenderByUid(d,M,w){if(P.logger.info("[ApplianceSinglePlugin] filterRenderByUid"),P.currentManager&&Q(e)&&e.isWritable)return P.currentManager.filterRenderByUid(d,M,w)},cancelFilterRender(d,M){if(P.logger.info("[ApplianceSinglePlugin] filterRenderByUid"),P.currentManager&&Q(e)&&e.isWritable)return P.currentManager.cancelFilterRender(d,M)},addListener:(d,M)=>{P.logger.info(`[ApplianceSinglePlugin] addListener ${d}`),Ge.PublicMsgEmitter.on(d,M)},removeListener:(d,M)=>{P.logger.info(`[ApplianceSinglePlugin] removeListener ${d}`),Ge.PublicMsgEmitter.off(d,M)},usePlugin:d=>{var M;P.logger.info("[ApplianceSinglePlugin] usePlugin",d.kind),(M=P.currentManager)==null||M.usePlugin(d)},getDisableDeviceInputs(){if(P.currentManager&&Q(e))return P.currentManager.disableDeviceInputs},setDisableDeviceInputs(d){P.logger.info(`[ApplianceSinglePlugin] setDisableDeviceInputs ${d}`),P.currentManager&&Q(e)&&(P.currentManager.disableDeviceInputs=d)},getDisableCameraTransform(){if(P.currentManager&&Q(e))return P.currentManager.disableCameraTransform},setDisableCameraTransform(d){P.logger.info(`[ApplianceSinglePlugin] setDisableCameraTransform ${d}`),P.currentManager&&Q(e)&&(P.currentManager.disableCameraTransform=d)},getDisableEraseImage(){if(P.currentManager&&Q(e))return P.currentManager.disableEraseImage},setDisableEraseImage(d){P.logger.info(`[ApplianceSinglePlugin] setDisableEraseImage ${d}`),P.currentManager&&Q(e)&&(P.currentManager.disableEraseImage=d)},setWritable:async function(d){var M;P.logger.info(`[ApplianceSinglePlugin] setWritable ${d}`),Q(e)&&l&&(await((M=P.currentManager)==null?void 0:M.setWritable(d)),await l.call(e,d))},requestIdleCallback:(d,M)=>{const w=(M==null?void 0:M.timeout)||0,m=performance.now();let y;const S=new MessageChannel;let v;const k=C=>{try{d({didTimeout:C,timeRemaining:()=>{const O=performance.now()-m;return Math.max(0,w-O)}})}catch(x){P.logger.error("[ApplianceSinglePlugin] requestIdleCallback error:",x)}finally{S.port1.close(),S.port2.close(),y!==void 0&&cancelAnimationFrame(y),v!==void 0&&clearTimeout(v)}};return S.port1.onmessage=()=>{y=requestAnimationFrame(()=>{w>0&&performance.now()-m>=w?k(!0):k(!1)})},S.port2.postMessage(null),w>0&&(v=setTimeout(()=>{k(!0)},w)),v||y||0},cancelIdleCallback:d=>{try{clearTimeout(d),cancelAnimationFrame(d)}catch(M){P.logger.error("[ApplianceSinglePlugin] cancelIdleCallback error:",M)}},injectMethodToObject:(d,M)=>{if(P.logger.info(`[ApplianceSinglePlugin] injectMethodToObject ${M}`),typeof d[M]=="function"||typeof d[M]>"u"){d[M]=h[M];return}M==="callbacks"&&(d.callbacks.on=h._callbacksOn.bind(h),d.callbacks.off=h._callbacksOff.bind(h),d.callbacks.once=h._callbacksOnce.bind(h))},blurText:()=>{P.logger.info("[ApplianceSinglePlugin] blurText"),P.currentManager&&Q(e)&&e.isWritable&&P.currentManager.textEditorManager.checkEmptyTextBlur()},hasElements:(d,M)=>{var w;if(P.logger.info(`[ApplianceSinglePlugin] hasElements ${d}`),P.currentManager&&Q(e)&&e.isWritable){let m=d;if(!m){const y=P.currentManager.viewContainerManager.focuedView;m=y==null?void 0:y.focusScenePath}if(m){const y=(w=P.currentManager.collector)==null?void 0:w.getScenePathData(m);if(y){const S=Object.values(y);return S.length>0?M?S.some(v=>M(v.toolsType)):!0:!1}return!1}return!1}},getElements:(d,M)=>{var w;if(P.logger.info(`[ApplianceSinglePlugin] getElements ${d}`),P.currentManager&&Q(e)&&e.isWritable){let m=d;if(!m){const y=P.currentManager.viewContainerManager.focuedView;m=y==null?void 0:y.focusScenePath}if(m){const y=(w=P.currentManager.collector)==null?void 0:w.getScenePathData(m),S=y&&Object.values(y)||[];return y&&S.length>0&&M?S.filter(v=>M(v.toolsType)):S}return[]}},stopDraw:d=>{if(P.logger.info(`[ApplianceSinglePlugin] stopDraw ${d}`),P.currentManager&&Q(e))return P.currentManager.stopDraw(d)},setViewLocalScenePathChange:async(d,M)=>{P.logger.info(`[ApplianceSinglePlugin] setViewLocalScenePathChange ${d} ${M}`),P.currentManager&&await P.currentManager.setViewLocalScenePathChange(d,M)},insertMarkmap:async(d,M)=>{if(P.logger.info(`[ApplianceSinglePlugin] insertMarkmap: ${d}, info: ${JSON.stringify(M)}`),P.currentManager&&P.currentManager.isUseBackgroundThread)return P.currentManager.worker.insertBackgroundMarkMap(d,M)},updateMarkmap:async(d,M,w)=>{if(P.logger.info(`[ApplianceSinglePlugin] updateMarkmap: ${d}, markmapId: ${M}, info: ${JSON.stringify(w)}`),P.currentManager&&P.currentManager.isUseBackgroundThread)return P.currentManager.worker.updateBackgroundMarkMap(d,M,w)},insertBackgroundImage:async(d,M)=>{if(P.logger.info(`[ApplianceSinglePlugin] insertBackgroundImage: ${d}, info: ${JSON.stringify(M)}`),P.currentManager&&P.currentManager.isUseBackgroundThread)return P.currentManager.worker.insertBackgroundSVG(d,M)},getSelectedElements:d=>{var M,w;return(w=(M=P.currentManager)==null?void 0:M.selectorApi)==null?void 0:w.getSelectedElements(d)},isElementPropertySupported:(d,M)=>{var w,m;return((m=(w=P.currentManager)==null?void 0:w.selectorApi)==null?void 0:m.isElementPropertySupported(d,M))||!1},blurSelector:d=>{var M;if(P.currentManager&&Q(e)&&e.isWritable){const w=(M=P.currentManager)==null?void 0:M.selectorApi;return w?w.blurSelector(d):Promise.resolve({ok:!1,requestId:`clear-${Date.now().toString(36)}`,viewId:d||ie,reason:"no-selection"})}return Promise.resolve({ok:!1,requestId:`clear-${Date.now().toString(36)}`,viewId:d||ie,reason:"no-selection"})},updateSelectedElements:d=>{var M;if(P.currentManager&&Q(e)&&e.isWritable){const w=(M=P.currentManager)==null?void 0:M.selectorApi;return w?w.updateSelectedElements(ie,d):Promise.resolve({requestId:`update-${Date.now().toString(36)}`,viewId:ie,ok:!1,reason:"no-selection"})}return Promise.resolve({requestId:`update-${Date.now().toString(36)}`,viewId:ie,ok:!1,reason:"no-writable permission"})},updateElement:(d,M,w,m,y=!0)=>{var S;if(P.currentManager&&Q(e)&&e.isWritable){const v=(S=P.currentManager)==null?void 0:S.selectorApi;return v?v.updateElement(d,M,w,m,y):Promise.resolve(!1)}return Promise.resolve(!1)},copySelectedElements:d=>{var M;if(P.currentManager&&Q(e)&&e.isWritable){const w=(M=P.currentManager)==null?void 0:M.selectorApi;return w?w.copySelectedElements(d):Promise.resolve({ok:!1,requestId:`copy-${Date.now().toString(36)}`,viewId:d||ie,reason:"no-selection"})}return Promise.resolve({ok:!1,requestId:`copy-${Date.now().toString(36)}`,viewId:d||ie,reason:"no-selection"})},deleteSelectedElements:d=>{var M;if(P.currentManager&&Q(e)&&e.isWritable){const w=(M=P.currentManager)==null?void 0:M.selectorApi;return w?w.deleteSelectedElements(d):Promise.resolve({ok:!1,requestId:`delete-${Date.now().toString(36)}`,viewId:d||ie,reason:"no-selection"})}return Promise.resolve({ok:!1,requestId:`delete-${Date.now().toString(36)}`,viewId:d||ie,reason:"no-selection"})},getFloatbarContainer:d=>{var M;return(M=P.currentManager)==null?void 0:M.viewContainerManager.getFloatbarContainer(d)},getViewOffsetToContainer:(d,M)=>{var w;return(w=P.currentManager)==null?void 0:w.viewContainerManager.getViewOffsetToContainer(d,M)}};h.injectMethodToObject(e,"undo"),h.injectMethodToObject(e,"redo"),h.injectMethodToObject(e,"cleanCurrentScene"),h.injectMethodToObject(e,"blurSelector"),h.injectMethodToObject(e,"updateElement"),h.injectMethodToObject(e,"insertImage"),h.injectMethodToObject(e,"completeImageUpload"),h.injectMethodToObject(e,"lockImage"),h.injectMethodToObject(e,"getImagesInformation"),h.injectMethodToObject(e,"insertText"),h.injectMethodToObject(e,"updateText"),h.injectMethodToObject(e,"callbacks"),h.injectMethodToObject(e,"screenshotToCanvasAsync"),h.injectMethodToObject(e,"getBoundingRectAsync"),h.injectMethodToObject(e,"scenePreviewAsync"),h.injectMethodToObject(e,"fillSceneSnapshotAsync"),h.injectMethodToObject(e,"setMemberState"),Q(e)&&h.injectMethodToObject(e,"setWritable"),Object.defineProperty(e,"canUndoSteps",{get(){return h.canUndoSteps()}}),Object.defineProperty(e,"canRedoSteps",{get(){return h.canRedoSteps()}});const g={...h,callbacks:h.callbacks()};return Object.defineProperty(g,"disableDeviceInputs",{set(d){h.setDisableDeviceInputs(d)},get(){return h.getDisableDeviceInputs()}}),Object.defineProperty(g,"disableEraseImage",{set(d){h.setDisableEraseImage(d)},get(){return h.getDisableEraseImage()}}),Object.defineProperty(g,"disableCameraTransform",{set(d){h.setDisableCameraTransform(d)},get(){return h.getDisableCameraTransform()}}),e._appliancePlugin=g,e._appliancePlugin}static onCreate(e){e&&P.currentManager&&(P.currentManager.bindPlugin(e),e.init(e.displayer))}static async createAppliancePlugin(e,t){try{await e.createInvisiblePlugin(P,{})}catch(r){if(!e.isWritable){await e.setWritable(!0);const s=await this.createAppliancePlugin(e,t);return await e.setWritable(!1),s}throw r}let i=e.getInvisiblePlugin(t);return i||(i=await P.createAppliancePlugin(e,t)),i}static effectInstance(){if(P.cursorAdapter){const e=P.cursorAdapter.onAddedCursor;P.cursorAdapter.onAddedCursor=function(t){t.onCursorMemberChanged=i=>{try{i.appliance===re.pencil||i.appliance===re.shape||i.appliance===re.text||i.appliance===re.arrow||i.appliance===re.straight||i.appliance===re.rectangle||i.appliance===re.ellipse||i.appliance===re.eraser||i.appliance===re.selector?t!=null&&t.divElement&&(t.divElement.style.display="none"):t!=null&&t.divElement&&(t.divElement.style.display="block")}catch(r){throw r}},e.call(P.cursorAdapter,t)}}}get isReplay(){return oi(this.displayer)}get callbackName(){return this.isReplay?"onPlayerStateChanged":"onRoomStateChanged"}init(e){var i,r;const t=e.state;(i=P.currentManager)==null||i.onRoomMembersChange(t.roomMembers),Q(e)&&t!=null&&t.memberState&&((r=P.currentManager)==null||r.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;P.logger.info("[ApplianceSinglePlugin] passive destroy"),(e=P.currentManager)==null||e.destroy(),P.currentManager=void 0,P.cursorAdapter=void 0}};I(P,"kind","appliance-single-plugin"),I(P,"cursorAdapter"),I(P,"currentManager"),I(P,"logger",{info:console.log,warn:console.warn,error:console.error}),I(P,"createCurrentManager",(e,t,i)=>{P.currentManager&&P.currentManager.destroy();const r={plugin:i,displayer:e,options:t},s=new Ge(r);if(s.init(),P.logger.info("[ApplianceSinglePlugin] refresh ApplianceSingleManager object"),P.currentManager=s,Q(e)){const a=s.hasOffscreenCanvas,c=s.isUseOffscreenTransfer,l=s.pluginOptions,u=s.isUseSimple;e.logger.info(`[Appliance]: [ApplianceSinglePlugin] use ${a?"worker":"mainThread"}, isUseSimple: ${u} ${c?"offscreenTransfer":""}, options: ${JSON.stringify(l)}`)}});let ni=P;const Dt=class Dt extends f.Component{constructor(){super(...arguments);I(this,"mainViewRef",null)}componentDidMount(){Dt.emiter||(Dt.emiter=Ge.InternalMsgEmitter),Dt.emiter.emit(te.BindMainView,this.mainViewRef)}render(){return f.createElement(f.Fragment,null,this.props.children,f.createElement("div",{className:"appliance-plugin-main-view-displayer",ref:e=>this.mainViewRef=e}))}};I(Dt,"emiter");let ii=Dt;const Sw=Object.freeze(Object.defineProperty({__proto__:null,ActiveContainerType:Nr,ApplianceMultiPlugin:ti,ApplianceNames:re,ApplianceSigleWrapper:ii,ApplianceSinglePlugin:ni,Cursor_Hover_Id:Cr,ECanvasShowType:Ze,EDataType:J,EForceStopReason:ri,EImageType:At,EMatrixrRelationType:jt,EOperationType:je,EPostMessageType:W,ERenderFilterType:He,ESVGType:Et,EScaleType:Oe,EStrokeType:ce,EToolsKey:T,ElayerType:st,EmitEventType:R,EventMessageType:Kt,EventWorkState:E,EvevtWorkState:E,InternalMsgEmitterType:te,Main_View_Id:ie,ShapeType:Be,Task_Time_Interval:Mn},Symbol.toStringTag,{value:"Module"}));exports.Cursor_Hover_Id=Cr;exports.DefaultAppliancePluginExtrasOptions=we;exports.ECanvasShowType=Ze;exports.EDataType=J;exports.EImageType=At;exports.EMatrixrRelationType=jt;exports.EPostMessageType=W;exports.ESVGType=Et;exports.EScaleType=Oe;exports.EStrokeType=ce;exports.EToolsKey=T;exports.EmitEventType=R;exports.EventWorkState=E;exports.Main_View_Id=ie;exports.Point2d=Me;exports.Storage_Selector_key=Z;exports.Storage_Splitter=Ve;exports.Storage_ViewId_ALL=io;exports.Task_Time_Interval=Mn;exports.TextBoxPadding=Zn;exports.Vec2d=F;exports.ViewContainerManager=Lt;exports._Stack=zr;exports._baseGetTag=Rt;exports._equalArrays=ro;exports._equalByTag=Rf;exports._getAllKeys=Hr;exports._getTag=Nn;exports.average=LM;exports.checkOp=DM;exports.cloneDeep=en;exports.colorRGBA2Array=qt;exports.computRect=yM;exports.decimalPlaces=AM;exports.gcd=EM;exports.getDefaultExportFromCjs=yn;exports.getRectFromPoints=Ti;exports.getRectMatrixrRelation=PM;exports.getRectRotated=SM;exports.getRectScaleWPoint=vM;exports.getRectTranslated=wM;exports.getSafetyRect=IM;exports.getWHRatio=bM;exports.index=Sw;exports.isArray_1=_t;exports.isBufferExports=ci;exports.isDecimal=jM;exports.isIntersect=mM;exports.isIntersectForPoint=lo;exports.isObjectLike_1=ct;exports.isSet=Kd;exports.isTypedArray_1=Br;exports.precise=zM;exports.requestAsyncCallBack=qe;exports.rgbToRgba=bt;exports.rotateLitePoints=CM;exports.rotatePoints=NM;exports.scaleLitePoints=xM;exports.scalePoints=kM;exports.strlen=OM;exports.transformToNormalData=zt;exports.transformToSerializableData=St;